$(function () {
    $("#login_sub").click(function () {

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

        if (xhr.responseText.trim() == "loggingOk") {
            xhr = new XMLHttpRequest();

            xhr.open("GET", './pages/verification.php?type=addSessionAccount&email=' + $("#email").val() + "&mdp=" + $("#userpass").val(), false);
            xhr.send();
            window.location.href = "./pages/compte/profil";

            return false;
        } else {

            $('#email').css('background-color', '#e4442c');
            $('#email').css('border-color', '#e4442c');

            $('#userpass').css('background-color', '#e4442c');
            $('#userpass').css('border-color', '#e4442c');

            return false;
        }

    });
    $("#login_sub1").click(function () {
        xhr = new XMLHttpRequest();
        xhr.open("GET", './pages/verification.php?type=tryConnect&email=' + $("#email1").val() + "&mdp=" + $("#userpass1").val(), false);
        xhr.send();
        if (xhr.responseText.trim() == "loggingOk") {
            xhr = new XMLHttpRequest();
            xhr.open("GET", './pages/verification.php?type=addSessionAccount&email=' + $("#email1").val() + "&mdp=" + $("#userpass1").val(), false);
            xhr.send();

            window.location.href = "./azoteMe/pages/compte/profil";
            return false;
        } else {

            $('#email1').css('background-color', '#e4442c');
            $('#email1').css('border-color', '#e4442c');

            $('#userpass1').css('background-color', '#e4442c');
            $('#userpass1').css('border-color', '#e4442c');

            return false;
        }
    });
    $("#btn_submit_inscription").click(function () {
        var pseudo = $('#pseudo');
        alert(pseudo.trim());
        xhr.open("GET", './pages/verification.php?type=getPseudoAvailable&pseudo=' + pseudo, false);
        xhr.send();
    });

    $("#btn_disconnect").click(function () {
alert(location.pathname);
        if (location.pathname == "/azoteMe/pages/compte/profil/") {
            xhr = new XMLHttpRequest();
            xhr.open("GET", '../../.././pages/verification.php?type=disconnect', false);

            xhr.send();
            window.location.href = "../../.././index.php";
        } else if (location.pathname == "/azoteMe/") {

            xhr = new XMLHttpRequest();
            xhr.open("GET", './pages/verification.php?type=disconnect', false);

            xhr.send();
            window.location.href = "./index.php";

        }else if(location.pathname=="/azoteMe/pages/classement/drakah/")
        {
            xhr = new XMLHttpRequest();
            xhr.open("GET", '../../.././pages/verification.php?type=disconnect', false);

            xhr.send();
            window.location.href = "../../.././index.php";
        }
        return false;
    });

    /*
     $("#pseudo").change(function () {
     xhr = new XMLHttpRequest();
     xhr.open("GET", "./pages/verification.php?type=getPseudoAvailable&pseudo=" + $("#pseudo").val(), false);
     xhr.send();
     if (xhr.responseText.trim() == "false") {
     $('#pseudo').css('background-color', '#e4442c');
     $('#pseudo').css('border-color', '#e4442c');
     } else {
     $('#pseudo').css('background-color', '#fff');
     $('#pseudo').css('border-color', '#c7c3b4');
     }

     return false;
     });
     */
    $("#passwordConfirmation").change(function () {
        if ($("#passwordConfirmation").val() != $("#password").val()) {
            $('#passwordConfirmation').css('background-color', '#e4442c');
            $('#passwordConfirmation').css('border-color', '#e4442c');
            $('#password').css('background-color', '#e4442c');
            $('#password').css('border-color', '#e4442c');
        } else {
            $('#passwordConfirmation').css('background-color', '#fff');
            $('#passwordConfirmation').css('border-color', '#c7c3b4');
            $('#password').css('background-color', '#fff');
            $('#password').css('border-color', '#c7c3b4');
        }
        return false;
    });
    /*
     $("#email").change(function () {

     xhr = new XMLHttpRequest();
     xhr.open("GET", "./pages/verification.php?type=getUnusedMail&email=" + $("#email").val(), false);
     xhr.send();
     if (xhr.responseText.trim() == "false") {
     //window.alert(xhr.responseText.trim());
     $('#email').css('background-color', '#e4442c');
     $('#email').css('border-color', '#e4442c');
     } else {
     $('#email').css('background-color', '#fff');
     $('#email').css('border-color', '#c7c3b4');
     }
     return false;
     });
     */

});