﻿//************ Check for Odd and even VT Starts Here ***************************

var noXpop = "false";
var RegionalPop = "false";
var Cont = "Default";
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i = 0; i < vars.length; i++) {

	var pair = vars[i].split("=");
	if (pair[0] == "VP") {
		var VP = pair[1];
	}

	//Setting Variables Used in SiteRedirector
	if (pair[0] == "sourcesite" || pair[0] == "s") {
		var strSource = pair[1];
	}

	if (pair[0] == "MU") {
		var SiteRedirectorTag = pair[1]; //xp
	}

	if (pair[0] == "sourcesite" || pair[0] == "s") {
		var strSource = pair[1];
	}

	if (pair[0] == "trd") {
		var SiteRedirectorTag1 = pair[1]; //
	}
	if (pair[0] == "cuba") {
		var cuba = pair[1]; //
	}

	//Exclusion from Existing Exit
	if (pair[0] == "sourcesite" || pair[0] == "s") {
		var strSource = pair[1];
	}
	if (pair[0] == "mode") {
		var modeTag = pair[1]; //1
	}
}

//************ Check for Odd and even VT Ends Here ***************************
//------------------------Cookie State Management Starts Here---------------------------------------------

var expDays = 365 * 3; // number of days the cookie should last

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;
}

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" : "");
}

function DeleteCookie(name) {
	var exp = new Date();
	exp.setTime(exp.getTime() - 1);
	var cval = GetCookie(name);
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

var exp = new Date();
exp.setTime(exp.getTime() + (expDays * 24 * 60 * 60 * 1000));

function amt() {
	var count = GetCookie('mycount')
	if (count == null) {
		SetCookie('mycount', '1')
		return 1
	}
	else {
		var newcount = parseInt(count) + 1;
		DeleteCookie('mycount')
		SetCookie('mycount', newcount, exp)
		return count
	}
}

function getCookieVal(offset) {
	var endstr = document.cookie.indexOf(";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

//------------------------Cookie State Management Ends Here---------------------------------------------
//************* SourceSites Checks Starts Here *******************************

function BotsExclusion() {
	var noPop_array = new Array(6);
	noPop_array[0] = "AFF81035"
	noPop_array[1] = "AFF57222"
	noPop_array[2] = "AFF25486"
	noPop_array[3] = "AFF16205"
	noPop_array[4] = "AFF75501"
	noPop_array[5] = "AFF72573"

	var x = 0;

	if (strSource != null) {
		for (x = 0; x < 6; x++) {
			if (strSource.toUpperCase() == noPop_array[x]) {
				noXpop = "true";
			}
		}
	}
}

//************* SourceSites Checks Ends Here *******************************
//------------ Site redirector exlcusions Starts Here ----------------------

function SiteRedirectorExclusion() {

	if (SiteRedirectorTag != null) {
		if (SiteRedirectorTag.toUpperCase() == "XP") {
			noXpop = "true";
		}
	}
}

//------------ Site redirector exlcusions Ends Here ------------------------
/*---------------------------------------------------------------------------
!!!!!! Collection of geopraphical location info Starts Here !!!!!!!!!!!!!!!!*/

function GetCountry() {
	if (document.cookie.length > 0) {
		var AllCookies = document.cookie;
		var IndividualCookie = AllCookies.split(";");

		if (AllCookies.indexOf("&cont=") != -1)
			var AllCookiesIndex = AllCookies.indexOf("cont=")
		var AllCookiesLastIndex = AllCookies.lastIndexOf("&start")
		var FullCont = AllCookies.substring(AllCookiesIndex, AllCookiesLastIndex)
		Cont = FullCont.replace("cont=", "")
	}
}

/*!!!! Collection of geopraphical location info Ends Here !!!!!!!!!!!!!!!!
-----------------------------------------------------------------------------*/

function RegionalExitExecution() {
	GetCountry();
	var ContValue = Cont.toLowerCase();
	var result = null;
}

window.onunload = function() {
	var mydomain = getDomain(window.location.href);
	var elem = document.activeElement;

	if (elem) {
		if (elem.tagName == 'A') {
			if (elem.href && elem.href.indexOf("javascript:")==-1) {
				
				var yourdomain = getDomain(elem.href);

				if (yourdomain != mydomain)
					getExitTraffic();
			}
		}
	}
	else {
		getExitTraffic();
	}
}

//Sart of the main function

function getExitTraffic() {
	BotsExclusion();
	SiteRedirectorExclusion();


	var popup = GetCookie('popup');
	if (!popup) {
	    SetCookie("popup", "1", exp);
	    var exitWindow = window.open('exit-strategy/exit-strategy.aspx', 'exit', 'width=500,height=430');
	} 
	
//	if (!(Affiliatecheck == 0)) {
//		if (noXpop == "false") {
//			var ct = GetCookie('ct');
//			if (!ct) {
//				ct = 1;
//				document.cookie = 'ct=' + escape(ct) + ';expires=Sun, 7 Mar 2010 23:59:59 GMT;'; // my birthday ;-) lol
//				var exitWindow = window.open('http://localhost:10907/exit-strategy/index.aspx' + VT + '&mode=o&cc=LNC', 'exit', 'width=550,height=300');
//			}
//			else
//				var answer = confirm("Start playing Casino games now! \n No download required.")
//			if (answer) {
//				//window.navigate("/download_helper/download.asp?VT=<%=VT%>&EventID=24824");
//				var exitWindow = window.open('http://www.luckynugget.co.uk/tracking.asp?Link=MICROGAMING&EventId=30290');
//			}
//			RegionalExitExecution();
//		}
//	}
}

/************** Execution of the exit strategy Starts here *****************************************************************
----------------------------------------------------------------------------------------------------------------------------*/
function getDomain(url) {
	var domain = url.match(/:\/\/(www\.)?([^\/:]+)/);
	if (domain) {
		return domain[2];
	}
	else {
		return '';
	}
}

function showhide(divid, state){
document.getElementById(divid).style.display=state}