/****************************************************
* Este script possui os seguintes métodos:
* hidelayer(lay) - esconde layer
* function showlayer(lay) - mostra layer
*
*/


var ie4 = (document.all) ? true : false;
var ns4 = (document.layers) ? true : false;
var ns6 = (document.getElementById && !document.all) ? true : false;

//esconde layer
function hidelayer(lay) 
	{
	if (ie4) {document.all[lay].style.visibility = "hidden";}
	if (ns4) {document.layers[lay].visibility = "hide";}
	if (ns6) {document.getElementById([lay]).style.display = "none";}
	}

//mostra layer	
function showlayer(lay) 
	{
	if (ie4) {document.all[lay].style.visibility = "visible";}
	if (ns4) {document.layers[lay].visibility = "show";}
	if (ns6) {document.getElementById([lay]).style.display = "block";}
	}

// Verifica se uma string tem vogais acentuadas
function vogalAcentuada(s) {
	ls = s.toLowerCase();
	if ((ls.indexOf("á")>=0) || (ls.indexOf("à")>=0) || (ls.indexOf("ã")>=0) || (ls.indexOf("â")>=0) || (ls.indexOf("é")>=0) || (ls.indexOf("í")>=0) || (ls.indexOf("ó")>=0) || (ls.indexOf("õ")>=0) || (ls.indexOf("ô")>=0) || (ls.indexOf("ú")>=0) || (ls.indexOf("ü")>=0))
		return true;
}

//-------------------------------------------------------------
//Funções para data
//--------------------------------------------------------------

function eData(dia,mes,ano,nome)
{
	var erro;
	erro='';
			
	if (dia<1 || dia>31){
		erro='O dia do campo ' + nome + ' deve estar entre 1 e 31!\n';
	}
	if (mes<1 || mes>12){
		erro=erro + 'O mês do campo ' + nome + ' deve estar entre 1 e 12!\n';
	}
	else{
		var meses = new Array("","Janeiro","Fevereiro","Março","Abril","Maio","Junho","Julho","Agosto","Setembro","Outubro","Novembro","Dezembro")
		if (((mes==4 || mes==6 || mes==9 || mes==11) && (dia>30))){
			erro=erro + 'O mês ' + meses[mes] + ' do campo ' + nome + ' possui apenas 30 dias!\n';	
		}
		else if (dia > 31){
			erro=erro + 'O mês ' + meses[mes] + ' do campo ' + nome + ' possui apenas 31 dias!\n';	
		}
	}
	if (ano<1900 || ano>2100){
		erro=erro + 'O ano do campo ' + nome + ' deve estar entre 1900 e 2100!\n';
	}		
	else if (mes==2){
		if (ano % 4 > 0 && dia > 28){
			erro=erro + 'O mês fevereiro do ano ' + ano + ' do campo ' + nome + ' possui apenas 28 dias!\n';	
		} 
		else if (dia > 29){
			erro=erro + 'O mês fevereiro do ano ' + ano + ' do campo ' + nome + ' possui apenas 29 dias!\n';	
		}
	}

	if (erro.length>0){
		alert(erro);
		return false;
	}

	return true;

}	

function eAno(ano,nome){
	var erro;
	if (ano<1753 || ano>9999){
		erro='O ano do campo ' + nome + ' está inválido!';
		alert(erro); 
		return false;
	}
	return true;
}


//
// Cálculo de DAC10
//


function dac10 (val) {
var str_final;
var dig;
var mult;
	mult = 2;
	str_final = "";
	soma=0; aux=0; mult = 2;
	str_len = parseInt(val.length);
	str_final_len = parseInt(str_final.length);
//extrai o dígito do número
	dig = str_final.substring(parseInt(str_final_len-1), parseInt(str_final_len));
	str_final = str_final.substring(0, str_final_len-1);
	str_final_len = parseInt(str_final.length);
	if (str_final_len > 0) {
		for (i=1; i<=str_final_len; i++) {
			if ((i-1)%2 != 0) {
				//posição par
				aux = parseInt(str_final.charAt(str_final_len-i));
			} else {
				//posição ímpar
				aux = parseInt(str_final.charAt(str_final_len-i))*mult;
				if (aux > 9) {
					aux = aux.toString();
					aux = parseInt(aux.charAt(0)) + parseInt(aux.charAt(1));
				}
			}
			soma = soma + aux;
		}
		soma = soma.toString();
		soma_len = parseInt(soma.length);
		res = 10 - parseInt(soma.charAt(soma_len-1));
		if (res == 10) {
			res = 0;
		}
	} else {
		//Número inválido!
		return (false);
	}
	if (res != dig) {
		//número inválido
		return (false);
	} else {
		//número correto
		return (true);
	}
}

//
// Retorna falso caso campo nulo ou vazio.
//
function validaCampo( objeto, descricao ) {
	var ret = false

	if ( objeto.value == "" || objeto.value == null || parseFloat( objeto.value ) == 0 ) {
		alert( descricao + " deve ser informado." )
		objeto.focus()
	} else {
		ret = true
	}

	return ret
}

function valor( objeto ) {
	if( objeto.value.indexOf(',') <= 0 ) {
		if( objeto.value.length <= 0 )
			objeto.value = "0,00"
		else
			objeto.value += ",00"
	} else {
		var posV = objeto.value.indexOf(',')
		var posD = objeto.value.substr(posV+1)
		var posA = objeto.value.substr(0,posV)

		if( posD.length < 2 )
			posD += '0'

		objeto.value = posA + "," + posD
	}
}

function validarLimite( msg, objeto, limI, limS ) {
	var ret = false
	var val = objeto.value

	if( val < limI || val > limS )
		alert( msg )
	else
		ret = true

	return ret
}

function defineDialimite( mes, ano ) {
	var ret = 0

	if( mes == 2 ) {
		if( ano % 4 == 0 )
			ret = 29
		else
			ret = 28
	} else if( mes == 1 || mes == 3 || mes == 5 || mes == 7 || mes == 8 || mes == 10 || mes == 12 )
			ret = 31
	else
		ret = 30

	return ret
}

function transformaData( dia, mes, ano ) {

	if( dia < 10 )
		dia = "0" + dia

	if( mes < 10 )
		mes = "0" + mes

	return dia + "/" + mes + "/" + ano
}




/*
Trim: elimina brancos a esquerda e a direita de uma string

Entrada:
	String s: string a ser tratada

Saida:
	String tratada
*/


function trim(s) {
	s = s.replace(/^\s+/, "")
	s = s.replace(/\s+$/, "")
	return s;
}



/*
Salta: função para alterar o foco de um campo text para o campo seguinte. A função não move 
o foco para campos escondidos (hidden).

Entrada:
	String form: nome do objeto form
	String campo: nome do campo corrente no form
	int maxlen: inteiro indicando o tamanho máximo do campo corrente

Saida: nenhuma	
*/

function salta(form, campo, maxlen) {
	form = "this.window.document."+form;
	var nr_form = this.window.document.forms.length;
	var aux = form+".elements['" + campo + "'].value.length";
	if (maxlen == eval(aux)) {
		var nr = eval(form+".elements.length-1;");
		for (i=0; i<nr; i++) {
			if ((eval(form).elements[i].name == campo) && ((i+1) <= nr)) {
				for (k=i+1; k<=nr; k++) {
					aux = eval(form).elements[k].type;
					aux = aux.toLowerCase();
					if (aux != 'hidden') {
						eval(form).elements[k].focus();
						break;
					}
				}
				break;
			}
		}
	}
}


/*
Salta: função para alterar o foco de um campo não text para o campo seguinte. A função não move 
o foco para campos escondidos (hidden).

Entrada:
	String form: nome do objeto form
	String campo: nome do campo corrente no form
	int maxlen: inteiro indicando o tamanho máximo do campo corrente
*/

function saltaComboChk(form, campo){
	form = "this.document."+form;
	var nr = eval(form).elements.length;
	for (i=0; i<nr; i++) {
		if ((eval(form).elements[i].name == campo) && ((i+1) < nr)) {
			for (k=i+1; k<nr; k++) {
				aux = eval(form).elements[k].type;
				aux = aux.toLowerCase();
				if (aux != 'hidden') {
					eval(form).elements[k].focus();
					break;
				}
			}
			break;
		}
	}	
}


/*
isNumeric: testa se uma String possui apenas caracteres numéricos.

Entrada:
	String valor: String a ser testada

Saida:
	Boolean false: caso a String esteja vazia ou com caracteres não numericos
	Boolean true: caso a String contenha uma sequencia apenas de caracteres numericos, 
	seguidos ou precedidos de espaços.
*/

function isNumeric(valor){
	valor = trim(valor);
	rExp = /^\d+$/;

	results = valor.search(rExp);

	if (results == -1) {
		return false;
	}
	else{
		return true;
	}
}

/*
parseFloat: converte uma String que representa um Float (NNNN,NN) em uma variável do tipo Float

Entrada:
	String valor: String a ser convertida

Saida:
	String vazia em caso de valor inválido
	float com o valor correspondente ao valor em caso de String válida
*/

function parseFloat(valor){
	valor = trim(valor);
	valor = valor.replace(/\./,'');
	valor = valor.replace(/,/,'.');
	valor = valor.replace(/[ ]+/,'');    
	if (valor != ""){
		if (isNaN(valor))
	    		return("");
		else
    			return(eval(valor));
	}
	else{
 		return("");
	}
}


/*
parseNumeric: elimina caracteres não numéricos em uma String

Entrada:
	String valor: String a ser tratada

Saida:
	String tratada
*/

function parseNumeric(str) {
	var str_aux
	var tam;
	str_aux = "";
	tam = str.length;
	for (i=0;i<tam;i++){
		if (!isNaN(str.charAt(i))) {
			str_aux = str_aux+str.charAt(i);
		}
	}
	return str_aux;
}


/*
isFloat: testa se uma String representa o valor de um Float.

Entrada:
	String s: String a ser testada

Saida:
	Boolean false: caso a String esteja vazia ou com caracteres não numericos
	Boolean true: caso a String contenha uma sequencia apenas de caracteres numericos, 
	seguidos ou precedidos de espaços.
*/

function isFloat(s){
	s = trim(s);

	var i;
	if (isEmpty(s)) return false;
	valor = parseFloat(s);
	if(valor == "") return false;
	return true;
}



/*
warnInvalid: mostra uma mensagem de alerta ao usuário e move o foco para um campo.

Entrada:
	Object theField: Campo para onde o foco deve ser movido
	String warnText: texto da mensagem de alerta

Saida:	nenhuma
*/

function warnInvalid (theField, warnText){
	if ((theField.type != "radio") && (theField.type != "checkbox"))
		theField.focus()
	alert(warnText)
	return false
}


/*
isEmpty: testa se uma String é vazia ou está preenchida apenas com espaços.

Entrada:
	String s: String a ser testada

Saida:	
	Boolean false: caso a String esteja preenchida
	Boolean true: caso a String esteja vazia ou apenas com espaços.
*/

function isEmpty(s) {

	s = trim(s);
	
	return ((s == null) || (s.length == 0));
	
	
	
}


function formatData(sdia, smes, sano){
if(eval(sdia) < 10){
 sdia = '0' + eval(sdia);
}
if(eval(smes) < 10){
 smes = '0' + eval(smes);
}

return (sano+smes+sdia);
}

function formatDataAbertura(smes, sano){
if(eval(smes) < 10){
 smes = '0' + eval(smes);
}
return (smes+sano);
}

function formatDataIMS(sdia, smes, sano){
if(eval(sdia) < 10){
 sdia = '0' + eval(sdia);
}
if(eval(smes) < 10){
 smes = '0' + eval(smes);
}

return (sdia+smes+sano);
}

// Retorna o código ASC do caracter passada por parâmetro
function asc(achar){
var n=0;
var ascstr = makeCharsetString()
for(i=0;i<ascstr.length;i++){
 if(achar==ascstr.substring(i,i+1)){
    n=i;
    break;
 }
}
return n+32
}

function warnInvalidSelect (theField, warnText){
	theField.focus()
	alert(warnText)
	return false
}

function isSelected(box) {
	return (box.selectedIndex > 0);
}

function verificaCEP(cep, compl){
	iCep 			= parseNumeric(cep);
	iCepCompl 	= parseNumeric(compl);

	if((iCep.length == 5 && iCepCompl.length == 3)){
		return true;
	}
	else{
		return false;
	}
}

function verificaDDD(ddd){
	iDdd 			= parseNumeric(ddd);

	if ((iDdd.length >= 2) && (iDdd.length <= 3)){
		return true;
	}
	else{
		return false;
	}
}

function verificaTel(tel){
	iTel 			= parseNumeric(tel);

	if ((iTel.length >= 7) && (iTel.length <= 8)){
		return true;
	}
	else{
		return false;
	}
}

function verificaEmail(email){
	results = email.search(/^[a-z0-9._-]+@[a-z0-9._-]+$/gi);
	if(results >= 0) return true;
	else return false;
}

function verificaRG(rg){
	aux = rg.replace(/[^a-z\d]/gi, "");
	if(aux.length < 5){
		return false;
	} else{
		return true;
	}
}

//Verifica o tamanho. A variável minlen, contêm o mínimo do tamanho que o campo pode ter
function checkLength(form, campo, minlen) {
	scampo = "document."+form+"."+campo+".value";		
	if ((eval(scampo).length) >= minlen){
		return true;
	}
	else{
		return false;
	}
} 

//Verifica se é numérico
function notNumeric(form, campo) {
	scampo = "document."+form+"."+campo+".value";		
	if (isNaN(eval(scampo))){
		return true;
	}
	else{
		return false;
	}
}

//Arredonda valor
function roundValor(valor){		

	resultado	= "";
	aux			= 0.01;
	ini			= valor.indexOf(",") + 3;
	fim			= valor.indexOf(",") + 4;

	if (isFloat(valor)){			
		if (valor.indexOf(",") > 0) {
			if (valor.substring(ini, fim) != ""){
				if (parseInt(valor.substring(ini, fim)) <= 5){
					resultado = valor.substring(0, fim - 1);
				}
				else{
					resultado = valor.substring(0, fim - 1);	
					aux = (1 + parseFloat(parseFloat(resultado)) * 100) / 100;	
					resultado = aux;
				}
			}
			else{					
				if (valor.substring(ini - 2, fim - 2) == ""){
					resultado = valor + "00";
				}
				else{
					if (valor.substring(ini - 1, fim - 1) == ""){
						resultado = valor + "0";
					}
					else{	
						resultado = valor;
					}
				}
			}
		}
		else{
			resultado = valor + ".00";
		}
	}
	else{
		resultado = valor + "0.00";
	}

	resultado = "" + resultado;
	return resultado.replace(".", ",");
}



// Função para habilitar ou desabilitar o campo "X", ou seja, 
// quando selecionado a opção "Y" desabilitar o campo "X"
// quando não-selecionado a opção "Y" abilitar o campo "X"
// @param CampoCheck campo a ser verificado
// @param CampoHabDes campo a ser abilitado/desabilitado

function habilitDesabilitCampo(CampoCheck,CampoHabDes){
	if (CampoCheck.checked ){
		CampoHabDes.disabled = true;
	} else {
		CampoHabDes.disabled = false;
	}
}


function setaCombo(campo, valor){
	for(i = 0; i < campo.length; i++){
		if(campo[i].value == valor){
			campo.selectedIndex = i;
			break;
		}
	}
}


/**
 * PROTÓTIPOS:
 * método String.lpad(int pSize, char pCharPad)
 * método String.trim()
 *
 * String unformatNumber(String pNum)
 * String formatCpfCnpj(String pCpfCnpj, boolean pUseSepar, boolean pIsCnpj)
 * String dvCpfCnpj(String pBase, boolean pIsCnpj)
 * boolean isCpf(String pCpf)
 * boolean isCnpj(String pCnpj)
 * boolean isCpfCnpj(String pCpfCnpj)
 */


var NUM_DIGITOS_CNPJ = 14;
var NUM_DIGITOS_CPF  = 11;


/**
 * Adiciona método lpad() à classe String.
 * Preenche a String à esquerda com o caractere fornecido,
 * até que ela atinja o tamanho especificado.
 */
String.prototype.lpad = function(pSize, pCharPad)
{
	var str = this;
	var dif = pSize - str.length;
	var ch = String(pCharPad).charAt(0);
	for (; dif>0; dif--) str = ch + str;
	return (str);
} //String.lpad


/**
 * Adiciona método trim() à classe String.
 * Elimina brancos no início e fim da String.
 */
String.prototype.trim = function()
{
	return this.replace(/^\s*/, "").replace(/\s*$/, "");
} //String.trim


/**
 * Elimina caracteres de formatação e zeros à esquerda da string
 * de número fornecida.
 * @param String pNum
 *      String de número fornecida para ser desformatada.
 * @return String de número desformatada.
 */
function unformatNumber(pNum)
{
	return String(pNum).replace(/\D/g, "").replace(/^0+/, "");
} //unformatNumber


/**
 * Formata a string fornecida como CNPJ ou CPF, adicionando zeros
 * à esquerda se necessário e caracteres separadores, conforme solicitado.
 * @param String pCpfCnpj
 *      String fornecida para ser formatada.
 * @param boolean pUseSepar
 *      Indica se devem ser usados caracteres separadores (. - /).
 * @param boolean pIsCnpj
 *      Indica se a string fornecida é um CNPJ.
 *      Caso contrário, é CPF. Default = false (CPF).
 * @return String de CPF ou CNPJ devidamente formatada.
 */
function formatCpfCnpj(pCpfCnpj, pUseSepar, pIsCnpj)
{
	if (pIsCnpj==null) pIsCnpj = false;
	if (pUseSepar==null) pUseSepar = true;
	var maxDigitos = pIsCnpj? NUM_DIGITOS_CNPJ: NUM_DIGITOS_CPF;
	var numero = unformatNumber(pCpfCnpj);

	numero = numero.lpad(maxDigitos, '0');
	if (!pUseSepar) return numero;

	if (pIsCnpj)
	{
		reCnpj = /(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})$/;
		numero = numero.replace(reCnpj, "$1.$2.$3/$4-$5");
	}
	else
	{
		reCpf  = /(\d{3})(\d{3})(\d{3})(\d{2})$/;
		numero = numero.replace(reCpf, "$1.$2.$3-$4");
	}
	return numero;
} //formatCpfCnpj


/**
 * Calcula os 2 dígitos verificadores para o número-base pBase de
 * CNPJ (12 dígitos) ou CPF (9 dígitos) fornecido. pIsCnpj é booleano e
 * informa se o número-base fornecido é CNPJ (default = false).
 * @param String pBase
 *      String do número-base (SEM dígitos verificadores) de CNPJ ou CPF.
 * @param boolean pIsCnpj
 *      Indica se a string fornecida é de um CNPJ.
 *      Caso contrário, é CPF. Default = false (CPF).
 * @return String com os dois dígitos verificadores.
 */
function dvCpfCnpj(pBase, pIsCnpj)
{
	if (pIsCnpj==null) pIsCnpj = false;
	var i, j, k, soma, dv;
	var cicloPeso = pIsCnpj? 8: NUM_DIGITOS_CPF;
	var maxDigitos = pIsCnpj? NUM_DIGITOS_CNPJ: NUM_DIGITOS_CPF;
	var calculado = formatCpfCnpj(pBase, false, pIsCnpj);
	calculado = calculado.substring(2, maxDigitos);
	var result = "";

	for(j = 1; j <= 2; j++)
	{
		k = 2;
		soma = 0;
		for (i = calculado.length-1; i >= 0; i--)
		{
			soma += (calculado.charAt(i) - '0') * k;
			k = (k-1) % cicloPeso + 2;
		}
		dv = 11 - soma % 11;
		if (dv > 9) dv = 0;
		calculado += dv;
		result += dv
	}

	return result;
} //dvCpfCnpj


/**
 * Testa se a String pCpf fornecida é um CPF válido.
 * Qualquer formatação que não seja algarismos é desconsiderada.
 * @param String pCpf
 *      String fornecida para ser testada.
 * @return <code>true</code> se a String fornecida for um CPF válido.
 */
function isCpf(pCpf)
{
	var numero = formatCpfCnpj(pCpf, false, false);
	var base = numero.substring(0, numero.length - 2);
	var digitos = dvCpfCnpj(base, false);
	var algUnico, i;

	// Valida dígitos verificadores
	if (numero != base + digitos) return false;

	/* Não serão considerados válidos os seguintes CPF:
	 * 000.000.000-00, 111.111.111-11, 222.222.222-22, 333.333.333-33, 444.444.444-44,
	 * 555.555.555-55, 666.666.666-66, 777.777.777-77, 888.888.888-88, 999.999.999-99.
	 */
	algUnico = true;
	for (i=1; i<NUM_DIGITOS_CPF; i++)
	{
		algUnico = algUnico && (numero.charAt(i-1) == numero.charAt(i));
	}
	return (!algUnico);
} //isCpf

function bloquearDigitacaoString()
	{
	if (event.keyCode == 32){
		event.returnValue = 0
	}
	if (event.keyCode > 57)
		{
		if (event.keyCode < 96)
			event.returnValue = 0
		if (event.keyCode > 105)
			event.returnValue = 0
		}
	}

//--------------------------------------
//Bankline: Pula campos no formulário
//--------------------------------------
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) {
	 //quem.selected;
	 //VerifiqueTAB=false;
}

function ChecarTAB() {
	//VerifiqueTAB=true;
}

function fctVerificaCampoDecimal(objEvent, objElement){
					
	var keyCode  = objEvent.keyCode;                // Código da tecla pressionada.
	var caracter = String.fromCharCode(keyCode);    // Caracter que representa o código.

	if( isNaN( caracter ) && ".,".indexOf( caracter ) == -1  ) event.returnValue = false;
	if( keyCode == 32 ) event.returnValue = false;  // Não permite digitar espaço (" ").
	if( keyCode == 46 ) event.keyCode = 44;	        // Trocar ponto por virgula.
	// Só permite digitar uma virgula em cada campo.
	if( objElement.value.indexOf(",") != -1 && ( keyCode == 44 || keyCode == 46 ) ) event.returnValue = false;

}

function AutoTab(objElement) {
	if(objElement.value.length >= objElement.maxLength) {
		objElement.blur();
	}
}

function fctValidaCampoDecimal(objElement, intInteiros, intDecimais)
	{

		if ( (objElement.value.indexOf(",") == -1) && (objElement.value.length > intInteiros) )
		{
			alert("Valores inteiros podem ter no máximo "+ intInteiros +" digitos.");
			objElement.focus();
			objElement.select();
			return false;
		}
		if ( objElement.value.indexOf(",") > intInteiros )
		{
			alert("A parte inteira pode ter no máximo "+ intInteiros +" digitos.");
			objElement.focus();
			objElement.select();
			return false;
		}
		if ( objElement.value.indexOf(",") != -1 )
		{
			if ( objElement.value.length - (objElement.value.indexOf(",") + 1) > intDecimais )
			{
				alert("A parte decimal pode ter no máximo "+ intDecimais +" digitos.");
				objElement.focus();
				objElement.select();
				return false;
			}
			
			for  ( i = 0; i < objElement.maxLength; i++ )
			{
				if ( objElement.value.length - (objElement.value.indexOf(",") + 1) < intDecimais )
					objElement.value = objElement.value + "0";
									
				//if ( objElement.value.indexOf(",") < intInteiros )
				//	objElement.value = "0" + objElement.value;
			}
							
							
			objElement.value = objElement.value.slice(0, objElement.maxLength);
			for( var i=(getIndex(objElement)+1); i < objElement.form.length; i++ ){
				if( objElement.form[i].type != "hidden" && objElement.form[i].readOnly == false){				
					try {
						objElement.form[i].focus();
						i = objElement.form.length; //abortar loop
					}
					catch(e) {}
				}
			}
		}
		if ( objElement.value != "" && objElement.value.indexOf(",") == -1 )
		{
			/* Completa a parte inteira com zeros...
			for  ( i = 0; i < intInteiros; i++ )
			{
				if ( objElement.value.length < 3 )
					objElement.value = "0" + objElement.value;
			}*/
			
			if (intDecimais > 0)
			{
				objElement.value = objElement.value + ",0" ;
				for  ( i = 0; i < intDecimais; i++ )
				{
					if ( objElement.value.length - (objElement.value.indexOf(",") + 1) < intDecimais )
						objElement.value = objElement.value + "0";
				}				
			}
							
			objElement.value = objElement.value.slice(0, objElement.maxLength);
			for( var i=(getIndex(objElement)+1); i < objElement.form.length; i++ ){
				if( objElement.form[i].type != "hidden" && objElement.form[i].readOnly == false){				
					try {
						objElement.form[i].focus();
						i = objElement.form.length; //abortar loop
					}
					catch(e) {}
				}
			}
		}
	}
	
	function setaRadio(cpoRadio, valor){

		tamRadio =  cpoRadio.length;

		for (i=0; i<tamRadio; i++){
			
			if (cpoRadio[i].value == valor){
				cpoRadio[i].checked = true;
			}			
		}
	}
	
	function PlataformaRevenda(){
		var busca = window.open('/credline/consorcio/popup/plataforma.jsp', 'combos', 'scrolbars=yes,resizable=no,status=yes,width=360,height=200');
	}
	
	function verificaData(Day, Month, Year){
	
      if(!isNumeric(Month)) {
         return false;
      }
      if (eval(Month) > 12){
         return false;
      }
      if(!isNumeric(Day)) {
         return false;
      }

       if ((eval(Month) == 4) || (eval(Month == 6)) || (eval(Month == 9)) ||(eval(Month == 11))){
         if (eval(Day) > 30) return false;
       }
      if (eval(Month) == 2){
         if (((eval(Year)%4) != 0) && (eval(Day) > 28)){
           return false;
         }
         else{
            if (eval(Day) > 29) return false;
         }
      }
      if (eval(Day) > 31){
         return false;
      }
      if(!isNumeric(Year)) {
         return false;
      }
      if(eval(Year) < 1900) {
         return false;
      }
      
      return true;
   }
   
   function validaNumero(valor){
   		//Tirar esta função
   }
   //Função que verifica se o campo só tem números e -
//Específico para o campo telefone
		function isNum(str){
		var checkOK = "0123456789--";
			var checkStr = str;
			var validaOK = true;
			for (i=0;i<checkStr.length;i++){
				ch=checkStr.charAt(i);
				for (j=0;j<checkOK.length;j++)
					if (ch==checkOK.charAt(j))
						break;
				if (j==checkOK.length){
					validaOK = false;
					break;
				}
			}
			if (!validaOK){
				return false;
			}
			else{
				return true;
			}
		}
		
   //Função que verifica se o campo só tem números e -
//Específico para o campo DDD
		function isNumerico(str){
			var checkOK = "0123456789";
			var checkStr = str;
			var validaOK = true;
			for (i=0;i<checkStr.length;i++){
				ch=checkStr.charAt(i);
				for (j=0;j<checkOK.length;j++)
					if (ch==checkOK.charAt(j))
						break;
				if (j==checkOK.length){
					validaOK = false;
					break;
				}
			}
			if (!validaOK){
				return false;
			}
			else{
				return true;
			}
		}

//Função que verifica se o campo só tem números e -
//Específico para o campo telefone
		function isNum(str){
		var checkOK = "0123456789--";
			var checkStr = str;
			var validaOK = true;
			for (i=0;i<checkStr.length;i++){
				ch=checkStr.charAt(i);
				for (j=0;j<checkOK.length;j++)
					if (ch==checkOK.charAt(j))
						break;
				if (j==checkOK.length){
					validaOK = false;
					break;
				}
			}
			if (!validaOK){
				return false;
			}
			else{
				return true;
			}
		}
		
   
   function verificaCNPJ (umCNPJ) {

      var mask = new String("99.999.999/9999-99");
      var temp = new String(umCNPJ);
      var cnpj = new String();

      // Verifica o tamanho

      if ( temp.length != 14 && temp.length != 18 ) return false;

      // Verifica máscara, se foi digitado com a máscara
      if ( temp.length != 14 )
         for (var i = 0; i < mask.length; i++)
            if ( mask.charAt(i) != "9" && mask.charAt(i) != temp.charAt(i) )
               return false;  

      // Cria uma nova string, somente com os números do CNPJ
      for (i = 0; i < temp.length; i++)
         if ( !isNaN( temp.charAt(i) ) && temp.charAt(i) != " " )
            cnpj += temp.charAt(i);

      if ( cnpj.length != 14) return false;

      // Verifica se o valor do CNPJ é válido
      var total1 = cnpj.charAt(0) * 5 + cnpj.charAt(1) * 4 + cnpj.charAt(2) * 3 +
               cnpj.charAt(3) * 2 + cnpj.charAt(4) * 9 + cnpj.charAt(5) * 8 +
               cnpj.charAt(6) * 7 + cnpj.charAt(7) * 6 + cnpj.charAt(8) * 5 +
               cnpj.charAt(9) * 4 + cnpj.charAt(10) * 3 + cnpj.charAt(11) * 2;

      var dv1;
      if ( total1 % 11 > 1 ) dv1 = 11 - total1 % 11;
      else dv1 = 0;

      var total2 = cnpj.charAt(0) * 6 + cnpj.charAt(1) * 5 + cnpj.charAt(2) * 4 +
               cnpj.charAt(3) * 3 + cnpj.charAt(4) * 2 + cnpj.charAt(5) * 9 +
               cnpj.charAt(6) * 8 + cnpj.charAt(7) * 7 + cnpj.charAt(8) * 6 +
               cnpj.charAt(9) * 5 + cnpj.charAt(10) * 4 + cnpj.charAt(11) * 3 +
               dv1 * 2;

      var dv2;
      if ( total2 % 11 > 1 ) dv2 = 11 - total2 % 11;
      else dv2 = 0;

      if ( dv1 == cnpj.charAt(12) && dv2 == cnpj.charAt(13) ) return true;
      else return false;
   }   
      
   	function colocaCasasDecimais(objeto, quantasCasas) {
   	
		if(objeto.value.indexOf(',') <= 0){		
			if(objeto.value.length <= 0){
				
				objeto.value = "0,";
				for (i=0; i<quantasCasas; i++){
					objeto.value = objeto.value + "0";
				}				
			}
			else{
				objeto.value = objeto.value + ",";
				for (i=0; i<quantasCasas; i++){
					objeto.value = objeto.value + "0";
				}
			}
		}
		else{
			var posV = objeto.value.indexOf(',')
			var posD = objeto.value.substr(posV+1)
			var posA = objeto.value.substr(0,posV)

			if(posD.length < 5){
				
				for (i=0; i<quantasCasas; i++){
					
					if (posD.substring(i, i+1) == ""){
						posD += '0';	
					}
				}
			}
			
			objeto.value = posA + "," + posD;
		}
	}
