function play() {
	document.location = "/?<SHELL><COMMAND>EXIT=1</COMMAND></SHELL>" ;
}

function buy() {
              	popup_open("PopBuy");
                window.location.href ="/?<SHELL><COMMAND>EX_DATA=&expired="+$Expired+"</COMMAND>";
              	setTimeout('window.location.href ="/?<SHELL><COMMAND>TRANSACTION_BROWSER=REQUEST_TYPE_PURCHASE</COMMAND>";', 250);
}

function alreadybought() {
        popup_open("PopAlready");
	//document.location = "/?<SHELL><COMMAND>URL_POPUP=" + $AlreadyBoughtURL + "</COMMAND></SHELL>" ;
}

function moregame() {
	document.location = "/?<SHELL><COMMAND>URL_BROWSER=" + $MoreGameURL + "</COMMAND></SHELL>" ;
}

function unlock()
{
	document.location = "boontyshell://activateonline/?" ;
}

function CloseWindow() {
	window.location.href ="/?<SHELL><COMMAND>EXIT=0</COMMAND>";
}

function ShellRepair() {
         window.location.href ="/?<SHELL><COMMAND>EX_DATA=idTran="+idTran+"</COMMAND>";
         window.location.href ="/?<SHELL><COMMAND>TRANSACTION=REQUEST_TYPE_REPAIR</COMMAND>";
}

function ShellReinstall() {
         var idTran = document.ToDeblocCode.idTran.value;
         var offert = document.ToDeblocCode.offert.value;
         window.location.href ="/?<SHELL><COMMAND>EX_DATA=idTran="+idTran+"&offert="+offert+"</COMMAND>";
         setTimeout('window.location.href ="/?<SHELL><COMMAND>TRANSACTION=REQUEST_TYPE_REINSTALL</COMMAND>"', 250);
}

function ContactSupport() {
         window.location.href ="/?<SHELL><COMMAND>URL_SHELL=" + $ContactSupportURL + "</COMMAND></SHELL>";
}

function GetLostCode() {
         //window.location.href ="/?<SHELL><COMMAND>URL_SHELL=" + $ContactSupportURL + "</COMMAND></SHELL>";
         alert("Fallait pas le perdre !!!");
}

function activateOfflineSN (serialNumber) 
{
	//document.location = "boontyshell://applyserialnumber/?" + serialNumber ;
	suppRequestActCode(serialNumber);
}

function activateOfflineAC (activationCode) 
{
        document.location.href='/?<SHELL><COMMAND>RESPONSE_CODE='+ activationCode +'</COMMAND></SHELL>';
}

function subscribe_popup() {
	window.location.href = "./activate.html" ;
}

function buy_popup() {
	window.location.href = "./activation_unlock.html" ;
}

function buy_popup_idtran(theIdTran) {
	setidtran(theIdTran);
	window.location.href = "./activation_unlock.html" ;
}

function helpPurchase() {
	document.location = "boontyshell://help/?ui/help/purchase.html" ;
}

function helpActivation() {
	document.location = "boontyshell://help/?ui/help/activation.html" ;
}

function help() {
	document.location = "boontyshell://help/?ui/help/index.html" ;
}

function browseLink(theLink) {
	//alert(theLink);
        document.location = "/?<SHELL><COMMAND>URL_BROWSER=" + theLink + "</COMMAND></SHELL>"  ;
}

function browseGame() {
	document.location = "boontyshell://browser/?" + gamePageAtPartner ;
}

function getmoregames() {
	document.location = "boontyshell://browser/?" + baseSiteBoonty ;
}

function closepopup (command) {
	document.location = "boontyshell://close/?" + command ;	
}

function customersupport() {
	document.location = "boontyshell://browser/?" + baseSiteBoonty + "/contact.php";
}

function customersupportrecover() {
	document.location = "boontyshell://browser/?" + baseSiteBoonty + "/contact.php";
}

function privacy() {
	document.location = "boontyshell://browser/?" + baseSiteBoonty + "/howitworks.php?intMode=5";
}

function cancel() {
	document.location = "boontyshell://cancel/?" ;	
}
function retry() {
	document.location = "boontyshell://retryunlock/?" ;
}

function setidtran(idTran) {
	document.location ="/?<SHELL><COMMAND>URL_SHELL=http://pp.genericshell.boonty.com/flex_already.php?idTran="+idTran+"</COMMAND>";
        //document.location = "boontyshell://idtran/?" + idTran ;
}

function newsletter (email) {
	if(/^[a-zA-Z0-9]([-_\.]?[a-zA-Z0-9])*@[a-zA-Z0-9]([-\.]?[a-zA-Z0-9])*\.([a-z]{2,4})$/.test(email)) {
		document.location = "boontyshell://browser/?poll.mshell.boonty.com/redirect.php?strAction=newsletter&strEmail=" + email + "&intIdSite=" +  idSite;
	}
	else {
		alert(txtCorrectEmailMsg);
	} 
}

function openPartnerWebsite() {
	document.location = "boontyshell://browser/?" + baseSitePartner;
}

function openPartnerWebsiteFAQ() {
	document.location = "boontyshell://browser/?" + baseSiteBoonty + "/howitworks.php?intMode=2";
}

function openPartnerGame(intIdGame) {
	document.location = "boontyshell://browser/?" + baseSiteBoonty + "/fiche.php?intIdGame=" + intIdGame;
}

function openBoontyWebsite() {
	document.location = "boontyshell://browser/?" + baseCorporateBoonty;
}

function textOut(theText) {
	document.write ( theText ) ;
}
function activateCode() {
	var code = document.getElementById("input_idtran").value;
        //setidtran(code);
        window.location.href ="/?<SHELL><COMMAND>EX_DATA=&idTran="+code+"&offert=0&int_IdGame="+IdGame+"</COMMAND>";
	setTimeout('window.location.href ="/?<SHELL><COMMAND>TRANSACTION=REQUEST_TYPE_REINSTALL</COMMAND>"', 250);
        //document.location ="/?<SHELL><COMMAND>URL=http://pp.genericshell.boonty.com/flex_already.php?idTran="+code+"</COMMAND>";
	/*if (code=='') alert(txtNoCodeMsg);
	else buy_popup();*/
}

function ConversionHeure(TrialMin) {
              	return (Math.floor(TrialMin/60));
              }
              
              function conversionHM(duration) {
                return (Math.floor(duration/60))+" heures "+(duration%60)+" minutes";
              }
              
              function ConversionMin(TrialMin) {
              	      return (TrialMin/60);
                      //return (TrialMin%60);
              }

var trialLeft = "";
var trialTotal = "";
function prepareTrialPeriod() {
/*
Status="EXPIRED";
ExpirationDate=-1;
LifeTime=-1;
RemainingTime=-1;
TotalRuns=-1;
RemainingRuns=-1;
TotalExecutionTime=-1;
RemainingExecutionTime=-1;
*/
	if ( typeof(Status) == "string") 
	{
		switch ( Status ) 
		{ 
			case "TRIAL": // Trial period is valid
				if (TotalExecutionTime != -1) 
				{
					if ( RemainingExecutionTime > 24*60*60) 
						trialLeft = Math.round(RemainingExecutionTime/60/60/24) + ' jours' ;
					else if ( RemainingExecutionTime > 60*60) 
						trialLeft = Math.round(RemainingExecutionTime/60/60) + ' heures' ;
					else if ( RemainingExecutionTime > 60) 
						trialLeft = Math.round(RemainingExecutionTime/60) + ' mins' ;
					else 
						trialLeft = (RemainingExecutionTime) + ' secs' ;

					if ( TotalExecutionTime > 24*60*60) 
						trialTotal = Math.round(TotalExecutionTime/60/60/24) + ' jours' ;
					else if ( TotalExecutionTime > 60*60) 
						trialTotal = Math.round(TotalExecutionTime/60/60) + ' heures' ;
					else if ( TotalExecutionTime > 60) 
						trialTotal = Math.round(TotalExecutionTime/60) + ' mins' ;
					else 
						trialTotal = (TotalExecutionTime) + ' secs' ;
				} 
				else if (LifeTime != -1) 
				{
					if ( RemainingTime > 24*60*60) 
						trialLeft = Math.round(RemainingTime/60/60/24) + ' jours' ;
					else if ( RemainingTime > 60*60) 
						trialLeft = Math.round(RemainingTime/60/60) + ' heures' ;
					else if ( RemainingTime > 60) 
						trialLeft = Math.round(RemainingTime/60) + ' mins' ;
					else 
						trialLeft = (RemainingTime) + ' secs' ;

					if ( LifeTime > 24*60*60) 
						trialTotal = Math.round(LifeTime/60/60/24) + ' jours' ;
					else if ( LifeTime > 60*60) 
						trialTotal = Math.round(LifeTime/60/60) + ' heures' ;
					else if ( LifeTime > 60) 
						trialTotal = Math.round(LifeTime/60) + ' mins' ;
					else 
						trialTotal = (LifeTime) + ' secs' ;
				} 
				else if (TotalRuns != -1) 
				{
					trialLeft = RemainingRuns + ' parties' ;
					trialTotal = TotalRuns ;
				} 
				break ;
			case 'EXPIRED': // Game is expired
				break ;
			case "BUYONLY": // Game is buy only
				break ;
			case "NORMAL": // Game is unlocked
				break ;
			case "BROKEN": // License is broken
				break ;
			case "ERROR": // Error encoutered
				break ;
		}
	}
}

  function Drag() {
  	window.location.href ="EVENT:DRAG";
  }


  function BuyCoca(strCocaCode) {
  	var expired = "<? echo $expired; ?>";
  	
  	
  	window.location.href ="/?<SHELL><COMMAND>EX_DATA=&expired="+expired+"&strCocaCode="+strCocaCode+"</COMMAND>";
  	setTimeout('window.location.href ="/?<SHELL><COMMAND>TRANSACTION=REQUEST_TYPE_PURCHASE</COMMAND>";', 250);
  }
  
  function SubscribeCreate() {
  	var expired = "<? echo $expired; ?>";
  	window.location.href ="/?<SHELL><COMMAND>TRANSACTION=REQUEST_TYPE_SUBS_CREATE</COMMAND><SUBCOMMAND>SHELLCOOKIE_DATA=expired="+expired+"&createMode=1&</SUBCOMMAND></SHELL>";
  }
  
  // create mode set to 2
  function SubscribeCreateAuto() {
  	var expired = "<? echo $expired; ?>";
  	window.location.href ="/?<SHELL><COMMAND>TRANSACTION=REQUEST_TYPE_SUBS_CREATE</COMMAND><SUBCOMMAND>SHELLCOOKIE_DATA=expired="+expired+"&createMode=2&</SUBCOMMAND></SHELL>";
  }
  
  // create mode set to 3
  function SubscribeCreateManu() {
  	var expired = "<? echo $expired; ?>";
  	window.location.href ="/?<SHELL><COMMAND>TRANSACTION=REQUEST_TYPE_SUBS_CREATE</COMMAND><SUBCOMMAND>SHELLCOOKIE_DATA=expired="+expired+"&createMode=3&</SUBCOMMAND></SHELL>";
  }
  
  function SubscribeLogin() {
  	var expired = "<? echo $expired; ?>";
  	window.location.href ="/?<SHELL><COMMAND>TRANSACTION=REQUEST_TYPE_SUBS_CREATE</COMMAND><SUBCOMMAND>SHELLCOOKIE_DATA=expired="+expired+"&loginMode=1&</SUBCOMMAND></SHELL>";
  }

// Disable text selection and righ-click
document.onselectstart=new Function ("return false;");
var myOcm = document.oncontextmenu;
document.oncontextmenu=new Function("return false;");

/****************************** SUPPORT ************************************************/
var suppEmailTo = 'helpdesk@boonty.com';
var suppEmailSubjSN = "[Req. SN] " + gameName;
var suppEmailSubjActCode = "[Req. ActCode] " + gameName;


function suppRequestSn(orderId) {
	var emailBody = "OrderId: " + orderId;
	emailBody += "%0d%0a%0d%0aSite: " + partnerName + " ("+idSite+")";
	emailBody += "%0d%0a%0d%0aGame: " + gameName + " ("+IdGame+")";
	emailBody += "%0d%0a%0d%0aCPA: " + CPA;
	if(orderId == "")
	{
		alert('Please enter a valid Order ID!');
		return false;
	} else {
		window.location = "mailto:"+suppEmailTo+"?subject="+suppEmailSubjSN+"&body="+emailBody ;
		}
}

function suppRequestActCode(mySerialNumber)
{
        var emailBody = "Serial Number: " + mySerialNumber;
	emailBody += "%0d%0a%0d%0aSite: " + partnerName + " ("+idSite+")";
	emailBody += "%0d%0a%0d%0aGame: " + gameName + " ("+IdGame+")";
	emailBody += "%0d%0a%0d%0aLicence: " + CPA;
	emailBody += "%0d%0a%0d%0aReq. code: " + RequestCode;
	emailBody += "%0d%0a%0d%0aType: Flexnet GS"
	window.location = "mailto:"+suppEmailTo+"?subject="+suppEmailSubjActCode+"&body="+emailBody ;
	window.location = "man-unlock-01.html" ;
}

/*************************************** RUN ***************************************************************/

// Disable text selection and righ-click
document.onselectstart=new Function ("return false;");
var myOcm = document.oncontextmenu;
document.oncontextmenu=new Function ("return false;");
// Initialise Trial Period
prepareTrialPeriod();
