$(document).ready(function() {


    blurFocus('.formLogin .login', 'Login');
    blurFocus('.formLogin .senha', 'Senha');


    $('.formLogin .login').focus(function() {
        if ($(this).attr('value') == 'Login') {
            $(this).attr('value', '');
            //$(this).removeClass('erro');
        }
    });

    $('.formLogin .senha').focus(function() {
        if ($(this).attr('value') == 'Senha') {
            $(this).attr('value', '');
            //$(this).removeClass('erro');
        }
    });

    $('.formLogin .btLogin').click(function() {
        var _error = 0;
        var campo = $('.formLogin .login');

        if (campo.attr('value').length < 3 || campo.attr('value') == 'Login' || campo.attr('value') == 'Digite seu nome') {
            _error = 1;
            //campo.addClass('erro');
            campo.attr('value', 'Login');
        } else {
            //campo.removeClass('erro');
        }
        
        campo = $('.formLogin .senha');
        if (campo.attr('value') == '' || campo.attr('value') == 'Senha') {
            _error = 1;
            //campo.addClass('erro');
            campo.attr('value', '');
        } else {
            //campo.removeClass('erro');
        }


        if (_error == 0) {
            //enviarContato();
        }

    }); ;

    /*
    $('.conteudoPag .boxSucesso .btFechar, .conteudoPag .boxErro .btFechar').click(function() {
        $(this).parent().fadeOut('fast');
    });
    */

});


function enviarContato() {

    var dataPost = $("#formLogin").serialize();

    $.ajax({
        type: "POST",
        url: "fale-conosco-ajax.asp",
        data: dataPost,
        dataType: 'html',
        success: function(html) {
            
            if (html == "OK") {
                $('.conteudoPag .boxSucesso').fadeIn('fast');

            } else {
                $('.conteudoPag .boxErro').fadeIn('fast');
            }

        }

    });
}



function validEmail(email) {
    var regmail = /^[\w!#$%&amp;'*+\/=?^`{|}~-]+(\.[\w!#$%&amp;'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
    if (regmail.test(email)) {
        return true;
    } else {
        return false;
    }
}


function blurFocus(objeto, texto) {
    $(objeto).blur(function() {
        if ($(this).attr('value') == '') {
            $(this).attr('value', texto);
        }
    });
    $(objeto).focus(function() {
        if ($(this).attr('value') == texto) {
            $(this).attr('value', '');
        }
    });
}
