var showPromotedLocation=true; var deepPromotedIncluded = true; $j = jQuery.noConflict(); $j(document).ready(function(){ $j("#btnNavSearch").click(function(){ $j.facebox($j("#popupSearch").html()); searchPopupBox.UseFreshCountryData = true; searchPopupBox.SubmitURL = '/property/search/'; searchPopupBox.AutoPriceIndexSelect = true; searchPopupBox.Init(); $j(searchPopupBox.KeywordsTextBox).hide(); $j(searchPopupBox.MinBedDropDown).show(); $j(searchPopupBox.MaxBedDropDown).show(); $j(searchPopupBox.RegionDropDown).hide(); $j('#facebox #searchPopupPropertyID').show(); $j('#facebox #searchPopupPropertyName').hide(); $j(searchPopupBox.MinBedDropDown).hide(); $j(searchPopupBox.MaxBedDropDown).hide(); $j(searchPopupBox.CurrencyDropDown).after(searchPopupBox.CountryDropDown); $j(searchPopupBox.MinPriceDropDown).after(searchPopupBox.AutoCompleteTextBox); $j(searchPopupBox.MaxPriceDropDown).after($j('#facebox #searchPopupPropertyID')); $j('#facebox #searchPopupForm').show(); Utils.DropDownSelect(searchPopupBox.CurrencyDropDown,'USD'); $j(searchPopupBox.CurrencyDropDown).click(); searchPopupBox.SelectedCurrencyCode = $j("option:selected",searchPopupBox.CurrencyDropDown).val(); //alert(searchPopupBox.SelectedCurrencyCode); searchPopupBox.UpdateSubmitButton(); if(searchPopupBox.SelectedCurrencyCode=='GBP'||searchPopupBox.SelectedCurrencyCode=='EUR'||searchPopupBox.SelectedCurrencyCode=='USD'){ //alert(searchPopupBox.SelectedCurrencyCode); searchPopupBox.ExchangeRate = Utils.getCurrencyRateByCurrency(searchPopupBox.SelectedCurrencyCode); searchPopupBox.CurrencyCode = searchPopupBox.SelectedCurrencyCode; }else{ searchPopupBox.ExchangeRate = parseInt(Utils.getCurrencyRate($j("option:selected",searchPopupBox.CountryDropDown).text())); //alert(this.ExchangeRate); searchPopupBox.CurrencyCode = $j("option:selected",searchPopupBox.CurrencyDropDown).val(); } if(searchPopupBox.ExchangeRate==0){ExchangeRate=1;} searchPopupBox.FillMinPriceDropDown(); if($j(searchPopupBox.MinPriceDropDown).is(":disabled")){searchPopupBox.MinPriceDropDown.disabled=false;} searchPopupBox.MaxPriceDropDown.disabled=true; searchPopupBox.SelectedMixPrice = 0; searchPopupBox.SelectedMaxPrice = 0; if($j(searchPopupBox.MinBedDropDown).is(":disabled")){searchPopupBox.MinBedDropDown.disabled=false;} searchPopupBox.FillMinBedsDropDown(); }); // btnSearchNav.click }); // ready() var searchPopupBox = { Init:function(){ // objects searchPopupBox.CountryDropDown = $j('#facebox #selectPopupCountry')[0]; searchPopupBox.RegionDropDown = $j('#facebox #selectPopupRegion')[0]; searchPopupBox.MinPriceDropDown = $j('#facebox #selectPopupMinPrice')[0]; searchPopupBox.MaxPriceDropDown = $j('#facebox #selectPopupMaxPrice')[0]; searchPopupBox.MinBedDropDown = $j('#facebox #selectPopupMinBed')[0]; searchPopupBox.MaxBedDropDown = $j('#facebox #selectPopupMaxBed')[0]; searchPopupBox.CurrencyDropDown = $j('#facebox #selectPopupCurrency')[0]; searchPopupBox.AutoCompleteTextBox = $j('#facebox #searchPopupIntellLocation')[0]; searchPopupBox.PropertyNameTextBox = $j('#facebox #searchPopupPropertyName')[0]; searchPopupBox.ReferenceTextBox = $j('#facebox #searchPopupPropertyID')[0]; searchPopupBox.SubmitButton = $j('#facebox #searchPopupSubmit')[0]; searchPopupBox.MessageBox = $j('#facebox #searchPopupMessageBox')[0]; searchPopupBox.PriceUnitValueControl = $j('#facebox #ctr_searchPopupBox_PriceUnitValue'); searchPopupBox.KeywordsTextBox = $j('#facebox #ctr_searchPopupBox_Keywords'); // prepare Controls this.EnableMinControls(); // Watermark Controls $j('#facebox #searchIntellLocation').Watermark("Введите Месторасположение"); $j('#facebox #searchPropertyName').Watermark("Введите Название Недвижимости"); $j('#facebox #searchPropertyID').Watermark("Введите ID Недвижимости"); $j(searchPopupBox.KeywordsTextBox).Watermark("Введите ключевые слова"); // DataBind() aCountries=this.getCountries() this.FillDropDownCountriesLocal(aCountries,this.CountryDropDown); this.FillDropDownCountries(aCountries,this.CountryDropDown); this.FillDropDown(this.getCurrencies(),this.CurrencyDropDown); //this.FillDropDown(this.getPriceRanges(),this.MinPriceDropDown); //this.FillDropDown(this.getPriceRanges(),this.MaxPriceDropDown); //this.FillDropDown(this.getBedRanges(),this.MinBedDropDown); //this.FillDropDown(this.getBedRanges(),this.MaxBedDropDown); // events $j(this.SubmitButton).click(function(e){searchPopupBox.onSubmit(e);}); $j(this.CountryDropDown).change(function(e){searchPopupBox.onCountryChanged(e);}); $j(this.RegionDropDown).change(function(e){searchPopupBox.onRegionChanged(e);}); $j(this.CurrencyDropDown).change(function(e){searchPopupBox.onCurrencyChanged(e);}); $j(this.MinPriceDropDown).change(function(e){searchPopupBox.onMinPriceChanged(e);}); $j(this.MaxPriceDropDown).change(function(e){searchPopupBox.onMaxPriceChanged(e);}); $j(this.MinBedDropDown).change(function(e){searchPopupBox.onMinBedChanged(e);}); $j(this.MaxBedDropDown).change(function(e){searchPopupBox.onMaxBedChanged(e);}); // get current controls value this.SelectedCurrencyCode = $j("option:selected",this.CurrencyDropDown).val(); // auto complete $j(this.AutoCompleteTextBox).autocomplete('/tmc.system/tmc.services.locations.asp', { delay: 100, width: 400, scroll: false, formatItem: formatItem, formatResult: formatResult, selectFirst: true, extraParams: { country: "Myanmar", countryID: "", GetLocationsByPrefix:"a" } }); // auto complete for keywords $j(this.KeywordsTextBox).autocomplete('/tmc.system/tmc.services.locations.asp', { delay: 100, width: 400, scroll: false, formatItem: formatItem, formatResult: formatResult, selectFirst: true, extraParams: { country: "Myanmar", countryID: "", GetkeywordsByPrefix:"a" } }); $j(this.AutoCompleteTextBox).result(function(event,data,formatted){ //alert(data); var level = data[4]; var IDs; var regionID; //alert(data); IDs = data[3].split('_'); if(level==1){ regionID = data[2]; } else{ regionID = IDs[0]; } Utils.DropDownSelect(searchPopupBox.RegionDropDown,regionID); // set loation id searchPopupBox.SelectedLocationID = data[2]; }); }, onSubmit:function(e){ e.preventDefault(); //alert('submitting form now'); // now update form control with price bands index if (searchPopupBox.AutoPriceIndexSelect){ $j('#facebox #searchPopupForm #ctr_searchPopupBox_minPriceIndex').attr("value",searchPopupBox.MinPriceDropDown.selectedIndex); $j('#facebox #searchPopupForm #ctr_searchPopupBox_maxPriceIndex').attr("value",searchPopupBox.MaxPriceDropDown.selectedIndex); }else{ $j('#facebox #searchPopupForm #ctr_searchPopupBox_minPriceIndex').attr("value",-1); $j('#facebox #searchPopupForm #ctr_searchPopupBox_maxPriceIndex').attr("value",-1); } if (searchPopupBox.AutoBedroomIndexSelect){ $j('#facebox #searchPopupForm #ctr_searchPopupBox_minBedsIndex').attr("value",searchPopupBox.MinBedDropDown.selectedIndex); $j('#facebox #searchPopupForm #ctr_searchPopupBox_maxBedsIndex').attr("value",searchPopupBox.MaxBedDropDown.selectedIndex); }else{ $j('#facebox #searchPopupForm #ctr_searchPopupBox_minBedsIndex').attr("value",-1); $j('#facebox #searchPopupForm #ctr_searchPopupBox_maxBedsIndex').attr("value",-1); } $j('#facebox #searchPopupForm #ctr_searchPopupBox_countryName').attr("value",$j("option:selected",searchPopupBox.CountryDropDown).text()); $j('#facebox #searchPopupForm #ctr_searchPopupBox_countryID').attr("value",$j("option:selected",searchPopupBox.CountryDropDown).val()); $j('#facebox #searchPopupForm').attr("action",searchPopupBox.SubmitURL); $j('#facebox #searchPopupForm').attr("method",searchPopupBox.SubmitMethod); // now write searchFrom values to cookies var cookieContent; cookieContent = "country="+encodeURIComponent($j("option:selected",searchPopupBox.CountryDropDown).text()); cookieContent += "¤cy="+encodeURIComponent($j("option:selected",searchPopupBox.CurrencyDropDown).val()); cookieContent += "&minprice="+encodeURIComponent($j("option:selected",searchPopupBox.MinPriceDropDown).val()); cookieContent += "&maxprice="+encodeURIComponent($j("option:selected",searchPopupBox.MaxPriceDropDown).val()); cookieContent += "&minbed="+encodeURIComponent($j("option:selected",searchPopupBox.MinBedDropDown).val()); cookieContent += "&maxbed="+encodeURIComponent($j("option:selected",searchPopupBox.MaxBedDropDown).val()); cookieContent += "&name="+encodeURIComponent(searchPopupBox.PropertyNameTextBox); cookieContent += "&locationID="+encodeURIComponent(searchPopupBox.SelectedLocationID); cookieContent += "®ion="+encodeURIComponent($j("option:selected",searchPopupBox.RegionDropDown).text()); cookieContent += "&autocomplete="+encodeURIComponent(searchPopupBox.AutoCompleteTextBox); cookieContent += "&propertyRef="+encodeURIComponent(searchPopupBox.ReferenceTextBox); $j('#facebox #searchPopupSelectedLocationID').attr("value",this.SelectedLocationID); var msg = $j("option:selected",searchPopupBox.CurrencyDropDown).text(); $j.cookie('tmc_searchForm',cookieContent); // -- end of cookies $j('#facebox #searchPopupForm').submit(); }, onCountryChanged:function(e){ e.preventDefault(); // if no country selected? then reset form back to original state. if($j("option:selected",this.CountryDropDown).val()==0){ this.Init(); this.SelectedDropdown = ""; return false; } this.SelectedDropdown = "country"; // enable controls if($j(this.RegionDropDown).is(":disabled")){this.RegionDropDown.disabled=false;} if($j(this.PropertyNameTextBox).is(":disabled")){this.PropertyNameTextBox.disabled=false;} if($j(this.AutoCompleteTextBox).is(":disabled")){this.AutoCompleteTextBox.disabled=false;} if($j(this.MinBedDropDown).is(":disabled")){this.MinBedDropDown.disabled=false;} // set loation id this.SelectedLocationID = $j("option:selected",this.CountryDropDown).val(); //alert($j("option:selected",this.CountryDropDown).text() + " is selected."); this.FillMinBedsDropDown(); this.FillRemoteDropDown(this.RegionDropDown,this.CountryDropDown); //alert(Utils.getCurrencyRate($j("option:selected",this.CountryDropDown).text())); // check currency //alert('Currency : '+searchPopupBox.SelectedCurrencyCode); //alert($j("option:selected",searchPopupBox.CurrencyDropDown).val()); // if current selected currency is not GBP EUR USD var currentCurrency = $j("option:selected",searchPopupBox.CurrencyDropDown).val(); if ((currentCurrency!='GBP'&¤tCurrency!='USD'&¤tCurrency!='EUR')||currentCurrency=='Currency'){ // then refill dropdown with default currencies or no currency is selected if($j(this.MinPriceDropDown).is(":disabled")){ this.MinPriceDropDown.disabled=false; this.FillMinPriceDropDown(); } this.FillDropDown(this.getCurrencies(),this.CurrencyDropDown); } // first get default currency and rate of selected Country var countryRate = parseInt(Utils.getCurrencyRate($j("option:selected",this.CountryDropDown).text())); var countryCurrency = Utils.getCurrencyCode($j("option:selected",this.CountryDropDown).text()); // if country's default Currency is not GBP EUR USD if(countryCurrency!='GBP'&&countryCurrency!='EUR'&&countryCurrency!='USD'){ // now add a new currency to the drop down list this.AddCurrency(countryCurrency); //this.CurrencyCode = countryCurrency; //this.ExchangeRate = countryRate; if($j(this.MinPriceDropDown).is(":disabled")){this.MinPriceDropDown.disabled=false;} //this.FillMinPriceDropDown(); } // check current selected CUR on the drop-down contorl var selectedCurrency = $j("option:selected",this.CurrencyDropDown).val(); if(selectedCurrency == 'Currency'){ // if not currency is selected then, set the country default currency as selected currency; this.SelectCurrencyByCode(countryCurrency); } searchPopupBox.SelectedCurrencyCode = $j("option:selected",searchPopupBox.CurrencyDropDown).val(); this.UpdateSubmitButton(); $j(this.AutoCompleteTextBox).setOptions({ extraParams : { country:$j('option:selected',$j(this.CountryDropDown)).text(), countryID:"0",GetLocationsByPrefix:"a"} }).flushCache(); }, onRegionChanged:function(e){ e.preventDefault(); //alert($j("option:selected",this.RegionDropDown).text()+" region is selected."); //alert($j(this.AutoCompleteTextBox).val()); this.SelectedDropdown = "region"; // set loation id this.SelectedLocationID = $j("option:selected",this.RegionDropDown).val(); if($j(this.AutoCompleteTextBox).val() != 'Enter Location'){ $j(this.AutoCompleteTextBox).val(''); } $j(this.AutoCompleteTextBox).setOptions({ extraParams : { restrictedLocationID:this.SelectedLocationID,country:$j('option:selected',$j(this.CountryDropDown)).text(), countryID:"0",GetLocationsByPrefix:"a"} }).flushCache(); }, onCurrencyChanged:function(e){ e.preventDefault(); //alert($j(this.CurrencyDropDown).val() + " is selected."); searchPopupBox.SelectedCurrencyCode = $j("option:selected",searchPopupBox.CurrencyDropDown).val(); //alert(searchPopupBox.SelectedCurrencyCode); this.UpdateSubmitButton(); if(this.SelectedCurrencyCode=='Currency'){ this.SelectedMixPrice = 0; this.SelectedMaxPrice = 0; this.FillMinPriceDropDown(); this.FillMaxPriceDropDown(); this.MinPriceDropDown.disabled=true; this.MaxPriceDropDown.disabled=true; return false; } if(this.SelectedCurrencyCode=='GBP'||this.SelectedCurrencyCode=='EUR'||this.SelectedCurrencyCode=='USD'){ //alert(searchPopupBox.SelectedCurrencyCode); this.ExchangeRate = Utils.getCurrencyRateByCurrency(this.SelectedCurrencyCode); this.CurrencyCode = this.SelectedCurrencyCode; }else{ this.ExchangeRate = parseInt(Utils.getCurrencyRate($j("option:selected",this.CountryDropDown).text())); //alert(this.ExchangeRate); this.CurrencyCode = $j("option:selected",this.CurrencyDropDown).val(); } if(this.ExchangeRate==0){ExchangeRate=1;} this.FillMinPriceDropDown(); if($j(this.MinPriceDropDown).is(":disabled")){this.MinPriceDropDown.disabled=false;} this.MaxPriceDropDown.disabled=true; this.SelectedMixPrice = 0; this.SelectedMaxPrice = 0; }, onMinPriceChanged:function(e){ e.preventDefault(); if($j("option:selected",this.MinPriceDropDown).text()!="Мин цена"){ if($j(this.MaxPriceDropDown).is(":disabled")){this.MaxPriceDropDown.disabled=false;} this.SelectedMinPrice = $j("option:selected",this.MinPriceDropDown).val(); this.SelectedMinPriceIndex = this.MinPriceDropDown.selectedIndex; this.FillMaxPriceDropDown(); } else{ this.MaxPriceDropDown.disabled=true; this.SelectedMixPrice = 0; this.SelectedMinPriceIndex = this.MinPriceDropDown.selectedIndex; this.SelectedMaxPrice = 0; this.SelectedMaxPriceIndex = this.MaxPriceDropDown.selectedIndex; } }, onMaxPriceChanged:function(e){ e.preventDefault(); if($j("option:selected",this.MaxPriceDropDown).text()!="Макс цена"){ this.SelectedMaxPrice = $j("option:selected",this.MaxPriceDropDown).val(); this.SelectedMaxPriceIndex = this.MaxPriceDropDown.selectedIndex; } }, onMinBedChanged:function(e){ e.preventDefault(); if($j("option:selected",this.MinBedDropDown).text()!="Мин Спален"){ if($j(this.MaxBedDropDown).is(":disabled")){this.MaxBedDropDown.disabled=false;} this.SelectedMinBeds = $j("option:selected",this.MinBedDropDown).val(); this.FillMaxBedsDropDown(); } else{ this.MaxBedDropDown.disabled=true; this.SelectedMinBeds = 0; this.SelectedMaxBeds = 0; } this.FillMaxBedsDropDown(); }, onMaxBedChanged:function(e){}, FillBedDropDown:function(data,obj){ $j(obj).removeOption(/./); //alert(searchPopupBox.ExchangeRate); var label = "Мин Спален"; var skip = false; var lastItemIndex = data.length; if(obj.id=='selectMaxBed'){label="Max Beds"}; $j(data).each(function(index){ var cols = data[index].split('|'); //$j(obj).addOption(cols[1],cols[0]); var optn = document.createElement("option"); var value = cols[1]; //parseInt(cols[1])*searchPopupBox.ExchangeRate; optn.text = cols[0].replace("@value",value).replace("@label",label); if(lastItemIndex==(index+1)&&obj.id=='selectMaxBed'){optn.text = optn.text + " > ";} optn.value = value; if (cols[1]!=undefined){ if(obj.id=='selectMaxBed'){ if(searchPopupBox.SelectedMinBeds > value){skip=true;}else{skip=false;} }else{ if(lastItemIndex==index){skip=true;}//skip the last highest item for max drop-down } if(optn.text=="Студия"&&obj.id!='selectMaxBed'){skip=false;}// if min bed label, do not skip if(!skip){ $j(obj)[0].options.add(optn); } } }); }, FillPriceDropDown:function(data,obj){ $j(obj).removeOption(/./); //alert(searchPopupBox.ExchangeRate); var label = "Мин цена"; var skip = false; var lastItemIndex = data.length-1; if(obj.id=='selectMaxPrice'){label="Макс цена"}; $j(data).each(function(index){ var cols = data[index].split('|'); //$j(obj).addOption(cols[1],cols[0]); var optn = document.createElement("option"); var value = parseInt(cols[1])*searchPopupBox.ExchangeRate; if (cols.length==3) { optn.text = cols[2]; }else{ optn.text = cols[0].replace("@value",value).replace("@label",label); optn.text = optn.text.replace("1000k","1m").replace("2000k","2m"); } if(lastItemIndex==index){optn.text = optn.text + " > ";} optn.value = value; if (cols[1]!=undefined){ if(obj.id=='selectMaxPrice'){ if(searchPopupBox.SelectedMinPrice > value){skip=true;}else{skip=false;} }else{ if(lastItemIndex==index){skip=true;}//skip the last highest item for max drop-down } // if label, do not skip if(parseInt(cols[1])<0){ skip=false; } if(!skip){ $j(obj)[0].options.add(optn); } } }); }, FillDropDown:function(data,obj){ $j(obj).removeOption(/./); $j(data).each(function(index){ var cols = data[index].split('|'); //$j(obj).addOption(cols[1],cols[0]); var optn = document.createElement("option"); optn.text = cols[0]; optn.value = cols[1]; if (cols[1]!=undefined){ $j(obj)[0].options.add(optn);} }); }, FillDropDownCountries:function(data,obj){ $j(data).each(function(index){ if (index>0) { var cols = data[index].split('|'); var optn = document.createElement("option"); optn.text = cols[0]; optn.value = cols[1]; if (cols[1]!=undefined){ $j(obj)[0].options.add(optn);} } }); }, FillDropDownCountriesLocal:function(data,obj){ $j(data).each(function(index){ var cols = data[index].split('|'); if (cols[3]!=undefined && cols[3]>"" & cols[3]!="\r") { var optn = document.createElement("option"); optn.text = cols[3]; optn.value = cols[1]; $j(obj)[0].options.add(optn); } }); }, FillRemoteDropDownPopulateData:function(obj,parent,s){ var ary = s.split('\n'); var cols; var showAddlocation = allowUKNewLocation; if ($j(searchPopupBox.CountryDropDown).val()<0 && obj.id == 'selectRegion'){ showAddlocation = false;} var temp = allowNewLocation; if ($j(searchPopupBox.CountryDropDown).val()<0){ // but if UK, then dont allow user to add first region level allowNewLocation=showAddlocation; } if ($j(searchPopupBox.CountryDropDown).val()<0 || obj.id == 'selectRegion'){allowNewLocation=false;} if(obj.id=='selectLocation1'){ //alert($j('#facebox #selectCountry option:selected').text()); if(secondLevelFixedCountries.exists($j('#facebox #selectCountry option:selected').text())){ allowNewLocation = false; } if(secondLevelFixedRegions.exists($j('#facebox #selectRegion option:selected').text())){ allowNewLocation = false; } } if(obj.id=='selectLocation3'){ allowNewLocation = allowNewLocation3; } if (showPromotedLocation){ var hAry = new Array(); var pAry = new Array(); var nAry = new Array(); var gAry = new Array(); var pcounter = 0; var ncounter = 0; var hcounter = 0; var gcounter = 0; var curGroupLabel = ''; var headerAdded = false; $j(ary).each(function(index){ cols = ary[index].split('|'); var ltype = cols[7]; var skipthis = false; if(!showUserLocationForFixedLevel){ if(secondLevelFixedCountries.exists($j('#facebox #selectCountry option:selected').text())){ if(obj.id=='selectRegion'||obj.id=='selectLocation1') { if($j.trim(cols[8])=='U'){ skipthis = true; } } } } if(!skipthis){ if(ltype==undefined){ ltype=""; hAry[hcounter]=ary[index]; hcounter++; }else if(ltype.replace(/^\s\s*/, '').replace(/\s\s*$/, '')=='P'){ pAry[pcounter]=ary[index]; pcounter++; }else{ nAry[ncounter]=ary[index]; ncounter++; } } }); if($j(hAry).length > 0){ searchPopupBox.AddLocationsToDropDownLocal(hAry,$j(obj)) } if($j(pAry).length > 0){ if(groupLocationsByLabel){ for(var i = 0;i 0){ if(groupLocationsByLabel){ for(var i = 0;i<$j(nAry).length;i++){ var cols = nAry[i].split('|'); var skipThisLocation = false; //alert('cur:'+$j.trim(cols[2])+'=old:'+curGroupLabel); if($j.trim(cols[2])=='Top Locations:'&&showTopLocationsWithPromoted){ skipThisLocation = true; } if(!skipThisLocation){ gAry = new Array(); if($j.trim(cols[2])!=curGroupLabel){ var group = searchPopupBox.AddGroupLabelToDropDown(cols[2],obj); } gAry[0] = nAry[i]; searchPopupBox.AddLocationsToDropDown(gAry,obj); curGroupLabel = $j.trim(cols[2]); //alert(cols[2]); } } }else{ var group = searchPopupBox.AddGroupLabelToDropDown('Locations :',obj); searchPopupBox.AddLocationsToDropDown(nAry,obj); } //locations.AddLocationsToGroup(nAry,group); } }else{ searchPopupBox.AddLocationsToDropDown(ary,obj); } allowNewLocation = temp; /*});*/ }, FillRemoteDropDownPopulateDataLocal:function(obj,parent,s){ var ary = s.split('\n'); var cols; $j(obj).removeOption(/./); Utils.ClearDropDown(obj); //$j(obj).addOption(cols[1],cols[0]); var showAddlocation = allowUKNewLocation; if ($j(searchPopupBox.CountryDropDown).val()<0 && obj.id == 'selectRegion'){ showAddlocation = false;} var temp = allowNewLocation; if ($j(searchPopupBox.CountryDropDown).val()<0){ // but if UK, then dont allow user to add first region level allowNewLocation=showAddlocation; } if ($j(searchPopupBox.CountryDropDown).val()<0 || obj.id == 'selectRegion'){allowNewLocation=false;} if(obj.id=='selectLocation1'){ //alert($j('#facebox #selectCountry option:selected').text()); if(secondLevelFixedCountries.exists($j('#facebox #selectCountry option:selected').text())){ allowNewLocation = false; } if(secondLevelFixedRegions.exists($j('#facebox #selectRegion option:selected').text())){ allowNewLocation = false; } } if(obj.id=='selectLocation3'){ allowNewLocation = allowNewLocation3; } if (showPromotedLocation){ var hAry = new Array(); var pAry = new Array(); var nAry = new Array(); var gAry = new Array(); var pcounter = 0; var ncounter = 0; var hcounter = 0; var gcounter = 0; var curGroupLabel = ''; var headerAdded = false; $j(ary).each(function(index){ cols = ary[index].split('|'); var ltype = cols[7]; var skipthis = false; if(!showUserLocationForFixedLevel){ if(secondLevelFixedCountries.exists($j('#facebox #selectCountry option:selected').text())){ if(obj.id=='selectRegion'||obj.id=='selectLocation1') { if($j.trim(cols[8])=='U'){ skipthis = true; } } } } if (cols[9]=="" || cols[9]==undefined || cols[9]=="\r") { skipthis=true; } if(!skipthis){ if(ltype==undefined){ ltype=""; hAry[hcounter]=ary[index]; hcounter++; }else if(ltype.replace(/^\s\s*/, '').replace(/\s\s*$/, '')=='P'){ pAry[pcounter]=ary[index]; pcounter++; }else{ nAry[ncounter]=ary[index]; ncounter++; } } }); if($j(hAry).length > 0){ searchPopupBox.AddLocationsToDropDownLocal(hAry,$j(obj)) } if($j(pAry).length > 0){ if(groupLocationsByLabel){ for(var i = 0;i 0){ if(groupLocationsByLabel){ for(var i = 0;i<$j(nAry).length;i++){ var cols = nAry[i].split('|'); var skipThisLocation = false; //alert('cur:'+$j.trim(cols[2])+'=old:'+curGroupLabel); if($j.trim(cols[2])=='Top Locations:'&&showTopLocationsWithPromoted){ skipThisLocation = true; } if(!skipThisLocation){ gAry = new Array(); if($j.trim(cols[2])!=curGroupLabel){ var group = searchPopupBox.AddGroupLabelToDropDown(cols[2],obj); } gAry[0] = nAry[i]; searchPopupBox.AddLocationsToDropDownLocal(gAry,obj); curGroupLabel = $j.trim(cols[2]); //alert(cols[2]); } } }else{ var group = searchPopupBox.AddGroupLabelToDropDown('Locations :',obj); searchPopupBox.AddLocationsToDropDownLocal(nAry,obj); } } }else{ searchPopupBox.AddLocationsToDropDownLocal(ary,obj); } allowNewLocation = temp; /*});*/ }, FillRemoteDropDown:function(obj,parent){ var getURL = this.remoteURL+$j(parent).val(); var cacheKey = "Locations:"+$j(parent).val(); if(this.CacheRegions){ // check cached locations if it already there if ($j.jCache.hasItem(cacheKey)){ var data = $j.jCache.getItem(cacheKey); // now load data to region drop down; searchPopupBox.FillRemoteDropDownPopulateDataLocal(obj,parent,data); searchPopupBox.FillRemoteDropDownPopulateData(obj,parent,data); return; } } if (this.SelectedDropdown=='country'){ var countryName = $j('option:selected',parent).html(); if(countryName=='England'){ getURL = this.remoteURL+'-10001';} else if(countryName=='Scotland'){ getURL = this.remoteURL+'-10002';} else if(countryName=='Northern Ireland'){ getURL = this.remoteURL+'-10003';} else if(countryName=='Wales'){ getURL = this.remoteURL+'-10004';} } $j.ajax({ type: "GET", url:getURL, async:true, beforeSend: function(xhr) { }, success:function(s){ if(searchPopupBox.CacheRegions){ if (!$j.jCache.hasItem(cacheKey)){ $j.jCache.setItem(cacheKey,s); } } searchPopupBox.FillRemoteDropDownPopulateDataLocal(obj,parent,s); searchPopupBox.FillRemoteDropDownPopulateData(obj,parent,s); } }); }, AddGroupLabelToDropDown:function(label,dropdown){ var optn = document.createElement("optgroup"); optn.label = label; $j(optn).addClass('locationGroup'); //optn.value = '-3'; $j(dropdown)[0].appendChild(optn); return optn; }, AddLocationsToDropDown:function(ary,dropdown){ $j(ary).each(function(index){ cols = ary[index].split('|'); //$j(obj).addOption(cols[1],cols[0]); var optn = document.createElement("option"); optn.text = cols[0]; optn.value = $j.trim(cols[1]); if(showPromotedLocation){ $j(optn).attr("data",ary[index]); } if (cols[1]!=undefined){ if (allowNewLocation){ $j(dropdown)[0].options.add(optn);} else{ //alert(cols[1]); if(cols[1]!=-2){ $j(dropdown)[0].options.add(optn);} } } }); }, AddLocationsToDropDownLocal:function(ary,dropdown){ $j(ary).each(function(index){ cols = ary[index].split('|'); //$j(obj).addOption(cols[1],cols[0]); var optn = document.createElement("option"); optn.text = cols[9]; optn.value = $j.trim(cols[1]); if(showPromotedLocation){ $j(optn).attr("data",ary[index]); } if (cols[1]!=undefined && optn.text!="undefined"){ if (allowNewLocation){ $j(dropdown)[0].options.add(optn);} else{ //alert(cols[1]); if(cols[1]!=-2){ $j(dropdown)[0].options.add(optn);} } } }); }, CountryDropDown:null, RegionDropDown:null, Location1DropDown:null, Location2DropDown:null, Location3DropDown:null, AutoCompleteTextBox:null, SubmitButton:null, CurrencyDropDown:null, MinPriceDropDown:null, MaxPriceDropDown:null, PriceUnitValue:0, KeywordsTextBox:null, MinBedDropDown:null, MaxBedDropDown:null, PropertyNameTextBox:null, ReferenceTextBox:null, MessageBox:null, ExchangeRate:1, CurrencyCode:"GBP", SelectedDropdown:"", SelectedMinBeds:0, SelectedMaxBeds:0, SelectedMinPrice:0, SelectedMinPriceIndex:0, SelectedMaxPrice:0, SelectedMaxPriceIndex:0, SelectedCurrencyCode:"", SelectedLocationID:0, CacheRegions:true, UseFreshCountryData:false, AutoPriceIndexSelect:true, AutoBedroomIndexSelect:true, SubmitURL:"property/search", SubmitMethod:"POST", SelectCountryByID:function(id){ Utils.DropDownSelect(searchPopupBox.CountryDropDown,id); }, SelectRegionByID:function(id){ Utils.DropDownSelect(searchPopupBox.RegionDropDown,id); }, SelectCurrencyByCode:function(CurrencyCode){ Utils.DropDownSelect(searchPopupBox.CurrencyDropDown,CurrencyCode); }, SelectMinPriceByValue:function(value){ Utils.DropDownSelect(searchPopupBox.MinPriceDropDown,value); }, SelectMaxPriceByValue:function(value){ Utils.DropDownSelect(searchPopupBox.MaxPriceDropDown,value); }, SelectMinBedByValue:function(value){ Utils.DropDownSelect(searchPopupBox.MinBedDropDown,value); }, SelectMaxBedByValue:function(value){ Utils.DropDownSelect(searchPopupBox.MaxBedDropDown,value); }, UpdateSubmitButton:function(){ var msg = ""; if($j("option:selected",searchPopupBox.CurrencyDropDown).text()=="Currency"){ msg = "Currency";} if($j("option:selected",searchPopupBox.CountryDropDown).text()==""){ if(msg==""){msg = "a Country";}else{msg="a Country and "}} //alert(msg); if(msg!=""){ msg = "Please select " + msg; $j(this.SubmitButton).hide(); $j(this.MessageBox).text(msg); }else{ $j(this.MessageBox).hide(); $j(this.SubmitButton).show(); } }, IsCurrencyExist:function(CurrencyCode){ var exist = false; $j("option",searchPopupBox.CurrencyDropDown).each(function(index){ if(searchPopupBox.CurrencyDropDown.options[index].value==CurrencyCode && exist==false) exist = true; }); return exist; }, AddCurrency:function(CurrencyCode){ if(!this.IsCurrencyExist(CurrencyCode)){ //alert('addnow'+CurrencyCode); if(CurrencyCode!=0){ Utils.AddOptionToDropDown(CurrencyCode,CurrencyCode,searchPopupBox.CurrencyDropDown); } } }, RemoveCurrency:function(CurrencyCode){ if(!this.IsCurrencyExist(CurrencyCode)){ //alert('remove now'); alert($j("option[value='"+CurrencyCode+"']",this.CurrencyDropDown).text()); } }, FillMinPriceDropDown:function(){ this.FillPriceDropDown(this.getPriceRanges(),this.MinPriceDropDown); }, FillMaxPriceDropDown:function(){ this.FillPriceDropDown(this.getPriceRanges(),this.MaxPriceDropDown); }, FillMinBedsDropDown:function(){ this.FillBedDropDown(this.getBedRanges(),this.MinBedDropDown); }, FillMaxBedsDropDown:function(){ this.FillBedDropDown(this.getBedRanges(),this.MaxBedDropDown); }, FillPriceDropDowns:function(){ this.FillMinPriceDropDown(); this.FillMaxPriceDropDown }, FillBedDropDowns:function(){ this.FillBedDropDown(this.getBedRanges(),this.MinBedDropDown); this.FillBedDropDown(this.getBedRanges(),this.MaxBedDropDown); }, remoteURL:"/tmc.system/tmc.services.locations.asp?IncludePromoted="+showPromotedLocation+"&IsDeep="+deepPromotedIncluded+"&GetLMSChildLocations=", remoteCountryDataURL:"/tmc.system/tmc.services.locations.asp?Country=ActiveLMS", EnableMinControls:function(){ this.CountryDropDown.disabled = false; this.MinPriceDropDown.disabled = true; this.RegionDropDown.disabled = true; this.MaxPriceDropDown.disabled = true; this.MinBedDropDown.disabled = true; this.MaxBedDropDown.disabled = true; this.CurrencyDropDown.disabled = false; this.AutoCompleteTextBox.disabled = true; this.PropertyNameTextBox.disabled = true; this.ReferenceTextBox.disabled = false; this.UpdateSubmitButton(); }, getCountries:function(){ if (this.UseFreshCountryData){ var dummy = 'выберите страну|0'; $j.ajax({ type: "GET", url:this.remoteCountryDataURL, async:false, beforeSend: function(xhr) { }, success:function(s){ // var ukLocations = 'England|35283\nScotland|50505\nWales|50535\nNorthern Ireland|50558\n'; // s = ukLocations + s; var ary = s.split('\n').join(':'); dummy = dummy + ':' + ary; //alert(dummy); } }); return dummy.split(":"); }else{ return countries; } }, getCurrencies:function(){return defaultCurrencies;}, getPriceRanges:function(){return ("@label|-1:@value|0:@valuek|25:@valuek|50:@valuek|75:@valuek|100:@valuek|150:@valuek|200:@valuek|300:@valuek|500:@valuek|1000").split(":");}, getBedRanges:function(){return ("@label|@label:Студия|0:1|1:2|2:3|3:4|4:5|5:6|6:7|7:8|8:9|9:10|10").split(":");} } function formatItem(row) { //var row = row.split("|"); //return row[0] + " (id: " + row[1] + ")"; return row[1].replace(/[/]/gi," » ").replace(/[_]/gi," "); } function formatResult(row) { return row[0]; }