if (typeof(aWmxTracks)!="object")
    aWmxTracks = new Array();

var wmxTrack = new function(){
        //property
        this.wmx_clid = "asushqmax";
        this.wmx_cpid = "HQ999";
        this.counterURL = (document.location.protocol=="https:"?"https:":"http:")+"//track.asus.com/web_service/counter/CSTrack.aspx";
        this.adURL = (document.location.protocol=="https:"?"https:":"http:")+"//track.asus.com/web_service/counter/ad_total_open.aspx"+"?"+this.wmx_clid;
        this.wmx_cntracking = "1";
        this.wmx_sltracking = "1";
        var strAccount = encodeURIComponent(wmx_GetCookie("WMX_Account"));
        this.strAccount = (strAccount=="null" ? "" : strAccount); // replace null to empty
        this.wmx_from = document.referrer;
        this.wmx_thisURL = document.URL;
        this.wmx_thisURL = Replace_URL(this.wmx_thisURL);
        //this.wmx_title = document.title;
        this.wmx_title = pagename;
        this.sessionKey = "wmx_" + this.wmx_clid;
        this.strUID = (navigator.cookieEnabled ? "W_S_UID" : "-1");
        this.s12; //flash1
        this.s13; //flash2
        this.s15; //keep1
        this.s16; //keep2
        this.s17; //keep3
        this.s18; //keep4
        this.s19; //keep5
        this.uli;
        this.u1;
        this.u2;
        this.imgCounter = new Image(1,1);
        this.vTitle;
        this.vUrl = location.protocol + "//" + location.hostname + location.pathname;

        //method
        this.wmxTracking = wmx_Tracking;
        this.adLoad = wmx_ad_onload;

        this.wmxTracking();
        //this.adLoad();
    };

aWmxTracks[wmxTrack.wmx_clid+"_"+wmxTrack.wmx_cpid] = wmxTrack;

function wmx_Flash2(sJS, sTitle, sParam)
{
    var oWMXTrack = ckTracker(sJS);
    if (oWMXTrack==null) return;

    oWMXTrack.wmx_title = sTitle;
    oWMXTrack.wmx_from = oWMXTrack.wmx_thisURL;
    oWMXTrack.wmx_thisURL = oWMXTrack.vUrl + "?" + sParam;
    oWMXTrack.wmxTracking();
}

function wmx_Flash(sJS, s12, s13)
{
    var oWMXTrack = ckTracker(sJS);
    if (oWMXTrack==null) return;

    oWMXTrack.s12 = s12;
    oWMXTrack.s13 = s13;
    oWMXTrack.wmxTracking();
}

function ckTracker(sJS)
{
    if (typeof(aWmxTracks)!="object") return null;
    return aWmxTracks[sJS];
}

function wmx_Tracking()
{	
	var wmx_Common_Param = "cli="+this.wmx_clid+"&countertracking="+this.wmx_cntracking+"&sltracking="+this.wmx_sltracking+"&uid="+this.strUID;		
	var wmx_Counter_Param = "";
	var wmx_Cross_Param = "";
	var wmx_Tracking_Param = "";
			
	if (this.wmx_cntracking == "1") // counter parameter
	{
		if(this.wmx_title == "")
		{
			this.wmx_title = this.wmx_thisURL;
			var nIndex = this.wmx_title.indexOf("?");
			if(nIndex != -1) this.wmx_title = this.wmx_title.substring(0, nIndex);
			nIndex = this.wmx_title.indexOf("#");
			if(nIndex != -1) this.wmx_title = this.wmx_title.substring(0, nIndex);
			nIndex = this.wmx_title.lastIndexOf("/");
			if(nIndex != -1)
			{
				var nLen = this.wmx_title.length;
				this.wmx_title = this.wmx_title.substring(nIndex+1, nLen);
			}
		}
		
		wmx_Counter_Param = "pname=" + escape(this.wmx_title);
		wmx_Cross_Param = "1="+encodeURIComponent(this.wmx_thisURL)+"&3=W_S_SC&9="+encodeURIComponent(this.wmx_from)+"&11="+this.wmx_cpid;
	}
	
	if (this.wmx_sltracking =="1")  // tracking parameter
	{
		wmx_Tracking_Param = "1="+encodeURIComponent(this.wmx_thisURL)+"&2="+this.strUID+"&3=W_S_SC";
		wmx_Tracking_Param += "&4="+this.strAccount+"&5=W_S&6=W_S_DATE&7=W_S&8=W_S&9="+encodeURIComponent(this.wmx_from)+"&10=W_S_IP&11="+this.wmx_cpid;
		wmx_Tracking_Param += "&20="+wmx_GetHttpUrl(this.wmx_thisURL)+"&21="+encodeURIComponent(wmx_GetHttpUrlParam(this.wmx_thisURL));		
	}
		
	var strSrc = this.counterURL+"?"+wmx_Common_Param;
	if (wmx_Counter_Param != "")
		strSrc += "&" + wmx_Counter_Param;
	
	if (wmx_Tracking_Param != "")
		strSrc += "&" + wmx_Tracking_Param;	
	else
		strSrc += "&" + wmx_Cross_Param;
		
	strSrc +="&22="+encodeURIComponent(navigator.userAgent.substring(0,128))+"&23="+screen.width+"&24="+screen.height;
    // extend
    if (this.s12) strSrc += "&12=" + this.s12;
    if (this.s13) strSrc += "&13=" + this.s13;
    if (this.s15) strSrc += "&15=" + this.s15;
    if (this.s16) strSrc += "&16=" + this.s16;
    if (this.s17) strSrc += "&17=" + this.s17;
    if (this.s18) strSrc += "&18=" + this.s18;
    if (this.s19) strSrc += "&19=" + this.s19;
    if (this.uli) strSrc += "&uli=" + this.uli;
    if (this.u1) strSrc += "&u1=" + this.u1;
    if (this.u2) strSrc += "&u2=" + this.u2;

    this.imgCounter[this.imgCounter.length] = new Image(1,1);
    this.imgCounter[this.imgCounter.length].src = strSrc;
}

function wmx_GetCookie(sName)
{
  var aCookie = document.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++) {
    var aCrumb = aCookie[i].split("=");
    if (sName == unescape(aCrumb[0])) 
      return unescape(aCrumb[1]);
  }
  return null;
}

function wmx_GetHttpUrl(strUrl)
{
	var nPos = strUrl.indexOf("?");
	if (nPos != -1)
		return (strUrl.substring(0,nPos));
	else
		return (strUrl);
}

function wmx_GetHttpUrlParam(strUrl)
{
	var strResParam = "";
	var strUnListParam = "";
	var oParam, oTmpArray;
	var nPos = strUrl.indexOf("?");	
	
	var strFileName = "products.aspx";
	var oArray = ["l1","l2","l3","l4","model"];
	var oValueArray = new Array(oArray.length);
	
	var strTmp = strUrl.substring(0,nPos);
	var nPos2 = strTmp.lastIndexOf("/");

	if (nPos != -1)
		strTmp = strTmp.substring(nPos2+1,strTmp.length);
	else
		strTmp = "";		

		
	if (nPos != -1)
	{
		var strSrcParam = strUrl.substring(nPos+1,strUrl.length);
		oParam = strSrcParam.split('&');
		oParam.sort();
		
		if (strTmp == strFileName)  //  process if filename is products.aspx
		{
			for (i=0; i<oParam.length; i++)
			{	      	      		      		
			   oTmpArray = oParam[i].split('=');
	
			   var nIndex = Common_Array_IndexOf(oArray,oTmpArray[0]);		   
			   if (nIndex >=0)
			   {
			       oValueArray[nIndex] = oTmpArray[1];
			   }		       
			   else
			   {
			   	   if (strUnListParam != "")
			          strUnListParam += "&";		   
			          
			       strUnListParam += oTmpArray[0] + "=" + oTmpArray[1];
			   }		       		
			}
	
			for (i=0; i<oArray.length; i++)
			{
			   if (strResParam != "")
			      strResParam += "&";
			      		
			   if (typeof(oValueArray[i]) == "undefined")
			       strResParam += oArray[i] + "=";		   
			   else		   		      		
			       strResParam += oArray[i] + "=" + oValueArray[i];
			}	    
			
			if (strUnListParam != "")
			   strResParam += "&" + strUnListParam
		}
		else  // Normal process
		{
			for (i=0; i<oParam.length; i++)
			{
			   if (strResParam != "")
			      strResParam += "&";
			      
				strResParam += oParam[i];      
			}
		}		   

	}

	return (strResParam);		
}

function wmx_total_open(clid,cpid)    
{    
    var oWmxTrack = ckTracker(clid+"_"+cpid);
    if (oWmxTrack==null) return;

    oWmxTrack.imgCounter[oWmxTrack.imgCounter.length] = new Image(1,1);
    oWmxTrack.imgCounter[oWmxTrack.imgCounter.length].src = oWmxTrack.adURL;
}

function wmx_ad_onload()
{
    if(this.wmx_from != this.wmx_thisURL)
    {
        if(window.addEventListener) // Mozilla, Netscape, Firefox
            addEventListener('load', new Function("wmx_total_open('"+this.wmx_clid+"','"+this.wmx_cpid+"');"), false);
        else
            attachEvent('onload', new Function("wmx_total_open('"+this.wmx_clid+"','"+this.wmx_cpid+"');"));
    }
}


function Common_Array_IndexOf(oArray, strValue)
{
    var nIndex = -1;
    for (var i=0; i < oArray.length; i++)
    {
        if (oArray[i] == strValue)
            nIndex = i;
    }
    
    return (nIndex);
}

function Replace_URL(strSrcURL)
{  
   // -----------------------------------------------
   
   var oSrcArray = new Array(42);
   var oAllowArray = new Array(42);
   
   oSrcArray[0] = "http://taiwan.asus.com.tw/";
   oAllowArray[0] = "http://tw.asus.com/";
   
   oSrcArray[1] = "http://www.asus.gr/";
   oAllowArray[1] = "http://gr.asus.com/";  

   oSrcArray[2] = "http://www.asus.nl/";
   oAllowArray[2] = "http://nl.asus.com/"; 

   oSrcArray[3] = "http://france.asus.com/";
   oAllowArray[3] = "http://fr.asus.com/";
   
   oSrcArray[4] = "http://www.asus.es/";
   oAllowArray[4] = "http://es.asus.com/";  

   oSrcArray[5] = "http://www.asus.fi/";
   oAllowArray[5] = "http://fi.asus.com/"; 

   oSrcArray[6] = "http://www.asus.it/";
   oAllowArray[6] = "http://it.asus.com/";
   
   oSrcArray[7] = "http://www.asus.ch/";
   oAllowArray[7] = "http://ch.asus.com/";  

   oSrcArray[8] = "http://www.asus.cz/";
   oAllowArray[8] = "http://cz.asus.com/"; 

   oSrcArray[9] = "http://www.asus.dk/";
   oAllowArray[9] = "http://dk.asus.com/";
   
   oSrcArray[10] = "http://www.asus.se/";
   oAllowArray[10] = "http://se.asus.com/";  

   oSrcArray[11] = "http://www.asus.no/";
   oAllowArray[11] = "http://no.asus.com/"; 

   oSrcArray[12] = "http://www.asus.com.pl/";
   oAllowArray[12] = "http://pl.asus.com/";
   
   oSrcArray[13] = "http://www.asustek.pl/";
   oAllowArray[13] = "http://pl.asus.com/";  

   oSrcArray[14] = "http://www.asus.pl/";
   oAllowArray[14] = "http://pl.asus.com/"; 

   oSrcArray[15] = "http://www.asus.at/";
   oAllowArray[15] = "http://de.asus.com/";
   
   oSrcArray[16] = "http://at.asus.com/";
   oAllowArray[16] = "http://de.asus.com/";  

   oSrcArray[17] = "http://www.asuscom.de/";
   oAllowArray[17] = "http://de.asus.com/"; 

   oSrcArray[18] = "http://www.asus.de/";
   oAllowArray[18] = "http://de.asus.com/";
   
   oSrcArray[19] = "http://www.asus.com.mx/";
   oAllowArray[19] = "http://ar.asus.com/";  

   oSrcArray[20] = "http://mx.asus.com/";
   oAllowArray[20] = "http://ar.asus.com/"; 

   oSrcArray[21] = "http://www.asus.com.ar/";
   oAllowArray[21] = "http://ar.asus.com/";
   
   oSrcArray[22] = "http://my.asus.com/";
   oAllowArray[22] = "http://my.asus.com/";  

   oSrcArray[23] = "http://www.asus.com.au/";
   oAllowArray[23] = "http://au.asus.com/"; 

   oSrcArray[24] = "http://www.asus.com.ph/";
   oAllowArray[24] = "http://ph.asus.com/";
   
   oSrcArray[25] = "http://www.asus.ph/";
   oAllowArray[25] = "http://ph.asus.com/";  

   oSrcArray[26] = "http://www.asus.sg/";
   oAllowArray[26] = "http://sg.asus.com/"; 

   oSrcArray[27] = "http://www.asus.co.th/";
   oAllowArray[27] = "http://th.asus.com/";
   
   oSrcArray[28] = "http://www.asuscom.ru/";
   oAllowArray[28] = "http://ru.asus.com/";  

   oSrcArray[29] = "http://www.asus.co.jp/";
   oAllowArray[29] = "http://jp.asus.com/"; 

   oSrcArray[30] = "http://www.asus-korea.co.kr/";
   oAllowArray[30] = "http://kr.asus.com/";
   
   oSrcArray[31] = "http://www.asus.com.cn/";
   oAllowArray[31] = "http://cn.asus.com/";  

   oSrcArray[32] = "http://www.asus.com.tr/";
   oAllowArray[32] = "http://tr.asus.com/"; 

   oSrcArray[33] = "http://www.asus.lk/";
   oAllowArray[33] = "http://lk.asus.com/";

   oSrcArray[34] = "http://www.asus.com.tw/";
   oAllowArray[34] = "http://www.asus.com/";  

   oSrcArray[35] = "http://www.asus.net.nz/";
   oAllowArray[35] = "http://www.asus.com/"; 

   oSrcArray[36] = "http://www.asus.co.nz/";
   oAllowArray[36] = "http://www.asus.com/";

   oSrcArray[37] = "http://ua.asus.com/";
   oAllowArray[37] = "http://www.asus.ua/";

   oSrcArray[38] = "http://www.asus.com.pk/";
   oAllowArray[38] = "http://pk.asus.com/";

   oSrcArray[39] = "http://www.asus.rs/";
   oAllowArray[39] = "http://yu.asus.com/";

   oSrcArray[40] = "http://rs.asus.com/";
   oAllowArray[40] = "http://yu.asus.ua/";

   oSrcArray[41] = "http://asus.rs/";
   oAllowArray[41] = "http://yu.asus.com/";

   // -----------------------------------------------   


   var strResultUrl = strSrcURL;
	
   for (i=0; i<oSrcArray.length; i++)
   {
      strResultUrl = strSrcURL.replace(oSrcArray[i],oAllowArray[i]);
      if (strSrcURL != strResultUrl)
         break;
   }
	
   return strResultUrl;
   
}

