function SearchWidgetHandler(b,a){this.myId=b;this.parent=a;this.searchOption=-1;this.searchPriceFrom=0;this.searchPriceTo=0;this.searchKeyWord="";this.searchItemList="";this.searchdirectionTypeList="";this.bedroomBox=0;this.bathroomBox=0;this.builtUpBox=0;this.queryObj={};this.propertyTypeList=[];this.myView=new SearchWidget(b,a,this.callbackHandler,this);this.activeView="basic";this.init();this.load()}SearchWidgetHandler.prototype.init=function(){reapfield.G_EventMgr.registerEvent("newModuleLoaded",this,"moduleLoadedListener");reapfield.G_EventMgr.registerEvent("allPropertyTypesListArrived",this,"getPropertyTypeListDataListener");reapfield.G_EventMgr.registerEvent("allDirectionTypesListArrived",this,"allDirectionTypesListListener");reapfield.G_EventMgr.registerEvent("getPropertySearchResultListDataArrived",this,"propertyListDataListener");reapfield.G_EventMgr.registerEvent("propertySubTypesListArrived",this,"propertySubTypesListArrivedListener");reapfield.G_EventMgr.registerEvent("getPropertySubTypeListDataEvents",this,"getAllPropertySubTypeListener")};SearchWidgetHandler.prototype.load=function(){this.myView.loadView(this.activeView);if(reapfield.G_API.propertyTypeList.length<=0){reapfield.G_API.getAllPropertyTypesList();reapfield.G_API.getlistallpropertysubtypes()}else{this.getAllPropertySubType();this.myView.createPropertyTypeDropDown(this.propertyTypeList)}if(reapfield.G_API.directionTypeList.length<=0){reapfield.G_API.getAllDirectionTypesList()}else{if(this.activeView=="advance"){this.myView.createDirectionTypeDropDown(reapfield.G_API.directionTypeList)}}};SearchWidgetHandler.prototype.getAllPropertySubTypeListener=function(){if(reapfield.G_API.propertyTypeList.length<=0){reapfield.G_API.getAllPropertyTypesList();reapfield.G_API.getlistallpropertysubtypes()}else{this.getAllPropertySubType();this.myView.createPropertyTypeDropDown(this.propertyTypeList)}};SearchWidgetHandler.prototype.getAllPropertySubType=function(){var c=reapfield.G_API.propertyTypeList,g=reapfield.G_API.propertySubTypeList,e=[];for(var b=0;b<c.length;b++){var d=c[b].propertytype_propertytypeid,a="-- All "+c[b].propertytype_propertytype+" --";e.push({id:d,name:a,isSubType:false});for(var f=0;f<g.length;f++){if(g[f].propertytypeid==d){e.push({id:g[f].propertysubtypeid,name:g[f].propertysubtype,isSubType:true})}}}this.propertyTypeList=e};SearchWidgetHandler.prototype.propertyListDataListener=function(b){var a=reapfield.G_ViewMgr.activeModule;this.queryObj=a.queryObj;if(this.queryObj.searchPriceFrom&&this.queryObj.searchPriceFrom!=""){document.getElementById("advanceSearchPriceFrom").value=this.queryObj.searchPriceFrom}if(this.queryObj.searchPriceTo&&this.queryObj.searchPriceTo!=""){document.getElementById("advanceSearchPriceto").value=this.queryObj.searchPriceTo}if(this.queryObj.propertyType&&this.queryObj.propertyType>=0){this.selectDropDown(document.getElementById("propertyTypeList"),this.queryObj.propertyType,"type")}else{if(this.queryObj.propertySubType&&this.queryObj.propertySubType>0){this.selectDropDown(document.getElementById("propertyTypeList"),this.queryObj.propertySubType,"subtype")}}};SearchWidgetHandler.prototype.propertySubTypesListArrivedListener=function(a){if(reapfield.G_ViewMgr.LayoutMgr.activeLayout=="landing"){return}this.myView.showSubTypes(a.data);if(this.queryObj.propertySubType&&this.queryObj.propertySubType>0){this.selectDropDown(document.getElementById(this.myView.propertySubTypeListId),this.queryObj.propertySubType)}};SearchWidgetHandler.prototype.selectDropDown=function(e,d,c){for(var b=1;b<e.options.length;b++){var a=this.getPropertyType(b);if(e.options[b].value==d&&c==a){e.selectedIndex=b;break}}};SearchWidgetHandler.prototype.moduleLoadedListener=function(a){var b=this.activeView;if(a.data=="loadBasicView"||a.data!="searchResultlist"){this.activeView="basic"}else{this.activeView="advance"}if(b!=this.activeView){this.load()}};SearchWidgetHandler.prototype.allDirectionTypesListListener=function(a){if(this.activeView=="advance"&&reapfield.G_API.directionTypeList.length>0){this.myView.createDirectionTypeDropDown(reapfield.G_API.directionTypeList)}};SearchWidgetHandler.prototype.getPropertyTypeListDataListener=function(a){if(reapfield.G_API.propertyTypeList.length<=0){reapfield.G_API.propertyTypeList=a.data}this.myView.createPropertyTypeDropDown(reapfield.G_API.propertyTypeList)};SearchWidgetHandler.prototype.createQueryObj=function(a,f){var g=this;if(f=="advanceSearchDivSubmit"){var e=new Object();this.queryObj.searchPriceFrom="";this.queryObj.searchPriceTo="";this.queryObj.propertyType="";this.queryObj.noOfBed="";this.queryObj.noOfBath="";this.queryObj.builtUpArea="";this.queryObj.directiontype="";if(a.advanceSearchPriceFrom.value!="Price From"&&parseInt(a.advanceSearchPriceFrom.value)>0){this.queryObj.searchPriceFrom=a.advanceSearchPriceFrom.value}if(a.advanceSearchPriceto.value!="Price To"&&parseInt(a.advanceSearchPriceto.value)>0){this.queryObj.searchPriceTo=a.advanceSearchPriceto.value}var c=a.propertyTypeList;var b=this.getPropertyType(c.selectedIndex);if(b=="type"){this.queryObj.propertyType=c.value}else{if(b=="subtype"){this.queryObj.propertySubType=c.value}}if(a.bedroomBox.value!="Bedrooms"&&parseInt(a.bedroomBox.value)>0){this.queryObj.noOfBed=a.bedroomBox.value}if(a.bathroomBox.value!="Bathrooms"&&parseInt(a.bathroomBox.value)>0){this.queryObj.noOfBath=a.bathroomBox.value}if(a.builtupArea.value!="Bathrooms"&&parseInt(a.builtupArea.value)>0){this.queryObj.builtUpArea=a.builtupArea.value}if(a.directionType.value>0){this.queryObj.directiontype=a.directionType.value}}else{if(f=="quickSearchDivSubmit"){e=new Object();this.queryObj={};var d=0;if(a.searchtypeOptionBuy.checked){this.queryObj.searchOption=a.searchtypeOptionBuy.value}else{if(a.searchtypeOptionRent.checked){this.queryObj.searchOption=a.searchtypeOptionRent.value}}if(a.quickSearchkeyword.value!="Location Keyword"){this.queryObj.locationKeyword=a.quickSearchkeyword.value}var c=a.propertyTypeList;if(c.selectedIndex>0){var b=this.getPropertyType(c.selectedIndex);if(b=="type"){this.queryObj.propertyType=c.value}else{if(b=="subtype"){this.queryObj.propertySubType=c.value}}}if(a.quickSearchPriceFrom.value!="Price From"&&parseInt(a.quickSearchPriceFrom.value)>0){this.queryObj.searchPriceFrom=a.quickSearchPriceFrom.value}if(a.quickSearchPriceto.value!="Price To"&&parseInt(a.quickSearchPriceto.value)>0){this.queryObj.searchPriceTo=a.quickSearchPriceto.value}}}};SearchWidgetHandler.prototype.getPropertyType=function(a){var b="type";if(this.propertyTypeList[a-1].isSubType){b="subtype"}return b};SearchWidgetHandler.prototype.callbackHandler=function(d,c,a){if(d=="quickSearchDivSubmit"||d=="advanceSearchDivSubmit"){a.createQueryObj(c,d);var b={moduleId:"43",detailId:a.queryObj};reapfield.G_EventMgr.fireEvent("loadModuleEvent",b)}else{if(d=="propertyChangeEvent"){if(c==1){reapfield.G_API.listPropertySubTypes(c)}else{a.myView.hideSubTypes();a.queryObj.propertySubType=0}}}};function SearchWidget(c,b,d,a){this.myId=c;this.parent=b;this.callbackFn=d;this.owner=a;this.quickSearchId="quickSearch";this.middleSectionId="middleSection";this.advanceSearchid="advanceSearchid";this.quickSearchDivId="quickSearchDivId";this.quickSearchPriceFrom="quickSearchPriceFrom";this.quickSearchPriceto="quickSearchPriceto";this.quickSearchkeyword="quickSearchkeyword";this.propertyTypeDiv="propertyTypeDiv";this.propertyTypeList="propertyTypeList";this.searchtypeOptionBuy="searchtypeOptionBuy";this.searchtypeOptionRent="searchtypeOptionRent";this.bedRoomBoxId="bedroomBox";this.bathRoomBoxId="bathroomBox";this.builtUpAreaBoxId="builtupArea";this.directionTypeDiv="directionTypeDiv";this.directionType="directionType";this.advanceSearchPriceFrom="advanceSearchPriceFrom";this.advanceSearchPriceto="advanceSearchPriceto";this.propertySubTypeDivId="propertySubTypeContainer";this.propertySubTypeListId="propertysubtypeid"}SearchWidget.prototype.loadView=function(a){trace(a);try{if(a=="basic"){this.createBasicView()}else{if(a=="advance"){this.createAdvanceView()}}}catch(b){alert(b)}};SearchWidget.prototype.createBasicView=function(){var b='<div class="quickSearchTop"></div>						<div class="quickSearchContent">						<form name="'+this.quickSearchDivId+'" id="'+this.quickSearchDivId+'">							<div class="quickSearchTitle">New Search</div>							<div class="quickSearchOptBtn">								<input type="radio" id="'+this.searchtypeOptionBuy+'" name="searchtypeOption"  value="1" /><span class="searchTypeLabel">Buy</span>								<input type="radio" id="'+this.searchtypeOptionRent+'" name="searchtypeOption"  value="2" /><span class="searchTypeLabel">Rent</span>							</div>							<input type="text" id="'+this.quickSearchkeyword+'" name="'+this.quickSearchkeyword+'" value="Location Keyword" class="quickSearchTextFields" /><br />							<div class="quickSearchFields">								<div id="'+this.propertyTypeDiv+'" class="reapFieldAgentSearch" style="vertical-align:middle;">									<select name="propertyTypeDivId" id="propertyTypeDivId" >										<option value="">-- Please Select --</option>									</select>								</div>							</div>							<div id="'+this.propertySubTypeDivId+'"></div>							<input type="text" id="'+this.quickSearchPriceFrom+'" class="quickSearchTextFields" value="Price From"><br/>							<input type="text" id="'+this.quickSearchPriceto+'" class="quickSearchTextFields" value="Price To"><br />							<input type="submit" value="Search" class="quickSearchBtn reapFieldCommonBtn" />						</form></div>						<div class="quickSearchBottom">													</div>';this.parent.innerHTML=b;var d=document.getElementById(this.quickSearchPriceFrom);if(d){this.watermarkEventHandler(d,d.value)}var a=document.getElementById(this.quickSearchPriceto);if(a){this.watermarkEventHandler(a,a.value)}var c=document.getElementById(this.quickSearchkeyword);if(c){this.watermarkEventHandler(c,c.value)}this.eventHandler(document.getElementById(this.quickSearchDivId),"submit",this.callbackFn,this.owner)};SearchWidget.prototype.createAdvanceView=function(){var b='<div class="quickSearchTop"></div>						<div class="quickSearchContent">						<form name="'+this.advanceSearchid+'" id="'+this.advanceSearchid+'">							<div class="quickSearchTitle">Refine Search</div>							<input type="text" id="'+this.advanceSearchPriceFrom+'" class="quickSearchTextFields" value="Price From"><br/>							<input type="text" id="'+this.advanceSearchPriceto+'" class="quickSearchTextFields" value="Price To"><br />							<div class="quickSearchFields">								<div id="'+this.propertyTypeDiv+'" class="reapFieldAgentSearch" style="vertical-align:middle;">									<select name="propertyTypeDivId" id="propertyTypeDivId" >										<option value="">-- Please Select --</option>									</select>								</div>							</div>							<div id="'+this.propertySubTypeDivId+'"></div>							<input type="text" id="'+this.bedRoomBoxId+'" class="quickSearchTextFields" value="Bedrooms"><br />							<input type="text" id="'+this.bathRoomBoxId+'" class="quickSearchTextFields" value="Bathrooms"><br />							<input type="text" id="'+this.builtUpAreaBoxId+'" class="quickSearchTextFields" value="Build up area"><br />							<div id="'+this.directionTypeDiv+'" class="reapFieldAgentSearch" style="vertical-align:middle;">								<select name="directionType" id="directionType" >									<option value="">-- Please Select --</option>								</select>							</div>							<input type="submit" value="Search" class="quickSearchBtn reapFieldCommonBtn" />						</form></div>						<div class="quickSearchBottom">						</div>';this.parent.innerHTML=b;var a=document.getElementById(this.advanceSearchPriceFrom),c=document.getElementById(this.advanceSearchPriceto),f=document.getElementById(this.bedRoomBoxId),d=document.getElementById(this.bathRoomBoxId),e=document.getElementById(this.builtUpAreaBoxId);if(a){this.watermarkEventHandler(a,a.value)}if(c){this.watermarkEventHandler(c,c.value)}if(f){this.watermarkEventHandler(f,f.value)}if(d){this.watermarkEventHandler(d,d.value)}if(e){this.watermarkEventHandler(e,e.value)}this.eventHandler(document.getElementById(this.advanceSearchid),"submit",this.callbackFn,this.owner)};SearchWidget.prototype.createPropertyTypeDropDown=function(b,a){document.getElementById(this.propertyTypeDiv).innerHTML=this.createDropDownList(b,"id","name",this.propertyTypeList,"Search By Property","Property Type");this.eventHandler(document.getElementById(this.propertyTypeList),"change",this.callbackFn,this.owner)};SearchWidget.prototype.createDirectionTypeDropDown=function(a){if(document.getElementById(this.directionTypeDiv)){document.getElementById(this.directionTypeDiv).innerHTML=this.createDropDownList(a,"directiontype_directiontypeid","directiontype_directiontype",this.directionType,"Search By Direction","Direction")}};SearchWidget.prototype.showSubTypes=function(a){var b=document.getElementById(this.propertySubTypeDivId);b.innerHTML=this.createDropDownList(a,"id","name",this.propertyTypeList,"Property Type");b.innerHTML=this.createDropDownList(a,"propertysubtype_propertysubtypeid","propertysubtype_propertysubtype",this.propertySubTypeListId,"Property Subtype","Property Subtype");b.className="quickSearchFields"};SearchWidget.prototype.hideSubTypes=function(a){var b=document.getElementById(this.propertySubTypeDivId);b.innerHTML="";b.className=""};SearchWidget.prototype.createDropDownList=function(b,k,d,c,h,e){var f='<select name="'+c+'" id="'+c+'" class="quickSearchFields">';if(e){f+='<option  value="0">'+e+"</option>"}for(var j=0;j<b.length;j++){var a=b[j],i=a[k],g=(a[d]||"");f+='<option  value="'+i+'"';if(i==h){f+=" selected"}f+=">"+g+"</option>"}f+="</select> ";return f};SearchWidget.prototype.eventHandler=function(d,b,f,a){var e=this;function c(i){if(!i){i=window.event}if(d.id==e.advanceSearchid){f("advanceSearchDivSubmit",d,a);if(i.preventDefault){i.preventDefault()}i.returnValue=false;return false}else{if(d.id==e.quickSearchDivId){var h=d.quickSearchkeyword,g=(h.value!="Location Keyword")?h.value:"";if(g){if(g.length>2){f("quickSearchDivSubmit",d,a)}else{alert("Please enter atleast 3 characters in location");h.focus()}}else{alert("Please key in a location");h.focus()}if(i.preventDefault){i.preventDefault()}i.returnValue=false;return false}else{if(d.id==e.propertyTypeList){f("propertyChangeEvent",d.value,a)}}}}if(d){reapfield.AttachEvent(d,b,c,false,"search1")}};SearchWidget.prototype.watermarkEventHandler=function(d,b){var e=this;function a(h){var f=b;var g=d;g.style.color="#222";g.value=(d.value==f)?"":d.value}function c(f){e.blurAssignText(d,b)}reapfield.AttachEvent(d,"focus",a,false,"search2");reapfield.AttachEvent(d,"blur",c,false,"search3")};SearchWidget.prototype.blurAssignText=function(c,b){var a=b;if(c.value==""){c.value=a;c.style.color="#999"}else{if(c.value==a){c.style.color="#999"}else{c.style.color="#222"}}};