// XMLHttpRequest object created after checking wheather the browser are compatible with ajax.
//============================================================================================
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;
}


//Getting XMLHttpRequest object for starting Ajax functionalities.
//===================================================================
function validate(state)
{
 
 //alert(state);
 xmlHttp=GetXmlHttpObject()
 if (xmlHttp==null)
 {
    alert ("Your browser does not support AJAX!");
	return;
 }
 else
 {
  
  if(state){
   
	  xmlHttp.onreadystatechange=stateChanged66;
	  var uname=document.form2.user_name.value;
	  var password=document.form2.password.value;
	  var con_password=document.form2.con_password.value;
	  var email=document.form2.email.value;
	  var year=document.form2.year.value;
	  var month=document.form2.month.value;
	  var date=document.form2.date.value;
	  var country=document.form2.country.value;
	  var state=document.form2.state.value;
	  var city=document.form2.city.value;
	  var ethnicity=document.form2.ethnicity.value;
	  var relationship_desire=document.form2.relationship_desire.value;
	  var image=document.form2.default_photo.value;
	  var state1=document.form2.state1.value;
	  //alert(image);
	  
	  url="ajax/validate.php?uname="+uname+"&password="+password+"&con_password="+con_password+"&email="+email+"&year="+year+"&month="+month+"&date="+date+"&country="+country+"&state="+state+"&city="+city+"&ethnicity="+ethnicity+"&relationship_desire="+relationship_desire+"&image="+image+"&state1="+state1+"&u="+Math.random();
	  xmlHttp.open("GET",url,true);
	  xmlHttp.send(null);
	  
  }
  
 } 
 //return true;
}

//After getting response from server,response text is being manupulated here.
//===========================================================================
function stateChanged66()
{
 if (xmlHttp.readyState==4)
 {
  
  var str=xmlHttp.responseText;//full_name~designation~salary
  
 	arr=str.split("~");
	
	document.getElementById("errmsg").innerHTML=arr[1];
	if(arr[0]==1)
	{
		document.form2.user_name.focus();
		return false;
	}	
	else if(arr[0]==2)
	{
		document.form2.password.focus();
		return false;
	}	
	else if(arr[0]==3)
	{
		document.form2.con_password.focus();
		return false;
	}	
	else if(arr[0]==16)
	{
		document.form2.password.focus();
		return false;
	}
	else if(arr[0]==4)
	{
		document.form2.password.value='';
		document.form2.con_password.value='';
		document.form2.password.focus();
		return false;
	}	
	else if(arr[0]==5)
	{
		document.form2.email.focus();
		return false;
	}	
	else if(arr[0]==17)
	{
		document.form2.email.focus();
		return false;
	}
	else if(arr[0]==6)
	{
		document.form2.year.focus();
		return false;
	}	
	else if(arr[0]==7)
	{
		document.form2.month.focus();
		return false;
	}	
	else if(arr[0]==8)
	{
		document.form2.date.focus();
		return false;
	}
	else if(arr[0]==10)
	{
		document.form2.country.focus();
		return false;
	}
	
	if(arr[0]==11)
	{
		document.form2.state1.focus();
		return false;
	}
	else if(arr[0]==19)
	{
		document.form2.state.focus();
		return false;
	}
	else if(arr[0]==12)
	{
		document.form2.city.focus();
		return false;
	}
	else if(arr[0]==13)
	{
	   	document.form2.ethnicity.focus();
		return false;
	}
	else if(arr[0]==14)
	{
		document.form2.relationship_desire.focus();
		return false;
	}
	else if(arr[0]==17)
	{
		document.form2.default_photo.focus();
		return false;
	}
	else if(arr[0]==18)
	{
		document.form2.default_photo.focus();
		return false;
	}
	
	else //if(arr[0]==15)
	{
		//alert("ok");
		
		document.form2.submit();
		//return true;
		exit;
	} 
 }
}
