//REFERENCE PAGE TAG
// CONSTANTS
var ct = "<img src=";
var cd = "http://analytics.sanoma.fi"; //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 ce = ">";

//TMSEC custom code
var tmsec;
if(typeof(tmsec)!="undefined"){
  var tmsec_str = "";
  for (i=0;i<tmsec.length;i++){
	if (tmsec[i].indexOf("<") == -1) {
	tmsec_str +="/"+tmsec[i].split("=")[1];
	}
  }
var tm = "&tmsec="+ tmsec_str;
} else {
var tm = "&tmsec=undefined";
}
//END TMSEC custom code

var c = {};
c["sw"] = screen.width;
c["sh"] = screen.height;
c["cd"] = screen.colorDepth;
c["cb"] = new Date().getTime(); //HH:Moved from the page tag
var co = "";

for ( cKey in c ) {
	co = co+"&"+cKey+"="+escape1(c[cKey]);
}
//document.write(ct,cd,cu,co,ce); // Send constant tag - HH:co copied to page tag

var d = {};
d["dt"] = enco(document.title);
d["dr"] = document.referrer;
var vo = "";

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,co,tm,ce); // Send page level tag - HH:co added from the constant

//END REFERENCE PAGE TAG

//ESCAPES
function escape1(s)
{ return escape(s).replace(/\+/g,"%20") }

function escape2(s)
{ return escape(s).replace(/\+/g, "%2B") }

function enco(en)
{ return encodeURI(en) }

//END ESCAPES


//REFERENCE LINK AND FORM CLICK PAGE TAG - version 5.3
//INITIATE FUNCTIONS ONLOAD
function addEvent(obj, evType, fn){
	if (obj.addEventListener){
		obj.addEventListener(evType, fn, false);
		return true;
	} else if (obj.attachEvent){
		var r = obj.attachEvent("on"+evType, fn);
		return r;
	} else {
		return false;
	}
}
if(typeof(vlc)!="undefined"){
  addEvent(window, 'load', startCapture);
  addEvent(window, 'load', startCapture);
}
function startCapture(){
  if (vlc == "1"){captureLink();} //TO CAPTURE LINK CLICKS
}
//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++]) {
				link.onclick = captureLinkName;
			}
		}
	}
}

function captureLinkName() {
	var lc=new Image();
	this.parent = this.parentNode;
	lc.src='http://analytics.sanoma.fi/zag2.gif?linkname=' + escape1(this.id) + "&lid=" + escape1(this.href) + "&ev=link" + "&cb=" + new Date().getTime();
}
//END LINK CAPTURE PAGE TAG
