function getParameter(str){
	var dec = decodeURIComponent;
	var par = new Array, itm;
	if(typeof(str) == 'undefined') return par;
	if(str.indexOf('?', 0) > -1) str = str.split('?')[1];
	str = str.split('&');
	for(var i = 0; str.length > i; i++){
		itm = str[i].split("=");
		if(itm[0] != ''){
			par[itm[0]] = typeof(itm[1]) == 'undefined' ? true : dec(itm[1]);
		}
	}
	return par;
}
function getSearchQuery () {
	var url = location.href;
	var res = getParameter(url);
	var str = "";
	if( typeof(res["utm_source"]) != "undefined" && res["utm_source"].length > 0 ) str += res["utm_source"]+",";
	else str += ",";
	if( typeof(res["utm_medium"]) != "undefined" && res["utm_medium"].length > 0 ) str += res["utm_medium"];
//	else str += ",";
//	if( typeof(res["utm_term"]) != "undefined" && res["utm_term"].length > 0 ) str += res["utm_term"]+",";
//	else str += ",";
//	if( typeof(res["utm_content"]) != "undefined" && res["utm_content"].length > 0 ) str += res["utm_content"]+",";
//	else str += ",";
//	if( typeof(res["utm_campaign"]) != "undefined" && res["utm_campaign"].length > 0 ) str += res["utm_campaign"];
	return str;
}
function cutString(str,num){
	len = 0;
	estr = escape(str);
	ostr = "";
	for(i=0;i<estr.length;i++){
		len++;
		ostr = ostr + estr.charAt(i);
		if(estr.charAt(i) == "%"){
			i++;
			ostr = ostr + estr.charAt(i);
			if(estr.charAt(i) == "u"){
				ostr = ostr + estr.charAt(i+1) + estr.charAt(i+2) + estr.charAt(i+3) + estr.charAt(i+4);
				i+=4;
				len++;
			}
		}
		if(len >= num-3){
			return unescape(ostr)+"...";
		}
	}
	return unescape(ostr);
}
function checkCookie(c_name){
	if ( $.cookie(c_name) ) {
		return true;
	} else {
		return false;
	}
}
function setCookie(c_name,value){
	$.cookie(c_name, value,{ expires: 100 });
}
function getRef() {
	var ref = document.referrer;
	if (ref!="") {
		ref = ref.split('/')[2];
		return cutString( decodeURI(ref),64);
	} else {
		return "none";
	}
}
function setVal(url,flg) {
	if ( flg==1 ) {
		str1 = "FREF";
		str2 = "FWD";
	} else {
		str1 = "NREF";
		str2 = "NWD";
	}
	if ( url=="" ) {
		setCookie(str1,"direct");
		setCookie(str2,"");
	} else {
		url = url.split('/')[2];
		if ( url!="www.0120128888.com" ){
			setCookie(str1,getRef());
			setCookie(str2,getSearchQuery());
		}
	}
}
function tracking(){
	var url = document.referrer;
	var ref = checkCookie("CID");
	var dt = new Date;
	url = url.replace(/(^\s+)|(\s+$)/g,"");
	url = url.substr(0,25);
    if (!ref){
		setCookie("CID",parseInt((new Date)/1000)+"-"+dt.getMilliseconds());
		setVal(url,1);
    }else{
		setVal(url,2);
	}
}
tracking();
