/*
 * Fonction in_array(booleen) test si un element existe dans un tableau
 * JavaScript Argument Element : Element recherché dans Tableau Argument Tableau :
 * Tableau dans lequel on cherche Element Argument argStrict : Vérifie
 * strictement la présence de l'élément en utilisant la triple égalitée Retourne
 * Vrai si l'élément a été trouvé, et Faux si l'élément n'a pas été trouvé
 */
function in_array(element, tableau, argStrict) {
	var key = '', strict = !!argStrict; 
	if (strict){
		for (key in tableau) {
			if (tableau[key] === element) {
				return true;
			}
		}
	}else{
		for (key in tableau) {
			if (tableau[key] == element) {
				return true;
			}
		}
	}
	return false;
}

/*
 * Fonction verifchamp test les élément d'un formulaire Argument id : id de
 * l'élément formulaire Argument callback : Callback appelé après vérification
 * du formulaire Argument tabignor : Tableau listant le nom des champs à ignorer
 * Appel la fonction Callback si le formulaire a bien été vérifié, sinon génère
 * un message d'alerte
 */
// TODO : vérifier email
function verifchamp(id, callback, tabignor, tabobl){
	var num				= 0;
	var i				= 0;
	var champmanquant	= new Array();
	var strchampmanquant= '';
	var maform			= document.getElementById(id);
	//var champ_totaltab 	= new Array();
	var champ_ok		= 0;
	var erreur			= 0;
	
	//if(!tabignor){
		// si aucun champ n'est facultatif
		//var ok = 0;
	//}else{
		// je compte 'ok' les champs facultatif
		//var ok = tabignor.length;
	//}
	for (var champ=0; champ < tabobl.length; champ++) {
		if(typeof(maform.elements[tabobl[champ]]) == 'undefined'
		|| maform.elements[tabobl[champ]].value == ""
		|| maform .elements[tabobl[champ]].value == '0'
		|| maform .elements[tabobl[champ]].value == 'NULL'){
			champmanquant[num]							= tabobl[champ];
			if(typeof(maform.elements[tabobl[champ]]) != 'undefined'){
				maform.elements[tabobl[champ]].className	= 'erreurform';
			}
			num = num + 1;
		}else{
			champ_ok = champ_ok + 1 ;
			maform .elements[tabobl[champ]].className = '';
		}
		//champ_totaltab[maform.elements[champ].name] = maform.elements[champ].name;
	}
//	if(tabobl){
//		for(key in tabobl){
//			if(document.getElementById(tabobl[key]) == null
//				|| document.getElementById(tabobl[key]).value == ''
//				|| document.getElementById(tabobl[key]).value == '0'){
//				champmanquant[num]	= tabobl[key];
//				num = num + 1;
//			}else{
//				champ_ok	= champ_ok + 1;
//			}
//		}
//	}else{
//		var tabobl = new Array();
//	}
	//var champ_total 	= champ_totaltab.length;
	
	if(champ_ok == tabobl.length){
		if(callback){
			callback.call();
			return false;
		}
		return true;
	}else{
		for(key in champmanquant){
			if(i > 0){
				strchampmanquant = strchampmanquant + ', ';
			}
			strchampmanquant = strchampmanquant + champmanquant[key];
			i = i + 1;
		}
		alert('il manque un ou plusieurs champ(s) (' + strchampmanquant + ')');
		if(document.getElementById('loading')){
			document.getElementById('loading').innerHTML = '';
		}
		document.getElementById('submit').disabled	= false;
		insubmit = false;
		return false;
	}
}

function hideExp(id){
	$("#labulle").hide('slow',function(){BulleHide(id)});
}

xpnum = 0;
function affExp(xp,id){
	if(xpnum == 0){
		xpnum = xp;
	}
	if(bulleactive == 0){
		xpnum = 0;
		BulleWrite('<span style="color:green;font-weight:bold;">+'+xp+' XP</span>','80px','none',id);
	}else{
		xpnum = xpnum + xp;
		BulleWrite('<span style="color:green;font-weight:bold;">+'+xpnum+' XP</span>','80px','none',id);
		clearTimeout(t);
	}
	$("#labulle").show('slow');
	t=setTimeout("hideExp('"+id+"')",5000);
}

function MsgOkCancel(mess){
	var fRet;
	fRet = confirm(mess);
	return fRet;
}


function ajax_load(id,texte){
	if(texte == undefined){
		texte = '';
	}
	if(document.getElementById(id)){
		document.getElementById(id).innerHTML = texte + '<img src="'+domain_name+'/img/ajax-loader.gif" alt="load">';
	}
}

function afficherbulleresum(id,mess){
	tbul = setInterval('BulleWrite("");ajax_load("labulletext","Chargement");xajax_aff_resumprofil('+id+',"'+mess+'");clearInterval(tbul);',1000);
}

function afficherbulletheme(id){
	themebul = setInterval('BulleWrite("");ajax_load("labulletext","Chargement");xajax_userInstalledTheme('+id+');clearInterval(themebul);',1000);
}
/*
reso_limit	= 1124;
function agrdwindow(){
	document.getElementById('lienstream').style.display		= 'none';
	document.getElementById('lienmanga').style.display		= 'table-cell';
	document.getElementById('lienserie').style.display		= 'table-cell';
	document.getElementById('lienfilm').style.display		= 'table-cell';
	document.getElementById('lienshow').style.display		= 'table-cell';
	document.getElementById('menu_droit').style.display		= 'table';
	$(row_nm_pub).before(row_ct_vargeek);
	$(row_ct_vargeek).before(row_nm_vargeek);
	$(row_nm_vargeek).before(row_ct_membr);
	$(row_ct_membr).before(row_nm_membr);
}

function reduitwindow(){
	document.getElementById('lienstream').style.display	= 'table-cell';
	document.getElementById('lienmanga').style.display	= 'none';
	document.getElementById('lienserie').style.display	= 'none';
	document.getElementById('lienfilm').style.display	= 'none';
	document.getElementById('lienshow').style.display	= 'none';
	document.getElementById('menu_droit').style.display	= 'none';
	$(row_ct_contenu).after(row_nm_vargeek);
	$(row_nm_vargeek).after(row_ct_vargeek);
	$(row_ct_vargeek).after(row_nm_membr);
	$(row_nm_membr).after(row_ct_membr);
	//document.getElementById('tabl_menugauch').insertBefore(row_nm_vargeek,row_ct_stat);
	//document.getElementById('tabl_menugauch').insertBefore(row_ct_vargeek,row_nm_vargeek);
}

function doresize(){
	tabl_menugauch	= document.getElementById('tabl_menugauch');
	row_nm_vargeek	= document.getElementById('row_nm_vrgeek');
	row_ct_vargeek	= document.getElementById('row_ct_vrgeek');
	row_ct_stat		= document.getElementById('row_ct_stat');
	row_ct_contenu	= document.getElementById('row_ct_contenu');
	row_nm_membr	= document.getElementById('row_nm_membr');
	row_ct_membr	= document.getElementById('row_ct_membr');
	row_nm_pub		= document.getElementById('row_nm_pub');
	if (document.body){
		var larg = (document.body.clientWidth);
		//var haut = (document.body.clientHeight);
	}else{
		var larg = (window.innerWidth);
		//var haut = (window.innerHeight);
	}
	if(largbase > larg && larg < reso_limit && largbase > reso_limit){
		//il réduit
		//window.alert("Tu réduit ta page : " + larg + " (" + largbase+")");
		reduitwindow();
		largbase = larg;
	}else{
		if(largbase < larg && larg > reso_limit  && largbase < reso_limit){
			//il agrandit
			//window.alert("Tu agrandi ta page : " + larg + " (" + largbase+")");
			agrdwindow();
			largbase = larg;
		}
	}
	//window.alert("Vous êtes en résolution : " + larg + "*" + haut);
}
*/

function hideDiv(){
	document.body.style.overflow = 'auto';
	$('#connectFB').hide('slow',function(){
		$('#video').hide('slow',function(){
			$('#filtre').fadeOut('slow');
		});
		
		//document.getElementById('connectFB').innerHTML='';
		//document.getElementById('video').innerHTML='';
		return false;
	});
	
	
}

function stars(type,id,num){
	var nb = 1;
	for(var i = 0; i<num; i++){
		document.getElementById(type + "-" + id + "-" + nb).src = domain_name+"/img/star_on.png";
		nb++;
	}
	for(var i = nb; i<=5; i++){
		document.getElementById(type + "-" + id + "-" + nb).src = domain_name+"/img/star_off.png";
		nb++;
	}
	document.getElementById("label" + "-" + type + "-" + id).innerHTML = '<small>'+valueTitleImg(num)+'</small>';
}

function valueTitleImg(nb){
	switch(nb){
		case '1':
			title ='Horrible';
			break;
		case '2':
			title ='Pas terrible';
			break;
		case '3':
			title ='Bien';
			break;
		case '4':
			title ='Très bon!';
			break;
		case '5':
			title ='Excellent!!';
			break;
	}
	return title;
}

function taillevideo(largeur,num){
	bobject = document.getElementById(num).getElementsByTagName("object")[0];
	bembed	= document.getElementById(num).getElementsByTagName("object")[0].getElementsByTagName("embed")[0];
	objheight = bobject . height;
	objwidth = bobject . width;

	ratio = objwidth / objheight;
	ratio = ratio.toFixed(2);

	nouv_hauteur = largeur/ratio;
	nouv_hauteur = nouv_hauteur.toFixed(2);
	
	bobject.height	= nouv_hauteur;
	bobject.width	= largeur;
	bembed.height	= nouv_hauteur;
	bembed.width	= largeur;
}
/*
var timder;
var idprochain;
var idernier;
var LoadEnCours = false;
var reprise;
var time;
function timerdernier(){
	if(idernier==6){
		idprochain=1;
	}else{
		idprochain=idernier+1;
	}
	LoadEnCours=true;
	$('#loadmess').fadeIn('fast');
	for(key in tabdernier){
		if(key==6){
			$('#contenu_'+tabdernier[key]+'').fadeOut('fast',function(){
				setTimeout("$('#contenu_"+tabdernier[idprochain]+"').fadeIn('fast');",100);
				});
		}else{
			$('#contenu_'+tabdernier[key]+'').fadeOut('fast');
		}
		document.getElementById('liendernier'+tabdernier[key]).className='menulink';
	}
	document.getElementById('liendernier'+tabdernier[idprochain]).className='menulinkr';
	$('#loadmess').fadeOut('fast');
	idernier	= idprochain;
	LoadEnCours	= false;
	timder		= setTimeout("timerdernier()",10000);
}

function canceltimer(){
	clearTimeout(timder);
	document.getElementById('etatnews').innerHTML = 'Pause';
}

function reprise(){
	document.getElementById('etatnews').innerHTML = 'Lecture des news';
	timder=setTimeout("timerdernier()",10000);
}

function changeNews(id){
	if(LoadEnCours==false){
		LoadEnCours=true;
		$('#loadmess').fadeIn('fast');
		for(key in tabdernier){	
			$('#contenu_'+tabdernier[key]+'').fadeOut('fast');
			document.getElementById('liendernier'+tabdernier[key]).className='menulink';
		}
		$('#contenu_'+tabdernier[idernier]).fadeOut('fast',function(){
			xajax_maj_dernierajout(tabdernier[id],false,'contenu_'+tabdernier[id],'fast');
			});
		idernier = id;
	}
}

function stptimder(idernier){
	clearTimeout(timder);
	if(idernier==6){
		idprochain=1;
	}else{
		idprochain=idernier+1;
	}
	timder=setTimeout("timerdernier()",20000);
}

tab = new Array();

function initdefil(type,divdefaut,div1,div2,hauteur,largeur,couleur){
	init_defil = true;
	tab[type] = new Array();
	tab[type]['txt_defil_width'] = largeur; //largeur
	tab[type]['txt_defil_height'] = hauteur; //hauteur
	tab[type]['txt_defil_bgcolor'] = couleur; //couleur de fond
	tab[type]['txt_defil_pause'] = 0; //Temps en milliemes de secondes
	tab[type]['txt_defil_info'] = new Array();
	tab[type]['txt_defil_info'][0]=div1;
	tab[type]['txt_defil_info'][1]=div2;
	tab[type]['txt_nom_aff'] = divdefaut; //Nom du div affich�
	tab[type]['txt_nom_voulu'] = ''; //Nom du div voulu
	tab[type]['txt_defil_1'] = 1;
	tab[type]['txt_defil_2'] = 0;
	tab[type]['stop_mouss'] = 0;
	tab[type]['en_cours']=false;
	tab[type]['prct']=(2/100)*largeur;
	document.write('<DIV ID="txt_defil_relativ'+type+'" STYLE="vertical-align:top;position:relative;width:'+tab[type]['txt_defil_width'] +'px;height:'+tab[type]['txt_defil_height']+'px;background-color:'+tab[type]['txt_defil_bgcolor']+';">');
	document.write('<DIV ID="txt_defil_cadre'+type+'" STYLE="position:absolute;width:'+(tab[type]['txt_defil_width'] -8)+'px;height:'+(tab[type]['txt_defil_height']-8)+'px;top:4;left:4;clip:rect(0px '+(tab[type]['txt_defil_width'] -8)+'px '+(tab[type]['txt_defil_height']-8)+'px 0px)">');
	document.write('<div id="txt_defiler_1'+type+'" style="position:absolute;width:'+(tab[type]['txt_defil_width'] -8)+'px;left:0px;top:0px;" >'+document.getElementById(tab[type]['txt_defil_info'][0]).innerHTML+'</DIV>');
	document.write('<div id="txt_defiler_2'+type+'" style="position:absolute;width:'+(tab[type]['txt_defil_width'] -8)+'px;left:'+tab[type]['txt_defil_width']+'px;top:0;" >'+document.getElementById(tab[type]['txt_defil_info'][1]).innerHTML+'</DIV>');
	document.write('</DIV></DIV>');
}

function defiler(txt_nom_voulu,type,cote){
	if(tab[type]['en_cours']==false){
		if(tab[type]['txt_nom_aff'] != txt_nom_voulu){
			tab[type]['txt_defil_nb_info'] = tab[type]['txt_defil_info'].length-1;
			if(cote=='droite'){
				if(tab[type]['txt_defil_2'] == tab[type]['txt_defil_nb_info']){
					tab[type]['txt_defil_next'] = 0;
				}else{
					tab[type]['txt_defil_next'] = tab[type]['txt_defil_2']+1;
				}
			}else{
				if(tab[type]['txt_defil_2'] == 0)
					tab[type]['txt_defil_next'] = tab[type]['txt_defil_nb_info'];
				else{
					tab[type]['txt_defil_next'] = tab[type]['txt_defil_next']-1;
				}
			}
			document.getElementById(tab[type]['txt_defil_info'][tab[type]['txt_defil_next']]).innerHTML=document.getElementById(tab[type]['txt_defil_info'][1]).innerHTML;
			txt_defil_f1(cote,type);
			tab[type]['txt_nom_aff'] = txt_nom_voulu;
		}
	}
}


function txt_defil_f1(cote,type){
	if(tab[type]['txt_defil_1'] == 1){
		tab[type]['txt_defil_haut'] = "txt_defiler_1"+type;
		tab[type]['txt_defil_bas'] = "txt_defiler_2"+type;
		tab[type]['txt_defil_1'] = 0;
	}else{
		tab[type]['txt_defil_bas'] = "txt_defiler_1"+type;
		tab[type]['txt_defil_haut'] = "txt_defiler_2"+type;
		tab[type]['txt_defil_1'] = 1;
	}
	tab[type]['txt_defil_nb_info'] = tab[type]['txt_defil_info'].length-1;
	tab[type]['txt_defil_next'] = tab[type]['txt_defil_nb_info'];	
	document.getElementById(tab[type]['txt_defil_bas']).innerHTML = document.getElementById(tab[type]['txt_defil_info'][tab[type]['txt_defil_next']]).innerHTML;
	tab[type]['txt_defil_left'] = 0;
	document.getElementById(tab[type]['txt_defil_info'][0]).innerHTML="";
	document.getElementById(tab[type]['txt_defil_info'][1]).innerHTML="";
	tab[type]['en_cours']=true;
	if(cote=='droite'){
		tab[type]['move1']=setTimeout("txt_defil_f2 ('"+cote+"','"+type+"')",tab[type]['txt_defil_pause']);
	}else{
		tab[type]['move1']=setTimeout("txt_defil_f2 ('"+cote+"','"+type+"')",tab[type]['txt_defil_pause']);
	}
}

function txt_defil_f2 (cote,type){
	if (tab[type]['stop_mouss'] == 0){
		if(cote=='droite'){
			tab[type]['txt_defil_left'] = tab[type]['txt_defil_left'] - tab[type]['prct'];
			document.getElementById(tab[type]['txt_defil_haut']).style.left = parseInt(tab[type]['txt_defil_left'])+'px';
			document.getElementById(tab[type]['txt_defil_bas']).style.left = parseInt(tab[type]['txt_defil_left'])+parseInt(tab[type]['txt_defil_width'])+'px';
		}else{
			tab[type]['txt_defil_left'] = tab[type]['txt_defil_left'] + tab[type]['prct'];
			document.getElementById(tab[type]['txt_defil_haut']).style.left = parseInt(tab[type]['txt_defil_left'])+'px';
			document.getElementById(tab[type]['txt_defil_bas']).style.left = parseInt(tab[type]['txt_defil_left'])-parseInt(tab[type]['txt_defil_width'])+'px';
		}
		if(cote=='droite'){
			if((parseInt(tab[type]['txt_defil_left']) + parseInt(tab[type]['txt_defil_width'])) > 0){
				tab[type]['move2']=setTimeout("txt_defil_f2 ('"+cote+"','"+type+"')",5);
			}else{
				txt_defil_f3(cote,type);
				//alert(document.getElementById(tab[type]['txt_defil_haut']).style.left);
				document.getElementById(tab[type]['txt_defil_bas']).style.left='0px';
			}
		}else{
			if((parseInt(tab[type]['txt_defil_left'])) < parseInt(tab[type]['txt_defil_width'])){
				tab[type]['move2']=setTimeout("txt_defil_f2 ('"+cote+"','"+type+"')",5);
			}else{
				txt_defil_f3(cote,type);
				document.getElementById(tab[type]['txt_defil_bas']).style.left = '0px';
			}
		}
	}
	else{
		tab[type]['move1']=setTimeout("txt_defil_f2 ('"+cote+"','"+type+"')",5);
	}
}

function txt_defil_f3(cote,type){
	tab[type]['en_cours']=false;
	tab[type]['txt_defil_2'] = tab[type]['txt_defil_next'];
}*/

function maxlength_textarea(id, crid, max, tchat){
	txtarea = document.getElementById(id);
	document.getElementById(crid).innerHTML= max - txtarea.value.length;
	if(tchat == true){
		txtarea.onkeypress=function(event){if(event.keyCode == 13 && this.value != ''){TchatPost(this);}eval('v_maxlength("'+id+'","'+crid+'",'+max+');')};
		txtarea.onkeyup=function(event){if(event.keyCode == 13){deletelastnl(this);}eval('v_maxlength("'+id+'","'+crid+'",'+max+');')};
	}else{
		txtarea.onkeypress=function(){eval('v_maxlength("'+id+'","'+crid+'",'+max+');')};
		txtarea.onkeyup=function(){eval('v_maxlength("'+id+'","'+crid+'",'+max+');')};
	}
	txtarea.onblur=function(){eval('v_maxlength("'+id+'","'+crid+'",'+max+');')};
	txtarea.onkeydown=function(){eval('v_maxlength("'+id+'","'+crid+'",'+max+');')};
}
	
function v_maxlength(id, crid, max){
	var txtarea = document.getElementById(id);
	var crreste = document.getElementById(crid);
	var len = txtarea.value.length;
	if(len>max){
		txtarea.value=txtarea.value.substr(0,max);
	}
	len = txtarea.value.length;
	crreste.innerHTML=max-len;
}

$(document).ready(function() {
	slide_actuelle	= 0;
	slidesuivante	= slide_actuelle +1;
	$(".main_image .slidedesc").show(); //Show Banner
	$(".main_image .slideblock").animate({ opacity: 0.85 }, 1 ); //Set Opacity
	$(".slide_image_thumb ul li:first").addClass('active'); //Add the active class (highlights the very first list item by default)
	
	t = setTimeout('$("#'+slidesuivante+'").click();',10000);
	
	$(".slide_image_thumb ul li").click(function(){
		//remise à zero du timer s'il existe
		if(typeof(t) != 'undefined'){
			clearTimeout(t);
		}
		
	    //Set Variables
	    var imgAlt = $(this).find('img').attr("alt"); //Get Alt Tag of Image
	    var imgTitle = $(this).find('a').attr("href"); //Get Main Image URL
	    var imgDesc = $(this).find('.slideblock').html();  //Get HTML of the "slideblock" container
	    var imgDescHeight = $(".main_image").find('.slideblock').height(); //Find the height of the "slideblock"
	    var imgLink = $(this).find('input').attr("value");
	    var nomserie = $(this).find('h2').html();
	    
	    
	    slide_actuelle = $(this).attr("id");
	    slide_actuelle = parseInt(slide_actuelle);
		//calcul de la slide suivante à afficher
		slidesuivante	= slide_actuelle + 1;
		if(slide_actuelle == nbslide){
			slidesuivante = 0;
		}
	    
	    if ($(this).is(".active")) {  //If the list item is active/selected, then...
	        return false; // Don't click through - Prevents repetitive animations on active/selected list-item
	    } else { //If not active then...
	        //Animate the Description
	        $(".main_image .slideblock").animate({ opacity: 0, marginBottom: -imgDescHeight }, 250 , function() { //Pull the slideblock down (negative bottom margin of its own height)
	            $(".main_image .slideblock").html(imgDesc).animate({ opacity: 0.85,  marginBottom: "0" }, 250 ); //swap the html of the slideblock, then pull the slideblock container back up and set opacity
	            $(".main_image img").attr({ src: imgTitle , alt: imgAlt}); //Switch the main image (URL + alt tag)
	            $(".main_image h2").html("<a href='"+imgLink+"'>"+nomserie+"</a>");
	        });
	    }
	    //Show active list-item
	    $(".slide_image_thumb ul li").removeClass('active'); //Remove class of 'active' on all list-items
	    $(this).addClass('active');  //Add class of 'active' on the selected list
	    
	    
		//mise a jour des variables
		slide_actuelle	= slidesuivante;
		//la slide suivante sera affiché dans 10 secondes
		t = setTimeout('$("#'+slidesuivante+'").click();',10000);
	    
	    return false; 
	
	})
	.hover(function(){ //Hover effects on list-item 
	    $(this).addClass('hover'); //Add class "hover" on hover 
	}, function() {
	    $(this).removeClass('hover'); //Remove class "hover" on hover out
	});
});
