function salvarecrutado(selecionado,i) {
	var recrutado,recrutados01,cpf;		
	if(selecionado[0].checked) { 
		recrutado = "recrutados"+i.toString();
        //a mensagem de erro da data ja é enviada no if
        if(document.getElementById(recrutado).value=="" || document.getElementById("data_fechamento").value=="" || verifica_data("data_fechamento", 1) == false) {
			if(document.getElementById(recrutado).value=="") {
				alert('Selecione o candidato aprovado!');
				document.getElementById(recrutado).focus();   
			}
			else {
				if(document.getElementById("data_fechamento").value=="") {
					alert('Preencha a data de fechamento da vaga!');
					document.getElementById("data_fechamento").focus();   
				}				
			}	     	
        }
        else {
			document.forms['finalizaVagaParcial'].origem_curriculo.value = "0";
			document.forms['finalizaVagaParcial'].id_vaga_curriculo.value = document.getElementById(recrutado).value;
			document.forms['finalizaVagaParcial'].data_fechamento_parcial.value = document.getElementById("data_fechamento").value;     			
			document.forms['finalizaVagaParcial'].submit();
        }

	}
	else {
        recrutados01 = "recrutados01"+i.toString();
		cpf = "cpf"+i.toString();
        if(document.getElementById(recrutados01).value=="" || 
           document.getElementById(cpf).value=="" || 
           document.getElementById("data_fechamento").value=="" ||
           verifica_data("data_fechamento", 1) == false) {
			if(document.getElementById(recrutados01).value=="") {
				alert('Preencha o nome do aprovado!');
				document.getElementById(recrutados01).focus();        	
			}
			else {
				if(document.getElementById(cpf).value=="") {
					alert('Preencha o cpf do aprovado!');
					document.getElementById(cpf).focus();        	
				}
				else {
					if(document.getElementById("data_fechamento").value=="") {
						alert('Preencha a data de fechamento da vaga!!');
						document.getElementById("data_fechamento").focus();        	
					}
				}				
			}
        }
        else {
			document.forms['finalizaVagaParcial'].origem_curriculo.value = "1";		
			document.forms['finalizaVagaParcial'].nome_parcial.value = document.getElementById(recrutados01).value;				
			document.forms['finalizaVagaParcial'].cpf_parcial.value = document.getElementById(cpf).value;     
			document.forms['finalizaVagaParcial'].data_fechamento_parcial.value = document.getElementById("data_fechamento").value;     
			document.forms['finalizaVagaParcial'].submit();   	
        }
	}
	
}
function calcvalor() {
   if(document.getElementById('qde').value!=""&&document.getElementById('valor').value!="") {
			var valor = document.getElementById('valor').value;
			valor = valor.replace(",",".");
			var qde = document.getElementById('qde').value;
		    var valor_final  = parseFloat(valor * qde) ;
		    valor_final = valor_final.toString().replace(".",",");
        	var j = 0; var x = 0;
            if(valor_final.length) {
				for(i=0;i<valor_final.length;i++){   
			        if(valor_final.charAt(i) == ",") {
                       j++;
			        }
			        // se j igual a 1 tem casas decimais. se x==1 tem uma casa e se x==2 tem duas casa
			        if(j==1) {
			        	x++;
			        }
				}  
				if(j==0) {
					valor_final = valor_final + ",00";
				}
				if(x==2) {
					valor_final = valor_final + "0";
				}
				
            }
           else {
            	valor_final = valor_final + ",00"; 
           }
		   document.getElementById('valor_total').value = valor_final;
   }         
} 
function roundNumber (rnum) {

   return Math.round(rnum*Math.pow(10,2))/Math.pow(10,2);

}
function ckeck(formName,fieldName) { 
	//formName é o formulario de origem 
	//fieldName é o nome do campo.. igual nos dois formularios
	//formdest é o nome do formulario de destino
	//Verifica se o checkbox foi selecionado
	if(document.forms[formName][fieldName].checked) {
	    //caso seja selecinado, o formDest receberá o valor
		document.forms[formName][fieldName].value   =  'selecionado';
	}
	else {
		//caso seja desmarcado, seu valor será limpo
		document.forms[formName][fieldName].value   =  '';
	}	
}

function checarCkeckebox(formName,fieldName) { 
		document.forms[formName][fieldName].checked = true;
}
function limparRadio(formName,fieldName1,fieldName2) { 
	//formName -> formulario
	//fieldName1 -> Checkbox que esta sendo clicado 
	//fieldName2 -> radio que será "limpados"
	if(document.forms[formName][fieldName1].checked)	{
		//document.forms[formName][fieldName2][0].checked = true;
	}
	else {
		//se o pai nao estiver checkado, desmarca os filhos
		for(i = 0; i < document.forms[formName][fieldName2].length; i++) {
			document.forms[formName][fieldName2][i].checked = false;
		}	
	}	
}


function abre_janela(url,janela,larg,alt,scroll){
      if (!scroll) { scroll='auto' }
      window.open(url,janela,"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars="+scroll+",resizable=yes,copyhistory=no,width="+larg+",height="+alt);
}

function msgLogin() {  
	alert("Usuário e senha não conferem");
	return;
}
//formatar valor monetario
function formatCurrency(o, n, dig, dec){
    o.c = !isNaN(n) ? Math.abs(n) : 2;
    o.dec = typeof dec != "string" ? "," : dec, o.dig = typeof dig != "string" ? "." : dig;
    addEvent(o, "keypress", function(e){
        if(e.key > 47 && e.key < 58){
            var o, s, l = (s = ((o = this).value.replace(/^0+/g, "") + String.fromCharCode(e.key)).replace(/\D/g, "")).length, n;
            if(o.maxLength + 1 && l >= o.maxLength) return false;
            l <= (n = o.c) && (s = new Array(n - l + 2).join("0") + s);
            for(var i = (l = (s = s.split("")).length) - n; (i -= 3) > 0; s[i - 1] += o.dig);
            n && n < l && (s[l - ++n] += o.dec);
            o.value = s.join("");
        }
        e.key > 30 && e.preventDefault();
    });
}	

/*
**************************************
* Event Listener Function v1.4       *
* Autor: Carlos R. L. Rodrigues      *
**************************************
*/
addEvent = function(o, e, f, s){
    var r = o[r = "_" + (e = "on" + e)] = o[r] || (o[e] ? [[o[e], o]] : []), a, c, d;
    r[r.length] = [f, s || o], o[e] = function(e){
        try{
            (e = e || event).preventDefault || (e.preventDefault = function(){e.returnValue = false;});
            e.stopPropagation || (e.stopPropagation = function(){e.cancelBubble = true;});
            e.target || (e.target = e.srcElement || null);
            e.key = (e.which + 1 || e.keyCode + 1) - 1 || 0;
        }catch(f){}
        for(d = 1, f = r.length; f; r[--f] && (a = r[f][0], o = r[f][1], a.call ? c = a.call(o, e) : (o._ = a, c = o._(e), o._ = null), d &= c !== false));
        return e = null, !!d;
    }
};

removeEvent = function(o, e, f, s){
    for(var i = (e = o["_on" + e] || []).length; i;)
        if(e[--i] && e[i][0] == f && (s || o) == e[i][1])
            return delete e[i];
    return false;
};

function limpaCombo(oList){
    for (var i = oList.options.length - 1; i >= 0; i--){
        oList.options[i] = null;
    }
    oList.selectedIndex = -1;
}  

function habilitaCampos(privilegio,unidade) {
   if(privilegio.value=='1') {
      if(unidade.length) {
		  for (i = 0; i < unidade.length; i++) {
			unidade[i].disabled = true;   
		  }
      }  
      else 
         unidade.disabled = true;
   }      	  
   else {
      if(unidade.length) {
	      for (i = 0; i < unidade.length; i++) {
	         unidade[i].disabled = false;
	      }
      }
      else
         unidade.disabled = false;      	    
   }     
}
function habilitaComissaoSalario(campo) {
   if(campo.disabled) {
      campo.disabled = false;
   }      
   else {
      campo.disabled = true;   
   }
}
function habilitaFuncSubstituido(tipovaga,func_substituido) {
   if(tipovaga.value=="2") {
      document.getElementById('func_substituido').disabled = false;
   }      
   else {
     document.getElementById('func_substituido').disabled = true; 
   }
}
function habilitaSelecionado(campo,id) {
   if(campo.value=='01') {
   	document.getElementById('recrutados'+id).disabled = false;
   	document.getElementById('recrutados01'+id).disabled = true;
   	document.getElementById('cpf'+id).disabled = true;
   }
   else {
   	document.getElementById('recrutados'+id).disabled = true;
   	document.getElementById('recrutados01'+id).disabled = false;
   	document.getElementById('cpf'+id).disabled = false;   	
   }
}