/*
 *WEB点击流 CMchApplyStat.js
 */
function CMchApplyStat()
{
	this.m_dispDJL = null;
	this.m_sDivId = "CTrans_DJL";
	this.m_sHost = "tenpay.com";
	this.m_sWhoId = "11";
	
	this.Click = CMchApplyStat_Click;
	this.GetUrlPara = CMchApplyStat_GetUrlPara;
	this.GetCookie = CMchApplyStat_GetCookie;
	this.SetCookie = CMchApplyStat_SetCookie;
	this.GetPos = CMchApplyStat_GetPos;
	this.GetOp = CMchApplyStat_GetOp;
	this.Stat = CMchApplyStat_Stat;
	
	
	//位置配置：财付通 位置代码 说明
	this.m_arrPos = [
					["", "184", "未带标识"],		
				   ["1202243001", "186", "商户申请1202243001位置"],
				   ["1201648901", "187", "商户申请1201648901位置"],
				   ["1201264801", "188", "商户申请1201264801位置"],
				   ["ACT0", "190", "商户申请ACT0位置"],
				   ["ACT1", "191", "商户申请ACT1位置"],
				   ["ACT2", "192", "商户申请ACT2位置"],
				   ["ACT3", "193", "商户申请ACT3位置"],
				   ["ACT4", "194", "商户申请ACT4位置"],
				   ["ACT5", "195", "商户申请ACT5位置"],
				   ["ACT6", "196", "商户申请ACT6位置"],
				   ["ACT7", "197", "商户申请ACT7位置"],
				   ["ACT8", "198", "商户申请ACT8位置"],
				   ["ACT9", "199", "商户申请ACT9位置"],
				   ["ACT10", "201", "商户申请ACT10位置"],
				   ["ACT11", "202", "商户申请ACT11位置"],
				   ["ACT12", "203", "商户申请ACT12位置"],
				   ["ACT13", "204", "商户申请ACT13位置"],
				   ["ACT14", "205", "商户申请ACT14位置"],
				   ["ACT15", "206", "商户申请ACT15位置"],
				   ["ACT16", "207", "商户申请ACT16位置"],
				   ["ACT17", "208", "商户申请ACT17位置"],
				   ["ACT18", "209", "商户申请ACT18位置"],
				   ["ACT19", "210", "商户申请ACT19位置"],
				   ["542554970", "200", "商户申请542554970ecshop位置"],
				   ["AD17", "189", "商户申请AD17位置"]
				   ];
	//商户申请其他带标识位置
	this.m_sOtherPos = "185";
	
	//业务配置：页面代码（活动代码） 入口代码（业务代码） 说明
	this.m_arrOp = [
					["144", "58", "介绍页面"],
					["145", "59", "选择页面"],
					["146", "60", "中介申请页面"],
					["147", "61", "即时到帐申请页面"],
					["152", "62", "商户申请平台专用b2c入口"],
					["154", "63", "商户申请平台专用中介入口"],
					["177", "74", "商户申请主站商家工具入口"]
					];

}
/*
 pay 9 1 2 11
 gat 7 1 1 11
 ent 7 1 6 11
 aa  7 1 7 11
 */
function CMchApplyStat_Click(posid, actid, opid, whoid)
{
	var web_analyse_url = 
		"http://id.zone.tenpay.com/cgi-bin/analyse/advclick.cgi?posid=" 
		+ posid + "&actid=" + actid + "&opid=" + opid + "&whoid="+ whoid + "&PcacheTime=" + (new Date()).getTime();

	this.m_dispDJL = document.getElementById(this.m_sDivId);
	if(this.m_dispDJL)	
		this.m_dispDJL.innerHTML = 	"<img src='"+ web_analyse_url + "' height=\"0\" width=\"0\">";
	else
		document.write('<div style="display:none" id="' + this.m_sDivId + '">' + '<img src="' + web_analyse_url + '" height="0" width="0"></div>');
			
}

function CMchApplyStat_GetUrlPara(name, url)
{
	if(url)
		str = url;
	else
		str = window.location.href;
	var reg = new RegExp("(^|&|\\?)"+ name +"=([^&]*)(&|$)");
    var r = str.substr(1).match(reg);
    if (r != null)
    	return unescape(r[2]); 

    return "";
}

function CMchApplyStat_GetCookie(name) 
{
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) 
    {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg) 
        {
			var endstr = document.cookie.indexOf (";", j);
    		if (endstr == -1) 
    		{
        		endstr = document.cookie.length;
   			 }
    		return unescape(document.cookie.substring(j, endstr));
        }
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break; 
    }
    return "";
}

// store cookie value with optional details as needed
function CMchApplyStat_SetCookie(name, value, expires, path, domain, secure) 
{
    document.cookie = name + "=" + escape (value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function CMchApplyStat_GetPos(user)
{
	for(i=0; i<this.m_arrPos.length; i++)
	{
		if(this.m_arrPos[i] && this.m_arrPos[i][0] == user)
			return this.m_arrPos[i][1];
	}
	return this.m_sOtherPos;
	
}

function CMchApplyStat_GetOp(page)
{
	for(i=0; i<this.m_arrOp.length; i++)
	{
		if(this.m_arrOp[i] && this.m_arrOp[i][0] == page)
			return this.m_arrOp[i][1];
	}
	return "";
	
}

//当first为true时，即可以作为入口是，user值有效
function CMchApplyStat_Stat(page, first, user)
{
	var sOp = "";
	var sCUser=this.GetCookie("MchApplyStatUser");
	var sCPos=this.GetCookie("MchApplyStatPos");
	var sCOp=this.GetCookie("MchApplyStatOp");
	if(first)
	{
		sOp = this.GetOp(page);
		if(sOp != "" && (sCUser !=  user || user=="" ))
		{
			sCOp = sOp;
			sCUser = user;
			sCPos = this.GetPos(sCUser);
			this.SetCookie("MchApplyStatUser",sCUser, "", "/", this.m_sHost, "");
			this.SetCookie("MchApplyStatPos",sCPos, "", "/", this.m_sHost, "");
			this.SetCookie("MchApplyStatOp",sCOp, "", "/", this.m_sHost, "");
			
		}
	}
	if(sCPos!="" && sCOp!="")
	{
  		this.Click(sCPos, page, sCOp, this.m_sWhoId);
  		this.SetCookie("MchApplyStatPage",page, "", "/", this.m_sHost, "");
  }
	
	
	
}

/*
 * 定义全局变量g_CCftUser
 */
var g_CMchApplyStat =null ;
if(!g_CMchApplyStat)
	g_CMchApplyStat = new CMchApplyStat();
