﻿window.onload = function showAds() {
    addCount();
    setAgentId();
    setTimeout("noneAds()", 15000);
}
var agentId, QueryString
var URL = document.location.toString();
if (URL.lastIndexOf("?") != -1) {
    QueryString = URL.substring(URL.lastIndexOf("?") + 1, URL.length);
    if (isDigit(QueryString)) {
        agentId = "?" + QueryString;
    } else {
        agentId = "";
    }
} else {
    agentId = "";
}
function isDigit(s) {
    var patrn = /^[0-9]{1,5}$/;
    if (!patrn.exec(s)) return false
    return true
}

function isRegisterUserName(s) {
    var patrn = /^([a-zA-Z0-9]|[._]){3,20}$/;
    if (!patrn.exec(s)) return false
    return true
}

function isPasswd(s) {
    var patrn = /^(\w){6,20}$/;
    if (!patrn.exec(s)) return false
    return true
}

function $(o) {
    return document.getElementById(o);
}

function setAgentId() {
    var ulArr = document.getElementsByTagName("ul");
    for (i = 0; i < ulArr.length; i++) {
        var aArr = ulArr[i].getElementsByTagName("a");
        for (j = 0; j < aArr.length; j++) {
            aArr[j].href = aArr[j].href + agentId;
        }
    }
    $("UserId").focus();
    setStation();
}

function checkLogin() {
    var UserId = $("UserId").value;
    var UserPwd = $("UserPwd").value;
    var UserStation = $("Station").value;
    if (UserStation == "1000") {
        alert('请选择分站');
        $("Station").focus();
        return false;
    }

    if (UserId == null || UserId == "") {
        alert('用户名不能为空！');
        $("UserId").focus();
        return false;
    } else if (UserPwd == null || UserPwd == "") {
        alert('密码不能为空！');
        $("UserPwd").focus();
        return false;
    } else {
        if (!isRegisterUserName(UserId)) {
            alert('用户名只能是3-20个字母或数字！');
            $("UserId").focus();
            return false;
        }
        if (!isPasswd(UserPwd)) {
            alert('密码只能输入6-20个字母、数字、下划线 ！');
            $("UserPwd").focus();
            return false;
        }
    }
    formlogin.submit();
}

function setStation() {
    var station;
    station = getCookie("fenzhan");
    if (station != null) {
        var staArr = $("Station");
        for (i = 0; i < staArr.length; i++) {
            if (staArr[i].value == station) {
                staArr[i].selected = true;
            }
        }
    }
}

function setCookie(name, value) {
    var Days = 30;
    var expTime = new Date();
    expTime.setTime(expTime.getTime() + Days * 24 * 60 * 60 * 1000);
    document.cookie = name + "=" + encodeURI(value) + ";expires=" + expTime.toGMTString() + ";path=/";
}

function getCookie(name) {
    var arrCookies = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
    if (arrCookies != null) return decodeURI(arrCookies[2]);
    return null;

}

function addCount() {
    document.getElementById("jisou_ad").style.display = "block";
}

var T = 260;
var N = 20;
function noneAds() {
    if (T > 0) {
        T--;
        N = N - 5;
    } else {
        return;
    }
    if (N < 0) {
        document.getElementById("jisou_ad").style.display = "none";
        return;
    }

    document.getElementById("jisou_ad").style.height = N + "px";
    setTimeout("noneAds()", 30);
}