var SearchControl={MsgSelectOneField:"",MsgValidArrDate:"",MsgValidDepDate:"",MsgBothDates:"",MsgDateOrder:"",HideErrorMessage:function(searchControlFormName){var control=Utils.GetControlByName(searchControlFormName);if(1>control.length)control=Utils.GetControlById(searchControlFormName);control.find("#errorsContainer").empty();control.find("#showErrorSmall").hide()},ShowErrorMessage:function(searchControlFormName,message){Utils.GetControlByName(searchControlFormName).find("#errorsContainer").append(message);Utils.GetControlByName(searchControlFormName).find("#showErrorSmall").show()},IsDateFieldComplete:function(dateControl){if(dateControl.val().trim()!=""&&dateControl.val().trim()!=dateControl.attr("emptyText"))return true;return false},Valid:function(searchControlFormName){var val=true,control=Utils.GetControlByName(searchControlFormName);if(1>control.length)control=Utils.GetControlById(searchControlFormName);var city=control.find("#City"),country=control.find("#Country"),hotel=control.find("#HotelName"),errContainer=control.find("#errorsContainer"),arrDateControl=control.find("#ArrivalDate"),depDateControl=control.find("#DepartureDate");if(city.val()==0&&country.val()==0&&hotel.val().trim()==""){errContainer.append("<li>"+this.MsgSelectOneField+"</li>");val=false}var arrDate=null,depDate=null,wrongDate=false,dateTimeFormat=typeof currentDateFormat!="undefined"?currentDateFormat:"MM/dd/yyyy";if(SearchControl.IsDateFieldComplete(arrDateControl)){arrDate=Date.parseLocale(arrDateControl.val().trim(),dateTimeFormat);if(!arrDate){errContainer.append("<li>"+this.MsgValidArrDate+"</li>");val=false;wrongDate=true}}if(SearchControl.IsDateFieldComplete(depDateControl)){depDate=Date.parseLocale(depDateControl.val().trim(),dateTimeFormat);if(!depDate){errContainer.append("<li>"+this.MsgValidDepDate+"</li>");val=false;wrongDate=true}}if(!wrongDate&&(arrDate&&!depDate||!arrDate&&depDate)){errContainer.append("<li>"+this.MsgBothDates+"</li>");val=false}if(typeof bothDatesRequired!="undefined"&&!arrDate&&!depDate){errContainer.append("<li>"+this.MsgBothDates+"</li>");val=false}if(arrDate&&depDate&&depDate<arrDate){errContainer.append("<li>"+this.MsgDateOrder+"</li>");val=false}return val},AllCities:null,onDropDownCountry_IndexChange:function(){var countryObj=jQuery("[name=Country]").find("[selected]"),cityObj=jQuery("[name=City]");if(!this.AllCities)this.AllCities=cityObj.find(" > option");cityObj.empty();if(countryObj.val()>0){cityObj.append(this.AllCities.filter("[value=0]"));cityObj.append(this.AllCities.filter("."+countryObj.attr("type")+"_"+countryObj.val()))}else cityObj.append(this.AllCities);cityObj.val(0);"function"==typeof OnCityChange&&OnCityChange()},onArrivalDepartureDatePicker_Selected:function(selectedDate){var instance=jQuery(this).data("datepicker"),date=jQuery.datepicker.parseDate(instance.settings.dateFormat||jQuery.datepicker._defaults.dateFormat,selectedDate,instance.settings),dateTimeFormat=typeof currentDateFormat!="undefined"?currentDateFormat:"mm/dd/yy",dates=jQuery("#ArrivalDate ,#DepartureDate");dates.filter("#"+this.id).val(formatDate(date.localeFormat(dateTimeFormat)));var option=this.id=="ArrivalDate"?"minDate":"maxDate";dates.not("#"+this.id).datepicker("option",option,date);if(this.id=="ArrivalDate"){var departureDate=new Date(date);departureDate.setDate(date.getDate()+2);dates.filter("#DepartureDate").val(formatDate(departureDate.localeFormat(dateTimeFormat)))}},ClearEmptyTexts:function(searchControlFormName){var obj=Utils.GetControlByName(searchControlFormName).find("input[emptyText]");obj.each(function(){var obj=jQuery(this);obj.attr("emptyText")==obj.val()&&obj.val("")})},RestoreEmptyTexts:function(searchControlFormName){var obj=Utils.GetControlByName(searchControlFormName).find("input[emptyText]");obj.each(function(){var obj=jQuery(this);""==obj.val()&&obj.val(obj.attr("emptyText"))})},Search:function(searchControlFormName,actionUrl,hotelUrlSlug,buton){SearchControl.HideErrorMessage(searchControlFormName);if(SearchControl.Valid(searchControlFormName)){SearchControl.HideErrorMessage(searchControlFormName);SearchControl.ClearEmptyTexts(searchControlFormName);jQuery.post(actionUrl,Utils.GetControlByName(searchControlFormName).serialize(),function(response){$(".processingBtnImage").hide();$("#"+buton).show();if(response.Success)window.location=unescape(response.Result.replace(/\+/g," "));else SearchControl.ShowErrorMessage(searchControlFormName,response.Result)},"json");SearchControl.RestoreEmptyTexts(searchControlFormName)}else SearchControl.ShowErrorMessage(searchControlFormName);return false}};function formatDate(date){for(var formattedDate="",splittedDate=date.split("/"),i=0;i<splittedDate.length;i++)if(splittedDate[i].length==1)formattedDate=formattedDate+"0"+splittedDate[i]+"/";else formattedDate=formattedDate+splittedDate[i]+"/";if(formattedDate.charAt(formattedDate.length-1)=="/")formattedDate=formattedDate.substring(0,formattedDate.length-1);return formattedDate}function OnCityCountryFocus(hotelNameControlId){jQuery("#HotelID").val("0");jQuery("#CityID").val("0");jQuery("#"+hotelNameControlId).val("")}function OnTxtHotelName_Focus(){if(jQuery("#Country").val()>0||jQuery("#City").val()>0){jQuery("#Country").val("0");SearchControl.onDropDownCountry_IndexChange()}}function findValueCallback(event,data){jQuery("#HotelID").val("0");jQuery("#CityID").val("0");data&&data.hotelID&&jQuery("#HotelID").val(data.hotelID);data&&data.cityID&&jQuery("#CityID").val(data.cityID)}function InitializeAutocomplete(controlId,imagesURL,matchContainsValue){jQuery("#"+controlId).autocomplete(smartSearchBoxSource,{minChars:3,width:300,matchContains:matchContainsValue,autoFill:false,scroll:false,formatItem:function(row){var s="<img src='"+imagesURL;s+=row.cityID?"autocompleteCity.PNG":"autocompleteHotel.PNG";s+="'/>";s+="<span>";s+=row.name;s+="</span>";return s},formatMatch:function(row){return row.state?row.state+" "+row.name:row.name},formatResult:function(row){row.name},selectFirst:false});jQuery("#"+controlId).blur(function(){jQuery("#"+controlId).search()});jQuery("#"+controlId).result(findValueCallback).next().click(function(){jQuery(this).prev().search()})};
