var xmlhttp=false;

function xmlObject()

{

	try 

	{

			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

	} 

	catch (e) 

	{

		try 

		{

			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

		} 

		catch (e) 

		{

			try 

			{

				xmlhttp = new XMLHttpRequest();

			}

			catch(e)

			{

				xmlhttp=false;

			} 

		}

	}

return xmlhttp;

}



function selectSubcountry(id)

{



	xmlhttp=xmlObject();

	xmlhttp.onreadystatechange = function(){

		var ajaxDisplay = document.getElementById('substate');

		if(xmlhttp.readyState == 4){

			

			ajaxDisplay.innerHTML = xmlhttp.responseText;

		}

		else

		{

			ajaxDisplay.innerHTML = "<img src='../images/load4.gif'/>";

		}

	}

	

	xmlhttp.open("GET", www+"/ajax/substate.php?cid=" + id, true);

	xmlhttp.send(null); 

}

function selectSubstate(id)

{

	

	xmlhttp=xmlObject();

	xmlhttp.onreadystatechange = function(){

		var ajaxDisplay = document.getElementById('subcity');

		if(xmlhttp.readyState == 4){

			ajaxDisplay.innerHTML = xmlhttp.responseText;

		}

		else

		{

			ajaxDisplay.innerHTML = "<img src='../images/load4.gif'/>";

		}

	}

	xmlhttp.open("GET",www+"/ajax/subcity.php?cid=" + id, true);

	xmlhttp.send(null); 

}

function selectLocality(id)

{

	xmlhttp=xmlObject();

	xmlhttp.onreadystatechange = function(){

			var ajaxDisplay = document.getElementById('sublocality');

		if(xmlhttp.readyState == 4){

		

			ajaxDisplay.innerHTML = xmlhttp.responseText;

		}

		else

		{

			ajaxDisplay.innerHTML = "<img src='../images/load4.gif'/>";

		}

	}

	xmlhttp.open("GET", www+"/ajax/sublocality.php?cid=" + id, true);

	xmlhttp.send(null); 

}

function getcityid(id)

{

		

	xmlhttp=xmlObject();

	xmlhttp.onreadystatechange = function(){

		

			var ajaxDisplay = document.getElementById('citycodedis');

		if(xmlhttp.readyState == 4){

			ajaxDisplay.innerHTML = xmlhttp.responseText;

		}

		else

		{

			ajaxDisplay.innerHTML = "<img src='../images/load4.gif'/>";

		}

	}

	xmlhttp.open("GET", www+"/ajax/getcityid.php?cid=" + id, true);

	xmlhttp.send(null); 

}



function loadEvent(str)

{

		bttype=document.form1.hiddajax.value;

		cid=document.form1.cid.value;

		var p=0;

		var arr=Array();

		for (var i=0;i<document.form1.elements.length;i++)

  		{

    		var e =document. form1.elements[i];

			if ((e.type=='checkbox'))

			{

				if(e.checked==true)

				{

					arr[p]=document. form1.elements[i].value;

			  		 p++;

				}

			}

  		}

		if(p<1)

		{

				alert("Please select the checkboxes");

		}

		else

		{

				xmlhttp=xmlObject();

				xmlhttp.onreadystatechange = function(){

					if(xmlhttp.readyState == 4){

						var ajaxDisplay = document.getElementById('ajaxBox');

						ajaxDisplay.innerHTML = xmlhttp.responseText;

					}

				}

				xmlhttp.open("GET", www+"/ajax/loadBets.php?cid=" + cid+"&bttype="+bttype+"&bid="+arr, true);

				xmlhttp.send(null); 

		}

	return false;

}

function changebettype(val)

{

	document.form1.hiddajax.value=val;	

}

function checkUser(name)

{

	xmlhttp=xmlObject();

	

	xmlhttp.onreadystatechange = function()

	{

		if(xmlhttp.readyState == 4)

		{

				var len=0;	

				var len=xmlhttp.responseText;



				if(len==1)

				{

					document.getElementById('edit').value=len;

				}

				else

				if(len==1)

				{

					document.getElementById('edit').value=len;

				}

				else

				{

					document.getElementById('edit').value=len;

				}

		}

	}

	xmlhttp.open("GET", "ajax/checkusername.php?name="+name, true);

	xmlhttp.send(null);

	len=document.getElementById('edit').value;

	return len;

}

function uncheckAll(form1)

{

	

	for (var i=0;i<document.form1.elements.length;i++)

  		{

				

    		var e =document. form1.elements[i];

			if ((e.type=='checkbox'))

			{

			   e.checked = false;

			}

  		}

	return false;

}

function selectSubstateid(id)

{

	xmlhttp=xmlObject();

	xmlhttp.onreadystatechange = function(){

		var ajaxDisplay = document.getElementById('subcity');

		if(xmlhttp.readyState == 4){

			ajaxDisplay.innerHTML = xmlhttp.responseText;

		}

		else

		{

			ajaxDisplay.innerHTML = "<img src='../images/load4.gif'/>";

		}

	}

	xmlhttp.open("GET", www+"/ajax/subcityid.php?cid=" + id, true);

	xmlhttp.send(null); 

}

function selectSubcountryid(id)

{

	

	xmlhttp=xmlObject();

	

	xmlhttp.onreadystatechange = function(){

		

		var ajaxDisplay = document.getElementById('substate');

		if(xmlhttp.readyState == 4){

			ajaxDisplay.innerHTML = xmlhttp.responseText;

		}

		else

		{

			ajaxDisplay.innerHTML = "<img src='../images/load4.gif'/>";

		}

	}

	xmlhttp.open("GET",www+"/ajax/substateid.php?cid=" + id, true);

	xmlhttp.send(null); 

}

function ajaxSearch(str)

{

	xmlhttp=xmlObject();

	xmlhttp.onreadystatechange = function(){

		var ajaxDisplay = document.getElementById('srchlist');

		if(xmlhttp.readyState == 4){

			var len=xmlhttp.responseText.length;

			if(len!=0)

			{

				document.getElementById('srchlist').style.display="";

				ajaxDisplay.innerHTML = xmlhttp.responseText;

			}

			else

			{

				document.getElementById('srchlist').style.display="none";

				ajaxDisplay.innerHTML = "";

			}

		}

		else

		{

			//ajaxDisplay.innerHTML = "<img src='../images/load4.gif'/>";

		}

	}

	

	xmlhttp.open("GET", www+"/ajax/ajaxsearch.php?str=" + str, true);

	xmlhttp.send(null); 

	return false;

}

function checkemaildb(str)

{

	xmlhttp=xmlObject();

	var len=0;	

	xmlhttp.onreadystatechange = function()

	{

		if(xmlhttp.readyState == 4)

		{

				var len=xmlhttp.responseText;



				if(len==1)

				{

					document.getElementById('emailErr').innerHTML='acoount with email already exist';

					document.getElementById('emailVal').value=-1;

				}

				else

				{

					document.getElementById('emailVal').value=2;

					document.getElementById('emailErr').innerHTML='';

				}

				return false;

		}

	}

	xmlhttp.open("GET", www+"/ajax/checkuseremail.php?username=" + str, true);

	xmlhttp.send(null);

	return false;

}

function checkuserdb(username,email,radioval)

{

	xmlhttp=xmlObject();

	var len=0;	

	xmlhttp.onreadystatechange = function()

	{

		if(xmlhttp.readyState == 4)

		{

				

				var len=xmlhttp.responseText;



				if(len==2)

				{

					document.getElementById('emailErr').innerHTML='';

					document.getElementById('usernameErr').innerHTML='Username is already in database';

					document.getElementById('userVal').value=1;

				}

				else

				if(len==3)

				{					document.getElementById('usernameErr').innerHTML='';

					document.getElementById('emailErr').innerHTML='Email is already in database';

					document.getElementById('userVal').value=1;

				}

				else

				if(len==5)

				{

					document.getElementById('usernameErr').innerHTML='Username is already in database';

					document.getElementById('emailErr').innerHTML='Email is already in database';

					document.getElementById('userVal').value=1;	

				}

				else

				{

					document.getElementById('userVal').value=0;

					document.getElementById('emailErr').innerHTML='';

					document.getElementById('usernameErr').innerHTML='';

					document.getElementById('email').value='';

					document.getElementById('username').value='';

					alert(xmlhttp.responseText);

					document.getElementById('success').innerHTML='Password has been emailed to your email address.';

				}

				return false;

		}

		else

		{

			document.getElementById('usernameErr').innerHTML='loading..';

			document.getElementById('emailErr').innerHTML='loading..';

		}

	}

	xmlhttp.open("GET", www+"/ajax/checkusername.php?username=" + username+"&email="+email+"&memtype="+radioval, true);

	xmlhttp.send(null);

	return false;

}

function userlogin(username,pass)

{

	xmlhttp=xmlObject();

	var len=0;	

	xmlhttp.onreadystatechange = function()

	{

		if(xmlhttp.readyState == 4)

		{

				var len=xmlhttp.responseText;

				if(len==0)

				{

					document.getElementById('passLoginErr').innerHTML='';

					document.getElementById('usernameLoginErr').innerHTML='';

					document.getElementById('invalidAcces').innerHTML='Invalied Access';

				}

				else

				if(len==1)

				{	

					document.getElementById('passLoginErr').innerHTML='';

					document.getElementById('usernameLoginErr').innerHTML='';

					document.getElementById('invalidAcces').innerHTML='Your Account is not verified yet';

				}

				else

				if(len==5)

				{

					alert(5);

					window.location=www+'/userhome.php?msg=loggedin';

				}

				/*else

				if(len==2)

				{	

					document.getElementById('passLoginErr').innerHTML='';

					document.getElementById('usernameLoginErr').innerHTML='';

					document.getElementById('invalidAcces').innerHTML='Your Account is suspended by admin, please contact admin for detail';

				}

				*/

		

				return false;

		}

		else

		{

			document.getElementById('usernameLoginErr').innerHTML='loading..';

			document.getElementById('passLoginErr').innerHTML='loading..';

		}

	}

	xmlhttp.open("GET", www+"/ajax/loginuser.php?username=" + username+"&pass="+pass, true);

	xmlhttp.send(null);

	return false;

}

function ajaxLogin(frm)

{

	

	if(frm.username.value=="")

	{

		document.getElementById('usernameLoginErr').innerHTML='Please enter username';

	}

	else

	if(frm.pass.value=="")

	{

		document.getElementById('usernameLoginErr').innerHTML='';

		document.getElementById('passLoginErr').innerHTML='Please enter password';

	}

	else

	{

		document.getElementById('usernameLoginErr').innerHTML='';

		/*if((document.getElementById('radiobutton1').checked)==true)

		{

			radioval=1;

		}

		else

		{

			radioval=2

		}*/

		//radioval=frm.radiobutton.value;

		pass=frm.pass.value;

		username=frm.username.value;

		userlogin(username,pass);

	}

	return false;

}



function ajaxSignUp(frm)

{

	

	if(frm.username.value=="")

	{

		document.getElementById('usernameErr').innerHTML='Please enter username';

	}

	else

	if(frm.email.value=="")

	{

		document.getElementById('usernameErr').innerHTML='';

		document.getElementById('emailErr').innerHTML='Please enter email address';

	}

	else

	{

		document.getElementById('emailErr').innerHTML='';

		if((document.getElementById('radiobutton1').checked)==true)

		{

			radioval=1;

		}

		else

		{

			radioval=2

		}

		//radioval=frm.radiobutton.value;

		email=frm.email.value;

		username=frm.username.value;

		checkuserdb(username,email,radioval);

	}

	return false;

}

function ajaxSearchState(id,target)

{	
var host = window.location.host;
var proto = window.location.protocol;
var pathArray = window.location.pathname.split( '/' );

var secondLevelLocation = pathArray[1];
var ajax_url = proto+"//"+host+"/";

	xmlhttp=xmlObject();

	var len=0;

	if(id=="")

	{

		alert('Please select Country');

		return false;

	}

	xmlhttp.onreadystatechange = function()

	{

		if(xmlhttp.readyState == 4)

		{

				

				var len=xmlhttp.responseText;



				if(len)

				{

					document.getElementById(target).innerHTML=len;	

					return false;		

				}

				

		}

		else

		{

			document.getElementById(target).innerHTML="Loading...";

		}

	}

	xmlhttp.open("GET", ajax_url+"ajax/get_statelist.php?id="+id, true);

	xmlhttp.send(null);

	return false;

}

function ajaxSearchState2(id,target)

{

	
var host = window.location.host;
var proto = window.location.protocol;
var pathArray = window.location.pathname.split( '/' );

var secondLevelLocation = pathArray[1];
var ajax_url = proto+"//"+host+"/";
	xmlhttp=xmlObject();

	var len=0;

	if(id=="")

	{

		alert('Please select Country');

		return false;

	}



	xmlhttp.onreadystatechange = function()

	{

		if(xmlhttp.readyState == 4)

		{

				var len=xmlhttp.responseText;

				if(len)

				{

					document.getElementById(target).innerHTML=len;	

					return false;		

				}

				

		}

		else

		{

				//alert('fgfg');

					document.getElementById(target).innerHTML="Loading...";

		}

	}

	xmlhttp.open("GET", ajax_url+"ajax/get_statelist2.php?id="+id, true);

	xmlhttp.send(null);

	return false;

}

function ajaxSearchState1(id,target)

{
var host = window.location.host;
var proto = window.location.protocol;
var pathArray = window.location.pathname.split( '/' );

var secondLevelLocation = pathArray[1];
var ajax_url = proto+"//"+host+"/";
	xmlhttp=xmlObject();

	var len=0;

	if(id=="")

	{

		alert('Please select Country');

		return false;

	}

	xmlhttp.onreadystatechange = function()

	{

		if(xmlhttp.readyState == 4)

		{

				var len=xmlhttp.responseText;

				if(len)

				{

					document.getElementById(target).innerHTML=len;	

					return false;		

				}

				

		}

		else

		{

				//alert('fgfg');

					document.getElementById(target).innerHTML="Loading...";

		}

	}

	xmlhttp.open("GET", ajax_url+"ajax/get_statelist1.php?id="+id, true);

	xmlhttp.send(null);

	return false;

}

function ajaxSearchCity(id,target)

{
var host = window.location.host;
var proto = window.location.protocol;
var pathArray = window.location.pathname.split( '/' );

var secondLevelLocation = pathArray[1];
var ajax_url = proto+"//"+host+"/";
	xmlhttp=xmlObject();

	var len=0;

	if(id=="")

	{

		alert('Please select State');

		return false;

	}

	xmlhttp.onreadystatechange = function()

	{

		if(xmlhttp.readyState == 4)

		{

				var len=xmlhttp.responseText;



				if(len)

				{

					document.getElementById(target).innerHTML=len;	

					return false;		

				}

		}

		else

		{

				//alert('fgfg');

					document.getElementById(target).innerHTML="Loading...";

		}

	}

	xmlhttp.open("GET", ajax_url+"ajax/get_city.php?id="+id, true);

	xmlhttp.send(null);

	return false;

}

function ajaxSearchCity1(id,target)

{
var host = window.location.host;
var proto = window.location.protocol;
var pathArray = window.location.pathname.split( '/' );

var secondLevelLocation = pathArray[1];
var ajax_url = proto+"//"+host+"/";
	xmlhttp=xmlObject();

	var len=0;

	if(id=="")

	{

		alert('Please select State');

		return false;

	}

	xmlhttp.onreadystatechange = function()

	{

		if(xmlhttp.readyState == 4)

		{

				var len=xmlhttp.responseText;



				if(len)

				{

					document.getElementById(target).innerHTML=len;	

					return false;		

				}

		}

		else

		{

				//alert('fgfg');

					document.getElementById(target).innerHTML="Loading...";

		}

	}

	xmlhttp.open("GET",ajax_url+"ajax/get_city.php?id="+id, true);

	xmlhttp.send(null);

	return false;

}

function localitySearch(str)

{
var host = window.location.host;
var proto = window.location.protocol;
var pathArray = window.location.pathname.split( '/' );

var secondLevelLocation = pathArray[1];
var ajax_url = proto+"//"+host+"/";
	xmlhttp=xmlObject();

	var len=0;	

	target='displayloc';

	if(str!="")

	{

		xmlhttp.onreadystatechange = function()

		{

			if(xmlhttp.readyState == 4)

			{

					var len=xmlhttp.responseText;

					if(len==0)

					{

						document.getElementById(target).style.display="none";

						document.getElementById(target).innerHTML='';

					}

					else

					if(len!="")

					{

						document.getElementById(target).style.display="";

						document.getElementById(target).innerHTML=xmlhttp.responseText;

					}

					return false;

			}

			else

			{

						document.getElementById(target).style.display="";

						document.getElementById(target).innerHTML="Loading...";

			}

		}

		xmlhttp.open("GET", ajax_url+"/ajax/localitysearch.php?str="+str, true);

		xmlhttp.send(null);

		return false;

	}

	else

	{

		document.getElementById(target).style.display="none";

		document.getElementById(target).innerHTML="";

		return false;

	}

}

function displayval(str)

{

		document.getElementById("keywords").value=str;

		document.getElementById("displayloc").style.display='none';

		return false;

}
