if (typeof(aWmxTracks)!="object")
    aWmxTracks = new Array();

aWmxTracks["WhiskasTW6cc_Pouch2009"] = new function(){
        //property
        this.wmx_clid = "WhiskasTW6cc";
        this.wmx_cpid = "Pouch2009";
        this.protocol = location.protocol=="https:"?"https:":"http:";
        this.counterURL = this.protocol + "//wm6.ecrm.com.tw/web_service/counter/CSTrack.aspx";
        this.adURL = this.protocol + "//wm6.ecrm.com.tw/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_title = document.title;
        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 Array();
        this.vUrl = this.protocol + "//" + location.hostname + location.pathname;
        this.adURL2 = this.protocol + "//wm6.ecrm.com.tw/web_service/counter/wmax_event.aspx";
		var wmx_thisURL = document.URL;
		var sAdParams = wmx_thisURL.match(/\?wmx_ad_id=\w+:\w+:\w+$|&wmx_ad_id=\w+:\w+:\w+|wmx_ad_id=\w+:\w+:\w+&/);
        this.wmx_thisURL = wmx_thisURL.replace(sAdParams, "");
        this.sAdParams = sAdParams;
        if (sAdParams) this.adURL2 += "?" + this.sAdParams.toString().replace(/[\?&]/,"").split("=")[1];

        //method
        this.wmxTracking = wmx_Tracking;
        this.adLoad = wmx_ad_onload;
    };

function wmx_LogTrack(sPath, sTitle, sMode, sJS)
{
    if (sPath==undefined || sPath == "") return;

    if (sMode==undefined || sMode=="") sMode = "D";
    sMode = sMode.toUpperCase();

    var oWmxTrack;
    oWmxTrack = getTracker(sJS);
    if (oWmxTrack==null) return;
    
    var thisURL = "";
    if (sMode=="D")
    {
        var aP = sPath.split("/");
        var aF = new Array();
        var nLimit = 5; // LimitDynamicParams
        for (var i=1; i<aP.length; i++)
        {
            aF.push("L"+i+"="+aP[i]);
            if (i==nLimit) break;
        }
        thisURL = oWmxTrack.vUrl + "?" + aF.join("&");
    }
    else if (sMode=="S")
    {
        thisURL = oWmxTrack.protocol + "//" + location.hostname + sPath;
    }
    else if (sMode=="E")
    {
        sTitle = oWmxTrack.wmx_title;
        thisURL = oWmxTrack.wmx_thisURL;
        oWmxTrack.wmx_thisURL = oWmxTrack.wmx_from;
        var aE = sPath.split("/");
        var nLimit = 5; // LimitReserve
        for (var i=1; i<aE.length; i++)
        {
            try
            {                
                eval("oWmxTrack.s"+(14+i)+"='"+aE[i]+"'");
            }
            catch (e)
            {
            }
            if (i==nLimit) break;
        }
    }
    
    oWmxTrack.wmx_title = (sTitle==undefined || sTitle=="")?sPath:sTitle;
    oWmxTrack.wmx_from = oWmxTrack.wmx_thisURL;
    oWmxTrack.wmx_thisURL = thisURL;

    //oWmxTrack.wmxTracking();
	return oWmxTrack;
	
}

function wmx_EventTrack(s12, s13, sJS)
{
    var oWmxTrack;
    oWmxTrack = getTracker(sJS);
    if (oWmxTrack==null) return;

    oWmxTrack.s12 = s12;
    oWmxTrack.s13 = s13;
    oWmxTrack.wmxTracking();
}

function getTracker(sJS)
{
    if (typeof(aWmxTracks)!="object") return null;
    for (i in aWmxTracks) 
        if (sJS==undefined) return aWmxTracks[i];

    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=" + escape(this.s12);
    if (this.s13) strSrc += "&13=" + escape(this.s13);
    if (this.s15) strSrc += "&15=" + escape(this.s15);
    if (this.s16) strSrc += "&16=" + escape(this.s16);
    if (this.s17) strSrc += "&17=" + escape(this.s17);
    if (this.s18) strSrc += "&18=" + escape(this.s18);
    if (this.s19) strSrc += "&19=" + escape(this.s19);
    if (this.uli) strSrc += "&uli=" + escape(this.uli);
    if (this.u1) strSrc += "&u1=" + escape(this.u1);
    if (this.u2) strSrc += "&u2=" + escape(this.u2);

    this.imgCounter[this.imgCounter.length] = new Image(1,1);
    this.imgCounter[this.imgCounter.length-1].src = strSrc;

    // ad_id tracking
    if (this.sAdParams){this.imgCounter[this.imgCounter.length] = new Image(1,1);this.imgCounter[this.imgCounter.length-1].src=this.adURL2};
}

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 nPos = strUrl.indexOf("?");	

	if (nPos != -1)
	{
		var strSrcParam = strUrl.substring(nPos+1,strUrl.length).toLowerCase();
		var oParam = strSrcParam.split('&');
		oParam.sort();
		
		for (i=0; i<oParam.length; i++)
		{
		   if (strResParam != "")
		      strResParam += "&";
		      
			strResParam += oParam[i];      
		}
	}

	return (strResParam);	
}

function wmx_total_open(clid,cpid)    
{    
    var oWmxTrack = getTracker(clid+"_"+cpid);
    if (oWmxTrack==null) return;

    oWmxTrack.imgCounter[oWmxTrack.imgCounter.length] = new Image(1,1);
    oWmxTrack.imgCounter[oWmxTrack.imgCounter.length-1].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 wmx_flash_counter(title,url)  // for flash tracking
{
	
	var tracker = wmx_LogTrack(url, title, "S", "WhiskasTW6cc_Pouch2009");
	tracker.wmxTracking();
}

var oWmxTrack = getTracker("WhiskasTW6cc_Pouch2009");
oWmxTrack.wmxTracking();