

function load_elements(a){ 
	document.getElementById(a).style.display='block';
}



/******************************************************************
				PRELOAD IMAGES
*******************************************************************/
function preload_images(){
  
		
		
}


/******************************************************************
				FICHE DE JEUX
*******************************************************************/
function urldecode (str) {
    // http://kevin.vanzonneveld.net
    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: AJ
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +      input by: travc
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Lars Fischer
    // +      input by: Ratheous
    // +   improved by: Orlando
    // %        note 1: info on what encoding functions to use from: http://xkr.us/articles/javascript/encode-compare/
    // *     example 1: urldecode('Kevin+van+Zonneveld%21');
    // *     returns 1: 'Kevin van Zonneveld!'
    // *     example 2: urldecode('http%3A%2F%2Fkevin.vanzonneveld.net%2F');
    // *     returns 2: 'http://kevin.vanzonneveld.net/'
    // *     example 3: urldecode('http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a');
    // *     returns 3: 'http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a'
    
    var hash_map = {}, ret = str.toString(), unicodeStr='', hexEscStr='';
    
    var replacer = function (search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };
    
    // The hash_map is identical to the one in urlencode.
    hash_map["'"]   = '%27';
    hash_map['(']   = '%28';
    hash_map[')']   = '%29';
    hash_map['*']   = '%2A';
    hash_map['~']   = '%7E';
    hash_map['!']   = '%21';
    hash_map['%20'] = '+';
    hash_map['\u00DC'] = '%DC';
    hash_map['\u00FC'] = '%FC';
    hash_map['\u00C4'] = '%D4';
    hash_map['\u00E4'] = '%E4';
    hash_map['\u00D6'] = '%D6';
    hash_map['\u00F6'] = '%F6';
    hash_map['\u00DF'] = '%DF';
    hash_map['\u20AC'] = '%80';
    hash_map['\u0081'] = '%81';
    hash_map['\u201A'] = '%82';
    hash_map['\u0192'] = '%83';
    hash_map['\u201E'] = '%84';
    hash_map['\u2026'] = '%85';
    hash_map['\u2020'] = '%86';
    hash_map['\u2021'] = '%87';
    hash_map['\u02C6'] = '%88';
    hash_map['\u2030'] = '%89';
    hash_map['\u0160'] = '%8A';
    hash_map['\u2039'] = '%8B';
    hash_map['\u0152'] = '%8C';
    hash_map['\u008D'] = '%8D';
    hash_map['\u017D'] = '%8E';
    hash_map['\u008F'] = '%8F';
    hash_map['\u0090'] = '%90';
    hash_map['\u2018'] = '%91';
    hash_map['\u2019'] = '%92';
    hash_map['\u201C'] = '%93';
    hash_map['\u201D'] = '%94';
    hash_map['\u2022'] = '%95';
    hash_map['\u2013'] = '%96';
    hash_map['\u2014'] = '%97';
    hash_map['\u02DC'] = '%98';
    hash_map['\u2122'] = '%99';
    hash_map['\u0161'] = '%9A';
    hash_map['\u203A'] = '%9B';
    hash_map['\u0153'] = '%9C';
    hash_map['\u009D'] = '%9D';
    hash_map['\u017E'] = '%9E';
    hash_map['\u0178'] = '%9F';
    hash_map['\u00C6'] = '%C3%86';
    hash_map['\u00D8'] = '%C3%98';
    hash_map['\u00C5'] = '%C3%85';
 
    for (unicodeStr in hash_map) {
        hexEscStr = hash_map[unicodeStr]; // Switch order when decoding
        ret = replacer(hexEscStr, unicodeStr, ret); // Custom replace. No regexing
    }
    
    // End with decodeURIComponent, which most resembles PHP's encoding functions
    ret = decodeURIComponent(ret);
 
    return ret;
}

var jeux = {

	reloadGame: function(){
	  if($("#bloc_jeu").attr("class") == 'enlarge')
    {
      iframe_jeu.twElargir(false);
    }
		src = $("#iframe_jeu").attr("src");
		$("#iframe_jeu").attr("src", src);
		$("#messageReload").hide();
		$("#messagePersiste").show();
	},
	reloadGameB3W: function(url){
		//src = $("#iframe_jeu").attr("src");
		$("#iframe_jeu").attr("src", urldecode(url));
	},
	
	saveGame: function( id ){		
		$.ajax({
			type: "POST",
			data: {id: id},
			url:"/member/save-game-ajax/",
			dataType: "json",
		  	success: function(data){
	  			if( !data.isValid)	_class = "error";
		  		else 				_class = "success";
				
	  			if( data.isValid){
	  				$("#favorisAjouter").hide();
	  				$("#favorisRemove").show();
	  				$("#favoris").attr("class", "favoris-border-moins");
	  			}
	  			$("#mess_add_to_favoris").html(data.mess).attr("class", _class).show();

		 	}
		});
	},
	
	removeSaveGame: function( id ){		
		
		$.ajax({
			type: "POST",
			url:"/member/delete-game-ajax/",
			data: {id: id} ,
			dataType: "json",
		  	success: function(data){
	  			if( !data.isValid)	_class = "error";
		  		else 				_class = "success";
	  			
	  			if( data.isValid){
	  				$("#favorisRemove").hide();
	  				$("#favorisAjouter").show();
	  				$("#favoris").attr("class", "favoris-border-plus");
	  			}
	  			
	  			$("#mess_add_to_favoris").html(data.mess).attr("class", _class).show();				
		    }
		 });		
	}	
	
};

/******************************************************************
				GESTION DES FAVORIS
*******************************************************************/

var favoris = {
	HOMEPAGE: "7",
	JEUX 	: "0",
	PROFILE : "1",
	ARTICLE : "2",
	PARAM	: "3",
	COMMENTS: "4",
	CASINO:	  "5",
	EDITEUR:  "6",
	ANNUAIRE: "7",
	STATISTIQUE_CASINO: "9"
};

var img_up = new Image();
img_up.src = '/public/img/layout/img-bt-fleche-up.gif';
img_up.width = 25;
img_up.height = 25;

var img_down = new Image();
img_down.src = '/public/img/layout/img-bt-fleche-down.gif';
img_down.width = 25;
img_down.height = 25;


var member = {
	showData: function( html, id){
		$(".nav_interface .bt_on").removeClass("bt_on");

	
		$("#page_interface").slideUp("normal", function(){
			$(this).html(html).slideDown();
			loadSifr();
			$("#" + id).addClass("bt_on");
		});
	
	},

	toggleExpandable: function(){

		$('#content_interface').toggle(function(){
				loadSifr();
			if( $(this).is(":hidden") == true)
			{
				$("#openCloseExpandable").html(img_down);
			}else{			  		
				$("#openCloseExpandable").html(img_up);
			}
		});
	},
	
	loadInterface: function(){
		if( $('#content_interface').html().length == 0 ){
			$("#loader-member").css("visibility", "visible");
			$.ajax({
				type: "POST",
				url:"/member/load-interface-ajax/",
				dataType: "json",
			  	success: function(data){
			  		if( !data.isValid )
			  			$("#logged_mess").html(data.mess ).attr("class","error");
			  		else{
			  			$('#content_interface').html(data.html).ready( function(){
                $("#typeFavoris").val( favoris.HOMEPAGE );
			  				$("#bt-inter-homepage").addClass("bt_on");
			  				member.toggleExpandable();
				  			$("#loader-member").css("visibility", "hidden");	
			  			});			  			
			  		}
			 	}
			});
		}else
			member.toggleExpandable();
		

	},
	setNoNewsletter: function(){	
		$.ajax({
			type: "POST",
			url:"/member/set-no-newsletter/",
			dataType: "json",
		  	success: function(data){
		  		member.showHomepage(true); 		
		 	  }
		});
		return false;
	},
	
  subscribeToNewsletter: function(){	
		$.ajax({
			type: "POST",
			url:"/member/subscribe-to-newsletter/",
			dataType: "json",
		  	success: function(data){
		  		member.showHomepage(true); 		
		 	  }
		});
		return false;
	},
	
	showDoYouKnow: function(){	
		$.ajax({
			type: "POST",
			url:"/member/do-you-know/",
			dataType: "json",
		  	success: function(data){
		  		if( data.display )
		  			$("#doYouKnow").html(data.mess);		  		
		 	  }
		});
		return false;
	},
	
	showHomepage: function(force){
		if( $("#typeFavoris").val() == favoris.HOMEPAGE && $("#page_interface").is(":hidden") == false && !force  ){
			return false;
		}
	
		$("#loader-member").css("visibility", "visible");
		$.ajax({
			type: "POST",
			url:"/member/show-homepage-ajax/",
			dataType: "json",
		  	success: function(data){
		  		if( !data.isValid )
		  			$("#logged_mess").html(data.mess ).attr("class","error");
		  		else
		  			member.showData( data.html, "bt-inter-homepage" );
		  		
		  		$("#typeFavoris").val( favoris.HOMEPAGE );
		  		$("#loader-member").css("visibility", "hidden");
		  		
		 	}
		});
		return false;
	},
	
	showArticle: function(){
		if( $("#typeFavoris").val() == favoris.ARTICLE && $("#page_interface").is(":hidden") == false  ){
			return false;
		}		

		$("#loader-member").css("visibility", "visible");
		$.ajax({
			type: "POST",
			url:"/member/show-article-ajax/",
			dataType: "json",
		  	success: function(data){
		  		if( !data.isValid )
		  			$("#logged_mess").html(data.mess ).attr("class","error");
		  		else
		  			member.showData( data.html, "bt_inter_articles" );
		  		
	  			$("#typeFavoris").val( favoris.ARTICLE );
	  			$("#loader-member").css("visibility", "hidden");
		 	}
		});
		return false;
	},
	
	showComments: function(){
		if( $("#typeFavoris").val() == favoris.COMMENTS && $("#page_interface").is(":hidden") == false  ){
			$("#memberInfo").slideUp();
			return false;
		}		

		$("#loader-member").css("visibility", "visible");
		$.ajax({
			type: "POST",
			url:"/member/show-comments-ajax/",
			dataType: "json",
		  	success: function(data){
		  		if( !data.isValid )
		  			$("#logged_mess").html(data.mess ).attr("class","error");
		  		else
		  			member.showData( data.html, "bt_inter_comments" );
		  		
	  			$("#typeFavoris").val( favoris.COMMENTS );
	  			$("#loader-member").css("visibility", "hidden");
		 	}
		});
		return false;
	
	},	
	
	
	
	showAnnuaireMarked: function(type, id_bouton ){		
		if(	$("#typeFavoris").val() == (favoris.ANNUAIRE + type) && $("#page_interface").is(":hidden") == false ){
			return false;	
		}

		$("#loader-member").css("visibility", "visible");
		
		$.ajax({
			type: "POST",
			url: "/member/show-annuaire-marked-ajax/",
			data: {type : type},
			dataType: "json",
		  	success: function(data){
		  		if( !data.isValid )
		  			$("#logged_mess").html(data.mess ).attr("class","error");
		  		else
		  			member.showData( data.html, id_bouton );
		  		
		  		$("#typeFavoris").val(favoris.ANNUAIRE + type);
		  		$("#loader-member").css("visibility", "hidden");
		 	}
		});
		return false;
	},	
	
	showGames: function(type, cat, isInsideChange, meta_title ){
	
		
		if(	$("#typeFavoris").val() == (favoris.JEUX + type) && $("#page_interface").is(":hidden") == false && isInsideChange == undefined){
			return false;
		}

		$("#loader-member").css("visibility", "visible");
	
		if( meta_title ==null )
			meta_title = "";
		
		if( type == "saved"){
			url = "/member/show-saved-games-ajax/";
			id = "bt_inter_jeuxfav";
			listIdAllGame = $("#e_listIdAllGame_saved").val();

			
		}else if( type == "marked"){
			url = "/member/show-marked-games-ajax/";
			id = "bt_inter_jeuxnotes";
			listIdAllGame = $("#e_listIdAllGame_marked").val();

		}

		if( listIdAllGame)	param = {meta_title: meta_title, categorie : cat, listIdAllGame: listIdAllGame };
		else			param = {meta_title: meta_title, categorie : cat };
		
		$.ajax({
			type: "POST",
			url: url,
			data: param,
			dataType: "json",
		  	success: function(data){
		  		if( !data.isValid )
		  			$("#logged_mess").html(data.mess ).attr("class","error");
		  		else{
		  			member.showData( data.html, id );
		  		
		  			
		  		}
		  		$("#typeFavoris").val( favoris.JEUX + type );
		  		$("#loader-member").css("visibility", "hidden");
		 	}
		});
		return false;
	},
	
	showStatistiqueSite: function( categorie ){

		if(	$("#typeFavoris").val() == favoris.STATISTIQUE_CASINO && $("#page_interface").is(":hidden") == false ){
			return false;
		}
		
		if( categorie == null)	categorie = $('#input_games_cat').val();


		$("#loader-member").css("visibility", "visible");
		$.ajax({
			type: "POST",
			url:"/member/show-statistique-site-ajax/",
			dataType: "json",
			data: { categorie: categorie },
		  	success: function(data){
		  		if( !data.isValid )
		  			$("#logged_mess").html(data.mess ).attr("class","error");
		  		else
		  			member.showData( data.html, "bt_inter_caz" );
		  		
		  		$("#typeFavoris").val( favoris.STATISTIQUE_CASINO );
		  		$("#loader-member").css("visibility", "hidden");
		  		
		 	}
		});
		return false;
	},

	showParam: function(){
		if( $("#typeFavoris").val() == favoris.PARAM && $("#page_interface").is(":hidden") == false  )
			return false;
		
		
		$("#loader-member").css("visibility", "visible");
		$.ajax({
			type: "POST",
			url:"/member/show-param-ajax/",
			dataType: "json",
		  	success: function(data){
		  		if( !data.isValid )
		  			$("#logged_mess").html(data.mess ).attr("class","error");
		  		else
		  			member.showData( data.html, "bt_inter_param" );

	  			$("#typeFavoris").val( favoris.PARAM );
	  			$("#loader-member").css("visibility", "hidden");
		 	}
		});
		return false;
		
	},
	
	showProfil: function(){		
		
		if( $("#typeFavoris").val() == favoris.PROFILE && $("#page_interface").is(":hidden") == false  ){
			$("#memberInfo").slideUp();
			return false;
		}		
		$("#loader-member").css("visibility", "visible");
		
		$.ajax({
			type: "POST",
			url:"/member/show-profile-ajax/",
			dataType: "json",
		  	success: function(data){
		  		if( !data.isValid )
		  			$("#logged_mess").html(data.mess ).attr("class","error");
		  		else{
		  			member.showData( data.html, "bt_inter_modif" );
	  					
		  			$("#typeFavoris").val( favoris.PROFILE );
		  		}
		  		$("#loader-member").css("visibility", "hidden");

		 	}
		});
		return false;
	},
	
	changePassword: function(){
		
		data = {newsletter: $("#newsletter").is(':checked') ,newPass: escape( $("#newPass").val()), newPass2: escape( $("#newPass2").val()) };
		$("#loader-member").css("visibility", "visible");
		$.ajax({
			type: "POST",
			url:"/member/change-password-ajax/",
			dataType: "json",
			data: data,
		  	success: function(data){
		  		if( !data.isValid )		member.showMessageAction("error", data.mess);
		  		else		  			member.showMessageAction("success", data.mess);		  			
		  		
		  		$("#loader-member").css("visibility", "hidden");
		 	}
		});
	},
	
	deleteGameSaved: function( id ){
		$.ajax({
			type: "POST",
			url:"/member/delete-game-ajax/",
			data: {id: id} ,
			dataType: "json",
		  	success: function(data){
				if(data.isValid ){
					$("#m_jeux_" + id).hide();
					member.showMessageAction("success", data.mess);
				}
				else
					member.showMessageAction("error", data.mess);
		    }
		 });
	
	},
	
	addGameToFavorite: function( id, refresh ){
		$.ajax({
			type: "POST",
			url:"/member/save-game-ajax/",
			data: {id: id} ,
			dataType: "json",
		  	success: function(data){
  				if(data.isValid ){
  					$("#m_jeux_" + id).hide();
  					member.showMessageAction("success", data.mess);
  					if(refresh)
  					 member.showTabFavHomepage();
  				}
  				else
  				{
  					member.showMessageAction("error", data.mess);
  		    }
        }
		 });
	
	},	

	showTabFavHomepage : function(){
  	$.ajax({
			type: "POST",
			url:"/member/show-tab-fav-homepage/",
			dataType: "json",
		  	success: function(data){
		  	  if( !data.isValid )
		  			$("#logged_mess").html(data.mess ).attr("class","error");
		  		else
		  		{
		  	   $("#showTabFavHomepage").html( data.html);
		  	   loadSifr();
		  	  }
				}
		 });
  },
  
  showEmptyLobby : function(div){
  	$.ajax({
			type: "POST",
			url:"/member/show-empty-lobby/",
			dataType: "json",
		  	success: function(data){
		  	  if( !data.isValid )
		  			$("#logged_mess").html(data.mess ).attr("class","error");
		  		else
		  		{
		  	   $("#"+div).append( data.html);
		  	   loadSifr();
		  	  }
				}
		 });
  },
  
	showDescription: function( type, langue, idGame, version, typeProfil, pseudo){

		idPreview = "#descr_" + type + "_" + langue + "_" + idGame + "_" + version + "_" + typeProfil;
		if( !$(idPreview).is(":hidden")  ){
			$(idPreview).slideUp();
		}else{		
			$.ajax({
				type: "POST",
				url:"/ajax/preview-article/",
				data: {provenance: 'editor', type: type, id: idGame, version: version, pseudo: pseudo, langue: langue },
				dataType: "json",
			  	success: function(data){
						$(idPreview ).slideUp( function(){
							$(idPreview + " div div").html(data.html);
							$(this).slideDown();
						});
				}
			});
		}
	},
	
	showMessageAction: function(className, mess){
		$("#page_interface > .mess").html(mess).decHTML().attr("class", "mess " + className).show();
	}

};
/******************************************************************
				LOGIN
*******************************************************************/

var login = {
	showLostPassword: function(){
		$("#login-wrapper").slideUp("normal",function(){
			$("#mdp-wrapper").slideDown();
		});
	},
	
	showSignIn: function(){
		$("#mdp-wrapper").slideUp("normal",function(){
			$("#login-wrapper").slideDown();
		});
	},
	
	showLogin: function(){
		$("#mdp-wrapper").slideUp("normal",function(){
			$("#login-wrapper").slideDown("normal", function(){
				$("#txtLogin").focus();
			});		
		});
	},	
	
	sendPassword: function(){	
		$("#load_mdpPerdue").css("visibility", "visible");
		
		$.ajax({
			type: "POST",
			url:"/member/lost-password-ajax/",
			data: {compte: escape($("#mdp_login").val()) },
			dataType: "json",
		  	success: function(data){
		  		if( !data.isValid )
		  			$("#mdp_mess").html(data.mess ).attr("class","error");
		  		else{
		  			$("#mdp_mess").html(data.mess ).attr("class","success");
		  		}
		  		$("#load_mdpPerdue").css("visibility", "hidden");

		 	}
		});
	},
	
	sendActivationCode: function(){	
		$("#newActivationCode").css("visibility", "hidden");
		$.ajax({
			type: "POST",
			url:"/member/send-activation-code-ajax/",
			data: {},
			dataType: "json",
	  	success: function(data){
	  		$("#newActivationCode").html('<span class="couleur">'+data.mess+'</span>' );
	  		$("#newActivationCode").css("visibility", "visible");
	 	  }
		});
	},
 
  
	login: function(){
		$("#load_login").css("visibility", "visible");
		
		
    
		data = {
			login: 				escape( $('#txtLogin').val() ), 
			pass: 				escape( $('#txtPassword').val() ), 
			rememberme: 		$('#rememberMe').attr("checked"),
			refreshWhenLogin: 	$('#refreshWhenLogin').val()
		};
		for( l = 0; l< lg.length ; l++)
    {
		  ($("#bt_"+lg[l]).attr("href"))? data['url_'+lg[l]] = $("#bt_"+lg[l]).attr("href"): data['url_'+lg[l]] = "";
		}
		
		$.ajax({
			type: "POST",
			url:"/member/login-ajax/",
			data: data,
			dataType: "json",
		  	success: function(data){
		  		if( !data.isValid ){
		  			$("#loginErreur").html(data.error ).attr("class","error");
			  		$("#load_login").hide();
		  		}else{
		  			if( data.refresh == true){
		  				window.location.reload();
		  			}else{
			  			$("#top_barre").slideUp("normal", function(){			  				
			  				$("#feedback").slideUp();//Cas du login si l'on se trouve sur une fiche de jeux
			  				$(this).html(data.html).slideDown("normal");
			  			});	
		  			
		  				if( data.typeCompte == 2 || data.typeCompte == 0) 		  		
		  					$(".webmaster").attr("class", "webmaster").fadeIn();
		  				
		  				$("#load_login").css("visibility", "hidden");
		  			}
		  			window.setTimeout('member.loadInterface()',500);
		  			/*
            if($("#form_inscription"))
		  			{
              $("#form_inscription").slideUp(function(){
		  				  $("#form_inscription").html('');
		  			 });
		  			}
		  			*/
		  		}

		 	}
		});
	},
	
	toggleFocusValue: function(obj, defaut){
		if(obj.value == defaut) { obj.value="";}
	},
	
	toggleBlurValue: function(obj, defaut){
		if(obj.value == "") {obj.value = defaut;}
	}

};

/******************************************************************
				REGISTRATION
*******************************************************************/
var registration = {
	
	register:function(){
		
		data = {
			pseudo:	escape($("#pseudo").val()),
			email:	escape($("#email").val()),
			newsletter:	escape($("#newsletter").val())			
		}
		
		$.ajax({
			type: "POST",
			url:"/inscription/register/",
			data: data,
			dataType: "json",
		  	success: function(data){
	  			
		  		if( !data.isValid ){
		  			mess_pseudo = data.errorPseudo;
		  			mess_email 	= data.errorEmail;
		  			registration.traiter_erreur(mess_pseudo, "pseudo");
		  		  registration.traiter_erreur(mess_email, "email");
		  			
		  		}else{
		  			mess_pseudo = "";
		  			mess_email 	= "";
		  			$("#form_inscription").slideUp(function(){
		  				$("#form_inscription").html('<p>'+ data.mess + '</p>').slideDown();
		  			});
		  			
		  			$('#txtLogin').val($('#pseudo').val());
		  			$('#txtPassword').val(data.pass);
		  			//pageTracker =_gaq._getAsyncTracker('UA-1569386-1');
            //pageTracker._trackPageview('/register-ok.html');
		  			setTimeout(function(){login.login();window.scrollTo(0,-200);},4000);
		  			
		  		}
		  		
		  		
	  			

				
		 	}
		});		
	},
	check:function(champ){
		

		data = {
			pseudo:	escape($("#pseudo").val()),
			email:	escape($("#email").val())
		}
		$('#'+champ+'_info').html('<img src=\'/public/img/layout/load_ajax_register.gif\' />');
		$.ajax({
			type: "POST",
			url:"/inscription/check/",
			data: data,
			dataType: "json",
		  	success: function(data){
	  			mess_pseudo = data.errorPseudo;
	  			mess_email 	= data.errorEmail;

          if(champ=='email')
          {
            registration.traiter_erreur(mess_email, "email",'');		
            if(mess_pseudo=='')
              $('#pseudo_info').html('');
          }if(champ=='pseudo')
		  		{
            registration.traiter_erreur(mess_pseudo, "pseudo",mess_email)
            if(mess_email=='')
              $('#email_info').html('');
          }
		 	}
		});		
	},
	traiter_erreur: function(mess, cat, mess2){
		if( mess != ""){
		  $('#'+cat+'_info').html(mess);
		  $('#'+cat+'_info').show();
		  $('#input_'+cat).removeClass('ok');
			$('#input_'+cat).addClass('erro');
			if(cat=='email')
			 if(mouseY > $('#form_inscription').position().top && mouseY < ($('#form_inscription').position().top+$('#form_inscription').height())){document.frm.email.focus();}
			if(cat=='pseudo' &&  mess2 == '')
			 if(mouseY > $('#form_inscription').position().top && mouseY < ($('#form_inscription').position().top+$('#form_inscription').height())){document.frm.pseudo.focus();}
			else
       if(mouseY > $('#form_inscription').position().top && mouseY < ($('#form_inscription').position().top+$('#form_inscription').height())){document.frm.email.focus();}
		}else if(  mess2 == ''){
		  $('#'+cat+'_info').html('');
			$('#input_'+cat).removeClass('erro');
			$('#'+cat+'_info').show();
			$('#input_'+cat).addClass('ok');
			if(cat=='email')
			 registration.traiter_edit();
		}
	},

  traiter_edit: function(){
    if(!$('#input_pseudo').hasClass('ok'))
      document.frm.pseudo.focus();
    var email =	escape($("#email").val());
		if(email!='')
		{
		  data = {
  			email:	email
  		}
      $.ajax({
			type: "POST", 
			url:"/inscription/edit/",
			data: data,
			dataType: "json",
		  	success: function(data){
		      $("#edit").html(data.msg+' <span><a href="#" onClick="$(\'#input_email\').removeClass(\'ok\');$(\'#input_email\').addClass(\'erro\');$(\'#email_info\').html(\''+data.messEdit+'\');document.frm.email.focus();return false;">'+data.ceLien+'</a></span>');
		  	}
		  });
    }

	}


};



/******************************************************************
				AWB
*******************************************************************/
var awb = {

	check:function(r){
		

		data = {
			pseudo:	escape($("#pseudo_awb"+r).val()),
			email:	escape($("#email_awb"+r).val())
		}
		$.ajax({
			type: "POST",
			url:"/inscription/awbcheck/",
			data: data,
			dataType: "json",
		  	success: function(data){
	  			mess_pseudo = data.errorPseudo;
	  			mess_email 	= data.errorEmail;	
          if(mess_pseudo=='')
          {
            $('#awb_err_pseudo'+r).html('').removeClass('error');
            $("#pseudo_awb"+r).removeClass('error');
          }else
          {
            $('#awb_err_pseudo'+r).html(mess_pseudo).addClass('error');
            $("#pseudo_awb"+r).addClass('error');
          }if(mess_email=='')
          {
            $('#awb_err_mail'+r).html('').removeClass('error');
            $("#email_awb"+r).removeClass('error');
          }else
          {
            $('#awb_err_mail'+r).html(mess_email).addClass('error');
            $("#email_awb"+r).addClass('error');
          }
          if(mess_pseudo=='' && mess_email=='')
            document.forms['awbForm'+r].submit();
		 	}
		});		
	},
  
  displayPopup: function( type, name ){
   if(!type) type = '';
		$.ajax({
			type: "POST",
			url:"/ajax/awb/",
			data: {type: type,name: name} ,
			dataType: "html",
		  	success: function(data){
            $('body').prepend(data);
	  			  $('#popup_close.awb').bind('click',function(){$('#popup_bloc.awb').fadeOut();});
            $('#popup_bloc.awb').fadeIn(3000);
		 	}
		});
	},
  
  displayInscriptionPopup: function( type, name ){
   if(!type) type = '';
		$.ajax({
			type: "POST",
			url:"/ajax/awb-inscription/",
			data: {type: type,name: name} ,
			dataType: "html",
		  	success: function(data){
            $('body').prepend(data);
	  			  $('#popup_close.inscription').bind('click',function(){$('#popup_bloc.inscription').fadeOut();});
            $('#popup_bloc.inscription').fadeIn(3000);
		 	}
		});
	}


};


/******************************************************************
				PAGE CONTACT
*******************************************************************/
var contact = {
	
	send:function(){
		
		data = {
			nom:		escape($("#nom").val()),
			email:		escape($("#email").val()),
			sujet: 		escape($("#sujet").val()),
			message:	escape($("#message").val())
			
		}
		
		$.ajax({
			type: "POST", 
			url:"/basic-page/send-mail-contact-ajax/",
			data: data,
			dataType: "json",
		  	success: function(data){
	  			$(".error").hide().attr("class", "error hidden");
	  			
		  		if( !data.isValid ){
		  			mess_nom = data.errorNom; mess_email = data.errorEmail;	mess_sujet = data.errorSujet; mess_message = data.errorMessage;
		  			
		  			contact.traiter_erreur(mess_nom, 		"nom");
  		  		contact.traiter_erreur(mess_email, 		"email");
  		  		contact.traiter_erreur(mess_sujet, 		"sujet");
  		  		contact.traiter_erreur(mess_message, 	"message");
		  		}else{
		  			mess_nom = ""; mess_email = ""; mess_sujet = ""; mess_message = "";
		  			
		  			$("#bg_int").css('height',$("#bg_int").height());
            $("#bloc_contact").slideUp(function(){
		  				$("#form_contact").html( data.html );
		  				$("#form_contact").addClass("ok");
		  				$("#texte_contact_txt").html('');
		  				$("#bloc_contact").css('background-image','url(/public/img/layout/bg-contact-ok.jpg)');
		  				$("#texte_pinup").html( data.pinup );
              $("#bloc_contact").slideDown();
		  			});
		  			
		  		}
		  		
		  		
	  			

				
		 	}
		});		
	},
	
	traiter_erreur: function( mess, cat){
		if( mess != ""){
			//$("#label_" + cat).hide();
			$("#error_" + cat).html( "<br />"+mess ).show();
		}else{
			$("#error_" + cat).html( "" ).hide();
			//$("#label_" + cat).show();
		}
	},

  traiter_edit: function(){
    var email =	escape($("#email").val());
		if(email!='')
		  $("#edit").html('<span><a href="#" onClick="document.frm.email.focus();return false;">EDIT</a> - </span>'+email);
	}

};



/******************************************************************
				COMMENT
*******************************************************************/
var comment = {
	register: function(){
		param = {
			idGame: $("#messageIdGame").val(),
			email:  escape( $("#messageEmail").val() ),
			texte:  escape( $("#messageTexte").val() ) 
			
		}

		$.ajax({
			type: "POST",
			url:"/ajax/register-message/",
			data: param,
			dataType: "json",
		  	success: function(data){
		  		if( !data.isValid ){
		  			$("#messageError").slideUp( function(){ $(this).html(data.mess).slideDown(); } );
		  			//$("#messageError").slideDown();
		  		}else{
		  			$("#feedback").slideUp(function(){
		  				$(this).html(data.html).slideDown();
		  				$("#messagePersiste").hide();
		  			
		  			});
		  		}
		 	}
		});	
	
	},
	
	displayMessage: function( id ){
		$.ajax({
			type: "POST",
			url:"/ajax/show-message/",
			data: {idGame: id} ,
			dataType: "json",
		  	success: function(data){
		  			$("#feedback").html(data.html).slideToggle();

		 	}
		});
	}

};


/******************************************************************
				NO DISPO
*******************************************************************/

var nodispo = {
	displayPopup: function( id, display, type ){
   if(!type) type = '';
	 if($('#popup_bloc.cas'+id+type).html()==null)
   {
		$.ajax({
			type: "POST",
			url:"/ajax/no-dispo/",
			data: {idSite: id,type: type} ,
			dataType: "html",
		  	success: function(data){
            $('body').prepend(data);
	  			  $('#popup_close.cas'+id+type).bind('click',function(){$('#popup_bloc.cas'+id+type).fadeOut();popupSwfCheck.show();});
            if(display)
              $('#popup_bloc.cas'+id+type).fadeIn(3000);
		 	}
		});
	 }else{
    popupSwfCheck.hide();
    $('#popup_bloc.cas'+id+type).fadeIn(3000);
   }
	}

};


var popupSwfCheck = {
  hide: function(){
    if($("#iframe_jeu").length>0)
    {
      if(document.getElementById('iframe_jeu').contentWindow.switchSwf(true))
        document.getElementById('iframe_jeu').contentWindow.switchSwf();
    }
  },
  show: function(){
    if($("#iframe_jeu").length>0)
    {
      if(!document.getElementById('iframe_jeu').contentWindow.switchSwf(true))
        document.getElementById('iframe_jeu').contentWindow.switchSwf();
    }
  }
}
    
/******************************************************************
				TOP BANNER / TOP SITE
*******************************************************************/

var topBanner = {
	display: function(){
	 $.ajax({
			type: "POST",
			url:"/ajax/top-banner/",
			data: {} ,
			dataType: "html",
		  	success: function(data){
            $('body').prepend(data);
            $('#topBanner').slideDown(2000);
		 	}
		});
	},
  
  close: function(){
    $('#topBanner').slideUp('slow',function(){
      $.ajax({
  			type: "POST",
  			url:"/ajax/top-banner/",
  			data: {close:true} ,
  			dataType: "html",
  		  	success: function(data){    
  		 	}
  		});
    });
  },
  
  clic: function(href){
    $.ajax({
  			type: "POST",
  			url:"/ajax/top-banner/",
  			data: {clic:true} ,
  			dataType: "html",
  		  	success: function(data){
            window.location.href = href;
  		 	}
  		});
  }
};

var topSiteC = {
	clic: function(site, href){
	 $.ajax({
			type: "POST",
			url:"/ajax/top-site-clic/",
			data: {site:site} ,
			dataType: "html",
		  	success: function(data){
            window.location.href = href;
		 	}
		});
	}
};
/******************************************************************
				Social BLOC
*******************************************************************/

var socialBloc = {
	
	sendToFriend: function( idGame ){
		param = {
			idGame: 		idGame,
			email: 			$("#sEmail").val(),
			friendEmail:	$("#sFriendEmail").val(),
			name:			$("#sName").val(),
			urlGame:		$("#urlPage").val(),
			imgGame:		$("#imgGame").val(),
			captcha:		$("#sCaptcha").val(),
			nomGame:		$("#sNomGame").val()
		};
		
		$.ajax({
			type: "POST",
			url:"/ajax/send-to-friend/",
			data: param,
			dataType: "json",
		  	success: function(data){
					if( !data.isValid )
						$("#sMess").html( data.mess ).attr("class","error");
					else
						$("#sMess").html( data.mess ).attr("class","success");
						
		 	}
		});
	
	},
	
	updateLink: function(idGame, urlBase){
		$.ajax({
			type: "POST",
			url:"/ajax/update-iframe-link/",
			data: { idGame: idGame, url: urlBase, width: $("#s_width").val() },
			dataType: "json",
		  	success: function(data){
				if( data.isValid ){
					$("#s_socialMess").attr("class", "success").html(data.mess);
					$("#socialIframe").fadeOut( function(){
							$(this).val(data.html).fadeIn();
					});
				}else{
					$("#s_socialMess").attr("class", "error").html(data.mess);
				}
						
		 	}
		});
	}
	
};

var ajaxLoad = {
	
		
	//Récupère la div login "top_barre"
	getLoginHtml: function( urls ){
		$.ajax({
			type: "POST", 
			data: {site: true, urls:urls},
			url:"/widget/get-login-html/",
			dataType: "html",
		  	success: function(data){
	  				  		
				$(data).appendTo('#top_barre');
				
		 	}
		});		
	}
};



jQuery.download = function(url, data, method){
  	if( url && data ){ 
  		data = typeof data == 'string' ? data : jQuery.param(data);
  		var inputs = '';
  		jQuery.each(data.split('&'), function(){ 
  			var pair = this.split('=');
  			inputs+='<input type="hidden" name="'+ pair[0] +'" value="'+ pair[1] +'" />'; 
  		});
  		jQuery('<form action="'+ url +'" method="'+ (method||'post') +'">'+inputs+'</form>')
  		.appendTo('body').submit().remove();
  	};
  };

jQuery.fn.encHTML = function() {
  return this.each(function(){
    var me   = jQuery(this);
    var html = me.html();
    me.html(html.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;'));
  });
};
 
jQuery.fn.decHTML = function() {
  return this.each(function(){
    var me   = jQuery(this);
    var html = me.html();
    me.html(html.replace(/&amp;/g,'&').replace(/&lt;/g,'<').replace(/&gt;/g,'>'));
  });
};
 
jQuery.fn.isEncHTML = function(str) {
  if(str.search(/&amp;/g) != -1 || str.search(/&lt;/g) != -1 || str.search(/&gt;/g) != -1)
    return true;
  else
    return false;
};
 
jQuery.fn.decHTMLifEnc = function(){
  return this.each(function(){
    var me   = jQuery(this);
    var html = me.html();
    if(jQuery.fn.isEncHTML(html))
      me.html(html.replace(/&amp;/g,'&').replace(/&lt;/g,'<').replace(/&gt;/g,'>'));
  });
};
