//Created by Cory Gagliardi. Copyright 2006 Sullivan
function setBedrooms(cBox){var box;var index;var other;var i;if(cBox.value=='0'&&cBox.checked){for(i=1;i<=5;++i){box=document.getElementById("bedrooms"+i);box.checked=false;}}else if(cBox.value!='0'&&cBox.checked){box=document.getElementById("bedrooms");box.checked=false;index=Number(cBox.value);other=false;for(i=1;i<index&&!other&&i<=5;++i){box=document.getElementById("bedrooms"+i);if(box.checked)other=Number(box.value);}
if(other){for(i=other+1;i<index;++i){box=document.getElementById("bedrooms"+i);box.checked=true;}}else{for(i=index+1;i<=5&&!other;++i){box=document.getElementById("bedrooms"+i);if(box.checked)other=Number(box.value);}
if(other){for(i=index+1;i<other;++i){box=document.getElementById("bedrooms"+i);box.checked=true;}}}}else{setPreference(cBox,'bedrooms',5);}}
function showHideCondo(box){if(box.checked){condoExpander.start({'height':152,'opacity':1});}else{condoExpander.start({'height':0,'opacity':0});}}
var minprice='';var maxprice='';var minComms=new Array(499000,140000,149000,29900,250000,210000,829900,220000,149900,239000,1295000,359000,84900,309430,38900,149900,79000,11250,129900,129900,40000,144900,79900,230000,280000,109900,169900,13000,89500,259900,999900,116375,159900,144900,294900,109900,118900,99000,71500,384995,99000,189900,189900,139900,135000,283900,27900,165000,179900,89050,165900,72500,154800,183000,129900,99900,119900,215000,179000,239900,95535,185000,159900,375000,175000,234900,152365,59900,135900,22975000,95000,304000,474300,795000,129900,324900,499900,124000,159900,47500,119000,150000,29000,209900,210000,139900,214900,179000,159000,221100,355000,89900,159920,64900,12000,159900,175000,392500,12500000,45600,109900,75000,89900,225000,218500,134900,147300,169000,179900,139900,908850,75000,134900,7000,129900,24900,119900,228900,695000,199900,209000,2000,309900,70000,3600000,219900,299000,139900,139900,1325000,114900,875000,373900,249000,74500,109000,124900,100900,34900,19900,550000,249900,550000,279900,55900,87500,425000,4595000,149900,399000,95000,34995,189900,9000,169900,62000,36900,69900,129900,1750000,74900,47900,139000,180000,105900,225000,39900,211613,142500,219000,436108,170725,127000,32900,67900,129900,149000,179000,109900,2895000,2900000,2925000,-1);var maxComms=new Array(12575000,4850000,4895000,399000,699000,539900,1695000,2775000,689500,300000,840000,3795000,1875000,359000,699900,798000,159000,699000,799000,659000,499000,2590000,347000,1979000,499000,749000,1595000,899000,2499999,339000,178888,2997000,2495000,769000,560000,2997000,3729000,649900,495000,549900,499000,697995,229000,439000,675000,499000,399990,379000,399850,349900,1600000,399000,239990,6350000,293000,939000,579200,525000,599900,1450000,499999,675000,499000,299900,2500000,1195000,3750000,17700000,495000,397900,479900,379000,447900,2987000,8495000,595000,631900,649900,6395000,5995000,359000,559000,6499000,1192000,499000,600000,725000,269000,339900,1099000,699900,640000,375000,549900,2400000,924900,7999500,1370000,245000,1695000,1195000,3299000,975000,399900,17700000,6395000,2795000,9950000,1599000,499000,979900,484900,949500,17700000,345000,359000,429000,3750000,435900,2750000,3975000,559000,8495000,899000,499000,899000,611100,14000000,419000,718900,699900,999000,1799900,10495000,279000,510000,300000,2900000,859000,2495000,849000,5950000,798767,439000,4995000,454000,419000,5700000,4600000,22975000,995000,3695000,2450000,589000,1695000,989900,4595000,8750000,1200000,5950000,1099000,175000,13900000,389000,1500000,7900000,8500000,270000,23000000,376000,139500,6900000,244000,1175000,1595000,4995000,5400000,599000,3400000,139000,438900,1695000,-1);function filterComms(){var newminprice=document.getElementById('minprice').value;var newmaxprice=document.getElementById('maxprice').value;var newtargetprice=$('targetprice').value;if(newtargetprice&&!newminprice&&!newmaxprice){newminprice=parseInt(removeChar(newtargetprice,','));newmaxprice=parseInt(removeChar(newtargetprice,','));}else{if(newminprice==''){newminprice=0;}else{newminprice=parseInt(removeChar(newminprice,','));}
if(newmaxprice==''){newmaxprice=Number.MAX_VALUE;}else{newmaxprice=parseInt(removeChar(newmaxprice,','));}}
var size=minComms.length-1;if(newmaxprice!=maxprice||newminprice!=minprice){maxprice=newmaxprice;minprice=newminprice;if(!isNaN(minprice)&&!isNaN(maxprice)){for(i=0;i<size;++i){if(maxprice<minComms[i]||minprice>maxComms[i]){document.getElementById('cl'+i.toString()).style.color='#888';}else{document.getElementById('cl'+i.toString()).style.color='black';}}}}}
function removeChar(str,char){var pos;while((pos=str.indexOf(char))!==-1){if(str.length==1){str='';}else if(pos==0){str=str.substring(1,str.length);}else if(pos==str.length-1){str=str.substring(0,pos);}else{str=str.substring(0,pos)+str.substring(pos+1,str.length);}}
return str;}
function setRange(c,lower,upper){var minchoice=document.getElementById(lower);var maxchoice=document.getElementById(upper);if(minchoice.selectedIndex>=maxchoice.selectedIndex&&maxchoice.selectedIndex!=0&&minchoice.selectedIndex!=0){if(minchoice.selectedIndex==maxchoice.length-1&&minchoice==c)maxchoice.selectedIndex=0;else
if(c==minchoice)maxchoice.selectedIndex=minchoice.selectedIndex+1;else minchoice.selectedIndex=maxchoice.selectedIndex-1;}}
function setPreference(c,name,count){var i;var box;if(c.checked){if(c==document.getElementById(name))
for(i=1;i<=count;++i)
document.getElementById(name+i).checked=false;else
document.getElementById(name).checked=false;}else{if(c==$(name))
c.checked=true;else{var anyChecked;for(i=1;i<=count&&!anyChecked;++i)
anyChecked=$(name+i).checked;if(!anyChecked)
$(name).checked=true;}}}
function fakeRadio(c,other){if(c.checked&&$(other).checked){$(other).checked=false;}}
function setWhere(hiddenVal,show,hide1,hide2){$('whereby').value=hiddenVal;$(show).style.display='block';$(hide1).style.display='none';$(hide2).style.display='none';$(currentWhere).removeClass('current');currentWhere='W'+hiddenVal;$('W'+hiddenVal).addClass('current');}
function setC(w){if(w.checked){if(w.value=='0'){$$('#whereComm td input').each(function(a){a.checked=false});w.checked=true;}else{$('c_nopref').checked=false;}}else{if(w.value=='0')
w.checked=true;else{var anyChecked;var allComms=$$('#whereComm td input');for(i=1;i<allComms.length&&!anyChecked;++i)
anyChecked=allComms[i].checked;if(!anyChecked)
$('c_nopref').checked=true;}}}
function setB(w){if(w.checked){if(w.value=='0'){$$('#whereBeach input').each(function(a){a.checked=false;});w.checked=true;}else{$('b_nopref').checked=false;}}else{if(w.value=='0')
w.checked=true;else{var anyChecked;var allComms=$$('#whereBeach input');for(i=1;i<allComms.length&&!anyChecked;++i)
anyChecked=allComms[i].checked;if(!anyChecked)
$('b_nopref').checked=true;}}}
function setBT(w,titleId){if(w.id.contains('beachtitle')){if(w.checked)
$$('#whereBeach input.bt'+titleId).each(function(a){a.checked=true;});else
$$('#whereBeach input.bt'+titleId).each(function(a){a.checked=false;});}else{if(w.checked){var allChecked=true;$$('#whereBeach input.bt'+titleId).each(function(a){allChecked=allChecked&&a.checked;});if(allChecked){$('beachtitle'+titleId).checked=true;}}else{$('beachtitle'+titleId).checked=false;}}
setB(w);}
function resetForm(){var intext=['minprice','maxprice','targetprice','yearbuilt'];intext.each(function(a){$(a).value=''});$('floor').checked=true;$('endunit').checked=true;$('bedrooms').checked=true;setBedrooms($('bedrooms'));var prefs=[['proptype_condo',3],['proptype_code',4],['rearexp',4],['furnished',3],['area',6]];prefs.each(function(a){$(a[0]).checked=true;setPreference($(a[0]),a[0],a[1])});var opts=['minsqft','maxsqft','newconstruction'];opts.each(function(a){$(a).selectedIndex=0});$('c_nopref').checked=true;setC($('c_nopref'));var uncheck=['view1','view2','view3','view4','view5','pool','spa','gated','golf','tennis','gulf'];uncheck.each(function(a){$(a).checked=false});$$('#whereBeach input').each(function(a){$(a).checked=false});$('b_nopref').checked=false;quickResetForm();scroller=new Fx.Scroll(window,{duration:600});(function(){scroller.scrollTo(0,$('searchform').getTop()-7)}).delay(150);}
function quickResetForm(){setWhere('area','whereArea','whereComm','whereBeach');}
function loadSearchDom(){condoExpander=new Fx.Styles($('condopr'),{duration:500,wait:false});var prices=[['100,000','100000'],['125,000','125000'],['150,000','150000'],['175,000','175000'],['200,000','200000'],['225,000','225000'],['250,000','250000'],['275,000','275000'],['300,000','300000'],['325,000','325000'],['350,000','350000'],['375,000','375000'],['400,000','400000'],['425,000','425000'],['450,000','450000'],['475,000','475000'],['500,000','500000'],['525,000','525000'],['550,000','550000'],['575,000','575000'],['600,000','600000'],['625,000','625000'],['650,000','650000'],['675,000','675000'],['700,000','700000'],['725,000','725000'],['750,000','750000'],['775,000','775000'],['800,000','800000'],['825,000','825000'],['850,000','850000'],['875,000','875000'],['900,000','900000'],['925,000','925000'],['950,000','950000'],['975,000','975000'],['1,000,000','1000000'],['1,200,000','1200000'],['1,400,000','1400000'],['1,600,000','1600000'],['1,800,000','1800000'],['2,000,000','2000000'],['2,200,000','2200000'],['2,400,000','2400000'],['2,600,000','2600000'],['2,800,000','2800000'],['3,000,000','3000000'],['3,200,000','3200000'],['3,400,000','3400000'],['3,600,000','3600000'],['3,800,000','3800000'],['4,000,000','4000000'],['4,200,000','4200000'],['4,400,000','4400000'],['4,600,000','4600000'],['4,800,000','4800000'],['5,000,000','5000000']];var completers=['minprice','maxprice','targetprice'];completers.each(function(completer){new Autocompleter.Local($(completer),prices,{'delay':50,'filterTokens':function(){var regex=new RegExp('^'+this.queryValue.escapeRegExp(),'i');return this.tokens.filter(function(token){return(regex.test(token[0])||regex.test(token[1]));});},'injectChoice':function(choice){var el=new Element('li').setHTML(this.markQueryValue(choice[0]));el.inputValue=choice[0];this.addChoiceEvents(el).injectInside(this.choices);},'onSelect':function(){filterComms();},'minLength':1});});if(currentComms.length){currentComms.each(function(c){$('c'+c).checked=true;});}
if(currentBeachfs.length){currentBeachfs.each(function(c){$('b'+c).checked=true;});}}