// JavaScript Document

//CRIA A VARIÁVEL RETORNO
var retorno;
function CarregaArquivo(url,valor,valor2)
{
    retorno = null;
	//CRIA O OBJETO HttpRequest PARA O RESPECTIVO NAVEGADOR
	//Mozilla Fire Fox / Safari ...
	//
    if (window.XMLHttpRequest) {
        retorno = new XMLHttpRequest();
		//SETA A FUNÇÃO QUE SERÁ CHAMADA QUANDO O AJAX DER UM RETORNO
        retorno.onreadystatechange = processReqChange;
		 //ABRE A REQUISIÇÃO AJAX, PASSANDO O MÉTODO DE ACESSO, URL E O PARÂMETRO
        retorno.open("GET", url+'?id='+valor+'&pagina='+valor2, true);
		//INICIA O TRANSPORTA DOS OBJETOS NA REQUISIÇÃO
        retorno.send(null);
    } else if (window.ActiveXObject) {
		//
		//IE
		//
        retorno = new ActiveXObject("Microsoft.XMLHTTP");
        if (retorno) {
			//SETA A FUNÇÃO QUE SERÁ CHAMADA QUANDO O AJAX DER  UM RETORNO
            retorno.onreadystatechange = processReqChange;
		    //ABRE A REQUISIÇÃO AJAX, PASSANDO O MÉTODO DE ACESSO, URL E O PARÂMETRO
            retorno.open("GET", url+'?id='+valor+'&pagina='+valor2, true);
			//INICIA O TRANSPORTA DOS OBJETOS NA REQUISIÇÃO
            retorno.send();
        }
    }
}
//FUNÇÃO QUE TRATA O RETORNO DO AJAX
function processReqChange()
{
	// PEGA A DIV QUE IRÁ EXIBIR O CONTEUDO
	var conteudo = document.getElementById('mostraConteudo');
	//CASO O STATUS DO AJAX SEJA OK, CHAMA A FUNÇÃO mudar()
	//A LISTA COMPLETA DOS VALORES readyState É A SEGUINTE:
	//0 (uninitialized) 
	//1 (a carregar) 
	//2 (carregado) 
	//3 (interactivo) 
	//4 (completo) 
	if (retorno.readyState == 2) {
		conteudo.innerHTML = "<div align='center'><img src='../imgs/loading.gif' /></div>";
	}
	if (retorno.readyState == 4)
	{
		if(retorno.status == 200) 
			{
				//PROCURA PELA DIV MOSTRACOMBO E INSERE O OBJETO
				conteudo.innerHTML = retorno.responseText;
			} 
				else 
				{
					//MOSTRA UM ALERTA AO OBTER UM RETORNO DE OK.
					alert("Houve um problema ao obter os dados:\n" + retorno.statusText);
				}
   }
}

//FUNÇÃO MUDAR, QUE CHAMA AS INFORMAÇÕES PASSADAS NO PARÂMETRO E CARREGA O ARQUIVO EXTERNO
function mudar(valor,valor2)
{
	//CARREGA O ARQUIVO EXTERNO DO AJAX
    CarregaArquivo("includes/ajax.php",valor,valor2);
}


//////////////////// EXIBE / ESCONDE DIV ////////////////////

function displayDiv(name) {
	if (document.getElementById(name).style.display=='') {
		document.getElementById(name).style.display='none';
	} else {
		document.getElementById(name).style.display='';
	}
}


//////////////////// BARRAS AUTOMATICAS EM DATA ////////////////////

function formatar(src, mask) {
	var i = src.value.length;
	var saida = mask.substring(0,1);
	var texto = mask.substring(i)
	if (texto.substring(0,1) != saida) {
		src.value += texto.substring(0,1);
	}
}

//////////////////// PULAR CAMPO AUTOMÁTICAMENTE ////////////////////

function exibeValor(nomeCampo, lenCampo, controle)
{
	if ((nomeCampo.value.length == lenCampo) && (checarTabulacao))
	{	
		var i=0;
		for (i=0; i<document.forms[0].elements.length; i++)
		{
			if (document.forms[0].elements[i].name == nomeCampo.name)
			{
				while ((i+1) < document.forms[0].elements.length)
				{
					if (document.forms[0].elements[i+1].type != "hidden")
					{
						document.forms[0].elements[i+1].focus();
						break;
					}
					i++;
				}
				checarTabulacao=false;
				break;
			}
		}
	}
}
	
function stopTabCheck(nomeCampo)
{checarTabulacao=false;}

function startTabCheck()
{checarTabulacao=true;}


//////////////////////////////////////////FUNÇÃO PARA ENVIAR FORMAÇÃO DO CURRICULO POR AJAX//////////////////////////////////
function goPage(pag,div){
	
	$.ajax({
		type: "GET",
		url: pag,
		success: function(texto){
			$("#"+div).html(texto);
		}
	});
	
}


function enviarFormacao(){
	
		var valoget = '?'
		
		valoget = valoget+'grauescolaridade='+document.getElementById('grauescolaridade').value
		valoget = valoget+'&curso='+document.getElementById('curso').value
		valoget = valoget+'&mesinicio='+document.getElementById('mesinicio').value
		valoget = valoget+'&anoinicio='+document.getElementById('anoinicio').value		
		valoget = valoget+'&mesfim='+document.getElementById('mesfim').value				
		valoget = valoget+'&anofim='+document.getElementById('anofim').value						
		valoget = valoget+'&instituicao='+document.getElementById('instituicao').value								
		valoget = valoget+'&id_curriculo='+document.getElementById('id_trabalhe').value								
		
	
		goPage('trabalhe_formacao.php'+valoget,'divescolaridade')
	
}


function enviarExperiencia(){
	
		var valoget = '?'
		
		valoget = valoget+'mesentrada='+document.getElementById('mesentrada').value
		valoget = valoget+'&anoentrada='+document.getElementById('anoentrada').value
		valoget = valoget+'&messaida='+document.getElementById('messaida').value
		valoget = valoget+'&anosaida='+document.getElementById('anosaida').value		
		valoget = valoget+'&empresa='+document.getElementById('empresa').value				
		valoget = valoget+'&cargo='+document.getElementById('cargo').value						
		valoget = valoget+'&salario='+document.getElementById('salario').value								
		valoget = valoget+'&atribuicoes='+document.getElementById('atribuicoes').value								
		valoget = valoget+'&atual='+document.getElementById('atual').checked								
		valoget = valoget+'&id_curriculo='+document.getElementById('id_trabalhe').value								
		
	
		goPage('trabalhe_experiencia.php'+valoget,'divexperiencia')
	
}


function desabilitarcampo(){
	
	
	if(document.getElementById('atual').checked==true){
		
		document.getElementById('messaida').disabled = true
		document.getElementById('anosaida').disabled = true
	}
	else
	if(document.getElementById('atual').checked==false){
		
		document.getElementById('messaida').disabled = false
		document.getElementById('anosaida').disabled = false
	}
	
}


function excluirFormacao(fid){
	
	if(confirm("Deseja Excluir?")){								

		goPage('trabalhe_formacao.php?idFormacao='+fid+'&id_curriculo='+document.getElementById('id_trabalhe').value,'divescolaridade')
		
	}	
	
}

function excluirExperiencia(fid){
	
	if(confirm("Deseja Excluir?")){								

		goPage('trabalhe_experiencia.php?idExperiencia='+fid+'&id_curriculo='+document.getElementById('id_trabalhe').value,'divexperiencia')
		
	}	
	
}



/*
////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
							FUNÇÃO PARA MASCARA
////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
*/


function mascara(o,f){
    v_obj=o
    v_fun=f
    setTimeout("execmascara()",1)
}

/*
////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
							FUNÇÃO PARA EXECUTA MASCARA
////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
*/


function execmascara(){
    v_obj.value=v_fun(v_obj.value)
}

/*
////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
							FUNÇÃO PARA LEECH
////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
*/


function leech(v){
    v=v.replace(/o/gi,"0")
    v=v.replace(/i/gi,"1")
    v=v.replace(/z/gi,"2")
    v=v.replace(/e/gi,"3")
    v=v.replace(/a/gi,"4")
    v=v.replace(/s/gi,"5")
    v=v.replace(/t/gi,"7")
    return v
}


/*
////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
							FUNÇÃO PARA SO NUMEROS
////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
*/



function soNumeros(v){
    return v.replace(/\D/g,"")
}


/*
////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
			FUNÇÃO PARA FORMATAÇÃO DE MASCARA DO CAMPO DO JEITO QUE COLOCAR
////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
*/

function txtBoxFormat(objeto, sMask, evtKeyPress) {
var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;
if(document.all) { // Internet Explorer
nTecla = evtKeyPress.keyCode; }
else if(document.layers) { // Nestcape
nTecla = evtKeyPress.which;
}else{
nTecla = evtKeyPress.which;
}
sValue = objeto.value;
// Limpa todos os caracteres de formatação que
// já estiverem no campo.
sValue = sValue.toString().replace( "-", "" );
sValue = sValue.toString().replace( "-", "" );
sValue = sValue.toString().replace( ".", "" );
sValue = sValue.toString().replace( ".", "" );
sValue = sValue.toString().replace( "/", "" );
sValue = sValue.toString().replace( "/", "" );
sValue = sValue.toString().replace( ":", "" );
sValue = sValue.toString().replace( ":", "" );
sValue = sValue.toString().replace( "(", "" );
sValue = sValue.toString().replace( "(", "" );
sValue = sValue.toString().replace( ")", "" );
sValue = sValue.toString().replace( ")", "" );
sValue = sValue.toString().replace( " ", "" );
sValue = sValue.toString().replace( " ", "" );
fldLen = sValue.length;
mskLen = sMask.length;
i = 0;
nCount = 0;
sCod = "";
mskLen = fldLen;
if (nTecla != 8) { // backspace
while (i <= mskLen) {
bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/") || (sMask.charAt(i) == ":"))
bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))
if (bolMask) {
sCod += sMask.charAt(i);
mskLen++; }
else {
sCod += sValue.charAt(nCount);
nCount++;
}
i++;
}
objeto.value = sCod;
if (sMask.charAt(i-1) == "9") { // apenas números...
return ((nTecla > 47) && (nTecla < 58)); } // números de 0 a 9
else { // qualquer caracter...
return true;
} }
else {
return true;
}
}

/*
////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
							FUNÇÃO FORMATAR VALOR
////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
*/

function Limpar(valor, validos) {
// retira caracteres invalidos da string
var result = "";
var aux;
for (var i=0; i < valor.length; i++) {
aux = validos.indexOf(valor.substring(i, i+1));
if (aux>=0) {
result += aux;
}
}
return result;
}


function Formata(campo,tammax,teclapres,decimal) {
var tecla = teclapres.keyCode;
vr = Limpar(campo.value,"0123456789");
tam = vr.length;
dec=decimal

if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

if (tecla == 8 )
{ tam = tam - 1 ; }

if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )
{

if ( tam <= dec )
{ campo.value = vr ; }

if ( (tam > dec) && (tam <= 5) ){
campo.value = vr.substr( 0, tam - 2 ) + "," + vr.substr( tam - dec, tam ) ; }
if ( (tam >= 6) && (tam <= 8) ){
campo.value = vr.substr( 0, tam - 5 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ;
}
if ( (tam >= 9) && (tam <= 11) ){
campo.value = vr.substr( 0, tam - 8 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
if ( (tam >= 12) && (tam <= 14) ){
campo.value = vr.substr( 0, tam - 11 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
if ( (tam >= 15) && (tam <= 17) ){
campo.value = vr.substr( 0, tam - 14 ) + "." + vr.substr( tam - 14, 3 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - 2, tam ) ;}
}

}


