/*
Início Funções utlizadas pelo sistema
*/
window.focus();
theObjects = document.getElementsByTagName("object");
for (var i = 1; i < theObjects.length; i++)
{
	theObjects[i].outerHTML = theObjects[i].outerHTML;//
}

var datas = new Date();
var dia = datas.getDate();
var DiaHoje = datas.getDay();
var EsteMes = datas.getMonth();
var Ano = datas.getFullYear();
var DiaMes = datas.getDate();
var timerID = null;
var timerRunning = false;

if (DiaMes < 10)
{
	DiaMes = "0" + DiaMes;
}

NomeDia = new CriaTab(7)
NomeDia[0] = "Domingo"
NomeDia[1] = "Segunda-Feira"
NomeDia[2] = "Terça-Feira"
NomeDia[3] = "Quarta-Feira"
NomeDia[4] = "Quinta-Feira"
NomeDia[5] = "Sexta-Feira"
NomeDia[6] = "Sábado"

DiaSemana = NomeDia[DiaHoje]

MesAtual = new CriaTab(12)
MesAtual[0] = "01"
MesAtual[1] = "02"
MesAtual[2] = "03"
MesAtual[3] = "04"
MesAtual[4] = "05"
MesAtual[5] = "06"
MesAtual[6] = "07"
MesAtual[7] = "08"
MesAtual[8] = "09"
MesAtual[9] = "10"
MesAtual[10] = "11"
MesAtual[11] = "12"

Mes = MesAtual[EsteMes]

// When the page loads:
window.onload = function()
{
  if (document.getElementsByTagName)
  {
    // Get all the tags of type object in the page.
    var objs = document.getElementsByTagName("embed");
    for (i=0; i<objs.length; i++)
    {
      // Get the HTML content of each object tag
      // and replace it with itself.
      objs[i].outerHTML = objs[i].outerHTML;
    }
  }
}

// When the page unloads:
window.onunload = function()
{
  if (document.getElementsByTagName)
  {
    //Get all the tags of type object in the page.
    var objs = document.getElementsByTagName("embed");
    for (i=0; i<objs.length; i++)
    {
      // Clear out the HTML content of each object tag
      // to prevent an IE memory leak issue.
      objs[i].outerHTML = "";
    }
  }
}

//Bloqueando help do browser via F1
document.onhelp = function ()
{
	event.cancelBubble = true;
	event.returnValue = false;
}

//Bloqueando teclas ALT e F11(que muda o visual do browser)
document.onkeydown = function ()
{
	var codigo = window.event ? event.keyCode : event.which;
	if (codigo == 18 || codigo == 122) {
		 event.keyCode = 0;
		 event.returnValue = false;
		 event.cancelBubble = true;
		 return false;
	}
}

function CriaTab (n)
{
	this.length = n
	for (var x = 1 ; x<= n ; x++)
	{
		this[x] = ""
	}
}//CriaTab

function stopclock ()
{
	if(timerRunning)
		clearTimeout(timerID);
	timerRunning = false;
}//stopclock

function showtime()
{
	var now = new Date();
	var hours = now.getHours();
	var minutes = now.getMinutes();
	var seconds = now.getSeconds()
	var timeValue = "" + hours
	var timeValue = "" + ((hours > 9) ? hours : "0" + hours)

	timeValue += ((minutes < 10) ? ":0" : ":") + minutes + "h"
	// timeValue += ((seconds < 10) ? ":0" : ":") + seconds
	// timeValue += (hours >= 12) ? " PM" : " AM"
	document.formHora.clock.value = timeValue;

	// you could replace the above with this
	// and have a clock on the status bar:
	// window.status = timeValue;

	timerID = setTimeout("showtime()",1000);
	timerRunning = true;
}//showtime

function startclock ()
{
	// Make sure the clock is stopped
	MenuCss();
	stopclock();
	showtime();
}//startclock

function MenuCss()
{
	if (document.all&&document.getElementById)
	{
		navRoot = document.getElementById("nav");
		for (i=0; i<navRoot.childNodes.length; i++)
		{
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI")
			{
				node.onmouseover=function()
				{
					this.className+=" over";
				}
				node.onmouseout=function()
				{
				  this.className=this.className.replace
					(" over", "");
				}
			}
		}
	}
}//MenuCss

function Trim(s)
{
  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
  {
    s = s.substring(1,s.length);
  }

  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
  {
    s = s.substring(0,s.length-1);
  }
  return s;
}//Trim

function validaEmail(objeto)
{
/********************************************************************************
 * Autor : Caito
 * Última modificação :	11/07/2001			Responsável : Autor
 *
 * Verifica se um email é válido.
 * Parâmetro : objeto, O campo de Email - usar o this.
 *
 * retorno : retorna TRUE caso o campo seja um email válido, caso contrário
 *           retorna FALSE e seta o focus no campo de Email.
 *******************************************************************************/
	var re = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
	return re.test(objeto.value);
}//validaEmail

function EhNumero()
{
	var codigo;
	//codigo = event.keyCode;
	codigo = window.event ? event.keyCode : event.which;

	//O Código 46 é correspondente ao ponto(.) usado para casas decimais.
	//O Código 58 é correspondente ao dois pontos(:) para campos Hora.
	// 13 - <ENTER>
	// 46 - .
	// 58 - :
	//alert(codigo);
	if (codigo == 13 || codigo == 46)
	{
		return true;
	}

	if(codigo < 48 || codigo > 57)
	{
		alert("Esse campo só aceita números!");
		event.keyCode = 0;
		return false;
	}
}//EhNumero

function selecionarTodos(objImg, objCheck)
{
	var imgSelTodos  = "bt_check_on.jpg";
	var imgNenhumSel = "bt_check_off.jpg";
	var pChecked, title;
	var src, posImage;

	if (objCheck == null)
	{
		alert("Nenhum item na lista.");
		return false;
	}
	src 	= objImg.src;
	title = objImg.title;
	posImage = src.indexOf(imgSelTodos);

	if (posImage>0) {
		src = src.substring(0, posImage) + imgNenhumSel;
		title = "Deselecionar Todos";
		pChecked = true;
	}
	else {
		posImage = src.indexOf(imgNenhumSel)
		src = src.substring(0, posImage) + imgSelTodos;
		title = "Selecionar Todos";
		pChecked = false;
	}

	objImg.src 		= src;
	objImg.title 	= title;

	if (objCheck.length == null) {
		objCheck.checked = pChecked;
	}
	else {

		for (var i=0;i<objCheck.length;i++) {
			objCheck[i].checked = pChecked;
		}
	}
}//selecionarTodos

function verAlgunMarcado(objCheck)
{
	var existe = false;
	if (objCheck == null)
	{
		alert("Nenhum item na lista");
		return false;
	}
	if (objCheck.length == null)
	{
		existe = objCheck.checked;
	}
	else
	{
		for (var i=0;i<objCheck.length;i++)
		{
			if (objCheck[i].checked)
			{
				existe = true;
				break;
			}
		}
	}
	if (!existe)
	{
		alert("Selecione um item");
		return false;
	}
	return true;
} //verAlgunMarcado

/* USADOS NO FORMULÁRIO COM 'CHECK ITENS' */
function verTodosMarcados(objCheck) {
	var countMarcados = 0;
	if (objCheck == null) {
		alert("Nenhum item na lista");
		return false;
	}
	if (objCheck.length != null){
		for (var i=0;i<objCheck.length;i++) {
			if (objCheck[i].checked) {
				countMarcados = countMarcados + 1;
				}
			}
	}
	if (countMarcados>1) {
		alert("Selecione um item");
		return false;
		}
	return true;
} //verTodosMarcados

function ValidaCNPJeCPF(pValue,sTipoValidacao)
{
	var lTam, numeroCNPJ, digitoCNPJ, strValida;
	var i = 0;
	var novoValida = "";

	strValida = pValue.value;
	lTam = strValida.length;

	// Esse loop server para a conversão do ponto em virgula para perfeito funcionamento
	// no browser Netscape.
	while(i < lTam)
	{
		if(strValida.charAt(i) == ".")
		{
			novoValida = novoValida + ',';
		}
		else
		{
			novoValida = novoValida + strValida.charAt(i);
		}
		i = i + 1;
	}//while
	strValida = novoValida;

	//retira rodos os caracteres diferentes de mumero que serao
	//utilizados para a formatacao.
	strValida = strValida.replace("-", "");
	strValida = strValida.replace(",", "");
	strValida = strValida.replace("/", "");
	strValida = strValida.replace(",", "");

	lTam = strValida.length;
	if (lTam <= 11 && sTipoValidacao == "CPF")
	{
		if (validaCPF(strValida))
		{
			pValue.value = colocaMascaraCPF(strValida);
		}
		else
		{
			alert("CPF inválido");
			return false;
		}//else
	}//if
	else if (sTipoValidacao == "CNPJ")
	{
		//captura o digito do cnpj
		if (strValida.length>14)
		{
			alert("CNPJ inválido!");
			return false;
		}//if
		else
		{
			numeroCNPJ = strValida.substring(-2,strValida.length-2);
		}//else
		digitoCNPJ = strValida.substring(strValida.length-2,strValida.length);
		if (validaCNPJ(numeroCNPJ, digitoCNPJ))
		{
			if (lTam==14)
			{
				strValida = strValida;
			}//if
			pValue.value = colocaMascaraCNPJ(strValida);
		}//if
		else
		{
			alert("CNPJ inválido");
			return false;
		}//else
	}//else if
 	return true;
}//ValidaCNPJeCPF

function validaCPF(cpf)
{
	var fach = 1;
	var pdig = cpf.substring(0,1);
	var cdig;
	if (cpf == "")
	{
	return true;
	}
	if (cpf.length < 11)
	{
		return false;
	}
	for(i = 1; i < cpf.length ;i++)
	{
		cdig = cpf.substring(i,i+1);
		if(pdig == cdig )
		{
			fach=fach+1;
		}
	}//for
	if(fach == cpf.length)
	{
		return false;
	}
	x = 0;
	soma = 0;
	dig1 = 0;
	dig2 = 0;
	texto = "";
	cpf1="";
	len = cpf.length; x = len -1;
	for (var i=0; i <= len - 3; i++)
	{
		y = cpf.substring(i,i+1);
		soma = soma + ( y * x);
		x = x - 1;
		texto = texto + y;
	}//for
	dig1 = 11 - (soma % 11);
	if (dig1 == 10) dig1=0 ;
	if (dig1 == 11) dig1=0 ;
	cpf1 = cpf.substring(0,len - 2) + dig1 ;
	x = 11; soma=0;
	for (var i=0; i <= len - 2; i++)
	{
		soma = soma + (cpf1.substring(i,i+1) * x);
		x = x - 1;
	}//for
	dig2= 11 - (soma % 11);
	if (dig2 == 10) dig2=0;
	if (dig2 == 11) dig2=0;
	if ((dig1 + "" + dig2) == cpf.substring(len,len-2))
	{
		return true;
	}//if
	else
	{
		return false;
	}//else
}//validaCPF

function colocaMascaraCPF(pValue)
{
	var i, strTemp, tam;
	strTemp = "";
	tam 		= pValue.length
	for (i=tam;i>0;i--)
	{
		if (i==(tam-2))
		{
			strTemp = pValue.substring(i-1,i) + "-" + strTemp;
		}//else if
		else if(i==(tam-5))
		{
			strTemp = pValue.substring(i-1,i) + "." + strTemp;
		}//else if
		else if (i==(tam-8))
		{
			strTemp = pValue.substring(i-1,i) + "." + strTemp;
		}//else if
		else
		{
			strTemp = pValue.substring(i-1,i) + strTemp;
		}//else
  }//for
  return strTemp;
}//colocaMascaraCPF

function colocaMascaraCNPJ(pValue)
{
	var i, strTemp, tam;
	strTemp="";
	tam = pValue.length
	for (i=tam;i>0;i--)
	{
		if (i==(tam-2))
		{
			strTemp = pValue.substring(i-1,i) + "-" + strTemp;
		}
		else if (i==tam-6)
		{
			strTemp = pValue.substring(i-1,i) + "/" + strTemp;
		}
		else if (i==(tam-9))
		{
			strTemp = pValue.substring(i-1,i) + "." + strTemp;
		}
		else if (i==(tam-12))
		{
			strTemp = pValue.substring(i-1,i) + "." + strTemp;
		}
		else
		{
			strTemp = pValue.substring(i-1,i) + strTemp;
		}
	}//for
	return strTemp;
}//colocaMascaraCNPJ

function validaCNPJ(Numero,Digito)
{
	var CGC = Numero;
	var peso1 = '543298765432';
	var peso2 = '654329876543';
	var soma1 = 0;
	var soma2 = 0;
	var digito1 = 0;
	var digito2 = 0;
	var total = 0;
	var i = 0;

	total = Numero.length + Digito.length;
	// Se o CNPJ for todo zero.
	if(parseInt(CGC) == 0) return false;
	if(Numero == "" && Digito == "") return true;
	// Para pergar a quantidade correta, pois o usuário pode ter preenchido
	// o CNPJ com 14 ou 15 números.
	if(total == 15)  CGC = Numero.substr(1,12);
	if ((Numero.length < 12) || (Digito.length < 2)) return false;
	for (i = 1; i < 12 - Numero.length+1; i++)
	{
		CGC = eval("'" + CGC + "'")
	}//for
	for (i = 1; i < CGC.length+1; i++)
	{
		soma1 += CGC.substring(i, i-1) * peso1.substring(i, i-1);
	}//for
	soma1 %= 11;
	if (soma1  < 2)
	{
 		digito1 = 0;
	}
	else
	{
 		digito1 = 11 - soma1;
	}//else
	for (i = 1; i < CGC.length+1; i++)
	{
		soma2 += CGC.substring(i, i-1) * peso2.substring(i, i-1);
	}//for
	soma2 += digito1 * 2
	soma2 %= 11;
	if (soma2  < 2)
	{digito2 = 0;}
	else
	{digito2 = 11 - soma2;}//else
	if (eval("'" + digito1 + digito2 + "'") != Digito)
	{
		return false;
	}//if
	else
	{
		return true;
	}//else
}//validaCNPJ

/* MODIFICA OS CARACTERES DIGITADOS PARA CAIXA BAIXA */
function modificarCaixaBaixa(id)
{
	var objeto;
	objeto = document.getElementsByName(id).item(0);
	objeto.value = objeto.value.toLowerCase();
} //modificarCaixaBaixa

/* EVITA A DIGITAÇÃO DE ESPAÇOS EM BRANCO */
function evitarEspaco()
{
	var codigo;
	codigo = window.event ? event.keyCode : event.which;
	if (codigo != 32) {
		return true;
	}
	if(codigo = 32){
		event.keyCode = 0;
		return false;
	}
	return true;
} //evitarEspaco

function FormataCEP(objeto)
{
	var tecla, tamanho;
	tecla = window.event ? event.keyCode : event.which;
	if (tecla != 8)
	{
		tamanho = objeto.value.length;
		if(tamanho == 6)
		{
			objeto.value = objeto.value + '-';
		}
		else if(tamanho == 2)
		{
			objeto.value = objeto.value + '.';
		}
	}//if
}//FormataCEP

function popUp(sUrl, nomeJanela, iAltura, iLargura, bScroll, bstatus)
{

	if (iLargura == 0) window.screen.width/2;
	if (iAltura  == 0) window.screen.height/2;

	var LeftPosition 	= (screen.width) ? (screen.width-iLargura)/2 : 0;
	var TopPosition 	= (screen.height) ? (screen.height-iAltura)/2 : 0;
	var settings 			= 'height=' + iAltura + ',width=' + iLargura + ',top=' + TopPosition + ',left=' + LeftPosition + ',scrollbars=' + bScroll + ',resizable=no, TOOLBAR=no, MENUBAR=no, STATUS=' + bstatus;

	return window.open (sUrl , nomeJanela, settings);void(0);
}//popUp

function showModal(sUrl, nomeJanela, iAltura, iLargura, aumentavel, bstatus)
{
	if (iLargura == 0) window.screen.width/2;
	if (iAltura  == 0) window.screen.height/2;

	window.showModalDialog(sUrl, nomeJanela,'dialogHeight: " + iAltura + "px; dialogWidth: " + iLargura + "px; center: Yes; help: No; resizable: " + aumentavel + "; status: " + bstatus + ";');
}//showModal

function Fechar()
{
	self.close();
}//Fechar

function FecharSessoes()
{
	//if(window.closed)
		//popUp('../Includes/FecharSessoes.asp', 'FecharSessoes','150', '30', 'no','no');
}//FecharSessoes

//Disable right mouse click Script
//By Maximus (maximus@nsimail.com) w/ mods by DynamicDrive
//For full source code, visit http://www.dynamicdrive.com

/*
var message="Direitos Reservados® a ASABRASIL\nArticulação no Semi-Árido Brasileiro.";

///////////////////////////////////
function clickIE4(){
if (event.button==2){
alert(message);
return false;
}
}

function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==2||e.which==3){
alert(message);
return false;
}
}
}

if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
document.onmousedown=clickIE4;
}

document.oncontextmenu=new Function("alert(message);return false")
*/
/*
//Impede clicar com p botão direito
function right(e)
{
	if (navigator.appName == 'Netscape' && (e.which == 3 || e.which == 2)) return false;
	else if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 || event.button == 3))
	{
		alert("Direitos Reservados® \nSindicato dos Policiais Federais em Pernambuco.\nSINPEF/PE");
		return false;
	}
	return true;
}//right
document.onmousedown=right;
if (document.layers) window.captureEvents(Event.MOUSEDOWN);
window.onmousedown=right;
*/
function max(txarea, tot)
{
	var d = document.Produtos_Clientes;
	total = tot;
	tam = txarea.value.length;
	str = "";
	str = str + tam;
	d.valor.value = total - str;
	if (tam >= total)
	{
		aux = txarea.value;
		txarea.value = aux.substring(0,total);
		if(d.valor.value == -1)
			d.valor.value = 0;
	}
}//max

function limitaTxtArea(TextArea, tamanhoMaximo)
{
	if (TextArea.value.length > tamanhoMaximo)
	{return(TextArea.value = TextArea.value.substr(0, tamanhoMaximo));}
	return(true);
}//limitaTxtArea

/* VALIDA DATA DE INÍCIO E DATA DE FIM */
function validarPeriodo(dataini, datafim) {
	var valdataini, valdatafim;
	if (dataini!= "" && datafim!= "")
	{
		valdataini = dataParaNumero(dataini);
		valdatafim = dataParaNumero(datafim);

		if (valdatafim >= valdataini)
		{return true;}
		else
		{return false;}
	}
} //validarPeriodo

/* tranforma uma data DD/MM/AAAA em um número com o valor AAAAMMDD para utilizar em comparações
   objData é um objeto HTML
 */
function dataParaNumero(objData)
{

  var strAux = new String("");
  var aSplit;

   aSplit = objData.value.split("/");

   //Ano
   strAux = aSplit[2];

   //Mes
   if (aSplit[1].length == 1)//Garante que haverá 2 caracteres
  	 strAux += "0";

   strAux += aSplit[1];

   //dia
   if (aSplit[0].length == 1)//Garante que haverá 2 caracteres
	   strAux += "0";

   strAux += aSplit[0];
   try
   {
   		return parseInt(strAux);
   }
   catch (e)
   {
   		return 0;
   }
}//dataParaNumero

function FormataData(objeto)
{
	var tecla, tamanho;
	tecla = window.event ? event.keyCode : event.which;
	if (!numeroInteiro(objeto))
		return;
	if (tecla != 8)
	{
		tamanho = objeto.value.length;
		if (tamanho == 2 || tamanho == 5)
		{
			objeto.value = objeto.value + "/";
		}
	}
} //FormataData

//Verifica se é um número inteiro
function numeroInteiro(obj)
{
	var codigo;
	codigo = window.event ? event.keyCode : event.which;
	if(codigo < 48 || codigo > 57)
	{
		event.keyCode = 0;
		return false;
	}
	return true;
}//numeroInteiro

/*****************************************************************
 * validaData                                                    *
 * Para ser aceita, a data deverá vir no formato D[D]/M[M]/AAAA  *
 * Onde os itens entre colchetes são opcionais                   *
 *****************************************************************/
function validaData(objeto)
{
	var valor = objeto.value;
	var mValores = "312831303130313130313031";
	var retorno = false;
	var lastDate = 0;
	var dia;
	var mes;
	var ano;
	var arrayData;

	if(valor == '') return true;

   /*  Cria expressão regular no formato da data.
       Não necessariamente o mês e o dia precisam ter 2 dígitos. */
   var reData = /^\d{1,2}\/\d{1,2}\/\d{4}$/;
   if (!reData.test(valor))
	 {
	      //Data deve estar no formato DD/MM/AAAA.
	      alert("Data deve estar no formato DD/MM/AAAA.");
		  objeto.focus();
      return false;
   }

	//Como chegou até aqui, sabe-se que o formato está garantido com 2 barras.
	arrayData = valor.split("/");

	dia  = arrayData[0];	// pega o dia
	mes  = arrayData[1];	// pega o mês
	ano  = arrayData[2];	// pega o ano

	if (ano < 1900)
	{
		//O sistema não trabalha com datas inferiores a 1980
		alert("O sistema não trabalha com datas inferiores a 1980.");
		objeto.focus();
		objeto.select();
		return false;
	}

	if (mes == 2){
		if (anobissexto(ano)) {
			lastDate = 29
		}
		else {
			lastDate = 28
		}
	}
	else {
		lastDate = mValores.substring((mes-1)*2, (mes-1)*2+2)
	}

   if ( (mes > 12) || (mes <= 0) ){
		retorno = false
	}
	else if ( (dia > lastDate) || (dia <=0) ){
		retorno = false
	}
	else {
		retorno = true
	}

	if (!retorno){
		alert("Data inválida");
		objeto.focus();
		objeto.select();
	}
	return retorno;


} //validaData

/* VERIFICA SE O ANO É BISSEXTO */
function anobissexto(ano)
{
	if (((ano % 4)==0) && ((ano % 100)!=0) || ((ano % 400)==0))
	{
		return (true);
	}
	else
		return (false);
} //anobissexto

function Enter(Funcao)
{
	var codigo = window.event ? event.keyCode : event.which;
	if(codigo != '13')
	{
		return false;
	}
	Funcao();
}//Enter

function recarregar(url)
{
	if(!EhPopup())
	{
		document.location.reload();
		return true;
	}
	if(window.parent.topo !=null)
	{
		window.parent.opener.document.location.reload();
		window.parent.top.document.location.reload();
		document.location.target='botton';
	}
	else
	{
		window.opener.document.location.reload();
	}
	document.location.href = url;
	return;
}//recarregar

function EhPopup()
{
	var retorno;
	//A janela anterior existe
	retorno = (window.opener != null);
	//No caso de haver frames
	if (window.parent.top != null)
	{
		retorno = (window.parent.opener != null);
	}
	return retorno;
}//EhPopup

// Para marcar todos os itens de um select
function marcaTodosOptions(objSelect)
{
	for(var i = 0; i < objSelect.options.length; i++)
	{objSelect.options[i].selected = true;} //for
} //marcaTodosOptions

function VerificarResposta(form)
{
	for(var i = 0;i< form.length;i++)
	{
		if (((form.elements[i].type=='radio') || (form.elements[i].type=='checkbox')) && (form.elements[i].checked))
		{
			var COD_ENQUETEITEM = "";
			for(var j=0;j < form.length;j++)
			{
				if (((form.elements[j].type=='radio') || (form.elements[j].type=='checkbox')) && (form.elements[j].checked))
				{
					COD_ENQUETEITEM = COD_ENQUETEITEM + form.elements[j].value + ","
				}
			}//for
			//Retira a ultima virgula dos itens selecionados
			COD_ENQUETEITEM = COD_ENQUETEITEM.substr(0,COD_ENQUETEITEM.length -1)
			popUp ("../Includes/ResultadoEnquete.asp?COD_ENQUETE=" + form.COD_ENQUETE.value + "&COD_ENQUETEITEM=" + COD_ENQUETEITEM, 'VotarEnquete',250,405,'no','no');
			return false;
		}//if
	}//for
	alert("É necessário selecionar um item da enquete.");
	return false;
}//VerificarResposta

function Resultado(codigo)
{
	popUp ("../Includes/Resultado.asp?COD_ENQUETE=" + codigo, 'Resultado',250,405,'no','no');
}//Resultado

function onFocus(obj)
{
	obj.style.background = "#fbf4c2";
	obj.style.border = "1px solid #bdbdbd";
}//onFocus

function onBlur(obj)
{
	obj.style.background = "#FFFFFF";
	obj.style.border = "1px solid #000000";
}//onBlur

function VerificaTecla()
{
	var tecla = window.event ? event.keyCode : event.which;
	if(tecla == 44)
	{
		alert("Para separar vários E-mails utilize o \";\" (ponto-e-vírgula)");
		event.keyCode = 59;
		return false;
	}
}//VerificaTecla

function fMudarCorOn(objeto)
{
   objeto.style.backgroundColor = "#fbf4c2";
}//fMudarCorOn

function fMudarCorOf(objeto)
{
   objeto.style.backgroundColor = "";
}//fMudarCorOf

/*
Fim das funções utilizadas pelo sistema
*/
function loadAjax(url,id,objForm,callBackFunction)
{
	var objAjax = new Ajax();
	var strParameters = mountParameters(objForm);

	if(objAjax)
	{
		objAjax.open("POST",url, true);
		objAjax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");
		objAjax.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
		objAjax.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
		objAjax.setRequestHeader("Pragma", "no-cache");

		objAjax.onreadystatechange = function()
		{
			if(objAjax.readyState == 1)
			{
				printById(id,"<img src='../Imagens/loading.gif' border='0' height='32' width='32'>&nbsp;<Span class='FontePadrao'>Aguarde...</span>");
			}
			if(objAjax.readyState == 2)
			{
				printById(id,"<img src='../Imagens/loading.gif' border='0' height='32' width='32'>&nbsp;<Span class='FontePadrao'>Carregando...</span>");
			}
			if(objAjax.readyState == 4)
			{
				if(objAjax.status == 200)
				{
					printById(id,objAjax.responseText);
					if(callBackFunction)
					{
						eval(callBackFunction);
					}
				}
				else
				{
					alert("Error: A página não pode ser carregada!");
					window.location='../includes/erro.asp';
				}
			}
		}
		objAjax.send(strParameters);
	}
}//loadAjax

/* It returns object XMLHTTP from navigator in use */

function Ajax()
{
	var ajax;
	try
	{
		ajax = new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(ex)
		{
			try
			{
				ajax = new XMLHttpRequest();
				ajax.overrideMimeType("text/xml");
			}
			catch(exc)
			{
				alert("Este browser não tem recursos para uso do XMLHTTP");
				ajax = null;
			}
		}
	}
	return ajax;
}//Ajax

/* It mounts in the form and submit to return page */

function mountParameters(objForm)
{
	var strReturn = "";
	if(objForm)
	{
		var y = objForm.length-1;
		for(x = 0; x < objForm.length; x++)
		{
			if(objForm[x].value && !objForm[x].disabled && objForm[x].style.display != "none" && objForm[x].type != "button" && objForm[x].type != "reset" && objForm[x].type != "submit"){
				if(strReturn){
					strReturn = strReturn + "&";
				}
				strReturn = strReturn + objForm[x].name + "=" + escape(objForm[x].value);
			}
		}
	}
	return strReturn;
}//mountParameters

/* It prints in the HTML of the appointed ID */
function printById(id,texto)
{
	document.getElementById(id).innerHTML = texto;
}

//funcao que recebe como parametro qualquer objeto do tipo Select e retorna o campo valor
//do item correspondente selecionado.
function getCodigoSelect(obj)
{
	return (obj.options[obj.selectedIndex].value);
}
//funcao que recebe como parametro qualquer objeto do tipo Select e retorna o campo text em maiusculo
//do item correspondente selecionado.
function getNomeSelect(obj)
{
	return(obj.options[obj.selectedIndex].text.toUpperCase());
}

function exibeDiv(nomeDiv)
{
	var div = document.getElementById(nomeDiv);
	if(div)
	{
		var div = document.getElementById(nomeDiv);
		var label = document.getElementById("Label");
		if(div.style.display == 'none')
		{
			div.style.display = '';
			label.value = "OCULTAR";
		}
		else
		{
			div.style.display = 'none';
			label.value = "PESQUISAR";
		}
	}
}//exibeDiv

function seeDay(day,Tipo)
{
	//showModal(sUrl, nomeJanela, iAltura, iLargura, aumentavel, bstatus)
	popUp('../Includes/Eventos.asp?Data=' + day + '&Tipo='+Tipo,'Evento',450,350, 'yes','no');
}//seeDay

function ComentarNoticia(codigo)
{
	alert('Para comentar esta informação é necessário estar logado');
	window.location = '../Includes/AutenticarUsuario.asp?' + codigo
}

function Buscar()
{
	var d = document.formbusca;
	if(d.PESQUISA.value == "")
	{
		alert("Por favor, informe o item a pesquisar");
		d.PESQUISA.focus();
		return false;
	}/*
	if((d.DATA_INICIO.value != "") && (d.DATA_FIM.value == ""))
	{
			alert("Por favor, informe a data final")
			d.DATA_FIM.focus();
			return false;
	}
	if((d.DATA_INICIO.value == "") && (d.DATA_FIM.value != ""))
	{
			alert("Por favor, informe a data incial")
			d.DATA_INICIO.focus();
			return false;
	}
	if((d.DATA_INICIO.value != "") && (d.DATA_FIM.value != ""))
	{
			if(!validarPeriodo(d.DATA_INICIO, d.DATA_FIM))
			{
				alert("A data inicial deve ser menor que a final")
				d.DATA_INICIO.select();
				return false;
			}
	}*/
	d.action = "../Includes/ListarBusca.asp"
	d.submit();
}//Buscar

function IndicarSite()
{
	var d = document.Indique;
	if(d.REMETENTE.value == '')
	{
		alert("Por favor, informe seu nome");
		d.REMETENTE.focus();
		return false;
	}
	if(d.EMAIL_REMETENTE.value == '')
	{
		alert("Por favor, informe seu email");
		d.EMAIL_REMETENTE.focus();
		return false;
	}
	else if(!validaEmail(d.EMAIL_REMETENTE))
	{
		alert("Email Inválido!");
		d.EMAIL_REMETENTE.focus();
		return false;
	}
	if(d.DESTINATARIO.value == '')
	{
		alert("Por favor, informe o nome do destinatário");
		d.DESTINATARIO.focus();
		return false;
	}
	if(d.EMAIL_DESTINATARIO.value == '')
	{
		alert("Por favor, informe o email do destinatário");
		d.EMAIL_DESTINATARIO.focus();
		return false;
	}
	else if(!validaEmail(d.EMAIL_DESTINATARIO))
	{
		alert("Email Inválido!");
		d.EMAIL_DESTINATARIO.focus();
		return false;
	}
	loadAjax('../Includes/IndicarSite.asp?REMETENTE=' + d.REMETENTE.value + '&EMAIL_REMETENTE=' + d.EMAIL_REMETENTE.value + '&DESTINATARIO=' + d.DESTINATARIO.value + '&EMAIL_DESTINATARIO=' + d.EMAIL_DESTINATARIO.value, 'Pesquisar', Indique, null);
}