﻿function Msearch_onclick() {
    showProgress();
    var url = "../hotel/list.aspx?city=" + $("#MsearchCity").val();
    if ($("#MsearchHotel").val() != "")
        url += "&hotel=" + $("#MsearchHotel").val();
    if ($("#date_begin").val() != "")
        url += "&date_begin=" + $("#date_begin").val();
    if ($("#date_end").val() != "")
        url += "&date_end=" + $("#date_end").val();
    if ($("#pr_min").val() != "")
        url += "&pr_min=" + $("#pr_min").val();
    if ($("#pr_max").val() != "")
        url += "&pr_max=" + $("#pr_max").val();
    if ($("#s_h_input_area").val() != "")
        url += "&area=" + $("#s_h_input_area").val();
    if ($("#input[name=MsearchStar]:checked").val() != "")
        url += "&star=" + $("input[name=MsearchStar]:checked").val();
    if ($("#input[name=MsearchType]:checked").val() != "")
        url += "&type=" + $("input[name=MsearchType]:checked").val();
    window.location.href = encodeURI(url);
    return false;
}
$(function() {
    var MsearchCity = $("#MsearchCity");
    var MsearchHotel = $("#MsearchHotel");
    var MsearchSelProvince = $("#Sel_province");
    var MsearchSelCity = $("#Sel_city");
    var MsearchDistrict = $("#s_h_input_area");
    var MsearchDistrictDiv = $("#s_h_input_areadiv");
    var MsearchMain = $("#MsearchMain");
    function sel_city_change() {
        MsearchSelCity.change(function() {
            MsearchCity.val(MsearchSelCity.val());
            MsearchCity.attr("val", MsearchSelCity.val());
            MsearchHotel.val("");
            MsearchDistrict.val("");
        });
        MsearchSelCity.trigger("change");
    }

    Msearch(MsearchCity.attr("id"), "'../Msearch/Msearch_City.aspx?'", function() {
        $.getJSON("../Msearch/msearch_SelCity1.aspx?" + escape(MsearchCity.val()), {}, function(data) {
            MsearchSelProvince.val(data.province);
            MsearchSelCity.html(data.city);
            MsearchHotel.val("");
            MsearchDistrict.val("");
        });
    }, "重庆|ChongQing,三亚|SanYa,香港|HongKong,丽江|LiJiang,上海|ShangHai,北京|BeiJing,成都|ChengDu,广州|GuangZhou,桂林|GuiLin,厦门|XiaMen");
    Msearch(MsearchHotel.attr("id"), "'../Msearch/msearch_hotel.aspx?city='+escape($(\"#" + MsearchCity.attr("id") + "\").val())+'&district='+escape($(\"#" + MsearchDistrict.attr("id") + "\").val())+'&name='", 0, 0, 0, 1);
    MsearchSelProvince.change(function() {
        MsearchSelCity.load("../Msearch/msearch_SelCity.aspx?" + MsearchSelProvince.val(), {}, function() {
            sel_city_change();
        });
    });
    sel_city_change();
    var s_h_input_areadivIsShow = false;
    MsearchDistrictDiv.appendTo($(document.body));
    MsearchDistrictDiv.css("left", MsearchDistrict.offset().left);
    MsearchDistrictDiv.css("top", MsearchDistrict.offset().top + MsearchDistrict.outerHeight());
    MsearchDistrict.focus(function(e) {
        MsearchDistrictDiv.load("../Msearch/Msearch_district.aspx?" + escape(MsearchCity.val()), {}, function() {
            $(this).show();
            MsearchDistrictDiv.find("li").click(function() {
                MsearchDistrict.val($(this).text());
                MsearchDistrictDiv.hide();
            });
            MsearchDistrictDiv.find("div").click(function() {
                MsearchDistrict.val("");
                MsearchDistrictDiv.hide();
            });
        });
    });
    MsearchDistrict.blur(function() {
        if (!s_h_input_areadivIsShow)
            MsearchDistrictDiv.hide();
    });
    MsearchDistrict.mousemove(function() { s_h_input_areadivIsShow = true; });
    MsearchDistrict.mouseout(function() { s_h_input_areadivIsShow = false; });
    MsearchDistrictDiv.mousemove(function() { s_h_input_areadivIsShow = true; });
    MsearchDistrictDiv.mouseout(function() { s_h_input_areadivIsShow = false; });
    $(document).click(function() {
        if (!s_h_input_areadivIsShow)
            MsearchDistrictDiv.hide();
    });
    MsearchMain.keydown(function(event) {
        if (event.keyCode == 13) {
            return Msearch_onclick();
        }
    });

    var Mcookies = function(name, value, options) { if (typeof value != "undefined") { options = options || {}; if (value === null) { value = ""; options.expires = -1; } var expires = ""; if (options.expires && (typeof options.expires == "number" || options.expires.toUTCString)) { var date; if (typeof options.expires == "number") { date = new Date(); date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000)); } else { date = options.expires; } expires = "; expires=" + date.toUTCString(); } var path = options.path ? "; path=" + options.path : ""; var domain = options.domain ? "; domain=" + options.domain : ""; var secure = options.secure ? "; secure" : ""; document.cookie = [name, "=", encodeURIComponent(value), expires, path, domain, secure].join(""); } else { var cookieValue = null; if (document.cookie && document.cookie != "") { var cookies = document.cookie.split(";"); for (var i = 0; i < cookies.length; i++) { var cookie = jQuery.trim(cookies[i]); if (cookie.substring(0, name.length + 1) == (name + "=")) { cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); break; } } } return cookieValue; } };
    $("#date_begin").val(Mcookies("date_begin"));
    $("#date_end").val(Mcookies("date_end"));
    
    $(".input_price").keyup(function() {
        var tmptxt = $(this).val();
        $(this).val(tmptxt.replace(/\D|^0/g, ''));
    }).bind("paste", function() { $(this).trriger("keyup"); }).blur(function() {
        if (parseInt($("#pr_min").val()) >= parseInt($("#pr_max").val()))
            $(this).val('');
    });
});

//international
function Msearch_onclick_inter() {
    if ($("#Text1").val() == "") {
        alert("请输入/选择城市！");
        return;
    }
    showProgress();
    var url = "../hotel/list.aspx?city=" + $("#Text1").val();
    if ($("#Text7").val() != "")
        url += "&hotel=" + $("#Text7").val();
    if ($("#Text3").val() != "")
        url += "&date_begin=" + $("#Text3").val();
    if ($("#Text4").val() != "")
        url += "&date_end=" + $("#Text4").val();
    if ($("#Text5").val() != "")
        url += "&pr_min=" + $("#Text5").val();
    if ($("#Text6").val() != "")
        url += "&pr_max=" + $("#Text6").val();
    if ($("#Text2").val() != "")
        url += "&area=" + $("#Text2").val();
    if ($("#input[name=MsearchStar2]:checked").val() != "")
        url += "&star=" + $("input[name=MsearchStar2]:checked").val();
    if ($("#input[name=MsearchType2]:checked").val() != "")
        url += "&type=" + $("input[name=MsearchType2]:checked").val();
    window.location.href = encodeURI(url);
    return false;
}
function showInternational() {
var MsearchCity = $("#Text1");
var MsearchHotel = $("#Text7");
var MsearchSelProvince = $("#ctl00_ContentPlaceHolder1_ListBox1");
var MsearchSelCity = $("#ctl00_ContentPlaceHolder1_ListBox2");
var MsearchDistrict = $("#Text2");
var MsearchDistrictDiv = $("#Div2");
var MsearchMain = $("#MsearchMain_inter");
    function sel_city_change() {
        MsearchSelCity.change(function() {
            if (MsearchSelCity.val() != null) {
                MsearchCity.val(MsearchSelCity.val());
                MsearchCity.attr("val", MsearchSelCity.val());
            } else {
                MsearchCity.val("");
                MsearchCity.attr("");            
             }
            MsearchHotel.val("");
            MsearchDistrict.val("");
        });
        MsearchSelCity.trigger("change");
    }

    Msearch(MsearchCity.attr("id"), "'../Msearch/Msearch_CityInternational.aspx?'", function() {
        $.getJSON("../Msearch/msearch_SelCity1.aspx?" + escape(MsearchCity.val()), {}, function(data) {
            MsearchSelProvince.val(data.province);
            MsearchSelCity.html(data.city);
            MsearchHotel.val("");
            MsearchDistrict.val("");
        });
    });
    Msearch(MsearchHotel.attr("id"), "'../Msearch/msearch_hotel.aspx?city='+escape($(\"#" + MsearchCity.attr("id") + "\").val())+'&district='+escape($(\"#" + MsearchDistrict.attr("id") + "\").val())+'&name='", 0, 0, 0, 1);
    MsearchSelProvince.change(function() {
        MsearchSelCity.load("../Msearch/msearch_SelCity.aspx?" + MsearchSelProvince.val(), {}, function() {
            sel_city_change();
        });
    });
    sel_city_change();
    var s_h_input_areadivIsShow = false;
    MsearchDistrictDiv.appendTo($(document.body));
    MsearchDistrictDiv.css("left", MsearchDistrict.offset().left);
    MsearchDistrictDiv.css("top", MsearchDistrict.offset().top + MsearchDistrict.outerHeight());
    MsearchDistrict.focus(function(e) {
        MsearchDistrictDiv.load("../Msearch/Msearch_district.aspx?" + escape(MsearchCity.val()), {}, function() {
            $(this).show();
            MsearchDistrictDiv.find("li").click(function() {
                MsearchDistrict.val($(this).text());
                MsearchDistrictDiv.hide();
            });
            MsearchDistrictDiv.find("div").click(function() {
                MsearchDistrict.val("");
                MsearchDistrictDiv.hide();
            });
        });
    });
    MsearchDistrict.blur(function() {
        if (!s_h_input_areadivIsShow)
            MsearchDistrictDiv.hide();
    });
    MsearchDistrict.mousemove(function() { s_h_input_areadivIsShow = true; });
    MsearchDistrict.mouseout(function() { s_h_input_areadivIsShow = false; });
    MsearchDistrictDiv.mousemove(function() { s_h_input_areadivIsShow = true; });
    MsearchDistrictDiv.mouseout(function() { s_h_input_areadivIsShow = false; });
    $(document).click(function() {
        if (!s_h_input_areadivIsShow)
            MsearchDistrictDiv.hide();
    });
    MsearchMain.keydown(function(event) {
        if (event.keyCode == 13) {
            return Msearch_onclick_inter();
        }
    });

    var Mcookies = function(name, value, options) { if (typeof value != "undefined") { options = options || {}; if (value === null) { value = ""; options.expires = -1; } var expires = ""; if (options.expires && (typeof options.expires == "number" || options.expires.toUTCString)) { var date; if (typeof options.expires == "number") { date = new Date(); date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000)); } else { date = options.expires; } expires = "; expires=" + date.toUTCString(); } var path = options.path ? "; path=" + options.path : ""; var domain = options.domain ? "; domain=" + options.domain : ""; var secure = options.secure ? "; secure" : ""; document.cookie = [name, "=", encodeURIComponent(value), expires, path, domain, secure].join(""); } else { var cookieValue = null; if (document.cookie && document.cookie != "") { var cookies = document.cookie.split(";"); for (var i = 0; i < cookies.length; i++) { var cookie = jQuery.trim(cookies[i]); if (cookie.substring(0, name.length + 1) == (name + "=")) { cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); break; } } } return cookieValue; } };
    $("#Text3").val(Mcookies("date_begin"));
    $("#Text4").val(Mcookies("date_end"));
    
    $(".input_price").keyup(function() {
        var tmptxt = $(this).val();
        $(this).val(tmptxt.replace(/\D|^0/g, ''));
    }).bind("paste", function() { $(this).trriger("keyup"); }).blur(function() {
    if (parseInt($("#Text5").val()) >= parseInt($("#Text6").val()))
            $(this).val('');
    });
}
