var isSaveLogByLocalSource = "true";//是否记录本地来源
var xmlHttp_siteTotal;
var sitestat_time_start = new Date().getTime();

	try{    
            if(!window.onbeforeunload )    //为了不覆盖原来的onbeforeunload方法，先判断    
                window.onbeforeunload = SitestatClose;   //关闭事件  
        }catch(e){}   

//关闭事件调用
  function SitestatClose() {    
  	sendRequestTotalXML();
    }   

function createXMLHttpRequest() {
    if(window.XMLHttpRequest) {
            xmlHttp_siteTotal = new XMLHttpRequest();    
    }else if(window.ActiveXObject) {
            xmlHttp_siteTotal = new ActiveXObject("Microsoft.XMLHTTP");    
    }
}

/**
获取域名
*/
function getDomainName(){
  var s,siteUrl;
  s=document.location+"";
  return s.substring(7,s.indexOf('/',7));

}

function prepareXML() { 
	var sourceUrl = document.referrer;//访问来源
	if(sourceUrl == null || sourceUrl==""){
		if(document.parentWindow.document.referrer!=null && document.parentWindow.document.referrer!=""){
			sourceUrl = document.parentWindow.document.referrer;
		}else{
			sourceUrl = "handwork";
		}
	}
   var xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
   			+"<WebSite-Total>"
   			+"<Request-Step>1</Request-Step>"
		    +"<Request>"
			+"<Source-Url>"+ sourceUrl +"</Source-Url>"
			+"<Visit-Url>"+ document.URL +"</Visit-Url>"
			+"<Article-Title></Article-Title>"
			+"</Request>"
			+"</WebSite-Total>";
   return xml;
 }
 
 function sendRequestTotalXML() {
    var xml = prepareXML(); 
    var xmldoc = new ActiveXObject("Microsoft.XMLDOM");
    xmldoc.async=false;
	xmldoc.loadXML(xml);   
    var url ="http://www.sx.10086.cn/sitestat/WebsiteTotalService?timeStamp" + new Date().getTime(); 
    try{
    	createXMLHttpRequest();   
	xmlHttp_siteTotal.open("POST", url);    
	xmlHttp_siteTotal.send(xml);   
    }catch(e) {
    }
}

 


