﻿$(document).ready(function() {
var pv = "";
if (_g("hsv_p") && _g("hsv_p").value)
    pv = _g("hsv_p").value;
var cv = "";
if (_g("hsv_c") && _g("hsv_c").value)
    cv = _g("hsv_c").value;
if (_g("hsv_p") && _g("hsv_c"))
    {
    setCookie("search_info", pv + "_" + cv);}
    if (_g("hd_p") && _g("hd_c")) { search_show(); }

    initLocalSide("sh_p", "sh_c", _g("hd_p").value, _g("hd_c").value);
    
    //    initLocalSide("sh_p", "sh_c", pv, cv);
    initpcs("sh_cn");
    initDate("sh_st", "sh_et");
    checkInitInOutTime();
    checkInitStar();
    checkInitPrice();
    $("#sh_cn").focus(function() { if (this.value == "中文或拼音") this.value = ""; });
    $("#sh_cn").blur(function() { if (this.value == "") this.value = "中文或拼音"; });
    init_sh_n();
    initClickEvent();
    initSearchTime();

});
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"; } });
}
function initSearchTime() {
    if (_g("sh_st")) {
        _g("sh_st").value = getSearchStartTime();
    }
    if (_g("sh_et")) {
        _g("sh_et").value = getSearchEndTime();
    }
        
}
function checkInitArea() {
    if (_g("sh_a").options.length > 1 && _g("hsv_a") && _g("hsv_a").value) {
        for (var i = 0; i < _g("sh_a").options.length; i++) {
            if (_g("sh_a").options[i].value == _g("hsv_a").value) {
                _g("sh_a").selectedIndex = i;                
                break;
            }
        }
    }
}
function checkInitBizArea() {
    if (_g("sh_b").options.length > 1 && _g("hsv_b") && _g("hsv_b").value) {
        for (var i = 0; i < _g("sh_b").options.length; i++) {
            if (_g("sh_b").options[i].value == _g("hsv_b").value) {                
                _g("sh_b").selectedIndex = i;
                break;
            }
        }
    }
}

function checkInitStar() {
    if (_g("sh_s").options.length > 1 && _g("hsv_s") && _g("hsv_s").value) {
        for (var i = 0; i < _g("sh_s").options.length; i++) {
            if (_g("sh_s").options[i].value == _g("hsv_s").value) {
                _g("sh_s").selectedIndex = i;
                break;
            }
        }
    }
}
function checkInitPrice() {
    if (_g("sh_r").options.length > 1 && _g("hsv_r") && _g("hsv_r").value) {
        for (var i = 0; i < _g("sh_r").options.length; i++) {
            if (_g("sh_r").options[i].value == _g("hsv_r").value) {
                _g("sh_r").selectedIndex = i;
                break;
            }
        }
    }
}
function checkInitInOutTime() {
    if (_g("hsv_st") && _g("hsv_st").value != "")
        _g("sh_st").value = _g("hsv_st").value;
    else
        _g("sh_st").value = getCurrentDate();
    if (_g("hsv_et") && _g("hsv_et").value != "")
        _g("sh_et").value = _g("hsv_et").value;
    else
        _g("sh_et").value = getNextDay(3);
}
function checkInitInName() {
    if (_g("hsv_n") && _g("hsv_n").value != "")
        _g("sh_n").value = _g("hsv_n").value;    
}
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("请选择城市！");
        return false;
    }
    setCookie("search_info", pid + "_" + cid);
    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;
    }
    setCookie("search_info", pid + "_" + cid);
    var area = _g("sh_a").value;
    var bizarea = _g("sh_b").value;
    var star = _g("sh_s").value;   
    var price = _g("sh_r").value;
    var nm = _g("sh_n").value;
    if (nm == "输入关键字")
        nm = "";
   
    var nnm = trim(nm);
    var url = "/Search/Prov" + pid + "/City" + cid + "/From" + st + "/To" + et + "/";
    url += "Area" + area + "/Commerce" + bizarea + "/";
    url += "Star" + star + "/Price" + price + "/PC/Air/";
    if (nm != "")
        url += "Key-" + encodeURIComponent(nnm) + "/";
    else
        url += "Key-/";
    url += "List.shtml";
    document.location = url;
    btn.disabled = true;
}