// ONLOAD
	// uso -> arOnload.push('findimg');
	var arOnload = new Array();
	var wol = window.onload;
	window.onload = function(){
		if (wol) wol.call();
		if (arOnload) {for (var i in arOnload) {arOnload[i].call();}}
		delete arOnload;
	}
	arOnload.push(findimg);

// HOVER DE IMAGENS
	var sufixoImgOver = '_ov';
	var sufixoImgDown = '_down';
	var classToOver = 'roll';
	var classDown = 'down';

	function roll(o,state){
		var i,isnode,src,ftype,newsrc,nownode;
		// loop através de todos os childNodes
		for (i=0;i<o.childNodes.length;i++){
			nownode = o.childNodes[i];
			// se o nó é um elemento
			// e é uma IMG, muda a variável e sai do loop
			if(nownode.nodeType==1 && /img/i.test(nownode.nodeName)){
				isnode = i;
				break;
			}
		}  // verifica o src e faz o roll-over
		if (o.locked){
			//o.locked from submenu.js
			return;
		}
		src = o.childNodes[isnode].src;
		ftype = src.substring(src.lastIndexOf('.'), src.length);
		if (state == 'over' && o.state != state) {
			//set over
			newsrc = src.replace(ftype, sufixoImgOver+ftype);
		} else if(o.state == 'over') {
			//set up
			newsrc = src.replace(sufixoImgOver,'');
		}
		if (state == 'down' && o.state != state) {
			//set over
			newsrc = src.replace(ftype, sufixoImgDown+ftype);
		} else if(o.state == 'down') {
			//set up
			newsrc = src.replace(sufixoImgDown,'');
		}
		if (newsrc) {
			o.state = state;
			o.childNodes[isnode].src=newsrc;
		}
	}
	function findimg(){
		var imgs,i;  // Faz um loop através de todas as imagens
		//verificando se alguma delas contém a classe da var 'classToOver'
		imgs=document.getElementsByTagName('img');
		for(i=0;i<imgs.length;i++){
			if(eval('/'+classDown+'/').test(imgs[i].className)) {
				roll(imgs[i].parentNode,'over');
			}
			if(eval('/'+classToOver+'/').test(imgs[i].className)) {
				// adiciona a função roll ao elemento-pai da imagem
				imgs[i].parentNode.onmouseover=function(){roll(this,'over'); };
				imgs[i].parentNode.onmouseout=function(){roll(this,'up');};
				imgs[i].parentNode.onfocus=function(){roll(this,'over');};
				imgs[i].parentNode.onblur=function(){roll(this,'up');};
			}
		}
	}
/*
DOWN
<script>
	var mnprodDown = id('id DOM da imagem');
	roll(mnprodDown.parentNode,'over');
	mnprodDown.parentNode.locked = true;
</script>
*/

//uso -> id("id_dom").value
	function id(idDesc){return document.getElementById(idDesc);}

	var objDiv_temp = document.getElementById("ing_0");
	function navInauguracoes(direcao){
		if(objDiv_temp == null){
			objDiv_temp = document.getElementById("ing_0");
		}
		objDiv_temp.style.display = "none";	
		var ids_inauguracao = document.getElementById("ids_inauguracao").value;
		var arrIds = ids_inauguracao.split(",");
		if(direcao < 0) direcao = arrIds.length-1;
		else if(direcao == arrIds.length) direcao = 0;
		
		if(document.getElementById("ing_"+direcao) != null){
			document.getElementById("ing_"+direcao).style.display = "";
			objDiv_temp = document.getElementById("ing_"+direcao);
		}
	}
	
	function goInauguracao(id,data){
		location.href = "../institucional/calendario_inauguracoes.php?ing_id="+id+"&ing_data="+data;
	}
	
	function goEvento(id,data){
		location.href = "../institucional/calendario_eventos.php?evn_id="+id+"&evn_data="+data;
	}
	
	function validaData(objeto) {
		var msg = "Digite uma data correta.";
		var data = objeto.value;
		if (data == "") return true;
		if (data.length != 8 && data.length != 10) {
			alert(msg); 
			objeto.focus();
			return false;
		}
		dia = data.substring(0, 2);
		mes = data.substring(3, 5);
		
		if (data.length == 8)
			ano = data.substring(6, 8);
		else
			ano = data.substring(6, 10);
		
		objeto.value = dia + "/" + mes + "/" + ano;
		if ((retorno = isDate(objeto)) != false) {
			return true;
		} else {
			alert(msg);
			objeto.focus();
			return false;
		}	
	}
	
	
	
	//------------------------------------------------------------------------------------------------------------------------
	function isDate(objeto) {
		
	//	var ano = "<%'= year(date) %>";
	//	var hoje = "<%= year(date) & right("0"& month(date), 2) & right("0"& day(date), 2) %>";
		
		var data = objeto.value;
		var itens = data.split("/");
		if (itens[0] == "" || itens[1] == "" || itens[2] == "")
			return false;	
	
		if (isNaN(itens[0]) || isNaN(itens[1]) || isNaN(itens[2]))
			return false;
	
		/*if ((itens[2] + itens[1] + itens[0]) < strHoje)
			return "MENOR";//*/
	
		t0 = itens[0].length;	t1 = itens[1].length;	t2 = itens[2].length;
		if (t0 >= 3 || t1 >= 3 || t2 >= 5)
			return false;
	
		// valida se nunhum valor  menor que 0
		if (itens[0] <= 00 || itens[1] <= 00 || itens[2] <= 0000)
			return false;
	
		// valida o ano
		if (t2 <= 3) {
			if (itens[2] > 22)
				ano = "1900";
			else ano = "2000";
			aux = "";
			for (w = 0; w < 4 - t2; w++)
				aux += ano.charAt(w);
			y = 0;
			for (; w < 4; w++)
				aux += itens[2].charAt(y++);		
			itens[2] = aux;
		}
	
		// valida o mes
		if (itens[1] >= 13)
			return false;
	
		// captura o dia maximo para o mes digitado
		itens[1] = itens[1] * 1;
		if (itens[1] == 2) {
			if (itens[2]%400 == 0 || itens[2]%4 == 0 && itens[2]%100 != 0)
				vMax = 29;
			else	
				vMax = 28;
		} else
		if (itens[1] == 1 || itens[1] == 3 || itens[1] == 5 || itens[1] == 7 || itens[1] == 8 || itens[1] == 10 || itens[1] == 12)
			vMax = 31;
		else vMax = 30;
		itens[1] = "0"+ itens[1]; itens[1] = itens[1].charAt(itens[1].length - 2) + itens[1].charAt(itens[1].length - 1);
	
		// valida o dia do mes
		if (itens[0] > vMax)
			return false;
		itens[0] = "0"+ itens[0]; itens[0] = itens[0].charAt(itens[0].length - 2) + itens[0].charAt(itens[0].length - 1);
	
		objeto.value = itens[0] +"/"+ itens[1] +"/"+ itens[2];
		
		return true;
		
	}
	
	function Mascarar_CEP(evento, objeto){
		if(document.all){
			keypress = evento.keyCode;
		}else{
			keypress = evento.which;
		}
		campo = eval (objeto);
		caracteres = '1234567890';
		if ((caracteres.search(String.fromCharCode (keypress)) == -1) || (keypress == 36) || (keypress == 41) || (keypress == 46) || (keypress == 94) || (keypress == 124)) {
			evento.returnValue = false;
		}
		else {
			if (campo.value.length == 5 ) { 
				campo.value = campo.value;
				campo.value = campo.value + '-';
			}
		}
	}
	
	function Mascarar_Data(evento, objeto){
		if(document.all){
			keypress = evento.keyCode;
		}else{
			keypress = evento.which;
		}
		campo = eval (objeto);
		caracteres = '1234567890';
		if ((caracteres.search(String.fromCharCode (keypress)) == -1) || (keypress == 36) || (keypress == 41) || (keypress == 46) || (keypress == 94) || (keypress == 124)) {
			evento.returnValue = false;
		}
		else {
			if (campo.value.length == 2 ) { 
				campo.value = campo.value;
				campo.value = campo.value + '/';
			}
			if (campo.value.length == 5 ) { 
				campo.value = campo.value;
				campo.value = campo.value + '/';
			}
		}
	}
	
	function verificahora(hora) {
	  if ((aux = isTime(hora.value)) != false) { 
			if (aux == "vazio")
				return;
			hora.value = aux; 
		} else { 
			alert("Digite uma hora correta!"); 
			hora.focus();
		} 
	}
	
	function isTime(hora) {
	  if (hora == "")
		return "vazio"
	  var horac, e, d;
	  horac = "";
	  ido = hora.indexOf(":");
	  tam = hora.length;
	  if (ido >= 0) {
		e = hora.substr(0, ido);
		d = hora.substr(ido+1);
		if (isNaN(e) && e || isNaN(d) && d || ido == 0 || ido >= 3 || d.length >= 3)
		  return false;
		if (ido == 1)
		   horac = "0"+ e +":";
		else horac = e +":";
		horac += d;
	  } else {
		if (isNaN(hora) || tam == 0 || tam >= 5)
		  return false;
		if (tam == 1)
		  horac = "0"+ hora +":";
		else if (tam == 2)
		  horac = hora +":";
		else if (tam == 3)
		  horac = "0"+ hora.substr(0, 1) +":"+ hora.substr(1);
		else
		  horac = hora.substr(0, 2) +":"+ hora.substr(2);
	  } 
	  ido = horac.indexOf(":");
	  d = horac.substr(ido + 1);
	  while (d.length <= 1) {
		horac += "0";
		d = horac.substr(ido + 1);
	  }
	  if (horac.substr(0, 2) == 24)
		horac = "00:"+ horac.substr(3);
	  if (horac.substr(0, 2) >= 25 || horac.substr(3) >= 60)
		   return false;
	  else return horac;
	}
	
	
	//VALIDA QUANTIDADE DE CARACTERES DIGITADOS
	function countChars(num_chars, obj_mostrador, obj_texto, msg) {
		var campo = obj_texto.value;
		obj_mostrador.value=campo.length;
		if (campo.length>parseInt(num_chars)) {
			alert(msg+" "+num_chars+" caracteres.");
			obj_texto.value=campo.substring(0,parseInt(num_chars));
			obj_mostrador.value=num_chars;
			return false;
		}
		return true;
	}
	
	
	function TeclaInteiro(e){
		var key;
		var keychar;
		var reg;
		
		if(window.event) {
			// for IE, e.keyCode or window.event.keyCode can be used
			key = e.keyCode; 
		}
		else if(e.which) {
			// netscape or firefox
			key = e.which; 
		}
		else {
			// no event, so pass through
			return true;
		}
		if((key > 47 && key < 58) || (key == 8)) // numeros de 0 a 9 OU BACKSPACE
			return true;
		else {
			return false;
		}
	}

	
	function navMes(incremento){
		//var UCevento = document.getElementById("UCevento").value;
		var strData = document.getElementById("hdd_data_amostra").value;
		var dia = strData.substr( 0, 2 );
		var mes = strData.substr( 3, 2 );
		var ano = strData.substr( 6, 4 );
		
		mes = parseInt(mes,10) + incremento;
		
		if(mes < 1){
			mes = 12;
			ano = parseInt(ano) - 1;
		}else if(mes > 12){
			mes = 1;
			ano = parseInt(ano) + 1;
		}
		
		if(mes < 10)mes = "0" + mes;
		
		//alert(mes);
		
		document.getElementById("hdd_data_amostra").value = "01/" + mes + "/" + ano;//dia + 
		document.getElementById("hdd_tipo_amostra").value = "mes";
		document.getElementById("hdd_evento_data_amostra").value = "01/" + mes + "/" + ano;//dia + 
		document.getElementById("hdd_evento_tipo_amostra").value = "mes";
		document.getElementById("hdd_evento_id_amostra").value = "";
		//alert(document.getElementById("hdd_evento_data_amostra").value);
		document.form1.submit();
	}
	
	function navAno(incremento){
		//var UCevento = document.getElementById("UCevento").value;
		var strData = document.getElementById("hdd_data_amostra").value;
		var dia = strData.substr( 0, 2 );
		var mes = strData.substr( 3, 2 );
		var ano = strData.substr( 6, 4 );
		
		ano = parseInt(ano) + incremento;
			
		document.getElementById("hdd_data_amostra").value = "01/" + mes + "/" + ano;//dia + 
		document.getElementById("hdd_tipo_amostra").value = "ano";
		document.getElementById("hdd_evento_data_amostra").value = "01/" + mes + "/" + ano;//dia + 
		document.getElementById("hdd_evento_tipo_amostra").value = "ano";//
		document.getElementById("hdd_evento_id_amostra").value = "";
		document.form1.submit();
	}
	
	function navAnoCompleto(qual_ano){
	
		var strData = document.getElementById("hdd_data_amostra").value;
		var dia = strData.substr( 0, 2 );
		var mes = strData.substr( 3, 2 );
		var ano = strData.substr( 6, 4 );
	
		ano = qual_ano;//parseInt(ano) + incremento;
			
		document.getElementById("hdd_data_amostra").value = "01/" + mes + "/" + ano;//dia + 
		document.getElementById("hdd_tipo_amostra").value = "ano_completo";
		document.getElementById("hdd_evento_data_amostra").value = "01/" + mes + "/" + ano;//dia + 
		document.getElementById("hdd_evento_tipo_amostra").value = "ano_completo";//
		document.getElementById("hdd_evento_id_amostra").value = "";
		document.form1.submit();
	}
	
	function mostraDia(qual_dia){
		//var UCevento = document.getElementById("UCevento").value;
		var strData = document.getElementById("hdd_data_amostra").value;
		var dia = qual_dia;//strData.substr( 0, 2 );
		var mes = strData.substr( 3, 2 );
		var ano = strData.substr( 6, 4 );
		
		if(dia < 10)dia = "0" + dia;
	
		document.getElementById("hdd_data_amostra").value = dia + "/" + mes + "/" + ano;
		document.getElementById("hdd_tipo_amostra").value = "dia";
		document.getElementById("hdd_evento_data_amostra").value = dia + "/" + mes + "/" + ano;
		document.getElementById("hdd_evento_tipo_amostra").value = "dia";
		document.getElementById("hdd_evento_id_amostra").value = "";
		document.form1.submit();
	}

