//REFERENCE PAGE TAG
function CollectValue(remote, name) {
	vo += '&' + name + '=' + escape2(remote);
}

// CONSTANTS
var ct = "<img src=";
var cd = "//csvtq.intuit.co.uk"; //this should contain the domain of the web site
var cu = "/zag.gif?Log=1"; //this should contain the full path to the zag.gif file (excluding domain) and include the query string of log=1
var cc = "/zag3.gif?Log=1";
var cve = ">";

var c = {};
c["sw"] = screen.width;
c["sh"] = screen.height;
c["cd"] = screen.colorDepth;
var co = "";

for ( cKey in c ) {
	co = co+"&"+cKey+"="+escape1(c[cKey]);
}
document.write(ct,cd,cc,co,cve);

var d = {};
d["dt"] = document.title;
d["dr"] = document.referrer;
d["cb"] = new Date().getTime();
var vo = "";

if (typeof subtotal != "undefined") { CollectValue(subtotal, "subtotal") }

if (typeof firstname != "undefined") { CollectValue(firstname, "firstname") }

if (typeof lastname != "undefined") { CollectValue(lastname, "lastname") }

if (typeof email != "undefined") { CollectValue(email, "email") }

if (typeof orderid != "undefined") { CollectValue(orderid, "orderid") }

if (typeof customerid != "undefined") { CollectValue(customerid, "customerid") }

if (typeof shippingmethod != "undefined") { CollectValue(shippingmethod, "shippingmethod") }

if (typeof v != "undefined") {
	for ( vKey in v ) {
		vo = vo+"&"+vKey+"="+escape1(v[vKey]);
	}
}
for ( dKey in d ) {
	vo = vo+"&"+dKey+"="+escape2(d[dKey]);
}
document.write(ct,cd,cu,vo,cve);
//END REFERENCE PAGE TAG


//REFERENCE LINK AND FORM CLICK PAGE TAG
//INITIATE FUNCTIONS ONLOAD
function addToWindowOnLoad(funct){
	var oldOnload = window.onload;
	if (typeof window.onload != 'function') { window.onload = funct; }
	else { 
		window.onload = function() {
			oldOnload();
			funct();
		}
	}
}

addToWindowOnLoad(startCapture);

function startCapture(){
	
	//TO CAPTURE LINK CLICKS
	if (vlc == "1"){captureLink();}
	
}

//BEGIN LINK CAPTURE PAGE TAG
function captureLink(){
	if (document.links[0]){
	if (document.links){
	var links = document.links, link, k=0;
			while(link=links[k++]) {
				if (typeof link.onclick != 'function') {
					link.onclick = captureLinkName;
				}
				else {
					link.onmouseup = captureLinkName;
				}
			}
		}
	}
}
function captureLinkName() {
	var lc=new Image();
	this.parent = this.parentNode;
	lc.src= cd + '/zag2.gif?Log=1&linkname=' + escape1(this.name) + '&linkurl=' + escape2(this.href) + '&cd=' + new Date().getTime();
}
//END LINK CAPTURE PAGE TAG

//BEGIN EVENT CAPTURE PAGE TAG
function eventOnclick(id) {
	var ec=new Image();
	ec.src= cd + '/zag2.gif?Log=1&eventid=' + escape1(id) + '&cd=' + new Date().getTime();
}
//END EVENT CAPTURE PAGE TAG

//HTML EXCAPE FUNCTIONS
function escape1(s)
{ return escape(s).replace(/\+/g,"%20") }

function escape2(s)
{ return escape(s).replace(/\+/g, "%2B") }

//BEGIN ITEM COLLECTION
var ex = {};

if ( typeof itemqty != "undefined" ) {
	for ( itemqtyKey in itemqty ) { 
		if (typeof ex[itemqtyKey] != "undefined") { ex[itemqtyKey] = ex[itemqtyKey]+"&itemqty="+itemqty[itemqtyKey] }
		else { ex[itemqtyKey] = "&itemqty="+itemqty[itemqtyKey] }
	}
}
if ( typeof itemname != "undefined" ) {
	for ( itemnameKey in itemname ) {
		if (typeof ex[itemnameKey] != "undefined") { ex[itemnameKey] = ex[itemnameKey]+"&itemname="+itemname[itemnameKey] }
		else { ex[itemnameKey] = "&itemname="+itemname[itemnameKey] }
	}
}
if ( typeof itemtotal != "undefined" ) {
	for ( itemtotalKey in itemtotal ) {
		if (typeof ex[itemtotalKey] != "undefined") { ex[itemtotalKey] = ex[itemtotalKey]+"&itemtotal="+itemtotal[itemtotalKey] }
		else { ex[itemtotalKey] = "&itemtotal="+itemtotal[itemtotalKey] }
	}
}
if ( typeof itemsku != "undefined" ) {
	for ( itemskuKey in itemsku ) {
		if (typeof ex[itemskuKey] != "undefined") { ex[itemskuKey] = ex[itemskuKey]+"&itemsku="+itemsku[itemskuKey] }
		else { ex[itemskuKey] = "&itemsku="+itemsku[itemskuKey] }
	}
}
// 
for ( exKey in ex ) {
	var ec=new Image();
	ec.src= cd + '/zag2.gif?Log=1' + ex[exKey] + '&cd=' + new Date().getTime();
}
//END ITEM COLLECTION