﻿//报价
var currentDiv = "";
$(document).ready(function () {
    //报价
    $("#priceService").click(function () { HideLi("liPriceCountry,liPriceProvince"); ShowLi("liPriceService"); })
    //$("#priceService").blur(function () { setTimeout(function () { document.getElementById("liPriceService").style.display = "none"; }, 120) })
    $("#priceCountry").click(function () { HideLi("liPriceService,liPriceProvince"); ShowLi("liPriceCountry"); })
    $("#priceProvince").click(function () { HideLi("liPriceService,liPriceCountry"); ShowLi("liPriceProvince"); })
    GetLiValue("liPriceService", "priceService", "hidPriceService");
    OtherCountryPart();
    //景点
    $("#liArea").click(function () { HideLi("liSceneryCountry,liSceneryType"); ShowLi("liSceneryArea"); })
    //$("#liArea").blur(function () { setTimeout(function () { document.getElementById("liSceneryArea").style.display = "none"; }, 120) })
    $("#liCountry").click(function () { HideLi("liSceneryArea,liSceneryType"); ShowLi("liSceneryCountry"); })
    //$("#liCountry").blur(function () { setTimeout(function () { document.getElementById("liSceneryCountry").style.display = "none"; }, 120) })
    $("#liType").click(function () { HideLi("liSceneryArea,liSceneryCountry"); ShowLi("liSceneryType"); })
    //$("#liType").blur(function () { setTimeout(function () { document.getElementById("liSceneryType").style.display = "none"; }, 120) })
    AreaClick("liSceneryArea", "liArea", "hid_Area");
    SceneryTypeClick("liSceneryCountry", "liCountry", "hid_Country");
    SceneryTypeClick("liSceneryType", "liType", "hid_Type");
    $("#hid_Area").val(0);
    $("#hid_Country").val(0);
    $("#hid_Type").val(0);
    //院校
    //模糊搜索
    document.getElementById("aRightImgSearch").onclick = function () {
        delCookieParm();
        var schoolName = document.getElementById("keyindex");
        if (schoolName.value.trim().length > 0 && schoolName.value.trim() != "可输入院校名称") {
            window.open("http://school.nihaowang.com/SearchResult.aspx?schoolName=" + escape(schoolName.value.trim()));
        }
        else {
            alert("请输入院校名称");
            return;
        }
    }
    $("#liSchoolCountry").click(function () { HideLi("liSchoolEducationList"); ShowLi("liSchoolCountryList"); })
    //$("#liSchoolCountry").blur(function () { setTimeout(function () { document.getElementById("liSchoolCountryList").style.display = "none"; }, 120) })
    $("#liSchoolEducation").click(function () { HideLi("liSchoolCountryList"); ShowLi("liSchoolEducationList"); })
    //$("#liSchoolEducation").blur(function () { setTimeout(function () { document.getElementById("liSchoolEducationList").style.display = "none"; }, 120) })
    SceneryTypeClick("liSchoolCountryList", "liSchoolCountry", "hid_SchoolCountry");
    SceneryTypeClick("liSchoolEducationList", "liSchoolEducation", "hid_Education");
    $("#hid_SchoolCountry").val(0);
    $("#hid_Education").val(0);
})
function OtherCountryPart() {
    var others = document.getElementsByName("otherCountry");
    for (var i = 0; i < others.length; i++) {
        others[i].onclick = function () {
            var parentLi = this.parentNode;
            var liParts = parentLi.getElementsByTagName("li");
            if (this.checked) {
                for (var j = 0; j < liParts.length; j++) {
                    liParts[j].getElementsByTagName("input")[0].checked = true;
                }
            }
            else {
                for (var j = 0; j < liParts.length; j++) {
                    liParts[j].getElementsByTagName("input")[0].checked = false;
                }
            }
        }
    }
}
function ShowLi(objID) {
    currentDiv = objID;
    var objLi = document.getElementById(objID);
    if (document.getElementById("countryOrLanguage").innerHTML == "语种:") {
        document.getElementById("ulCountry").style.display = "none";
        document.getElementById("ulCountryOther").style.display = "none";
        document.getElementById("ulLanguage").style.display = "block";
    }
    objLi.style.display = "block";
}
function HideLi(LiID) {
    var lis = LiID.split(",");
    for (var i = 0; i < lis.length; i++) {
        document.getElementById(lis[i]).style.display = "none";
    }
    document.getElementById("ulCountry").style.display = "block";
    document.getElementById("ulCountryOther").style.display = "none";
}
function GetLiValue(LiID, inputID, hidInputID) {
    var objLl = document.getElementById(LiID);
    var objLis = objLl.getElementsByTagName("li");
    for (var i = 0; i < objLis.length; i++) {
        objLis[i].onclick = function () {
            //var objValueA = this.getElementsByTagName("a");
            $("#" + inputID).val(this.innerHTML);
            //$("#" + inputID).val(objValueA[0].innerHTML);
            $("#" + hidInputID).val(this.value);
            HideLi(LiID);
            if ($("#" + hidInputID).val() == 4 || $("#" + hidInputID).val() == 7) {
                if (document.getElementById("countryOrLanguage").innerHTML == "前往国家:") {
                    document.getElementById("countryOrLanguage").innerHTML = "语种:";
                    document.getElementById("ulCountry").style.display = "none";
                    document.getElementById("ulCountryOther").style.display = "none";
                    document.getElementById("ulLanguage").style.display = "block";
                    document.getElementById("CountryOther").style.display = "none";
                    document.getElementById("priceCountry").value = "不限";
                    document.getElementById("hidPriceCountry").value = "";
                }
            }
            else {
                if (document.getElementById("countryOrLanguage").innerHTML == "语种:") {
                    document.getElementById("countryOrLanguage").innerHTML = "前往国家:";
                    document.getElementById("ulCountry").style.display = "block";
                    document.getElementById("ulCountryOther").style.display = "none";
                    document.getElementById("ulLanguage").style.display = "none";
                    document.getElementById("CountryOther").style.display = "block";
                    document.getElementById("priceCountry").value = "不限";
                    document.getElementById("hidPriceCountry").value = "";
                }
            }
        }
    }
}
function GetLiValues(LiID, objName, inputID, hidInputID) {
    if (LiID == "liPriceCountry") {
        if (document.getElementById("countryOrLanguage").innerHTML == "语种:") {
            objName = "cboLanguage";
        }
    }
    var objChecks = document.getElementsByName(objName);
    var valuesID = "";
    var valuesName = "";
    for (var i = 0; i < objChecks.length; i++) {
        if (objChecks[i].checked) {
            valuesID += objChecks[i].value + ",";
            valuesName += objChecks[i].nextSibling.innerHTML + ",";
        }
    }
    valuesID = valuesID.substring(0, valuesID.lastIndexOf(","));
    valuesName = valuesName.substring(0, valuesName.lastIndexOf(","));
    if (objName != "cboLanguage") {
        $("#" + hidInputID).val(valuesID);
    }
    $("#" + inputID).val(valuesName == "" ? "不限" : valuesName);
    HideLi(LiID);
}
function NullValues(LiID, inputID, hidInputID) {
    $("#" + hidInputID).val("");
    $("#" + inputID).val("不限");
    HideLi(LiID);
}
function ShowCountryOther() {
    document.getElementById("liPriceCountry").style.display = "none";
    document.getElementById("ulCountryOther").style.display = "block";
}
function searchPrice() {
    var Type = $("#priceService").val();
    var Country = $("#priceCountry").val();
    var Language = $("#hidPriceCountry").val();
    var Province = $("#priceProvince").val();
    var order = -1; //$("#txt_order").val();
    if (Type == "必选" || Type == "") {
        alert('请选择服务类型');
        return;
    }
    //alert("http://price.nihaowang.com/quotation/index_project.aspx?Type=" + Type + "&Country=" + Country + "&Language=" + Language + "&Province=" + Province + "&order=" + order);
    window.parent.open("http://price.nihaowang.com/quotation/index.aspx?Type=" + escape(Type) + "&Country=" + escape(Country) + "&Language=" + escape(Language) + "&Province=" + escape(Province) + "&order=" + escape(order));
}

//景点
//大洲列表单击事件
var cache_data_scenery_country = new Array()
function AreaClick(LiID, inputID, hidInputID) {
    var objLl = document.getElementById(LiID);
    var objLis = objLl.getElementsByTagName("li");
    for (var i = 0; i < objLis.length; i++) {
        objLis[i].onclick = function () {
            document.getElementById(inputID).innerHTML = this.innerHTML;
            $("#" + hidInputID).val(this.value);
            HideLi(LiID);

            if (cache_data_scenery_country[this.value] != null) {
                $("#ulSceneryCountry").html("");
                $("#ulSceneryCountry").html(cache_data_scenery_country[this.value]);
            }
            else {
                $.post("indexUserControl/scenery.ashx", { oper: "getCountry", areaID: this.value },
                    function (data) {
                        $("#ulSceneryCountry").html(data);
                        var objUlCountry = document.getElementById("ulSceneryCountry");
                        var objLisCountry = objUlCountry.getElementsByTagName("li");
                        for (var j = 0; j < objLisCountry.length; j++) {
                            objLisCountry[j].onclick = function () {
                                document.getElementById("liCountry").innerHTML = this.innerHTML;
                                $("#hid_Country").val(this.value);
                                HideLi("liSceneryCountry");
                            }
                        }
                    });
            }

        }
    }
}
var eduList = "<li value=\"0\">不限</li><li value=\"4\">本科</li><li value=\"5\">硕士</li><li value=\"7\">博士</li>" +
                "<li value=\"6\">MBA</li><li value=\"2\">预科</li><li value=\"1\">语言中心</li><li value=\"3\">专科</li>" +
                "<li value=\"8\">副博士</li><li value=\"9\">专家</li><li value=\"10\">网校</li>";
var eduList1 = "<li value=\"0\">不限</li><li value=\"4\">本科</li><li value=\"5\">硕士</li><li value=\"7\">博士</li>" +
                "<li value=\"6\">MBA</li><li value=\"2\">预科</li><li value=\"1\">语言中心</li><li value=\"3\">专科</li>" +
                "<li value=\"10\">网校</li>";
function SceneryTypeClick(LiID, inputID, hidInputID) {
    var objLl = document.getElementById(LiID);
    var objLis = objLl.getElementsByTagName("li");
    for (var i = 0; i < objLis.length; i++) {
        objLis[i].onclick = function () {
            if (LiID == "liSchoolCountryList") {
                if (this.innerHTML == "俄罗斯") {
                    document.getElementById("ulEdu").innerHTML = eduList;
                    SceneryTypeClick("liSchoolEducationList", "liSchoolEducation", "hid_Education");
                }
                else {
                    document.getElementById("ulEdu").innerHTML = eduList1;
                    SceneryTypeClick("liSchoolEducationList", "liSchoolEducation", "hid_Education");
                }
            }
            document.getElementById(inputID).innerHTML = this.innerHTML;
            $("#" + hidInputID).val(this.value);
            HideLi(LiID);
        }
    }
}
function Submit() {
    var url = "http://scenery.nihaowang.com/searchResult.html";
    var area = document.getElementById("hid_Area").value;
    var sceneryCountry = document.getElementById("hid_Country").value;
    var sceneryType = document.getElementById("hid_Type").value;
    if (area == "0" && sceneryCountry == "0" && sceneryType == "0") {// && sceneryName.value == "可输入景点名称"
        alert("请至少选择一个搜索条件");
    } else {
        url += "?s1=" + area + "&s2=" + sceneryCountry + "&s3=" + escape(sceneryType) + "";
        window.open(url);
    }
}

//院校
function stripscript(s) {
    var pattern = new RegExp("[`~!@#$^&*()=|{}':;',<>\\[\\].&lt;&gt;/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？]")
    var rs = "";
    for (var i = 0; i < s.length; i++) {
        rs = rs + s.substr(i, 1).replace(pattern, '');
    }
    return rs;
}
function Search() {
//    var schoolCountry = document.getElementById("hid_SchoolCountry").value;
//    var schoolEducation = document.getElementById("hid_Education").value;
//    var major = stripscript(document.getElementById("liSchoolMajor").innerHTML);
//    if (schoolCountry == "0") {
//        alert('国家必选！');
//    }
//    else {
//        var url = "http://search.nihaowang.com/c" + schoolCountry;
//        if (schoolEducation != 0) {
//            url += "x" + schoolEducation;
//        }
//        url += ".html";
//        if (major != '' && major != '可输入所查询专业') {
//            url += "?z=" + escape(major);
//        }
//        window.open(url);
//    }

    var schoolCountry = document.getElementById("hid_SchoolCountry").value;
    var schoolEducation = document.getElementById("liSchoolEducation").innerHTML;
    var major = stripscript(document.getElementById("hid_Major").value);
    var majorName = document.getElementById("keyMajor").value;
    if (schoolCountry == "0") {
        alert('国家必选！');
    }
    else {
        setCookie("hidCountry", schoolCountry, null);
        var cookieParmInfo = "<li>国家：" + document.getElementById("liSchoolCountry").innerHTML + "</li>";
        var url = "http://school.nihaowang.com/SearchResult.aspx?countryID=" + schoolCountry;
        if (schoolEducation != "学历" && schoolEducation != "不限") {
            setCookie("hidEducation", schoolEducation, null);
            cookieParmInfo += "<li><span>申请学历：" + schoolEducation + "</span><a name=\"edu|hidEducation\"></a></li>";
            url += "&edu=" + escape(schoolEducation);
            //url += "x" + schoolEducation;
        }
        if (majorName != "" && majorName!="可输入所查询专业") {
//            setCookie("hidEducation", schoolEducation, null);
//            cookieParmInfo += "<li>申请学历：" + schoolEducation + "</li>";
//            url += "&edu=" + escape(schoolEducation);
            //url += "x" + schoolEducation;


            if (major != 0) {
                setCookie("hid_Major", major, null);
                setCookie("majorName", majorName, null);
            }
            else {
                setCookie("hid_Major", "0", null);
                setCookie("majorName", majorName, null);
                major = majorName;
            }
            cookieParmInfo += "<li><span>申请专业：" + majorName + "</span><a name=\"major|hid_Major|majorName\"></a></li>";
            //url += "?z=" + escape(major);
            url += "&major=" + escape(major);
        }
        else {
            DelCookie("hid_Major");
            DelCookie("majorName");
        }
        setCookie("cookie_ParmList", cookieParmInfo, null);
        window.open(url);
    }



}
function delCookieParm() {
    DelCookie("hidCountry");
    DelCookie("hidProvince");
    DelCookie("hidEducation");
    DelCookie("hid_Major");
    DelCookie("majorName");
    DelCookie("hidBurse");
    DelCookie("hidAuthorization");
    DelCookie("hidNature");
    DelCookie("hidYear");
    DelCookie("hidCount");
    DelCookie("hidFour");
    DelCookie("hidHundred");
    DelCookie("hidAB");
    DelCookie("hidIELTS");
    DelCookie("hidTraditionTOEFL");
    DelCookie("hidWebTOEFL");
    DelCookie("selOtherExam");
    DelCookie("hidEduNeed");
    DelCookie("hidWorkingLife");
    DelCookie("hidSchoolSystem");
    DelCookie("hidAge");
    DelCookie("hidAgeMBA");
    DelCookie("hidOverDate");
    DelCookie("hidTuition");
    DelCookie("cookie_ParmList");
    DelCookie("orderOld");
}
$(document).click(function (e) {
    e = e ? e : e.window.event;
    var tag1 = e.srcElement || e.target;
    if (tag1.className.indexOf("isLeaveClass") < 0) {
        if (tag1.parentNode.className.indexOf("isLeaveClass") < 0) {
            if (currentDiv != "") {
                $("#" + currentDiv).css({ "display": "none" });
            }
        } else { return; }
    }
});
