//Retorna o objeto

//ATENÇÃO: DIRETÓRIO BASE DO SITE (ENDEREÇO LOCAL)
//var DIR_BASE_SITE = '/sites/persona/';

// ENDEREÇO NO SERVIDOR ITAKE
var DIR_BASE_SITE = '/';

function get(id) { 
	try { 
		var a = document.getElementById(id); 
	} catch(e) { 
		alert("Erro encontrado: "+e); 		
	} 
	return 	a;
}
function getObjs(name)
{
	var a = document.getElementsByName(name); 
	for(i=0; i<a.length; i++)
	{
		if(a[i].checked==true)
		{
			return true;
		}
	}
	return false;
}
function menu (id, o) {
	var obj = get(id).style;
	if(obj.display=="none")
	{
		obj.display = "block";

	}
	else if (obj.display=="block")
	{
		obj.display = "none";
	}
}

function addAction(objs) {
	for(i=0; i < objs.length; i++)
	{

		get(objs[i]).onfocus = function ()
		{
			valueField('focus', this.id);
		}
		
		get(objs[i]).onblur = function ()
		{
			valueField('blur', this.id);
		}
	}
}

function addFocus (obj) {
	get(obj).focus();
}
//Limpa/Preenche os campos
function valueField (e, obj) {
	var obj = get(obj);
	
	if(!obj.save)
	{
		obj.save = obj.value;		
	}
	
	if(e=="blur")
	{
		if(obj.value=="")
		{
			obj.value = obj.save;
		}
	}
	else if(e=="focus")
	{
		if(obj.value=="")
		{
			obj.value = obj.save;
		}
		else if(obj.value==obj.save)
		{
			obj.value = "";
		}
	}
}
function addFlash (file, width, height, id, wmode) {
	if(!wmode)
		wmode = "true";
	
	var fo = new FlashObject(file, "notify", width, height, "8", "#FFFFFF", true);
	fo.addParam("scale", "noscale");
	fo.addParam("wmode", "opaque");
	
	if(wmode=="true")
		fo.addParam("wmode", "transparent");
		
	fo.write(id);
}

function redirect (url) {
	parent.window.location.href = url;	
}
function busca_noticias (url) {
	var value = get('buscaNoticias').value;

	redirect(url+value);
	
	return false;
}
function busca_artigos (url) {
	var value = get('buscaArtigos').value;

	redirect(url+value);
	
	return false;
}
function show (id)
{
	get(id).style.display = 'block';
}
function hide(id)
{
	get(id).style.display = 'none';
}
function val (obj, size)
{	
	if(!size)
		var size = 4;
		
	var obj = get(obj);

	if(obj.value.length<size)
		return false;
	else
		return true;
}

function limpaErro (campo, classe) {
	if(!classe)
		var classe = 'inputForm';
		
	obj = get(campo);
	obj.className = classe;
}
function erro (campo)
{
	obj = get(campo);
	obj.className = 'inputError';
	obj.focus();
	
}
function valSel (campo)
{
	obj = get(campo);
	if(obj.selectedIndex<0)
	{
		obj.focus();
		return false;
	}
	else
	{
		return true;
	}
}
function valOpt (campo)
{
	obj = get(campo);
	if(obj.value==0)
	{
		obj.focus();
		return false;
	}
	else
	{
		return true;
	}
}
function abreCidades (value, local, cidade, obr, w, n)
{
	if(!cidade)
		cidade = 0;
	
	if(!obr)
		obr = '';

	if(!w)
		w = '';
		
	if(!n)
		n = '1';
	//ALTERAR AQUI
	ajax.loadContent(DIR_BASE_SITE+'site/cidades.php?value='+value+'&cidade='+cidade+'&obr='+obr+'&w='+w+'&n='+n, local);
}

function abreAtendimento () {
	   var width = 400;
	   var height = 450;
	   var left = (screen.width - width)/2;
	   var top = (screen.height - height)/2;;   
	   window.open(DIR_BASE_SITE+'new/atd/view/?action=AppUsr/espera','atendimento', 'width='+width+', height='+height+', top='+top+', left='+left+', scrollbars=no, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');
}
function limitSelect (e, obj)
{
	var count = 0;
	var selectx = obj;

	for(i = 0; i< selectx.options.length; i++)
	{
		if(selectx.options[i].selected == true)
		{
			count++;
			if(count>4)
			{
				selectx.options[i].selected = false;
			}
		}
	}

}
function indicarVaga (id)
{
   var width = 465;
   var height = 500;
   var left = (screen.width - width)/2;
   var top = (screen.height - height)/2;;   
   window.open(DIR_BASE_SITE+"files/indicar_vaga.php?id="+id,'enviar_vaga', 'width='+width+', height='+height+', top='+top+', left='+left+', scrollbars=no, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');
}

function indique ()
{
   var width = 465;
   var height = 500;
   var left = (screen.width - width)/2;
   var top = (screen.height - height)/2;;   
   window.open(DIR_BASE_SITE+"files/indique.php",'indicar_site', 'width='+width+', height='+height+', top='+top+', left='+left+', scrollbars=no, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');
}
function verCurriculo ()
{
   var width = 620;
   var height = 500;
   var left = (screen.width - width)/2;
   var top = (screen.height - height)/2;;   
   window.open(DIR_BASE_SITE+"files/ver_curriculo.php",'ver_curriculo', 'width='+width+', height='+height+', top='+top+', left='+left+', scrollbars=yes, status=no, toolbar=no, location=no, directories=no, menubar=no, fullscreen=no');
}

function divBusca () {
	var obj = get('div_busca');
	if(obj.style.display=='block') {
		obj.style.display = 'none';
		get('novaBusca').innerHTML = 'Mostrar';
	} else {
		get('novaBusca').innerHTML = 'Ocultar';
		obj.style.display = 'block';	
	}
}
function checkEntrarContato() {
	var aux = window.confirm("Entrar em contato com a Persona Empregos sobre o anúncio deste currículo?");	
	if(aux==true)
		return true;
	else
		return false;
}
function set_forma_pagamento (id) {
	ajax.loadContent(DIR_BASE_SITE+'site/forma_pagamento.php?id='+id, 'total_a_pagar');	
}
function textoPagamentos (id) {
	get('div_pagamento_1').style.display = 'none';
	get('div_pagamento_2').style.display = 'none';
	get('div_pagamento_'+id).style.display = 'block';
}
function geraBoleto () {
   var width = 720;
   var height = 600;
   var left = (screen.width - width)/2;
   var top = (screen.height - height)/2;;   
   window.open(DIR_BASE_SITE+"files/gera_boleto.php",'gera_boleto', 'width='+width+', height='+height+', top='+top+', left='+left+', scrollbars=yes, status=no, toolbar=no, location=no, directories=no, menubar=no, fullscreen=no');	
}



//FUNÇÕES ADICIONAR E REMOVER FORMAÇÕES (Cadastro)
var counter = 0;
var html = "";

function get(id) { 
	try { 
		var a = document.getElementById(id); 
	} catch(e) { 
		alert("Erro encontrado: "+e); 		
	} 
	return 	a;
}

function armazenaHTML () {
	html = "<div id='content_curso'><strong>Formação nº <span id='cont_curso'>1</span></strong><br><br><div class='floatLeft top2 clearBoth' style='width: 120px;'>Grau de Escolaridade</div><select name='grau_escolaridade[]' id='grau_escolaridade' class='select floatLeft' style='width: 355px;'><option value='1'>Graduação</option><option value='2'>Pós-Graduação</option><option value='3'>MBA</option><option value='4'>Mestrado</option><option value='5'>Doutorado</option><option value='6'>Pós Doutorado</option><option value='7'>Livre Docência</option><option value='8'>Técnico Profissionalizante</option><option value='9'>Ensino Médio</option></select><div class='br'></div><div class='floatLeft top2 clearBoth' style='width: 120px;'>Nome do Curso: </div><input id='nome_curso[]' name='nome_curso[]' class='inputForm' value='' type='text'><div class='br'></div><div class='floatLeft' style='width: 250px;'><div class='floatLeft top2 clearBoth' style='width: 120px;'>Data de Início: </div><input id='inicio_curso[]' name='inicio_curso[]' class='inputForm' value='' maxlength='10' style='width: 100px;' type='text'></div><div class='floatLeft' style='width: 230px;'><div class='floatLeft top2 clearBoth' style='width: 120px;'>Data de conclusão: </div><input id='fim_curso[]' name='fim_curso[]' class='inputForm' value='' maxlength='10' style='width: 100px;' type='text'></div><br><br><div class='clearBoth'></div><div class='floatLeft top2 clearBoth' style='width: 120px;'>Ano Atual</div><select name='ano_atual[]' id='ano_atual' class='select floatLeft' style='width: 355px;'><option value='1'>1º Ano</option><option value='2'>2º Ano</option><option value='3'>3º Ano</option><option value='4'>4º Ano</option><option value='5'>5º Ano</option><option value='6'>6º Ano</option><option value='7'>7º Ano</option><option value='8'>8º Ano</option><option value='9'>9º Ano</option><option value='11'>10º Ano</option><option value='10'>Já Formado</option></select><div class='br'></div><div class='floatLeft top2 clearBoth' style='width: 120px;'>Nome da Instituição: </div><input id='nome_instituicao[]' name='nome_instituicao[]' class='inputForm' value='' type='text'><div class='br'></div><br></div>";
}

function addCurso () {
	
	if(counter<4)
	{
		var cont = document.createElement("div");
		cont.innerHTML = html;
		counter++;
	
		cont.id = "content_curso"+counter;
	
		get("content_cursos").appendChild(cont);
	
		get('cont_curso').id = 'cont_curso'+counter;
	
		get("cont_curso"+counter).innerHTML = counter+1;
	} else {
		alert('Número de cursos excedido');
	}
}

function removeCurso () {
	var p = get('content_curso'+counter).parentNode;
	p.removeChild(get('content_curso'+counter));
	 
	counter--;
}

function validaH(obj) {
	if(obj.value == 'sim') {
		get('div_habilitacoes').style.display = 'block';
	} else {
		
		var objs = document.getElementsByName('carteira_motorista[]');
		var habilitacoes = document.getElementsByName('habilitacoes[]');
		
		for(var obj in objs) { 
			objs[obj].checked = false;
		}
		
		for(var obj in habilitacoes) { 
			habilitacoes[obj].checked = false;
		}		
		
		get('div_habilitacoes').style.display = 'none';
	}
}
//FIM
