// Initialisation of global var
  var $TrialInit = LifeTime; //Nombre de jours global
  var $Trial = RemainingTime; //Nombre de jours d'essais restants
  var $TrialInitMin = TotalExecutionTime;
  var $TrialMin = RemainingExecutionTime;
  var $TrialInitLau = TotalRuns;
  var $TrialLau = RemainingRuns;
  var $BuyURL = ""; // Buy URL for NeoShell
  //var $AlreadyBoughtURL = "<?=$start_dir."/already_bought.php?int_IdSite=".$int_IdSite."&str_Language=".$str_Language."&int_IdGame=".$int_IdGame."&int_IdMetagame=".$int_IdMetagame."&trial_day_max=".$trial_day_max."&trial_days_remaining=".$trial_days_remaining."&trial_min_max=".$trial_min_max."&trial_min_remaining=".$trial_min_remaining."&trial_lau_max=".$trial_lau_max."&trial_lau_remaining=".$trial_lau_remaining; ?>";
  var $AlreadyBoughtURL = "";
  var $Expired = "";
  var $MoreGameURL = "";
  var $strBaseGenericShell = "http://genericshell.boonty.com/";
  var suppEmailTo = '';
  
  //Gestion de l'affichage de la progress bar
  function PrintScroll() {
	        $maxWidthScroll = 310;
        	$image_scroll= "progress_bar.gif";
                cpt = 0;
  		$html = "";
  		myPercent = 0;
   	        if (($TrialInitMin != 0)) {
        		    myPercent = ($TrialMin/$TrialInitMin) * 100;
        		    //alert($TrialMin);
        		    //alert($TrialInitMin);
        	} else {
                  if (($TrialInitLau != 0)) {
                          myPercent = ($TrialLau/$TrialInitLau) * 100;
                  }
                  else {
                    if (($TrialInit != 0)) {
                            myPercent = ($Trial/$TrialInit) * 100;
		    }
                  }
                }
  		    if (myPercent > 0) {
                      $html = "<img src=\"Images/Boonty/progress_end.gif\" style=\"margin-top:5px;margin-left:7px;width:9px;height:27px;\" />";
                      //document.write("<img src=\"Images/progress_on.gif\" style=\"margin-top:5px;margin-left:7px;width:9px;height:27px;\" />");
                    }
                    for (cpt=4; cpt<myPercent; cpt+=4) {
                      if (cpt < 96) {
                         $html += "<img src=\"Images/Boonty/progress_on.gif\" style='margin-top:5px;margin-left:1px;width:12.5px;height:27px;' />";
                         //document.write("<img src=\"Images/progress_on.gif\" style=\"margin-top:5px;margin-left:-4px;width:13px;height:27px;\" />");
                      } else {
                         $html += "<img src=\"Images/Boonty/progress_end.gif\" style=\"margin-top:5px;margin-left:1px;width:9px;height:27px;\" />";
                         //document.write("<img src=\"Images/progress_on.gif\" style=\"margin-top:5px;margin-left:-4px;width:9px;height:27px;\" />");
                         }
                    }
                    //alert(cpt);
  		//}
  		//alert ($html);
  	return $html;
  }

  function activationWait()
  {
    document.getElementById("PopAlready").innerHTML = '<div class="MainBox"><img class="top_right" src="../Images/corner_top_right_inversed.gif" alt="" /><div class="content"><div class="PinkTitle">解除</div>ゲームのロックを解除しています。このウィンドウを閉じずに、しばらくお待ちください。</div><div class="bottom" style="margin-top:36px"><img class="bottom_right" src="../Images/corner_bottom_right_inversed.gif" alt="" /></div></div>';
  }
  
  function popup_close(idToClose) {
	document.getElementById(idToClose).style.visibility = "hidden";
  }
  
  function popup_open(idToOpen) {
	document.getElementById(idToOpen).style.visibility = "visible";
  }
  
  function beforeActivate()
  {
        var code = document.getElementById("input_idtran").value;
	if (code == '')
        {
          document.getElementById("error_msg").innerHTML = "<font class='RedMini' >入力されたコードでは、このゲームのロックは解除できません。</font>";
        } else {
         activateCode();
        }
   }

 function close_lostcode(isSuccess)
  {
            var strTmp;
            popup_close("PopAlready");
            strTmp = '<div class="MainBox">\
            <img class="top_right" src="../Images/corner_top_right_inversed.gif" alt="" />\
            <div class="content">\
            <div class="PinkTitle">解除</div>\
                <span id="error_msg" ><br /></span>\
                購入完了メールの中に記載されている解除コードを入力してください。  \
                <br />\
                <input type="text" id="input_idtran" style="width:240px;margin-left:10px;" />\
                <div class="GreenMini">例） 123456789der7e8d1cr887416164568 </div>\
                <div class="ButtonBox">\
                       <div class="ButtonLeft"></div>\
                       <div class="ButtonMiddle" style="width:100px"><a href="javascript:void(0);" onclick="beforeActivate()">確認</a></div>\
                       <div class="ButtonRight"></div>\
                </div>';
             if (isSuccess!=true) strTmp +='<a href="javascript:void(0);" onclick="lostCode();">解除コードをなくした</a>';
             strTmp +=   '<div class="Close" onclick="popup_close(\'PopAlready\');"><img src="Images/close.gif" /> 閉じる </div>\
              </div>\
              <div class="bottom" style="margin-top:36px"><img class="bottom_right" src="../Images/corner_bottom_right_inversed.gif" alt="" /></div>\
              </div>';
              document.getElementById("PopAlready").innerHTML = strTmp;
              //alert( document.getElementById("PopAlready").innerHTML);
  }
  
  function lostCode()
  {
    document.getElementById("PopAlready").innerHTML = '\
     <div class="MainBox">\
      <img class="top_right" src="../Images/corner_top_right_inversed.gif" alt="" />\
      <div class="content">\
      <div class="PinkTitle">コードを無くした</div>\
      <span id="error_msg" ><br /></span>\
        ゲームの購入時に指定したメールアドレスを入力してください。&nbsp;\
        <br />\
        <input type="text" id="lostcode_mail" style="width:240px;margin-left:10px;" />\
        <div class="GreenMini">例） my_name@internet_provider.co.jp</div>\
        <div class="ButtonBox">\
               <div class="ButtonLeft"></div>\
               <div class="ButtonMiddle" style="width:100px"><a href="javascript:void(0);" onclick="retriveCode()">確認</a></div>\
               <div class="ButtonRight"></div>\
        </div>\
        <div class="Close" onclick="close_lostcode(false);"><img src="Images/close.gif" id="manunlock_lostcode_close"  /> 閉じる</div>\
      </div>\
      <div class="bottombis" style="margin-top:54px"><img class="bottom_right" src="../Images/corner_bottom_right_inversed.gif" alt="" /></div>\
     </div>';
  }
  
  function manunlock_lostCode()
  {
    lostCode();
    document.getElementById("manunlock_lostcode_close").src = "../Images/close.gif";
    popup_open("PopAlready");
  }
  
  function retriveCode() {
   var filter = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/
   var strEmail = document.getElementById('lostcode_mail').value
   if (filter.test(strEmail) == true) {
     document.getElementById("error_msg").innerHTML = '<br />';
     //cr�ation de l'objet XMLHttpRequest
     var XMLHttpRequestObject = createXMLHttpRequestObject();
     var objDate = new Date();

     //traitement
     XMLHttpRequestObject.onreadystatechange = function () {
					if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) {
                                                var strStatus = XMLHttpRequestObject.responseText;
                                                if (strStatus == "success")
                                                {
                                                  close_lostcode(true);
                                                  document.getElementById("error_msg").innerHTML = '<font class="PinkMini" >解除コードを記載したメールを指定されたメールアドレスに送信しました。</font><br />';
                                                  popup_open('PopAlready');
                                                } else {
                                                  document.getElementById("error_msg").innerHTML = '<font class="RedMini" >申し訳ありませんが、このアドレスでの購入履歴を確認できませんでした。</font><br />';
                                                }
					} else if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status != 200) {
						// error in php file call 
                                            alert("error "+parseInt(XMLHttpRequestObject.status));
					} 	 				}
     //open

     XMLHttpRequestObject.open('GET', $strBaseGenericShell+'retrieve_code.php?intIdGame=<? echo $int_IdGame;?>&strEmail='+strEmail, false);

     //send
     XMLHttpRequestObject.send(null);
   } else {
     document.getElementById("error_msg").innerHTML = '<font class="RedMini" >メールアドレスが正しくありません。ご確認ください。</font><br />';
   }
}

//----------------------------------------- TRIAL EXIT UTILITIES


var intScore = 2;
var arrRatingComment = new Array('好みではない','今ひとつ','良い','すばらしい', '最高');
function starlight(intStar)
{
  for (i=0; i<(intStar+1); i++) {
	document.getElementById('star'+i).src = document.getElementById('star'+i).src.replace(/_off/,'_on');
  }
  for (i=intStar+1; i<5; i++) {
        document.getElementById('star'+i).src = document.getElementById('star'+i).src.replace(/_on/,'_off');
  }
  document.getElementById('rating_comment').innerHTML = arrRatingComment[intStar];
}

function starshadow()
{
  for (i=(intScore + 2); i<5; i++) {
        //alert(i);
        document.getElementById('star'+i).src = document.getElementById('star'+i).src.replace(/_on/,'_off');
  }
  
  for (i=0; i<=(intScore + 2); i++) {
	document.getElementById('star'+i).src = document.getElementById('star'+i).src.replace(/_off/,'_on');
  }
  document.getElementById('rating_comment').innerHTML = arrRatingComment[intScore + 2];
}

function starvote(intVote)
{
  //cr�ation de l'objet XMLHttpRequest
  var XMLHttpRequestObject = createXMLHttpRequestObject();
  var objDate = new Date();
  var strRatingTitle = 'このゲームの評価 : ';
  //traitement
	XMLHttpRequestObject.onreadystatechange = function () {
					if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) {
                                                //On ne prends plus le r�sultat re�u : intScore = parseInt(XMLHttpRequestObject.responseText);
                                                intScore = intVote;
                                                arrRatingComment = new Array('','','','', '');
                                                strRatingTitle = '投票ありがとうございます : ';
                                                document.getElementById('star0').onclick = function() { '' };
                                                document.getElementById('star1').onclick = function() { '' };
                                                document.getElementById('star2').onclick = function() { '' };
                                                document.getElementById('star3').onclick = function() { '' };
                                                document.getElementById('star4').onclick = function() { '' };
					} else if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status != 200) {
						// error in php file call
                                                alert("error "+parseInt(XMLHttpRequestObject.status));
					} 	 				}
	//open
        XMLHttpRequestObject.open('GET', $strBaseGenericShell+'get_rating.php?intIdMetagame=<?=$int_IdMetagame;?>&intVote='+intVote, false);
	//alert('get_rating.php?intIdMetagame=<?=$int_IdMetagame;?>&intVote='+intVote);
        //send
	XMLHttpRequestObject.send(null);
        document.getElementById('rating_Title').innerHTML = strRatingTitle;
        document.getElementById('rating_comment').style.width = '0px';
	starshadow();
}

function starvoteallready()
{
  var tmp; 
  tmp = document.getElementById('rating_comment').innerHTML;
  document.getElementById('rating_comment').innerHTML = '投票済みです。 ';
  sleep(200); 
  document.getElementById('rating_comment').innerHTML = tmp;
}

function newsletter_subscribe()
{
  //cr�ation de l'objet XMLHttpRequest
  var XMLHttpRequestObject = createXMLHttpRequestObject();
  var strCustomerMail = document.getElementById('newsletter_inscription').value;
  var filter = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
  if (filter.test(strCustomerMail))
  {
  //traitement
	XMLHttpRequestObject.onreadystatechange = function () {
					if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) {
						//alert('XML Answer : '+ XMLHttpRequestObject.responseText);
					} else if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status != 200) {
						// error in php file call 
						alert("error "+parseInt(XMLHttpRequestObject.status));
					} 	 				
          }
	//open
        XMLHttpRequestObject.open('GET', $strBaseGenericShell+'newsletter_subs.php?intIdSite=<?php echo $int_IdSite;?>&strEmail='+strCustomerMail, false);
	//alert('newsletter_subs.php?intIdSite=<?php echo $int_IdSite;?>&strEmail='+strCustomerMail);
        //send
	XMLHttpRequestObject.send(null);

  document.getElementById("NewsletterForm").innerHTML = '<div class="DarkGrey" style="font-weight:bold;margin-bottom:12px;">メルマガへの登録、ありがとうございます。ご登録いただいたメールアドレスに確認メールを送付いたしました。 </div>';
  document.getElementById("newsButton").innerHTML = '&nbsp;';
  document.getElementById("NewsletterText").innerHTML = '&nbsp;';
  } else {
    popup_open('PopErrorNews');
  }
}