// Redireciona o cliente para URL do banner
// Caso URL = https, mantenho-o na mesma janela;
// Caso URL = http, abro nova janela chamada Portal.

function makeParam(name, value)
{
    var p = document.createElement("param");
    p.name = name;
    p.value = value;
    return p;
}

function setAppletArea(oDivTcl)
{
        try {
            oDivTcl.style.width = 316;
            oDivTcl.style.height = 80;
            oDivTcl.style.backgroundColor = "#f7f7f7";
            oDivTcl.innerHTML =  getMensagemErro();
            oDivTcl.style.display = "block";
        } catch (e2) {}
}

function getMensagemErro()
{
    return mensagemErro;
}

function mostraErro()
{
    var oDivTcl = document.getElementById('tclTecladoContent');
    oDivTcl.innerHTML = '<br>Ocorreu um erro ao carregar o Teclado Virtual.<br>Pressione F5 ou <a href="/aapf/login.jsp?forcaApplet=sim" >acesse o Teclado<br>Virtual em Java</a><br><br>';
    return true;
}

function  montaObjetoApplet(caminhoApplet, versaoApplet, contraste, numCod, local, idTeclado, idDiv, legenda1, legenda2, showCamposLogin ) {
    var oDivTcl = document.getElementById(idDiv);
    var codigo = '<applet alt="Senha do auto-atendimento" tabindex="70" code="br/com/bb/aapf/bbteclado/CampoTeclado.class" cabbase="'+caminhoApplet+'/teclado/BBTeclado' + versaoApplet + '.cab" archive="'+caminhoApplet+'/teclado/BBTeclado' + versaoApplet + '.jar" codebase="'+caminhoApplet+'/teclado/" name="' + idTeclado + '" id="' + idTeclado + '" width="316" height="80" namespace="global" mayscript> ';
    codigo += '<param name="id" value="' + idTeclado + '"> ';
    codigo += '<param name="local" value="' + local + '"> ';
    codigo += '<param name="campoAnterior" value=""> ';
    codigo += '<param name="campoPosterior" value="98"> ';
    codigo += '<param name="colorLabel" value="0x000084"> ';
    codigo += '<param name="colorField" value="0xFFFFFA"> ';
    codigo += '<param name="colorBorder" value="0xBBBBBB"> ';
    codigo += '<param name="colorBackground" value="#FFFFFF"> ';
    if(local == "cartao")
    {
        codigo += '<param name="tipoLegenda" value="cartao"> ';
    }
    else if(local == "definido")
    {
        codigo += '<param name="tipoLegenda" value="definido"> ';
        codigo += '<param name="legenda1" value="' + legenda1 + '"> ';
        codigo += '<param name="legenda2" value="' + legenda2 + '"> ';
    }
    if(showCamposLogin == "true")
    {
        codigo += '<param name="showCamposLogin" value="true"> ';
    }
    codigo += '<param name="colorEmb" value="azul"> ';
    codigo += '<param name="valorContr" value="' + contraste + '"> ';
    codigo += '<param name="numCod" value="' + numCod + '"> ';
    codigo += '</applet>';
    mensagemErro = codigo;
    try {
        if (window.navigator.javaEnabled()&&oDivTcl) {
            var oAppletTcl = document.createElement("applet");
            //oAppletTcl.code = "br.com.bb.aapf.bbteclado.CampoTeclado.class";
            oAppletTcl.code = "br/com/bb/aapf/bbteclado/CampoTeclado.class";
            oAppletTcl.codeBase = caminhoApplet + "/teclado/";
            oAppletTcl.cabBase = caminhoApplet + "/teclado/BBTeclado" + versaoApplet + ".cab";
            oAppletTcl.archive = caminhoApplet + "/teclado/BBTeclado" + versaoApplet + ".jar";
            oAppletTcl.name = idTeclado;
            oAppletTcl.tabIndex = "70";
            oAppletTcl.title = "Senha do auto-atendimento";
            oAppletTcl.alt = "Senha do auto-atendimento";
            oAppletTcl.left = 0;
            oAppletTcl.top = 0;
            oAppletTcl.width = 316;
            oAppletTcl.height = 80;
            oAppletTcl.id = idTeclado;
            oAppletTcl.appendChild(makeParam("MAYSCRIPT", "true"));
            oAppletTcl.appendChild(makeParam("id", idTeclado));
            oAppletTcl.appendChild(makeParam("local", local));
            oAppletTcl.appendChild(makeParam("campoAnterior",""));
            oAppletTcl.appendChild(makeParam("campoPosterior","98"));
            oAppletTcl.appendChild(makeParam("colorLabel","0x000084"));
            oAppletTcl.appendChild(makeParam("colorField","0xFFFFFA"));
            oAppletTcl.appendChild(makeParam("colorBorder","0xBBBBBB"));
            oAppletTcl.appendChild(makeParam("colorBackground","#FFFFFF"));

            if(local == "cartao")
            {
                oAppletTcl.appendChild(makeParam("tipoLegenda","cartao"));
            }
            else if(local == "definido")
            {
                oAppletTcl.appendChild(makeParam("tipoLegenda","definido"));
                oAppletTcl.appendChild(makeParam("legenda1",legenda1));
                oAppletTcl.appendChild(makeParam("legenda2",legenda2));
            }
            if(showCamposLogin == "true")
            {
                oAppletTcl.appendChild(makeParam("showCamposLogin","true"));
            }
            oAppletTcl.appendChild(makeParam("colorEmb","azul"));
            oAppletTcl.appendChild(makeParam("valorContr",contraste));
            oAppletTcl.appendChild(makeParam("numCod",numCod));

            oDivTcl.appendChild(oAppletTcl);
        } else {
            window.defaultStatus = "Erro: Java nao suportado ou nao habilitado!";
            window.status = "Erro: Java nao suportado ou nao habilitado!";
            setAppletArea(oDivTcl);
        }
    } catch (e) {
        window.defaultStatus = "Erro ao criar Applet:" + e.description;
        window.status = "Erro ao criar Applet:" + e.description;
        setAppletArea(oDivTcl);
    }

    return true;
}

function redirecionamentoInteligente(){
	url = document.getElementById('bannerLinkId').href;
	if (url.indexOf("https")>-1){
		location.href = url;
	} else {
		window.open( url , 'Portal');
	}
}

// Limpa os campos da tela
function limparCampo(){
	var elements = document.forms.formulario.elements;
	for (i = 0; i < elements.length; i++) {
		if (elements[i].type == 'text' 
			|| elements[i].type == 'text-area'
			|| elements[i].type == 'select-one' 
			|| elements[i].type == 'radio'
			|| elements[i].type == 'checkbox' 
			|| elements[i].type == 'password'
			|| elements[i].type == 'textarea'){
			elements[i].value='';
		}
	}
	if(document.tclJava)
	{
		document.tclJava.limpa();
	}
}
// Limpa todos campos do formulario associado ao botão
function limparCampos(campo){
	var elements = campo.form.elements;
	for (i = 0; i < elements.length; i++) {
		if (elements[i].type == 'text' 
			|| elements[i].type == 'text-area'
			|| elements[i].type == 'select-one' 
			|| elements[i].type == 'radio'
			|| elements[i].type == 'checkbox' 
			|| elements[i].type == 'password'
			|| elements[i].type == 'textarea'){
			elements[i].value='';
		}
	}
	if(document.tclJava)
	{
		document.tclJava.limpa();
	}
}


// Javascript para impedir duplo clique
var submeteuFormulario = 0;
function controleDuploClique() {
	if(submeteuFormulario=="1") {
		return false;
	}
	submeteuFormulario = "1";
	return true;
}

// Abre janela de ajuda
function janelaAjuda(url)
{
	janela = window.open( url , 'Ajuda', 'height=500,width=600,status=yes,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=yes');
	if (window.focus) {
		janela.focus();
	}
}

//Script que esconde um elemento
function escondeLayer(layer) {
	document.getElementById(layer).style.display="none";
}

//Script que mostra um elemento
function mostraLayer(layer) {
	document.getElementById(layer).style.display="";
}

//Script que abre popup
var janela;
function popup(url, target, features) {
	newwindow = window.open(url, target, features);
	if (window.focus) {
		newwindow.focus();
	}
	return false;
}

// Formata o campo CEP
function formataCEP(campo){
	campo.value = filtraCampo(campo);
	vr = Limpar(campo.value, "0123456789");
	//vr = campo.value;
	tam = vr.length;

	if ( tam <= 3 )
		campo.value = vr;
	if ( tam > 3 ) 
		campo.value = vr.substr(0, tam-3 ) + '-' + vr.substr(tam-3, tam);
}

// Limpa os campos da tela
function limpa(){
	var elements = document.forms.formulario.elements;
	for (i = 0; i < elements.length; i++) {
		if (elements[i].type == 'text' || elements[i].type == 'text-area'
				|| elements[i].type == 'select-one' || elements[i].type == 'radio'
				|| elements[i].type == 'checkbox' || elements[i].type == 'password'
				|| elements[i].type == 'textarea'){
			elements[i].value='';
		}
	}
}

function limpaEspecifico(text,textarea,selectone,radio,checkbox,password,submit){

	var elements = document.forms.formulario.elements;
	
	for (i = 0; i < elements.length; i++) {
		if(text == 'true'){
			if(elements[i].type == 'text'){
				elements[i].value='';
			}
		}
		if(textarea == 'true'){
			if(elements[i].type == 'text-area'){
				elements[i].value='';
			}
		}
		if(selectone == 'true'){
			if(elements[i].type == 'select-one'){
				elements[i].value='';
			}
		}
		if(radio == 'true'){
			if(elements[i].type == 'radio'){
				elements[i].value='';
			}
		}
		if(checkbox == 'true'){
			if(elements[i].type == 'checkbox'){
				elements[i].value='';
			}
		}
		if(password == 'true'){
			if(elements[i].type == 'password'){
				elements[i].value='';
			}
		}
	}
}


function formataAgencia(campo){
	formataAgenciaConta(campo);
}
// Formata o campo Agencia
function formataAgenciaConta(campo){
	campo.value = filtraCampo(campo);
	vr = campo.value;
	tam = vr.length;

	if ( tam <= 1 )
		campo.value = vr;
	if ( tam > 1 ) 
		campo.value = vr.substr(0, tam-1 ) + '-' + vr.substr(tam-1, tam); 
}

// Formata data no padr?o DDMMAAAA
function formataData(campo){
	filtraCampo(campo);
	vr = Limpar(campo.value, "0123456789");
	vrini = campo.value;
	tam = vr.length;

	if ( tam > 2 && tam < 5 )
		vr = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
	if ( tam >= 5 && tam <= 10 )
		vr = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ); 
	if (vrini!=vr)
		campo.value=vr;
}

// Formata hora no padrao HH:MM
function formataHora(campo,teclapres) {
	var tecla = teclapres.keyCode;
	campo.value = filtraCampo(campo);
	vr = campo.value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( ":", "" );
	vr = vr.replace( ":", "" );
	tam = vr.length + 1;

	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 5 )
			campo.value = vr.substr( 0, tam - 2  ) + ':' + vr.substr( tam - 2, tam );
	}
}

// Formata o campo valor
function formataValor(campo) {
	//campo.value = filtraCampo(campo);
	vr = Limpar(campo.value, "0123456789");
	tam = vr.length;

	if ( tam <= 2 ){ 
 		campo.value = vr ; }
 	if ( (tam > 2) && (tam <= 5) ){
 		campo.value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
 	if ( (tam >= 6) && (tam <= 8) ){
 		campo.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
 	if ( (tam >= 9) && (tam <= 11) ){
 		campo.value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
 	if ( (tam >= 12) && (tam <= 14) ){
 		campo.value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
 	if ( (tam >= 15) && (tam <= 18) ){
 		campo.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 Limpar(valor, validos) {
  // retira caracteres invalidos da string
  var result = "";
  var aux;
  for (var i=0; i<valor.length; i++)
  {
    aux = validos.indexOf(valor.substring(i, i+1));
    if (aux>=0)
    {
    	result += aux;
    }
  }
  return result;
}


// Formata o campo valor
function formataNumerico(campo) {
	valorAnterior = campo.value
	valorAtual = Limpar(campo.value, "0123456789");
	if (valorAnterior!=valorAtual) campo.value = Limpar(campo.value, "0123456789");
}

// limpa todos os caracteres especiais do campo solicitado
function filtraCampo(campo){
	var s = "";
	var cp = "";
	vr = campo.value;
	vrini = vr;
	tam = vr.length;
	for (i = 0; i < tam ; i++) {  
		if (vr.substring(i,i + 1) != "/" && vr.substring(i,i + 1) != "-" && vr.substring(i,i + 1) != "."  && vr.substring(i,i + 1) != "," ){
		 	s = s + vr.substring(i,i + 1);}
	}
	if (vrini!=s)
		campo.value = s;
	return cp = campo.value
}
		
// Seta o ajuda do campo no campo <SPAN> 
function setaTextoAjuda(txt) {
	if(document.getElementById('textoAjuda')) document.getElementById('textoAjuda').innerHTML = txt + '&nbsp;' ;
	if(document.getElementById('idCampoAjuda')) document.getElementById('idCampoAjuda').innerHTML = txt + '&nbsp;' ;
}



function getTeclaPressionada(evt)
{
	if(typeof(evt)=='undefined')
		evt = window.event;
	return(evt.keyCode ? evt.keyCode : (evt.which ? evt.which : evt.charCode));
}

function isTeclaEspecial(key)
{
	return key<32||(key>=35&&key<=36)||(key>=37&&key<=40)||key==46;
}

function isTeclaRelevante(key)
{
	return (key == 8)||(key == 46)||(key == 88)||(key>=48&&key<=57)||(key>=96&&key<=105);
}

function isCaracterRelevante(key)
{
	return (key == 88)||(key == 120)||(key>=48&&key<=57);
}

function filtraTeclas(evt)
{
	var key = getTeclaPressionada(evt);
	if(isTeclaEspecial(key) || isTeclaRelevante(key))
		return true;
	StopEvent(evt);
	return false;
}

function filtraCaracteres(evt)
{
	var key = getTeclaPressionada(evt);
	if(isTeclaEspecial(key) || isCaracterRelevante(key))
		return true;
	StopEvent(evt);
	return false;
}

function StopEvent(evt)
{
	if(document.all)evt.returnValue=false;
	else if(evt.preventDefault)evt.preventDefault();
}

function formataMascara(format, field)
{
	var result = "";
	var maskIdx = format.length - 1;
	var error = false;
	var valor = field.value;
	valor = valor.replace(/[^0123456789Xx]/g,'')
	for (var valIdx = valor.length - 1; valIdx >= 0 && maskIdx >= 0; --maskIdx)
	{
		var chr = valor.charAt(valIdx);
		var chrMask = format.charAt(maskIdx);
		switch (chrMask)
		{
		case '#':
			if(!(/\d/.test(chr)))
				error = true;
			result = chr + result;
			--valIdx;
			break;
		case '@':
			result = chr + result;
			--valIdx;
			break;
		default:
			result = chrMask + result;
		}
	}

	if (result!=field.value)
		field.value = result;
	field.style.color = error ? 'red' : '';
	return result;
}

function saltaCampo(campo,tamanhoMaximo,indice,evt,campoValor){
	var vr = campo.value;
	var tam = vr.length;
	var elements = campo.form.elements;
	var key = getTeclaPressionada(evt);
	if (key && ! isTeclaEspecial(key)) {
		if (tam>=tamanhoMaximo && typeof(elements[indice])!='undefined'){
			for (i=0;i<elements.length;i++) {
				if (elements[i].tabIndex==indice+1){
					elements[i].focus();
				}
			}
		}
	}
}




function trocaBotaoAction(botao)
{
	if ( document.applets['tclAssinador'] )
	{
		pos = document.forms.formulario.action.indexOf("?");
		acao = document.forms.formulario.action;
		if(pos != -1)
		{
			acao = acao.substring(0, pos);
		}
		document.forms.formulario.action = acao + "?" + botao + ".x=1";
	}
}

var confirmaAssinador = 0;
var linkJS = "";

function getSenha() {
	if ( document.getElementById('tclAssinadorContent') && document.getElementById('tclAssinadorContent').style.display == 'none' )
	{
		if(showApplet());
			return false;
	}

	if ( document.applets['tclJava'] ){
		var senha = document.applets['tclJava'].getSenha();
		document.forms.formulario.elements['senhaConta'].value = senha;
	}
	else if ( document.applets['tclAssinador'] )
	{
		if(confirmaAssinador == 1)
		{
			confirmaAssinador = 0;
			if( document.applets['tclAssinador'].ok() )
			{
				loadData();
				return true;
			}	
			else
			{
				document.applets['tclAssinador'].focus();
				return false;
			}
		}
		else
		{
			return document.applets['tclAssinador'].cancel();
		}
	}
	return true;
}

function trocaBotaoAction(botao)
{
	if ( document.applets['tclAssinador'] )
	{
		pos = document.forms.formulario.action.indexOf("?");
		acao = document.forms.formulario.action;
		if(pos != -1)
		{
			acao = acao.substring(0, pos);
		}
		document.forms.formulario.action = acao + "?" + botao + ".x=1";
	}
}

// metodo chamado pela applet na finaliza??o do processo
function appletTerminated(ok)
{
	if (ok)
		loadData();
	if (linkJS == "")
		document.forms.formulario.submit();
	else if (linkJS == "retorna") {
		linkJS = "";
		window.history.back(1);
	}
	else {
		var linkJSTemp = linkJS;
		linkJS = "";
		window.navigate(linkJSTemp);
	}
}


function formataMesAno(campo){
	campo.value = filtraCampo(campo);
	vr = campo.value;
	tam = vr.length;

	if ( tam > 2 && tam < 5 )
		campo.value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
	if ( tam >= 5 && tam <= 10 )
		campo.value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 4 ); 
}

function formataCgc(campo) {
	campo.value = filtraCampo(campo);
	vr = campo.value;
	tam = vr.length;

	if ( tam <= 2 ){ 
 		campo.value = vr ; }
 	if ( (tam > 2) && (tam <= 6) ){
 		campo.value = vr.substr( 0, tam - 2 ) + '-' + vr.substr( tam - 2, tam ) ; }
 	if ( (tam >= 7) && (tam <= 9) ){
 		campo.value = vr.substr( 0, tam - 6 ) + '/' + vr.substr( tam - 6, 4 ) + '-' + vr.substr( tam - 2, tam ) ; }
 	if ( (tam >= 10) && (tam <= 12) ){
 		campo.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) ){
 		campo.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) ){
 		campo.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 formataCPF(campo){
	//campo.value = filtraCampo(campo);
	vr = Limpar(campo.value, "0123456789");
	tam = vr.length ;
	if ( tam <= 2 ){
 		campo.value = vr ;}
	if ( tam > 2 && tam <= 5 ){
		campo.value = vr.substr( 0, tam - 2 ) + '-' + vr.substr( tam - 2, tam );}
	if ( tam >= 6 && tam <= 8 ){
		campo.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr(tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam );}
	if ( tam >= 9 && tam <= 11 ){
		campo.value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr(tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam );}

}

function formataPercentual(campo) {
	campo.value = filtraCampo(campo);
	vr = campo.value;
	tam = vr.length;

	if ( tam <= 3 ){ 
 		campo.value = vr ; }
 	if ( (tam > 3) && (tam <= 6) ){
 		campo.value = vr.substr( 0, tam - 3 ) + ',' + vr.substr( tam - 3, tam ) ; }	
}

function formataTelefone(campo) {
	//campo.value = filtraCampo(campo);
	vr = Limpar(campo.value, "0123456789");
	tam = vr.length;

	if ( tam <= 4 )
		campo.value = vr;
	if ( tam > 4 ) 
		campo.value = vr.substr(0, tam-4 ) + '-' + vr.substr(tam-4, tam);
}
function contacampo(campo, tamtxt) {
	document.forms.formulario[tamtxt].value =  1540-document.forms.formulario[campo].value.length;
}

function limita(campo){
	var tamanho = document.forms.formulario[campo].value.length;
	var tex=document.forms.formulario[campo].value;
	if (tamanho>=1539) {
		document.forms.formulario[campo].value=tex.substring(0,1539); 
	}
	return true;
}

function focaCampo(campofoco) { 
	if ( campofoco == '' || document.forms.formulario.elements.length == 0 ) 
		return;
	var num = parseInt(campofoco);

	if ( num || num == 0 )
	{
		if ( document.forms["formulario"][num] && document.forms["formulario"][num].focus)
			document.forms["formulario"][num].focus();
	}
	else 
	{
		if ( (campofoco == "senhaConta" || campofoco == "senhaAtual") && document.applets["tclJava"] )
			document.applets["tclJava"].setFocus();
		else if ( document.forms["formulario"][campofoco] && document.forms["formulario"][campofoco].focus )
			document.forms["formulario"][campofoco].focus();
	}
}


function formataCartaoCredito(campo, teclapres) {
    var tammax = 16;
	var tecla = teclapres.keyCode;
	vr = document.forms.formulario[campo].value;

	if ( tecla == 8 || (tecla >= 48 && tecla <= 57) || (tecla >= 96 && tecla <= 105)) {
		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 ( tam < 5 )
		   { document.forms.formulario[campo].value = vr ; }
	 	if ( ( tam >  4 ) && ( tam < 9 ) )
		   { document.forms.formulario[campo].value = vr.substr( 0, 4 ) + '.' + vr.substr( 4, tam-4 ) ; }
	 	if ( ( tam >  8 ) && ( tam < 13 ) )
		   { document.forms.formulario[campo].value = vr.substr( 0, 4 ) + '.' + vr.substr( 4, 4 ) + '.' + vr.substr( 8, tam-4 ) ; }
	 	if ( tam > 12 )
		   { document.forms.formulario[campo].value = vr.substr( 0, 4 ) + '.' + vr.substr( 4, 4 ) + '.' + vr.substr( 8, 4 ) + '.' + vr.substr( 12, tam-4 ); }
	}	
}

/* Inicio do Menu */
	// Controle de rotação de banners
	var img = 0;
	var imagensList = new Array();
	var linksList = new Array();
	var tempo;
	var tempoMax = 4000;
	function controlaImagens() { 
		if (imagensList.length == 0) 
			return; 
		var imgs_ = imagensList; 
		var links_ = linksList; 
		if (imgs_.length == img) 
			{ img = 0; } 
		document.getElementById('bannerId').src = imgs_[img]; 
		document.getElementById('bannerLinkId').href = links_[img]; 
		img++; 
		tempo = setTimeout('controlaImagens()', tempoMax); 
	}
	function escolherAnterior() { if (tempo != null) { clearTimeout(tempo); } var qtdImgs = imagensList.length; if (img == 1) { img = qtdImgs - 1; } else { img = img - 2; } controlaImagens(); }
	function escolherProximo() { if (tempo != null) { clearTimeout(tempo); } var qtdImgs = imagensList.length; if (img == qtdImgs) { img = 0; } controlaImagens(); }
	// Controle de Abertura e Fechamento dos Boxes
	function abrirDiv(idDiv){ 
		divStyle_ = document.getElementById(idDiv).style;
		btaStyle_ = document.getElementById(idDiv + '_a').style;
		btfStyle_ = document.getElementById(idDiv + '_f').style;
		//divStyle_.position = 'relative'; 
		divStyle_.display = ''; 
		//btaStyle_.position = 'absolute';
		btaStyle_.display = 'none'; 
		//btfStyle_.position = 'relative'; 
		btfStyle_.display = ''; 
		return false; 
	}
	
	function fecharDiv(idDiv){
		divStyle_ = document.getElementById(idDiv).style;
		btaStyle_ = document.getElementById(idDiv + '_a').style;
		btfStyle_ = document.getElementById(idDiv + '_f').style;
		//divStyle_.position = 'absolute'; 
		divStyle_.display = 'none'; 
		//btaStyle_.position = 'relative'; 
		btaStyle_.display = ''; 
		//btfStyle_.position = 'absolute'; 
		btfStyle_.display = 'none'; 
		return false; 
	}
	
	function vDiv(idDiv){ idDiv.style.position = 'relative'; idDiv.style.visibility = 'visible'; }
	function hDiv(idDiv){ idDiv.style.position = 'absolute'; idDiv.style.visibility = 'hidden'; }
//	function vsmn1(ltDiv) { hDiv(smn1a); hDiv(smn1b); hDiv(smn1c); hDiv(smn1d); hDiv(smn1e); thisDiv = eval("smn1"+ltDiv); vDiv(thisDiv); }
//	function vsmn2(ltDiv) { hDiv(smn2a); hDiv(smn2b); hDiv(smn2c); thisDiv = eval("smn2"+ltDiv); vDiv(thisDiv); }
//	function vsmn3(ltDiv) { hDiv(smn3a); hDiv(smn3b); hDiv(smn3c); hDiv(smn3d); hDiv(smn3e); thisDiv = eval("smn3"+ltDiv); vDiv(thisDiv); }

	function setaMenuOver(idDiv) { 
		hDiv(smn0);
		hDiv(smn1a); hDiv(smn1b); hDiv(smn1c); hDiv(smn1d); hDiv(smn1e);
		hDiv(smn2a); hDiv(smn2b); hDiv(smn2c);
		hDiv(smn3a); hDiv(smn3b); hDiv(smn3c); hDiv(smn3d); hDiv(smn3e);
		submenuThis = document.getElementById("smn"+idDiv+"a");
		vDiv(submenuThis);
	}

	function vSubMenu (idSubMenu) {
		if (idSubMenu < 4) {
			setaThis = document.getElementById("setaPos"+idSubMenu);
			document.getElementById("setaPos1").src = '/aapf/im/btSetaMenuOff.gif'; 
			document.getElementById("setaPos2").src = '/aapf/im/btSetaMenuOff.gif'; 
			document.getElementById("setaPos3").src = '/aapf/im/btSetaMenuOff.gif'; 
			setaThis.src = '/aapf/im/btSetaMenuOn.gif'; 
			lineThis = document.getElementById("lnmn"+idSubMenu); 
			lineLatAThis = document.getElementById("lnmnLt"+idSubMenu+"a"); 
			lineLatBThis = document.getElementById("lnmnLt"+idSubMenu+"b");
			lnmn1.style.background = '#CFCDCD'; 
			lnmn2.style.background = '#CFCDCD'; 
			lnmn3.style.background = '#CFCDCD';
			document.getElementById("nomeMenu1").className = "txtMenuBig";
			document.getElementById("nomeMenu2").className = "txtMenuBig";
			document.getElementById("nomeMenu3").className = "txtMenuBig";
			document.getElementById("descricaoMenu1").className = "txtMenuMed";
			document.getElementById("descricaoMenu2").className = "txtMenuMed";
			document.getElementById("descricaoMenu3").className = "txtMenuMed";
			lineThis.style.background = '#ffffff'; 
			lnmnLt1a.src = '/aapf/im/spSubMenu.gif'; 
			lnmnLt1b.src = '/aapf/im/spSubMenu.gif'; 
			lnmnLt2a.src = '/aapf/im/spSubMenu.gif'; 
			lnmnLt2b.src = '/aapf/im/spSubMenu.gif';
			lnmnLt3a.src = '/aapf/im/spSubMenu.gif'; 
			lnmnLt3b.src = '/aapf/im/spSubMenu.gif'; 
			lineLatAThis.src = '/aapf/im/d.gif'; 
			lineLatBThis.src = '/aapf/im/d.gif';
			thisMenuTamanho = document.getElementById("quantidadeMenu").innerHTML;
			for(i=1;i<=thisMenuTamanho;i++) {			
				thisSubMenuTamanho = document.getElementById("quantidadeSubMenu"+i).innerHTML;
				if (thisSubMenuTamanho > 0) {
					thisMenuClose = document.getElementById("subMenu"+i);
					thisMenuClose.className = 'fechado';
					for (j=1;j<=thisSubMenuTamanho;j++){
						thisSubMenuClose = document.getElementById("subMenu"+i+"Trans"+j);
						thisSubMenuItemClose = document.getElementById("linkSubMenu"+i+"Trans"+j);
						//thisSubMenuBgClose = eval("bgsmn"+i+"_"+j);
						thisSubMenuClose.className = "fechado";
						thisSubMenuItemClose.className = "smtOff";
						//thisSubMenuBgClose.style.background = "#ffffff";
					}
				}
			}
		}
		var thisSubMenu;
		complementoMontado = "";
		thisSubMenuDiv = document.getElementById("subMenu"+idSubMenu);
		thisSubMenuDiv.className = 'aberto';
	}
	function vSubMenuTrans(idSubMenu,idSubMenuTrans){
		vSubMenu(idSubMenu);
		thisLinkSubMenu = document.getElementById("linkSubMenu"+idSubMenu+"Trans"+idSubMenuTrans);
		thisLinkSubMenu.blur();
		thisSubMenuTrans = document.getElementById("subMenu"+idSubMenu+"Trans"+idSubMenuTrans);
		thisSubMenuTrans.className = "aberto";
		thisLinkSubMenu.className = "smtOn";
		if (idSubMenu < 4) {
			document.getElementById("nomeMenu"+idSubMenu).className = "txtMenuBigOn";
			document.getElementById("descricaoMenu"+idSubMenu).className = "txtMenuMedOn";
		}
		//lineDown = eval("bgsmn"+idSubMenu+"_"+ idSubMenuTrans);
		//lineDown.style.background = "#ffffff";
	}

	//Identica a função vSubMenu, porém alterada para o segmento Private onde só existem dois menus.
	function vSubMenuPvt (idSubMenu) {
		if (idSubMenu < 3) {
			setaThis = document.getElementById("setaPos"+idSubMenu);
			document.getElementById("setaPos1").src = '/aapf/im/btSetaMenuOff.gif'; 
			document.getElementById("setaPos2").src = '/aapf/im/btSetaMenuOff.gif'; 
			setaThis.src = '/aapf/im/btSetaMenuOn.gif'; 
			lineThis = document.getElementById("lnmn"+idSubMenu); 
			lineLatAThis = document.getElementById("lnmnLt"+idSubMenu+"a"); 
			lineLatBThis = document.getElementById("lnmnLt"+idSubMenu+"b");
			lnmn1.style.background = '#CFCDCD'; 
			lnmn2.style.background = '#CFCDCD'; 
			document.getElementById("nomeMenu1").className = "txtMenuBig";
			document.getElementById("nomeMenu2").className = "txtMenuBig";
			document.getElementById("descricaoMenu1").className = "txtMenuMed";
			document.getElementById("descricaoMenu2").className = "txtMenuMed";
			lineThis.style.background = '#ffffff'; 
			lnmnLt1a.src = '/aapf/im/spSubMenu.gif'; 
			lnmnLt1b.src = '/aapf/im/spSubMenu.gif'; 
			lnmnLt2a.src = '/aapf/im/spSubMenu.gif'; 
			lnmnLt2b.src = '/aapf/im/spSubMenu.gif';
			lineLatAThis.src = '/aapf/im/d.gif'; 
			lineLatBThis.src = '/aapf/im/d.gif';
			thisMenuTamanho = document.getElementById("quantidadeMenu").innerHTML;
			for(i=1;i<=thisMenuTamanho;i++) {			
				thisSubMenuTamanho = document.getElementById("quantidadeSubMenu"+i).innerHTML;
				if (thisSubMenuTamanho > 0) {
					thisMenuClose = document.getElementById("subMenu"+i);
					thisMenuClose.className = 'fechado';
					for (j=1;j<=thisSubMenuTamanho;j++){
						thisSubMenuClose = document.getElementById("subMenu"+i+"Trans"+j);
						thisSubMenuItemClose = document.getElementById("linkSubMenu"+i+"Trans"+j);
						//thisSubMenuBgClose = eval("bgsmn"+i+"_"+j);
						thisSubMenuClose.className = "fechado";
						thisSubMenuItemClose.className = "smtOff";
						//thisSubMenuBgClose.style.background = "#ffffff";
					}
				}
			}
		}
		var thisSubMenu;
		complementoMontado = "";
		thisSubMenuDiv = document.getElementById("subMenu"+idSubMenu);
		thisSubMenuDiv.className = 'aberto';
	}

	//Identica a função vSubMenuTrans, porém alterada para o segmento Private onde só existem dois menus.
	function vSubMenuTransPvt(idSubMenu,idSubMenuTrans){
		vSubMenuPvt(idSubMenu);
		thisLinkSubMenu = document.getElementById("linkSubMenu"+idSubMenu+"Trans"+idSubMenuTrans);
		thisLinkSubMenu.blur();
		thisSubMenuTrans = document.getElementById("subMenu"+idSubMenu+"Trans"+idSubMenuTrans);
		thisSubMenuTrans.className = "aberto";
		thisLinkSubMenu.className = "smtOn";
		if (idSubMenu < 3) {
			document.getElementById("nomeMenu"+idSubMenu).className = "txtMenuBigOn";
			document.getElementById("descricaoMenu"+idSubMenu).className = "txtMenuMedOn";
		}
		//lineDown = eval("bgsmn"+idSubMenu+"_"+ idSubMenuTrans);
		//lineDown.style.background = "#ffffff";
	}


	function getMenu() {
		if (typeof nomeMenu1 != 'undefined') {
			for (i=1;i<=3;i++) {
				thisNomeMenu = document.getElementById("nomeMenu"+i);
				thisDescricaoMenu = document.getElementById("descricaoMenu"+i);
				novoNomeMenu = document.getElementById("menu"+i);
				novoDescricaoMenu = document.getElementById("listaSubMenu"+i);
				thisNomeMenu.innerHTML = novoNomeMenu.innerHTML;
				thisDescricaoMenu.innerHTML = novoDescricaoMenu.innerHTML;
			}
			vSubMenuTrans(4,1);
		}
	}
/* Fim do Menu */

function getConexaoHttp()
{
	var http_request = null;
	if (window.XMLHttpRequest) 
	{ // Mozilla, Safari, ...
	    http_request = new XMLHttpRequest();
	} 
	else if (window.ActiveXObject) 
	{ // IE
	    try 
	    {
	        http_request = new ActiveXObject("Msxml2.XMLHTTP");
	    } 
	    catch (e) 
	    {
	        try 
	        {
	            http_request = new ActiveXObject("Microsoft.XMLHTTP");
	        } catch (e) {}
	    }
	}
	return http_request;

}

function mostraActive(caminhoApplet, versaoApplet, contraste, numCod, local, idTeclado, idDiv, legenda1, legenda2 )
{
	var oDivTcl = document.getElementById(idDiv);
	var codigo = '<object alt="Senha do auto-atendimento" tabindex="70" codebase="' + caminhoApplet + '/teclado/BBTecladoV' + versaoApplet + '.cab#version=1,0,0,2" CLASSID="CLSID:6F03F00A-71B3-4B59-A934-25686DC63B42" name="' + idTeclado + '" id="' + idTeclado + '" width="316" height="80" NOEXTERNALDATA="true"> ';
	codigo += '<param name="id" value="' + idTeclado + '"> ';
	codigo += '<param name="local" value="cartao"> ';
	codigo += '<param name="campoAnterior" value=""> ';
	codigo += '<param name="campoPosterior" value="98"> ';
	codigo += '<param name="colorLabel" value="#000084"> ';
	codigo += '<param name="colorField" value="#FFFFFA"> ';
	codigo += '<param name="colorBorder" value="#BBBBBB"> ';
	codigo += '<param name="colorBackground" value="#FFFFFF"> ';
	if(local == 'cartao')
	{
		codigo += '<param name="tipoLegenda" value="cartao"> ';
	}
	else if(local == 'definido')
	{
		codigo += '<param name="tipoLegenda" value="definido"> ';
		codigo += '<param name="legenda1" value="' + legenda1 + '"> ';
		codigo += '<param name="legenda2" value="' + legenda2 + '"> ';
	}
	codigo += '<param name="colorEmb" value="azul"> ';
	codigo += '<param name="valorContr" value="' + contraste + '"> ';
	codigo += '<param name="numCod" value="' + numCod + '"> ';
	codigo += '</object>';
	oDivTcl.innerHTML = codigo;
	return true;
}


function mostraApplet(caminhoApplet, versaoApplet, contraste, numCod, local, idTeclado, idDiv, legenda1, legenda2 )
{
	var oDivTcl = document.getElementById(idDiv);
	var codigo = '<applet alt="Senha do auto-atendimento" tabindex="70" code="br/com/bb/aapf/bbteclado/CampoTeclado.class" cabbase="/aapf/ncresp/teclado/BBTeclado' + versaoApplet + '.cab" archive="/aapf/ncresp/teclado/BBTeclado' + versaoApplet + '.jar" codebase="/aapf/ncresp/teclado/" name="' + idTeclado + '" id="' + idTeclado + '" width="316" height="80" mayscript> ';
	codigo += '<param name="id" value="' + idTeclado + '"> ';
	codigo += '<param name="local" value="cartao"> ';
	codigo += '<param name="campoAnterior" value=""> ';
	codigo += '<param name="campoPosterior" value="98"> ';
	codigo += '<param name="colorLabel" value="0x000084"> ';
	codigo += '<param name="colorField" value="0xFFFFFA"> ';
	codigo += '<param name="colorBorder" value="0xBBBBBB"> ';
	codigo += '<param name="colorBackground" value="#FFFFFF"> ';
	if(local == "cartao")
	{
		codigo += '<param name="tipoLegenda" value="cartao"> ';
	}
	else if(local == "definido")
	{
		codigo += '<param name="tipoLegenda" value="definido"> ';
		codigo += '<param name="legenda1" value="' + legenda1 + '"> ';
		codigo += '<param name="legenda2" value="' + legenda2 + '"> ';
	}
	codigo += '<param name="colorEmb" value="azul"> ';
	codigo += '<param name="valorContr" value="' + contraste + '"> ';
	codigo += '<param name="numCod" value="' + numCod + '"> ';
	codigo += '</applet>';
	oDivTcl.innerHTML = codigo;
	return true;
}


function mostraAssinador(width, caminhoApplet, nomeBotaoSubmit, idCartao, parametroD)
{
	var oDivTcl = document.getElementById("tclTecladoContent");
	var codigo = '<applet name="tclAssinador" id="tclAssinador" code="br.com.bb.cdg.assinador.applet.SignApplet" codebase="' + caminhoApplet + '/certificacao/" archive="' + caminhoApplet + '/certificacao/slogin.jar" width="' + width + '" height="80" mayscript="mayscript" alt="Assinador do auto-atendimento"> ';
	codigo += '<param name="botao" value="' + nomeBotaoSubmit + '"> ';
	if(idCartao != "null")
		codigo += '<param name="c" value="' + idCartao + '"> ';
	codigo += parametroD + ' ';
	codigo += 'Seu assinador do auto-atendimento não foi habilitado.<br> ';
	codigo += '<a href="/aapf/ajuda/faqCertificacao.jsp">Clique aqui para saber mais...</a><br><br> ';
	codigo += '</applet>';
	oDivTcl.innerHTML = codigo;
	return true;
}

/*-- funcoes para uso na nova estrutura de controle de transacoes --*/
function criarCampoComando(submit, comando)
{
	var formulario = submit.form;
	var campoComando 	= formulario.elements['controle.comando'];
	if (!campoComando){
		campoComando = document.createElement('input');
		campoComando.name 	= 	'controle.comando';
		campoComando.type 	= 	'hidden';
		formulario.appendChild(campoComando);
	}
	campoComando.value 	= 	comando;
}

function submitControleComando(submit, comando)
{
	submitControleComandoToTarget(submit, comando, '');
}

function submitControleComandoToPopUp(submit, comando, atributos)
{
	var popup = window.open('' , 'nome', 	atributos);
	submitControleComandoToTarget(submit, comando, comando);
}
function submitControleComandoToTarget(submit, comando, target)
{
	var formulario = submit.form;
	formulario.target = target;
	var campoComando 	= formulario.elements['controle.comando'];
	if (!campoComando){
		campoComando = document.createElement('input');
		campoComando.name 	= 	'controle.comando';
		campoComando.type 	= 	'hidden';
		formulario.appendChild(campoComando);
	}
	campoComando.value 	= 	comando;
}

function linkChamaComando(action,comando)
{
	var formulario 		= document.forms.item('formulario');
	if (!formulario) {
		formulario 		= document.createElement('form');
		formulario.action = action;
		formulario.method 	= 'post';
		document.body.appendChild(formulario);
	}
	var campoComando	= formulario.elements['controle.comando'];
	if (!campoComando){
		campoComando	= document.createElement('input');
		campoComando.name 	= 	'controle.comando';
		campoComando.type 	= 	'hidden';
		formulario.appendChild(campoComando);
	}
	campoComando.value 	= 	comando;
	formulario.submit();
}

