// function restorePage()
// function esconde()
// function mostra()
// function limita(campo)
// function contacampo(campo, tamtxt)
// function main(campofoco)
// function FormataDado(campo,tammax,pos)
// function SaltaCampo(campo,prox,tammax,event)
// function FormataData(campo)
// function FiltraCampo(campo)
// function setHelp(text)
// function printPage()
// function ApagaCampos()
// function FormataValor(campo)
// function VerificaJava()
// function formataMesAno(campo)

//Apaga frames herdados  - formatadadosns1.js
if (top.frames.length!=0)
    top.location=self.document.location;
// 

//Bloco de código para esconder e mostra form
var Ver4 = parseInt(navigator.appVersion) >= 4
var Nav4 = ((navigator.appName == "Netscape") && Ver4)
var block = "formulario";
// save window content dimensions to work around resize
// behavior in Win32 version of Navigator 4
if (Nav4) {
	 var origWidth = window.innerWidth
	 var origHeight = window.innerHeight
}

// invoked by <BODY>'s onResize event handler to refresh the page for
// Navigator 4 to assist in getting positioned elements back in place
function restorePage() {
	if (origWidth != window.innerWidth || origHeight != window.innerHeight) { history.go(0) }
}

function esconde() {	document.layers[block].visibility = "hidden" }
function mostra() { document.layers[block].visibility = "visible" }
//Fim do bloco de código para esconder e mostra form


// -- Contador para objeto TextArea.
function limita(campo){
	var tamanho = document.form[campo].value.length;
	var tex=document.form[campo].value;
	if (tamanho >= 1199) {
		alert("Alcançado o limite máximo de caracteres.");
		document.form[campo].value=tex.substring(0,1199); 
	}
	return true;
}

function contacampo(campo, tamtxt) {
document.form[tamtxt].value =  1200 - document.form[campo].value.length;
}
// --


function main(campofoco) { 
	var i;
	if (campofoco == '') 
		return false;
//	ApagaCampos();
	ApagaPassword();
	if(document.forms.length > 1)	
		for (j = 0; j < document.forms.length; j++){	
			for (i = 0; i < document.forms[j].elements.length; i++){
			   	if (campofoco == document.forms[j].elements[i].name)
					document.forms[j].elements[campofoco].focus(); 
			}	
		}
	else if (document.forms.length == 1)
		for (i = 0; i < document.forms[0].elements.length; i++){
		   	if (campofoco == document.forms[0].elements[i].name)
				document.forms[0].elements[campofoco].focus();  
		}
}

function FormataDado(campo,tammax,pos){
	document.form[campo].value = FiltraCampo(campo);
	vr = document.form[campo].value;
	tam = vr.length;

	if ( tam <= 2 )
 		document.form[campo].value = vr ;
	if ( tam > pos && tam <= tammax )
		document.form[campo].value = vr.substr( 0, tam - pos ) + '-' + vr.substr( tam - pos, tam );
}

function SaltaCampo(campo,prox,tammax,event){
	//alert(campo);
	var tecla = event.which;
	vr = document.form[campo].value;
	tam = vr.length;
	if (tecla != 9 && tecla != 0)
		if ( tam == tammax ){ document.form[prox].focus(); }
}

function FormataData(campo){
	document.form[campo].value = FiltraCampo(campo);
	vr = document.form[campo].value;
	tam = vr.length;

	if ( tam > 2 && tam < 5 )
		document.form[campo].value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
	if ( tam >= 5 && tam <= 8 ) 
		document.form[campo].value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ); 
}

function FiltraCampo(campo){
	var s = "";
	var cp = "";
	vr = document.form[campo].value;
	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);}
	}
	document.form[campo].value = s;
	return cp = document.form[campo].value
}

function setHelp(text){
	if(document.help)
	{
		document.help.document.helpns.document.write('<font face="Trebuchet MS, Arial, Helvetica" size="0" color="#3399FF"><b>'+text+'</b></font>');
		document.help.document.helpns.document.close();
		document.help.visibility="show";
	}
}

function SetHelp(text){
	setHelp(text);
}

function SetHelpCenter(text){
	if(document.help)
	{
		document.help.document.helpns.document.write('<font face="Trebuchet MS, Arial, Helvetica" size="0" color="#3399FF"><b><center>'+text+'</center></b></font>');
		document.help.document.helpns.document.close();
		document.help.visibility="show";
	}
}

//------------------------------------------

var da = (document.all) ? 1 : 0;
var pr = (window.print) ? 1 : 0;
var mac = (navigator.userAgent.indexOf("Mac") != -1); 

function printPage(){
	if (pr) // NS4, IE5
		window.print()
	else if (da && !mac) // IE4 (Windows)
  		vbPrintPage()
	else // other browsers
  		alert("Desculpe seu browser não suporta esta função. Por favor utilize a barra de trabalho para imprimir a página.");
	return false;
}

if (da && !pr && !mac) with (document) {
  writeln('<OBJECT ID="WB" WIDTH="0" HEIGHT="0" CLASSID="clsid:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>');
  writeln('<' + 'SCRIPT LANGUAGE="VBScript">');
  writeln('Sub window_onunload');
  writeln('  On Error Resume Next');
  writeln('  Set WB = nothing');
  writeln('End Sub');
  writeln('Sub vbPrintPage');
  writeln('  OLECMDID_PRINT = 6');
  writeln('  OLECMDEXECOPT_DONTPROMPTUSER = 2');
  writeln('  OLECMDEXECOPT_PROMPTUSER = 1');
  writeln('  On Error Resume Next');
  writeln('  WB.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER');
  writeln('End Sub');
  writeln('<' + '/SCRIPT>');
}

function ApagaCampos(){
	if(document.forms.length > 1)	
		for (j = 0; j < document.forms.length; j++){	
			for (i = 0; i < document.forms[j].elements.length; i++){
			   	document.forms[j].elements[i].value = ""; 
			}	
		}
	else if (document.forms.length == 1)
		for (i = 0; i < document.forms[0].elements.length; i++){
			document.forms[0].elements[i].value = ""; 
		}
}

function Apaga(){
	if(document.forms.length > 1)	
		for (j = 0; j < document.forms.length; j++){	
			for (i = 0; i < document.forms[j].elements.length; i++){
			   	document.forms[j].elements[i].value = ""; 
			}	
		}
	else if (document.forms.length == 1)
		for (i = 0; i < document.forms[0].elements.length; i++){
			document.forms[0].elements[i].value = ""; 
		}
}

function ApagaPassword(){
	if(document.forms.length > 1)	
		for (j = 0; j < document.forms.length; j++){	
			for (i = 0; i < document.forms[j].elements.length; i++){
			   	if (document.forms[j].elements[i].type == "password")
					document.forms[j].elements[i].value = ""; 
			}	
		}
	else if (document.forms.length == 1)
		for (i = 0; i < document.forms[0].elements.length; i++){
		   	if (document.forms[0].elements[i].type == "password")
				document.forms[0].elements[i].value = ""; 
		}
}

function FormataValor(campo) {
	document.form[campo].value = FiltraCampo(campo);
	vr = document.form[campo].value;
	tam = vr.length;

	if ( tam <= 2 ) 
 		document.form[campo].value = vr ; 
 	if ( (tam > 2) && (tam <= 5) ) 
 		document.form[campo].value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; 
 	if ( (tam >= 6) && (tam <= 8) ) 
 		document.form[campo].value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; 
 	if ( (tam >= 9) && (tam <= 11) ) 
 		document.form[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) ) 
 		document.form[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 <= 17) )
 		document.form[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 FormataJuros(campo) {
	document.form[campo].value = FiltraCampo(campo);
	vr = document.form[campo].value;
	tam = vr.length;
	
		if ( tam <= 2 ){ 
	 		document.form[campo].value = vr ; 
		}
	 	if ( tam > 2){
	 		document.form[campo].value = vr.substr( 0, tam - 4 ) + ',' + vr.substr(tam - 4, tam ) ; 
		}
}

function VerificaJava(){
	if (navigator.javaEnabled())
		document.form.javas.value="sim"
}

function FormataMesAno(campo) {
	document.form[campo].value = FiltraCampo(campo);
	vr = document.form[campo].value;
	tam = vr.length;
	
	if ( tam > 2 && tam < 7 )
		document.form[campo].value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, tam );
}

function FormataCpf(campo){
	document.form[campo].value = FiltraCampo(campo);
	vr = document.form[campo].value;
	tam = vr.length;	
	
	if ( tam <= 2 ) 
		document.form[campo].value = vr ;
	if ( (tam > 2) && (tam <= 5) )
		document.form[campo].value = vr.substr( 0, tam - 2 ) + '-' + vr.substr( tam - 2, tam ) ;
	if ( (tam >= 6) && (tam <= 8) )
		document.form[campo].value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ;
	if ( (tam >= 9) && (tam <= 11) )
		document.form[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) )
		document.form[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 <= 17) )
		document.form[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 FormataCgc(campo){
	document.form[campo].value = FiltraCampo(campo);
	vr = document.form[campo].value;
	tam = vr.length;	
	
	if ( tam <= 2 ){ 
		document.form[campo].value = vr ; }
	if ( (tam > 2) && (tam <= 6) ){
		document.form[campo].value = vr.substr( 0, tam - 2 ) + '-' + vr.substr( tam - 2, tam ) ; }
	if ( (tam >= 7) && (tam <= 9) ){
		document.form[campo].value = vr.substr( 0, tam - 6 ) + '/' + vr.substr( tam - 6, 4 ) + '-' + vr.substr( tam - 2, tam ) ; }
	if ( (tam >= 10) && (tam <= 12) ){
		document.form[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) ){
		document.form[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) ){
		document.form[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 ) ;}
}

//os métodos abaixo são utilizados na Applet do Teclado Virtual
function getSenha() {
	if ( document.applets['tclJava'] ){
		var senha = document.applets['tclJava'].getSenha();
		document.form.elements['senhaConta'].value = senha;
		if (document.form.elements['numCod']) {
			document.form.elements['numCod'].value = document.applets['tclJava'].getNumCod();
		}
	}
}

function enviaSub() {
	document.form.submit();
	return false;
}

function mudaFoco(campo)
{
	if(campo == "98") {
		return;
	}
	if( (campo == "senhaConta" || (document.form.elements[campo] && document.form.elements[campo].name == "senhaConta")) && document.applets['tclJava'] )
		document.applets.tclJava.setFocus();
	else if (document.form.elements[campo])
		document.form.elements[campo].focus();
}

function mostraBalao(mst) {
	if (mst) {
		SetHelp("Informe sua senha de 8 dígitos, clicando com o mouse no teclado virtual na tela");
		//document.layers["balaoApplet"].visibility="visible";
	}
	else {
		SetHelp("");
		//document.layers["balaoApplet"].visibility="hidden";
	}
}

function teclaTab(teclaPress) {
	if(teclaPress.keyCode ==9)
		focaApplet();
}

function focaApplet() {
	if (document.applets['tclJava'] ) {
		document.applets.tclJava.setFocus();
	}
}

function focaApplet2(nomeApplet) {
	if (document.applets[nomeApplet] ) {
		document.applets[nomeApplet].setFocus();
	}
}

function setaCod(numCod) {
	if (document.form.elements['numCod'])
		document.form.elements['numCod'].value = numCod;
}

function setaContraste(valorContr) {
	if (document.form.elements['valorContr'])
		document.form.elements['valorContr'].value = valorContr;
}
