var xmlHttp

function GetXmlHttpObject()
{ 
	var objXMLHttp=null
	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest()
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
}
function checkemail(value)
{ 
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="getemail.php";
	url=url+"?email="+value;
	xmlHttp.onreadystatechange=chkemailavailability 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}
function checkusr(val)
{ 
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="getuname.php";
	url=url+"?uid="+val;
	xmlHttp.onreadystatechange=chkuseravailability 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}
function chkuseravailability() 
{ 
	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		if(xmlHttp.responseText==1){
			document.getElementById("usr").style.display="block";
			document.getElementById("usr").innerHTML="This username already exists.";
			document.getElementById("usr").value="";
			document.getElementById("exR_usrname").focus();
			return false;
		}
		else if(xmlHttp.responseText==2){
			document.getElementById("usr").style.display="block";
			document.getElementById("usr").innerHTML="This keyword is not allowed in username.";
			document.getElementById("usr").value="";
			document.getElementById("exR_usrname").focus();
			return false;
		}
		else{
			document.getElementById("usr").style.display="none";
		}			
	}
} 

function chkemailavailability() 
{ 
	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		if(xmlHttp.responseText==1)
		{
			document.getElementById("ema").style.display="block";
			document.getElementById("ema").innerHTML="This email address already exists.";
			document.getElementById("ema").value="";
			document.getElementById("exR_emailid").focus();
			return false;
		}
		else
		{
			document.getElementById("ema").style.display="none";
		}			
	}
} 

function chkpass($a)
{	// var docf=document.frmRegister.d;
	
	$value = document.registrationfrm.getElementById("exR_pass").value;
	if(!isAlphaNumeric($a))
	{
		document.registrationfrm.getElementById("pa").style.display="block";
		document.registrationfrm.getElementById("pa").innerHTML="Please enter valid password.";
		document.registrationfrm.pass.focus();
		return false
	}
	else
	{
		document.registrationfrm.getElementById("pa").style.display="none";
		document.registrationfrm.getElementById("pa").innerHTML="";
	}
	if($a.length<6) // password should not be less than 6 characters
	{
		document.registrationfrm.getElementById("pa").style.display="block";
		document.registrationfrm.getElementById("pa").innerHTML="Password should not less than 6 characters";
		document.registrationfrm.pass.focus();
		return false
	}
	else
	{
		document.registrationfrm.getElementById("pa").style.display="none";
		document.registrationfrm.getElementById("pa").innerHTML="";
	}
	if($a.length>32) // password should not exceed 32 characters
	{
		document.registrationfrm.getElementById("pa").style.display="block";
		document.registrationfrm.getElementById("pa").innerHTML="Password should not exceed 32 characters";
		document.registrationfrm.pass.focus();
		return false
	}
	else
	{
		document.registrationfrm.getElementById("pa").style.display="none";
		document.registrationfrm.getElementById("pa").innerHTML="";
	}
}
function nochars(e,a)
{	// var docf=document.frmRegister.d;
	
	
	var unicode=e.charCode? e.charCode : e.keyCode
	
		if (unicode>32||unicode<126) //if not a number
		{	
			document.getElementById("db").style.display="block";
			document.getElementById("db").innerHTML = "Please select your date of birth from the given calendar";
			return false ;//disable key press
		}
		else if(unicode==32 || unicode==13)
		{
			document.getElementById("db").style.display="none";
			document.getElementById("db").innerHTML = "";
			return true;	
		}
		else
		{
			document.getElementById("db").style.display="none";
			document.getElementById("db").innerHTML = "";
		}
}

function isValidPassword(val)
{
	strval = val
	if (strval.length < 6 || strval.length > 32)
	{
		return false
	}	
	else
	{
		return true;
	}	
}
function isAlphaNumeric(objValue)
{ 
		var characters="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
		var tmp
		var lTag
		lTag = 0
		temp = (objValue.length)
		//(temp);
		for (var i=0;i<temp;i++)
		{
			tmp=objValue.substring(i,i+1)
			if (characters.indexOf(tmp)==-1)
			{ 
				lTag = 1
			}
		}(characters.indexOf(tmp));
		(lTag);
		if(lTag == 1)
			{ 
			return false;
			}
		else
			{ 
			return true;
			}
}
