
function message(text,handler){

	if(document.readyState=="complete"){
	
		_message(text,handler);
	
	}
	else{
	
		window.onload=function(){
	
			_message(text,handler);
	
		}
	}
}

function _message(text,handler){

	var div=document.body.appendChild(document.createElement("div"));
	div.className="message";
	div.innerHTML=text;
	var button=div.appendChild(document.createElement("button"));
	button.appendChild(document.createTextNode("OK"));
	button.onclick=function(){

		document.body.removeChild(div);
		eval(handler||"");
		
	}
	div.style.top=(150+document.body.scrollTop)+"px";
	div.style.left=(((document.body.clientWidth/2)-(div.offsetWidth/2))+document.body.scrollLeft)+"px";
	
}

function progress(text){

	var div=document.body.appendChild(document.createElement("div"));
	div.className="progress";
	div.innerHTML=text;
	div.style.top=(150+document.body.scrollTop)+"px";
	div.style.left=(((document.body.clientWidth/2)-(div.offsetWidth/2))+document.body.scrollLeft)+"px";

}

function validate(form){

	var valid=true;
	var inputs=form.elements;
	for(var i=0;i<inputs.length;i++){
	
		var input=inputs[i];
		if(window.FCKeditorAPI){
		
			var editor=FCKeditorAPI.GetInstance(input.name);
			if(editor){
		
				input.value=editor.GetHTML();
				
			}
		}
		
		if((input.name=="email"||input.name=="name"||input.name=="title"||input.name=="text"||input.name=="contact"||input.name=="photo"||input.name=="detail")&&!input.value){
		
			input.style.backgroundColor="#ffcccc";
			input.onfocus=function(){ this.style.backgroundColor=""; }
			valid=false;
		
		}
		
		// Specific email validation
		if(input.name=="email"){
			
			var email=input.value.replace(/^\s+/, '').replace(/\s+$/, '');;
			if(!email.match(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/)){
		
				message("Please enter a valid email address.");
				return false;
		
			}
		}
	}
	if(!valid){
	
		if(inputs.forgot){
		
			inputs.forgot.value="";
		
		}
		message("Please complete all marked fields.");
		return false;
	
	}
	else{
	
		if((inputs.picture&&inputs.picture.value)||(inputs.photo&&inputs.photo.value)){ 
			
			progress("Uploading "+((inputs.photo)?"photo":"picture")+", please wait...<br/>Large "+((inputs.photo)?"photos":"pictures")+" may take several minutes.");
			
		}
	}
}



