﻿//function createXMLHTTP2(){
//    var xmlhttp
//    if (window.XMLHttpRequest)
//    {
//      xmlhttp = new XMLHttpRequest();
//    }
//    else if (window.ActiveXObject)
//    { 
//      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
//    }
//    return xmlhttp
//}

//使用前要调用 /IYP_API/js/iypCommon.js

function webTraffic(eid,sLang,evalue1,evalue2,evalue3,evalue4,servername)
{
  if(evalue1 == undefined)
		evalue1="";
  if(evalue2 == undefined)
    evalue2="";
  if(evalue3 == undefined)
    evalue3="";
  if(evalue4 == undefined)
    evalue4="";
  if(servername == undefined)
    servername="";
     
	if(sLang=="sc" && servername=="")
	{
		var strU=location.href
		strU=strU.replace(/http:\/\/gb.yp.com.hk\/han3\/7\/6\/9\/0\/0\/0\/0\//g,"http:\/\/")
		strU=strU.replace(/http:\/\//g,"")
		strU=strU.substr(0,strU.indexOf("/"))
		//strUrl="http://"+strU+"/IYP_API/statistics/web_traffic_capture.aspx?" Not same domain,can't use AJAX.
    servername=strU
	}
	var strUrl=servername+"/IYP_API/statistics/web_traffic_capture.aspx?"
	strUrl+="eid="+eid
	strUrl+="&evalue1="+encodeURIComponent(evalue1)
	strUrl+="&evalue2="+encodeURIComponent(evalue2)
	strUrl+="&evalue3="+encodeURIComponent(evalue3)
	strUrl+="&evalue4="+encodeURIComponent(evalue4)
	strUrl+="&sLang="+sLang
	strUrl+="&title="+encodeURIComponent(document.title)
	strUrl+="&host="+encodeURIComponent(location.host)
	strUrl+="&url="+encodeURIComponent(location.pathname)
	strUrl+="&referral_url="+encodeURIComponent(document.referrer)
	strUrl+="&resolution="+encodeURIComponent(screen.width+"x"+screen.height)
	//alert(strUrl);
	
	if(getP("debug")=="Y" && document.form_box1)
	{
		document.form_box1.txtKeyword.value=strUrl
	}
	
	if(servername!="")
	{
		var element = document.createElement("script");
		element.src = strUrl;
		element.type = "text/javascript";
		element.language = "javascript";
		document.getElementsByTagName("head")[0].appendChild(element);
	}
	else
	{
		var xmlhttp2=createXMLHTTP()
		xmlhttp2.onreadystatechange = function ()
		{
			if (xmlhttp2.readyState == 4)
			{
				if (xmlhttp2.status == 200)
				{
					var strResult = xmlhttp2.responseText
				}
			}
		}
		xmlhttp2.open("GET",strUrl,true);
		xmlhttp2.send(null);
	}
}

function getP(nameP)
{
  var strL=new String(document.location)
  var strP=strL.substr(strL.indexOf("?")+1)
	var arrP=new Array()
	var arrP1=new Array()
	var kw=""

	arrP=strP.split("&")
	for(var i=0;i<arrP.length;i++)
	{
	  arrP1=arrP[i].split("=")
	  if(arrP1[0]==nameP)
	  {
	    kw=decodeURIComponent(arrP1[1])
	  }
	}
	
	return kw;
}

