$(document).ready(function(){

	//HIDE AND SHOW SERVIÇOS SIDE-BAR
	$("a#bt-side-bar-servicos-online").click(function(){
	   if($('#side-bar-servicos-online .hide').css('display') == 'none'){
	   		$('#side-bar-servicos-online .hide').slideDown("fast");
			$("a#bt-side-bar-servicos-online").addClass("down");
	   }else{
		   $('#side-bar-servicos-online .hide').slideUp("fast");
		   $("a#bt-side-bar-servicos-online").removeClass("down");
	   }
	 });

	//BT TOPO
	$(".bt-topo").scrollTo('0',800);

	$(".transp").css("opacity","0.9");

	//BT BACK
	$(".bt-back").click(function(){
		history.back();
	});
	//BT BACK
	$("#bt-imprimir").click(function(){
		window.print();
	});

	//LINKS EXTERNOS
	$("a[rel=externo]").attr('target','_blank');

	// USE HAND CURSOR
	$("input[type=submit]").css("cursor","pointer");
	$("input[type=button]").css("cursor","pointer");

	//CONTROLADOR DO TAMANHO DAS FONTES
	if($('#font')){
		$("a#font-small").click(function(){
			$('.texto-editor').css('font-size', '10px');
		});
		$("a#font-normal").click(function(){
			$('.texto-editor').css('font-size', '11px');
		});
		$("a#font-big").click(function(){
			$('.texto-editor').css('font-size', '16px');
		});
		$("a#font-up").click(function(){
			var currentFontSize = $('.texto-editor').css('font-size');
			var currentFontSizeNum = parseFloat(currentFontSize, 10);
			if(currentFontSizeNum<18){
				var newFontSize = currentFontSizeNum*1.1;
				$('.texto-editor').css('font-size', newFontSize);
			}
		});
		$("a#font-down").click(function(){
			var currentFontSize = $(".texto-editor").css('font-size');
			var currentFontSizeNum = parseFloat(currentFontSize);
			if(currentFontSizeNum>10){
				var newFontSize = currentFontSizeNum*0.9;
				$('.texto-editor').css('font-size', newFontSize);
			}
		});
	}

	//AREAS DE ATIVACAO DO LIGHTBOX
	$('a[rel*=lightbox]').lightBox({
		overlayBgColor: '#000',
		overlayOpacity: 0.6,
		imageLoading: 		'http://www.crea-sc.org.br/portal/img/loading.gif',
		imageBtnClose: 	'http://www.crea-sc.org.br/portal/img/close.gif',
		imageBtnPrev: 	'http://www.crea-sc.org.br/portal/img/prev.gif',
		imageBtnNext: 	'http://www.crea-sc.org.br/portal/img/next.gif',
		containerResizeSpeed: 300,
		txtImage: 'Imagem',
		txtOf: 'de'
	});

	//TABS
	$('.tabss > ul').tabs();

	// SLIDES HOME
	$('.holder').cycle({
	    fx: "scrollHorz",
	    prev: '.bt-Prev',
	    next: '.bt-Next',
	    timeout: 0
	});


	$("#ano").change(function(){
		$("#form-search").submit();
	});

	/* GALERIA DE IMAGENS */
	$('#thumbs-galeria a').click(function(){
		$('#foto-grande img').attr('src',$(this).attr('href'));
		$('#desc-galeria').html($(this).attr('title'));
		return false;
	});

	/**
	   * Mostra a subcategoria da entidade
	   **/
	$("#fk_categoria").change(function(){
		$.ajax( {
			type: "POST",
			url: "incs/jQuery.php",
			data: "acao=exibeSubCategoria&id=" + this.value,
			beforeSend: function() {
				$("#fk_subcategoria").html("<option>Carregando...</option>");
			},
			success: function(txt) {
				$("#fk_subcategoria").html(txt);
			},
			error: function(txt) {
				alert('Erro: '+txt);
			}
		});
	});

	// ATIVAS JANELAS MODAL
	$(".dialog-box").dialog({
		autoOpen: false,
	    modal: true,
		resizable: false,
		width: 450,
		height: 410,
	    overlay: {
	        opacity: 0.5,
	        background: "black"
	    }
	});

	// BOTOES PARA JANELAS MODAL
	$(".dialog-bt").click(function(){
		var rel = $(this).attr('rel');
		$(rel).dialog("open");
		$(".ui-dialog-overlay").click(function(){
			$(rel).dialog("close");
		});
	});

	// TIKER NEWS INDEX
	$('#tiker-news').cycle({
	    speed:       600,
	    timeout:     5000,
	    pager:      '#tiker-news-nav',
	    pagerEvent: 'mouseover',
	    pauseOnPagerHover: true
	});

	// CYCLE-BANNER - HOME
	$('.cycle-banner ul').cycle({
		fx: "fade",
	    speed:       600,
	    timeout:     5000,
	    pager:      '.cycle-banner .cycle-nav',
	    pagerEvent: 'mouseover',
	    pauseOnPagerHover: true
	});

	// CYCLE-CONTEUDO - HOME
	$('.cycle-conteudo ul').cycle({
		fx: "scrollHorz",
	    timeout: 4000,
	    pager: '.cycle-conteudo .nav'
	});

	$(".header-content .menu ul .menusup").hover(
		function(){
			$(this).addClass("active", 0);
		},
		function(){
			$(this).removeClass("active", 0);
	});

	//	MENU
	$("#nav ul").css({display:"none"});
	$("#nav li").hover(
	function(){
			if($(this).attr('id')=='links-uteis-nav'){
				$(this).css({background: "#0787b8" });
				$(this).find('a:first').css({color:"#FFFFFF"});
			}else{
				$(this).addClass("hovered", 0);
				$(this).find('ul:first').show(0);
				/*$('select').hide();*/
			}
		},
		function(){
			if($(this).attr('id')=='links-uteis-nav'){
				$(this).css({background: "none" });
				$(this).find('a:first').css({color:"#0787b8"});
			}else{
				$(this).removeClass("hovered", 0);
				$(this).find('ul:first').hide(0);
				/*$('select').show();*/
			}
	});

	// IE HACK MENU PRINCIPAL
	if($.browser.msie){
		$("ul#nav .sun").mouseover(function(){
				var width = $(this).width();
				width = width*-1;
				$(this).find('ul:first').css("margin-left",width);
		});
	}

	// ATIVA HORARIO E DATA NO HEADER
	$("#clock").jclock();
	var date 		= new Date();
	var weekDay		= new Array("Domingo","Segunda-Feira","Terça-Feira","QuartaFeira","Quinta-Feira","Sexta-Feira","Sábado");
	var monthName	= new Array("janeiro","fevereiro","março","abril","maio","junho","julho","agosto","setembro","outubro","novembro","dezembro");
	$("#date").html(date.getDate()+" de "+monthName[date.getMonth()]+" de "+date.getFullYear());

	// MASCARAS
	$('#fale-conosco #fone, .fone').mask('(99) 9999-9999');
	$('#validade').mask('99/99/9999');
	$('#class_cnpj').mask('99999999999999');
	$('#cnpj').mask('99.999.999/9999-99');
	$('#registro').mask('999999-9');
	$('#telefone').mask('(99) 9999-9999');
	$('#registro_b').mask('999999-9');
	$('#cpf').mask('999.999.999/99');
	$('#rg').mask('9.999.999');
	$('#cep').mask('99999-999');
//	$('#num_cod1').mask('999999-9');
//	$('#num_cod2').mask('99999999999999');

	//MALDITOS IES
	if($.browser.msie){

		$('.hack-ie').css("margin-top",-5);
		$('.indicador').css("margin-left",-55);

	}

	// FORM
	$(".forms input, .forms select, .forms textarea").focus(function(){
		$(this).addClass("campo-requerido", 100);
	});
	$(".forms input, .forms select, .forms textarea").blur(function(){
		$(this).removeClass("campo-requerido", 100);
	});

	$(".bt-topo").click(function(){
		$(document).scrollTo( {top:'0px',left:'0px'}, 200 );
	});


});

/**
  * Função limpa espaço
  * @param str String
  * @return nada
  **/
function getTrim(str) {
	if(typeof(str) !== "undefined"){
		return str.replace(/^\s+|\s+$/g, "");
	}else{
		return "";
	}
}

/**
  * Função Validar Formulário
  * @param form Identificador do form
  * @return Boolean
  **/
function validarForm(form) {
    for (var i = 0; i < document.getElementById(form).elements.length; i++) {
        var nomeObj = document.getElementById(form).elements[i].name;
        var idObj 	= document.getElementById(form).elements[i].id;
		var relObj 	= document.getElementById(form).elements[i].getAttribute("rel");
		switch (relObj) {
			case "email":
				expressao = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/i;
				if (!expressao.test(document.getElementById(form).elements[i].value)) {
					alert(document.getElementById(form).elements[i].title);
					document.getElementById(form).elements[i].value = "";
					document.getElementById(form).elements[i].focus();
					return false;
				}
			break;
			case "required":
				if ((document.getElementById(form).elements[i].value == null) || (document.getElementById(form).elements[i].value == "")) {
					alert(document.getElementById(form).elements[i].title);
					document.getElementById(form).elements[i].focus();
					return false;
				}
			break;
			case "cpf":
				if ((!validaCpf(document.getElementById(form).elements[i].value)) || (document.getElementById(form).elements[i].value == null) || (document.getElementById(form).elements[i].value == "")) {
					alert(document.getElementById(form).elements[i].title);
					document.getElementById(form).elements[i].value = "";
					document.getElementById(form).elements[i].focus();
					return false;
				}
			break;
			case "cnpj":
				if ((!validaCnpj(document.getElementById(form).elements[i].value)) || (document.getElementById(form).elements[i].value == null) || (document.getElementById(form).elements[i].value == "")) {
					alert(document.getElementById(form).elements[i].title);
					document.getElementById(form).elements[i].value = "";
					document.getElementById(form).elements[i].focus();
					return false;
				}
			break;
			case "data":
				if ((!validaData(document.getElementById(form).elements[i].value)) || (document.getElementById(form).elements[i].value == null) || (document.getElementById(form).elements[i].value == "")) {
					alert(document.getElementById(form).elements[i].title);
					document.getElementById(form).elements[i].value = "";
					document.getElementById(form).elements[i].focus();
					return false;
				}
			break;
			case "radio":
			case "checkbox":
				if(getCheckedValue(document.getElementsByName(nomeObj))) {
				} else {
					alert(document.getElementById(form).elements[i].title);
					document.getElementById(form).elements[i].focus();
					return false;
				}
			break;
			default:
			break;
		}
    }
    return true;
}

/**
   * Valida form
   **/
function validaForm(form) {
    for (var i = 0; i < document.getElementById(form).elements.length; i++) {

        var nomeObj = document.getElementById(form).elements[i].name;
        var idObj 	= document.getElementById(form).elements[i].id;
		var relObj 	= document.getElementById(form).elements[i].getAttribute('rel');

		if ((relObj == "email")) {
			expressao = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/i;
			if(!expressao.test(document.getElementById(form).elements[i].value)){
				alert(document.getElementById(form).elements[i].title);
				document.getElementById(form).elements[i].value = "";
				document.getElementById(form).elements[i].className = "campo-requerido";
				document.getElementById(form).elements[i].focus();
				return false;
			}
		}else if (relObj == "required") {
			if((document.getElementById(form).elements[i].value == null) || (document.getElementById(form).elements[i].value == "")){
				alert(document.getElementById(form).elements[i].title);
				document.getElementById(form).elements[i].className = "campo-requerido";
				document.getElementById(form).elements[i].focus();
				return false;
			}
		}
    }
    return true;
}


/**
  * Função validar cadastro crea-jr
  * @param form Identificador do form
  * @return mensagem de erro
  **/
function validarCadastroCreaJr(form) {
	if (validarForm(form)) {		
		var str = $("#" + form).serialize();
		$.ajax({
			type: "POST",
			url: "lib/acao-form-crea-jr.php",
			data: str,
			success: function(txt) {
				if (getTrim(txt) == "1") {
					alert("Cadastro realizado com sucesso.");
					document.getElementById(form).reset();
				} else {
					alert("Não foi possível realizar o cadastro, tente novamente.");
				}
			}
		});
	}
}

/**
   * Certidão
   **/
function abrirCertidao() {
	width = screen.width;
	height = screen.height;
	var top = height/2;
	var left = width/2;
	top = top - 500/2 - 30;
	left = left - 760/2 - 5;
	loc = "https://www.crea-sc.org.br/creanet/valcertidao.php";
	prop = 'left='+left+',top='+top+',toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=yes,resizable=no,width=760,height=500';
	janela_certidao = window.open(loc, '', prop)
}

/**
  * Função que valida o e-mail
  * @param String $value e-mail
  * @return boolean
  **/
function validaEmail(value) {
	expressao = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/i;
	if(!expressao.test(value)) {
		return false;
	}
	return true;
}

/**
  * Função que valida CPF
  * @param String $s CPF
  * @return boolean
  **/
function validaCpf (cpf) {
	if (cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999")
		return false;
	add = 0;
	for (i=0; i < 9; i ++)
		add += parseInt(cpf.charAt(i)) * (10 - i);
	rev = 11 - (add % 11);
	if (rev == 10 || rev == 11)
		rev = 0;
	if (rev != parseInt(cpf.charAt(9)))
		return false;
	add = 0;
	for (i = 0; i < 10; i ++)
		add += parseInt(cpf.charAt(i)) * (11 - i);
	rev = 11 - (add % 11);
	if (rev == 10 || rev == 11)
		rev = 0;
	if (rev != parseInt(cpf.charAt(10)))
		return false;
	return true;
}

/**
  * Função que valida o CNPJ
  * @param String $value CNPJ
  * @return int status da validação
  **/
function validaCnpj(valor) {
	var cnpj = new Array();
	cnpj = valor;		
	var tam = cnpj.length;
	/**
	  * blacklist cnpj
	  **/		
	if (
		cnpj == '00000000000000' || 
		cnpj == '11111111111111' || 
		cnpj == '22222222222222' || 
		cnpj == '33333333333333' || 
		cnpj == '44444444444444' || 
		cnpj == '55555555555555' || 
		cnpj == '66666666666666' || 
		cnpj == '77777777777777' || 
		cnpj == '88888888888888' || 
		cnpj == '99999999999999' ||
		tam != 14 ) 
	{
		return false;
	}	
	var soma = 0;
	soma += (cnpj.charAt(0) * 5);
	soma += (cnpj.charAt(1) * 4);
	soma += (cnpj.charAt(2) * 3);
	soma += (cnpj.charAt(3) * 2);
	soma += (cnpj.charAt(4) * 9);
	soma += (cnpj.charAt(5) * 8);
	soma += (cnpj.charAt(6) * 7);
	soma += (cnpj.charAt(7) * 6);
	soma += (cnpj.charAt(8) * 5);
	soma += (cnpj.charAt(9) * 4);
	soma += (cnpj.charAt(10) * 3);
	soma += (cnpj.charAt(11) * 2);
	var d1 = soma % 11;
	d1 = d1 < 2 ? 0 : 11 - d1;
	if(cnpj.charAt(12) != d1){	
		return false;
	}
	var soma = 0;
	soma += (cnpj.charAt(0) * 6);
	soma += (cnpj.charAt(1) * 5);
	soma += (cnpj.charAt(2) * 4);
	soma += (cnpj.charAt(3) * 3);
	soma += (cnpj.charAt(4) * 2);
	soma += (cnpj.charAt(5) * 9);
	soma += (cnpj.charAt(6) * 8);
	soma += (cnpj.charAt(7) * 7);
	soma += (cnpj.charAt(8) * 6);
	soma += (cnpj.charAt(9) * 5);
	soma += (cnpj.charAt(10) * 4);
	soma += (cnpj.charAt(11) * 3);
	soma += (cnpj.charAt(12) * 2);
	var d2 = soma % 11;
	d2 = d2 < 2 ? 0 : 11 - d2;
	if (cnpj.charAt(13) != d2){
		return false;
	}
	return true;
}	

/**
   * Newsletter
   **/
function validarNewsHome() {
	var msg = "";
	var flag = false;

	if(document.getElementById("new_email").value == "") {
		flag = true;
		msg += "Campo E-mail não está preenchido.\n";
	} else {
		if(!validaEmail(document.getElementById("new_email").value)) {
			msg += "Campo E-mail inválido.\n";
			flag = true;
		}
	}

	if(flag) {
		alert(msg);
	} else {
		$.ajax( {
			type: "POST",
			url: "lib/acao_news.php",
			data: "email=" + document.getElementById("new_email").value,
			beforeSend: function() {
			},
			success: function(txt) {
				$('#mensagem').html(txt);
				document.getElementById("form-webcrea-home").reset();
			},
			error: function(txt) {
				alert('Erro: '+txt);
			}
		});
	}
}

/**
   * Newsletter
   **/
function validarNews() {
	var msg = "";
	var flag = false;

	if(document.getElementById("new_email").value == "") {
		flag = true;
		msg += "Campo E-mail não está preenchido.\n";
	} else {
		if(!validaEmail(document.getElementById("new_email").value)) {
			msg += "Campo E-mail inválido.\n";
			flag = true;
		}
	}

	if(flag) {
		alert(msg);
	} else {
		$.ajax( {
			type: "POST",
			url: "lib/acao_news.php",
			data: "email=" + document.getElementById("new_email").value,
			beforeSend: function() {
			},
			success: function(txt) {
				$('#mensagem').html(txt);
				document.getElementById("form-webcrea").reset();
			},
			error: function(txt) {
				alert('Erro: '+txt);
			}
		});
	}
}

/**
   * Creanet
   **/
function cadastrarCreaNet(acao) {
	var msg = "";
	var flag = false;
	
	if(document.getElementById("c-prof").checked == false && document.getElementById("c-emp").checked == false) {
		flag = true;
		msg += "Campo Tipo não está preenchido.\n";
	}

	if(flag) {
		alert(msg);
		return false;
	} else {
		if(document.getElementById("c-prof").checked == true) {			
			$.ajax( {
				type: "POST",
				url: "lib/acao_crea_net_novo.php",
				data: "acao=" + acao,
				beforeSend: function() {				
				},
				success: function(txt) {					
					
					width = screen.width;
					height = screen.height;
					var top = height/2;
					var left = width/2;
					top = top - 500/2 - 30;
					left = left - 760/2 - 5;			
					prop = 'left='+left+',top='+top+',toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=yes,resizable=no,width=760,height=500';			
					window.open("https://www.crea-sc.org.br/creanet/index.php", "", prop);				

				},
				error: function(txt) {
					alert('Erro: '+txt);
				}
			});
		} else {
			$.ajax( {
				type: "POST",
				url: "lib/acao_crea_net_novo.php",
				data: "acao=" + acao,
				beforeSend: function() {				
				},
				success: function(txt) {					
					
					width = screen.width;
					height = screen.height;
					var top = height/2;
					var left = width/2;
					top = top - 500/2 - 30;
					left = left - 760/2 - 5;			
					prop = 'left='+left+',top='+top+',toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=yes,resizable=no,width=760,height=500';			
					window.open("https://www.crea-sc.org.br/creanet_emp/index.php", "", prop);				

				},
				error: function(txt) {
					alert('Erro: '+txt);
				}
			});
		}
	}
}

/**
   * Creanet
   **/
function validarLoginCreanet(form) {
	var msg = "";
	var flag = false;

	if(document.getElementById("c-prof").checked == false && document.getElementById("c-emp").checked == false) {
		flag = true;
		msg += "Campo Tipo não está preenchido.\n";
	}

	if(document.getElementById("registro").value == "") {
		flag = true;
		msg += "Campo Registro não está preenchido.\n";
	}

	if(document.getElementById("senha").value == "") {
		flag = true;
		msg += "Campo Senha não está preenchido.\n";
	}

	if(flag) {
		alert(msg);
		return false;
	} else {
		if(document.getElementById("c-prof").checked == true) {
			$.ajax( {
				type: "POST",
				url: "lib/acao_crea_net.php",
				data: "temp_registro=" + document.getElementById("registro").value + "&temp_senha=" + document.getElementById("senha").value,
				beforeSend: function() {
				},
				success: function(txt) {
					width = screen.width;
					height = screen.height;
					var top = height/2;
					var left = width/2;
					top = top - 500/2 - 30;
					left = left - 760/2 - 5;
					prop = 'left='+left+',top='+top+',toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=yes,resizable=no,width=760,height=500';
					window.open("https://www.crea-sc.org.br/creanet/index.php", "", prop);
				},
				error: function(txt) {
					alert('Erro: '+txt);
				}
			});
		} else {
			$.ajax( {
				type: "POST",
				url: "lib/acao_crea_net.php",
				data: "temp_registro=" + document.getElementById("registro").value + "&temp_senha=" + document.getElementById("senha").value,
				beforeSend: function() {
				},
				success: function(txt) {
					width = screen.width;
					height = screen.height;
					var top = height/2;
					var left = width/2;
					top = top - 500/2 - 30;
					left = left - 760/2 - 5;
					prop = 'left='+left+',top='+top+',toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=yes,resizable=no,width=760,height=500';
					window.open("https://www.crea-sc.org.br/creanet_emp/index.php", "", prop);
				},
				error: function(txt) {
					alert('Erro: '+txt);
				}
			});
		}
	}
}

/**
   * Creanet
   **/
function validarLoginCreanetBar(form) {
	var msg = "";
	var flag = false;

	if(document.getElementById("c-prof").checked == false && document.getElementById("c-emp").checked == false) {
		flag = true;
		msg += "Campo Tipo não está preenchido.\n";
	}

	if(document.getElementById("registro_b").value == "") {
		flag = true;
		msg += "Campo Registro não está preenchido.\n";
	}

	if(document.getElementById("senha_b").value == "") {
		flag = true;
		msg += "Campo Senha não está preenchido.\n";
	}

	if(flag) {
		alert(msg);
	} else {
		if(document.getElementById("c-prof").checked == true) {
			width = screen.width;
			height = screen.height;
			var top = height/2;
			var left = width/2;
			top = top - 500/2 - 30;
			left = left - 760/2 - 5;
			loc = "https://www.crea-sc.org.br/creanet/index.php";
			prop = 'left='+left+',top='+top+',toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=yes,resizable=no,width=760,height=500';
			janela_certidao = window.open(loc, '', prop);
		} else {
			width = screen.width;
			height = screen.height;
			var top = height/2;
			var left = width/2;
			top = top - 500/2 - 30;
			left = left - 760/2 - 5;
			loc = "https://www.crea-sc.org.br/creanet_emp/index.php";
			prop = 'left='+left+',top='+top+',toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=yes,resizable=no,width=760,height=500';
			janela_certidao = window.open(loc, '', prop);
		}
	}
}


/**
   * Serviços
   **/
function validarServicos(form) {
	var msg = "";
	var flag = false;

	if(document.getElementById("servico").value == "") {
		flag = true;
		msg += "Campo Serviço não está preenchido.\n";
	}

	if(document.getElementById("num_cod").value == "") {
		flag = true;
		msg += "Campo Número não está preenchido.\n";
	} else {
		if(document.getElementById("servico").value == "4") {
			var resultado = document.getElementById("num_cod").value;
			if(resultado.length == 14) {
				if(!validaCnpj(resultado)) {
					flag = true;
					msg += 'Campo "CNPJ" inválido.\n';
				}
			} else if(resultado.length == 11) {
				if(!validaCpf(resultado)) {
					flag = true;
					msg += 'Campo "CPF" inválido.\n';
				}
			} else {
				flag = true;
				msg += 'Preencha um "CPF" ou "CNPJ" válido.\n';
			}		
		}
	}

	if(flag == true) {
		alert(msg);
		return false;
	} else {
		if(document.getElementById("servico").value == 4) {
			document.getElementById(form).target = "tela_servicos";
			document.getElementById(form).action = "http://www.crea-sc.org.br/portal/incs/pop-servicos.php";
			
			width = screen.width;
			height = screen.height;
			var top = height/2;
			var left = width/2;
			top = top - 500/2 - 30;
			left = left - 760/2 - 5;
			loc = "https://www.crea-sc.org.br/creanet_emp/index.php";
			prop = 'left='+left+',top='+top+',toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=yes,resizable=no,width=760,height=500';
			window.open("about:blank" ,"tela_servicos", prop);
		} else {
			document.getElementById(form).target = "";
			document.getElementById(form).action = "index.php?cmd=emissao-boleto";
			document.getElementById(form).submit();
		}
	}
	
}

/**
   * Busca
   **/
function validarBusca() {
	var msg = "";
	var flag = false;

	if(document.getElementById("search").value == "") {
		flag = true;
		msg += "Campo Busca não está preenchido.\n";
	} else {
		valor = document.getElementById('search').value;
		if(valor.length < 4) {
			flag = true;
			msg += "Campo Busca inválido, digite no mínimo 4(quatro) caracteres.\n";
		}
	}

	if(flag) {
		alert(msg);
	} else {
		document.getElementById("formBusca").submit();
	}
}

/**
   * Busca Interna
   **/
function validarBuscaInterna() {
	var msg = "";
	var flag = false;

	if(document.getElementById("input-search").value == "") {
		flag = true;
		msg += "Campo Busca não está preenchido.\n";
	} else {
		valor = document.getElementById('input-search').value;
		if(valor.length <= 4) {
			flag = true;
			msg += "Campo Busca inválido, digite no mínimo 5(cinco) caracteres.\n";
		}
	}

	if(flag) {
		alert(msg);
		document.getElementById("input-search").focus();
	} else {
		document.getElementById("formBuscaInterna").submit();
	}
}

/**
   * Validar Contato
   **/
function validarContato() {
	if(validaForm('formContato')) {

		$.ajax( {
			type: "POST",
			url: "lib/acao_contato.php",
			data: "con_nome=" + $("#nome").val() + "&con_telefone=" + $("#fone").val() + "&con_email=" + $("#email").val() + "&con_area_desejada=" + $("#area_desejada").val() + "&con_assunto=" + $("#assunto").val() + "&con_mensagem=" + $("#msg").val(),
			beforeSend: function() {
			},
			success: function(txt) {
				alert("Mensagem enviada com sucesso, em breve entraremos em contato! Obrigado!");
				document.getElementById("formContato").reset();
			},
			error: function(txt) {
				alert('Erro: '+txt);
			}
		});
	}
}

/**
   * Validar Contato
   **/
function validarDenuncia() {
	if(validaForm('formDenuncia')) {
		$.ajax( {
			type: "POST",
			url: "lib/acao_denuncia.php",
			data: "den_nome=" + $("#den_nome").val() + "&den_email=" + $("#den_email").val() + "&den_cidade=" + $("#den_cidade").val() + "&den_denuncia=" + $("#den_denuncia").val() + "&con_mensagem=" + $("#msg").val(),
			beforeSend: function() {
			},
			success: function(txt) {
				alert("Mensagem enviada com sucesso, em breve entraremos em contato! Obrigado!");
				document.getElementById("formDenuncia").reset();
			},
			error: function(txt) {
				alert('Erro: '+txt);
			}
		});
	}
}

/**
   * Votar enquete
   **/
function votarEnquete(pergunta, quant) {
	var flag = 0;
	var resposta = "";

	if(quant > 0) {
		for(i = 1; i <= quant; i++) {
			if(document.getElementById("respota" + i).checked == true) {
				resposta = document.getElementById("respota" + i).value;
			}
		}
	}

	if(resposta == "") {
		alert("Selecione uma resposta!");
	} else {
		$.ajax( {
			type: "POST",
			url: "lib/acao_enquete.php",
			data: "fk_enquete=" + pergunta + "&fk_topico=" + resposta,
			beforeSend: function() {
			},
			success: function(txt) {
				alert(txt);
				//resultadoEnquete(pergunta);
			},
			error: function(txt) {
				alert('Erro: '+txt);
			}
		});
	}
}

/**
   * Resultado Enquete
   **/
function resultadoEnquete(pergunta) {
	$.ajax( {
		type: "POST",
		url: "lib/resultado_enquete.php",
		data: "fk_enquete=" + pergunta,
		beforeSend: function() {
		},
		success: function(txt) {
//            $('#enquete-exibe').html(txt);
            document.getElementById("enquete-exibe").innerHTML=txt;
		},
		error: function(txt) {
			alert('Erro: '+txt);
		}
	});
}

/**
   * Validar Eventos
   **/
function validarEventos() {
	var msg = "";
	var flag = false;

	if(document.getElementById("evento").value == "") {
		flag = true;
		msg += "Campo Busca eventos não está preenchido.\n";
	}

	if(flag) {
		alert(msg);
	} else {
		document.getElementById("encontre-um-evento").submit();
	}
}

/**
   * Validar Vagas
   **/
function validarVagas() {
	var msg = "";
	var flag = false;

	if(document.getElementById("cargo").value == "") {
		flag = true;
		msg += "Campo Cargo não está preenchido.\n";
	}

	if(document.getElementById("validade").value == "") {
		flag = true;
		msg += "Campo Validade do Anúncio não está preenchido.\n";
	}

	if(flag) {
		alert(msg);
	} else {
		document.getElementById("form-cadastrar-currirulos").submit();
		document.getElementById("form-cadastrar-currirulos").reset();
	}
}

/**
   * Validar Currículos
   **/
function validarCurriculos() {
	var msg = "";
	var flag = false;

	if(document.getElementById("tipo1").checked == true) {
		if(document.getElementById("registro").value == "") {
			flag = true;
			msg += "Campo Registro não está preenchido.\n";
		}
	}

	if(document.getElementById("nome").value == "") {
		flag = true;
		msg += "Campo Nome não está preenchido.\n";
	}

	if(document.getElementById("email").value == "") {
		flag = true;
		msg += "Campo E-mail não está preenchido.\n";
	} else {
		if(!validaEmail(document.getElementById("email").value)) {
			msg += "Campo E-mail inválido.\n";
			flag = true;
		}
	}

	if(document.getElementById("senha").value == "") {
		flag = true;
		msg += "Campo Senha não está preenchido.\n";
	}

	if(document.getElementById("nome").value == "") {
		flag = true;
		msg += "Campo Nome não está preenchido.\n";
	}

	if(document.getElementById("fk_especialidade").value == "") {
		flag = true;
		msg += "Campo Especialidade não está preenchido.\n";
	}

	if(flag) {
		alert(msg);
	} else {
		document.getElementById("form-cadastrar-currirulos").submit();
		document.getElementById("form-cadastrar-currirulos").reset();
	}
}

function mostrarVideo(id) {
	$.ajax( {
		type: "GET",
		url: "lib/acao_videos.php",
		data: "id=" + id,
		beforeSend: function() {
		},
		success: function(txt) {
			$('#div_video').html(txt).hide().fadeIn(500);
		},
		error: function(txt) {
			alert('Erro: '+txt);
		}
	});
}

/**
   * Validar Enviar E-mail
   **/
function validarEnviarEmail() {
	var msg = "";
	var flag = false;

	if(document.getElementById("seu-nome").value == "") {
		flag = true;
		msg += "Campo Seu nome não está preenchido.\n";
	}

	if(document.getElementById("seu-email").value == "") {
		flag = true;
		msg += "Campo Seu e-mail não está preenchido.\n";
	} else {
		if(!validaEmail(document.getElementById("seu-email").value)) {
			msg += "Campo Seu e-mail inválido.\n";
			flag = true;
		}
	}

	if(document.getElementById("emails-envio").value == "") {
		flag = true;
		msg += "Campo E-mails para envio não está preenchido.\n";
	}

	if(document.getElementById("msg").value == "") {
		flag = true;
		msg += "Campo Digite uma mensagem não está preenchido.\n";
	}

	if(flag) {
		alert(msg);
	} else {
		$.ajax( {
			type: "POST",
			url: "lib/acao_enviar_email.php",
			data: "nome=" + $("#seu-nome").val() + "&email=" + $("#seu-email").val() + "&email_envio=" + $("#emails-envio").val() + "&msg=" + $("#msg").val() + "&link=" + escape($("#link").val()),
			beforeSend: function() {
			},
			success: function(txt) {
				alert("Mensagem enviada com sucesso. Obrigado!");
				document.getElementById("form-enviar-email").reset();
			},
			error: function(txt) {
				alert('Erro: '+txt);
			}
		});
	}
}

/**
   * Validar
   **/
function validarLoginEmpregos() {
	var msg = "";
	var flag = false;

	if(document.getElementById("emp_tipo").value == "") {
		flag = true;
		msg += "Campo Usuário não está preenchido.\n";
	}

	if(document.getElementById("emp_email").value == "") {
		flag = true;
		msg += "Campo E-mail não está preenchido.\n";
	} else {
		if(!validaEmail(document.getElementById("emp_email").value)) {
			msg += "Campo E-mail inválido.\n";
			flag = true;
		}
	}

	if(document.getElementById("emp_senha").value == "") {
		flag = true;
		msg += "Campo Senha não está preenchido.\n";
	}

	if(flag) {
		alert(msg);
	} else {
		document.getElementById("form-emprego").submit();
		document.getElementById("form-emprego").reset();
	}
}

/**
   * Validar
   **/
function validarSenhaLoginEmpregos() {
	var msg = "";
	var flag = false;

	if(document.getElementById("sen_emp_email").value == "") {
		flag = true;
		msg += "Campo E-mail não está preenchido.\n";
	} else {
		if(!validaEmail(document.getElementById("sen_emp_email").value)) {
			msg += "Campo E-mail inválido.\n";
			flag = true;
		}
	}

	if(flag) {
		alert(msg);
	} else {
		document.getElementById("form-senha-emprego").submit();
		//document.getElementById("form-senha-emprego").reset();
	}
}

/**
   * Validar Empresas
   **/
function validarEmpresas() {
	var msg = "";
	var flag = false;

	if(document.getElementById("razao").value == "") {
		flag = true;
		msg += "Campo Razão Social não está preenchido.\n";
	}

	if(document.getElementById("fantasia").value == "") {
		flag = true;
		msg += "Campo Fantasia não está preenchido.\n";
	}

	if(document.getElementById("cnpj").value == "") {
		flag = true;
		msg += "Campo CNPJ não está preenchido.\n";
	}

	if(document.getElementById("email").value == "") {
		flag = true;
		msg += "Campo E-mail não está preenchido.\n";
	} else {
		if(!validaEmail(document.getElementById("email").value)) {
			msg += "Campo E-mail inválido.\n";
			flag = true;
		}
	}

	if(document.getElementById("senha").value == "") {
		flag = true;
		msg += "Campo Senha não está preenchido.\n";
	}

	if(flag) {
		alert(msg);
	} else {
		document.getElementById("form-cadastrar-currirulos").submit();
		document.getElementById("form-cadastrar-currirulos").reset();
	}
}

function excluirVaga(id) {
	if(confirm("Deseja realmente excluir a vaga?")) {
		window.location = "lib/acao_vaga_excluir.php?fk_vaga=" + id;
	}
}

function excluirCurriculo() {
	if(confirm("Deseja realmente excluir seu currículo?")) {
		window.location = "lib/acao_curriculo_excluir.php";
	}
}

function validarFiltroEmpresa() {
	var msg = "";
	var flag = false;

	if((document.getElementById("razao").value == "") && (document.getElementById("municipio").value == "")) {
		flag = true;
		msg += "É necessário o preenchimento do campo nome ou cidade.\n";
	}

	temp_razao = document.getElementById("razao").value;

	if((document.getElementById("razao").value != "") && (temp_razao.length < 4)) {
		flag = true;
		msg += "É necessário o preenchimento do campo nome com no mínimo 4 caracteres.\n";
	}

	temp_municipio = document.getElementById("municipio").value;

	if((document.getElementById("municipio").value != "") && (temp_municipio.length < 3)) {
		flag = true;
		msg += "É necessário o preenchimento do campo cidade com no mínimo 3 caracteres.\n";
	}

	if(flag) {
		alert(msg);
	} else {
		document.getElementById("form-search-empresa").submit();
	}
}

function validarFiltroProfissional() {
	var msg = "";
	var flag = false;
	var cont = 0;

	if((document.getElementById("nome").value == "") && (document.getElementById("nroreg").value == "") && (document.getElementById("cidade").value == "")) {
		flag = true;
		msg += "É necessário o preenchimento do campo nome ou título ou cidade.\n";
	}

	if(document.getElementById("nome").value != "") {
		cont++;
	}

	if(document.getElementById("nroreg").value != "") {
		cont++;
	}

	if(document.getElementById("cidade").value != "") {
		cont++;
	}

	if(cont == 1) {
		temp_nome = document.getElementById("nome").value;

		if((document.getElementById("nome").value != "") && (temp_nome.length < 5)) {
			flag = true;
			msg += "É necessário o preenchimento do campo nome com no mínimo 5 caracteres.\n";
		}

		temp_nroreg = document.getElementById("nroreg").value;

		if((document.getElementById("nroreg").value != "") && (temp_nroreg.length < 5)) {
			flag = true;
			msg += "É necessário o preenchimento do campo título com no mínimo 5 caracteres.\n";
		}

		temp_cidade = document.getElementById("cidade").value;

		if((document.getElementById("cidade").value != "") && (temp_cidade.length < 5)) {
			flag = true;
			msg += "É necessário o preenchimento do campo cidade com no mínimo 5 caracteres.\n";
		}
	}

	if(flag) {
		alert(msg);
	} else {
		document.getElementById("form-search-profissional").submit();
	}
}

/**
 * Formata um CPF ou CNPJ em inteiro, ou seja, remove, os ".", "/" e "-"
 * @param $id_federal String CPF ou CNPF
 * @return String número formatado
 **/
function idFederalToInt(id_federal){
	var retorno = "";
	return retorno = id_federal.replace(/\D/g,'');		
}

/**
  * Formata número
  * @param $campo int id
  * @param $event Evento
  * @return String 
  **/
function formataNumero(campo, e) {
	t = typeof window.event != "undefined" ? window.event.keyCode : e.which;
	if((isNaN(String.fromCharCode(t)) || (t == 32)) && (t != 8 && t != 0)) {
		return false;
	}
}

function trocarMascaraServico(id) {
	$('#num_cod').unmask();
	if((id == 2) || (id == 3)) {        
		$('#num_cod').mask('999999-9');
	} else if(id == 1) {        
		$('#num_cod').mask('9999999-9');
	} else if(id == 4) {
		document.getElementById("num_cod").value = idFederalToInt(document.getElementById("num_cod").value);
		document.getElementById("num_cod").maxlength = "14";
	}
}


/* Outros Serviços */
function servicos_outros(id){
	
	switch(id){
		case 1:
		window.location = 'index.php?cmd=empregos';
		break;

		case 2:
		abrirCertidao();
		break;

		case 3:
		window.location = 'index.php?cmd=profissionais-habilitados';
		break;

		case 4:
		window.location = 'index.php?cmd=empresas-habilitadas';
		break;

		case 5:
		window.location = 'lib/download.php?id=249';
		break;
	}

}

