var referrerUrl = escape(document.referrer);
var pageTitle = escape(document.title);

/** Cookie functions **/
function SetCookie (name, value) {  
	var argv = SetCookie.arguments;  
	var argc = SetCookie.arguments.length;  
	var path = '/';
	var expires = (argc > 2) ? argv[2] : null;  
	var domain = (argc > 3) ? argv[4] : null;  
	var secure = (argc > 4) ? argv[5] : false;  
	document.cookie = name + "=" + escape (value) + 
		((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
		((path == null) ? "" : ("; path=" + path)) +  
		((domain == null) ? "" : ("; domain=" + domain)) +    
		((secure == true) ? "; secure" : "");
}

function getCookieVal (offset) {  
	var endstr = document.cookie.indexOf (";", offset);  
	if (endstr == -1)    
		endstr = document.cookie.length;  
		return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {  
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen) {    
		var j = i + alen;    
		if (document.cookie.substring(i, j) == arg)      
			return getCookieVal (j);    
		i = document.cookie.indexOf(" ", i) + 1;    
		if (i == 0) break;   
	}  
	return null;
}

/** Popup functions **/
var showPopup = function (popupSettings) {
	var expDays = popupSettings['cookieExpire'];
	var exp = new Date(); 
	exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
	alert("Test 01");
	if (GetCookie('pwID23619069') != 'true') {
		alert("Test 02");
		if (typeof(urchinTracker)=='function') {
			_uacct = popupSettings['gwo_uacct'];
			urchinTracker("/" + popupSettings['gwo_k'] + "/test");
		}
		dynamicIbox(popupSettings);
		SetCookie ('pwID23619069', 'true', exp);
	}
}

function timedShowPopup(popupSettings) {
	alert("Test 00");
	window.setTimeout("showPopup(popupSettings)",String(popupSettings['delay']*1000));
}

function disablePopup(expDays) {
	var exp = new Date(); 
	exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
	SetCookie ('pwID23619069', 'true', exp);
}