// set leaving flag to true
// used by exitTraffic() function
var leaving = true;
var the_language = "en";

function getCookieData(labelName){
	var labelLen = labelName.length;
	var cookieData = document.cookie;
	var cLen = cookieData.length;
	var i = 0;
	var cEnd;
	while (i < cLen){
		var j = i + labelLen;
		if (cookieData.substring(i,j) == labelName){
			cEnd = cookieData.indexOf(";",j)
			if(cEnd == -1){
				cEnd = cookieData.length;
			}
			return unescape(cookieData.substring(j+1, cEnd));
		}
		i++;
	}
	return "";		
}

// called from window.onunload event
function exitTraffic(){
	// leaving is true when page loads
	// leaving is set to false by every link on the site and when any form is submitted
	// if leaving is still true then user is leaving the site so launch popunder
	if (leaving){
		// set redirect cookie flag so that user only gets popunder once per month
		var redirectCookie = getCookieData("redirectCookie");
		// check for existance noPopUp cookie
		// if cookie exists, then user has already downloaded
		// if cookie does not exist, prompt to launch popDownload.asp popup
		var exitCookie = getCookieData("noPopUp");
		/* This part is for download pop-up
		if(exitCookie != 'true'){
			if(confirm("Click OK to download our FREE Software while browsing the site")){
				popDownload(the_language);
			}
		}
		*/
		// if cookie not found (equal to true) then launch popover
		if(redirectCookie != 'true'){
			var expDate = new Date();
			var oneMonthFromNow = expDate.getTime() + (30 * 24 * 60 * 60 * 1000);
			expDate.setTime(oneMonthFromNow);
			document.cookie = "redirectCookie=true; expires=" + expDate.toGMTString();
			//exitWin=window.open('http://www.bingocard.com/e.asp?e=29&id=1114','','scrollbars=1,resizable=1,toolbar=1,location=1,menubar=1,status=1,directories=0,height=500,width=640');
			//exitWin=window.open('http://www.1776bingo.com/adpage2.asp?sourceid=102715','LOL_exit','scrollbars=1,resizable=1,toolbar=1,location=1,menubar=1,status=1,directories=0,height=500,width=640');
			//exitWin=window.open('http://www.bingolol.com/adpage2.asp?sourceid=103489','LOL_exit','scrollbars=1,resizable=1,toolbar=1,location=1,menubar=1,status=1,directories=0,height=500,width=640');
			//exitWin=window.open('https://www.bingocard.com/amsBGC/campaignhit.action?trackingId=111141&redirecturl=https://www.1776bingo.com/paasSSS/home.action','LOL_exit','scrollbars=1,resizable=1,toolbar=1,location=1,menubar=1,status=1,directories=0,height=500,width=640');
			//exitWin=window.open('http://bingobingobingobingo.gotop100.com/','LOL_exit','scrollbars=1,resizable=1,toolbar=1,location=1,menubar=1,status=1,directories=0,height=500,width=640');
			//exitWin.blur();  // pop "under"
			//exitWin.focus();  // pop "over"

		}
	}
}

// call exitTraffic() function when window unloads
window.onunload=exitTraffic;
