$(function()
{
    $("#signupButton").show();
    $("#loginButton").show();
    $(".req").addClass("required");
    $(".req").blur(function(){$(this).val() == "" ? $(this).addClass("req") : $(this).removeClass("req");});

    $("#txtTelephone, #txtReferal").keydown(function(e)
    { 	
        if (e == null) // ie
            keycode = event.keyCode;
        else // mozilla
            keycode = e.which;

        if(keycode == 13) $("#butSignup").click();

    });

    $("#txtLoginPassword").keydown(function(e)
    { 	
        if (e == null) // ie
            keycode = event.keyCode;
        else // mozilla
            keycode = e.which;

        if(keycode == 13) $("#butLogin").click();
    });

    $("#butLogin").click(function()
    {
        var email = $("#txtLoginEmail").val();
        var password = $("#txtLoginPassword").val();
        var errors = "";

        if ( email == "" )
        {
            errors += "<br><b>Email</b>";
        }
        if ( password == "" )
        {
            errors += "<br><b>Password</b>";
        }
        if ( errors != "" )
        {
            myAlert("Empty Fields", "The following fields are required:" + errors, "error");
            return false;
        }
        $("#loginButton").hide();
        $("#loginWait").show();
        $("#frmLogin").submit();
    });
    
    $("#butSignup").click(function()
    {
        var name = $("#txtName").val();
        var email = $("#txtEmail").val();
        var password = $("#txtPassword").val();
        var telephone = $("#txtTelephone").val();
        var errors = "";
        
        if ( name == "" )
        {
            errors += "<br><b>Name</b>";
        }
        if ( email == "" )
        {
            errors += "<br><b>Email</b>";
        }
        if ( password == "" )
        {
            errors += "<br><b>Password</b>";
        }
        if ( telephone == "" )
        {
            errors += "<br><b>Telephone</b>";
        }
        
        if ( errors != "" )
        {
            myAlert("Empty Fields", "The following fields are required:" + errors, "error");
            return false;
        }
        $("#signupButton").hide();
        $("#signupWait").show();
        $("#frmSignup").submit();
    });
});
