function $(name) { return document.getElementById(name); };

if (window.addEventListener) {
	window.addEventListener("load", updateDateSpan, false);
} else {
	window.attachEvent("onload", updateDateSpan);	
}

var agt = navigator.userAgent.toLowerCase();
if (agt.indexOf("safari") != -1) {
	if ($('downloadLink')) {
		$('downloadLink').style.height = '35px';
	}
}

function linkOver(linkObj, type, section) {
	var imagesPath = $('topLinksLeft').src.substring(0, $('topLinksLeft').src.indexOf("images"));
		
	if (type == 'first') {
		linkObj.className = (section == 'aff') ? 'affTopLinkHover' : 'topLinkHover';		
		$('topLinksLeft').src = (section == 'aff') ? imagesPath+'images/affToplinkslefthover.gif' : imagesPath+'images/toplinkslefthover.gif';
	} else if (type == 'last') {
		linkObj.className = (section == 'aff') ? 'affTopLinkHover' : 'topLinkHover';
		$('topLinksRight').src = (section == 'aff') ? imagesPath+'images/affToplinksrighthover.gif' : imagesPath+'images/toplinksrighthover.gif';	
	} else {
		linkObj.className = (section == 'aff') ? 'affTopLinkHover' : 'topLinkHover';
	}	
}

function linkOut(linkObj, type, section) {
	var imagesPath = $('topLinksLeft').src.substring(0, $('topLinksLeft').src.indexOf("images"));

	if (type == 'first') {
		linkObj.className = (section == 'aff') ? 'affTopLink affTlFirst' : 'topLink tlFirst';
		$('topLinksLeft').src = (section == 'aff') ? imagesPath+'images/affToplinksleft.gif' : imagesPath+'images/toplinksleft.gif';
	} else if (type == 'last') {
		linkObj.className = (section == 'aff') ? 'affTopLink' : 'topLink';
		$('topLinksRight').src = (section == 'aff') ? imagesPath+'images/affToplinksright.gif' : imagesPath+'images/toplinksright.gif';
	} else {
		linkObj.className = (section == 'aff') ? 'affTopLink' : 'topLink';
	}	
}

var Days = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
var Months = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];	
		
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;
}

function updateDateSpan() {
    var dateSpan = $('dateContainer');
    if (dateSpan) {
        var date = new Date();

        dateSpan.innerHTML = Days[date.getUTCDay()] + ", " +
                             Months[date.getUTCMonth()] + " " +
                             addLeadingZero(date.getUTCDate()) + ", " +
                             addLeadingZero(date.getUTCFullYear()) + " - " +
                             cutHoursToAMPM(date.getUTCHours()) + ":" +
                             addLeadingZero(date.getUTCMinutes()) + " " + getAMPM(date.getUTCHours()) + " GMT";
    }
    setTimeout("updateDateSpan();", 10000);
}

function handleSideBar(linkObj) {
	if ($('promoLinks').style.display == 'none') {
		$('promoLinks').style.display = '';
	} else {
		$('promoLinks').style.display = 'none';
	}
}

function handleStartedSteps(step) {
	var imagesPath = $('startedStepImage'+step).src.substring(0, $('startedStepImage'+step).src.indexOf("images"));

	if ($('startedStep'+step).style.display == 'none') {
		$('startedStepImage'+step).src = imagesPath+'images/sarrowdown.gif';
		$('startedStep'+step).style.display = '';
	} else {
		$('startedStepImage'+step).src = imagesPath+'images/sarrowright.gif';
		$('startedStep'+step).style.display = 'none';
	}
}

var emerpcomp = null;
var counter = 0;
var userGuid = "";

function EMERPCallback(comp, eventName) {
	emerpcomp = comp;
	userGuid = comp.GetUserID();
}

function getDownloadLink() {
	var downloadUrl = "http://banner.mansion.com/cgi-bin/SetupCasino.exe?creferer=UserGUID:"+userGuid;
	return downloadUrl;
}

function doDownload() {
	var downloadframe = document.getElementById("download_iframe");
	if (downloadframe == null) {
		downloadframe = document.createElement("iframe");
		downloadframe.width = "1px";
		downloadframe.height = "1px";
		downloadframe.position = "absolute";
		downloadframe.left = "-100px";
		document.body.appendChild(downloadframe);
	}
	downloadframe.src = getDownloadLink();
	window.setTimeout(function() { document.location.href = "/download/"; }, 2000); 
}

function startDownload() {
	if (emerpcomp != null) emerpcomp.SendEvent("", "download", "");
	doDownload();
}

function openForgot() {
	$('forgotPassword').style.display = '';
}

function closeForgot() {
	$('forgotPassword').style.display = 'none';
}