
function showHideFormulaire() {
    if($("#formulaireContact").is(":hidden")){
        $("#formulaireContact").slideDown(1000);
    }
    else {
        $("#formulaireContact").slideUp(1000, cleanForm());
    }
}

function cleanForm() {
    $("#nom").val("");
    $("#prenom").val("");
    $("#email").val("");
    $("#adresse").val("");
    $("#checkCatalogue").attr('checked', false);
    $("#checkMaison").attr('checked', false);
    $("#checkImmo").attr('checked', false);
    $("#checkMateriaux").attr('checked', false);
    $("#checkFormations").attr('checked', false);
    $("#telephone").val("");
    $("#commentaire").val("");
}

/**
 * AJAX : Envoyer un message au chat
 * (demande d'insertion d'un message dans la base de données
 * grâce à PHP)
 */
function sendCatalogue() {

    var nom = $("#nom").val();
    var prenom  = $("#prenom").val();
    var email  = $("#email").val();
    var adresse  = $("#adresse").val();
    var checkCatalogue  = $("#checkCatalogue").is(":checked");
    var checkMaison  = $("#checkMaison").is(":checked");
    var checkImmo  = $("#checkImmo").is(":checked");
    var checkMateriaux  = $("#checkMateriaux").is(":checked");
    var checkFormations  = $("#checkFormations").is(":checked");
    var telephone  = $("#telephone").val();
    var commentaire  = $("#commentaire").val();
    if(nom != "" && prenom != "" && email != "" && telephone != "" && adresse != "") {
        $.ajax({
            type    :   "POST",
            url     :   "sendCatalogue.php",
            data    : {
                nom : nom,
                prenom : prenom,
                email : email,
                adresse : adresse,
                checkCatalogue : checkCatalogue,
                checkMaison : checkMaison,
                checkImmo : checkImmo,
                checkMateriaux : checkMateriaux,
                checkFormations : checkFormations,
                telephone : telephone,
                commentaire : commentaire
            },/*
                "nom=" + nom +
                "&prenom=" + prenom +
                "&email=" + email +
                "&adresse=" + adresse +
                "&checkCatalogue=" + checkCatalogue +
                "&checkMaison=" + checkMaison +
                "&checkImmo=" + checkImmo +
                "&checkMateriaux=" + checkMateriaux +
                "&checkFormations=" + checkFormations +
                "&telephone=" + telephone +
                "&commentaire=" + commentaire ,*/
            datatype:   "xml",
            error   :   function() {alertJS("L'envoi de votre demande de formulaire a échoué, merci de rééssayer ultérieurement.");},
            success :
                function  (response) {
                    $(response).find("result").each(function() {
                        alertJS($(this).find("message").text());
                        
                        if($(this).find("status").text() == 'OK')
                            showHideFormulaire();
                        
                    });
                    
                }
        });


    }
    else {
        alertJS("Veuilliez remplir les champs obligatoires* avant de valider ce formulaire.");
    }
}

function alertJS(text){
      // effects : 'blind', 'clip', 'drop', 'explode', 'fold', 'puff', 'slide', 'scale', 'size', 'pulsate'
      $("#dialog").text(text);
      $("#dialog").dialog( {
          buttons: {"OK": function() {$(this).dialog("close");}},
          draggable: false,
          resizable : false,
          modal: true,
          show: "drop",
          hide: "drop",
          title : 'Information',
          closeOnEscape : true
      });
}

function showLinkConfirm(text, url) {
      $("#dialog").text(text);
      $("#dialog").dialog( {
          buttons: {"OK": function() {
                            window.location.href = url;
                    },
                    "Annuler": function() {
                            $( this ).dialog( "close" );
                    }},
          draggable: false,
          resizable : false,
          modal: true,
          show: "drop",
          hide: "drop",
          title : 'Information',
          closeOnEscape : true
      });
}

