﻿var IndexClient=Elong.Page.IndexClient;IndexClient=Class.create();Object.extend(IndexClient.prototype,{name:"IndexClient",initialize:function(){this.initializeDOM();this.initializeEvent();this.urlTemplate=new Template(HotelIndexController.UrlConfig.Hotel_List);this.ListCityurlTemplate=new Template(HotelIndexController.UrlConfig.Hotel_ListCity);this.afterDays=HotelIndexController.AfterDays;this.inDays=HotelIndexController.InDays;this.render();},initializeDOM:function(){this.citySelectpanel=$("#citySelectpanel");this.divDatePanel=$("#divDatePanel");this.btnSearch=$("#btnSearch");this.InCityName_input=$("#InCityName_input");this.ulSearch=$("#ulSearch");},destroyDOM:function(){},initializeEvent:function(){this.citySelectpanel.bind("click",this.OnClickcitySelectpanel.bindAsEventListener(this));this.divDatePanel.bind("click",this.OnClickdivDatePanel.bindAsEventListener(this));this.btnSearch.bind("click",this.OnClickbtnSearch.bindAsEventListener(this));this.InCityName_input.bind("focus",this.OnFocusInCityNameinput.bindAsEventListener(this));this.InCityName_input.bind("change",this.OnChangeInCityName.bindAsEventListener(this));this.ulSearch.bind("keydown",this.checkSearch.bindAsEventListener(this));$(window).unload(this.dispose.bind(this));},destroyEvent:function(){},checkSearch:function(A){if(A.keyCode==13){$("#btnSearch").click();}},OnChangeInCityName:function(A){if($("#InCityName_input").val()!="undefined"&&$("#InCityName_input").val()!=""){var B=this.FindCity($("#InCityName_input").val(),"hotelcity");}},OnFocusInCityNameinput:function(A){$("#currCityName").val("");$("#OtherCityName")[0].checked;document.getElementById("OtherCityName").checked=true;},OnClickbtnSearch:function(evt){if(document.getElementById("OtherCityName").checked==true){if(validator.valid($("#InCityName_input").val(),"enString")){$("#currCityName").val($("#InCityName_input").val());}}if(!validator.valid($("#currCityName").val(),"notEmpty")){$error($("#InCityName_input"),"Please enter the city name!");return;}if(!validator.valid($("#CheckInDate").val(),"notEmpty & dateEn")){$error($("#CheckInDate"),"Please enter a valid check-in date!");return;}if(!validator.valid($("#CheckOutDate").val(),"notEmpty & dateEn")){$error($("#CheckOutDate"),"Please enter a valid check-out date!");return;}var now=new Date();var nowDate=validator.reFormatDateString(now.getFullYear()+"-"+(now.getMonth()+1)+"-"+now.getDate());var StartDate=$("#CheckInDate").val();var EndDate=$("#CheckOutDate").val();var dateStart=validator.reFormatDateString(StartDate);var dateEnd=validator.reFormatDateString(EndDate);if(dateStart<nowDate){$error($("#CheckInDate"),"The check-in date cannot be earlier than today!");return;}if(dateEnd<nowDate){$error($("#CheckOutDate"),"The check-out date cannot be earlier than today!");return;}var date=validator.convertDate(dateStart);date=new Date(date.setHours(24));if(!validator.valid($("#CheckOutDate").val(),"notEmpty & dateRange",validator.getDateString(date),null)){$error($("#CheckOutDate"),"The check-out date should be later than the check-in date!");return false;}var checkAfteDays=this.daysBetween(dateStart,validator.reFormatDateString(new Date().getFullYear()+"-"+(new Date().getMonth()+1)+"-"+new Date().getDate()));if(checkAfteDays>this.afterDays){$error($("#CheckInDate"),"If you need to reserve a hotel room for "+dateStart+",please contact our booking center by calling "+HotelIndexController.WebTelAndNo+" !");return;}var checkInDays=this.daysBetween(dateStart,dateEnd);if(checkInDays>this.inDays){$error($("#CheckOutDate"),"Reservations cannot be made online more than "+this.inDays+" days in advance.<br />Please call "+HotelIndexController.WebTelAndNo+" to make this reservation.");return;}var cityName=$("#currCityName").val();var checkInDate=$("#CheckInDate")[0].value;var checkOutDate=$("#CheckOutDate")[0].value;var star=$("#selStar").val();var price=$("#selPrice").val();var hotelName=$("#HotelName").val();if(cityName!="undefined"&&cityName!=""){cityName=this.FindCity(cityName,"hotelcity");}if(!validator.valid(cityName,"notEmpty")){$error($("#InCityName_input"),"Invalid city name!");return;}this.WaitingProcess();var arrPrice=price.split(",");var LowPrice=arrPrice[0];var HighPrice=arrPrice[1];Globals.cookie("ShHotel","",{InDate:checkInDate,OutDate:checkOutDate});var url=this.urlTemplate.eval({cityid:cityName,enterdate:validator.reFormatDateString(checkInDate),exitdate:validator.reFormatDateString(checkOutDate),starlevel:star,language:"en",lowprice:LowPrice,highprice:HighPrice,areaid:0,language:HotelIndexController.Language.toLowerCase(),hotelsort:1,pageindex:1});var actionUrl;if(hotelName==""){actionUrl=url;}else{actionUrl=url+""+(HotelIndexController.CampaignId==""?"?s="+hotelName:"&s="+hotelName);}if(LowPrice=="0"&&HighPrice=="0"&&star=="-1"){var url=this.ListCityurlTemplate.eval({cityid:cityName,language:HotelIndexController.Language.toLowerCase()});if(hotelName==""){actionUrl=url;}else{actionUrl=url+""+(HotelIndexController.CampaignId==""?"?s="+hotelName:"&s="+hotelName);}}$("#ConditionForm").attr("action",actionUrl);$("#ConditionForm").submit();},OnClickdivDatePanel:function(B){var C=Event.element(B);var A=C.attr("method");switch(A){case"EnterDate":new CalendarWindow({eventElement:C,selectedDate:C.val(),language:"en",onSelected:function(E){C.val(E);$("#CheckOutDate").click();}.bind(this)});break;case"OutDate":var D=validator.convertDate($("#CheckInDate").val());D=new Date(D.setHours(24));D=validator.reFormatDateString(D.getFullYear()+"-"+(D.getMonth()+1)+"-"+D.getDate());new CalendarWindow({eventElement:C,selectedDate:validator.reFormatDateString(D),language:"en",enabledFrom:validator.reFormatDateString(D),onSelected:function(E){C.val(E);}.bind(this)});break;}},OnClickcitySelectpanel:function(C){var D=Event.element(C);var A=D.attr("method");var B=this.citySelectpanel.find("input[name='InCityName']:checked").val();$("#currCityName").val(B);},WaitingProcess:function(A){document.getElementById("divWaiting").style.display="block";document.getElementById("ulSearch").style.display="none";document.getElementById("divSeekGif").className="s-lbj";$(".search_box").addClass("search_lbox");},FindCity:function(cityname,citytype){var cityData;eval("cityData = "+citytype+";");var cityName="CityNameEn";var result=Globals.searchObj(cityName,cityname,cityData);if(result.length>0&&result[0]!=null){return decodeURIComponent(result[0].CityId);}return"";},daysBetween:function(A,I){var B=A.substring(5,A.lastIndexOf("-"));var F=A.substring(A.length,A.lastIndexOf("-")+1);var C=A.substring(0,A.indexOf("-"));var D=I.substring(5,I.lastIndexOf("-"));var G=I.substring(I.length,I.lastIndexOf("-")+1);var E=I.substring(0,I.indexOf("-"));var H=((Date.parse(B+"/"+F+"/"+C)-Date.parse(D+"/"+G+"/"+E))/86400000);return Math.abs(H);},render:function(){var A={dataId:"hotelcity",dataHotId:"hotelcityhot",needGetData:false,needGetDataHot:false,hotHeight:"155"};$("#InCityName_input").CitySuggest(jQuery.CitySuggest.OptionsEn,jQuery.extend({},A,{resultId:"currCityName",resultNextId:"CheckInDate",resultExtendMethod:function(C,D,B){$("#currCityName").val(D.CityNameEn);}}));},dispose:function(){this.destroyEvent();this.destroyDOM();}});var client=null;$ready(function(){client=new IndexClient();});