var url = "liste.php?dir="; 
var url2 = "selection.php"; 
var url6 = "action_form_galerie.php?cas="; 
var url7 = "liste.php?"; 
var url8 = "i_panier.php?id_photo=";
var url12 = "s_panier.php?id_photo=";
var url9 = "recherche.php?cas=";
var url10 = "list_ev.php";
var url11 = "action_form_recherche.php?cas=";
var url13 = "majPanier.php";
var url14 = "action_panier.php?id_photo=";
var url15 = "action_intro.php?cas=";
var url16 = "form_recherche.php";
var url17 = "action_recherche_av.php";
var url18 = "action_message.php?id_message=";
var url21 = "action_panier.php?id_produit=";
var url22 = "action_form_galerie.php?cas="; 
var url23 = "list_ev.php?id_config=";
var cas_temp=1;
var div_courante = "arbo";
var plus = [];
var cas = [];
var index = 1;
var id_temp_list = 0;
var id_temp=0;
var nb_temp=0;
var nom_dossier = null;
var cas_temp_recherche = null;
var id_dest_temp = null;
var InfosSsDossier = 2;
var id_select_temp = 0;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var url_actuelle = location.href;
var liste1 = 0;		  
var liste2 = 0;
var liste3 = 0;		  
var liste4 = 0;	
var liste5 = 0;		  
var liste6 = 0;
var liste7 = 0;		  
var liste8 = 0;	

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function findObj(theObj, theDoc) {
	var p, i, foundObj;
  
	if(!theDoc) theDoc = document;
	if( (p = theObj.indexOf("?")) > 0 && parent.frames.length) {
		theDoc = parent.frames[theObj.substring(p+1)].document;
		theObj = theObj.substring(0,p);
	}
	if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
	for (i=0; !foundObj && i < theDoc.forms.length; i++) 
		foundObj = theDoc.forms[i][theObj];
	for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
		foundObj = findObj(theObj,theDoc.layers[i].document);
	if(!foundObj && $) foundObj = $(theObj);
		return foundObj;
}

/*Affichage de la page annexe*/
function affPage(id,nom) { 
      var url = 'affiche_page.php?id_page='+id;
	  window.open(''+url+'',''+nom+'','toolbar=0,menubar=0,location=0,resizable=1,scrollbars=1,width=550,height=600, left=10, top=10'); 
} 
	
function aff_lien(cadre) {
	var div;
	div = $('mess');
	div.style.visibility='visible'; 
}
/*Affichage de la preview*/

/* Apercu d'une photo */
function affPreview(text,cas, aff_prevnext) { 
	var param;
	if(!cas) cas = 0;
	
	if(!aff_prevnext)
		param = 'preview_final.php?id_photo='+text+'&cas='+cas;
	else
		param = 'preview_final.php?aff_prevnext=0&id_photo='+text+'&cas='+cas;

	//document.body.style.overflow = 'hidden';
	$('backDiv').style.display = "";
	
	new Ajax.Updater('preview', param, {
		onFailure: function(transport) {
			// Echec : on remet l'affichage normal
			//document.body.style.overflow = 'auto';
			$('backDiv').style.display = "none";
		},
		onSuccess: function(transport) {
			// Succes : on affiche le div
			$('preview').style.display = "";
		}
	});
}

/*Affichage de l'image à imprimer*/
function affImprimer(text) { 
	window.open('preview_final.php?print=1&id_photo='+text,'Image',
				'toolbar=0,menubar=0,location=0,resizable=1,scrollbars=1,width=550,height=600, left=10, top=10'); 
} 
/*Lancement du téléchargement libre*/
function affDownload(text,cas) { 
	if(!cas)
		cas = 0;
	window.open('download_free.php?id_photo='+text+'&id_client='+cas,'Image',
				'toolbar=0,menubar=0,location=0,resizable=1,scrollbars=1,width=550,height=600, left=10, top=10'); 
}

/*Ne semble plus être utilisé*/
function maj5(text,dir) { 
	parent.$('panier_petit').src = 's_panier.php?nomImg='+text;
	majActeur2();
	div = $(text);
	div.style.backgroundColor="#FFFFCC"; 
	div.style.border="solid 1px #94B6DE"; 
	var code = "<a Href='#' onclick=\"maj4('"+text+"','"+dir+"')\"><IMG src='images/add_p.png' border='0' alt='Ajouter cette photo Ã  votre sÃ©lection'></a>";
	findObj('img_'+text).innerHTML = code;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function majActeur(dir,name_dir,node) {
	// liste.php?dir=
	param = url + dir + "&name_dir="+name_dir;
	new Ajax.Updater('liste', param);
}

function majActeur2() {
	// selection.php
	new Ajax.Updater('apercu', url2);
}

/*Ne semble plus être utilisé*/
function majActeur3() {
	div = $('mess_attente');
	div.style.visibility='visible';
	$('mess_attente').innerHTML = '<img src="../images/load.gif" width="26" height="26" />Suppresion de votre selection en cours...';
	
	new Ajax.Request(url3, {
		onSuccess: function(transport) {
			majActeur2();
			div = $('mess_attente');
			div.style.visibility = 'hidden';
		}
	});
}

function majPanierDyn(id_photo,cas) {
	if(cas == 1) // i_panier.php?id_photo=
		url_temp = url8 + id_photo;
	else if(cas == 2) // s_panier.php?id_photo=
		url_temp = url12 + id_photo;
	
	new Ajax.Request(url_temp, {
		onSuccess: function(transport) {
			majTotalFinal();
			majActeur2();
		}
	});
}

/*Mise à jour du cadre de l'image si elle est dans la sélection*/
function majSelection(id_photo,cas) {
	if(id_photo) {
		if(cas==1) {
			var photo = $("photo_"+id_photo);
			if(photo!=null)
				photo.style.border = "solid green 4px"; //Pouvoir paramétrer la couleur
		} else if(cas==2) {
			var photo = $("photo_"+id_photo);
			if(photo!=null)
				photo.style.border = "none";  
		}
	}
	if(cas && id_photo) {
		if(cas == 1) // i_panier.php?id_photo=
        url_temp = url8 + id_photo;
	  else if(cas == 2) // s_panier.php?id_photo=
        url_temp = url12 + id_photo;
	
		new Ajax.Request(url_temp, {
			onSuccess: function(transport) {
				//majTotalFinal(); // FIXME marche pas sous IE6 A REMPLACER
				new Ajax.Updater('appercu', url2);
			}
		});
		// majPanierDyn(id_photo,cas); <-- ne marche pas sous IE6
	} else {
		// majActeur2()   <-- ne marche pas sous IE 6
		new Ajax.Updater('appercu', url2);
	}
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function suppr_mess() {
	var div;
	div = $('mess');
	div.style.visibility='hidden'; 
}
/*Ne semble plus être utilisé*/
function red() {
	var mott;
	mott = document.form1.mot.value;
	
	if(document.form1.action[0].checked) {	
		var action = 1;
	} else if(document.form1.action[1].checked) {	
		var action = 2;
	} else 	if(document.form1.action[2].checked) {	
		var action = 3;
	}

	$('liste').src= "t_search2.php?action="+action+"&mot="+mott;
	$('liste').reload();
}

/*Ne semble plus être utilisé*/
function afficher_arbo() {
	  div = $('mess_attente');
  	  div.style.visibility='visible';
	  findObj('mess_attente').innerHTML = '<img src="../images/load.gif" width="26" height="26" />Génération de l\'arborescence en cours...';
}

/*Test opacité - ne doit plus servir*/
function essai() {
	var div;
	div = $('page');
	div.style.filters.alpha.opacity=20; 
}

/////////////////////////////GALERIE////////////////////////////////////////////////////////////////////////
/*Mise à jour de la liste des miniataures*/
function majList(cas,id,annee,no) {

	if(!no)
		majListeMin(5);

	var val = null;
	var val2 = null;

	cas_temp = cas;
	  
	if(annee && cas!=2) {
		var val = annee;
	} else {
		var val = $('sel_'+cas).options[$('sel_'+cas).selectedIndex].value;  
	}

	if(id && id != -1){
		id_temp_list = id;
	}

	if(cas==2 && !no){
		var i =$('sel_'+1);
		if(i!=null){
			val2 = i.value;
			// action_form_galerie.php?cas=
			param = url6 + cas + "&var="+val+"&annee="+val2;	  			  
		}
	} else if(cas==2 && no){
		// action_form_galerie.php?cas=
		param = url6 + cas + "&var="+val+"&annee="+annee;	  			  
	} else {
		// action_form_galerie.php?cas=
		param = url6 + cas + "&var="+val;
	}

	if(cas==3){
		if(InfosSsDossier == 1){
			$("titre_dossier_recherche").style.visibility = "visible";
			$("liste_dossier_recherche").style.visibility = "visible";
		} else {
			$("titre_dossier_recherche").style.visibility = "hidden";
			$("liste_dossier_recherche").style.visibility = "hidden";			
		}
	}

	new Ajax.Request(param, {
		onSuccess: function(transport) {
			results = transport.responseText.split(";");
			taille = results.length - 1;
			if(cas_temp == 1) {
				var i = $("sel_2");
			} else if(cas_temp == 2) {
				var i = $("sel_3");
			} else if(cas_temp == 3) {
				var i = $("sel_4");
			}
			
			while (i.options.length>0){
				i.options[0] = null;
			}
			var k = document.createElement('option');
			k.value= '0';
			i.appendChild(k);
			var l = document.createTextNode('Choisissez');
			k.appendChild(l);
			for(var j=0;j<taille;j++) {
				var tab_temp = results[j].split("::");
				k = document.createElement('option');
				k.value= tab_temp[0];
				i.appendChild(k);
				l = document.createTextNode(tab_temp[1]);
				k.appendChild(l);
		
				if(id_temp_list != 0 && id_temp_list == tab_temp[0]) {
					i.selectedIndex = true;
				}
			}
		}
	});
}

function getInfosSsDossier(cas) {
	if($('sel_'+cas) && $('sel_'+cas).options[$('sel_'+cas).selectedIndex].value !=0) {
		var id = $('sel_'+cas).options[$('sel_'+cas).selectedIndex].value;
		var url = "action_form_galerie.php?cas=6&id_ev="+id;    
		  
		new Ajax.Request(url, {
			onSuccess: function(transport) {
				InfosSsDossier = transport.responseText;
				majList(3);
			}
		});
	} else if(cas==3) {
		$("titre_dossier_recherche").style.visibility = "hidden";
		$("liste_dossier_recherche").style.visibility = "hidden";			
	}
}

function addSelect(cas,id,type) {

	id_select_temp = id;

	if($(id))
		var id_dossier = $(id).value;
		
	if($('3'))
		var id_ev = $('3').value;
		// action_form_galerie.php?cas=
	var param = url22 + cas +'&id_dossier='+id_dossier + '&id=' + id + '&id_ev=' + id_ev;
	  
	if(type == url22) {
		if($('lien_titre_arbo'))
			$('lien_titre_arbo').href = url_actuelle +'&id_dossier=' + id_dossier;
	}

	new Ajax.Request(param, {
		onSuccess: function(transport) {
			if(transport.responseText!="") {
				var nouveauDiv = document.createElement("div");
				var id = "div_"+id_select_temp;
				nouveauDiv.id= id;
				nouveauDiv.innerHTML = transport.responseText;
				if($('c_rech_ss_dossier').hasChildNodes())	
					$('c_rech_ss_dossier').removeChild($('c_rech_ss_dossier').firstChild);
				$('c_rech_ss_dossier').appendChild(nouveauDiv);
			}
		}
	});
}

/*Déroule les sous-menus d'un reportage*/
function majMenusDroit(id) {
  var idFind = null

	for(i = id; i < id+20; i++) {
		idFind = "div_"+i;
		if($(idFind))
			findObj('c_rech_ss_dossier').removeChild($(idFind));	
	}	
}
/*Permet d'obtenir le nom du dossier*/
function getNomDossierDroit(id_select) {
	if($(id_select)){
		var id_dossier = $(id_select).value;
		// action_form_galerie.php?cas=
		param = url22 + "5&id_dossier=" + id_dossier;

		new Ajax.Request(param, {
			onSuccess: function(transport) {
				$('recap_recherche').innerHTML = transport.responseText.replace("::::", "'");
			}
		});
	}  
}


function majListeMin(cas,annee,id_cat,id_ev,dossier,nom_annee,nom_id_cat,nom_id_ev,nom_dossier,mini,nom_champ,id_champ) {
	var recap_recherche = "";
	var nbmin = readCookie("gal_nbmini");
	
	if(!nbmin) {
		nbmin = 12;
	}
	
	if(cas == 0) {
		 liste1 = $('sel_1').value;
		 liste5 = $('sel_1').options[$('sel_1').selectedIndex].text;
		 liste2 = $('sel_2').value;
		 liste6 = $('sel_2').options[$('sel_2').selectedIndex].text;
		 liste3 = $('sel_3').value;
		 liste7 = $('sel_3').options[$('sel_3').selectedIndex].text;		  
		 liste4 = $('sel_4').value;
		 liste8 = $('sel_4').options[$('sel_4').selectedIndex].text;
	} else if(cas == 1) {
		liste1 = null;
		liste2 = null;
		liste3 = null;
		liste4 = null;
		liste5 = null;
		liste6 = null;
		liste7 = null;
		liste8 = null;		  
		
		if(annee && annee != -1)
			liste1 = annee;		  
		if(id_cat && id_cat != -1)			   
			liste2 = id_cat;
		if(id_ev && id_ev != -1)
			liste3 = id_ev;		
		if(dossier && dossier != -1)			
			liste4 = dossier;	
		if(nom_annee && nom_annee != -1)		   
					liste5 = nom_annee;		  
		if(nom_id_cat && nom_id_cat != -1)
			liste6 = nom_id_cat;
		if(nom_id_ev && nom_id_ev != -1)
			liste7 = nom_id_ev;		  
		if(nom_dossier && nom_dossier != -1)
			liste8 = nom_dossier;	
	} else if(cas == 2) {
		if(annee && annee != -1)
			liste1 = annee;		  
		if(id_cat && id_cat != -1)			   
			liste2 = id_cat;
		if(id_ev && id_ev != -1)
			liste3 = id_ev;		
		if(dossier && dossier != -1)			
			liste4 = dossier;	
		if(nom_annee && nom_annee != -1)		   
					liste5 = nom_annee;		  
		if(nom_id_cat && nom_id_cat != -1)
			liste6 = nom_id_cat;
		if(nom_id_ev && nom_id_ev != -1)
			liste7 = nom_id_ev;		  
		if(nom_dossier && nom_dossier != -1)
			liste8 = nom_dossier;	
	} else if(cas==4) {
		liste1 = $('sel_1').value;
		liste5 = $('sel_1').options[$('sel_1').selectedIndex].text;
		liste2 = $('sel_2').value;
		liste6 = $('sel_2').options[$('sel_2').selectedIndex].text;
		liste3 = $('sel_3').value;
		liste7 = $('sel_3').options[$('sel_3').selectedIndex].text;		  
		liste4 = $('sel_4').value;
		liste8 = $('sel_4').options[$('sel_4').selectedIndex].text;
		var champ = $(id_champ).value;
	} else if(cas == 5) {
		liste1 = $('sel_1').value;
		liste5 = $('sel_1').options[$('sel_1').selectedIndex].text;
		liste2 = $('sel_2').value;
		liste6 = $('sel_2').options[$('sel_2').selectedIndex].text;
		liste3 = $('sel_3').value;
		liste7 = $('sel_3').options[$('sel_3').selectedIndex].text;
	} 

	if(liste1 && liste1 != null && liste1 !=0) {
		recap_recherche+="<a href='#'>"+liste5+"</a>";
	}
	
	if(liste2 && liste2 != null && liste2 !=0) {
		recap_recherche+=" > <a href='#' onclick=\"majListeMin(1,'"+liste1+"','"+liste2+"',0,0,'"+liste5+"','"+liste6+"')\">"+liste6+"</a>";
	}
	
	if(liste3 && liste3 != null && liste3 !=0) {
		recap_recherche+=" > <a href='#' onclick=\"majListeMin(1,'"+liste1+"','"+liste2+"','"+liste3+"',0,'"+liste5+"','"+liste6+"','"+liste7+"')\">"+liste7+"</a>";
	}
	
	if(liste4 && liste4 != null && liste4 !=0) {
		recap_recherche+=" > <a href='#' onclick=\"majListeMin(1,'"+liste1+"','"+liste2+"','"+liste3+"','"+liste4+"','"+liste5+"','"+liste6+"','"+liste7+"','"+liste8+"')\">"+liste8+"</a>";
	}

	if(mini && mini != -1) {
		// liste.php?
		param = url7 + "annee=" + liste1 + "&id_cat="+liste2+"&id_ev="+liste3+"&id_dossier="+liste4+"&min="+mini+"&max="+nbmin;
	} else if(cas==5) {
		// liste.php?
		param = url7 + "annee=" + liste1 + "&id_cat="+liste2+"&id_ev="+liste3+"&max="+nbmin;
	} else {
		// liste.php?
		param = url7 + "annee=" + liste1 + "&id_cat="+liste2+"&id_ev="+liste3+"&id_dossier="+liste4+"&max="+nbmin;
	}

	if(nom_champ && nom_champ != -1) {
		var num_page = $(nom_champ).value;  
		param += '&numero_page='+num_page;  
	}
	
	if(champ) {
		param += '&id_champ=' + champ;  
	}
	
	if(liste3!=0 /*&& liste2!=0*/) {
		new Ajax.Updater('miniatures', param, {
			onSuccess: function(transport) {
				$('recap_recherche').innerHTML = recap_recherche;
			}
		});
	}
}

/*Met à jour le cadre de recherche*/
function majCadreRecherche(cas) {
	cas_temp_recherche = cas;
	var param2 = "";
	chaine = location.search.substring(1);
	
	if (chaine) { // si chaine est vide c'est pas la peine de continuer
		variables = chaine.split("&");
		_GET = new Array();
		for (i in variables) {
			//alert(variables[i]);
			if(typeof(variables[i]) == String) {
				get = variables[i].split('=');
				_GET[get[0]] = unescape(get[1]);
			}
		}
		for (i in _GET) {
			if(i<_GET.length)//alert(i);
				param2 = param2 +'&'+ i+'='+_GET[i];
		}
	}
	//recherche.php?cas=
	param = url9 + cas + param2;		  

	new Ajax.Request(param, {
		onSuccess: function(transport) {
			if($('c_recherche').innerHTML = transport.responseText) {
				if(cas_temp_recherche == 1){
					getInfosSsDossier(3);
					majChampsRecherche();
				}
			}
		}
	});
}

/*Redirige le panier en fonction de la session en cours*/
function redir_panier() {

	var param2 = "";
	var url = "";
	var url2 = self.location.href;
	var tab = [];
	
	tab = url2.split("?");
	taille = tab.length - 1;	

	if(tab[1] == null || tab[1] == "panier=1") {
		url = "panier.php";
	} else {
		chaine = location.search.substring(1);
		if (chaine) { // si chaine est vide c'est pas la peine de continuer
			variables = chaine.split("&");
			_GET = new Array();
			for (i in variables) {
				get = variables[i].split("=");
				_GET[get[0]] = unescape(get[1]);
			}
			for (i in _GET) {
				param2 = param2 +'&'+ i+'='+_GET[i];
			}
		} else {
		   liste1 = $('1').value;
		   liste2 = $('2').value;
		   liste3 = $('3').value;
		   liste4 = $('4').value;
		
		   if(liste1 !=0)
			   param2 += "annee="+liste1;
		   if(liste2 !=0)
			   param2 += "&id_cat="+liste2;
		   if(liste3 !=0)
			   param2 += "&id_ev="+liste3;
		   if(liste4 !=0)
			   param2 += "&dossier="+liste4;		   
		}	
		url = "panier.php?"+param2;
		url = url.replace("?&","?");
	}
	location.href=url;
}
/*Met à jour les champs de recherche*/
function majChampsRecherche() {
	var annee = 0;
	var id_cat = 0;
	var id_ev = 0;
	var chaine = location.search.substring(1);
	
	if (chaine) { // si chaine est vide c'est pas la peine de continuer
		variables = chaine.split("&");
		_GET = new Array();
		for (i in variables) {
			get = variables[i].split("=");
			_GET[get[0]] = unescape(get[1]);
		}
		for (i in _GET) {
			if(i=="annee")
				annee = _GET[i];
			if(i=="id_cat")
				id_cat = _GET[i];			
			if(i=="id_ev")
				id_ev = _GET[i];				
		}
	}

	if(id_cat != 0)
		majList(1,id_cat,annee,'no');
	if(id_ev !=0)
		majList(2,id_ev,annee,'no');
		
	majList(3);
}
/*Permet de passer d'une langue à une autre*/
function modifierlangue(url) {
	var langue = $('langue').value;
	url = url + "?lang=" + langue;
	location.href = url;
}
/**************PAGE INTRO**************/
/* Met a jour la liste des evenements grace au menu */
function majListeEvMenuCat(id_cat) {
	// list_ev.php?id_config=
	param = url10 + "?id_cat=" + id_cat;
	new Ajax.Updater('cadre_ev', param);
}

/*Met à jour la liste des évènements dans la page intro.php*/
function majListeEv(cas) {
	if(cas == 1) {
		var id_cat = $('categorie').options[$('categorie').selectedIndex].value;
		var annee = $('annee').options[$('annee').selectedIndex].value;
		var id_ev = $('evenement').options[$('evenement').selectedIndex].value;
		
		//majCatIntro(annee);
		majEvIntro(annee,id_cat);
		if(id_cat == 0) {
			// list_ev.php
			param = url10;
			if(annee != 0) {
			 	param +=  "?annee="+annee;
			}
			new Ajax.Updater('bannieres', 'bannieres.php');
		} else {
			// list_ev.php
			param = url10 + "?id_cat=" + id_cat;
			if(annee != 0) {
			 	param +=  "&annee="+annee;
			}
			//var ajaxurl = 'bannieres.php?id_cat='.id_cat;
			new Ajax.Updater('bannieres', 'bannieres.php?id_cat='+id_cat);
		}
	} else if(cas == 0) {
		// list_ev.php
		param = url10;		  
	}
	  
	if(id_ev && id_ev!=0 && cas!=0){
		location.href="galerie.php?annee="+annee+"&id_cat="+id_cat+"&id_ev="+id_ev;  
	}
	new Ajax.Updater('cadre_ev', param);
}

/*Met à jour la liste des catégories dans la page intro.php*/
function majCatIntro() {
	if($('annee')) {
		var annee = $('annee').options[$('annee').selectedIndex].value;
		// action_intro.php?cas=
		param = url15 + '2' + '&annee=' + annee;		  
		new Ajax.Request(param, {
			onSuccess: function(transport) {
				results = transport.responseText.split(";;");
				taille = results.length - 1;
				var i = $('categorie');
	
				while (i.options.length>0) {
					i.options[0] = null;
				}
				var k = document.createElement('option');
				k.value= '0';
				i.appendChild(k);
				var l = document.createTextNode('Choisissez');
				k.appendChild(l);
				for(var j=0;j<taille;j++) {
					var tab_temp = results[j].split(",");
					k = document.createElement('option');
					k.value= tab_temp[0];
					i.appendChild(k);
					l = document.createTextNode(tab_temp[1]);
					k.appendChild(l);
				}
			}
		});
	}
}

function majEvIntro(annee,categorie) {
	// action_intro.php?cas=
	param = url15 + '1' + '&annee=' + annee + '&cat=' + categorie;		  
	new Ajax.Request(param, {
		onSuccess: function(transport) {
			results = transport.responseText.split(";");
			taille = results.length - 1;
			
			var i = $('evenement');
			while (i.options.length>0){
				i.options[0] = null;
			}
			
			var k = document.createElement('option');
			k.value= '0';
			i.appendChild(k);
			var l = document.createTextNode('Choisissez');
			k.appendChild(l);
			for(var j=0;j<taille;j++) {
				var tab_temp = results[j].split(",");
				k = document.createElement('option');
				k.value= tab_temp[0];
				i.appendChild(k);
				l = document.createTextNode(tab_temp[1]);
				k.appendChild(l);
			}
		}
	});
}

/* FORMULAIRE DE RECHERCHE AVANCEE*/

var cas_vis = 0;
/*Afficher plus de critères pour les IPTC/Exifs*/
function aff_criteres() {
	var div = $('more_critere');
	
	if(cas_vis == 0) {
		div.style.visibility = "visible";
		cas_vis = 1;
	} else if(cas_vis == 1) {
		div.style.visibility = "hidden";
		cas_vis = 0;
	}
}

/*Mise à jour de la liste des années des évènements*/
function majListeAnneesRechAv() {
	var idCat;
	var myurl;
	
	idCat=$('categorie_rech').value;
	// action_form_recherche.php?cas=
	myurl = url11 + '2' + "&id_cat="+idCat;
	
	new Ajax.Request(myurl, {
		onSuccess: function(transport) {
			results = transport.responseText.split(";");
			var i=$('rech_annee');
			var taille=results.length - 1;
			
			while(i.options.length>0){
				i.options[0] = null;
			}
	
			var k=document.createElement('option');
			k.value='0';
			i.appendChild(k);
			var l=document.createTextNode('Choisissez');
			k.appendChild(l);
			for(var j=0;j<taille;j++) {
				var tab_temp = results[j].split("::");
				k = document.createElement('option');
				k.value= tab_temp[0];
				i.appendChild(k);
				l = document.createTextNode(tab_temp[1]);
				k.appendChild(l);
			}
		}
	});
}

/*Recherche d'évènement*/
function majListEv() {
	var val = $('categorie_rech').value;  
	var annee = $('rech_annee').value;  
	
	// action_form_recherche.php?cas=
	param = url11 + '1' + "&id_cat="+val+"&annee="+annee;
	
	new Ajax.Request(param, {
		onSuccess: function(transport) {
			results = transport.responseText.split(";");
			taille = results.length - 1;
			var i = $('evenement_rech');
			while (i.options.length>0) {
				i.options[0] = null;
			}
			var k = document.createElement('option');
			k.value= '0';
			i.appendChild(k);
			var l = document.createTextNode('Choisissez');
			k.appendChild(l);
			for(var j=0;j<taille;j++){
				var tab_temp = results[j].split("::");
				k = document.createElement('option');
				k.value= tab_temp[0];
				i.appendChild(k);
				l = document.createTextNode(tab_temp[1]);
				k.appendChild(l);
			}
		}
	});
}

/*Affiche le résultat d'une recherche sur la page intro*/
function majListeRechAvIntro() {
	// form_recherche.php
	new Ajax.Updater('recap_recherche', url16);
}

function affResults(mini,div) {		
	if(mini && mini != -1) {
		// action_recherche_av.php
		param = url17 + "?min="+mini; 
	} else if(div) {
		var obj=$(div);
		// action_recherche_av.php
		param = url17 + "?numero_page="+obj.value;
	} else {
		// action_recherche_av.php
		param = url17;
	}
	
	new Ajax.Updater('miniatures', param, {
		onSuccess: function(transport) {
			if (transport.responseText!=""){
				//$('recap_recherche').innerHTML = "";
				//$("backDiv").style.display="none";
				//$("rech_av_att").style.display="none";
			}
		}
	});
}

////////////////PAGE PANIER//////////////////////////////

function majPanier(cas,id_photo) {
	if(cas && cas==1)
		majPanierDyn(id_photo,2);
	// majPanier.php
	new Ajax.Updater('c_panier', url13);
}

/*Gestion du prix d'une licence - ne doit plus servir car il n'y a pas de traduction*/
function majDroitsListe(id_photo) {
	var url_temp = "";
	// action_panier.php?id_photo=
	url_temp = url14 + id_photo;
	
	new Ajax.Request(url_temp, {
		onSuccess: function(transport) {
			results2 = transport.responseText.split("!*!*!*!");
			taille = results2.length - 1;
		
			var html = '';
			var html2 = '';
		
			for(i=0;i<taille;i++) {
				results = results2[i].split(";");
				html2 = results[10]+' &euro;';
				html += 'Nom du projet : <span class="infos_droits">'+ results[9] +'</span><br>';	
				html += 'Cat&eacute;gorie : <span class="infos_droits">'+ results[1] +'</span><br>';
				html += 'Type de produit : <span class="infos_droits">'+ results[2] +'</span><br>';
				html += 'Usage : <span class="infos_droits">'+ results[3] +'</span><br>';
				html += 'Quantit&eacute; : <span class="infos_droits">'+ results[4] +'</span><br>';		
				html += 'Secteur d\'activit&eacute; : <span class="infos_droits">'+ results[5] +'</span><br>';
				html += 'Date de d&eacute;but d\'utilisation : <span class="infos_droits">'+ results[6] +'</span><br>';
				html += 'Dur&eacute; d\'utilisation : <span class="infos_droits">'+ results[8] +'</span><br>';
				html += '<br><a href="#" onClick="window.open(\'droit_calc.php?id_photo='+ results[0] +'\',\'Panier\',\'toolbar=1,menubar=1,location=1,scrollbars=0,width=800,height=700, left=100, top=100\');">Calculer le prix</a> | <a href="javascript:majDroitsListe('+results[0]+')">Appliquer ce choix a tous</a>';
		//		findObj('total_final').innerHTML = "Total : "+results[8]+" &euro;";
				$('total_'+results[0]).innerHTML = html2;
				$('recap_'+results[0]).innerHTML = html;
			}
			majTotalFinal();
		}
	});
}

/*Gestion du message*/
function majMessage(cas,id_message,id_client) {
	if(cas==1){
		$('message').style.display="none";
		$('backDiv').style.display="none";	
	} else if(cas==2) {
		// action_message.php?id_message=
		var url = url18 + id_message + "&id_client=" + id_client;
		
		new Ajax.Request(url, {
			onSuccess: function(transport) {
				$('message').style.display="none";
				$('backDiv').style.display="none";	
			}
		});
	}
}

/*******GALERIE PARTIE TIRAGE********/

/*Permet d'obtenir le nom du dossier en cours*/
function getNomDossier(id_dossier) {
	// action_form_galerie.php?cas=
	param = url2 + "5&id_dossier=" + id_dossier;
	
	new Ajax.Request(param, {
		onSuccess: function(transport) {
			$('recap_recherche').innerHTML = transport.responseText.replace("'","::::");
		}
	});
}

/*Mets à jour la liste des miniatures pour la partie tirage*/
function majListeMinTirage(id_ev, id_dossier, id) {
	var nbmin = readCookie("gal_nbmini");
	if(!nbmin)
		nbmin = 12;

	if(id_dossier==-2)
		if($(id))
			id_dossier = $(id).value;
	  
	if(id_dossier != -1) {
		// liste.php?
	  param = url7 + "id_dossier=" + id_dossier+"&max="+nbmin;
	} else {
		// liste.php?
	  param = url7 + "id_ev=" + id_ev+"&max="+nbmin;
	} 
	/*	  if(nom_champ)
	{
	var num_page = $(nom_champ).value;  
	param += '&numero_page='+num_page;  
	}*/
	new Ajax.Updater('miniatures', param, {
		onSuccess: function(transport) {
			$('mini_par_page').onchange = function() {
				createCookie('gal_nbmini', this.options[this.selectedIndex].value, 7);
				majListeMinTirage(id_ev, id_dossier, id);
			}
		}
	});
}

/* Permet de récupérer la liste des mots cles*/
function majListeMotsclefs(mot, debut, div) {
	if(!debut)
		debut = 0;
	if(div)	{
		var obj=$(div);
		// action_recherche_av.php
		param = url17 + "?mots_cles=" + mot+"&numero_page="+obj.value;	
	} else {
		param = url17 + "?mots_cles=" + mot+'&min='+debut;
	}
	$("backDiv").style.display="";
	$("rech_av_att").style.display="";
	// action_recherche_av.php
	
	
	new Ajax.Updater('miniatures', param, {
		onSuccess: function(transport) {
			$("backDiv").style.display="none";
			$("rech_av_att").style.display="none";
		}
	});
}

/******************PARTIE TIRAGE******************/

/*Gère la quantité d'un produit dans le panier*/
function majQuantitePanier(id,nb) {
	id_produit = $('produit_'+id).value;
	if(id_produit!=0) {
		id_temp = id;
		nb_temp = nb;
		// action_panier.php?id_produit=
		param = url21 + id_produit +'&cas=1&nb='+nb;	
		
		new Ajax.Request(param, {
			asynchronous: false, 
			onSuccess: function(transport) {
				results = transport.responseText.split(";;");
				var total = results[0];
				var quantite = results[1];

				var i = $('quantite_'+id_temp);

				while (i.options.length>0){
					i.options[0] = null;
				}

				for(var j=1;j<=total;j++){
					k = document.createElement('option');
					k.value= j;
					i.appendChild(k);
					l = document.createTextNode(j);
					k.appendChild(l);
					
					if(j == quantite)
					{
						Try.these(
							function() { l.selectedIndex = true;}, // firefox
							function() { i.selectedIndex = j;}); 		// ie
					}
				}
			}
		});
		/* majPrixProduitPanier */
		id_produit = $('produit_'+id).value;
		if(id_produit!=0)	{
			id_temp = id;
			nb_temp = nb;
	
			var quantite = $('quantite_'+id).value;
			// action_panier.php?id_produit=
			param = url21 + id_produit +'&cas=2&nb='+nb+'&quantite='+quantite;	
	
			new Ajax.Request(param, {
				asynchronous: false,
				onSuccess: function(transport) {
					$('prix_u_'+id).innerHTML = transport.responseText+' &euro;';
				}	
			});
		}
		
		/* majPrixProduitTotal */
		var sel_quantite = $('quantite_'+id).value;
		if(sel_quantite != 0){
			id_temp = id;
			nb_temp = nb;
			// action_panier.php?id_produit=
			param = url21 + '-1' +'&cas=3&nb='+nb+'&quantite='+sel_quantite;	
			
			new Ajax.Request(param, {
				asynchronous: false,
				onSuccess: function(transport) {
					$('total_'+id_temp).innerHTML = transport.responseText+' &euro;';
				}
			});
		}
		
		/* majTotalFinal */
		// action_panier.php?id_produit=
		param = url21 + '-1' +'&cas=4';
		new Ajax.Request(param, {
			asynchronous: false,
			onSuccess: function(transport) {
				if($('total_final')) {
					$('total_final').innerHTML = 'Total : '+transport.responseText+' &euro;';
				}
			}
		});
	}
}

function majQuantitePanier2(id,nb) {
	/* majPrixProduitPanier */
	id_produit = $('produit_'+id).value;
	if(id_produit!=0)	{
		id_temp = id;
		nb_temp = nb;

		var quantite = $('quantite_'+id).value;
		// action_panier.php?id_produit=
		param = url21 + id_produit +'&cas=2&nb='+nb+'&quantite='+quantite;	

		new Ajax.Request(param, {
			asynchronous: false,
			onSuccess: function(transport) {
				$('prix_u_'+id).innerHTML = transport.responseText+' &euro;';
			}	
		});
	}
	
	/* majPrixProduitTotal */
	var sel_quantite = $('quantite_'+id).value;
	if(sel_quantite != 0){
		id_temp = id;
		nb_temp = nb;
		// action_panier.php?id_produit=
		param = url21 + '-1' +'&cas=3&nb='+nb+'&quantite='+sel_quantite;	
		
		new Ajax.Request(param, {
			asynchronous: false,
			onSuccess: function(transport) {
				$('total_'+id_temp).innerHTML = transport.responseText+' &euro;';
			}
		});
	}
	
	/* majTotalFinal */
	// action_panier.php?id_produit=
	param = url21 + '-1' +'&cas=4';
	new Ajax.Request(param, {
		asynchronous: false,
		onSuccess: function(transport) {
			if($('total_final')) {
				$('total_final').innerHTML = 'Total : '+transport.responseText+' &euro;';
			}
		}
	});
}

/*Affiche le total final*/
function majTotalFinal() {
	// action_panier.php?id_produit=
	param = url21 + '-1' +'&cas=4';
	
	new Ajax.Request(param, {
		asynchronous: false,
		onSuccess: function(transport) {
			if($('total_final')) {
				$('total_final').innerHTML = 'Total : '+transport.responseText+' &euro;';
			}
		}
	});
}

/*Gère la bordure du tirage papier - Partie tirage*/
function majBordure(id,nb) {
	var bordure = $('bordure_'+id).value;

	if(bordure == 5){
		$('mess_erreur').innerHTML = 'Veuillez choisir une bordure pour chaque photo';
	} else {
		$('mess_erreur').innerHTML = '';
		// action_panier.php?id_produit=
		param = url21 + '-1' +'&cas=5&nb='+nb+'&bordure='+bordure;
		Ajax.Request(param);
	}
}

/*Affiche la bordure du tirage papier - partie tirage*/
function affBordure(id, i) {
	id_produit = $('produit_'+id).value;
	// action_panier.php?id_produit=
	param = url21 + id_produit +'&cas=6&id='+id+"&i="+i;

	id_temp = id;
	
	new Ajax.Request(param, {
		onSuccess: function(transport) {
			if(transport.responseText == 0) {
				$('bordure_'+id_temp).style.visibility = "hidden";
			} else if(transport.responseText == 1
						 && $('bordure_'+id_temp).style.visibility == "hidden") {
				$('bordure_'+id_temp).style.visibility = "";
			}
		}
	});
}

/*Affiche le formulaire de contact*/
function majListeContact(id) {
	param = "form_contact.php";
    id_dest_temp = id;
	
	new Ajax.Updater(id_dest_temp, param);
}

/*Vérifie l'accès d'un client à un reportage par rapport à un mot de passe*/
function verifAccesEv(id_ev) {
	if($("pass_ev")) {
		var mdp = $("pass_ev").value;

		param = "action_form_galerie.php?id_ev="+id_ev+"&cas=7&pass_ev="+mdp;
		new Ajax.Request(param, {
			onSuccess: function(transport) {
				if(transport.responseText == "1") {
					$('login').style.display="none";
					$('backDiv').style.display="none";
				} else {
					location.href = "intro.php";
				}
			}
		});
	}
}

/* sens : 0 -> sens psitif (clockwise)
	  1 -> sens negatif (counterclockwise) */
function rotationPhoto(id_photo,sens) {
	$('miniatures').style.cursor="wait";

	new Ajax.Updater(id_photo, "action_rotation.php?id_photo="+id_photo+"&sens="+sens, {
		onSuccess: function(transport) {
			var now=new Date();
			$('miniatures').style.cursor="auto";
			$("photo_"+id_photo).src="rotation.php?id_photo="+id_photo+"&forcereload="+now.getTime();
		}
	});
}

function cacherPhoto(id_photo,cacher) {
	$('miniatures').style.cursor="wait";

	new Ajax.Request("action_photo.php?id_photo="+id_photo+"&cacher="+cacher , {
		onSucces: function(transport) {
			var ret=transport.responseText.split('::');
			var id_photo=ret[0];
			var cacher=ret[1];
			
			$('miniatures').style.cursor="auto";
			
			if(cacher==0) {
				$("cacher_"+id_photo).src="../../images/cacher.png";
				$("lcacher_"+id_photo).onclick=function() { cacherPhoto(id_photo,1); };
			} else {
				$("cacher_"+id_photo).src="../../images/afficher.png";
				$("lcacher_"+id_photo).onclick=function() { cacherPhoto(id_photo,0); };
			}
		}
	});
}


