/*
function valida_campos_nova_senha(form)
{
  if (form.login.value == '')	
  {
	 alert('Digite o seu login');  
	 form.login.focus();
	 return(false);
  }
  if (form.data_nascimento.value == '')	
  {
	 alert('Digite a sua data de nascimento');  
	 form.data_nascimento.focus();
	 return(false);
  }
  return(true);
}
*/

function valida_grupo_tipo_rubrica(form, field)
{
   //TAXA ADMINISTRATIVA
   if (field.options[field.selectedIndex].value == 10)
   {
	   form.despesa.value = "TAXA ADMINISTRATIVA";
	   form.quantidade.value = "1";
	   form.unidade.value = "UNIDADE";
	   form.valor_unitario.value = "";
	   form.valor_total.value = "";
	   form.data_prevista.value = "";

       form.despesa.readonly = true;
	   form.quantidade.readonly = true;
	   form.unidade.readonly = true;
	   form.valor_unitario.readonly = true;
	   form.valor_total.readonly = true;
	   form.data_prevista.readonly = true;
   } 
   else
   {
       form.despesa.readonly = false;
	   form.quantidade.readonly = false;
	   form.unidade.readonly = false;
	   form.valor_unitario.readonly = false;
	   form.valor_total.readonly = false;
	   form.data_prevista.readonly = false;
   }
   return(true);
}

function valida_status_atividade(form)
{
   if (form.status.options[form.status.selectedIndex].value == 'CONCLUÍDA')
   {
	  if (form.observacoes.value == "")   
	  {
		alert('Preenchimento obrigatório.');  
	    form.observacoes.focus();
		return(false);
	  }
	  if (form.data_baixa.value == "")
	  {
		alert('Preenchimento obrigatório.');  
		form.data_baixa.focus();  
		return(false);
	  }
   }
   return(true);
}

function valida_valores_rubrica(field_valor_atual, field_valor_alterado)
{
  	if (field_valor_alterado.value == '')
	{
	   alert('O novo valor solicitado deve ser difertente de vazio.');	
	   field_valor_alterado.focus();
	   return(false);
	}
	else
	{
	  if (!isNaN(troca_virgula_ponto(tira_ponto(field_valor_alterado.value))))
	  {
		if (parseFloat(troca_virgula_ponto(field_valor_alterado.value)) > parseFloat(troca_virgula_ponto(tira_ponto(field_valor_atual.value))))
		{
		   alert('O novo valor solicitado é maior do que o valor disponível na rubrica atual.');	
		   field_valor_alterado.focus();
		   return(false);
		}
	  }
	  else
	  {
		 alert('Não é um valor válido!');  
		 return(false);
	  }
	}
	return(true);
}

function formata_dinheiro(number) {
    return formata_real(Math.floor(number-0) + '') + formata_centavo(number - 0);
}

function formata_real(number) {
    if (number.length <= 3)
        return (number == '' ? '0' : number);
    else {
        var mod = number.length%3;
        var output = (mod == 0 ? '' : (number.substring(0,mod)));
        for (i=0 ; i < Math.floor(number.length/3) ; i++) {
            if ((mod ==0) && (i ==0))
                output+= number.substring(mod+3*i,mod+3*i+3);
            else
//                output+= '.' + number.substring(mod+3*i,mod+3*i+3);
                output+= number.substring(mod+3*i,mod+3*i+3);
        }
        return (output);
    }
}

function formata_centavo(amount) {
    amount = Math.round( ( (amount) - Math.floor(amount) ) *100);
    return (amount < 10 ? ',0' + amount : ',' + amount);
}

function tira_ponto(str)
{
    var strret, newstr;
    strret = str.toString();
    newstr = strret.replace('.','');
	return(newstr);
}

function troca_ponto_virgula(str)
{
    var strret, newstr;
    strret = str.toString();
    newstr = strret.replace('.',',');
	return(newstr);
}

function troca_virgula_ponto(str)
{
    var newstr, strret;
    strret = str.toString();
    newstr = strret.replace(',','.');
	return(newstr);
}

function multiplica(campo1,campo2,dest)
{
	var1 = troca_virgula_ponto(tira_ponto(campo1.value));
	var2 = troca_virgula_ponto(tira_ponto(campo2.value));
	dest.value = formata_dinheiro(var1 * var2);
	return(true);
}

function alerta(mensagem)
{
  alert(mensagem);	
}

function confirma(texto,target)
{
	if (confirm(texto))
	{
	  window.open(target,"_self");
	  return(true);
	}
	else
	  return(false);
}

function verifica_selecao_projeto(form)
{
   if (form.projeto_id.value == 0)
   {
	  alert('Selecione primeiramente o projeto.');
	  return(false);
   }
   return(true);
}

function seleciona_projeto(form)
{
   form.submit();
//   document.getElementById(form).submit();
   return(false);
}

function recarrega_form(form)
{
   form.action = "";
   form.submit();
//   document.getElementById(form).submit();
   return(false);
}

function imprimir_projeto(form,pagina,target,width,height)
{
   if (form.projeto_id.value == 0)
   {
	  alert('Selecione primeiramente o projeto.');
	  return(false);
   }
   pagina = pagina+'?projeto_id='+form.projeto_id.options[form.projeto_id.selectedIndex].value;
   openWindow(pagina,target,width,height)
   return(true);
}

function valida_campos_iguais(campo1,campo2,nome1,nome2)
{
   if ((campo1.value != '') && (campo2.value != ''))
   {
	  if (campo1.value != campo2.value)
	  {
		alert('O campo '+nome1+' deve possuir valor igual a '+nome2);	
	    campo2.focus();
		return(false);
	  }
	  else
	    return(true);
   }
   else
     return(true);
}

function openWindow(pagina,target,width,height)
{
  var newWidth;
  var newHeight;
  var win;
  if ((width == 0) && (height == 0))
    win = window.open(pagina,target);	
  else
  {
    newWidth = (screen.availWidth-10 - width) / 2;
    newHeight = (screen.availHeight-20 - height) / 2;    
    win = window.open(pagina,target,"width="+width+",height="+height+",location=no,scrollbars=yes,menubars=no,directores=no,copyhistory=no,toolbars=no,resizable=yes,left=" + newWidth + ",top=" + newHeight);
    win.moveTo(newWidth, newHeight);
    win.focus();
  }
  return(true);
}

function ir(arquivo)
{
   if ((arquivo == 'principal.php') || (arquivo == '../principal.php') || (arquivo == '../../principal.php'))
     window.open(arquivo,"_parent");	
   else
     window.open(arquivo,"_self");	
}

function CPFFilter(field)
{
   if (!isCPFCNPJ(field.value,1))
   {
	 alert("Este CPF não é válido. Por favor redigite-o corretamente.");
	 field.focus();
	 return (false);
   }
   else
   {
	  FormataCPF(field);	
	  return (true);
   }
}

function CNPJFilter(field)
{
   if ((!isCPFCNPJ(field.value,2)) && (field.value != ''))
   {
	 alert("Este CNPJ não é válido. Por favor redigite-o corretamente.");
	 field.focus();
	 return (false);
   }
   else
   {
	  if (field.value != '') 
	     FormataCNPJ(field);	
	  return (true);
   }

}

function phoneFilter(form) {
	var input = form.value;
	if(input.length > 0) { //do not perform if empty input
		var numbers = ""; //store all the numbers here
		//process to remove non-numbers and spaces
		for(var i = 0; i < input.length; i++) {
			var char = input.charAt(i);
			if(!(isNaN(char) || char == " ")) numbers += char;
		}
		//remove country code, if any
//		if(numbers.substring(0, 2) == "47") numbers = numbers.substring(2, numbers.length);
		var output = ""; //assign numbers here
		//assign numbers to chosen format
		var n = 0, i = 0;
		if (numbers.length == 10)
		{
		  format = "(##)####-####";		
  		  while(i < format.length && n < numbers.length) {
			  var char = format.charAt(i);
			  if(char == "#") {
			  	  output += numbers.charAt(n++)
			  } else {
				  output += char;
			  }
			  i++;
		  }
		}
		if (numbers.length == 9)
		{
		  format = "(##)###-####";
  		  while(i < format.length && n < numbers.length) {
			  var char = format.charAt(i);
			  if(char == "#") {
			  	  output += numbers.charAt(n++)
			  } else {
				  output += char;
			  }
			  i++;
		  }
		}
		//give alert if length is less than 8.
		if ((numbers.length != 9) && (numbers.length != 10)) {
			alert("O seu número de telefone deve conter somente 9 ou 10 números (incluindo o DDD).");
			form.focus();
		}

		form.value = output; //output to form
	}
}

function cepFilter(form) 
{
	var input = form.value;
	if(input.length > 0) 
	{ //do not perform if empty input
		var numbers = ""; //store all the numbers here
		//process to remove non-numbers and spaces
		for(var i = 0; i < input.length; i++) 
		{
			var char = input.charAt(i);
			if(!(isNaN(char) || char == " ")) 
			   numbers += char;
		}
		//remove country code, if any
//		if(numbers.substring(0, 2) == "47") numbers = numbers.substring(2, numbers.length);
		var output = ""; //assign numbers here
		//assign numbers to chosen format
		var n = 0, i = 0;
		if (numbers.length == 8)
		{
		  format = "#####-###";		
  		  while(i < format.length && n < numbers.length) 
		  {
			  var char = format.charAt(i);
			  if(char == "#") 
			  	  output += numbers.charAt(n++)
			  else 
				  output += char;
			  i++;
		  }
		}
		//give alert if length is less than 8.
		if (numbers.length != 8) 
		{
			alert("O seu número de CEP não é válido. O Seu CEP deve conter somente números (8 dígitos).");
			form.focus();
		}

		form.value = output; //output to form
	}
}

//Validar CNPJ
function isEmpty(pStrText){ 
   var   len = pStrText.length; 
   var pos; 
   var vStrnewtext = ""; 

   for (pos=0; pos<len; pos++){ 
      if (pStrText.substring(pos, (pos+1)) != " "){ 
         vStrnewtext = vStrnewtext + pStrText.substring(pos, (pos+1)); 
      } 
   } 

   if (vStrnewtext.length > 0) 
      return false; 
   else 
      return true; 
}

function isCPFCNPJ(campo,pType){
   if( isEmpty( campo ) ){return false;}
   var campo_filtrado = "", valor_1 = " ", valor_2 = " ", ch = "";
   var valido = false;
        
   for (i = 0; i < campo.length; i++){
      ch = campo.substring(i, i + 1);
      if (ch >= "0" && ch <= "9"){
         campo_filtrado = campo_filtrado.toString() + ch.toString()
         valor_1 = valor_2;
         valor_2 = ch;
      }
      if ((valor_1 != " ") && (!valido)) valido = !(valor_1 == valor_2);
   }
   if (!valido) campo_filtrado = "12345678912";

   if (campo_filtrado.length < 11){
//      for (i = 1; i <= (11 - campo_filtrado.length); i++){campo_filtrado = "0" + campo_filtrado;}
//     alert("CPF deve possuir 11 dígitos numéricos");
	 return(false);
   }
	if(pType <= 1){
		if ( ( campo_filtrado.substring(9,11) == checkCPF( campo_filtrado.substring(0,9) ) ) && ( campo_filtrado.substring(11,12)=="") ){return true;}
	}

	if((pType == 2) || (pType == 0)){
		if (campo_filtrado.length >= 14){
			if ( campo_filtrado.substring(12,14) == checkCNPJ( campo_filtrado.substring(0,12) ) ){ return true;}
		}
	}
	
	return false;
}

function checkCNPJ(vCNPJ){
   var mControle = "";
   var aTabCNPJ = new Array(5,4,3,2,9,8,7,6,5,4,3,2);
   for (i = 1 ; i <= 2 ; i++){
      mSoma = 0;
      for (j = 0 ; j < vCNPJ.length ; j++)
         mSoma = mSoma + (vCNPJ.substring(j,j+1) * aTabCNPJ[j]);
      if (i == 2 ) mSoma = mSoma + ( 2 * mDigito );
      mDigito = ( mSoma * 10 ) % 11;
      if (mDigito == 10 ) mDigito = 0;
      mControle1 = mControle ;
      mControle = mDigito;
      aTabCNPJ = new Array(6,5,4,3,2,9,8,7,6,5,4,3);
   }
   return( (mControle1 * 10) + mControle );
}

function checkCPF(vCPF){
   var mControle = ""
   var mContIni = 2, mContFim = 10, mDigito = 0;
   for (j = 1 ; j <= 2 ; j++){
      mSoma = 0;
      for (i = mContIni ; i <= mContFim ; i++)
         mSoma = mSoma + (vCPF.substring((i-j-1),(i-j)) * (mContFim + 1 + j - i));
      if (j == 2 ) mSoma = mSoma + ( 2 * mDigito );
      mDigito = ( mSoma * 10 ) % 11;
      if (mDigito == 10) mDigito = 0;
      mControle1 = mControle;
      mControle = mDigito;
      mContIni = 3;
      mContFim = 11;
   }
   return( (mControle1 * 10) + mControle );
}

function FormataCNPJ(el) 
{ 
  vr = el.value; 
  tam = vr.length; 
  
  vr = vr.replace(".", "");
  vr = vr.replace(".", "");
  vr = vr.replace("/", "");
  vr = vr.replace("-", "");

  if ((vr.indexOf(".") == -1)  && (vr.indexOf("/") == -1)  && (vr.indexOf("-") == -1))
  { 
    if (tam == 14)
       el.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,4) + '-' + vr.substr(12,2); 
	else
	{
	   if (tam != 18)
	   {
	     alert('Tamanho inválido do CNPJ');
	     return(false);
	   }
	}
   } 
  return(el); 
}

function FormataCPF(el) 
{ 
  vr = el.value; 
  tam = vr.length; 
  
  vr = vr.replace(".", "");
  vr = vr.replace(".", "");
  vr = vr.replace("-", "");
  if ((vr.indexOf(".") == -1) && (vr.indexOf("-") == -1))
  { 
     if (tam == 11)
       el.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,3) + '-' + vr.substr(9,2); 
	 else
	 {
	   if (tam != 14)
	   {
	     alert('Tamanho inválido do CPF');
	     return(false);
	   }
	 }
   } 
  return(el); 
}

function entreDatas(form_data1, form_data2, form_meses)
{
   minuto = 60 * 1000;
   dia = minuto * 60 * 24;
   mes = dia * 30.4375;
	
   data_inicio = form_data1.value;
   data_final = form_data2.value;

   dia1 = data_inicio.substring(0,2); // dia da data inicio
   mes1 = data_inicio.substring(3,5); // mes da data inicio
   ano1 = data_inicio.substring(6,10); //ano da data inicio

   dia2 = data_final.substring(0,2); // dia da data inicio
   mes2 = data_final.substring(3,5); // mes da data inicio
   ano2 = data_final.substring(6,10); //ano da data inicio

   data1 = new Date(ano1, mes1-1, dia1);
   data2 = new Date(ano2, mes2-1, dia2);
   
   data1.setHours(0); 
   data1.setMinutes(0); 
   data1.setSeconds(0); 

   data2.setHours(0); 
   data2.setMinutes(0); 
   data2.setSeconds(0); 
   
   data_dif = Date.parse(data2) - Date.parse(data1);
   
   data_dif_meses = data_dif / mes;
   
//   alert(data_dif_meses);
  
   meses = Math.ceil(data_dif_meses);
//   alert(meses);
   form_meses.value = meses;
}

function custoPessoal(form)
{
	//bloco de cálculo de insalubridade
	if ((form1.insalubridade.checked) && (!isNaN(form1.salario_minimo.value)) && (form1.salario_minimo.value > 0))
	{
	   form.insalubridade_valor.value = (form1.salario_minimo.value * 0.2);
	   form.insalubridade_valor.value = formata_dinheiro(form.insalubridade_valor.value);
    }
	else
    {
	   form.insalubridade_valor.value = '0,00';		
	}	
	//bloco de cálculo de base1
	if ((!isNaN(troca_virgula_ponto(tira_ponto(form1.salario_mensal_base.value)))) && (!isNaN(form1.salario_minimo.value)))
	{
	   form.base_calculo1.value = parseFloat(troca_virgula_ponto(form1.salario_mensal_base.value)) + parseFloat(troca_virgula_ponto(form1.insalubridade_valor.value));
	   form.base_calculo1.value = formata_dinheiro(form.base_calculo1.value);		
	}
	//bloco 13 salário
	if (!isNaN(troca_virgula_ponto(form1.base_calculo1.value)))
	{
	   form.f13_salario.value = parseFloat(troca_virgula_ponto(form1.base_calculo1.value)) * 0.0833;
	   form.f13_salario.value = formata_dinheiro(form.f13_salario.value);
	}	
	//bloco férias mais 1/3
	if (!isNaN(troca_virgula_ponto(form1.base_calculo1.value)))
	{
	   form.ferias_mais_1terco.value = parseFloat(troca_virgula_ponto(form1.base_calculo1.value)) * 0.1111;
	   form.ferias_mais_1terco.value = formata_dinheiro(form.ferias_mais_1terco.value);			
	}
	//bloco de cálculo de base2
	if ((!isNaN(troca_virgula_ponto(tira_ponto(form1.salario_mensal_base.value)))) && (!isNaN(troca_virgula_ponto(tira_ponto(form1.insalubridade_valor.value)))) && (!isNaN(troca_virgula_ponto(tira_ponto(form1.f13_salario.value)))) && (!isNaN(troca_virgula_ponto(tira_ponto(form1.ferias_mais_1terco.value)))))
	{
	   form.base_calculo2.value = parseFloat(troca_virgula_ponto(form1.salario_mensal_base.value)) + parseFloat(troca_virgula_ponto(form1.insalubridade_valor.value)) + parseFloat(troca_virgula_ponto(form1.f13_salario.value)) + parseFloat(troca_virgula_ponto(form1.ferias_mais_1terco.value));
	   form.base_calculo2.value = formata_dinheiro(form.base_calculo2.value);		
	}	
	//bloco de cálculo de FGTS
	if (!isNaN(troca_virgula_ponto(form1.base_calculo2.value)))
	{
	   form.fgts.value = troca_virgula_ponto(form1.base_calculo2.value) * 0.08;
	   form.fgts.value = formata_dinheiro(form.fgts.value);		
	}
	//bloco de cálculo de multa rescisória
	if (!isNaN(troca_virgula_ponto(form1.fgts.value)))
	{
	   form.multa_rescisoria.value = troca_virgula_ponto(form1.fgts.value) * 0.4;
	   form.multa_rescisoria.value = formata_dinheiro(form.multa_rescisoria.value);		
	}
	//bloco de cálculo de multa PIS
	if (!isNaN(troca_virgula_ponto(form1.base_calculo2.value)))
	{
	   form.pis.value = troca_virgula_ponto(form1.base_calculo2.value) * 0.01;
	   form.pis.value = formata_dinheiro(form.pis.value);		
	}
	//bloco de cálculo de INSS
	if (!isNaN(troca_virgula_ponto(form1.base_calculo2.value)))
	{
	   form.inss.value = troca_virgula_ponto(form.base_calculo2.value) * 0.265;
	   form.inss.value = formata_dinheiro(form.inss.value);		
	}
	//bloco de cálculo de total mensal funcionário
	if ((!isNaN(troca_virgula_ponto(form1.base_calculo2.value))) && (!isNaN(troca_virgula_ponto(form1.fgts.value))) && (!isNaN(troca_virgula_ponto(form1.multa_rescisoria.value))) && (!isNaN(troca_virgula_ponto(form1.pis.value))) && (!isNaN(troca_virgula_ponto(form1.inss.value))) && (!isNaN(troca_virgula_ponto(form1.vale_transporte_valor.value))))
	{
	   form.total_mensal.value = parseFloat(troca_virgula_ponto(form1.base_calculo2.value)) + parseFloat(troca_virgula_ponto(form1.fgts.value)) + parseFloat(troca_virgula_ponto(form1.multa_rescisoria.value)) + parseFloat(troca_virgula_ponto(form1.pis.value)) + parseFloat(troca_virgula_ponto(form1.inss.value)) + parseFloat(troca_virgula_ponto(form1.vale_transporte_valor.value));
	   form.total_mensal.value = formata_dinheiro(form.total_mensal.value);
	}
	//bloco de cálculo de total de funcionário pelo período contratado
	if (!isNaN(troca_virgula_ponto(form1.total_mensal.value)))
	{
	   form.total_periodo.value = parseFloat(troca_virgula_ponto(form1.total_mensal.value)) * form1.meses.value;
	   form.total_periodo.value = formata_dinheiro(form.total_periodo.value);		
	}	
}

function custoBolsista(form)
{
//   form.valor_bolsa.value = formata_dinheiro(form.valor_bolsa.value);
   //bloco de cálculo de taxas e somatórias
    if (form.tipo.options[form.tipo.selectedIndex].value == 'SELECIONE')
	{
	  form.valor_taxa_instituicao.value = '0,00';
	  form.total_mensal.value = '0,00';
	  form.instituicao_bolsa.value = '0,00';
      form.instituicao_bolsa.disabled = true;  
    }
    if (form.tipo.options[form.tipo.selectedIndex].value == 'ESTAGIÁRIO')
	{
	   form.instituicao_bolsa.disabled = false;
       if (form.instituicao_bolsa.options[form.instituicao_bolsa.selectedIndex].value == 'IEL')
	   {
		 form.valor_taxa_instituicao.value = formata_dinheiro(parseFloat(troca_virgula_ponto(form.valor_bolsa.value)) * 0.09);
		 form.total_mensal.value = formata_dinheiro(parseFloat(troca_virgula_ponto(form.valor_taxa_instituicao.value)) + parseFloat(troca_virgula_ponto(form.valor_bolsa.value)));
	   }
       if (form.instituicao_bolsa.options[form.instituicao_bolsa.selectedIndex].value == 'CIEE')
	   {
		 if (!isNaN(troca_virgula_ponto(form.valor_bolsa.value)))
		 {
		   if (parseFloat(form.valor_bolsa.value) <= 450)
		   {
		     form.valor_taxa_instituicao.value = formata_dinheiro(45);
		   }
		   else
		   {
		     form.valor_taxa_instituicao.value = formata_dinheiro(parseFloat(troca_virgula_ponto(form.valor_bolsa.value)) * 0.1);  
		   }
	       form.total_mensal.value = formata_dinheiro(parseFloat(troca_virgula_ponto(form.valor_taxa_instituicao.value)) + parseFloat(troca_virgula_ponto(form.valor_bolsa.value)));
		 }
	   }
	}
    if (form.tipo.options[form.tipo.selectedIndex].value == 'BOLSISTA')
	{
	   form.instituicao_bolsa.disabled = true;
 	   form.valor_taxa_instituicao.value = '0,00';
	   form.total_mensal.value = formata_dinheiro(troca_virgula_ponto(form.valor_bolsa.value));
	}
   //bloco de cálculo de somatório de bolsa no período
	if (!isNaN(troca_virgula_ponto(form1.total_mensal.value)))
	{
   	   form.total_periodo.value = formata_dinheiro(parseFloat(troca_virgula_ponto(form.total_mensal.value)) * form.meses.value);
	}
}

function calculaTotal(form)
{
	//bloco de cálculo de valor total
	if ((!isNaN(troca_virgula_ponto(form1.valor_unitario.value))) && (!isNaN(troca_virgula_ponto(form1.quantidade.value))))
	{
   	   form.total.value = formata_dinheiro(parseFloat(troca_virgula_ponto(form.valor_unitario.value)) * parseFloat(troca_virgula_ponto(form.quantidade.value)));
	}
}

function calculaViagemTotal(form)
{
	//Diárias
	if ((!isNaN(troca_virgula_ponto(form1.numero_diarias.value))) && (!isNaN(troca_virgula_ponto(form1.valor_diaria.value))))
	{
   	   form.total.value = formata_dinheiro(parseFloat(troca_virgula_ponto(form.numero_diarias.value)) * parseFloat(troca_virgula_ponto(form.valor_diaria.value)));
	}	
	//KM
	if ((!isNaN(troca_virgula_ponto(form1.veiculo_proprio_valor.value))) && (!isNaN(troca_virgula_ponto(form1.veiculo_instituicao_valor.value))) && (!isNaN(troca_virgula_ponto(form1.passagem_onibus_valor.value))) && (!isNaN(troca_virgula_ponto(form1.passagem_aerea_valor.value))))
	{
   	   form.total_previsto.value = formata_dinheiro(parseFloat(troca_virgula_ponto(form.total.value)) + parseFloat(troca_virgula_ponto(form.veiculo_proprio_valor.value)) + parseFloat(troca_virgula_ponto(form.veiculo_instituicao_valor.value)) + parseFloat(troca_virgula_ponto(form.passagem_onibus_valor.value)) + parseFloat(troca_virgula_ponto(form.passagem_aerea_valor.value)));
	}	
}

function calculaRessarcimentoTotal(form, quant)
{
  var total = 0;
  for (i = 0; i < quant; i++)
  {
	if (document.getElementById('item_valor'+i).value != '')
	{
 	  if (!isNaN(troca_virgula_ponto(document.getElementById('item_valor'+i).value)))
	  {
	     total = total + parseFloat(troca_virgula_ponto(document.getElementById('item_valor'+i).value));
	  }		
	}
  }
  form.total.value = formata_dinheiro(parseFloat(total));
}

function adicionarItensDespesa(form)
{
	form.action = "";
	form.submit();
}

function calculaMOPrestacaoContasTotal(form, quant)
{
  var valor;
  var total = 0;
  for (i = 0; i < quant; i++)
  {
	if (document.getElementById('item_valor'+i).value != '')
	{
 	  if (!isNaN(troca_virgula_ponto(document.getElementById('item_valor'+i).value)))
	  {
	     total = total + parseFloat(troca_virgula_ponto(document.getElementById('item_valor'+i).value));
	  }		
	}
  }
   form.total.value = formata_dinheiro(parseFloat(total));
   valor = parseFloat(troca_virgula_ponto(form.valor_adiantado.value)) - parseFloat(troca_virgula_ponto(form.total.value));
   if (valor < 0)
   {
     form.devolucao.value = formata_dinheiro(0);
     form.complementar.value = formata_dinheiro(valor);
   }
   if (valor > 0)
   {
     form.devolucao.value = formata_dinheiro(valor);
     form.complementar.value = formata_dinheiro(0);
   }
   if (valor == 0)
   {
     form.devolucao.value = formata_dinheiro(0);
     form.complementar.value = formata_dinheiro(0);
   }
}

function removeItemFormulario(tab, elem)
{
   var tabela = document.getElementById(tab);
   try 
   { 
//	  var linha = document.getElementById(row);
      var lastRow = tabela.rows.length;
	  elemento = document.getElementById(elem);
	  pos  = elemento.rowIndex;
//	  alert(pos+' - '+lastRow);
      if (lastRow > 1)
	  {
		 tabela.deleteRow(pos);
		 document.getElementById('numero_itens').value = tabela.rows.length;
	  }
	  else
		 alert('Este último registro não pde ser apagado!');
   } 
   catch (ex) 
   { 
      alert(ex); 
   } 
}

function removeRegistroStatus(pagina)
{
  if (confirm('Deseja realmente apagar este registro, a informação não poderá ser recuperada!'))   
  {
     window.open(pagina,'_self');
     return(true);
  }
  else
    return(false);
}