﻿    function MotifChanged(motif,lblmnt,Duree)
    {
    
    if (motif != null)
    {
    
        var Motif = document.getElementById(motif).selectedIndex;
        var Er = document.getElementById(lblmnt);
        
        if (Motif == 1 || Motif == 5)  //habitat ou raisons perso 
        {
	        Er.value ="Montant entre 5000 et 200 000 Dh";
		    Er.style.color = "#8CA46E";
        }  
    
	    if (Motif == 3 || Motif == 4)
	    {
	        Er.innerHTML ="Montant entre 2000 et 150 000 Dh";
	        Er.style.color = "#8CA46E";
	    }
	    
	    if (Motif == 6)
	    {
	        Er.innerHTML ="Montant entre 10 000 et 100 000 Dh";
	        Er.style.color = "#8CA46E";
	    }
	    
	    if (Motif == 2 || Motif == 7 || Motif == 0)  
	    {
	        Er.innerHTML ="";
	    }
	    
	    ///////////////////////////////////////////////////////////////////////////

	        RemplirDuree(Duree,motif);
	   }
    }
    function RemplirDuree(Duree,motif)
    {
        var objSelect = document.getElementById(Duree);
        
        var Motif = document.getElementById(motif).selectedIndex;
        
        for (var i = (objSelect.options.length - 1); i >= 0; i--){
        objSelect.options[i]=null;
        }

	 objSelect.options[0]=new Option('Sélectionnez', '0');
	 if (Motif == 0)
	    {
	            var i;
                for(i=objSelect.options.length-1;i>=1;i--)
                {
                objSelect.remove(i);
                }
	    }
     if (Motif == 1 || Motif == 5 || Motif == 7)  //habitat ou raisons perso 
        {
	    objSelect.options[1]=new Option('6', '6');
        objSelect.options[2]=new Option('12', '12');
        objSelect.options[3]=new Option('18', '18');
        objSelect.options[4]=new Option('24', '24');
        objSelect.options[5]=new Option('36', '36');
        objSelect.options[6]=new Option('48', '48');
        objSelect.options[7]=new Option('60', '60');
        objSelect.options[8]=new Option('72', '72');
        objSelect.options[9]=new Option('84', '84');
        }  
       
        if (Motif == 3 || Motif == 4)  //Loisir ou Electro wfv
        {

        objSelect.options[1]=new Option('6', '6');
        objSelect.options[2]=new Option('12', '12');
        objSelect.options[3]=new Option('18', '18');
        objSelect.options[4]=new Option('24', '24');
        objSelect.options[5]=new Option('36', '36');
        objSelect.options[6]=new Option('48', '48');

        }
	    if (Motif==2) //Auto
	    {

        objSelect.options[1]=new Option('6', '6');
        objSelect.options[2]=new Option('12', '12');
        objSelect.options[3]=new Option('18', '18');
        objSelect.options[4]=new Option('24', '24');
        objSelect.options[5]=new Option('36', '36');
        objSelect.options[6]=new Option('48', '48');
        objSelect.options[7]=new Option('60', '60');
        objSelect.options[8]=new Option('72', '72');
	    }
	    if (Motif==6) //Prêt internautes
	    {
	    objSelect.options[1]=new Option('11', '11');
        objSelect.options[2]=new Option('24', '24');
        objSelect.options[3]=new Option('36', '36');
        objSelect.options[4]=new Option('48', '48');
        objSelect.options[5]=new Option('57', '57');
        objSelect.options[6]=new Option('60', '60');
        objSelect.options[7]=new Option('72', '72');
        objSelect.options[8]=new Option('84', '84');
	    }
	}
    
    function ValidateMontant(Motif,Montant,lblMnt)
    {
       var bok = true;
    
       var Motif = Motif.value;
       var Montant = Montant.value;
       
       var lblValidateMontant = lblMnt;

        numChars = "0123456789";
        var isNum = true;
        var index = 0;
        var Data = Montant;
        if(Data!="")
        {
        while ((index < Data.length) && (isNum))
             {
             isNum = (numChars.indexOf(Data.charAt(index)) != -1);
             index ++;
             }
        if (!isNum)
             {          
	            lblValidateMontant.innerHTML ="Erreur ! Saisissez un nombre entier";
	            lblValidateMontant.style.color = "Red";
	            bok = false;
             }
             else
             {
		        lblValidateMontant.innerHTML ="";
		        lblValidateMontant.style.color = "White";
		        bok = true;
             }


       if (isNum)
       {
       if (Motif == 1 || Motif == 5)
	    {
	        if (Montant < 5000 || Montant > 200000)
	        {
		        lblValidateMontant.innerHTML ="Montant entre 5000 et 200 000 Dh";
		        lblValidateMontant.style.color = "Red";
		        bok = false;
		    }
		    else
		    {
		        lblValidateMontant.innerHTML ="";
		        lblValidateMontant.style.color = "White";
		        bok = true;
		    }
	    }
	    
	    if (Motif == 3 || Motif == 4)  
	    {
	        if (Montant < 2000 || Montant > 150000)
	        {
	            lblValidateMontant.innerHTML ="Montant entre 2000 et 150 000 Dh";
	            lblValidateMontant.style.color = "Red";
	            bok = false;
		    }
		    else
		    {
		        lblValidateMontant.innerHTML ="";
		        lblValidateMontant.style.color = "White";
		        bok = true;
		    }
	    }
	    if (Motif == 6)  
	    {
	        if (Montant < 10000 || Montant > 100000)
	        {
	            lblValidateMontant.innerHTML ="Montant entre 10 000 et 100 000 Dh";
	            lblValidateMontant.style.color = "Red";
	            bok = false;
		    }
		    else
		    {
		        lblValidateMontant.innerHTML ="";
		        lblValidateMontant.style.color = "White";
		        bok = true;
		    }
	    }
	    }
	    }
	    else
	    {
	        return false;
	    }       
	     return bok;
    }
    function Validation_Sigle(Sigle,lblSig)
    {
        var bok = true;
        if(Sigle.selectedIndex==0)
        {
            lblSig.innerHTML ="Veuillez choisir votre Sigle";
            lblSig.style.color = "Red";
            bok = false;
        }
        else
        {
            lblSig.innerHTML ="";
            lblSig.style.color = "White";
            bok = true;
        }
        return bok;
    }
    
    //-----------------Validation des champs [Obligatoire]--------------------------
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    function Validation_Obligation_Champs(Nom,lblnom,Prenom,lblprenom,Mail,lblmail,GSM,lblgsm,Tel,lbltel,lbltelGL,date1,horaire1,date2,horaire2,lblpref)
    {
        var bok = true;
        
        //-----------------NOM--------------
        if(Nom.value=="" && lblnom.innerHTML=="")
        {
            lblnom.innerHTML ="Veuillez saisir votre Nom";
            lblnom.style.color = "Red";
            bok = false;
        }
        else if(Nom.value=="" && lblnom.innerHTML!="")
        {
            lblnom.style.color = "Red";
            bok = false;
        }
        else if(Nom.value!="" && lblnom.innerHTML!="")
        {
            lblnom.style.color = "Red";
            bok = false;
        }
        else if(Nom.value!="" && lblnom.innerHTML=="")
        {
            lblnom.innerHTML ="";
            lblnom.style.color = "White";
        }
        //--------------PRENOM--------------
        if(Prenom.value=="" && lblprenom.innerHTML=="")
        {
            lblprenom.innerHTML ="Veuillez saisir votre Prénom";
            lblprenom.style.color = "Red";
            bok = false;
        }
        else if(Prenom.value=="" && lblprenom.innerHTML!="")
        {
            lblprenom.style.color = "Red";
            bok = false;
        }
        else if(Prenom.value!="" && lblprenom.innerHTML!="")
        {
            lblprenom.style.color = "Red";
            bok = false;
        }
        else if(Prenom.value!="" && lblprenom.innerHTML=="")
        {
            lblprenom.innerHTML ="";
            lblprenom.style.color = "White";
        }
        
        //--------------EMAIL---------------
        if(Mail.value=="" && lblmail.innerHTML=="")
        {
            lblmail.innerHTML ="Veuillez saisir votre Adresse Mail";
            lblmail.style.color = "Red";
            bok = false;
        }
        else if(Mail.value=="" && lblmail.innerHTML!="")
        {
            lblmail.style.color = "Red";
            bok = false;
        }
        else if(Mail.value!="" && lblmail.innerHTML!="")
        {
            lblmail.style.color = "Red";
            bok = false;
        }
        else if(Mail.value!="" && lblmail.innerHTML=="")
        {
            lblmail.innerHTML ="";
            lblmail.style.color = "White";
        }
        //--------------GSM-----------------
//        if(GSM.value=="" && lblgsm.innerHTML=="")
//        {
//            lblgsm.innerHTML ="Veuillez saisir votre Numéro de Téléphone GSM";
//            lblgsm.style.color = "Red";
//            bok = false;
//        }
//        else if(GSM.value=="" && lblgsm.innerHTML!="")
//        {
//            lblgsm.style.color = "Red";
//            bok = false;
//        }
//        else if(GSM.value!="" && lblgsm.innerHTML!="")
//        {
//            lblgsm.style.color = "Red";
//            bok = false;
//        }
//        else if(GSM.value!="" && lblgsm.innerHTML=="")
//        {
//            lblgsm.innerHTML ="";
//            lblgsm.style.color = "White";
//        }
        //--------------Tél. résidentiel-----
//        if(Tel.value=="" && lbltel.innerHTML=="")
//        {
//            lbltel.innerHTML ="Veuillez saisir votre Numéro de Téléphone résidentiel";
//            lbltel.style.color = "Red";
//            bok = false;
//        }
//        else if(Tel.value=="" && lbltel.innerHTML!="")
//        {
//            lbltel.style.color = "Red";
//            bok = false;
//        }
//        else if(Tel.value!="" && lbltel.innerHTML!="")
//        {
//            lbltel.style.color = "Red";
//            bok = false;
//        }
//        else if(Tel.value!="" && lbltel.innerHTML=="")
//        {
//            lbltel.innerHTML ="";
//            lbltel.style.color = "White";
//        }
        //--------------Téléphone--------------------
        if (Tel.value == "" && GSM.value == "") {
            lbltelGL.innerHTML = "Veuillez saisir soit votre Tél. Fix ou Tél. Mobile";
            lbltelGL.style.color = "Red";
            bok = false;
        }
        else {
            lbltelGL.innerHTML = "";
            lbltelGL.style.color = "White";
        }
        //--------------Préference--------------------
        if (((date1.value == "" && horaire1.selectedIndex == 0) || (date1.value == "" && horaire1.selectedIndex != 0)
                || (date1.value != "" && horaire1.selectedIndex == 0)) &&
            ((date2.value == "" && horaire2.selectedIndex == 0) || (date2.value == "" && horaire2.selectedIndex != 0)
                || (date2.value != "" && horaire2.selectedIndex == 0))) {
            lblpref.innerHTML = "Veuillez saisir une des préferences";
            lblpref.style.color = "Red";
            bok = false;
        }
        else {
            lblpref.innerHTML = "";
            lblpref.style.color = "White";
        }
        return bok;
    }    
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    //-----------------Validation Du Nom et Prénom----------------------------------
    function ValidateNom(Nom,lblnom)
    {
     var bok = true;
     var alphaPat = /^[A-Za-z ]*$/;
     var nomid = Nom.value;
     if(nomid!="")
     {
         var matchArray = nomid.match(alphaPat);
         if (matchArray == null && alphaPat != "" || nomid.length < 3)
         {
               lblnom.innerHTML = "Nom invalide ";
               bok = false;
         }
	    else 
	     {
		       lblnom.innerHTML ="";
	     }
     }
     else
     {
            lblnom.innerHTML ="";
            bok=false;
     }
	 return bok;
     }
 
    function ValidatePrenom(Prenom,lblprenom)
    {
     var bok = true;
     var alphaPat = /^[A-Za-z ]*$/;
     var prenomid = Prenom.value;
     if(prenomid!="")
     {
         var matchArray = prenomid.match(alphaPat);
         if (matchArray == null && alphaPat != "" || prenomid.length < 3)
         {
               lblprenom.innerHTML = "Prénom invalide ";
               bok = false;
         }
	    else 
	    {
		    lblprenom.innerHTML ="";
	    }
	  }
	  else
	  {
	        lblprenom.innerHTML ="";
	        bok=false;
	  }
	 return bok;
    }
    //------------------------------------------------------------------------------
    //------------------------Validation de la CIN----------------------------------
    //------------------------------------------------------------------------------
    
    function ValidateCIN(CIN,lblcin)
    {
         var bok = true;
         var cinPat = /^[a-zA-Z]{1,2}[0-9]{4,6}$/;
         var cinid = CIN.value;
         if(cinid!="")
         {
             var matchArray = cinid.match(cinPat);
             if (matchArray == null && cinid != "")
             {
                   lblcin.innerHTML = "CIN invalide ";
                   bok = false;
             }
             else 
             {
	             lblcin.innerHTML ="";
             }
         }
         else
         {
            lblcin.innerHTML ="";
            bok = false;
         }
         return bok;
    }
    
    
    //------------------------------------------------------------------------------
    //----------------------------Validation de l'Adresse Mail----------------------
    //------------------------------------------------------------------------------
    
    function ValidateEmail(Mail,lblmail)
    {
         var bok = true;
         var emailPat = /^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
         var emailid=Mail.value;
         if(emailid!="")
         {
             var matchArray = emailid.match(emailPat);
             if (matchArray == null && emailid != "")
             {
                   lblmail.innerHTML = "Adresse Mail invalide ";
                   bok = false;
             }
	         else 
	         {
	             lblmail.innerHTML ="";
	         }
	     }
	     else
	     {
	        lblmail.innerHTML ="";
	        bok = false;
	     }
    	    
	     return bok;
     }
    
     //------------------------------------------------------------------------------
     //------------------------Validation du Téléphone FIX---------------------------
     //------------------------------------------------------------------------------
     function ValidatePhoneFIX(tel, lbltel,lblt) {
         var bok = true;
         if (tel.value != "") {
             var Tel = new String(tel.value);

             numChars = "0123456789";
             var isNum = true;
             var index = 0;
             var Data = tel.value;
             while ((index < Data.length) && (isNum)) {
                 isNum = (numChars.indexOf(Data.charAt(index)) != -1);
                 index++;
             }

             if (!isNum) {
                 lbltel.innerHTML = "Erreur ! Saisissez un nombre entier";
                 lbltel.style.color = "Red";
                 lblt.innerHTML = "";
                 bok = false;
             }
             else {
                 if (Tel.length != 0 && Tel.length != 10) {
                     lbltel.innerHTML = "Num. Téléphone fix Invalide ";
                     lbltel.style.color = "Red";
                     lblt.innerHTML = "";
                     bok = false;
                 }
                 else {
                     lbltel.innerHTML = "";
                     lblt.innerHTML = "";
                 }
             }
         }
         else {
             lbltel.innerHTML = "";
             lblt.innerHTML = "";
             bok = false;
         }
         return bok;
     }
     //------------------------------------------------------------------------------
     //------------------------Validation du Téléphone Mobile------------------------
     //------------------------------------------------------------------------------
     function ValidatePhoneMobile(tel, lbltel, lblt) {
         var bok = true;
         if (tel.value != "") {
             var Tel = new String(tel.value);

             numChars = "0123456789";
             var isNum = true;
             var index = 0;
             var Data = tel.value;
             while ((index < Data.length) && (isNum)) {
                 isNum = (numChars.indexOf(Data.charAt(index)) != -1);
                 index++;
             }

             if (!isNum) {
                 lbltel.innerHTML = "Erreur ! Saisissez un nombre entier";
                 lbltel.style.color = "Red";
                 lblt.innerHTML = "";
                 bok = false;
             }
             else {
                 if (Tel.length != 0 && Tel.length != 10) {
                     lbltel.innerHTML = "Num. Téléphone mobile Invalide ";
                     lbltel.style.color = "Red";
                     lblt.innerHTML = "";
                     bok = false;
                 }
                 else {
                     lbltel.innerHTML = "";
                     lblt.innerHTML = "";
                 }
             }
         }
         else {
             lbltel.innerHTML = "";
             lblt.innerHTML = "";
             bok = false;
         }
         return bok;
     }
     
     //------------------------------------------------------------------------------
     //------------------------Validation du Téléphone ------------------------------
     //------------------------------------------------------------------------------
     
     function ValidatePhone(tel, gsm, lbltel) {
         var bok = true;
         if (tel.value == "" && gsm.value == "") {
             lbltel.innerHTML = "";
             bok = false;
         }
         else {
             if (tel.value != "" && gsm.value == "") {
                 var Tel = new String(tel.value);

                 numChars = "0123456789";
                 var isNum = true;
                 var index = 0;
                 var Data = tel.value;
                 while ((index < Data.length) && (isNum)) {
                     isNum = (numChars.indexOf(Data.charAt(index)) != -1);
                     index++;
                 }

                 if (!isNum) {
                     lbltel.innerHTML = "Erreur ! Saisissez un nombre entier";
                     lbltel.style.color = "Red";
                     lblt.innerHTML = "";
                     bok = false;
                 }
                 else {
                     if (Tel.length != 0 && Tel.length != 10) {
                         lbltel.innerHTML = "Num. Téléphone fix Invalide ";
                         lbltel.style.color = "Red";
                         lblt.innerHTML = "";
                         bok = false;
                     }
                     else {
                         lbltel.innerHTML = "";
                         lblt.innerHTML = "";
                     }
                 }
             }
             else if (gsm.value != "" && tel.value == "") {
                 var Tel = new String(gsm.value);

                 numChars = "0123456789";
                 var isNum = true;
                 var index = 0;
                 var Data = gsm.value;
                 while ((index < Data.length) && (isNum)) {
                     isNum = (numChars.indexOf(Data.charAt(index)) != -1);
                     index++;
                 }

                 if (!isNum) {
                     lbltel.innerHTML = "Erreur ! Saisissez un nombre entier";
                     lbltel.style.color = "Red";
                     bok = false;
                 }
                 else {
                     if (Tel.length != 0 && Tel.length != 10) {
                         lbltel.innerHTML = "Num. Téléphone mobile Invalide ";
                         lbltel.style.color = "Red";
                         bok = false;
                     }
                     else {
                         lbltel.innerHTML = "";
                     }
                 }
             }
             else if (gsm.value != "" && tel.value != "") {
                 numChars = "0123456789";
                 var isNum = true;
                 var isNum1 = true;
                 var index = 0;
                 var index1 = 0;
                 var Data = tel.value;
                 var Data1 = gsm.value;
                 while ((index < Data.length) && (isNum)) {
                     isNum = (numChars.indexOf(Data.charAt(index)) != -1);
                     index++;
                 }
                 while ((index1 < Data1.length) && (isNum1)) {
                     isNum1 = (numChars.indexOf(Data1.charAt(index1)) != -1);
                     index1++;
                 }

                 if ((!isNum || !isNum1) || (!isNum && !isNum1)) {
                     lbltel.innerHTML = "Erreur ! Saisissez un nombre entier";
                     lbltel.style.color = "Red";
                     bok = false;
                 }
                 else {
                     if (tel.value.length != 0 && tel.value.length != 10) {
                         lbltel.innerHTML = "Num. Téléphone fix Invalide ";
                         lbltel.style.color = "Red";
                         bok = false;
                     }
                     else {
                         lbltel.innerHTML = "";
                     }
                     if (gsm.value.length != 0 && gsm.value.length != 10) {
                         lbltel.innerHTML = "Num. Téléphone mobile Invalide ";
                         lbltel.style.color = "Red";
                         bok = false;
                     }
                     else {
                         lbltel.innerHTML = "";
                     }
                 }
             }
         }
         return bok;
     }
    
    
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    //------------------------------Récuperation de la ville à partir --------------
    //----------------------------------------du code postal------------------------
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    function onTxtBlur(txtcp,lblcp,ddlcp,ddlville,lblville)
    {
    var t = docGetElmt(txtcp);
    var lbl = docGetElmt(lblcp);
    var reg = /^\d{5}$/;
    if(t.value.search(reg) == -1 && t.value.length != 0)
    {
        lbl.innerHTML = "Le code postal saisi ne correspond à aucune localité, merci de vérifier votre saisie";
        ddlville.selectedIndex = 0;
    }
    else if(t.value.length != 0)
    {
        var ddlHV = docGetElmt(ddlcp);
        var ddlV = docGetElmt(ddlville);
        var j = 0;
        for(var i=0; i<ddlHV.options.length; i++)
        {
            if(ddlHV.options[i].value.toString() == t.value.toString())
            {
                ddlV.value = ddlHV.options[i].text;
                j = 1;
                break;
            }
        }
        if(j == 0)
        {
        lbl.innerHTML = "Le code postal saisi ne correspond à aucune localité, merci de vérifier votre saisie";
        ddlville.selectedIndex = 0;
        //onQuartierChange(false);
        }
        else
        {
        lbl.innerHTML = "";
        //onQuartierChange(true);
        }
        }
        else
        {
        lbl.innerHTML = "";
        }
        var m = ValidateVille(document.getElementById(ddlville),document.getElementById(lblville));
    }
    
    function onTxtChange(txtcp,lblcp,ddlcp,ddlville,lblville)
    {
    var t = document.getElementById(txtcp);
    var ddlHV = document.getElementById(ddlcp);
    var ddlV = document.getElementById(ddlville);
    var lbl = document.getElementById(lblcp);
    var reg = /^\d$/;
    if(t.value.charAt(t.value.length - 1).search(reg) != -1)
    {
    if(t.value.length > 5)
    {
        t.value = t.value.substring(0,5);
    }
    else if(t.value.length == 5)
    {
        var j = 0;
        for(var i=0; i<ddlHV.options.length; i++)
        {
            if(ddlHV.options[i].value.toString() == t.value.toString())
            {
                ddlV.value = ddlHV.options[i].text;
                j = 1;
                break;
            }
        }
        if(j == 0)
        {
        lbl.innerHTML = "Le code postal saisi ne correspond à aucune localité, merci de vérifier votre saisie";
        ddlville.selectedIndex = 0;
        }
        else
        {
        lbl.innerHTML = "";
        }
    }
    else
    {
    lbl.innerHTML = "";
    }
    }
    else
    {
    t.value = t.value.substring(0,t.value.length-1);
    }
    var m = ValidateVille(document.getElementById(ddlville),document.getElementById(lblville));
    }
    //------------------------------------------------------------------------------
    //-----------------------------FIN RECHERCHE VILLE------------------------------
    //-----------------------------PAR CODE POSTAL---------------------------------- 
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    //-----------------------------VALIDATION DATE ---------------------------------
    //---------------------------------NAISSANCE------------------------------------
    //------------------------------------------------------------------------------
    function DateValidate(jd,md,ad,lbld) 
    {   
    try
    {
    var bok = true;
        var JourNaissDEBUT = jd.value;
        var MoisNaissDEBUT = md.value;
        var AnneeNaissDEBUT = ad.value;

        if(JourNaissDEBUT == 0 || MoisNaissDEBUT == 0 || AnneeNaissDEBUT == 0)
        {
            lbld.innerHTML = "Veuillez choisir votre Date de Naissance";
            bok = false;
        }
        
        if(!bok)
         {
            return false;
         }
         else
         {
            lbld.innerHTML = "";
         }
  
        var DateNaissDEBUT = JourNaissDEBUT + "/" + MoisNaissDEBUT + "/" + AnneeNaissDEBUT;
        //check leap year
        var returndaysDEBUT = isleap(AnneeNaissDEBUT);

         if(JourNaissDEBUT > returndaysDEBUT && MoisNaissDEBUT=="2")
         {
            bok = false;
         }
         if(!bok)
         {
            lbld.innerHTML = "Date invalide";
            return false;
         }
         else
         {
            lbld.innerHTML = "";
            return true;
         }
}
catch(e)
{
alert("ERROR : " + e);
}
}
    //fonction verification si l'année est bisextile
    function isleap(yr)
    {
     if ((parseInt(yr)%4) == 0)
     {
      if (parseInt(yr)%100 == 0)
      {
        if (parseInt(yr)%400 != 0)
        {
          return 28;
        }
        if (parseInt(yr)%400 == 0)
        {
          return 29;
        }
      }
      if (parseInt(yr)%100 != 0)
      {
        return 29;
      }
     }
     if ((parseInt(yr)%4) != 0)
     {
       return 28;
     }
    }

//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
//----------------------------------FIN Validation Date de naissance-------------------------------
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
    //-----------------Validation des champs [Obligatoire]ETAPE 2        --------------------------
    //---------------------------------------------------------------------------------------------
    //---------------------------------------------------------------------------------------------
    //---------------------------------------------------------------------------------------------
    function Validation_Obligation_Champs_Etape_2(day,month,year,lbldn,situation,lblsituation,habitation,lblhabitation,adresse,lbladresse,ville,lblville,profession,lblprofession,embauche,lblembauche)
    {
        var bok = true;
        //-----------------Date de Naissance--------------
        if(DateValidate(day,month,year,lbldn) == false)
        {
            bok = false;
        }
        if(ValidateSituation(situation,lblsituation) == false)
        {
            bok = false;
        }
        if(ValidateHabitation(habitation,lblhabitation) == false)
        {
            bok = false;
        }
        if(ValidateAdresse(adresse,lbladresse) == false)
        {
            bok = false;
        }
        if(ValidateVille(ville,lblville) == false)
        {
            bok = false;
        }
        if(ValidateProfession(profession,lblprofession) == false)
        {
            bok = false;
        }
        if(ValidateEmbauche(embauche,lblembauche) == false)
        {
            bok = false;
        }
        return bok;
    }    
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    //-------------------------   VALIDATION ADRESSE    ----------------------------
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    function ValidateAdresse(adresse,lbladresse)
    {
        var bok = true;
         if (adresse.value == "")
         {
               lbladresse.innerHTML = "Veuillez saisir votre Adresse ";
               bok = false;
         }
	    else 
	     {
		       lbladresse.innerHTML ="";
	     }
	    return bok;
     }
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    //-------------------------   VALIDATION SITUATION  ----------------------------
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    function ValidateSituation(situation,lblsituation)
    {
        var bok = true;
         if (situation.selectedIndex == 0)
         {
               lblsituation.innerHTML = "Veuillez choisir votre Situation Matrimonial";
               bok = false;
         }
	    else 
	     {
		       lblsituation.innerHTML ="";
	     }
	    return bok;
     }
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    //-------------------------   VALIDATION HABITATION  ----------------------------
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    function ValidateHabitation(habitation,lblhabitation)
    {
        var bok = true;
         if (habitation.selectedIndex == 0)
         {
               lblhabitation.innerHTML = "Veuillez choisir votre Mode d'habitation";
               bok = false;
         }
	    else 
	     {
		       lblhabitation.innerHTML ="";
	     }
	    return bok;
     }
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    //-------------------------   VALIDATION VILLE  --------------------------------
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    function ValidateVille(ville,lblville)
    {
        var bok = true;
         if (ville.selectedIndex == 0)
         {
               lblville.innerHTML = "Veuillez choisir votre Ville";
               bok = false;
         }
	    else 
	     {
		       lblville.innerHTML ="";
	     }
	    return bok;
     }
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    //-------------------------   VALIDATION PROFESSION  ---------------------------
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    function ValidateProfession(profession,lblprofession)
    {
        var bok = true;
         if (profession.selectedIndex == 0)
         {
               lblprofession.innerHTML = "Veuillez choisir votre Profession";
               bok = false;
         }
	    else 
	     {
		       lblprofession.innerHTML ="";
	     }
	    return bok;
     }
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    //-------------------------  VALIDATION A.EMBAUCHE  ----------------------------
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    function ValidateEmbauche(embauche,lblembauche)
    {
        var bok = true;
         if (embauche.selectedIndex == 0)
         {
               lblembauche.innerHTML = "Veuillez choisir votre Année d'embauche";
               bok = false;
         }
	    else 
	     {
		       lblembauche.innerHTML ="";
	     }
	    return bok;
     }
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    //-------------------------   VALIDATION CONTRACTé CREDIT  ---------------------
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    function ValidateContracte(contracte,lblcontracte)
    {
        var bok = true;
         if (contracte.selectedIndex == 0)
         {
               lblcontracte.innerHTML = "Veuillez choisir si vous avec déjà contracté un crédit";
               bok = false;
         }
	    else 
	     {
		       lblcontracte.innerHTML ="";
	     }
	    return bok;
     }
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    //-------------------------   VALIDATION SALAIRE  ------------------------------
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    function ValidateSalaire(salaire,lblsalaire)
    {
        var bok = true;
         if (salaire.value == "")
         {
               lblsalaire.innerHTML = "Veuillez saisir votre Salaire NET ";
               bok = false;
         }
	    else 
	     {
		       lblsalaire.innerHTML ="";
	     }
	    numChars = "0123456789";
        var isNum = true;
        var index = 0;
        var Data = salaire.value;
        if(Data!="")
        {
        while ((index < Data.length) && (isNum))
             {
             isNum = (numChars.indexOf(Data.charAt(index)) != -1);
             index ++;
             }
        if (!isNum)
             {          
	            lblsalaire.innerHTML ="Erreur ! Saisissez un nombre entier";
	            bok = false;
             }
             else
             {
		        lblsalaire.innerHTML ="";
		        bok = true;
             }
        }
	    return bok;
     }
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    //-------------------------   VALIDATION CHARGES  ------------------------------
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    function ValidateCharges(charge,lblcharge)
    {
        var bok = true;
         if (charge.value == "")
         {
               lblcharge.innerHTML = "Veuillez saisir vos charges ";
               bok = false;
         }
	    else 
	     {
		       lblcharge.innerHTML ="";
	     }
	     numChars = "0123456789";
        var isNum = true;
        var index = 0;
        var Data = charge.value;
        if(Data!="")
        {
        while ((index < Data.length) && (isNum))
             {
             isNum = (numChars.indexOf(Data.charAt(index)) != -1);
             index ++;
             }
        if (!isNum)
             {          
	            lblcharge.innerHTML ="Erreur ! Saisissez un nombre entier";
	            bok = false;
             }
             else
             {
		        lblcharge.innerHTML ="";
		        bok = true;
             }
        }
	    return bok;
     }
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    //-------------------------   VALIDATION BANQUE  -------------------------------
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    function ValidateBanque(banque,lblbanque)
    {
        var bok = true;
         if (banque.selectedIndex == 0)
         {
               lblbanque.innerHTML = "Veuillez choisir votre Banque";
               bok = false;
         }
	    else 
	     {
		       lblbanque.innerHTML ="";
	     }
	    return bok;
     }
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    //-------------------------   VALIDATION ANCIENNETé  ---------------------------
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    function ValidateAncien(ancien,lblancien)
    {
        var bok = true;
         if (ancien.selectedIndex == 0)
         {
               lblancien.innerHTML = "Veuillez choisir l'Ancienneté de votre compte banquaire";
               bok = false;
         }
	    else 
	     {
		       lblancien.innerHTML ="";
	     }
	    return bok;
     }
     //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    //-------------------------   VALIDATION ACCORD  -------------------------------
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    function ValidateAccord(accord,lblaccord)
    {
         var bok = true;
         if (accord.selectedIndex == 0)
         {
               lblaccord.innerHTML = "Veuillez choisir l'accord du crédit";
               bok = false;
         }
	    else 
	     {
		       lblaccord.innerHTML ="";
	     }
	    return bok;
     }
    //---------------------------------------------------------------------------------------------
    //---------------------------------------------------------------------------------------------
    //---------------------------------------------------------------------------------------------
    //-----------------   Validation des champs [Obligatoire]ETAPE 3   ----------------------------
    //---------------------------------------------------------------------------------------------
    //---------------------------------------------------------------------------------------------
    //---------------------------------------------------------------------------------------------
    function Validation_Obligation_Champs_Etape_3(contracte,lblcontracte,salaire,lblsalaire,charge,lblcharge,banque,lblbanque,ancien,lblancien,accord,lblaccord)
    {
        var bok = true;
        //-----------------Date de Naissance--------------
        if(ValidateContracte(contracte,lblcontracte) == false)
        {
            bok = false;
        }
        if(ValidateSalaire(salaire,lblsalaire) == false)
        {
            bok = false;
        }
        if(ValidateCharges(charge,lblcharge) == false)
        {
            bok = false;
        }
        if(ValidateBanque(banque,lblbanque) == false)
        {
            bok = false;
        }
        if(ValidateAncien(ancien,lblancien) == false)
        {
            bok = false;
        }
        if(ValidateAccord(accord,lblaccord) == false)
        {
            bok = false;
        }
        
        return bok;
    }    
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    
    function docGetElmt(a)
    {
        return document.getElementById(a);
    }
    function ValidationForm(c)
    {
    //************************************************************************************************
    //************************************************************************************************
    //********************************************   ETAPE 1   ***************************************
    //************************************************************************************************
    //************************************************************************************************
    try{
    // -------------------- COMMENTAIRE ------------------------- //
    /*
    t[0] = Motif                t[1] = Message Motif
    t[2] = Montant              t[3] = Message Montant
    t[4] = Duree                t[5] = Message Duree
    t[6] = Sigle                t[7] = Message Sigle
    t[8] = Nom                  t[9] = Message Nom
    t[10]= Prenom              t[11]= Message Prenom
    t[12]= CIN                 t[13]= Message CIN
    t[14]= Email               t[15]= Message Email
    t[16]= GSM                 t[17]= Message GSM
    t[18]= Tel                 t[19]= Message Tel. résidenciel
    */
    // --------------------- FIN -----------------------//
    var tab = new Array(100);
    var t = c.split(",");
    tab[0] = ValidateNom(docGetElmt(t[0]),docGetElmt(t[1]));
    tab[1] = ValidatePrenom(docGetElmt(t[2]),docGetElmt(t[3]));
    tab[2] = ValidateEmail(docGetElmt(t[4]),docGetElmt(t[5]));
    tab[3] = ValidatePhoneMobile(docGetElmt(t[6]), docGetElmt(t[7]), docGetElmt(t[10])); //Validation GSM
    tab[4] = ValidatePhoneFIX(docGetElmt(t[8]), docGetElmt(t[9]), docGetElmt(t[10])); //Validation Tel Résidentiel
    tab[5] = Validation_Obligation_Champs(docGetElmt(t[0]), docGetElmt(t[1]), docGetElmt(t[2]),
                                          docGetElmt(t[3]), docGetElmt(t[4]), docGetElmt(t[5]),
                                          docGetElmt(t[6]), docGetElmt(t[7]), docGetElmt(t[8]),
                                          docGetElmt(t[9]), docGetElmt(t[10]),
                                          docGetElmt(t[11]), docGetElmt(t[12]),
                                          docGetElmt(t[13]), docGetElmt(t[14]),
                                          docGetElmt(t[15])); //Validation des champs vide [Etape 1]

    for(var i=0;i<=tab.length-1;i++)
    {
        if (tab[i] == false && i == 3 && tab[i+1] == false)
        {
            return false;
        }
        else if (tab[i] == false && i == 4 && tab[i - 1] == false) {
            return false;
        }
        else if (tab[i] == false && i!=3 && i!=4) {
            return false;
        }
    }
    }catch(e)
    {
        alert(e);
    }
    }
    function Validation_Etape_2(c)
    {
    //************************************************************************************************
    //************************************************************************************************
    //********************************************   ETAPE 2   ***************************************
    //************************************************************************************************
    //************************************************************************************************
    try
    {
        // -------------------- COMMENTAIRE ------------------------- //
        /*
        t1[0] = Jour                                 t1[1] = Mois
        t1[2] = Année                                t1[3] = Message Date
        t1[4] = Situation matrimoniale               t1[5] = Message Situation matrimoniale
        t1[6] = Mode d'habitation                    t1[7] = Message Mode d'habitation
        t1[8] = Adresse                              t1[9] = Message Adresse
        t1[10]= Ville                                t1[11]= Message Ville
        t1[12]= Profession                           t1[13]= Message Profession
        t1[14]= Année d'embauche                     t1[15]= Message Année d'embauche
        t1[16]= Code postal                          t1[17]= Message Code postal
        */
        // --------------------- FIN -----------------------//
        var tab1 = new Array(100);
        var t1 = c.split(",");
        tab1[0] = Validation_Obligation_Champs_Etape_2(docGetElmt(t1[0]),docGetElmt(t1[1]),docGetElmt(t1[2]),
                                              docGetElmt(t1[3]),docGetElmt(t1[4]),docGetElmt(t1[5]),
                                              docGetElmt(t1[6]),docGetElmt(t1[7]),docGetElmt(t1[8]),
                                              docGetElmt(t1[9]),docGetElmt(t1[10]),docGetElmt(t1[11]),
                                              docGetElmt(t1[12]),docGetElmt(t1[13]),docGetElmt(t1[14]),
                                              docGetElmt(t1[15]));//Validation des champs vide [Etape 2]
        for(var i=0;i<=tab1.length-1;i++)
        {
            if(tab1[i] == false)
            {
                return false;
            }
        }
    }
    catch(e)
    {
        alert(e);
    }
    }
    function Validation_Etape_3(c)
    {
    //************************************************************************************************
    //************************************************************************************************
    //********************************************   ETAPE 3   ***************************************
    //************************************************************************************************
    //************************************************************************************************
    try
    {
        // -------------------- COMMENTAIRE ------------------------- //
        /*
        t1[0] = Déjà contracté un crédit             t1[1] = Message contracté un crédit
        t1[2] = Salaire                              t1[3] = Message Salaire
        t1[4] = Charges                              t1[5] = Message Charges, loyers, allocations mensuels
        t1[6] = Banque                               t1[7] = Message Banque
        t1[8] = Ancienneté                           t1[9] = Message Ancienneté du compte
        */
        // --------------------- FIN -----------------------//
        var tab1 = new Array(100);
        var t1 = c.split(",");
        tab1[0] = Validation_Obligation_Champs_Etape_3(docGetElmt(t1[0]),docGetElmt(t1[1]),docGetElmt(t1[2]),
                                              docGetElmt(t1[3]),docGetElmt(t1[4]),docGetElmt(t1[5]),
                                              docGetElmt(t1[6]),docGetElmt(t1[7]),docGetElmt(t1[8]),
                                              docGetElmt(t1[9]),docGetElmt(t1[10]),docGetElmt(t1[11]));//Validation des champs vide [Etape 3]
        for(var i=0;i<=tab1.length-1;i++)
        {
            if(tab1[i] == false)
            {
                return false;
            }
        }
    }
    catch(e)
    {
        alert(e);
    }
    }
    //************************************************************************************************
    //************************************************************************************************
    //************************************** VALIDATION **********************************************
    //**************************************** FINALE ************************************************
    //************************************************************************************************
    function Validation(c,d,e)
    {
        var bok = true;
        if(Validation_Etape_1(c) == false)
        {
            bok = false;
        }
        if(Validation_Etape_2(d) == false)
        {
            bok = false;
        }
        if(Validation_Etape_3(e) == false)
        {
            bok = false;
        }
        
        return bok;
    }
    //************************************************************************************************
    //******************************************FIN***************************************************
    //************************************** VALIDATION **********************************************
    //**************************************** FINALE ************************************************
    //************************************************************************************************
    //************************************************************************************************
    //************************************************************************************************
    //***********************************   VALIDATION DATE   ****************************************
    //************************************************************************************************
    //************************************************************************************************  
    function relanceOnChange(ddlr,a,txtd)
    {
        var ddl = document.getElementById(ddlr);
        var txtdate = document.getElementById(txtd);
        if(ddl.selectedIndex != 0)
        {
            document.getElementById(a).style.visibility = "visible";
            txtdate.value = (txtdate.value == "")?getDATENOW():txtdate.value;
        }
        else
        {
            document.getElementById(a).style.visibility = "hidden";
            txtdate.value = "";
        }
    }
    
    function getDATENOW()
    {
        var d = new Array();
        var date = new Date();
        d[0] = (date.getDate().toString().length == 1)? "0" + (date.getDate()):(date.getDate());
        d[1] = (date.getMonth().toString().length == 1)? "0" + (date.getMonth() + 1):(date.getMonth() + 1);
        d[2] = date.getFullYear();
        d[3] = (date.getHours().toString().length == 1)? "0" + (date.getHours()):(date.getHours());
        d[4] = (date.getMinutes().toString().length == 1)? "0" + (date.getMinutes()):(date.getMinutes());
        
        return (d[0] + "-" + d[1] + "-" + d[2] + " " + d[3] + ":" + d[4]);
    }
    
    //************************************************************************************************
    //************************************************************************************************
    //*********************************   END DISABLE TXT DATE   *************************************
    //************************************************************************************************
    //************************************************************************************************
    //************************************************************************************************
    //************************************************************************************************
    //************************************************************************************************
    //***********************************   PRINTING DEMANDE   ***************************************
    //************************************************************************************************
    //************************************************************************************************
    //************************************************************************************************
    function stopRKey(evt) {
        var evt = (evt) ? evt : ((event) ? event : null);
        var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
        if ((evt.keyCode == 13) && (node.type == "text")) { return false; }
    }
//    function printing_Demande(id)
//    {
//        window.open('Teste.aspx');
//    }    
