﻿
    var arrJours = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

    var Jours = ".jours";
    var Mois = ".mois";
    var Annees = ".annees";

    function RemplirChamps(obj) {
        var Result = obj.split(" - ");
        $('#'+arrObligatoire[7]).val(Result[0]);
        $('#'+arrObligatoire[8]).val(Result[1]);             
    }
    
    function afficherMessage(objID, msg, color) {
        $("#"+objID+"_error").text(msg);
        $("#"+objID).css("borderColor", color);         
    }

    function afficherMessages(obj, msg) {
        if (msg == "") {
            afficherMessage(obj.id, "", "#0C0");
        } 
        else if (msg != " ") {
            afficherMessage(obj.id, msg, "#C00");
        }           
    }

    function chargement(e) {
        afficherMessage(this.id, "", "");
    }
    
    function verificationInput(e) {
        var msg = "";

        msg = verificationInputNonVide(this);                  
        afficherMessages(this, msg);
    }

    function verificationInputNonVide(obj) {
        var msg = "";   
        
        if (obj.value == "") {
            msg = "Le champ ne peut pas être vide.";    
        }
        
        return msg;
    }
    
    function verificationTaille(p_Objet, p_min, p_max) {
        var msg = verificationInputNonVide(p_Objet);

        if (msg == "") {
            if (p_Objet.value.length < p_min || p_Objet.value.length > p_max) {
                msg = "Le texte doit comporter de " + p_min + " à " + p_max + " caractères.";
            }
        }
        
        afficherMessages(p_Objet, msg);
    }

    function verificationPassword(p_Objet, p_Obj1, p_Obj2) {
        var msg = verificationInputNonVide(p_Objet);
        
        if (msg == "") {
            if (p_Obj1.value != p_Obj2.value) {
                msg = "Le texte saisi ne correspond pas au premier mot de passe.";
            }
            afficherMessages(p_Obj2, msg);
        }
        else {
            afficherMessages(p_Objet, msg);
        }            
    }

    function verificationAJAX(e) {
        var objAjax = this;
        var txtValeur = this.value;
        var msg = " ";
        var result;
        
        afficherMessage(this.id, "", "");
        
        $.getJSON("testPseudo.aspx", {nom:this.title, valeur:txtValeur}, function(p_Data) {
            if (txtValeur == $("#"+objAjax.id).val()) {                
                if (p_Data.code == 'OK') {
                    //afficherMessages(objAjax, p_Data.message);
                }
            }        
        });        
    }
        


    function ajouterJour(listeID, valeur, texte) {
        var jour = document.createElement('option');
        jour.text = texte;
        jour.value = valeur;
        try {
            $(listeID)[0].add(jour, null);
        }
        catch(ex) {
            $(listeID)[0].add(jour);
        }        
    }

    function afficheJours(e) {
        var dernierJour = $(Jours)[0].length - 1;
        var jour = $(Jours)[0].options[$(Jours)[0].selectedIndex].value;
        var mois = $(Mois)[0].options[$(Mois)[0].selectedIndex].value;
        var annee = $(Annees)[0].options[$(Annees)[0].selectedIndex].value;
        var maxJours = arrJours[mois - 1];            
        
        while(maxJours < dernierJour) {                
            $(Jours)[0].remove(--dernierJour + 1);
        }
        
        while(maxJours > dernierJour) {     
            dernierJour++           
            ajouterJour(Jours, dernierJour, dernierJour);
        }
        
        if (mois == 2) {
            if (!((annee%4==0 && annee%100!=0) || annee%400==0)) {
                $(Jours)[0].remove(--dernierJour + 1);
                maxJours--;
            }
        }        
        
        if (jour > maxJours) {
            $(Jours)[0].selectedIndex = maxJours;
        }
    }
    
    
    function genCaptcha(p_Code) {
        var date = new Date();
        $('#imgCaptcha').attr("src", "CaptchaGenerator.aspx?s=" + p_Code + "&r=" + date.getMilliseconds());
    }
    
    function Switch(p_Sender, p_ObjId, p_Texte){
        var obj = $("#" + p_ObjId); 
        
        if (!obj.hasClass('e_invisible')) {
            obj.addClass('e_invisible'); 
            p_Sender.innerHTML = 'Afficher ' + p_Texte;
        }
        else {
            obj.removeClass('e_invisible');
            p_Sender.innerHTML = 'Masquer ' + p_Texte;
        }
    }
    
    function displayResult(p_ObjectId) {
        $("#" + p_ObjectId).load("EnvoiMailConfirmation.aspx");
        $("#" + p_ObjectId).css("display", "block");
        return false;
    }
	
	function RenvoiMailConfirmationCompte(p_ObjectId, url) { 
		$("#" + p_ObjectId).load("EnvoiMailConfirmation.aspx?url="+url); 
		$("#" + p_ObjectId).css("display", "block"); 
		return false; 
	} 
    
    
