function set_ajax_obj() {
	
	var xmlhttp;	
	if (window.XMLHttpRequest)
	  {
	  // code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else if (window.ActiveXObject)
	  {
	  // code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	else
	  {
	  alert("Your browser does not support XMLHTTP!");
	  }
	
	return xmlhttp;
} // end funcion set_ajax_obj();


function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		  // alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		 //  alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		  //  alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		  //  alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		 //   alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		  //  alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		 //   alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}
function isEmpty(s){ 
	return ((s == null) || (s.length == 0))
	}

function isEmail (s){
		
		if(!echeck(s)){
			return false;
		}
		
	if (isEmpty(s))
	// is s whitespace?
	if (isWhitespace(s)) return false;
	// there must be >= 1 character before @, so we
	// start looking at character position 1
	// (i.e. second character)
	var i = 1;
	var sLength = s.length;
	// look for @
	while ((i < sLength) && (s.charAt(i) != "@")){
	i++
	}
    
	if ((i >= sLength) || (s.charAt(i) != "@")) 
	return false;
	else i += 2;
 
	// look for .
	while ((i < sLength) && (s.charAt(i) != ".")){
	i++
	}
	
	// there must be at least one character after the .
	if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
	else return true;
	}

function check_regForm()
{
		err=0;
		err_msg = '';
		if (document.getElementById('name').value == '')
		{
			err_msg += 'Please enter your name. \n';
			err++; 		
		}
		if (!isEmail(document.getElementById('email').value))
		{
			err_msg += 'Please enter valid email id. \n';
			err++; 		
		}
		if (document.getElementById('password').value == '')
		{
			err_msg += 'Please enter password. \n';
			err++; 		
		}
		if (document.getElementById('city').value == "")
		{
			err_msg += 'Please select city name. \n';
			err++; 		
		}
		if (document.getElementById('confirm').checked == false)
		{
			err_msg += 'Please confirm you are 18 yrs. old. \n';
			err++; 		
		}
		if (document.getElementById('terms').checked == false)
		{
			err_msg += 'Please read terms and conditions. \n';
			err++; 		
		}
		if(document.getElementById("ono_err_div1").style.display!='none')
		{
			err_msg += 'Email Id Already Exist. Please Change Email Id. \n';
			err++; 		
		}
		if (err == 0)
		{
			document.reg_form.submit();	
			return true;
		}
		else
		{
			alert (err_msg);
			return false;
		}
}


function check_updateForm(){
	err=0;
	err_msg = '';
	if (document.getElementById('name').value == '')
	{
		err_msg += 'Please enter your name. \n';
		err++; 		
	}
	
	if (document.getElementById('city').value == "")
	{
		err_msg += 'Please select city name. \n';
		err++; 		
	}
	if (err == 0)
	{
		document.reg_form.submit();	
		return true;
	}
	else
	{
		alert (err_msg);
		return false;
	}
}


var q_no="";
var txt_box="";
function dup_Chk(txtbox,qno)
{
	txt_box=txtbox;
	q_no=qno;
	if(document.getElementById(txt_box).value!="")
	{
		var txt_name=document.getElementById(txt_box).value;
		var ajaxConn = new XHConn();
		ajaxConn.connect("dup_chk.php", "POST", "txt_name="+txt_name+"&qno="+qno,fnWhenDone_dup_Chk);
	}
}

function fnWhenDone_dup_Chk(XML)
{
		if(XML.responseText != "")
		{
			//document.getElementById("txtname").focus();
			if(q_no==1)
			{
				document.getElementById("ono_err_div").style.display='block';
			}
			else if(q_no==2)
			{
				document.getElementById("ono_err_div1").style.display='block';
			}
			else if(q_no==3)
			{
				document.getElementById("ono_err_div2").style.display='block';
			}
			else if(q_no==4)
			{
				document.getElementById("ono_err_div3").style.display='block';
			}
			document.getElementById(txt_box).style.borderColor="red";
		}
		else
		{
			if(q_no==1)
			{
				document.getElementById("ono_err_div").style.display='none';
			}
			else if(q_no==2)
			{
				document.getElementById("ono_err_div1").style.display='none';
			}
			else if(q_no==3)
			{
				document.getElementById("ono_err_div2").style.display='none';
			}
			else if(q_no==4)
			{
				document.getElementById("ono_err_div3").style.display='none';
			}
			document.getElementById(txt_box).style.borderColor="#7f9db9";
		}
}





function postAdsubmit() {
	
	err=0;
	err_msg = '';
	if (document.getElementById('txtClassifiedTitle').value == '')
	{
		err_msg += 'Please Enter Ad Title. \n';
		err++; 		
	}
	/*if (document.getElementById('txtareaClassifiedDescription').innerHTML == '')
	{
		err_msg += 'Please Enter Ad Description. \n';
		err++; 		
	}*/
	if (document.getElementById('ClassifiedCityName').value == 0)
	{
		err_msg += 'Please Select City Name. \n';
		err++; 		
	}
	
	if (document.getElementById('ClassifiedType').value == 0)
	{
		err_msg += 'Please Select Classified Type. \n';
		err++; 		
	}
	//if (document.getElementById('ClassifiedCategory2').value == 0)
	//{
	//	err_msg += 'Please Select Classified Category. \n';
	//	err++; 		
	//}
	//if(document.getElementById("ClassifiedMobile").value == '')
	//{
		//err_msg += 'Pleaes Enter Mobile Number \n';
		//err++; 		
	//}

	if (err == 0) {
		//document.saveClassified.submit();	
		return true;
	}
	else {
		alert (err_msg);
		return false;
	}

}




function my_ad_detail(action) {
	
	//alert(action);
	var url = "";
	
	if(action == 'my_replies') {
		url = "my_reply.php";
	}
	
	if(action == 'my_classified_replies') {
		url = "my_classified_reply.php";
	}
	
	if(action == 'my_active_ads') {
		url = "my_active_ads.php";
	}
	
	if(action == 'my_expired_ads') {
		url = "my_expired_ads.php";
	}
	
	if(action == 'my_deleted_ads') {
		url = "my_deleted_ads.php";
	}
	
	
	
	xmlhttp = set_ajax_obj();
			
	xmlhttp.open("GET", url,true);
	xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) 
				{
				//alert(xmlhttp.responseText);
			
				document.getElementById('myAdDetails').innerHTML= xmlhttp.responseText;
				}
	}
	xmlhttp.send(null);

}


function changesubcategory(id) {
	
	xmlhttp = set_ajax_obj();
	if(id == null || id == '') {
		var catid = document.getElementById('classifiedCategorySelectBox').value;
	} else {
		var catid = id;
	}	
	
	var url = "includes/get_sub_categories.php?catid="+catid;
		
	xmlhttp.open("GET", url,true);
	xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) 
				{
				//alert(xmlhttp.responseText);
			
				document.getElementById('classifiedSubCategorySelectBox').innerHTML= xmlhttp.responseText;
				}
	}
	xmlhttp.send(null);

	
	
}

function delete_ad(delId, action) {
	
	//alert(delId);
	//alert(action);
	var answer = confirm ("Are you sure!");

	if (answer) {
		if(action == 'my_replies') {
			var url = "my_reply.php?delid="+delId;
		}
		
		if(action == 'my_classified_replies') {
			var url = "my_classified_reply.php?delid="+delId;
		}
		
		if(action == 'my_active_ads') {
			var url = "my_active_ads.php?delid="+delId;
		}
		
		
		
		xmlhttp = set_ajax_obj();
			
		xmlhttp.open("GET", url,true);
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) 
				{
				//alert(xmlhttp.responseText);
			
				document.getElementById('myAdDetails').innerHTML= xmlhttp.responseText;
				}
		}
		xmlhttp.send(null);

	}	

}

/// paging according  category and subcategory

/// paging functions start here

function pagingofferingads(catid,subcatid,type,pageno){
	var catid = catid ;
	var subcatid= subcatid;
	var type= type;
	
	//alert(catid);
	//alert(subcatid);
	//alert(type);
	//alert(pageno);
	
	
	xmlhttp=new XMLHttpRequest();
	var url = "calssifiedpaging.php?catid="+catid+"&subcat="+subcatid+"&type="+type+"&page_no="+pageno;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200);
	    {
		  //alert(xmlhttp.responseText);
	    document.getElementById("offeringads").innerHTML=xmlhttp.responseText;
	    }
	  }
	
	 }

function pagingwantedads(catid,subcatid,type,pageno){
		var catid = catid ;
		var subcatid= subcatid;
		xmlhttp=new XMLHttpRequest();
		var url = "calssifiedpaging.php?catid="+catid+"&subcat="+subcatid+"&type="+type+"&page_no="+pageno;
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
		
		xmlhttp.onreadystatechange=function()
		  {
		  if (xmlhttp.readyState==4 && xmlhttp.status==200);
		    {
		    document.getElementById("wantedads").innerHTML=xmlhttp.responseText;
		    }
		  }
		
		 }

function pagingallads(catid,subcatid,type,pageno){
		var catid = catid ;
		var subcatid= subcatid;
		
		
		xmlhttp=new XMLHttpRequest();
		var url = "calssifiedpaging.php?catid="+catid+"&subcat="+subcatid+"&type="+type+"&page_no="+pageno;
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
		
		xmlhttp.onreadystatechange=function()
		  {
		  if (xmlhttp.readyState==4 && xmlhttp.status==200);
		    {
		    document.getElementById("allads").innerHTML=xmlhttp.responseText;
		    }
		  }
		
		 }



// code for my ads paging here

function pagingMyads(userid,pageno){
	
	//alert(userid);
	//alert(pageno);
	
	
	xmlhttp=new XMLHttpRequest();
	var url = "my_ads_ajax.php?user_id="+userid+"&page_no="+pageno;
	//alert(url);
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
	
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200);
	    {
	    document.getElementById("myadsh").innerHTML=xmlhttp.responseText;
	    }
	  }
	
	 }
////// code for my active ads pageing

function pagingMyactiveads(userid,pageno){
	
	//alert(userid);
	//alert(pageno);
	
	
	xmlhttp=new XMLHttpRequest();
	var url = "my_active_ads_ajx.php?user_id="+userid+"&page_no="+pageno;
	//alert(url);
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
	
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200);
	    {
	    document.getElementById("activeads").innerHTML=xmlhttp.responseText;
	    }
	  }
	
	 }
// code for my expired ads paging


function pagingMyExpiredads(userid,pageno){
	
	//alert(userid);
	//alert(pageno);
	
	
	xmlhttp=new XMLHttpRequest();
	var url = "my_expired_ads_ajax.php?user_id="+userid+"&page_no="+pageno;
	//alert(url);
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
	
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200);
	    {
	    document.getElementById("expired").innerHTML=xmlhttp.responseText;
	    }
	  }
	
	 }

//code for offered ads from home menu paging

function pagingheaderOffred(type,pageno){
	
	//alert(type);
	//alert(pageno);
	
	
	xmlhttp=new XMLHttpRequest();
	var url = "offred_ajax.php?page_no="+pageno;
	//alert(url);
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
	
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200);
	    {
	    document.getElementById("offeredact").innerHTML=xmlhttp.responseText;
	    }
	  }
	
	 }
//code for wanted ads from home menu paging

function pagingheaderWanted(type,pageno){
	
	//alert(type);
	//alert(pageno);
	
	
	xmlhttp=new XMLHttpRequest();
	var url = "wanted_ajax.php?page_no="+pageno;
	//alert(url);
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
	
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200);
	    {
	    document.getElementById("wantact").innerHTML=xmlhttp.responseText;
	    }
	  }
	
	 }

//code for Business ads from home menu paging

function pagingheaderBusiness(type,pageno){
	
	//alert(type);
	//alert(pageno);
	
	
	xmlhttp=new XMLHttpRequest();
	
	//var url = "my_expired_ads_ajax.php?catid="+catid+"&page_no="+pageno;
	var url = "business_ajx.php?page_no="+pageno;
	//alert(url);
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
	
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200);
	    {
	    document.getElementById("busineesact").innerHTML=xmlhttp.responseText;
	    }
	  }
	
	 }
/// code for my deleted ads paging

function pagingMydeletedads(userid,pageno){
	
	//alert(userid);
	//alert(pageno);
	
	
	xmlhttp=new XMLHttpRequest();
	var url = "my_deleted_ads_ajax .php?user_id="+userid+"&page_no="+pageno;
	//alert(url);
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
	
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200);
	    {
	    document.getElementById("deletedads").innerHTML=xmlhttp.responseText;
	    }
	  }
	
	 }
///code for filter search values paging

function pagingFilterSearchAll(type,pageno){
	
	//alert(type);
	//alert(pageno);
	
	
	xmlhttp=new XMLHttpRequest();
	var url = "filter_serch_ajax.php?type="+type+"&page_no="+pageno;
	alert(url);
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
	
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200);
	    {
	    document.getElementById("allads").innerHTML=xmlhttp.responseText;
	    }
	  }
	
	 }



	
//code for paging Filter Search offered

function pagingFilterSearchOffered(pageno,cantaint,city,type){
	
	//alert(type);
	//alert(pageno);
	//alert(cantaint);
	//alert(city);
	
	xmlhttp=new XMLHttpRequest();
	var url = "filter_serch_ajax.php?page_no="+pageno+"&city="+city+"&cantaint="+cantaint+"&type="+type;
	//var url = "filter_serch_ajax.php?type="+type+"&page_no="+pageno;
	//alert(url);
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
	
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200);
	    {
	    document.getElementById("Offering").innerHTML=xmlhttp.responseText;
	    }
	  }
	
	 }


//code for paging Filter Search Want
//

//pagingFilterSearchWant
function pagingFilterSearchWant_filter(pageno,cantaint,city,type){
	
	//alert(type);
//	alert(pageno);
	//alert(cantaint);
	//alert(city);
	
	xmlhttp=new XMLHttpRequest();
	var url = "filter_serch_ajax.php?page_no="+pageno+"&city="+city+"&cantaint="+cantaint+"&type="+type;
	//var url = "filter_serch_ajax.php?type="+type+"&page_no="+pageno;
	//alert(url);
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
	
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200);
	    {
	    document.getElementById("Wanted").innerHTML=xmlhttp.responseText;
	    }
	  }
}

// code for all classifieds from filter swearch

function pagingFilterSearchAll_filter(pageno,cantaint,city,type){
	
	//alert(type);
//	alert(pageno);
	//alert(cantaint);
	//alert(city);
	
	xmlhttp=new XMLHttpRequest();
	var url = "filter_serch_ajax.php?page_no="+pageno+"&city="+city+"&cantaint="+cantaint+"&type="+type;
	//var url = "filter_serch_ajax.php?type="+type+"&page_no="+pageno;
	//alert(url);
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
	
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200);
	    {
	    document.getElementById("Allads_filter").innerHTML=xmlhttp.responseText;
	    }
	  }
}
/// find subcategory according Categories

function findsubcat(id){
	var catid = id ;
	//alert(catid);
	xmlhttp=new XMLHttpRequest();
	xmlhttp.open("GET","subcategory.php?q="+catid,true);
	xmlhttp.send(null);
	
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200);
	    {
		  //alert(xmlhttp.responseText);
	    document.getElementById("subcat").innerHTML=xmlhttp.responseText;
	    }
	  }
	
	 }

/// find locality according City
////

function findsubcatSearch(id){
	var catid = id ;
	//alert(catid);
	xmlhttp=new XMLHttpRequest();
	xmlhttp.open("GET","subcategory_search.php?q="+catid,true);
	xmlhttp.send(null);
	
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200);
	    {
		  //alert(xmlhttp.responseText);
	    document.getElementById("subcat").innerHTML=xmlhttp.responseText;
	    }
	  }
	
	 }

////////////////////

function emailcheck(email){
	var email = email ;
	//alert(email);
	xmlhttp=new XMLHttpRequest();
	var url = "email_exist.php?q="+email;
	//alert(url);
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
	
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200);
	    {
		 // alert(xmlhttp.responseText);
	    document.getElementById("email_exit").innerHTML=xmlhttp.responseText;
	    }
	  }
	
	 }


function findlocality(id){
	var caity_id = id ;
	//alert(caity_id);
	xmlhttp=new XMLHttpRequest();
	xmlhttp.open("GET","locality_cities.php?q="+caity_id,true);
	xmlhttp.send(null);
	
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200);
	    {
		  //alert(xmlhttp.responseText);
	    document.getElementById("locality").innerHTML=xmlhttp.responseText;
	    }
	  }
	
	 }
function chkSearchValidate()
{
	//alert('hye');
	var searchField=document.getElementById('cantaint').value;
	var searchCriteria=document.getElementById('ClassifiedCategory_header').value;
	if(searchField=='')
	{
			alert('Please enter value for search');
			document.getElementById('cantaint').focus();
			return false;
	}
	else if(searchCriteria==0)
	{
			alert('Please select search criteria');
			document.getElementById('ClassifiedCategory_header').focus();
			return false;
	}
	else
	return true;
	
}

