function getVersaoCDCSimuladorJS() {
	return "1.20080208";
}

function simular() {
	var campo	= null;
	
	var validar	= (
		(((campo = document.getElementById("cbxProduto")) != null) && (campo.value != "0")) &&
		(((campo = document.getElementById("cbxTabela")) != null) && (campo.value != "0")) &&
		(
			((document.getElementById("rdValor1").checked) && ((campo = document.getElementById("edtValorBem")) != null) && (campo.value != "")) ||
			((document.getElementById("rdValor2").checked) && ((campo = document.getElementById("edtValorParcela")) != null) && (campo.value != ""))
		)
	);
	
	if (validar) {
		var aux 			= document.getElementById("EdtDataRetorno").value;
		var dia				= parseInt(aux.substr(0,2), 10);
		var vencimento		= new Date(parseInt(aux.substr(6, 4), 10), parseInt(aux.substr(3, 2), 10) -1, dia, 0, 0, 0, 0);
		var hoje			= new Date(HOJE);
		var carencia_maxima	= incDay(hoje, CARENCIA_MAXIMA);
		var carencia_minima	= incDay(hoje, CARENCIA_MINIMA);

//		if (validar = ((dia <= 28) && (vencimento.getTime() >= carencia_minima.getTime()) && (vencimento.getTime() <= carencia_maxima.getTime()))) {
		if (validar = (
			(vencimento.getTime() >= carencia_minima.getTime()) &&
			(vencimento.getTime() <= carencia_maxima.getTime())
		)) {
			document.getElementById("frmPrincipal").submit();
			desabilitaCampos(true);
		} else {
			var msg =	//"O primeiro vencimento está fora da carência ou não esta entre o dia 1 a 28.\n\n" +
						"1º Vencimento: " + vencimento.getDate() + "/" + (vencimento.getMonth() +1) + "/" + vencimento.getFullYear() + "\n\n" +
						"Hoje : " + hoje.getDate() + "/" + (hoje.getMonth() +1) + "/" + hoje.getFullYear() + "\n\n" +
						"Carencia Máxima: " + carencia_maxima.getDate() + "/" + (carencia_maxima.getMonth() +1) + "/" + carencia_maxima.getFullYear() + "\n\n" +
						"Carencia Mínima: " + carencia_minima.getDate() + "/" + (carencia_minima.getMonth() +1) + "/" + carencia_minima.getFullYear();
			alert(msg);
		}
	} else {
		alert("Campos obrigatórios não foram preencidos!");
		campo.focus();
	}
}

function desabilitaCampos(desabilitar) {
	var formulario	= document.getElementById("frmPrincipal");
	var i			= 0;
	
	for (i = (formulario.elements.length -1); i >= 0; i--) {
		if (formulario.elements[i].name == "edtValorEntrada") {
			if (document.getElementById("rdEntrada3").checked) {
				formulario.elements[i].disabled	= desabilitar;
			} else {
				formulario.elements[i].disabled	= true;
			}
		} else if (formulario.elements[i].name == "edtValorBem") {
			if (document.getElementById("rdValor1").checked) {
				formulario.elements[i].disabled	= desabilitar;
			} else {
				formulario.elements[i].disabled	= true;
			}
		} else if (formulario.elements[i].name == "edtValorParcela") {
			if (document.getElementById("rdValor2").checked) {
				formulario.elements[i].disabled	= desabilitar;
			} else {
				formulario.elements[i].disabled	= true;
			}
		} else if (formulario.elements[i].name != "BtnReiniciar") {
			formulario.elements[i].disabled	= desabilitar;
		}
	}
}

function atribuiValores(prestacao) {
	if (prestacao != null) {
		document.getElementById("ValorIOF").innerHTML			= prestacao.valorIOF;
		document.getElementById("ValorTAC").innerHTML			= prestacao.valorTAC;
		document.getElementById("ValorFinanciado").innerHTML	= prestacao.valorFinanciado;
		document.getElementById("ValorParcela").innerHTML		= prestacao.valorParcela;
		document.getElementById("QtdParcela").innerHTML			= prestacao.parcelas;
		document.getElementById("ValorOperacao").innerHTML		= prestacao.saldoDevedor;
		document.getElementById("ValorCompra").innerHTML		= prestacao.valorCompra;
		document.getElementById("ValorEntrada").innerHTML		= prestacao.valorEntrada;
		document.getElementById("PrimeiroVencimento").innerHTML	= prestacao.primeiroVencimento;
		document.getElementById("UltimoVencimento").innerHTML	= prestacao.ultimoVencimento;
		document.getElementById("liquidoOperacao").innerHTML	= prestacao.liquidoOperacao;
		
		//MONTA A LINHA DO VALOR LIQUIDO
		if(prestacao.liquidoOperacao != ""){
			document.getElementById("td1").innerHTML				= "Vlr Liquido";
			document.getElementById("td2").innerHTML				= "(=)";
		}
	}
}

function resetSimulacao() {
	parent.document.getElementById("resultado").src = "resultado.htm";
	desabilitaCampos(false);
//	document.getElementById("cbxProduto").focus();
	atribuiValores(new parcela("0,00", "0,00", "0,00", "0,00", "0,00", "0", "0,00", "0,00", "00/00/0000", "00/00/0000", ""));
	//LIMPA A LINHA DO VALOR LIQUIDO
	document.getElementById("td1").innerHTML	= "";
	document.getElementById("td2").innerHTML	= "";
	
	document.getElementById("frmPrincipal").reset();
	marcaValor(document.getElementById("rdValor1"));
	marcaEntrada(document.getElementById("rdEntrada3"));
	tabela(-1);
	try {
		document.getElementById("cbxProduto").focus();
	} catch (e1) {
		
	}
}
function marcaEntrada(opcao) {
	var edtValorEntrada = document.getElementById("edtValorEntrada");
	
	document.getElementById("BtnDataChama").disabled = (opcao.value == "2");
	
	if (edtValorEntrada.disabled = (opcao.value != "1")) {
		edtValorEntrada.value = "";
	} else {
		edtValorEntrada.focus();
	}
}
function marcaValor(opcao) {
	var edtValorBem		= document.getElementById("edtValorBem");
	var edtValorParcela	= document.getElementById("edtValorParcela");

	if (edtValorBem.disabled = (!(edtValorParcela.disabled = (opcao.value != "2")))) {
		edtValorBem.value = "";
		edtValorParcela.focus();
	} else {
		edtValorParcela.value = "";
		try {
			edtValorBem.focus();
		} catch (e2) {
			
		} 
	}
}
function desabilitaValorCompra(opcao) {
	if (opcao) {
		var rdValor2 = document.getElementById("rdValor2");
		rdValor2.checked = true;
		marcaValor(rdValor2);
	}
	document.getElementById("rdValor1").disabled = opcao;
}

function setPrimeiroVencimento(incremento) {
	var novoVencimento = incMonth(HOJE, incremento);
	
//	alert(novoVencimento);
//	alert(formataData(novoVencimento));

	document.getElementById('EdtDataRetorno').value = formataData(novoVencimento);
}
