﻿
var BgColorInput = "#edf0c2";

function valideIdent(Tchamp,TchampLiv, email)
{
    var cpt=0;
	//check champs vide
	for(i=0; i< Tchamp.length; i++)
	{
	    document.getElementById(Tchamp[i]).style.background="#FFFFFF";
	    document.getElementById(Tchamp[i]).style.border = "1px solid #a5acb2";
	    document.getElementById(Tchamp[i]).style.padding = "2px";

	    if(document.getElementById(Tchamp[i]).value == "")
	    { 
	        cpt++;
	        document.getElementById(Tchamp[i]).style.background= BgColorInput;
	        document.getElementById(Tchamp[i]).style.border = "1px solid #a5acb2";
	        document.getElementById(Tchamp[i]).style.padding = "2px";
	    }
	}
	//alert
	if(cpt != 0){alert("Veuillez remplir les champs obligatoires"); return false;}
	
	//check syntaxe email
	if ((document.getElementById(email).value.indexOf("@")>=0)&&(document.getElementById(email).value.indexOf(".")>=0)) 
	{ 
	    var cpt2=0;
	    var remp = false;
	    
	    //cherche si au moins un champ remplie
	    for(i=0; i< TchampLiv.length; i++)
	    {
	        if(document.getElementById(TchampLiv[i]).value != "")
	        {
	            remp=true;
	        }
	    }
	    
	    //si oui controle champs de livraison
	    if(remp)
	    {
	        //controle
	        for(i=0; i< TchampLiv.length; i++)
	        {
	            document.getElementById(TchampLiv[i]).style.background="#FFFFFF";
	            document.getElementById(TchampLiv[i]).style.border = "1px solid #a5acb2";
	            document.getElementById(TchampLiv[i]).style.padding = "2px";

	            if(document.getElementById(TchampLiv[i]).value == "")
	            { 
	                cpt2++;
	                document.getElementById(TchampLiv[i]).style.background= BgColorInput;
	                document.getElementById(TchampLiv[i]).style.border = "1px solid #a5acb2";
	                document.getElementById(TchampLiv[i]).style.padding = "2px";
	            }
	        }
	        //alert
	        if(cpt2 != 0)
	        {
	            alert("Veuillez remplir les champs obligatoires"); 
	            return false;
	        }
	        else //si ok => valide
	        {
	            return true;	
	        }
	    }
	    else //si non => valide
	    {
	        return true;
	    }
	}
	else { //msg erreur invalide
		alert ("mail invalide !!"); 
		document.getElementById(email).style.background= BgColorInput;
		document.getElementById(email).style.border = "1px solid #a5acb2";
		document.getElementById(email).style.padding = "2px";
		return false;
	}
}



// Formulaire de Contact
function valideContact(Tchamp, email){
	var cpt=0;
	
	//check champs vide
	for(i=0; i< Tchamp.length; i++)
	{
	    document.getElementById(Tchamp[i]).style.background="#FFFFFF";
	    document.getElementById(Tchamp[i]).style.border = "1px solid #a5acb2";

	    if(document.getElementById(Tchamp[i]).value == "")
	    { 
	        cpt++;
	        document.getElementById(Tchamp[i]).style.background= BgColorInput;
	        document.getElementById(Tchamp[i]).style.border = "1px solid #a5acb2";
	    }
	}
	//alert
	if(cpt != 0){alert("Veuillez remplir les champs obligatoires"); return false;}
	
	//check syntaxe email
	if ((document.getElementById(email).value.indexOf("@")>=0)&&(document.getElementById(email).value.indexOf(".")>=0)) { return true;	}
	else {
		alert ("mail invalide !!"); 
		document.getElementById(email).style.background= BgColorInput;
		document.getElementById(email).style.border = "1px solid #a5acb2";
		return false;
	}
}