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 = "";

	var domain = "; domain=" + document.domain.substr(document.domain.lastIndexOf(".", document.domain.lastIndexOf(".")-1));

	document.cookie = name+"="+value+expires+"; path=/"+ domain;
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

var v2nd = readCookie("v2nd");
if (v2nd==null) {
	var vdate = new Date();
	v2nd_tmp = Math.random().toString(16).substring(2,10)+vdate.getTime().toString(16);

	createCookie("v2nd", v2nd_tmp, 7300);
	v2nd = readCookie("v2nd");
}

var v = {};
v["v2nd"] = v2nd;

if(window.vscount != null)
{
    window.vscount = window.vscount + 1;
    v["logCount"] = window.vscount;
}
else
{
    window.vscount = 1;
}


var ct = "<img src=";
var cd = "http://v.npr.org";
if (document.location.href.indexOf("https:") > -1) {
	cd = "https://v.npr.org";
}
var cu = "/images/zag.gif?Log=1";
var ce = ">";

var c = {};
c["sw"] = screen.width;
c["sh"] = screen.height;
c["cd"] = screen.colorDepth;
var co = "";

var d = {};
d["dr"] = document.referrer;
d["duri"] = document.location.href;
d["cb"] = new Date().getTime();

if(window.nprid != null)
{
d["nprid"] = window.nprid;
}
else
{
d["nprid"] = "-1";
}

for ( cKey in c ) {
    co = co+"&"+cKey+"="+escape(c[cKey]);
}
document.write(ct,cd,cu,co,"&nprid=",escape(d["nprid"]),ce);

var vo = "";

if (typeof v != "undefined") {
    for ( vKey in v ) {
        vo = vo+"&"+vKey+"="+v[vKey];
    }
}
if(window.vstag != null)
{
    for (vKey in window.vstag) {
        if(vKey != 'title' && vKey != 'dt') {
        vo = vo+"&"+vKey+"="+window.vstag[vKey];
        }
    }
}
if(window.vstag && window.vstag.title)
{
    vo = vo+"&dt="+window.vstag.title;
}
else
{
    vo = vo+"&dt="+escape(document.title);
}

for ( dKey in d ) {
    vo = vo+"&"+dKey+"="+escape(d[dKey]);
}
document.write(ct,cd,cu,vo,ce);
