function check_option_selected(obj,div){
	if(obj[obj.selectedIndex].value=="0"){
		html='<font color="RED" size=1"><img src="images/cross.gif" height="15" width="15">Please select your state</font>'; 
		document.getElementById(div).innerHTML=html;
		obj.style.border="1px solid #FF0000";
		
		
		return true;	
	}
	
	html='<img	src="images/tick.gif" height="15" width="15" alt="ok">';
	document.getElementById(div).innerHTML=html;
	obj.style.border="1px solid #A0BABB";
	return false;
	
}


function check_email(email){
	if(!is_email(email.value)){
		html='<font color="RED" size=1"><img src="images/cross.gif" height="15" width="15">Invalid email address</font>'; 
		document.getElementById("emaildiv").innerHTML=html;
		email.style.border="1px solid #FF0000";
		return true;
	}
	
	html='<img	src="images/tick.gif" height="15" width="15" alt="ok">';
	document.getElementById("emaildiv").innerHTML=html;
	email.style.border="1px solid #A0BABB";
	return false;
	
}

function validate_phone(obj,div){
	
		
	if(is_empty(obj.value)){
		document.getElementById(div).innerHTML='';
		obj.style.border="1px solid #A0BABB";
		return false;
	}
	
	if(!is_number(obj.value)){
		html='<font color="RED" size=1"><img src="images/cross.gif" height="15" width="15">Must be a number</font>'; 
		document.getElementById(div).innerHTML=html;
		obj.style.border="1px solid #FF0000";
		return true;
	}
	html='<img	src="images/tick.gif" height="15" width="15" alt="ok">';
	document.getElementById(div).innerHTML=html;
	obj.style.border="1px solid #A0BABB";	
	return false;
}

function validate_field(obj,div){
	if(is_empty(obj.value)){
		html='<font color="RED" size=1"><img src="images/cross.gif" height="15" width="15">Can not be empty</font>'; 
		document.getElementById(div).innerHTML=html;
		obj.style.border="1px solid #FF0000";
		return true;
	}
	
	if(!is_number(obj.value) && div=="zipdiv"){
		html='<font color="RED" size=1"><img src="images/cross.gif" height="15" width="15">Must be a number</font>'; 
		document.getElementById(div).innerHTML=html;
		obj.style.border="1px solid #FF0000";
		return true;
	}
	html='<img	src="images/tick.gif" height="15" width="15" alt="ok">';
	document.getElementById(div).innerHTML=html;
	obj.style.border="1px solid #A0BABB";	
	return false;
}
function validate_form(form){
 error=0;

	if(validate_field(form.firstname,"firstnamediv"))
		error=1;
			
	if(validate_field(form.lastname,"lastnamediv"))
		error=1;

	if(validate_field(form.city,"citydiv"))
		error=1;
		
	if(validate_field(form.zip,"zipdiv"))
	error=1;	
			
	if(check_email(form.email))
		error=1;			
				
	if(check_option_selected(form.state,"statediv"))
		error=1;		
	if(validate_phone(form.phone,"phonediv"))
		error=1	;
		
		
if(error)
	return false;
else
	return true;	

}

function clear_all(){
	
	
	
	document.getElementById("firstname").style.border='1px solid #A0BABB';
	document.getElementById("firstnamediv").innerHTML='';
	
	document.getElementById("lastname").style.border='1px solid #A0BABB';
	document.getElementById("lastnamediv").innerHTML='';
	
	document.getElementById("city").style.border='1px solid #A0BABB';
	document.getElementById("citydiv").innerHTML='';
	
	document.getElementById("zip").style.border='1px solid #A0BABB';
	document.getElementById("zipdiv").innerHTML='';	

	document.getElementById("phone").style.border='1px solid #A0BABB';
	document.getElementById("phonediv").innerHTML='';
	
	document.getElementById("email").style.border='1px solid #A0BABB';
	document.getElementById("emaildiv").innerHTML='';	
	
	document.getElementById("state").style.border='1px solid #A0BABB';
	document.getElementById("statediv").innerHTML='';	
	
				
	//document.getElementById("password").style.border='';
}