function CalcAposentado(obj){
	var valorRet = RetNumero(obj.value)
	if (valorRet > 12696.00)
		valorRet = 12696.00
		obj.value = FormataNumero(valorRet.toString());
}
function calculoDependentes(valor,objRetorno){
		var valorRet = 0; 
		if (valor > 0)
			valorRet = RetNumero(valor) * 1272.00;
		else
			valorRet = 0;
		var vl = Math.round(valorRet * 100) / 100;
		objRetorno.innerText = FormataNumero(vl.toString());
	}
function despesaInstrucao(valor,objRetorno,qtdPessoas, dependentes)	{
		var valorRet = 0; 
		var valor = 0;
		if (RetNumero(objRetorno.value) > 0){
			valor = RetNumero(objRetorno.value);
		}else{
			valor = 0;
		}				
				if(dependentes > 0){
					qtdPessoas.disabled = false;
				}else{
					qtdPessoas.value = '';
					qtdPessoas.disabled = true;
				}
				if(dependentes > 0){
					if(RetNumero(qtdPessoas.value) > 0){
						if(RetNumero(qtdPessoas.value) < RetNumero(dependentes)){
							valorRet = RetNumero(qtdPessoas.value) * 1998.00;
						}else{
							valorRet = RetNumero(dependentes) * 1998.00;
							qtdPessoas.value = dependentes;
						}
					}else{
						if (valor > 0){}
							//objRetorno.value = FormataNumero(valor.toString());
						else{}
							//objRetorno.value = valor;
					}
				}
	}
function PrevidenciaPrivada(objRetorno,valorRendimentos,valorPrevidencia){
		var valorRet = parseFloat(12 / 100) * RetNumero(valorRendimentos);
		var vl;
		if (RetNumero(valorPrevidencia) > valorRet){
			vl = Math.round(valorRet * 100) / 100;
 
			objRetorno.innerText = FormataNumero(vl.toString());
		}
		else{
			objRetorno.innerText = valorPrevidencia;
		}
	}
function baseCalculo(valorRendimentos,valorDeducoes,objRetorno,objImpostoDevido,objPosDeducao){
		var valor = RetNumero(valorRendimentos) - RetNumero(valorDeducoes);
		if (valor < 0){
			objRetorno.innerText = '0,00' ;
		}
		else{
			valor = Math.round(valor * 100) / 100;
			objRetorno.innerText = FormataNumero(valor.toString());
			if (RetNumero(objRetorno.innerText) < 12696.01){		
				objImpostoDevido.innerText = '0,00';
			}
			else{
				if (RetNumero(objRetorno.innerText) < 25380.01){
					valor = (RetNumero(objRetorno.innerText) * 0.15) - 1904.40;
				}
				else{
					valor = (RetNumero(objRetorno.innerText) * 0.275) - 5076.90;
				}
				valor = Math.round(valor * 100) / 100;
				objImpostoDevido.innerText = FormataNumero(valor.toString());
			}
		}
	}
function calculaDeducoes(objRetorno,valorRendimento, valorDepedentes,valorInss,valorDespesas,valorPensao,valorPrevidencia,valorAposentado,valorInstrucao, valorInstrucaoDecla, pessoas){
		var valor=0; 
		var instrucao=0;
		var aposentado=0;
		var intrucaoDeclarante = 0;
		if (RetNumero(valorInstrucaoDecla) > 1998.00){
			intrucaoDeclarante = 1998.00;
		}	
		else
			intrucaoDeclarante = RetNumero(valorInstrucaoDecla);
		
		if (RetNumero(pessoas) < 1 && RetNumero(document.all.lblDespesaInstrucao.value)>1998.00 )
			instrucao = 1998.00;
		else{
			if (RetNumero(document.all.lblDespesaInstrucao.value) > RetNumero(pessoas) * 1998.00)
				instrucao = RetNumero(pessoas) * 1998.00
				else
				instrucao = RetNumero(document.all.lblDespesaInstrucao.value)
		}
		if (RetNumero(valorAposentado) > 12696.00)
			aposentado = 12696.00;
		else
			aposentado = RetNumero(valorAposentado)
		
		if ((RetNumero(valorPrevidencia) <= RetNumero(valorRendimento) * 0.12)){
			valor = RetNumero(valorDepedentes) + RetNumero(valorInss) + RetNumero(valorDespesas) + instrucao + RetNumero(valorPensao) + RetNumero(valorPrevidencia) + aposentado + intrucaoDeclarante;			
			valor = Math.round(valor * 100) / 100;
		}else{
			valor = RetNumero(valorDepedentes) + RetNumero(valorInss) + RetNumero(valorDespesas) + instrucao + RetNumero(valorPensao) + (RetNumero(valorRendimento) * 0.12) + aposentado + intrucaoDeclarante;			
			valor = Math.round(valor * 100) / 100;
		}		
		objRetorno.innerText = FormataNumero(valor.toString());
	}
function Limite(objRetorno,valorImpostoDevido,objPosDeducao, objIr){
		var valor = parseFloat(6 / 100) * RetNumero(valorImpostoDevido);
		if (valor > 0)
		{
			valor = Math.round(valor * 100) / 100;
 
			objRetorno.innerText = FormataNumero(valor.toString());
			objPosDeducao.innerText = FormataNumero((RetNumero(valorImpostoDevido) - valor).toString());
			objIr.innerText = FormataNumero(valor.toString());
		}
		else{
			objRetorno.innerText= '0,00';
			objIr.innerText = '0,00';
		}
	}
function ImpostoRendaRetido(valor,valorPosDeducao,objRetorno){
	var valorRet = RetNumero(valor) - RetNumero(valorPosDeducao);
	var result;
	
	VerificaTipoImposto(valor, valorPosDeducao);
	
	if (valorRet != 0)
	{
		valorRet  = Math.abs(valorRet * 100) / 100;
		objRetorno.innerText = FormataNumero(valorRet.toString());
	} 
	else
	{
		objRetorno.innerText = '0,00';		
	}
}
function VerificaTipoImposto(ImpostoRetido, ImpostoRenda){
	if (RetNumero(ImpostoRetido) >= RetNumero(ImpostoRenda))
		lblimpostoPR.innerText = "Imposto a restituir";
	else
		lblimpostoPR.innerText = "Imposto a pagar";
}
function CalculoPj(Lucro, objRetorno){
	var percent = '0.15025';
	var valor3=0;
	
	if(RetNumero(Lucro) > 0){
		valor = RetNumero(Lucro) * parseFloat(percent);
		valor2 = valor * 100;
		valor3 = Math.round(valor2) / 100;
	}else{		
		objRetorno.innerText = 0;
	}	
	objRetorno.innerText = FormataNumero(valor3.toString());
}
function LimiteDeducao(Valor, objRetorno){
	var ivalor, ivalor2;
	ivalor = RetNumero(Valor) * RetNumero('1/100');
	ivalor2 = Math.round(ivalor)/100;
	objRetorno.innerText = FormataNumero(ivalor2.toString());
}
function FormataNumero(pValor){
	  var i;
	  var j;
	  var iDecimal;
	  var iInteiro;
	  var iNovoValor;
 
	  iInteiro = pValor;
	  iDecimal = '00';
 
	  i = 0;
	  for (i = 0; i < pValor.length; i++)
	  {
	    if (pValor.charAt(i) == ".")
	    {
	      iInteiro = pValor.substring(0,i);
	      iDecimal = pValor.substring(i + 1,pValor.length);
	    }
	  }
 
	  if (iDecimal.length == 1)
	  {
	    iDecimal = iDecimal + "0";
	  }else{
		if (iDecimal.length > 0)
			iDecimal = iDecimal.substring(0,2);
	  }
 
	  iNovoValor = '';
	  j = 0;
	  for (i = iInteiro.length; i > 0; i--){
	    j = j + 1;
	    if (j == 4){
	      iNovoValor = iInteiro.substring(i,i-1) + '.' + iNovoValor;
	      j = 1;
	    }
	    else{
	      iNovoValor = iInteiro.substring(i,i-1) + iNovoValor;
	    }
	  }
	  iNovoValor = iNovoValor + "," + iDecimal;
	  return (iNovoValor);
	}
function RetNumero(str){
		var PosicaoVirgula = 0;
		var PosicaoPonto = 0;
		var TamanhoString = 0;
		var NumeroFormatado = 0;
		if (str == null)
			return 0;
		TamanhoString = str.length;
		if (TamanhoString == 1)
			return parseFloat(str);
		else{
			if (TamanhoString == null)
				return 0;
			}
		while (str.indexOf(".") > -1){
			str = str.replace(".","");
		}
 
		while (PosicaoVirgula != -1){
		    PosicaoVirgula = str.indexOf(",");
		    str = str.substring(0,PosicaoVirgula) + "." + str.substring(PosicaoVirgula + 1, str.length);
		}
		PosicaoPonto = str.indexOf(".");
		if (PosicaoPonto != -1)
		        str= str.substring(0,PosicaoPonto) + str.substring(PosicaoPonto + 1, str.length);
		TamanhoString = str.length;
		if (TamanhoString > 3){
		   NumeroFormatado = str;
		}
		else{
		   NumeroFormatado = Math.round(str);
		}
		return(parseFloat(NumeroFormatado));
	}
function MontaDecimal(valor){	
	var retorno, tamanho;
	tamanho = valor.length;
	if(tamanho > 3){		 
		retorno = valor.substring(0, tamanho - 2) + "." + valor.substring(tamanho - 2, tamanho);
	}else
		retorno = valor + ".00";
	return (retorno)
}
function AutoFormata(campo){
		var PosicaoVirgula = campo.value.indexOf(',');
		if (PosicaoVirgula == -1){
			campo.value = campo.value + ',00';
		}
		else if (campo.value.charAt(campo.value.length - 2) == ',')	{
			campo.value = campo.value + '0';
		}
		else if ((campo.value.length - 3) > PosicaoVirgula){
			campo.value = campo.value.substring(0, PosicaoVirgula + 3);
		}
		else if (campo.value.substring(0, 1) == ','){
			campo.value = '0' + campo.value;
		}
		
		if (RetNumero(campo.value) == 0){
			campo.value = '0';
		}
		campo.value = FormataNumero(RetNumero(campo.value).toString());
	}
function Zerar(campo){
		if (campo.value == ''){
			campo.value = '0';
		}
	}
function ValidaTecla(campo, blnDecimal){
		var Tecla = event.keyCode;
		if (!(Tecla >= 96 && Tecla <= 105) && !(Tecla >= 48 && Tecla <= 57) && Tecla != 8 && Tecla != 9 && Tecla != 35 && Tecla != 36 && Tecla != 37 && Tecla != 39 && Tecla != 45 && Tecla != 46 && Tecla != 110){
			if ((blnDecimal && Tecla != 188) || (!blnDecimal) || ((campo.value.indexOf(',') != -1))){
				event.returnValue = 0;
				return;
			}
		}
	}
function VerificaValorDoacao(obj, pessoa){
	if(RetNumero(obj.value) > 12500.00){
		alert('O limite diário de transações no Real Internet Banking(pessoas) é de  R$ 8.000,00. No Real Internet Empresa \n (empresas), o limite é de 12.500,00. Caso você queira doar acima desses valores, basta visitar novamente \n este site em 24 horas após sua última doação.');
		obj.value = "";
		obj.focus();
		return false;
	}
	else{
		if(RetNumero(obj.value) > 8000.00){
			alert('O limite diário de transações no Real Internet Banking(pessoas) é de  R$ 8.000,00. No Real Internet Empresa \n (empresas), o limite é de 12.500,00. Caso você queira doar acima desses valores, basta visitar novamente \n este site em 24 horas após sua última doação.');
			pessoa.value='J';
		}
		else
			pessoa.value='F';
			return true;
	}
}
function VerificaPessoa(valor, pessoa){
	if (RetNumero(valor.value) > 0){	
		if (RetNumero(valor.value) > 8000){
			if (pessoa.checked == false){				
				return true;
			}else{
				alert('Valor não coincide com tipo de pessoa');				
				return false;
			}
		}else
			return false;		
	}		
}
function  validaPrioridade(obj){
	var elm = document.getElementsByTagName("SELECT");
	for(i=0;i<elm.length;i++){
		if (elm[i].name != obj.name){
				if(elm[i].selectedIndex == obj.selectedIndex){
					alert('Prioridade já selecionada!');
					obj.focus();
					obj.selectedIndex = 0;
					return false;
				}
			}
	}
	return true;
}
function VerificarDadosObrigatorio(){
    var vFindErro ='';
		if (document.forms[0].Prioridade5 != null)
		        if (document.forms[0].Prioridade5.selectedIndex == 0){vFindErro ='Prioridade';}
		if (document.forms[0].Prioridade4 != null)
				if (document.forms[0].Prioridade4.selectedIndex == 0){vFindErro ='Prioridade';}
		if (document.forms[0].Prioridade3 != null)
		        if (document.forms[0].Prioridade3.selectedIndex == 0){vFindErro ='Prioridade';}
		if (document.forms[0].Prioridade2 != null)
		        if (document.forms[0].Prioridade2.selectedIndex == 0){vFindErro ='Prioridade';}
		if (document.forms[0].Prioridade1 != null)
		        if (document.forms[0].Prioridade1.selectedIndex == 0){vFindErro ='Prioridade';}
		if (document.forms[0].Prioridade0 != null)
		        if (document.forms[0].Prioridade0.selectedIndex == 0){vFindErro ='Prioridade';}
        if (document.forms[0].txtValorDoacao.value == ''){vFindErro ='Valor';}
        if (vFindErro !=''){
			alert('O Campo '  + vFindErro + ' é de preenchimento obrigatório!');
			return false;
		}
		else{ 
			return true;
		}
}
