/* 	
#################################################################
#---------------------------------------------------------------#
# 			 		e-Net : Agência Web 						#
# 																#
#					  www.enetbr.com.br							#
# 					 info@enetbr.com.br							#
# 																#
#					   Biblioteca JS					#
#																#
# 		Copyright © 2010 - Todos os Direitos Reservados			#
#---------------------------------------------------------------#
#################################################################

*/

$(document).ready(function(){

	if ( $("#msg").val() != '') {
		$("#mensagem").show();
		$("#mensagem").html($("#msg").val());
		hideMessage();
	}else{
		$("#mensagem").hide();
	}

});

function hideMessage(){
	var intervalo = window.setInterval(function() {
		$("#mensagem").hide();
		$("#msgbox").hide();
		$("#msgRequired").hide();
		$("#msgRequired2").hide();
		$("#msgArea").hide();
		$("#msgDisponivelUser").hide();
		$("#msgDisponivelEmpresa").hide();
		}, 3000);
			window.setTimeout(function() {
			clearInterval(intervalo);
		}, 3000);	
}

function hideMessageModal(){
	var intervalo = window.setInterval(function() {
		$("#msgRequired").hide();
		}, 3000);
			window.setTimeout(function() {
			clearInterval(intervalo);
		}, 3000);	
}


function setCurrency(cur,len){
   n='__0123456789';
   d=cur.value;
   l=d.length;
   r='';
   if (l > 0){
	z=d.substr(0,l-1);
	s='';
	a=2;
	for (i=0; i < l; i++)
	{
		c=d.charAt(i);
		if (n.indexOf(c) > a)
		{
			a=1;
			s+=c;
		};
	};
	l=s.length;
	t=len-1;
	if (l > t)
	{
		l=t;
		s=s.substr(0,t);
	};
	if (l > 2)
	{
		r=s.substr(0,l-2)+','+s.substr(l-2,2);
	}
	else
	{
		if (l == 2)
		{
			r='0,'+s;
		}
		else
		{
			if (l == 1)
			{
				r='0,0'+s;
			};
		};
	};
	if (r == '')
	{
		r='0,00';
	}
	else
	{
		l=r.length;
		if (l > 6)
		{
			j=l%3;
			w=r.substr(0,j);
			wa=r.substr(j,l-j-6);
			wb=r.substr(l-6,6);
			if (j > 0)
			{
				w+='.';
			};
			k=(l-j)/3-2;
			for (i=0; i < k; i++)
			{
				w+=wa.substr(i*3,3)+'.';
			};
			r=w+wb;
		};
	};
   };
   if (r.length <= len)
   {
	cur.value=r;
   }
   else
   {
	cur.value=z;
   };
   return 'ok';
};

function addAreaCurriculo(id){
		
	if ($("#areasInteresse").val() != ''){
		
		$("#loading_area").show();
		$("#listaAreas").hide();
	
		$.post('/principal/sistemas/rh/jq_addAreaCurriculo.php?action=save', {idCurriculo: id, idArea: $("#areasInteresse").val() },
			   function(lista){
					$("#loading_area").hide();
					$("#listaAreas").html(lista);
					$("#listaAreas").show();
			   }
		);
		
	}else{
		$("#msgArea").html('Selecione uma &aacute;rea!');
		$("#msgArea").show();
		hideMessage();
	}

}

function removerAreaCurriculo(id, curriculo){
	
	$("#loading_area").show();
	$("#listaAreas").hide();
	
	$.post('/principal/sistemas/rh/jq_addAreaCurriculo.php?action=erase', {idCurriculo: curriculo, idAreaCurriculo: id},
		   function(lista){
			    $("#loading_area").hide();
				$("#listaAreas").html(lista);
				$("#listaAreas").show();
		   }
	);
}

function dialogFrm(id){
	
	$.post('/principal/sistemas/rh/formacaoEditar.php', {idFrm : id, idCurriculo : $("#idCurriculo").val() },
			   function(resposta){  
					$('#editarFormacao').dialog('open');
					$('#editarFormacao').html(resposta);

			   });
	
	$("#editarFormacao").dialog({
		bgiframe: true,
		autoOpen: false,
		title: "Forma&ccedil;&atilde;o",
		width: 400,
		height: 'auto',
		maxHeight: 400,
		resizable: false,
		modal: true,
		
		open: function() {
			$('#dialog').parent().appendTo($('#form1'));
		},
		
		buttons: {
			
			'Salvar': function(){
				
				if($("#grauInstrucao").val() == ''){
					$("#msgRequired").show();
					$("#msgRequired").html('Grau de Instru&ccedil;&atilde;o Obrigat&oacute;rio');
					$("#grauInstrucao").focus();
					hideMessage();
					return false;	
				}
				if($("#curso").val() == ''){
					$("#msgRequired").show();
					$("#msgRequired").html('Curso Obrigat&oacute;rio');
					$("#curso").focus();
					hideMessage();
					return false;	
				}
				if($("#instituicao").val() == ''){
					$("#msgRequired").show();
					$("#msgRequired").html('Institui&ccedil;&atilde;o Obrigat&oacute;rio');
					$("#instituicao").focus();
					hideMessage();
					return false;	
				}
				if($("#situacao").val() == ''){
					$("#msgRequired").show();
					$("#msgRequired").html('Situa&ccedil;&atilde;o Obrigat&oacute;rio');
					$("#situacao").focus();
					hideMessage();
					return false;	
				}
				if($("#dataInicioCurso").val() == ''){
					$("#msgRequired").show();
					$("#msgRequired").html('Data de In&iacute;cio do curso Obrigat&oacute;rio');
					$("#dataInicioCurso").focus();
					hideMessage();
					return false;	
				}
				
				if($("#situacao").val() == '7'){
					
					if( $("#dataFimCurso").val() == ''){				
						$("#msgRequired").show();
						$("#msgRequired").html('Data de Conclus&atilde;o do curso Obrigat&oacute;rio');
						$("#dataFimCurso").focus();
						hideMessage();
						return false;
					}
				}
				
				$("#loading_frm").show();
				$("#innerFormacao").hide();
				
				$.post('/principal/sistemas/rh/innerFormacao.php?action=save', $('#formacao').serialize() ,
					function(formacao){
						$("#loading_frm").hide();
						$("#innerFormacao").html(formacao);
						$("#innerFormacao").show();
				});
				$(this).dialog('destroy');
				
			},

			'Fechar': function() {
				$(this).dialog('close');
			}
		}		
		
	});



}

function dialogExp(id){
	
	$.post('/principal/sistemas/rh/experienciaEditar.php', {idExp : id, idCurriculo : $("#idCurriculo").val() },
			   function(resposta){
					$('#editarExperiencia').dialog('open');
					$('#editarExperiencia').html(resposta);
	
			   });
		
	$("#editarExperiencia").dialog({
		bgiframe: true,
		autoOpen: false,
		title: "Experi&ecirc;ncia ",
		width: 450,
		height: 'auto',
		maxHeight: 480,
		modal: true,
		resizable: false,
		buttons: {
			
			'Salvar': function(){
				
				if($("#ultimaEmpresa").val() == ''){
					$("#msgRequired").show();
					$("#msgRequired").html('Nome da Empresa Obrigat&oacute;rio');
					$("#ultimaEmpresa").focus();
					hideMessage();
					return false;	
				}
				if($("#ramoEmpresa").val() == ''){
					$("#msgRequired").show();
					$("#msgRequired").html('Ramo de Atua&ccedil;&atilde;o Obrigat&oacute;rio');
					$("#ramoEmpresa").focus();
					hideMessage();
					return false;	
				}
				if($("#telEmpresa").val() == ''){
					$("#msgRequired").show();
					$("#msgRequired").html('Telefone Obrigat&oacute;rio');
					$("#telEmpresa").focus();
					hideMessage();
					return false;	
				}
				if($("#ultimaCargo").val() == ''){
					$("#msgRequired").show();
					$("#msgRequired").html('&Uacute;ltimo cargo Obrigat&oacute;rio');
					$("#ultimaCargo").focus();
					hideMessage();
					return false;	
				}
				if($("#dataEntradaExp").val() == ''){
					$("#msgRequired").show();
					$("#msgRequired").html('Data de entrada Obrigat&oacute;rio');
					$("#dataEntradaExp").focus();
					hideMessage();
					return false;	
				}
				
				var lastJob = $("input:checked[id=checkedUltimoEmprego]:checked").val();
				if(!lastJob){
					if($("#dataSaidaExp").val() == ''){
						$("#msgRequired").show();
						$("#msgRequired").html('Data de sa&iacute;da Obrigat&oacute;rio');
						$("#dataSaidaExp").focus();
						hideMessage();
						return false;	
					}
				}
				
				$("#loading_exp").show();
				$("#innerExperiencia").hide();
				
				$.post('/principal/sistemas/rh/innerExperiencia.php?action=save', $('#fExperiencia').serialize(),
					function(experiencia){
						$("#loading_exp").hide();
						$("#innerExperiencia").html(experiencia);
						$("#innerExperiencia").show();
				});
				$(this).dialog('destroy');
			},
			
			'Fechar': function() {
				$(this).dialog('destroy');
			}
		}
	});

}

function dialogExcExp(id){
	
	var titulo = 'Deseja apagar este registro?';
	var mensagem = 'Ap&oacute;s confirmado o registro ser&aacute; apagado definitivamente.';
	
	$('#dialogMensagem').html(mensagem);
	$("#dialog").attr({title: titulo});
	$("#dialog").show();
	$("#dialog").dialog({
		bgiframe: false,
		resizable: false,
		width:500,
		height: 'auto',
		maxHeight:200,
		modal: true,
		overlay: {
			backgroundColor: '#000',
			opacity: 0.3
		},
		buttons: {
			
			'Confirmar': function() {
				$.post('/principal/sistemas/rh/innerExperiencia.php?action=excluir&idExp='+id,
					function(experiencia){
						$("#innerExperiencia").html(experiencia);
				});
				
				$(this).dialog('destroy');
	
			},
			'Cancelar': function() {
				$(this).dialog('destroy');
			}
		}
	});
}

function dialogExcFrm(id){

	var titulo = 'Deseja apagar este registro?';
	var mensagem = 'Ap&oacute;s confirmado o registro ser&aacute; apagado definitivamente.';
	
	$('#dialogMensagem').html(mensagem);
	$("#dialog").attr({title: titulo});
	$("#dialog").show();
	$("#dialog").dialog({
		bgiframe: false,
		resizable: false,
		width:500,
		height: 'auto',
		maxHeight:200,
		modal: true,
		overlay: {
			backgroundColor: '#000',
			opacity: 0.3
		},
		buttons: {
			
			'Confirmar': function() {
				$.post('/principal/sistemas/rh/innerFormacao.php?action=excluir&idFrm='+id,
					function(formacao){
						$("#innerFormacao").html(formacao);
				});
				
				$(this).dialog('destroy');
	
			},
			'Cancelar': function() {
				$(this).dialog('destroy');
			}
		}
	});
}

/* CURSOS */

function dialogCurso(id){
	
	$.post('/principal/sistemas/rh/cursoEditar.php', {idCurso: id, idCurriculo: $("#idCurriculo").val() },
			   function(resposta){  
					$('#editarCurso').dialog('open');
					$('#editarCurso').html(resposta);
	
			   });
		
	$("#editarCurso").dialog({
		bgiframe: true,
		autoOpen: false,
		title: "Curso",
		width: 400,
		height: 'auto',
		maxHeight: 400,
		resizable: false,
		modal: true,
		buttons: {
			
			'Salvar': function(){				
							
				if($("#curso").val() == ''){
					$("#msgRequired").show();
					$("#msgRequired").html('Curso Obrigat&oacute;rio');
					$("#curso").focus();
					hideMessageModal();
					return false;	
				}
				
				if($("#instituicao").val() == ''){
					$("#msgRequired").show();
					$("#msgRequired").html('Institui&ccedil;&atilde;o Obrigat&oacute;rio');
					$("#instituicao").focus();
					hideMessageModal();
					return false;	
				}
				
				if($("#carga").val() == ''){
					$("#msgRequired").show();
					$("#msgRequired").html('Carga Hor&aacute;ria Obrigat&oacute;rio');
					$("#carga").focus();
					hideMessageModal();
					return false;	
				}
				
				if($("#dataFimCurso").val() == ''){
					$("#msgRequired").show();
					$("#msgRequired").html('Data de Conclus&atilde;o do curso Obrigat&oacute;rio');
					$("#dataFimCurso").focus();
					hideMessageModal();
					return false;	
				}

				$.post('/principal/sistemas/rh/innerCurso.php?action=save', $('#fCurso').serialize() ,
					function(curso){
						$("#innerCurso").html(curso);
				});
				$(this).dialog('destroy');
			},
			
			
			'Fechar': function() {
				$(this).dialog('close');
			}
		}
	});

}

function dialogExcCurso(id){

	var titulo = 'Deseja apagar este registro?';
	var mensagem = 'Ap&oacute;s confirmado o registro ser&aacute; apagado definitivamente.';
	
	$('#dialogMensagem').html(mensagem);
	$("#dialog").attr({title: titulo});
	$("#dialog").show();
	$("#dialog").dialog({
		bgiframe: false,
		resizable: false,
		width:500,
		height: 'auto',
		maxHeight:200,
		modal: true,
		overlay: {
			backgroundColor: '#000',
			opacity: 0.3
		},
		buttons: {
			
			'Confirmar': function() {
				$.post('/principal/sistemas/rh/innerCurso.php?action=excluir&idCurso='+id,
					function(formacao){
						$("#innerCurso").html(formacao);
				});
				
				$(this).dialog('destroy');
	
			},
			'Cancelar': function() {
				$(this).dialog('destroy');
			}
		}
	});
}

/* VAGAS */

function confirmaCandidato(id){
		
	$.post('/principal/sistemas/rh/candidatar.php', { idVaga: id },
		   function(resposta){
				$('#confirmacao').dialog('open');
				$('#confirmacao').html(resposta);
	
	});
		
	$("#confirmacao").dialog({
		bgiframe: true,
		autoOpen: false,
		title: "Confirma&ccedil;&atilde;o",
		width: 350,
		height: 'auto',
		maxHeight: 450,
		modal: true,
		resizable: false,
		buttons: {
			
			'OK': function(){				
				$(this).dialog('destroy');
			}
		}
	});

}

function dialogRemoverVaga(id){
	
	var titulo = 'Deseja apagar este registro?';
	var mensagem = 'Ap&oacute;s confirmado o registro ser&aacute; apagado definitivamente.';
	
	$('#dialogMensagem').html(mensagem);
	$("#dialog").attr({title: titulo});
	$("#dialog").show();
	$("#dialog").dialog({
		bgiframe: false,
		resizable: false,
		width:500,
		height: 'auto',
		maxHeight:200,
		modal: true,
		overlay: {
			backgroundColor: '#000',
			opacity: 0.3
		},
		buttons: {
			
			'Confirmar': function() {
				$.post('/vagas/vagas', {action: 'excluir', idVaga: id},
					function(vaga){
						window.location='../../vagas/vagas';
				});
				
				$(this).dialog('destroy');
	
			},
			'Cancelar': function() {
				$(this).dialog('destroy');
			}
		}
	});
}


