/*
 * other_new.js
 * @注册页面&LP统一跟踪二
 */

var oCookieOther = {
	
	domain : "kunlun.com",
	surl : location.href,
	excludeDomain:"[kunlun.com][klonline.cn][17sanguo.com][17kunlun.com]",
	
	//判断url来源类别
	getRefferDomain:function(reffer){
		aTemp = reffer.split("/")[2].split(".");
		//return aTemp.length >= 2 ? (sDomain = aTemp[aTemp.length-2] + "." + aTemp[aTemp.length-1]) : null;
		if(aTemp.length >= 2)
			sDomain = aTemp[aTemp.length-2] + "." + aTemp[aTemp.length-1]
		else
			sDomain = null;
		return sDomain;
	},
	
	K_SetCookie:function(name, value){
	 	var expdate = new Date();
	 	var argv = this.K_SetCookie.arguments;
	 	var argc = this.K_SetCookie.arguments.length;
	 	var expires = (argc > 2) ? argv[2] : null;
	 	var path = (argc > 3) ? argv[3] : '/';
	 	this.domain = (argc > 4) ? argv[4] : this.domain;
	 	var secure = (argc > 5) ? argv[5] : false;
	 	if(expires!=null) expdate.setTime(expdate.getTime() + ( expires * 1000 ));
	 	document.cookie = name + "=" + escape (value)
		 	+((expires == null) ? "" : ("; expires="+ expdate.toGMTString()))
		 	+((path == null) ? "/" : ("; path=" + path))
		 	+("; domain=" + this.domain) 
		 	+((secure == true) ? "; secure" : "");
	},
	getPara:function(strname,url){
		var hrefstr,pos,parastr,para,tempstr;
		var hrefstr = this.getPara.arguments.length == 2 ? url : this.surl;
		var pos = hrefstr.indexOf("?")
		var parastr = hrefstr.substring(pos+1);
		var para = parastr.split("&");
		var tempstr = "";
		for(i=0;i<para.length;i++)
		{
			var tempstr = para[i];
			var pos = tempstr.indexOf("=");
	
			if(tempstr.substring(0,pos) == strname)
			{
				return tempstr.substring(pos+1);
			}
		}
		return null;
	
	},
	getDomain:function(){
		return document.domain;
	}
}

//根据url得到联盟ID及子站ID
u = oCookieOther.getPara('u');
u2 = oCookieOther.getPara('u2');
if(u2 == "null")u2 = null;

reffer = document.referrer;

if(u != null && u2 != null){
	//u&u2均存在,重写cookie
	oCookieOther.K_SetCookie('u',u,12*30*24*3600);
	oCookieOther.K_SetCookie('u2',u2,12*30*24*3600);
	//2966 
	oCookieOther.K_SetCookie('u',u,12*30*24*3600,'/','2966.com');
	oCookieOther.K_SetCookie('u2',u2,12*30*24*3600,'/','2966.com');
	//other
	oCookieOther.K_SetCookie('u',u,12*30*24*3600,'/',oCookieOther.getDomain());
	oCookieOther.K_SetCookie('u2',u2,12*30*24*3600,'/',oCookieOther.getDomain());
}else if(u != null && u2 == null){
	//u存在u2为不存在置u2为null
	oCookieOther.K_SetCookie('u',u,12*30*24*3600);
	oCookieOther.K_SetCookie('u2',null,12*30*24*3600);
	//2966
	oCookieOther.K_SetCookie('u',u,12*30*24*3600,'/','2966.com');
	oCookieOther.K_SetCookie('u2',null,12*30*24*3600,'/','2966.com');
	//kunlun.tw
	oCookieOther.K_SetCookie('u',u,12*30*24*3600,'/','kunlun.tw');
	oCookieOther.K_SetCookie('u2',null,12*30*24*3600,'/','kunlun.tw');
	//other
	oCookieOther.K_SetCookie('u',u,12*30*24*3600,'/',oCookieOther.getDomain());
	oCookieOther.K_SetCookie('u2',null,12*30*24*3600,'/',oCookieOther.getDomain());
}else if(u == null && u2 == null){
	if(reffer != ""){
		//带有reffer
		rootDomain = oCookieOther.getRefferDomain(reffer);
		//根据js所带参数设置联盟ID
		typeU = oCookieOther.getPara('u',document.getElementById('gameuid').src);
		typeU = typeU == null ? 241 : typeU;
		//排除自身的url地址
		if(oCookieOther.excludeDomain.indexOf("["+rootDomain+"]") == -1){
			oCookieOther.K_SetCookie('u',typeU,12*30*24*3600);
			oCookieOther.K_SetCookie('u2',rootDomain,12*30*24*3600);
			//2966
			oCookieOther.K_SetCookie('u',typeU,12*30*24*3600,'/','2966.com');
			oCookieOther.K_SetCookie('u2',rootDomain,12*30*24*3600,'/','2966.com');
			//kunlun.tw
			oCookieOther.K_SetCookie('u',typeU,12*30*24*3600,'/','kunlun.tw');
			oCookieOther.K_SetCookie('u2',rootDomain,12*30*24*3600,'/','kunlun.tw');
			//other
			oCookieOther.K_SetCookie('u',typeU,12*30*24*3600,'/',oCookieOther.getDomain());
			oCookieOther.K_SetCookie('u2',rootDomain,12*30*24*3600,'/',oCookieOther.getDomain());
		}
	}else{
		//不带参数及reffer，不作修改
	}
}













