var images = new Array();
images[0] = 'ALTERAR_br.jpg';
images[1] = 'avancar.jpg';
images[2] = 'botao_fechar.jpg';
images[3] = 'bt_detalhamento.jpg';
images[4] = 'caixa_banner.jpg';
images[5] = 'CALCULAR.jpg';
images[6] = 'ce-planilha.jpg';
images[7] = 'como_contratar.jpg';
images[8] = 'grafico_Cet.jpg';
images[9] = 'grafico_sac.jpg';
images[10] = 'seta_1.jpg';
images[11] = 'simulador_barra.gif';
images[12] = 'SIM_IMPRIMIR.jpg';
images[13] = 'SIM_IMPRIMIR_G.jpg';
images[14] = 'SIM_PLANILHA.jpg';
images[15] = 'SIM_SALVAR.jpg';
images[16] = 'SIM_VOLTAR.jpg';
images[17] = 'SIM_VOLTAR_G.jpg';

function validaCPFCNPJ() {
	cpfCnpj = document.forms[0].cpf;
	
	if (cpfCnpj.value.length < 15) {
		if (!ValidarCPF(cpfCnpj)) {
			alert('CPF inválido.');
			cpfCnpj.focus();
			return false;
		}
	} else if (cpfCnpj.value.length == 18) {
		if (!ValidarCNPJ(cpfCnpj)) {
			alert('CNPJ inválido.');
			cpfCnpj.focus();
			return false;
		}
	}
	return true;
}

function inicia() {
	var form = document.forms[0];
	var inicioWS = form.inicioWS.value;
	if ((inicioWS!=null)&&(inicioWS!='')&&(inicioWS=='V')) {
		voltaParametros();

		chamadas.simulaWS();

		verificaValorReforma();
		imagePreload();
	} else {
		voltaParametros();
		verificaValorReforma();
		imagePreload();
		externalLinks();
		if (form.tipoImovel.value != '') {
			alteraTipoImovel(form.tipoImovel.value);
		}
		if (form.uf.value != '') {
			alteraUf();
		}
		if (form.pessoa[0].checked || form.pessoa[1].checked) {
			validaPessoaInicio();
		}
	}
	limparCombosSeguradora(true);
}

function limparCombosSeguradora(exibeCombo) {
	var form = document.forms[0];
	var comboSeguradora = form.codigoSeguradora;
	if (comboSeguradora != null) {
		inibirSeguradora('trSeguradora', 'trLabelSeguradora', exibeCombo);
		comboSeguradora.selectedIndex = 0;
	}
	var comboSeguradoraConvenio = form.codigoSeguradoraConvenio;
	if (comboSeguradoraConvenio != null) {
		inibirSeguradora('trSeguradoraConvenio', 'trLabelSeguradoraConvenio', 
				exibeCombo);
		comboSeguradoraConvenio.selectedIndex = 0;
	}
}

function imagePreload() {
	var contexto = document.forms[0].contexto.value;
	var i = 0;
    imageObj = new Image();
    for(i=0; i<images.length; i++) {
    	imageObj.src=contexto + '/imagens/simulador/' + images[i];
	}
}

var rdm;
var arr;

function exibir(x){
	arr = x;
	rdm = "";
	arr = arr.split("#");
	for (y=0; y<=3; y++){
		rdm = rdm + arr[y];
	}
}

function atualizaCaptcha() {
	var captcha = document.getElementById("captcha");
	var contexto = document.forms[0].contexto.value;
	if (isIE) {
		captcha.innerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0"'
			+ ' width="130" height="25" title="Deficiente visual, clique aqui para ouvir aos caracteres necess&aacute;rios para concluir seu registro">'
			+ ' <param name="movie" value="' + contexto + '/captcha/flash/validador.swf" />'
			+ ' <embed src="' + contexto + '/captcha/flash/validador.swf" type="application/x-shockwave-flash" width="130" height="25"></embed></object>';
	} else {
		captcha.innerHTML = '<object type="application/x-shockwave-flash" data="' + contexto + '/captcha/flash/validador.swf" width="130" height="25" title="Deficiente visual, clique aqui para ouvir aos caracteres necess&aacute;rios para concluir seu registro"></object>';
	}
}

function exibirDataBeneficio() {
	
	var form = document.forms[0];
	var divDataBeneficio = document.getElementById('divDataBeneficio');
	if (form.beneficiadoFGTS.checked) {
		divDataBeneficio.style.display = 'block';
	}else {
		form.dataBeneficioFGTS.value = '';
		divDataBeneficio.style.display = 'none';
	}
}

// Classe utilizada pelo Ajax do Simula Operação Imobiliária Internet
function SimulaOperacao() {
	// Herança de AjaxConnect
	AjaxConnect.call(this);

	// Chamado para enquadrar os itens de produto
	this.simulaInicial = function() {
		var form = document.forms[0];
				
				var renda = form.rendaFamiliar.value;
				var dataNascimento = form.dataNascimento.value;
				var imovel = form.valorImovel.value;
				var tipo = form.tipoImovel.value;
				var grupoTipoFinanciamento = form.grupoTipoFinanciamento.value;
				var uf = form.uf.value;
				var cidade = form.cidade.value;
				var fisica = form.pessoa[0].checked ? "V" : "F";
				var juridica = form.pessoa[1].checked ? "V" : "F";
				var imovelCidade = form.imovelCidade.checked ? "V" : "F";
				var vaContaFgts = form.vaContaFgts.checked ? "V" : "F";
				var valorReforma = formataValorNumerico(form.valorReforma.value);
				var convenio = form.convenio.value;
				var dataUltimoBeneficio = form.dataBeneficioFGTS.value;
				var beneficiadoFGTS = form.beneficiadoFGTS.checked ? "V" : "F";
				if ((convenio!=null)&&(convenio!="")&&(convenio.length > 0)) {
					alteraConvenio();
					return;
				}

				if (fisica == 'V') {
					document.getElementById('tipoPessoa').innerHTML = 'Pessoa Física';
				} else {
					document.getElementById('tipoPessoa').innerHTML = 'Pessoa Jurídica';
				}
				if (fisica == 'F' && juridica == 'F') {
					var erroPessoa = document.getElementById("erroPessoa");
					erroPessoa.innerHTML = 'Campo obrigatório não informado';
					erroPessoa.style.display = 'block';
					setTimeout("chamadas.fade('erroPessoa');", ERRO_TIMEOUT);
				} else if (tipo == "") {
					var erroTipoImovel = document.getElementById("erroTipoImovel");
					erroTipoImovel.innerHTML = 'Campo obrigatório não informado';
					erroTipoImovel.style.display = 'block';
					setTimeout("chamadas.fade('erroTipoImovel');", ERRO_TIMEOUT);
				} else if (grupoTipoFinanciamento == "") {
					var erroCategoriaImovel = document.getElementById("erroCategoriaImovel");
					erroCategoriaImovel.innerHTML = 'Campo obrigatório não informado';
					erroCategoriaImovel.style.display = 'block';
					setTimeout("chamadas.fade('erroCategoriaImovel');", ERRO_TIMEOUT);
				} else if ((grupoTipoFinanciamento == 3 || grupoTipoFinanciamento == 5) && valorReforma == 0) {
					var erroValorReforma = document.getElementById("erroValorReforma");
					erroValorReforma.innerHTML = 'Valor inválido.';
					erroValorReforma.style.display = 'block';
					setTimeout("chamadas.fade('erroValorReforma');", ERRO_TIMEOUT);
				} else if ((grupoTipoFinanciamento == 3 || grupoTipoFinanciamento == 5) && isNaN(valorReforma)) {
					var erroValorReforma = document.getElementById("erroValorReforma");
					erroValorReforma.innerHTML = 'Campo obrigatório não informado';
					erroValorReforma.style.display = 'block';
					setTimeout("chamadas.fade('erroValorReforma');", ERRO_TIMEOUT);
				} else if (uf == "" || cidade == "") {
					var erroUfCidade = document.getElementById("erroUfCidade");
					erroUfCidade.innerHTML = 'Campo obrigatório não informado';
					erroUfCidade.style.display = 'block';
					setTimeout("chamadas.fade('erroUfCidade');", ERRO_TIMEOUT);
				} else if (imovel == "") {
					var erroValorImovel = document.getElementById("erroValorImovel");
					erroValorImovel.innerHTML = 'Campo obrigatório não informado';
					erroValorImovel.style.display = 'block';
					setTimeout("chamadas.fade('erroValorImovel');", ERRO_TIMEOUT);
				} else if (fisica == 'V' && renda == "") {
					var erroRendaFamiliar = document.getElementById("erroRendaFamiliar");
					erroRendaFamiliar.innerHTML = 'Campo obrigatório não informado';
					erroRendaFamiliar.style.display = 'block';
					setTimeout("chamadas.fade('erroRendaFamiliar');", ERRO_TIMEOUT); 
				}else if (form.beneficiadoFGTS.checked && dataUltimoBeneficio == "") {
					var erroDataUltimoBeneficio = document.getElementById("erroRendaFamiliar");
					erroDataUltimoBeneficio.innerHTML = 'Campo obrigatório não informado';
					erroDataUltimoBeneficio.style.display = 'block';
					setTimeout("chamadas.fade('erroRendaFamiliar');", ERRO_TIMEOUT);
				} else if (fisica == 'V' && dataNascimento == "") {
					var erroDataNascimento = document.getElementById("erroDataNascimento");
					erroDataNascimento.innerHTML = 'Campo obrigatório não informado';
					erroDataNascimento.style.display = 'block';
					setTimeout("chamadas.fade('erroDataNascimento');", ERRO_TIMEOUT);
				} else {
					if (grupoTipoFinanciamento != 3 && grupoTipoFinanciamento != 5) {
						valorReforma = '';
					}
					setaImagem('botaoEnquadar');
					
					var link = 'method=enquadrarProdutos&valorImovel=' + imovel
						+ '&rendaFamiliarBruta=' + renda + '&tipoImovel=' + tipo
						+ '&grupoTipoFinanciamento=' + grupoTipoFinanciamento + '&dataNascimento=' + dataNascimento
						+ '&uf=' + uf + '&cidade=' + cidade + '&fisica=' + fisica + '&juridica=' + juridica
						+ '&imovelCidade=' + imovelCidade + '&vaContaFgts=' 
						+ vaContaFgts + '&valorReforma=' + valorReforma 
						+ '&dataBeneficioFGTS=' + dataUltimoBeneficio
						+ '&beneficiadoFGTS=' + beneficiadoFGTS;
					this.enviar('simulaOperacaoInternet.do', link, this.retornoSimulaInicial);
				}
	}
	
	this.simulaInicialEmpresa = function(empresa) {
		var form = document.forms[0];
		this.empresa = empresa;
				var renda = form.rendaFamiliar.value;
				var dataNascimento = form.dataNascimento.value;
				var imovel = form.valorImovel.value;
				var tipo = form.tipoImovel.value;
				var grupoTipoFinanciamento = form.grupoTipoFinanciamento.value;
				var uf = form.uf.value;
				var cidade = form.cidade.value;
				var fisica = form.pessoa[0].checked ? "V" : "F";
				var juridica = form.pessoa[1].checked ? "V" : "F";
				var imovelCidade = form.imovelCidade.checked ? "V" : "F";
				var vaContaFgts = form.vaContaFgts.checked ? "V" : "F";
				var valorReforma = formataValorNumerico(form.valorReforma.value);
				var convenio = form.convenio.value;
				var nuEmpresa = chamadas.empresa.getAttribute("nuEmpresa");
				var nomeEmpresa = chamadas.empresa.getAttribute("nomeEmpresa");

				if (fisica == 'V') {
					document.getElementById('tipoPessoaConvenio').innerHTML = 'Pessoa Física';
				} else {
					document.getElementById('tipoPessoaConvenio').innerHTML = 'Pessoa Jurídica';
				}
				if (fisica == 'F' && juridica == 'F') {
					var erroPessoa = document.getElementById("erroPessoa");
					erroPessoa.innerHTML = 'Campo obrigatório não informado';
					erroPessoa.style.display = 'block';
					setTimeout("chamadas.fade('erroPessoa');", ERRO_TIMEOUT);
				} else if (tipo == "") {
					var erroTipoImovel = document.getElementById("erroTipoImovel");
					erroTipoImovel.innerHTML = 'Campo obrigatório não informado';
					erroTipoImovel.style.display = 'block';
					setTimeout("chamadas.fade('erroTipoImovel');", ERRO_TIMEOUT);
				} else if (grupoTipoFinanciamento == "") {
					var erroCategoriaImovel = document.getElementById("erroCategoriaImovel");
					erroCategoriaImovel.innerHTML = 'Campo obrigatório não informado';
					erroCategoriaImovel.style.display = 'block';
					setTimeout("chamadas.fade('erroCategoriaImovel');", ERRO_TIMEOUT);
				} else if ((grupoTipoFinanciamento == 3 || grupoTipoFinanciamento == 5) && valorReforma == 0) {
					var erroValorReforma = document.getElementById("erroValorReforma");
					erroValorReforma.innerHTML = 'Valor inválido.';
					erroValorReforma.style.display = 'block';
					setTimeout("chamadas.fade('erroValorReforma');", ERRO_TIMEOUT);
				} else if ((grupoTipoFinanciamento == 3 || grupoTipoFinanciamento == 5) && isNaN(valorReforma)) {
					var erroValorReforma = document.getElementById("erroValorReforma");
					erroValorReforma.innerHTML = 'Campo obrigatório não informado';
					erroValorReforma.style.display = 'block';
					setTimeout("chamadas.fade('erroValorReforma');", ERRO_TIMEOUT);
				} else if (uf == "" || cidade == "") {
					var erroUfCidade = document.getElementById("erroUfCidade");
					erroUfCidade.innerHTML = 'Campo obrigatório não informado';
					erroUfCidade.style.display = 'block';
					setTimeout("chamadas.fade('erroUfCidade');", ERRO_TIMEOUT);
				} else if (imovel == "") {
					var erroValorImovel = document.getElementById("erroValorImovel");
					erroValorImovel.innerHTML = 'Campo obrigatório não informado';
					erroValorImovel.style.display = 'block';
					setTimeout("chamadas.fade('erroValorImovel');", ERRO_TIMEOUT);
				} else if (fisica == 'V' && renda == "") {
					var erroRendaFamiliar = document.getElementById("erroRendaFamiliar");
					erroRendaFamiliar.innerHTML = 'Campo obrigatório não informado';
					erroRendaFamiliar.style.display = 'block';
					setTimeout("chamadas.fade('erroRendaFamiliar');", ERRO_TIMEOUT); 
				} else if (fisica == 'V' && dataNascimento == "") {
					var erroDataNascimento = document.getElementById("erroDataNascimento");
					erroDataNascimento.innerHTML = 'Campo obrigatório não informado';
					erroDataNascimento.style.display = 'block';
					setTimeout("chamadas.fade('erroDataNascimento');", ERRO_TIMEOUT);
				} else {
					if (grupoTipoFinanciamento != 3 && grupoTipoFinanciamento != 5) {
						valorReforma = '';
					}
					setaImagem('botaoEnquadar');
					
					var link = 'method=enquadrarProdutosConvenio&valorImovel=' + imovel
						+ '&rendaFamiliarBruta=' + renda + '&tipoImovel=' + tipo
				+ '&grupoTipoFinanciamento=' + grupoTipoFinanciamento + '&dataNascimento=' + dataNascimento
				+ '&uf=' + uf + '&cidade=' + cidade + '&fisica=' + fisica + '&juridica=' + juridica
				+ '&imovelCidade=' + imovelCidade + '&vaContaFgts=' + vaContaFgts + '&valorReforma=' + valorReforma +  '&nuEmpresa=' + nuEmpresa +  '&convenio=' + convenio;
			this.enviar('simulaOperacaoInternet.do', link, this.retornoSimulaInicialConvenio);
		}
	}

	// Resultado do enquadrar itens de produto
	this.retornoSimulaInicial = function(xml) {
		var form = document.forms[0];
		var root = xml.getElementsByTagName("root");
		var erro;
		var child;

		//Indica se foi informado pessoa física.
		var pessoaFisica = form.pessoa[0].checked;
		
		document.getElementById('botaoEnquadar').innerHTML = '<a href="javascript: void(0)" onclick="chamadas.simulaInicial()" id="botaoEnquadar"><img src="' + form.contexto.value + '/imagens/simulador/avancar.jpg">';
		
		for (var i = 0; i < root.length; i++) {
			child = root[i];

			erro = child.getElementsByTagName("error");
			if (erro.length > 0) {
				var desc = erro[0].firstChild.nodeValue;
				var erroLocal = document.getElementById("erroSimulaInicial");
				erroLocal.innerHTML = desc;
				erroLocal.style.display = 'block';
				setTimeout("chamadas.fade('erroSimulaInicial');", 5000);
			} else {
				// Div aonde os produtos irão aparecer.
				var divProdutos = document.getElementById("listaProdutos");
				
				// Apaga os produtos existentes de outras simulações.
				while(divProdutos.firstChild != null) {
					divProdutos.removeChild(divProdutos.firstChild);
				}
				divProdutos.innerHTML = '';
				
				// Array com os itens de produto enquadrados
				var produtos = child.getElementsByTagName("itemproduto");
				var cor = true;
				
				var codigo;
				var versao;
				var nome;
				var descricao;
				var contratar;
				var documentacao;
				var linkProduto;
				var seTemLink;
				
				for (var ip = 0; ip < produtos.length; ip++) {
					codigo = produtos[ip].getElementsByTagName("codigo")[0].firstChild.nodeValue;
					versao = produtos[ip].getElementsByTagName("versao")[0].firstChild.nodeValue;
					nome = produtos[ip].getElementsByTagName("nome")[0].firstChild.nodeValue;
					var codigoSeguradora = produtos[ip].getElementsByTagName("codigoSeguradora");
					var nomeSeguradora = produtos[ip].getElementsByTagName("nomeSeguradora");
					descricao = '';
					contratar = '';
					documentacao = '';
					seTemLink = '';
					linkProduto = '';
					
					// Verifica se a descrição foi realmente retornada
					if (produtos[ip].getElementsByTagName("descricao").length > 0 && 
							produtos[ip].getElementsByTagName("descricao")[0].firstChild != null) {
						descricao = produtos[ip].getElementsByTagName("descricao")[0].firstChild.nodeValue;
					}
					if (produtos[ip].getElementsByTagName("link").length > 0 && 
							produtos[ip].getElementsByTagName("link")[0].firstChild != null) {
						contratar = produtos[ip].getElementsByTagName("link")[0].firstChild.nodeValue;
					}
					if (produtos[ip].getElementsByTagName("documentacao").length > 0 && 
							produtos[ip].getElementsByTagName("documentacao")[0].firstChild != null) {
						documentacao = produtos[ip].getElementsByTagName("documentacao")[0].firstChild.nodeValue;
					}
					if (produtos[ip].getElementsByTagName("linkProduto").length > 0 && 
							produtos[ip].getElementsByTagName("linkProduto")[0].firstChild != null) {
						linkProduto = produtos[ip].getElementsByTagName("linkProduto")[0].firstChild.nodeValue;
					}
					if (produtos[ip].getElementsByTagName("seTemLink").length > 0 && 
							produtos[ip].getElementsByTagName("seTemLink")[0].firstChild != null) {
						seTemLink = produtos[ip].getElementsByTagName("seTemLink")[0].firstChild.nodeValue;
					}
					// DIV para armazenar um produto
					var produto = document.createElement("div");
					if (cor == true) {
						produto.className = "field_block_1";
					} else {
						produto.className = "field_block_2";
					}
					cor = !cor;
					
					var nomeItem = document.createElement('div');
					var seta = document.createElement("img");
					seta.src = form.contexto.value + '/imagens/simulador/seta_1.jpg';
					nomeItem.appendChild(seta);
					var link = document.createElement("a");
					link.href = 'javascript: void(0)';
					link.innerHTML = '&nbsp;' + nome + '&nbsp;';
					if ((seTemLink!=null)&&(seTemLink == 'V')) {
						if ((linkProduto!=null)&&(linkProduto != '')) {
							link.href = linkProduto;
							link.target = '_blank';
						} else {
							link.href = '#';
						}	
					} else {
						link.onclick = function() {
							chamadas.simula(this);
						}
					}	
					link.setAttribute("codigo", codigo);
					link.setAttribute("versao", versao);
					link.setAttribute("nome", nome);
					link.setAttribute("contratar", contratar);
					link.setAttribute("documentacao", documentacao);
					if (codigoSeguradora.length > 0 
							&& codigoSeguradora[0].firstChild != null) {
						link.setAttribute("codigoSeguradoraSelecionada", 
								codigoSeguradora[0].firstChild.nodeValue);
					}
					if (nomeSeguradora.length > 0 
							&& nomeSeguradora[0].firstChild != null) {
						link.setAttribute("nomeSeguradora", 
								nomeSeguradora[0].firstChild.nodeValue);
					}

					link.className = 'titulo_item';
					nomeItem.appendChild(link);
					
					var img = document.createElement('span');
					img.id = 'produto_img' + codigo + '.' + versao;
					img.style.verticalAlign = 'middle';
					nomeItem.appendChild(img);

					produto.appendChild(nomeItem);
					
					// Detalhe que aparece abaixo do item de produto
					var detalhe = document.createElement("div");
					detalhe.className = 'texto_campos';
					detalhe.innerHTML = descricao;
					detalhe.style.paddingLeft = '10px';
					produto.appendChild(detalhe);
					
					// Campo aonde será mostrado o erro do calculo caso exista um. 
					var erro = document.createElement("div");
					erro.className = 'error_box';
					erro.id = 'produto' + codigo + '.' + versao;
					produto.appendChild(erro);
					
					// Adiciona a DIV do item de produto a lista 
					divProdutos.appendChild(produto);
				}
				
				// link para o botão voltar
				var table = document.createElement("table");
				var tb = document.createElement("tbody");
				table.appendChild(tb);
				table.className = "field_block_2";
				
				tr = document.createElement("tr");
				td = document.createElement("td");
				td.className = 'texto_campos'
				td.innerHTML = '<b>Para visualizar a simulação clique no nome do produto</b>';
				tr.appendChild(td);
				
				td = document.createElement("td");
				var link2 = document.createElement("a");
				link2.href = 'javascript: void(0)';
				link2.onclick = voltaParametros;
				td.appendChild(link2);
				
				// Imagem do botão voltar
				var img = document.createElement("img");
				img.src = form.contexto.value + '/imagens/simulador/SIM_VOLTAR.jpg';
				link2.appendChild(img);
				//td.appendChild(voltar);
				tr.appendChild(td);
				tb.appendChild(tr);
				
				tr = document.createElement("tr");
				td = document.createElement("td");
				td.className = 'texto_campos'
				td.style.textAlign='right';
				td.innerHTML = '<b>Veja outras opções no<b> ';
				td.colSpan = '2';
				tr.appendChild(td);
				link2 = document.createElement("a");
				link2.href = 'http://www.caixaconsorcios.com.br/portal/site/CaixaConsorcios/menuitem.8da41945029d4a67d647866130e001ca/?vgnextoid=8fd714dd9e572110VgnVCM100000790110acRCRD';
				link2.target = 'new';
				link2.className = 'texto_link';
				td.appendChild(link2);
				text = document.createTextNode('Consórcio Imobiliário CAIXA');
				link2.appendChild(text);
				tb.appendChild(tr);
				
				// Adiciona o botão a lista de div
				divProdutos.appendChild(table);
				
				// Preenche o cabeçalho da tela
				var campo;

				// Tipo de Imóvel
				campo = document.getElementById("headerTipo");
				campo.innerHTML = form.tipoImovel.options[form.tipoImovel.selectedIndex].text;
				
				// Grupo de tipo de financiamento
				campo = document.getElementById("headerCategoria");
				campo.innerHTML = form.grupoTipoFinanciamento.options[form.grupoTipoFinanciamento.selectedIndex].text;

				// Valor do Imóvel
				campo = document.getElementById("headerValor");
				campo.innerHTML = 'R$ ' + form.valorImovel.value;

				// Cidade + "-" + UF 
				campo = document.getElementById("headerCidade");
				campo.innerHTML = form.cidade.options[form.cidade.selectedIndex].text
					+ "-" + form.uf.options[form.uf.selectedIndex].text;
				if (form.imovelCidade.checked) {
					campo.innerHTML += 'Possui imóvel neste município.'; 
				}

				campo = document.getElementById("headerRegimeFGTS");
				if (form.vaContaFgts.checked) {
					campo.innerHTML = ' Sim'; 
				} else {
					campo.innerHTML = ' Não';
				}

				// Renda Familiar Bruta
				campo = document.getElementById("headerRenda");
				if (form.rendaFamiliar.value != '' && pessoaFisica) {
					campo.innerHTML = 'R$ ' + form.rendaFamiliar.value;
				}else {
					campo.innerHTML = '';
				}
				
				/*
				 * Configura a exibição dos campos que são apenas p/ pessoa fisica
				 */ 
				if(pessoaFisica){
					document.getElementById("tdRendaBruta").style.display = 'block';
					document.getElementById("tdDataNascimento").style.display = 'block';
					document.getElementById("trPossuiFGTS").style.display = 'block';
					document.getElementById("trBeneficiadoFGTS").style.display = 'block';
					document.getElementById("trDtBeneficio").style.display = 'block';
				}else{
					document.getElementById("tdRendaBruta").style.display = 'none';
					document.getElementById("tdDataNascimento").style.display = 'none';
					document.getElementById("trPossuiFGTS").style.display = 'none';
					document.getElementById("trBeneficiadoFGTS").style.display = 'none';
					document.getElementById("trDtBeneficio").style.display = 'none';
				} 


				// Data de Nascimento 
				campo = document.getElementById("headerData");
				campo.innerHTML = form.dataNascimento.value;

				campo = document.getElementById("headerBeneficiadoFGTS");
				if (form.beneficiadoFGTS.checked) {
					campo.innerHTML = ' Sim'; 
					campo = document.getElementById("headerDataBeneficioFGTS");
					campo.innerHTML = form.dataBeneficioFGTS.value; 
				} else {
					campo.innerHTML = ' Não';
					campo = document.getElementById("headerDataBeneficioFGTS");
					campo.innerHTML = ''; 
				}
				
				// Apresenta somente o DIV da lista de produtos
				var parametros = document.getElementById("parametros");
				var telaProdutos = document.getElementById("produtos");
				var headerSimulacao = document.getElementById("headerSimulacao");
				var telaProdutosConvenio = document.getElementById("produtosConvenio");
				var headerSimulacaoConvenio = document.getElementById("headerSimulacaoConvenio");

				headerSimulacaoConvenio.style.display = 'none';
				telaProdutosConvenio.style.display = 'none';
				parametros.style.display = 'none';
				headerSimulacao.style.display = 'block'; 
				telaProdutos.style.display = 'block';
				limparCombosSeguradora(true);
			}
		}
	};//Fim retornoSimulaInicial
	
	this.retornoSimulaInicialConvenio = function(xml) {
		var form = document.forms[0];
		var root = xml.getElementsByTagName("root");
		var tagConvenio;
		var tagPessoa;
		var erro;
		var child; 
		var childPai;
		
		//Indica se foi informado pessoa física.
		var pessoaFisica = form.pessoa[0].checked;  
		
		/*
		 * Configura a exibição dos campos que são apenas p/ pessoa fisica
		 */
		if(pessoaFisica){
			document.getElementById("tdRendaBrutaConvenio").style.display = 'block';
			document.getElementById("tdDataNascimentoConvenio").style.display = 'block';
			document.getElementById("trPossuiFGTSConvenio").style.display = 'block';
			document.getElementById("trBeneficiadoFGTSConvenio").style.display = 'block';
			document.getElementById("trDtBeneficioConvenio").style.display = 'block';
		}else{
			document.getElementById("tdRendaBrutaConvenio").style.display = 'none';
			document.getElementById("tdDataNascimentoConvenio").style.display = 'none';
			document.getElementById("trPossuiFGTSConvenio").style.display = 'none';
			document.getElementById("trBeneficiadoFGTSConvenio").style.display = 'none';
			document.getElementById("trDtBeneficioConvenio").style.display = 'none';
		} 
		
		
		document.getElementById('botaoEnquadar').innerHTML = '<a href="javascript: void(0)" onclick="chamadas.simulaInicialEmpresa()" id="botaoEnquadar"><img src="' + form.contexto.value + '/imagens/simulador/avancar.jpg">';
		for (var i = 0; i < root.length; i++) {
			childPai = root[i];
			erro = childPai.getElementsByTagName("error");
			if (erro.length > 0) {
				var desc = erro[0].firstChild.nodeValue;
				var erroLocal = document.getElementById("erroEmpresa");
				erroLocal.innerHTML = desc;
				erroLocal.style.display = 'block';
				setTimeout("chamadas.fade('erroEmpresa');", 5000);
			} else {
				tagConvenio = childPai.getElementsByTagName("convenio");
				// Div aonde os produtos irão aparecer.
				var divProdutosConvenio = document.getElementById("listaProdutosConvenio");
				
				// Apaga os produtos existentes de outras simulações.
				while(divProdutosConvenio.firstChild != null) {
					divProdutosConvenio.removeChild(divProdutosConvenio.firstChild);
				}
				divProdutosConvenio.innerHTML = '';
				for (var j = 0; j < tagConvenio.length; j++) {
					child = tagConvenio[i];
					
					// Array com os itens de produto enquadrados
					var produtos = child.getElementsByTagName("itemproduto");
					var cor = true;
					
					var codigo;
					var versao;
					var nome;
					var descricao;
					var contratar;
					var documentacao;
					var infoComplementar;
					var sePermiteEhCliente;
					var sePermiteCarencia;
					var sePermiteCota;
					var sePermiteTaxas;
					var carenciaMaxima;
					var taxasMaxima;
					var linkProduto;
					var seTemLink;
					for (var ip = 0; ip < produtos.length; ip++) {
						codigo = produtos[ip].getElementsByTagName("codigo")[0].firstChild.nodeValue;
						versao = produtos[ip].getElementsByTagName("versao")[0].firstChild.nodeValue;
						nome = produtos[ip].getElementsByTagName("nome")[0].firstChild.nodeValue;
						descricao = '';
						contratar = '';
						documentacao = '';
						sePermiteEhCliente = '';
						sePermiteCarencia = '';
						sePermiteCota = '';
						sePermiteTaxas = '';
						carenciaMaxima = '';
						taxasMaxima = '';
						infoComplementar = '';
						seTemLink = '';
						linkProduto = '';
						if (produtos[ip].getElementsByTagName("sePermiteEhCliente").length > 0 && produtos[ip].getElementsByTagName("sePermiteEhCliente")[0].firstChild != null) {
							sePermiteEhCliente = produtos[ip].getElementsByTagName("sePermiteEhCliente")[0].firstChild.nodeValue;
						}	
						if (produtos[ip].getElementsByTagName("sePermiteCarencia").length > 0 && produtos[ip].getElementsByTagName("sePermiteCarencia")[0].firstChild != null) {
							sePermiteCarencia = produtos[ip].getElementsByTagName("sePermiteCarencia")[0].firstChild.nodeValue;
						}	
						if (produtos[ip].getElementsByTagName("sePermiteCota").length > 0 && produtos[ip].getElementsByTagName("sePermiteCota")[0].firstChild != null) {
							sePermiteCota = produtos[ip].getElementsByTagName("sePermiteCota")[0].firstChild.nodeValue;
						}	
						if (produtos[ip].getElementsByTagName("sePermiteTaxas").length > 0 && produtos[ip].getElementsByTagName("sePermiteTaxas")[0].firstChild != null) {
							sePermiteTaxas = produtos[ip].getElementsByTagName("sePermiteTaxas")[0].firstChild.nodeValue;
						}	
						if (produtos[ip].getElementsByTagName("carenciaMaxima").length > 0 && produtos[ip].getElementsByTagName("carenciaMaxima")[0].firstChild != null) {
							carenciaMaxima = produtos[ip].getElementsByTagName("carenciaMaxima")[0].firstChild.nodeValue;
						}	
						if (produtos[ip].getElementsByTagName("taxasMaxima").length > 0 && produtos[ip].getElementsByTagName("taxasMaxima")[0].firstChild != null) {
							taxasMaxima = produtos[ip].getElementsByTagName("taxasMaxima")[0].firstChild.nodeValue;
						}	
						if (produtos[ip].getElementsByTagName("infoComplementar").length > 0 && produtos[ip].getElementsByTagName("infoComplementar")[0].firstChild != null) {
							infoComplementar = produtos[ip].getElementsByTagName("infoComplementar")[0].firstChild.nodeValue;
						}	
						if (produtos[ip].getElementsByTagName("linkProduto").length > 0 && produtos[ip].getElementsByTagName("linkProduto")[0].firstChild != null) {
							linkProduto = produtos[ip].getElementsByTagName("linkProduto")[0].firstChild.nodeValue;
						}
						if (produtos[ip].getElementsByTagName("seTemLink").length > 0 && produtos[ip].getElementsByTagName("seTemLink")[0].firstChild != null) {
							seTemLink = produtos[ip].getElementsByTagName("seTemLink")[0].firstChild.nodeValue;
						}
						
						// Verifica se a descrição foi realmente retornada
						if (produtos[ip].getElementsByTagName("descricao").length > 0 && produtos[ip].getElementsByTagName("descricao")[0].firstChild != null) {
							descricao = produtos[ip].getElementsByTagName("descricao")[0].firstChild.nodeValue;
						}
						if (produtos[ip].getElementsByTagName("link").length > 0 && produtos[ip].getElementsByTagName("link")[0].firstChild != null) {
							contratar = produtos[ip].getElementsByTagName("link")[0].firstChild.nodeValue;
						}
						if (produtos[ip].getElementsByTagName("documentacao").length > 0 && produtos[ip].getElementsByTagName("documentacao")[0].firstChild != null) {
							documentacao = produtos[ip].getElementsByTagName("documentacao")[0].firstChild.nodeValue;
						}
						// DIV para armazenar um produto
						var produto = document.createElement("div");
						if (cor == true) {
							produto.className = "field_block_1";
						} else {
							produto.className = "field_block_2";
						}
						cor = !cor;
						
						var nomeItem = document.createElement('div');
						var seta = document.createElement("img");
						seta.src = form.contexto.value + '/imagens/simulador/seta_1.jpg';
						nomeItem.appendChild(seta);
						var link = document.createElement("a");
						link.href = 'javascript: void(0)';
						link.innerHTML = '&nbsp;' + nome + '&nbsp;';
						if ((seTemLink!=null)&&(seTemLink == 'V')) {
							if ((linkProduto!=null)&&(linkProduto != '')) {
								link.href = linkProduto;
								link.target = '_blank';
							} else {
								link.href = '#';
							}	
						} else {
							link.onclick = function() {
								chamadas.simulaConvenio(this);
							}
						}	
						link.className = 'titulo_item';
						link.setAttribute("codigo", codigo);
						link.setAttribute("versao", versao);
						link.setAttribute("nome", nome);
						link.setAttribute("contratar", contratar);
						link.setAttribute("documentacao", documentacao);
						link.setAttribute("sePermiteEhCliente", sePermiteEhCliente);
						link.setAttribute("sePermiteCarencia", sePermiteCarencia);
						link.setAttribute("sePermiteCota", sePermiteCota);
						link.setAttribute("sePermiteTaxas", sePermiteTaxas);
						link.setAttribute("carenciaMaxima", carenciaMaxima);
						link.setAttribute("taxasMaxima", taxasMaxima);
						link.setAttribute("infoComplementar", infoComplementar);
						link.className = 'titulo_item';
						nomeItem.appendChild(link);
						
						var img = document.createElement('span');
						img.id = 'produtoConvenio_img' + codigo + '.' + versao;
						img.style.verticalAlign = 'middle';
						nomeItem.appendChild(img);
	
						produto.appendChild(nomeItem);
						
						// Detalhe que aparece abaixo do item de produto
						var detalhe = document.createElement("div");
						detalhe.className = 'texto_campos';
						detalhe.innerHTML = descricao;
						detalhe.style.paddingLeft = '10px';
						produto.appendChild(detalhe);
						
						// Campo aonde será mostrado o erro do calculo caso exista um. 
						var erro = document.createElement("div");
						erro.className = 'error_box';
						erro.id = 'produtoConvenio' + codigo + '.' + versao;
						produto.appendChild(erro);
						
						// Adiciona a DIV do item de produto a lista 
						divProdutosConvenio.appendChild(produto);
					}
				}
				tagPessoa = childPai.getElementsByTagName("pessoa");
				// Div aonde os produtos irão aparecer.
				var divProdutos = document.getElementById("listaProdutos");
				// Apaga os produtos existentes de outras simulações.
				while(divProdutos.firstChild != null) {
					divProdutos.removeChild(divProdutos.firstChild);
				}
				divProdutos.innerHTML = '';
				for (var j = 0; j < tagPessoa.length; j++) {
					child = tagPessoa[i];
					
					
					// Array com os itens de produto enquadrados
					var produtos = child.getElementsByTagName("itemproduto");
					var cor = true;
					
					var codigo;
					var versao;
					var nome;
					var descricao;
					var contratar;
					var documentacao;
					var linkProduto;
					var seTemLink;
					
					for (var ip = 0; ip < produtos.length; ip++) {
						codigo = produtos[ip].getElementsByTagName("codigo")[0].firstChild.nodeValue;
						versao = produtos[ip].getElementsByTagName("versao")[0].firstChild.nodeValue;
						nome = produtos[ip].getElementsByTagName("nome")[0].firstChild.nodeValue;
						descricao = '';
						contratar = '';
						documentacao = '';
						seTemLink = '';
						linkProduto = '';
						
						// Verifica se a descrição foi realmente retornada
						if (produtos[ip].getElementsByTagName("descricao").length > 0 && produtos[ip].getElementsByTagName("descricao")[0].firstChild != null) {
							descricao = produtos[ip].getElementsByTagName("descricao")[0].firstChild.nodeValue;
						}
						if (produtos[ip].getElementsByTagName("link").length > 0 && produtos[ip].getElementsByTagName("link")[0].firstChild != null) {
							contratar = produtos[ip].getElementsByTagName("link")[0].firstChild.nodeValue;
						}
						if (produtos[ip].getElementsByTagName("documentacao").length > 0 && produtos[ip].getElementsByTagName("documentacao")[0].firstChild != null) {
							documentacao = produtos[ip].getElementsByTagName("documentacao")[0].firstChild.nodeValue;
						}
						if (produtos[ip].getElementsByTagName("linkProduto").length > 0 && produtos[ip].getElementsByTagName("linkProduto")[0].firstChild != null) {
							linkProduto = produtos[ip].getElementsByTagName("linkProduto")[0].firstChild.nodeValue;
						}
						if (produtos[ip].getElementsByTagName("seTemLink").length > 0 && produtos[ip].getElementsByTagName("seTemLink")[0].firstChild != null) {
							seTemLink = produtos[ip].getElementsByTagName("seTemLink")[0].firstChild.nodeValue;
						}
						// DIV para armazenar um produto
						var produto = document.createElement("div");
						if (cor == true) {
							produto.className = "field_block_1";
						} else {
							produto.className = "field_block_2";
						}
						cor = !cor;
						
						var nomeItem = document.createElement('div');
						var seta = document.createElement("img");
						seta.src = form.contexto.value + '/imagens/simulador/seta_1.jpg';
						nomeItem.appendChild(seta);
						var link = document.createElement("a");
						link.href = 'javascript: void(0)';
						link.innerHTML = '&nbsp;' + nome + '&nbsp;';
						if ((seTemLink!=null)&&(seTemLink == 'V')) {
							if ((linkProduto!=null)&&(linkProduto != '')) {
								link.href = linkProduto;
								link.target = '_blank';
							} else {
								link.href = '#';
							}	
						} else {
							link.onclick = function() {
								chamadas.simula(this);
							}
						}	
						link.className = 'titulo_item';
						link.setAttribute("codigo", codigo);
						link.setAttribute("versao", versao);
						link.setAttribute("nome", nome);
						link.setAttribute("contratar", contratar);
						link.setAttribute("documentacao", documentacao);
						link.className = 'titulo_item';
						nomeItem.appendChild(link);
						
						var img = document.createElement('span');
						img.id = 'produto_img' + codigo + '.' + versao;
						img.style.verticalAlign = 'middle';
						nomeItem.appendChild(img);
	
						produto.appendChild(nomeItem);
						
						// Detalhe que aparece abaixo do item de produto
						var detalhe = document.createElement("div");
						detalhe.className = 'texto_campos';
						detalhe.innerHTML = descricao;
						detalhe.style.paddingLeft = '10px';
						produto.appendChild(detalhe);
						
						// Campo aonde será mostrado o erro do calculo caso exista um. 
						var erro = document.createElement("div");
						erro.className = 'error_box';
						erro.id = 'produto' + codigo + '.' + versao;
						produto.appendChild(erro);
						
						// Adiciona a DIV do item de produto a lista 
						divProdutos.appendChild(produto);
					}
				}
				// link para o botão voltar
				var table = document.createElement("table");
				var tb = document.createElement("tbody");
				table.appendChild(tb);
				table.className = "field_block_2";
				
				tr = document.createElement("tr");
				td = document.createElement("td");
				td.className = 'texto_campos'
				td.innerHTML = '<b>Para visualizar a simulação clique no nome do produto</b>';
				tr.appendChild(td);
				
				td = document.createElement("td");
				var link2 = document.createElement("a");
				link2.href = 'javascript: void(0)';
				link2.onclick = voltaParametrosConvenio;
				td.appendChild(link2);
				
				// Imagem do botão voltar
				var img = document.createElement("img");
				img.src = form.contexto.value + '/imagens/simulador/SIM_VOLTAR.jpg';
				link2.appendChild(img);
				//td.appendChild(voltar);
				tr.appendChild(td);
				tb.appendChild(tr);
				
				tr = document.createElement("tr");
				td = document.createElement("td");
				td.className = 'texto_campos'
				td.style.textAlign='right';
				td.innerHTML = '<b>Veja outras opções no<b> ';
				td.colSpan = '2';
				tr.appendChild(td);
				link2 = document.createElement("a");
				link2.href = 'http://www.caixaconsorcios.com.br/portal/site/CaixaConsorcios/menuitem.8da41945029d4a67d647866130e001ca/?vgnextoid=8fd714dd9e572110VgnVCM100000790110acRCRD';
				link2.target = 'new';
				link2.className = 'texto_link';
				td.appendChild(link2);
				text = document.createTextNode('Consórcio Imobiliário CAIXA');
				link2.appendChild(text);
				tb.appendChild(tr);
				
				// Adiciona o botão a lista de div
				divProdutos.appendChild(table);
				
				// Preenche o cabeçalho da tela
				var campo;
	
				// Tipo de Imóvel
				campo = document.getElementById("headerTipoConvenio");
				campo.innerHTML = form.tipoImovel.options[form.tipoImovel.selectedIndex].text;
				
				// Grupo de tipo de financiamento
				campo = document.getElementById("headerCategoriaConvenio");
				campo.innerHTML = form.grupoTipoFinanciamento.options[form.grupoTipoFinanciamento.selectedIndex].text;
	
				// Valor do Imóvel
				campo = document.getElementById("headerValorConvenio");
				campo.innerHTML = 'R$ ' + form.valorImovel.value;
	
				// Cidade + "-" + UF 
				campo = document.getElementById("headerCidadeConvenio");
				campo.innerHTML = form.cidade.options[form.cidade.selectedIndex].text
					+ "-" + form.uf.options[form.uf.selectedIndex].text;
				if (form.imovelCidade.checked) {
					campo.innerHTML += ' - Possui imóvel neste município.'; 
				}
	
				campo = document.getElementById("headerRegimeFGTSConvenio");
				if (form.vaContaFgts.checked) {
					campo.innerHTML = ' Sim'; 
				} else {
					campo.innerHTML = ' Não';
				}
	
				// Renda Familiar Bruta
				campo = document.getElementById("headerRendaConvenio");
				if (form.rendaFamiliar.value != '') {
					campo.innerHTML = 'R$ ' + form.rendaFamiliar.value;
				}else {
					campo.innerHTML = '';
				}
	
				// Data de Nascimento 
				campo = document.getElementById("headerDataConvenio");
				campo.innerHTML = form.dataNascimento.value;
	
				campo = document.getElementById("headerConvenio");
				campo.innerHTML = form.convenio.options[form.convenio.selectedIndex].text;
				
				campo = document.getElementById("headerEmpresa");
				campo.innerHTML = chamadas.empresa.getAttribute("nomeEmpresa");

				campo = document.getElementById("headerBeneficiadoFGTSConvenio");
				if (form.beneficiadoFGTS.checked) {
					campo.innerHTML = ' Sim'; 
					campo = document.getElementById("headerDataBeneficioFGTSConvenio");
					campo.innerHTML = form.dataBeneficioFGTS.value; 
				} else {
					campo.innerHTML = ' Não';
					campo = document.getElementById("headerDataBeneficioFGTSConvenio");
					campo.innerHTML = ''; 
				}
				
				// Apresenta somente o DIV da lista de produtos
				var parametros = document.getElementById("parametros");
				var telaProdutos = document.getElementById("produtos");
				var telaProdutosConvenio = document.getElementById("produtosConvenio");
				var convenios = document.getElementById("convenios");
				var headerSimulacaoConvenio = document.getElementById("headerSimulacaoConvenio");
				var headerSimulacao = document.getElementById("headerSimulacao");
	
				parametros.style.display = 'none';
				headerSimulacao.style.display = 'none';
				convenios.style.display = 'none';
				headerSimulacaoConvenio.style.display = 'block';
				telaProdutosConvenio.style.display = 'block';
				telaProdutos.style.display = 'block';
			}
		}
	}

	this.simulaWS = function() {
		var form = document.forms[0];
		var vaEnquadra = form.vaEnquadraWS.value;
		var vaMunicipioImovel = form.vaMunicipioImovelWS.value;
		var vaVlAvaliacao = form.vaVlAvaliacaoWS.value;
		var vaVlRendaFamBruta = form.vaVlRendaFamBrutaWS.value;
		var vaDtNascimentoProp1 = form.vaDtNascimentoProp1WS.value;
		var vaPossuiImovel = form.vaPossuiImovelWS.value;
		var vaContaFgts = form.vaContaFgtsWS.value;
		var codigoSeguradora = form.codigoSeguradoraSelecionada.value;
		var nomeSeguradora = form.nomeSeguradora.value;
		
		setaImagem('botaoCalcular');
	
		var link = 'method=simularOperacaoImobiliariaInternetWebService&vaEnquadra=' + vaEnquadra
			+ '&vaMunicipioImovel=' + vaMunicipioImovel + '&vaVlAvaliacao=' + vaVlAvaliacao
			+ '&vaVlRendaFamBruta=' + vaVlRendaFamBruta + '&vaDtNascimentoProp1=' + vaDtNascimentoProp1
			+ '&vaPossuiImovel=' + vaPossuiImovel + '&vaContaFgts=' 
			+ vaContaFgts + '&codigoSeguradoraSelecionada=' + codigoSeguradora 
			+ '&nomeSeguradora=' + nomeSeguradora;
			
		chamadas.enviar('simulaOperacaoInternet.do', link, chamadas.retornoSimulaWS);
	}

	// Chamado ao alterar o prazo do subsídio / Alterar prazo
	this.confirmaPrazo = function() {
		// Indica que o subsídio já foi validado pela aplicação.
		this.validadoSubsidio = true;
		
		var form = document.forms[0];
		var imovel = form.valorImovel.value;
		var renda = form.rendaFamiliar.value;
		var tipo = form.tipoImovel.value;
		var grupoTipoFinanciamento = form.grupoTipoFinanciamento.value;
		var dataNascimento = form.dataNascimento.value;
		var uf = form.uf.value;
		var cidade = form.cidade.value;
		var imovelCidade = form.imovelCidade.checked ? "V" : "F";
		var vaContaFgts = form.vaContaFgts.checked ? "V" : "F";
		var dataUltimoBeneficio = form.dataBeneficioFGTS.value;
		var beneficiadoFGTS = form.beneficiadoFGTS.checked ? "V" : "F";

		var nuItemProduto = '';
		var inicioWS = form.inicioWS.value;
		if ((inicioWS!=null)&&(inicioWS!='')&&(inicioWS=='V')) {
			nuItemProduto = form.nuItemProdutoWS.value; 
			nuVersao = form.nuVersaoWS.value; 
		} else {
			nuItemProduto = chamadas.campo.getAttribute('codigo');
			nuVersao = chamadas.campo.getAttribute('versao');
		}	
		var valorReforma = form.valorReforma.value;
		var valorEntrada = form.valorEntrada.value;
		var prazoDesejavel = form.prazoDesejavel.value;
		var codigoSeguradora = form.codigoSeguradora[form.codigoSeguradora.selectedIndex].value;
		var nomeSeguradora = form.codigoSeguradora[form.codigoSeguradora.selectedIndex].text;
		
		var campoSeguradora = form.codigoSeguradora; 
		var exibeSeguradora = document.getElementById("trSeguradora");
		
		if (exibeSeguradora != undefined &&    
				exibeSeguradora.style.display == 'block' &&
				campoSeguradora != undefined && 
				campoSeguradora.options != undefined &&
				campoSeguradora.options.length > 1 && 
					codigoSeguradora == '') { 
			alert('Campo obrigatório não informado');
			return false;
		}
		
		if (codigoSeguradora == '') {
			form.codigoSeguradoraSelecionada.value = '1';
			form.nomeSeguradora.value = 'Caixa Seguros';
			codigoSeguradora = '1';
			nomeSeguradora = 'Caixa Seguros';
		}
		
		setaImagem('botaoCalcular');
		
		var link = 'method=simularOperacaoImobiliariaInternet&valorImovel=' + imovel
			+ '&rendaFamiliarBruta=' + renda + '&tipoImovel=' + tipo
			+ '&grupoTipoFinanciamento=' + grupoTipoFinanciamento + '&dataNascimento=' + dataNascimento
			+ '&uf=' + uf + '&cidade=' + cidade + '&nuItemProduto=' + nuItemProduto + '&nuVersao=' + nuVersao
			+ '&imovelCidade=' + imovelCidade + '&vaContaFgts=' + vaContaFgts 
			+ '&prazo=' + prazoDesejavel + '&recursosProprios=' + valorEntrada 
			+ '&codigoSeguradoraSelecionada=' + codigoSeguradora + '&nomeSeguradora=' + nomeSeguradora
			+ '&valorReforma=' + valorReforma 
			+ '&inicioWS=' + inicioWS
			+ '&dataBeneficioFGTS=' + dataUltimoBeneficio
			+ '&beneficiadoFGTS=' + beneficiadoFGTS;
		if ((inicioWS!=null)&&(inicioWS!='')&&(inicioWS=='V')) {
			chamadas.enviar('simulaOperacaoInternet.do', link, chamadas.retornoSimulaWS);
		} else {
			chamadas.enviar('simulaOperacaoInternet.do', link, chamadas.retornoSimula);
		}	
	}
	
	this.confirmaPrazoConvenio = function() {
		// Indica que o subsídio já foi validado pela aplicação.
		this.validadoSubsidio = true;
		
		var form = document.forms[0];
		var imovel = form.valorImovel.value;
		var renda = form.rendaFamiliar.value;
		var tipo = form.tipoImovel.value;
		var grupoTipoFinanciamento = form.grupoTipoFinanciamento.value;
		var dataNascimento = form.dataNascimento.value;
		var uf = form.uf.value;
		var cidade = form.cidade.value;
		var nuItemProduto = chamadas.campo.getAttribute('codigo');
		var nuVersao = chamadas.campo.getAttribute('versao');
		var valorReforma = form.valorReforma.value;
		var imovelCidade = form.imovelCidade.checked ? "V" : "F";
		var vaContaFgts = form.vaContaFgts.checked ? "V" : "F";
		var codigoSeguradora = form.codigoSeguradoraConvenio[form.codigoSeguradoraConvenio.selectedIndex].value;
		var nomeSeguradora = form.codigoSeguradoraConvenio[form.codigoSeguradoraConvenio.selectedIndex].text;
		if (existeSeguradora() && codigoSeguradora == '') {
			alert('Campo obrigatório não informado');
			return false;
		}

		if (codigoSeguradora == '') {
			form.codigoSeguradoraSelecionada.value = '1';
			form.nomeSeguradora.value = 'Caixa Seguros';
			codigoSeguradora = '1';
			nomeSeguradora = 'Caixa Seguros';
		}
		
		var valorEntradaConvenio = form.valorEntradaConvenio.value;
		var prazoDesejavelConvenio = form.prazoDesejavelConvenio.value;
		var convenio = form.convenio.value;
		var nuEmpresa = chamadas.empresa.getAttribute("nuEmpresa");
		var ehCliente = (((form.seEhCliente[0]!=null) && (!form.seEhCliente[0].disabled) && (document.getElementById("trSeEhCliente").style.display!= 'none')  && (form.seEhCliente[0].checked)) ? "V" : "F");
		var desejaCota = (((form.seDesejaCotaFinanciamento[0]!=null) && (!form.seDesejaCotaFinanciamento[0].disabled) && (document.getElementById("trSeDesejaCotaFinanciamento").style.display!= 'none') && (form.seDesejaCotaFinanciamento[0].checked)) ? "V" : "F");
		var desejaCarencia = (((form.seDesejaCarencia[0]!=null) && (!form.seDesejaCarencia[0].disabled) && (document.getElementById("trSeDesejaCarencia").style.display!= 'none') && (form.seDesejaCarencia[0].checked)) ? "V" : "F");
		var seDesejaFinanciarDespesas = (((form.seDesejaFinanciarDespesas[0]!=null) && (!form.seDesejaFinanciarDespesas[0].disabled) && (document.getElementById("trSeDesejaFinanciarDespesas").style.display!= 'none') && (form.seDesejaFinanciarDespesas[0].checked)) ? "V" : "F");
		var prazoCarencia = form.prazoCarencia.value;
		var valorTaxasFinanciadas = form.valorTaxasFinanciadas.value;

		var sePermiteEhCliente = chamadas.campo.getAttribute('sePermiteEhCliente');
		var sePermiteCarencia = chamadas.campo.getAttribute('sePermiteCarencia');
		var sePermiteCota = chamadas.campo.getAttribute('sePermiteCota');
		var sePermiteTaxas = chamadas.campo.getAttribute('sePermiteTaxas');
		var carenciaMaxima = chamadas.campo.getAttribute('carenciaMaxima');
		var taxasMaxima = chamadas.campo.getAttribute('taxasMaxima');
		var infoComplementar = chamadas.campo.getAttribute('infoComplementar');
		
		var prazoCarenciaF = formataValorNumerico(prazoCarencia);
		var valorTaxasF = formataValorNumerico(valorTaxasFinanciadas);
		var carenciaMaximaF = parseFloat(carenciaMaxima);
		var taxasMaximaF = parseFloat(taxasMaxima);
		if ((prazoCarenciaF < 0)  || (prazoCarenciaF > carenciaMaximaF)) {
			var mensagemInfoComplementar = document.getElementById("mensagemInfoComplementar");
			mensagemInfoComplementar.innerHTML = 'Carência deve ser maior que zero e limitada a ' + carenciaMaxima + '.';
			mensagemInfoComplementar.style.display = 'block';
			setTimeout("chamadas.fade('mensagemInfoComplementar');", ERRO_TIMEOUT);
			return;
		}
		if ((valorTaxasF < 0)  || (valorTaxasF > taxasMaximaF)) {
			var mensagemInfoComplementar = document.getElementById("mensagemInfoComplementar");
			mensagemInfoComplementar.innerHTML = 'Valor das taxas financiadas deve estar compreendido entre zero e ' + taxasMaxima + '.';
			mensagemInfoComplementar.style.display = 'block';
			setTimeout("chamadas.fade('mensagemInfoComplementar');", ERRO_TIMEOUT);
			return;
		}
	
		setaImagem('botaoCalcular');
	
		var link = 'method=simularOperacaoImobiliariaInternetConvenio&valorImovel=' + imovel
			+ '&rendaFamiliarBruta=' + renda + '&tipoImovel=' + tipo
			+ '&grupoTipoFinanciamento=' + grupoTipoFinanciamento + '&dataNascimento=' + dataNascimento
			+ '&uf=' + uf + '&cidade=' + cidade + '&nuItemProduto=' + nuItemProduto + '&nuVersao=' + nuVersao
			+ '&prazo=' + prazoDesejavelConvenio + '&recursosProprios=' + valorEntradaConvenio + '&valorReforma=' + valorReforma
			+ '&nuEmpresa=' + nuEmpresa + '&convenio=' + convenio + '&convenioInicial=false'
			+ '&imovelCidade=' + imovelCidade + '&vaContaFgts=' + vaContaFgts
			+ '&sePermiteCarencia=' + sePermiteCarencia + '&sePermiteCota=' + sePermiteCota + '&sePermiteTaxas=' + sePermiteTaxas
			+ '&carenciaMaxima=' + carenciaMaxima + '&taxasMaxima=' + taxasMaxima + '&sePermiteEhCliente=' + sePermiteEhCliente + '&infoComplementar=' + infoComplementar
			+ '&seEhCliente=' + ehCliente + '&seDesejaCotaFinanciamento=' + desejaCota + '&seDesejaCarencia=' + desejaCarencia
			+ '&prazoCarencia=' + prazoCarencia 
			+ '&seDesejaFinanciarDespesas=' + seDesejaFinanciarDespesas 
			+ '&valorTaxasFinanciadas=' + valorTaxasFinanciadas
			+ '&nomeSeguradora=' + nomeSeguradora
			+ '&codigoSeguradoraSelecionada=' + codigoSeguradora;
		chamadas.enviar('simulaOperacaoInternet.do', link, chamadas.retornoSimulaConvenio);
	}
	// Chamado ao selecionar um item de produto na lista de produtos enquadrados.
	this.simula = function(campo) {
		var form = document.forms[0];
		// Armazena os valores do item de produto selecionado
		this.campo = campo;
		// O subsídio precisa ser revalidado
		this.validadoSubsidio = false;

		setaImagem('produto_img' +  chamadas.campo.getAttribute("codigo") + '.' + chamadas.campo.getAttribute("versao"));

		var imovel = form.valorImovel.value;
		var imovelCidade = form.imovelCidade.checked ? "V" : "F";
		var vaContaFgts = form.vaContaFgts.checked ? "V" : "F";
		var renda = form.rendaFamiliar.value;
		var tipo = form.tipoImovel.value;
		var grupoTipoFinanciamento = form.grupoTipoFinanciamento.value;
		var dataNascimento = form.dataNascimento.value;
		var uf = form.uf.value;
		var cidade = form.cidade.value;
		var nuItemProduto = chamadas.campo.getAttribute('codigo');
		var nuVersao = chamadas.campo.getAttribute('versao');
		var valorReforma = form.valorReforma.value;
		var codigoSeguradora = chamadas.campo.getAttribute("codigoSeguradoraSelecionada");
		var nomeSeguradora = chamadas.campo.getAttribute("nomeSeguradora");
		var dataUltimoBeneficio = form.dataBeneficioFGTS.value;
		var beneficiadoFGTS = form.beneficiadoFGTS.checked ? "V" : "F";
	
		if (codigoSeguradora == null || codigoSeguradora == '') {
			form.codigoSeguradoraSelecionada.value = '1';
			form.nomeSeguradora.value = 'Caixa Seguros';
			codigoSeguradora = '1';
			nomeSeguradora = 'Caixa Seguros';
		}
		
		var link = 'method=simularOperacaoImobiliariaInternet&valorImovel=' + imovel
			+ '&rendaFamiliarBruta=' + renda + '&tipoImovel=' + tipo
			+ '&imovelCidade=' + imovelCidade + '&vaContaFgts=' + vaContaFgts
			+ '&grupoTipoFinanciamento=' + grupoTipoFinanciamento + '&dataNascimento=' + dataNascimento
			+ '&uf=' + uf + '&cidade=' + cidade + '&nuItemProduto=' 
			+ nuItemProduto + '&nuVersao=' + nuVersao 
			+ '&valorReforma=' + valorReforma
			+ '&codigoSeguradoraSelecionada=' + codigoSeguradora
			+ '&nomeSeguradora=' + nomeSeguradora
			+ '&dataBeneficioFGTS=' + dataUltimoBeneficio
			+ '&beneficiadoFGTS=' + beneficiadoFGTS;
		chamadas.enviar('simulaOperacaoInternet.do', link, chamadas.retornoSimula);
	}
	
	this.simulaConvenio = function(campo) {
		var form = document.forms[0];
		// Armazena os valores do item de produto selecionado
		this.campo = campo;
		// O subsídio precisa ser revalidado
		this.validadoSubsidio = false;
		setaImagem('produtoConvenio_img' +  chamadas.campo.getAttribute("codigo") + '.' + chamadas.campo.getAttribute("versao"));

		var imovel = form.valorImovel.value;
		var renda = form.rendaFamiliar.value;
		var tipo = form.tipoImovel.value;
		var grupoTipoFinanciamento = form.grupoTipoFinanciamento.value;
		var dataNascimento = form.dataNascimento.value;
		var uf = form.uf.value;
		var cidade = form.cidade.value;
		var nuItemProduto = chamadas.campo.getAttribute('codigo');
		var nuVersao = chamadas.campo.getAttribute('versao');
		var valorReforma = form.valorReforma.value;
		var sePermiteEhCliente = chamadas.campo.getAttribute('sePermiteEhCliente');
		var sePermiteCarencia = chamadas.campo.getAttribute('sePermiteCarencia');
		var sePermiteCota = chamadas.campo.getAttribute('sePermiteCota');
		var sePermiteTaxas = chamadas.campo.getAttribute('sePermiteTaxas');
		var carenciaMaxima = chamadas.campo.getAttribute('carenciaMaxima');
		var taxasMaxima = chamadas.campo.getAttribute('taxasMaxima');
		var infoComplementar = chamadas.campo.getAttribute('infoComplementar');
		var imovelCidade = form.imovelCidade.checked ? "V" : "F";
		var vaContaFgts = form.vaContaFgts.checked ? "V" : "F";

		var convenio = form.convenio.value;
		var nuEmpresa = chamadas.empresa.getAttribute("nuEmpresa");
		var seEhCliente = (((form.seEhCliente[0]!=null) && (!form.seEhCliente[0].disabled) && (form.seEhCliente[0].checked)) ? "V" : "F");
		var seDesejaCotaFinanciamento = (((form.seDesejaCotaFinanciamento[1]!=null) && (!form.seDesejaCotaFinanciamento[1].disabled) && (form.seDesejaCotaFinanciamento[1].checked)) ? "F" : "V");
		var seDesejaCarencia = (((form.seDesejaCarencia[1]!=null) && (!form.seDesejaCarencia[1].disabled) && (form.seDesejaCarencia[1].checked)) ? "F" : "V");

		var seDesejaFinanciarDespesas = (((form.seDesejaFinanciarDespesas[1]!=null) && (!form.seDesejaFinanciarDespesas[1].disabled) && (form.seDesejaFinanciarDespesas[1].checked)) ? "F" : "V");
		var prazoCarencia = form.prazoCarencia.value;
		var valorTaxasFinanciadas = form.valorTaxasFinanciadas.value;
		var codigoSeguradora = chamadas.campo.getAttribute("codigoSeguradoraSelecionada");
		var nomeSeguradora = chamadas.campo.getAttribute("nomeSeguradora");
		if (codigoSeguradora == null || codigoSeguradora == '') {
			form.codigoSeguradoraSelecionada.value = '1';
			form.nomeSeguradora.value = 'Caixa Seguros';
			codigoSeguradora = '1';
			nomeSeguradora = 'Caixa Seguros';
		}
		
		var link = 'method=simularOperacaoImobiliariaInternetConvenio&valorImovel=' + imovel
			+ '&rendaFamiliarBruta=' + renda + '&tipoImovel=' + tipo
			+ '&imovelCidade=' + imovelCidade + '&vaContaFgts=' + vaContaFgts
			+ '&grupoTipoFinanciamento=' + grupoTipoFinanciamento + '&dataNascimento=' + dataNascimento
			+ '&uf=' + uf + '&cidade=' + cidade + '&nuItemProduto=' + nuItemProduto  + '&convenioInicial=true'
			+ '&nuVersao=' + nuVersao + '&valorReforma=' + valorReforma + '&nuEmpresa=' + nuEmpresa + '&convenio=' + convenio
			+ '&sePermiteCarencia=' + sePermiteCarencia + '&sePermiteCota=' + sePermiteCota + '&sePermiteTaxas=' + sePermiteTaxas
			+ '&carenciaMaxima=' + carenciaMaxima + '&taxasMaxima=' + taxasMaxima + '&sePermiteEhCliente=' + sePermiteEhCliente + '&infoComplementar=' + infoComplementar
			+ '&seEhCliente=' + seEhCliente + '&seDesejaCotaFinanciamento=' + seDesejaCotaFinanciamento + '&seDesejaCarencia=' + seDesejaCarencia
			+ '&prazoCarencia=' + prazoCarencia + '&seDesejaFinanciarDespesas=' + seDesejaFinanciarDespesas 
			+ '&valorTaxasFinanciadas=' + valorTaxasFinanciadas
			+ '&nomeSeguradora=' + nomeSeguradora
			+ '&codigoSeguradoraSelecionada=' + codigoSeguradora;
		chamadas.enviar('simulaOperacaoInternet.do', link, chamadas.retornoSimulaConvenio);
	}

	// Preenche os dados da simulação.
	this.retornoSimula = function(xml) {
		var form = document.forms[0];
		
		document.getElementById('botaoCalcular').innerHTML = '<a href="javascript: void(0)" onclick="chamadas.confirmaPrazo()"><img src="' + form.contexto.value + '/imagens/simulador/CALCULAR.jpg">';
		removeImagem('produto_img' +  chamadas.campo.getAttribute("codigo") + '.' + chamadas.campo.getAttribute("versao"));

		// Nome do item de produto que fica em cima da tela de resultado
		document.getElementById("nomeProduto").innerHTML = chamadas.campo.getAttribute('nome');
		// Nome do item de produto que fica em cima da tela de evolução
		document.getElementById("evolucaoProduto").innerHTML = chamadas.campo.getAttribute('nome');

		var headerSimulacao = document.getElementById("headerSimulacao");
		var headerSimulacaoConvenio = document.getElementById("headerSimulacaoConvenio");

		headerSimulacao.style.display = 'block';
		headerSimulacaoConvenio.style.display = 'none';

		var convenio = form.convenio.value;
		if ((convenio!=null)&&(convenio!='')&&(convenio.length > 0)) {
			document.getElementById("linkVoltarConvenio").onclick = voltaProdutosConvenio;
			document.getElementById("linkVoltarConvenioBotoes").onclick = voltaProdutosConvenio;
		} else {
			document.getElementById("linkVoltarConvenio").onclick = voltaProdutos;
			document.getElementById("linkVoltarConvenioBotoes").onclick = voltaProdutos;
		}
		document.getElementById('resultadoVoltar').style.display = 'block';
		document.getElementById('resultadoBotoes').style.display = 'none';
		document.getElementById('resultadoLinks').style.display = 'none';
		document.getElementById('condicoes').innerHTML = '';
		document.getElementById('resultadoMip1').value = '';
		document.getElementById('resultadoDfi1').value = '';
		
		var root = xml.getElementsByTagName("root");
		var temSubsidio;
		var altDadosSimulacao;
		var valor;
		var valor2;
		var exibeCombo = true;
		
		for (var i = 0; i < root.length; i++) {
			var child = root[i];

			var erro = child.getElementsByTagName("error");
			if (erro.length > 0) {
				var desc = erro[0].firstChild.nodeValue;
				var nomeCampo = 'produto' +  chamadas.campo.getAttribute("codigo") + '.' + chamadas.campo.getAttribute("versao");
				var erroLocal = document.getElementById(nomeCampo);
				erroLocal.innerHTML = 'Cálculo não disponível para este produto.';
				erroLocal.style.display = 'block';
				setTimeout("chamadas.fade('" + nomeCampo + "');", 5000);
			} else {
				// Verifica se a simulação possui subsídio
				temSubsidio = child.getElementsByTagName("temSubsidio");
				if (temSubsidio.length > 0 && temSubsidio[0].firstChild != null 
						&& (temSubsidio[0].firstChild.nodeValue == 'V'
						|| temSubsidio[0].firstChild.nodeValue == '"V"'
						|| temSubsidio[0].firstChild.nodeValue == 'TRUE')) {
					temSubsidio = true;
				} else {
					temSubsidio = false;
				}
				altDadosSimulacao = child.getElementsByTagName("altDadosSimulacao");
				if (altDadosSimulacao.length > 0 && altDadosSimulacao[0].firstChild != null 
						&& (altDadosSimulacao[0].firstChild.nodeValue == 'V'
						|| altDadosSimulacao[0].firstChild.nodeValue == '"V"'
						|| altDadosSimulacao[0].firstChild.nodeValue == 'TRUE')) {
					altDadosSimulacao = true;
				} else {
					altDadosSimulacao = false;
				}
				
				document.getElementById("linkAlteraPrazo").onclick = alteraPrazo;

				document.getElementById("resultadoValorImovel").innerHTML = form.valorImovel.value;
				// Prazo Máximo
				valor = child.getElementsByTagName("prazoMaximo");
				if (valor.length > 0 && valor[0].firstChild != null) {
					document.getElementById("resultadoPrazoMaximo").innerHTML = valor[0].firstChild.nodeValue;
				} else {
					document.getElementById("resultadoPrazoMaximo").innerHTML = '';
				}
				
				valor = child.getElementsByTagName("nomeSeguradora");
				if (valor.length > 0 && valor[0].firstChild != null) {
					document.getElementById("resultadoNomeSeguradora").innerHTML = valor[0].firstChild.nodeValue;
					document.getElementById("nomeSeguradora").value = valor[0].firstChild.nodeValue;
				} else {
					document.getElementById("resultadoNomeSeguradora").innerHTML = '';
					document.getElementById("nomeSeguradora").value = '';
				}

				valor = child.getElementsByTagName("codigoSeguradora");
				if (valor.length > 0 && valor[0].firstChild != null) {
					document.getElementById("codigoSeguradoraSelecionada").value = valor[0].firstChild.nodeValue;
				} else {
					document.getElementById("codigoSeguradoraSelecionada").value = '';
				}
				
				// Sistema de Amortização
				valor = child.getElementsByTagName("sistemaAmortizacao");
				if (valor.length > 0 && valor[0].firstChild != null) {
					document.getElementById("resultadoSistemaAmortizacao").innerHTML = valor[0].firstChild.nodeValue;
					form.descAmortizacao.value = valor[0].firstChild.nodeValue;
				} else {
					document.getElementById("resultadoSistemaAmortizacao").innerHTML = '';
					form.descAmortizacao.value = '';
				}
				
				
				// Sistema de Amortização
				valor = child.getElementsByTagName("codSistemaAmortizacao");
				if (valor.length > 0 && valor[0].firstChild != null) {
					form.codAmortizacao.value = valor[0].firstChild.nodeValue;
				} else {
					form.codAmortizacao.value = '';
				}
				
				// Sistema de Amortização
				valor = child.getElementsByTagName("numeroAmortizacao");
				if (valor.length > 0 && valor[0].firstChild != null) {
					form.numeroAmortizacao.value = valor[0].firstChild.nodeValue;
				} else {
					form.numeroAmortizacao.value = '';
				}
				
				/*
				 * Não deverá exibir o gráfico se a operação do item de produto
				 * estiver configurada com essa opção.
				 */
				valor = child.getElementsByTagName("icGrafico");
				if (valor.length > 0 && valor[0].firstChild != null) {
					var exibeGrafico = valor[0].firstChild.nodeValue;
					if(exibeGrafico == 'S'){
						document.getElementById('graficoAmortizacao').style.display = 'block';
					}else{
						document.getElementById('graficoAmortizacao').style.display = 'none';
					}
				}
				
				// Tipo de Financiamento
				valor = child.getElementsByTagName("tipoFinanciamento");
				if (valor.length > 0 && valor[0].firstChild != null) {
					form.tipoFinanciamento.value = valor[0].firstChild.nodeValue;
				} else {
					form.tipoFinanciamento.value.innerHTML = '';
				}

				// Mensagem
				valor = child.getElementsByTagName("mensagem");
				if (valor.length > 0 && valor[0].firstChild != null) {
					document.getElementById("resultadoMensagem").innerHTML = valor[0].firstChild.nodeValue;
				} else {
					document.getElementById("resultadoMensagem").innerHTML = 
					     'Os resultados obtidos representam apenas uma simulação e não valem como proposta,' + 
					     ' pois estão sujeitos a alterações de acordo com a apuração da capacidade de pagamento' + 
					     ' e à aprovação da análise de crédito a ser efetuada pela CAIXA. Poderá haver alterações das taxas,' + 
					     ' dos prazos máximos e das demais condições, sem aviso prévio. A contratação está condicionada a' + 
					     ' disponibilidade de recursos para sua região e ao atendimento das exigências do programa.';
				}

				// Cota máxima
				valor = child.getElementsByTagName("cotaMaxima");
				if (valor.length > 0 && valor[0].firstChild != null) {
					document.getElementById("resultadoCotaMaximaFinanciamento").innerHTML = valor[0].firstChild.nodeValue;
				} else {
					document.getElementById("resultadoCotaMaximaFinanciamento").innerHTML = '';
				}
				
				// Taxas a Vista
				valor = child.getElementsByTagName("taxasVista");
				if (valor.length > 0 && valor[0].firstChild != null) {
					form.taxasVista.value = valor[0].firstChild.nodeValue;
				} else {
					form.taxasVista.value = '';
				}
				
				// Caso exista um subsídio e precise ser validado.
				if (!chamadas.validadoSubsidio && (altDadosSimulacao||temSubsidio)) {
					
					// Recursos próprios
					valor = child.getElementsByTagName("recursosProprios");
					if (valor.length > 0 && valor[0].firstChild != null) {
						document.forms[0].valorEntrada.value = valor[0].firstChild.nodeValue;
					}
					
					valor2 = child.getElementsByTagName("prestacao");
					if (valor2.length > 0 && valor2[0].firstChild != null) {
						valor = valor2[0].getElementsByTagName("mip");
						if (valor.length > 0 && valor[0].firstChild != null) {
							document.getElementById("resultadoMip1").value = valor[0].firstChild.nodeValue;
						} else {
							document.getElementById("resultadoMip1").value = '';
						}
	
						valor = valor2[0].getElementsByTagName("dfi");
						if (valor.length > 0 && valor[0].firstChild != null) {
							document.getElementById("resultadoDfi1").value = valor[0].firstChild.nodeValue;
						} else {
							document.getElementById("resultadoDfi1").value = '';
						}
					}	

					// Prazo
					valor = child.getElementsByTagName("prazo");
					if (valor.length > 0 && valor[0].firstChild != null) {
						document.forms[0].prazoDesejavel.value = valor[0].firstChild.nodeValue;
					}

					exibeCombo = chamadas.preencherSeguradoras(
							child.getElementsByTagName("seguradoras"));
					
					// Mostra a DIV de entrada do prazo e recursos próprios
					document.getElementById("subsidioParcela").style.display = 'block';
					// Esconde a DIV de resultado da simulação
					document.getElementById("subsidio").style.display = 'none';
					document.getElementById("convenioSimulacao").style.display = 'none';
					document.getElementById("cabecalhoComplementoConvenio").style.display = 'none';

					document.getElementById("cabecalhoComplemento").style.display = 'block';
					limparCombosSeguradora(exibeCombo);
				} else {
					// Caso o subsídio não exista ou não precise ser validado
					document.getElementById('resultadoVoltar').style.display = 'none';
					document.getElementById('resultadoBotoes').style.display = 'block';
					
					/*
					 * Não deverá ser exibido o link "Consulte seu FGTS"
					 * Se a operação do item de produto não estiver
					 * configurado com essa opção.
					 */
					valor = child.getElementsByTagName("icLinkFgts");
					if (valor.length > 0 && valor[0].firstChild != null) {
						var exibeLinkFGTS = valor[0].firstChild.nodeValue;
						
						if(exibeLinkFGTS == 'S'){
							document.getElementById('resultadoLinks').style.display = 'block';
						}else{
							document.getElementById('resultadoLinks').style.display = 'none';
						}
					}
					
					
					var contratar = chamadas.campo.getAttribute("contratar");
					if (contratar != '') {
						var c = document.getElementById('comoContratar'); 
						c.href = contratar;
						c.style.display = 'block';
						c.target = '_new';
						var c = document.getElementById('comoContratar2');
						c.href = contratar;
						c.style.display = 'block';
						c.target = '_new';
					} else {
						document.getElementById('comoContratar').style.display = 'none';
						document.getElementById('comoContratar2').style.display = 'none';
					}
					var documentacao = chamadas.campo.getAttribute("documentacao");
					if (documentacao != '') {
						var d = document.getElementById('documentacao');
						d.href = documentacao;
						d.style.display = 'block';
						d.target = '_new';
						var d = document.getElementById('documentacao2');
						d.href = documentacao;
						d.style.display = 'block';
						d.target = '_new';
					} else {
						document.getElementById('documentacao').style.display = 'none';
						document.getElementById('documentacao2').style.display = 'none';
					}
					
					// Esconde a DIV de entrada do prazo e recursos próprios
					document.getElementById("subsidioParcela").style.display = 'none';
					// Mostra a DIV de resultado da simulação
					document.getElementById("subsidio").style.display = 'block';
					
					document.getElementById("convenioSimulacao").style.display = 'none';

					document.getElementById("cabecalhoComplementoConvenio").style.display = 'none';

					document.getElementById("cabecalhoComplemento").style.display = 'block';
					// Se tem subsídio, mostrar o seu valor, caso contrário, esconder o campo
					if (temSubsidio) {
						// Mostrar o valor de subsídio
						document.getElementById("resultadoNomeSubsidio").style.display = 'block';
						// Valor do subsídio
						valor = child.getElementsByTagName("valorSubsidio");
						if (valor.length > 0 && valor[0].firstChild != null) {
							document.getElementById('resultadoValorSubsidio').innerHTML = valor[0].firstChild.nodeValue;
							document.getElementById('resultadoValorSubsidioDisplay').style.display = 'block';
						}
					} else {
						// Não mostrar o valor de subsídio
						document.getElementById("resultadoNomeSubsidio").style.display = 'none';
						document.getElementById('resultadoValorSubsidio').innerHTML = '';
						document.getElementById('resultadoValorSubsidioDisplay').style.display = 'none';
					}

					// TR Projetada
					valor = child.getElementsByTagName("trProjetada");
					if (valor.length > 0 && valor[0].firstChild != null) {
						form.evolucaoTrProjetada.value = valor[0].firstChild.nodeValue;
					} else {
						form.evolucaoTrProjetada.value = '';
					}

					// Recursos próprios
					valor = child.getElementsByTagName("recursosProprios");
					if (valor.length > 0 && valor[0].firstChild != null) {
						document.getElementById("resultadoValorEntrada").innerHTML = valor[0].firstChild.nodeValue;
						document.getElementById('evolucaoValorEntrada').innerHTML =  valor[0].firstChild.nodeValue;
						document.forms[0].valorEntrada.value = valor[0].firstChild.nodeValue;
					} else {
						document.getElementById("resultadoValorEntrada").innerHTML = '0,00';
						document.getElementById('evolucaoValorEntrada').innerHTML = '0,00';
						document.forms[0].valorEntrada.value = '';
					}
					
					// Prazo
					valor = child.getElementsByTagName("prazo");
					if (valor.length > 0 && valor[0].firstChild != null) {
						document.getElementById("resultadoPrazo").innerHTML = valor[0].firstChild.nodeValue;
						document.getElementById("resultadoPrazo").innerHTML = valor[0].firstChild.nodeValue;
						document.forms[0].prazoDesejavel.value = valor[0].firstChild.nodeValue;
					} else {
						document.getElementById("resultadoPrazo").innerHTML = '';
						document.getElementById("resultadoPrazo").innerHTML = '';
						document.forms[0].prazoDesejavel.value = '';
					}
					
					// Valor de Financiamento
					valor = child.getElementsByTagName("valorFinanciamento");
					if (valor.length > 0 && valor[0].firstChild != null) {
						// Tela de resultado
						document.getElementById("resultadoValorFinanciamento").innerHTML = valor[0].firstChild.nodeValue;
						// Tela de evolução
						document.getElementById("evolucaoValorFinanciamento").innerHTML = valor[0].firstChild.nodeValue;
					} else {
						document.getElementById("resultadoValorFinanciamento").innerHTML = '';
						document.getElementById("evolucaoValorFinanciamento").innerHTML = '';
					}
					
					// 1º Prestação
					valor2 = child.getElementsByTagName("prestacao");
					if (valor2.length > 0 && valor2[0].firstChild != null) {
						chamadas.preencherTaxasGenericas(valor2[0]);

						valor = valor2[0].getElementsByTagName("encargo");
						if (valor.length > 0 && valor[0].firstChild != null) {
							document.getElementById("resultadoPrestacao1").innerHTML = valor[0].firstChild.nodeValue;
						} else {
							document.getElementById("resultadoPrestacao1").innerHTML = '';
						}

						valor = valor2[0].getElementsByTagName("amortizacao");
						if (valor.length > 0 && valor[0].firstChild != null) {
							document.getElementById("resultadoAmortizacao1").value = valor[0].firstChild.nodeValue;
						} else {
							document.getElementById("resultadoAmortizacao1").value = '';
						}

						valor = valor2[0].getElementsByTagName("juros");
						if (valor.length > 0 && valor[0].firstChild != null) {
							document.getElementById("resultadoJuros1").value = valor[0].firstChild.nodeValue;
						} else {
							document.getElementById("resultadoJuros1").value = '';
						}
						
						
						valor = valor2[0].getElementsByTagName("percentualJuros");
						if (valor.length > 0 && valor[0].firstChild != null) {
							document.getElementById("resultadoPercentualJuros1").value = valor[0].firstChild.nodeValue;
						} else {
							document.getElementById("resultadoPercentualJuros1").value = '';
						}

						valor = valor2[0].getElementsByTagName("jurosNominal");
						if (valor.length > 0 && valor[0].firstChild != null) {
							document.getElementById("resultadoJurosNominais1").innerHTML = valor[0].firstChild.nodeValue;
						} else {
							document.getElementById("resultadoJurosNominais1").innerHTML = '';
						}

						valor = valor2[0].getElementsByTagName("jurosEfetivo");
						if (valor.length > 0 && valor[0].firstChild != null) {
							document.getElementById("resultadoJurosEfetivos1").innerHTML = valor[0].firstChild.nodeValue;
						} else {
							document.getElementById("resultadoJurosEfetivos1").innerHTML = '';
						}

                        valor = child.getElementsByTagName("codSistemaAmortizacao");
						if (valor.length > 0 && valor[0].firstChild != null) {
							document.getElementById("resultadoCodAmortizacao1").value = valor[0].firstChild.nodeValue;
						} else {
							document.getElementById("resultadoCodAmortizacao1").value = '';
						}

						valor = child.getElementsByTagName("sistemaAmortizacao");
						if (valor.length > 0 && valor[0].firstChild != null) {
							document.getElementById("resultadoDescAmortizacao1").value = valor[0].firstChild.nodeValue;
						} else {
							document.getElementById("resultadoDescAmortizacao1").value = '';
						}

						valor = valor2[0].getElementsByTagName("mip");
						if (valor.length > 0 && valor[0].firstChild != null) {
							document.getElementById("resultadoMip1").value = valor[0].firstChild.nodeValue;
						} else {
							document.getElementById("resultadoMip1").value = '';
						}

						valor = valor2[0].getElementsByTagName("dfi");
						if (valor.length > 0 && valor[0].firstChild != null) {
							document.getElementById("resultadoDfi1").value = valor[0].firstChild.nodeValue;
						} else {
							document.getElementById("resultadoDfi1").value = '';
						}

						valor = valor2[0].getElementsByTagName("taxa");
						if (valor.length > 0 && valor[0].firstChild != null) {
							document.getElementById("resultadoTaxa1").value = valor[0].firstChild.nodeValue;
						} else {
							document.getElementById("resultadoTaxa1").value = '';
						}

						valor = valor2[0].getElementsByTagName("taxaAdministracao");
						if (valor.length > 0 && valor[0].firstChild != null) {
							document.getElementById("resultadoTaxaAdministracao1").value = valor[0].firstChild.nodeValue;
						} else {
							document.getElementById("resultadoTaxaAdministracao1").value = '';
						}

						valor = valor2[0].getElementsByTagName("riscoCredito");
						if (valor.length > 0 && valor[0].firstChild != null) {
							document.getElementById("resultadoRiscoCredito1").value = valor[0].firstChild.nodeValue;
						} else {
							document.getElementById("resultadoRiscoCredito1").value = '';
						}
					}
					
					cor = true;
					// Condicoes
					valor2 = child.getElementsByTagName("condicao");
					if (valor2.length > 0 && valor2[0].firstChild != null) {
						for (var icondicao = 0; icondicao < valor2.length; icondicao++) {
							chamadas.preencheCondicao(icondicao, valor2[icondicao]);
						}
					}
				}
				// Ajusta a tela
				var produtos = document.getElementById("produtos");
				var resultado = document.getElementById("resultado");
				var evolucao = document.getElementById("evolucao");
				var produtosConvenio = document.getElementById("produtosConvenio");
				
				produtosConvenio.style.display = 'none';
				produtos.style.display = 'none';
				evolucao.style.display = 'none';
				resultado.style.display = 'block';
				limparCombosSeguradora(exibeCombo);
			}
		}
	};// Fim retornoSimula
	
	this.preencherSeguradoras = function(listaSeguradoras) {
		var comboSeguradoras = document.getElementById("cmbSeguradoras");
		var comboSeguradorasConvenio = document.getElementById(
				"cmbSeguradorasConvenio");
		var exibeCombo = false;
		if (comboSeguradoras && listaSeguradoras != null) {
			var seguradoras = listaSeguradoras[0].getElementsByTagName("seguradora");
			comboSeguradoras.length = 0;

			comboSeguradoras.options[0] = new Option("Selecione ------->", 
					"", true, false);
			comboSeguradorasConvenio.options[0] = new Option(
					"Selecione ------->", "", true, false);
			var nomeSeguradora;
			var codigoSeguradora;
			exibeCombo = seguradoras.length > 1;
			for (var i = 0; i < seguradoras.length; i++) {
				nomeSeguradora = chamadas.obterValor(seguradoras[i], 'nome');
				codigoSeguradora = chamadas.obterValor(seguradoras[i], 'codigo');
				comboSeguradoras.options[i + 1] = new Option(nomeSeguradora, 
						codigoSeguradora, false, false);
				comboSeguradorasConvenio.options[i + 1] = new Option(nomeSeguradora,
						codigoSeguradora, false, false);
			}
			
			if (seguradoras.length > 0 && !exibeCombo) {
				iniciarValoresSeguradora(codigoSeguradora, nomeSeguradora);
			}
		}
		return exibeCombo;
	};
	
	function iniciarValoresSeguradora(codigo, nome) {
		var labelSeguradora = document.getElementById(
				'labelSeguradora');
		if (labelSeguradora) {
			labelSeguradora.innerHTML = nome;
		}
		
		var labelSeguradora = document.getElementById(
				'labelSeguradoraConvenio');
		if (labelSeguradora) {
			labelSeguradora.innerHTML = nome;
		}
		
		var campo = document.forms[0].codigoSeguradoraSelecionada;
		if (campo) {
			campo.value = codigo;
		}

		var campo = document.forms[0].nomeSeguradora;
		if (campo) {
			campo.value = nome;
		}
	}
	
	this.preencherTaxasGenericas = function(node) {
		var form = document.forms[0];
		form.nomeTaxaGenerica1.value = chamadas.obterValor(node, 'nomeTaxaGenerica1');
		form.nomeTaxaGenerica2.value = chamadas.obterValor(node, 'nomeTaxaGenerica2');
		form.valorTaxaGenerica1.value = chamadas.obterValor(node, 'valorTaxaGenerica1');
		form.valorTaxaGenerica2.value = chamadas.obterValor(node, 'valorTaxaGenerica2');
		form.valorPercentualGenerica1.value = chamadas.obterValor(node, 'valorPercentualGenerica1');
		
		document.getElementById('resultadoValorTaxaGenerica11').value = form.valorTaxaGenerica1.value;
		document.getElementById('resultadoValorTaxaGenerica21').value = form.valorTaxaGenerica2.value;
	}
	
	this.obterValor = function(node, nomeAtributo) {
		var valor = node.getElementsByTagName(nomeAtributo);
		if (valor.length > 0 && valor[0].firstChild != null) {
			valor = valor[0].firstChild.nodeValue;
		}else {
			valor = '';
		}
		return valor;
	}

	// Preenche os dados da simulação.
	this.retornoSimulaWS = function(xml) {
		var form = document.forms[0];
		

		var root = xml.getElementsByTagName("root");
		var temSubsidio;
		var altDadosSimulacao;
		var valor;
		var valor2;
		
		for (var i = 0; i < root.length; i++) {
			var child = root[i];
				
			var itemProduto = child.getElementsByTagName("itemproduto");
			if ((itemProduto!=null)&&(itemProduto.length > 0)) {
			    var itemPrdXML = itemProduto[0];
				var codigoIPIn = itemPrdXML.getElementsByTagName("codigo");
				var codigoIP = '';
				if (codigoIPIn.length > 0 && codigoIPIn[0].firstChild != null) {
					codigoIP = codigoIPIn[0].firstChild.nodeValue;
				}
				var nomeIPIn = itemPrdXML.getElementsByTagName("nome");
				var nomeIP = '';
				if (nomeIPIn.length > 0 && nomeIPIn[0].firstChild != null) {
					nomeIP = nomeIPIn[0].firstChild.nodeValue;
				}
				var versaoIPIn = itemPrdXML.getElementsByTagName("versao");
				var versaoIP = '';
				if (versaoIPIn.length > 0 && versaoIPIn[0].firstChild != null) {
					versaoIP = versaoIPIn[0].firstChild.nodeValue;
				}
				var descricaoIPIn = itemPrdXML.getElementsByTagName("descricao");
				var descricaoIP = '';
				if (descricaoIPIn.length > 0 && descricaoIPIn[0].firstChild != null) {
					descricaoIP = descricaoIPIn[0].firstChild.nodeValue;
				}
				var linkIPIn = itemPrdXML.getElementsByTagName("link");
				var linkIP = '';
				if (linkIPIn.length > 0 && linkIPIn[0].firstChild != null) {
					linkIP = linkIPIn[0].firstChild.nodeValue;
				}
				var documentacaoIPIn = itemPrdXML.getElementsByTagName("documentacao");
				var documentacaoIP = '';
				if (documentacaoIPIn.length > 0 && documentacaoIPIn[0].firstChild != null) {
					documentacaoIP = documentacaoIPIn[0].firstChild.nodeValue;
				}
				form.nuItemProdutoWS.value = codigoIP;
				form.nuVersaoWS.value = versaoIP;
				
				var parametros = child.getElementsByTagName("parametros");
				if ((parametros!=null)&&(parametros.length > 0)) {
				    var parametrosXML = parametros[0];
				    var rendaFamiliar = parametrosXML.getElementsByTagName("rendaFamiliar");
				    var dataNascimento = parametrosXML.getElementsByTagName("dataNascimento");
				    var valorImovel = parametrosXML.getElementsByTagName("valorImovel");
				    var tipoImovel = parametrosXML.getElementsByTagName("tipoImovel");
				    var grupoTipoFinanciamento = parametrosXML.getElementsByTagName("grupoTipoFinanciamento");
				    var uf = parametrosXML.getElementsByTagName("uf");
				    var cidade = parametrosXML.getElementsByTagName("cidade");
					var fisica = parametrosXML.getElementsByTagName("fisica");
					var juridica = parametrosXML.getElementsByTagName("juridica");
					var imovelCidade = parametrosXML.getElementsByTagName("imovelCidade");
					var vaContaFgts = parametrosXML.getElementsByTagName("contaFGTS");
					if (rendaFamiliar.length > 0 && rendaFamiliar[0].firstChild != null) {
						form.rendaFamiliar.value = rendaFamiliar[0].firstChild.nodeValue;
					} else {
						form.rendaFamiliar.value = '';
					}	
					if (dataNascimento.length > 0 && dataNascimento[0].firstChild != null) {
						form.dataNascimento.value = dataNascimento[0].firstChild.nodeValue;
					} else {
						form.dataNascimento.value = '';
					}	
					if (valorImovel.length > 0 && valorImovel[0].firstChild != null) {
						form.valorImovel.value = valorImovel[0].firstChild.nodeValue;
					} else {
						form.valorImovel.value = '';
					}	
					if (tipoImovel.length > 0 && tipoImovel[0].firstChild != null) {
						form.tipoImovel.value = tipoImovel[0].firstChild.nodeValue;
						var i;
						for (i = 0;i < form.tipoImovel.options.length;i++) {
						   if ((form.tipoImovel.options[i]!=null)&&(form.tipoImovel.options[i].value == tipoImovel[0].firstChild.nodeValue)) {
								form.tipoImovel.selectedIndex = i;
								break;
						   }
						}
					} else {
						form.tipoImovel.value = '';
					}	
					if (uf.length > 0 && uf[0].firstChild != null) {
						form.uf.value = uf[0].firstChild.nodeValue;
						var i;
						for (i = 0;i < form.uf.options.length;i++) {
						   if ((form.uf.options[i]!=null)&&(form.uf.options[i].value == uf[0].firstChild.nodeValue)) {
								form.uf.selectedIndex = i;
								break;
						   }
						}
					} else {
						form.uf.value = '';
					}	
					if (fisica.length > 0 && fisica[0].firstChild != null) {
						if ((fisica[0].firstChild.nodeValue!=null)&&(fisica[0].firstChild.nodeValue == 'V')) {
							form.pessoa[0].checked = true;
						} else {
							form.pessoa[0].checked = false;
						}
					} else {
						form.pessoa[0].checked = false;
					}	
					if (juridica.length > 0 && juridica[0].firstChild != null) {
						if ((juridica[0].firstChild.nodeValue!=null)&&(juridica[0].firstChild.nodeValue == 'V')) {
							form.pessoa[1].checked = true;
						} else {
							form.pessoa[1].checked = false;
						}
					} else {
						form.pessoa[1].checked = false;
					}	
					if (imovelCidade.length > 0 && imovelCidade[0].firstChild != null) {
						if ((imovelCidade[0].firstChild.nodeValue!=null)&&(imovelCidade[0].firstChild.nodeValue == 'V')) {
							form.imovelCidade.checked = true;
						} else {
							form.imovelCidade.checked = false;
						}
					} else {
						form.imovelCidade.checked = false;
					}	
					if (vaContaFgts.length > 0 && vaContaFgts[0].firstChild != null) {
						if ((vaContaFgts[0].firstChild.nodeValue!=null)&&(vaContaFgts[0].firstChild.nodeValue == 'V')) {
							form.vaContaFgts.checked = true;
						} else {
							form.vaContaFgts.checked = false;
						}
					} else {
						form.vaContaFgts.checked = false;
					}	
					form.valorReforma.value = '';
					form.convenio.value = '';
					if (cidade.length > 0 && cidade[0].firstChild != null) {
						form.cidade.value = cidade[0].firstChild.nodeValue;
						var i;
						for (i = 0;i < form.cidade.options.length;i++) {
						   if ((form.cidade.options[i]!=null)&&(form.cidade.options[i].value == cidade[0].firstChild.nodeValue)) {
								form.cidade.selectedIndex = i;
								break;
						   }
						}
					} else {
						form.cidade.value = '';
					}	
					if (grupoTipoFinanciamento.length > 0 && grupoTipoFinanciamento[0].firstChild != null) {
						form.grupoTipoFinanciamento.value = grupoTipoFinanciamento[0].firstChild.nodeValue;
						var i;
						for (i = 0;i < form.grupoTipoFinanciamento.options.length;i++) {
						   if ((form.grupoTipoFinanciamento.options[i]!=null)&&(form.grupoTipoFinanciamento.options[i].value == grupoTipoFinanciamento[0].firstChild.nodeValue)) {
								form.grupoTipoFinanciamento.selectedIndex = i;
								break;
						   }
						}
					} else {
						form.grupoTipoFinanciamento.value = '';
					}	
					form.inicioWS.value = 'V';
					// Preenche o cabeçalho da tela
					var campo;
	
					// Tipo de Imóvel
					campo = document.getElementById("headerTipo");
					campo.innerHTML = form.tipoImovel.options[form.tipoImovel.selectedIndex].text;
					
					// Grupo de tipo de financiamento
					campo = document.getElementById("headerCategoria");
					campo.innerHTML = form.grupoTipoFinanciamento.options[form.grupoTipoFinanciamento.selectedIndex].text;
	
					// Valor do Imóvel
					campo = document.getElementById("headerValor");
					campo.innerHTML = 'R$ ' + form.valorImovel.value;
	
					// Cidade + "-" + UF 
					campo = document.getElementById("headerCidade");
					campo.innerHTML = form.cidade.options[form.cidade.selectedIndex].text
						+ "-" + form.uf.options[form.uf.selectedIndex].text;
					if (form.imovelCidade.checked) {
						campo.innerHTML += ' - Possui imóvel neste município.'; 
					}
					campo = document.getElementById("headerRegimeFGTS");
					if (form.vaContaFgts.checked) {
						campo.innerHTML = ' Sim'; 
					} else {
						campo.innerHTML = ' Não';
					}
					// Renda Familiar Bruta
					campo = document.getElementById("headerRenda");
					if (form.rendaFamiliar.value != '') {
						campo.innerHTML = 'R$ ' + form.rendaFamiliar.value;
					}else {
						campo.innerHTML = '';
					}
					
					campo = document.getElementById("headerBeneficiadoFGTS");
					if (form.beneficiadoFGTS.checked) {
						campo.innerHTML = ' Sim'; 
						campo = document.getElementById("headerDataBeneficioFGTS");
						campo.innerHTML = form.dataBeneficioFGTS.value; 
					} else {
						campo.innerHTML = ' Não';
						campo = document.getElementById("headerDataBeneficioFGTS");
						campo.innerHTML = ''; 
					}

					// Data de Nascimento 
					campo = document.getElementById("headerData");
					campo.innerHTML = form.dataNascimento.value;
					document.getElementById('botaoCalcular').innerHTML = '<a href="javascript: void(0)" onclick="chamadas.confirmaPrazo()"><img src="' + form.contexto.value + '/imagens/simulador/CALCULAR.jpg">';
			
					// Nome do item de produto que fica em cima da tela de resultado
					document.getElementById("nomeProduto").innerHTML = nomeIP;
					// Nome do item de produto que fica em cima da tela de evolução
					document.getElementById("evolucaoProduto").innerHTML = nomeIP;
					var headerSimulacao = document.getElementById("headerSimulacao");
					var headerSimulacaoConvenio = document.getElementById("headerSimulacaoConvenio");
			
					headerSimulacao.style.display = 'block';
					headerSimulacaoConvenio.style.display = 'none';
			
					var convenio = form.convenio.value;
					document.getElementById("linkVoltarConvenio").onclick = voltaParametros;
					document.getElementById("linkVoltarConvenioBotoes").onclick = voltaParametros;
					document.getElementById('resultadoVoltar').style.display = 'block';
					document.getElementById('resultadoBotoes').style.display = 'none';
					document.getElementById('resultadoLinks').style.display = 'none';
					document.getElementById('condicoes').innerHTML = '';
					var erro = child.getElementsByTagName("error");
					if (erro.length > 0) {
						var desc = erro[0].firstChild.nodeValue;
						var nomeCampo = 'produto' +  codigoIP + '.' + versaoIP;
						var erroLocal = document.getElementById(nomeCampo);
						erroLocal.innerHTML = 'Cálculo não disponível para este produto.';
						erroLocal.style.display = 'block';
						setTimeout("chamadas.fade('" + nomeCampo + "');", 5000);
					} else {
						// Verifica se a simulação possui subsídio
						temSubsidio = child.getElementsByTagName("temSubsidio");
						if (temSubsidio.length > 0 && temSubsidio[0].firstChild != null 
								&& (temSubsidio[0].firstChild.nodeValue == 'V'
								|| temSubsidio[0].firstChild.nodeValue == '"V"'
								|| temSubsidio[0].firstChild.nodeValue == 'TRUE')) {
							temSubsidio = true;
						} else {
							temSubsidio = false;
						}
						
						altDadosSimulacao = child.getElementsByTagName("altDadosSimulacao");
						if (altDadosSimulacao.length > 0 && altDadosSimulacao[0].firstChild != null 
								&& (altDadosSimulacao[0].firstChild.nodeValue == 'V'
								|| altDadosSimulacao[0].firstChild.nodeValue == '"V"'
								|| altDadosSimulacao[0].firstChild.nodeValue == 'TRUE')) {
							altDadosSimulacao = true;
						} else {
							altDadosSimulacao = false;
						}

						document.getElementById("linkAlteraPrazo").onclick = alteraPrazo;
		
						document.getElementById("resultadoValorImovel").innerHTML = form.valorImovel.value;
						// Prazo Máximo
						valor = child.getElementsByTagName("prazoMaximo");
						if (valor.length > 0 && valor[0].firstChild != null) {
							document.getElementById("resultadoPrazoMaximo").innerHTML = valor[0].firstChild.nodeValue;
						} else {
							document.getElementById("resultadoPrazoMaximo").innerHTML = '';
						}
		
						// Sistema de Amortização
						valor = child.getElementsByTagName("sistemaAmortizacao");
						if (valor.length > 0 && valor[0].firstChild != null) {
							document.getElementById("resultadoSistemaAmortizacao").innerHTML = valor[0].firstChild.nodeValue;
							form.descAmortizacao.value = valor[0].firstChild.nodeValue;
						} else {
							document.getElementById("resultadoSistemaAmortizacao").innerHTML = '';
							form.descAmortizacao.value = '';
						}
						
						// Sistema de Amortização
						valor = child.getElementsByTagName("codSistemaAmortizacao");
						if (valor.length > 0 && valor[0].firstChild != null) {
							form.codAmortizacao.value = valor[0].firstChild.nodeValue;
						} else {
							form.codAmortizacao.value = '';
						}

						// Sistema de Amortização
						valor = child.getElementsByTagName("numeroAmortizacao");
						if (valor.length > 0 && valor[0].firstChild != null) {
							form.numeroAmortizacao.value = valor[0].firstChild.nodeValue;
						} else {
							form.numeroAmortizacao.value = '';
						}
						
						// Tipo de Financiamento
						valor = child.getElementsByTagName("tipoFinanciamento");
						if (valor.length > 0 && valor[0].firstChild != null) {
							form.tipoFinanciamento.value = valor[0].firstChild.nodeValue;
						} else {
							form.tipoFinanciamento.value.innerHTML = '';
						}
		
						// Seguradora
						valor = child.getElementsByTagName("codigoSeguradora");
						if (valor.length > 0 && valor[0].firstChild != null) {
							form.codigoSeguradoraSelecionada.value = valor[0].firstChild.nodeValue;
						} else {
							form.codigoSeguradoraSelecionada.value = '1';
						}
						valor = child.getElementsByTagName("nomeSeguradora");
						if (valor.length > 0 && valor[0].firstChild != null) {
							document.getElementById("resultadoNomeSeguradora").innerHTML = valor[0].firstChild.nodeValue;
							form.nomeSeguradora.value = valor[0].firstChild.nodeValue;
						} else {
							document.getElementById("resultadoNomeSeguradora").innerHTML = 'Caixa Seguros';
							form.nomeSeguradora.value = 'Caixa Seguros';
						}

						// Mensagem
						valor = child.getElementsByTagName("mensagem");
						if (valor.length > 0 && valor[0].firstChild != null) {
							document.getElementById("resultadoMensagem").innerHTML = valor[0].firstChild.nodeValue;
						} else {
							document.getElementById("resultadoMensagem").innerHTML = 
							     'Os resultados obtidos representam apenas uma simulação e não valem como proposta,' + 
							     ' pois estão sujeitos a alterações de acordo com a apuração da capacidade de pagamento' + 
							     ' e à aprovação da análise de crédito a ser efetuada pela CAIXA. Poderá haver alterações das taxas,' + 
							     ' dos prazos máximos e das demais condições, sem aviso prévio. A contratação está condicionada a' + 
							     ' disponibilidade de recursos para sua região e ao atendimento das exigências do programa.';
						}
		
						// Cota máxima
						valor = child.getElementsByTagName("cotaMaxima");
						if (valor.length > 0 && valor[0].firstChild != null) {
							document.getElementById("resultadoCotaMaximaFinanciamento").innerHTML = valor[0].firstChild.nodeValue;
						} else {
							document.getElementById("resultadoCotaMaximaFinanciamento").innerHTML = '';
						}
						
						// Taxas a Vista
						valor = child.getElementsByTagName("taxasVista");
						if (valor.length > 0 && valor[0].firstChild != null) {
							form.taxasVista.value = valor[0].firstChild.nodeValue;
						} else {
							form.taxasVista.value = '';
						}
						
						// Caso exista um subsídio e precise ser validado.
						if (!chamadas.validadoSubsidio && (altDadosSimulacao||temSubsidio)) {
							// Recursos próprios
							valor = child.getElementsByTagName("recursosProprios");
							if (valor.length > 0 && valor[0].firstChild != null) {
								document.forms[0].valorEntrada.value = valor[0].firstChild.nodeValue;
							}
							
							// Prazo
							valor = child.getElementsByTagName("prazo");
							if (valor.length > 0 && valor[0].firstChild != null) {
								document.forms[0].prazoDesejavel.value = valor[0].firstChild.nodeValue;
							}
							
							// Mostra a DIV de entrada do prazo e recursos próprios
							document.getElementById("subsidioParcela").style.display = 'block';
							// Esconde a DIV de resultado da simulação
							document.getElementById("subsidio").style.display = 'none';
							document.getElementById("convenioSimulacao").style.display = 'none';
							document.getElementById("cabecalhoComplementoConvenio").style.display = 'none';
		
							document.getElementById("cabecalhoComplemento").style.display = 'block';
						} else {
							// Caso o subsídio não exista ou não precise ser validado
							document.getElementById('resultadoVoltar').style.display = 'none';
							document.getElementById('resultadoBotoes').style.display = 'block';
							document.getElementById('resultadoLinks').style.display = 'block';
							
							var contratar = linkIP;
							if (contratar != '') {
								var c = document.getElementById('comoContratar'); 
								c.href = contratar;
								c.style.display = 'block';
								c.target = '_new';
								var c = document.getElementById('comoContratar2');
								c.href = contratar;
								c.style.display = 'block';
								c.target = '_new';
							} else {
								document.getElementById('comoContratar').style.display = 'none';
								document.getElementById('comoContratar2').style.display = 'none';
							}
							var documentacao = documentacaoIP;
							if (documentacao != '') {
								var d = document.getElementById('documentacao');
								d.href = documentacao;
								d.style.display = 'block';
								d.target = '_new';
								var d = document.getElementById('documentacao2');
								d.href = documentacao;
								d.style.display = 'block';
								d.target = '_new';
							} else {
								document.getElementById('documentacao').style.display = 'none';
								document.getElementById('documentacao2').style.display = 'none';
							}
							// Esconde a DIV de entrada do prazo e recursos próprios
							document.getElementById("subsidioParcela").style.display = 'none';
							// Mostra a DIV de resultado da simulação
							document.getElementById("subsidio").style.display = 'block';
							
							document.getElementById("convenioSimulacao").style.display = 'none';
		
							document.getElementById("cabecalhoComplementoConvenio").style.display = 'none';
		
							document.getElementById("cabecalhoComplemento").style.display = 'block';
							// Se tem subsídio, mostrar o seu valor, caso contrário, esconder o campo
							if (temSubsidio) {
								// Mostrar o valor de subsídio
								document.getElementById("resultadoNomeSubsidio").style.display = 'block';
								// Valor do subsídio
								valor = child.getElementsByTagName("valorSubsidio");
								if (valor.length > 0 && valor[0].firstChild != null) {
									document.getElementById('resultadoValorSubsidio').innerHTML = valor[0].firstChild.nodeValue;
									document.getElementById('resultadoValorSubsidioDisplay').style.display = 'block';
								}
							} else {
								// Não mostrar o valor de subsídio
								document.getElementById("resultadoNomeSubsidio").style.display = 'none';
								document.getElementById('resultadoValorSubsidio').innerHTML = '';
								document.getElementById('resultadoValorSubsidioDisplay').style.display = 'none';
							}
		
							// TR Projetada
							valor = child.getElementsByTagName("trProjetada");
							if (valor.length > 0 && valor[0].firstChild != null) {
								form.evolucaoTrProjetada.value = valor[0].firstChild.nodeValue;
							} else {
								form.evolucaoTrProjetada.value = '';
							}
		
							// Recursos próprios
							valor = child.getElementsByTagName("recursosProprios");
							if (valor.length > 0 && valor[0].firstChild != null) {
								document.getElementById("resultadoValorEntrada").innerHTML = valor[0].firstChild.nodeValue;
								document.getElementById('evolucaoValorEntrada').innerHTML =  valor[0].firstChild.nodeValue;
								document.forms[0].valorEntrada.value = valor[0].firstChild.nodeValue;
							} else {
								document.getElementById("resultadoValorEntrada").innerHTML = '0,00';
								document.getElementById('evolucaoValorEntrada').innerHTML = '0,00';
								document.forms[0].valorEntrada.value = '';
							}
							
							// Prazo
							valor = child.getElementsByTagName("prazo");
							if (valor.length > 0 && valor[0].firstChild != null) {
								document.getElementById("resultadoPrazo").innerHTML = valor[0].firstChild.nodeValue;
								document.getElementById("resultadoPrazo").innerHTML = valor[0].firstChild.nodeValue;
								document.forms[0].prazoDesejavel.value = valor[0].firstChild.nodeValue;
							} else {
								document.getElementById("resultadoPrazo").innerHTML = '';
								document.getElementById("resultadoPrazo").innerHTML = '';
								document.forms[0].prazoDesejavel.value = '';
							}
							
							// Valor de Financiamento
							valor = child.getElementsByTagName("valorFinanciamento");
							if (valor.length > 0 && valor[0].firstChild != null) {
								// Tela de resultado
								document.getElementById("resultadoValorFinanciamento").innerHTML = valor[0].firstChild.nodeValue;
								// Tela de evolução
								document.getElementById("evolucaoValorFinanciamento").innerHTML = valor[0].firstChild.nodeValue;
							} else {
								document.getElementById("resultadoValorFinanciamento").innerHTML = '';
								document.getElementById("evolucaoValorFinanciamento").innerHTML = '';
							}
							
							// 1º Prestação
							valor2 = child.getElementsByTagName("prestacao");
							if (valor2.length > 0 && valor2[0].firstChild != null) {
								valor = valor2[0].getElementsByTagName("encargo");
								if (valor.length > 0 && valor[0].firstChild != null) {
									document.getElementById("resultadoPrestacao1").innerHTML = valor[0].firstChild.nodeValue;
								} else {
									document.getElementById("resultadoPrestacao1").innerHTML = '';
								}
		
								valor = valor2[0].getElementsByTagName("amortizacao");
								if (valor.length > 0 && valor[0].firstChild != null) {
									document.getElementById("resultadoAmortizacao1").value = valor[0].firstChild.nodeValue;
								} else {
									document.getElementById("resultadoAmortizacao1").value = '';
								}
		
								valor = valor2[0].getElementsByTagName("juros");
								if (valor.length > 0 && valor[0].firstChild != null) {
									document.getElementById("resultadoJuros1").value = valor[0].firstChild.nodeValue;
								} else {
									document.getElementById("resultadoJuros1").value = '';
								}
								
								
								valor = valor2[0].getElementsByTagName("percentualJuros");
								if (valor.length > 0 && valor[0].firstChild != null) {
									document.getElementById("resultadoPercentualJuros1").value = valor[0].firstChild.nodeValue;
								} else {
									document.getElementById("resultadoPercentualJuros1").value = '';
								}
		
								valor = valor2[0].getElementsByTagName("jurosNominal");
								if (valor.length > 0 && valor[0].firstChild != null) {
									document.getElementById("resultadoJurosNominais1").innerHTML = valor[0].firstChild.nodeValue;
								} else {
									document.getElementById("resultadoJurosNominais1").innerHTML = '';
								}
		
								valor = valor2[0].getElementsByTagName("jurosEfetivo");
								if (valor.length > 0 && valor[0].firstChild != null) {
									document.getElementById("resultadoJurosEfetivos1").innerHTML = valor[0].firstChild.nodeValue;
								} else {
									document.getElementById("resultadoJurosEfetivos1").innerHTML = '';
								}
		
								valor = valor2[0].getElementsByTagName("mip");
								if (valor.length > 0 && valor[0].firstChild != null) {
									document.getElementById("resultadoMip1").value = valor[0].firstChild.nodeValue;
								} else {
									document.getElementById("resultadoMip1").value = '';
								}
		
								valor = valor2[0].getElementsByTagName("dfi");
								if (valor.length > 0 && valor[0].firstChild != null) {
									document.getElementById("resultadoDfi1").value = valor[0].firstChild.nodeValue;
								} else {
									document.getElementById("resultadoDfi1").value = '';
								}
		
								valor = valor2[0].getElementsByTagName("taxa");
								if (valor.length > 0 && valor[0].firstChild != null) {
									document.getElementById("resultadoTaxa1").value = valor[0].firstChild.nodeValue;
								} else {
									document.getElementById("resultadoTaxa1").value = '';
								}
		
								valor = valor2[0].getElementsByTagName("taxaAdministracao");
								if (valor.length > 0 && valor[0].firstChild != null) {
									document.getElementById("resultadoTaxaAdministracao1").value = valor[0].firstChild.nodeValue;
								} else {
									document.getElementById("resultadoTaxaAdministracao1").value = '';
								}
		
								valor = valor2[0].getElementsByTagName("riscoCredito");
								if (valor.length > 0 && valor[0].firstChild != null) {
									document.getElementById("resultadoRiscoCredito1").value = valor[0].firstChild.nodeValue;
								} else {
									document.getElementById("resultadoRiscoCredito1").value = '';
								}
							}
							
							cor = true;
							// Condicoes
							valor2 = child.getElementsByTagName("condicao");
							if (valor2.length > 0 && valor2[0].firstChild != null) {
								for (var icondicao = 0; icondicao < valor2.length; icondicao++) {
									chamadas.preencheCondicao(icondicao, valor2[icondicao]);
								}
							}
						}
						// Ajusta a tela
						var parametros = document.getElementById("parametros");
						var headerSimulacao = document.getElementById("headerSimulacao");
						var telaProdutosConvenio = document.getElementById("produtosConvenio");
						var headerSimulacaoConvenio = document.getElementById("headerSimulacaoConvenio");
		
						var produtos = document.getElementById("produtos");
						var resultado = document.getElementById("resultado");
						var evolucao = document.getElementById("evolucao");
						var produtosConvenio = document.getElementById("produtosConvenio");
						
						headerSimulacaoConvenio.style.display = 'none';
						telaProdutosConvenio.style.display = 'none';
						parametros.style.display = 'none';
						headerSimulacao.style.display = 'block';
						produtosConvenio.style.display = 'none';
						produtos.style.display = 'none';
						evolucao.style.display = 'none';
						resultado.style.display = 'block';
					}
				}
			}	
		}
		limparCombosSeguradora(true);
	}; // Fim retornoSimulaWS

	this.retornoSimulaConvenio = function(xml) {
		var form = document.forms[0];
		
		document.getElementById('botaoCalcularConvenio').innerHTML = '<a href="javascript: void(0)" onclick="chamadas.confirmaPrazoConvenio()"><img src="' + form.contexto.value + '/imagens/simulador/CALCULAR.jpg">';
		removeImagem('produtoConvenio_img' +  chamadas.campo.getAttribute("codigo") + '.' + chamadas.campo.getAttribute("versao"));

		// Nome do item de produto que fica em cima da tela de resultado
		document.getElementById("nomeProduto").innerHTML = chamadas.campo.getAttribute('nome');
		// Nome do item de produto que fica em cima da tela de evolução
		document.getElementById("evolucaoProduto").innerHTML = chamadas.campo.getAttribute('nome');
		var headerSimulacao = document.getElementById("headerSimulacao");
		var headerSimulacaoConvenio = document.getElementById("headerSimulacaoConvenio");

		headerSimulacaoConvenio.style.display = 'block';
		headerSimulacao.style.display = 'none';

		document.getElementById('resultadoVoltar').style.display = 'block';
		document.getElementById("linkVoltarConvenio").onclick = voltaProdutosConvenio;
		document.getElementById("linkVoltarConvenioBotoes").onclick = voltaProdutosConvenio;
		document.getElementById('resultadoBotoes').style.display = 'none';
		document.getElementById('resultadoLinks').style.display = 'none';
		document.getElementById('condicoes').innerHTML = '';
		document.getElementById('resultadoMip1').value = '';
		document.getElementById('resultadoDfi1').value = '';

		var root = xml.getElementsByTagName("root");
		var temSubsidio;
		var altDadosSimulacao;
		var convenioInicial;
		var valor;
		var valor2;
		var exibeComboSeguradoras = true;
		
		for (var i = 0; i < root.length; i++) {
			var child = root[i];

			var erro = child.getElementsByTagName("error");
			if (erro.length > 0) {
				var desc = erro[0].firstChild.nodeValue;
				var nomeCampo = 'produtoConvenio' +  chamadas.campo.getAttribute("codigo") + '.' + chamadas.campo.getAttribute("versao");
				var erroLocal = document.getElementById(nomeCampo);
				erroLocal.innerHTML = 'Cálculo não disponível para este produto.';
				erroLocal.style.display = 'block';
				setTimeout("chamadas.fade('" + nomeCampo + "');", 5000);
			} else {
				// Verifica se a simulação possui subsídio
				convenioInicial = child.getElementsByTagName("convenioInicial");
				temSubsidio = child.getElementsByTagName("temSubsidio");
				if (temSubsidio.length > 0 && temSubsidio[0].firstChild != null 
						&& (temSubsidio[0].firstChild.nodeValue == 'V'
						|| temSubsidio[0].firstChild.nodeValue == '"V"'
						|| temSubsidio[0].firstChild.nodeValue == 'TRUE')) {
					temSubsidio = true;
				} else {
					temSubsidio = false;
				}
				altDadosSimulacao = child.getElementsByTagName("altDadosSimulacao");
				if (altDadosSimulacao.length > 0 && altDadosSimulacao[0].firstChild != null 
						&& (altDadosSimulacao[0].firstChild.nodeValue == 'V'
						|| altDadosSimulacao[0].firstChild.nodeValue == '"V"'
						|| altDadosSimulacao[0].firstChild.nodeValue == 'TRUE')) {
					altDadosSimulacao = true;
				} else {
					altDadosSimulacao = false;
				}
				if (convenioInicial.length > 0 && convenioInicial[0].firstChild != null 
						&& (convenioInicial[0].firstChild.nodeValue == 'V'
						|| convenioInicial[0].firstChild.nodeValue == '"V"'
						|| convenioInicial[0].firstChild.nodeValue == 'TRUE')) {
					convenioInicial = true;
				} else {
					convenioInicial = false;
				}
				document.getElementById("linkAlteraPrazo").onclick = alteraPrazoConvenio;
				
				document.getElementById("resultadoValorImovel").innerHTML = form.valorImovel.value;
				// Prazo Máximo
				valor = child.getElementsByTagName("prazoMaximo");
				if (valor.length > 0 && valor[0].firstChild != null) {
					document.getElementById("resultadoPrazoMaximo").innerHTML = valor[0].firstChild.nodeValue;
					document.getElementById("resultadoPrazoMaximoConvenio").innerHTML = valor[0].firstChild.nodeValue;
				} else {
					document.getElementById("resultadoPrazoMaximo").innerHTML = '';
					document.getElementById("resultadoPrazoMaximoConvenio").innerHTML = '';
				}

				valor = child.getElementsByTagName("nomeSeguradora");
				if (valor.length > 0 && valor[0].firstChild != null) {
					document.getElementById("resultadoNomeSeguradora").innerHTML = valor[0].firstChild.nodeValue;
					document.getElementById("nomeSeguradora").value = valor[0].firstChild.nodeValue;
				} else {
					document.getElementById("resultadoNomeSeguradora").innerHTML = 'Caixa Seguros';
					document.getElementById("nomeSeguradora").value = 'Caixa Seguros';
				}

				valor = child.getElementsByTagName("codigoSeguradora");
				if (valor.length > 0 && valor[0].firstChild != null) {
					document.getElementById("codigoSeguradoraSelecionada").value = valor[0].firstChild.nodeValue;
				} else {
					document.getElementById("codigoSeguradoraSelecionada").value = '1';
				}

				// Sistema de Amortização
				valor = child.getElementsByTagName("sistemaAmortizacao");
				if (valor.length > 0 && valor[0].firstChild != null) {
					document.getElementById("resultadoSistemaAmortizacao").innerHTML = valor[0].firstChild.nodeValue;
					document.getElementById("resultadoSistemaAmortizacaoConvenio").innerHTML = valor[0].firstChild.nodeValue;
					form.descAmortizacao.value = valor[0].firstChild.nodeValue;
				} else {
					document.getElementById("resultadoSistemaAmortizacao").innerHTML = '';
					document.getElementById("resultadoSistemaAmortizacaoConvenio").innerHTML = '';
					form.descAmortizacao.value = '';
				}
				
				// Sistema de Amortização
				valor = child.getElementsByTagName("codSistemaAmortizacao");
				if (valor.length > 0 && valor[0].firstChild != null) {
					form.codAmortizacao.value = valor[0].firstChild.nodeValue;
				} else {
					form.codAmortizacao.value = '';
				}

				// Sistema de Amortização
				valor = child.getElementsByTagName("numeroAmortizacao");
				if (valor.length > 0 && valor[0].firstChild != null) {
					form.numeroAmortizacao.value = valor[0].firstChild.nodeValue;
				} else {
					form.numeroAmortizacao.value = '';
				}
				
				// Tipo de Financiamento
				valor = child.getElementsByTagName("tipoFinanciamento");
				if (valor.length > 0 && valor[0].firstChild != null) {
					form.tipoFinanciamento.value = valor[0].firstChild.nodeValue;
				} else {
					form.tipoFinanciamento.value.innerHTML = '';
				}

				// Mensagem
				valor = child.getElementsByTagName("mensagem");
				if (valor.length > 0 && valor[0].firstChild != null) {
					document.getElementById("resultadoMensagem").innerHTML = valor[0].firstChild.nodeValue;
				} else {
					document.getElementById("resultadoMensagem").innerHTML = 
					     'Os resultados obtidos representam apenas uma simulação e não valem como proposta,' + 
					     ' pois estão sujeitos a alterações de acordo com a apuração da capacidade de pagamento' + 
					     ' e à aprovação da análise de crédito a ser efetuada pela CAIXA. Poderá haver alterações das taxas,' + 
					     ' dos prazos máximos e das demais condições, sem aviso prévio. A contratação está condicionada a' + 
					     ' disponibilidade de recursos para sua região e ao atendimento das exigências do programa.';
				}

				// Cota máxima
				valor = child.getElementsByTagName("cotaMaxima");
				if (valor.length > 0 && valor[0].firstChild != null) {
					document.getElementById("resultadoCotaMaximaFinanciamento").innerHTML = valor[0].firstChild.nodeValue;
					document.getElementById("resultadoCotaMaximaFinanciamentoConvenio").innerHTML = valor[0].firstChild.nodeValue;
				} else {
					document.getElementById("resultadoCotaMaximaFinanciamento").innerHTML = '';
					document.getElementById("resultadoCotaMaximaFinanciamentoConvenio").innerHTML = '';
				}
				
				valor = child.getElementsByTagName("jurosEfetivo");
				if (valor.length > 0 && valor[0].firstChild != null) {
					document.getElementById("resultadoJurosEfetivosConvenio").innerHTML = valor[0].firstChild.nodeValue;
				} else {
					document.getElementById("resultadoJurosEfetivosConvenio").innerHTML = '';
				}

				valor = child.getElementsByTagName("codAmortizacao");

				valor = child.getElementsByTagName("jurosNominal");
				if (valor.length > 0 && valor[0].firstChild != null) {
					document.getElementById("resultadoJurosNominaisConvenio").innerHTML = valor[0].firstChild.nodeValue;
				} else {
					document.getElementById("resultadoJurosNominaisConvenio").innerHTML = '';
				}

				// Taxas a Vista
				valor = child.getElementsByTagName("taxasVista");
				if (valor.length > 0 && valor[0].firstChild != null) {
					form.taxasVista.value = valor[0].firstChild.nodeValue;
				} else {
					form.taxasVista.value = '';
				}
				
				
				var sePermiteEhCliente = chamadas.campo.getAttribute('sePermiteEhCliente');
				var sePermiteCarencia = chamadas.campo.getAttribute('sePermiteCarencia');
				var sePermiteCota = chamadas.campo.getAttribute('sePermiteCota');
				var sePermiteTaxas = chamadas.campo.getAttribute('sePermiteTaxas');
				var carenciaMaxima = chamadas.campo.getAttribute('carenciaMaxima');
				var taxasMaxima = chamadas.campo.getAttribute('taxasMaxima');

				document.forms[0].sePerguntaEhCliente.value = sePermiteEhCliente;
				document.forms[0].sePerguntaCota.value = sePermiteCota;
				document.forms[0].sePerguntaCarencia.value = sePermiteCarencia;
				document.forms[0].sePerguntaTaxas.value = sePermiteTaxas;
				
				exibeEscondePerguntaComplementoConvenio(sePermiteEhCliente,sePermiteCarencia,sePermiteCota,sePermiteTaxas);					
				// Prazo de carencia
				valor = child.getElementsByTagName("carenciaMaxima");
				var prazoCarenciaT = child.getElementsByTagName("prazoCarencia");
				if (prazoCarenciaT.length > 0 && prazoCarenciaT[0].firstChild != null) {
					document.forms[0].prazoCarencia.value = prazoCarenciaT[0].firstChild.nodeValue;
				} else {
					if (valor.length > 0 && valor[0].firstChild != null) {
						document.forms[0].prazoCarencia.value = valor[0].firstChild.nodeValue;
					} else {
						document.forms[0].prazoCarencia.value = carenciaMaxima;
					}	
				}

				valor = child.getElementsByTagName("taxasMaxima");
				var valorTaxasFinanciadasT = child.getElementsByTagName("valorTaxasFinanciadas");
				if (valorTaxasFinanciadasT.length > 0 && valorTaxasFinanciadasT[0].firstChild != null) {
					document.forms[0].valorTaxasFinanciadas.value = valorTaxasFinanciadasT[0].firstChild.nodeValue;
				} else {
					if (valor.length > 0 && valor[0].firstChild != null) {
						document.forms[0].valorTaxasFinanciadas.value = valor[0].firstChild.nodeValue;
					} else {
						document.forms[0].valorTaxasFinanciadas.value = taxasMaxima;
					}	
				}
				// Caso exista um subsídio e precise ser validado.
				if ((!chamadas.validadoSubsidio && (altDadosSimulacao||temSubsidio))||(convenioInicial)) {
					exibeComboSeguradoras = chamadas.preencherSeguradoras(
							child.getElementsByTagName("seguradoras"));
					

					document.getElementById("convenioSimulacao").style.display = 'block';
					atualizaDadosComplementaresConvenio();
					document.getElementById("cabecalhoComplementoConvenio").style.display = 'block';
					document.getElementById("cabecalhoComplemento").style.display = 'none';
					// Esconde a DIV de resultado da simulação
					document.getElementById("subsidio").style.display = 'none';
					// Esconde a DIV de entrada do prazo e recursos próprios
					document.getElementById("subsidioParcela").style.display = 'none';
					// Recursos próprios
					valor = child.getElementsByTagName("recursosProprios");
					if (valor.length > 0 && valor[0].firstChild != null) {
						document.forms[0].valorEntradaConvenio.value = valor[0].firstChild.nodeValue;
					}
					
					// Prazo
					valor = child.getElementsByTagName("prazo");
					if (valor.length > 0 && valor[0].firstChild != null) {
						document.forms[0].prazoDesejavelConvenio.value = valor[0].firstChild.nodeValue;
					}
					
					// Mostra a DIV de entrada do prazo e recursos próprios
//					document.getElementById("subsidioParcela").style.display = 'block';
				} else {
					// Caso o subsídio não exista ou não precise ser validado
					document.getElementById('resultadoVoltar').style.display = 'none';
					document.getElementById('resultadoBotoes').style.display = 'block';
					document.getElementById('resultadoLinks').style.display = 'block';
					
					var contratar = chamadas.campo.getAttribute("contratar");
					if (contratar != '') {
						var c = document.getElementById('comoContratar'); 
						c.href = contratar;
						c.style.display = 'block';
						c.target = '_new';
						var c = document.getElementById('comoContratar2');
						c.href = contratar;
						c.style.display = 'block';
						c.target = '_new';
					} else {
						document.getElementById('comoContratar').style.display = 'none';
						document.getElementById('comoContratar2').style.display = 'none';
					}
					var documentacao = chamadas.campo.getAttribute("documentacao");
					if (documentacao != '') {
						var d = document.getElementById('documentacao');
						d.href = documentacao;
						d.style.display = 'block';
						d.target = '_new';
						var d = document.getElementById('documentacao2');
						d.href = documentacao;
						d.style.display = 'block';
						d.target = '_new';
					} else {
						document.getElementById('documentacao').style.display = 'none';
						document.getElementById('documentacao2').style.display = 'none';
					}
					// Esconde a DIV de entrada do prazo e recursos próprios e de informações do convênio
					document.getElementById("convenioSimulacao").style.display = 'none';
					// Esconde a DIV de entrada do prazo e recursos próprios
					document.getElementById("subsidioParcela").style.display = 'none';
					// Mostra a DIV de resultado da simulação
					document.getElementById("subsidio").style.display = 'block';
					document.getElementById("cabecalhoComplementoConvenio").style.display = 'none';
					document.getElementById("cabecalhoComplemento").style.display = 'block';
					
					
					// Se tem subsídio, mostrar o seu valor, caso contrário, esconder o campo
					if (temSubsidio) {
						// Mostrar o valor de subsídio
						document.getElementById("resultadoNomeSubsidio").style.display = 'block';
						// Valor do subsídio
						valor = child.getElementsByTagName("valorSubsidio");
						if (valor.length > 0 && valor[0].firstChild != null) {
							document.getElementById('resultadoValorSubsidio').innerHTML = valor[0].firstChild.nodeValue;
							document.getElementById('resultadoValorSubsidioDisplay').style.display = 'block';
						}
					} else {
						// Não mostrar o valor de subsídio
						document.getElementById("resultadoNomeSubsidio").style.display = 'none';
						document.getElementById('resultadoValorSubsidio').innerHTML = '';
						document.getElementById('resultadoValorSubsidioDisplay').style.display = 'none';
					}
					
					// TR Projetada
					valor = child.getElementsByTagName("trProjetada");
					if (valor.length > 0 && valor[0].firstChild != null) {
						form.evolucaoTrProjetada.value = valor[0].firstChild.nodeValue;
					} else {
						form.evolucaoTrProjetada.value = '';
					}

					// Recursos próprios
					valor = child.getElementsByTagName("recursosProprios");
					if (valor.length > 0 && valor[0].firstChild != null) {
						document.getElementById("resultadoValorEntrada").innerHTML = valor[0].firstChild.nodeValue;
						document.getElementById('evolucaoValorEntrada').innerHTML =  valor[0].firstChild.nodeValue;
						document.forms[0].valorEntradaConvenio.value = valor[0].firstChild.nodeValue;
					} else {
						document.getElementById("resultadoValorEntrada").innerHTML = '0,00';
						document.getElementById('evolucaoValorEntrada').innerHTML = '0,00';
						document.forms[0].valorEntradaConvenio.value = '';
					}
					
					// Prazo
					valor = child.getElementsByTagName("prazo");
					if (valor.length > 0 && valor[0].firstChild != null) {
						document.getElementById("resultadoPrazo").innerHTML = valor[0].firstChild.nodeValue;
						document.getElementById("resultadoPrazo").innerHTML = valor[0].firstChild.nodeValue;
						document.forms[0].prazoDesejavelConvenio.value = valor[0].firstChild.nodeValue;
					} else {
						document.getElementById("resultadoPrazo").innerHTML = '';
						document.getElementById("resultadoPrazo").innerHTML = '';
						document.forms[0].prazoDesejavelConvenio.value = '';
					}

					// Valor de Financiamento
					valor = child.getElementsByTagName("valorFinanciamento");
					if (valor.length > 0 && valor[0].firstChild != null) {
						// Tela de resultado
						document.getElementById("resultadoValorFinanciamento").innerHTML = valor[0].firstChild.nodeValue;
						// Tela de evolução
						document.getElementById("evolucaoValorFinanciamento").innerHTML = valor[0].firstChild.nodeValue;
					} else {
						document.getElementById("resultadoValorFinanciamento").innerHTML = '';
						document.getElementById("evolucaoValorFinanciamento").innerHTML = '';
					}
					
					// 1º Prestação
					valor2 = child.getElementsByTagName("prestacao");
					if (valor2.length > 0 && valor2[0].firstChild != null) {
						valor = valor2[0].getElementsByTagName("encargo");
						if (valor.length > 0 && valor[0].firstChild != null) {
							document.getElementById("resultadoPrestacao1").innerHTML = valor[0].firstChild.nodeValue;
						} else {
							document.getElementById("resultadoPrestacao1").innerHTML = '';
						}

						valor = valor2[0].getElementsByTagName("amortizacao");
						if (valor.length > 0 && valor[0].firstChild != null) {
							document.getElementById("resultadoAmortizacao1").value = valor[0].firstChild.nodeValue;
						} else {
							document.getElementById("resultadoAmortizacao1").value = '';
						}

						valor = valor2[0].getElementsByTagName("juros");
						if (valor.length > 0 && valor[0].firstChild != null) {
							document.getElementById("resultadoJuros1").value = valor[0].firstChild.nodeValue;
						} else {
							document.getElementById("resultadoJuros1").value = '';
						}
						
						
						valor = valor2[0].getElementsByTagName("percentualJuros");
						if (valor.length > 0 && valor[0].firstChild != null) {
							document.getElementById("resultadoPercentualJuros1").value = valor[0].firstChild.nodeValue;
						} else {
							document.getElementById("resultadoPercentualJuros1").value = '';
						}

						valor = valor2[0].getElementsByTagName("jurosNominal");
						if (valor.length > 0 && valor[0].firstChild != null) {
							document.getElementById("resultadoJurosNominais1").innerHTML = valor[0].firstChild.nodeValue;
						} else {
							document.getElementById("resultadoJurosNominais1").innerHTML = '';
						}

						valor = valor2[0].getElementsByTagName("jurosEfetivo");
						if (valor.length > 0 && valor[0].firstChild != null) {
							document.getElementById("resultadoJurosEfetivos1").innerHTML = valor[0].firstChild.nodeValue;
						} else {
							document.getElementById("resultadoJurosEfetivos1").innerHTML = '';
						}

                        valor = child.getElementsByTagName("codSistemaAmortizacao");
						if (valor.length > 0 && valor[0].firstChild != null) {
							document.getElementById("resultadoCodAmortizacao1").value = valor[0].firstChild.nodeValue;
						} else {
							document.getElementById("resultadoCodAmortizacao1").value = '';
						}

                        valor = child.getElementsByTagName("sistemaAmortizacao");
						if (valor.length > 0 && valor[0].firstChild != null) {
							document.getElementById("resultadoDescAmortizacao1").value = valor[0].firstChild.nodeValue;
						} else {
							document.getElementById("resultadoDescAmortizacao1").value = '';
						}

						valor = valor2[0].getElementsByTagName("mip");
						if (valor.length > 0 && valor[0].firstChild != null) {
							document.getElementById("resultadoMip1").value = valor[0].firstChild.nodeValue;
						} else {
							document.getElementById("resultadoMip1").value = '';
						}

						valor = valor2[0].getElementsByTagName("dfi");
						if (valor.length > 0 && valor[0].firstChild != null) {
							document.getElementById("resultadoDfi1").value = valor[0].firstChild.nodeValue;
						} else {
							document.getElementById("resultadoDfi1").value = '';
						}

						valor = valor2[0].getElementsByTagName("taxa");
						if (valor.length > 0 && valor[0].firstChild != null) {
							document.getElementById("resultadoTaxa1").value = valor[0].firstChild.nodeValue;
						} else {
							document.getElementById("resultadoTaxa1").value = '';
						}

						valor = valor2[0].getElementsByTagName("taxaAdministracao");
						if (valor.length > 0 && valor[0].firstChild != null) {
							document.getElementById("resultadoTaxaAdministracao1").value = valor[0].firstChild.nodeValue;
						} else {
							document.getElementById("resultadoTaxaAdministracao1").value = '';
						}

						valor = valor2[0].getElementsByTagName("riscoCredito");
						if (valor.length > 0 && valor[0].firstChild != null) {
							document.getElementById("resultadoRiscoCredito1").value = valor[0].firstChild.nodeValue;
						} else {
							document.getElementById("resultadoRiscoCredito1").value = '';
						}
					}
					
					cor = true;
					// Condicoes
					valor2 = child.getElementsByTagName("condicao");
					if (valor2.length > 0 && valor2[0].firstChild != null) {
						for (var icondicao = 0; icondicao < valor2.length; icondicao++) {
							chamadas.preencheCondicao(icondicao, valor2[icondicao]);
						}
					}
				}
				// Ajusta a tela
				var produtos = document.getElementById("produtos");
				var resultado = document.getElementById("resultado");
				var evolucao = document.getElementById("evolucao");
				var produtosConvenio = document.getElementById("produtosConvenio");
				
				produtosConvenio.style.display = 'none';
				produtos.style.display = 'none';
				evolucao.style.display = 'none';
				resultado.style.display = 'block';
			}
		}
		limparCombosSeguradora(exibeComboSeguradoras);
	}; //Fim retornoSimulaConvenio

	this.detalhe = function() {
		var form = document.forms[0];
		var contexto = form.contexto.value;
		
		var condicoes = 0;
		for (i = 1; i <= 5; i++) {
			if (document.getElementById('resultadoAmortizacao' + i) != undefined) {
				condicoes++;
			} else {
				break;
			}
		}
		
		var temp = new StringBuffer("");

		temp.append('&nomeTaxaGenerica1=');
		temp.append(form.nomeTaxaGenerica1.value);
		temp.append('&nomeTaxaGenerica2=');
		temp.append(form.nomeTaxaGenerica2.value);
		temp.append('&valorTaxaGenerica1=');
		temp.append(form.valorTaxaGenerica1.value);
		temp.append('&valorTaxaGenerica2=');
		temp.append(form.valorTaxaGenerica2.value);
		temp.append('&valorPercentualGenerica1=');
		temp.append(form.valorPercentualGenerica1.value);
		
		temp.append('&nomeSeguradora=');
		temp.append(form.nomeSeguradora.value);
		
		for (i = 1; i <= condicoes; i++) {
			temp.append('&resultadoJurosNominais=');
			temp.append(this.getValor('resultadoJurosNominais', i));
			temp.append('&resultadoJurosEfetivos=');
			temp.append(this.getValor('resultadoJurosEfetivos', i));
			temp.append('&resultadoCodAmortizacao=');
			temp.append(this.getValor('resultadoCodAmortizacao', i));
			temp.append('&resultadoDescAmortizacao=');
			temp.append(this.getValor('resultadoDescAmortizacao', i));
			temp.append('&resultadoPrestacao=');
			temp.append(this.getValor('resultadoPrestacao', i));
			temp.append('&resultadoAmortizacao=');
			temp.append(this.getValor('resultadoAmortizacao', i));
			temp.append('&resultadoJuros=')
			temp.append(this.getValor('resultadoJuros', i));
			temp.append('&resultadoMip=');
			temp.append(this.getValor('resultadoMip', i));
			temp.append('&resultadoDfi=');
			temp.append(this.getValor('resultadoDfi', i));
			temp.append('&resultadoTaxaAdministracao=');
			temp.append(this.getValor('resultadoTaxaAdministracao', i));
			temp.append('&resultadoTaxa=');
			temp.append(this.getValor('resultadoTaxa', i));
			temp.append('&resultadoRiscoCredito=');
			temp.append(this.getValor('resultadoRiscoCredito', i));
			if (i > 1) {
				temp.append('&descricaoCondicao=');
				temp.append(this.getValor('descricaoCondicao', i));
			}

			temp.append('&resultadoTaxaGenerica1=');
			temp.append(this.getValor('resultadoValorTaxaGenerica1', i));
			temp.append('&resultadoTaxaGenerica2=');
			temp.append(this.getValor('resultadoValorTaxaGenerica2', i));
		}
		
		window.open('simulaOperacaoInternet.do?method=detalhes&condicoes=' + condicoes + temp.toString() + '&preencherVoltar=false', 'detalheSimulacao', "resizable=no,toolbar=no,scrollbars=auto,width=500,height=640");
	}
	
	this.getValor = function(campo, condicoes) {
		var c = document.getElementById(campo + condicoes);
		if (c.value != undefined && c != null) {
			return escape(c.value);
		}
		return escape(c.innerHTML);
	}
	
	this.graficoCet = function() {
		var form = document.forms[0];
		var percentualJuros = document.getElementById("resultadoPercentualJuros1").value;
		var amortizacao = document.getElementById('resultadoAmortizacao1').value;
		var juros = document.getElementById("resultadoJuros1").value;
		var valorFinanciamento = document.getElementById("resultadoValorFinanciamento").innerHTML;
		var prazo = document.getElementById("resultadoPrazo").innerHTML;
		var nuItemProduto;
		var nuVersao;
		var inicioWS = form.inicioWS.value;
		if ((inicioWS!=null)&&(inicioWS!='')&&(inicioWS=='V')) {
			nuItemProduto = form.nuItemProdutoWS.value; 
			nuVersao = form.nuVersaoWS.value; 
		} else {
			nuItemProduto = chamadas.campo.getAttribute('codigo');
			nuVersao = chamadas.campo.getAttribute('versao');
		}	
		
		var params = '&percentualJuros=' + percentualJuros + '&amortizacao=' + amortizacao
			+ '&juros=' + juros + '&valorFinanciamento=' + valorFinanciamento + '&prazo=' + prazo
			+ '&nuItemProduto=' + nuItemProduto + '&nuVersao=' + nuVersao
			+ '&nomeTaxaGenerica1=' + form.nomeTaxaGenerica1.value 
			+ '&nomeTaxaGenerica2=' + form.nomeTaxaGenerica2.value 
			+ '&valorTaxaGenerica1=' + form.valorTaxaGenerica1.value 
			+ '&valorTaxaGenerica2=' + form.valorTaxaGenerica2.value 
			+ '&valorPercentualGenerica1=' + form.valorPercentualGenerica1.value;

		window.open('simulaOperacaoInternet.do?method=graficoCet' + params, 'graficoCet', "resizable=yes,toolbar=no,scrollbars=yes,width=500");
	}
	
	this.preencheCondicao = function(contagem, condicao) {
		var buff = new StringBuffer();
		var permitePlanilha = document.forms[0].permitePlanilha.value;
		valor = 1;
		if (cor) {
			valor = 2;
		}
		cor = !cor;
		buff.append('<div class=field_block_' + valor + '>');
		buff.append('<div class=texto_camposb id=descricaoCondicao' + (contagem + 2) + '>');
		valor = condicao.getElementsByTagName("descricao");
		if (valor.length > 0 && valor[0].firstChild != null) {
			buff.append(valor[0].firstChild.nodeValue);
		}
		buff.append('</div><input value="');
		
		valor = condicao.getElementsByTagName("amortizacao");
		if (valor.length > 0 && valor[0].firstChild != null) {
			buff.append(valor[0].firstChild.nodeValue);
		}
		buff.append('" id=resultadoAmortizacao' + (contagem + 2) + ' type="hidden"/><input value="');
		
		valor = condicao.getElementsByTagName("dfi");
		if (valor.length > 0 && valor[0].firstChild != null) {
			buff.append(valor[0].firstChild.nodeValue);
		}
		buff.append('" id=resultadoDfi' + (contagem + 2) + ' type="hidden"/><input value="');
		
		valor = condicao.getElementsByTagName("mip");
		if (valor.length > 0 && valor[0].firstChild != null) {
			buff.append(valor[0].firstChild.nodeValue);
		}
		buff.append('" id=resultadoMip' + (contagem + 2) + ' type="hidden"/><input value="');
		
		valor = condicao.getElementsByTagName("taxa");
		if (valor.length > 0 && valor[0].firstChild != null) {
			buff.append(valor[0].firstChild.nodeValue);
		}
		buff.append('" id=resultadoTaxa' + (contagem + 2) + ' type="hidden"/><input value="');
		
		valor = condicao.getElementsByTagName("juros");
		if (valor.length > 0 && valor[0].firstChild != null) {
			buff.append(valor[0].firstChild.nodeValue);
		}
		buff.append('" id=resultadoJuros' + (contagem + 2) + ' type="hidden"/><input value="');
		
		valor = condicao.getElementsByTagName("percentualJuros");
		if (valor.length > 0 && valor[0].firstChild != null) {
			buff.append(valor[0].firstChild.nodeValue);
		}
		buff.append('" id=resultadoPercentualJuros' + (contagem + 2) + ' type="hidden"/><input value="');
		
		valor = condicao.getElementsByTagName("riscoCredito");
		if (valor.length > 0 && valor[0].firstChild != null) {
			buff.append(valor[0].firstChild.nodeValue);
		}
		buff.append('" id=resultadoRiscoCredito' + (contagem + 2) + ' type="hidden"/><input value="');
		
		valor = condicao.getElementsByTagName("taxaAdministracao");
		if (valor.length > 0 && valor[0].firstChild != null) {
			buff.append(valor[0].firstChild.nodeValue);
		}
		buff.append('" id=resultadoTaxaAdministracao' + (contagem + 2) + ' type="hidden"/><input value="');

		valor = condicao.getElementsByTagName("codAmortizacao");
		if (valor.length > 0 && valor[0].firstChild != null) {
			buff.append(valor[0].firstChild.nodeValue);
		}
		buff.append('" id=resultadoCodAmortizacao' + (contagem + 2) + ' type="hidden"/><input value="');

		valor = condicao.getElementsByTagName("descAmortizacao");
		if (valor.length > 0 && valor[0].firstChild != null) {
			buff.append(valor[0].firstChild.nodeValue);
		}
		buff.append('" id=resultadoDescAmortizacao' + (contagem + 2) + ' type="hidden"/><input value="');


		valor = condicao.getElementsByTagName("nomeTaxaGenerica1");
		if (valor.length > 0 && valor[0].firstChild != null) {
			buff.append(valor[0].firstChild.nodeValue);
		}
		buff.append('" id=resultadoNomeTaxaGenerica1' + (contagem + 2) + ' type="hidden"/><input value="');


		valor = condicao.getElementsByTagName("nomeTaxaGenerica2");
		if (valor.length > 0 && valor[0].firstChild != null) {
			buff.append(valor[0].firstChild.nodeValue);
		}
		buff.append('" id=resultadoNomeTaxaGenerica2' + (contagem + 2) + ' type="hidden"/><input value="');

		valor = condicao.getElementsByTagName("valorTaxaGenerica1");
		if (valor.length > 0 && valor[0].firstChild != null) {
			buff.append(valor[0].firstChild.nodeValue);
		}
		buff.append('" id=resultadoValorTaxaGenerica1' + (contagem + 2) + ' type="hidden"/><input value="');

		valor = condicao.getElementsByTagName("valorTaxaGenerica2");
		if (valor.length > 0 && valor[0].firstChild != null) {
			buff.append(valor[0].firstChild.nodeValue);
		}
		buff.append('" id=resultadoValorTaxaGenerica2' + (contagem + 2) + ' type="hidden"/><input value="');

		valor = condicao.getElementsByTagName("valorPercentualGenerica1");
		if (valor.length > 0 && valor[0].firstChild != null) {
			buff.append(valor[0].firstChild.nodeValue);
		}
		buff.append('" id=resultadoValorPercentualGenerica1' + (contagem + 2) + ' type="hidden"/>');
		
		buff.append('<table><tbody><tr class=texto_campos><td class=texto_camposb>1º Prestação</td>');
		buff.append('<td>Juros Nominais</td><td>Juros Efetivos</td><td width="30%" rowspan="2" align="center" id="botaoCet' + (contagem + 2) + '">');
		if (permitePlanilha == 'S') {
			buff.append('<a href="javascript: void(0)" onclick="chamadas.evolucao(\'');
			buff.append((contagem + 2));
			buff.append('\')"><img src="' + document.forms[0].contexto.value + '/imagens/simulador/ce-planilha.jpg"></a></td>');
		}
		buff.append('</tr><tr class=texto_linkCopy><td>R$ <span id=resultadoPrestacao' + (contagem + 2) + '>');
		valor = condicao.getElementsByTagName("encargo");
		if (valor.length > 0 && valor[0].firstChild != null) {
			buff.append(valor[0].firstChild.nodeValue);
		}
		buff.append('</span></td><td><div id=resultadoJurosNominais' + (contagem + 2) + '>');
		valor = condicao.getElementsByTagName("jurosNominal");
		if (valor.length > 0 && valor[0].firstChild != null) {
			buff.append(valor[0].firstChild.nodeValue);
		}
		buff.append('</div></td><td><div id=resultadoJurosEfetivos' + (contagem + 2) + '>');
		valor = condicao.getElementsByTagName("jurosEfetivo");
		if (valor.length > 0 && valor[0].firstChild != null) {
			buff.append(valor[0].firstChild.nodeValue);
		}
		buff.append('</div></td></tbody></table></div>');
		document.getElementById('condicoes').innerHTML += buff.toString();
	}
	
	this.evolucao = function(condicao) {
		var form = document.forms[0];
		var inicioWS = form.inicioWS.value;
		var nuItemProduto;
		var nuVersao;
		if ((inicioWS!=null)&&(inicioWS!='')&&(inicioWS=='V')) {
			nuItemProduto = form.nuItemProdutoWS.value; 
			nuVersao = form.nuVersaoWS.value; 
		} else {
			nuItemProduto = chamadas.campo.getAttribute('codigo');
			nuVersao = chamadas.campo.getAttribute('versao');
		}	
		var juros = document.getElementById("resultadoJuros" + condicao).value;
		var jurosNominal = document.getElementById("resultadoJurosNominais" + condicao).innerHTML; 
		var percentualJuros = document.getElementById("resultadoPercentualJuros" + condicao).value; 
		var dataNascimento = form.dataNascimento.value;
		var prazo = document.getElementById("resultadoPrazo").innerHTML;
		var valorFinanciamento = document.getElementById("resultadoValorFinanciamento").innerHTML;
		var riscoCredito = form.riscoCredito.value;
		var parcelaAmortizacao = document.getElementById('resultadoAmortizacao' + condicao).value;
		var dfi = document.getElementById('resultadoDfi' + condicao).value;
		var mip = document.getElementById('resultadoMip' + condicao).value;
		var txAdm = document.getElementById('resultadoTaxa' + condicao).value;
		var taxaAdministracao = document.getElementById('resultadoTaxaAdministracao' + condicao).value;
		var valorImovel = form.valorImovel.value;
		var rendaFamiliarBruta = form.rendaFamiliar.value;
		var codAmortizacao = document.getElementById('resultadoCodAmortizacao' + condicao).value;
		var descAmortizacao = document.getElementById('resultadoDescAmortizacao' + condicao).value;
		var resultadoValorSubsidio = document.getElementById('resultadoValorSubsidio').innerHTML;
		var taxasVista = form.taxasVista.value;
		var encargo = document.getElementById('resultadoPrestacao' + condicao).innerHTML;

		var nomeTaxa1 = form.nomeTaxaGenerica1.value;
		var nomeTaxa2 = form.nomeTaxaGenerica2.value;
		var valorTaxa1 = form.valorTaxaGenerica1.value;
		var valorTaxa2 = form.valorTaxaGenerica2.value;
		var valorPercentual1 = form.valorPercentualGenerica1.value;
		
		var codigoSeguradora = form.codigoSeguradoraSelecionada.value;
		var nomeSeguradora = form.nomeSeguradora.value;
		var dataUltimoBeneficio = form.dataBeneficioFGTS.value;
		var beneficiadoFGTS = form.beneficiadoFGTS.checked ? "V" : "F";

		setaImagem('botaoCet' + condicao);
		chamadas.condicao = condicao;

		var link = 'method=estimarEvolucao&nuItemProduto=' + nuItemProduto + '&nuVersao=' + nuVersao
			+ '&percentualJuros=' + percentualJuros + '&juros=' + juros + '&dataNascimento=' + dataNascimento + '&prazo=' + prazo
			+ '&valorFinanciamento=' + valorFinanciamento + '&riscoCredito=' + riscoCredito
			+ '&amortizacao=' + parcelaAmortizacao + '&seguroDfi=' + dfi + '&seguroMip=' + mip
			+ '&valorImovel=' + valorImovel + '&rendaFamiliarBruta=' + rendaFamiliarBruta
			+ '&txAdm=' + txAdm + '&desconto=' + resultadoValorSubsidio + '&taxasVista=' + taxasVista
			+ '&taxaAdministracao=' + taxaAdministracao + '&encargo=' + encargo 
			+ '&codAmortizacao=' + codAmortizacao + '&descAmortizacao=' + descAmortizacao
			+ '&nomeTaxaGenerica1=' + nomeTaxa1 + '&nomeTaxaGenerica2=' + nomeTaxa2 
			+ '&valorTaxaGenerica1=' + valorTaxa1 + '&valorTaxaGenerica2=' 
			+ valorTaxa2 + '&valorPercentualGenerica1=' + valorPercentual1
			+ '&codigoSeguradoraSelecionada=' + codigoSeguradora
			+ '&nomeSeguradora=' + nomeSeguradora
			+ '&dataBeneficioFGTS=' + dataUltimoBeneficio
			+ '&beneficiadoFGTS=' + beneficiadoFGTS
			+ '&prazoCarencia=' + form.prazoCarencia.value
			+ '&seDesejaCarencia=' + getValorRadio(form.seDesejaCarencia); 
			
		chamadas.enviar('simulaOperacaoInternet.do', link, chamadas.retornoEvolucao);
	}
	
	this.retornoEvolucao = function(xml) {
		var form = document.forms[0];
		var root = xml.getElementsByTagName("root");
		var child;
		var erro;
		var valor;
		
		document.getElementById('botaoCet' + chamadas.condicao).innerHTML = '<a href="javascript: void(0)" onclick="chamadas.evolucao('
		+ chamadas.condicao + ')"><img src="' + form.contexto.value + '/imagens/simulador/ce-planilha.jpg">';
				
		for (var i = 0; i < root.length; i++) {
			child = root[i];

			erro = child.getElementsByTagName("error");
			if (erro.length > 0) {
				var erroLocal = document.getElementById("mensagemErroPlanilha");
				erroLocal.innerHTML = erro[0].firstChild.nodeValue;
				erroLocal.style.display = 'block';
				setTimeout("chamadas.fade('mensagemErroPlanilha');", 5000);
			} else {
				chamadas.preencherTaxasGenericas(child);
				valor = child.getElementsByTagName("cet");
				if (valor.length > 0 && valor[0].firstChild != null) {
					document.getElementById("valorCet").innerHTML = valor[0].firstChild.nodeValue;
				} else {
					document.getElementById("valorCet").innerHTML = '';
				}
			
				valor = child.getElementsByTagName("cesh");
				if (valor.length > 0 && valor[0].firstChild != null) {
					document.getElementById("valorCESH").innerHTML = valor[0].firstChild.nodeValue;
				} else {
					document.getElementById("valorCESH").innerHTML = '';
				}

				valor = child.getElementsByTagName("juros");
				if (valor.length > 0 && valor[0].firstChild != null) {
					document.getElementById("evolucaoJuros").innerHTML = valor[0].firstChild.nodeValue;
				} else {
					document.getElementById("evolucaoJuros").innerHTML = '';
				}
				
				// Sistema de Amortização
				valor = child.getElementsByTagName("sistemaAmortizacao");
				if (valor.length > 0 && valor[0].firstChild != null) {
					document.getElementById("resultadoSistemaAmortizacaoEvol").innerHTML = valor[0].firstChild.nodeValue;
					form.descAmortizacao.value = valor[0].firstChild.nodeValue;
				} else {
					document.getElementById("resultadoSistemaAmortizacaoEvol").innerHTML = '';
					form.descAmortizacao.value = '';
				}
				document.getElementById("resultadoCetNomeSeguradora").innerHTML = form.nomeSeguradora.value;
				
				valor = child.getElementsByTagName("mensagem");
				if (valor.length > 0 && valor[0].firstChild != null) {
					document.getElementById("obsPlanilha").innerHTML = valor[0].firstChild.nodeValue;
				} else {
					document.getElementById("obsPlanilha").innerHTML = 
						"Os resultados obtidos representam apenas uma simulação e não valem como proposta, " +
						"pois estão sujeitos as alterações de acordo com a apuração da capacidade de pagamento e " +
						"à aprovação da análise de risco a ser efetuada pela CAIXA. Poderá haver alterações das taxas, " +
						"dos prazos e das demais condições, sem aviso prévio. A contratação está condicionada ao atendimento " +
						"das exigências do programa. <br /><br /> " + 
						"O CET apresentado corresponde somente à fase de amortização. " +
						"Nos casos de construção o CET pode variar em função do cronograma de cada obra.";
				}
				/*
				 * Monta os Componentes CET
				 */
				valor = child.getElementsByTagName("composicaoCet");
				if (valor.length > 0 && valor[0].firstChild != null) {
					var cet = new StringBuffer();
					cet.append("<table class=te><tr><td class=lcet>");
					valor = valor[0].firstChild.nodeValue;
					var acumulador = ""; 
					for (icet = 0; icet < valor.length; icet++) {
						c = valor.charAt(icet);
						
						if (c == '\n') {
							cet.append('</tr><tr><td class=lcet>');
						} else if (c == '/') {
							acumulador = c;
						} else if (c == ':') {
							cet.append(':<td class=rcet>');
						} else if (c == 'n') {
							if (acumulador == '/') {
								cet.append('</tr><tr><td class=lcet>');
							} else {
							    if (acumulador.length > 0) {
									cet.append(acumulador);
							    }
								cet.append(c);
							}
							acumulador = "";
						} else {
						    if (acumulador.length > 0) {
								cet.append(acumulador);
								acumulador = "";
						    }
								cet.append(c);
						}
					}
					cet.append("</table>");
					document.getElementById("evolucaoComposicaoCet").innerHTML = cet.toString();
				} else {
					document.getElementById("evolucaoComposicaoCet").innerHTML = '';
				}
				
				
				/*
				 * Monta a tabela da fase de carência, caso exista.
				 */
				valor = child.getElementsByTagName("prazoCarencia");
				if (valor.length > 0 && valor[0].firstChild != null) {
					var qtdParcelasCarencia = parseInt(valor[0].firstChild.nodeValue);
					var tabela = new StringBuffer();

					//Cria a tabela
					var html = new StringBuffer();
					html.append("<div class='titulo_evolucao' align='center' style='color:black;padding-top: 15px;font-size: 13px;'>Fase de Carência</div>");
					html.append("<table cellpadding=0 cellspacing=0 border=1 bordercolor=#d2ddfb>");
					html.append("<colgroup><col width=13%/><col width=15%/><col width=15%/><col width=12%/><col width=15%/><col width=15%/></colgroup>");
					html.append("<tbody><tr class=tevolucao><td>Nº</td><td>Prestação</td><td>j*</td><td>Total Seguros</td>");
					html.append("<td>Taxas</td><td>Saldo Devedor</td></tr>");
					
					var linhaAzul = false;
					var prestacoesCarencia = child.getElementsByTagName("prestacoesCarencia");
					var lengthCarencia = prestacoesCarencia.length;
					
					document.getElementById("qtdMesesAmortizacao").innerHTML = length + " ";
					if (lengthCarencia > 0) {
						for (var iprestacoes = 0; iprestacoes < lengthCarencia; iprestacoes++) {
							var pr = prestacoesCarencia[iprestacoes];
							
							// Insere uma nova linha
							html.append("<tr class=");
							//tr = document.createElement("tr");
							if (par) {
								html.append("'eb'>");
							} else {
								html.append("'ee'>");
							}
							par = !par;
							
							// Número de prestação
							valor = pr.getElementsByTagName("numeroCarencia");
							html.append("<td>");
							html.append(valor[0].firstChild.nodeValue);
							html.append("</td>");
							
							// Prestacao
							valor = pr.getElementsByTagName("totalCarencia");
							html.append("<td>");
							html.append(valor[0].firstChild.nodeValue);
							html.append("</td>");
							
							// AJ
							valor = pr.getElementsByTagName("ajCarencia");
							html.append("<td>");
							html.append(valor[0].firstChild.nodeValue);
							html.append("</td>");
							
							// Seguro
							valor = pr.getElementsByTagName("seguroCarencia");
							html.append("<td>");
							html.append(valor[0].firstChild.nodeValue);
							html.append("</td>");
							
							// Taxas
							valor = pr.getElementsByTagName("taxasCarencia");
							html.append("<td>");
							html.append(valor[0].firstChild.nodeValue);
							html.append("</td>");
							
							// Saldo devedor
							valor = pr.getElementsByTagName("saldoCarencia");
							html.append("<td>");
							html.append(valor[0].firstChild.nodeValue);
							html.append("</td>");
						}
						html.append("</table>");
						document.getElementById("evolucaoCarenciaDetalhe").innerHTML = html.toString();
						document.getElementById("qtdMesesCarencia").innerHTML = qtdParcelasCarencia + " ";
					}

					
				}else{
					document.getElementById("evolucaoCarenciaDetalhe").innerHTML = "";
					document.getElementById("qtdMesesCarencia").innerHTML = "0 ";
				}
			
				/*
				 * Monta a tabela da fase de amortização
				 */
				var html = new StringBuffer();
				html.append("<div class='titulo_evolucao' align='center' style='color:black;padding-top: 15px;font-size: 13px;'>Fase de Amortização</div>");
				html.append("<table cellpadding=0 cellspacing=0 border=1 bordercolor=#d2ddfb>");
				html.append("<colgroup><col width=13%/><col width=15%/><col width=15%/><col width=12%/><col width=15%/><col width=15%/></colgroup>");
				html.append("<tbody><tr class=tevolucao><td>Nº</td><td>Prestação</td><td>(a+j)*</td><td>Total Seguros</td>");
				html.append("<td>Tarifas</td><td>Saldo Devedor</td></tr>");
				var par = false;

				var prestacoes = child.getElementsByTagName("prestacoes");
				var length = prestacoes.length;
				
				document.getElementById("qtdMesesAmortizacao").innerHTML = length + " ";
				if (length > 0) {
					for (var iprestacoes = 0; iprestacoes < length; iprestacoes++) {
						var pr = prestacoes[iprestacoes];
						
						// Insere uma nova linha
						html.append("<tr class=");
						//tr = document.createElement("tr");
						if (par) {
							html.append("'eb'>");
						} else {
							html.append("'ee'>");
						}
						par = !par;
						
						// Número de prestação
						valor = pr.getElementsByTagName("numero");
						html.append("<td>");
						html.append(valor[0].firstChild.nodeValue);
						html.append("</td>");
						
						// Prestacao
						valor = pr.getElementsByTagName("total");
						html.append("<td>");
						html.append(valor[0].firstChild.nodeValue);
						html.append("</td>");
						
						// AJ
						valor = pr.getElementsByTagName("aj");
						html.append("<td>");
						html.append(valor[0].firstChild.nodeValue);
						html.append("</td>");
						
						// Seguro
						valor = pr.getElementsByTagName("seguro");
						html.append("<td>");
						html.append(valor[0].firstChild.nodeValue);
						html.append("</td>");
						
						// Taxas
						valor = pr.getElementsByTagName("taxa");
						html.append("<td>");
						html.append(valor[0].firstChild.nodeValue);
						html.append("</td>");
						
						// Saldo devedor
						valor = pr.getElementsByTagName("saldo");
						html.append("<td>");
						html.append(valor[0].firstChild.nodeValue);
						html.append("</td>");
					}
					html.append("</table>");
					document.getElementById("evolucaoDetalhe").innerHTML = html.toString();
				}
				// Prazo desejavel
				document.getElementById("evolucaoPrazo").innerHTML = form.prazoDesejavel.value +' meses';

				// Mostra somente os DIVs de evolução
				document.getElementById("resultado").style.display = 'none';
				document.getElementById("evolucao").style.display = 'block';
			}
		}
	}
	
	this.imprimir = function() {
		window.print();
	}
	
	// Responsável por mostrar o erro por algum tempo
	this.fade = function(campo) {
		var c = document.getElementById(campo);
		c.style.display = 'none';
	}
	
	this.contratarInicio = function() {
//		document.forms[0].clienteCaixa[0].checked = true;
//		document.getElementById('agencias').style.display = 'none';
		document.getElementById("resultado").style.display = 'none';
		document.getElementById("contratar").style.display = 'block';
		var erroLocal = document.getElementById("mensagemRegistraInteresse");
		document.getElementById("botaoRegistraInteresse").style.display = 'block';
		erroLocal.innerHTML = 'O ato de salvar o registro de interesse na data atual, implicará na sobreposição dos demais registros da mesma data e do mesmo usuário. ';
		erroLocal.style.display = 'block';
	}
	
	this.voltaContratar = function() {
		document.getElementById("resultado").style.display = 'block';
		document.getElementById("contratar").style.display = 'none';
		var erroLocal = document.getElementById("mensagemRegistraInteresse");
		erroLocal.style.display = 'none';
	}
	
	this.registraInteresse = function() {
		
		chamadas.contratar = document.getElementById('botaoRegistraInteresse').innerHTML;
		var form = document.forms[0]; 
		var cpf = form.cpf.value;
		var telefone = form.telefone.value;
		var celular = form.celular.value;
		var nome = form.nome.value;
		
		
		
		
		if (nome == '') {
			form.nome.focus();
			var erroLocal = document.getElementById("mensagemRegistraInteresse");
			erroLocal.innerHTML = 'Campo obrigatório não informado';
			erroLocal.style.display = 'block';
			setTimeout("chamadas.fade('mensagemRegistraInteresse');", 5000);
		} else if (cpf == '') {
			form.cpf.focus();
			var erroLocal = document.getElementById("mensagemRegistraInteresse");
			erroLocal.innerHTML = 'Campo obrigatório não informado';
			erroLocal.style.display = 'block';
			setTimeout("chamadas.fade('mensagemRegistraInteresse');", 5000);
		} else if (!validaCPFCNPJ()){
			return;
		} else if (telefone == '' && celular == '') {
			form.telefone.focus();
			var erroLocal = document.getElementById("mensagemRegistraInteresse");
			erroLocal.innerHTML = 'Para registrar o interesse é necessário informar telefone ou celular para contato';
			erroLocal.style.display = 'block';
			setTimeout("chamadas.fade('mensagemRegistraInteresse');", 5000);
		} else {
			if ((telefone != '')&&(telefone.length < 13)) {
				form.telefone.focus();
				var erroLocal = document.getElementById("mensagemRegistraInteresse");
				erroLocal.innerHTML = 'Dados do contato incompleto';
				erroLocal.style.display = 'block';
				setTimeout("chamadas.fade('mensagemRegistraInteresse');", 5000);
				return;
			}
			if ((celular != '')&&(celular.length < 13)) {
				form.telefone.focus();
				var erroLocal = document.getElementById("mensagemRegistraInteresse");
				erroLocal.innerHTML = 'Dados do contato incompleto';
				erroLocal.style.display = 'block';
				setTimeout("chamadas.fade('mensagemRegistraInteresse');", 5000);
				return;
			}			
			var nuItemProduto = chamadas.campo.getAttribute('codigo');
			var nuVersao = chamadas.campo.getAttribute('versao');
			var dataNascimento = form.dataNascimento.value;
			var prazo = document.getElementById("resultadoPrazo").innerHTML;
			var valorFinanciamento = document.getElementById("resultadoValorFinanciamento").innerHTML;
			var rendaFamiliarBruta = form.rendaFamiliar.value;
			var tipoImovel = form.tipoImovel.value;
			var cidade = form.cidade.value;
			var uf = form.uf.value;
			var tipoFinanciamento = form.tipoFinanciamento.value; 
			var recursosProprios = document.getElementById('resultadoValorEntrada').innerHTML;
			var codAmortizacao = form.codAmortizacao.value;
			var numeroAmortizacao = form.numeroAmortizacao.value;
			var valorImovel = document.getElementById("resultadoValorImovel").innerHTML;
			var periodoDiaManha = form.periodoDiaManha.checked ? "M" : "";
			var periodoDiaTarde = form.periodoDiaTarde.checked ? "T" : "";
			var periodoDiaNoite = form.periodoDiaNoite.checked ? "N" : "";
			var periodoDiaSabadoManha = form.periodoDiaSabadoManha.checked ? "M" : "";
			var periodoDiaSabadoTarde = form.periodoDiaSabadoTarde.checked ? "T" : "";
			var diaSemanaSegunda = form.diaSemanaSegunda.checked ? "1" : "";
			var diaSemanaTerca = form.diaSemanaTerca.checked ? "2" : "";
			var diaSemanaQuarta = form.diaSemanaQuarta.checked ? "3" : "";
			var diaSemanaQuinta = form.diaSemanaQuinta.checked ? "4" : "";
			var diaSemanaSexta = form.diaSemanaSexta.checked ? "5" : "";
			var diaSemanaSabado = form.diaSemanaSabado.checked ? "6" : "";
//			var agencia = form.agencia.value;
//			var clienteCaixa = form.clienteCaixa[0].checked ? 'S' : 'N';
	
			setaImagem('botaoRegistraInteresse');
			var link = 'method=registraInteresse&nuItemProduto=' + nuItemProduto + '&nuVersao=' + nuVersao
				+ '&dataNascimento=' + dataNascimento + '&prazo=' + prazo + '&valorFinanciamento=' + valorFinanciamento
				+ '&rendaFamiliarBruta=' + rendaFamiliarBruta + '&cpf=' + cpf + '&tipoImovel=' + tipoImovel
				+ '&cidade=' + cidade + '&uf=' + uf + '&tipoFinanciamento=' + tipoFinanciamento
				+ '&recursosProprios=' + recursosProprios + '&numeroAmortizacao=' + numeroAmortizacao + '&codAmortizacao=' + codAmortizacao
				+ '&nome=' + escape(nome) + '&telefone=' + escape(telefone)
				+ '&celular=' + escape(celular) +  '&valorImovel=' + valorImovel
				+ '&periodoDiaManha=' + periodoDiaManha +  '&periodoDiaTarde=' + periodoDiaTarde +  '&periodoDiaNoite=' + periodoDiaNoite
				+ '&periodoDiaSabadoManha=' + periodoDiaSabadoManha +  '&periodoDiaSabadoTarde=' + periodoDiaSabadoTarde
				+ '&diaSemanaSegunda=' + diaSemanaSegunda +  '&diaSemanaTerca=' + diaSemanaTerca +  '&diaSemanaQuarta=' + diaSemanaQuarta
				+ '&diaSemanaQuinta=' + diaSemanaQuinta +  '&diaSemanaSexta=' + diaSemanaSexta +  '&diaSemanaSabado=' + diaSemanaSabado;
			this.enviar('simulaOperacaoInternet.do', link, this.retornoRegistraInteresse);
		}
	}
	
	this.retornoRegistraInteresse = function(xml) {
		var root = xml.getElementsByTagName("root");
		document.getElementById('botaoRegistraInteresse').innerHTML = chamadas.contratar;
		
		var falha = false;
		for (var i = 0; i < root.length; i++) {
			var child = root[i];
			var erro = child.getElementsByTagName("error");
			if (erro.length > 0) {
				var erroLocal = document.getElementById("mensagemRegistraInteresse");
				erroLocal.innerHTML = erro[0].firstChild.nodeValue;
				erroLocal.style.display = 'block';
				setTimeout("chamadas.fade('mensagemRegistraInteresse');", 5000);
				falha = true; 
			}
		}
		if (!falha) {
			var erroLocal = document.getElementById("mensagemRegistraInteresse");
			erroLocal.innerHTML = 'Seu interesse foi enviado para análise.';
			erroLocal.style.display = 'block';
			setTimeout("chamadas.fade('mensagemRegistraInteresse');", 5000);
		} else {
			var existeCpf = child.getElementsByTagName("existeCpfCnpj");
			if ((existeCpf!=null)&&(existeCpf[0].firstChild!=null)
				&&(existeCpf[0].firstChild.nodeValue!=null)&&(existeCpf[0].firstChild.nodeValue == 'V')) {
				document.getElementById('botaoRegistraInteresse').style.display = 'none';
			}
		}
	}
}

function voltaParametros() {
	var form = document.forms[0]; 
	var parametros = document.getElementById("parametros");
	var produtos = document.getElementById("produtos");
	var headerSimulacao = document.getElementById("headerSimulacao");
	var produtosConvenio = document.getElementById("produtosConvenio");
	var convenio = document.getElementById("convenios");
	var headerSimulacaoConvenio = document.getElementById("headerSimulacaoConvenio");
	var resultado = document.getElementById("resultado");
	var botaoEnquadar = document.getElementById('botaoEnquadar');
	
	headerSimulacaoConvenio.style.display = 'none';
	produtosConvenio.style.display = 'none';
	convenio.style.display = 'none';
	headerSimulacao.style.display = 'none';
	produtos.style.display = 'none';
	resultado.style.display = 'none';
	parametros.style.display = 'block';
	//document.getElementById('botaoEnquadar').innerHTML = '<a href="javascript: void(0)" onclick="chamadas.simulaInicial()" id="botaoEnquadar"><img src="' + form.contexto.value + '/imagens/simulador/avancar.jpg">';
	if (botaoEnquadar != null) {
		botaoEnquadar.style.display = 'block';
		botaoEnquadar.innerHTML = '<a href="javascript: void(0)" onclick="chamadas.simulaInicial()" id="botaoEnquadar"><img style="visibility:visible;" src="' + form.contexto.value + '/imagens/simulador/avancar.jpg">';
	}

	
//	atualizaCaptcha();
}
function voltaParametrosConvenio() {
	var parametros = document.getElementById("parametros");
	var produtos = document.getElementById("produtos");
	var headerSimulacao = document.getElementById("headerSimulacao");
	var produtosConvenio = document.getElementById("produtosConvenio");
	var convenio = document.getElementById("convenios");
	var headerSimulacaoConvenio = document.getElementById("headerSimulacaoConvenio");
	var resultado = document.getElementById("resultado");
	
	headerSimulacaoConvenio.style.display = 'none';
	headerSimulacao.style.display = 'block';
	produtosConvenio.style.display = 'none';
	produtos.style.display = 'none';
	convenio.style.display = 'block';
	parametros.style.display = 'none';
	resultado.style.display = 'none';
	
//	atualizaCaptcha();
}

function voltaProdutos() {
	var produtos = document.getElementById("produtos");
	var resultado = document.getElementById("resultado");
	var headerSimulacao = document.getElementById("headerSimulacao");
	var produtosConvenio = document.getElementById("produtosConvenio");
	var headerSimulacaoConvenio = document.getElementById("headerSimulacaoConvenio");
	
	headerSimulacaoConvenio.style.display = 'none';
	produtosConvenio.style.display = 'none';
	headerSimulacao.style.display = 'block';
	produtos.style.display = 'block';
	resultado.style.display = 'none';
}
function voltaProdutosConvenio() {
	var produtos = document.getElementById("produtos");
	var produtosConvenio = document.getElementById("produtosConvenio");
	var resultado = document.getElementById("resultado");
	var headerSimulacao = document.getElementById("headerSimulacao");
	var headerSimulacaoConvenio = document.getElementById("headerSimulacaoConvenio");
	
	headerSimulacao.style.display = 'none';
	headerSimulacaoConvenio.style.display = 'block';
	produtos.style.display = 'block';
	produtosConvenio.style.display = 'block';
	resultado.style.display = 'none';
}

function voltaResultado() {
	var resultado = document.getElementById("resultado");
	var evolucao = document.getElementById("evolucao");

	evolucao.style.display = 'none';
	resultado.style.display = 'block';
}

var chamadas = new SimulaOperacao();

function alteraPrazo() {
	var form = document.forms[0]; 
	var convenio = form.convenio.value;
	var inicioWS = form.inicioWS.value;
	var subsidioParcela = document.getElementById("subsidioParcela");
	var subsidio = document.getElementById("subsidio");
	var resultadoVoltar = document.getElementById('resultadoVoltar');
	var resultadoBotoes = document.getElementById('resultadoBotoes');
	var resultadoLinks = document.getElementById('resultadoLinks');
	var convenioSimulacao = document.getElementById("convenioSimulacao");
	var cabecalhoComplemento = document.getElementById("cabecalhoComplemento");
	var cabecalhoComplementoConvenio = document.getElementById("cabecalhoComplementoConvenio");

	if ((convenio!=null)&&(convenio!='')&&(convenio.length > 0)) {
		document.getElementById("linkVoltarConvenio").onclick = voltaProdutosConvenio;
		document.getElementById("linkVoltarConvenioBotoes").onclick = voltaProdutosConvenio;
	} else {
		if ((inicioWS!=null)&&(inicioWS!='')&&(inicioWS=='V')) {
			document.getElementById("linkVoltarConvenio").onclick = voltaParametros;
			document.getElementById("linkVoltarConvenioBotoes").onclick = voltaParametros;
		} else {
			document.getElementById("linkVoltarConvenio").onclick = voltaProdutos;
			document.getElementById("linkVoltarConvenioBotoes").onclick = voltaProdutos;
		}	
	}	
	convenioSimulacao.style.display = 'none';
	resultadoVoltar.style.display = 'block';
	resultadoBotoes.style.display = 'none';
	resultadoLinks.style.display = 'none';
	subsidioParcela.style.display = 'block';
	subsidio.style.display = 'none';
	cabecalhoComplemento.style.display = 'block';
	cabecalhoComplementoConvenio.style.display = 'none';
	limparCombosSeguradora(true);
}
function alteraPrazoConvenio() {
	var subsidioParcela = document.getElementById("subsidioParcela");
	var subsidio = document.getElementById("subsidio");
	var resultadoVoltar = document.getElementById('resultadoVoltar');
	var resultadoBotoes = document.getElementById('resultadoBotoes');
	var resultadoLinks = document.getElementById('resultadoLinks');
	var convenioSimulacao = document.getElementById("convenioSimulacao");
	var cabecalhoComplemento = document.getElementById("cabecalhoComplemento");
	var cabecalhoComplementoConvenio = document.getElementById("cabecalhoComplementoConvenio");

	resultadoVoltar.style.display = 'block';
	document.getElementById("linkVoltarConvenio").onclick = voltaProdutosConvenio;
	document.getElementById("linkVoltarConvenioBotoes").onclick = voltaProdutosConvenio;
	resultadoBotoes.style.display = 'none';
	resultadoLinks.style.display = 'none';
	subsidioParcela.style.display = 'none';
	subsidio.style.display = 'none';
	convenioSimulacao.style.display = 'block';
	atualizaDadosComplementaresConvenio();
	cabecalhoComplemento.style.display = 'none';
	cabecalhoComplementoConvenio.style.display = 'block';
}

function verificaValorReforma() {
	var form = document.forms[0];

	if (form.grupoTipoFinanciamento.value == 3 || form.grupoTipoFinanciamento.value == 5) {
		document.getElementById('parametrosValorImovel').style.display = 'block';
	} else {
		document.getElementById('parametrosValorImovel').style.display = 'none';
	}
}

function validaPessoaInicio() {
	var form = document.forms[0];
	var pessoa = form.pessoa[0].checked ? "F" : "J";

	if (pessoa == 'F') {
		document.getElementById('pessoaFisica').style.display = 'block';
		document.getElementById('pessoaFisica2').style.display = 'block';
	} else {
		document.getElementById('pessoaFisica').style.display = 'none';
		document.getElementById('pessoaFisica2').style.display = 'none';
		form.rendaFamiliar.value = '';
		form.dataNascimento.value = '';
	}
}	
function validaPessoa() {
	var form = document.forms[0];
	var pessoa = form.pessoa[0].checked ? "F" : "J";

	if (pessoa == 'F') {
		document.getElementById('pessoaFisica').style.display = 'block';
		document.getElementById('pessoaFisica2').style.display = 'block';
	} else {
		document.getElementById('pessoaFisica').style.display = 'none';
		document.getElementById('pessoaFisica2').style.display = 'none';
		form.rendaFamiliar.value = '';
		form.dataNascimento.value = '';
	}
	var combo = document.forms[0].tipoImovel;
	while(combo.options.length > 1) {
		combo.remove(1);
	}
	enviarRequisicao(this.populaTipoImovel,"simulaOperacaoInternet.do","method=consultarTipoImovel&pessoa="+pessoa);
}

function alteraCliente(valor) {
/*	if (valor == 'S') {
		document.getElementById('agencias').style.display = 'none';
	} else {
		document.getElementById('agencias').style.display = 'block';
	}*/
}

function alteraUf() {
	var form = document.forms[0];
//	form.ufInteresse.value = form.uf.value;

	// Remove os valores do campo de UF
	var cidade = form.cidade;
	while(cidade.options.length > 1) {
		cidade.remove(1);
	}
	cidade.options[0].text = 'Aguarde...';
	cidade.disabled = true;

	setaImagem('imageCidade');
	enviarRequisicao(this.populaCidade,"simulaOperacaoInternet.do",'method=listarCidades&uf=' + form.uf.value);
}

function populaCidade(resultado) {
	var form = document.forms[0];
	populaCombo(resultado, form.cidade,"codigo" ,"nome");
//	populaCombo(resultado, form.cidadeInteresse,"codigo" ,"nome");
	form.cidade.disabled = false;
	removeImagem('imageCidade');
}

function alteraCidade() {
	var form = document.forms[0];
	var valor = form.cidade.value;
//	form.cidadeInteresse.value = valor;
//	atualizaAgencia(valor);
}

function alteraConvenio() {
	var form = document.forms[0];
	
	// Recupera o convenio
	var renda = form.rendaFamiliar.value;
	var dataNascimento = form.dataNascimento.value;
	var imovel = form.valorImovel.value;
	var tipo = form.tipoImovel.value;
	var grupoTipoFinanciamento = form.grupoTipoFinanciamento.value;
	var uf = form.uf.value;
	var cidade = form.cidade.value;
	var fisica = form.pessoa[0].checked ? "V" : "F";
	var juridica = form.pessoa[1].checked ? "V" : "F";
	var imovelCidade = form.imovelCidade.checked ? "V" : "F";
	var vaContaFgts = form.vaContaFgts.checked ? "V" : "F";
	var valorReforma = formataValorNumerico(form.valorReforma.value);
	var convenio = form.convenio.value;

	if ((convenio!=null) && (convenio!="") && (convenio.length > 0)) {
		if (fisica == 'V') {
			document.getElementById('tipoPessoa').innerHTML = 'Pessoa Física';
		} else {
			document.getElementById('tipoPessoa').innerHTML = 'Pessoa Jurídica';
		}
		if (fisica == 'F' && juridica == 'F') {
			var erroPessoa = document.getElementById("erroPessoa");
			erroPessoa.innerHTML = 'Campo obrigatório não informado';
			erroPessoa.style.display = 'block';
			setTimeout("chamadas.fade('erroPessoa');", ERRO_TIMEOUT);
		} else if (tipo == "") {
			var erroTipoImovel = document.getElementById("erroTipoImovel");
			erroTipoImovel.innerHTML = 'Campo obrigatório não informado';
			erroTipoImovel.style.display = 'block';
			setTimeout("chamadas.fade('erroTipoImovel');", ERRO_TIMEOUT);
		} else if (grupoTipoFinanciamento == "") {
			var erroCategoriaImovel = document.getElementById("erroCategoriaImovel");
			erroCategoriaImovel.innerHTML = 'Campo obrigatório não informado';
			erroCategoriaImovel.style.display = 'block';
			setTimeout("chamadas.fade('erroCategoriaImovel');", ERRO_TIMEOUT);
		} else if ((grupoTipoFinanciamento == 3 || grupoTipoFinanciamento == 5) && valorReforma == 0) {
			var erroValorReforma = document.getElementById("erroValorReforma");
			erroValorReforma.innerHTML = 'Valor inválido.';
			erroValorReforma.style.display = 'block';
			setTimeout("chamadas.fade('erroValorReforma');", ERRO_TIMEOUT);
		} else if ((grupoTipoFinanciamento == 3 || grupoTipoFinanciamento == 5) && isNaN(valorReforma)) {
			var erroValorReforma = document.getElementById("erroValorReforma");
			erroValorReforma.innerHTML = 'Campo obrigatório não informado';
			erroValorReforma.style.display = 'block';
			setTimeout("chamadas.fade('erroValorReforma');", ERRO_TIMEOUT);
		} else if (uf == "" || cidade == "") {
			var erroUfCidade = document.getElementById("erroUfCidade");
			erroUfCidade.innerHTML = 'Campo obrigatório não informado';
			erroUfCidade.style.display = 'block';
			setTimeout("chamadas.fade('erroUfCidade');", ERRO_TIMEOUT);
		} else if (imovel == "") {
			var erroValorImovel = document.getElementById("erroValorImovel");
			erroValorImovel.innerHTML = 'Campo obrigatório não informado';
			erroValorImovel.style.display = 'block';
			setTimeout("chamadas.fade('erroValorImovel');", ERRO_TIMEOUT);
		} else if (fisica == 'V' && renda == "") {
			var erroRendaFamiliar = document.getElementById("erroRendaFamiliar");
			erroRendaFamiliar.innerHTML = 'Campo obrigatório não informado';
			erroRendaFamiliar.style.display = 'block';
			setTimeout("chamadas.fade('erroRendaFamiliar');", ERRO_TIMEOUT); 
		} else if (fisica == 'V' && dataNascimento == "") {
			var erroDataNascimento = document.getElementById("erroDataNascimento");
			erroDataNascimento.innerHTML = 'Campo obrigatório não informado';
			erroDataNascimento.style.display = 'block';
			setTimeout("chamadas.fade('erroDataNascimento');", ERRO_TIMEOUT);
		} else {
			// Preenche o cabeçalho da tela
			var campo;
	
			// Tipo de Imóvel
			campo = document.getElementById("headerTipo");
			campo.innerHTML = form.tipoImovel.options[form.tipoImovel.selectedIndex].text;
			
			// Grupo de tipo de financiamento
			campo = document.getElementById("headerCategoria");
			campo.innerHTML = form.grupoTipoFinanciamento.options[form.grupoTipoFinanciamento.selectedIndex].text;
	
			// Valor do Imóvel
			campo = document.getElementById("headerValor");
			campo.innerHTML = 'R$ ' + form.valorImovel.value;
	
			// Cidade + "-" + UF 
			campo = document.getElementById("headerCidade");
			campo.innerHTML = form.cidade.options[form.cidade.selectedIndex].text
				+ "-" + form.uf.options[form.uf.selectedIndex].text;
			if (form.imovelCidade.checked) {
				campo.innerHTML += ' - Possui imóvel neste município.'; 
			}
	
			campo = document.getElementById("headerRegimeFGTS");
			if (form.vaContaFgts.checked) {
				campo.innerHTML = ' Sim'; 
			} else {
				campo.innerHTML = ' Não'; 
			}
			// Renda Familiar Bruta
			campo = document.getElementById("headerRenda");
			if (form.rendaFamiliar.value != '') {
				campo.innerHTML = 'R$ ' + form.rendaFamiliar.value;
			}else {
				campo.innerHTML = '';
			}
	
			campo = document.getElementById("headerBeneficiadoFGTS");
			if (form.beneficiadoFGTS.checked) {
				campo.innerHTML = ' Sim'; 
				campo = document.getElementById("headerDataBeneficioFGTS");
				campo.innerHTML = form.dataBeneficioFGTS.value; 
			} else {
				campo.innerHTML = ' Não';
				campo = document.getElementById("headerDataBeneficioFGTS");
				campo.innerHTML = ''; 
			}

			// Data de Nascimento 
			campo = document.getElementById("headerData");
			campo.innerHTML = form.dataNascimento.value;
			enviarRequisicao(this.populaConvenios,"simulaOperacaoInternet.do",'method=listarEmpresasConvenio&convenio=' + convenio);
		}	
	}
}

function alteraUfInteresse() {
	var form = document.forms[0];

	// Remove os valores do campo de UF
	var cidade = form.cidadeInteresse;
	while(cidade.options.length > 1) {
		cidade.remove(1);
	}
	cidade.options[0].text = 'Aguarde...';
	cidade.disabled = true;

	setaImagem('imageCidadeInteresse');
	enviarRequisicao(this.populaCidadeInteresse,"simulaOperacaoInternet.do",'method=listarCidades&uf=' + form.ufInteresse.value);
}

function populaCidadeInteresse(resultado) {
	var form = document.forms[0];
	populaCombo(resultado, form.cidadeInteresse,"codigo" ,"nome");
	form.cidadeInteresse.disabled = false;
	removeImagem('imageCidadeInteresse');
}
 
function populaConvenios(xml) {
		var form = document.forms[0];
		var root = xml.getElementsByTagName("root");
		var erro;
		var child; 
		
		//Indica se foi informado pessoa física.
		var pessoaFisica = form.pessoa[0].checked;   
		
		for (var i = 0; i < root.length; i++) {
			child = root[i];

			erro = child.getElementsByTagName("error");
			if (erro.length > 0) {
				var desc = erro[0].firstChild.nodeValue;
				var erroLocal = document.getElementById("erroSimulaInicial");
				erroLocal.innerHTML = desc;
				erroLocal.style.display = 'block';
				setTimeout("chamadas.fade('erroSimulaInicial');", 5000);
			} else {
				var descricaoConvenio = child.getElementsByTagName("descricaoConvenio")[0].firstChild.nodeValue;
				var divEmpresas = document.getElementById("listaEmpresas");
				
				// Apaga os produtos existentes de outras simulações.
				while(divEmpresas.firstChild != null) {
					divEmpresas.removeChild(divEmpresas.firstChild);
				}
				
				// Array com os itens de produto enquadrados
				var empresas = child.getElementsByTagName("empresa");
				var cor = true;
				
				var nuEmpresa;
				var nomeEmpresa;
				var siglaEmpresa;
				
				var tabela1 = document.createElement("div");
				tabela1.className = "field_block_1";
				tabela1.innerHTML = '&nbsp;';
				divEmpresas.appendChild(tabela1);
				var cabecalho = document.createElement("div");
				cabecalho.className = "field_block_2";
				cabecalho.innerHTML = '&nbsp;<label class="texto_alerta">Clique no nome da empresa</label>&nbsp;';
				divEmpresas.appendChild(cabecalho);
				var table1 = document.createElement("table");
				var tb1 = document.createElement("tbody");
				table1.appendChild(tb1);
				for (var ip = 0; ip < empresas.length; ip++) {
					nuEmpresa = empresas[ip].getElementsByTagName("nuEmpresa")[0].firstChild.nodeValue;
					nomeEmpresa = empresas[ip].getElementsByTagName("nomeEmpresa")[0].firstChild.nodeValue;
					siglaEmpresa = empresas[ip].getElementsByTagName("siglaEmpresa")[0].firstChild.nodeValue;
					
					// DIV para armazenar uma empresa
					var tr1 = document.createElement("tr");
					if (cor == true) {
						tr1.className = "field_block_2";
					} else {
						tr1.className = "field_block_1";
					}
					cor = !cor;
					
					var nomeItem = document.createElement('div');
	
					var link = document.createElement("a");
					link.href = 'javascript: void(0)';
					link.innerHTML = '&nbsp;' + siglaEmpresa + '&nbsp;';
					link.onclick = function() {
						chamadas.simulaInicialEmpresa(this);
					}
					link.setAttribute("nuEmpresa", nuEmpresa);
					link.setAttribute("siglaEmpresa", siglaEmpresa);
					link.setAttribute("nomeEmpresa", nomeEmpresa);
					link.className = 'texto_link_empresa';

					var nomeEmpresaLabel = document.createElement("label");
					nomeEmpresaLabel.className = 'texto_campos';
					nomeEmpresaLabel.innerHTML = ' - ' + nomeEmpresa;
					nomeEmpresaLabel.style.paddingLeft = '10px';

					var td1 = document.createElement("td");
					td1.className = 'texto_campos';
					td1.appendChild(link);
					tr1.appendChild(td1);
					var td2 = document.createElement("td");
					td2.className = 'texto_campos';
					td2.appendChild(nomeEmpresaLabel);
					tr1.appendChild(td2);

					tb1.appendChild(tr1);
					
				}
				divEmpresas.appendChild(table1);
				var erro = document.createElement("div");
				erro.className = 'error_box';
				erro.id = 'erroEmpresa';
				divEmpresas.appendChild(erro);
				
				// Adiciona a mensagem parametrizada do convênio
				var tabela2 = document.createElement("div");
				tabela2.className = "field_block_2";
				tabela2.innerHTML = '&nbsp;' + descricaoConvenio + '&nbsp;';
				divEmpresas.appendChild(tabela2);

				var table = document.createElement("table");
				var tb = document.createElement("tbody");
				table.appendChild(tb);
				table.className = "field_block_2";
				
				tr = document.createElement("tr");
				td = document.createElement("td");
				td.className = 'texto_campos'
				td.innerHTML = '<b></b>';
				tr.appendChild(td);
				
				td = document.createElement("td");
				var link2 = document.createElement("a");
				link2.href = 'javascript: void(0)';
				link2.onclick = voltaParametros;
				td.appendChild(link2);
				
				// Imagem do botão voltar
				var img = document.createElement("img");
				img.src = form.contexto.value + '/imagens/simulador/SIM_VOLTAR.jpg';
				link2.appendChild(img);
				//td.appendChild(voltar);
				tr.appendChild(td);
				tb.appendChild(tr);
/*				
				tr = document.createElement("tr");
				td = document.createElement("td");
				td.className = 'texto_campos'
				td.style.textAlign='right';
				td.innerHTML = 'Se a sua empresa n&atilde;o est&aacute; na rela&ccedil;&atilde;o acima, ';
				td.colSpan = '3';
				tr.appendChild(td);
				link2 = document.createElement("a");
				link2.href = '#';
				link2.target = 'new';
				link2.className = 'texto_link';
				td.appendChild(link2);
				text = document.createTextNode('Clique aqui');
				link2.appendChild(text);
				var text2 = document.createTextNode(' e simule seu convênio');
				td.appendChild(text2);
				
				tb.appendChild(tr);
				*/
				// Adiciona o botão a lista de div
				divEmpresas.appendChild(table);
				
				/*
				 * Configura a exibição dos campos que são apenas p/ pessoa fisica
				 */
				if(pessoaFisica){
					document.getElementById("tdRendaBruta").style.display = 'block';
					document.getElementById("tdDataNascimento").style.display = 'block';
					document.getElementById("trPossuiFGTS").style.display = 'block';
					document.getElementById("trBeneficiadoFGTS").style.display = 'block';
					document.getElementById("trDtBeneficio").style.display = 'block';
				}else{
					document.getElementById("tdRendaBruta").style.display = 'none';
					document.getElementById("tdDataNascimento").style.display = 'none';
					document.getElementById("trPossuiFGTS").style.display = 'none';
					document.getElementById("trBeneficiadoFGTS").style.display = 'none';
					document.getElementById("trDtBeneficio").style.display = 'none';
				} 
				
				var parametros = document.getElementById("parametros");
				var produtos = document.getElementById("produtos");
				var produtosConvenio = document.getElementById("produtosConvenio");
				var convenio = document.getElementById("convenios");
				var headerSimulacao = document.getElementById("headerSimulacao");
				var headerSimulacaoConvenio = document.getElementById("headerSimulacaoConvenio");
				
				var nomeConvenio = document.getElementById("nomeConvenio");
				nomeConvenio.innerHTML = form.convenio.options[form.convenio.selectedIndex].text;

				
				headerSimulacao.style.display = 'block';
				headerSimulacaoConvenio.style.display = 'none';
				produtos.style.display = 'none';
				produtosConvenio.style.display = 'none';
				convenio.style.display = 'block';
				parametros.style.display = 'none';
				
			}
		}		
}

function atualizaAgencia(valor) {
	var agencia = document.forms[0].agencia;
	agencia.options[0].text = 'Aguarde...';
	agencia.disabled = true;
	enviarRequisicao(this.populaAgencia,"simulaOperacaoInternet.do","method=listarAgencias&cidade="+valor);
}

function populaAgencia(resultado) {
	var agencia = document.forms[0].agencia;
	populaCombo(resultado, agencia, "codigo", "noUnidade");
	agencia.disabled = false;
}

function alteraTipoImovel(valor) {
	var form = document.forms[0];
	var pessoa = form.pessoa[0].checked ? "F" : "J";
	
	// Construtora
	if (valor == 999) {
		window.open(form.linkConstrutora.value, 'Construtora', 'scrollbars=yes,width=500,height=560');
		self.close();
	} else {
		setaImagem('imageFinanciamento');
		var g = form.grupoTipoFinanciamento;
		g.options[0].text = 'Aguarde...';
		g.disabled = true;
		enviarRequisicao(this.populaGrupoFinanciamento,"simulaOperacaoInternet.do","method=consultarGrupoTipoFinanciamento&pessoa="+pessoa+'&tipoImovel='+valor);
	}
} 

function populaTipoImovel(resultado) {
	var form = document.forms[0];
	populaCombo(resultado, form.tipoImovel,"nuTpoImovel" ,"noTpoImovel");
	var combo = form.grupoTipoFinanciamento;
	while(combo.options.length > 1) {
		combo.remove(1);
	}
}

function populaGrupoFinanciamento(resultado) {
	var form = document.forms[0];
	populaCombo(resultado, form.grupoTipoFinanciamento,"codigo" ,"descricao");
	removeImagem('imageFinanciamento');
	var g = form.grupoTipoFinanciamento;
	g.disabled = false;
}

function formataValorNumerico(valor) {
	valor = valor + '';
	var end = '';
	for (loopPonto = 0; loopPonto < valor.length; loopPonto++) {
		if (valor.charAt(loopPonto) == ',') {
			end += '.';
		} else if (valor.charAt(loopPonto) != '.') {
			end += valor.charAt(loopPonto);
		}
	}
	return parseFloat(end);
}

function setaImagem(id) {
	document.getElementById(id).innerHTML = '<img src="' + document.forms[0].contexto.value + '/imagens/progress.gif">';
}

function removeImagem(id) {
	document.getElementById(id).innerHTML = '';
}


function atualizaDadosComplementaresConvenio() {
	var form = document.forms[0];
	document.getElementById("seDesejaCotaFinanciamento1").disabled = false;
	document.getElementById("seDesejaCotaFinanciamento2").disabled = false;
	document.getElementById("seDesejaFinanciarDespesas1").disabled = false;
	document.getElementById("seDesejaFinanciarDespesas2").disabled = false;
	document.getElementById("seDesejaCarencia1").disabled = false;
	document.getElementById("seDesejaCarencia2").disabled = false;
/*	var ehCliente = (((form.seEhCliente[0]!=null) && (!form.seEhCliente[0].disabled) && (form.seEhCliente[0].checked)) ? "V" : "F");
	if ((ehCliente!=null)&&(ehCliente=="V")) {
		document.getElementById("seDesejaCotaFinanciamento1").disabled = false;
		document.getElementById("seDesejaCotaFinanciamento2").disabled = false;
		document.getElementById("seDesejaFinanciarDespesas1").disabled = false;
		document.getElementById("seDesejaFinanciarDespesas2").disabled = false;
	} else {
		document.getElementById("seDesejaCotaFinanciamento1").disabled = true;
		document.getElementById("seDesejaCotaFinanciamento2").disabled = true;
		document.getElementById("seDesejaFinanciarDespesas1").disabled = true;
		document.getElementById("seDesejaFinanciarDespesas2").disabled = true;
	}
	var desejaCota = (((form.seDesejaCotaFinanciamento[0]!=null) && (!form.seDesejaCotaFinanciamento[0].disabled) && (form.seDesejaCotaFinanciamento[1].checked)) ? "F" : "V");
	if ((desejaCota!=null)&&(desejaCota=="F")) {
		document.getElementById("seDesejaCarencia1").disabled = false;
		document.getElementById("seDesejaCarencia2").disabled = false;
	} else {
		document.getElementById("seDesejaCarencia1").disabled = true;
		document.getElementById("seDesejaCarencia2").disabled = true;
	}*/
	var ehCliente = (((form.seEhCliente[0]!=null) && (!form.seEhCliente[0].disabled) && (form.seEhCliente[0].checked)) ? "V" : "F");
	var desejaCota = (((form.seDesejaCotaFinanciamento[1]!=null) && (!form.seDesejaCotaFinanciamento[1].disabled) && (form.seDesejaCotaFinanciamento[1].checked)) ? "F" : "V");
	var desejaCarencia = (((form.seDesejaCarencia[1]!=null) && (!form.seDesejaCarencia[1].disabled)  && (form.seDesejaCarencia[1].checked)) ? "F" : "V");
	if ((desejaCarencia!=null)&&(desejaCarencia=="V")) {
		document.getElementById("prazoCarencia1").disabled = false;
	} else {
		document.getElementById("prazoCarencia1").disabled = true;
	}
	var desejaDespesas = (((form.seDesejaFinanciarDespesas[1]!=null) && 
			(!form.seDesejaFinanciarDespesas[1].disabled) && 
			(form.seDesejaFinanciarDespesas[1].checked)) ? "F" : "V");
	if ((desejaDespesas!=null)&&(desejaDespesas=="V")) {
		document.getElementById("valorTaxas1").disabled = false;
	} else {
		document.getElementById("valorTaxas1").disabled = true;
	}

	var sePermiteEhCliente = form.sePerguntaEhCliente.value;
	var sePermiteCarencia = form.sePerguntaCarencia.value;
	var sePermiteCota = form.sePerguntaCota.value;
	var sePermiteTaxas = form.sePerguntaTaxas.value;
	exibeEscondePerguntaComplementoConvenio(sePermiteEhCliente,sePermiteCarencia,sePermiteCota,sePermiteTaxas);					
}

function exibeEscondePerguntaComplementoConvenio(sePermiteEhCliente, sePermiteCarencia,sePermiteCota,sePermiteTaxas) {
	var form = document.forms[0];
	var ehCliente = (((form.seEhCliente[0]!=null) && (!form.seEhCliente[0].disabled) && (form.seEhCliente[0].checked)) ? "V" : "F");
	var desejaCota = (((form.seDesejaCotaFinanciamento[1]!=null) && (!form.seDesejaCotaFinanciamento[1].disabled) && (form.seDesejaCotaFinanciamento[1].checked)) ? "F" : "V");
	var desejaCarencia = (((form.seDesejaCarencia[1]!=null) && (!form.seDesejaCarencia[1].disabled) && (form.seDesejaCarencia[1].checked)) ? "F" : "V");
	
	if ((sePermiteEhCliente!=null)&&(sePermiteEhCliente=="1")) {
		document.getElementById("trSeEhCliente").style.display = 'block';
	} else {
		document.getElementById("trSeEhCliente").style.display = 'none';
	}
	
	if ((sePermiteCota==null)||(sePermiteCota=="0")||(sePermiteCota=="")) {
		document.getElementById("trSeDesejaCotaFinanciamento").style.display = 'none';
	} else {
		if (((ehCliente=="V")&&(sePermiteCota=="2"))||
			((ehCliente=="V")&&(sePermiteCota=="1"))) {
			document.getElementById("trSeDesejaCotaFinanciamento").style.display = 'block';
		} else {
			document.getElementById("trSeDesejaCotaFinanciamento").style.display = 'none';
		}
	}
	
	if ((sePermiteCarencia==null)||(sePermiteCarencia=="0")||(sePermiteCarencia=="")) {
		document.getElementById("trSeDesejaCarencia").style.display = 'none';
		document.getElementById("trPrazoCarencia").style.display = 'none';
	} else {
		if (((ehCliente=="V")&&(sePermiteCarencia=="2"))||
			((ehCliente=="V")&&(desejaCota=="F")&&(sePermiteCarencia=="3"))||
			(sePermiteCarencia=="1")) {
			document.getElementById("trSeDesejaCarencia").style.display = 'block';
			document.getElementById("trPrazoCarencia").style.display = 'block';
		} else {
			document.getElementById("trSeDesejaCarencia").style.display = 'none';
			document.getElementById("trPrazoCarencia").style.display = 'none';
		}
	}
	
	if ((sePermiteTaxas==null)||(sePermiteTaxas=="0")||(sePermiteTaxas=="")) {
		document.getElementById("trSeDesejaFinanciarDespesas").style.display = 'none';
		document.getElementById("trValorTaxas").style.display = 'none';
	} else {
		if (((ehCliente=="V")&&(sePermiteTaxas=="2"))||
			((ehCliente=="V")&&(desejaCarencia=="F")&&(sePermiteTaxas=="3"))||
			((ehCliente=="V")&&(desejaCarencia=="F")&&(sePermiteTaxas=="1"))) {
			document.getElementById("trSeDesejaFinanciarDespesas").style.display = 'block';
			document.getElementById("trValorTaxas").style.display = 'block';
		} else {
			document.getElementById("trSeDesejaFinanciarDespesas").style.display = 'none';
			document.getElementById("trValorTaxas").style.display = 'none';
		}
	}

}

	function pause(millis) {
		var date = new Date();
		var curDate = null;
		do { curDate = new Date(); }
		while ( curDate-date < millis);
	}
	function inibirSeguradora(idSeguradora, idTrLabelSeguradora, exibeCombo) {
		var mip = document.getElementById("resultadoMip1");
		var dfi = document.getElementById("resultadoDfi1");
		var trSeguradora = document.getElementById(idSeguradora);
		var trLabelSeguradora = document.getElementById(idTrLabelSeguradora);
		
		if ((mip == null || isVazio(mip.value)) 
				&& (dfi == null || isVazio(dfi.value))) {
			if (trSeguradora) {
				trSeguradora.style.display = 'none';
			}
			if (trLabelSeguradora) {
				trLabelSeguradora.style.display = 'none';
			}
		}else {
			if (trSeguradora && exibeCombo) {
				trSeguradora.style.display = 'block';
			}else if (trLabelSeguradora) {
				trLabelSeguradora.style.display = 'block';
			}
		}
	}
	
	function existeSeguradora() {
		var mip = document.getElementById("resultadoMip1");
		var dfi = document.getElementById("resultadoDfi1");
		var existe = true;
		
		if ((mip == null || isVazio(mip.value)) 
				&& (dfi == null || isVazio(dfi.value))) {
			existe = false;
		}
		return existe;
	}
	
	/**
	 * Recupera o valor da opção marcada do radioButton
	 * 
	 * @param obj - Object
	 * 		O radioButton
	 */
	function getValorRadio(obj){
		if(obj != undefined && obj.length != undefined){
			for(var i=0; i < obj.length ; i++){
				if(obj[i].checked == true){
					return obj[i].value;
				}
			}
		}
		return null;
	}

