function DialogMessage(DivElement, Title) {
    DivElement.dialog
    ({
        modal: true,
        title: Title,
        buttons: {
            'Ok': function () {
                $(this).dialog("close");
            }
        },
        resizable: false,
    })
}

function Valida(InputElement) {
    var InputValue = $(InputElement).val();
    if (InputValue == "") {
        return false;
    }
    else {
        return true;
    }
}

function ValidaMail(InputElement) {
    var InputValue = $(InputElement).val();
    if (InputValue.indexOf("@") == -1 || InputValue.indexOf(".") == -1)
    {
        return false;
    }
    else
    {
        return true;
    }
}

$(document).ready(function() {
    $(".SubmitButtonClick").click(function() {
        var InputElement = $("input[type=text], input[type=password], textarea");
        for(var i = 0; i < InputElement.length; i++)
        {
            if (Valida(InputElement[i]) == false)
            {
                var DivElement = $("<div>Preencha todos os campos!</div>");
                DialogMessage(DivElement, "Erro!");
                return false;
            }
        }

        var InputMail = $(".MailInput");

        if (InputMail.length > 0)
        {
            if (ValidaMail(InputMail) == false)
            {
                var DivElement = $("<div>Preencha um e-mail v&aacute;lido.</div>");
                DialogMessage(DivElement, "Erro!");
                return false;
            }
        }
    });
});
