公司前端脚本

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.urlMapTemplate = new Template(HotelIndexController.UrlConfig.Hotel_ListMap);
                this.afterDays = HotelIndexController.AfterDays;
                this.inDays = HotelIndexController.InDays;
                this.WebCategory = HotelIndexController.WebKind;
                this.render();
            },
            initializeDOM: function () {
                this.dvSearchRegion = $("#dvSearchRegion");
                this.hotelName = $("#HotelName");
                this.InCityName_input = $("#InCityName_input");
                this.InCityName = $("#InCityName");
            },
            destroyDOM: function () {
                this.dvSearchRegion = null;
            },
            initializeEvent: function () {
                this.dvSearchRegion.bind("click", this.OnClickdvSearchRegion.bindAsEventListener(this));
                this.hotelName.bind("focus", this.OnFocusHotelName.bindAsEventListener(this));
                this.hotelName.bind("blur", this.OnBlurHotelName.bindAsEventListener(this));
                this.dvSearchRegion.bind("change", this.OnChangedvSearchRegion.bindAsEventListener(this));
                this.InCityName_input.bind("change", this.OnChangeInCityName_input.bindAsEventListener(this));
                this.InCityName.bind("change", this.OnChangeInCityName.bindAsEventListener(this));
                this.InCityName.bind("focus", this.OnFocusInCityName.bindAsEventListener(this));
                
                this.dvSearchRegion.bind("keydown", this.checkSearch.bindAsEventListener(this));
                $(window).unload(this.dispose.bind(this));
            },
            destroyEvent: function () { },
            CreateGuid: function () {
                var a = "";
                for (var b = 1; b <= 32; b++) {
                    var c = Math.floor(Math.random() * 16).toString(16);
                    a += c;
                    if ((b == 8) || (b == 12) || (b == 16) || (b == 20)) {
                        a += "-";
                    }
                } return a;
            },
            CreateAndSaveSearchGuid: function (b) {
                var a = b;
                if (Object.isNull(b)) {
                    a = this.CreateGuid();
                }
                Globals.cookie("TriggerSearchGUID", "", a, { expires: 1, path: "/", secure: false });
            },
            checkSearch: function (a) {
                if (a.keyCode == 13) {
                    $("#btnSearch").click();
                }
            },
            OnFocusInCityName: function (a) {
                $("#InCityName_input").val("");
                $("#InCityName").removeClass();
                $("#InCityName").addClass("city-i sc-w1");
            },
            OnChangeInCityName: function (b) {
                var a = Event.element(b);
                $("#InCityName").removeClass();
                $("#InCityName").addClass("city-i sc-w1");
            },
            OnFocusHotelName: function (b) {
                var a = Event.element(b);
                if (a[0].value == "输入酒店部分或全部名称") {
                    a[0].value = "";
                }
                $("#HotelName").removeClass();
                $("#HotelName").addClass("sc-w4");
            },
            OnBlurHotelName: function (b) {
                var a = Event.element(b);
                if (a[0].value == "") {
                    a[0].value = "输入酒店部分或全部名称";
                    $("#HotelName").removeClass(); $("#HotelName").addClass("sc-w4 l_black");
                }
            },
            OnChangeInCityName_input: function (a) { },
            OnChangedvSearchRegion: function (b) {
                var a = Event.element(b);
                var c = a.attr("method");
                switch (c) {
                    case "txtEnterDate":
                    case "txtOutDate":
                        break;
                }
            },
            OnClickdvSearchRegion: function (evt) {
                var element = Event.element(evt);
                var method = element.attr("method");
                switch (method) {
                    case "txtEnterDate":
                        new CalendarWindow({ eventElement: element, selectedDate: element.val(), language: "cn",
                            onSelected: function (date) {
                                element.val(date);
                                $("#CheckOutDate").click();
                                $("#CheckInDate").removeClass();
                                $("#CheckInDate").addClass("time-i sc-w");
                            } .bind(this)
                        });
                        break;
                    case "txtOutDate":
                        var edate = validator.convertDate($("#CheckInDate").val());
                        edate = new Date(edate.setHours(24));
                        edate = validator.reFormatDateString(edate.getFullYear() + "-" + (edate.getMonth() + 1) + "-" + edate.getDate());
                        new CalendarWindow({ eventElement: element, selectedDate: validator.reFormatDateString(edate), language: "cn",
                            enabledFrom: validator.reFormatDateString(edate),
                            onSelected: function (date) {
                                element.val(date);
                                $("#CheckOutDate").removeClass();
                                $("#CheckOutDate").addClass("time-i sc-w");
                            } .bind(this)
                        });
                        break;
                    case "lnkGo2Map":
                        if (!this.searchValid()) {
                            return false;
                        } if ($("#InCityName").get(0).City == null) {
                            $error($("#InCityName"), "没有匹配的城市。");
                            return false;
                        }
                        var cityName = $("#InCityName").get(0).City.CityNameCn;
                        var cityId = $("#InCityName").get(0).City.CityId;
                        var cityNameEn = $("#InCityName").get(0).City.CityNameEn;
                        var checkInDate = $("#CheckInDate")[0].value;
                        var checkOutDate = $("#CheckOutDate")[0].value;
                        var star = $("#Star").val();
                        var price = $("#Price").val();
                        var hotelName = $("#HotelName").val();
                        var arrPrice = price.split(",");
                        var LowPrice = arrPrice[0];
                        var HighPrice = arrPrice[1];
                        if (cityId == "")
                        { $error($("#InCityName"), "没有匹配的城市。"); return false; }
                        var url = this.urlMapTemplate.eval({ cityid: cityId, starlevel: star, lowprice: LowPrice, highprice: HighPrice, startlat: 0, startlng: 0, areaid: 0, endlat: 0, endlng: 0, distance: 5, language: HotelIndexController.Language.toLowerCase(), hotelsort: 1, brandid: 0, pageindex: 1 });
                        this.CreateAndSaveSearchGuid(null); Globals.cookie("ShHotel", "", { InDate: checkInDate, OutDate: checkOutDate, CityNameCN: cityName, CityNameEN: cityNameEn, CityID: cityId }); var hotelStr = ""; hotelStr = hotelStr + "raCityName|" + cityName + ","; hotelStr = hotelStr + "CheckInDate|" + checkInDate + ","; hotelStr = hotelStr + "CheckOutDate|" + checkOutDate; try { this.writeHotelCookie("elong_hotel_cookie", hotelStr, 1); } catch (e) { } if (HotelIndexController.WebCategory != "Online") { $("#lnkGo2Map")[0].href = url; } break; case "Price": $("#Price").css({ color: "#000" }); break; case "Star": $("#Star").css({ color: "#000" }); break; case "btnSearch": if (!this.searchValid()) { return false; } if ($("#InCityName").get(0).City == null) { $error($("#InCityName"), "没有匹配的城市。"); return false; } var cityName = $("#InCityName").get(0).City.CityNameCn; var cityNameEn = $("#InCityName").get(0).City.CityNameEn; var cityId = $("#InCityName").get(0).City.CityId; var checkInDate = $("#CheckInDate")[0].value; var checkOutDate = $("#CheckOutDate")[0].value; var star = $("#Star").val(); var price = $("#Price").val(); var hotelName = $("#HotelName").val(); var arrPrice = price.split(","); var LowPrice = arrPrice[0]; var HighPrice = arrPrice[1]; if (cityId == "") { $error($("#InCityName"), "没有匹配的城市。"); return false; } Globals.cookie("ShHotel", "", { InDate: checkInDate, OutDate: checkOutDate, CityNameCN: cityName, CityNameEN: cityNameEn, CityID: cityId }); this.WaitingProcess(); var url = this.urlTemplate.eval({ language: HotelIndexController.Language.toLowerCase(), cityid: cityId }); if (star != "-1") { url += (url.indexOf("?") != -1 ? "&" : "?") + "starlevel=" + star; } if (HighPrice != "0") { url += (url.indexOf("?") != -1 ? "&" : "?") + "highprice=" + HighPrice; } if (LowPrice != "0") { url += (url.indexOf("?") != -1 ? "&" : "?") + "lowprice=" + LowPrice; } if (HotelIndexController.WebCategory == "Online") { url += (url.indexOf("?") != -1 ? "&" : "?") + "hotelsort=2"; } if (hotelName != "输入酒店部分或全部名称") { url += (url.indexOf("?") != -1 ? "&" : "?") + "q=" + encodeURIComponent(hotelName) + "&qt=9"; } if (window.location.host == "big5.elong.com") { url = "http://big5.elong.com/gate/big5/hotel.elong.com" + url; url += url.indexOf("?") != -1 ? "&isbig5=true" : "?isbig5=true"; } $("#ConditionForm").attr("action", url); $("#ConditionForm").submit(); break;
                }
            },
            FindCity: function (cityname, citytype) {
                var cityData; eval("cityData = " + citytype + ";");
                var resultCN = Globals.searchObj("CityNameCn", cityname, cityData);
                if (resultCN.length > 0 && resultCN[0] != null) {
                    return decodeURIComponent(resultCN[0].CityId);
                }
                var resultEN = Globals.searchObj("CityNameEn", cityname, cityData);
                if (resultEN.length > 0 && resultEN[0] != null) {
                    return decodeURIComponent(resultEN[0].CityId);
                } return "";
            },
            WaitingProcess: function (a) {
                document.getElementById("divSearch").style.display = "block";
                document.getElementById("ulSearch").style.display = "none";
            },
            daysBetween: function (b, c) {
                var e = b.substring(5, b.lastIndexOf("-"));
                var d = b.substring(b.length, b.lastIndexOf("-") + 1);
                var f = b.substring(0, b.indexOf("-"));
                var h = c.substring(5, c.lastIndexOf("-")); var g = c.substring(c.length, c.lastIndexOf("-") + 1); var i = c.substring(0, c.indexOf("-")); var a = ((Date.parse(e + "/" + d + "/" + f) - Date.parse(h + "/" + g + "/" + i)) / 86400000); return Math.abs(a);
            },
            render: function () {
                var b = Globals.cookie("ShHotel");
                if (b != null && b != "") {
                    if (Globals.cookie("ShHotel", "CityNameCN") != "" && b.indexOf("CityNameCN") > 0) {
                        $("#InCityName").val(Globals.cookie("ShHotel", "CityNameCN"));
                        $("#InCityName").attr("cityid", Globals.cookie("ShHotel", "CityID"));
                        $("#InCityName").attr("cityname", Globals.cookie("ShHotel", "CityNameEN"));
                    }
                } else {
                    $("#InCityName").val("北京");
                    $("#InCityName").attr("cityid", "0101");
                    $("#InCityName").attr("cityname", "beijing");
                }
                var a = new CityWindow({ eventElement: $("#InCityName"), cityType: "hotel", lang: "cn", resultNextId: "CheckInDate", onSelect: function (d, c) { } }); 
                if (HotelIndexController.Language != "EN") { this.hotelName.HotelSuggest("http://hotel.elong.com/suggest.html", { matchSubset: false, formatItem: function (c) { return c; }, scroll: true, scrollHeight: 300, max: 10, mouseDownOnSelect: true, dataType: "jsonp", delay: 200, submitId: $("#btnSearch"), isSubmit: true, extraParams: { EnCode: "UTF", CityId: function () { return $("#InCityName").get(0).City.CityId; } } }); }
            },
            onCityNameChange: function () { },
            searchValid: function () {
                if (!validator.valid($("#InCityName").val(), "notEmpty & nonSpecialSign")) {
                    $error($("#InCityName"), "请输入城市名称,且不可包含*&+等符号及阿拉伯数字。"); return false;
                } if (!validator.valid($("#CheckInDate").val(), "notEmpty & date")) { $error($("#CheckInDate"), "请输入有效的入住日期。"); return false; }
                if (!validator.valid($("#CheckOutDate").val(), "notEmpty & date")) { $error($("#CheckOutDate"), "请输入有效的离店日期。"); return false; }
                var g = new Date(); var h = validator.reFormatDateString(g.getFullYear() + "-" + (g.getMonth() + 1) + "-" + g.getDate());
                var i = $("#CheckInDate").val();
                var f = $("#CheckOutDate").val();
                var e = validator.reFormatDateString(i);
                var d = validator.reFormatDateString(f);
                if (e < h) {
                    $error($("#CheckInDate"), "入住日期须晚于或者等于当天日期。");
                    return false;
                } if (d < h) { $error($("#CheckOutDate"), "离店日期须晚于或者等于当天日期。"); return false; }
                      var c = validator.convertDate(e); c = new Date(c.setHours(24)); if (!validator.valid($("#CheckOutDate").val(), "notEmpty & dateRange", validator.getDateString(c), null)) { $error($("#CheckOutDate"), "离店日期须至少晚于入住日期1天。"); return false; } var a = this.daysBetween(e, validator.reFormatDateString(new Date().getFullYear() + "-" + (new Date().getMonth() + 1) + "-" + new Date().getDate())); if (a > this.afterDays) { $error($("#CheckInDate"), "如果您需要预订" + e + "的酒店,请致电:" + HotelIndexController.WebTelAndNo + ",我们会竭诚为您服务。"); return false; } var b = this.daysBetween(e, d); if (b > this.inDays) { $error($("#CheckOutDate"), "如果您需要在酒店入住" + this.inDays + "天以上,请致电:" + HotelIndexController.WebTelAndNo + ",我们会竭诚为您服务。"); return false; } return true; },
            dispose: function () {
                this.destroyEvent();
                this.destroyDOM();
            }
        });
        var client = null;
        $ready(function () {
            client = new IndexClient();
        });
posted @ 2011-06-30 00:16  jackyong  阅读(646)  评论(0编辑  收藏  举报