
/*
 * 通用参数配置
 */
var API = {
    userLoginApi:"https://api.139cm.com:444/login/loginApi.ashx",
    postEmailApi:"https://api.139cm.com:444/api/mailSendApi.ashx",
    adminLoginApi:"http://admin.139cm.com/WebService/loginIn.aspx",
    tryOutApi:"https://api.139cm.com:444/api/tryoutapi.ashx",
    homepageUrl:"http://www.139cm.com/SCTryout.htm",
    getCodeApi:"https://api.139cm.com:444/Captcha/GetRandNum1.aspx?n="+Math.random()
}

//获取Query参数
function GetUrlParms(){
    var args = new Object();
    var query = location.search.substring(1);
    var pairs = query.split("&");
    for (var i = 0; i < pairs.length; i++) {
        var pos = pairs[i].indexOf('=');
        if (pos == -1) 
            continue;
        var argname = pairs[i].substring(0, pos);
        var value = pairs[i].substring(pos + 1);
        args[argname] = decodeURI(value);
    }
    return args;
}

//读取Cookie
function GetCookie(CookieName, Key){
    var allcookies = document.cookie;
    var pos = allcookies.indexOf(CookieName);
    if (pos != -1) {
        var start = pos + CookieName.length;
        var end = allcookies.indexOf(";", start);
        if (end == -1) 
            end = allcookies.length;
        var value = allcookies.substring(start, end);
        var paramValue = "";
        var charIndex0 = value.lastIndexOf(Key + "=");
        if (charIndex0 != -1) {
            var charIndex1 = value.indexOf("&", charIndex0);
            paramValue = charIndex1 == -1 ? value.substr(charIndex0 +
            Key.length +
            1) : value.substring(charIndex0 +
            Key.length +
            1, charIndex1);
            return decodeURIComponent(paramValue);
        }
    }
    return "";
}

//设置Cookie
function SetCookie(CookieName, Key, Value,Expires){
    var allcookies = document.cookie;
    var pos = allcookies.indexOf(CookieName);
    if (pos != -1) {
        var start = pos + CookieName.length;
        var end = allcookies.indexOf(";", start);
        if (end == -1) 
            end = allcookies.length;
        var value = allcookies.substring(start, end);
        var charIndex0 = value.lastIndexOf(Key + "=");
        if (charIndex0 != -1) {
            var v = Key + '=' + encodeURIComponent(Value);
            var reg = new RegExp(Key + "=[^&;]*");
            var s = value.replace(reg, v);
            document.cookie = CookieName + s + ";domain=" +
            window.location.host +
            ";path=/"+
            ";expires="+Expires;
        }
        else {
            var v = value.length == 1 ? '' : '&' + Key + '=' +
            encodeURIComponent(Value) +
            ';';
            var s = value + v;
            document.cookie = CookieName + s + ";domain=" +
            window.location.host +
            ";path=/"+
            ";expires="+Expires;
        }
    }
    else {
        var v = Key + '=' + encodeURIComponent(Value) + ';';
        var s = '=' + v;
        document.cookie = CookieName + s + ";domain=" +
        window.location.host +
        ";path=/"+
        ";expires="+Expires;
    }
    
}

function $(element){
    return document.getElementById(element);
}




