
/**
 Zone inscription
 */
function submitInscription(formulaire) {

    xhr = new XMLHttpRequest();
    xhr.open("GET", '../../pages/verification.php?type=getUnusedMail&email=' + $("#email").val(), false);
    xhr.send();

    var mail, password, pseudo,firstname,lastname = true;

if($('#pseudo').val() == '')
{
    $('#pseudo').css('background-color', '#e4442c');
    $('#pseudo').css('border-color', '#e4442c');
    pseudo = false;
}else
{
    $('#pseudo').css('background-color', '#c5d432');
    $('#pseudo').css('border-color', '#9baa0f');
    pseudo = true;
}
    if($('#firstname').val() == '')
    {
        $('#firstname').css('background-color', '#e4442c');
        $('#firstname').css('border-color', '#e4442c');
        firstname = false;
    }else{
        $('#firstname').css('background-color', '#c5d432');
        $('#firstname').css('border-color', '#9baa0f');
        firstname = true;
    }
    if($('#lastname').val() == '')
    {
        $('#lastname').css('background-color', '#e4442c');
        $('#lastname').css('border-color', '#e4442c');
        lastname = false;
    }else {
        $('#lastname').css('background-color', '#c5d432');
        $('#lastname').css('border-color', '#9baa0f');
        lastname = true;
    }

    if (getValideEmail() && $('#email').val() != '') {
        mail = true;
        $('#email').css('background-color', '#c5d432');
        $('#email').css('border-color', '#9baa0f');
    } else {
        mail = false;
        $('#email').css('background-color', '#e4442c');
        $('#email').css('border-color', '#e4442c');
    }


    if ($('#password').val() == $('#passwordConfirmation').val() && $('#password').val() !='' ) {
        $('#password').css('background-color', '#c5d432');
        $('#password').css('border-color', '#9baa0f');
        $('#passwordConfirmation').css('background-color', '#c5d432');
        $('#passwordConfirmation').css('border-color', '#9baa0f');
        password = true;
    } else {
        password = false;
        $('#password').css('background-color', '#e4442c');
        $('#password').css('border-color', '#e4442c');
        $('#passwordConfirmation').css('background-color', '#e4442c');
        $('#passwordConfirmation').css('border-color', '#e4442c');
    }


    if (mail == true && password == true && firstname==true && lastname ==true && pseudo == true) {
        xhr = new XMLHttpRequest() ;
        xhr.open("GET", "../verification.php?type=addAccount&pseudo=" + $("#pseudo").val() +"&mdp=" +$("#password").val()+ "&mail=" +$("#email").val(), false) ;
        xhr.send();
        toastr.options = {"progressBar": true, "escapeHtml": true};
        toastr.info('Votre compte à était créé avec succès!')

        setTimeout(function()
        {
            $("#ErrorMessage").hide();
            window.location.href = "../../index.php";
        }, 2500);
    } else {
        toastr.options = {"progressBar": true, "escapeHtml": true};
        toastr.error('Verifier vos informations !')
    }
}


function getValideEmail() {
    xhr = new XMLHttpRequest();
    xhr.open("GET", '../../pages/verification.php?type=getUnusedMail&email=' + $("#email").val(), false);
    xhr.send();
    if (xhr.responseText.trim() == "false") {
        return false;
    } else if (xhr.responseText.trim() == "true") {
        return true;
    }
}