<!-- Função JavaScript para a consistência de seleção de RadioBox -->
function SetHelp(txt) { help.innerText = txt ; }
function FormataDado(campo,tammax,pos,teclapres){
	var tecla = teclapres.keyCode;
	vr = document.form.campo.value;
	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 ( tecla == 8 || tecla == 88 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){
	 		campo.value = vr ;}
		if ( tam > pos && tam <= tammax ){
			campo.value = vr.substr( 0, tam - pos ) + '-' + vr.substr( tam - pos, tam );}
	}
	//alert("campo: " + document.form[campo+1].name);
	if ( !teclapres.shiftKey && tecla == 9 && document.form[campo+1].name == "senhaConta" && document.applets['tclJava'] ){
		//alert("aki 1");
			document.applets['tclJava'].setFocus();
	}
}
function formataValorPreco(num) {
 return eval(Math.round(num*100)/100).toString().replace('.',',');
}

function FormataValor(campo,tammax,teclapres) {
	var tecla = teclapres.keyCode;
	vr = campo.value;
	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 ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		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 <= 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 ) ;}
	}
		
	for (var ct = 0; ct < document.form.elements.length; ct++) {
		if (document.form.elements[ct].name == document.form.elements[campo].name) {
			if ( !teclapres.shiftKey && tecla == 9 && document.form.elements[ct+1] && document.form.elements[ct+1].name == "senhaConta" && document.applets['tclJava'] ){
				document.applets['tclJava'].setFocus();
			}	
		}
	}
}

function SaltaCampo (campo,prox,tammax,teclapres){
	var tecla = teclapres.keyCode;
	vr = campo.value;
	if( tecla == 109 || tecla == 188 || tecla == 110 || tecla == 111 || tecla == 223 || tecla == 108 ){
		campo.value = vr.substr( 0, vr.length - 1 ); }
	else{
	 	vr = vr.replace( "-", "" );
	 	vr = vr.replace( "/", "" );
	 	vr = vr.replace( "/", "" );
	 	vr = vr.replace( ",", "" );
	 	
	 	tam = vr.length;	
		
	 	if (tecla != 0 && tecla != 9 && tecla != 16 && tecla != 144 ){
		
			if ( tam == tammax ){
				if ( prox == "senhaConta" || (document.form.elements[prox] && document.form.elements[prox].name == "senhaConta"))
				{
					if ( document.applets['tclJava'] )
						document.applets['tclJava'].setFocus();
					else if ( document.form.senhaConta )
						document.form.senhaConta.focus();
				}
				else if ( document.form[prox] )
					document.form[prox].focus();
			}
		}
	}
}
function results(campo)
  {
	var b = 0
	var a = 0
	var x
	
	//Atribui ao 'x' um valor lógico
	x = campo.checked

	//Condição para um único RadioBox
	if (x == false)
	{
		alert("Selecione uma opção")
        return false
	}
	
	//Condição para mais de um RadioBox
	if(campo.length > 1)
	{
	  while(a<campo.length)
	  {
	 	  if(campo[a].checked)
		  {
		  	b = 1
			break
		  }
		  a++
	  }
	  if(b == 0)
	  {

	      alert("Selecione uma opção")
 	      return false
	  }
	}
    
	}
// mascaras
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++;
          }}
      }
    
      //alert(valorFinal)
      _RefObjeto.value = valorFinal 

  }
  
  //verificador de CPF
function cpf()
{
cpfNum=(document.form.cpf.value);

cpfDig1=cpfNum.slice(8);   a1=eval(cpfDig1);
cpfDig2=cpfNum.slice(7,8); a2=eval(cpfDig2);
cpfDig3=cpfNum.slice(6,7); a3=eval(cpfDig3);
cpfDig4=cpfNum.slice(5,6); a4=eval(cpfDig4);
cpfDig5=cpfNum.slice(4,5); a5=eval(cpfDig5);
cpfDig6=cpfNum.slice(3,4); a6=eval(cpfDig6);
cpfDig7=cpfNum.slice(2,3); a7=eval(cpfDig7);
cpfDig8=cpfNum.slice(1,2); a8=eval(cpfDig8);
cpfDig9=cpfNum.slice(0,1); a9=eval(cpfDig9);

cpfPriDig=(a1*9+a2*8+a3*7+a4*6+a5*5+a6*4+a7*3+a8*2+a9)%11;
if(cpfPriDig==10){cpfPriDig=0;}
cpfSegDig=(cpfPriDig*9+a1*8+a2*7+a3*6+a4*5+a5*4+a6*3+a7*2+a8)%11;
if(cpfSegDig==10){cpfSegDig=0;}
cpfDV=cpfPriDig*10+cpfSegDig;
if(cpfDV==0){cpfDV="00";}
if(cpfDV>0&&cpfDV<10){cpfDV="0"+cpfDV;}

if(document.form.dv.value!=cpfDV){
	alert("CPF inválido!");
	document.form.cpf.focus() <!--focus deixa o cursor no textarea correspondente-->
	return false <!--retorna falso-->
	}
else  return true
}

function limpaCampo(campo,vlrInicial){
	if(campo.value == vlrInicial){
		campo.value = "";
	}
}

function veCampoVazio(campo,vlrInicial){
	if(campo.value == ""){
		campo.value = vlrInicial;
	}
}

//verifica se campo está com o valor inicial ou campo está com nada escrito 
function validaCampoInicial(campo,valorInicial,mensagem)
{
	if(campo.value == "")
	{
		alert(mensagem);
		campo.focus();
		return false;
	}
	else if(campo.value == valorInicial)
	{
		alert("Digite uma palavra-chave no campo de busca.")
		campo.focus();
		return false;
	}
	else
	{
		return true;
	}
}

/**
* Javascript prototypes - String.pad() and Number.format()
* Carlos Reche (carlosreche@yahoo.com)
*/
String.PAD_LEFT  = 0;
String.PAD_RIGHT = 1;
String.PAD_BOTH  = 2;

String.prototype.pad = function(size, pad, side) {
  var str = this, append = "", size = (size - str.length);
  var pad = ((pad != null) ? pad : " ");
  if ((typeof size != "number") || ((typeof pad != "string") || (pad == ""))) {
    throw new Error("Wrong parameters for String.pad() method.");
  }
  if (side == String.PAD_BOTH) {
    str = str.pad((Math.floor(size / 2) + str.length), pad, String.PAD_LEFT);
    return str.pad((Math.ceil(size / 2) + str.length), pad, String.PAD_RIGHT);
  }
  while ((size -= pad.length) > 0) {
    append += pad;
  }
  append += pad.substr(0, (size + pad.length));
  return ((side == String.PAD_LEFT) ? append.concat(str) : str.concat(append));
}

Number.prototype.format = function(d_len, d_pt, t_pt) 
{
  var d_len = d_len || 0;
  var d_pt = d_pt || ".";
  var t_pt = t_pt || ",";
  if ((typeof d_len != "number")
    || (typeof d_pt != "string")
    || (typeof t_pt != "string")) {
    throw new Error("wrong parameters for method 'Number.format()'.");
  }
  var integer = "", decimal = "";
  var n = new String(this).split(/\./), i_len = n[0].length, i = 0;
  if (d_len > 0) {
    n[1] = (typeof n[1] != "undefined") ? n[1].substr(0, d_len) : "";
    decimal = d_pt.concat(n[1].pad(d_len, "0", String.PAD_RIGHT));
  }
  while (i_len > 0) {
    if ((++i % 3 == 1) && (i_len != n[0].length)) {
      integer = t_pt.concat(integer);
    }
    integer = n[0].substr(--i_len, 1).concat(integer);
  }
  return (integer + decimal);
}

