var EdtDataNascimento	= null;
var EdtRenda			= null;
var EdtCEP				= null;
var cbxAtividade		= null;
var linha				= "";

function getVersaoCDCOperacaoJS() {
	return "1.20081216";
}

function inicializa() {
	EdtDataNascimento	= document.getElementById("EdtDataNascimento");
	EdtRenda			= document.getElementById("EdtRenda");
	EdtCEP				= document.getElementById("EdtCEP");
	cbxAtividade 		= document.getElementById("cbxAtividade");
	document.getElementById("chkCPF").checked = (!document.getElementById("chkCPF").disabled);
	document.getElementById("chkCNPJ").checked = (!document.getElementById("chkCNPJ").disabled);
	setCPF(document.getElementById("chkCPF").disabled);
	setCNPJ(document.getElementById("chkCNPJ").disabled);
}

function validaForm() {
	var aux = null;
	
	var retorno = (
		(
			((document.getElementById("chkCPF").checked) && (isCpf((aux = document.getElementById("EdtCPF")).value))) ||
			((document.getElementById("chkCNPJ").checked) && (isCnpj((aux = document.getElementById("EdtCNPJ")).value)))
		) &&
		(
			(
				(aux.id == "EdtCPF") &&
				(((aux = cbxAtividade).value != null) && (aux.value != "-1"))
			) || 
			(
				(aux.id == "EdtCNPJ") &&
				(((aux = document.getElementById("cbxRamoAtividade")).value != null) && (aux.value != "-1")) &&
				(isCpf((aux = document.getElementById("edtCPFSocio")).value)) &&
				(validaCEP((aux = document.getElementById("edtCEPSocio")).value)) &&
				(validaData((aux = document.getElementById("edtNascimentoSocio")).value))	
			)
		) &&
		(((aux = EdtDataNascimento).value != null) && (validaData(aux.value))) &&//Data de nascimento
		(((aux = EdtRenda).value != null) && (("" + aux.value) != "")) &&//Renda
		(((aux = EdtCEP).value != null) && (("" + aux.value) != "")) &&//CEP
		(
			(!obrigatorioCMC7) ||
			(
				(((aux = document.getElementById("EdtBanco")).value != null) && (("" + aux.value).length == 3)) &&//Banco
				(((aux = document.getElementById("EdtAgencia")).value != null) && (("" + aux.value) != "")) && //AgenciaDV
				(((aux = document.getElementById("EdtConta")).value != null) && (("" + aux.value) != "")) && //ContaDV
				(((aux = document.getElementById("EdtCheque")).value != null) && (("" + aux.value).length == 6)) &&//Cheque
				(((aux = document.getElementById("EdtCompensacao")).value != null) && (("" + aux.value).length == 3)) //Compensacao
			)
		) &&//Banco
		(
		//	(document.getElementById('tr_banco_01').style.visibility == 'hidden') ||
			((!obrigatorioConta) || ((aux = document.getElementById("EdtAbertura")).value != null) && (validaData("01/" + aux.value)))
		) //Data de abertura da conta
	
	);
	
	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 = "validaoperacao.jsp";
		form.submit();	
	}
	
	return retorno;
}
function anterior() {
	alert("Não é possivel retornar");
	return true;
}

function setCPF(desabilita) {
	var edtCPF			= document.getElementById("EdtCPF");
	var cbxAtividade	= document.getElementById("cbxAtividade");
	
	edtCPF.disabled			= desabilita;
	cbxAtividade.disabled	= desabilita;
	
	if (desabilita) {
		edtCPF.value = "";
		cbxAtividade.value = "-1";
	} else {
		edtCPF.focus();
	}
}

function setCNPJ(desabilita) {
	var edtCNPJ				= document.getElementById("EdtCNPJ");
	var edtCPFSocio			= document.getElementById("edtCPFSocio");
	var edtCEPSocio			= document.getElementById("edtCEPSocio");
	var btnCEPSocio			= document.getElementById("btnCEPSocio");
	var edtNascimentoSocio	= document.getElementById("edtNascimentoSocio");
	var cbxRamoAtividade	= document.getElementById("cbxRamoAtividade");
	
	edtCNPJ.disabled			= desabilita;
	edtCPFSocio.disabled		= desabilita;
	edtCEPSocio.disabled		= desabilita;
	btnCEPSocio.disabled		= desabilita;
	edtNascimentoSocio.disabled	= desabilita;
	cbxRamoAtividade.disabled	= desabilita;

	if (desabilita) {
		edtCNPJ.value				= "";
		edtCPFSocio.value			= "";
		edtCEPSocio.value			= "";
		btnCEPSocio.value			= "";
		edtNascimentoSocio.value	= "";
		cbxRamoAtividade.value		= "-1";
	} else {
		edtCNPJ.focus();
	}
}

function setCaixaTextoCPFCNPJ(botaoOpcao) {
	if (botaoOpcao.value == "CPF") {
		setCPF(false);
		setCNPJ(true);
	} else if (botaoOpcao.value == "CNPJ") {
		setCPF(true);
		setCNPJ(false);
	}
	//inibiInfoConta(); Danilo 10/12/2008 Solicitacao 45396
}

function processaLinhaCMC7() {
	if (linha != null) {
		var cmc7 = desmembraCMC7(linha);
		
		if (cmc7 != null) {
			document.getElementById("lblCMC7").innerHTML = linha;

			document.getElementById("lblBanco").innerHTML = cmc7.banco;
			document.getElementById("lblAgencia").innerHTML = cmc7.agencia;
			document.getElementById("lblConta").innerHTML = cmc7.conta;
			document.getElementById("lblCheque").innerHTML = cmc7.numeroCheque;
			document.getElementById("lblCompensacao").innerHTML = cmc7.compensacao;
		
			document.getElementById("EdtBanco").value = cmc7.banco;
			document.getElementById("EdtAgencia").value = cmc7.agencia;
			document.getElementById("EdtConta").value = cmc7.conta;
			document.getElementById("EdtCheque").value = cmc7.numeroCheque;
			document.getElementById("EdtCompensacao").value = cmc7.compensacao;
			document.getElementById("EdtAbertura").focus();
		} else if (linha == "") {
			document.getElementById("lblCMC7").innerHTML = "Informe o CMC7 do campo.";
		
			document.getElementById("lblBanco").innerHTML = linha;
			document.getElementById("lblAgencia").innerHTML = linha;
			document.getElementById("lblConta").innerHTML = linha;
			document.getElementById("lblCheque").innerHTML = linha;
			document.getElementById("lblCompensacao").innerHTML = linha;
		
			document.getElementById("EdtCMC7").value = linha;
			document.getElementById("EdtBanco").value = linha;
			document.getElementById("EdtAgencia").value = linha;
			document.getElementById("EdtConta").value = linha;
			document.getElementById("EdtCheque").value = linha;
			document.getElementById("EdtCompensacao").value = linha;
		}
	} else {
		linha = "";
	}
}

function processaCMC7() {
	linha = prompt("Informe o CMC7 do 1º cheque", "");
	processaLinhaCMC7();
}

function processaCMC7Digitado() {
	linha = document.getElementById("edtCMC7_1").value + document.getElementById("edtCMC7_2").value + document.getElementById("edtCMC7_3").value;
	processaLinhaCMC7();
}

function buscaCEP() {
	window.open("../buscaCEP/busca_cep.htm", "buscaCEP", "resizable=yes,width=350,height=350,top=0,left=0");
}

function consultaReceita() {
	window.open("http://www.receita.fazenda.gov.br/Aplicacoes/ATCTA/cpf/ConsultaPublica.asp", "receita", "resizable=yes,width=750,height=400,top=0,left=0");
}

function inibiInfoConta() {
	if ((obrigatorioConta) || (!document.getElementById("EdtCNPJ").disabled)) {
		document.getElementById('tr_banco_01').style.visibility = 'visible';
		document.getElementById('tr_banco_02').style.visibility = 'visible';
		document.getElementById('tr_banco_03').style.visibility = 'visible';
	} else {
		document.getElementById('tr_banco_01').style.visibility = 'hidden';
		document.getElementById('tr_banco_02').style.visibility = 'hidden';
		document.getElementById('tr_banco_03').style.visibility = 'hidden';
	}
}
