var ie4 = (document.all) ? true : false;
var ns4 = (document.layers) ? true : false;
var ns6 = (document.getElementById && !document.all) ? true : false;

function hidelayer(lay){
		if (ie4) {document.all[lay].style.display = "none";}
		if (ns4) {document.layers[lay].visibility = "hide";}
		if (ns6) {document.getElementById([lay]).style.display = "none";}
	}
	
function showlayer(lay){
	if (ie4) {document.all[lay].style.display = "";}
	if (ns4) {document.layers[lay].visibility = "show";}
	if (ns6) {document.getElementById([lay]).style.display = "block";}
	}

function mostrar(div){
	if (nomeDiv!="Glossario"){
		if (ie4) { 
			if (document.all[div].style.display != ""){
					showlayer(div);		
			}
			else{
				hidelayer(div);
			}
		}
		if (ns4) {
			if (document.layers[div].visibility != "show"){
					showlayer(div);	
			}
			else{
					hidelayer(div);
			}
		}
		if (ns6) {
			if (document.getElementById([div]).style.display != "block"){
				showlayer(div);	
			}
			else{
				hidelayer(div);
			}	
		}
	} 
	else{
		if (ie4){showlayer(div);}
		if (ns4) {showlayer(div);}
		if (ns6) {showlayer(div);}
		if (ie4) {var Layer = document.all.tags("DIV");}
		if (ns6) {var Layer = document.getElementsByTagName("DIV");}
	}
	for (vi=1;vi<=totalDiv;vi++)
		{
		try{
			if(Layer[vi-1].id.substring(0,9).toLowerCase().toString()=='glossario'){
				auxdiv = Layer[vi-1].id
				if (div!=auxdiv) {hidelayer(auxdiv);} 	
			}	
		}catch(e){
			auxdiv=nomeDiv + vi;
			if (div!=auxdiv) {hidelayer(auxdiv);} 
		}
	}	
}
	
function hideAllLayers() {
	if (ie4) {
		var Layer = document.all.tags("DIV");
	}
	if (ns6) {
		var Layer = document.getElementsByTagName("DIV");
	}
	for (var j=1 ; j <= totalDiv ; j++) {
		auxdiv= nomeDiv + j;
		hidelayer(auxdiv); 
	}
}	

var totalDiv=0;
var nomeDiv='';

function defineParametrosDiv(total,nome){	
	totalDiv= total;
	nomeDiv=nome;	
}

function Trim(campo) { 
	var i = 0
	var j = campo.length-1
	var digitos = " "
	
	while (i < campo.length && digitos.indexOf(campo.charAt(i)) == 0 ) 
		i++;
	while (j > i && digitos.indexOf(campo.charAt(j)) == 0 ) 
		j--;
	return campo.substring(i,j+1);
}

function check_cpf(numcpf) {
	if (EhIgual(numcpf)==true) { alert ('Número do CPF inválido!'); return false; }
	if (numcpf.length < 11) {
		var qtde = 11 - numcpf.length;
		for (var i=1; i <= qtde; i++) {
			numcpf = '0'+numcpf;
		}
	}
	x=0; soma=0; dig1=0; dig2=0; texto=""; numcpf1="";
	len = numcpf.length; x = len -1;
	for (i=0; i <= len - 3; i++) {
		y = numcpf.substring(i,i+1); soma = soma + ( y * x);
		x = x - 1; texto = texto + y;
	}
	dig1 = 11 - (soma % 11);
	if (dig1 == 10) dig1=0 ; if (dig1 == 11) dig1=0 ;
	numcpf1 = numcpf.substring(0,len - 2) + dig1 ;
	x = 11; soma=0;
	for (var i=0; i <= len - 2; i++) {
		soma = soma + (numcpf1.substring(i,i+1) * x); x = x - 1;
	}
	dig2= 11 - (soma % 11);
	if (dig2 == 10) dig2=0; if (dig2 == 11) dig2=0;
	if ((dig1 + "" + dig2) == numcpf.substring(len,len-2)) {
		return true;
	}
	alert ('Número do CPF inválido!');
	return false;
}

function EhIgual(campo) { 
	var i = 0
	var j = 1
	var igual = true;
	while (i < campo.length-1 && igual == true) {
		while (j < campo.length && igual == true) {
			if (campo.charAt(i) != campo.charAt(j)) {
				igual = false;
			}
			else j++;
		}
		i++;
	}
	return igual;
}

function MM_openBrWindow(theURL,winName,features){
  window.open(theURL,winName,features);
}

function Pop_Up(v_pagina,v_altura) {
	v_altura = v_altura + 145;
	v_features = 'height=' + v_altura + ',width=570,directories=0,location=0,menubar=0,resizable=0,scrollbars=0,status=0,toolbar=0,marginleft=0,margintop=0,left=20,top=30';
	window.open(v_pagina,'_blank',v_features);
}

function MM_swapImage(){
  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];}
}

function MM_swapImgRestore() {
  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_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.getElementById(n); return x;
}
 	 
function Sensi_bankline(valor,bkpar){
	var linkBKL = '';
	var origem = 'ItauPF';
	if (get_imob_tipobkl()=='personnalite'){
		linkBKL = document.bank_first.action;	
		document.bank_first.action = linkBKL.replace('bankline','itaubankline');
		origem = 'Pers';
	}
	// Alteracao para contemplar o envio de dados simulados para proposta para 
	// correntistas - via BKL - inclusao de 9 arrobas delimitadoras.
	var nDelimiter = bkpar.indexOf('@');
	if (nDelimiter == -1) {
		bkpar = bkpar + '@@@@@@@@@'
	}
	document.bank_first.cdg.value=valor;
	document.bank_first.bkpar.value=bkpar;
	document.bank_first.origem.value=origem;
	
	document.bank_first.submit();
}
    
VerifiqueTAB=true;
		
function Mostra(quem, tammax) {
	if ( (quem.value.length == tammax) && (VerifiqueTAB) ) {
		var i=0,j=0, indice=-1;
		for (i=0; i<document.forms.length; i++) {
			for (j=0; j<document.forms[i].elements.length; j++) {
				if (document.forms[i].elements[j].name == quem.name) {
					indice=i;
					break;
				}
			}
			if (indice != -1)
				break;
		}
		for (i=0; i<=document.forms[indice].elements.length; i++) {
			if (document.forms[indice].elements[i].name == quem.name) {
				while ( (document.forms[indice].elements[(i+1)].type == "hidden") &&
						(i < document.forms[indice].elements.length) ) {
							i++;
				}
				document.forms[indice].elements[(i+1)].focus();
				VerifiqueTAB=false;
				break;
			}
		}
	}
}

function PararTAB(quem) {
	VerifiqueTAB=false;
}

function ChecarTAB() {
	VerifiqueTAB=true;
}
	
function soNumero(){
	if (!(event.keyCode>47 && event.keyCode<58)){
		event.keyCode=0;
	}
}