 $("#loading-popup").bind("ajaxSend", function(){
   $(this).show();
 }).bind("ajaxComplete", function(){
   $(this).hide();
 });

function changeTheme(theName) {

	var theStyle = $("link[rel='stylesheet']");
	theStyle.attr({href:'/include/style/'+theName+'/style.css'});

}


function rezizeTabs(id) {
TheElement = $('#'+id+' .tabs');
var sommeTabs = 0;
var currentWidth = TheElement.innerWidth();

theTabs = $('#'+id+' .tabs a');
var TheFirstTabEnTrop = '';

theTabs.each(function(i,e) {
	var value = $(this).innerWidth();
	sommeTabs = sommeTabs + value;
	if(sommeTabs > currentWidth) {
		TheFirstTabEnTrop = $(this).attr('id');
		return;
	}
}
);

if(sommeTabs > currentWidth) {

	// On chope le dernier tabs avant exces !
		alert(TheFirstTabEnTrop);
		$('#'+TheFirstTabEnTrop).hide();





}
}


function switchPartnerBann(bouton) {
	var path = '/img/boutons/';
	var theImg = $("#PartnerBan");
	theImg.attr("src", path+bouton);
}

function CreatePopUp(name,title) {
if ($('#popup-'+name).length < 1 ) { 
if(!title) title= '';
var PopupCode = '<div id="popup-'+name+'" class="popup" style="display:none;"><div id="popupbar-'+name+'" class="popupbar"><div style="background-color: transparent;"><a href="#null" onclick="hidePopUp(\''+name+'\');"><img src="/img/icons/cross.png" alt="Close" /></a></div>'+title+'</div><div id="popupcontent-'+name+'" class="popupcontent"></div></div>';
	$('#boxes').append(PopupCode);
	$('#popup-'+name).draggable({ handle: '#popupbar-'+name, opacity: 0.75});
}
return;

}

function popup(donnees_json) {
	var data = new Array();
	data["title"] = 'New Dialog';	// Titre de la boite
	data["name"] = 'alertbox';		// nom (id de la boite), pour éviter des doublons
	data["url"] = '';				// Le nom du fichier à executer en Ajax
	data["data"] = new Array();			// Objet JSON, avec des variables à faire passer lors de la requere AJAX
	data["html"] = '';				// Ou bien du code HTML pour la boite
	data["width"] = 450;			// Largeur de la boite
	data["height"] = 250;			// Hauteur de la boite
	

	//var json = JSON.parse(donnees_json);

//$('#popupcontent-'+data["name"]).load(data["url"], data["data"], function() { showPopUp('', data["width"], data["height"], data["name"]);

	$.each(donnees_json, function(k, v)
	{
		data[k] = v;
	});
	
	data["data"]["PopupName"] = data["name"];
	
	if ($('#popup-'+data["name"]).length < 1 ) {
		CreatePopUp(data["name"], data["title"]);

		if(data["url"] != '') {
			data["url"] = '/include/action/'+data["url"]+'.php';
			$.post(data["url"], data["data"], function(r) {
				
				content = r.split(':://::');
				
				$('#popupcontent-'+data["name"]).html(content[0]);
				if(content[1]) {
				eval(content[1]);	
					
				}
				showPopUp('', data["width"], data["height"], data["name"]);
			
			
			});
			return;
		}

		//$('#popupcontent-'+data["name"]).html();
		showPopUp(data["html"], data["width"], data["height"], data["name"]);
		return;
	}
}

function sendpopupform(donnees_json) {
	var data = new Array();
	data["name"] = 'dialogbox';
	data["url"] = '';
	data["form"] = '';
	data["action"] = '';
	data["div"] = '';
	
	$.each(donnees_json, function(k, v)
	{
		data[k] = v;
	});
	
	var values = $('#'+data["form"]).serialize();
	//alert(data["div"]);
	if(data["div"]) {
		$('#'+data["div"]).load('/include/action/'+data["url"]+'.php', {action: data["action"], values: values}, function() { hidePopUp(data["name"]); });
	} else {
		$.post('/include/action/'+data["url"]+'.php', {values: values}, function() {hidePopUp(data["name"]);});
	}
}



function ShowBox(divid,checkid) {
    if (document.getElementById(checkid).checked==true) {document.getElementById(divid).style.display='none';}
    else {document.getElementById(divid).style.display='block';}
}
function ShowAndHideElement(divid) {
    if ($("#"+divid).css('display') == 'block') {
    $("#"+divid).css('display','none');
    } else {
    $("#"+divid).css('display','block');
    }
}

function SwitchElement(divid,divid2) {
    if (document.getElementById(divid).style.display=='block' && document.getElementById(divid2).style.display=='none') {
    document.getElementById(divid).style.display='none';
	document.getElementById(divid2).style.display='block';
	return;
    } else if (document.getElementById(divid2).style.display=='block' && document.getElementById(divid).style.display=='none') {
    document.getElementById(divid).style.display='block';
	document.getElementById(divid2).style.display='none';
	return;
    }

    if (document.getElementById(divid2).style.display=='block' && document.getElementById(divid).style.display=='none') {
    document.getElementById(divid2).style.display='none';
	document.getElementById(divid).style.display='block';
	return;
    } else {
    document.getElementById(divid2).style.display='block';
	document.getElementById(divid).style.display='none';
	return;
    }
}


/* Requête Ajax pour choper l'avatar du memnbre quand il veut se loguer */
function GetLoginAvatar() {
	var pseudo = $('#LoginPseudoInput').val();
	var LeDiv = $('#LoginAvatar');
	LeDiv.load('/include/action/get_login_avatar.php?pseudo='+pseudo);
}

/* Requête Ajax pour vérifier la disponibilité d'un pseudo */
function VerifPseudo(pseudo, item) {
	
	$.get('/include/action/misc_functions.php', { act: 'login_is_available', item: item, pseudo: encodeURIComponent(pseudo) }, function (r) {
		data = r.split(':::');
		$('#VerifPseudoSpan_'+item).html(data[0]);
		

		if(data[1] > 0) {
			$('#VerifPseudoSpan_'+item).attr('class', 'is_valid');			
			$('#VerifPseudoSpan_'+item).prepend('<img src="/img/icons/accept.png" alt=""> ');		
		} else {
			$('#VerifPseudoSpan_'+item).attr('class', 'no_valid');
			$('#VerifPseudoSpan_'+item).prepend('<img src="/img/icons/cross.png" alt=""> ');		
		}		
		

		
		
	});
	

}

function checkForm(form_id) {
		
		theForm = '#'+form_id;
	
		if($(theForm+' .no_valid').size() > 0) {
			alert('Un champs est mal rempli!');
					return false;
		}
		else 
		{
					return false;
		}
		

		

		
		//alert($(theForm+' .no_valid').size());			
}

function VerifPassword(element1, element2) {
	if(element1 != element2) {
		$("#VerifPasswordCheck").html('Wrong password');
		$('#VerifPasswordCheck').prepend('<img src="/img/icons/cross.png" alt=""> ');			
		
	} else {
		$("#VerifPasswordCheck").html('OK!');
		$('#VerifPasswordCheck').prepend('<img src="/img/icons/accept.png" alt=""> ');			
	}
}

function VerifMail(val) {

    var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;

	if(pattern.test(val)) {
		$("#VerifMailCheck").html('OK!');
		$('#VerifMailCheck').prepend('<img src="/img/icons/accept.png" alt=""> ');		
} else {
		$("#VerifMailCheck").html('Bad mail address!');
		$('#VerifMailCheck').prepend('<img src="/img/icons/cross.png" alt=""> ');	
			
	}


}
/* Fonction d'affigache d'un popup */
function showPopUp(text,largeur,hauteur,name,title) {


    if ($('#popupcontent-'+name).length < 1 ) { CreatePopUp(name,title)}
	lePopUp = $("#popup-"+name);
    if(text != '') { $('#popupcontent-'+name).html(text); } // fixe le texte dans l'infobulle
	
	//$('#popupcontent-'+name).dialog({ title: title, minWidth: 600, width: 600, modal: true});

	if(lePopUp.css('display') == 'none') {
	lePopUp.css('top','50%');
	lePopUp.css('left','50%');
    lePopUp.css('width',largeur + 'px');
    lePopUp.css('height', hauteur + 'px');
    largeur2 = largeur / 2;
    hauteur2 = hauteur / 2;
    lePopUp.css('marginTop', '-' +hauteur2+ 'px');
    lePopUp.css('marginLeft', '-' +largeur2+ 'px');
    lePopUp.fadeIn('slow')
   }

}

function hidePopUp(name) {
	lePopUp = $("#popup-"+name);
	//alert(lePopUp.css('height'));
	
	lePopUp.html('');
	//LePopUp.draggable('destroy');
	lePopUp.remove();
}

function ToolTips(content, e) {
LeDiv = $("#toolTipBox");
LeDiv.html(content);
	if(LeDiv.css('display') == 'none') {
	LeDiv.show();
	CurrentTitle = content;
	} else {
	LeDiv.hide();
	}
}





function showLoading() {
    var LoadingBulle = $("#loading-popup");
	if(LoadingBulle.css('display') == 'none') {
	LoadingBulle.show();
	} else {
	LoadingBulle.hide();
	}
}

function SwitchStatRub(id) {
var LeDiv = $(id);
TabArray = $('Content').select('[class="TabElement"]');
TabArray.each(Element.hide);
LeDiv.show();
}

function showHelp(help) {
	var name = 'helppopup';
	if ($('#popup-'+name).length < 1 ) {
	CreatePopUp(name);
	}
	$('#popupcontent-'+name).load('/help.php', { help: help}, function() {showPopUp('', 400, 300,name)});
}


function showGameLinks(id) {
	var name = 'gamelinks';
	if ($('#popup-'+name).length < 1 ) {
	CreatePopUp(name);
	}
	$('#popupcontent-'+name).load('/download/inc_links.php', { id: id}, function() {showPopUp('', 400, 300,name)});
}
/*
function GetMemberInfos(id,pseudo) {
	var name = 'memberprofil';
	if ($('#popup-'+name).length < 1 ) {
	CreatePopUp(name,'Infos membre : '+pseudo);
	}
	$('#popupcontent-'+name).load('/myguardiana/get_member_infos.php', { id: id}, function() {showPopUp('', 300, 135,name)});
}
*/


function CreateStaticPop(id) {
	if ($('#static_pop-'+id).length < 1 ) {

	var PopupCode = '<div id="static_pop-'+id+'" class="static_popup">gfgfgfg</div>';
	$('#Wrapper').after(PopupCode);

	}

}

function GetMemberInfos(id) {;
	$('#static_popup').load('/myguardiana/get_member_infos.php', { id: id}, function() {  });
}


function sendChatBox(texte) {
	if(texte == '') { alert("Vous n'avez pas tapé de texte !"); return false;}
	/*texte = texte.stripTags();*/
	/*if(texte.length > 255) { alert("Il y a trop de caractères !"); return false;}*/
	/*new Ajax.Updater($('chatBoxContent'), '/Action/sendChatBox.html',  { onComplete: function() {$('chatBoxFormMess').value = '';}, method: 'post', parameters: { texte: texte}})*/
	$('#chatBoxContent').load('/Action/sendChatBox.html',
	{texte: texte},
	function() {
		$('#chatBoxFormMess').val('');
		}
	);
	}

function refreshChatBox() {
	$('#chatBoxContent').load('/Action/sendChatBox.html');
}

function switchTop5(id,console) {
 /*new Ajax.Updater($('Top5Content'), '/myguardiana/inc_top5/top5_incl_in_profile.php',  { method: 'post', parameters: { console: console, id: id}})*/
   $("#Top5Content").load("/myguardiana/inc_top5/top5_incl_in_profile.php", { console: console, id: id });

}

function SwitchScreenshots(gameid,console,page) {
	/*new Ajax.Updater('ScreensContent', '/database/process_screens.php',{ method: 'get', parameters: { id: gameid, console: console, page: page } });*/

var TheDiv = $('#ScreensContent');
var AnimSpeed = 200;
TheDiv.fadeTo(AnimSpeed, 0, function() {
TheDiv.load('/database/process_screens.php?id='+gameid+'&console='+console+'&page='+page, function() {
TheDiv.fadeTo(AnimSpeed, 1);
});
});

}

function SwitchSagaTitles(serie, div) {
var TheDiv = $('.sagas_'+serie);
var TheDiv2 = $('#saga_'+serie+'_div_'+div);
TheDiv.hide();
TheDiv2.show();
}


/* Switch Commentaires */
function switchComments(box_id, comment_type, id, page) {
		$('#'+box_id).load('/Comments.html', { box_id: box_id, comment_type: comment_type, id: id, page: page });
} 

/* Switch des notes de membres*/

function switchMembersEvaluations(gameid, page) {
		$('#MembersEvaluationBox').load('/MDG-Database/MembersNotes.html', { id: gameid, page: page });
}

function switchReviews(console,filter) {
		$('#ReviewsList').load('/reviews/md/incl_reviews.php?console', { console: console, filter: filter });
}



function showGameIntro(insert,title,console) {
	var name = 'gameintro';
	if(!$('popup-'+name)) {
	CreatePopUp(name,'Vidéo introduction de jeu');
	$('#popupcontent-'+name).html('<div class="TextCenter">'+insert+'<br /><img src="/games/img/icon_console_'+console+'.png" alt="" /> '+title+'</div>');
	showPopUp('',345,300,name);
}
}

function bbcode(editor,tagdeb,tagfin){
LeTextArea = $('#'+editor);

function getSelection(){
		if(!!document.selection)
			return document.selection.createRange().text;
		else if(!!LeTextArea.setSelectionRange)
			return LeTextArea.value.substring(LeTextArea.selectionStart,LeTextArea.selectionEnd);
		else
			return false;
}

function replaceSelection(newtext) {
var scroll_top = LeTextArea.scrollTop;
		if(!!document.selection){
			LeTextArea.focus();
			var range = (LeTextArea.range) ? LeTextArea.range : document.selection.createRange();
			range.text = newtext;
			range.select();
		}else if(!!LeTextArea.setSelectionRange){
			var selection_start = LeTextArea.selectionStart;
			LeTextArea.value = LeTextArea.value.substring(0,selection_start) + newtext + LeTextArea.value.substring(LeTextArea.selectionEnd);
			LeTextArea.setSelectionRange(selection_start + newtext.length,selection_start + newtext.length);
		}
		LeTextArea.focus();
		LeTextArea.scrollTop = scroll_top;
}
replace = replaceSelection(tagdeb + getSelection() + tagfin);
return replace;
}


function chgOngletStatut(id) {
var LeLink = $(id);
TabArray = $('Content').select('[class="toggle"]');
TabArray.each(function(s) {
	if(s.hasClassName('toggle')) {
	s.removeClassName('toggle'); }
}
);
LeLink.addClassName('toggle');
}

function SwitchOngletBox(id,classe) {
var name = classe+'_'+id;
var LeDiv = $(name);

TabArray = $('Content').select('[class~="'+classe+'"]');
TabArray.each(Element.hide);
LeDiv.show();

}


function SwitchLittlePopup(id,classe) {
var name = classe+'_'+id;
var LeDiv = $('#'+name);
var LeLink = $('#'+name+'_Link');


// On verifie si le popup n'est pas déjà ouvert en vérifiant s'il possde la classe toggle
var isVisible = LeDiv.is(':visible');



if(isVisible) { // Si le div est visible, on le cache
	LeDiv.slideToggle(100, function() {LeLink.removeClass('AHighlight');});

} else { // Sinon, on cache tous les autres, et on affiche notre Div
TabArray = $('.'+classe+':visible');

TabArray.slideToggle(100, function() {
	LinkArray = $("a[id^='"+classe+"_']");
	LinkArray.removeClass('AHighlight');

	});

	LeDiv.slideToggle(100, function() {
		LeLink.addClass('AHighlight');
	});




}
}


$(document).ready(function()    {
    // Indicateur de chargement sur image portant la classe 'loading';
    // Jay Salvat - http://blog.jaysalvat.com
    $(".loading").each(function() {
        var img = $(this);
        // on met de côté la source de l'image originale
        var src = img.attr("src");
        // on la remplace par un pixel blanc
        img.attr("src", "/img/pixel.gif");
        // on créé une nouvelle image
        $("<img>")
         // on attend qu'elle soit chargée
         .bind("load", function() {
             // lorsque c'est le cas, on la fait disparaitre doucement
            img.fadeOut("slow", function() {
                // puis on lui réattribue l'image originale
                img.attr("src", src)
                // et on la réaffiche doucement.
                   .fadeIn();
            });
        })
        // on attribue l'image originale
        .attr("src", src);
    });
});



function toggleFiche(onglets_id,id) {
$LesFiches = $('#'+onglets_id+' .fiche');
LeDiv = $('#'+onglets_id+'_fiche_'+id);

$LesFiches.hide();
LeDiv.show();

TheOnglets = $('#'+onglets_id+' .toggle');
TheOnglets.removeClass('toggle');
TheOnglet = $('#'+onglets_id+'_onglet_'+id);
TheOnglet.addClass('toggle');
}

function switchVersionFiche(id) {
$LesFiches = $('.versionFiche');
LeDiv = $('#v'+id);

$LesFiches.hide();
LeDiv.show();
/*
TheOnglets = $('#'+onglets_id+' .toggle');
TheOnglets.removeClass('toggle');
TheOnglet = $('#'+onglets_id+'_onglet_'+id);
TheOnglet.addClass('toggle');
*/
}




/*
 * jQuery UI Autocomplete HTML Extension
 *
 * Copyright 2010, Scott González (http://scottgonzalez.com)
 * Dual licensed under the MIT or GPL Version 2 licenses.
 *
 * http://github.com/scottgonzalez/jquery-ui-extensions
 */
(function( $ ) {

var proto = $.ui.autocomplete.prototype,
initSource = proto._initSource;

function filter( array, term ) {
var matcher = new RegExp( $.ui.autocomplete.escapeRegex(term), "i" );
return $.grep( array, function(value) {
return matcher.test( $( "<div>" ).html( value.label || value.value || value ).text() );
});
}

$.extend( proto, {
_initSource: function() {
if ( this.options.html && $.isArray(this.options.source) ) {
this.source = function( request, response ) {
response( filter( this.options.source, request.term ) );
};
} else {
initSource.call( this );
}
},

_renderItem: function( ul, item) {
return $( "<li></li>" )
.data( "item.autocomplete", item )
.append( $( "<a></a>" )[ this.options.html ? "html" : "text" ]( item.label ) )
.appendTo( ul );
}
});

})( jQuery );


/* gggggggggg */




function updateSetSelectForAddReview(console, game) {
	$('#SelectForAddReview').load('/tools/reviews/ajax.php', {console: console, game: game});
}



/*
function AddMiniatureDialog(game_id) {
	var name = 'addminiature';
	var title="Nouvelle miniature pour ce jeu";
	if ($('#popup-'+name).length < 1 ) {
	CreatePopUp(name,title);
	$('#popupcontent-'+name).load('/database/ajax.php', {action: 'add_miniature', game_id: game_id}, function() {showPopUp('', 450, 75, name);});
}
}

*/


function AddGameCollecInMDGD(id) {
	var values = $('#VersionAddForm_'+id).serialize();
	$.post('/include/action/mdgd.php', {action: 'addGameInCollecViaMDGD', id: id, values: values}, function(d) {alert('Jeu ajouté'); });
}




/* Fonction gestion notes */
function EditPressDialog(game_id) {
	var name = 'editnote';
	var title="Modification d'une note";
	if ($('#popup-'+name).length < 1 ) {
	CreatePopUp(name,title);
	$('#popupcontent-'+name).load('/include/action/press.php', {action: 'editnote', id: game_id}, function() {showPopUp('', 550, 350, name);});
}
}

function UpdatePress(id) {
	var name = 'editnote';
	var values = $('#PressNoteForm_'+id).serialize();
	$('#PressNoteBox').load('/include/action/press.php', {action: 'updatenote', id: id, values: values}, function() {hidePopUp(name);});
}

/*

function AddPressDialog(game_id) {
	var name = 'addnote';
	var title="Ajout d'une note de presse";
	if ($('#popup-'+name).length < 1 ) {
	CreatePopUp(name,title);
	$('#popupcontent-'+name).load('/include/action/press.php', {action: 'addnote', game_id: game_id}, function() {showPopUp('', 550, 350, name);});
}
}
*/

/* Fonction gestion MDG */
function MDGD_DeleteVersion(version_id) {
if (confirm("Supprimer cette version ?")) {
	$.post('/tools/database/action.php', {n_act: 'delete_version', n_id: version_id}, function(data) { 
	alert(data);
	$('#v'+version_id).remove(); });
	return true;
	} else {
		return false;
	}
}


function AddPress(id) {
	var name = 'addnote';
	var values = $('#PressNoteAddForm').serialize();
	alert(values);
	$('#PressNoteBox').load('/include/action/press.php', {action: 'add2note', id: id, values: values}, function() { hidePopUp(name);});
}

function DeletePress(id, game_id) {
if (confirm("Supprimer cette note de presse ?")) {
	$('#PressNoteBox').load('/include/action/press.php', {action: 'delnote', id: id, game_id: game_id});
	return true;
	} else {
		return false;
	}
}

function DeleteLink(id, game_id) {
if (confirm("Supprimer ce lien Internet ?")) {
	$('#LinksBox').load('/include/action/links.php', {action: 'dellink', id: id, game_id: game_id});
	return true;
	} else {
		return false;
	}
}


/* Gestion des codes (GG / AR) */
function DeleteCode(id) {
if (confirm("Supprimer ce code ?")) {
	$.post('/include/action/cheats.php', {action: 'DelCodeDB', id: id}, function() {$("#GameCode_"+id).remove();});
	return true;
	} else {
		return false;
	}
}

/* Gestion des astuces */
function DeleteCheat(id) {
if (confirm("Supprimer cette astuce ?")) {
	$.post('/include/action/cheats.php', {action: 'DelTipsDB', id: id}, function() {$("#Tips_"+id).remove();});
	return true;
	} else {
		return false;
	}
}


/* Fonctions pour la gestion des commentaires */
function Commentaire_Delete(comment_id, type) {
	if (confirm("Supprimer ce commentaire ?")) {
		$.post('/include/action/comments.php?action=delete', { n_id: comment_id, n_type: type }, function(data) {
		if(data.length > 0) { alert(data); } else {
		theBox = $('#CommentBox_'+comment_id);
		theBox.fadeOut('slow', function() {theBox.remove();});
		}
		});
		return true;
	} else {
		return false;
	}
}

function Commentaire_Edit(comment_id, type) {
	$('#CommentBox_'+comment_id+'_TextBox').load('/include/action/comments.php?action=edit', {n_id: comment_id, n_type: type});
}

function Commentaire_Update(comment_id, type, text) {

		$('#CommentBox_'+comment_id+'_TextBox').load('/include/action/comments.php?action=update', { n_id: comment_id, n_type: type, n_text: text });

}

/* Fonctions Others Reviews */
function OthersReviewsMiniatureEdit(id_review, id_box) {
	$.post('/include/action/EditReviews.php', { action: 'add_miniature', review_id: id_review, box_id: id_box },
	function(r) { var array = r.split("|||"); $('#'+id_box).html(array[0]); eval(array[1]); $('#'+id_box).append(array[2]);}
	);	
}

function OthersReviewsCoversEdit(id_review, id_box) {
	$.post('/include/action/EditReviews.php', { action: 'add_other_cover', review_id: id_review, box_id: id_box }, 
	function(r) { var array = r.split("|||"); $('#'+id_box).html(array[0]); eval(array[1]); $('#'+id_box).append(array[2]);}
	);	
}

function OthersReviewsCoversUpdate(id_review, id_box, id_cropper) {
	var data = $('#'+id_cropper+'_form').serialize();
	$('#'+id_box).load('/include/action/EditReviews.php', { action: 'update_other_cover', values: data, review_id: id_review, box_id: id_box });	
}


function sendFlashUpdate() {
	
		var theText = $('#udpateFlashInput').val();

		$('#udpateFlashBox').load('/include/action/misc_functions.php?act=sendFlashUpdate', { n_text: theText });

}





/* Edition des listes de jeux */
function updateAssociatedGameSelectList(console, select_name) {
	$('#AssociatedGamesSelectBox_'+select_name).load('/tools/database/associated_select.php', { console: console, name: select_name });
}

function addAssociatedGames(id, titre, select_name) {

	var el1 = $('#AssociatedGamesInput_'+select_name).val();

	var string = '(^[,]?)'+id+'($[,]?)';
	if(id != '' && !el1.match(string)) {
		$('#AssociatedGamesList_'+select_name).append('<li title="'+id+'"><a href="#null" onclick="deleteAssociatedGames($(this).parent(), \''+select_name+'\');"><img src="/img/icones/del.gif" alt="" title="Supprimer le titre" /></a> '+titre+'</li>');
		updateAssociatedGameInput(select_name);
	}
}

function deleteAssociatedGames(li, select_name) {
	li.remove();
	updateAssociatedGameInput(select_name);
}

function updateAssociatedGameInput(select_name) {
	var theli = $('#AssociatedGamesList_'+select_name+' li');

	var theArray = new Array();
	var i = 0;
	theli.each(
	function(e) {

			theArray[i] = $(this).attr('title');
			i++;	
	}
		);
	var finaldata = theArray.join(',');
	
	
	$('#AssociatedGamesInput_'+select_name).val(finaldata);
}





/* MyGreatLegend */
function MyGreatLegend(options) {
	
	/*
	options are :
		TextContener : L'id du div ou span à insérer le texte
		TextSource : la class où choper le texte dans l'attribut rel
		
	
	*/
	var data = new Array();
	$.each(options, function(k, v)
	{
		data[k] = v;
	});	
	
	ToGet = $('.'+data['TextSource']);
	ToComplete = $('#'+data['TextContener']);

	ToGet.mouseover(function() {
		ToComplete.html($(this).attr('rel'));
	});
		
	ToGet.mouseout(function() {
		ToComplete.html('&nbsp;');
	});	
	
	
	
}




function uploadifySerialize(form_id, upload_id){ //all inputs from details div
$.opt = {};

$('#'+form_id+' input, #'+form_id+' textarea').each(function(){

$.opt[$(this).attr('name')] = $(this).attr('value');

$('#'+upload_id).uploadifySettings('scriptData', $.opt); //passing options as predeclared namespace
});
}

function switchMDGDList(console, letter, letter2, page, country, view) {
	var theDiv = $('div#MDGD_Box');

	theDiv.load('/include/action/mdgd.php', {action: 'switchMDGList', console: console, page: page, letter: letter, letter2: letter2, country: country, view: view},
	function() {

		shp = theDiv.offset().top + 100;
		$('html,body').animate({'scrollTop': shp}, 200);
		var encodedState = console+','+letter+','+letter2+','+page+','+country+','+view;
		var newLocation = '' + "#mdgd-" + encodedState;
		document.location = newLocation;

	
	});





}




/* Fonctiona  a executer au chargement */
function startPageJS() {

var TheToolTips = $('[rel="tooltip"]');
	TheToolTips.tooltip( {
	opacity: 1,
	predelay: 250,
	position: 'bottom right'
	});

	

	
/*$('a[rel="tooltip"]').mouseover( function() { });
*/
  
var myFile = document.location.toString();

if (myFile.match('#ong_[a-z]+')) { // the URL contains an anchor

  // click the navigation item corresponding to the anchor
  var myAnchor = myFile.split('#ong_')[1];
  // On récupe l'id du systeme d'onglet auquel appartient le tab souhaité
  var OngletsId = $('.ong_'+myAnchor+':parent').attr('id');
  var TheId = OngletsId.split('_')[0];
  var theTab = OngletsId.split('_')[2];
	toggleFiche(TheId, theTab);
}

if (myFile.match('#mdgd-')) { // the URL contains an anchor

  // click the navigation item corresponding to the anchor
  var myAnchor = myFile.split('#mdgd-')[1];

  // On obtien une série speraé par virugles
  var myValues = myAnchor.split(',');
  switchMDGDList(myValues[0], myValues[1], myValues[2], myValues[3], myValues[4], myValues[5]);
}


/*
	TheToolTips = $('[rel="tooltip"]');
	TheToolTips.mouseover(function() {ToolTips($(this).attr('title'), $(this)); $(this).attr('title', ''); });
	TheToolTips.mouseout(function() {ToolTips('', $(this)); $(this).attr('title', CurrentTitle);});
      */
    ThePartners = $('[class*="partnerButton-"]');


	ThePartners.mouseover(function() { theButton = $(this).attr('class').match(' partnerButton-.+'); id_button = theButton[0].split('-'); switchPartnerBann(id_button[1]); });
	 ThePartners.mouseout(function() { switchPartnerBann('nopartner.gif'); });
	

	
	$("#menuLeftSearchForm").autocomplete({
		source: function(request, response) {
			$.ajax({
				url: "/include/action/searching.php",
				dataType: "json",
				data: {
					value: request.term,
					type: $('#MenuFormSearch input:radio:checked').val()
				},
				success: function(data) {
					//map the data into a response that will be understood by the autocomplete widget
					response($.map(data, function(item) {
						return {
							label: item.console + item.title,
							value: item.title,
							link: item.link
						}
					}));
				}
			});
			},
			minLength: 4 ,
			html: true,
			select: function(event, ui) {
				window.location = ui.item.link;
			},
			
			});

		


	/* This is basic - uses default settings */
	
	$(".fancybox_img").fancybox();
	$(".fancybox_modal").fancybox();

	$('.ext_link').click(function() { window.open($(this).attr('href')); return false; });
		

}

// Password strength meter
// This jQuery plugin is written by Firas Kassem [2007.04.05] and modified by Amin Rajaee [2009.07.26]
// Firas Kassem  phiras.wordpress.com || phiras at gmail {dot} com
// Amin Rajaee  rajaee at gmail (dot) com

// for more information : http://phiras.wordpress.com/2007/04/08/password-strength-meter-a-jquery-plugin/

var shortPass = 'Too Short Password'
var badPass = 'Week; Use letters & numbers'
var goodPass = 'Medium; Use special charecters'
var strongPass = 'Strong Password'
var sameAsUsername = 'Password is the same as username.'


function passwordStrength(password,username)
{
    score = 0 
    
    //password < 4
    if (password.length < 4 ) { return shortPass }
    
    //password == username
    if (password.toLowerCase() == username.toLowerCase()) return sameAsUsername
    
    //password length
    score += password.length * 4
    score += ( checkRepetition(1,password).length - password.length ) * 1
    score += ( checkRepetition(2,password).length - password.length ) * 1
    score += ( checkRepetition(3,password).length - password.length ) * 1
    score += ( checkRepetition(4,password).length - password.length ) * 1

    //password has 3 numbers
    if (password.match(/(.*[0-9].*[0-9].*[0-9])/))  score += 5 
    
    //password has 2 sybols
    if (password.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/)) score += 5 
    
    //password has Upper and Lower chars
    if (password.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/))  score += 10 
    
    //password has number and chars
    if (password.match(/([a-zA-Z])/) && password.match(/([0-9])/))  score += 15 
    //
    //password has number and symbol
    if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([0-9])/))  score += 15 
    
    //password has char and symbol
    if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([a-zA-Z])/))  score += 15 
    
    //password is just a nubers or chars
    if (password.match(/^\w+$/) || password.match(/^\d+$/) )  score -= 10 
    
    //verifing 0 < score < 100
    if ( score < 0 )  score = 0 
    if ( score > 100 )  score = 100 
    
    if (score < 34 )  return badPass 
    if (score < 68 )  return goodPass
    return strongPass
}



function passwordStrengthPercent(password,username)
{
    score = 0 
    
    //password < 4
    if (password.length < 4 ) { return 0 }
    
    //password == username
    if (password.toLowerCase()==username.toLowerCase()) return 0
    
    //password length
    score += password.length * 4
    score += ( checkRepetition(1,password).length - password.length ) * 1
    score += ( checkRepetition(2,password).length - password.length ) * 1
    score += ( checkRepetition(3,password).length - password.length ) * 1
    score += ( checkRepetition(4,password).length - password.length ) * 1

    //password has 3 numbers
    if (password.match(/(.*[0-9].*[0-9].*[0-9])/))  score += 5 
    
    //password has 2 sybols
    if (password.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/)) score += 5 
    
    //password has Upper and Lower chars
    if (password.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/))  score += 10 
    
    //password has number and chars
    if (password.match(/([a-zA-Z])/) && password.match(/([0-9])/))  score += 15 
    //
    //password has number and symbol
    if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([0-9])/))  score += 15 
    
    //password has char and symbol
    if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([a-zA-Z])/))  score += 15 
    
    //password is just a nubers or chars
    if (password.match(/^\w+$/) || password.match(/^\d+$/) )  score -= 10 
    if (score > 100) return 100
  return (score)
 
}

// checkRepetition(1,'aaaaaaabcbc')   = 'abcbc'
// checkRepetition(2,'aaaaaaabcbc')   = 'aabc'
// checkRepetition(2,'aaaaaaabcdbcd') = 'aabcd'

function checkRepetition(pLen,str) {
    res = ""
    for ( i=0; i<str.length ; i++ ) {
        repeated=true
        for (j=0;j < pLen && (j+i+pLen) < str.length;j++)
            repeated=repeated && (str.charAt(j+i)==str.charAt(j+i+pLen))
        if (j<pLen) repeated=false
        if (repeated) {
            i+=pLen-1
            repeated=false
        }
        else {
            res+=str.charAt(i)
        }
    }
    return res
}


