$(document).ready(function() {
    $("#bt_inscription").click(function() {
        $("#_form").show();
        $("#popup").fadeIn(500);
    });

    $("#ferme_popup").click(function() {
        $("#popup").fadeOut(500);
    });

    $("#inscription").click(function() {
        var mail = VerifMail($("#f_email").val());
        var nom = VerifNom($("#f_nom").val());
        if (mail && nom) {
            $.ajax({
                type: "POST",
                url: "new_inscrit.php",
                data: "name="+$("#f_nom").val()+"&email="+$("#f_email").val()+"",
                success: function(msg){
                    switch (msg) {
                        case "ok":
                            $("#_form").fadeOut(500, function() {
                                $("#_ok").fadeIn(2000, function() {
                                    $("#_ok").fadeOut(2000, function() {
                                        $("#popup").fadeOut(1000);
                                    });
                                });
                            });
                            break;
                        case "deja":
                            $("#_form").fadeOut(500, function() {
                                $("#_deja").fadeIn(1000, function() {
                                    $("#_deja").fadeOut(1000, function() {
                                        $("#_form").fadeIn(500);
                                    });
                                });
                            });
                            break;
                        default:
                            $("#_form").fadeOut(500, function() {
                                $("#_nok").fadeIn(1000, function() {
                                    $("#_nok").fadeOut(1000, function() {
                                        $("#_form").fadeIn(500);
                                    });
                                });
                            });
                            break;
                    }

                }
            });
        }
    });

});

function VerifMail(adresse)
{
    var place = adresse.indexOf("@",1);
    var point = adresse.indexOf(".",place+1);
    if ((place > -1)&&(adresse.length >2)&&(point > 1))
    {
        return(true);
    }
    else
    {
        $("#f_email").show("highlight", 1000);
        return(false);
    }
}

function VerifNom(nom)
{
    if (nom.length < 2) {
        $("#f_nom").show("highlight", 1000);
        return(false)
    } else {
        return(true);
    }
}
