/*------------------------------------------------------*/
/*	VARIAVEIS GLOBAIS DO SISTEMA DE VALIDACAO DE DADOS	*/
/*------------------------------------------------------*/
var _perm = new Array();
var _mess = new Array();
var _conf = new Array();
var _gMsg = "";
var _isIE = false;
var _isNav = false;
var browser = "";
/*------------------------------------------*/
/*	IDENTIFICACAO DO NAVEGADOR DO USUARIO	*/
/*------------------------------------------*/
if (navigator.appName.indexOf("Netscape") != -1) _isNav = true;
if (navigator.appName.indexOf("Microsoft") != -1 ) _isIE = true;

indVisivel = false;

/*// Descobre o browser
if (browser == "Microsoft Internet Explorer") { 
  _isIE = true;
}
else {
  _isNav = true;
} */

// Monitora teclas
  if (_isIE) { 

    function alert_keycode(){

      // Se for CTRL + SHIFT + H mostra ou esconde o assistente
      if (event.keyCode == 8) {
        if (indVisivel == false) {
          Assistente.style.visibility='';
          indVisivel = true;
        }
        else{
          Assistente.style.visibility='hidden';
          indVisivel = false;
        }
      }

    }

    document.onkeypress=alert_keycode;
  }
  else {

    document.captureEvents(Event.KEYPRESS)

    function processkey(e){

      // Se for CTRL + SHIFT + H mostra ou esconde o assistente
      if (e.which == 8) {
	      if (indVisivel == false) {
          document.Assistente.visibility='show';
          indVisivel = true;
        }
        else{
          document.Assistente.visibility='hidden';     
          indVisivel = false;
        }
      }

    }

    document.onkeypress=processkey;
  }

// Funcao para mudar o texto do assitente

function mudaAssistente(strTexto) {

  if (strTexto == null) {
    strTexto = "Estou aqui para ajud&aacute;-lo durante sua navega&ccedil;&atilde;o.";
  }

  if (_isIE) {
    TextoAssistente.innerHTML = '<font face="Verdana, Arial, Helvetica, sans-serif" size="1">'+strTexto+'</font>';
  }
  else {
    document.Assistente.document.TextoAssistente.document.write('<font face="Verdana, Arial, Helvetica, sans-serif" size="1">'+strTexto+'</font>');
    document.Assistente.document.TextoAssistente.document.close();
  }

}



/***************************/
/* Funções criadas por mim */
/***************************/


//-> Funções de data
function mDate(){
	this.strDay = "Favor preencha corretamente o valor do campo Dia."
	this.strMonth = "Favor preencha corretamente o valor do campo Mês."
	this.strYear = "Favor preencha corretamente o valor do campo Ano."
	this.error = false;
	this.lowerYear = 1899;
	this.day;
	this.month;
	this.year;
	this.objDay;
	this.objMonth;
	this.objYear;
	this.obr = false;
	this.sep = "/";
	this.printDate = printDMY;
	this.printDMY = printDMY;
	this.printMDY = printMDY;
	this.isYear = isYear;
	this.isMonth = isMonth;
	this.isDay = isDay;
	this.isDate = isDate;
	this.isNull = isNull;
	this.setDay = setDay;
	this.setMonth = setMonth;
	this.setYear = setYear;
	this.setDateDMY = setDateDMY;
	this.vetComp = new Array(2,4,1,4,3,4,3,4,4,3,4,3,4);
}

function printYMD(){
	var ret = "";
	with(this){
		if (isNull() && !this.obr) return ret;
		if (isDate())	ret = year+sep+month+sep+day;
	}
	return ret;
}

function printDMY(){
	var ret = "";
	with(this){
		if (isNull() && !this.obr) return ret;
		if (isDate())	ret = day+sep+month+sep+year;
	}
	return ret;
}

function printMDY(){
	var ret = "";
	with(this){
		if (isNull() && !this.obr) return ret;
		if (isDate())	ret = month+sep+day+sep+year;
	}
	return ret;
}

function isNull(){
	if (this.day == "" && this.month == "" && this.year == "") return true;
	return false;
}

function isYear(){
	if (this.year > this.lowerYear) return true;
	return false;
}

function isMonth(){
	if (this.month > 0 && this.month < 13) return true;
	return false;
}

function isDay(){
	var upperDays;
	if (Number(this.year)%Number(4) == 0 && Number(this.month) == 2){
		upperDays = Number(28)+Number(this.vetComp[0]);
	}else{
		upperDays = Number(28)+Number(this.vetComp[Number(this.month)]);
	}
	if (this.day > 0 && this.day < upperDays) return true;
	return false;
}

function isDate(){
	with(this){
		if (!isDay()){
			objDay.focus();
			alert(strDay);
			objDay.value = "";
			error = true;
			objDay.focus();
			return false;
		}
		if (!isMonth()){
			objMonth.focus();
			alert(strMonth);
			objMonth.value = "";
			error = true;
			objMonth.focus();
			return false;
		}
		if (!isYear() ){
			objYear.focus();
			alert(strYear);
			objYear.value = "";
			error = true;
			objYear.focus();
			return false;
		}
	}
	return true;
}

function setDay(objText){
	this.day = objText.value;
	this.objDay = objText;
	return;
}

function setMonth(objText){
	this.month = objText.value;
	this.objMonth = objText;
	return;
}

function setYear(objText){
	this.year = objText.value;
	this.objYear = objText;
	return;
}

function setDateDMY(objD, objM, objY){
    this.day = objD.value;
	this.objDay = objD;
	this.month = objM.value;
	this.objMonth = objM;
	this.year = objY.value;
	this.objYear = objY;
	return;
}


//-> Funções de data
	function cDate(){
		this.day;
		this.month;
		this.year;
		this.delimiter = "/";
		this.toYMD = toYMD;
		this.toDMY = toDMY;

	}

	function toYMD(){
		var D,M,Y,S;
		D = this.day;
		M = this.month;
		Y = this.year;
		S = this.delimiter;
		return (Y+S+M+S+D);
	}

	function toDMY(){
		var D,M,Y,S;
		D = this.day;
		M = this.month;
		Y = this.year;
		S = this.delimiter;
		return (D+S+M+S+Y);
	}



//-> Funções de data-hora
	function cDateHour(){
		this.day;
		this.month;
		this.year;
		this.hour;
		this.minutes;		
		this.delimiter = "/";
		this.delimiter1 = " ";
		this.delimiterHour = ":"		
		this.toYMDH = toYMDH;
		this.toDMYH = toDMYH;

	}

	function toYMDH(){
		var D,M,Y,H,M1,S,B,B1;
		D = this.day;
		M = this.month;
		Y = this.year;
		H = this.hour;
		H1 = this.minutes;
		B = this.delimiter;
		S = this.delimiter1;
		B1 = this.delimiterHour;
		return (Y+B+M+B+D+S+H);
	}

	function toDMYH(){
		var D,M,Y,H,M1,S,B,B1;
		D = this.day;
		M = this.month;
		Y = this.year;
		H = this.hour;
		H1 = this.minutes;
		B = this.delimiter;
		S = this.delimiter1;
    	B1 = this.delimiterHour;
		return (D+B+M+B+Y+S+H+B1+H1);
	}


//-> Função de Hora
	function cHour(){
		this.hour;
		this.minutes;
		this.delimiter = ":";
		this.toH = toH;
	}

	function toH(){
		var H,M,B;
		M = this.minutes;
		H = this.hour;
		B = this.delimiter;
		return (H+B+M);
	}

	
//-> Funções de string

	function estarVazio(objText){
	 	return !objText.value.match(/[a-zA-Z0-9]/g);
	}

	function serNumero(objText){
	 	return objText.value.match(/[0-9]/g);
	}
//-> Funções de conteudo

function verInformacao(lcodArea, lcodItem, lindTipo)
{
	with(document.form)
	{
		method = "get";
		codArea.value = lcodArea;
		codItem.value = lcodItem;
		indTipo.value = lindTipo;
		if(codArea.value == '256')
		action = "modelo_leitura_noticias.php";
		if(codArea.value == '259')
		action = "dicas.php";
		
		if ( (lcodArea == 0 || lcodArea == -1) && (lcodItem == 0) ) 
		{
			location.href = 'inicial.php';
		}
		else
		{
			submit();
		}
	}
	return;
}
    

//-> Funções de conteudo

    function alterarMural(lcodArea){
      with(document.formConteudo){
        action='alterar_mural.php';
        codArea.value = lcodArea;
        submit();
      }
      return;
    }    
    
    function inserirItem(lcodArea){
      with(document.formConteudo){
        action='administracao/conteudo/principal.php';
        codArea.value = lcodArea;
        submit();
      }
      return;
    }        

//-> Função usada na gerencia das aplicações de conteudo

	function selecionarArea(strPaginaDestino, codAreaArg){
		with(document.form){
			codArea.value = codAreaArg;
			action = strPaginaDestino;
			submit();
		}
		return;
	}

function saltarCampo(campo_atual, event, tamanho_maximo, campo_proximo){
    var tecla;
    var vr;

    if (_isNav)
        tecla = event.which;
    else
        tecla = event.keyCode;

    vr = campo_atual.value;
    tam = vr.length;

    if (tam >= tamanho_maximo && tecla >= 48)
        campo_proximo.focus();
}

	function retirarEspeciais(strEntrada){
		return strEntrada.replace(/\||;|'/g,"");
	}


 	function filtrarMaiusculas(evt){
	  if (_isNav)
	    tecla = evt.which;
		else
	    tecla = evt.keyCode;
		if (tecla < 65){tecla = 0;}
		if (tecla > 123){tecla = 0;}
		if (tecla > 89 && tecla < 97){tecla = 0;}
		if (tecla > 96 && tecla < 123){tecla -= 32;}
	  if (_isNav)
	    evt.which = tecla;
		else
	    evt.keyCode = tecla;
		return;
	}

 	function selecionarList(objList, numValor){
		var i;
		for(i=0; i < objList.length; i++){
			if(objList.options[i].value == numValor){
				objList.selectedIndex = i;
				return;
			}
		}
		return;
	}

 	function filtrarNumeros(evt)
	{
		if (_isNav)
			tecla = evt.which;
		else
			tecla = evt.keyCode;
		if (tecla < 48 || tecla > 57)
		{
			tecla = 0;
		}
		if (_isNav)
			evt.which = tecla;
		else
			evt.keyCode = tecla;
		return;
	}

   	function baixarArquivo(strIn)
	{
		with(document.formConteudo)
		{
			strNomeArquivo.value = strIn;
			action = "download.php"
			submit();
		}
		return;
	}
	
	function Item(name, subItens){
    	this.name = name;
    	this.subItens = subItens;
    }
    
    function subItem(value, name){
    	this.name = name;
    	this.value = value;
	}

	function trocarCombos2(strForm ,strListPai, strListFilho, arrDados)
    {
    	var i;
    	objListPai = eval("document."+ strForm +"."+ strListPai);
    	objListFilho = eval("document."+ strForm +"."+ strListFilho);
    	objListFilho.length = 0;
    	for(i = 0; i < arrDados[objListPai.value].subItens.length; i++){
    		tmpOption = new Option ();
    		tmpOption.text = arrDados[objListPai.value].subItens[i].name;
    		tmpOption.value = arrDados[objListPai.value].subItens[i].value;
    		objListFilho.options[i] = tmpOption;
    	}
    	objListFilho.selectedIndex = 0;
    	return;
    }
	
	function trocarCombos(strForm ,strListPai, strListFilho, arrDados)
    {
    	var i;
    	objListPai = eval("document."+ strForm +"."+ strListPai);
    	objListFilho = eval("document."+ strForm +"."+ strListFilho);
    	objListFilho.length = 0;
		//alert (arrDados.length);
    	for(i = 0; i < arrDados[objListPai.value].length; i++){
    		tmpOption = new Option ();
    		tmpOption.text = arrDados[objListPai.value][i].name;
    		tmpOption.value = arrDados[objListPai.value][i].value;
    		objListFilho.options[i] = tmpOption;
    	}
    	objListFilho.selectedIndex = 0;
    	return;
    }
    

function filtrarNumero(evt)
{
	var key;
	if (_isNav || _isIE){
		key = (_isNav)? evt.which: evt.keyCode;
		return (key > 47 && key < 58) || key == 8 || key == 0 ? true: false;
	}
	return true;
}

function validaCpf(objeto)
{
	var i;

	s = objeto.value;

	if ( s != "" ){
		var c = s.substr(0,9);
		var dv = s.substr(9,2);
		var d1 = 0;
	 
		for (i = 0; i < 9; i++)
		{
			d1 += c.charAt(i)*(10-i);
		}
	 
		if (d1 == 0)
		{
			return false;
		}
	 
		d1 = 11 - (d1 % 11);
	 
		if (d1 > 9) d1 = 0;
	 
		if (dv.charAt(0) != d1)
		{
			return false;
		}
	
		d1 *= 2;
	 
		for (i = 0; i < 9; i++) 
		{
			d1 += c.charAt(i)*(11-i);
		}
	 
		d1 = 11 - (d1 % 11);
	 
		if (d1 > 9) d1 = 0;
	 
		if (dv.charAt(1) != d1)
		{
			return false;
		}

		return true;
	}
	else
	{
		return false;
	}
}

function filtrarReal(evt)
{
	var key;
	if (_isNav || _isIE){
		key = (_isNav) ? evt.which: evt.keyCode;
		return (key > 47 && key < 58) || key == 8 || key == 0 || key == 44 ? true: false;
	}
	return true;
}

function MM_reloadPage(init) 
{  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

/**
* Oculta ou exibe um item atraves de um checkbox
* @input: id_do_campo, id_do_check
**/
function ocultarItem(idCampo, idCheck)
{
    objCheck = document.form.elements[idCheck];
    objCampo = document.form.elements[idCampo];

    objCheck.blur(); //retirando o foco
    if( objCheck.checked == true )
    {
        objCampo.style.display = '';
    }
    else
    {
        objCampo.style.display = 'none';
    }
    
    objCheck.blur();

}