function validate_form(error_loading, formname) {
	$(error_loading).update("<img src='/images/ajax-loader.gif'>");
	
	
	$(formname).request(  {
		onSuccess: function(transport){
			//alert(transport.responseText);
			response  = 	transport.responseXML.documentElement;
			
			$(error_loading).update();
			//alert(formname);
			
			document.getElementsByClassName("error").each( function(input) { 
					$(input).update();
			})
			
			if(response.getElementsByTagName('result_flag')[0].childNodes[0].firstChild.nodeValue=="true") {
				
				/*Form.getElements(formname).each( function(input) { 
												
					$(input.id).removeClassName('validation-failed');
				})*/
				
				if(response.getElementsByTagName('result_field')[0].childNodes[0].nodeName=="call_function") {
					eval(response.getElementsByTagName('result_field')[0].childNodes[0].firstChild.nodeValue);
				} else if(typeof(red_url)=="undefined") {
					red_url	=	response.getElementsByTagName('result_field')[0].childNodes[0].firstChild.nodeValue;
					
					window.location.href	=	red_url;
				}
				
			} else {
				
				var total_error	=	response.getElementsByTagName('error_field')[0].childNodes.length;
				
				for(var i=0;i<total_error;i++) {
					var field_name	=	response.getElementsByTagName('error_field')[0].childNodes[i].nodeName;
					
					$("id_"+field_name).update(response.getElementsByTagName('error_field')[0].childNodes[i].firstChild.nodeValue);
				}
				
				var total_highlight	=	response.getElementsByTagName('highlight_field')[0].childNodes.length;
				
				for(var i=0;i<total_highlight;i++) {
					var field_name	=	response.getElementsByTagName('highlight_field')[0].childNodes[i].nodeName;
					$("txt_"+field_name).addClassName('validation-failed');
				}
				/*
				if(response.getElementsByTagName('redirect')[0].childNodes[0].nodeValue) {
					document.location.href=	"#error";
				}
				*/
			}
		}
	})
	return false;

}

function redirect_from_login(redirect) {

		document.location.href=	redirect;
	
}

function redirect_from_popup(redirect, from) {
	
	if(redirect.length==0) {
		
		document.location.href	=	"popup-login.html?from=close";
	} else {
		parent.myLytebox.setPageRefersh('true',parent.location.href);	
		
		document.location.href=	redirect;
	}
}

function redirect_to_sendfriend(redirect) {

	parent.myLytebox.setPageRefersh('true',redirect);	
		parent.myLytebox.end();
}

function reload_window() {
	
	window.location.href	=	window.location.href;
}

function update_aboutme() {
	$("id_about").innerHTML	=	document.editaboutme.txt_aboutme.value.replace(/([^>])\n/g, '$1<br />\n');
	$("id_about_edit").hide();
	$("id_about").show();
}



var obj = {
  fx: function(e) {
	var elm = Event.element(e);
		$(elm.id).removeClassName('validation-failed');
  }
};

var Validation = Class.create();

Validation.prototype = {
	initialize : function(form, options){
		this.options = Object.extend({
			onSubmit : true,
			immediate : false
		}, options || {});
		
		
		this.form = $(form);


		if(this.options.immediate) {
															   	
				
			Form.getElements(this.form).each( function(input) { 
				$(input.id).removeClassName('validation-failed');
				
				Event.observe(input, 'focus', obj.fx.bindAsEventListener(obj));
			})
		}
	}
}

function setfocusevent(formname) {
	var valid = new Validation(formname, {immediate : true});
}	

function showhide(id){

	$(id).removeClassName('hide');

}

function quickpost(){

	$('post_comment_block').show();

	var text = $('txt_comment');

	text.value = "";

	text.focus(); 

}

function save_title() {
   var image_title;
  
	if(document.editaboutme.txt_title.value.length==0) {
		image_title	=	"Click to edit image caption";
	} else {
		image_title	=	document.editaboutme.txt_title.value.replace(/([^>])\n/g, '$1<br />\n');	
	}
	
	$("image_title").innerHTML	=	'<a href="#edit" onclick="javascript:if($(\'image_title_edit\').hide()) { $(\'image_title_edit\').show();$(\'image_title\').hide() }" class="brownlink">'+image_title+'</a>';
	$("image_title_edit").hide();
	$("image_title").show();

}
function write_name(name){
	$("id_name").innerHTML	=	name;
}

function write_email(email){
	$("id_email").innerHTML	=	email;
}
