// JavaScript Document
function Page(pager){
	var page=pager;
	if(page == 'services'){
		$("#contenub").load("services.php");
		document.getElementById("sousmenu").innerHTML='';
	}
	if(page == 'fournitures'){
		$("#contenub").load("fournitures.php");
		document.getElementById("sousmenu").innerHTML='';
	}
	if(page == 'album'){
		$("#contenub").load("album.php");
		document.getElementById("sousmenu").innerHTML='';
	}
}
function Searchusers(){
	var val=encodeURI(document.getElementById("word_search").value);
	
	Searching="searchusers.php?val="+val;
	$("#contenub").load(Searching);
}
function Email(){
	var nom=encodeURI(document.getElementById("nom").value);
	var email=encodeURI(document.getElementById("email").value);
	var sujet=encodeURI(document.getElementById("sujet").value);
	var message=encodeURI(document.getElementById("message").value);
	
	document.getElementById("answer").innerHTML='';
	if(nom == ''){document.getElementById("answer").innerHTML='<div style=\"color:red; margin-left:125px; font-weight:bold\">Veuillez entrer votre nom.</div>';}
	if(email==''){document.getElementById("answer").innerHTML='<div style=\"color:red; margin-left:125px; font-weight:bold\">Veuillez entrer votre adresse mail.</div>';}
	if(message==''){document.getElementById("answer").innerHTML='<div style=\"color:red; margin-left:125px; font-weight:bold\">Veuillez entrer votre message.</div>';}
	else if((nom!='') && (email!='') && (message!='')) {
		mail="mail.php?nom="+nom+"&email="+email+"&sujet="+sujet+"&message="+message;
		$("#answer").load(mail);
	}
}
/*function Modifier(lid){
	$("#modif").load("modifier.php?lid="+lid);
}

function Miseajour(){
	var id=encodeURI(document.getElementById("cacher_up").value);
	var cat=encodeURI(document.getElementById("cat_up").value);
	var desc=encodeURI(document.getElementById("desc_up").value);
	var sscat=encodeURI(document.getElementById("sscat_up").value);
	var nom=encodeURI(document.getElementById("nom_up").value);
	
	appel="update.php?id="+id+"&cat="+cat+"&desc="+desc+"&sscat="+sscat+"&nom="+nom;
 	$("#result").load(appel);
	$("#result").load(Searching);
}

function Chaine(Val) {
	this.Val=Val;
	this.Add=Add;
	this.Supr=Supr;
}

function Add(To_Add) {
	var separation=";";
	this.Val=this.Val+To_Add+separation;
}

function Supr(To_Supr) {
	var Reg= new RegExp(";"+To_Supr+";","g");
	this.Val=this.Val.replace(Reg,";");
}

var Niark = new Chaine(";");// La chaine contenant les checkbox cochées 

function cocher(box) {
	if (box.checked) { Niark.Add(box.value)} else { Niark.Supr(box.value)}
}

function Supprimer() {
	supri="supprimer.php?+cocher="+Niark.Val;
	$("#result").load(supri);
	$("#result").load(Searching);
	Niark.Val='';
}

function Verif_form_ajout(formu){
	var index=formu.selectedIndex;
	var actif_value=encodeURI(formu.value);
	var form_id=encodeURI(formu.id);
	var temoin='a';
	var cat_select=encodeURI(document.getElementById("categorie").value);
	
//Nom des options du premier formulaire
	var fruitiers=encodeURI('Arbres fruitiers');
	var arbustes=encodeURI('Arbustes d\'ornement');
	var arbres_ornement=encodeURI('Arbres d\'ornement');
	var conifere=encodeURI('Conifères à isoler');
	var plantes_ornement=encodeURI('Plantes d\'ornement');
	var plantes_haie=encodeURI('Plantes de haies');
//Nom des formulaires
	var sous_categorie=encodeURI('sous_categorie');
	var nom=encodeURI('nom');
	var description=encodeURI('description');
	
	
	var form_ajout="verif_form_ajout.php?choisi="+actif_value+"&form_id="+form_id+"&temoin="+temoin;//apelle la page php et lui passe des variables

 		if(actif_value == fruitiers || actif_value == arbres_ornement || actif_value == plantes_ornement || actif_value == plantes_haie){//Si on choisi une option correspondant a l'une des 4 variables
			$("#sous_categorie_div").load(form_ajout);//alors on execute form_ajout dans #variete
			if(actif_value == fruitiers || actif_value == plantes_ornement){
			document.getElementById("persistant_div").innerHTML='';//supprime le formulaire de persistant
			}
		}
		if(actif_value == arbustes || actif_value == conifere || form_id == sous_categorie){
			$("#nom_div").load(form_ajout);
			document.getElementById("nom").focus();
			if(actif_value == arbustes || actif_value == conifere){
				document.getElementById("sous_categorie_div").innerHTML='';//supprime le formulaire de sous cat�gorie
				document.getElementById("formes_div").innerHTML='';//supprime le formulaire de formes
			}
		}
	
	if(form_id == nom && actif_value != null){
			$("#description_div").load(form_ajout);
	}
	if(form_id == description && cat_select != fruitiers){
			$("#persistant_div").load(form_ajout);
			temoin='c';
			form_ajout="verif_form_ajout.php?choisi="+actif_value+"&form_id="+form_id+"&temoin="+temoin;
			$("#image_div").load(form_ajout);
	}
	if(form_id == description && cat_select == fruitiers){
			temoin='b';
			form_ajout="verif_form_ajout.php?choisi="+actif_value+"&form_id="+form_id+"&temoin="+temoin;
			$("#formes_div").load(form_ajout);
			temoin='c';
			form_ajout="verif_form_ajout.php?choisi="+actif_value+"&form_id="+form_id+"&temoin="+temoin;
			$("#image_div").load(form_ajout);
	}
	/*if(document.getElementById("formes_div").innerHTML !='' || document.getElementById("persistant_div").innerHTML !=''){
		temoin='c';
		form_ajout="verif_form_ajout.php?choisi="+actif_value+"&form_id="+form_id+"&temoin="+temoin;
		$("#image_div").load(form_ajout);
	}
}

function Ajouter(){
	var fruitiers=encodeURI('Arbres fruitiers');
	var plantes_ornement=encodeURI('Plantes d\'ornement');
	var arbres_ornement=encodeURI('Arbres d\'ornement');
	var plantes_haie=encodeURI('Plantes de haies');
	var arbustes=encodeURI('Arbustes d\'ornement');
	var conifere=encodeURI('Conifères à isoler');
	
	var cat=encodeURI(document.getElementById("categorie").value);
	if(cat == fruitiers || cat == plantes_ornement || cat == arbres_ornement || cat == plantes_haie){
		var sscat=encodeURI(document.getElementById("sous_categorie").value);
	}
	var nom=encodeURI(document.getElementById("nom").value);
	var desc=encodeURI(document.getElementById("description").value);
	var formes='';
	var persistant='';
	var nom_img=encodeURI(document.getElementById("nom_img").value);
	
	if(cat == fruitiers){
		for(var i=0;i<5;i++){
			if(document.getElementsByName("formes")[i].checked){
				formes=formes+document.getElementsByName("formes")[i].value;
			}
		}
		formes=encodeURI(formes);
		
		ajout="ajouter_formes.php?cat="+cat+"&sscat="+sscat+"&nom="+nom+"&desc="+desc+"&formes="+formes+"&nom_img="+nom_img;
		$("#msg").load(ajout);
		$("#result").load("search.php?val="+nom);
	}
	else{
		if(cat == fruitiers || cat == plantes_ornement || !document.getElementById("persistant").checked){
			persistant='';
		}
		else{
			if(cat == arbustes || cat == conifere){
				persistant='Persistant';
				ajout="ajouter_pers1.php?cat="+cat+"&nom="+nom+"&desc="+desc+"&persistant="+persistant+"&nom_img="+nom_img;
				$("#msg").load(ajout);
				$("#result").load("search.php?val="+nom);
				alert('coucou');
			}
			else{
				persistant='Persistant';
				ajout="ajouter_pers2.php?cat="+cat+"&sscat="+sscat+"&nom="+nom+"&desc="+desc+"&persistant="+persistant+"&nom_img="+nom_img;
				$("#msg").load(ajout);
				$("#result").load("search.php?val="+nom);
			}
				
		}
	}
}*/
