/***************************************************************************
 This is the cheader.aspx javascript file
/***************************************************************************/

function check(form)  {
  r = true;
  if (Trim(form.q.value)=="")  {
    alert("請 輸 入 樓 宇 名 稱 或 地 址。");
    r = false;
  }else{
	ls1 = "paddresssearch1.aspx?search="+ escape(form.q.value);
	if(mstartuptype=="newpopup"){
//		wpopup3(ls1,"directory","");
		this.location.href = ls1;
	}else{
		this.location.href = ls1;
	}
	//setTimeout(ls1,300);
	//alert(2);
    r = false;
  }
  return r;
}

function load18districtsearch(type,code){
	ls1 = "paddresssearch1.aspx?type="+type+"&code=" + code;
	if(mstartuptype=="newpopup"){
		//wpopup3(ls1,"directory","");
		this.location.href = ls1;
	}else{
		this.location.href = ls1;
	}
}

function loadbldglist(atype,acode){
	ls1 = "paddresssearch1.aspx?type="+atype+"&code="+acode;
	this.location.href = ls1;
}

	function addresssearch1_callback(atype, acode){
		//alert(acode);
		if(atype != "" && acode != ""){
			laspx = document.location.pathname;
			if(laspx.indexOf("pinfo") < 0 ){
				laspx = "ptest.aspx";
			}
			location.href = laspx + "?type=" + atype + "&code="+acode + "&info="+jsminfo;
		}
	}



	function jsmypopupdiv2a(atxt,ax,ay){
		var pchartoffset = document.getElementById("mypopupdiv").offsetTop;	
		ls2 = '';
		atxt = atxt;
		ly =ay;
		lx =ax;
		ls2 = "<div id='menucloser' style='position:absolute; top:-20px; left:-20px;  z-index:100; '><img id=imgmenuclosesp src='img/space.gif' style='width:420; height:460' border=0 onMouseOver='jsmypopupdiv2b();'></div>";
		ls2 += "<div id='menucontent' style='position:absolute; top:0px; left:0px; z-index:100'>";
		ls2 += atxt ;
		ls2 += "</div>";
		ls2 +=  "</div>";
		document.getElementById('mypopupdiv').innerHTML = ls2;
		document.getElementById("mypopupdiv").style.top = ly;
		document.getElementById("mypopupdiv").style.left = lx;
	}

	function jsmypopupdiv2b(){
		document.getElementById('mypopupdiv').innerHTML = '';
		//document.getElementById('mypopupdiv').style.height = 1;
	}
			function jsTDgetrealxy(aobj){
				if(aobj==null){
					this.x = 0;
					this.y = 0;
					return this;
				}	else{
					a = jsTDgetrealxy(aobj.offsetParent);
					this.x = aobj.offsetLeft + a.x;
					this.y = aobj.offsetTop + a.y;
					return this;
				}
			}

	function jsmypopupdiv3a(atxt,ax,ay){
	
		var pchartoffset = document.getElementById('mypopupdiv2').offsetTop;	
		ls2 = '';
		atxt = atxt;
		ly =ay;
		lx =ax;
		ls2 = "<div id='menucloser2' style='position:absolute; top:-20px; left:-20px;  z-index:100; '><img id=imgmenuclosesp src='img/space.gif' style='width:420; height:460' border=0 onMouseOver='jsmypopupdiv3b();'></div>";
		ls2 += "<div id='menucontent2' style='position:absolute; top:0px; left:0px; z-index:100'>";
		ls2 += atxt ;
		ls2 += "</div>";
		ls2 +=  "</div>";
		document.getElementById('mypopupdiv2').innerHTML = ls2;
		document.getElementById("mypopupdiv2").style.top = ly;
		document.getElementById("mypopupdiv2").style.left = lx;
	}

	function jsmypopupdiv3b(){
		document.getElementById('mypopupdiv2').innerHTML = '';
		//document.getElementById('mypopupdiv').style.height = 1;
	}

			//var termsncond = '本 網 頁 免 費 提 供 香 港 房 地 產 市 場 詳 盡 資 訊，內 容	力 求 準 確。 \n所 提 供 資 料 僅 作 參 考 用 途。 若 因 錯 漏 而 引 致 任 何 不 便 或 損 失，\nCentadata.com 及 中 原 集 團 概 不 負 責。';
			//var termsncond = '本 網 頁 免 費 提 供 香 港 房 地 產 市 場 詳 盡 資 訊 ， 內 容 力 求 準 確 。 \n所 提 供 資 料 僅 作 參 考 用 途 。 若 因 錯 漏 而 引 致 任 何 不 便 或 損 失 ，\nCentadata.com  及 中 原 集 團 概 不 負 責 。';
			var termsncond = '本 網 頁 免 費 提 供 香 港 房 地 產 市 場 詳 盡 資 訊 ， 內 容 力 求 準 確 。 \n所 提 供 資 料 僅 作 參 考 用 途 。 若 因 錯 漏 而 引 致 任 何 不 便 或 損 失 ，\nCentadata.com  概 不 負 責 。';
			function jsheaderdropdownhtml(a){
					var region = ""
					ls = "";
					for(i=0;i<a.length;i=i+2){
						if(i==0){
							region = a[i];
							ls1 = "<table cellpadding=0 cellspacing=0  bgcolor='#d85977' class=myheadmenu1><tr><td><a href=javascript:load18districtsearch('district16','"+a[i]+"');>"+a[i+1]+"</a></td></tr></table>";
							//ls1 += "<table cellpadding=0 cellspacing=0  bgcolor='#d85977' width=120 class=myheadmenu2>";
							// scope change
							ls1 += "<table cellpadding=0 cellspacing=0  bgcolor='#d85977' width=130 class=myheadmenu2>";
							
						}else{
							ls1 += "<tr><td onmouseover=\"jsheaderscopeselected(this,'"+  a[i] + "','" +  a[i+1] + "','" +  region+ "');\" ><a href=javascript:load18districtsearch('district17','"+a[i]+"');>"+a[i+1]+"</a></td></tr>";
						}
					}
					ls1 += "</table>";
					return ls1;
			}			
						
			function jsheaderitemselected(aobj,apop){
					if(apop != null){
						a = null;
						if(apop=='HK'){
							//a = Array('HK','香港','101','堅尼地城/西營盤','102','鴨利洲/海怡','104','貝沙灣/沙宣道','105','香港仔/碧瑤置富','106','西半山','107','山頂/南區','108','灣仔/銅鑼灣','109','中半山','110','跑馬地/大坑','111','北角半山','112','北角/炮台山','113','則魚涌/康怡','114','太古城','115','筲箕灣/柴灣','116','杏花村');
							// scope change
							//a = Array('HK','香港','101','堅尼地城/西營盤','117','上環/中環/金鐘','102','海怡','104','數碼港','105','香港仔/鴨利洲','106','西半山','107','山頂/南區','108','灣仔/銅鑼灣 ','109','中半山','110','跑馬地/大坑 ','111','北角半山','112','北角/炮台山','113','則魚涌/康怡','114','太古城','115','筲箕灣/柴灣','116','杏花村');
							// scope change again on 2009-02-11 by Louis 
							a = Array('HK','香港','101','堅尼地城/西營盤','117','上環/中環/金鐘','102','海怡','104','數碼港','105','香港仔/鴨利洲','106','西半山','107','山頂/南區','108','灣仔/銅鑼灣 ','109','中半山','110','跑馬地/東半山 ','111','北角半山','112','北角/炮台山','113','則魚涌/康怡','114','太古城','115','筲箕灣/柴灣','116','杏花村');
						}
						if(apop=='KL'){
							//a = Array('KL','九龍','201','奧運站','202','九龍站','203','旺角/油麻地','204','尖沙咀/佐敦','205','何文田/京士柏','206','紅磡/土瓜灣','207','黃埔/海逸','209','將軍澳','210','美孚/西九龍','211','華景/海峰','212','長沙灣/深水步','213','又一村/畢架山','214','九龍塘','215','藍田/油塘','216','九龍灣/牛池灣','217','觀塘','218','鑽石山/黃大仙');
							// scope change
							a = Array('KL','九龍','201','奧運站','202','九龍站','203','旺角/油麻地','204','尖沙咀/佐敦','205','何文田/京士柏','206','土瓜灣','219','土瓜灣東','207','黃埔/海逸','220','紅磡','209','將軍澳','210','美孚/華景','212','長沙灣/深水步','211','長沙灣西','213','又一村/石硤尾','214','九龍塘/畢架山','215','藍田/油塘','216','九龍灣/牛池灣','217','觀塘','218','鑽石山/黃大仙');
						}
						if(apop=='NE'){
							//a = Array('NE','新界東','208','西貢','301','大圍市中心','302','沙田/第一城','303','火炭/沙田半山','304','馬鞍山','305','九肚山','306','大埔半山/康樂園','307','大埔墟/太和','308','上水/粉嶺');
							// scope change
							//a = Array('NE','新界東','208','西貢','301','大圍','302','沙田','303','火炭/沙田半山/九肚山','304','馬鞍山','306','大埔半山/康樂園','307','大埔墟/太和','308','上水/粉嶺');
							a = Array('NE','新界東','208','西貢','301','大圍','302','沙田','303','火炭/沙田半山/九肚山','304','馬鞍山','306','大埔半山/康樂園','307','大埔墟/太和','308','上水/粉嶺/古洞');
						}
						if(apop=='NW'){
							//a = Array('NW','新界西','103','愉景灣/離島','309','錦繡/加州','401','元朗','402','屯門','403','天水圍','404','荃灣','405','葵涌','406','青衣','407','珀麗灣','408','東涌','409','深井/黃金海岸','410','荃灣(麗城)');
							// scope change
							//a = Array('NW','新界西','103','愉景灣','309','錦繡/加州','401','元朗','402','屯門','403','天水圍','404','荃灣','405','葵涌','406','青衣','407','馬灣/珀麗灣','408','東涌/離島','409','深井/青山公路(屯門段)','410','麗城/青山公路(荃灣段)');
							//a = Array('NW','新界西','103','愉景灣','309','錦繡/加州','401','元朗','402','屯門','409','深井/青山公路(屯門段)','403','天水圍','404','荃灣','410','麗城/青山公路(荃灣段)','405','葵涌','406','青衣','407','馬灣/珀麗灣','408','東涌/離島');
							a = Array('NW','新界西','103','愉景灣','309','錦繡/加州/葡萄園','401','元朗','402','屯門','409','深井/青山公路(屯門段)','403','天水圍','404','荃灣','410','麗城/青山公路(荃灣段)','405','葵涌','406','青衣','407','馬灣/珀麗灣','408','東涌/離島');
						}
						if (a != null){
							ls1 = jsheaderdropdownhtml(a);
							a =	 jsTDgetrealxy(aobj);
							jsmypopupdiv2a(ls1,a.x,a.y);
						}
				}
			}
			
			function jsheaderscopeselected(aobj, ascp, anamec, amkt){
				//var content = "<table class=\"myheadmenu2\" border=0 bordercolor='#b60932' cellpadding=0 cellspacing=0><tr><td valign=\"top\"  width=110>";
				// scope change
				var content = "<table class=\"myheadmenu2\" border=0 bordercolor='#b60932' cellpadding=0 cellspacing=0><tr><td valign=\"top\"  width=130>";
				var inscp = false;
				var count = 0;
				if(amkt == 'HK'){
					for(i=0;i<arrHK.length;i=i+3){
						if(arrHK[i] == ascp){
							inscp = true;
							if(count%3 == 0){
								content += "<a href=\"javascript:load18districtsearch('district17','" + ascp + "');\">" + anamec+ "</a></td>";
								content += "<td width=120><a href=\"" + arrHK[i+2] + "\">" + arrHK[i+1] + "</a></td></tr>";
								count++;
							}
							else{
								content += "<tr><td onmouseover=\"jsmypopupdiv3b();\"></td><td  width=120><a href=\"" + arrHK[i+2] + "\">" + arrHK[i+1] + "</a></td></tr>";
								count++;
							}
						}
						else if( inscp == true){
							break;
						}
					}
					content += "<tr><td onmouseover=\"jsmypopupdiv3b();\"></td><td align=right width=120><a href=javascript:load18districtsearch('district17','"+ascp+"');>>> 更多</a></td></tr></table>";
				}
				else if(amkt == 'KL'){
					for(i=0;i<arrKL.length;i=i+3){
						if(arrKL[i] == ascp){
							inscp = true;
							if(count%3 == 0){
								content += "<a href=\"javascript:load18districtsearch('district17','" + ascp + "');\">" + anamec+ "</a></td>";
								content += "<td width=120><a href=\"" + arrKL[i+2] + "\">" + arrKL[i+1] + "</a></td></tr>";
								count++;
							}
							else{
								content += "<tr><td onmouseover=\"jsmypopupdiv3b();\"></td><td  width=120><a href=\"" + arrKL[i+2] + "\">" + arrKL[i+1] + "</a></td></tr>";
								count++;
							}
						}
						else if( inscp == true){
							break;
						}
					}
					content += "<tr><td onmouseover=\"jsmypopupdiv3b();\"></td><td align=right width=120><a href=javascript:load18districtsearch('district17','"+ascp+"');>>> 更多</a></td></tr></table>";
				}
				else if(amkt == 'NE'){
					for(i=0;i<arrNE.length;i=i+3){
						if(arrNE[i] == ascp){
							inscp = true;
							if(count%3 == 0){
								content += "<a href=\"javascript:load18districtsearch('district17','" + ascp + "');\">" + anamec+ "</a></td>";
								content += "<td width=120><a href=\"" + arrNE[i+2] + "\">" + arrNE[i+1] + "</a></td></tr>";
								count++;
							}
							else{
								content += "<tr><td onmouseover=\"jsmypopupdiv3b();\"></td><td  width=120><a href=\"" + arrNE[i+2] + "\">" + arrNE[i+1] + "</a></td></tr>";
								count++;
							}
						}
						else if( inscp == true){
							break;
						}
					}
					content += "<tr><td onmouseover=\"jsmypopupdiv3b();\"></td><td align=right width=120><a href=javascript:load18districtsearch('district17','"+ascp+"');>>>更多</a></td></tr></table>";
				}
				else if(amkt == 'NW'){
					for(i=0;i<arrNW.length;i=i+3){
						if(arrNW[i] == ascp){
							inscp = true;
							if(count%3 == 0){
								content += "<a href=\"javascript:load18districtsearch('district17','" + ascp + "');\">" + anamec+ "</a></td>";
								content += "<td width=120><a href=\"" + arrNW[i+2] + "\">" + arrNW[i+1] + "</a></td></tr>";
								count++;
							}
							else{
								content += "<tr><td onmouseover=\"jsmypopupdiv3b();\"></td><td  width=120><a href=\"" + arrNW[i+2] + "\">" + arrNW[i+1] + "</a></td></tr>";
								count++;
							}
						}
						else if( inscp == true){
							break;
						}
					}
					content += "<tr><td onmouseover=\"jsmypopupdiv3b();\"></td><td width=120 align=right><a href=javascript:load18districtsearch('district17','"+ascp+"');>>>更多</a></td></tr></table>";
				}
				var a = jsTDgetrealxy(aobj);
				jsmypopupdiv3a(content, a.x, a.y);
			}
			
			function jsfwindowopen(ax,ay,ax1,ay1,aurl){
				feature="width="+ax1+",height="+ay1+",left="+ax+",top="+ay+",toolbar=1,location=0,directories=0,status=1,menuBar=1,scrollBars=1,resizable=1";
				if(gwin_directory !=null && isIE4) gwin_directory.close();
				gwin_directory = window.open('redir.htm?'+escape(aurl),"otherinfo",feature);
			}
			
				function Trim(TRIM_VALUE){
		if(TRIM_VALUE.length < 1){
			return "";
		}
		TRIM_VALUE = RTrim(TRIM_VALUE);
		TRIM_VALUE = LTrim(TRIM_VALUE);
		if(TRIM_VALUE==""){
			return "";
		}
		else{
			return TRIM_VALUE;
		}
	} 

	function RTrim(VALUE){
		var w_space = String.fromCharCode(32);
		var v_length = VALUE.length;
		var strTemp = "";
		if(v_length < 0){
			return"";
		}
		var iTemp = v_length -1;

		while(iTemp > -1){
			if(VALUE.charAt(iTemp) == w_space){
			}
		else{
			strTemp = VALUE.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;

		}
		return strTemp;

	} 
	
	function LTrim(VALUE){
		var w_space = String.fromCharCode(32);
		if(v_length < 1){
		return"";
		}
		var v_length = VALUE.length;
		var strTrim = "";

		var iTrim = 0;

		while(iTrim < v_length){
			if(VALUE.charAt(iTrim) == w_space){
			}
			else{
				strTrim = VALUE.substring(iTrim,v_length);
				break;
			}
			iTrim = iTrim + 1;
		} 
		return strTrim;
	} 