//common ajax
function getAjaxRes(url,params,ResRetFun){
	var http = new GetXmlHttpObject();
	http.open("POST", url, true);
	//Send the proper header information along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");

	http.onreadystatechange = function() {
		if(http.readyState == 4 && http.status == 200)			
			ResRetFun(http.responseText);
	}
	http.send(params);
}
function GetXmlHttpObject(){
	var xmlHttp=null;
	try{ xmlHttp=new XMLHttpRequest();}
	catch (e){// Internet Explorer
		try{ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
		catch (e){ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
	}
	return xmlHttp;	
}
function ResetValues()
{
	
}

function toggle(show,hide)
{
	if(!hide)
		{
			var el=document.getElementById(show);
			if (el.style.display != "none")	
				{el.style.display = 'none';} 
			else 
				{el.style.display = "";} 
		}	
	else
		{		
			document.getElementById(hide).style.display="none";
			document.getElementById(show).style.display="block";
		}
}

function checkavail(str,urlstr)
{
	var host = top.location.host;	
	var url="http://"+host+"/indian-classified/check_avail_user.php";
	var param="name="+str;	
	var success = function(u)
	{
		if(u == 1)
		{		
			alert("User already exists!!!");
		}
		else if(u == 2)
		{
			alert("Please enter valid url");
		}
		else
		{	
			document.getElementById("linkstr").href=urlstr+str;
			document.getElementById("linkstr").innerHTML=urlstr+str;
			toggle('prodis','proeddis');
			toggle('prodis1','proeddis1');
		}
	}
	getAjaxRes(url,param,success);
}


function emailalert(username,email,mobile,cat,subcat,city,qry)
{

	var host = top.location.host;	
	var url="http://"+host+"/indian-classified/emailalert.php";
	var param='username='+username+'&email='+email+'&mobile='+ mobile+'&cat='+cat+'&subcat='+subcat+'&city='+city+'&qry='+qry;

	var salert = function(u)
	{	
		if(u == 0)
		{
			toggle('two','one');
		}	
		else if(u == 2)
		{
			alert("Please enter a valid Email Id");
		}
		else if(u == 3)
		{
			alert("Please enter a valid Mobile Number");
		}
		else
		{
			alert("Please enter a valid Name");
		}
	}
	getAjaxRes(url,param,salert);
}

function lfacet(lqry,page,fcat,fsubcat,loc)
{
	var host = top.location.host;	
	var furl="http://"+host+"/indian-classified/lfacet.php";	
	var fpara='loc='+loc+'&qry='+lqry+'&page='+page+'&cat='+fcat+'&subcat='+fsubcat+'&host='+host;
	var lfacet = function(u)
	{	
		parent.tb_remove();
		parent.document.getElementById("facet").innerHTML=u;
		parent.document.getElementById("refine").style.display="none";
	}
	getAjaxRes(furl,fpara,lfacet);
}