$(document).ready(function(){
	/*
	if(check_test_on())
	{
		$('a').live("click",function(){
			alert(p_jumpurl(this.href));
			if(typeof (window._stat_page_url_) == "undefined")
			{
				window._stat_page_url_ = p_jumpurl(window.location.href);
			}
			if(!check_js_url(this.href))
			{
				console.log(p_jumpurl(this.href));
				console.log("http://log.stat.yijia.com/pagestat.php?page_url="+window._stat_page_url_+"&jump_url="+p_jumpurl(this.href)+"&param="+get_unid(this.href));
				return false;
				$.ajax({
			        type : "GET",
			        url : "http://log.stat.yijia.com/pagestat.php?page_url="+window._stat_page_url_+"&jump_url="+p_jumpurl(this.href)+"&param="+get_unid(this.href),
			        dataType : "jsonp",
			        jsonp: 'callback',
			        success : function(json){
			        }
			    });
			}
			return false;
		});
		return false;
	}
	*/
	if(check_show_on())
	{
		$.getScript("http://stat.yijia.com/showstat.js");
	}
	else
	{
		$('a').live("click",function(){
			if(typeof (window._stat_page_url_) == "undefined")
			{
				window._stat_page_url_ = p_jumpurl(window.location.href);
			}
			/*
			if(check_test_on())
			{
				console.log("http://log.stat.yijia.com/pagestat.php?page_url="+window._stat_page_url_+"&jump_url="+p_jumpurl(this.href)+"&param="+get_unid(this.href));
			}
			*/
			if(!check_js_url(this.href))
			{

				$.ajax({
			        type : "GET",
			        url : "http://log.stat.yijia.com/pagestat.php?page_url="+window._stat_page_url_+"&jump_url="+p_jumpurl(this.href)+"&param="+get_unid(this.href),
			        dataType : "jsonp",
			        jsonp: 'callback',
			        success : function(json){
			        }
			    });
			}
			return true;
		});
	}
	
});

function check_show_on(){
	var reg = new RegExp("(^|\\?|&)showstat=([^&]*)(\\s|&|$)", "i");   
	return reg.test(location.href);
}

function check_test_on(){
	var reg = new RegExp("(^|\\?|&)test=([^&]*)(\\s|&|$)", "i");   
	return reg.test(location.href);
}

function check_js_url(str){
	var reg = new RegExp("javascript", "i");   
	return reg.test(str);
}

function p_url(url)
{
	
}

function p_jumpurl(url)
{
	var reg = new RegExp("(^|\\?|&)unid=([^&]*)(\\s|&|$)", "i");   
	var _unid_value = "";
	if(reg.test(url))
	{
		
		_unid_value = unescape(RegExp.$1.replace(/\+/g, " ")) + "unid=" + unescape(RegExp.$2.replace(/\+/g, " "));
	}
	
	if(_unid_value!="")
	{
		url = url.replace(_unid_value,"");
	}
	
	
	
	if(url.indexOf('cam.taoke.alimama.com') || url.indexOf('http://search'))
	{
		reg = new RegExp("(^|\\?|&)pid=([^&]*)(\\s|&|$)", "i");   
		_unid_value = "";
		if(reg.test(url))
		{
			
			_unid_value = unescape(RegExp.$1.replace(/\+/g, " ")) + "pid=" + unescape(RegExp.$2.replace(/\+/g, " "));
		}
		
		if(_unid_value!="")
		{
			url = url.replace(_unid_value,"");
		}
	}
	
	if(url.indexOf('s.click.taobao.com/t_1')>-1)
	{
		reg = new RegExp("(^|\\?|&)p=([^&]*)(\\s|&|$)", "i");   
		_unid_value = "";
		if(reg.test(url))
		{
			
			_unid_value = unescape(RegExp.$1.replace(/\+/g, " ")) + "p=" + unescape(RegExp.$2.replace(/\+/g, " "));
		}
		
		if(_unid_value!="")
		{
			url = url.replace(_unid_value,"");
		}
		
		reg = new RegExp("(^|\\?|&)n=([^&]*)(\\s|&|$)", "i");   
		_unid_value = "";
		if(reg.test(url))
		{
			
			_unid_value = unescape(RegExp.$1.replace(/\+/g, " ")) + "n=" + unescape(RegExp.$2.replace(/\+/g, " "));
		}
		
		if(_unid_value!="")
		{
			url = url.replace(_unid_value,"");
		}
		
		reg = new RegExp("(^|\\?|&)u=([^&]*)(\\s|&|$)", "i");   
		_unid_value = "";
		if(reg.test(url))
		{
			
			_unid_value = unescape(RegExp.$1.replace(/\+/g, " ")) + "u=" + unescape(RegExp.$2.replace(/\+/g, " "));
		}
		
		if(_unid_value!="")
		{
			url = url.replace(_unid_value,"");
		}
	}
	
	if(url.indexOf('s.click.taobao.com/a') || url.indexOf('s.click.alimama.com/a'))
	{
		reg = new RegExp("(^|\\=)-([^&]*)(\\s|&|$)", "i");   
		_unid_value = "";
		if(reg.test(url))
		{
			
			_unid_value = "-" + unescape(RegExp.$2.replace(/\+/g, " "));
		}
		
		if(_unid_value!="")
		{
			url = url.replace(_unid_value,"");
		}
	}
	
	if(url.indexOf('j.yijia.com/a.php'))
	{
		var reg = new RegExp("(^|\\?|&)union=([^&]*)(\\s|&|$)", "i");   
		var _unid_value = "";
		if(reg.test(url))
		{
			
			_unid_value = unescape(RegExp.$1.replace(/\+/g, " ")) + "union=" + unescape(RegExp.$2.replace(/\+/g, " "));
		}
		
		if(_unid_value!="")
		{
			url = url.replace(_unid_value,"");
		}
	}
	url = url.replace(/&/g,"_");
	return url;
}

function get_unid(url)
{
	var reg = new RegExp("(^|\\?|&)unid=([^&]*)(\\s|&|$)", "i");   
	var _unid_value = "";
	if(reg.test(url))
	{
		_unid_value = unescape(RegExp.$2.replace(/\+/g, " "));
	}
	if(_unid_value == "")
	{
		reg = new RegExp("([0-9]{7}[a-z]{1}[0-9]{2}[a-z]{1}[0-9]{4}[a-zA-Z]{3})", "i");
		if(reg.test(url))
		{
			_unid_value = unescape(RegExp.$1.replace(/\+/g, " "));
		}
	}
	return _unid_value;
}
