//**************************************************    
// Envoyer un email avec login et password   	
function VerifierLogin() {
    if (VerifierUnEmail('var_login'))
    {
            document.form_identification.login.value = trim(document.form_identification.login.value);
            if (document.form_identification.login.value=='') {
                lib_message("Veuillez vous identifier par votre E-mail !");
            } else {
                lib_message(file("ajax/EnvoiEmail.php?login="+document.form_identification.login.value));
            }
    }
    else lib_message("Votre E-Mail n\'est pas conforme !");
}

function trim(chaine) {
    // espaces au debut
    while (chaine.substring(0,1) == ' ')
        chaine = chaine.substring(1, chaine.length);

    // espaces a la fin
    while (chaine.substring(chaine.length-1,chaine.length) == ' ')
        chaine = chaine.substring(0, chaine.length-1);
    return chaine;
} 

//************************************************** 
// Afficher le div de creation de compte
function CreerUncompte() {
    if (getElement("TableauAccueil"))
    {
        if (TestSocket())
        {
            getElement("TableauAccueil").style.visibility ='hidden';
            if (getElement("TableauCreerCompte"))
            {
                // replacer le div
                getElement("TableauCreerCompte").style.left=parseInt(getElement("TableauAccueil").style.left);
                getElement("TableauCreerCompte").style.top=parseInt(getElement("TableauAccueil").style.top);
                InitCreerUncompte();
                Element_SetVisible("TableauCreerCompte");
                Element_SetVisible("contact_create_ctl13");
                Element_SetVisible("contact_create_ctl23");
                Element_SetVisible("contact_create_ctl25");
                Element_SetVisible("contact_create_ctl30");
                Element_SetNotVisible("contact_create_ctl32");
                Element_SetVisible("contact_create_ctl35");
                Element_SetVisible("contact_create_ctl350"); 
                Element_SetVisible("contact_create_ctl355"); 
                Element_SetNotVisible("contact_create_ctl27");
                getElement("contact_create_txtLastName").focus();
                return false;
            }
        }
        else 
        lib_message("Pour des raisons de maintenance, ce service est actuellement indisponible. Nous vous prions de nous excuser pour ce désagrément.");  
    }
}

// verifier les deux valeurs de mot de passe
function VerifierMP() {
   var reponse=false;
   
   if (getElement("contact_create_txtmp")) {
        if (getElement("contact_create_txtcmp")) { 
             if (getElement("contact_create_txtmp").value==getElement("contact_create_txtcmp").value)
                reponse = true;
             else lib_message("Vos mots de passe sont diff\351rents !");  
        }
    }
   return reponse; 
}  

// Creer un nouveau compte   
function VerifierCreerUncompte() {
    //  Verification champ obligatoire
    if (VerifierUnChamps("contact_create_txtLastName","contact_create_ctl13"))
    if (VerifierUnChamps("contact_create_txtPc","contact_create_ctl23"))
    if (VerifierUnChamps("contact_create_txtCity","contact_create_ctl25"))
    if (VerifierUnChamps("contact_create_txtPhone","contact_create_ctl30"))
    if (VerifierUnChamps("contact_create_txtMailAddress","contact_create_ctl35"))
    if (VerifierUnChamps("contact_create_txtmp","contact_create_ctl350"))
    if (VerifierUnChamps("contact_create_txtcmp","contact_create_ctl355"))
    if (VerifierMP()) 
    {
        if (VerifierUnEmail("contact_create_txtMailAddress"))
        {
            parametre="txtLastName="+ URLEncode(RetourValeurPage("contact_create_txtLastName"))+"&";
            parametre= parametre + "txtFirstName="+ URLEncode(RetourValeurPage("contact_create_txtFirstName"))+"&";
            parametre= parametre + "txtPc="+ URLEncode(RetourValeurPage("contact_create_txtPc"))+"&";
            parametre= parametre + "txtCity="+ URLEncode(RetourValeurPage("contact_create_txtCity"))+"&";
            parametre= parametre + "txtPhone="+ URLEncode(RetourValeurPage("contact_create_txtPhone"))+"&";
            parametre= parametre + "txtMailAddress="+URLEncode(trim(RetourValeurPage("contact_create_txtMailAddress")))+"&";
            parametre= parametre + "txtSp="+ URLEncode(RetourValeurPage("contact_create_txtSp"))+"&";
            parametre= parametre + "txtAdresse1="+ URLEncode(RetourValeurPage("contact_create_txtAdresse1"))+"&";
            parametre= parametre + "txtAdresse2="+ URLEncode(RetourValeurPage("contact_create_txtAdresse2"))+"&";
            parametre= parametre + "txtmconect="+ URLEncode(RetourValeurPage("contact_create_txtmp"))+"&"; 
            if (getElement("CIVILITE1").checked==true) parametre= parametre + "txtcivilite=M.&";
            if (getElement("CIVILITE2").checked==true)parametre= parametre + "txtcivilite=Mme&";
            if (getElement("CIVILITE3").checked==true)parametre= parametre + "txtcivilite=Mle&";
            parametre= parametre + "txtFax="+ URLEncode(RetourValeurPage("contact_create_txtFax"));

            lib_message(file("ajax/CreerClient.php?"+parametre));
            document.form_identification.login.value = trim(RetourValeurPage("contact_create_txtMailAddress"));
            // retour accueil
            FermerUncompte();
        }
        else lib_message("Votre E-Mail n\'est pas conforme !");
    }
    return false;
}
// Preparation ecran compte
function InitCreerUncompte() {
    Element_SetNotVisible("contact_create_ctl11");
    Element_SetNotVisible("contact_create_ctl13");
    Element_SetNotVisible("contact_create_ctl23");
    Element_SetNotVisible("contact_create_ctl25");
    Element_SetNotVisible("contact_create_ctl30");
    Element_SetNotVisible("contact_create_ctl32");
    Element_SetNotVisible("contact_create_ctl35");
    Element_SetNotVisible("contact_create_ctl27");
    Element_SetNotVisible("contact_create_ctl350"); 
    Element_SetNotVisible("contact_create_ctl355");
    getElement("contact_create_btnCreate").value="Créer un compte";
    getElement("contact_create_btnAnnulCreate").value="Retour accueil";
    Element_SetVisible("logoCreerCompte");
    Element_SetNotVisible("logoModifierCompte");
    Element_SetVisible("logoCreerCompte2");
    Element_SetNotVisible("logoModifierCompte2");
    EffacerUnChamps("contact_create_txtLastName");
    EffacerUnChamps("contact_create_txtFirstName");
    EffacerUnChamps("contact_create_txtPc");
    EffacerUnChamps("contact_create_txtCity");
    EffacerUnChamps("contact_create_txtPhone");
    EffacerUnChamps("contact_create_txtMailAddress");
    EffacerUnChamps('contact_create_txtmp'); 
    EffacerUnChamps('contact_create_txtcmp'); 
    EffacerUnChamps("contact_create_txtSp");
    EffacerUnChamps("contact_create_txtFax");
    EffacerUnChamps("contact_create_txtAdresse1");
    EffacerUnChamps("contact_create_txtAdresse2");
}   
// Fermer tous les div et afficher le div accueil       
function FermerUncompte() 
{
    Element_SetNotVisible("logoCreerCompte");
    Element_SetNotVisible("logoCreerCompte2");
    Element_SetNotVisible("logoModifierCompte");
    Element_SetNotVisible("logoModifierCompte2");
    Element_SetNotVisible("TableauCreerCompte"); 
    Element_SetVisible("TableauAccueil");
    Element_SetNotVisible("contact_create_ctl13");
    Element_SetNotVisible("contact_create_ctl23");
    Element_SetNotVisible("contact_create_ctl25");
    Element_SetNotVisible("contact_create_ctl30");
    Element_SetNotVisible("contact_create_ctl32");
    Element_SetNotVisible("contact_create_ctl35");
    Element_SetNotVisible("contact_create_ctl350"); 
    Element_SetNotVisible("contact_create_ctl355");
    Element_SetNotVisible("contact_create_ctl27");
    return false;
}          



//*********************************************   
// Identification (login Password)        
function Sidentifier()
{
    var reponse = false;
    var idinternaute = 0;
    if (VerifierUnEmail('var_login')){
        if (document.form_identification.login.value==''){
            lib_message("Veuillez vous identifier par votre E-mail !");
        }
        else
        {
            if (document.form_identification.password.value==''){
                lib_message("Veuillez vous identifier par mot de passe !");
            }
            else
            {
                document.form_identification.login.value = trim(document.form_identification.login.value);
                document.form_identification.password.value = trim(document.form_identification.password.value); 
                var data = "login="+document.form_identification.login.value+"&MP="+document.form_identification.password.value+"&idinternaute="+idinternaute;
                var reponse = filePost("ajax/VerifierMP.php", "POST", data);
                // login et password OK //
                if (reponse==1)
                {
                    // Gestion des Cookie
                    if (getElement('persistent'))
                    {
                        if (getElement('persistent').checked)
                        {
                            memologin(document.form_identification.login.value);
                        }
                        else DeleteCookie();
                    }
                    reponse = true;  
                } else {
                    // Gestion des erreurs
                    if (reponse==2)
                        lib_message("Vos codes d\'acc\350s n\'ont pas \351t\351 reconnus. Merci d\'essayer \340 nouveau en respectant les majuscules et minuscules");           
                    else
                        lib_message("Vos codes d\'acc\350s n\'ont pas \351t\351 reconnus. Merci d\'essayer \340 nouveau en respectant les majuscules et minuscules");              
                }
            }
        }
    }
    else lib_message("Votre E-Mail n\'est pas conforme !");
    return reponse;

}


