﻿function Navigation_Go(){switch(nav.elements['to'].value){case'house':if(nav.elements['by'].value=='map'){location.href="house_city_search.php";}
if(nav.elements['by'].value=='dis'){location.href="house_dis_search.php";}
break;case'agent':location.href="agents_list.php";break;case'broker':location.href="brokers_list.php";break;}}
function navigation_Set(){switch(nav.elements['to'].value){case'house':nav.elements['by'].options.remove(0);var oOption=document.createElement("OPTION");nav.elements['by'].options.add(oOption);oOption.innerText="地圖方式";oOption.Value="map";var oOption=document.createElement("OPTION");nav.elements['by'].options.add(oOption);oOption.innerText="區域方式";oOption.Value="dis";break;case'agent':case'broker':nav.elements['by'].options.remove(0);if(nav.elements['by'].options.length==1)nav.elements['by'].options.remove(0);var oOption=document.createElement("OPTION");nav.elements['by'].options.add(oOption);oOption.innerText="名稱方式";oOption.Value="name";break;}}
function Compare_Do(){if(document.getElementsByName("mls[]").length<2)return;if(search.houseclass.value=='Free')search.action="freehold_compare.php";if(search.houseclass.value=='Condo')search.action="condo_compare.php";search.submit();}
function c_pages(arg,total_record){
	houses=document.getElementsByName("mls[]");
	for(i=0;i<houses.length;i=i+4){
		if(eval('h_'+houses[i].value).style.display=='')
			break;
	}
	if(arg=="first"){
		p1=0;if(p1==i)return;p2=Math.min(p1+4,houses.length);
	}
	if(arg=="prev"){
		if(i-4<0)return;p1=i-4;p2=Math.min(p1+4,houses.length);
	}
	if(arg=="next"){
		if(i>=houses.length-4)return;p1=i+4;p2=Math.min(p1+4,houses.length);
	}
	if(arg=="last"){
		p1=(Math.ceil(houses.length/4)-1)*4;if(p1==i)return;p2=Math.min(p1+4,houses.length);
	}
	p3=Math.min(i+4,houses.length);
	for(;i<p3;i++){eval('h_'+houses[i].value).style.display='none';}
	for(i=p1;i<p2;i++){eval('h_'+houses[i].value).style.display='';}
	msg.innerText=""+(p1+1)+" - "+p2+" / "+houses.length;
}
function c_del(obj){eval('h_'+obj.index).removeNode(true);try{eval("window.opener.c"+obj.index).removeNode(true);}catch(e){}
try{houses=document.getElementsByName("mls[]");for(i=0;i<houses.length;i=i+4){if(eval('h_'+houses[i].value).style.display=='')break;}
if(i>=houses.length)i=Math.min(i-4,houses.length);p1=i;p2=Math.min(i+4,houses.length);for(;i<p2;i++){eval('h_'+houses[i].value).style.display='';}
msg.innerText=""+(p1+1)+" - "+p2+" / "+houses.length;}catch(e){msg.innerText="0 - 0 / 0";}}
function pages(arg){search.page.value=arg;search.submit();}
function opendetail(housetype,str){if(housetype=='Free'){ strurl ="freehold.php";}else{strurl="condo.php";} window.open("/toronto/"+strurl+"?mls="+str,str,"width=728,height=600,scrollbars=1,status=no");}
function openagent(str){window.open("agent/"+str,'agent_window',"width=740,height=600,scrollbars=1,status=no");}
function condoshow(str){window.open("","show","width=770,height=600,scrollbars=1,toolbar=1,status=no");show.ml_num.value=str;show.submit();}
function pdfshow(mls,page){window.open("pdf/"+page+".php?mls="+mls,"show","width=770,height=600,scrollbars=1,toolbar=1,status=no");}
function freeholdshow(str){window.open("","show","width=770,height=600,scrollbars=1,toolbar=1,status=no");show.ml_num.value=str;show.submit();}
function t2(obj){var r_i;r_i=document.form.interestRate.value/1200;var factr=1;var ratePlusOne=r_i+1;for(var i=0;i<document.form.nrOfYears.value * 12;i++){factr*=ratePlusOne;}
if(obj.name=='f_payment')document.form.loanAmount.value=document.form.prop_amount.value-obj.value;if(obj.name=='loanAmount')document.form.f_payment.value=document.form.prop_amount.value-document.form.loanAmount.value;if(r_i==0)return;am=document.form.loanAmount.value;x=Math.ceil(100*(am*factr*r_i)/(factr-1));document.form.m_payment.value=x/100;return true;}
function t1(){var prop_value=document.form.prop_amount.value;var province=document.form.province.options[document.form.province.selectedIndex].value;var land_tax_value;if(prop_value==0){alert("Please enter a property value!");}else if(prop_value>0&&prop_value<=100){alert("Please choose a property value over $100!");}else{if(province=="Alberta"){if(prop_value!=0){land_tax_value=((0.001*prop_value)+35);document.form.land_tax.value=land_tax_value;}}else if(province=="British Columbia"){if(prop_value<=200000){land_tax_value=(0.01*prop_value);document.form.land_tax.value=land_tax_value;}else if(prop_value>200000){land_tax_value=((0.02*prop_value)-2000);document.form.land_tax.value=land_tax_value;}}else if(province=="Manitoba"){if(prop_value<=30000){land_tax_value="0";document.form.land_tax.value=land_tax_value;}else if(prop_value>30000&&prop_value<=90000){land_tax_value=((0.005*prop_value)-110);document.form.land_tax.value=land_tax_value;}else if(prop_value>90000&&prop_value<=150000){land_tax_value=((0.01*prop_value)-560);document.form.land_tax.value=land_tax_value;}else if(prop_value>150000){land_tax_value=((0.015*prop_value)-1350);document.form.land_tax.value=land_tax_value;}}else if(province=="New Brunswick"){if(prop_value!=0){land_tax_value=((0.0025*prop_value)+55);document.form.land_tax.value=land_tax_value;}}else if(province=="Newfoundland"){if(prop_value!=0){land_tax_value=((0.004*prop_value)+50);document.form.land_tax.value=land_tax_value;}}else if(province=="Northwest Territories"){if(prop_value<=1000000){land_tax_value=((0.0015*prop_value)+40);document.form.land_tax.value=land_tax_value;}else if(prop_value>1000000){land_tax_value=(0.001*prop_value);document.form.land_tax.value=land_tax_value;}}else if(province=="Nova Scotia"){if(prop_value!=0){land_tax_value=(0.0005*prop_value);document.form.land_tax.value=land_tax_value;}}else if(province=="Ontario"){if(prop_value<=55000){land_tax_value=(0.005*prop_value);document.form.land_tax.value=land_tax_value;}else if(prop_value>55000&&prop_value<=250000){land_tax_value=((0.01*prop_value)-275);document.form.land_tax.value=land_tax_value;}else if(prop_value>250000&&prop_value<=400000){land_tax_value=((0.015*prop_value)-1525);document.form.land_tax.value=land_tax_value;}else if(prop_value>400000){land_tax_value=((0.02*prop_value)-3525);document.form.land_tax.value=land_tax_value;}}else if(province=="Prince Edward Island"){if(prop_value>500){land_tax_value=(0.01*prop_value);document.form.land_tax.value=land_tax_value;}else{land_tax_value=0;document.form.land_tax.value=land_tax_value;}}else if(province=="Quebec"){if(prop_value<=50000){land_tax_value=(0.005*prop_value);document.form.land_tax.value=land_tax_value;}else if(prop_value>50000&&prop_value<=250000){land_tax_value=((0.01*prop_value)-250);document.form.land_tax.value=land_tax_value;}else if(prop_value>250000){land_tax_value=((0.015*prop_value)-1500);document.form.land_tax.value=land_tax_value;}}else if(province=="Saskatchewan"){if(prop_value<=1000){land_tax_value="0";document.form.land_tax.value=land_tax_value;}else if(prop_value>1000){land_tax_value=((0.0015*prop_value)+15);document.form.land_tax.value=land_tax_value;}}else if(province=="Yukon Territory"){if(prop_value<=10000){land_tax_value=(0.001*prop_value);document.form.land_tax.value=land_tax_value;}else if(prop_value>10000&&prop_value<=25000){land_tax_value=(0.005*prop_value);document.form.land_tax.value=land_tax_value;}else if(prop_value>25000){land_tax_value=(0.0025*prop_value);document.form.land_tax.value=land_tax_value;}}}}
function map_DoFSCommand(command,arg){if(command=="show")doshow(arg);if(command=="select")dozns(arg);}
function doshow(arg){var isInternetExplorer=navigator.appName.indexOf("Microsoft")!=-1;var Obj=isInternetExplorer?document.all.dis_detail:document.dis_detail;Obj.SetVariable("_root.zid",arg);}
function send(str){var isInternetExplorer=navigator.appName.indexOf("Microsoft")!=-1;var mapObj=isInternetExplorer?document.all.dis:document.dis;mapObj.SetVariable("_root.zid",str);}
function removeitem(_obj){if(_obj.selectedIndex==-1)return;var str=dis_search.elements['zns[]'].options[_obj.selectedIndex].innerHTML;send(str);dis_search.elements['zns[]'].removeChild(dis_search.elements['zns[]'].options[_obj.selectedIndex]);}
function dis_DoFSCommand(command,arg){if(command=="show")doshow(arg);if(command=="select")dozns(arg);}
function dozns(arg){var find=0;for(i=0;i<dis_search.elements['zns[]'].options.length;i++){if(arg==dis_search.elements['zns[]'].options[i].value){dis_search.elements['zns[]'].removeChild(dis_search.elements['zns[]'].options[i]);find=1;break;}}
if(find==0){var oNewNode=document.createElement("OPTION");dis_search.elements['zns[]'].appendChild(oNewNode);oNewNode.text=arg;oNewNode.value=arg;oNewNode.selected=true;oNewNode.style.color='red';}}
function selectall(){var i;for(i=0;i<dis_search.elements['zns[]'].options.length;i++){dis_search.elements['zns[]'].options[i].selected=true;}
if(i>0&&i<6){return true;}else{alert("請選擇 1-5 個區域");return false;}}
function dis_submit(){if(selectall())dis_search.submit();}
function compare_select(obj){compare=document.getElementById("search");if(obj.checked){var strHTML;strHTML="<div id='c"+obj.value+"' style='float:left;width:122px;100px;margin:2px;text-align:center'><img src='pics/"+obj.value+"_1.jpg' width='120' height='82' border='1' onerror=\"this.src='pics/default.jpg';\">";strHTML+="<br><span class='m_c_t'  onclick=\"opendetail('"+search.elements['houseclass'].value+"','"+obj.value+"');\">詳情</span>";	strHTML+="<span class='m_c_t' onclick=\"tb_c_del(c"+obj.value+");\">刪除</span>";strHTML+="<input type='hidden' name='mls[]' value='"+obj.value+"'>";	strHTML+="</div>";div_m_c.innerHTML= strHTML + div_m_c.innerHTML;}else{document.getElementById("c"+obj.value).removeNode(true);}}
function tb_c_del(obj){obj.removeNode(true);if(document.getElementsByName("ml").length>0){for(i=0;i<document.getElementsByName("ml").length;i++){if(document.getElementsByName("ml")[i].value==obj.id.substr(1)){document.getElementsByName("ml")[i].checked=false;return;}}}}
function housetype_change_housestyle(obj){if(search.housetype.selectedIndex>17){search.housestyle.selectedIndex=18;}else{search.housestyle.selectedIndex=0;}}
function broker(str){window.open('broker.php?id='+str,'','width=700,height=600,scrollbars=1');}
function rdl_play(str){oParentDiv=document.all("idParentDiv");with(oParentDiv){if(children[0].style.visibility=="hidden"){children[1].style.visibility="visible";big_1.src=str;}else{children[1].style.visibility="hidden";big_2.src=str;}
filters[0].Apply();if(children[0].style.visibility=="hidden")children[0].style.visibility="visible";else children[0].style.visibility="hidden";if(children[1].style.visibility=="hidden")children[1].style.visibility="visible";else children[1].style.visibility="hidden";filters[0].play();}}
function tabchoose(obj){if(obj.className =='btab'){if(obj.id == 'at'){at.className='atab';bt.className='btab';tab_at.style.display='block';tab_bt.style.display='none';}else{bt.className='atab';at.className='btab';tab_bt.style.display='block';tab_at.style.display='none';}}}function tellfreind(mls,housetype){window.open('tellfriend.php?housetype='+housetype+'&mls='+mls,'',"width=540,height=370,scrollbars=1,status=no");}function openmap(lat,lng){window.open("map.php?lat="+lat+"&lng="+lng,"_blank","width=440,height=330");};

