function _(clef){
	// Si la traduction existe
    try{
    	// Récupération de la chaine correspondant à la clef
   		var str = i18n[clef];
        // Si la traduction n'existe pas
    	if (str === undefined){
        	//Renvoi la clef
            str = clef;
    		// Dans le cadre du développement,
            // une notification peut être ajouté.
    		window.console.log("Traduction  non trouvée pour la clef: "+clef);
        };
    
   	    // Renvoi la chaine traduite    
        return str;
    }catch(e){
        //cSi il y a un problème (fichier non chargé par exemple),
        // renvoi la clée
    	return clef;
    };
};

function redirection(nouvelle_url){
   location.href = nouvelle_url;
}

$(document).ready(function(){
	
	$("#form_login").submit( function() { 
		var bool = true;
  		
  		$("#form_login :input").each(function(){
  			var valeur = $(this).val();
		    var nom = $(this).attr("name");
				
			if (nom == 'login'){
				if (valeur.length == 0) bool = false;
			}
			if (nom == 'password'){
				if (valeur.length == 0) bool = false;
			}
  		});
		if (bool == false) alert('ERREUR');
		return bool;
	});
	
	
	$("#form_recherche").submit( function() { 
		var bool = true;
		
		$("div#info").empty();
  		$("div#info").removeClass();
		$("div#info").addClass("hidden");
		
		$("#form_recherche :input").each(function(){
  			var valeur = $(this).val();
		    var nom = $(this).attr("name");
		    
		    if (nom == 'recherche'){
		    	if (valeur.length < 2){
		    		bool = false;
  					$("#info").append(_("recherche_non_conforme")+"<br />");
  				}
		    }
		});    
 
  		if (bool == false){
  			$("div#info").removeClass();
			$("div#info").addClass("display");
		}	
  		
		return bool;
	});
	
	
	$("#content .pointer").mouseover(function(){
		$(this).css("color","#FF8C00");
	});
	
	$("#bottom .pointer").mouseover(function(){
		$(this).css("color","#FFFFFF");
	});
	
	$(".pointer").mouseout(function(){
		$(this).css("color", "#333333");
	});
	
	
	
	
	
	$("select#selectionJeu").change(function ()  {
      	var id = $(this).val();
      	if (id == 'ALL'){
      		location.href = 'index.php5?c=listeJeu&a=byPlateForme';
      	}else{
      		location.href = 'index.php5?c=jeu&id='+id;
      	}
    });
    
    
    /**
     * Création du forum sur les pages de jeux si le forum n'existe pas
     */
    $(".form_forum a").click(function ()  {
      	$(this).parents("form").submit();
    });
    
       
    $('.form_forum').ajaxForm({
        dataType: 'json',
	   	success: function(data) {
    		if (data.success == 0){
    			location.href = 'index.php5?c=forum&id='+data.idForum;
    		}		
    	}
    });
    
    
	/**
	 * popup video
	 */    
    $(".video").click(function (e)  {
  		var pos = $(this).offset();
    	var url = "index.php5?c=video&a=_display";
    	var array = $(this).attr("id").split("_");
    	var idVideo = array[1];
    	data = "idVideo="+idVideo;
    	vgrJS.showPopup(url,data,pos);
    });
    
    
    /**
	 * popup imagePreuve
	 */    
    $(".imagePreuve").click(function (e)  {
  		var pos = $(this).offset();
    	var url = "index.php5?c=preuve&a=_displayImage";
    	var array = $(this).attr("id").split("_");
    	var idMembre = array[1];
    	var idRecord = array[2];
    	data = "idMembre="+idMembre+"&idRecord="+idRecord;
    	vgrJS.showPopup(url,data,pos);
    });
    
    /**
     * popup demande de preuve
     */
    $("img.imageDemande").click(function (e)  {
     	var pos = $(this).offset();
     	var url = "index.php5?c=preuve&a=_demande";
     	var array = $(this).attr("id").split("_");
    	var idMembre = array[1];
    	var idRecord = array[2];
 
      	$(this).parents(".recordMembre").toggleClass("highlight");
      	data = "idRecord="+idRecord+"&idMembre="+idMembre;
      	vgrJS.showPopup(url,data,pos);
      	

      	$('#form_demande').ajaxForm({
            dataType: 'json',
    		beforeSubmit: function(formData) { 
        		vgrJS.showInfoDiv(false);
    		},
    		success: function(data) {
				
				if (data.success == 0){
    				vgrJS.closePopup();
    				var id = "imageDemande_"+data.idMembre+"_"+data.idRecord;
    				$("#"+id).unbind();
    				$("#"+id).removeClass("pointer");
    				$("#"+id).attr("src",vgrJS.config.imageDir+"/png/carre_orange.png");
    				$("#"+id).attr("alt",_("etatRecord1"));
    				$("#"+id).attr("title",_("etatRecord1"));
      			}
    		}
        });
    });  
    
    
    $("#info").clone().prependTo(".content_large");
    $("#info").remove();
    
    
	$("#" + vgrJS.config.popupAlerteDivName + " .fermer").click(function (e)  {
		vgrJS.showAlerteDiv(false);
	});
    
	$("#" + vgrJS.config.popupAlerteDivName).hide();
	
	$(".jTagEditor").jTagEditor();
	
	$("button.btn_spoiler").next().hide();
	
	$("button.btn_spoiler").click( function(e) {
		$(this).next().toggle();
	});
	
});





