//Rules functions
var rulediv = 'rulecontent';
var rulewidth = '400';
var ruleheight = '322';
var tlmin = 00;
var tlmax= 60;

function OpenGSURL(origin_suffix,divid)
{
	var GSURL = getBuyUrl();
	var SetSysId = SysId();
	var channelId = window.external.ChannelId;
	var BuyUrlParameters = getBuyUrlParameters();
	var origin = '';

	if(stat == 'enter')
		{origin = 'lnch_buy_before' + '_' + origin_suffix;}
	if(stat == 'exit')
		{origin = 'lnch_buy_after' + '_' + origin_suffix;}

	var GSURL = GSURL + '?code=' + SetSysId + '&channel=' + channelId  + '&origin=' + origin;

	if(BuyUrlParameters != '')
		{GSURL = GSURL + '&' + BuyUrlParameters;}

	window.open(GSURL,'_blank');

	closeLauncher();
}

function GetRuletoActivate()
{
	var tl = window.external.TrialTimeUsed;
	var rule = '';

	if (mode=='demo' && tl <= tlmax && tl >= tlmin)
	{
		rule = '<div id="GameSaver" class="gameSaver"><div class="gameSaverContent"><div class="gameSaverBackground">'+
			'<div class="gameSaverClose" onclick="hiddenFloatingDiv(\'rulecontent\');"><img src="images/gameSaverCloseX.gif"></div>'+
			'<div class="gameSaverGetGameText">Get this game at up to&nbsp;<span class="gameSaverGetGameText2">65% OFF</span></div>' +
			'<div class="gameSaverJoinNowButton" onclick="OpenGSURL(\'promo\', \'rulecontent\');"><img src="images/gsJoinButton.gif"></div>'+
			'<div class="gameSaverAlreadyMemberText">Already a member?<br />Get it now at your membership price.</div>'+
			'<div class="gameSaverBuyNowButton" onclick="OpenGSURL(\'promo\', \'rulecontent\');">'+
			'<img src="images/gsBuyButton.gif"></div>'+
			'<div class="gameSaverNoThanksText">'+
			'<a class="gameSaverNoThanksLink" href="#" onclick="hiddenFloatingDiv(\'rulecontent\');">No, thanks</a></div>'+
			'</div></div></div>';
	}
	
	return rule;
}

function displayRule(width, height)
{
	var w = width;
	var h = height;
	var l=document.body.offsetWidth/2-w/2;
	var t=document.body.offsetHeight/2-h/2;
					
	displayFloatingDiv(rulediv, w, h, l, t);
}

var ruletoshow = GetRuletoActivate();

function RuleCheck()
{
	if(ruletoshow != '')
		{displayRule(rulewidth, ruleheight);}
}

//Dimming functions
var originalRuleHTML = "";

function buildDimmerRule()
{
    document.write('<div id="dimmer" class="dimmer" style="width:'+ window.screen.width + 'px; height:' + window.screen.height +'px"></div>');
}

function displayFloatingDiv(divId, width, height, left, top) 
{
	document.getElementById('dimmer').style.visibility = "visible";
	document.getElementById(divId).style.width = width + 'px';
    document.getElementById(divId).style.height = height + 'px';
    document.getElementById(divId).style.left = left + 'px';
    document.getElementById(divId).style.top = top + 'px';
		
	if (originalRuleHTML == "")
	    originalRuleHTML = document.getElementById(divId).innerHTML;
	
	document.getElementById(divId).innerHTML = originalRuleHTML;
	document.getElementById(divId).className = 'dimming';
	document.getElementById(divId).style.visibility = "visible";
}

function hiddenFloatingDiv(divId) 
{
	document.getElementById(divId).innerHTML = originalRuleHTML;
	document.getElementById(divId).style.visibility='hidden';
	document.getElementById('dimmer').style.visibility = 'hidden';
}

buildDimmerRule();