	
	function mostraCalcBeneficio()
	{
		document.getElementById('ob_calc_beneficio_1').style.display = "";
	}

	function escondeCalcBeneficio()
	{
		document.getElementById('ob_calc_beneficio_1').style.display = "none";
		document.getElementById('nr_prazo').value = "";
		
		document.getElementById('vl_invalidez_contribuicao').value = "";
		document.getElementById('vl_pensao_contribuicao').value = "";
		
		document.getElementById('vl_invalidez_renda').value = "";
		document.getElementById('vl_pensao_renda').value = "";		
	}

	function getStatusInvalidez()
	{
		var fl_invalidez = true;
		
		if((document.getElementById('vl_invalidez_capital').value == "") || (parseInt(document.getElementById('vl_invalidez_capital').value) == 0))
		{
			var fl_invalidez = false;
		}

		return fl_invalidez;
	}
	
	function validaInvalidez()
	{

		var fl_invalidez = getStatusInvalidez();
		
		if((fl_invalidez) && (document.getElementById('vl_invalidez_contribuicao').value == ""))
		{
			alert("Calcule a Contribuição do benefício de invalidez.");
			return false;
		}
		else if((fl_invalidez) && (document.getElementById('vl_invalidez_renda').value == ""))
		{
			alert("Calcule o Prazo do benefício de invalidez.");
			return false;
		}
		else if(parseInt(document.getElementById('nr_invalidez_prazo').value) < 5)
		{
			alert("Prazo mínimo de 5 anos.");
			return false;
		}
		else
		{
			return true;
		}
	}
	
	function getStatusPensao()
	{
		var fl_pensao = true;
		
		if((document.getElementById('vl_pensao_capital').value == "") || (parseInt(document.getElementById('vl_pensao_capital').value) == 0))
		{
			var fl_pensao = false;
		}

		return fl_pensao;
	}	
	
	function validaPensao()
	{
		var fl_pensao = getStatusPensao();
		
		if((fl_pensao) && (document.getElementById('vl_pensao_contribuicao').value == ""))
		{
			alert("Calcule a Contribuição da pensão.");
			return false;
		}
		else if((fl_pensao) && (document.getElementById('vl_pensao_renda').value == ""))
		{
			alert("Calcule o Prazo da pensão.");
			return false;
		}	
		else if(parseInt(document.getElementById('nr_pensao_prazo').value) < 5)
		{
			alert("Prazo mínimo de 5 anos.");
			return false;
		}		
		else
		{
			return true;
		}
	}	
	
	function calcContribuicaoInvalidez()
	{
		var nr_a = parseInt(document.getElementById('vl_invalidez_capital').value.replace(".", "")) / 1000;
		var nr_b = Math.round(nr_a);
		
		if(document.getElementById('vl_invalidez_capital').value == "")
		{
			alert('Informe o Capital Segurado');
			document.getElementById('vl_invalidez_capital').focus();
		}	
		else if(parseInt(document.getElementById('vl_invalidez_capital').value.replace(".", "")) < 1000)
		{
			alert('Capital Segurado mínimo de R$ 1.000,00');
			document.getElementById('vl_invalidez_capital').focus();
		}
		else if(nr_a != nr_b)
		{
			alert('Capital segurado: múltiplos de R$ 1.000,00.');
			document.getElementById('vl_pensao_contribuicao').focus();			
		}		
		else
		{
			var ds_url   = "sinprors_simulador_ajax.php";
			var lt_param = "ds_funcao=calculaContribuicaoInvalidez";
				lt_param+= "&vl_invalidez_capital=" + document.getElementById('vl_invalidez_capital').value;
				lt_param+= "&dt_nascimento=" + document.getElementById('dt_nascimento').value;
				
				ajaxExecute(ds_url, lt_param, "calcContribuicaoInvalidezRetorno", '', 'POST');			
		}
	}
	
	function calcContribuicaoInvalidezRetorno(ds_retorno)
	{
		document.getElementById('vl_invalidez_contribuicao').value = ds_retorno;
	}
	
	function calcRendaInvalidez()
	{
		if(document.getElementById('nr_invalidez_prazo').value == "")
		{
			alert('Informe o Prazo');
			document.getElementById('nr_invalidez_prazo').focus();
		}	
		else if(parseInt(document.getElementById('nr_invalidez_prazo').value) < 5)
		{
			alert("Prazo mínimo de 5 anos.");
			document.getElementById('nr_invalidez_prazo').focus();
		}
		else
		{
			var ds_url   = "sinprors_simulador_ajax.php";
			var lt_param = "ds_funcao=calcRenda";
				lt_param+= "&vl_capital=" + document.getElementById('vl_invalidez_capital').value;
				lt_param+= "&nr_prazo=" + document.getElementById('nr_invalidez_prazo').value;
				
				
				ajaxExecute(ds_url, lt_param, "calcRendaInvalidezRetorno", '', 'POST');			
		}
	}
	
	function calcRendaInvalidezRetorno(ds_retorno)
	{
		document.getElementById('vl_invalidez_renda').value = ds_retorno;
	}	
	
	function calcContribuicaoPensao()
	{
		var nr_a = parseInt(document.getElementById('vl_pensao_capital').value.replace(".", "")) / 1000;
		var nr_b = Math.round(nr_a);
		
		if(document.getElementById('vl_pensao_capital').value == "")
		{
			alert('Informe o Capital Segurado');
			document.getElementById('vl_pensao_capital').focus();
		}	
		else if(parseInt(document.getElementById('vl_pensao_capital').value.replace(".", "")) < 1000)
		{
			alert('Capital Segurado mínimo de R$ 1.000,00');
			document.getElementById('vl_pensao_contribuicao').focus();
		}
		else if(nr_a != nr_b)
		{
			alert('Capital segurado: múltiplos de R$ 1.000,00.');
			document.getElementById('vl_pensao_contribuicao').focus();			
		}
		else
		{
			var ds_url   = "sinprors_simulador_ajax.php";
			var lt_param = "ds_funcao=calculaContribuicaoPensao";
				lt_param+= "&vl_pensao_capital=" + document.getElementById('vl_pensao_capital').value;
				lt_param+= "&dt_nascimento=" + document.getElementById('dt_nascimento').value;
				
				ajaxExecute(ds_url, lt_param, "calcContribuicaoPensaoRetorno", '', 'POST');			
		}
	}
	
	function calcContribuicaoPensaoRetorno(ds_retorno)
	{
		document.getElementById('vl_pensao_contribuicao').value = ds_retorno;
	}	
	
	function calcRendaPensao()
	{
		if(document.getElementById('nr_pensao_prazo').value == "")
		{
			alert('Informe o Prazo');
			document.getElementById('nr_pensao_prazo').focus();
		}	
		else if(parseInt(document.getElementById('nr_pensao_prazo').value) < 5)
		{
			alert("Prazo mínimo de 5 anos.");
			document.getElementById('nr_pensao_prazo').focus();
		}		
		else
		{
			var ds_url   = "sinprors_simulador_ajax.php";
			var lt_param = "ds_funcao=calcRenda";
				lt_param+= "&vl_capital=" + document.getElementById('vl_pensao_capital').value;
				lt_param+= "&nr_prazo=" + document.getElementById('nr_pensao_prazo').value;
				
				
				ajaxExecute(ds_url, lt_param, "calcRendaPensaoRetorno", '', 'POST');			
		}
	}
	
	function calcRendaPensaoRetorno(ds_retorno)
	{
		document.getElementById('vl_pensao_renda').value = ds_retorno;
	}	
	
	function validaCalculaPrazo()
	{
		if(!validaData(document.getElementById('dt_nascimento').value))
		{
			alert('Informe a Data de Nascimento');
			document.getElementById('dt_nascimento').focus();
		}
		else if((document.getElementById('qt_idade').value == "") || (document.getElementById('qt_idade').value < 50))
		{
			alert('A idade mínima para aposentadoria é de 50 anos');
			document.getElementById('qt_idade').focus();
		}		
		else if((document.getElementById('vl_contribuicao').value == "") || (parseInt(document.getElementById('vl_contribuicao').value.replace(".", "")) < 50))
		{
			alert('O valor mínimo de contribuição é de R$ 50,00.');
			document.getElementById('vl_contribuicao').focus();
		}
		else if(document.getElementById('vl_rentabilidade').value == 0)
		{
			alert('Informe a Rentabilidade');
			document.getElementById('vl_rentabilidade').focus();
		}		
		else
		{
			verificaTempoPlano();
		}
	}
	
	function calculaPrazo()
	{
		var ds_url   = "sinprors_simulador_ajax.php";
		var lt_param = "ds_funcao=calculaPrazo";
			lt_param+= "&dt_nascimento=" + document.getElementById('dt_nascimento').value;
			lt_param+= "&qt_idade=" + document.getElementById('qt_idade').value;
			lt_param+= "&vl_contribuicao=" + document.getElementById('vl_contribuicao').value;
			lt_param+= "&vl_rentabilidade=" + document.getElementById('vl_rentabilidade').value;
			
			ajaxExecute(ds_url, lt_param, "calculaPrazoRetorno", '', 'POST');			
	}
	
	function calculaPrazoRetorno(ds_retorno)
	{
		if(parseInt(ds_retorno) > 0)
		{
			mostraCalcBeneficio();
		}
		else
		{
			alert("Saldo insuficiente para gerar benefícios de aposentadoria.\n\nAltere a idade de aposentadoria ou o valor da contribuição.");
		}
	}
	
	function calculaBeneficio()
	{
		document.getElementById('ob_normal').style.display = "none";
		if ((document.getElementById('ob_calc_beneficio_1').style.display == "none"))
		{
			alert('É necessário Calcular o Prazo da Aposentadoria Normal.');
		}		
		else if(document.getElementById('nr_prazo').value == "")
		{
			alert('Informe o Prazo.');
		}
		else if(!validaData(document.getElementById('dt_nascimento').value))
		{
			alert('Informe a Data de Nascimento');
			document.getElementById('dt_nascimento').focus();
		}
		else if((document.getElementById('qt_idade').value == "") || (document.getElementById('qt_idade').value < 50))
		{
			alert('A idade mínima para aposentadoria é de 50 anos');
			document.getElementById('qt_idade').focus();
		}		
		else if(document.getElementById('vl_contribuicao').value == "")
		{
			alert('Informe o Valor da Contribuição');
			document.getElementById('vl_contribuicao').focus();
		}
		else if((document.getElementById('nr_prazo').value == "") || (document.getElementById('nr_prazo').value < 5))
		{
			alert('Prazo mínimo de 5 anos.');
			//document.getElementById('nr_prazo').focus();
		}		
		else if(document.getElementById('vl_rentabilidade').value == 0)
		{
			alert('Informe a Rentabilidade');
			document.getElementById('vl_rentabilidade').focus();
		}
		else
		{
			
			var ds_url   = "sinprors_simulador_ajax.php";
			var lt_param = "ds_funcao=calculaBeneficio";
				lt_param+= "&dt_nascimento=" + document.getElementById('dt_nascimento').value;
				lt_param+= "&qt_idade=" + document.getElementById('qt_idade').value;
				lt_param+= "&vl_contribuicao=" + document.getElementById('vl_contribuicao').value;
				lt_param+= "&nr_prazo=" + document.getElementById('nr_prazo').value;
				lt_param+= "&vl_rentabilidade=" + document.getElementById('vl_rentabilidade').value;
				
				ajaxExecute(ds_url, lt_param, "calculaBeneficioRetorno", '', 'POST');				
		}
	}	
	
	function calculaBeneficioRetorno(ds_retorno)
	{
		var ar_tmp = ds_retorno.split("|");
		
		document.getElementById('re_saldo').value = ar_tmp[0];
		document.getElementById('re_renda').value = ar_tmp[1];
		document.getElementById('re_contribuicao').value = ar_tmp[2];
		document.getElementById('re_prazo').value = document.getElementById('nr_prazo').value;
		document.getElementById('re_taxa').value = document.getElementById('vl_rentabilidade').options[document.getElementById('vl_rentabilidade').selectedIndex].text;
		
		document.getElementById('re_nome').value = document.getElementById('ds_nome').value;
		document.getElementById('re_nascimento').value = document.getElementById('dt_nascimento').value;
		document.getElementById('re_idade').value = document.getElementById('qt_idade').value;
		
		document.getElementById('ob_normal').style.display = "";
		
	}

	function validaPessoa()
	{
		var re_requerido = /[^.*]/;
		var re_telefone = /^[\d\s ().-]+$/;
		var re_email = /^[a-z0-9._%-]+@[a-z0-9.-]+\.[a-z]{2,4}$/i;
		
		if ((re_requerido.exec(document.getElementById('ds_nome').value) == null) || (trimStringCampo(document.getElementById('ds_nome').value) == ""))
		{
			alert("Informe o Nome");
			return false;
		}
		else if (re_telefone.exec(document.getElementById('nr_telefone').value) == null)
		{
			alert("Informe um Telefone Válido");
			return false;
		}
		else if (re_email.exec(document.getElementById('ds_email').value) == null)
		{
			alert("Informe um Email válido.");
			return false;
		}
		else
		{
			return true;
		}
	}
	
	function montaResumo()
	{
		if (validaPessoa())
		{
			var fl_exibe = false;
			if ((document.getElementById('ob_calc_beneficio_1').style.display == "") && (parseInt(document.getElementById('nr_prazo').value) > 0))
			{
				fl_exibe = true;
			}		
			
			if(parseInt(document.getElementById('nr_prazo').value) < 5)
			{
				fl_exibe = false;
			}
			
			if((validaInvalidez()) && (fl_exibe))
			{
				fl_exibe = true;
			}
			else
			{
				fl_exibe = false;
			}
			
			if((validaPensao()) && (fl_exibe))
			{
				fl_exibe = true;
			}
			else
			{
				fl_exibe = false;

			}

			calculaBeneficio();
			if(getStatusInvalidez())
			{
				document.getElementById('re_capital_invalidez').value = document.getElementById('vl_invalidez_capital').value;
				document.getElementById('re_contribuicao_invalidez').value = document.getElementById('vl_invalidez_contribuicao').value;
				document.getElementById('re_prazo_invalidez').value = document.getElementById('nr_invalidez_prazo').value;
				document.getElementById('re_renda_invalidez').value = document.getElementById('vl_invalidez_renda').value;
				document.getElementById('ob_resul_invalidez').style.display = "";
			}
			else
			{
				document.getElementById('ob_resul_invalidez').style.display = "none";
			}
			
			if(getStatusPensao())
			{
				document.getElementById('re_capital_pensao').value = document.getElementById('vl_pensao_capital').value;
				document.getElementById('re_contribuicao_pensao').value = document.getElementById('vl_pensao_contribuicao').value;
				document.getElementById('re_prazo_pensao').value = document.getElementById('nr_pensao_prazo').value;
				document.getElementById('re_renda_pensao').value = document.getElementById('vl_pensao_renda').value;
				document.getElementById('ob_resul_pensao').style.display = "";
			}
			else
			{
				document.getElementById('ob_resul_pensao').style.display = "none";
			}
			
			if(fl_exibe)
			{
				$('ob_formulario').toggleClass('ocultaObj');
				$('ob_resumo').toggleClass('ocultaObj');			

				document.getElementById('ob_renda_ano_beneficio').innerHTML = "";
				document.getElementById('ob_renda_ano_invalidez').innerHTML = "";
				document.getElementById('ob_renda_ano_pensao').innerHTML = "";		

				if($('ob_resumo').className != "ocultaObj")
				{
					gravaPreCadastro();
				}
			}
		}
	}
	
	function calcRendaAno()
	{
		document.getElementById('ob_renda_ano_beneficio').innerHTML = "";
		document.getElementById('ob_renda_ano_invalidez').innerHTML = "";
		document.getElementById('ob_renda_ano_pensao').innerHTML = "";
		calcRendaAnoBeneficio();
		
		if(getStatusInvalidez())
		{
			calcRendaAnoInvalidez();
		}
	
		if(getStatusPensao())
		{
			calcRendaAnoPensao();
		}	
	}
	
	function calcRendaAnoBeneficio()
	{
		var ds_url   = "sinprors_simulador_ajax.php";
		var lt_param = "ds_funcao=calcRendaAno";
			lt_param+= "&vl_saldo=" + document.getElementById('re_saldo').value;
			lt_param+= "&vl_renda=" + document.getElementById('re_renda').value;
			lt_param+= "&nr_prazo=" + document.getElementById('re_prazo').value;
			lt_param+= "&vl_rentabilidade=" + document.getElementById('vl_rentabilidade').value;
			
			ajaxExecute(ds_url, lt_param, "calcRendaAnoBeneficioRetorno", '', 'POST');			
	}
	
	function calcRendaAnoBeneficioRetorno(ds_retorno)
	{
		document.getElementById('ob_renda_ano_beneficio').innerHTML = ds_retorno;
	}
	
	function calcRendaAnoInvalidez()
	{
		var ds_url   = "sinprors_simulador_ajax.php";
		var lt_param = "ds_funcao=calcRendaAno";
			lt_param+= "&vl_saldo=" + document.getElementById('re_capital_invalidez').value;
			lt_param+= "&vl_renda=" + document.getElementById('re_renda_invalidez').value;
			lt_param+= "&nr_prazo=" + document.getElementById('re_prazo_invalidez').value;
			lt_param+= "&vl_rentabilidade=" + document.getElementById('vl_rentabilidade').value;

			ajaxExecute(ds_url, lt_param, "calcRendaAnoInvalidezRetorno", '', 'POST');			
	}
	
	function calcRendaAnoInvalidezRetorno(ds_retorno)
	{
		document.getElementById('ob_renda_ano_invalidez').innerHTML = ds_retorno;
	}
	
	function calcRendaAnoPensao()
	{
		var ds_url   = "sinprors_simulador_ajax.php";
		var lt_param = "ds_funcao=calcRendaAno";
			lt_param+= "&vl_saldo=" + document.getElementById('re_capital_pensao').value;
			lt_param+= "&vl_renda=" + document.getElementById('re_renda_pensao').value;
			lt_param+= "&nr_prazo=" + document.getElementById('re_prazo_pensao').value;
			lt_param+= "&vl_rentabilidade=" + document.getElementById('vl_rentabilidade').value;

			ajaxExecute(ds_url, lt_param, "calcRendaAnoPensaoRetorno", '', 'POST');			
	}	
	
	function calcRendaAnoPensaoRetorno(ds_retorno)
	{
		document.getElementById('ob_renda_ano_pensao').innerHTML = ds_retorno;
	}

	function trimStringCampo(str)
	{

	    while (str.charAt(0) == " ")
	    {
	        str = str.substr(1,str.length -1);
	    }

	    while (str.charAt(str.length-1) == " ")
	    {
	        str = str.substr(0,str.length-1);
	    }
	    str = str.replace(/\r|\n|\r\n/g,"");
	    return str;
	}
	
	function verificaTempoPlano()
	{
		var ds_url   = "sinprors_simulador_ajax.php";
		var lt_param = "ds_funcao=verificaTempoPlano";
			lt_param+= "&dt_nascimento=" + document.getElementById('dt_nascimento').value;
			lt_param+= "&qt_idade=" + document.getElementById('qt_idade').value;

			ajaxExecute(ds_url, lt_param, "verificaTempoPlanoRetorno", '', 'POST');		
	}
	
	function verificaTempoPlanoRetorno(ds_retorno)
	{
		if(ds_retorno < 5)
		{
			alert("Período de contribuição ao plano deve ser no mínimo de 5 anos completos.")
		}
		else
		{
			calculaPrazo();
		}
	}
	
	function gravaPreCadastro()
	{
		var ds_url   = "sinprors_simulador_ajax.php";
		var lt_param = "ds_funcao=gravaPreCadastro";
			lt_param+= "&ds_nome=" + document.getElementById('ds_nome').value;
			lt_param+= "&nr_telefone=" + document.getElementById('nr_telefone').value;
			lt_param+= "&ds_email=" + document.getElementById('ds_email').value;

			ajaxExecute(ds_url, lt_param, "gravaPreCadastroRetorno", '', 'POST');			
	}	
	
	function gravaPreCadastroRetorno(ds_retorno)
	{
		
	}	
	
	function validaData(DataString) 
	{
		var DataArray	= DataString.split("/");  
		var Flag=true; 

		if (DataArray.length != 3) 
			Flag=false; 
		else 
			{
				if (DataArray.length==3) 
				{
					var dia = DataArray[0], mes = DataArray[1], ano = DataArray[2]; 

					if (((Flag) && (ano<1000) || ano.length>4)) 
						Flag=false; 
					
					if (Flag) 
					{ 
						verifica_mes = new Date(mes+"/"+dia+"/"+ano); 
						if (verifica_mes.getMonth() != (mes - 1)) 
							Flag=false; 
					} 
				} 
				else 
					Flag=false; 
			} 
		return Flag;
	}
	
	function gerarPDF()
	{
		action_old = document.forms[0].action;
		document.fr_simula.action = 'sinprors_simulador_gerar_pdf.php';
		document.fr_simula.target = "_blank";
		document.fr_simula.submit();
		document.fr_simula.action = action_old;
	}