var xmlHttp

function CheckAvail(str,str1,str2)
{ 
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }

var url
if(str2=="D")	//check for duplicates
{
	url="checkavail.php"
}
else if(str2=="ED" || str2=="CD")	//check for email referral or captcha  - user registration (duplicate)
{
	url="checkemailregdup.php"
}
else if (str2=="A")		//check for posted url existence
{
	url="checkurl.php"
}
else if(str2=="M")	//check for email existence
{
	url="checkmail.php"
}
else
{
	url="checklogin.php"
}
url=url+"?q="+str
url=url+"&vrVar2="+str1
url=url+"&vrVar3="+str2

url=url+"&sid="+Math.random()

xmlHttp.onreadystatechange=stateChanged 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 {
	if (xmlHttp.responseText == "Success")		//if other than adv.post & Data mining
	{
		window.location = "home.php"
	}

/*	else if (xmlHttp.responseText == "e-Success")		//if email - referral
	{
		window.location = "home-email.php"
	}*/

	else if (xmlHttp.responseText == "dm-Success")		//if data mining
	{
		window.location = "home-dm.php"
	}

	else if (xmlHttp.responseText == "A-Success")		//if adv.posting - login
	{
		window.location = "home-ap.php"
	}
	
	else if (xmlHttp.responseText == "AE" || xmlHttp.responseText == "AN")		//if adv.posting - url existence status
	{
		document.forms[0].txtDupSt.value=xmlHttp.responseText

		if(xmlHttp.responseText == "AN")
		{
			document.forms[0].action="posturl.php?vrVar1=1"
			document.forms[0].submit()
		}
		else if(xmlHttp.responseText == "AE")
		{
			document.getElementById("dvAvail").innerHTML = "The URL '" + document.forms[0].txtURL.value + "' already exists."
		}
	}

	else if (xmlHttp.responseText == "dm-Finished")		//if data mining - 5 hrs time is been reached
	{
		alert("Work duration for this day is finished. Try tomorrow.")
		//window.location = "home-dm.php"
	}
 
 	else if (xmlHttp.responseText == "Failure")		//if login failed
	{
		alert("Invalid Username or Password")
	}

	else if (xmlHttp.responseText == "S")		//if email ref -duplicate verification
	{
		document.forms[0].txtDupSt.value=xmlHttp.responseText 
		
		document.getElementById("dvAvail").innerHTML = ""
	}
 
	else
	 {
		//document.forms[0].txtDupSt.value="F";

		document.getElementById("dvAvail").innerHTML=xmlHttp.responseText;
	 }
 }
}function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}

