var dominio_id = "14";

function SomenteNumero(e){
    var tecla=(window.event)?event.keyCode:e.which;   
    if((tecla>47 && tecla<58)) return true;
    else{
    	if (tecla==8 || tecla==0) return true;
	else  return false;
    }
}


function initMenu(){
	//alert('testeeee');
	$('#menu ul').hide();
	$('#menu li a').click( 
		function() {
			var checkElement = $(this).next();
			if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
				$('#menu ul:visible').slideUp('normal');
				return false;
				
			}
			if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
				$('#menu ul:visible').slideUp('normal');
				checkElement.slideDown('normal');
				return false;
			 }
		}
	);
}	

function CarregaPage(page, param){
	
	if ( $('#DadosSalvos').val() == "NAO"){
		AbreMensagem("Existem dados n&atilde;o salvos. Clique em SALVAR ou se preferir, clique em CANCELAR !!","mensagem_erro");	
		exit;
	}
	
	$('#conteudo').html("");
	$('#conteudo').hide("fast");
	$('#conteudo').load("conteudo/" + page + ".php",{parametros:param});
	$('#conteudo').show("fast");
	
	//$('#menu ul').hide("slow");
	
}

function CarregaCalendario(){
	$.colorbox({
		width:"90%",
		height:"80%",
		iframe:true,
		overlayClose:false,
		opacity:0.50,
		speed:50,
		href:"conteudo/agenda/wdCalendar/sample.php"
		//href:"http://www.web-delicious.com/jquery-plugins-demo/wdCalendar/sample.php"
	});
}

function AbreMensagem(msg, tipo){
	
	$('#var_'+tipo+'').html(msg);
	$.colorbox({
		width:"500px",
		inline:true,
		escKey:false,
		overlayClose:false,
		opacity:0.50,
		speed:50,
		href:"#"+tipo+""
	});
	//setTimeout(FechaMensagem,3000);

}

function TelaPermissao(msg, tipo, param){
	
	$('#var_'+tipo+'').html(msg);
	$('#dominios_empresas').html(param);
	$.colorbox.close();
	$.colorbox({
		width:"350px",
		inline:true,
		escKey:false,
		overlayClose:false,
		opacity:0.50,
		speed:50,
		href:"#"+tipo+""
	});
	//setTimeout(FechaMensagem,3000);

}

function FechaMensagem(){
	$.colorbox.close();
}

function Formatar(src, mascara) {
	var campo = src.value.length;
	var saida = mascara.substring(0,1);
	var texto = mascara.substring(campo);
	if(texto.substring(0,1) != saida) {
		src.value += texto.substring(0,1);
	}
}

function checkMail(mail){
	var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
	if(!er.test(mail)){ 
		return "erro";
	}else{
		return "ok";
	}
}

function valida_cpf(cpf){
	var numeros, digitos, soma, i, resultado, digitos_iguais;
	digitos_iguais = 1;
	exp = /\.|\-/g
    cpf = cpf.toString().replace( exp, "" );
	if (cpf.length < 11)
		return false;
	for (i = 0; i < cpf.length - 1; i++)
		if (cpf.charAt(i) != cpf.charAt(i + 1))
			  {
			  digitos_iguais = 0;
			  break;
			  }
	if (!digitos_iguais)
		{
		numeros = cpf.substring(0,9);
		digitos = cpf.substring(9);
		soma = 0;
		for (i = 10; i > 1; i--)
			  soma += numeros.charAt(10 - i) * i;
		resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
		if (resultado != digitos.charAt(0))
			  return false;
		numeros = cpf.substring(0,10);
		soma = 0;
		for (i = 11; i > 1; i--)
			  soma += numeros.charAt(11 - i) * i;
		resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
		if (resultado != digitos.charAt(1))
			  return false;
		return true;
		}
	else
		return false;
}

function validarData(campo){
	var expReg = /^(([0-2]\d|[3][0-1])\/([0]\d|[1][0-2])\/[1-2][0-9]\d{2})$/;
	if ((campo.match(expReg)) && (campo !='')){
		var dia = campo.substring(0,2);
		var mes = campo.substring(3,5);
		var ano = campo.substring(6,10);
		if( (mes==4 || mes==6 || mes==9 || mes==11) && dia > 30){
			return false;
		}else{
			if(ano%4!=0 && mes==2 && dia>28){
				return false;
			}else{
				if(ano%4==0 && mes==2 && dia>29){
					return false;
				}else{
					return true;
				}
			}
		}
	} else {
		return false;
	}
}


