function MM_showHideLayers() {
  var i,p,v,obj,args=MM_showHideLayers.arguments;if(document.getElementById){
   for (i=0; i<(args.length-2); i+=3){ obj=tmt_findObj(args[i]);v=args[i+2];
   v=(v=='show')?'visible':(v='hide')?'hidden':v;
   if(obj)obj.style.visibility=v;}} else{
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }}
}

function showTip(tip)
{
	eval("dyntip"+tip+"Layer.moveTo("+(xMouse+15)+","+(yMouse+10)+")")
	eval("dyntip"+tip+"Layer.show()")	
}
function esconde(camada)
{
	MM_showHideLayers(camada,'','hide');
}

function vaiPara(url)
{
	document.location.href = url;	
}

function FormataCGC(campo,tammax,teclapres) {
	var tecla = teclapres.keyCode;
	// vr = document.form[campo].value;
	vr = event.srcElement.value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	tam = vr.length;

	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){	tam = tam - 1 ; }
		
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){ 
	 		event.srcElement.value = vr ; }
	 	if ( (tam > 2) && (tam <= 6) ){
	 		event.srcElement.value = vr.substr( 0, tam - 2 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 7) && (tam <= 9) ){
	 		event.srcElement.value = vr.substr( 0, tam - 6 ) + '/' + vr.substr( tam - 6, 4 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 10) && (tam <= 12) ){
	 		event.srcElement.value = vr.substr( 0, tam - 9 ) + '.' + vr.substr( tam - 9, 3 ) + '/' + vr.substr( tam - 6, 4 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 13) && (tam <= 14) ){
	 		event.srcElement.value = vr.substr( 0, tam - 12 ) + '.' + vr.substr( tam - 12, 3 ) + '.' + vr.substr( tam - 9, 3 ) + '/' + vr.substr( tam - 6, 4 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 15) && (tam <= 17) ){
	 		event.srcElement.value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ;}
	}		
}
function FormataCEP(campo,tammax,teclapres) {
	var tecla = teclapres.keyCode;
	// vr = document.form[campo].value;
	vr = event.srcElement.value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	tam = vr.length;

	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){	tam = tam - 1 ; }
		
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 3 ){ 
	 		event.srcElement.value = vr ; }
	 	if ( (tam > 3) && (tam <= 8) ){
	 		event.srcElement.value = vr.substr( 0, tam - 3 ) + '-' + vr.substr( tam - 3, tam ) ; }
	}		
}
function FormataTelefone(campo,tammax,teclapres) {
	var tecla = teclapres.keyCode;
	// vr = document.form[campo].value;
	vr = event.srcElement.value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( " ", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( ")", "" );
	vr = vr.replace( "(", "" );
	tam = vr.length;

	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){	tam = tam - 1 ; }
		
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 4 ){ 
	 		event.srcElement.value = vr ; }
	 	if ( (tam > 4) && (tam <= 8) ){
	 		event.srcElement.value = vr.substr( 0, tam - 4 ) + '-' + vr.substr( tam - 4, tam ) ; }
	 	if ( (tam >= 9) && (tam < 10) ){
	 		event.srcElement.value = vr.substr( 0, tam - 8 ) + ') ' + vr.substr( tam - 8, 4 ) + '-' + vr.substr( tam - 4, tam ) ; }
	 	if ( (tam == 10)){
	 		event.srcElement.value = '(' + vr.substr( tam - 10, 3 ) + ') ' + vr.substr( tam - 7, 3 ) + '-' + vr.substr( tam - 4, tam ) ; }
	 	if ( (tam == 11)){
	 		event.srcElement.value = '(' + vr.substr( tam - 11, 3 ) + ') ' + vr.substr( tam - 8, 4 ) + '-' + vr.substr( tam - 4, tam ) ; }
		

	}		
}



function FormataData(Campo,teclapres)
{
	var tecla = teclapres.keyCode;
	//vr = document.form[Campo].value;
	vr = event.srcElement.value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;
	if (((tecla > 47) && (tecla < 58)) || tecla == 46)
	{
		if ( tecla != 9 && tecla != 8 )
		{
			if ( tam > 2 && tam < 5 )
			{
				//	document.form[Campo].value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
				event.srcElement.value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
			}
			if ( tam >= 5 && tam <= 10 )
			{
				//	document.form[Campo].value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ); }
				event.srcElement.value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 );
			}
			return true;
		}
	}
	else
	{
		alert("Digite somente números");
		event.srcElement.value = vr.substr( 0, tam - 1  )
		return false;
	}
}


function High(e)
{
	e.filters.alpha.opacity = 100;
}

function Low(e)
{
	e.filters.alpha.opacity = 60;
}
function abreJanela(endereco, nome)
{
   window.open(endereco, nome,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1');
}

// Impede Seleção
//document.onselectstart = function() { return false; }
    

function tmt_findObj(n){
	var x,t; if((n.indexOf("?"))>0&&parent.frames.length){t=n.split("?");
	x=eval("parent.frames['"+t[1]+"'].document.getElementById('"+t[0]+"')");
	}else{x=document.getElementById(n)}return x;
}
function abreFecha(nome,imagem)
{
  //WK Sistemas - Juarez Fernando de Souza - 15/08/2005
  objeto = tmt_findObj(nome)
  imagem = tmt_findObj(imagem)
  var ar = document.getElementById("masterdiv").getElementsByTagName("span");
  var im = document.getElementById("masterdiv").getElementsByTagName("img");

  for (var i=0; i<ar.length; i++)
  {
    if (ar[i].className=="options")
    ar[i].style.display = "none";
  }

  for (var i=0; i<im.length; i++)
  {
    im[i].src="../imagens/arrow.gif";
  }

  if (objeto.style.display=="")
  {
    objeto.style.display="none";
    imagem.src='../imagens/arrow.gif';
  }
  else
  {
    objeto.style.display="";
    imagem.src='../imagens/arrow_expanded.gif';
  }

}
function abreF4(endereco,janela)
{
  window.open(endereco, janela,'width=550, height=500, toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1');
}
function ativaGuia(nomeGuia)
{
	var objGuiaVigente = document.all.item(nomeGuia);		
	trocaEstilo(objGuiaVigente);
}

function trocaEstilo(nomeTitulo)
{	    
    var guiaVigente = 'guia_' + nomeTitulo.id;    
	var objGuiaVigente = document.all.item(guiaVigente);		
	
	var tabelas = document.getElementsByTagName("table");
	for (var x = 0; x < tabelas.length; x++)
	{			
		if (tabelas[x].id.substring(0,4) == "guia")
		{
			if (tabelas[x].id == objGuiaVigente.id)
			{
				tabelas[x].style.display = "";				
			}
			else
			{
				tabelas[x].style.display = "none";				
			}
		}
	}
	var objLinhaTitulo = document.all.item('tabelaTitulo');		
	var colunas = objLinhaTitulo.cells;
	for (var i = 0; i < colunas.length; i++)
	{
	    if (objLinhaTitulo.cells[i].id != 'nulo')
	    {
		   if (objLinhaTitulo.cells[i].id == nomeTitulo.id)
		   {					
		  	 objLinhaTitulo.cells[i].className = 'telaTituloON';
		   }
		   else
		   {
		     objLinhaTitulo.cells[i].className = 'telaTituloOFF';
		   }
	    }
	}
}

function submitForm()
{
	var btOK = document.all.item("btOK");	
	var btCancelar = document.all.item("btCancelar");
	btOK.style.display = "none";
	btCancelar.style.display = "none";
	document.forms[0].submit();	
}

function somenteNumeros(teclapres)
{
	var tecla = teclapres.keyCode;
	if (((tecla > 47) && (tecla < 58)) || tecla == 46)
		return true;
	else
		return false;
}

function RequisicaoAjax(url, callback) {
    if(window.XMLHttpRequest) {
        RequisicaoXML = new XMLHttpRequest();
    } else {
        RequisicaoXML = new ActiveXObject("Microsoft.XMLHTTP");
    }
    
    RequisicaoXML.onreadystatechange = callback;
    
    RequisicaoXML.open("GET", url, false);
    RequisicaoXML.send();
}

function getElementByTag(xml, tag) {
    try {
        ret = xml.getElementsByTagName(tag)[0].childNodes[0].nodeValue;
    } catch(e) {
        ret = "";
    }
    return ret;
}