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 habilita_envio_curriculo(formName,fieldName1,fieldName2) { 
	//formName é o formulario de origem 
	//fieldName é o nome do campo
	if(document.forms[formName][fieldName1].checked) {
 		document.forms[formName][fieldName2].disabled = false;
	}
	else {
 		document.forms[formName][fieldName2].disabled = true;
	}	
}

function habilita_envio_vaga(formName,fieldName1,fieldName2) { 
	//formName é o formulario de origem 
	//fieldName é o nome do campo
	if(document.forms[formName][fieldName1].checked) {
 		document.forms[formName][fieldName2].disabled = false;
	}
	else {
 		document.forms[formName][fieldName2].disabled = true;
	}	
}

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 habilitaComissaoSalario(campo) {
   if(campo.disabled) {
      campo.disabled = false;
   }      
   else {
      campo.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;   	
   }
}
function habilitaCampo(campo1) {
   if(campo1.disabled) {
      campo1.disabled = false;
   }      
   else {
      campo1.disabled = true;   
   }
}
function formatNoticia(valor){
   var f = document.forms['cad_noticia'];
   f.elements['noticia'].value += ' '+valor+' ';
}
function formatArtigo(valor){
   var f = document.forms['cad_artigo'];
   f.elements['artigo'].value += ' '+valor+' ';
}
