function mostrar(obj, abaprincipal, numaba) {
    var primeiro = document.getElementById(abaprincipal + '1');
    var segundo = document.getElementById(abaprincipal + '2');
    var terceiro = document.getElementById(abaprincipal + '3');
    if (primeiro) primeiro.style.display = 'none';
    if (segundo) segundo.style.display = 'none';
    if (terceiro) terceiro.style.display = 'none';

    var aba = document.getElementById(abaprincipal+numaba);
    if (aba) aba.style.display = 'block';

    var locli = document.getElementById(abaprincipal);
    var lis = locli.getElementsByTagName('li');

    for (var i=0; i<lis.length; i++)
    {
        lis[i].setAttribute('class', '');
        lis[i].className = '';
    }

    lis[numaba-1].setAttribute('class', 'selecionado');
    lis[numaba-1].className = 'selecionado';
    document.getElementById(abaprincipal).innerHTML = locli.innerHTML;
}


// Início Validação de Formulário

function validacao(formulario){

for(i=0;i<=formulario.length-1;i++){
	if ((formulario[i].type=="textarea")||(formulario[i].type=="file")||(formulario[i].type=="hidden")||(formulario[i].type=="text")||(formulario[i].type=="password")){
		if ((formulario[i].wmsg!="")&&(formulario[i].wmsg!=undefined)){
			if (formulario[i].email=="sim"){
				if((formulario[i].value=="")||(formulario[i].value.indexOf('@')==-1)||(formulario[i].value.indexOf('.')==-1)){
					alert(formulario[i].wmsg);
					try{
						formulario[i].focus();
					}
					catch(e){
						}				
				    return false
				}	
			}else{
				if(formulario[i].value==""){
					alert(formulario[i].wmsg);
					try{
						formulario[i].focus();
					}
					catch(e){

						}
				
					return false
				}
			}
		}
	}	
}
}

// Fim Validação de Formulário


function criaMascara(_RefObjeto, _Modelo)
{
	var valorAtual = _RefObjeto.value;        
	var valorNumerico = '';
	var nIndexModelo = 0;
	var nIndexString = 0;
	var valorFinal = '';
	var adicionarValor = true;
    
     
	// limpa a string valor atual para verificar 
	// se todos os caracteres são números
	for (i=0;i<_Modelo.length;i++){
		if (_Modelo.substr(i,1) != '#'){
			valorAtual = valorAtual.replace(_Modelo.substr(i,1),'');
  		}
 	}
      
 	// verifica se todos os caracteres são números
 	for (i=0;i<valorAtual.length;i++){
  		if (!isNaN(parseFloat(valorAtual.substr(i,1)))){
			valorNumerico = valorNumerico + valorAtual.substr(i,1);
  		}
 	}
      
 	// aplica a máscara ao campo informado usando
 	// o modelo de máscara informado no script
 	for (i=0;i<_Modelo.length;i++){
  		if (_Modelo.substr(i,1) == '#'){
    			if (valorNumerico.substr(nIndexModelo,1) != ''){
				valorFinal = valorFinal + valorNumerico.substr(nIndexModelo,1);
				nIndexModelo++;nIndexString++;
    			} 
    			else {
        			adicionarValor = false;
    			}
  		}
  		else {
     			if (adicionarValor && valorNumerico.substr(nIndexModelo,1) != ''){
  				valorFinal = valorFinal + _Modelo.substr(nIndexString,1)
				nIndexString++;
     			}
  		}
 	}
    
 	_RefObjeto.value = valorFinal 
}


function soNums(e,args)
{        
//  onKeyPress ="return (soNums(event,'(/){,}.'));"
	var valid_chars    = new Array();
   	if (document.all){
		var evt = event.keyCode;
	}
	else{
		var evt = e.charCode;
	}
   	var chr= String.fromCharCode(evt);
   	
	if (evt <20 || (evt >47 && evt<58) || (args.indexOf(chr)>-1 ) ){return true;}
   	return false;
}


// Início Pop-up com e sem scrollbar
function abrir(url, width, height)
{
	var lado = (screen.width - width) / 2;
	var topo = (screen.height - height) / 2;
	window.open(url,'_blank','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,menubar=no,top='+topo+',left='+lado+',width=' + width + ',height=' + height)
}

function abrirnb(url, width, height)
{
	var lado = (screen.width - width) / 2;
	var topo = (screen.height - height) / 2;
	window.open(url,'_blank','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,menubar=no,top='+topo+',left='+lado+',width=' + width + ',height=' + height)
}
// Fim Pop-up com e sem scrollbar


// Início funções by Hargon

function alteraImg(resultado,imagem){
	document.getElementById(resultado).src = imagem;
}

var mcomboGeral = 0;
function mostrarCombo(camada){
	if (mcomboGeral == 0){
		new Effect.BlindDown(camada);
		mcomboGeral = 1;
	}else{
		new Effect.BlindUp(camada);
		mcomboGeral = 0;
	}
}

function escolheCombo(formulario,campo,codigo,nome){
	new Effect.BlindUp('div_cd'+campo);
	mcomboGeral = 0;
	document.forms[formulario].elements['txtcd'+campo].value = codigo;
	document.forms[formulario].elements['optcd'+campo].value = nome;
}

function ContaCaracteres(tamanho,form,campo){
   	var campo = document.forms[form].elements[campo];
	intCaracteres = tamanho - campo.value.length;
	if (intCaracteres > 0){
	      	return true;
	}
	else {
		campo.value = campo.value.substr(0,tamanho);
      		return false;
   	}
}

// Fim funções by Hargon



// Função de mascara de moeda
function Moeda(fld, e) 
{
	if (window.event.keyCode >= 48 && window.event.keyCode <= 57)
	{ 
		var milSep = "."; 
		var decSep = ","; 
		var sep = 0; 
		var key = ''; 
		var i = j = 0; 
		var len = len2 = 0; 
		var strCheck = '0123456789'; 
		var aux = aux2 = ''; 
		var whichCode = (window.Event) ? e.which : e.keyCode; 

		if (whichCode == 13) 
			return true; 

		key = String.fromCharCode(whichCode); 

		if (strCheck.indexOf(key) == -1) 
			return false; 

		len = fld.value.length; 

		for (i = 0; i < len; i++) 
		if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) 
		break; 

		aux = ''; 

		for (; i < len; i++) 
			if (strCheck.indexOf(fld.value.charAt(i))!=-1) 
				aux += fld.value.charAt(i); 

		aux += key; 
		len = aux.length; 

		if (len == 0) 
			fld.value = ''; 

		if (len == 1) 
			fld.value = '0'+ decSep + '0' + aux; 

		if (len == 2) 
			fld.value = '0'+ decSep + aux; 

		if (len > 2){ 
			aux2 = ''; 

		for (j = 0, i = len - 3; i >= 0; i--){ 
			if (j == 3){ 
				aux2 += milSep; 
				j = 0; 
			} 
			aux2 += aux.charAt(i); 
			j++; 
		} 

		fld.value = ''; 
		len2 = aux2.length; 

		for (i = len2 - 1; i >= 0; i--) 
			fld.value += aux2.charAt(i); 
		fld.value += decSep + aux.substr(len - 2, len); 
	} 

	return false; 

	} 
	else 
	{
		if (e.keyCod != 8) { // backspace
			e.keyCode = 0;
		}
	}
}


// Função de mascara e bloqueio de teclas não numéricas
function formata(valor)
{
	if (window.event.keyCode >= 48 && window.event.keyCode <= 57)
	{ 
		if (document.getElementById(valor).value.length == 2 || document.getElementById(valor).value.length == 5 ){
			document.getElementById(valor).value += "/";
		}	
	}
	else {
		if (window.event.keyCod != 8) { // backspace
			window.event.keyCode = 0;
			alert("Utilize apenas números!");
		}
	}
}


function gerarswf(arquivo,largura,altura,id,variaveis){
    document.writeln('    <object id="globalnav-object" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + largura + '" height="' + altura + '" id="' + id + '" name="' + id + '">');
    document.writeln('        <param name="movie" value="' + arquivo + '" />');
    document.writeln('        <param name="FlashVars" value="loc=en_US&htmlApp=false&gatewayURL=gwurl&' +variaveis+ '" />');
    document.writeln('        <param name="menu" value="true" />');
    document.writeln('        <param name="quality" value="high" />');
    document.writeln('        <param name="salign" value="tl" />');
    document.writeln('        <param name="scale" value="noscale" />');
    document.writeln('        <param name="wmode" value="transparent" />');
    document.writeln('        <embed id="globalnav-embed" src="' + arquivo + '" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" wmode="transparent" flashvars="loc=en_US&htmlApp=false&gatewayURL=gwurl&' +variaveis+ '" bgcolor="#ffffff" menu="false" quality="high" salign="tl" scale="noscale" id="' + id + '" width="' + largura + '" height="' + altura + '"></embed>');
    document.writeln('    </object>');
}
