// JavaScript Document
var xmlHttp1;
var xmlHttp2;
var xmlHttp3;
latest_img_counter=1;
function getXmlHttpObject(){
	var objXMLHttp=null;
	if(window.XMLHttpRequest){
 		objXMLHttp=new XMLHttpRequest();
 	}else if(window.ActiveXObject){
 		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
 	}
 	return objXMLHttp;
}
//-----Start of Left Side Menu Loader-------------------------------------------------
function getAdMenu(){
	xmlHttp1=getXmlHttpObject();
	if(xmlHttp1==null){
		alert("Your browser has to be updated.");
		return;
	}else{
		var url="../settings/ad_category_list_loader.php";
		//url=url+"?page="+page_id;
		xmlHttp1.onreadystatechange=loadAdMenu;
		xmlHttp1.open("GET",url,true);
		xmlHttp1.send(null);
	}		
}
function loadAdMenu(){
	if(xmlHttp1.readyState!=4){
		document.getElementById('ad_category_panel').innerHTML='Loading Menu...';	
	}
	if(xmlHttp1.readyState==4){
		document.getElementById('ad_category_panel').innerHTML=xmlHttp1.responseText;
	}
}
//-----End of Left Side Menu Loader----------------------------------------------------
//-----Start of Content Loader---------------------------------------------------------
/*function getCategoryContents(pcid,ug_id,max_ug_id){
	
	xmlHttp2=getXmlHttpObject();
	if(xmlHttp2==null){
		alert("Your browser has to be updated.");
		return;
	}else{
		
		var url="common_step1.php";
		
		url=url+"?pcid="+pcid+"&ug_id="+ug_id;
		xmlHttp2.onreadystatechange=loadCategoryContents;
		xmlHttp2.open("GET",url,true);
		xmlHttp2.send(null);
		for(c=1;c<=max_ug_id;c++){
			if(c==ug_id){
				document.getElementById(c).style.background='#FFFFFF';	
			}
			else{
				document.getElementById(c).style.background='';	
			}
		}
		
	}		
}*/
function getCategoryContents(pcid,ug_id,max_ug_id,sub_cat){
	xmlHttp2=getXmlHttpObject();
	if(xmlHttp2==null){
		alert("Your browser has to be updated.");
		return;
	}else{
		var url="common_step1.php";
		url=url+"?pcid="+pcid+"&ug_id="+ug_id+"&sel_sub_category="+sub_cat;
		//alert(url);
		xmlHttp2.onreadystatechange=loadCategoryContents;
		xmlHttp2.open("GET",url,true);
		xmlHttp2.send(null);
		for(c=1;c<=max_ug_id;c++){
			if(c==ug_id){
				document.getElementById(c).style.background='#FFFFFF';	
			}
			else{
				document.getElementById(c).style.background='';	
			}
		}
		
	}		
}
function loadCategoryContents(){
	if(xmlHttp2.readyState!=4){
		document.getElementById('main_contents').innerHTML='Loading...';	
	}
	if(xmlHttp2.readyState==4){
		document.getElementById('main_contents').innerHTML=xmlHttp2.responseText;		
	}
}
//-----End of Content Loader------------------------------------------------------------

//-----Start of Furniture Content Loader---------------------------------------------------------
function getFurnitureContents(pcid,ug_id,max_ug_id){
	//alert(ug_id);
	xmlHttp2=getXmlHttpObject();
	if(xmlHttp2==null){
		alert("Your browser has to be updated.");
		return;
	}else{
		//if(ug_id == 4){
			var url="furniture_step1.php";
		/*}else{
			var url="furniture.php";
		}*/
			
		url=url+"?pcid="+pcid+"&ug_id="+ug_id;
		xmlHttp2.onreadystatechange=loadFurnitureContents;
		xmlHttp2.open("GET",url,true);
		xmlHttp2.send(null);
		for(c=1;c<=max_ug_id;c++){
			if(!document.getElementById(c))continue;
			if(c==ug_id){
				document.getElementById(c).style.background='#FFFFFF';	
			}
			else{
				document.getElementById(c).style.background='';	
			}
		}
	}
}

function loadFurnitureContents(){
	if(xmlHttp2.readyState!=4){
		document.getElementById('main_contents').innerHTML='Loading...';	
	}
	if(xmlHttp2.readyState==4){
		document.getElementById('main_contents').innerHTML=xmlHttp2.responseText;		
	}
}
//-----End of Furniture Content Loader------------------------------------------------------------

//-----Start of Advertiser Info Loader--------------------------------------------------
function getAdvertiserInfo(p_category_name,c_category_name,c_category_type_name,ug_id,pcid){
	xmlHttp2=getXmlHttpObject();
	if(xmlHttp2==null){
		alert("Your browser has to be updated.");
		return;
	}else{
		var url="common_step2.php";
		
		url=url+"?p_category_name="+p_category_name+"&c_category_name="+c_category_name+"&c_category_type_name="+c_category_type_name+"&ug_id="+ug_id+"&pcid="+pcid;
		//alert(url);
		xmlHttp2.onreadystatechange=loadAdvertiserInfo;
		xmlHttp2.open("GET",url,true);
		xmlHttp2.send(null);
	}		
}
function loadAdvertiserInfo(){
	if(xmlHttp2.readyState!=4){
		document.getElementById('main_contents').innerHTML='Loading...';	
	}
	if(xmlHttp2.readyState==4){
		document.getElementById('main_contents').innerHTML=xmlHttp2.responseText;		
	}
}
function getVendorList(pcat, scat, ugid){
	var type = $("#sel_sub_category_type").val();
	//alert(pcat+" - "+scat+" - "+type+" - "+ugid);
	var post_var="what=VLT&pcat=" + pcat + "&scat=" + scat + "&type=" + type + "&ugid=" + ugid;
	$.post("search_option.php", post_var, function(html){
		$("#ad_list").html(html);
		//alert(html);						
	});
}
//-----End of Advertiser Info Loader-----------------------------------------------------
//-----Start of Item Info Loader---------------------------------------------------------
function getCategoryList(p_category_name,c_category_name,c_category_type_name,ug_id,pcid,uid){
	xmlHttp2=getXmlHttpObject();
	if(xmlHttp2==null){
		alert("Your browser has to be updated.");
		return;
	}else{
		var url="common_step3.php";
		url=url+"?p_category_name="+p_category_name+"&c_category_name="+c_category_name+"&c_category_type_name="+c_category_type_name+"&ug_id="+ug_id+"&pcid="+pcid+"&uid="+uid+"&rb=OK";
		//alert(url);
		xmlHttp2.onreadystatechange=loadCategoryList;
		xmlHttp2.open("GET",url,true);
		xmlHttp2.send(null);
	}		
}
function loadCategoryList(){
	if(xmlHttp2.readyState!=4){
		document.getElementById('main_contents').innerHTML='Loading...';	
	}
	if(xmlHttp2.readyState==4){
		document.getElementById('main_contents').innerHTML=xmlHttp2.responseText;		
	}
}
//-----End of Advertiser Info Loader------------------------------------------------------------

//-----Start of Restaurant Contents Loader------------------------------------------------------
function getRestaurantContents(pcid,ug_id,c_cat){
	//alert(pcid+' - '+ug_id+' - '+c_cat);
	xmlHttp2=getXmlHttpObject();
	if(xmlHttp2==null){
		alert("Your browser has to be updated.");
		return;
	}else{
		div_to_expand = c_cat;
		var url="restaurants_step1.php";
		url=url+"?pcid="+pcid+"&ug_id="+ug_id;//alert(url);
		xmlHttp2.onreadystatechange=loadRestaurantContents;
		xmlHttp2.open("GET",url,true);
		xmlHttp2.send(null);
	}		
}

var div_to_expand = 0;

function loadRestaurantContents(){
	if(xmlHttp2.readyState!=4){
		document.getElementById('main_contents').innerHTML='Loading...';	
	}
	if(xmlHttp2.readyState==4){
		document.getElementById('main_contents').innerHTML=xmlHttp2.responseText;
		showDiv(div_to_expand);
	}
}
//-----End of Restaurant Contents Loader---------------------------------------------------------

//-----Start of Bank Contents Loader------------------------------------------------------
function getBankContents(pcid,ug_id){
	xmlHttp2=getXmlHttpObject();
	if(xmlHttp2==null){
		alert("Your browser has to be updated.");
		return;
	}else{
		var url="banks_step1.php";
		url=url+"?pcid="+pcid+"&ug_id="+ug_id;
		xmlHttp2.onreadystatechange=loadBankContents;
		xmlHttp2.open("GET",url,true);
		xmlHttp2.send(null);
	}		
}
function loadBankContents(){
	if(xmlHttp2.readyState!=4){
		document.getElementById('main_contents').innerHTML='Loading...';	
	}
	if(xmlHttp2.readyState==4){
		document.getElementById('main_contents').innerHTML=xmlHttp2.responseText;		
	}
}
//-----End of Restaurant Contents Loader---------------------------------------------------------

//-----Start of Information Loader---------------------------------------------------------
function getInfo(category_name){
	xmlHttp2=getXmlHttpObject();
	if(xmlHttp2==null){
		alert("Your browser has to be updated.");
		return;
	}else{
		var url=""+category_name+"_info.php";
		//url=url+"?cid="+cid;
		xmlHttp2.onreadystatechange=loadInfo;
		xmlHttp2.open("GET",url,true);
		xmlHttp2.send(null);
	}		
}
function loadInfo(){
	if(xmlHttp2.readyState!=4){
		document.getElementById('main_contents').innerHTML='Loading...';	
	}
	if(xmlHttp2.readyState==4){
		document.getElementById('main_contents').innerHTML=xmlHttp2.responseText;
	}
}
//-----End of Infomation Loader------------------------------------------------------------
//function swapImage(direction){
//		if(direction=='n'){
//			latest_img_counter+=1;
//			if(latest_img_counter>5){
//				latest_img_counter=1;	
//			}
//		}
//		else if(direction=='p'){
//			latest_img_counter-=1;
//			if(latest_img_counter<1){
//				latest_img_counter=5;	
//			}	
//		}
//		document.getElementById('new_this_week_image').innerHTML='<a href="#"><img src="images.php?item_id=+latest_img_counter+ border="0" /></a>';
//	}

function addToBookmark(url, title){
if (window.sidebar) // firefox
    window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
    var elem = document.createElement('a');
    elem.setAttribute('href',url);
    elem.setAttribute('title',title);
    elem.setAttribute('rel','sidebar');
    elem.click();
}
else if(document.all)// ie
    window.external.AddFavorite(url, title);
} 


//-----Start of Item View Loader--------------------------------------------------
function itemViewBank(item_id,tmp_id){
	//alert(tmp_id);
	xmlHttp2=getXmlHttpObject();
	if(xmlHttp2==null){
		alert("Your browser has to be updated.");
		return;
	}else{
		var url="templates/banks_template"+tmp_id+".php";
		url=url+"?item_id="+item_id;
		xmlHttp2.onreadystatechange=loadItemViewBank;
		xmlHttp2.open("GET",url,true);
		xmlHttp2.send(null);
	}		
}
function loadItemViewBank(){
	if(xmlHttp2.readyState!=4){
		document.getElementById('main_contents').innerHTML='Loading...';	
	}
	if(xmlHttp2.readyState==4){
		document.getElementById('main_contents').innerHTML=xmlHttp2.responseText;		
	}
}
//-----End of Item View Loader-----------------------------------------------------

//-----Start of Item View Rest Loader--------------------------------------------------
function itemViewRest(item_id,tmp_id){
	//alert(item_id);
	xmlHttp2=getXmlHttpObject();
	if(xmlHttp2==null){
		alert("Your browser has to be updated.");
		return;
	}else{
		var url="templates/restaurants_template"+tmp_id+".php";
		url=url+"?item_id="+item_id;
		xmlHttp2.onreadystatechange=loadItemViewRest;
		xmlHttp2.open("GET",url,true);
		xmlHttp2.send(null);
	}		
}
function loadItemViewRest(){
	if(xmlHttp2.readyState!=4){
		document.getElementById('main_contents').innerHTML='Loading...';	
	}
	if(xmlHttp2.readyState==4){
		document.getElementById('main_contents').innerHTML=xmlHttp2.responseText;		
	}
}
//-----End of Item View Rest Loader-----------------------------------------------------



//-----Start of Everything Else Contents Loader------------------------------------------------------
function getEverythingElseContents(pcid,ug_id,max_ug_id){
	//alert("xxx"+ug_id+"xxxxx"+max_ug_id);
	xmlHttp2=getXmlHttpObject();
	if(xmlHttp2==null){
		alert("Your browser has to be updated.");
		return;
	}else{
		var url="everything_else.php";
		url=url+"?pcid="+pcid+"&ug_id="+ug_id;
		xmlHttp2.onreadystatechange=loadEverythingElseContents;
		xmlHttp2.open("GET",url,true);
		xmlHttp2.send(null);
		for(c=1;c<=max_ug_id;c++){
			if(c==ug_id){
				if(document.getElementById(c)!=null)
				document.getElementById(c).style.background='#FFFFFF';	
			}
			else{
				if(document.getElementById(c)!=null)
				document.getElementById(c).style.background='';	
			}
		}
	}		
}
function loadEverythingElseContents(){
	if(xmlHttp2.readyState!=4){
		document.getElementById('main_contents').innerHTML='Loading...';	
	}
	if(xmlHttp2.readyState==4){
		document.getElementById('main_contents').innerHTML=xmlHttp2.responseText;		
	}
}
//-----End of Everything Else Loader---------------------------------------------------------

//-----Start of Furniture Contents Loader------------------------------------------------------
function itemViewFurniture(ad_id,ug_id,s_cat_id){
	//alert("xxx");
	xmlHttp2=getXmlHttpObject();
	if(xmlHttp2==null){
		alert("Your browser has to be updated.");
		return;
	}else{
		var url="furniture_step2.php";
		url=url+"?ad_id="+ad_id+"&ug_id="+ug_id+"&sc_id="+s_cat_id;//alert(url);
		xmlHttp2.onreadystatechange=loadFurnitureContents;
		xmlHttp2.open("GET",url,true);
		xmlHttp2.send(null);
	}		
}
function loadFurnitureContents(){
	if(xmlHttp2.readyState!=4){
		document.getElementById('main_contents').innerHTML='Loading...';	
	}
	if(xmlHttp2.readyState==4){
		document.getElementById('main_contents').innerHTML=xmlHttp2.responseText;		
	}
}
//-----End of Furniture Loader---------------------------------------------------------

//-----Start of News Event Contents Loader------------------------------------------------------
function in_focus(n_id){
	//alert(n_id);
	xmlHttp2=getXmlHttpObject();
	if(xmlHttp2==null){
		alert("Your browser has to be updated.");
		return;
	}else{
		var url="news_events/infocus_images.php";
		url=url+"?n_id="+n_id;
		//alert(url);
		xmlHttp2.onreadystatechange=loadin_focus;
		xmlHttp2.open("GET",url,true);
		xmlHttp2.send(null);
	}		
}
function loadin_focus(){
	if(xmlHttp2.readyState!=4){
		document.getElementById('new_this_week_image').innerHTML='Loading...';	
	}
	if(xmlHttp2.readyState==4){
		document.getElementById('new_this_week_image').innerHTML=xmlHttp2.responseText;		
	}
}
//-----End of News Event Loader---------------------------------------------------------

//-----Start of Real Estate Contents Loader------------------------------------------------------
function getRealEstateContents(pcid,ug_id,max_ug_id){
	//alert(pcid+" xxxx "+ug_id+" xxxxx "+max_ug_id);
	xmlHttp2=getXmlHttpObject();
	if(xmlHttp2==null){
		alert("Your browser has to be updated.");
		return;
	}else{
		var url="real_step1.php";
		url=url+"?pcid="+pcid+"&ug_id="+ug_id;
		xmlHttp2.onreadystatechange=loadRealEstateContents;
		xmlHttp2.open("GET",url,true);
		xmlHttp2.send(null);
		
		for(c=1;c<=max_ug_id;c++){
			if(c==ug_id){
				if(document.getElementById(c)!=null)
				document.getElementById(c).style.background='#FFFFFF';	
			}
			else{
				if(document.getElementById(c)!=null)
				document.getElementById(c).style.background='';	
			}
		}
	}		
}
function loadRealEstateContents(){
	if(xmlHttp2.readyState!=4){
		document.getElementById('main_contents').innerHTML='Loading...';	
	}
	if(xmlHttp2.readyState==4){
		document.getElementById('main_contents').innerHTML=xmlHttp2.responseText;		
	}
}
//-----End of Real Estate Loader---------------------------------------------------------

//-----Start of Real Estate Result Contents Loader------------------------------------------------------
function getRealEstateResultContents(item_id,ug_id){
	//alert(item_id);
	//alert(ug_id);
	xmlHttp2=getXmlHttpObject();
	if(xmlHttp2==null){
		alert("Your browser has to be updated.");
		return;
	}else{
		var url="real_step3.php";
		url=url+"?item_id="+item_id+"&ug_id="+ug_id;
		xmlHttp2.onreadystatechange=loadRealEstateResultContents;
		xmlHttp2.open("GET",url,true);
		xmlHttp2.send(null);
	}		
}
function loadRealEstateResultContents(){
	if(xmlHttp2.readyState!=4){
		document.getElementById('glow_panel_result').innerHTML='Loading...';
		//document.getElementById('main_contents').innerHTML='Loading...';
	}
	if(xmlHttp2.readyState==4){
		document.getElementById('glow_panel_result').innerHTML=xmlHttp2.responseText;
		//document.getElementById('main_contents').innerHTML=xmlHttp2.responseText;
	}
}
//-----End of Real Estate Result Contents Loader---------------------------------------------------------



//-----Start of Real Estate item profile image Contents Loader------------------------------------------------------
function in_focus_real(image_id){
	//alert(image_id);
	xmlHttp2=getXmlHttpObject();
	if(xmlHttp2==null){
		alert("Your browser has to be updated.");
		return;
	}else{
		var url="infocus_images.php";
		url=url+"?image_id="+image_id;
		//alert(url);
		xmlHttp2.onreadystatechange=loadin_focus_real;
		xmlHttp2.open("GET",url,true);
		xmlHttp2.send(null);
	}		
}
function loadin_focus_real(){
	if(xmlHttp2.readyState!=4){
		//document.getElementById('real_img').innerHTML='Loading...';	
	}
	if(xmlHttp2.readyState==4){
		//alert(xmlHttp2.responseText);
		document.getElementById('real_img').src = xmlHttp2.responseText;
		//alert(xmlHttp2.responseText);
		//document.getElementById('real_img') = xmlHttp2.responseText;

	}
}
//-----End of Real Estate item profile image Loader---------------------------------------------------------

//-----Start of Real Estate item image title Contents Loader------------------------------------------------------
function changeTitle(image_id){
	//alert(image_id);
	xmlHttp1=getXmlHttpObject();
	if(xmlHttp1==null){
		alert("Your browser has to be updated.");
		return;
	}else{
		var url="real_image_title.php";
		url=url+"?image_id="+image_id;
		//alert(url);
		xmlHttp1.onreadystatechange=changeTitle_;
		xmlHttp1.open("GET",url,true);
		xmlHttp1.send(null);
	}		
}
function changeTitle_(){
	if(xmlHttp1.readyState!=4){
		//document.getElementById('real_img').innerHTML='Loading...';	
	}
	if(xmlHttp1.readyState==4){
		//alert(xmlHttp1.responseText);
		document.getElementById('real_img').title = xmlHttp1.responseText;
		if(document.getElementById('item_image_desc')){
			document.getElementById('item_image_desc').innerHTML = xmlHttp1.responseText;
		}
		//alert(xmlHttp2.responseText);
		//document.getElementById('real_img') = xmlHttp2.responseText;

	}
}
//-----End of Real Estate item image title Loader---------------------------------------------------------

//-----Start of Real Estate Search Result Contents Loader------------------------------------------------------
function getRealSearch(){
	//alert("xxx");
	var poststr = 	"deal_type=" + encodeURI( document.getElementById("deal_type").value ) +
	  				"&location=" + encodeURI( document.getElementById("location").value )+
					"&prop_type=" + encodeURI( document.getElementById("prop_type").value )+
					"&beds=" + encodeURI( document.getElementById("beds").value )+
					"&baths=" + encodeURI( document.getElementById("baths").value )+
					"&floor_area=" + encodeURI( document.getElementById("floor_area").value )+
					"&land_area=" + encodeURI( document.getElementById("land_area").value )+
					"&air_condition=" + encodeURI( document.getElementById("air_condition").value )+
					"&garden=" + encodeURI( document.getElementById("garden").value )+
					"&quarters=" + encodeURI( document.getElementById("quarters").value )+
					"&pool=" + encodeURI( document.getElementById("pool").value )+
					"&furniture=" + encodeURI( document.getElementById("furniture").value )+
					"&price_fr=" + encodeURI( document.getElementById("price_fr").value )+
					"&price_to=" + encodeURI( document.getElementById("price_to").value )+
					"&ug_id=" + encodeURI( document.getElementById("ug_id").value );
					
	xmlHttp2=getXmlHttpObject();
	if(xmlHttp2==null){
		alert("Your browser has to be updated.");
		return;
	}else{
		var url="real_step2.php";
		url=url+"?"+poststr;
		//alert(url);
		xmlHttp2.onreadystatechange=loadRealSearchContents;
		xmlHttp2.open("GET",url,true);
		xmlHttp2.send(null);
	}		
}
function loadRealSearchContents(){
	if(xmlHttp2.readyState!=4){
		document.getElementById('glow_panel_result').innerHTML='Loading...';	
	}
	if(xmlHttp2.readyState==4){
		document.getElementById('glow_panel_result').innerHTML=xmlHttp2.responseText;		
	}
}
//-----End of Real Estate Search Result Contents Loader---------------------------------------------------------

//-----Start of item view Contents Loader------------------------------------------------------
function getItemViewContents(item_id,ug_id,uid,link_id,pcid,pid,tmp_id,p_category_name,c_category_name,c_category_type_name){
	//alert(item_id+' - '+ug_id+' - '+uid+' - '+link_id+' - '+pcid+' - '+pid+' - '+tmp_id+' - '+p_category_name+' - '+c_category_name+' - '+c_category_type_name);
	//alert('xxx');
	//alert(ug_id);
	xmlHttp2=getXmlHttpObject();
	if(xmlHttp2==null){
		alert("Your browser has to be updated.");
		return;
	}else{
		if(pid == 101){
		var url="real_step3.php";
		}else if(pid == 109){
		var url="templates/restaurants_template"+tmp_id+".php";
		}else if(pid == 110){
		var url="templates/banks_template"+tmp_id+".php";
		}
		//alert(url);
		url=url+"?p_category_name="+p_category_name+"&c_category_name="+c_category_name+"&c_category_type_name="+c_category_type_name+"&ug_id="+ug_id+"&pcid="+pcid+"&uid="+uid+"&link_id="+link_id+"&item_id="+item_id;
		//url=url+"?ug_id="+ug_id+"&pcid="+pcid+"&uid="+uid+"&item_id="+item_id+"&link_id="+link_id;
		//alert(url);
		xmlHttp2.onreadystatechange=loadItemViewContents;
		xmlHttp2.open("GET",url,true);
		xmlHttp2.send(null);
	}		
}
function loadItemViewContents(){
	if(xmlHttp2.readyState!=4){
		document.getElementById('main_contents').innerHTML='Loading...';
		//document.getElementById('main_contents').innerHTML='Loading...';
	}
	if(xmlHttp2.readyState==4){
		document.getElementById('main_contents').innerHTML=xmlHttp2.responseText;
		//document.getElementById('main_contents').innerHTML=xmlHttp2.responseText;
	}
}
function gotoVendorAdd(p_category_name,pcid,ug_id){
	var c_category_name = $('#sel_sub_category :selected').text();
	var c_category_type_name = $('#sel_sub_category_type :selected').text();
	var uid = $('#ad_list').val();
	
	getCategoryList(p_category_name,c_category_name,c_category_type_name,ug_id,pcid,uid);
}
//-----End of Real Estate Result Contents Loader---------------------------------------------------------

function slide_show(img_string,total,direction){
//alert(img_string+' - '+total+' - '+direction);
	func(img_string, total, direction);
	changeTitle(document.getElementById('nxtImg').value);
	in_focus_real(document.getElementById('nxtImg').value);
	//
}