﻿var BgColorInput = "#ffbbbb";

// Formulaire de Contact
function valideForm(Tchamp, email,idcp){
	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;}
	
	if(email != null){
	    //check syntaxe email
	    document.getElementById(email).style.background="#FFFFFF";
        document.getElementById(email).border = "1px solid #a5acb2";

	    if (!((document.getElementById(email).value.indexOf("@")>=0)&&(document.getElementById(email).value.indexOf(".")>=0)))
	    {
		    alert ("mail invalide !!"); 
		    document.getElementById(email).style.background = BgColorInput;
		    document.getElementById(email).style.border = "1px solid #a5acb2";
		    return false;
	    }
	}

	//cp valide
	try {
	    if (idcp != null) {
	        if (document.getElementById(idcp).options[document.getElementById(idcp).selectedIndex].value == "") {
	            alert("Code postal non valide !");
	            return false;
	        }
	    }
	} catch (e) { alert("Code postal non valide !");  return false; }
	
	if (!GlobalcpValide) {
	    alert("Code postal non valide");
	    return false;
	}

	return true;
}


function valideFormLogon(Tchamp) {
    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; }

    return true;
}

function valideSociete(radioPro, txtBoxSoc1, radioLivAutre, txtBoxSoc2, txtBoxTvaIntra){
    var ret = true;
    var pro = window.document.getElementById(radioPro);
    var autreLiv = window.document.getElementById(radioLivAutre);
    var soc1 = window.document.getElementById(txtBoxSoc1);
    var soc2 = window.document.getElementById(txtBoxSoc2);
    var tvaI = window.document.getElementById(txtBoxTvaIntra);
    
    soc1.style.background= "#FFFFFF";
    soc1.style.border = "1px solid #a5acb2";
    soc2.style.background = "#FFFFFF";
    soc2.style.border = "1px solid #a5acb2";
    tvaI.style.background = "#FFFFFF";
    tvaI.style.border = "1px solid #a5acb2";

    if(pro.checked && soc1.value == ""){
        soc1.style.background = BgColorInput;
        soc1.style.border = "1px solid #a5acb2";
        ret = false;
    }

    if(pro.checked && autreLiv.checked && soc2.value == ""){
        soc2.style.background = BgColorInput;
        soc2.style.border = "1px solid #a5acb2";
        ret = false;
    }

    if(pro.checked && tvaI.value == ""){
        tvaI.style.background = BgColorInput;
        tvaI.style.border = "1px solid #a5acb2";
        ret = false;
    }
    
    if(!ret){alert("Veuillez remplir les champs obligatoires"); return false;}
    
    return ret;
}

// 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;
	}
}

function check_champ_nombre(champ){
	var chiffres = new RegExp("[0-9]"); /* Modifier pour : var chiffres = new RegExp("[0-9\.]"); */
	var verif;
	var points = 0; /* Supprimer cette ligne */
	
	for(x = 0; x < champ.value.length; x++)
	{
	verif = chiffres.test(champ.value.charAt(x));
	if(champ.value.charAt(x) == "."){points++;} /* Supprimer cette ligne */
	if(points > 1){verif = false; points = 1;} /* Supprimer cette ligne */
	if(verif == false){champ.value = champ.value.substr(0,x) + champ.value.substr(x+1,champ.value.length-x+1); x--;}
	}
	return false;
}

function not_null(champ){
	if(champ.value == "0" || champ.value == ""){champ.value = "1";}
}


function CheckConfEmail(email1, email2) {
    if (document.getElementById(email1).value != document.getElementById(email2).value) {
        alert("l'Email de confirmation ne correspond pas à votre Email");
        return false;
    }
    else return true;
}
