/* Version: 060412 */

/* WARNING: Do not modify the visitorNamespace parameter
unless instructed to by Omniture */
s.visitorNamespace="amazonms"
s.server=window.location.hostname
	
/* Override any s_code.js default settings here */
s.currencyCode="GBP"


if (s_account=="amznmscom" || s_account=="amznmsdev") {
	s.trackExternalLinks=true
	s.linkInternalFilters="javascript:,marksandspencer"
}
	

/* Merchant specific prePlugins functions (runs before doPlugins) */
function s_prePlugins(s) {
	
	// get external tracking code
	if (!s.campaign) {s.campaign=s.getQueryParam("extid")}

        var objInfo = new Object();
        // Check if campaign is set
        if (s.campaign) {
            // Get the required values from cookies
            getCookieInfoForCampaign(objInfo);
 
            // check if the extid is already set in cookie but for old session
            if (objInfo.currSession != objInfo.lastSession) {
               // Delete the cookies
               deleteCookie('extid');
               // Create a new one with updated extid
               createCookie('extid', objInfo.currSession + ':' + s.campaign, 7);
            } else if(objInfo.extid != s.campaign) {
               // If the extid is set, but if it doesn't match with present value
               // clear the cookie and create a new one
               deleteCookie('extid');
               createCookie('extid', objInfo.currSession + ':' + s.campaign, 7);
            }
        } else if(s.purchaseID || s.eVar13) {
            // If its a thankyou page, then set the s.campaign value from cookies
            getCookieInfoForCampaign(objInfo); 
            // Check if the extid from cookie doesn't belong to any old session
            if (objInfo.currSession == objInfo.lastSession) {
                s.campaign =  objInfo.extid; 
            } else {
                deleteCookie('extid');
            }
        }
		
	/*
	* Save value in s.campaign to a cookie 's_cpm' 
	* Return list of up to 5 stacked campaign values from this cookie or the current value in s.campaign
	*  Expire the concatenated values after 7 days or after a purchase.
	*/
	if(!s.eVar23)
		s.eVar23= s.crossVisitParticipation(s.campaign,'s_cpm','7','5','>','purchase');

    
	// get internal tracking code
	if (!s.eVar1) {
		s.eVar1=s.getQueryParam("intid");
		s.prop39=s.eVar1;
		}

        // get ep_mid
        if (!s.eVar32) {s.eVar32=s.getQueryParam("ep_mid")}

        // get persisted variable of link clicked
       if(!s.prop34) { s.prop34=s.getQueryParam("pos")};
}


/* Merchant specific postPlugins functions (runs after doPlugins) */
function s_postPlugins(s) {
	s.setupDynamicObjectIDs();
	// cleanup browse node and search merchandising
	if (s.eVar14) {
		if (s.eVar14!="Browse") {s.eVar5="non-Browse"}
	}
        s.prop6 = s.pageName + s.prop6;
        s.prop40 = s.pageName;

	if (s.eVar11) {
		s.prop6 = s.prop6 + "AB: " + s.eVar11;
		s.eVar11 = s.pageName + ": " + s.eVar11;
	}

        if (s.campaign) {s.prop6 = s.prop6+" CMP: "+s.campaign}
        if (s.eVar1) {s.prop6 = s.prop6+" INT: "+s.eVar1}
        if (s.prop44) {s.prop6 = s.prop6+" "+s.prop44;
        	      s.prop40 = s.prop40+" "+s.prop44;}
        if (s.prop20) {s.prop6 = s.prop6+" DS: "+s.prop20;
        	       s.prop40 = s.prop40+" DS: "+s.prop20;}
        if (s.prop14) {s.prop6 = s.prop6+" ERR: "+s.prop14}
        if (s.eVar5) {s.eVar25 = s.eVar5}
        s.prop7 = document.location.href;
}

/* function to create a cookie */
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

/* function to read the cookie */
function readCookie(name) {
	var nameEQ = name + "=";
	var temp = document.cookie.split(';');
	for(var iCount=0;iCount < temp.length;iCount++) {
		var curr = temp[iCount];
		while (curr.charAt(0)==' ') curr = curr.substring(1,curr.length);
		if (curr.indexOf(nameEQ) == 0) return curr.substring(nameEQ.length,curr.length);
	}
	return null;
}

/* function to clear the cookie wirh th specific name passed
   as argument */
function deleteCookie(name) {
	createCookie(name,"",-1);
}

/* function to get specific implementaion values */
function getCookieInfoForCampaign(objInfo) {
       objInfo.currSession = readCookie("session-id");
       var extid = readCookie("extid");

       if (extid) {
           var arrTemp = extid.split(":");
           objInfo.lastSession = arrTemp[0];
           objInfo.extid      = arrTemp[1];
       }
}

/* DynamicObjectIDs config */
function s_getObjectID(o) {
	/* TODO: Add code to identify whether an objectID should be created,
	 *       parse the URLs and return objectID. If no objectID should
	 *       be created, return ''.
	 */
	var ID=o.href;
	return ID;
}
s.getObjectID=s_getObjectID



/*
 * DynamicObjectIDs v1.4: Setup Dynamic Object IDs based on URL
 */
s.setupDynamicObjectIDs=new Function(""
+"var s=this;if(!s.doi){s.doi=1;if(s.apv>3&&(!s.isie||!s.ismac||s.apv"
+">=5)){if(s.wd.attachEvent)s.wd.attachEvent('onload',s.setOIDs);else"
+" if(s.wd.addEventListener)s.wd.addEventListener('load',s.setOIDs,fa"
+"lse);else{s.doiol=s.wd.onload;s.wd.onload=s.setOIDs}}s.wd.s_semapho"
+"re=1}");
s.setOIDs=new Function("e",""
+"var s=s_c_il["+s._in+"],b=s.eh(s.wd,'onload'),o='onclick',x,l,u,c,i"
+",a=new Array;if(s.doiol){if(b)s[b]=s.wd[b];s.doiol(e)}if(s.d.links)"
+"{for(i=0;i<s.d.links.length;i++){l=s.d.links[i];c=l[o]?''+l[o]:'';b"
+"=s.eh(l,o);z=l[b]?''+l[b]:'';u=s.getObjectID(l);if(u&&c.indexOf('s_"
+"objectID')<0&&z.indexOf('s_objectID')<0){u=s.repl(u,'\"','');u=s.re"
+"pl(u,'\\n','').substring(0,97);l.s_oc=l[o];a[u]=a[u]?a[u]+1:1;x='';"
+"if(c.indexOf('.t(')>=0||c.indexOf('.tl(')>=0||c.indexOf('s_gs(')>=0"
+")x='var x=\".tl(\";';x+='s_objectID=\"'+u+'_'+a[u]+'\";return this."
+"s_oc?this.s_oc(e):true';if(s.isns&&s.apv>=5)l.setAttribute(o,x);l[o"
+"]=new Function('e',x)}}}s.wd.s_semaphore=0;return true");


/********************************************************************
 *
 * Supporting functions that may be shared between plug-ins
 *
 *******************************************************************/
/*
 * Plugin Utility: Replace v1.0
 */
s.repl=new Function("x","o","n",""
+"var i=x.indexOf(o),l=n.length;while(x&&i>=0){x=x.substring(0,i)+n+x."
+"substring(i+o.length);i=x.indexOf(o,i+l)}return x");

/*
 * Only return an objectID for URLs that should have an objectID.
 *   For all others, return empty string.
s.getObjectID=new Function("u",""

	// strip query string
	+"var x=u.indexOf('?');"
	+"u=x>-1?u.substring(0,x):u;"

	// find the file name (last portion of path)
	+"y=u.lastIndexOf('/');"
	+"x=u.substring(y+1);"

	// if the dashes are in the right place, strip it
	+"if(x.charAt(3)!='-'||x.charAt(11)!='-')"
		+"u='';"
	+"else "
		+"u=u.substring(0,y);"

	// if '/qid=XXXXXXXXXXX/' exists, strip it
	+"x=u.indexOf('qid=');"
	+"y=x>-1?u.indexOf('/',x):0;"
	+"u=x>-1?u.substring(0,x)+u.substring(y+1):u;"

	// return the cleaned up URL (u) or nothing
	+"return u"
);
 */
/*                                                                                        
 * Plugin: s.crossVisitParticipation : 1.2 - stacks values from 
 * specified variable in cookie and returns value
 * Requires: s.split and s.join                                           
 */                                                                                                                                                                                             
s.crossVisitParticipation = new Function("v","cn","ex","ct","dl","ev",""                          
+"var s=this;var ay=s.split(ev,',');for(var u=0;u<ay.length;u++){if(s"                     
+".events&&s.events.indexOf(ay[u])!=-1){s.c_w(cn,'');return '';}}if(!"                     
+"v||v=='')return '';var arry=new Array();var a=new Array();var c=s.c"                     
+"_r(cn);var g=0;var h=new Array();if(c&&c!='') arry=eval(c);var e=ne"                     
+"w Date();e.setFullYear(e.getFullYear()+5);if(arry.length>0&&arry[ar"                     
+"ry.length-1][0]==v)arry[arry.length-1]=[v, new Date().getTime()];el"                     
+"se arry[arry.length]=[v, new Date().getTime()];var data=s.join(arry"                     
+",{delim:',',front:'[',back:']',wrap:'\\''});var start=arry.length-c"                     
+"t < 0?0:arry.length-ct;s.c_w(cn,data,e);for(var x=start;x<arry.leng"                     
+"th;x++){var diff=Math.round(new Date()-new Date(parseInt(arry[x][1]"                     
+")))/86400000;if(diff<ex){h[g]=arry[x][0];a[g++]=arry[x];}}var r=s.j"                     
+"oin(h,{delim:dl});return r;");
/*
 * Utility Function: s.join: v1.0
 */
s.join = new Function("v","p",""
+"var s = this;var f,b,d,w;if(p){f=p.front?p.front:'';b=p.back?p.back"
+":'';d=p.delim?p.delim:'';w=p.wrap?p.wrap:'';}var str='';for(var x=0"
+";x<v.length;x++){if(typeof(v[x])=='object' )str+=s.join( v[x],p);el"
+"se str+=w+v[x]+w;if(x<v.length-1)str+=d;}return f+str+b;");
/*
 * Utility Function: split v1.5 (JS 1.0 compatible)
 */
s.split=new Function("l","d",""
+"var i,x=0,a=new Array;while(l){i=l.indexOf(d);i=i>-1?i:l.length;a[x"
+"++]=l.substring(0,i);l=l.substring(i+d.length);}return a");


