// JavaScript Document
var xmlHttp;
function fnGoBack(pageName)
{
		location.replace("http://"+pageName);
}
function fnCheckName()
{
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
	 	alert ("Browser does not support HTTP Request");
	 return
	}
	var name=document.getElementById("txtUser1").value;
	if(name=="") 
	{
		document.getElementById("userName").style.color="red";
		document.getElementById("userName").innerHTML="Please Provide your name";
		document.getElementById("txtUser1").focus();
		return false; 
	}
	else if(name.length < 6)
	{
		document.getElementById("userName").style.color="red";
		document.getElementById("userName").innerHTML="Atleast 6 characters";
		document.getElementById("txtUser1").focus();
		return false;
	}
	var url="callAjax.php?name1="+name;
	xmlHttp.onreadystatechange=stateChanged ;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);

	
}
function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 	if(xmlHttp.responseText=="0") {
		document.getElementById("userName").style.color="blue";
 document.getElementById("userName").innerHTML="Continue";
 document.getElementById("btnOk").disabled=false;
	}
	else {
		document.getElementById("userName").style.color="red";
	 document.getElementById("userName").innerHTML="Choose Another";
	 document.getElementById("txtUser").focus();
	}
 } 
}
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;
}
function fnValidateRegister()
{
	var name=document.getElementById("txtUser1").value;
	var pwd=document.getElementById("txtPwd1").value;
	var repwd=document.getElementById("txtRePwd").value;
	var mail=document.getElementById("txtEmail").value;
	var remail=document.getElementById("txtReEmail").value;
	if(name=="")
	{
		alert("Please enter your name");
		document.getElementById("txtUser1").focus();
		return false;
		
	}
	else if(name.length < 6)
	{
		alert("Username should be atleast 6 characters");
		document.getElementById("txtUser1").focus();
		return false;
	}
	if(pwd=="")
	{
		alert("What should be your Password");
		document.getElementById("txtPwd1").focus();
		return false;
		
	}
	else if(pwd.length < 6)
	{
		alert("Password should be atleast 6 characters");
		document.getElementById("txtPwd1").focus();
		return false;
	}
	if(repwd=="")
	{
		alert("Enter your Password Again");
		document.getElementById("txtRePwd").focus();
		return false;
		
	}
	if(pwd!=repwd)
	{
		alert("Both Passwords Should Match");
		document.getElementById("txtRePwd").focus();
		return false;
	}
	if(mail=="")
	{
		alert("Provide Your Valid Email");
		document.getElementById("txtEmail").focus();
		return false;
		
	}
	else 
	{
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (!filter.test(mail)) 
		{
		alert("Invalid Email");
		document.getElementById("txtEmail").focus();
		return false;
		}
	}
	if(remail=="")
	{
		alert("Retype your Email Please");
		document.getElementById("txtReEmail").focus();
		return false;
		
	}
	if(mail!=remail)
	{
		alert("Both Emails Should Match");
		document.getElementById("txtReEmail").focus();
		return false;
			
	}
	
	
}
function fnValidateAd()
{
	var title=document.getElementById("txtTitle").value;
	var price1=document.getElementById("txtPrice1").value;
	var price2=document.getElementById("txtPrice2").value;
	if(title=="")
	{
			alert("Provide title of your Ad");
			document.getElementById("txtTitle").focus();
			return false;
	}
	if(!price1=="")
	{
			var s = price1;
			for (i = 0 ; i < s.length ; i++) {
				if ((s.charAt(i) < '0') || (s.charAt(i) > '9')) 
				{
					alert('Price From should be a number');
					document.getElementById("txtPrice1").focus();
					return false;
				}
			}
	}
	if(!price2=="")
	{
			var s = price2;
			for (i = 0 ; i < s.length ; i++) {
				if ((s.charAt(i) < '0') || (s.charAt(i) > '9')) 
				{
					alert('Price To should be a number');
					document.getElementById("txtPrice2").focus();
					return false;
				}
			}
	}
	var getSelected = document.getElementById("frmUserAd").ddStates.options[document.getElementById("frmUserAd").ddStates.options.selectedIndex].value;
	if(getSelected==0)
	{
			alert("Select State in which you want to place Ad");
			return false;
	}



}
function fnContact()
{
	var name=document.getElementById("txtUser1").value;
	var mail=document.getElementById("txtEmail").value;
	var code=document.getElementById("txtCheck").value;
	if(name=="")
	{
			document.getElementById("lblError").style.color="red";
			document.getElementById("lblError").innerHTML = "*";
			document.getElementById("txtUser1").focus();
			return false;
	}
	else
	
	{
		document.getElementById("lblError").innerHTML = "";
		
	}
	if(mail=="")
	{
			document.getElementById("lblError1").style.color="red";
			document.getElementById("lblError1").innerHTML = "*";
			document.getElementById("txtEmail").focus();
			return false;
		
	}
	else 
	{
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (!filter.test(mail)) 
		{
		alert("Invalid Email");
		document.getElementById("txtEmail").focus();
		return false;
		}
	}
	if(code=="")
	{
			document.getElementById("lblError10").style.color="red";
			document.getElementById("lblError10").innerHTML = "*";
			document.getElementById("txtCheck").focus();
			return false;
	}
}

function fnShowCities()
{
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
	 	alert ("Browser does not support HTTP Request");
	 return
	}
	
	var getSelected = document.getElementById("frmUserAd").ddStates.options[document.getElementById("frmUserAd").ddStates.options.selectedIndex].value;
	var url="callAjax.php?state="+getSelected;
	xmlHttp.onreadystatechange=stateChanged1 ;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);

	
}

function stateChanged1() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 	document.getElementById("showCity").innerHTML=xmlHttp.responseText;
 } 
}

function fnValidateAccount()
{
		var email = document.getElementById("txtEmail").value;
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (!filter.test(email)) 
		{
			alert("Invalid Email");
			document.getElementById("txtEmail").focus();
			return false;
		}
}

function fnShowNext(pageName)
{
	var page = pageName;
	document.getElementById("lblMsg").innerHTML= "Wait Loading...";
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
	 	alert ("Browser does not support HTTP Request");
	 return
	}
		
	var url="nextpage.php?nextpage="+page;
	xmlHttp.onreadystatechange=stateChangednext ;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function stateChangednext() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
//alert(xmlHttp.responseText);
document.getElementById("ShowNext").innerHTML=xmlHttp.responseText;
document.getElementById("lblMsg").innerHTML= "";
 } 
}

function fnShowSubCats()
{
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
	 	alert ("Browser does not support HTTP Request");
	 return
	}
	
	var getSelected = document.getElementById("frmUserAd").ddCategory.options[document.getElementById("frmUserAd").ddCategory.options.selectedIndex].value;
	var url="callAjax.php?catid="+getSelected;
	xmlHttp.onreadystatechange=stateChanged2 ;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);

	
}

function stateChanged2() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 	document.getElementById("showSubCat").innerHTML=xmlHttp.responseText;
 } 
}
function fnShowSubCatAds(id,pid,page,name)
{
		var sPath = window.location.pathname;
		document.getElementById("lblLoading").innerHTML= "Wait Loading...";
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
	 	alert ("Browser does not support HTTP Request");
	 return
	}
	var getSelected = document.getElementById("frmSubCat").ddSortSub.options[document.getElementById("frmSubCat").ddSortSub.options.selectedIndex].value;
	var url;
	if(name == "state") {
		url="../callAjax.php?subid="+getSelected+"&id="+id+"&pid="+pid+"&page="+page; }
	else {
		url="../callAjax.php?subid="+getSelected+"&id="+id+"&pid="+pid+"&page="+page+"&name="+name; }
	xmlHttp.onreadystatechange=stateChanged3 ;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);


	
}

function stateChanged3() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 	//alert(xmlHttp.responseText);
 	document.getElementById("showSortAds").innerHTML=xmlHttp.responseText;
	document.getElementById("lblLoading").innerHTML= "";
 } 
}










