var xmlHttp
function GetXmlHttpObject()
{ 
   //alert("Hi");
	var objXMLHttp=null
	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest()
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
}

function userEmail(val)
{   
    //alert("Hi email already exist");
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="check.php";
	url=url+"?email="+val;
	xmlHttp.onreadystatechange=chkemailavailability 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function userEmail1(val)
{   
    xmlHttp=GetXmlHttpObject();
    
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="check.php";
    url=url+"?email="+val;
    
    xmlHttp.onreadystatechange=chkemailavailability_new; 
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
}
function chkusr(val)
{   
    //alert("Hi username already exist");
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="check.php";
	url=url+"?uname="+val;
	xmlHttp.onreadystatechange=chkemailavailability 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function chkemailavailability_new()
{
 
  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    { 
        // alert(xmlHttp.responseText); 
        if(xmlHttp.responseText==2)
        {
            document.getElementById("emailid").innerHTML="<TR><td  width='100%'  colspan='3' height='25px' align='center'><b style='color:#009900'>You are not valid user for site.</b></td></TR>";//div id
            document.getElementById("emailid").style.visibility='visible';
            document.getElementById("emailid").style.display='block';
        }
        
                
    }
}

function chkemailavailability () 
{ 
	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		  
        if(xmlHttp.responseText==1)
		{
			document.getElementById("emailid").innerHTML="<b style='color:#FF0000'>Email already exists.</b>";//div id
			document.getElementById("emailid").style.visibility='visible';
			document.getElementById("emailid").style.display='block';
			document.getElementById("emailaddress").value="";                                                  //input tag id
			document.getElementById("emailaddress").focus();
		}
		else if(xmlHttp.responseText==2)
		{
			document.getElementById("emailid").innerHTML="<b style='color:#009900'>You can use this email.</b>";//div id
			document.getElementById("emailid").style.visibility='visible';
			document.getElementById("emailid").style.display='block';
		}
		else if(xmlHttp.responseText==3) // for username
		{
			document.getElementById("usrnm").innerHTML="<b style='color:#FF0000'>User name already exists.</b>";//div id
			document.getElementById("usrnm").style.visibility='visible';
			document.getElementById("usrnm").style.display='block';
			document.getElementById("username").value="";                                                         //input tag id
			document.getElementById("username").focus(); 
		}
		else if(xmlHttp.responseText==4) // for username
		{
			document.getElementById("usrnm").innerHTML="<b style='color:#009900'>You can use this username.</b>";//div id
			document.getElementById("usrnm").style.visibility='visible';
			document.getElementById("usrnm").style.display='block';
		}
				
	}
} 
