function GetCookie(name) {

    var start = document.cookie.indexOf(name+"=");
    var len = start+name.length+1;
    if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
    if (start == -1) return null;
    var end = document.cookie.indexOf(";",len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len,end));
    
}

function SetCookie (name, value) {

	var argv = SetCookie.arguments;  
	var argc = SetCookie.arguments.length;  
	var expires = (argc > 2) ? argv[2] : null;  
	var path = (argc > 3) ? argv[3] : null;  
	var domain = (argc > 4) ? argv[4] : null;  
	var secure = (argc > 5) ? argv[5] : false;  
	document.cookie = name + "=" + escape (value) + 
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
	((path == null) ? "" : ("; path=" + path)) +  
	((domain == null) ? "" : ("; domain=" + domain)) +    
	((secure == true) ? "; secure" : "");

}

var exp = new Date(); 
exp.setTime(exp.getTime() + 1200000);

function swarm() {

	var tsexit = GetCookie('TSEXIT');
	
	if (tsexit == null) {

		if (top.name!='TrafficSwarm') {

			SetCookie('TSEXIT', id, exp);

			var swarmurl = 'http://www.trafficswarm.com/cgi-bin/exit.cgi?' + id;
			if (typeof cat != "undefined") { swarmurl += '&' + cat; }

			exit = window.open(swarmurl,'TrafficSwarm','width=750,height=550,left=1,right=1,top=0,toolbar=yes,menubar=yes,scrollbars=yes,status=yes,resizable=yes,status=yes,location=yes');

			exit.blur();
			self.focus();

			return true;

		}	
	
	}
        
}

document.onunload=swarm;
window.onunload=swarm;

