
function GetXmlHTTP() {
    if (window.XMLHttpRequest) {
        return new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        var request = new ActiveXObject("Msxml2.XMLHTTP");
        if (!request) {
            request = new ActiveXObject("Microsoft.XMLHTTP");
        }
        return request;
    }
}

function GetCity(Pro, City) {
    var ddlCity = document.getElementById(City);
    var ddlPro = document.getElementById(Pro);
    var proUrl = "/ajax/newprocity.aspx?proID=" + ddlPro.options[ddlPro.selectedIndex].value;
    var xmlHTTP = GetXmlHTTP();
    xmlHTTP.open("get", proUrl, true);

    xmlHTTP.onreadystatechange = function selectedPro() {
        if (xmlHTTP.readyState == 4) {
            if (xmlHTTP.status == 200) {
                var responseText = xmlHTTP.responseText;
                //                var newOption = document.createElement("OPTION");
                //                ddlCity.options[0] = new Option("地/市", 0);
                var arrayProCity = responseText.split(';');
                for (var i = 1; i < arrayProCity.length; i++) {
                    var selOption = arrayProCity[i - 1].split('*');
                    ddlCity.options[i] = new Option(selOption[0], selOption[1])
                }

            }
        }
    }
    xmlHTTP.send(null);
}


function login() {
    var userName = document.getElementById("username");
    var userPwd = document.getElementById("userpwd");
    if (userName.value == "") {
        alert("用户名不能为空!");
        return false;
    }
    if (userPwd.value == "") {
        alert("密码不能为空!");
        return false;
    }
    var checkUrl = "ajax/login.aspx?name=" + userName.value + "&pwd=" + userPwd.value + "&rand=" + Math.random();

    var xmlHTTP = GetXmlHTTP();
    xmlHTTP.open("get", checkUrl, true);
    xmlHTTP.onreadystatechange = function loginCheck() {
        if (xmlHTTP.readyState == 4) {
            if (xmlHTTP.status == 200) {
                var responseText = xmlHTTP.responseText;
                if (responseText == "失败") {
                    alert("用户名或密码错误");
                }
                else {
                    window.location.href = "blog/index.aspx?user=" + responseText;
                }
            }
        }
    }
    xmlHTTP.send(null);
}

function GetSelected(city, tbSelected) {
    var ddlCity = document.getElementById(city);
    var tbCity = document.getElementById(tbSelected);
    tbCity.value = ddlCity.options[ddlCity.selectedIndex].value;

}

//高级查询;
function OpenNewUrl(proID, cityId, classId, keyWordId) {

    var ddlCity = document.getElementById(cityId);
    var ddlPro = document.getElementById(proID);
    var ddlClass = document.getElementById(classId);
    var tbKeyWord = document.getElementById(keyWordId);

    if (ddlClass.options[ddlClass.selectedIndex].text == "请选择") {
        alert("请选择要查询的是律所还是律师;");
        return false;
    }
    window.location.href = "newsearch.aspx?cityid=" + ddlCity.options[ddlCity.selectedIndex].value + "&proid=" + ddlPro.options[ddlPro.selectedIndex].value + "&search=" + tbKeyWord.value + "&class=" + ddlClass.options[ddlClass.selectedIndex].value + "";
}

//普通查询;
function CommonSearch(classId, keyWordID) {

    var rblClass = document.getElementById(classId);
    var tbKeyWord = document.getElementById(keyWordID);
    var selectedOPtion;
    if (tbKeyWord.value == "") {
        alert("关键字不能为空");
        return false;
    }

    for (var i = 0; i < 3; i++) {
        if (document.getElementById(classId + "_" + i).checked == true)
            selectedOPtion = document.getElementById(classId + "_" + i).value;
    }
    window.location.href = "newsearch.aspx?cityid=&proid=&search=" + tbKeyWord.value + "&class=" + selectedOPtion;

}
//课程法律搜索;
function LawSearch(id, url, flag) {
    var tbKeyWord = document.getElementById(id);
    if (tbKeyWord.value == "") {
        alert("关键字不能为空");
        return false;
    }
    if (flag == 1) {
        window.open(url + "" + encodeURI(tbKeyWord.value));
    }
    else {
        window.open(url + "" + tbKeyWord.value);
    }
}
//对应课程
function courseSearch(url, keyWord) {
    window.open(url + "" + encodeURI(keyWord));
}
function getCookie2(cookie_name) {
    var allcookies = document.cookie;
    var cookie_pos = allcookies.indexOf(cookie_name);
    // 如果找到了索引，就代表cookie存在，
    // 反之，就说明不存在。
    if (cookie_pos != -1) {
        // 把cookie_pos放在值的开始，只要给值加1即可。
        cookie_pos += cookie_name.length + 1;
        var cookie_end = allcookies.indexOf(";", cookie_pos);
        if (cookie_end == -1) {
            cookie_end = allcookies.length;
        }
        var value = decodeURI(allcookies.substring(cookie_pos, cookie_end));
    }
    if (value.length > 0) {
        var arrayCookie = value.split("&");
        document.getElementById("divUserInfor").style.display = "";
        document.getElementById("divLogin").style.display = "none";
        //            document.getElementById("pName").innerHTML = arrayCookie[1].split("=")[1];
        //            document.getElementById("p_Index").href = "blog/index.aspx?user=" + arrayCookie[3].split("=")[1];
        alert(arrayCookie[1].split("=")[1]);
        alert(arrayCookie[4].split("=")[1]);
        var aa = new Array(2);
        aa[0] = arrayCookie[1].split("=")[1];
        aa[1] = "blog/index.aspx?user=" + arrayCookie[4].split("=")[1];
        alert(aa[0]);
        return aa;
    }

}

function getCookie(cookie_name) {
    var checkUrl = "ajax/loginflag.aspx?rand=" + Math.random();
    var xmlHTTP = GetXmlHTTP();
    xmlHTTP.open("get", checkUrl, true);
    xmlHTTP.onreadystatechange = function loginCheck() {
        if (xmlHTTP.readyState == 4) {
            if (xmlHTTP.status == 200) {
                var responseText = xmlHTTP.responseText;
                if (responseText == "未登陆") {
                    // alert("未登陆");
                }
                else {
                    document.getElementById("divUserInfor").style.display = "";
                    document.getElementById("divLogin").style.display = "none";
                    document.getElementById("pName").innerHTML = decodeURI(responseText.split('*')[1]);
                    document.getElementById("p_Index").href = "blog/index.aspx?user=" + responseText.split('*')[0];
                }
            }
        }
    }
    xmlHTTP.send(null);
}
