﻿$(document).ready(function() {
    if (_g("hd_p") && _g("hd_c")) { search_show(); }
    initLocalFull("sh_p", "sh_c", "hd_p", "hd_c");
    initpcs("sh_cn");
    initDate("sh_st", "sh_et", "img_st", "img_et");
    _g("sh_st").value = getSearchStartTime();
    _g("sh_et").value = getSearchEndTime(3);
    $("#sh_cn").focus(function() { if (this.value == "中文或拼音") this.value = ""; });
    $("#sh_cn").blur(function() { if (this.value == "") this.value = "中文或拼音"; });
    init_sh_n();
    initClickEvent();
});
function doSearch(btn) {
    var pid = _g("sh_p").value;
//    if (pid == "" || pid == "0") {
//        alert("请选择省份！");
//        return false;
//    }
    var cid = _g("sh_c").value;
    if (cid == "" || cid == "0") {
        alert("请选择城市！");
        _g("sh_cn").focus();
        return false;
    }
    var st = _g("sh_st").value;
    if (st == "") {
        alert("请选择入住时间！");
        _g("sh_st").focus();
        return false;
    }
    var et = _g("sh_et").value;
    if (et == "") {
        alert("请选择离店时间！");
        _g("sh_et").focus();
        return false;
    }
    var d1 = sToDate(st);
    var d2 = sToDate(et);
    if (d2 <= d1) {
        alert("离店时间必须在入住时间之后！");
        _g("sh_et").focus();
        return false;
    }
    //通过Cookie记录用户选择de城市
    setCookie("search_info", pid + "_" + cid);
    
    var at = 0;
    if (_g("sh_b").checked)
        at = 1;
    var ab = "0";
    var abc = _g("sh_ab");
    if (abc)
        ab = abc.options[abc.selectedIndex].value;
    var star = "";
    var sa = new Array();
    var rbs = document.getElementsByName("sh_s");
    for (var i = 0; i < rbs.length; i++) {
        if (rbs[i].checked) {
            if (rbs[i].value == "0") {
                star = "0";
                break;
            }
            sa.push(rbs[i].value);
        }
    }
    if (star != "0")
        star = sa.join(",");
    var dn = "";
    if (_g("sh_d").checked)
        dn = "1";
    var jj = "";
    if (_g("sh_j").checked)
        jj = "1";
    var price = "0";
    var rbp = document.getElementsByName("sh_p");
    for (var i = 0; i < rbp.length; i++) {
        if (rbp[i].checked) {
            price = rbp[i].value;
            break;
        }
    }
    var nm = _g("sh_n").value;
    if (nm == "输入酒店部分或全部名称")
        nm = "";
    var nnm = trim(nm);
    var url = "/Search/Prov" + pid + "/City" + cid + "/From" + st + "/To" + et + "/";
    if (at == 0)
        url += "Area" + ab + "/Commerce/";
    else
        url += "Area/Commerce" + ab + "/";
    url += "Star" + star + "/Price" + price + "/PC" + dn + "/Air" + jj + "/";
    if (nm != "")
        url += "Key-" + encodeURIComponent(nnm) + "/";
    else
        url += "Key-/";
    url += "List.shtml";
    document.location = url;
    btn.disabled = true;
}
function init_sh_n() {
    $("#sh_n").val("输入酒店部分或全部名称");
    $("#sh_n").addClass("gray");
    $("#sh_n").focus(function() { if (this.value == "输入酒店部分或全部名称") { this.value = ""; this.className = ""; } });
    $("#sh_n").blur(function() { if (this.value == "") { this.value = "输入酒店部分或全部名称"; this.className = "gray"; } });
}