﻿var cities=new Array(
new Array('多倫多',43.6734450,-79.455392,12,'Toronto'),
new Array('士嘉堡',43.7622891,-79.251878,12,'Scarborough'),
new Array('萬錦市',43.8800776,-79.350515,12,'Markham'),
new Array('旺市',43.7990266,-79.617571,12,'Vaughan'),
new Array('賓頓市',43.6936938,-79.850633,12,'Brampton'),
new Array('密西沙加市',43.5923595,-79.714050,11,'Mississauga'),
new Array('依桃碧谷市',43.6340873,-79.531779,12,'Etobicoke'),
new Array('烈治文山',43.8802772,-79.515174,12,'Richmond Hill'),
new Array('阿露拿',44.0026935,-79.513296,13,'Aurora'),
new Array('阿積士市',43.8384702,-79.086843,12,'Ajax'),
new Array('奧沙華市',43.8998715,-78.934021,12,'Oshawa'),
new Array('奧加魁',43.4708601,-79.760742,12,'Oakville'),
new Array('北約克市',43.7901435,-79.480070,12,'North York'),
new Array('東北',44.0426935,-79.126843,11,'North East'),
new Array('西北',44.0826935,-79.888633,11,'North West'));
function pictureplay(way,obj){
	var pic_array=new Array();
	imgobj=document.getElementById("m"+obj);
	eval(document.getElementById("es"+obj).innerHTML);
	osrc=imgobj.src.substr(imgobj.src.indexOf('pics/'));
	if(way==1){
		for(var i=0;i<pic_array.length;i++){
			if(pic_array[i]==osrc){
				i++;
				if(i==pic_array.length)i=0;
				imgobj.src=pic_array[i];break;
			}
		}
	}else{
		for(var i=pic_array.length-1;i>-1;i--){
			if(pic_array[i]==osrc){
				i--;
				if(i==-1)i=pic_array.length-1;imgobj.src=pic_array[i];break;}}}}
function citymarker(){for(var i=0;i<cities.length;i++){map.addOverlay(createcitymarker(cities[i]));}}function createcitymarker(city){var point=new GLatLng(city[1],city[2]);var marker=new GMarker(point);GEvent.addListener(marker,"click",function(){map_search.elements['city'].value=city[4];map_search.submit();});GEvent.addListener(marker,'mouseover',function(){var offset=map.getCurrentMapType().getProjection().fromLatLngToPixel(marker.getPoint(),map.getZoom());var point=map.getCurrentMapType().getProjection().fromLatLngToPixel(map.getBounds().getSouthWest(),map.getZoom());tooltip.innerHTML=city[0];var pos=new GControlPosition(G_ANCHOR_BOTTOM_LEFT,new GSize(offset.x-point.x+14,-offset.y+point.y-6));pos.apply(tooltip);tooltip.style.visibility="visible";});GEvent.addListener(marker,'mouseout',function(){tooltip.style.visibility="hidden";});return marker;}var infowindowopen=false;var house_xmlhttp_request;var msg;function MapRequest(){if(infowindowopen)return;var strURL="house_http_xml.php";if(window.XMLHttpRequest){xmlhttp_request=new XMLHttpRequest();}else if(window.ActiveXObject){try{xmlhttp_request=new ActiveXObject("Msxml2.XMLHTTP");}catch(ae){try{xmlhttp_request=new ActiveXObject("Microsoft.XMLHTTP");}catch(ae){}}}MapMsg('發送請求,數據下載中,請等待.....',true);var request=house_request();xmlhttp_request.onreadystatechange=HouseResponse;xmlhttp_request.open("POST",strURL,true);xmlhttp_request.setRequestHeader("Content-Length",request.length);xmlhttp_request.setRequestHeader("CONTENT-TYPE","application/x-www-form-urlencoded");xmlhttp_request.send(request);map.clearOverlays();}
function house_request(){var request;var bounds=map.getBounds();var southWest=bounds.getSouthWest();var northEast=bounds.getNorthEast();request="uy="+northEast.lat();request=request+"&dy="+southWest.lat();request=request+"&lx="+southWest.lng();request=request+"&rx="+northEast.lng();request=request+"&housetype="+search.housetype.options[Number(search.housetype.selectedIndex)].value;request=request+"&housestyle="+search.housestyle.options[Number(search.housestyle.selectedIndex)].value;request=request+"&bedroom="+search.bedroom.options[Number(search.bedroom.selectedIndex)].value;request=request+"&kitchen="+search.kitchen.options[Number(search.kitchen.selectedIndex)].value;request=request+"&bathroom="+search.bathroom.options[Number(search.bathroom.selectedIndex)].value;request=request+"&houseage="+search.houseage.options[Number(search.houseage.selectedIndex)].value;request=request+"&area="+search.area.options[Number(search.area.selectedIndex)].value;request=request+"&input_day="+search.input_day.options[Number(search.input_day.selectedIndex)].value;request=request+"&minprice="+search.minprice.value;request=request+"&maxprice="+search.maxprice.value;if(search.s.checked)request=request+"&s=1";if(search.h.checked)request=request+"&h=1";if(search.c.checked)request=request+"&c=1";if(search.l.checked)request=request+"&l=1";if(search.t.checked)request=request+"&t=1";try{if(search.g.checked)request=request+"&g=1";} catch(e){}try{if(search.dis.checked){for(i=0;i<document.getElementsByName('zns[]').length;i++){request=request+"&zns[]="+document.getElementsByName('zns[]')[i].value;}}}catch(e){} return request;}
function HouseResponse(){
	if(xmlhttp_request.readyState==4){
		if(xmlhttp_request.status==200){
			var pre_address=null;var infotabs;
			var same=0;
			MapMsg('數據下載完畢,數據分析開始.....',true);
			
			
			xmlDoc=GXml.parse(xmlhttp_request.responseText);
			var nodes=xmlDoc.documentElement.getElementsByTagName("house");
			MapMsg("獲得<font color='red'> "+nodes.length+"</font> 條數據,正在裝入畫面.....",true);
			for(i=0;i<nodes.length+1;i++){
				if(i<nodes.length&&pre_address==nodes[i].getAttribute("address")){
					infotabs.push(PropertyInfoTab(nodes[i]));tip+="<br>"+HouseTip(nodes[i]);same++;
				}else{
					if(infotabs!=null){
						AddPropertyMarker(PropertyMarker(nodes[i-1]),infotabs,tip);
						}
					if(i<nodes.length){
						infotabs=new Array();infotabs.push(PropertyInfoTab(nodes[i]));tip="";tip=HouseTip(nodes[i]);pre_address=nodes[i].getAttribute("address");}}}MapMsg("獲得<font color='red'> "+nodes.length+"</font> 條數據,裝入畫面完畢 !",true);MapMsg('',false,transparents.length);var nodes=xmlDoc.documentElement.getElementsByTagName("place");for(var i=0;i<nodes.length;i++){NeighbourMarker(nodes[i]);}var nodes=xmlDoc.documentElement.getElementsByTagName("broker");for(var i=0;i<nodes.length;i++){BrokerMarker(nodes[i]);} xmlhttp_request=null;infotabs=null;}}} function BrokerMarker(node){var point=new GPoint(node.getAttribute('lng'),node.getAttribute('lat'));var icon = new GIcon();icon.image='images/realtor.gif';icon.iconSize = new GSize(18, 18);icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";icon.shadowSize = new GSize(18, 18);icon.iconAnchor = new GPoint(6, 18);icon.infoWindowAnchor = new GPoint(5, 1);var marker=new GMarker(point,icon);GEvent.addListener(marker,'click',function(){marker.openInfoWindowHtml(GXml.value(node));});map.addOverlay(marker);}function NeighbourMarker(node){var point=new GPoint(node.getAttribute('longitude'),node.getAttribute('latitude'));var marker=new GMarker(point,NeighbourIcon(node.getAttribute("type")));var html="<div>"+GXml.value(node)+"</div>";GEvent.addListener(marker,'click',function(){marker.openInfoWindowHtml(html);});map.addOverlay(marker);}
function PropertyMarker(node){var longitude=parseFloat(node.getAttribute("longitude"));var latitude=parseFloat(node.getAttribute("latitude"));var point=new GLatLng(latitude,longitude);return new GMarker(point,PropertyIcon(node.getAttribute("typeid")));}function AddPropertyMarker(marker,infotabs,tip){GEvent.addListener(marker,'click',function(){marker.openInfoWindowTabsHtml(infotabs);});GEvent.addListener(marker,'mouseover',function(){var offset=map.getCurrentMapType().getProjection().fromLatLngToPixel(marker.getPoint(),map.getZoom());var point=map.getCurrentMapType().getProjection().fromLatLngToPixel(map.getBounds().getSouthWest(),map.getZoom());tooltip.innerHTML=tip;var pos=new GControlPosition(G_ANCHOR_BOTTOM_LEFT,new GSize(offset.x-point.x+14,-offset.y+point.y+24));pos.apply(tooltip);tooltip.style.visibility="visible";});GEvent.addListener(marker,'mouseout',function(){tooltip.style.visibility="hidden";;});map.addOverlay(marker);}var transparents=new Array('#5AC450','#57BE4D','#54B84A','#51B348','#50AF47','#4CA643','#49A241','#479D3F','#43953B','#419139','#3F8E37','#3B8734');function MapMsg(str,v,i){i--;if(v==true){msg.innerHTML=str;var pos=new GControlPosition(G_ANCHOR_TOP_LEFT,new GSize(110,200));pos.apply(msg);msg.style.backgroundColor="377F30";msg.style.visibility="visible";}else{if(i==0){msg.style.visibility="hidden";}else{msg.style.backgroundColor=transparents[i];setTimeout("MapMsg('',false,"+i+")",100);}}}
function PropertyInfoTab(node){
	var strhtml;
	strhtml="<div style='width:284px;height:100px;background-color:#FFFFFF;'>";
	strhtml+="<div style='float:right;margin-left:0;padding-left:2px;'>";
	strhtml+="<label id='type_lt'>類型:</label><label id='type_lv'>"+node.getAttribute("propertytype")+"<label>";
	strhtml+="<br><label id='style_lt'>樣式:</label><label id='style_lv'>"+node.getAttribute("propertystyle")+"<label>";
	strhtml+="<br><label id='zn_lt'>區域:</label><label id='zn_lv'>"+node.getAttribute("district")+"<label>";
	strhtml+="<br><label id='price_lt'>價格:</label><label id='price_lv'>$"+node.getAttribute("price")+"<label>";
	strhtml+="<hr width=126>";
	strhtml+="<span class='span_bt' index="+node.getAttribute("houseid")+" onclick=opendetail('"+node.getAttribute("housetype")+"','"+node.getAttribute("houseid")+"');>詳細</span>";
	strhtml+="<span class='span_bt' index="+node.getAttribute("houseid")+" onclick=m_add_compare(this,'"+node.getAttribute("housetype")+"');>比較</span>";
	strhtml+="</div>";
	strhtml+="<div style='margin:0;padding:0;'>"+GXml.value(node.childNodes[0])+"</div>";
	strhtml+="</div>";
	return new GInfoWindowTab(node.getAttribute("houseid"),strhtml);
}
function HouseTip(node){return node.getAttribute("propertytype")+" "+node.getAttribute("propertystyle")+" $<span style='color:green;'>"+node.getAttribute("price")+"</span>";}function InfoWindowOpen(){infowindowopen=true;}function InfoWindowClose(){infowindowopen=false;}function m_add_compare(obj,housetype){if(compare.elements.length>2&&compare.housetype.value!=housetype){}else{for(i=0;i<compare.elements.length-2;i++){if(obj.getAttribute('index')==compare.elements[i].value)break;}if(i!=compare.elements.length-2)return;var strHTML;strHTML="<div id='c"+obj.getAttribute('index')+"' style='float:left;width:122px;height:100px;margin:0px;'><img src='pics/"+obj.getAttribute('index')+"_1.jpg' width='120' height='82' border='1' onerror=\"this.src='pics/default.jpg';\">";strHTML+="<br><span class='m_c_t' onclick=\"opendetail('"+housetype+"','"+obj.getAttribute('index')+"');\">詳情</span>";strHTML+="<span class='m_c_t' onclick=\"map_c_del('c"+obj.getAttribute('index')+"');\">刪除</span>";strHTML+="<input type='hidden' name='mls[]' value='"+obj.getAttribute('index')+"'>";strHTML+="</div>";div_m_c.innerHTML= strHTML + div_m_c.innerHTML;compare.housetype.value=housetype;if(housetype=='Free')compare.action="freehold_compare.php";if(housetype=='Condo')compare.action="condo_compare.php";}}function map_c_del(obj){ obj = document.getElementById(obj); obj.removeNode(true);}function NeighbourIcon(type){var icon=new GIcon();switch(type){case"1":icon.image="images/s.png";icon.iconSize=new GSize(20,24);break;case"2":icon.image="images/h.png";icon.iconSize=new GSize(20,24);break;case"3":icon.image="images/c.png";icon.iconSize=new GSize(20,24);break;case"4":icon.image="images/m.png";icon.iconSize=new GSize(20,24);break;case"5":icon.image="images/l.png";icon.iconSize=new GSize(15,25);break;case"6":icon.image="images/ttc.gif";icon.iconSize=new GSize(24,24);break;case"7":icon.image="images/go.gif";icon.iconSize=new GSize(24,24);break;}
icon.shadow="images/dithshaadow.gif";icon.shadowSize=new GSize(1,1);icon.iconAnchor=new GPoint(6,34);icon.infoWindowAnchor=new GPoint(6,6);return icon;}function PropertyIcon(type){var icon=new GIcon();icon.image="images/"+type+".png";if(Number(type)==15){icon.iconSize=new GSize(24,30);}else{icon.iconSize=new GSize(24,24);}icon.shadow="images/dithshaadow.gif";icon.shadowSize=new GSize(1,1);icon.iconAnchor=new GPoint(5,34);icon.infoWindowAnchor=new GPoint(6,5);return icon;}
