var xmlHttp;
var HtmlTagId;

//------AJAX------AJAX------AJAX------AJAX------AJAX------AJAX------

function Get_Pro_Subcat(tagid,rftdid,controlid,width)
{ 
	
	HtmlTagId=tagid;
	if (document.getElementById("loadflag").value == "false")
	{	
		document.getElementById(HtmlTagId).innerHTML="<img src='images/loading.gif' hspace=0 vspace=0 border=0><br>" + document.getElementById(HtmlTagId).innerHTML;
		document.getElementById("loadflag").value = "true";
	}
	
	var url="get_pro_subcat.asp?sid="+ Math.random() +"&rftd_id="+ rftdid +"&controlid="+ controlid +"&width="+ width ;
	xmlHttp=GetXmlHttpObject(stateChanged);
	xmlHttp.open("GET", url , true);
	xmlHttp.send(null);
} 

function stateChanged() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		document.getElementById(HtmlTagId).innerHTML=xmlHttp.responseText;
	} 
} 
function GetXmlHttpObject(handler)
{ 
	var objXmlHttp=null;
	if (navigator.userAgent.indexOf("Opera")>=0)
	{
		alert("This page doesn't work in Opera") 
		return; 
	}
	if (navigator.userAgent.indexOf("MSIE")>=0)
	{ 
		var strName="Msxml2.XMLHTTP";
		if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
		{
			strName="Microsoft.XMLHTTP";
		}
		try
		{ 
			objXmlHttp=new ActiveXObject(strName);
			objXmlHttp.onreadystatechange=handler ;
			return objXmlHttp;
		} 
		catch(e)
		{ 
			alert("Error. Scripting for ActiveX might be disabled") 
			return;
		} 
	} 
	if (navigator.userAgent.indexOf("Mozilla")>=0)
	{
		objXmlHttp=new XMLHttpRequest();
		objXmlHttp.onload=handler;
		objXmlHttp.onerror=handler;
		return objXmlHttp;
	}
} 

//------AJAX------AJAX------AJAX------AJAX------AJAX------AJAX------

function GetStateVal(tagid,cid,controlid,width)
{ 
	
	
	HtmlTagId=tagid;
	//alert('hi');
	if (document.getElementById("loadflag").value == "false")
	{
		
		document.getElementById(HtmlTagId).innerHTML="<img src='images/loading.gif' hspace=0 vspace=0 border=0><br>" + document.getElementById(HtmlTagId).innerHTML;
		document.getElementById("loadflag").value = "true";
	}
	
	var url="get_state.asp?sid="+ Math.random() +"&countryid="+ cid +"&controlid="+ controlid +"&width="+ width ;
	xmlHttp=GetXmlHttpObject(stateChanged);
	xmlHttp.open("GET", url , true);
	xmlHttp.send(null);
} 
function GetStateVal_biz(tagid,cid,controlid,width)
{ 
	
	
	HtmlTagId=tagid;
	//alert('hi');
	if (document.getElementById("loadflag").value == "false")
	{
		
		document.getElementById(HtmlTagId).innerHTML="<img src='images/loading.gif' hspace=0 vspace=0 border=0><br>" + document.getElementById(HtmlTagId).innerHTML;
		document.getElementById("loadflag").value = "true";
	}
	
	var url="getstate_biz.asp?sid="+ Math.random() +"&countryid="+ cid +"&controlid="+ controlid +"&width="+ width ;
	xmlHttp=GetXmlHttpObject(stateChanged);
	xmlHttp.open("GET", url , true);
	xmlHttp.send(null);
} 
function GetStateVal_buyer(tagid,cid,controlid,width)
{ 
	
	
	HtmlTagId=tagid;
	//alert('hi');
	if (document.getElementById("loadflag").value == "false")
	{
		
		document.getElementById(HtmlTagId).innerHTML="<img src='images/loading.gif' hspace=0 vspace=0 border=0><br>" + document.getElementById(HtmlTagId).innerHTML;
		document.getElementById("loadflag").value = "true";
	}
	
	var url="getstate_buyer.asp?sid="+ Math.random() +"&countryid="+ cid +"&controlid="+ controlid +"&width="+ width ;
	xmlHttp=GetXmlHttpObject(stateChanged);
	xmlHttp.open("GET", url , true);
	xmlHttp.send(null);
} 

function stateChanged() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		document.getElementById(HtmlTagId).innerHTML=xmlHttp.responseText;
		document.getElementById("loadflag").value = "false";
	} 
} 
function GetXmlHttpObject(handler)
{ 
	var objXmlHttp=null;
	if (navigator.userAgent.indexOf("Opera")>=0)
	{
		alert("This page doesn't work in Opera") 
		return; 
	}
	if (navigator.userAgent.indexOf("MSIE")>=0)
	{ 
		var strName="Msxml2.XMLHTTP";
		if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
		{
			strName="Microsoft.XMLHTTP";
		}
		try
		{ 
			
			objXmlHttp=new ActiveXObject(strName);
			objXmlHttp.onreadystatechange=handler ;
			return objXmlHttp;
		} 
		catch(e)
		{ 
			alert("Error. Scripting for ActiveX might be disabled") 
			return;
		} 
	} 
	if (navigator.userAgent.indexOf("Mozilla")>=0)
	{
		objXmlHttp=new XMLHttpRequest();
		objXmlHttp.onload=handler;
		objXmlHttp.onerror=handler;
		return objXmlHttp;
	}
} 

//------AJAX------AJAX------AJAX------AJAX------AJAX------AJAX------

function GetSubcatVal(tagid,cid,controlid,width)
{ 
	HtmlTagId=tagid;
	
	
	if (document.getElementById("loadflag").value == "false")
	{
		document.getElementById(HtmlTagId).innerHTML="<img src='images/loading.gif' hspace=0 vspace=0 border=0><br>" + document.getElementById(HtmlTagId).innerHTML;
		document.getElementById("loadflag").value = "true";
	}
	var url="get_subcat.asp?sid="+ Math.random() +"&catid="+ cid +"&controlid="+ controlid +"&width="+ width ;
	xmlHttp=GetXmlHttpObject1(stateChanged1);
	xmlHttp.open("GET", url , true);
	xmlHttp.send(null);
} 
function GetSubcatVal_bizlist(tagid,cid,controlid,width)
{ 
	HtmlTagId=tagid;
	
	
	if (document.getElementById("loadflag").value == "false")
	{	
		document.getElementById(HtmlTagId).innerHTML="<img src='images/loading.gif' hspace=0 vspace=0 border=0><br>" + document.getElementById(HtmlTagId).innerHTML;
		document.getElementById("loadflag").value = "true";
	}
	var url="get_subcart_bizlist.asp?sid="+ Math.random() +"&catid="+ cid +"&controlid="+ controlid +"&width="+ width ;
	xmlHttp=GetXmlHttpObject1(stateChanged1);
	xmlHttp.open("GET", url , true);
	xmlHttp.send(null);
} 

function stateChanged1() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		document.getElementById(HtmlTagId).innerHTML=xmlHttp.responseText;
	} 
} 
function GetXmlHttpObject1(handler)
{ 
	var objXmlHttp=null;
	if (navigator.userAgent.indexOf("Opera")>=0)
	{
		alert("This page doesn't work in Opera") 
		return; 
	}
	if (navigator.userAgent.indexOf("MSIE")>=0)
	{ 
		var strName="Msxml2.XMLHTTP";
		if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
		{
			strName="Microsoft.XMLHTTP";
		}
		try
		{ 
			objXmlHttp=new ActiveXObject(strName);
			objXmlHttp.onreadystatechange=handler ;
			return objXmlHttp;
		} 
		catch(e)
		{ 
			alert("Error. Scripting for ActiveX might be disabled") 
			return;
		} 
	} 
	if (navigator.userAgent.indexOf("Mozilla")>=0)
	{
		objXmlHttp=new XMLHttpRequest();
		objXmlHttp.onload=handler;
		objXmlHttp.onerror=handler;
		return objXmlHttp;
	}
} 

//------AJAX------AJAX------AJAX------AJAX------AJAX------AJAX------

var obj;
var st;
var ct
function GetDataViaAJAX(country,state)
{
	try
	{
		obj = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			obj = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e1)
		{
			try
			{
				obj = new XMLHttpRequest();
			}
			catch(e2)
			{
				obj = null;
			}
		}
	}
	if(obj!=null)
	{
		st=state;
		ct=country;
		
		obj.onreadystatechange = ProcessResponse;
		obj.open("GET", "Country_data.aspx?countryid="+ document.getElementById(ct).value, true);
		obj.send(null);        
	}
	return false;
}

function ProcessResponse()
{
	if(obj.readyState == 4)
	{
		if(obj.status == 200)
		{
			var dsRoot=obj.responseXML.documentElement;
			var ddlState = document.getElementById(st);
			/*for (var count = ddlState.options.length-1;count >-1; count--)
			{
				ddlState.options[count] = null;
			}*/
			ddlState.options.length=0;
			
			var sname = dsRoot.getElementsByTagName('state_name');
			var sid = dsRoot.getElementsByTagName('state_id');
			var text;
			var tid;
			var listItem;
			
			ddlState.options.length ++;
			ddlState.options[0].value = 0;
			ddlState.options[0].text = "Select State";
			
			for (var count = 0; count < sname.length ; count++)
			{
				text = (sname[count].textContent || sname[count].innerText || sname[count].text);
				tid = (sid[count].textContent || sid[count].innerText || sid[count].text);
				//listItem = new Option(text, tid,  false, false);
				//ddlState.options[ddlState.length] = listItem;
				ddlState.options.length ++;
				ddlState.options[count + 1].value = tid;
				ddlState.options[count + 1].text = text;
			}
			ddlState.options.length ++;
			ddlState.options[count + 1].value = 0;
			ddlState.options[count + 1].text = "All state";
		}
		else
		{
			alert("Error retrieving data!" );
		}
	}
}

//------------------------------------------------------------------------------------------------------

function GetSubCategoyrViaAJAX(category,subcategory)
{
	try
	{
		obj = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			obj = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e1)
		{
			try
			{
				obj = new XMLHttpRequest();
			}
			catch(e2)
			{
			obj = null;
			}
		}
	}
	if(obj!=null)
	{
		st=subcategory;
		ct=category;
		
		obj.onreadystatechange = Subcat_ProcessResponse;
		obj.open("GET", "Category_data.aspx?&categoryid="+ document.getElementById(ct).value, true);
		obj.send(null);        
	}
	return false;
}

function Subcat_ProcessResponse()
{
	if(obj.readyState == 4)
	{
		if(obj.status == 200)
		{
			var dsRoot=obj.responseXML.documentElement;
			var ddlState = document.getElementById(st);
			
			/*for (var count = ddlState.options.length-1;count >-1; count--)
			{
				ddlState.options[count] = null;
			}*/
			
			ddlState.options.length=0;
			
			var sname = dsRoot.getElementsByTagName('subcategory_name');
			var sid = dsRoot.getElementsByTagName('subcategory_id');
			var text;
			var tid;
			var listItem;
			
			ddlState.options.length ++;
			ddlState.options[0].value = 0;
			ddlState.options[0].text = "Select Subcategory";
			
			for (var count = 0; count < sname.length ; count++)
			{
				text = (sname[count].textContent || sname[count].innerText || sname[count].text);
				tid = (sid[count].textContent || sid[count].innerText || sid[count].text);
				//listItem = new Option(text, tid,  false, false);
				//ddlState.options[ddlState.length] = listItem;
				ddlState.options.length ++;
				ddlState.options[count + 1].value = tid;
				ddlState.options[count + 1].text = text;
			}
		}
		else
		{
			alert("Error retrieving data!" );
		}
	}
}
//------AJAX------AJAX------AJAX------AJAX------AJAX------AJAX------
//------------------------------------------------------------------------------------------------------
//------AJAX------AJAX------AJAX------AJAX------AJAX------AJAX------

function check_AJAX_val()
{					
	var cid=document.getElementById("Listbpo_home_left1_Broker_search_com1_ddlBCountry").value;
	var sid=document.getElementById("Listbpo_home_left1_Broker_search_com1_ddState").value;
	var btype=document.getElementById("Listbpo_home_left1_Broker_search_com1_brokertype_id").value;
	
	location.href="Search_Broker.aspx?countryid="+ cid +"&stateid="+ sid +"&type="+ btype +"&flag=S";
	return false;
}	
			
//------------------------------------------------------------------------------------------------------
			
function page_redirect(val,ans,nurl)
{
	if (parseInt(val)==1)
	{
		var w=550;
		var h=550;
		var tval=(screen.height-h)/2;
		var lval=(screen.width-w)/2;
		var win=window.open(nurl,null,'toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,resizable=1,width='+ w +',height='+ h +',top='+ tval +',left='+ lval,'true');
		win.focus();
	}
	if (parseInt(val)==0)
	{
		document.location.href=ans;
	}
}

//-----------------------Buy_a_business_register.aspx/Adv_Search_SellBiz.ascx----------------------------------------------
function check_valid_buyer_searchby_regno()
{	
	if(emptyField(document.getElementById("Adv_Search_SellBiz1_txtRegNO")))
	{
		alert('Please insert business registration no.');
		document.getElementById("Adv_Search_SellBiz1_txtRegNO").focus();
		return false;
	}
}

function check_valid_buyer_search()
{
	var arg;
	var flag;
	if(document.getElementById("Adv_Search_SellBiz1_ddCountry").value==0)
	{
		alert('Please select country...');
		document.getElementById("Adv_Search_SellBiz1_ddCountry").focus();
		return false;
	}
	if(document.getElementById("Adv_Search_SellBiz1_ddCategory").value==0)
	{
		alert('Please select category...');
		document.getElementById("Adv_Search_SellBiz1_ddCategory").focus();
		return false;
	}
	document.Form1.Hcountry.value = document.getElementById("Adv_Search_SellBiz1_ddCountry").value;
	document.Form1.Hstate.value = document.getElementById("Adv_Search_SellBiz1_ddState").value;
	
	document.Form1.Hcategory.value = document.getElementById("Adv_Search_SellBiz1_ddCategory").value;
	document.Form1.Hsubcategory.value = document.getElementById("Adv_Search_SellBiz1_ddSubcategory").value;
	
	return true;
}

function check_valid_buyer_search_for_opportunity()
{
	var arg;
	var flag;
	if(document.getElementById("Adv_Search_BuyBiz1_ddCountry").value==0)
	{
		alert('Please select country...');
		document.getElementById("Adv_Search_BuyBiz1_ddCountry").focus();
		return false;
	}
	if(document.getElementById("Adv_Search_BuyBiz1_ddCategory").value==0)
	{
		alert('Please select category...');
		document.getElementById("Adv_Search_BuyBiz1_ddCategory").focus();
		return false;
	}
	document.Form1.Hcountry.value = document.getElementById("Adv_Search_BuyBiz1_ddCountry").value;
	document.Form1.Hstate.value = document.getElementById("Adv_Search_BuyBiz1_ddState").value;
	
	document.Form1.Hcategory.value = document.getElementById("Adv_Search_BuyBiz1_ddCategory").value;
	document.Form1.Hsubcategory.value = document.getElementById("Adv_Search_BuyBiz1_ddSubcategory").value;
	
	return true;
}
//------------------------------------------------------------------------------------

function quick_search_sellbiz()
{
	document.Form1.Hcategory.value = document.getElementById("Listbpo_home_left1_Sellbiz_search_com1_ddlbizcategory").value;
	document.Form1.Hstate.value = document.getElementById("Listbpo_home_left1_Sellbiz_search_com1_ddlBState").value;
}

//------------------------------------------------------------------------------------

function quick_search_comm_for_sale()
{
	var cat = document.getElementById("Listbpo_home_left1_Adv_Comm_Search1_ddPropertyType").value;
	var state = document.getElementById("Listbpo_home_left1_Adv_Comm_Search1_ddState").value;         
	location.href = "Comm_search_for_sale.aspx?id=4&reid=3&reforid=2&name=SearchComm&refortypedivid="+ cat +"&stateid="+ state +"&nativ=home";
	return false;
}
function set_width()
{
	
	//alert(document.getElementById("Listbpo_home_left1_Sellbiz_search_com1_ddlbizcategory").style.width);
	//document.getElementById("Listbpo_home_left1_Sellbiz_search_com1_ddlbizcategory").style.width=300;
	
}
//------------------------------------------------------------------------------------

function single_family_for_sale()
{
	var arg;
	var flag;
	if (emptyField(document.getElementById("listbpo_home_left1_txtFPrice")))
	{
		alert('Please insert price range.');
		document.getElementById("listbpo_home_left1_txtFPrice").focus();
		return false;
	}
	arg=document.getElementById("listbpo_home_left1_txtFPrice").value;
	flag=check_numeric(arg);
	if(flag==0)
	{
		alert('Only decimal value allowed..');
		document.getElementById("listbpo_home_left1_txtFPrice").focus();
		document.getElementById("listbpo_home_left1_txtFPrice").value="";
		return false;
	}
	if (emptyField(document.getElementById("listbpo_home_left1_txtLPrice")))
	{
		alert('Please insert price range.');
		document.getElementById("listbpo_home_left1_txtLPrice").focus();
		return false;
	}
	arg=document.getElementById("listbpo_home_left1_txtLPrice").value;
	flag=check_numeric(arg);
	if(flag==0)
	{
		alert('Only decimal value allowed..');
		document.getElementById("listbpo_home_left1_txtLPrice").focus();
		document.getElementById("listbpo_home_left1_txtLPrice").value="";
		return false;
	}
	if (!emptyField(document.getElementById("listbpo_home_left1_txtFPrice")))
	{
		if (!emptyField(document.getElementById("listbpo_home_left1_txtLPrice")))
		{
			if (parseFloat(document.getElementById("listbpo_home_left1_txtFPrice").value)>=parseFloat(document.getElementById("listbpo_home_left1_txtLPrice").value))
			{
				alert('First value must be smaller than second value for price range.');
				document.getElementById("listbpo_home_left1_txtFPrice").focus();
				return false;
			}
		}
	}
	
	var fp = document.getElementById("listbpo_home_left1_txtFPrice").value;
	var sp = document.getElementById("listbpo_home_left1_txtLPrice").value;
	var state = document.getElementById("Listbpo_home_left1_ddRState").value;
	
	location.href = "Resi_search_for_sale.aspx?id=4&reforid=4&reid=18&name=SearchResi&fp="+ fp +"&sp="+ sp +"&stateid="+ state +"&nativ=home";
	return false;
}

//------------------------------------------------------------------------------------

function quick_search_business_services()
{
	var btype = document.getElementById("Listbpo_home_left1_Bizservsearchbox1_ddBizServType").value;
	var country = document.getElementById("Listbpo_home_left1_Bizservsearchbox1_ddlBSCountry").value;						
	//alert(btype);
	//alert(country);
	location.href = "adv_search_bizserv.aspx?countryid="+ country +"&btypeid="+ btype +"&flag=S";
	return false;
}

//------------------------------------------------------------------------------------

function quick_search_franchises()
{
	var cat = document.getElementById("Listbpo_home_left1_Franchise_search_control1_ddFrCategory").value;
	location.href = "Search_Franchises.aspx?id=5&fcatid="+ cat +"&fsubcatid=0";
	return false;
}		