﻿function $(str) {
    return document.getElementById(str);
}

function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]); return null;
}

String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

function GetHttp() {
    var xhttp = null;
    if (window.XMLHttpRequest) {
        xhttp = new XMLHttpRequest();
    }
    else {
        if (window.ActiveXObject) {
            try {
                xhttp = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch (e) {
            }
            if (xhttp == null) {
                try {
                    xhttp = new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch (e) {
                }
            }
        }
    }
    return xhttp;
}

function GetTopMenu() {

    var PostUrl = "/user/user_top_menu.aspx?url=" + encodeURIComponent(window.location.href);

    var xhttp = GetHttp();

    xhttp.open("GET", PostUrl, false);

    xhttp.send(null);

    var Result = xhttp.responseText;
    xhttp.abort();
    xhttp = null;

    if (Result != null) {
        document.getElementById("topmenu").innerHTML = Result.trim();          
    }
}

function LoginOut() {

    var PostUrl = "/user/user_loginout.aspx";
    var xhttp = GetHttp();

    xhttp.open("GET", PostUrl, false);

    xhttp.send(null);

    var Result = xhttp.responseText;
    xhttp.abort();
    xhttp = null;

    if (Result != null) {
        Result = Result.trim();
    }

    if (Result == "ok") {
        GetTopMenu();
    }
    else {
        alert("很抱歉，暂时退出失败，请您稍后再试！");
    }
}

function findxx() {
    var FindK = document.getElementById("FindK").value;

    if (FindK == null) {
        return false;
    }
    FindK = FindK.trim();
    if (FindK.length < 2) {
        alert("校名应在2个字以上!");
        return false;
    }
    
    var id = GetQueryString("id");
    var t = GetQueryString("t");

    if (id == null) {
        id = "0";
    }
    if (t == null) {
        t = "0";
    }
    FindK = encodeURIComponent(FindK);

    window.location.href = "xxlb.aspx?id=" + id + "&t=" + t + "&k=" + FindK;
    return true;
}

function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != "function") {
        window.onload = func;
    } else {
        window.onload = function () {
            oldonload();
            func();
        }
    }
}

addLoadEvent(GetTopMenu);
