function remplirSelect() {
	var obj=document.getElementById("sousCategorie");
	obj.open;
	obj.innerHTML="chargement...";
	obj.close;

	var xhr_object=null;
	if(window.XMLHttpRequest)
		xhr_object=new XMLHttpRequest();
	else if(window.ActiveXObject)
		xhr_object=new ActiveXObject("Microsoft.XMLHTTP");
	else {
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
		return;
	}
	// Appel de la page PHP
	xhr_object.open("POST", "div_cadre.php", true);
	xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	// Envoi des éventuels paramètres
	xhr_object.send("idCategorie="+document.monform.idCategorie.value);
	// Attente des résultats
	xhr_object.onreadystatechange = function() {
		if(xhr_object.readyState == 4) {
		// Récupération du contenu de page dans un SELECT
		// on peut faire la même chose pour alimenter un DIV ou n'importe quoi d'autre
			obj.open;
			obj.innerHTML=xhr_object.responseText;
			obj.close;
		}
	}
}

function afficheCoordonnees() {
	var obj=document.getElementById("affichage");
	obj.open;
	obj.innerHTML="chargement...<br /><br />";
	obj.close;

	var xhr_object=null;
	if(window.XMLHttpRequest)
		xhr_object=new XMLHttpRequest();
	else if(window.ActiveXObject)
		xhr_object=new ActiveXObject("Microsoft.XMLHTTP");
	else {
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
		return;
	}
	// Appel de la page PHP
	xhr_object.open("POST", "afficheCoordonnees.php", true);
	xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	// Envoi des éventuels paramètres
	xhr_object.send("dept="+document.formDept.monDept.value);
	// Attente des résultats
	xhr_object.onreadystatechange = function() {
		if(xhr_object.readyState == 4) {
		// Récupération du contenu de page dans un SELECT
		// on peut faire la même chose pour alimenter un DIV ou n'importe quoi d'autre
			obj.open;
			obj.innerHTML=xhr_object.responseText;
			obj.close;
		}
	}
}

function recherche(val) {
	//alert(val);
	document.getElementById('zoneRecherche').style.display="block";
	document.getElementById('zoneInfo').style.display="none";
	remplirRecherche();	
}

function rechercheAvancee(val) {
	document.getElementById('rechercheAvancee').style.display="block";
	document.getElementById('rechercheNormale').style.display="none";
}

function rechercheAvanceeOut(val) {
	document.getElementById('rechercheAvancee').style.display="none";
	document.getElementById('rechercheNormale').style.display="block";
}

function rechercheOut() {
	document.getElementById('zoneInfo').style.display="block";
	document.getElementById('zoneRecherche').style.display="none";
}

//////////////////////////////////////////////
// UTILISEE POUR LA RECHERCHE PAR REFERENCE //
//////////////////////////////////////////////
function remplirRecherche() {
	// Obj destination
	var obj=document.getElementById("resRecherche");
	obj.open;
	obj.innerHTML="recherche...";
	obj.close;

	var xhr_object=null;
	if(window.XMLHttpRequest)
		xhr_object=new XMLHttpRequest();
	else if(window.ActiveXObject)
		xhr_object=new ActiveXObject("Microsoft.XMLHTTP");
	else {
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
		return;
	}
	// Appel de la page PHP
	xhr_object.open("POST", "ajaxRecherche.php", true);
	xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	// Envoi des éventuels paramètres
	xhr_object.send("ref="+document.getElementById('ref').value);
	// Attente des résultats
	xhr_object.onreadystatechange = function() {
		if(xhr_object.readyState == 4) {
		// Récupération du contenu de page dans un SELECT
		// on peut faire la même chose pour alimenter un DIV ou n'importe quoi d'autre
			obj.open;
			obj.innerHTML=xhr_object.responseText;
			obj.close;
		}
	}
}

////////////////////////////////////////
// UTILISEE POUR LA RECHERCHE AVANCEE //
////////////////////////////////////////
function remplirSelectCategorie() {
	// Obj destination
	var obj=document.getElementById("infoCategorie");
	obj.open;
	obj.innerHTML="chargement...";
	obj.close;
	var obj2=document.getElementById("infoSousCategorie");
	obj2.open;
	obj2.innerHTML="Sélectionnez une catégorie";
	obj2.close;
		
	var xhr_object=null;
	if(window.XMLHttpRequest)
		xhr_object=new XMLHttpRequest();
	else if(window.ActiveXObject)
		xhr_object=new ActiveXObject("Microsoft.XMLHTTP");
	else {
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
		return;
	}
	// Appel de la page PHP
	xhr_object.open("POST", "ajaxRechercheAvancee.php", true);
	xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	// Envoi des éventuels paramètres
	xhr_object.send("partie=categorie&branche="+document.getElementById('branche').value);
	// Attente des résultats
	xhr_object.onreadystatechange = function() {
		if(xhr_object.readyState == 4) {
		// Récupération du contenu de page dans un SELECT
		// on peut faire la même chose pour alimenter un DIV ou n'importe quoi d'autre
			obj.open;
			obj.innerHTML=xhr_object.responseText;
			obj.close;
		}
	}
}

////////////////////////////////////////
// UTILISEE POUR LA RECHERCHE AVANCEE //
////////////////////////////////////////
function remplirSelectSousCategorie() {
	// Obj destination
	var obj=document.getElementById("infoSousCategorie");
	obj.open;
	obj.innerHTML="chargement...";
	obj.close;

	var xhr_object=null;
	if(window.XMLHttpRequest)
		xhr_object=new XMLHttpRequest();
	else if(window.ActiveXObject)
		xhr_object=new ActiveXObject("Microsoft.XMLHTTP");
	else {
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
		return;
	}
	// Appel de la page PHP
	xhr_object.open("POST", "ajaxRechercheAvancee.php", true);
	xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	// Envoi des éventuels paramètres
	xhr_object.send("partie=sousCategorie&categorie="+document.getElementById('categorie').value);
	// Attente des résultats
	xhr_object.onreadystatechange = function() {
		if(xhr_object.readyState == 4) {
		// Récupération du contenu de page dans un SELECT
		// on peut faire la même chose pour alimenter un DIV ou n'importe quoi d'autre
			obj.open;
			obj.innerHTML=xhr_object.responseText;
			obj.close;
		}
	}
}

//////////////////////////////////////////////////////////
// UTILISEE DANS LA PARTIE GESTION AJOUT SOUS CATEGORIE //
//////////////////////////////////////////////////////////
function remplirSelectCategorieAdmin(num) {
	// Obj destination
	var obj=document.getElementById("infoCategorie");
	obj.open;
	obj.innerHTML="chargement...";
	obj.close;
		
	var xhr_object=null;
	if(window.XMLHttpRequest)
		xhr_object=new XMLHttpRequest();
	else if(window.ActiveXObject)
		xhr_object=new ActiveXObject("Microsoft.XMLHTTP");
	else {
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
		return;
	}
	// Appel de la page PHP
	xhr_object.open("POST", "selectionCategorie.php", true);
	xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	// Envoi des éventuels paramètres
	switch (num)
	{
		case 1:	xhr_object.send("partie=categorie&modif=non&idBranche="+document.getElementById('idBranche').value); break;
		case 2: xhr_object.send("partie=categorie&modif=oui&idBranche="+document.getElementById('idBranche').value); break;
	}
	// Attente des résultats
	xhr_object.onreadystatechange = function() {
		if(xhr_object.readyState == 4) {
		// Récupération du contenu de page dans un SELECT
		// on peut faire la même chose pour alimenter un DIV ou n'importe quoi d'autre
			obj.open;
			obj.innerHTML=xhr_object.responseText;
			obj.close;
		}
	}
}

function verifForm()
{
	if ((document.monform.branche.value==0) && (document.monform.style.value==0))
		alert("Veuillez spécifier au moins une branche ou un style.");
	else
		document.monform.submit();
}

function verifFormSelection()
{
	if (document.monform.branche.value==0)
		alert("Veuillez spécifier au moins une branche.");
	else
		document.monform.submit();
}

function ajoutProduit(id,reference,libelle,branche,categorie,sous_categorie)
{
	//alert("ajoute "+document.getElementById(id).value+" fois le produit n°"+id);
	if(document.getElementById(id).value!=0 && document.getElementById(id).value!=null && document.getElementById(id).value!='')
	{
		if (confirm("Vous allez ajouter à votre panier " + document.getElementById(id).value + " quantité(s) de la référence " + reference +"."))
			document.location.href="commande.php?action=AJOUT&id="+id+"&reference="+reference+"&libelle="+libelle+"&qte="+document.getElementById(id).value+"&branche="+branche+"&categorie="+categorie+"&sous_categorie="+sous_categorie;	
		else
			document.getElementById(id).value="";
	}
}

function hauteur(id)
{
	if (document.getElementById(id).offsetHeight < 460)   document.getElementById(id).style.height = '460px';
}

function hauteur2(id)
{
	if (document.getElementById(id).offsetHeight < 420)   document.getElementById(id).style.height = '420px';
}

function verifFormContact()
{
	if (document.monform.nom.value=="" && document.monform.mail.value=="")
	{
		alert("Veuillez renseigner les champs Nom et E-mail.");
		document.monform.nom.focus();
		document.getElementById('champNom').style.color='#F7AC10';
		document.getElementById('champMail').style.color='#F7AC10';
	}
	else
	{
		if (document.monform.nom.value=="")
		{
			alert("Veuillez renseigner le champ Nom.");
			document.monform.nom.focus();
		}
		else
			if (document.monform.mail.value=="")
			{
				alert("Veuillez renseigner le champ E-mail.");
				document.monform.mail.focus();
			}
			else
				if (verifMail(document.monform.mail.value)==true)
					document.monform.submit();
				else
				{
					alert("Votre adresse E-mail est incorrecte.");
					document.monform.mail.focus();
				}
	}
}

// On ouvre la fonction en lui envoyant la contenu du champ
function verifMail(a)
{
	testm = false ;
	/*Ici, ouverture d'une boucle for à 1 qui permettra de tester du premier jusqu'au dernier caractère de l'adresse e-mail entrée.*/ 
	for (var j=1 ; j<(a.length) ; j++)
	{
		if (a.charAt(j)=='@') 
		{
		// La on commence les conditions de tests. Ici on cherche l'@
			if (j<(a.length-4))
			{
				// Ici on regarde si il y a bien 4 caractère après le @
				for (var k=j ; k<(a.length-2) ; k++) {
					// On ouvre une seconde boucle pour 
					if (a.charAt(k)=='.') testm = true;
					/*on vérifie qu'il y ai bien un point et on met la variable testm à true (implicitement si toutes les conditions sont remplies) puis on ferme les conditions et boucles*/
				}
			}
		}
	}
	return testm;
}

// fonction de vérification de saisie des informations obligatoires pour un produit
function verifChampObligProduit()
{
	if (document.monform.reference.value!="" && document.monform.categorie.value!="0")
		document.monform.submit();
	else
		alert("Veuillez renseigner les champs obligatoires.");
}

// fonction de vérification de saisie des informations obligatoires pour un client
function verifChampObligClient()
{
	if (document.monform.nom.value!="" && document.monform.login.value!="" && document.monform.mdp.value!="" && document.monform.email.value!="")
		document.monform.submit();
	else
		alert("Veuillez renseigner les champs obligatoires.");
}

// fonction de vérification de saisie des informations obligatoires pour une branche
function verifChampObligBranche()
{
	if (document.monform.libelle.value!="")
		document.monform.submit();
	else
		alert("Veuillez renseigner le champ obligatoire.");
}

// fonction de vérification de saisie des informations obligatoires pour une categorie
function verifChampObligCategorie()
{
	if (document.monform.libelle.value!="" && document.monform.idBranche.value!="")
		document.monform.submit();
	else
		alert("Veuillez renseigner les champs obligatoires.");
}

// fonction de vérification de saisie des informations obligatoires pour une sous-categorie
function verifChampObligSousCategorie()
{
	if (document.monform.libelle.value!="" && document.monform.idCategorie.value!="" && document.monform.idCategorie.value!="0")
		document.monform.submit();
	else
		alert("Veuillez renseigner les champs obligatoires.");
}

// fonction de vérification de saisie des informations obligatoires pour un style
function verifChampObligStyle()
{
	if (document.monform.libelle.value!="")
		document.monform.submit();
	else
		alert("Veuillez renseigner le champ obligatoire.");
}

// fonction de confirmation de suppression d'un produit
function confirmSupprProduit(idProduit,idBranche,idCategorie,idSousCategorie)
{
	if (confirm("Êtes-vous sûr de vouloir supprimer ce produit ?"))
		document.location.href="adminOnProduitTraite.php?action=suppr&idProduit="+idProduit+"&branche="+idBranche+"&categorie="+idCategorie+"&sousCategorie="+idSousCategorie;
}

// fonction de confirmation de suppression d'un client
function confirmSupprClient(idClient)
{
	if (confirm("Êtes-vous sûr de vouloir supprimer ce client ?"))
		document.location.href="adminOnClientTraite.php?action=suppr&idClient="+idClient;
}

// fonction de confirmation de suppression d'une branche
function confirmSupprBranche(idBranche)
{
	if (confirm("Êtes-vous sûr de vouloir supprimer cette branche ?"))
		document.location.href="adminOnBrancheTraite.php?action=suppr&idBranche="+idBranche;
}

// fonction de confirmation de suppression d'une categorie
function confirmSupprCategorie(idCategorie,libelle)
{
	if (confirm("Êtes-vous sûr de vouloir supprimer cette catégorie ?"))
		document.location.href="adminOnCategorieTraite.php?action=suppr&idCategorie="+idCategorie;
}

// fonction de confirmation de suppression d'une sous-categorie
function confirmSupprSousCategorie(idSousCategorie,libelle)
{
	if (confirm("Êtes-vous sûr de vouloir supprimer cette sous-catégorie ?"))
		document.location.href="adminOnSousCategorieTraite.php?action=suppr&idSousCategorie="+idSousCategorie;
}

// fonction de confirmation de suppression d'un style
function confirmSupprStyle(idStyle)
{
	if (confirm("Êtes-vous sûr de vouloir supprimer ce style ?"))
		document.location.href="adminOnStyleTraite.php?action=suppr&idStyle="+idStyle;
}

// changement de couleur de la case on mouse over
function selectCase(i,id)
{
	if (i==0)
	{
		document.getElementById(id).style.borderColor='#DDDDDD';
		document.getElementById(id).style.color='#000000';
		document.getElementById(id).style.backgroundColor='#FBFCFD';
	}
	if (i==1)
	{
		document.getElementById(id).style.borderColor='#F7AC10';
		document.getElementById(id).style.color='#F7AC10';
		document.getElementById(id).style.backgroundColor='#FBFCFD';
	}
}

function detailProduit(existe,idProduit)
{
	if (existe==1)
		window.open ('pdf/'+idProduit+'.pdf', 'Elve', config='height=560, width=500, toolbar=no, menubar=yes, scrollbars=yes, resizable=yes, location=no, directories=no, status=no')
	else
		alert ("Fiche produit non disponible.\nMerci de nous contacter pour plus d'informations sur ce produit.");
}

function modifierCommande(id, numLigne)
{
	document.getElementById(id).style.display='none';
	document.getElementById("imgSave"+numLigne).style.display='block';
	document.getElementById("qtePanier"+numLigne).style.display='block';
	document.getElementById("span"+numLigne).style.display='none';
}

function sauverCommande(id, numLigne, idSession, qteSession)
{
	document.getElementById(id).style.display='none';
	document.getElementById("imgModif"+numLigne).style.display='block';
	document.getElementById("qtePanier"+numLigne).style.display='none';
	
	// Obj destination
	//var obj=document.getElementById("span"+numLigne);
	//obj.open;
	//obj.innerHTML=document.getElementById("qtePanier"+numLigne).value;
	//obj.close;
	
	//document.getElementById("span"+numLigne).style.display='block';
	if (document.getElementById("qtePanier"+numLigne).value == null || document.getElementById("qtePanier"+numLigne).value == 0)
	{
		document.getElementById("span"+numLigne).style.display='block';
		document.getElementById("qtePanier"+numLigne).value=qteSession;
		alert("Vous ne pouvez pas spécifier une quantité nulle");
	}
	else	
		document.location.href="commande.php?action=AJUSTER&id="+ idSession + "&qte=" + document.getElementById("qtePanier"+numLigne).value;
}
