// JavaScript Document

var myReq=null;
var ltrgt=null;

function checkAvail(trgtVal,trgtPage,trgtVar,trgtCat,trgtType)
{
	if(trgtType=='u')
	{
		trgtVal.value=trgtVal.value.replace(/ /g,"");
		trgtVal.value=trgtVal.value.replace(/\./g,"");
	}
	
	if(trgtVal.value=="")
	{
		alert("Please enter valid User Name to check Availability");
		return;
	}
	ltrgt=trgtVal;
	if(window.XMLHttpRequest)
	{
		myReq=new window.XMLHttpRequest();
	}
	else
	{
		if(window.ActiveXObject)
		{
			myReq=new window.ActiveXObject('Microsoft.XMLHTTP');
			if(!myReq)
			{
				myReq=new window.ActiveXObject('Msxml2.XMLHTTP');
				if(!myReq)
				{
					currWin=window.open(trgtPage + "?" + trgtVar + "=" + trgtVal.value + "&cat=" + trgtCat + "&type=" + trgtType,"Checking Availability","status=0,location=0,scrollbars=0,toolbar=0,menubar=0,resizeable=0,width=100,height=50");
					currWin.moveTo(100,25);
					return;
				}
			}
		}
		else
		{
			currWin=window.open(trgtPage + "?" + trgtVar + "=" + trgtVal.value + "&cat=" + trgtCat + "&type=" + trgtType,"Checking Availability","status=0,location=0,scrollbars=0,toolbar=0,menubar=0,resizeable=0,width=100,height=50");
			currWin.moveTo(100,25);
			return;
		}
	}
	
	myReq.onreadystatechange=handlereq;
	myReq.open("GET",trgtPage + "?" + trgtVar + "=" + trgtVal.value + "&cat=" + trgtCat + "&type=" + trgtType,true);
	myReq.send(null);
	//document.getElementById(trgtVal.id + 'other').innerHTML="Checking...";
	return;
}

function handlereq()
{
	if(myReq.readyState==4)
	{
		if(myReq.status==200)
		{
			document.getElementById(ltrgt.name + 'other').innerHTML=myReq.responseText;
		}
		else
		{
			alert("Communication with server failed. Pleae ignore it and fill & submit form.");
		}
	}
}