// JavaScript Document

//Get value de la zone
		function getZoneValue(name) 
{ 
   //alert("getZoneValue." + name);
   var element = document.getElementById(name);
   if(element.value == element.getAttribute("default"))
                               return "";
                else
                               return element.value;
}
//Get reference objet de la zone
                        function getZone(name) 
                        {
                                   //alert("getZone." + name);
                                   return document.getElementById(name);
                        }
		////////////////////////////////////////////
        //Validation des données saisies
        function validDatas() {
            var bReturn = true;
            if (getZoneValue("Nom") == "") {showInvalidTxtZone(getZone("Nom"));bReturn = false;}
            if (getZoneValue("Prenom") == "") {showInvalidTxtZone(getZone("Prenom"));bReturn = false;}
            if (getZoneValue("Societe") == "") {showInvalidTxtZone(getZone("Societe"));bReturn = false;}
            if (getZoneValue("Telephone") == "") {showInvalidTxtZone(getZone("Telephone"));bReturn = false;}
            if (getZoneValue("Email") == "") {showInvalidTxtZone(getZone("Email"));bReturn = false;}
			//if (getZoneValue("NombresTerminaux") == "") {showInvalidTxtZone(getZone("NombresTerminaux"));bReturn = false;}
			//if (getZoneValue("Message") == "") {showInvalidTxtZone(getZone("Message"));bReturn = false;}
         
            if (bReturn) {
                bReturn = isValidEmail(getZoneValue("Email"));
            }   
			if (bReturn) {
                bReturn = isValidPhone("Telephone");
            }   
			   
//			if (bReturn) {
//                bReturn = isValidNumber(getZoneValue("NombresTerminaux"));
//      }   
            return bReturn;
        }
        //validation email
        function isValidEmail(str) {
            var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
            if (reg.test(str)) {
                return true;
            } else {
                showInvalidTxtZone(getZone("Email"));
                showLabel(true,"format email invalide...");
                return false;
            }
        }
		//validation nombre de terminaux
        function isValidNumber(str) {
            var reg = /\d/;
            if (reg.test(str)) {
                return true;
            } else {
                showInvalidTxtZone(getZone("NombresTerminaux"));
                showLabel(true,"format nombre de terminaux invalide...");
                return false;
            }
        }
		//validation telephone
        function isValidPhone(strControlName) {
            var reg;
			if (strControlName == "Mobile") 
			{
				reg = /^0[6]\d{8}\s*$/;
			}
			else 
			{
				reg = /^0[123456789]\d{8}\s*$/;
			}
			var str = getZoneValue(strControlName);
			if (str=="0122334455"){
				showInvalidTxtZone(getZone(strControlName));
				showLabel(true,"Exemple du numéro de téléphone invalide...");
				return false;
			}
			else
			{
				if (reg.test(str)) {
					return true;
				} else {
					showInvalidTxtZone(getZone(strControlName));
					if (strControlName == "Mobile") 
					{
						showLabel(true,"format téléphone mobile invalide...");
					}
					else 
					{
						showLabel(true,"format téléphone invalide...");
					}
					return false;
				} 
			}
        }
        //Si saisie invalide alors on grise
        function showInvalidTxtZone(oObj) {
            oObj.style.backgroundColor = "#333333";
			oObj.style.color="#FFFFFF";
            showLabel(true,"Des informations sont manquantes...");
        }
        
        //Si saisie en cours alors on dégrise
        function unshowInvalidChZone(oObj) {
            oObj.style.backgroundColor = "#ededed";
            showLabel(false,"...");
			}
			
		//Texte par default dynamique
		function unshowInvalidTxtZone(element)
{
                if(element.value == element.getAttribute("default"))
                {
                               element.value ="";
        }
        //Si saisie en cours alors on dégrise
            element.style.backgroundColor = "White";
			element.style.color="#000000";
            showLabel(false,"...");
                
		}
		function toShowInvalidTxtZone(element)
		{
                if(element.value == "")
                {
                               element.value =element.getAttribute("default");
                }
}			
        //Appel fonction envoi de mail
        function sendMail() {
            var xhr_object = null; 
            if(window.XMLHttpRequest) // Firefox 
                xhr_object = new XMLHttpRequest(); 
            else if(window.ActiveXObject) // Internet Explorer 
                xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); 
            else {
                alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
                return; 
            } 
            xhr_object.open("POST", "./mail/sendMailForm.php", true);
                xhr_object.onreadystatechange = function() { 
                if(xhr_object.readyState == 4) {
	                eval(xhr_object.responseText);
	            }
            }
			
            xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

            // modif JSA 29/04/2010
            var page= document.URL;
			
            var data = "Nom=" + getZoneValue("Nom");
            data += "&Prenom=" + getZoneValue("Prenom");
            data += "&Societe=" + getZoneValue("Societe");
            data += "&Telephone=" + getZoneValue("Telephone");
            data += "&Email=" + getZoneValue("Email");
            //data += "&NombresTerminaux=" + getZoneValue("NombresTerminaux");
            data += "&Message=" + getZoneValue("Message");
            data += "&sid=" + getZoneValue("sid");
            // modif JSA 29/04/2010
            data += "&page=" + page;
			
            xhr_object.send(data);
        }

        //Affichage du label ou non si besoin d'afficher des informations
        function showLabel(bVisible,strCaption) {
            if (bVisible) {
                getZone("lblSendStatus").style.display = "";
            } else {
                getZone("lblSendStatus").style.display = "none";
            }
            getZone("lblSendStatus").innerHTML = strCaption;
        }
        ////////////////////////////////////////////
//-->
