var corDow = "#DDDDDD";
var corOut = "#F3F3F3";
var corOver = "#E9E9E9";

var corOverPaginacao = "#FFFFFF";
var corOutPaginacao = "#F9F0D3";

function mudaCorTr(lugar, cor){
	lugar.bgColor = cor;
}

function verificaEmail(mail){
	str = new String(mail);
	var arroba = str.indexOf('@',0);
	if (arroba > 0){ // Tem arroba
		var ponto = str.indexOf('.',arroba);
		if (ponto > 0){ // Tem ponto
			if (str.length > ponto){ // Tem algo depois do ponto
				if ((arroba + 1) != ponto){ // Tem algo entre a arroba e o ponto
					// É um E-mail !!!
					return true;
				}
				return false;
			}
			return false;
		}
		return false;
	}
	return false;
}

function mostraDiv(nomeDiv){
	document.getElementById(nomeDiv).style.display = "block";
}

function escondeDiv(nomeDiv){
	document.getElementById(nomeDiv).style.display = "none";
}

function abreJanela(url, name, height, width) {
  var str = "height=" + height + ",innerHeight=" + height;
  str += ",width=" + width + ",innerWidth=" + width + ',resizable=yes,scrollbars=no,menubar=no,status=no';
  if (window.screen) {
    var ah = screen.availHeight - 30;
    var aw = screen.availWidth - 5;

    var xc = (aw - width) / 2;
    var yc = (ah - height) / 2;

    str += ",left=" + xc + ",screenX=" + xc;
    str += ",top=" + yc + ",screenY=" + yc;
  }
  window.open(url, name, str);
}


function abreJanelaGaleria(url, name) {
  var str = "resizable=yes,scrollbars=yes,menubar=no,status=no, left=10, top=10, width=200, height=200";
  window.open(url, name, str);
}


function buscaInterna(){
	data_inicio = 'data_inicio=' + concatenaData('data_inicio');
	data_termino   = '&data_termino='   + concatenaData('data_termino');
	parametros='?';
	for (i = 0; i < document.form.length; i++){
		//verifica campos a serem enviados na URL baseado em seus names e values
		if(	form.elements[i].value!='' &&
			form.elements[i].value.indexOf('Selecione')<0 &&
			(form.elements[i].type!='text' || form.elements[i].type!='select-one') &&
			form.elements[i].name!='' &&
			form.elements[i].name.indexOf('dia_')<0 &&
			form.elements[i].name.indexOf('mes_')<0 &&
			form.elements[i].name.indexOf('ano_')<0){

			parametros+=form.elements[i].name + "=" + form.elements[i].value +'&';
		}
	}
	parametros += data_inicio + data_termino;
	window.location.href = 'lista.php' + parametros;
}
function concatenaData(nome){
	dia=eval('document.getElementById("dia_' + nome + '").value');
	mes=eval('document.getElementById("mes_' + nome + '").value');
	ano=eval('document.getElementById("ano_' + nome + '").value');
	data = dia + '/' + mes + '/' + ano;
	return data;
}

function nova_jan(newwindow)
   {
      var desktop = window.open(newwindow,'new_window','toolbar=yes,location=yes,directories=yes,status=yes,scrollbars=yes,menubar=yes,resizable=yes');
   }

// O BLOCO DE FUNÇÕES ABAIXO VALIDA AS DATAS CRIADAS PELA CLASSE COMBO_DATA DO PHP
var obData	= new Date();
var focoDia = new String(obData.getDate());
var focoMes = new String(obData.getMonth());
var focoAno = new String(obData.getFullYear());

function focusData(obDia, obMes, obAno) {
	focoDia = obDia.value;
	focoMes = obMes.value;
	focoAno = obAno.value;
}

function verificaData(obDia, obMes, obAno) {
	var dia = obDia.value;
	var mes = obMes.value;
	var ano = obAno.value;
	var controle = true;

	switch(mes) {
		case '02':
			ano = ano % 4;
			if (ano > 0) { // se não for ano bissexto
				if (dia >= 29) { controle = false; }
			} else {
				if (dia >= 30) { controle = false; }
			}
		break;

		case '04':
		case '06':
		case '09':
		case '11':
			if (dia == 31) { controle = false; }
		break;
	}

	if(controle === false) {
		alert('A data selecionada não é válida!');
		obDia.value = focoDia;
		obMes.value = focoMes;
		obAno.value = focoAno;
		return false;
	} else { return true; }
}
// AQUI TERMINA O BLOCO DE FUNÇÕES QUE VALIDAM DATA

function aceitaNumeros(e){
    if (event.keyCode < 48 || event.keyCode > 57) {
        event.returnValue = false;
    }
}

function votar(enquete) {
    voto = 0;
    qtd  = document.form.enquete.length;

    for(i=0;i<qtd;i++) {
        if(document.form.enquete[i].checked === true) {
            voto = i + 1;
        }
    }

    if(voto > 0) {
        abreJanela('../include-site/enquete.php?it_acao=voto&id_enquete='+enquete+'&resposta='+voto,'enquete', 284, 408, 'auto');
        document.form.enquete[voto - 1].checked = false;
    } else {
        alert('Selecione qual das opções corresponde à sua opção de resposta!');
    }
}

function anteriores() {
	abreJanela('../include-site/enquete.php?it_acao=lista','enquete', 284, 408, 'auto');
}

function resultado(enquete) {
	abreJanela('../include-site/enquete.php?it_acao=resultado&id_enquete='+enquete,'enquete', 284, 408, 'auto');
}

function abreImagem(link, width, height){
    var largura = width  + 25;
    var altura  = height + 25;

    var left = (screen.width - largura) / 2;
    var top  = (screen.height - altura) / 2;

    var propriedades = 'height='+altura+',width='+largura+',top='+top+',left='+left+',toolbar=no,copyhistory=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,maximize=no';

    window.open(link, 'Preview', propriedades);
}

var header = "";
function showHeader(swf_path, width, height, title, wmode, menu)
{
	header  = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" width=\"" + width + "\" height=\"" + height + "\" title=\"" + title + "\">";
	header += "<param name=\"movie\" value=\"../swf/" + swf_path + "\" />";
	header += "<param name=\"quality\" value=\"high\" />";
	header += "<param name=\"wmode\" value=\"" + wmode + "\" />";
	header += "<param name=\"menu\" value=\"" + menu + "\" />";
	header += "<embed menu=\"" + menu + "\" wmode=\"" + wmode + "\" src=\"../swf/"+ swf_path +"\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"" + width + "\" height=\"" + height + "\"></embed>";
	header += "</object>";
	
	document.write(header);
}


function enviaDados()
{
        var form = document.getElementById('form');
    	var erro_js = '';
    	var foco = '';

        if (form.nome.value == '')
        {
    		erro_js = 'Digite seu nome.\n';
    		foco = 'nome';
    	}
        if (form.email.value == ''){
            erro_js = erro_js + 'Digite seu e-mail\n';

           if (foco == '') foco = 'email';
        } 
		else 
		{
            if (!verificaEmail(form.email.value)){
                erro_js = erro_js + 'Endereço de e-mail inválido\n';
                if (foco == '') foco = 'email';
            }
        }
		
        if (form.ddd.value == '')
        {
    		erro_js += 'Digite o DDD.\n';
    		if (foco == '') foco = 'ddd';
    	}

        if (form.telefone.value == '')
        {
    		erro_js += 'Digite seu telefone.\n';
    		if (foco == '') foco = 'telefone';
    	}

        if (form.cidade.value == '')
        {
    		erro_js += 'Digite sua cidade.\n';
    		if (foco == '') foco = 'cidade';
    	}

        if (form.estado.value == '')
        {
    		erro_js += 'Digite seu estado.\n';
    		if (foco == '') foco = 'estado';
    	}
        if (form.pais.value == '')
        {
    		erro_js += 'Digite o país onde reside.\n';
    		if (foco == '') foco = 'pais';
    	}
		

		if(!isCpfCnpj(form.cnpj.value))
        {
    		erro_js += 'CPF ou CNPJ inválidos.\n';
    		if (foco == '') foco = 'cnpj';
    	}
		

    	if (erro_js == '')
    	{
    	 
            form.submit();
		    
            

    	} else {
    		alert(erro_js);
    		campo = eval('form.' + foco);
    		campo.focus();
    		return;
    	}
}


//*********************************************************



function login()
{
        var form = document.getElementById('form');
    	var erro_js = '';
    	var foco = '';

        if (form.email.value == ''){
            erro_js = erro_js + 'Digite seu e-mail\n';

           if (foco == '') foco = 'email';
        } 
        if (form.senha.value == '')
        {
    		erro_js += 'Digite a senha.\n';
    		if (foco == '') foco = 'senha';
    	}

    	if (erro_js == '')
    	{
            form.submit();

    	} else {
    		alert(erro_js);
    		campo = eval('form.' + foco);
    		campo.focus();
    		return;
    	}
}



function enviaPergunta()
{
        var form = document.getElementById('form');
    	var erro_js = '';
    	var foco = '';

        if (form.assunto.value == ''){
            erro_js = erro_js + 'Digite o assunto.\n';

           if (foco == '') foco = 'assunto';
        } 

    	if (erro_js == '')
    	{
            form.submit();

    	} else {
    		alert(erro_js);
    		campo = eval('form.' + foco);
    		campo.focus();
    		return;
    	}
}

