function contato(elemento){
    this.elementoForm = elemento;
    var _this =this;
    
}

contato.prototype.fields = {nome:null,email:null,ddd:null,fone:null,assunto:null,msg:null}

contato.prototype.eventos = function(){
     var _this =this;
     var e = _this.elementoForm;

   //  _this.showErros();
     
     $(e).find('input[type=submit]').click(
        function(event){
            event.preventDefault();
            _this.save(e);
        });
        
}
contato.prototype.save = function(e){
     var _this = this;
    var href = $(e).attr("action");

    $.ajax({
        type:'post',
        dataType:'json',
        url:href,
        data:$(e).serialize(),
        success:_this.loadSenting
    });

  

    return false;
}

contato.prototype.loadSenting = function(data)
{
     var _this = this;
    data2 = new String(data);

    if( data2 == 'true' )
    {
        Aviso("Sua mensagem será respondida o mais breve possível! O Hapvida agradeçe o contato!");
        
        $("strong.error").hide();
    }else{
        contato.prototype.showErros(data);
    }
    
}
contato.prototype.showErros = function(data){
    
        for(var i in data){

            $("strong.error").show();
            $('input[name='+i+']').focus();
            $("strong.error").html(data[i]);
            
            return false;
        }
}

    
contato.prototype.validacao = function(e){
    $(e).validate({
       
        rules: {
            nome_cliente: {
                required: true,
                minlength: 2
            },
            email_cliente: {
                required: true,
                email: true
            },
       
            telefone_cliente:
            {
                required:true,
                minlength: 8
            }
    },
        // define messages para cada campo
        messages: {
            nome_cliente:
            {
                required:"Preencha o seu nome",
                minlength:"Preencha o seu nome"
            },
            email_cliente:
            {
                required:"email ivalido",
                email:"email n�o valido"
            },

            telefone_cliente:
            {
                required: "Prenchar o campo de telefone",
                minlength: " Numero n�o valido"
            }
        }
    });
}

function Aviso(aviso){

    $.blockUI({message: aviso});

   setTimeout($.unblockUI, 3000);
}
