$(document).ready(function(){

    $(".fone").mask("(99)9999-9999");

    $("a[rel=grupo_imagens]").fancybox();

    $("#ne").click(function(event){
        event.preventDefault();
        $("#formNews").submit();
    });

    $("input[holder]").each(function(){
        var $this = $(this);
        $this.val($this.attr("holder")).addClass('holder');

        $this.focus(function(){
            var $this = $(this);

            if($this.val() == $this.attr('holder')) {
                $this.val("").removeClass('holder');
            }
        });

        $this.blur(function(){
            var $this = $(this);

            if(this.value.length == 0) {
                $this.val($this.attr("holder")).addClass('holder');
            }
        });

    });

    $("#at").click(function(event){
        event.preventDefault();
        $("#form_contato").submit();
    });

    $("#sub").click(function(event){
        event.preventDefault();
        $("#formIndique").submit();
    });

    $("#formIndique").validar({
        "after": function(){
            $("#env").show('slow');
            $.post(URLBASE+'local/enviar', this.serialize(), function(data){
                $("#env").hide("slow");
                if(data.ok){
                    alert("Em breve a pessoa indicada recebera uma mensagem da Moveis Boa Vista com o link do Site.  Agradecemos sua visita ao nosso site!");
                    document.formIndique.reset();
                //window.location = URLBASE+'index.php';
                }else{
                    alert('Erro: Impossivel enviar e-mail, tente mais tarde!!');
                //window.location = URLBASE+'index.php';
                }
            }, 'json');
            return false;
        },
        "marcar": false
    });

    $("#formNews").validar({
        "after": function(){
            $("#envy").show('slow');
            $.post(URLBASE+'local/cadastrar', this.serialize(), function(data){
                $("#envy").hide("slow");
                if(data.ok){
                    alert("Cadastro realizado com sucesso");
                    document.formNews.reset();
                //window.location = URLBASE+'index.php';
                }else{
                    alert('Não foi possível realizar o cadastro!!');
                //window.location = URLBASE+'index.php';
                }
            }, 'json');
            return false;
        },
        "marcar": false
    });

    $("#form_contato").validar({
        "after": function(){
            $("#envies").show('slow');
            $.post(URLBASE+'contato/enviar', this.serialize(), function(data){
                $("#envies").hide("slow");
                if(data.ok){
                    alert("Contato enviado com sucesso");
                    document.form_contato.reset();
                //window.location = URLBASE+'index.php';
                }else{
                    alert('Não foi possível enviar o contato!!');
                //window.location = URLBASE+'index.php';
                }
            }, 'json');
            return false;
        },
        "marcar": false
    });
});
