﻿var cityName=$("#fdestinationName").val();var arrBarcelona=Array("barcellona","barcelona","barcelone","barselona");var modeCalcDays=0;function autocompleteForm(){$("#fdestinationName").autocompleteArray(regional.autocompleteArray,{delay:2,minChars:1,matchSubset:1,onItemSelect:selectItem,onFindValue:findValue,autoFill:false,formatItem:formatItem});var valDestTmp=$("#fdestinationName").val();if(valDestTmp==""){vglobal.destinationVoid=true;$("#fdestinationName").val(regional.EnterDestiny);}else{vglobal.destinationVoid=false;}$("#fdestinationName").focus(function(){if(vglobal.destinationVoid){vglobal.destinationVoid=false;$("#fdestinationName").val("");}});}function simpleMoreopt(){$("#mopt-sh").height("0px");$("#more").click(function(){var mopth=$("#mopt-sh").is(":hidden");if(mopth){$(this).addClass("sh");$(this).html(regional.lessOptions);}else{$(this).removeClass("sh");$("#more").html(regional.moreOptions);}if(mopth){$("#mopt-sh label").show();$("#mopt-sh").show();if(!mascLoad.showfilters){$("#mopt-sh").addClass("loadingiconbl");}$("#mopt-sh").animate({height:"254px"},"normal","easeOutExpo",function(){if(!mascLoad.showfilters){mascLoad.showfilters=1;$("head").append("<link>");css=$("head").children(":last");css.attr({rel:"stylesheet",type:"text/css",href:"/css/theme/ui.slider.css"});$("head").append("<link>");css=$("head").children(":last");css.attr({rel:"stylesheet",type:"text/css",href:"/css/search-result.css"});$.get("/jx_filters_form.aspx",function(data){$.getScript("/js/regional/regional-"+vglobal.lang_code+"-extended.rjs",function(){$.getScript("/js/jquery/jquery.SearchControls.js",function(){$("#mopt-sh").html(data);pSliderReloadResults=0;pPeople=$("#fPax").val();maxDailyPrice=maxDailyPricePerson*pPeople;minDailyPrice=minDailyPricePerson*pPeople;pPriceMax=maxDailyPrice;pPriceMin=minDailyPrice;$.SearchControls();vglobalZones.txtDest="";makeSliderControls();updateAreas();$("#iniprice2").html(regional.maxprice);$("#mopt-sh").removeClass("loadingiconbl");});});});}});}else{$("#mopt-sh label").hide();$("#mopt-sh").animate({height:"0px"},"normal","easeOutExpo",function(){$(this).hide();});}});}function sendSearch(){return validation(ididioma);}function calendar(idbox,imgcal,firstDayIn){var _arrayDate=vglobalServer.currentDate.split("-");var _currentDay=parseInt(_arrayDate[2]);var _currentMonth=parseInt(_arrayDate[1])-1;var _currentYear=parseInt(_arrayDate[0]);$(idbox).datepicker({showOn:"button",maxDate:"+1y",minDate:new Date(_currentYear,_currentMonth,_currentDay),buttonImage:"/imgs/icons/"+imgcal,hideIfNoPrevNext:true,numberOfMonths:2,altFormat:vglobal.dateformatVis,dateFormat:vglobal.dateformatSys,buttonImageOnly:true,showButtonPanel:false,closeText:"",currentText:"",create:function(event,ui){},onSelect:function(date,inst){var currentId=$(this).attr("id");var dateArr=new Date($("#fcal-arr").datepicker("getDate"));var dateGo=new Date($("#fcal-go").datepicker("getDate"));if(currentId=="fcal-arr"){if(dateArr>dateGo){dateGo=new Date(dateArr.getFullYear(),dateArr.getMonth(),dateArr.getDate()+1);$("#fcal-go").datepicker("setDate",dateGo);showFormatDate("fcal-go",dateGo);}showFormatDate("fcal-arr",dateArr);}else{if(currentId=="fcal-go"){showFormatDate("fcal-go",dateGo);}}vglobal.onChangeDates(date,currentId);}});$("#fcalformat-arr").click(function(){$("#fcal-arr").datepicker("show");});$("#fcalformat-go").click(function(){$("#fcal-go").datepicker("show");});var currentId=$(idbox).attr("id");var currentDate=new Date($("#"+currentId).datepicker("getDate"));showFormatDate(currentId,currentDate);}function showFormatDate(idbox,unformattedDate){if(idbox=="fcal-arr"){$("#fcalformat-arr").html($.datepicker.formatDate(vglobal.dateformatVis,unformattedDate));}else{if(idbox=="fcal-go"){$("#fcalformat-go").html($.datepicker.formatDate(vglobal.dateformatVis,unformattedDate));}}}function validateEmptyDates(){if($("#day-arr").val()==""||$("#day-go").val()==""||$("#month-arr").val()==""||$("#month-go").val()==""){return false;}else{return true;}}function validation(ididiomaIn){var destino=$("#sform #fdestinationName").val();var dateArr=new Date($("#fcal-arr").datepicker("getDate"));var dateGo=new Date($("#fcal-go").datepicker("getDate"));var txtdest=regional.validateDest;var txtdate=regional.validateDate;var txtEmpty=regional.validateEmptyDates;var txterr="";if(destino==""){txterr=txtdest+"\n"+txterr;$("#fdestinationName").addClass("errormsg");}else{$("#fdestinationName").removeClass("errormsg");if(dateArr>=dateGo){txterr=txtdate;$("#fcalformat-go").addClass("errormsg");}else{$("#fcalformat-go").removeClass("errormsg");}}if(txterr!=""){alert(txterr);return false;}else{var casecity=false;for(i=0;i<arrBarcelona.length;i++){if(arrBarcelona[i]==destino.toLowerCase()){casecity=true;break;}}var domain=$("#fWebDomain").val();if((!casecity&&domain=="www.apartmentsramblas.com")||(casecity&&domain!="www.apartmentsramblas.com")){$.ajax({type:"POST",url:"/GlobalServices.asmx/GetDestinationDomainByName",data:"{'name':'"+destino+"','ididioma':'"+ididiomaIn+"'}",contentType:"application/json; charset=utf-8",dataType:"json",cache:false,success:function(result){SendDomainSearch(result.d);},error:function(result){}});}else{var ctLoading=$("#overlay_loading").html();$("body").append('<div id="overlay_loading_box">'+ctLoading+"</div>");document.getElementById("sform").submit();}return false;}}function formatItem(row,position,items){if(position%2){res='<div class="res_impar">'+row[0]+"</div>";}else{res='<div class="res_par">'+row[0]+"</div>";}return res;}function findValue(li){if(li==null){return alert("No match!");}if(!!li.extra){var sValue=li.extra[0];}else{var sValue=li.selectValue;}}function selectItem(li){findValue(li);}function SendDomainSearch(domainName){var f=document.getElementById("sform");$("#fidDestino").val("");var pagina=f.getAttribute("action");f.setAttribute("action","http://"+domainName+"/"+pagina.replace("/",""));f.submit();}function difDays(){var dateArr=new Date($("#fcal-arr").datepicker("getDate"));var dateGo=new Date($("#fcal-go").datepicker("getDate"));var resta=dateGo-dateArr;return resta;}function updateDifDays(){var dateArr=new Date($("#fcal-arr").datepicker("getDate"));var dateGo=new Date($("#fcal-go").datepicker("getDate"));var dDays=dateGo-dateArr;if(dDays>0){pDays=dDays;}}
