﻿/*
 * 通用参数配置
 */
var API = {
/*生产线*/
YNhomePageUrl:"http://yn.139cm.com/",
SChomePageUrl:"http://sc.139cm.com/",
HNhomePageUrl:"http://ha.139cm.com/",
	userLoginApiEnglish:"https://api.139cm.com:444/login/loginApi.ashx?lang=en_US",
    userLoginApi:"https://api.139cm.com:444/login/loginApi.ashx",
　　adminLoginApi:"http://admin.139cm.com/WebService/loginIn.aspx"

//开发线
/*	
YNhomePageUrl:"http://yn.139cm.com/",
SChomePageUrl:"http://sc.139cm.com/",
HNhomePageUrl:"http://ha.139cm.com/",
userLoginApiEnglish:"http://webmail.cmail2009.kf139.com/login/loginApi.ashx?lang=en_US",
userLoginApi:"http://webmail.cmail2009.kf139.com/login/loginApi.ashx",
adminLoginApi:"http://admin.cmail2008.kf139.com/WebService/loginIn.aspx"*/
/*测试线*//*
	userLoginApiEnglish:"http://api.cmailtest.rd139.com/login/loginApi.ashx?lang=en_US",
    userLoginApi:"http://api.cmailtest.rd139.com/login/loginApi.ashx",
　　adminLoginApi:"http://admin.cmailtest.rd139.com/WebService/loginIn.aspx"
*/
}

//获取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(CName, sName){
    if (!sName) {
			sName = CName;
			CName = "CMAIL";
		}
		var allcookies = document.cookie;
		var reg = new RegExp("(^|;)\\s*"+CName+"=([^;]*)\\s*(;|$)");
		var match = reg.exec(allcookies);
		var ret = "";
		if (match != null) {
			var value = match[2];
			ret = getUrlParamValue(value,sName);
			ret = decodeURIComponent(ret);
		} 
		return ret;
}

//设置Cookie
function SetCookie(CName, sName, sValue,Expires){
	var allcookies = document.cookie;
	var reg = new RegExp("(^|;)\\s*"+CName+"=([^;]*)\\s*(;|$)");
	var match = reg.exec(allcookies);
	var cv = "";
	var name = CName + "=";
	var value = "";
	if (match != null) {
		value = match[2];
		var reg1 = new RegExp("(^|&|\\?|\\s)"+sName+"\\s*=\\s*([^&]*)(\\s|&|$)");
		var match = reg1.exec(value);
		if (match){	
			cv = sName + "=" + encodeURIComponent(sValue);
			value = value.replace(match[0], match[1]+cv+match[3]);
		}else{
			cv = value.length == 1 ? "" : "&" + sName + "="+ encodeURIComponent(sValue) + ";";
			value += cv;
		}
	}else{
		cv = sName + '=' + encodeURIComponent(sValue) + ';';
		value = cv;
	}
	document.cookie = name + value + ";domain="+ window.location.host + ";path=/;expires="+Expires;
    
}

function getUrlParamValue(url, param){
	var reg = new RegExp("(^|&|\\?|\\s)"+param+"\\s*=\\s*([^&]*?)(\\s|&|$)","i");  
	var match = reg.exec(url); 
	if (match) {
		return match[2].replace(/[\x0f]/g, ";");
	}
	return "";  
}

function $(element){
    return document.getElementById(element);
}



