function getAbsPath() {
    if (!window.location.host.match("localhost")) {
        if (window.location.pathname.match("backoffice"))
            return "http://www.basmaevent.com/backoffice/";
        return "http://www.basmaevent.com/";
    }
    else {
        if (window.location.pathname.match("backoffice"))
            return "http://localhost/basmaevent/backoffice/";
        return "http://localhost/basmaevent/";
    }
}

var ABSPATH = getAbsPath();

function doContact() {
    var status  = $("#contactStatus option:selected").val();
    var name    = $("#contactName").val();
    var society = $("#contactSociety").val();
    var email   = $("#contactEmail").val();
    var mobile  = $("#contactMobile").val();
    var adresse = $("#contactAdresse").val();
    var codePostal = $("#contactCodePostal").val();
    var ville       = $("#contactVille").val();
    var message     = $("#contactMessage").val();
    
    var error   = [];
    
    $("#pageContact .error").hide();
    $("#pageContact .valid").hide();
    
    if (name.length == 0) {
        error.push('Nom');
    }
    
    if (society.length == 0) {
        error.push('Société');
    }
    
    if (!checkEmail(email)) {
        error.push('Email');
    }
    
    if (adresse.length == 0) {
        error.push('Adresse');
    }
    
    if (codePostal.length == 0) {
        error.push('Code postal');
    }
    
    if (ville.length == 0) {
        error.push('Ville');
    }

    
    if (mobile.length == 0) {
        error.push('Téléphone');
    }
    
    if (message.length == 0) {
        error.push('Message');
    }
    
    if (error.length > 0) {
        $("#contactForm .error").html(error.join(", ") + " invalide.");
        $("#contactForm .error").fadeIn(1500);
    } else {
        $.post(ABSPATH + "ajax/doContact.php", {
            email       : email,
            mobile      : mobile,
            ville       : ville,
            name        : name,
            status      : status,
            message     : message,
            adresse     : adresse,
            society     : society,
            codePostal  : codePostal
        },
            function (datas) {
            }, "json"
        );
        $("#contactForm .error").addClass("confirm");
        $("#contactForm .error").html("Votre message a bien &eacute;t&eacute; envoy&eacute;.");
        $("#contactForm .error").fadeIn(1500);
        $(".contactItem").remove();
    }
}


