var XmlReq;
var AjaxServerCheckEmail = "CheckSignUpEmail.aspx";

function CreateXmlReq()
{
	try
	{
		XmlReq = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlReq = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			XmlReq = null;
		}
	}
	if(!XmlReq && typeof XMLHttpRequest != "undefined") 
	{
		XmlReq = new XMLHttpRequest();
	}
}

function checkEmailAvailability( emid )
{
	if (document.getElementById(emid)){
		if(document.getElementById(emid).value != ""){
			CheckingDiv('chkEmail', '<img src="images/indicator.gif" width="21" height="5" />&nbsp;<span style="color:#000000;font-size:11px;">validate email</span>');
			
			var email = "";
			
			if (document.getElementById(emid))
				email = document.getElementById(emid).value;
			
			x_checkEmail( email );	
		}
		
	}	
}

function x_checkEmail( Email )
{
	var requestUrl = "../webcustom/remoteactions/" + 
					AjaxServerCheckEmail + 
					"?em=" + encodeURIComponent(Email);
	CreateXmlReq();
	
	if(XmlReq)
	{
		XmlReq.onreadystatechange = HandleChkEmailWebResponse;
		XmlReq.open("GET", requestUrl,  true);
		XmlReq.send(null);		
	}
}

function HandleChkEmailWebResponse()
{
	if(XmlReq.readyState == 4)
	{
		if(XmlReq.status == 200)
		{			
			ClearDiv('chkEmail');
			if(XmlReq.responseText != "")
			{
				ClearDiv('pnlResult');
				PopulateDiv('pnlResult', XmlReq.responseText);
				//document.getElementById('txtEmail').focus();
				document.getElementById('txtEmail').select();
			}
		}
		else
		{
			alert("There was a problem retrieving data from the server." );
			ClearDiv('pnlResult');
		}
	}
}

function ClearDiv(id)
{
	var tmpDiv = document.getElementById(id);
	if(tmpDiv.innerHTML != "")
		tmpDiv.innerHTML = "";
}

function PopulateDiv(id, content)
{
	var tmpDiv = document.getElementById(id);
	if (content != "")
		tmpDiv.innerHTML = content;
}
function CheckingDiv(id, content)
{
	var tmpDiv = document.getElementById(id);
	tmpDiv.innerHTML = content;
}