var linha			= "";
var edtBanco1		= null;
var edtAgencia1		= null;
var edtAgenciaDV1	= null;
var edtConta1		= null;
var edtContaDV1		= null;
var edtCompensacao1	= null;
var edt1Cheque		= null;
var lblCMC71		= null;
var edtAbertura		= null;
var edtBanco2		= null;
var edtAgencia2		= null;
var edtAgenciaDV2	= null;
var edtConta2		= null;
var edtContaDV2		= null;
var edtCompensacao2	= null;
var lblCMC72		= null;

function getVersaoCadastro1ChequesJS() {
	return "1.20080310";
}

function inicializa() {
	edtBanco1		= document.getElementById("edtBanco1");
	edtAgencia1		= document.getElementById("edtAgencia1");
	edtAgenciaDV1	= document.getElementById("edtAgenciaDV1");
	edtConta1		= document.getElementById("edtConta1");
	edtContaDV1		= document.getElementById("edtContaDV1");
	edtCompensacao1	= document.getElementById("edtCompensacao1");
	lblCMC71		= document.getElementById("lblCMC71");
	edt1Cheque		= document.getElementById("edt1Cheque");
	edtAbertura		= document.getElementById("edtAbertura");
	edtBanco2		= document.getElementById("edtBanco2");
	edtAgencia2		= document.getElementById("edtAgencia2");
	edtAgenciaDV2	= document.getElementById("edtAgenciaDV2");
	edtConta2		= document.getElementById("edtConta2");
	edtContaDV2		= document.getElementById("edtContaDV2");
	edtCompensacao2	= document.getElementById("edtCompensacao2");
	lblCMC72		= document.getElementById("lblCMC72");
	
	parent["rodape"].botoes(false);
}
function validaForm() {
	var retorno = confirm(
		"A T E N Ç Ã O\n" +
		"_______________________\n\n" +
		"Verifique os números dos cheques. Em caso de troca de folhas de cheques por rasuras, " +
		"erros, etc., clique em >Cancelar<. Se os números estiverem corretos, clique em >Ok<.\n\n" +
		"CONFIMA OS NÚMEROS DOS CHEQUES?"
	);
	
	if (retorno) {
		var aux = null;
		var auxValue = null;
	
		retorno = (
			validaData("01/" + (aux = edtAbertura).value) &&
			((parseInt(BANCO, 10) == 0) || ((aux = edtBanco1).value == BANCO)) &&
			((parseInt(AGENCIA, 10) == 0) || (AGENCIA.indexOf((aux = edtAgencia1).value) >= 0)) &&
			((parseInt(CONTA, 10) == 0) || ((CONTA.indexOf(auxValue = ((aux = edtConta1).value)) >= 0) || (auxValue.indexOf(CONTA) >= 0))) //&&
//			(((aux = edtAgenciaDV1).value != null) && (aux.value != ""))
		);
		
		var i		= 1;
		while ((retorno) &&  ((aux = document.getElementById("edtCheque" + (i++))) != null)) {
			retorno = (("" + aux.value).length == 6);
		}
		
		if (!retorno) {
			alert("E R R O\n_______________________\n\n" + aux.title);
			try {
				aux.focus();
				aux.select();
			} catch (e) {
			}
		}		
	}

	return retorno;
}
function proximo() {
	retorno = false;

	if (retorno = validaForm()) {
		var form = document.getElementById("frmPrincipal");
		form.action = "cadastropf1FinalizaCheques.jsp";
		form.submit();	
	}
	
	return retorno;
}
function anterior() {
	alert("Não é possivel retornar");
	return true;
}
function atribuiCheques(primeiroCheque) {
	var aux 	= null;
	var i		= 1;
	while ((aux = document.getElementById("edtCheque" + (i++))) != null) {
		var valor = "" + (parseInt(primeiroCheque, 10) + (i -2));
		
		while (valor.length < 6) {
			valor = "0" + valor;
		}	
		
		aux.value = valor;
	}
}
function processaCMC7(label, banco, agencia, conta, cheque, compensacao, abertura) {
	linha = prompt("Informe o CMC7 do cheque", linha);
	
	if (linha != null) {
		var cmc7 = desmembraCMC7(linha);
		
		if (cmc7 != null) {
			label.innerHTML		= linha;		
			banco.value			= cmc7.banco;
			agencia.value		= cmc7.agencia;
			conta.value			= "" + parseInt(cmc7.conta, 10);
			compensacao.value	= cmc7.compensacao;
			if (cheque != null) {
				cheque.value		= cmc7.numeroCheque;
			}
			if (abertura != null) {
				abertura.focus();
			}
			
			atribuiCheques(cmc7.numeroCheque);
		} else if (linha == "") {
			label.innerHTML		= "Informe o CM7";		
			banco.value			= "";
			agencia.value		= "";
			conta.value			= "";
			compensacao.value	= "";
			if (cheque != null) {
				cheque.value		= "";
			}
		}
	} else {
		linha = "";
	}
}
