

//===============================================================================================================================
// seleciona aba menu
//
function selectAba(eA,id){
	eRoot = $div('aba-root');
	forIn(eRoot.getElementsByTagName('div'),function(e){
		if(contain(e.className,'aba-on'))
			e.className = 'aba-off';
		if(e.className=='aba')
			e.style.display = 'none';
	});
	$div(id).style.display = 'block';
	eA.className = 'aba-on';
}

//===============================================================================================================================
// numero e virgula
// 
function sonumero_virgula(mobjeto, mevento)
{
  	//alert("EVENTO:"+mobjeto+"2:"+mevento);
	//somente deixa digitar números de 0 a 9, a virgula e a tecla enter
 	if ((mevento.keyCode >= 48) && (mevento.keyCode <= 57)) { return true; }
 	if ((mevento.keyCode == 44) || (mevento.keyCode == 8)) { return true; }
	
	return false;
}
//===============================================================================================================================
// Preload
// 
//
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//===============================================================================================================================
// Formatar Mascaras
// Uso: onkeypress="formatar_mascara(this, '#####-###')" 
//
function formatar_mascara(src, mascara) {
	var campo = src.value.length;
	var saida = mascara.substring(0,1);
	var texto = mascara.substring(campo);
	var tamanho = mascara.length; 
	if (texto.substring(0,1) != saida) {
		src.value += texto.substring(0,1);
	}
}

//===============================================================================================================================
// Verifica browser
//
function isCurrentBrowser(browserName) {	
	if(navigator.userAgent.search(browserName) != -1)
		return true;
	else
		return false;
}

//===============================================================================================================================
// Monta os flashs no site
//
function flash(piWid, piHei, psSrc, psId, psTitulo, psMode) {
	var strSwf;
	if (isCurrentBrowser("MSIE")) {
		strSwf = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" id="+psId+" width="+piWid+" height="+piHei+">";
		strSwf += "<param name=\"movie\" value="+psSrc+" />";
		strSwf += "<param name=\"allowScriptAccess\" value=\"sameDomain\" />";
		strSwf += "<param name=\"quality\" value=\"high\" />";
		strSwf += "<param name=\"wmode\" value="+psMode+"  />";
		if (psTitulo != "")
			strSwf += "<param name=\"FlashVars\" value=\"titulo="+psTitulo+"\" />";
		strSwf += "<embed id="+psId+" name="+psId+" allowScriptAccess=\"sameDomain\" swLiveConnect=\"true\" src="+psSrc+" quality=\"high\" wmode=\"transparent\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width="+piWid+" height="+piHei+"></embed></object>";
	} else {
		strSwf = "<object type=\"application/x-shockwave-flash\" data="+psSrc+" width="+piWid+" height="+piHei+" />";
		strSwf += "<param name=\"quality\" value=\"high\" />";
		strSwf += "<param name=\"wmode\" value="+psMode+"  />";
		strSwf += "<param name=\"allowScriptAccess\" value=\"sameDomain\" />";
		if (psTitulo != "")
			strSwf += "<param name=\"FlashVars\" value=\"titulo="+psTitulo+"\" />";
	}
	this.document.write(strSwf);
} 

//===============================================================================================================================
// Funcao usada para autocompletar
//
function upperCase(event) { 
   var keynum; 

   // IE 
   if (window.event) { 
	  keynum = event.keyCode; 
   } 
   // Netscape/Firefox/Opera 
   else if (event.which) { 
	  keynum = event.which; 
   } 

   if ((keynum >= 97 && keynum <= 122) || (keynum >= 224 && keynum <= 255)) { 
	  // converte de acordo com o valor decimal da tecla na tabela ascii    
	  keynum = keynum - 32; 
	   
	  // IE 
	  if (window.event) { 
		 window.event.keyCode = keynum; 
	  } 
	  // firefox e outros que usam o Gecko 
	  else if (event.which) { 
		 var newEvent = document.createEvent("KeyEvents"); 
		 newEvent.initKeyEvent("keypress", true, true, document.defaultView, 
				  event.ctrlKey, event.altKey, event.shiftKey, 
				  event.metaKey, 0, keynum); 
		 event.preventDefault(); 
		 event.target.dispatchEvent(newEvent); 
	  } 
   } 
	
   return true; 
}

//===============================================================================================================================
// mascara cep
//
function MascaraCEP (evento,objeto) 
{
	var keypress=(window.event)?event.keyCode:evento.which;
	campo = eval (objeto);
	if (campo.value == '00000-000'){
		campo.value=""
	}
	caracteres = '0123456789';
	if ((caracteres.search(String.fromCharCode (keypress))!=-1) && campo.value.length < (9)){
		if (campo.value.length == 5)
			campo.value = campo.value + "-";
	} else
		event.returnValue = false;	
}

//===============================================================================================================================
// formata data
//
function formatadata(obj, tecla)
{
   if (tecla.keyCode == 8)
      return true; 
   var continuar = false;	  
   if ((tecla.keyCode >= 48) && (tecla.keyCode <= 57)) { continuar = true; }
   if ((tecla.keyCode >= 96) && (tecla.keyCode <= 105)) { continuar = true; }
   if ((tecla.keyCode == 46) || (tecla.keyCode == 8)) { continuar = true; }
   if (continuar == false)
     return false;

   vlr = obj.value;
   vlr2 = "";
   vlr = vlr.replace("/","");
   vlr = vlr.replace("/","");
   vlr2 = vlr2 + vlr.substr(0,2);
   if (vlr.length >= 2) 
     vlr2 = vlr2 + "/";
   vlr2 = vlr2 + vlr.substr(2,2);
   if (vlr.length >= 4) 
     vlr2 = vlr2 +"/";
   vlr2 = vlr2 + vlr.substr(4,4);
   obj.value = vlr2;
   return true;
}

//===============================================================================================================================
// apenas numeros
//
function Apenas_Numeros(caracter) {
	var nTecla = 0;
	if (document.all) {
		nTecla = caracter.keyCode;
	} else {
		nTecla = caracter.which;
	}
	if ((nTecla> 47 && nTecla <58)
	|| nTecla == 8 || nTecla == 127
	|| nTecla == 0 || nTecla == 9 // 0 == Tab
	|| nTecla == 13) { // 13 == Enter
		return true;
	} else {
		return false;
	}

} 
//===============================================================================================================================
// abre pop up
//
function Abre(endereco, largura, altura)  
{
   window.open(endereco,"Detalhes","toolbar=0,scrollbars=0,location=0,directories=0,copyhistory=0,status=0,menubar=0,resizable=0,width="+largura+",height="+altura+",z-lock,screenX=150,screenY=100, Left=180, Top=100"); 
}

//===============================================================================================================================
// Verifica cnpj
//
function validaCNPJ(campo)  {  

	//Declaração as variáveis  
	var numeros, digitos, soma, i, resultado, pos, tamanho, digitos_iguais, cnpj;  
	cnpj = campo.value;  

	//Verificando se o campo é nulo  
	if (cnpj.length == 0) {  
		return false;  
	}  

	//Filtrar o campo para verificar se está com máscara  
	var filtro = /\d{2,3}.\d{3}.\d{3}\/\d{4}-\d{2}/;  

	if(!filtro.test(cnpj)){  
		alert("CNPJ inválido. Tente novamente.");  
		return false;  
	}  

	//Ultilização expressão regular para retirar o que não for número  
	cnpj = cnpj.replace(/\D+/g, '');  
	digitos_iguais = 1;  

	for (i = 0; i < cnpj.length - 1; i++)  

		if (cnpj.charAt(i) != cnpj.charAt(i + 1))   {  
			digitos_iguais = 0;  
			break;  
		}  

		 if (!digitos_iguais) {  
			tamanho = cnpj.length - 2
			numeros = cnpj.substring(0,tamanho);  
			digitos = cnpj.substring(tamanho); 
			soma = 0;  
			pos = tamanho - 7;  

			for (i = tamanho; i >= 1; i--)  {  
				soma += numeros.charAt(tamanho - i) * pos--;  
				if (pos < 2)  
					pos = 9;  
			}  

			resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;  

			if (resultado != digitos.charAt(0)){  
				alert('CNPJ inválido'); 
				return false;  
			}  

			tamanho = tamanho + 1;  
			numeros = cnpj.substring(0,tamanho);  
			soma = 0;  
			pos = tamanho - 7;  

			for (i = tamanho; i >= 1; i--)  {  
				soma += numeros.charAt(tamanho - i) * pos--;  
				if (pos < 2)
					pos = 9;  
			}  

			resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;  

			if (resultado != digitos.charAt(1)){  
				alert('CNPJ inválido');  
				return false;  
			}  
			return true;  

     } else 

            alert('CNPJ inválido');  

     return false;  

} 

function maskCNPJ(campo, teclapres) {
	var tecla = teclapres.keyCode;
	var vr = new String(campo.value);
	vr = vr.replace(".", "");
	vr = vr.replace("/", "");
	vr = vr.replace("-", "");
	tam = vr.length + 1;
	if (tecla != 14)
	{
		if (tam == 3)
			campo.value = vr.substr(0, 2) + '.';
		if (tam == 6)
			campo.value = vr.substr(0, 2) + '.' + vr.substr(2, 5) + '.';
		if (tam == 10)
			campo.value = vr.substr(0, 2) + '.' + vr.substr(2, 3) + '.' + vr.substr(6, 3) + '/';
		if (tam == 15)
			campo.value = vr.substr(0, 2) + '.' + vr.substr(2, 3) + '.' + vr.substr(6, 3) + '/' + vr.substr(9, 4) + '-' + vr.substr(13, 2);
	}

}

//===============================================================================================================================
// Verifica cpf
//
function validaCPF(cpf) 
{
erro = new String;

if (cpf.value.length == 11)
{ 
cpf.value = cpf.value.replace('.', '');
cpf.value = cpf.value.replace('.', '');
cpf.value = cpf.value.replace('-', '');

var nonNumbers = /\D/;

if (nonNumbers.test(cpf.value)) 
{
erro = "A verificacao de CPF suporta apenas números!"; 
}
else
{
if (cpf.value == "00000000000" || 
cpf.value == "11111111111" || 
cpf.value == "22222222222" || 
cpf.value == "33333333333" || 
cpf.value == "44444444444" || 
cpf.value == "55555555555" || 
cpf.value == "66666666666" || 
cpf.value == "77777777777" || 
cpf.value == "88888888888" || 
cpf.value == "99999999999") {

erro = "Número de CPF inválido!"
}

var a = [];
var b = new Number;
var c = 11;

for (i=0; i<11; i++){
a[i] = cpf.value.charAt(i);
if (i < 9) b += (a[i] * --c);
}

if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x }
b = 0;
c = 11;

for (y=0; y<10; y++) b += (a[y] * c--); 

if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; }

if ((cpf.value.charAt(9) != a[9]) || (cpf.value.charAt(10) != a[10])) {
erro = "Número de CPF inválido.";

}
}
}
else
{
if(cpf.value.length == 0)
return false
else
erro = "Número de CPF inválido.";
}
if (erro.length > 0) {
alert(erro);
cpf.focus();
return false;
} 
return true; 
}

//envento onkeyup
function maskCPF(CPF) {
var evt = window.event;
kcode=evt.keyCode;
if (kcode == 8) return;
if (CPF.value.length == 3) { CPF.value = CPF.value + '.'; }
if (CPF.value.length == 7) { CPF.value = CPF.value + '.'; }
if (CPF.value.length == 11) { CPF.value = CPF.value + '-'; }
}

// evento onblur
function formataCPF(CPF)
{
with (CPF)
{
value = value.substr(0, 3) + '.' + 
value.substr(3, 3) + '.' + 
value.substr(6, 3) + '-' +
value.substr(9, 2);
}
}
function retiraFormatacao(CPF)
{
with (CPF)
{
value = value.replace (".","");
value = value.replace (".","");
value = value.replace ("-","");
value = value.replace ("/","");
}
}

//===============================================================================================================================
// Verifica cpf
//
function formataFone(evento,objeto) {
	var keypress=(window.event)?event.keyCode:evento.which;
	campo = eval (objeto);
	if (campo.value == '(00)0000-0000'){
		campo.value=""
	}

	caracteres = '0123456789';

	if ((caracteres.search(String.fromCharCode (keypress))!=-1) && campo.value.length < (13)){
		if (campo.value.length == 0 )
			campo.value = "(";
		else if (campo.value.length == 3)
			campo.value = campo.value + ")";
		else if (campo.value.length == 8)
			campo.value = campo.value + "-";
		} else
		event.returnValue = false;
}	

//===============================================================================================================================
// wait(2000);
function wait(msecs) {
	var start = new Date().getTime();
	var cur = start
	while(cur - start < msecs) {
		cur = new Date().getTime();
	} 
} 

//===============================================================================================================================
// limpa campos
function LimpaCampo(campo, Text)
{	
	if (document.getElementById(campo).value == Text)
		document.getElementById(campo).value = "";
	
}
function voltacampo(campo, Text)
{
	if (document.getElementById(campo).value == "") 
		document.getElementById(campo).value = Text;
}

function sonumero(mobjeto, mevento)
{
  if ((mevento.keyCode >= 48) && (mevento.keyCode <= 57)) { return true; }
  //if ((mevento.keyCode >= 96) && (mevento.keyCode <= 105)) { return true; }
  if ((mevento.keyCode == 46) || (mevento.keyCode == 8)) { return true; }
  return false;
}  

//===============================================================================================================================
// mascara hora
function formatahora(obj, tecla)
{
   if (tecla.keyCode == 8)
      return true; 
   var continuar = false;	  
   if ((tecla.keyCode >= 48) && (tecla.keyCode <= 57)) { continuar = true; }
   if ((tecla.keyCode >= 96) && (tecla.keyCode <= 105)) { continuar = true; }
   if ((tecla.keyCode == 46) || (tecla.keyCode == 8)) { continuar = true; }
   if (continuar == false)
     return false;

   vlr = obj.value;
   vlr2 = "";
   vlr = vlr.replace(":","");
   vlr = vlr.replace(":","");
   vlr2 = vlr2 + vlr.substr(0,2);
   if (vlr.length >= 2) 
     vlr2 = vlr2 + ":";
   vlr2 = vlr2 + vlr.substr(2,2);
   if (vlr.length >= 4) 
     vlr2 = vlr2;
   obj.value = vlr2;
   return true;
}

function Abre(endereco, largura, altura)  
{
   popup = window.open(endereco,"Detalhes","toolbar=0,scrollbars=0,location=0,directories=0,copyhistory=0,status=0,menubar=0,resizable=0,width="+largura+",height="+altura+",z-lock,screenX=150,screenY=100, Left=180, Top=100"); 
}

function Abre_Curriculo(endereco, largura, altura)  
{
   popup = window.open(endereco,"Detalhes","toolbar=0,scrollbars=1,location=0,directories=0,copyhistory=0,status=0,menubar=0,resizable=0,width="+largura+",height="+altura+",z-lock,screenX=10,screenY=10, Left=10, Top=10"); 
}

function Visualizar(endereco, largura, altura)   {
   popup = window.open(endereco,"Intranet","toolbar=0,scrollbars=yes,location=0,directories=0,copyhistory=0,status=0,menubar=0,resizable=0,width="+largura+",height="+altura+",z-lock,screenX=150,screenY=100, Left=100, Top=50"); 
}
