var s="Games search";

// Get base url
url = document.location.href;
xend = url.lastIndexOf("/") + 1;
var base_url = url.substring(0, xend);
var ajax_get_error = false;
function ajax_do (url) {
   // Does URL begin with http?
   if (url.substring(0, 4) != 'http') {
      url = base_url + url;
   }
   // Create new JS element
   var jsel = document.createElement('SCRIPT');
   jsel.type = 'text/javascript';
   jsel.src = url;
   // Append JS element (therefore executing the 'AJAX' call)
   document.body.appendChild (jsel);
   return true;
}

function ajax_get (url, el) {
   // Has element been passed as object or id-string?
   if (typeof(el) == 'string') {
      el = document.getElementById(el);
   }
   // Valid el?
   if (el == null) { return false; }
   // Does URL begin with http?
   if (url.substring(0, 4) != 'http') {
      url = base_url + url;
   }
   // Create getfile URL
   getfile_url = base_url + 'reco/getfile.php?url=' + escape(url) + '&el=' + escape(el.id);
   // Do Ajax
   ajax_do (getfile_url);
   return true;
}

function ajax_get_fav (url, el) {
   // Has element been passed as object or id-string?
   if (typeof(el) == 'string') {
      el = document.getElementById(el);
   }
   // Valid el?
   if (el == null) { return false; }
   // Does URL begin with http?
   if (url.substring(0, 4) != 'http') {
      url = base_url + url;
   }
   // Create getfile URL
   getfile_url = base_url + 'reco/getfilefav.php?url=' + escape(url) + '&el=' + escape(el.id);
   // Do Ajax
   ajax_do (getfile_url);
   return true;
}

function validEmail(email) { // VERIFICATION DE LA SYNTHAXE DE L'EMAIL
   invalidChars = "/:,;~"
   // verifie qu'il n'y a pas de caracteres pas autorises
   for (i=0; i<invalidChars.length; i++) {
   badChar = invalidChars.charAt(i)
   if (email.indexOf(badChar,0) > -1) {
   return false
   }
   }
   // verifie qu'il y a un @
   atPos = email.indexOf("@",1)
   if (atPos == -1) {
   return false
   }
   // et seulement un @
   if (email.indexOf("@", atPos+1) != -1) {
   return false
   }
   // et au moins un point apres le @
   periodPos = email.indexOf(".",atPos)
   if (periodPos == -1) {
   return false
   }
   //verifie qu'il y a au moins un caractère entre le @ et le .
   if (periodPos - atPos < 2) {
   return false
   }
   //verifie qu'il y a au moins deux caracteres apres le point
   if (periodPos+3 > email.length) {
   return false
   }
   return true
}


function validEmail(emailami) { // VERIFICATION DE LA SYNTHAXE DE L'EMAIL
   invalidChars = "/:,;~"
   // verifie qu'il n'y a pas de caracteres pas autorises
   for (i=0; i<invalidChars.length; i++) {
   badChar = invalidChars.charAt(i)
   if (emailami.indexOf(badChar,0) > -1) {
   return false
   }
   }
   // verifie qu'il y a un @
   atPos = emailami.indexOf("@",1)
   if (atPos == -1) {
   return false
   }
   // et seulement un @
   if (emailami.indexOf("@", atPos+1) != -1) {
   return false
   }
   // et au moins un point apres le @
   periodPos = emailami.indexOf(".",atPos)
   if (periodPos == -1) {
   return false
   }
   //verifie qu'il y a au moins un caractère entre le @ et le .
   if (periodPos - atPos < 2) {
   return false
   }
   //verifie qu'il y a au moins deux caracteres apres le point
   if (periodPos+3 > emailami.length) {
   return false
   }
   return true
}


function valeurCheck() {
   var name2 = document.getElementById('name2').value;
   var email = document.getElementById('email').value;
   var emailami = document.getElementById('emailami').value;
   var comment = document.getElementById('comment').value;

   var jeu_id = document.getElementsByName('jeu_id')[0].value;
   var jeu_nom = document.getElementsByName('jeu_nom')[0].value;
   var jeu_cat = document.getElementsByName('jeu_cat')[0].value;
   var jeu_ref_cat = document.getElementsByName('jeu_ref_cat')[0].value;
   var jeu_image = document.getElementsByName('jeu_image')[0].value;
   var jeu_ip = document.getElementsByName('jeu_ip')[0].value;
   var jeu_total = document.getElementsByName('jeu_total')[0].value;

  /* 
   // CHECK MESSAGE -- on commence par en bas pour que le onfocus replace la page au bon niveau d'erreur
   if(comment == "" ){ // si champ comment vide
      document.getElementById('comment').focus(); // focus dans le champ
      document.getElementById('comment').style.border = '1px solid #D41919'; // on change la couleur du border du INPUT
      document.getElementById('commentbox').innerHTML = '<font style="color:#cc0000; font-size:10px;"><img src="reco\/images\/no.gif" alt="" \/> Veuillez entrer votre message.<\/font>'; // on affichage le message dans le div ID
   }else{ // si champ comment rempli
      document.getElementById('comment').style.border = '1px solid #CFD8E0'; // on remet la couleur du border du INPUT
      document.getElementById('commentbox').innerHTML = '&nbsp;<img src="reco\/images\/yes.gif" alt="" \/>'; // on affiche une image OK
   }
   */
   
   // CHECK EMAIL
    if(email == "" ){
      document.getElementById('email').focus();
      document.getElementById('email').style.border = '1px solid #D41919';
      document.getElementById('emailbox').innerHTML = '<font style="color:#cc0000; font-size:10px;"><img src="reco\/images\/no.gif" alt="" \/> Veuillez entrer votre email.<\/font>';
   }else if (!validEmail(email)) {
      document.getElementById('email').focus();
      document.getElementById('email').select();
      document.getElementById('email').style.border = '1px solid #D41919';
      document.getElementById('emailbox').innerHTML = '&nbsp;<img src="reco\/images\/no.gif" alt="" \/> <font style="color:#FD1813; font-size:10px;">Votre email n\'est pas valide<\/font>';
   }else{
      document.getElementById('email').style.border = '1px solid #CFD8E0';
      document.getElementById('emailbox').innerHTML = '&nbsp;<img src="reco\/images\/yes.gif" alt="" \/>';
   }
 
   // CHECK EMAIL AMI
    if(emailami == "" ){
      document.getElementById('emailami').focus();
      document.getElementById('emailami').style.border = '1px solid #D41919';
      document.getElementById('emailamibox').innerHTML = '<font style="color:#cc0000; font-size:10px;"><img src="reco\/images\/no.gif" alt="" \/> Veuillez entrer l\'email de votre ami.<\/font>';
   }else if (!validEmail(emailami)) {
      document.getElementById('emailami').focus();
      document.getElementById('emailami').select();
      document.getElementById('emailami').style.border = '1px solid #D41919';
      document.getElementById('emailamibox').innerHTML = '&nbsp;<img src="reco\/images\/no.gif" alt="" \/> <font style="color:#FD1813; font-size:10px;">L\'email de votre ami n\'est pas valide<\/font>';
   }else{
      document.getElementById('emailami').style.border = '1px solid #CFD8E0';
      document.getElementById('emailamibox').innerHTML = '&nbsp;<img src="reco\/images\/yes.gif" alt="" \/>';
   }
 
 
   // CHECK NOM
   if(name2 == "" ){
      document.getElementById('name2').focus();
      document.getElementById('name2').style.border = '1px solid #D41919';
      document.getElementById('name2box').innerHTML = '<font style="color:#cc0000; font-size:10px;"><img src="reco\/images\/no.gif" alt="" \/> Veuillez entrer votre nom.<\/font>';
   }else{
      document.getElementById('name2').style.border = '1px solid #CFD8E0';
      document.getElementById('name2box').innerHTML = '&nbsp;<img src="reco\/images\/yes.gif" alt="" \/>';
   }
   
   // CHECK FINAL
   if ( (name2 == "") || (email == "") || (emailami == "") || (!validEmail(email) ) || (!validEmail(emailami) ) || (jeu_id == "") || (jeu_nom == "") || (jeu_cat == "") || (jeu_ref_cat == "") || (jeu_image == "") || (jeu_ip == "") || (jeu_total == "") ) {
      return false;
   }
   
   url = 'reco/contact-check.php?name2=' + escape(name2) + '&email=' + escape(email) + '&emailami=' + escape(emailami) + '&comment=' + escape(comment) + '&jeu_id=' + escape(jeu_id) + '&jeu_nom=' + escape(jeu_nom) + '&jeu_cat=' + escape(jeu_cat) + '&jeu_ref_cat=' + escape(jeu_ref_cat) + '&jeu_image=' + escape(jeu_image) + '&jeu_ip=' + escape(jeu_ip) + '&jeu_total=' + escape(jeu_total);
   ajax_get (url, 'result')/**/;
   
   // On efface le champ MAIL AMI afin d'éviter l'envoi multiple
   document.getElementById("emailami").value="";
}



/*function favoris() {

	var jeu_id = document.getElementsByName('jeu_id_fav')[0].value;

   // CHECK ID
   document.getElementById('jeu_id_fav').style.border = '1px solid #CFD8E0';
   document.getElementById('jeu_id_box').innerHTML = '&nbsp;<img src="images\/yes.gif" alt="Jeu ajout&eacute; à vos favoris !" \/>';
     
   url = 'cookies_add.php?id=' + escape(jeu_id);
   ajax_get_fav (url, 'result_mes_jeux');
   
}*/

<!-- Ajouter au favoris COOKIE -->
function favorisadd(id) {

var base_url = url.substring(0, xend);
url = base_url + 'cookies_add.php?id=' + escape(id);
newwindow=window.open(
url,'name2', 'status=no, toolbar=no, scrollbars=yes, titlebar=no, menubar=no, resizable=no, width=1, height=1, directories=no, location=no');

//document.getElementById('jeu_id_box').innerHTML='<strong>You changed me</strong>';
document.getElementById('jeuxajoute').innerHTML='<strong>Game added to <a href="/?mg=1" title="Go to My Games">My Games</a> !</strong><br>';

if (window.focus) {newwindow.focus()}
return false;

}


<!-- Supprimer des favoris COOKIE -->
function favorissup(id) {

var base_url = url.substring(0, xend);
url = base_url + 'cookies_sup.php?id='+ escape(id);
newwindow=window.open(
url,'name3', 'status=no, toolbar=no, scrollbars=yes, titlebar=no, menubar=no, resizable=no, width=1, height=1, directories=no, location=no');

//document.getElementById('jeu_id_box').innerHTML='<strong>You changed me</strong>';
//document.getElementById('jeuxsupprime').innerHTML='<strong>Jeu supprim&eacute; de vos jeux favoris</strong><br>';
// A mettre dans le code de la page de destination :
// <div id=\"jeuxsupprime\" style=\"display:inline;\">AFFICHAGE ICI</div>

if (window.focus) {newwindow.focus()}
return false;

}


function NewsMaFonctionAjax(email, id_games)
{
  var OAjax;
  if (window.XMLHttpRequest) OAjax = new XMLHttpRequest();
  else if (window.ActiveXObject) OAjax = new ActiveXObject('Microsoft.XMLHTTP');
  OAjax.open('POST',"NewsMaPageDeRequPHP.php",true);
  OAjax.onreadystatechange = function()
  {
      if (OAjax.readyState == 4 && OAjax.status==200)
      {
          if (document.getElementById)
          {   
              if (OAjax.responseText =='true') { /* OK */
                    document.getElementById('msgnews').innerHTML='<font color=purple>'+OAjax.responseText+'</font>';
              }
			  else{                             /* PAS OK */
                    document.getElementById('msgnews').innerHTML='<font color=red>'+OAjax.responseText+'</font>';
              }
          }     
      }
  }
  OAjax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
  OAjax.send('email='+email+'&id_games='+id_games);  
}


function SizeMaFonctionAjax(id_games,width,height,screenwidth,screenheight)
{
  var OAjax;
  if (window.XMLHttpRequest) OAjax = new XMLHttpRequest();
  else if (window.ActiveXObject) OAjax = new ActiveXObject('Microsoft.XMLHTTP');
  OAjax.open('POST',"SizeMaPageDeRequPHP.php",true);
  OAjax.onreadystatechange = function()
  {
      if (OAjax.readyState == 4 && OAjax.status==200)
      {
          if (document.getElementById)
          {   
              if (OAjax.responseText =='true') { /* OK */
                    document.getElementById('size').innerHTML='<font color=green>'+OAjax.responseText+'</font>';
              }
			  else{                             /* PAS OK */
                    document.getElementById('size').innerHTML='<font color=green>'+OAjax.responseText+'</font>';
              }
          }     
      }
  }
  OAjax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
  OAjax.send('id_games='+id_games+'&width='+width+'&height='+height+'&screenwidth='+screenwidth+'&screenheight='+screenheight);  
}






function SetCookie (name, value) {
	var argv=SetCookie.arguments;
	var argc=SetCookie.arguments.length;
	var expires=(argc > 2) ? argv[2] : null;
	var path=(argc > 3) ? argv[3] : null;
	var domain=(argc > 4) ? argv[4] : null;
	var secure=(argc > 5) ? argv[5] : false;
	document.cookie=name+"="+escape(value)+
		((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
		((path==null) ? "" : ("; path="+path))+
		((domain==null) ? "" : ("; domain="+domain))+
		((secure==true) ? "; secure" : "");
}
	
function getCookieVal(offset) {
	var endstr=document.cookie.indexOf (";", offset);
	if (endstr==-1)
      		endstr=document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
	var arg=name+"=";
	var alen=arg.length;
	var clen=document.cookie.length;
	var i=0;
	while (i<clen) {
		var j=i+alen;
		if (document.cookie.substring(i, j)==arg)
                        return getCookieVal (j);
                i=document.cookie.indexOf(" ",i)+1;
                        if (i==0) break;}
	return null;
}
	  
	  
	  
function Resize(anim,id_games,size,widthorigine,heightorigine) {
	
/*
	NavName = navigator.appName;
	NavVers = navigator.appVersion;
	Nav = NavName + " " + NavVers;
   var navigateur = navigator.userAgent.toLowerCase();
   var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
*/
	var widthorigine = widthorigine;
	var heightorigine = heightorigine;
	
   // Zoom - ou + Flash object named "anim" or Div named "flash"
   if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){
   	   var width = document.getElementById('flash').style.width;
	   var height= document.getElementById('flash').style.height;
	   var width = parseInt(width,10)+ parseInt(size,10);
	   var height = parseInt(height,10)+ parseInt(size,10);
	   
	   document.getElementById('flash').style.width = width+'px'; void(0); 
	   document.getElementById('flash').style.height = height+'px'; void(0); 
   }

   else if(/MSIE[\/\s](\d+\.\d+)/.test(navigator.userAgent)) { 
   	   var width = document.getElementById(anim).width;
	   var height= document.getElementById(anim).height;

	   // If 100% ajust to original sizes
	   if(width=='100%') {
		   var width = widthorigine;
		   var height = heightorigine;
	   }
	   var width = parseInt(width,10)+ parseInt(size,10);
	   var height = parseInt(height,10)+ parseInt(size,10);
	   document.getElementById(anim).width = width; void(0); 
	   document.getElementById(anim).height = height; void(0); 
   }
   
   else {
   /*var width = document.getElementById('anim').width;
   var height= document.getElementById('anim').height;

   // If 100% ajust to original sizes
   if(width=='100%') {
	   var width = widthorigine;
	   var height = heightorigine;
   }

   var width = parseInt(width,10)+ parseInt(size,10);
   var height = parseInt(height,10)+ parseInt(size,10);

   document.getElementById('anim').width = width; void(0); 
   document.getElementById('anim').height = height; void(0); 
   */
	   //alert('Chrome');
   	   var width = document.getElementById('flash').style.width;
	   var height= document.getElementById('flash').style.height;
	   
	   // If 100% ajust to original sizes
	   if(width=='100%') {
		   var width = widthorigine;
		   var height = heightorigine;
	   }
	   var width = parseInt(width,10)+ parseInt(size,10);
	   var height = parseInt(height,10)+ parseInt(size,10);
	   document.getElementById('flash').style.width = width+'px'; void(0); 
	   document.getElementById('flash').style.height = height+'px'; void(0); 

   }

	// Add cookies
	var concatenation = id_games+"|"+width+"|"+height;
	var pathname=location.pathname;
	var myDomain=pathname.substring(0,pathname.lastIndexOf('/')) +'/';
	var date_exp = new Date();
	date_exp.setTime(date_exp.getTime()+(3650*24*3600*1000));
	// 365 days
	SetCookie(id_games,concatenation,date_exp,myDomain);

}



function GetSize(id_games) {

	size_id_games=GetCookie(id_games);
	if (size_id_games) {
    	//document.getElementById('size').innerHTML='<span style="save_load"><strong><a href="/" title="Save">'+le_prenom+' !</a></strong><br></span>'; 
		a=size_id_games.split('|');
		var id_games = a[0];
		var width = a[1];
		var height = a[2];

   var navigateur = navigator.userAgent.toLowerCase();

   if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){
	//   alert("ff "+width+" - "+height)
   document.getElementById('flash').style.width = width+'px'; void(0); 
   document.getElementById('flash').style.height = height+'px'; void(0); 
   }

   else if(/MSIE[\/\s](\d+\.\d+)/.test(navigator.userAgent)) { 
   document.getElementById('anim').width = width; void(0); 
   document.getElementById('anim').height = height; void(0); 
   }
   
   else {
   document.getElementById('flash').style.width = width+'px'; void(0); 
   document.getElementById('flash').style.height = height+'px'; void(0); 
   }

		// Résolution screen for DB
		var screenwidth = screen.width;
		var screenheight = screen.height;
		
		// save this size in DB
		SizeMaFonctionAjax(id_games,width,height,screenwidth,screenheight);
	}
	else {
	    //alert("Cookies OFF : "+id_games+" - "+width+" - "+height);
	}	
	
}



function ResizeOrigine(anim,id_games,width,height) {
   
   var navigateur = navigator.userAgent.toLowerCase();

   if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){
   document.getElementById('flash').style.width = width+'px'; void(0); 
   document.getElementById('flash').style.height = height+'px'; void(0); 
   }

   else if(/MSIE[\/\s](\d+\.\d+)/.test(navigator.userAgent)) { 
   document.getElementById('anim').width = width; void(0); 
   document.getElementById('anim').height = height; void(0); 
   }
   
   else {
   document.getElementById('flash').style.width = width+'px'; void(0); 
   document.getElementById('flash').style.height = height+'px'; void(0); 
   }
  
   	// Add cookies
	var concatenation = id_games+"|"+width+"|"+height;
	/*setCook("size",concatenation,365);*/
	
	var pathname=location.pathname;
	var myDomain=pathname.substring(0,pathname.lastIndexOf('/')) +'/';
	var date_exp = new Date();
	date_exp.setTime(date_exp.getTime()+(3650*24*3600*1000));
	// Ici on définit une durée de vie de 365 jours
	SetCookie(id_games,concatenation,date_exp,myDomain);

}




function Fullsize(anim,id_games) {

   var navigateur = navigator.userAgent.toLowerCase();

   if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){
	var screenwidth = screen.availWidth;
	var screenheight = screen.availHeight;
	  var screenwidth = parseInt(screenwidth,10)+ parseInt(-250,10);
	  var screenheight = parseInt(screenheight,10)+ parseInt(-333,10);
   document.getElementById('flash').style.width = screenwidth+'px'; void(0); 
   document.getElementById('flash').style.height = screenheight+'px'; void(0); 
   }

   else if(/MSIE[\/\s](\d+\.\d+)/.test(navigator.userAgent)) { 
	var screenwidth = screen.availWidth;
	var screenheight = screen.availHeight;
	  var screenwidth = parseInt(screenwidth,10)+ parseInt(-250,10);
	  var screenheight = parseInt(screenheight,10)+ parseInt(-293,10);
   document.getElementById('anim').width = screenwidth; void(0); 
   document.getElementById('anim').height = screenheight; void(0); 
   }
   
   else {
	var screenwidth = screen.availWidth;
	var screenheight = screen.availHeight;
	  var screenwidth = parseInt(screenwidth,10)+ parseInt(-250,10);
	  var screenheight = parseInt(screenheight,10)+ parseInt(-233,10);
   document.getElementById('flash').style.width = screenwidth+'px'; void(0); 
   document.getElementById('flash').style.height = screenheight+'px'; void(0); 
    var navig = navigator.userAgent;
  }

	// Add cookies
	var concatenation = id_games+"|"+screenwidth+"|"+screenheight;
	var pathname=location.pathname;
	var myDomain=pathname.substring(0,pathname.lastIndexOf('/')) +'/';
	var date_exp = new Date();
	date_exp.setTime(date_exp.getTime()+(3650*24*3600*1000));
	// Ici on définit une durée de vie de 365 jours
	SetCookie(id_games,concatenation,date_exp,myDomain);

}
