function uriencode(s){return encodeURIComponent(s);}
function uridecode(s){return decodeURIComponent(s);}
function addEvent(obj,evType,fn){
	if(!obj) return false;
    if (obj.addEventListener){
        return obj.addEventListener(evType,fn,false);
    }else if (obj.attachEvent){
        return obj.attachEvent("on" + evType,fn);
    }else{
        return false;
    }
}
function Enum(){
	this.data={};
}
Enum.prototype.set=function(key,val){
	this.data[key]=val;
}
Enum.prototype.get=function(key){
	return typeof(this.data[key])==='undefined'?'':this.data[key];
}
Enum.prototype.toString=function(){
	var str='';
	for(p in this.data){
		if(typeof(this.data[p])!=='function'){
			if (str!='') {str+='&'};
			str+=p+'='+uriencode(this.data[p]);
		}
	}
	return str;
}
function setCookie(name,value,expires,path,domain,secure){document.cookie=name+"="+escape(value)+((expires)?"; expires="+expires:"")+((path)?"; path="+path:"")+((domain)?"; domain="+domain:"")+((secure)?"; secure":"");}
function delCookie(name){var exp=new Date();exp.setTime(exp.getTime()-1);var cval=getCookie(name);document.cookie=name+"="+cval+"; expires="+exp.toGMTString();}
function getCookie(name){var cv="";var search=name+"=";if(document.cookie.length>0){offset=document.cookie.indexOf(search);if(offset!=-1){offset+=search.length;end=document.cookie.indexOf(";",offset);if(end==-1)end=document.cookie.length;cv=unescape(document.cookie.substring(offset,end))}}return uridecode(cv);}
function getExpDate(days,hours,minutes){var expDate=new Date();if(typeof(days)=="number"&&typeof(hours)=="number"&&typeof(hours)=="number"){expDate.setDate(expDate.getDate()+parseInt(days));expDate.setHours(expDate.getHours()+parseInt(hours));expDate.setMinutes(expDate.getMinutes()+parseInt(minutes));return expDate.toGMTString();}return null;}
function getUrlParam(key,url){
    var r=('?'+url).match(new RegExp("[&\?]"+key+"=([^&]*)","i"));
    return r?r[1]:'';
}
function randomStr(l) {
	var x="123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",tmp="";
	for(var i=0;i<l;i++) {
		tmp += x.charAt(Math.ceil(Math.random()*100000000)%x.length);
	}
	return tmp;
}
function searchEngine(url){
	url = url.substr(7);
	var domain = url.substring(0,url.indexOf('/')),se = '';
	var engines=[['baidu.','baidu'],['google.','google'],['yahoo.','yahoo'],['bing.','bing'],['ask.','ask'],['aol.','aol'],['sogou.','sogou'],['soso.','soso'],['youdao.','youdao']];
	var L = engines.length;
	while(L--){
		if(-1!==domain.indexOf(engines[L][0])){
			se = engines[L][1];
			break;
		}
	}
	return se;
}
function searchEngineKW(url){
	var kw = '',se = searchEngine(url);
	var engines = [['baidu','wd'],['google','q'],['yahoo','p'],['bing','q'],['ask','q'],['aol','q'],['sogou','query'],['soso','w'],['youdao','q']];
	var L = engines.length;
	while(L--){
		if(engines[L][0]==se){
			kw = getUrlParam(engines[L][1],url);
			break;
		}
	}
	return kw;
}

var stat={};
stat.conf={
	cookie:{
		domain:'.99pto.com',
		keys:{
			gwparam:'__99pto_param',
			lasttime:'_99pto_lasttime',
			ssid:'_99pto_ssid'
		}
	},
	param:{
		channel:'ch',
		site:'st',
		position:'pt',
		gwreferer:'gr',
		gwother:'go',
		ssid:'si',
		searcheg:'sn',
		searchkw:'kw',
		pageother:'po',
		pagereferer:'pr',
		pagelocation:'pl'
	}
};
stat.sendreq=function(src){
	var _img = document.createElement('img');
	_img.style.display = 'none';
	_img.src = src;
	document.body.appendChild(_img);
}
stat.onVarOK=function(queryVars,lastviewtime){
	stat.sendreq('http://stat2.99ptoimg.com/st_other.html'+'?'+queryVars.toString());
}
stat.main=function(){
	var queryVars=new Enum();
	var _cd=stat.conf.cookie.domain;
	
	var _koc=stat.conf.param.channel,_kos=stat.conf.param.site,_kop=stat.conf.param.position,_kogwr=stat.conf.param.gwreferer,_kogwo=stat.conf.param.gwother;
	var _gwparam = getCookie(stat.conf.cookie.keys.gwparam)||'';
	queryVars.set(_koc,getUrlParam(_koc,_gwparam));
	queryVars.set(_kos,getUrlParam(_kos,_gwparam));
	queryVars.set(_kop,getUrlParam(_kop,_gwparam));
	queryVars.set(_kogwr,getUrlParam(_kogwr,_gwparam));
	queryVars.set(_kogwo,getUrlParam(_kogwo,_gwparam));
	
	var _lastviewtime = getCookie(stat.conf.cookie.keys.lasttime)||'';
	setCookie(stat.conf.cookie.keys.lasttime,new Date().getTime().toString().substr(0,10),getExpDate(30,0,0),'/',_cd);
	
	var _ckossid=stat.conf.cookie.keys.ssid;
	var stat_ssid=getCookie(_ckossid)||(randomStr(22)+new Date().getTime().toString().substr(0,10));
	setCookie(_ckossid,stat_ssid,getExpDate(30,0,0),'/',_cd);
	queryVars.set(stat.conf.param.ssid,stat_ssid);
	
	queryVars.set(stat.conf.param.pagereferer,document.referrer);
	
	queryVars.set(stat.conf.param.searcheg,searchEngine(document.referrer));
	queryVars.set(stat.conf.param.searchkw,searchEngineKW(document.referrer));
	
	queryVars.set(stat.conf.param.pagelocation,'');/****/
	queryVars.set(stat.conf.param.pageother,'');/****/
	
	if(window==window.top){
		stat.onVarOK(queryVars,_lastviewtime);
	}
}