﻿// POUR LE MENU DU BACK-OFFICE ----------------------------------------------------------------------------- >>
function montre(id) {
	var d = document.getElementById(id);
	for (var i = 1; i<=10; i++) {
		if (document.getElementById('smenu'+i)) {
			document.getElementById('smenu'+i).style.display='none'; 
			if (navigator.appName=="Microsoft Internet Explorer") swapmenuUp("select");
		}
	}
	if (d) {
		d.style.display='block'; 
		if (navigator.appName=="Microsoft Internet Explorer") swapmenuDown("select");
	}
}
function selectall(theField) {
	//var tempval=eval("document.getElementById('"+theField+"'))
	var tempval=theField;
	tempval.focus()
	tempval.select()
	if (document.all&&copytoclip==1){
		therange=tempval.createTextRange()
		therange.execCommand("Copy")
		window.status="Le code a bien été copié !"
		setTimeout("window.status=''",1800)
	}
}
function envoyerAmi(id){
	if(id){
		window.open("/_includes/pages/envoi_ami.php?id_video="+id, "envoyer", "width=550, height=500");
	}
}

function swapmenuDown(tag) {
	tab = document.getElementsByTagName(tag);
	for(var i=0;i<tab.length;i++) {
			tab[i].style.visibility = "hidden";
	}
}

function swapmenuUp(tag) {
	tab = document.getElementsByTagName(tag);
	for(var i=0;i<tab.length;i++) {
			tab[i].style.visibility = "visible";
	}
}

/* POUR LES ONGLETS */
function aff_onglet(id){
	for (var i = 0; i<=10; i++) {
		if (document.getElementById('onglet_'+i)) {
			document.getElementById('onglet_'+i).style.display = 'none';
			document.getElementById('btn_'+i).className = 'btn_off';
		}
	}
	document.getElementById('onglet_'+id).style.display = 'block';
	document.getElementById('btn_'+id).className = 'btn_selected';
}


// FERMER UN GREYBOX --------------------------------------------------------------------------------------- >>
function fermer_greybox(){
	parent.parent.GB_hide();	
}

// SUPPRIMER LES IMAGES DANS LE GESTIONNAIRE D'IMAGES ET DE FICHIERS --------------------------------------- >>
function sup_asso(id) {
	document.getElementById("document_"+id).style.display = "none";
	document.forms.form1.ids_fich.value =  document.forms.form1.ids_fich.value.replace(id+",", "");
}

function sup_asso_img(id) {
	document.getElementById("image_"+id).style.display = "none";
	document.forms.form1.ids_img.value =  document.forms.form1.ids_img.value.replace(id+",", "");
}

// AFFICHER / MASQUER UNE DIV ------------------------------------------------------------------------------ >>
function swap(madiv){
	var etat = document.getElementById(madiv).style.display;
	if(etat == "none"){
		document.getElementById(madiv).style.display = "block";
	} else {
		document.getElementById(madiv).style.display = "none";
	}
}

// AFFICHER / MASQUER UNE DIV SELON ETAT ------------------------------------------------------------------- >>
function swapChoose(madiv,etat){
	if(etat == "none"){
		document.getElementById(madiv).style.display = "none";
	} else if (etat == "block") {
		document.getElementById(madiv).style.display = "block";
	} else if (etat == "inline") {
		document.getElementById(madiv).style.display = "inline";
	}
}

// TOUT DEPLIER / TOUT MASQUER ----------------------------------------------------------------------------- >>
function swapAllDown(){
	var tab = document.getElementsByTagName("div");
	for(i=0;i<tab.length; i++){
		if (tab[i].getAttribute("label") == "swapy") {
		tab[i].style.display = "none";
		}
	}
}
function swapAllUp(){
	var tab = document.getElementsByTagName("div");
	for(i=0;i<tab.length; i++){
		if (tab[i].getAttribute("label") == "swapy") {
		tab[i].style.display = "block";
		}
	}
}

function supprimer(quoi, urltraitement){
	if(confirm("Etes-vous sûr de vouloir supprimer "+quoi+"?")){
		document.location.href = urltraitement;
	}	
}


///////////////////////// ROBIN

////////////// GOTO ETAPE SUIVANTE ------------------------------------------------------>
function gotoEtape(nom, id){	
	for (var i=0; i<=20; i++) {
		if (document.getElementById(nom+i)) {
				document.getElementById(nom+i).style.display = 'none';
				document.getElementById("btn_suivant_"+i).className = '';
		}
	}	
	
	document.getElementById("form_etape_"+id).style.display = 'block';
	document.getElementById("btn_suivant_"+id).className = 'selected';
	
	return true;
}
	
function verif_email(email){
    var verif = /^[^@]+@(([\w\-]+\.){1,4}[a-zA-Z]{2,4}|(([01]?\d?\d|2[0-4]\d|25[0-5])\.){3}([01]?\d?\d|2[0-4]\d|25[0-5]))$/  
    return ( verif.test(email) );
}

function ChercheValeurRadio(nb_radio, nom_form, nom_champ)
	{
	for(i=0;i<nb_radio;i++)
		eval("if(document.forms."+nom_form+"."+nom_champ+"[i].checked)	valeur = document.forms."+nom_form+"."+nom_champ+"[i].value");
	return valeur;
	}

//Fonction permettant de récupérer n'importe quel valeur d'un élément de formulaire
function getFormElementValue(e) {
	if (e.type == 'radio') {
		return getFormRadioValue(e);
	} else if (e.type == 'checkbox') {
		return getFormCheckValue(e);
	} else {
		return e.value;
	}
}

//renvoi la valeur d'un checkbox
function getFormCheckValue(e) {
	if (e.checked) {
		return e.value;
	}
	return null;
}
//renvoi la valeur dun bouton radio
function getFormRadioValue(e) {
	for (var i=0; i <e.length; i++) {
		if (e[i].checked) {
			return e[i].value;
		} else {
			return null;
		}
	}
}
/////


//vérifie le traitement d'une action définie
function verifierTraitement(nom_form, nom_champs, nb_champs, debut, id_champs_verif, lien){	
	//nom du traitement à vérifier
	formulaire =  "document."+nom_form;
	nom_traitement = formulaire+"."+nom_champs;

	//
	if(compterNbCasesChochees(nom_form, id_champs_verif, nb_champs, debut)){
		//pour suppression
		if(eval(nom_traitement+".value") == 'supprimer'){
			if(confirm('Etes-vous sûr de vouloir supprimer tous les éléments sélectionnés ?')){
				eval(formulaire+".action = '"+lien+"'");
				eval(formulaire+".submit()");
			}
			else return false;
		}
	}
	else ("Vous devez sélectionner au moins un élément dans la liste !");
}
	

function compterNbCasesChochees(nom_form, id_champs, nb_champs, debut)
	{
	//initialisation du compteur
	compteur = 0;
	
	//on recupère l'id du formulaire et de la case à cocher
	id_checkbox = "document."+nom_form+"."+id_champs;
	
	for(i=debut; i<nb_champs; i++)
		if (eval(id_checkbox+i+".checked == true")) compteur++;
		
	//
	if(compteur > 0) return true;
	else return false;
	}
	
function CocherCase(nom_form, id_champs, nb_champs, debut, action)
	{
	//on recupère l'id du formulaire et de la case à cocher
	id_checkbox = "document."+nom_form+"."+id_champs;

	if(action == 'cocher')
		{
		for(i=debut; i<nb_champs; i++)
			{
			if(eval(id_checkbox+i+".disabled == false")) eval(id_checkbox+i+".checked = true");
			}
		}
	else if(action == 'decocher')
		{
		for(i=debut; i<nb_champs; i++) eval(id_checkbox+i+".checked = false");
		}
	}
//-->


function popupcentree(page,largeur,hauteur,options){
	var top = (screen.height-hauteur)/2;
	var left = (screen.width-largeur)/2;
	window.open(page,"pop","top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
}	
	
function confirmerSortirPage(){
	if(confirm("Etes-vous sûr de vouloir quitter la page en cours ?")) return true;
	else{ 
		return false;
		//document.location.href = '/mon_compte/messages/messages_composer.php?recup=1';
	}
}


function aller_vers(url){
	//(url);
	document.location.href = url;
}

// AJOUTER UN MSG DANS UNE DIV EN INNER HTML  -------------------------------------------------- >> # 07/05/2007
function affiche_inner(msg, div){
	document.getElementById(div).innerHTML = msg;
}

// STYLE DIV VISIBLE -------------------------------------------------------------------------- >> # 07/05/2007
function visible(div){
	var etat = document.getElementById(div).style.display;
	if(etat == "block"){
		var retour = "none";
	} else {
		var retour = "block";
	}
	document.getElementById(div).style.display = retour;

}

// GENERER UNE CHAINE TYPE URL8REWRITING ------------------------------------------------------ >> # 15/05/2007
function generer_url(chaine, champs){
		var nurl = chaine.toLowerCase();
		var remplacer = Array("#¤-", "?¤-", "ù¤u", "ô¤o", "û¤u", "î¤i", ".¤-", "|¤-", "_¤-", ",¤-", "°¤-", 
			"ü¤u", "ë¤e", "ö¤o", "ë¤e", "ê¤e", "%¤-", "(¤-", ")¤-", "ç¤c", "*¤-", "²¤2", '"¤-', "\\¤-",
			"¨¤-", "^¤-", "é¤e", "è¤e", "à¤a", "'¤-", "&¤et", "@¤a", "/¤-", " ¤-", 
			"&¤et", "&amp;¤et", "â¤a", '"¤', "+¤-", "!¤-", "$¤", ":¤-", ";¤-", "§¤", "=¤", "}¤", "]¤", 
			"`¤", "[¤", "{¤", "<¤-", ">¤-", "--¤-");
		for( var j=0; j < remplacer.length; j++){
			var chaine2 = remplacer[j].split("¤");
			while(nurl.indexOf(chaine2[0]) != -1){
				nurl = nurl.replace(chaine2[0], chaine2[1]);
			}
		}
		
		if(nurl.indexOf("-") == 0){ nurl = nurl.replace("-", ""); }
		if(nurl.lastIndexOf("-") == nurl.length-1){ nurl = nurl.substring(0, nurl.length-1);}
//		var newurl = (nurl+".html").toLowerCase();
		var newurl = nurl.toLowerCase();
		document.getElementById(champs).value = newurl;
	}
	
// GENERER UNE CHAINE ALEATOIRE ------------------------------------------------------ >> # 22/08/2007
function alea(longeur) {
	var aleatoire;
	var chaine = '';
	var cars = new Array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9");
	for(i=0; i<=longeur; i++){
		aleatoire = Math.round((Math.random()*35));
		chaine += cars[aleatoire];
	}
	return chaine;
}


// FONCTIONS AJAX ///////////////////////////////////////////////////////////////////////////////////////////////////////


// TOUT COCHER / DECOCHER ------------------------------------------------------------------------ >> 16/06/2007
function tout_cocher(nom,action){
	if(action == "cocher") var coche = true;
	if(action == "decocher") var coche = false;
	
	var field = document.getElementsByName(nom+"[]");
	
	for(i=0; i<field.length; i++){
		field[i].checked = coche;
	}
}

function actu_jedessine(divid, pos, tot){
	if(tot > 1){
		palier = 250;
		if(pos == "next") depl = -1*palier;
		if(pos == "prev") depl = palier;	
		max_top = parseInt(palier-(tot*palier));
		
		posactuel = $(divid).getStyle("top");
		pos = parseInt(posactuel.replace("px", ""));
		newpos = parseInt(pos+depl);
		
		if(newpos < max_top) newpos = 0;
		if(newpos > 0 ) newpos = max_top;
		
		$(divid).style.top = (newpos)+"px";
	}
}
function play_diapo(divid, pos, tot, tempo, interID){
	interID = setInterval("actu_jedessine('"+divid+"', '"+pos+"', "+tot+")", tempo);
}

function print_page(id){
	window.open("/v3/print.php?id="+id, 'print', "width=850, height=600, scrollbars=yes");
}
//SWITCH TOURNEUR -------------------------------------------->
function switchTourneur(mode, divid, tempo){
	var eltactif = $(divid).down('.controls').down('.on');
	
	if(mode=='next'){
		eval(divid+".next()");
		if(eltactif.next('a')) eltactif.next('a').addClassName('on');
		else eltactif.up('.controls').down('a').addClassName('on');
	}
	else{
		eval(divid+".previous()");
		if(eltactif.previous('a')) eltactif.previous('a').addClassName('on');
		else eltactif.up('.controls').down('a.last').addClassName('on');
	}
	eltactif.removeClassName('on');
	
	restoreIntervalTourneur(divid, tempo);
	
	return false;
}

function activePositionTourneur(item, divid, tempo){
	var eltactif = Element.extend(item);
	eltactif.siblings().each(function(e){
		e.removeClassName('on');
	});
	eltactif.addClassName('on');
	
	restoreIntervalTourneur(divid, tempo);
}

function restoreIntervalTourneur(divid, tempo){
	eval("clearInterval(timer_auto_tourneur_"+divid+")");
	eval("timer_auto_tourneur_"+divid+" = setInterval(\"if(!blocktourneur){switchTourneur('next', '"+divid+"', "+tempo+");}\", "+tempo+")");
}


// Publication d'un commentaire (jQuery 01/10/09)

jQuery.noConflict();

jQuery(document).ready(function(){
						   
	jQuery('#formCom').bind('submit',function()
	{
	// Vérification du formulaire ?
		bReturn = true;
			// Champs nom obligatoire
		if (!jQuery('#idUsr').length) //Si l'utilisateur est enregistré, pas besoin de vérifier certain champs
		{
			if (jQuery.trim(jQuery("#nomCom").val()).length==0)
			{
				bReturn = false;
				jQuery("#nomCom").css('background-color','#ffe7e7');
			} else {
				jQuery("#nomCom").css('background-color','#fff');
			}
				// Champs mail obligatoire
				mailCom = jQuery.trim(jQuery("#mailCom").val())
			if (mailCom.length==0 || !mailCom.match(/^([a-zA-Z0-9_-])+([.]?[a-zA-Z0-9_-]{1,})*@([a-zA-Z0-9-_]{2,}[.])+[a-zA-Z]{2,3}$/))
			{
				bReturn = false;
				jQuery("#mailCom").css('background-color','#ffe7e7');
			} else {
				jQuery("#mailCom").css('background-color','#fff');
			}
		}
			// Champs commentaire
		if (jQuery.trim(jQuery("#txtCom").val()).length<3)
		{
			bReturn = false;
			jQuery("#txtCom").css('background-color','#ffe7e7');
		} else {
			jQuery("#txtCom").css('background-color','#fff');
		}
		if (bReturn==false)
		{
			return false;
		}
		else // Si pas d'erreur de validation
		{
			// Vérifie si membre enregistré
			if (jQuery('#idUsr').length)
			{
				idUsr	= jQuery('#idUsr').val();
				nomCom 		= jQuery('#nomCom').val();
				$string	= 'id='+idUsr;
			}
			else
			{
				nomCom 		= jQuery('#nomCom').val();
				mailCom 	= jQuery('#mailCom').val();
				siteCom 	= jQuery('#siteCom').val();
				$string	= 'nom='+nomCom+'&mail='+mailCom+'&site='+siteCom;
			}
		// Récupérer les données du formulaire
			txtCom		= jQuery('#txtCom').val();
			idArt		= jQuery('#idArt').val();
			urlAvatar	= jQuery('#urlAvatar').val();
			capCom		= jQuery('#capCom').val();
			ipCom		= jQuery('#ipCom').val();
			nomCom		= jQuery('#nomCom').val();
			typeArt 	= jQuery('#typeArt').val();
			
			if (jQuery('#avertCom').is(':checked'))
				avertCom = 'on';
			else
				avertCom = 'off';
				
			dateCom		= jQuery('#dateCom').val();
			
			$string		= $string+'&txt='+txtCom+'&id_article='+idArt+'&capCom='+capCom+'&typeArt='+typeArt+'&avertCom='+avertCom+'&ipCom='+ipCom+'&nomCom='+nomCom;
			scriptUrl	= "/_scripts/ajax/post_com.php";
			jQuery.ajax( {type: 'POST', data: $string, url: scriptUrl, success: function(data, textStatus){
			if(data['inserted'])
			{
				listComs 	= jQuery('#listeComs');
				
				insert	= '<li id="newComment" style="display: none;">'
						+'<div class="vcard">'
						+'	<img src="'+urlAvatar+'" height="72" width="72" alt=""/>'
						+'</div>'
						+'<div class="comRight">'
						+'	<strong>'+nomCom+'</strong>'
						+'	<span class="comInfo">Post&eacute; le '+dateCom+'</span>'
						+'   <p class="leCom">'+txtCom+'</p>'
						+'</div>'
						+'<div class="spacer"></div>'
					+'</li>';
					
				listComs.append(insert);
				jQuery("#newComment").slideDown('normal');
				jQuery("#formComs").slideUp('normal');
			}
			else
			{
				alert('Erreur pendant l\'enregistrement du message : '+data['error']);
			}}, dataType: 'json', error: function (XMLHttpRequest, textStatus, errorThrown) { /*alert(XMLHttpRequest); */alert('Erreur 2 pendant l\'enregistrement du message : '. textStatus); }});
				return false; // Ne pas envoyer le formulaire par la méthode trad
		}
	});
 });

	function supp_com(id)
	{
		scriptUrl = "/_scripts/ajax/post_com.php";
		$string	= "id_com="+id+"&fn=supprimer";
		jQuery.post(scriptUrl, $string, function(data){if(data['deleted'] == true){jQuery("#com-"+id).slideUp('normal');} else ('erreur pendant la suppression')},"json");
	}