var refer=document.referrer;
function get_url(url) { 
 var ScriptName = "sname";
 var head = document.getElementsByTagName("head").item(0);
 var old = document.getElementById(ScriptName);
 if (old)  head.removeChild(old);
 var obj = document.createElement("SCRIPT");
 obj.src = url;
 obj.defer = true;
 obj.type = "text/javascript";
 obj.id = ScriptName;
 head.appendChild(obj);
 return 1;
} 
var url1='';
function querystr(){
	var types=tom_hjsGetVal("type");
	var bank_type=tom_hjsGetVal("bank_type");
	var bank_sub_type=tom_hjsGetVal("bank_sub_type");
	var card_type=tom_hjsGetVal("card_type");
	var product = "";
	if(bank_type&&bank_sub_type){
	    product=bank_type+"_"+bank_sub_type;
	}else if(bank_type!=""){
		product=bank_type;
	}else if(card_type!=""){
		product=card_type;
	}
	else{
		product="null";
	}
	var num=0;
	
	if(types=="")types="txt";
	
	try{
			var regx=/^http:\/\/[a-zA-z0-9.]*\/([a-zA-Z0-9._\/]*)/;
			regx.test(refer);		  
	   }
	catch(e){ 
			alert("user_xrd脚本异常!");
		} 
   var files=RegExp.$1;


   	if(files!=""){
       var geturl="http://skypetools1.tom.com/user_xrd/index.php?file="+files+"&type="+types+"&product="+product+"&num="+num+"&refer="+UrlEncode(refer);
    }else{
  	   var geturl="http://skypetools1.tom.com/user_xrd/index.php?file=index.html&type="+types+"&product="+product+"&num="+num+"&refer="+UrlEncode(refer);
    }
   get_url(geturl);	
} 

//点击回到本页使用
/*
*types:触发类型，如txt，button，img
*product:产品类型
*file:本页html文件名称
*/
function locationQuery(types,product,file){
	if(types!="undefined"&&file!="undefined"){		
		var geturl="http://skypetools1.tom.com/user_xrd/index.php?file="+file+"&type="+types+"&product="+product+"&num=0&refer="+UrlEncode(file);
		get_url(geturl);
	}
}
function UrlEncode(str)    
{    
    return transform(str);    
}    
   
function transform(s)    
{    
    var hex=''   
    var i,j,t    
   
    j=0    
    for (i=0; i<s.length; i++)    
    {    
        t = hexfromdec( s.charCodeAt(i) );    
        if (t=='25')    
        {    
            t='';    
        }    
        hex += '%' + t;    
    }    
    return hex;    
}    
   
function hexfromdec(num) {    
        if (num > 65535) { return ("err!") }    
        first = Math.round(num/4096 - .5);    
        temp1 = num - first * 4096;    
        second = Math.round(temp1/256 -.5);    
        temp2 = temp1 - second * 256;    
        third = Math.round(temp2/16 - .5);    
        fourth = temp2 - third * 16;    
        return (""+getletter(third)+getletter(fourth));    
}    
   
function getletter(num) {    
        if (num < 10) {    
                return num;    
        }    
        else {    
            if (num == 10) { return "A" }    
            if (num == 11) { return "B" }    
            if (num == 12) { return "C" }    
            if (num == 13) { return "D" }    
            if (num == 14) { return "E" }    
            if (num == 15) { return "F" }    
        }    
} 

//=======================================================================
function tom_hjsTrim(str) //2
{
        return str.replace(/(^\s*)|(\s*$)/g,"");
}

function tom_hjsUrlDecode(str){ //5
        var ret="";
        for(var i=0;i<str.length;i++){
                var chr = str.charAt(i);
                if(chr == "+"){
                        ret+=" ";
                }else if(chr=="%"){
                        var asc = str.substring(i+1,i+3);
                        ret+= String.fromCharCode(parseInt("0x"+asc));
                        i+=2;
                }else{
                        ret+= chr;
                }
        }
        return ret;
}


function tom_hjsGetQueryString()//4
{
        var pos = 0;
        var str = "" + document.location.href;
        pos = str.indexOf('?');
        if (-1 == pos) {
                return "";
        }

        return "&" + str.substr(pos + 1) + "&";
}


function tom_hjsGetVal(name)  //3
{
        var begin = 0;
        var end = 0;
        var nm = "" + name;
 
         
         
        var qstr = tom_hjsGetQueryString(); 

        if ("" == nm || "" == qstr) {
                return "";
        }

        nm = "&" + nm + "=";

        begin = qstr.search(new RegExp(nm));
        if (-1 == begin) {
                return "";
        }

        qstr = qstr.substr(begin + nm.length);

        end = qstr.indexOf('&');
        if (-1 == end) {
                return "";
        }

        return tom_hjsUrlDecode(qstr.substring(0, end));
}


function tom_hjsGetValTrim(name)  //1
{
        return tom_hjsTrim(tom_hjsGetVal(name));
}


//用户行为分析执行入口
try{
if(refer!="")querystr();
}catch(e){
} 