﻿var num = 0;
var intervalo;

function navDestaques() {
    navegaTabs();
    clearInterval(intervalo);
    intervalo = window.setInterval(navegaTabs, 5000);
}

function navegaTabs() {
    var numImages = $("#numImages > a").size();

    $(".tab").removeClass("ativo");
    $("#lk" + num).addClass("ativo");

    if(num==1){
        $("#lk" + num).css({
            'border-left':"3px solid #314657",
	        'border-right':"4px solid #314657"
        });
	}
	$(".imagem a").hide();
	$("#img" + num).show();
	num++;
	if (num > (numImages-1)) {
	    num = 0;
	}
}

function navegaTabsClick(id) {
    $(".tab").removeClass("ativo");
    $("#lk" + id).addClass("ativo");

    if(id==1){
        $("#lk" + id).css({
            'border-left':"3px solid #314657",
	        'border-right':"4px solid #314657"
        });
	}
	$(".imagem a").hide();
	$("#img" + id).show();
	num=id;
}

function pauseDestaque() {
    clearInterval(intervalo);
}


function is_email(email) {
    er = /^[a-zA-Z0-9][a-zA-Z0-9\._-]+@([a-zA-Z0-9\._-]+\.)[a-zA-Z-0-9]{2}/;

    if (er.exec(email)) {

        return true;
    } else {

        return false;
    }
}

function cadNews() {
    if (($("#cadNome").val() != "" || $("#cadNome").val() != "Nome" || $("#cadEmail").val() != "" || $("#cadEmail").val() != "E-mail") && is_email($("#cadEmail").val()) != false) {
        $.ajax({
            type: "POST",
            url: "/FaleConosco/GravarEmail",
            data: "nome=" + $("#cadNome").val() + "&email=" + $("#cadEmail").val() + "",
            success: function (msg) {
                alert(msg);
                $("#cadNome").val("");
                $("#cadEmail").val("");
            }
        });
    } else {
        alert("Preencha todos os campos corretamente.");
    }
};



function enviarParticipacao(id) {

    //var nome = $("#FormP" + id + " #nome").val();
    var nome = $("#nome"+ id ).val();
    var email = $("#email" + id).val();
    var cidade = $("#cidade" + id).val();
    var telefone = $("#telefone" + id).val();
    var mensagem = $("#mensagem" + id).val();
    var id = $("#id" + id).val();
    var cbxInformativo = true;

    if (!$("#cbxInformativo" + id).is("checked")) {
        cbxInformativo = false;
    }

    //alert($("#divFormP" + id+" form").attr("id") + " | " + nome + " | " + email + " | " + cidade + " | " + telefone + " | " + mensagem);

    if ((nome != "" || email != "" || cidade != "" || telefone != "" || telefone != "") && is_email(email) != false) {
        $.ajax({
            type: "POST",
            url: "/Programa/Participa",
            //data: $("#FormP" + id).serialize(),
            data: { nome: nome, email: email, cidade: cidade, telefone: telefone, mensagem: mensagem, cbxInformativo: cbxInformativo, id: id },
            success: function (msg) {
                alert(msg);
                $("#FormP" + id + "input").val('');
                $("#FormP" + id + "textarea").val('');
                $('#divFormP' + id).slideUp("fast");
            }
        });
    } else {
        alert("Preencha todos os campos corretamente.");
    }
};

function fecharForm(id) {
    $("#FormP" + id + "input").val('');
    $("#FormP" + id + "textarea").val('');
    $('#divFormP' + id).slideUp("fast");
};

function abrirForm(id) {
    $('#divFormP' + id).slideDown("fast");
};


function votarEnquete() {
    var id = $(".opcoes input[type='radio']:checked").val();
    if (id != undefined) {
        $.post('/home/votarEnquete/' + id, function (data) {
            if (data == "ok") {
                alert("Voto computado.");
                $(".opcoes input[type='radio']:checked").removeAttr("checked");
            } else {
                alert(data);
            }
        });
    } else {
        alert("Selecione uma opção");
    }
}
