<!--
// funções de Javascript




//AJAX_________________________________________

function cria_ajax()
	{
	var xmlhttp;
	try
		{
		xmlhttp = new XMLHttpRequest();
		}
	catch(ee)
		{
		try
			{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			}
		catch(e)
			{
			try
				{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				}
			catch(E)
				{
				xmlhttp = false;
				}
			}
		}
	return xmlhttp;
	}




//_____________________________________________


function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function






function checar(formulario)
{
for(var i=0;i<formulario.elements.length;i++)
     {
	 
	 var campo=formulario.elements[i];
	 
	 if(campo.type=="text" || campo.type=="hidden" || campo.type=="select" || campo.type=="select-one" || campo.type=="password" || campo.type=="file" || campo.type=="textarea" || campo.type=="radio")
	      {
	 	  var obriga=campo.getAttribute('obrigatorio');
	 	  var nomecampoatual=campo.getAttribute('nomecampo');
		  
		  if(campo.type=="radio" && obriga==1)
		       {
			   var meuradio=document.getElementsByName(campo.getAttribute('name'));
			   var preencheu = false;
			   for (var k=0; k<meuradio.length; k++) 
			             {
						 //alert(k + "- teste: " + meuradio[k].value + " está " + meuradio[k].checked);
						 
						 if (meuradio[k].checked)
						           {
								   preencheu = true;
								   }
  						 }
			  if (preencheu==false)
			            {
						alert("Ao menos uma das opções do campo '" + nomecampoatual + "' deve ser selecionada.");
			   			return false;
						break;
						}
			   }
		  else if(obriga==1 && trim(campo.value)=="")
		       {
			   alert("O campo '" + nomecampoatual + "' não pode ficar vazio.");
			   campo.focus();
			   return false;
			   break;
			   }
		  }
	 }
return true;
}



function limita_texto(field, countfield, maxlimit) 
     {
	 if (field.value.length > maxlimit) // if too long...trim it!
	      {
		  field.value = field.value.substring(0, maxlimit);
		  }
     else 
	      {
		  countfield.innerHTML = maxlimit - field.value.length;
		  }
     }




function confirma(destino, mensagem)
	{
	if(window.confirm(mensagem))
		{
		window.location.href=destino;
		}
	}






//_______FOLHINHA_________________

function fecha_folhinha()
     {
	 var removame=document.getElementById("divfolhinha");
	 if(removame!=null)
	      {
	 	  removame.parentNode.removeChild(removame);
		  }
	 }




function abre_folhinha(id_clicado, id_formulario, id_campo_dia, id_campo_mes, id_campo_ano)
     {
	 var campo_dia=document.getElementById(id_campo_dia);
	 var campo_mes=document.getElementById(id_campo_mes);
	 var campo_ano=document.getElementById(id_campo_ano);

	 
	 var dia_sel=campo_dia.value;
	 var mes_sel=campo_mes.options[campo_mes.selectedIndex].value;
	 var ano_sel=campo_ano.value;
	 
	 
	 //removendo outra instância do objeto que exista
	 var divfolhinha=document.getElementById("divfolhinha");

	 if (divfolhinha!=null)
	      {
		  if(id_clicado==divfolhinha.origem)
		       {
			   //alert("já existe e é o mesmo: " + id_clicado + " e " + divfolhinha.origem);
			   var pode_criar=false;
			   }
		  else
		       {
			   //alert("já existe mas não é o mesmo: " + id_clicado + " e " + divfolhinha.origem);
			   var pode_criar=true;
			   }
          fecha_folhinha();
		  }
     else
	      {
		  var pode_criar=true;
		  }



     if(pode_criar)
	      {
	 	  var novodiv=document.createElement("div");
	 	  novodiv.id="divfolhinha";
	 	  document.body.appendChild(novodiv);
		  //divfolhinha==document.getElementById("divfolhinha");
	 


		// Get the scroll offset of the window.
		var yScroll;
		if (self.pageYOffset) // all except Explorer
		{
			yScroll = self.pageYOffset;
		}
		else if (document.documentElement && document.documentElement.scrollTop) // Explorer 6 Strict
		{
			yScroll = document.documentElement.scrollTop;
		}
		else if (document.body) // all other Explorers
		{
			yScroll = document.body.scrollTop;
		}


		  //var imagemid=window.event.srcElement.id;
		  var imagemclicada=document.getElementById(id_clicado);
		  var imagemy=findPosY(imagemclicada);
		  var imagemx=findPosX(imagemclicada);
		  //alert("imagem clicada: " + imagemid);

	 	  var largura_div=150;
	 	  var altura_div=135;
	 
	 	  var coordenadax=imagemx-0-largura_div;
	 	  var coordenaday=imagemy+20;
		  

		  //alert("ponto: " + pontoy + ", coordy: " + coordenaday);
		  //alert("ponto: " + pontox + ", coordx: " + coordenadax);
	 
	 	  novodiv.style.position="absolute";
	 	  novodiv.style.display="block";
	 	  novodiv.style.left=coordenadax + "px";
	 	  novodiv.style.top=coordenaday + "px";
	 	  novodiv.style.width=largura_div + "px";
	 	  novodiv.style.height=altura_div + "px";
	 	  novodiv.style.border="1px solid #666";
	 	  novodiv.style.background="#eee";
	 	  novodiv.origem=id_clicado;
	 	  novodiv.innerHTML='<iframe src="../ferramentas/folhinha.php?dia=' + dia_sel + '&mes=' + mes_sel + '&ano=' + ano_sel + '&id_campo_dia=' + id_campo_dia + '&id_campo_mes=' + id_campo_mes + '&id_campo_ano=' + id_campo_ano + '" frameborder="0" scrolling="no" width="150" height="135"></iframe>';
		  }
	 
	 
	 
	 //alert("selecionado atualmente: " + forms[0].dia.value + "/" forms[0].mes.value + "/" + forms[0].ano.value);
	 } 





function hide_and_seek(id_item)
     {
	 var elemento=document.getElementById(id_item);

	 if(elemento.style.display=='none')
	      {
	 	  elemento.style.display='block';
		  }
	 else
	      {
	 	  elemento.style.display='none';
		  }
     }
	 


function checkAll(theForm, cName) {
for (i=0,n=theForm.elements.length;i<n;i++)
if (theForm.elements[i].className.indexOf(cName) !=-1)
if (theForm.elements[i].checked == true) {
theForm.elements[i].checked = false;
} else {
theForm.elements[i].checked = true;
}
}



function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}



function alterna_mais()
	{
	var mais=document.getElementById('botao_mais');
	var escolha=document.getElementById('escolha');
	
	if(mais.style.display=='none')
		{
		mais.style.display='block';
		escolha.style.display='none';
		}
	}




function exclui_imagem(id_pessoa)
	{
	//alert(id_evento);
	var quadro=document.getElementById('imagem_atual');
	quadro.innerHTML="Aguarde...";

	var xmlhttp=cria_ajax();
	xmlhttp.open("GET", "../ferramentas/ajax_exclui_imagem.php?id_pessoa=" + id_pessoa, true);
	xmlhttp.onreadystatechange=function()
		{
		if(xmlhttp.readyState==4)
			{
			var texto=xmlhttp.responseText;
			texto=texto.replace(/\+/g," ");
			texto=unescape(texto);
			
			quadro.innerHTML=texto;
			}
		}
	xmlhttp.send(null);
	delete xmlhttp;
	}


function exclui_arquivo(alvo, tabela, campo, id)
	{
	//alert(alvo + ", " + tabela + ", " + campo + ", " + id);

	var quadro=document.getElementById(alvo);
	quadro.innerHTML="Aguarde...";

	var xmlhttp=cria_ajax();
	xmlhttp.open("GET", "../ferramentas/ajax_exclui_arquivo.php?tabela=" + tabela + "&campo=" + campo + "&id=" + id, true);
	xmlhttp.onreadystatechange=function()
		{
		if(xmlhttp.readyState==4)
			{
			var texto=xmlhttp.responseText;
			texto=texto.replace(/\+/g," ");
			texto=unescape(texto);
			
			quadro.innerHTML=texto;
			}
		}
	xmlhttp.send(null);
	delete xmlhttp;
	}



function exclui_arquivo_com_nome(alvo, tabela, campo, campo_nome, id)
	{
	//alert(alvo + ", " + tabela + ", " + campo + ", " + id);

	var quadro=document.getElementById(alvo);
	quadro.innerHTML="Aguarde...";

	var xmlhttp=cria_ajax();
	xmlhttp.open("GET", "../ferramentas/ajax_exclui_arquivo_com_nome.php?tabela=" + tabela + "&campo=" + campo + "&campo_nome=" + campo_nome + "&id=" + id, true);
	xmlhttp.onreadystatechange=function()
		{
		if(xmlhttp.readyState==4)
			{
			var texto=xmlhttp.responseText;
			texto=texto.replace(/\+/g," ");
			texto=unescape(texto);
			
			quadro.innerHTML=texto;
			}
		}
	xmlhttp.send(null);
	delete xmlhttp;
	}




function foca(id_campo, atraso)
	{
	campo=document.getElementById(id_campo);
	setTimeout("campo.focus()",atraso);
	}

function seleciona(id_campo, atraso)
	{
	campo=document.getElementById(id_campo);
	setTimeout("campo.select()",atraso);
	}




function init()
	{
	//inicializa todas as ações necessárias no load da página
	
	DynarchMenu.setup('menusup', {electric: true});
	}


-->