// JavaScript Document
var xmlHttp = createXmlHttpRequestObject();
lnameexist=0;
function createXmlHttpRequestObject()
{
  var xmlHttp;
  if(window.ActiveXObject)
	{
		 try
		 {
			 xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		 }
		 catch (e)
		 {
			  xmlHttp = false;
		 }
	}
	else
	{
		try
		{
			xmlHttp = new XMLHttpRequest();
		}
		catch (e)
		{
			xmlHttp = false;
		}
	}
	if (!xmlHttp)
		alert("Error creating the XMLHttpRequest object.");
	else
		return xmlHttp;
}

function chkloginname()
{	
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
	{	
		var lname=document.getElementById('logname').value;	
		xmlHttp.open("GET", "chklnamexml.php?lname=" + lname, true);
		xmlHttp.onreadystatechange = chklnameout;
		xmlHttp.send(null);
	}
	else
		setTimeout('chkloginname()',1000);
}
function chklnameout()
{
	if (xmlHttp.readyState == 4)
	{
		if (xmlHttp.status == 200)
		{
			lnameexist= xmlHttp.responseXML.getElementsByTagName('userext')[0].childNodes[0].nodeValue;
			enqsubmit();
		}
		else
		{
			alert("There was a  problem accessing the server: " + xmlHttp.statusText);
		}
	}
}
function usercheck()
{
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
	{	
		var userinfo=new Array();
		userinfo=document.getElementById('regname').value+'-';
		userinfo+=document.getElementById('regpwd').value;
		xmlHttp.open("GET", "onlinetest/userchkajax.php?uinfo="+userinfo , true);
		xmlHttp.onreadystatechange =usercheckout;
		xmlHttp.send(null);
	}
	else
		setTimeout('usercheck()',1000);	
}
function usercheckout()
{
	if (xmlHttp.readyState == 4)
	{
		if (xmlHttp.status == 200)
		{
			var f=0;
			f=xmlHttp.responseXML.getElementsByTagName('userexist')[0].childNodes[0].nodeValue;		
			if(f==1)
			{
				document.getElementById('errormsg').innerHTML="";
				document.academy.submit();
			}
			else
				document.getElementById('errormsg').innerHTML='Check User Name/Password ';
		}			
		else
		{
			alert("There was a  problem accessing the server: " + xmlHttp.statusText);
		}
	}
}
