var regemail = new RegExp("^([_a-z0-9-]+)(\\.[_a-z0-9-]+)*@([a-z0-9-]+)(\\.[a-z0-9-]+)*(\\.[a-z]{2,4})$");
//var regtelefone = new RegExp("( \([0-9]{2}\) [0-9]{4}-[0-9]{4})");
$( function() {

    $("#frmContato .botao").click( function() {
        erros = validaFormContato();
        if ( erros != '' ) {
            alert(erros);
            return false;
        }
        $("#frmContato").submit();
    });

    $("#frmContato input").blur( function() {
        if ( $(this).val() == '' ) $(this).val($(this).attr('alt'));
    });

    $("#frmContato input").focus( function() {
        if ( $(this).val() == $(this).attr('alt') ) $(this).val('');
    });

    $("#msg").blur( function() {
        if ( $(this).text() == '' ) $(this).text('Digite sua mensagem...');
    });

    $("#msg").focus( function() {
        if ( $(this).text() == 'Digite sua mensagem...' ) $(this).text('');
    });

    $("#frmContato .telefone_input").focus( function() {
        //coloca mascara no campo apos o click sobre o mesmo
        //pois estava dando comflito entre a exebicao do valor do campo e a mascara
        $(this).setMask("(999) 9999-9999");
    });

});

function validaFormContato() {
    var msg = '';

    if ($("#frmContato .nome_input").val().length < 1 || $("#frmContato .nome_input").val() == 'Nome') msg += "Preencha o campo 'Nome'. \n";
    if ( !regemail.test($("#frmContato .email_input").val()) )        msg += "Preencha o campo 'Email'. \n";
    if ( $("#frmContato .telefone_input").val().length != 15 )  msg += "Preencha o campo 'Telefone'. \n";
    if ($("#frmContato #msg").text().length < 1 || $("#frmContato #msg").val() == 'Digite sua mensagem...') msg += "Preencha o campo 'Mensagem'. \n";

    return msg;
}
