var isDebug=false;var isIE6=($.browser.msie&&$.browser.version=="6.0");var PropertyData={};var PropertyDetails={};var PropertySorted={0:[],1:[],2:[],3:[]};var PropertyPreview={};var PropertyListed={};var Providers={};var SearchID="";var indexDistances=2;var PropertySetCount=10;var preloadDistance=1000;var checkInterval=500;var preloadDetails=20;var statusUpdateDelta=500;var isUpdating=false;var isUpdatingList=false;var availabilitySearched=false;var isDetailsFirstLoad=true;var totalPages=-1;var contStart=0;var thisPage=1;var thisSection=5;var countAvailable=-1;var statusUpdate=0;var sf_PropType="all";var isGMapLoaded=false;var googleMap=null;var googlePin=null;var thisCityName="";var thisCityLatitude=0;var thisCityLongitude=0;var iconsLocation="http://www.travellerspoint.com/img/";var googleMap_LargeMapControl=null;var googleMap_MapTypeControl=null;function initSearchVariables(){if(isDebug){console.log("initSearchVariables();")}if(isGMapLoaded){clearMap()}PropertyData={};PropertySorted={0:[],1:[],2:[],3:[]};PropertyPreview={};PropertyListed={};Providers={};SearchID="";availabilitySearched=false;isUpdating=false;isUpdatingList=false;isDetailsFirstLoad=true;totalPages=-1;countAvailable=-1;statusUpdate=0}function countObject(obj){var count=0;for(var k in obj){if(obj.hasOwnProperty(k)){count++}}return count}function initPageVariables(){if(isDebug){console.log("initPageVariables();")}contStart=0;thisPage=1;thisSection=(countObject(PropertyData)>0)?PropertyData[PropertySorted[sf_Order][0]].available:5;PropertyListed={}}function showError(msg){switch(msg){case"error":msg=i18nMessage("ajax_failed");break;case"parseerror":msg=i18nMessage("ajax_data_parsing");break;default:}$("#property_list").html('<ul class="error"><li>'+msg+"</li></ul>")}function storePropertyDetails(d,PropertyID){PropertyDetails[PropertyID]={};PropertyDetails[PropertyID].id=d.id;PropertyDetails[PropertyID].link=d.l;PropertyDetails[PropertyID].address=d.a;PropertyDetails[PropertyID].type=d.t;PropertyDetails[PropertyID].description=d.d;var thisPropertyImage=d.i;if(thisPropertyImage.length>0){if(thisPropertyImage.indexOf("http://")==-1){thisPropertyImage="http://propimg.travellerspoint.com/s_"+thisPropertyImage}else{if(thisPropertyImage.indexOf("images.webresint.com")!=-1&&thisPropertyImage.indexOf("http://images.webresint.com/images/hostels/mini_")==-1){thisPropertyImage=thisPropertyImage.replace("http://images.webresint.com/images/hostels/","http://images.webresint.com/images/hostels/mini_")}else{if(thisPropertyImage.indexOf("hb-247.com")!=-1&&thisPropertyImage.indexOf("s.jpg")==-1){thisPropertyImage=thisPropertyImage.replace(".jpg","s.jpg")}}}PropertyDetails[PropertyID].iCache=new Image(61,61);PropertyDetails[PropertyID].iCache.src=thisPropertyImage}PropertyDetails[PropertyID].image=thisPropertyImage}function fetchPropertyDetails(PropertyIDs,isUpdatePage){isUpdating=true;$.ajax({url:"/ajax/non_session/get_property_details.cfm",data:{PropertyID:PropertyIDs,Language:sf_Language},type:"get",dataType:"json",success:function(d){var PropertyIDs=d.id.split(",");var i=0;for(i=0,l=d.data.length;i<l;i++){var thisPropertyID=d.data[i].id;if(!PropertyDetails[thisPropertyID]){storePropertyDetails(d.data[i],thisPropertyID)}}for(i=0,l=PropertyIDs.length;i<l;i++){if(!PropertyDetails[PropertyIDs[i]]){PropertyListed[PropertyIDs[i]]=true;PropertyPreview[PropertyIDs[i]]={};PropertyPreview[PropertyIDs[i]][0]="";PropertyPreview[PropertyIDs[i]][1]="";PropertyPreview[PropertyIDs[i]][2]=""}}isUpdating=false;if(isUpdatePage){setTimeout(function(){updatePage()},0)}if(isDetailsFirstLoad){isDetailsFirstLoad=false;setTimeout(function(){loadExtraDetails()},0)}},error:function(xhr,message,ex){showError(message)}});return false}function countLoadedProviders(){var countLoaded=0;for(var key in Providers){if(Providers[key].loaded){countLoaded++}}return countLoaded}function updateStatus(){var countProviders=countObject(Providers);if(countProviders>0&&countProviders==countLoadedProviders()){return false}var unique=new Date().getTime();$.ajax({url:"/js/accommodation/"+SearchID+".js?u="+unique,type:"get",dataType:"json",success:function(j){j=j.r;var countProcessed=0;for(var i=0;i<j.length;i++){if(!Providers[j[i].id]){Providers[j[i].id]={};Providers[j[i].id].count=-1;Providers[j[i].id].loaded=false}if(Providers[j[i].id].count==-1&&j[i].c!=-1){setTimeout(function(){loadData(true,j[i].id)},0)}Providers[j[i].id].count=j[i].c;if(j[i].c!=-1){countProcessed++}}if(countProcessed!=j.length){statusUpdate+=statusUpdateDelta;setTimeout(function(){updateStatus()},statusUpdate);$("#loading").html("<p>Loading search results ...</p>")}},error:function(xhr,message,ex){statusUpdate+=statusUpdateDelta;setTimeout(function(){updateStatus()},statusUpdate)}});return false}function initData(){if($.cookie("Order")){sf_Order=parseInt($.cookie("Order"),10)}if($.cookie("Info")){sf_Info=parseInt($.cookie("Info"),10)}}function toggleSearchForm(h){if(document.getElementById("search_form")){if(h){$("#search_form").hide()}else{$("#search_form").show()}return false}return true}function loadSearchForm(){$.ajax({url:"/ajax/get_search_form.cfm",data:{Area:"ci",PropType:sf_PropType,Language:sf_Language,CityID:sf_CityID,Count:countAvailable},type:"get",dataType:"html",success:function(h){$("#booking_form").html(h);toggleSearchForm(true)}})}function setSearchMode(m){if(m=="select"){$("#ff_location_search_type_select").attr("checked","checked");$("#ff_country").removeClass("disabled");$("#ff_city").removeClass("disabled");$("#ff_location").addClass("disabled")}else{if(m=="text"){$("#ff_location_search_type_text").attr("checked","checked");$("#ff_country").addClass("disabled");$("#ff_city").addClass("disabled");$("#ff_location").removeClass("disabled")}}return false}function completeLoading(toggleSearchForm){if(isDebug){console.log("completeLoading();")}$("#loading").removeClass("loading");if(toggleSearchForm){setTimeout(function(){loadSearchForm()},0)}if(isGMapLoaded){setTimeout(function(){refreshMap()},0)}}function cacheSortedResults(){if(isDebug){console.log("cacheSortedResults();")}for(var i=0;i<=3;i++){if(i!=sf_Order){PropertySorted[i]=PropertySorted[sf_Order].slice(0);switch(i){case 1:PropertySorted[i].sort(comparePrice);break;case 2:PropertySorted[i].sort(compareDistance);break;case 3:PropertySorted[i].sort(compareName);break;default:PropertySorted[i].sort(comparePopularity)}}}}function loadExtraDetails(){if(isDebug){console.log("loadExtraDetails();")}var m=(PropertySorted[sf_Order].length<preloadDetails)?PropertySorted[sf_Order].length:preloadDetails;var loadPropertyIDs="";cacheSortedResults();for(var i=0;i<=3;i++){if(i!=sf_Order){for(var j=0;j<m;j++){if(!PropertyDetails[PropertySorted[i][j]]&&loadPropertyIDs.indexOf("|"+PropertySorted[i][j]+"|")==-1){loadPropertyIDs+="|"+PropertySorted[i][j]+"|"}}}}loadPropertyIDs=loadPropertyIDs.replace(/\|\|/g,",");loadPropertyIDs=loadPropertyIDs.replace(/\|/g,"");if(loadPropertyIDs.length>0){setTimeout(function(){fetchPropertyDetails(loadPropertyIDs,false)},0)}if(!isGMapLoaded&&document.getElementById("map")){if(!isIE6){$("#map").click(function(){activateMap()});$("#map .message").show();$("#map").addClass("map_clickable")}else{$("#map .message").remove();$("#map").removeClass("map_clickable")}}}function loadData(doSearch,ProviderID){isUpdating=true;$("#loading").addClass("loading");$("#loading").html("<p>Loading ...</p>");if(!ProviderID){ProviderID=""}else{$("#loading").html("<p>Loading property data ...</p>")}if(isDebug){console.log("loadData("+doSearch+","+ProviderID+")")}$.ajax({url:"/ajax/get_search_results.cfm",data:{CityID:sf_CityID,PropType:sf_PropType,Language:sf_Language,dtStart:sf_dtStart,numNights:sf_numNights,Currency:sf_Currency,doSearch:doSearch,ProviderID:ProviderID},type:"get",dataType:"json",success:function(j){if(j.sid){Providers={};SearchID=j.sid;setTimeout(function(){updateStatus()},0)}else{if(ProviderID!=""){Providers[ProviderID].loaded=true}sf_dtStart=j.dt;j=j.p;if(countAvailable==-1){countAvailable=0}for(var i=0;i<j.length;i++){var thisPropertyID=parseInt(j[i].id,10);if(!PropertyData[thisPropertyID]){PropertyData[thisPropertyID]={};PropertyData[thisPropertyID].id=thisPropertyID;PropertyData[thisPropertyID].name=j[i].n;PropertyData[thisPropertyID].lname=j[i].n.toLowerCase();PropertyData[thisPropertyID].popularity=parseFloat(j[i].pop);PropertyData[thisPropertyID].latitude=parseFloat(j[i].lat);PropertyData[thisPropertyID].longitude=parseFloat(j[i].lon);PropertyData[thisPropertyID].price=parseFloat(j[i].p);PropertyData[thisPropertyID].available=parseInt(j[i].a,10);PropertyData[thisPropertyID].minnights=parseInt(j[i].min,10);PropertyData[thisPropertyID].maxnights=parseInt(j[i].max,10);PropertyData[thisPropertyID].otherguests=parseInt(j[i].o,10);PropertyData[thisPropertyID].availabledates=j[i].dt;if(PropertyData[thisPropertyID].available==5){countAvailable++}PropertySorted[sf_Order][PropertySorted[sf_Order].length]=thisPropertyID}}calculateDistances();totalPages=Math.ceil(PropertySorted[sf_Order].length/PropertySetCount);isUpdating=false;var countProviders=countObject(Providers);if((ProviderID==""&&doSearch)||(countProviders>0&&countProviders==countLoadedProviders())){availabilitySearched=true}sortPropertyList();if(ProviderID==""||countObject(Providers)==countLoadedProviders()){completeLoading(doSearch)}}},error:function(xhr,message,ex){$("#loading").removeClass("loading");showError(message)}});return false}function ajaxSearch(obj){var s=$("#ff_month").val().split("-");sf_dtStart=toDateString(StrToInt(s[1]),StrToInt(s[0]),StrToInt($("#ff_day").val()));sf_numNights=$("#ff_numnights").val();sf_Currency=$("#ff_currency").val();initSearchVariables();loadData(true);return false}function updatePage(){var isMore=true;if(thisPage<=totalPages){if(isUpdating===false&&((thisPage==1)||(getPageHeight()-getScrollHeight()<preloadDistance))){isMore=showPropertyList()}if(totalPages>1&&isMore){setTimeout(function(){updatePage()},checkInterval)}}}function showPropertyList(thisStart){if(isDebug){console.log("showPropertyList();")}var htmlPropertyList="";var thisIdx=0;if(!thisStart){if(contStart!==0){thisStart=contStart}else{thisStart=(thisPage-1)*PropertySetCount}}else{contStart=thisStart}var thisEnd=thisPage*PropertySetCount-1;if(thisStart===0){htmlPropertyList+=showFilterPanel();if(availabilitySearched&&thisSection!=5){htmlPropertyList+='<div class="section">'+i18nMessage("other_properties")+"</div>"}}var newSection=thisSection;var toShow=[];var thisPropertyID=0;for(thisIdx=thisStart;thisIdx<=thisEnd;thisIdx++){if(thisIdx<PropertySorted[sf_Order].length){thisPropertyID=PropertySorted[sf_Order][thisIdx];var thisProperty=PropertyData[thisPropertyID];if(thisProperty.available!=thisSection){newSection=thisProperty.available;if(thisSection===5){break}else{thisSection=thisProperty.available;if(!PropertyListed[thisPropertyID]){toShow[toShow.length]=thisPropertyID}}}else{if(!PropertyListed[thisPropertyID]){toShow[toShow.length]=thisPropertyID}}}}var loadPropertyDetails="";for(i=0;i<toShow.length;i++){thisPropertyID=toShow[i];if(!PropertyDetails[thisPropertyID]){loadPropertyDetails+=(i!==0?",":"")+thisPropertyID}}if(loadPropertyDetails.length>0){setTimeout(function(){fetchPropertyDetails(loadPropertyDetails,true)},100);return false}else{for(i=0;i<toShow.length;i++){if(thisStart===0){htmlPropertyList+=showPropertyPreview(toShow[i])}else{$("#property_list_more").before(showPropertyPreview(toShow[i]))}}}if(thisStart===0){$("#property_list").html(htmlPropertyList);if(thisPage<totalPages){$("#property_list").append('<div id="property_list_more">'+i18nMessage("loading_more")+"</div>")}}if(thisPage<=totalPages&&thisSection!=newSection){$("#property_list_more").remove();$("#property_list").append('<div id="property_list_more"><a href="javascript:void(0);" onClick="return showMore('+newSection+');">'+i18nMessage("other_properties_option")+"</a></div>")}if(thisSection==newSection&&thisPage==totalPages){$("#property_list_more").remove()}contStart=0;if(thisSection==newSection){thisPage++;return true}return false}function showMore(showSection){var thisIdx=0;var thisStart=(thisPage-1)*PropertySetCount;var thisEnd=thisPage*PropertySetCount-1;for(thisIdx=thisStart;thisIdx<=thisEnd;thisIdx++){if(thisIdx<PropertySorted[sf_Order].length){var thisProperty=PropertyData[PropertySorted[sf_Order][thisIdx]];if(thisProperty.available==showSection){thisSection=showSection;break}}}if(thisIdx>0){var htmlPropertyList='<div class="section">'+i18nMessage("other_properties")+"</div>";htmlPropertyList+='<div id="property_list_more">'+i18nMessage("loading_more")+"</div>";$("#property_list_more").replaceWith(htmlPropertyList);if(showPropertyList(thisIdx)){setTimeout(function(){updatePage()},0)}}}function ajaxFilterOrder(f){if(f!=sf_Order){sf_Order=f;$.cookie("Order",f);sortPropertyList()}return false}function ajaxFilterInfo(f){if(f!=sf_Info){sf_Info=f;$.cookie("Info",f);initPageVariables();if(showPropertyList()){setTimeout(function(){updatePage()},0)}}return false}function comparePopularity(aPropertyID,bPropertyID){var objA=PropertyData[aPropertyID];var objB=PropertyData[bPropertyID];var retval=(objB.available===5?1:0)-(objA.available===5?1:0);if(retval===0){retval=objB.available-objA.available}if(retval===0){retval=objB.popularity-objA.popularity}if(retval===0){retval=objA.price-objB.price}if(retval===0){retval=objA.distance-objB.distance}if(retval===0){retval=objA.lname.localeCompare(objB.lname)}return retval}function comparePrice(aPropertyID,bPropertyID){var objA=PropertyData[aPropertyID];var objB=PropertyData[bPropertyID];var retval=(objB.available===5?1:0)-(objA.available===5?1:0);if(retval===0){retval=objB.available-objA.available}if(retval===0){retval=objA.price-objB.price}if(retval===0){retval=objB.popularity-objA.popularity}if(retval===0){retval=objA.distance-objB.distance}if(retval===0){retval=objA.lname.localeCompare(objB.lname)}return retval}function compareDistance(aPropertyID,bPropertyID){var objA=PropertyData[aPropertyID];var objB=PropertyData[bPropertyID];var retval=(objB.available===5?1:0)-(objA.available===5?1:0);if(retval===0){retval=objB.available-objA.available}if(retval===0){retval=objA.distance-objB.distance}if(retval===0){retval=objB.popularity-objA.popularity}if(retval===0){retval=objA.price-objB.price}if(retval===0){retval=objA.lname.localeCompare(objB.lname)}return retval}function compareName(aPropertyID,bPropertyID){var objA=PropertyData[aPropertyID];var objB=PropertyData[bPropertyID];var retval=(objB.available===5?1:0)-(objA.available===5?1:0);if(retval===0){retval=objB.available-objA.available}if(retval===0){retval=objA.lname.localeCompare(objB.lname)}if(retval===0){retval=objB.popularity-objA.popularity}if(retval===0){retval=objA.price-objB.price}if(retval===0){retval=objA.distance-objB.distance}return retval}function sortPropertyList(isReloadDistances){if(isDebug){console.log("sortPropertyList("+isReloadDistances+");")}if(isDetailsFirstLoad){switch(sf_Order){case 1:PropertySorted[sf_Order].sort(comparePrice);break;case 2:PropertySorted[sf_Order].sort(compareDistance);break;case 3:PropertySorted[sf_Order].sort(compareName);break;default:PropertySorted[sf_Order].sort(comparePopularity)}}else{if(isReloadDistances){PropertySorted[indexDistances].sort(compareDistance)}}if(PropertySorted[sf_Order].length>0){initPageVariables();if(showPropertyList()){setTimeout(function(){updatePage()},0)}}}function showPropertyPreview(PropertyID){if(!PropertyPreview[PropertyID]){PropertyPreview[PropertyID]={};var thisPropertyData=PropertyData[PropertyID];for(var i=0;i<3;i++){if(thisPropertyData){var thisPropertyDetails=PropertyDetails[PropertyID];var propertyPreview='<div id="property_'+thisPropertyData.id+'" class="property">';if(i>1&&thisPropertyDetails.image.length>0){propertyPreview+='<a href="'+thisPropertyDetails.link+'"><img src="'+thisPropertyDetails.image+'" class="property_thumb" /></a>'}if(thisPropertyData.popularity>0){propertyPreview+='<p class="user_rating"><a class="';if(thisPropertyData.popularity<=20){propertyPreview+="negative"}else{if(thisPropertyData.popularity<=40){propertyPreview+="average_low"}else{if(thisPropertyData.popularity<=60){propertyPreview+="average_mid"}else{if(thisPropertyData.popularity<=80){propertyPreview+="average_high"}else{propertyPreview+="positive"}}}}propertyPreview+='" href="'+thisPropertyDetails.link+'#reviews"><span>'+thisPropertyData.popularity+"%</span></a></p>"}propertyPreview+='<div class="property_info">';if(thisPropertyData.price>0){propertyPreview+='<div class="price_info"><p class="min_price';if(thisPropertyData.available==5){propertyPreview+=" available"}propertyPreview+='"><a href="'+thisPropertyDetails.link+'"><span>'+i18nMessage("price_from")+"</span> "+toPrice(thisPropertyData.price,sf_Currency)+'</a></p><p class="min_price_note">'+i18nMessage("per_person_per_night")+"</p></div>"}propertyPreview+='<h3><a href="'+thisPropertyDetails.link+'">'+thisPropertyData.name+"</a></h3>";if(i>0){propertyPreview+='<p class="description">'+thisPropertyDetails.description+"</p>"}propertyPreview+='<div style="clear:both;"></div>';propertyPreview+='<p class="book_now">';if(thisPropertyData.availabledates.length>0){propertyPreview+=showAvailableDates(thisPropertyData.availabledates,thisPropertyData.minnights,thisPropertyData.maxnights)}propertyPreview+='<a class="book_now_button" href="'+thisPropertyDetails.link+'">'+i18nMessage("book_now")+"</a></p>";propertyPreview+='<p class="property_details">';if(thisPropertyData.latitude!==0){propertyPreview+='<a href="#map" onClick="showProperty('+thisPropertyData.id+');" title="'+i18nMessage("show_on_map")+'">'+thisPropertyDetails.address+"</a>"}else{propertyPreview+=thisPropertyDetails.address}if(thisPropertyData.distance&&thisPropertyData.distance!=99999){propertyPreview+=' <span class="dts">'+thisPropertyData.distance.toFixed(2)+"</span>km"}propertyPreview+=" ("+thisPropertyDetails.type+")";propertyPreview+="</p>";if(thisPropertyData.otherguests>0){propertyPreview+='<p class="info">'+thisPropertyData.otherguests+" other Travellerspoint member";if(thisPropertyData.otherguests>1){propertyPreview+="s are"}else{propertyPreview+=" is"}propertyPreview+=" staying here on these dates.</p>"}propertyPreview+='</div><div style="clear:both;"></div>';propertyPreview+="</div>";PropertyPreview[PropertyID][i]=propertyPreview}else{PropertyPreview[PropertyID][i]=""}}}PropertyListed[PropertyID]=true;return PropertyPreview[PropertyID][sf_Info]}function showFilterPanel(){if(isDebug){console.log("showFilterPanel();")}var filterPanel='<div id="search_filters">';filterPanel+='<ul class="filter_info">';filterPanel+='<li class="size_s"><a href="javascript:void(0);"';if(sf_Info===0){filterPanel+=' class="selected"'}filterPanel+=' onClick="return ajaxFilterInfo(0);"><span>S</span></a></li>';filterPanel+='<li class="size_m"><a href="javascript:void(0);"';if(sf_Info===1){filterPanel+=' class="selected"'}filterPanel+=' onClick="return ajaxFilterInfo(1);"><span>M</span></a></li>';filterPanel+='<li class="size_l"><a href="javascript:void(0);"';if(sf_Info===2){filterPanel+=' class="selected"'}filterPanel+=' onClick="return ajaxFilterInfo(2);"><span>L</span></a></li>';filterPanel+="</ul>";filterPanel+='<ul class="filter_order">';filterPanel+='<li id="order_by">'+i18nMessage("order_by")+":</li>";filterPanel+="<li";if(sf_Order===0){filterPanel+=' class="selected"'}filterPanel+='><a href="javascript:void(0);" onClick="return ajaxFilterOrder(0);">'+i18nMessage("popularity")+"</a></li>";if(availabilitySearched){filterPanel+="<li";if(sf_Order===1){filterPanel+=' class="selected"'}filterPanel+='><a href="javascript:void(0);" onClick="return ajaxFilterOrder(1);">'+i18nMessage("price")+"</a></li>"}if(thisCityLatitude!==0&&thisCityLongitude!==0){filterPanel+="<li";if(sf_Order===2){filterPanel+=' class="selected"'}filterPanel+='><a href="javascript:void(0);" onClick="return ajaxFilterOrder(2);">'+i18nMessage("distance")+"</a></li>"}filterPanel+="<li";if(sf_Order===3){filterPanel+=' class="selected"'}filterPanel+='><a href="javascript:void(0);" onClick="return ajaxFilterOrder(3);">'+i18nMessage("name")+"</a></li>";filterPanel+="</ul>";filterPanel+='<div class="clearer"></div>';filterPanel+="</div>";return filterPanel}function dateadd(d,n){if(n===0){return d}else{var dt=new Date();dt.setFullYear(d.getFullYear(),d.getMonth(),d.getDate()+n);return dt}}function dateformat(d,f){var m=i18nMessage("calendar_months").split(",");switch(f){case"":return toDateString(d.getFullYear(),d.getMonth()+1,d.getDate());case"-":return toDateString(d.getFullYear(),d.getMonth()+1,d.getDate(),"-");case"s":return d.getDate()+" "+m[d.getMonth()];default:}}function showAvailableDates(dt,min,max){var dts=new Date();dts.setFullYear(StrToInt(sf_dtStart.substring(0,4)),StrToInt(sf_dtStart.substring(4,6))-1,StrToInt(sf_dtStart.substring(6,8)));var nn=StrToInt(sf_numNights);var datesSearched="";var i=0;for(i=1;i<=nn;){if(i>1){datesSearched+=","}datesSearched+=dateformat(dateadd(dts,i-1),"-");i=i+1}var outString="";if(datesSearched==dt){outString='<span class="fully_available">'+i18nMessage("available")+"</span>"}else{outString='<span class="booking_availability">';for(i=1;i<=nn;){outString+='<span class="';var isAvailable=dt.indexOf(dateformat(dateadd(dts,i-1),"-"))!=-1;if(!isAvailable){outString+="un"}outString+='available">';var j=i;var isAvailableNext=dt.indexOf(dateformat(dateadd(dts,j),"-"))!=-1;while(j+1<=nn&&isAvailable==isAvailableNext){isAvailableNext=dt.indexOf(dateformat(dateadd(dts,++j),"-"))!=-1}if(i<j){if(dateadd(dts,i-1).getMonth()==dateadd(dts,j-1).getMonth()){outString+=dateadd(dts,i-1).getDate()+"&ndash;"+dateformat(dateadd(dts,j-1),"s")}else{outString+=dateformat(dateadd(dts,i-1),"s")+" &ndash; "+dateformat(dateadd(dts,j-1),"s")}}else{outString+=dateformat(dateadd(dts,i-1),"s")}outString+="</span>";i=j+1}outString+="</span>"}if(min>0&&min>nn){outString+=i18nMessage("minimum_stay_required").replace(/#minNights#/,eval(min))}if(max>0&&max<nn){outString+=i18nMessage("maximum_stay_allowed").replace(/#maxNights#/,eval(max))}return outString}function getPageHeight(){var y;var test1=document.body.scrollHeight;var test2=document.body.offsetHeight;if(test1>test2){y=document.body.scrollHeight}else{y=document.body.offsetHeight}return parseInt(y,10)}function _getWindowHeight(){if(self.innerWidth){frameHeight=self.innerHeight}else{if(document.documentElement&&document.documentElement.clientWidth){frameHeight=document.documentElement.clientHeight}else{if(document.body){frameHeight=document.body.clientHeight}}}return parseInt(frameHeight,10)}function getScrollHeight(){var y;if(self.pageYOffset){y=self.pageYOffset}else{if(document.documentElement&&document.documentElement.scrollTop){y=document.documentElement.scrollTop}else{if(document.body){y=document.body.scrollTop}}}return parseInt(y,10)+_getWindowHeight()}function currencySymbol(c){switch(c){case"USD":return"$";case"CAD":return"C$";case"AUD":return"A$";case"NZD":return"NZ$";case"TWD":return"NT$";case"SGD":return"S$";case"FJD":return"FJ$";case"HKD":return"HK$";case"BSD":return"B$";case"BBD":return"Bds$";case"BZD":return"BZ$";case"BMD":return"BD$";case"BND":return"B$";case"KYD":return"CI$";case"XCD":return"EC$";case"GYD":return"G$";case"JMD":return"J$";case"LRD":return"L$";case"NAD":return"N$";case"WST":return"WS$";case"TTD":return"TT$";case"ZWD":return"Z$";case"EUR":return"€";case"GBP":return"£";case"JPY":return"¥";case"CNY":return"¥";default:return c}}function toPrice(p,c){var a=p.toString().split(".");var r=a[0];if(a.length>1){r+="<sup>"+a[1]+"</sup>"}return currencySymbol(c)+r}function createLocationText(PropertyID){var thisHtml='<a href="'+PropertyDetails[PropertyID].link+'"><img src="'+PropertyDetails[PropertyID].image+'" alt="'+PropertyData[PropertyID].name+'" width="65" align="left" style="padding:0;margin:0 10px 10px 0;float:left;" /></a>';thisHtml+='<div style="padding:0 10px 0 0;margin-left:5px;width:225px;float:left;">';thisHtml+='<div><strong><a href="'+PropertyDetails[PropertyID].link+'">'+PropertyData[PropertyID].name+"</a></strong></div>";thisHtml+='<div style="color:#ccc;">'+PropertyDetails[PropertyID].address+"</div>";thisHtml+='<div style="margin-top:7px;">'+PropertyDetails[PropertyID].description+"</div>";return thisHtml}function createMarker(PropertyID){var obj=PropertyData[PropertyID];var thisIcon=new google.maps.Icon();var imgColor=(availabilitySearched)?(obj.available==5)?"green":"red":"gray";thisIcon.image=iconsLocation+"mm_20_"+imgColor+".gif";thisIcon.iconSize=new google.maps.Size(12,20);thisIcon.iconAnchor=new google.maps.Point(6,20);thisIcon.infoWindowAnchor=new google.maps.Point(6,20);var thisMarker=new google.maps.Marker(new google.maps.LatLng(obj.latitude,obj.longitude),{icon:thisIcon});google.maps.Event.addListener(thisMarker,"click",function(){if(!PropertyDetails[PropertyID]){$.ajax({url:"/ajax/non_session/get_property_details.cfm",data:{PropertyID:PropertyID},type:"GET",dataType:"json",success:function(d){storePropertyDetails(d.data[0],PropertyID);thisMarker.openInfoWindowHtml(createLocationText(PropertyID))},error:function(xhr,message,ex){showError(message)}})}else{thisMarker.openInfoWindowHtml(createLocationText(PropertyID))}});return thisMarker}function showProperty(PropertyID){var mapDiv=document.getElementById("map");if(mapDiv.style.height==""||mapDiv.style.height=="75px"){toggleMap()}if(PropertyData[PropertyID].gmarker){PropertyData[PropertyID].gmarker.openInfoWindowHtml(createLocationText(PropertyID))}return false}function activateMap(){if(!isGMapLoaded){google.load("maps","2.x",{callback:loadMap,language:google_Language});isGMapLoaded=true;$("#map").unbind("click");$("#map .message").hide();$("#map").removeClass("map_clickable")}return false}function toggleMap(){var mapDiv=document.getElementById("map");if(mapDiv.style.height==""||mapDiv.style.height=="75px"){mapDiv.style.height="350px";googleMap_LargeMapControl=new google.maps.LargeMapControl();googleMap_MapTypeControl=new google.maps.MapTypeControl();googleMap.addControl(googleMap_LargeMapControl,new GControlPosition(G_ANCHOR_TOP_LEFT,new google.maps.Size(14,50)));googleMap.addControl(googleMap_MapTypeControl,new GControlPosition(G_ANCHOR_TOP_RIGHT,new google.maps.Size(10,10)));$("#map-toggle").html('<input type="button" class="standard" value="'+i18nMessage("reduce")+'" />')}else{mapDiv.style.height="75px";googleMap.removeControl(googleMap_LargeMapControl);googleMap.removeControl(googleMap_MapTypeControl);$("#map-toggle").html('<input type="button" class="standard" value="'+i18nMessage("enlarge")+'" />')}var c=googleMap.getCenter();googleMap.checkResize();googleMap.setCenter(c)}function loadMap(){var obj=document.getElementById("map");if(google.maps.BrowserIsCompatible()){ToggleControl=function(){};ToggleControl.prototype=new google.maps.Control();ToggleControl.prototype.initialize=function(map){var container=document.createElement("div");container.innerHTML='<input type="button" class="standard" value="'+i18nMessage("enlarge")+'" />';container.id="map-toggle";google.maps.Event.addDomListener(container,"click",toggleMap);googleMap.getContainer().appendChild(container);return container};ToggleControl.prototype.getDefaultPosition=function(){return new GControlPosition(G_ANCHOR_TOP_LEFT,new google.maps.Size(10,10))};googleMap=new google.maps.Map2(obj,{logoPassive:true});var mapCenter=new google.maps.LatLng(thisCityLatitude,thisCityLongitude);googleMap.setCenter(mapCenter,12);googleMap.addControl(new ToggleControl());var bounds=createMap(mapCenter);googleMap.setCenter(bounds.getCenter(),googleMap.getBoundsZoomLevel(bounds));googlePin=new google.maps.Marker(mapCenter,{draggable:true,title:i18nMessage("map_hint_center")});googleMap.addOverlay(googlePin);google.maps.Event.addListener(googleMap,"dragend",dragMap);google.maps.Event.addListener(googlePin,"dragend",dragPin);$(document.body).unload(function(){google.maps.Unload()});toggleMap()}}function dragMap(){googlePin.setPoint(googleMap.getCenter());dragPin()}function dragPin(){var _cp=googlePin.getPoint();googleMap.setCenter(_cp);thisCityLatitude=_cp.lat().toFixed(3);thisCityLongitude=_cp.lng().toFixed(3);calculateDistances();initPageVariables();sortPropertyList(true)}function clearMap(){if(isDebug){console.log("clearMap();")}for(var i=0,l=PropertySorted[indexDistances].length;i<l;i++){var thisPropertyID=PropertySorted[indexDistances][i];if(PropertyData[thisPropertyID].gmarker){googleMap.removeOverlay(PropertyData[thisPropertyID].gmarker);PropertyData[thisPropertyID].gmarker=null}}}function refreshMap(){if(isDebug){console.log("refreshMap();")}if(PropertySorted[indexDistances].length===0){cacheSortedResults()}for(var i=0,l=PropertySorted[indexDistances].length;i<l;i++){var thisPropertyID=PropertySorted[indexDistances][i];if(PropertyData[thisPropertyID].latitude!==0&&PropertyData[thisPropertyID].longitude!==0){PropertyData[thisPropertyID].gmarker=createMarker(thisPropertyID);googleMap.addOverlay(PropertyData[thisPropertyID].gmarker)}}}function createMap(mc){refreshMap();var bounds=new GLatLngBounds();bounds.extend(mc);var mL=Math.min(25,PropertySorted[indexDistances].length);for(var i=0;i<mL;i++){var thisPropertyID=PropertySorted[indexDistances][i];if(PropertyData[thisPropertyID].gmarker){bounds.extend(PropertyData[thisPropertyID].gmarker.getPoint())}}return bounds}function degreesToRadians(degrees){var pi_over_180=0.017453293;return degrees*pi_over_180}function distance(lat1_deg,lon1_deg,lat2_deg,lon2_deg){var R=3956;var lat1=degreesToRadians(lat1_deg);var lon1=degreesToRadians(lon1_deg);var lat2=degreesToRadians(lat2_deg);var lon2=degreesToRadians(lon2_deg);var dlon=lon2-lon1;var dlat=lat2-lat1;var s1=Math.sin(dlat/2);var s2=Math.sin(dlon/2);var a=s1*s1+Math.cos(lat1)*Math.cos(lat2)*s2*s2;var c=2*Math.atan2(Math.sqrt(a),Math.sqrt(1-a));var d=R*c;return d}function calculateDistances(){if(thisCityLatitude!==0&&thisCityLongitude!==0){for(var i=0;i<PropertySorted[sf_Order].length;i++){var thisPropertyID=PropertySorted[sf_Order][i];if(PropertyData[thisPropertyID].latitude!==0&&PropertyData[thisPropertyID].longitude!==0){PropertyData[thisPropertyID].distance=distance(thisCityLatitude,thisCityLongitude,PropertyData[thisPropertyID].latitude,PropertyData[thisPropertyID].longitude)}else{PropertyData[thisPropertyID].distance=99999}if(PropertyPreview[thisPropertyID]){var re=new RegExp('<span class="dts">(.+)</span>',"g");for(var j=0;j<3;j++){PropertyPreview[thisPropertyID][j]=PropertyPreview[thisPropertyID][j].replace(re,'<span class="dts">'+PropertyData[thisPropertyID].distance.toFixed(2)+"</span>")}}}}}function Left(str,n){if(n<=0){return""}else{if(n>String(str).length){return str}else{return String(str).substring(0,n)}}}function Right(str,n){if(n<=0){return""}else{if(n>String(str).length){return str}else{var iLen=String(str).length;return String(str).substring(iLen,iLen-n)}}}function makeValidDate(){var d=$("#ff_day").val();var m=$("#ff_month").val();var x=m.split("-");var y=StrToInt(x[1],10);m=StrToInt(x[0],10);d=StrToInt(d,10);var maxDay=31;if(m===4||m===6||m===9||m===11){maxDay=30}else{if(m===2){if(y%100!==0&&y%4===0){maxDay=29}else{maxDay=28}}}d=Math.min(d,maxDay);$("#ff_day").val(d);var dt=new Date();var dtNow=new Date(dt.getFullYear(),dt.getMonth(),dt.getDate());var dtSelected=new Date(y,m-1,d);if(dtSelected<dtNow){$("#invalid_date").show()}else{$("#invalid_date").hide()}}function toDateString(y,m,d,ch){if(!ch){ch=""}return[y,m<10?"0"+m:m,d<10?"0"+d:d].join(ch)}function populate(j){var options="";for(var i=0;i<j.length;i++){options+='<option value="'+j[i].val+'">'+j[i].txt+"</option>"}return options}function StrToInt(s){var c=s;while(c.length>0&&c.substring(0,1)=="0"){c=Right(c,c.length-1)}return parseInt(c,10)}function fillCity(cid){$.getJSON("/ajax/non_session/get_city_list.cfm",{CountryID:cid,PropertyType:sf_PropType,Language:sf_Language},function(j){$("#ff_city").html(populate(j));$("#ff_city option:first").attr("selected","selected")})}function cacheGmapIcons(){var cImages=[];cImages[0]=new Image();cImages[0].src=iconsLocation+"mm_20_green.gif";cImages[1]=new Image();cImages[1].src=iconsLocation+"mm_20_red.gif";cImages[2]=new Image();cImages[2].src=iconsLocation+"mm_20_gray.gif"}var timeDiff={setStartTime:function(){d=new Date();time=d.getTime()},getDiff:function(){d=new Date();return(d.getTime()-time)}};$(document).ready(function(){var countrySelect=$("select#ff_country");if(countrySelect.length>0){if(countrySelect.val()!=""){fillCity(countrySelect.val())}countrySelect.change(function(){if($(this).val()!=""){fillCity($(this).val())}else{$("#ff_city").html(populate([{val:"",txt:"Choose a city"}]));$("#ff_city option:first").attr("selected","selected")}})}cacheGmapIcons()});