function getParamFromUrl(name) {
	var re = new RegExp("(?:\\?|\\&)"+name+"=([^\\&]*)");
	var match = document.location.search.match(re);
	return (match != null) ? match[1] : "";
}

var Flag = {
	init:function() {
		Flag.raw = getParamFromUrl("f");
		Flag.values = Flag.raw.split("");
	},
	dict:["nxs", "popunder", "vsp", "downloadpixel"],
	get:function(name) {
		for (var i=0,ii=Flag.dict.length;i<ii;i++) {
			if (Flag.dict[i] == name) {
				return (Flag.values[i] && Flag.values[i] == "1") ? true : false;
			}
		}
		return null;
	}
}
Flag.init();

function _addjs(u) {
    if (navigator.appName.indexOf("Microsoft") == 0 && d) document.write("<scr" + "ipt defer='defer' async='true' src='" + u + "'></scr" + "ipt>");
    else {
	var s = document.createElement('script');
	s.type = 'text/javascript';
	s.async = true;
	s.src = u;
	(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(s);
    }
}

function _issem() {
	var __issem = false;
	var sid = emerpcomp.GetSerialID();
	var isnewsid = (sid != null && sid != "" && sid != knownsid);
	var issem = getReferrer();
	if ( issem && isnewsid ) {
		__issem = true;
	}
	return __issem;
}

function _isseo() {
	var __isseo = false;
	var sid = emerpcomp.GetSerialID();
	var isnewsid = (sid != null && sid != "" && sid != knownsid);
	var isseo = getReferrer();
	if ( isseo && !isnewsid ) {
		__isseo = true;
	}
	return __isseo;
}

var bannerserverlink = (typeof(CONSTANTS.bannerserver) != "undefined" && CONSTANTS.bannerserver != "") ? CONSTANTS.bannerserver : "http://banner2.casino.com";

function gotourl(url) {
	isLink = true;
	document.location.href = url;
}
function $(name) { return document.getElementById(name); };
if (window.addEventListener) {
	window.addEventListener("load", updateDateSpan, false);
} else {
	window.attachEvent("onload", updateDateSpan);	
}
var agt = navigator.userAgent.toLowerCase();
function changelanguage(lang) {
	savecookie('language', lang, 1000);
}
function addLeadingZero(value) {
    if (value < 10) {
        return '0' + value;
    } else {
        return value;
    }
}
function getAMPM(value) {
    return (value >= 12) ? "PM" : "AM";
}
function cutHoursToAMPM(value) {
    return (value == 12 || value == 0) ? 12 : value % 12;
}
function updateDateSpan() {
	var dateSpan = $('dateContainer');
    var menu_style = (typeof(date_menu_style) != "undefined") ? date_menu_style : 0;
	if (dateSpan) {
        var date = new Date();
        if (menu_style==1) {
			dateSpan.innerHTML = 
				addLeadingZero(date.getUTCDate()) + ". " +
				Months[date.getUTCMonth()] + ". " +
				addLeadingZero(date.getUTCFullYear());		
		}
		else {
			dateSpan.innerHTML = Days[date.getUTCDay()] + ", " +
				 Months[date.getUTCMonth()] + " " +
				 addLeadingZero(date.getUTCDate()) + ", " +
				 addLeadingZero(date.getUTCFullYear()) + " - " +
				 cutHoursToAMPM(date.getUTCHours()) + ":" +
				 addLeadingZero(date.getUTCMinutes()) + " " + getAMPM(date.getUTCHours()) + " GMT";
		}
    }
	if ($("navigation")) tabdropdown.init("navigation", -1);
    setTimeout("updateDateSpan();", 10000);
}
function handleStartedSteps(step) {
	if ($('startedStep'+step).style.display == 'none') {
		$('startedStepImage'+step).src = 'http://cache.casino.com/images/sarrowdown.gif';
		$('startedStep'+step).style.display = '';
	} else {
		$('startedStepImage'+step).src = 'http://cache.casino.com/images/sarrowright.gif';
		$('startedStep'+step).style.display = 'none';
	}
}

function redirecttodownload() {
	document.location.href = CONSTANTS.download_link;
}
var emerpcomp = null;
var counter = 0;
var userGuid = "";
document.EMERPCallbacks = [];
function EMERPCallback(comp, eventName) {
	emerpcomp = comp;
	if (Flag.get("downloadpixel")) {
		redirectafterdownload = false;
		comp.CONSTANTS.SupportedPTEvents.clientdownload = redirecttodownload;;
		comp.CONSTANTS.SupportedPTEvents.flashdownload = true;
	}
	userGuid = comp.GetUserID();
	document.shouldsendhphit = doubletracking();
	if (document.location.search.match(/[&\?]p=1/)) {
		document.shouldsendhphit = false;
		document.sshhwd = true;
	} else {
		document.sshhwd = false;
	}
	if (typeof(document.EMERPAdditionalCallback) != "undefined") document.EMERPAdditionalCallback(comp, eventName);
	else if (eventName == "DummyEvent") {
		if (typeof(document.shouldsendhphit) != "undfined" && document.shouldsendhphit) emerpcomp.SendEvent("", "?hphit", "cp");
	}
    	if (typeof(document.EMERPCallbacks) != "undefined" && typeof(document.EMERPCallbacks.length) != "undefined") {
        	for (var i=0,ii=document.EMERPCallbacks.length;i<ii;i++) {
            		document.EMERPCallbacks[i](comp, eventName);
        	}
    	}
	if (typeof(document.EMERPToUrchin) != "undefined") document.EMERPToUrchin(comp, eventName);
}

function in_array(needle, haystack){
	var len = haystack.length;
	for (var i = 0; i < len; i++)
		if(haystack[i] == needle)
			return true;
	return false;
}
function getDownloadLink() {
    var userGuid = (emerpcomp != null) ? emerpcomp.GetUserID() : "";
	var pixel = (emerpcomp != null) ? emerpcomp.GetPixelID() : "";
	var dp = (emerpcomp != null) ? emerpcomp.GetDPID() : "";
	var lang = getCurrentLanguageParameter("");
	var siteURL = document.location.href.substring(22,24);
	var siteParamURL = document.location.href.substring(22,23);
	var uniqueLang = '/au/nz/uk/za/';
	var uniqueGeoLang = '/se@sv/gb@uk/';
	var geoLang = readcookie('lo');
	var geoLangNew = uniqueGeoLang.indexOf(geoLang);
	var geoLang = geoLangNew!=-1 ? uniqueGeoLang.substring(geoLangNew+3,geoLangNew+5) : readcookie('lo');
	/* Removed by Itzik @ 2012/01/19 according OPT-92
	if (siteParamURL != '?') {
	lang = (uniqueLang.search(siteURL) != -1 ? "en" : lang);
	if (siteURL != geoLang) { lang = ""; }
	}
	*/
	if (siteURL == 'au' || siteURL == 'ie' || siteURL == 'uk' || siteURL == 'nz') {
	    lang = 'en';
	} else if (lang == 'en') {
	    lang = '';
	} else if (lang == 'dk') {
	    lang = 'da';
	} else {
	    lang = lang;
	};
	var banner_click = readcookie('banner_click');
    var creferer = '';
    if ( banner_click !== null && banner_click.toString() !== "null" ) {
    	banner_click = banner_click.split(',');
	    if ( banner_click[4].length >0 && banner_click[4] !== '*' ) {
	    	creferer = banner_click[4];
	    }
    }
	var cref = new cRefererObj(creferer);
	cref.add('UserGUID', userGuid);
	cref.add('pixelid', pixel);
	cref.add('DP', dp);
	var downloadUrl = bannerserverlink + "/cgi-bin/SetupCasino.exe?opt_lang=" + lang + "&creferer=" + cref.toString();

	return downloadUrl;
}
function findlanguage() {
	var language = "en";
	var m = null;
	if (document.location.href.match(/www\.casino\.com/)) m = document.location.href.match(/http:\/\/www.casino.com\/([a-z]{2})\/.*/);
	else m = document.location.href.match(/http:\/\/([^\.]*)\.casino\.com/);
	if (m != null) language = m[1];
	return language;
}

var __pb = __pb || [];
function getpropertybag() {
	var rs = [];
	if (readcookie("b") !== null && readcookie("b").toString() !== "null") rs.push("proposition:"+readcookie("b"));
	if (currentsrc != "") rs.push("DL:"+currentsrc);
	for (var i=0;i<__pb.length;i++) rs.push(__pb[i]);
	return rs.join(";");
}

function trackdownload(flash) {
	_extgaq.push(['_trackEvent', 'Download', flash ? 'flash' : 'exe', currentsrc]);
	_extgaq.push(['_trackPageview', '/'+(flash ? 'flash' : 'client')+'download.html']);

        if (typeof(_vis_opt_top_initialize) == "function") {
                var m = document.cookie.match(/_vis_opt_exp_([\d]+)_combi/g);
                if (m != null) {
                        for (var i=0;i<m.length;i++) {
                                var expid = m[i].replace(/_vis_opt_exp_([\d]+)_combi/, "$1");
                                _vis_opt_register_conversion(1, expid);
                        }
                }
        }

	if (readcookie('guid') == null || readcookie('guid').toString() == "null") {
		savecookie('sstc', '1', 1);
		stc();
	} else deletecookie('sstc');

	var script = document.createElement("script");
	script.src = "http://stat.casino.com/stats/track.php?r="+escape(document.referrer)+((flash) ? "&__f=true" : "")+"&__d=true&__b=cc&pb="+getpropertybag();
	document.body.appendChild(script);
}

var sstci;
function stc() {
	if ( readcookie('guid') !== null && readcookie('guid').toString() !== "null") {
		if (readcookie('sstc') == '1') {
			markuser('stc:1');
			deletecookie("sstc");
		}
		window.clearInterval(sstci);
	} else {
		window.setTimeout(stc, 1000);
	}
}
stc();

function doDownload(usepopup) {
	trackdownload();
	var w = null;
	if (usepopup) document.downloadmethod = "popup"; 
	if (document.location.href.match(/\/download\//i) || !navigator.userAgent.match(/(firefox|msie)/i)) document.downloadmethod = "iframe";

   	if (typeof(document.downloadmethod) != "undefined" && document.downloadmethod == "popup") {
		try {
			w = window.open(getDownloadLink(), "popDown", "width=1,height=1,top=0,left=0");
		} catch (e) {
			w = null;
		}
	
		if (w != null) {
			if (!redirectafterdownload || document.location.href.match(/\/download\//i)) return;
			document.location.href = CONSTANTS.download_link;
		}
	}
	if (w == null || typeof(document.downloadmethod) == "undefined" || document.downloadmethod == "iframe") {
		var downloadframe = document.getElementById("download_iframe");
		if (downloadframe == null) {
			downloadframe = document.createElement("iframe");
			downloadframe.width = "1px";
			downloadframe.height = "1px";
			downloadframe.position = "absolute";
			downloadframe.frameBorder = 0;
			downloadframe.left = "-100px";
			document.body.appendChild(downloadframe);
		}
		downloadframe.src = getDownloadLink();
		if (!redirectafterdownload || document.location.href.match(/\/download\//i)) return;
		window.setTimeout(function() { document.location.href = CONSTANTS.download_link; }, 4000); 
	}
}

var senddownload = false;
var downloadattempts = 0;
var redirectafterdownload = true;
var currentsrc = "";

function launchPlaytech(src) {
	savecookie('hideTheXsellPopup', true, 1);
	var source = document.location.href.replace(/^.*\//, "");
	if (typeof(src) != "undefined") source += ((source != "") ? ":" : "")+src;

	currentsrc = src;

	var clienttype = "cf";
	downloadattempts = 0;
	if (typeof(trackdownload) != "undefined") trackdownload(true);
	startActualDownload(clienttype, false);
}

function getCurrentLanguageParameter(prefix) {
	if (CONSTANTS.language == "") {
		var a = document.location.href.match(/casino.com\/([a-z]{2})\//); return (a != null && a.length > 1) ?prefix+a[1]:"";
	} else {
		return (CONSTANTS.language != "") ? prefix+CONSTANTS.language : "";
	}
}

function getCurrentLanguageParameterFromURI(prefix) {
    var a = document.location.href.match(/casino.com\/([a-z]{2})\//);
    return (a != null && a.length > 1) ? prefix + a[1] : "";
}

function startDownload(src, avoidredirection, usepopup, popupId) {
	if (avoidredirection) redirectafterdownload = false;
	var source = document.location.href.replace(/^.*\//, "");
	if (typeof(src) != "undefined") source += ((source != "") ? ":" : "")+src;

	currentsrc = src;

	isLink = true;
	var clienttype = "cd";
	try {
		if (!navigator.userAgent.match(/Windows/)) {
			clienttype = "cf";
		}
	} catch(e) {
	}

	downloadattempts = 0;
	if (typeof(setDLPopUp)!="undefined") {
		var popupId=setDLPopUp;
		redirectafterdownload = false;
	}
	if ( (typeof(popupId)!="undefined") && (popupId!=null) && (popupId) ) {
		var popupElement = document.getElementById(popupId);
		popupElement.style.display = '';
		window.setTimeout(function() {popupElement.style.display = 'none';}, 10000);
		startActualDownload(clienttype,usepopup,popupElement);
	}
	else {startActualDownload(clienttype, usepopup);}
	
}

function startActualDownload(clienttype, usepopup, popupElement) {
    if (emerpcomp == null || !cookiesreloaded) {
    	if ( emerpcomp !== null ) { 
    		reloadcookies( emerpcomp )
    	} else {
			downloadattempts += 1;
			if (downloadattempts < 8) {
				window.setTimeout(function() { startActualDownload(clienttype); }, 1000);
				return;
			}
    	}
	}
	
    if (emerpcomp != null) {
    	if (document.sshhwd) emerpcomp.SendEvents([["", "hphit", "cp"],["", "download", clienttype]], "download");
    		else emerpcomp.SendEvent("", "download", clienttype);
    } else senddownload = true;

    if (clienttype == "cd"){
		savecookie('hideTheXsellPopup', true, 1);
		doDownload(usepopup, popupElement);
	} else {
		if (typeof(trackdownload) != "undefined") trackdownload(true);
		var ref_info_cookie = readcookie('banner_click');
		var get_ref_info = "?";
		var userGuid = (emerpcomp != null) ? emerpcomp.GetUserID() : "";
	    var pixel = (emerpcomp != null) ? emerpcomp.GetPixelID() : "";
	    var dp = (emerpcomp != null) ? emerpcomp.GetDPID() : "";
	    var creferer = '';
	    
		if (ref_info_cookie!=null) {
			var ref_info = ref_info_cookie.split(",");
			creferer = ( ref_info[4] == '*' || ref_info[4] == '') ? '': ref_info[4];
			get_ref_info = "?advertisercode="+ref_info[0]+"&banner="+ref_info[1]+"&profile="+ref_info[2]+"&creferer=";
		} else {
		    get_ref_info = "?creferer=";
		}
		var cref = new cRefererObj(creferer);
		cref.add('UserGUID', userGuid);
		cref.add('pixelid', pixel);
		cref.add('DP', dp);
		window.open("http://cachebanner2.casino.com/flash/27/casino_casino.com/launchcasino.html"+get_ref_info+cref.toString()+"&"+getCurrentLanguageParameter("language="), "newwindow", "width=800, height=600");
	}
}

function startDownloadWORedirection(src) {
	startDownload(src, true);

}

function openForgot() {
	$('forgotPassword').style.display = '';
}
function closeForgot() {
	$('forgotPassword').style.display = 'none';
}
function findPosition(obj) {
	var pos = {x:0, y:0}
	try { while (obj.nodeName.toLowerCase() != "body") {
			pos.x += parseInt(obj.offsetLeft, 10);
			pos.y += parseInt(obj.offsetTop, 10);
			obj = obj.offsetParent;
		}} catch (e) {	}
	return pos;
}
function findPosX(obj) {
	var curleft = 0;
	if(obj.offsetParent)
		while(1) {
			curleft += obj.offsetLeft;
			if(!obj.offsetParent)
				break;
			obj = obj.offsetParent;
		}
	else if(obj.x)
		curleft += obj.x;
	return curleft;
}
function findPosY(obj) {
	var curtop = 0;
	if(obj.offsetParent)
		while(1) {
			curtop += obj.offsetTop;
			if(!obj.offsetParent)
				break;
			obj = obj.offsetParent;
		}
	else if(obj.y)
		curtop += obj.y;
	return curtop;
}
function openLanguages() {
	if ($('languages').style.display == 'none') {
		$('languages').style.display = '';
		$('langArrow').style.display = 'none';
		$('langArrowDown').style.display = '';
	} else {
		$('languages').style.display = 'none';
		$('langArrow').style.display = '';
		$('langArrowDown').style.display = 'none';
	}	
}
var traceoutput = "";
function trace(value) {
	traceoutput += value+"_";
}
function syncAffiliate(source, destinations) {
	var value = readcookie(source);
	for (var i=0;i<destinations.length;i++) {
		savecookie(destinations[i], value);
	}
}
function setAffiliate(name, profile) {
	profile = profile ? profile : "default";
	var domain = "."+(document.domain.match(/\./ig).length > 1) ? document.domain.replace(/[^\.]*\./, "") : document.domain;
	
	var date = new Date();
	date.setTime(date.getTime()+(3*24*60*60*1000));
	var expires = "; expires="+date.toGMTString();
	document.cookie = "banner_domainclick="+name+",,"+profile+",*,*"+expires+"; path=/"+((domain != "") ? ";domain="+domain : "");
	document.cookie = "banner_click="+name+",,"+profile+",*,*"+expires+"; path=/"+((domain != "") ? ";domain="+domain : "");
	document.cookie = "banner_download="+name+",,"+profile+",*,*"+expires+"; path=/"+((domain != "") ? ";domain="+domain : "");
}
function getaffiliate() {
	var match = (document.cookie.match(/banner_domainclick/)) ? document.cookie.match(/banner_domainclick=([\d\D]+)/i) : null;
	if (match != null && match[1].replace(/,.*/, "") != "default02") return match[1].replace(/,.*/, "");
	else return "";
}
function getdownloadaffiliate() {
	var match = (document.cookie.match(/banner_download/)) ? document.cookie.match(/banner_download=([\d\D]+)/i) : null;
	if (match != null && match[1].replace(/,.*/, "") != "default02") return match[1].replace(/,.*/, "");
	else {
		var tracker = getParamFromUrl("tracker");
		return (tracker != "default02") ? tracker : "";
	}
}
var __segment = "";
var synced = false;
var cookiesreloaded = false;

function doubletracking() {
	if (synced) return false;
	var shouldsendhphit = true;
	synced = true;
	var knownaffiliate = emerpcomp.GetProperty("aff");
	trace("k1"+knownaffiliate);
	var knownsid = emerpcomp.GetProperty("sid");
	trace("k2"+knownsid);
	
	var affiliate = getaffiliate();
	var downloadaffiliate = getdownloadaffiliate();
	trace("a1"+affiliate);
	trace("da"+downloadaffiliate);
	var sid = emerpcomp.GetSerialID();
	trace("s"+sid);
	var isnewaffiliate = (affiliate != "" && affiliate != knownaffiliate && !affiliate.match(/(Convertonet|convertonetC|ConvertonetC)/i));
	if (downloadaffiliate != "" && !downloadaffiliate.match(/(Convertonet|convertonetC|ConvertonetC)/i) && affiliate != downloadaffiliate && !isnewaffiliate) {
		isnewaffiliate = true;
		affiliate = downloadaffiliate;
		syncAffiliate("banner_download", new Array("banner_domainclick", "banner_click"));
	}
	
	var isnewsid = (sid != null && sid != "" && sid != knownsid);
	var isseo = getReferrer();
	var sidinurl =  document.location.search.match(/[\?\&]SID=[0-9]+/);
	trace("ia"+isnewaffiliate);
	trace("ic"+isnewsid);
	trace("is"+isseo);
	if (!isseo && affiliate == "" && sid == "") {
		trace("tu");
		emerpcomp.DeleteProperty("aff");
		emerpcomp.DeleteProperty("sid");
		emerpcomp.DeleteProperty("seo");
		__segment='Unknown';
		cookiesreloaded = true;
	} else if (!isnewaffiliate && !isnewsid && !sidinurl && ( !isseo || ( isseo && affiliate !== "" ) )) {
        trace("ka");
        emerpcomp.SetProperty("aff", affiliate);
        emerpcomp.SetProperty("seo", ( isseo ? 1 : 0 ));
        emerpcomp.SetProperty("sid", sid );
        emerpcomp.SetSerialID( sid );
        if ( typeof (document.shouldsendhphit) == "undefined" || (typeof (document.shouldsendhphit) != "undefined" && document.shouldsendhphit)) emerpcomp.SendEvent("", "?hphit", "cp");
        syncAffiliate("banner_domainclick", new Array("banner_click", "banner_download"));
        shouldsendhphit = false;
	} else if (isnewaffiliate && !sidinurl) {
		trace("na");
		emerpcomp.SetProperty("aff", affiliate);
		emerpcomp.SetProperty("seo", 0);
		setAFFILIATE(affiliate);
		syncAffiliate("banner_domainclick", new Array("banner_click", "banner_download"));
		shouldsendhphit = false;
	} else if (isseo && !isnewsid) {
		trace("sc");
		emerpcomp.SetProperty("aff", "ConvertonetC");
		emerpcomp.SetProperty("seo", 1);
		setAffiliate("ConvertonetC", "seo");
		setSEO(isseo);
		__segment='SEO';
		shouldsendhphit = false;
	} else if (isseo && isnewsid) {
		trace("smc");
		emerpcomp.SetProperty("aff", "ConvertonetC");
		emerpcomp.SetProperty("sid", sid);
		emerpcomp.SetProperty("seo", 0);
		setAffiliate("ConvertonetC", "sem");
		__segment='SEM';
		shouldsendhphit = false;
		cookiesreloaded = true;
	} else if (isnewsid && isnewaffiliate) {
		trace("ns");
		emerpcomp.SetProperty("aff", "ConvertonetC");
		emerpcomp.SetProperty("sid", sid);
		emerpcomp.SetProperty("seo", 0);
		setAffiliate("ConvertonetC", "media");
		__segment='Media/'+sid;
		cookiesreloaded = true;
	} else if (readcookie("__utmv") == null || readcookie("__utmv").toString() == "null") {
		var _aff = emerpcomp.GetProperty("aff");
		var _sid = emerpcomp.GetProperty("sid");
		var _seo = emerpcomp.GetProperty("seo");
		if (_aff != "" && !_aff.match(/(Convertonet|convertonetC|ConvertonetC)/i)) __segment='Affiliate/'+_aff;
		else if (_seo == "1") __segment='SEO';
		else if (_sid != "") __segment='Media/'+sid;
		else __segment='Unknown';
		cookiesreloaded = true;
	} else {
		cookiesreloaded = true;
	}

	return shouldsendhphit;
}
function getReferrer() {
	return extractSearch(document.referrer);
	function extractSearch(url) {
		if (!url) return;
		var sites = [
			/^http:\/\/[^\/]*?\b(google)(?:\.[^\.]+)*\/.+?[\?&]q=([^&#]*)/i,
			/^http:\/\/[^\/]*?\b(google\.com)\/.+?[\?&]q=([^&#]*)/i,
			/^http:\/\/[^\/]*?\b(google\.ca)\/.+?[\?&]q=([^&#]*)/i,
			/^http:\/\/[^\/]*?\b(google\.co\.uk)\/.+?[\?&]q=([^&#]*)/i,
			/^https:\/\/[^\/]*?\b(encrypted\.google\.com)\/.+?[\?&]q=([^&#]*)/i,
			/^http:\/\/[^\/]*?\b(yahoo)\.co(?:m|\.[^\.]+)\/.+?[\?&]p=([^&#]*)/i,
			/^http:\/\/search\.(yahoo\.com)\/.+?[\?&]p=([^&#]*)/i,
			/^http:\/\/(uk\.search\.yahoo\.com)\/.+?[\?&]p=([^&#]*)/i,
			/^http:\/\/(ca\.search\.yahoo\.com)\/.+?[\?&]p=([^&#]*)/i,
			/^http:\/\/[^\/]*?\b(bing\.com)\/.+?[\?&]q=([^&#]*)/i,
			/^http:\/\/[^\/]*?\b(yandex)\.[^\/]*\/.+?[\?&]text=([^&#]*)/i,
			/^http:\/\/[^\/]*?\b(baidu)\.[^\/]*\/.+?[\?&]wd=([^&#]*)/i,
			/^http:\/\/[^\/]*?\bsearch\.(aol)\.[^\/]*\/.+?[\?&]q=([^&#]*)/i,
			/^http:\/\/[^\/]*?\b(ask)\.[^\/]*\/.+?[\?&]q=([^&#]*)/i,
			/^http:\/\/[^\/]*?\b(search\.com)\/.+?[\?&]q=([^&#]*)/i,
			/^http:\/\/[^\/]*?\b(ricerca\.virgilio\.it)\/.+?[\?&]qs=([^&#]*)/i,
			/^http:\/\/[^\/]*?\b(rambler\.ru)\/.+?[\?&]query=([^&#]*)/i,
			/^http:\/\/[^\/]*?\b(onetonline\.org)\/.+?[\?&]s=([^&#]*)/i,
			/^http:\/\/[^\/]*?\b(onetcenter\.org)\/.+?[\?&]s=([^&#]*)/i,
			/^http:\/\/[^\/]*?\b(search\.seznam\.cz)\/.+?[\?&]q=([^&#]*)/i,
			/^http:\/\/[^\/]*?\b(excite\.com)\/.+?[\?&]Web\/([^\/&#]*)/i,
			/^http:\/\/[^\/]*?\b(live\.com)\/.+?[\?&]st=([^&#]*)/i,
			/^http:\/\/[^\/]*?\b(search\.lycos\.com)\/.+?[\?&]query=([^&#]*)/i,
			/^http:\/\/[^\/]*?\b(blog\.conduit\.com)\/.+?[\?&]s=([^&#]*)/i,
			/^http:\/\/[^\/]*?\b(conduit\.com)\/.+?[\?&]q=([^&#]*)/i,
		""];
		for (var m, i = sites.length-2; i >= 0; --i)  {
			if (m = sites[i].exec(url)) {
				return {site:m[1], keyword:decodeURIComponent(m[2])};
			}
		}
	}
}

function reloadcookies(comp) {
	emerpcomp.SetProperty("aff", comp.GetProperty("aff"));
	emerpcomp.SetProperty("sid", comp.GetProperty("sid"));
	emerpcomp.SetProperty("seo", comp.GetProperty("seo"));
	emerpcomp.SetSerialID(comp.GetSerialID());
        cookiesreloaded = true;
}
var iframese = null;
function setAFFILIATE(name) {
	iframese = document.createElement("iframe");
	iframese.width = 1;
	iframese.height = 1;
	iframese.frameBorder = 0;
	iframese.src = "/core/EMERPECp/aff.php?callback=reloadcookies&name="+name+"&r="+Math.random()*100000;
	callse();
}
function setSEO(q) {
	iframese = document.createElement("iframe");
	iframese.width = 1;
	iframese.height = 1;
	iframese.frameBorder = 0;
	iframese.src = "/core/EMERPECp/se.php?callback=reloadcookies&keyword="+q.keyword+"&site="+q.site+"&r="+Math.random()*100000;
	callse();
}
function callse() {
	if (document.getElementById("emerpec") == null) {
		window.setTimeout(callse, 100);
		return;
	} else {
		document.getElementById("emerpec").parentNode.appendChild(iframese);
	}
}

function savecookie(name, value, days) {
	var date = new Date();
	date.setTime(date.getTime()+( ((typeof(days) != "undefined") ? days : 3)*24*60*60*1000));
	var expires = "; expires="+date.toGMTString();
	document.cookie = name+"="+value+expires+"; path=/;domain=.casino.com";
}

function readcookie(name) {
	var re=new RegExp("(?:^| )"+name+"=([^;]*)","i");
	var matches = document.cookie.match(re);
	return(matches && matches.length==2) ? matches[1] : null;
}
function delCookie(name) {
document.cookie = name +'=; expires=Thu, 01-Jan-70 00:00:01 GMT;';
} 

function deletecookie(name) { 
	deleteCookie(name);
}
function deleteCookie(name) {
	savecookie(name, "", -1);
}

function reportserver(event, section) {
	return false;
}

var lastName = -1;
function gotoInfo(name) {
	if (lastName != -1 && name != lastName) {
		$(lastName).style.display = 'none';

		$(lastName+'Row').className = 'doTableRow';
		$(lastName+'Sep').className = 'doTableSep';
		$(lastName+'D').className = $(lastName+'D').className.replace('Open', '');
		$(lastName+'W').className = $(lastName+'W').className.replace('Open', '');

		$(lastName+'Frame').src = '';
	}

	if ($(name).style.display == 'none') {
		$(name).style.display = '';

		$(name+'Row').className = 'doTableRowOpen';
		$(name+'Sep').className = 'doTableSepOpen';
		$(name+'D').className = $(name+'D').className+'Open';
		$(name+'W').className = $(name+'W').className+'Open';

		$(name+'Frame').src = name+'/index.html?showlink=yes';
		document.location.href = '#link_'+name;
	} else {
		$(name).style.display = 'none';

		$(name+'Row').className = 'doTableRow';
		$(name+'Sep').className = 'doTableSep';
		$(name+'D').className = $(name+'D').className.replace('Open', '');
		$(name+'W').className = $(name+'W').className.replace('Open', '');

		$(name+'Frame').src = '';
	}
	lastName = name;
}

// Cross-sales Prompt
var isLink = false;

function on_unload() {
	if (document.location.search.match(/(client|nxs)=true/) || Flag.get('nxs')) document.cookie = "ptclient=true; path=/;domain=.casino.com";
	if (typeof(CONSTANTS.xsell_disabled) != "undefined" && CONSTANTS.xsell_disabled == "true") return false;
	if (isLink || readcookie("ptclient") == "true" || readcookie("x") == "true") {
		return false;
	} else {
                var under = Math.round(Math.random());
                var o = window.open(CONSTANTS.xsell_link+under, "_new", "width=1024, height=707");
                if (o != null) {
                        if (under == 0) {
                                o.blur();
                                window.focus();
                        }
                        document.cookie = "x=true; path=/;domain:.casino.com";
                }
		return true;
	}
}

function handleLinks(e) {
	if (window.event) {
		var srcEl = window.event.srcElement;
	} else {
		var srcEl = e.target;
	}

	var samePage = false;
	if (srcEl.href) {
		if (srcEl.href.toString().indexOf("#") != -1) {
			var path = srcEl.href.toString().substring(0, srcEl.href.toString().indexOf("#"));
			var name = srcEl.href.toString().substring(srcEl.href.toString().indexOf("#"));

			var urlpath = location.href.toString().substring(0, srcEl.href.toString().indexOf("#"));

			if (urlpath == path) {
				samePage = true;
			}
		}
	}

	var onclickLocation = false;
	if (!(null == srcEl.getAttribute('onclick'))) {
		if (srcEl.getAttribute('onclick').toString().indexOf("location") != -1) {
			onclickLocation = true;
		}
	}

	if (srcEl.tagName == 'A' || onclickLocation) {
		var parent = srcEl;
	} else {
		var parent = getParent(srcEl);
	}

	var hrefLink = false;
	if (!(null == parent.getAttribute('href')) && parent.getAttribute('href') != "") {
		if (parent.getAttribute('href').toString().indexOf("javascript") == -1) {
			hrefLink = true;
		}
	}

	var onclickLocationParent = false;
	if (!(null == parent.getAttribute('onclick'))) {
		if (parent.getAttribute('onclick').toString().indexOf("location") != -1) {
			onclickLocationParent = true;
		}
	}

	if ((parent.tagName == "A" && hrefLink && !samePage) || onclickLocationParent) {
		isLink = true;
	}
}

function getParent(obj){
	var p = obj;

	try {
		while (true) {
			if (p.tagName.toLowerCase() == "a" || p.getAttribute("onclick") != null) break;
			p = p.parentNode;
		}
		return p;
	} catch (e) {
		alert(e.description);
	}
}

//Drop Down Tabs Menu- Author: Dynamic Drive (http://www.dynamicdrive.com)
//Created: May 16th, 07'

	var tabdropdown={
		disappeardelay: 200, //set delay in miliseconds before menu disappears onmouseout
		disablemenuclick: false, //when user clicks on a menu item with a drop down menu, disable menu item's link?
		enableiframeshim: 1, //1 or 0, for true or false

		dropmenuobj: null, ie: document.all, firefox: document.getElementById&&!document.all, previousmenuitem:null,
		currentpageurl: window.location.href.replace("http://"+window.location.hostname, "").replace(/^\//, ""), //get current page url (minus hostname, ie: http://www.dynamicdrive.com/)

		getposOffset:function(what, offsettype){
			var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
			var parentEl=what.offsetParent;
				while (parentEl!=null){
					totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
					parentEl=parentEl.offsetParent;
				}
			return totaloffset;
		},

		showhide:function(obj, e, obj2){ //obj refers to drop down menu, obj2 refers to tab menu item mouse is currently over
			if (this.ie || this.firefox)
				this.dropmenuobj.style.left=this.dropmenuobj.style.top="-500px"
			if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover"){
				if (obj2.parentNode.className.indexOf("default")==-1) //if tab isn't a default selected one
					if (!obj2.className.match(/[ ]?ddopen/)) obj2.className+=" ddopen";
				obj.visibility="visible"
				}
			else if (e.type=="click")
				obj.visibility="hidden"
		},

		iecompattest:function(){
			return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
		},

		clearbrowseredge:function(obj, whichedge){
			var edgeoffset=0
			if (whichedge=="rightedge"){
				var windowedge=this.ie && !window.opera? this.standardbody.scrollLeft+this.standardbody.clientWidth-15 : window.pageXOffset+window.innerWidth-15
				this.dropmenuobj.contentmeasure=this.dropmenuobj.offsetWidth
			if (windowedge-this.dropmenuobj.x < this.dropmenuobj.contentmeasure)  //move menu to the left?
				edgeoffset=this.dropmenuobj.contentmeasure-obj.offsetWidth
			}
			else{
				var topedge=this.ie && !window.opera? this.standardbody.scrollTop : window.pageYOffset
				var windowedge=this.ie && !window.opera? this.standardbody.scrollTop+this.standardbody.clientHeight-15 : window.pageYOffset+window.innerHeight-18
				this.dropmenuobj.contentmeasure=this.dropmenuobj.offsetHeight
				if (windowedge-this.dropmenuobj.y < this.dropmenuobj.contentmeasure){ //move up?
					edgeoffset=this.dropmenuobj.contentmeasure+obj.offsetHeight
					if ((this.dropmenuobj.y-topedge)<this.dropmenuobj.contentmeasure) //up no good either?
						edgeoffset=this.dropmenuobj.y+obj.offsetHeight-topedge
				}
				this.dropmenuobj.firstlink.style.borderTopWidth=(edgeoffset==0)? 0 : "1px" //Add 1px top border to menu if dropping up
			}
			return edgeoffset
		},

		dropit:function(obj, e, dropmenuID){
			if (this.dropmenuobj!=null){ //hide previous menu
				this.dropmenuobj.style.visibility="hidden" //hide menu
				if (this.previousmenuitem!=null && this.previousmenuitem!=obj){
					if (this.previousmenuitem.className.indexOf("default")==-1) //If the tab isn't a default selected one
						this.previousmenuitem.className=this.previousmenuitem.className.replace(/[ ]?ddopen/g, "");
				}			
			}
			this.clearhidemenu()
			if (this.ie||this.firefox){
				obj.onmouseout=function(){tabdropdown.delayhidemenu(obj)}
				obj.onclick=function(){return !tabdropdown.disablemenuclick} //disable main menu item link onclick?
				this.dropmenuobj=document.getElementById(dropmenuID)			
				this.dropmenuobj.onmouseover=function(){tabdropdown.clearhidemenu()}
				this.dropmenuobj.onmouseout=function(e){tabdropdown.dynamichide(e, obj)}
				this.dropmenuobj.onclick=function(){tabdropdown.delayhidemenu(obj)}
				this.showhide(this.dropmenuobj.style, e, obj)
				this.dropmenuobj.x=this.getposOffset(obj, "left")
				this.dropmenuobj.y=this.getposOffset(obj, "top")		
				this.dropmenuobj.style.left=this.dropmenuobj.x-this.clearbrowseredge(obj, "rightedge")+"px"
				this.dropmenuobj.style.top=this.dropmenuobj.y-this.clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+1+"px"
				this.previousmenuitem=obj //remember main menu item mouse moved out from (and into current menu item)
				this.positionshim() //call iframe shim function
			}
		},

		contains_firefox:function(a, b) {
			while (b.parentNode)
			if ((b = b.parentNode) == a)
				return true;
			return false;
		},

		dynamichide:function(e, obj2){ //obj2 refers to tab menu item mouse is currently over
			var evtobj=window.event? window.event : e
			if (this.ie&&!this.dropmenuobj.contains(evtobj.toElement))
				this.delayhidemenu(obj2)
			else if (this.firefox&&e.currentTarget!= evtobj.relatedTarget&& !this.contains_firefox(evtobj.currentTarget, evtobj.relatedTarget))
				this.delayhidemenu(obj2)
		},

		delayhidemenu:function(obj2){
			this.delayhide=setTimeout(function(){
				tabdropdown.dropmenuobj.style.visibility='hidden'; if (obj2.className.indexOf('default')==-1) { 	
					obj2.className=obj2.className.replace(/[ ]?ddopen/g, "");
				}
			},this.disappeardelay) //hide menu
		},

		clearhidemenu:function(){
			if (this.delayhide!="undefined")
				clearTimeout(this.delayhide)
		},

		positionshim:function(){ //display iframe shim function
			if (this.enableiframeshim && typeof this.shimobject!="undefined"){
				if (this.dropmenuobj.style.visibility=="visible"){
					this.shimobject.style.width=this.dropmenuobj.offsetWidth+"px"
					this.shimobject.style.height=this.dropmenuobj.offsetHeight+"px"
					this.shimobject.style.left=this.dropmenuobj.style.left
					this.shimobject.style.top=this.dropmenuobj.style.top
				}
			this.shimobject.style.display=(this.dropmenuobj.style.visibility=="visible")? "block" : "none"
			}
		},

		hideshim:function(){
			if (this.enableiframeshim && typeof this.shimobject!="undefined")
				this.shimobject.style.display='none'
		},

		isSelected:function(menuurl){
			var menuurl=menuurl.replace("http://"+menuurl.hostname, "").replace(/^\//, "")
			return (tabdropdown.currentpageurl==menuurl)
		},

		init:function(menuid, dselected){
			this.standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body //create reference to common "body" across doctypes
			var menuitems=document.getElementById(menuid).getElementsByTagName("td")
			for (var i=0; i<menuitems.length; i++){
				if (menuitems[i].getAttribute("rel")){
					var relvalue=menuitems[i].getAttribute("rel")
					document.getElementById(relvalue).firstlink=document.getElementById(relvalue).getElementsByTagName("a")[0]
					menuitems[i].onmouseover=function(e){
						var event=typeof e!="undefined"? e : window.event
						tabdropdown.dropit(this, event, this.getAttribute("rel"))
					}
				}
				if (dselected=="auto" && typeof setalready=="undefined" && this.isSelected(menuitems[i].href)){
					if (!menuitems[i].className.match(/[ ]?ddopen/)) menuitems[i].className+=" ddopen";
					var setalready=true
				}
				else if (parseInt(dselected)==i)
					if (!menuitems[i].className.match(/[ ]?ddopen/)) menuitems[i].className+=" ddopen";
			}
		}
	}

// New Cross-Sell;	
function initxsell(priority) {
	if (priority!='1') return false;
	if (typeof(CONSTANTS.xsell_disabled) == "undefined" || CONSTANTS.xsell_disabled != "no") {
		if (typeof(showxsell) != "undefined") 
			CONSTANTS.xsell_disabled = (priority == "maybe") ? showxsell() : priority;
	}
	if (document.location.search.match(/[\?&]p=1/) || Flag.get('popunder')) CONSTANTS.xsell_disabled = "true";
	var Browser = {
		name:"", version:6,
		init:function() {
			navigator.userAgent.replace(/(chrome|safari|opera|firefox|msie)/i, function(a, b) {
				Browser.name = b.toLowerCase();
				try {
					switch (Browser.name) {
						case "msie":
							Browser.version = parseInt(navigator.userAgent.match(/msie ([0-9])/i)[1], 10);
							break;
						case "safari":
							var version = parseInt(navigator.userAgent.match(/version\/([0-9])/i)[1], 10);
							Browser.version = (version >= 4) ? 8 : (version == 3) ? 7 : 6;
							break;
						default:
							Browser.version = (typeof document.body.style.maxHeight != "undefined") ? 7 : 6;
					}
				} catch (e) {
				}
			});
		}
	}
	Browser.init();
	if (Browser.version >= 7) document.onmousemove = mousemove;
}

var pos = [];
function flat(arr) {
	var output = [];
	for (var i=0;i<pos.length;i++) output.push(pos[i].x+","+pos[i].y);
	return output.join("<br />");
}

var mousecheckinterval = 0;
function mousemove(e) {
	window.clearInterval(mousecheckinterval);
	e = e || event;
	if (pos.length == 0 || pos[pos.length-1].y > e.clientY) {
		pos.push({x:e.clientX, y:e.clientY});
		mousecheckinterval = window.setTimeout(checkmouseposition, 1500);
	} else pos = [];
}

function checkmouseposition() {
	if (pos.length < 2 || pos[pos.length-1].y > 150) { pos = []; return; }
	if (pos[pos.length-1].y > 10) {
		var lastgap = 10000;
		for (var i=pos.length-1;i>=1;i--) {
			var gap = pos[i-1].y-pos[i].y;
			if (gap >= lastgap) { pos = []; return; }
			lastgap = gap;
		}
	}
	popup.show('xsell');
}

var popup = {}
popup.show = function(popup) {
	var currentHeight = 0;
	containerHeight = (document.all) ? document.documentElement.offsetHeight-4 : document.documentElement.scrollHeight;
	bodyHeight = window.document.body.offsetHeight;
	
	if (containerHeight < bodyHeight) {
		currentHeight = bodyHeight;
	} else { 
		currentHeight = containerHeight;
	}
		
        if (document.location.search.match(/(client|nxs)=true/) || Flag.get('nxs')) document.cookie = "xsell=true; path=/;domain=.casino.com";
        if (typeof(CONSTANTS.xsell_disabled) != "undefined" && CONSTANTS.xsell_disabled == "true") return false;

	var xSellCookie = readcookie("xsell");
	if (xSellCookie=="true") return;
	else {
		$("blocker").style.height = currentHeight+"px";
		$("blocker").style.display = '';
		$('xsell_title').innerHTML=CONSTANTS.xsellTitle;
		$('xsell_offer').innerHTML=CONSTANTS.xsellOffer;
		$('xsell_visit').innerHTML=CONSTANTS.xsellVisitURL;
		$('download_button').innerHTML=CONSTANTS.xsellDownloadTitle;
	
	
		$(popup).style.display = '';
		document.cookie="xsell=true";

		$('xsell_iframe').src = "/xsell/gaxsell.html";
	}
}

function hideXsell(popup) {
	var iframe = document.getElementById('xsell_iframe').contentWindow; 
	iframe.sendpageview('exit');
	
	$("blocker").style.display = 'none';    
	$(popup).style.display = 'none';    
}	
	
function goTo(target) {
	var iframe = document.getElementById('xsell_iframe').contentWindow; 
	if (target=='main') {
		iframe.sendpageview('main');
		location.href=CONSTANTS.xsell_link;
	}
	else {
		iframe.sendpageview('download');
		location.href=CONSTANTS.xsellDownloadLink;
	}
}
function limitEvent(e) {
    if (!e && window.event) { //IE
        window.event.cancelBubble = true;
    } else if (e && e.stopPropagation) { //standard
        e.stopPropagation();
    }
}

function openWin(action,gameCode,lang,url) {
	if (action=='download' || action=='bonus') {launchPlaytech();}
	else if (action=='download_r') {startDownload();}
	else if (action=='uniqueGames') {flashGame(gameCode,lang);return;}
	else if (action=='playforreal') {playforreal();}
	else if (action=='openWin') {
		if (typeof(openWinParams)!='undefined' && openWinParams!='') {
			var winParams = new Array;
			winParams[0] = "\'"+url+"\'";
			winParams[1] = "\'newWindow\'";
			winParams[2] = "\'"+openWinParams+"\'";
			eval('window.open('+winParams[0]+','+winParams[1]+','+winParams[2]+')');
			return;
		}
		window.open(url);
	}
	else {window.open("http://www.casino.com/za/info.html","infowindow",'directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=no,width=670,height=470');}
	return false;
}

var bannerbuttonSet="0";
function setbannerbuttons(param) {
	if (bannerbuttonSet=="0"){
		var action = param[0].action;
		if (document.getElementById('instantplay')) {document.getElementById('instantplay').style.display='none'}
		if (action!='none') {setButton(param[0].width,param[0].height,param[0].top,param[0].left,'swf_wrapper',action);}
	}
	setbannerbuttons = "1";
	return false;
}

function setButton(width,height,top,left,parentId,action,divElement,gameCode,lang,url) {
	if (isNaN(width)) width = 680;
	if (isNaN(height)) height = 480;
	if (isNaN(left)) left = 0;
	if (isNaN(top)) top = 0;

	if (typeof(divElement)!="undefined" && divElement!='') {var newdiv = document.getElementById(divElement);}
	else {
		var newdiv=document.createElement("div")
		newdiv.style.width = width+"px";
		newdiv.style.background = "red";
		newdiv.style.opacity = "0";
		newdiv.style.filter = "alpha(opacity='0')";
		newdiv.style.height = height+"px";
		newdiv.style.position = "absolute";
		newdiv.style.top = top+"px";
		newdiv.style.left = left+"px";
		newdiv.style.cursor = "pointer";
		var parentElem = document.getElementById(parentId);
		if (parentElem) {document.getElementById(parentId).appendChild(newdiv)}
		else {return}
	}
	newdiv.onclick=function(event){
		limitEvent(event);
		openWin(action,gameCode,lang,url);
	};
}

function _as(u) {
	setTimeout(function(){
		var s = document.createElement('script'); 
		var f = document.getElementsByTagName('script')[0]; 
		s.type = 'text/javascript'; 
		s.async = true;
		s.src = u; 
		f.parentNode.insertBefore(s, f);
	}, 1);

}

function markuser(s) {
	_as("//stat.casino.com/stats/track.php?__d=false&__b=cc&pb="+s);	
}

function callfromflash(action) {
	isLink = true;
	switch (action) {
		case "download":
			startDownload('flash');
			break;			
		case "instantplay":
			launchPlaytech();
			break;
		case "vip":
			document.location.href = "/points/";
			break;		
		case "promo":
			document.location.href = "/points/";
			break;		
		case "promotion":
			document.location.href = "/promotions/latest-games/";
			break;
		default:
			alert('unknown action:'+action);
			break;
	}
}

function capture(path) {
	if (path!=0){
		path = path.replace(/^[^\/]*(?:\/[^\/]*){2}/, "");
		_extgaq.push(function() { _gaq.push(['_setCustomVar', 3, 'Unique Image', path, 1]); });
		__pb.push('image:'+path);
	}
} 
function cRefererObj( creferer ) {
	this.creferer = this.parse(creferer);
}

cRefererObj.prototype.parse = function ( creferer ) {
	var cret = new Object();
	if ( creferer !== '' && creferer !== '*' ) {
		var cref = unescape(creferer).split(';');
		for ( var idx in cref ) {
			var item = cref[idx].split(':',2);
			cret[item[0]] = item[1];
		}
	}
	return cret;
}

cRefererObj.prototype.add = function ( name, value ) {
	this.creferer[name] = value;
}

cRefererObj.prototype.get = function ( name ) {
	return ( typeof( this.creferer[name] ) == "string" ) ? this.creferer[name] : false;
}

cRefererObj.prototype.del = function ( name ) {
	delete this.creferer[name];
}

cRefererObj.prototype.toString = function ( ) {
	var cret = '';
	for ( var idx in this.creferer ) {
		cret = cret + idx + ':' + this.creferer[idx] + ';';
	}
	if ( cret.length > 0 ) {
		cret = cret.substr(0, cret.length - 1);
	}
	return cret;
}

