// JavaScript Document

var xmlHttp

function validate(value,name)
{
	if(name == "zip") {
		if(value.length == 0) {
			return;
		}
	}
	
	if (name == "email")
  	{ 
		if(value.length!=0) {
			//document.getElementById(name+"_msg").className="AjaxOK";			
	  		//document.getElementById(name+"_msg").innerHTML="OK";
		}else{		
	  		document.getElementById(name+"_msg").innerHTML="";
			return;
		}
  	}

	if(name == "password1") {
		if (value.length >= 6) {
			document.getElementById(name+"_msg").innerHTML="";
			document.getElementById("password1_msg").className="AjaxOK";
			document.getElementById("password1_msg").innerHTML="OK";
		}else if(value.length > 0){
			document.getElementById(name+"_msg").innerHTML="";
			document.getElementById("password1_msg").className="AjaxError";
			document.getElementById("password1_msg").innerHTML="Must be at least 6 characters";
		}else{
			return;
		}
		
		//alert(document.getElementById('password2').value.toString()+"-"+document.getElementById('password').value.toString());
		
		if(document.getElementById('password2').value.length > 0) {
			if (document.getElementById('password2').value.toString() != document.getElementById('password').value.toString()) {
				document.getElementById("password2_msg").className="AjaxError";
				document.getElementById("password2_msg").innerHTML="Passwords do not match";
			}else{
				document.getElementById("password2_msg").className="AjaxOK";
				document.getElementById("password2_msg").innerHTML="OK";
			}
		}
				
		return;
	}
	
	if(name == "password2") {
				
			if (document.getElementById('password1').value.toString() != value.toString()) {
				document.getElementById(name+"_msg").className="AjaxError";
				document.getElementById(name+"_msg").innerHTML="Passwords do not match";
			}else{
				document.getElementById(name+"_msg").className="AjaxOK";
				document.getElementById(name+"_msg").innerHTML="OK";
			}
			
			return;
	}
	
	xmlHttp=GetXmlHttpObject();
	
	if (xmlHttp==null)
  	{
  	//alert ("Your browser does not support AJAX!");
  		return;
  	}
	

	var url="./signup_ajax.php";
	url=url+"?validate="+name;
	url=url+"&value="+value;
	url=url+"&r="+Math.random();
	xmlHttp.onreadystatechange=function () {stateChanged(name+"_msg"); }
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 

function stateChanged(name) 
{ 
	if (xmlHttp.readyState==4)
	{ 
		var msgid;
		msgid=name+"_msg";
		
		response=xmlHttp.responseText;
		
		//alert(response);
		document.getElementById(name).innerHTML=xmlHttp.responseText;
	}
}

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
  	{
  	// Firefox, Opera 8.0+, Safari
  		xmlHttp=new XMLHttpRequest();
  	}

	catch (e)
  	{
  // Internet Explorer
  		try
    	{
    		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    	}
	
  		catch (e)
    	{
    		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    	}
  }
  
	return xmlHttp;
}

