//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(559000,154900,161900,34000,250000,210000,799000,220000,149900,257500,1295000,359000,89900,309430,38900,149600,79000,11250,129900,119900,40000,144900,75900,249000,325000,109900,174900,13000,79500,250000,999900,116375,159900,144900,294900,109900,149000,110000,84000,384995,104000,189900,189900,139900,135000,269000,27900,165000,179900,89050,165900,72500,154800,183000,129900,99900,1000,215000,179000,239900,95535,185000,159900,472000,175000,234900,152365,59900,135900,22975000,95000,304000,474300,795000,139900,324900,499900,124000,159900,47500,119000,170000,29000,209900,210000,147900,214900,198000,159000,286900,355000,114000,199000,64900,12000,159900,175000,392500,12500000,47500,128900,98000,89900,235000,218500,152500,147300,130000,170000,167900,908850,129000,134900,7000,134900,24900,119900,228900,745000,199900,239000,199000,339900,70000,219300,239900,334900,157900,147500,1650000,114900,925000,373900,249000,75000,109000,124900,100900,34900,22000,500000,300000,259900,279900,67900,87500,425000,7950000,75000,490000,95000,40000,199900,1000,169900,79500,36900,69900,144500,1995000,74900,47900,139000,185900,109395,225000,49500,135000,189500,239000,489900,170725,147500,32900,67900,129900,134900,179000,109900,2995000,2900000,-1);var maxComms=new Array(12575000,4850000,4995000,399000,1600000,539900,1795000,3495000,689500,300000,840000,3795000,1975000,359000,625000,798000,159000,699000,849000,659000,499000,2590000,329900,1995000,400000,1150000,1595000,899000,2499999,385000,199000,2989000,2495000,1174000,535900,2989000,4400000,599000,495000,549900,529000,697995,229000,439000,875000,476000,399990,369000,499500,349000,1600000,349900,239990,6350000,293000,939000,569800,395000,649900,1450000,499999,875000,499000,299900,2500000,1195000,3950000,17700000,449000,397900,475000,379000,447900,2999990,8495000,595000,631900,649000,5995000,359000,610000,6300000,879900,626916,600000,725000,274500,339900,1199000,745000,559778,375000,599000,2400000,924900,7999500,1109000,300000,1695000,1195000,3299000,975000,419000,17700000,6900000,2950000,9950000,1749000,499000,979900,599000,925000,17700000,345000,375900,429000,3750000,435900,2999000,3975000,699000,8495000,995900,545000,950000,611100,18000000,419000,718900,699900,999000,1799900,219300,1650000,545000,362000,2900000,800000,2195000,798900,5950000,798767,439000,4995000,454000,439900,5750000,4600000,22975000,995000,3950000,1825000,589000,1875000,989900,7950000,8750000,1200000,5999999,1099000,175000,13900000,399000,1500000,7900000,8500000,259000,19950000,376000,139500,4495000,244000,795000,1595000,4495000,5400000,555000,3400000,115000,474900,1250000,-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;});}}