// JavaScript Document

var ctrmenu = 1;

//+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
function gerLista(elem, op, idaux){
	//var lst = arraux[idaux];
	var lst = document.getElementById(idaux).value;
	expReg1 = eval('/@'+elem+'@/');
	aux = (lst.search(expReg1) == -1) ? true : false;
	if(op){ //Inserir
		if(aux){ //Não tem o elemento na lista (faz a inserção);
			//arraux[idaux] = lst + '®' + elem + '®';
			document.getElementById(idaux).value = lst + '@' + elem + '@';
			return true;
		}else{ //Tem elemento (não faz a inserção);
			return false;
		}
	}else{ //Remover
		if(aux){ //Não tem elemento na lista (não faz a remoção);
			return false;
		}else{ //Tem elemento (faz a remoção);
			//arraux[idaux] = lst.replace('®' + elem + '®','');
			document.getElementById(idaux).value = lst.replace('@' + elem + '@','');
			return true; 
		}
	}
}
//+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
function insConteudo(comp, strPost, pag, id){
	var td = document.createElement("td");
	td.id  = 'td_'+comp+'_'+id;
	var tr = document.createElement("tr");
	tr.id  = 'tr_'+comp+'_'+id;
	document.getElementById('tbody_'+comp).appendChild(tr);
	document.getElementById(tr.id).appendChild(td);
	atualizarDiv(td.id,strPost,pag,'ajax_padrao');
}
//+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
function remConteudo(pai, filho, id){
	var epai   = document.getElementById(pai);
	var efilho = document.getElementById(filho);
	epai.removeChild(efilho);
}
//+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
/*
function remConteudo(pai,filho){
	tirar = '<div id="'+filho+'"></div>';
	valor = '';
//	tam = tirar.length;
//	pos = document.getElementById(pai).innerHTML.search(tirar);
	document.getElementById(filho).innerHTML = '';
	temp = document.getElementById(pai).innerHTML.split(tirar);
	for(i=0; i<temp.length; i++){
		temp[i];
		valor = valor+''+temp[i];
	}
	document.getElementById(pai).innerHTML = valor;
}
*/
//+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
function stringToFloat(x){
	 if(x != ""){
       tmp = parseFloat(x.replace(",","."),2);
	    return tmp;
    }else{
       return 0;
    }
}
//+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=




//########################################################################################################
function controlarMenu(id){
	obj_img = document.getElementById('img_menu_'+id);
	
	patch_img = obj_img.src.substr(0,(obj_img.src.length-12));
	img       = obj_img.src.substr((obj_img.src.length-12),12);
	vet_img   = img.split('_');
	
	//alert(vet_img[0]+" - "+vet_img[1]+" - "+vet_img[2]);

	quant = 9 // Quantidade de imagens no menun + 2 (inicio e fim).
	for(i = 0; i < quant; i++){
		if(i == id){
			document.getElementById('img_menu_'+i).src = patch_img+'menu_'+i+'_1.gif';
			document.getElementById('img_menu_'+(i-1)).src = patch_img+'menu_'+(id-1)+'_2.gif';
			document.getElementById('tab_'+i).style.display = 'block';
		}else{
			if(i != (id-1)){
				document.getElementById('img_menu_'+i).src = patch_img+'menu_'+i+'_0.gif';
			}
			if((i > 0) && (i < 7)){
				document.getElementById('tab_'+i).style.display = 'none';
			}
		}
	}
	if(id == 6){
		document.getElementById('btnsalvar').style.display = 'block';		
	}else{
		document.getElementById('btnsalvar').style.display = 'none';				
	}
	controleBotoes2(id);
}
//########################################################################################################
function controlarMenuTopo(id){
	obj_img = document.getElementById('menu_tp_'+id);
	
	patch_img = obj_img.src.substr(0,(obj_img.src.length-15));
	img       = obj_img.src.substr((obj_img.src.length-15),15);
	vet_img   = img.split('_');

	quant = 4 // Quantidade de imagens no menu.
	for(i = 1; i <= quant; i++){
		if(i == id){
			document.getElementById('menu_tp_'+i).src = patch_img+'menu_tp_'+i+'_2.gif';
		}else{
			document.getElementById('menu_tp_'+i).src = patch_img+'menu_tp_'+i+'_1.gif';
		}
	}
	switch (id){
		case 1:
			window.location = "curriculo.php";
		break;
		case 2:
			window.location = "vaga.php";
		break;
		case 3:
			window.location = "senha.php";
		break;
		case 4:
			window.location = "logout.php";
		break;
	}
}
//########################################################################################################
function controlarLogin(exib, ocult){
	document.getElementById(exib).style.display = 'block';
	document.getElementById(ocult).style.display = 'none';	
}
//########################################################################################################
function comparar(a,b){
	return (a-b);
}
//########################################################################################################
/*
function gerenciarListaElementos(acao,valor,elem){
	vet_funcao   = document.getElementById(elem).value.split(';');
	//str     = vet_funcao.join(); //vetor declaro no inicio da arquivo
	array   = vet_funcao;
	retorno = '';
	id = '';
	for(i = 0; i < array.length; i++){
		if(array[i] == valor){ //localizou o elemento no array.
			id = i; //pego a indicie do elemento
		}
	}
	if(acao == 0){ //remover
		if (id != ''){// remove se o elemento existir
			array.splice(id,1);
			retorno = true;  //retorno indica que o elemento foi removido no array
		}else{
			retorno = false; //retorno indica que o array não possui o elemento
		}
	}else{ // inserir
		if (id == ''){// inseri se o elemento não existir		
			array.push(valor);
			retorno = true;  //retorno indica que o elemento foi inserido no array
		}else{
			retorno = false; //retorno indica que o array já possui o elemento
		}
	}
	array.sort(comparar);
	vet_funcao = array;
	//str           = vet_funcao.join();
	document.getElementById(elem).value = vet_funcao.join(';');
	return retorno;
}
*/
//########################################################################################################
/*
function verificaInsercao(div, strpost, pag, form, id, lista){
	if(controle){
		if(gerenciarListaElementos(1,id,lista)){
			setTimeout('insConteudo("'+div+'", "'+strpost+'", "'+pag+'","")',500);
		}else{
			alert('Você já inseriu este item');	
		}
	}else{
		controle = true;	
	}
}
*/
//########################################################################################################
function stringReplace(valor, novo, antigo){
	tmp = valor.split(antigo);
	str = '';
	for(i=0; i < tmp.length; i++){
		str = str+''+novo+''+tmp[i];
	}
	return str;
}
//##########################################################################################
function stringToFloat(x){
	tmp = parseFloat(x.replace(",","."),2); 
	return tmp;
}
//##########################################################################################
function doDate(pStr, pFmt){
	eval("reDate = reDate" + pFmt);
		if (reDate.test(pStr)) {
			return true;
		}else if (pStr != null && pStr != "") {
			return false
	}
} // doDate

var reDate1 = /^\d{1,2}\/\d{1,2}\/\d{1,4}$/;
var reDate2 = /^[0-3]?\d\/[01]?\d\/(\d{2}|\d{4})$/;
var reDate3 = /^(0?[1-9]|[12]\d|3[01])\/(0?[1-9]|1[0-2])\/(19|20)?\d{2}$/;
var reDate4 = /^((0?[1-9]|[12]\d)\/(0?[1-9]|1[0-2])|30\/(0?[13-9]|1[0-2])|31\/(0?[13578]|1[02]))\/(19|20)?\d{2}$/;
var reDate5 = /^((0[1-9]|[12]\d)\/(0[1-9]|1[0-2])|30\/(0[13-9]|1[0-2])|31\/(0[13578]|1[02]))\/\d{4}$/;
var reDate = reDate4;
//##########################################################################################
//+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
function controleBotoes(op){
	if(op == 'ant'){
		ctrmenu--;
	}
	if(op == 'pro'){
		ctrmenu++;
	}
	controlarMenu(ctrmenu);
	if(ctrmenu == 1){
		document.getElementById('btn_ant').style.display = 'none'; 	
		document.getElementById('btn_pro').style.display = 'block';	
	}else if(ctrmenu == 6){
		document.getElementById('btn_ant').style.display = 'block'; 	
		document.getElementById('btn_pro').style.display = 'none';	
		document.getElementById('btnsalvar').style.display = 'block';	
	}else{
		document.getElementById('btn_ant').style.display = 'block';	
		document.getElementById('btn_pro').style.display = 'block'; 	
		document.getElementById('btnsalvar').style.display = 'none';	
	}
}
//+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
function controleBotoes2(id){
	switch(id){
		case 1:
			document.getElementById('btn_ant').style.display = 'none'; 	
			document.getElementById('btn_pro').style.display = 'block';
		break;
		case 2:
			document.getElementById('btn_ant').style.display = 'block';	
			document.getElementById('btn_pro').style.display = 'block';
		break;
		case 3:
			document.getElementById('btn_ant').style.display = 'block';	
			document.getElementById('btn_pro').style.display = 'block'; 		
		break;
		case 4:
			document.getElementById('btn_ant').style.display = 'block';	
			document.getElementById('btn_pro').style.display = 'block'; 		
		break;
		case 5:
			document.getElementById('btn_ant').style.display = 'block';	
			document.getElementById('btn_pro').style.display = 'block'; 		
		break;
		case 6:
			document.getElementById('btn_ant').style.display = 'block'; 	
			document.getElementById('btn_pro').style.display = 'none';	
		break;
	}
	ctrmenu = id;
}
//+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
function checarTamanho(tam,elem){
	if(elem.value.length < tam){
		document.getElementById(elem.id+'_aux').value = elem.value;
	}else{
		elem.value = document.getElementById(elem.id+'_aux').value;
	}
}
//+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
function dataMenorMaior(d1, d2){
	d1part = d1.split('/');
	d2part = d2.split('/');
	
	d1 = stringToFloat(d1part[2]+''+d1part[1]+''+d1part[0]);
	d2 = stringToFloat(d2part[2]+''+d2part[1]+''+d2part[0]);
	
	calc = d1 - d2;
	if(calc > 0){ 
		return 'maior';  //dt1 > dt2
	}else if(calc < 0){ //dt1 < dt2
		return 'menor';		
	}else{
		return 'igual'; //dt1 = dt2		
	}
}
//+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=