/** ========== JS INICIANDO O SISTEMA E VERIFICANDO ULTIMO MENU ACESSADO ==========**/
	
	 $(document).ready(function() {
 		 // some code here
		 var aLocation = location.href.split("#");
		if(aLocation[3] != undefined){
		 getMenuPag(aLocation[1],aLocation[2],aLocation[3]);
		}else{
		 if(aLocation[1] != undefined){
			 getMenu(aLocation[1],aLocation[2]);
		 }else{
			 getMenu('SYSTEM');
		 }
		}
		relogio();
		
		$("#loading")
		.ajaxStart(function(){
			$(this).show();
			$(this).html("Aguarde...");
		})
		.ajaxComplete(function(){
			$(this).hide();
		});
		
	 });
	 
	
	/** ========== MENU DO SISTEMA NAO ALTERAR ==========**/
	
	function geraMenuPrincipal(){
		var params = "Param=Menu";
		$.ajax({
			type: "POST",
			url: "controller/controller.php",
			data: params,
			success: function(data){
				
				$("#MenuDinamico").html(data);	
			}
		});	
	}
	function getMenu(Menu,ParamModule){
		
		var params = "Param="+Menu+"&ParamModule="+ParamModule;

		$("#loading")
			.ajaxStart(function(){
				$(this).show();
				$(this).html("Aguarde...");
			})
			.ajaxComplete(function(){
				$(this).hide();
		});
				
		$.ajax({
			type: "POST",
			url: "controller/controller.php",
			data: params,
			success: function(data){
				$("#contentcolumn").html(data);	
			}
		});
	}

	function getMenuPag(Menu,ParamModule,PaginaAtual){		
		var params = "Param="+Menu+"&ParamModule="+ParamModule+"&PaginaAtual="+PaginaAtual+"&QntPag="+$("select[@name=QntPag]").val();
		
		$.ajax({
			type: "POST",
			url: "controller/controller.php",
			data: params,
			success: function(data){
				$("#contentcolumn").html(data);	
			}
		});	
	}
	
	function getMenuRapido(Menu,ParamModule){

		var params = "Param="+$("select[@name=selMenuRapido]").val()+"&ParamModule="+ParamModule;
		
		$.ajax({
			type: "POST",
			url: "controller/controller.php",
			data: params,
			success: function(data){
				$("#contentcolumn").html(data);	
			}
		});	
	}
	 
	/** ========== VALIDA ==========**/
	 
	function isMail(pVal){
		reEmail3 = /^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
		return reEmail3.test(pVal);
	}
	function isIp(pVal){
		reEmail3 = /(([0-1]?[0-9]{1,2}\.)|(2[0-4][0-9]\.)|(25[0-5]\.)){3}(([0-1]?[0-9]{1,2})|(2[0-4][0-9])|(25[0-5]))/;
		return reEmail3.test(pVal);
	}
	
	

        	function isDate(pVal){
        		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}$/;
        		//reEmail3 = /(([0-1]?[0-9]{1,2}\.)|(2[0-4][0-9]\.)|(25[0-5]\.)){3}(([0-1]?[0-9]{1,2})|(2[0-4][0-9])|(25[0-5]))/;
        		return reDate5.test(pVal);
        	} 
        	function isTime(pVal){
//        		reTime2 = /^([0-1]\d|2[0-3]):[0-5]\d$/;
        		reTime4 = /^\d+:[0-5]\d:[0-5]\d$/;

        		//reEmail3 = /(([0-1]?[0-9]{1,2}\.)|(2[0-4][0-9]\.)|(25[0-5]\.)){3}(([0-1]?[0-9]{1,2})|(2[0-4][0-9])|(25[0-5]))/;
        		return reTime4.test(pVal);
        	}    
            
	function formatar(mascara, documento){
		  var i = documento.value.length;
		  var saida = mascara.substring(0,1);
		  var texto = mascara.substring(i)
		  
		  if (texto.substring(0,1) != saida){
			documento.value += texto.substring(0,1);
		  }
	}
	/** ========== EXTRA CNS ==========**/
	
	function CNSsubmeter(){
			if(document.frmSUS.co_acesso.value == "")
			{
				alert("Preenchimento Obrigatrio.");
				document.frmSUS.co_acesso.focus();
				return false;
			}
			if(document.frmSUS.c_usuario.value == "")
			{
				alert("Preenchimento Obrigatrio.");
				document.frmSUS.c_usuario.focus();
				return false;
			}
			if(document.frmSUS.c_senha.value == "")
			{
				alert("Preenchimento Obrigatrio.");
				document.frmSUS.c_senha.focus();
				return false;
			}
		  	document.frmSUS.btnentrar.style.visibility = "hidden"
			document.frmSUS.varaux.value = '1';
			//document.frmSUS.submit();
		}
		function help(){
				window.open("http://cadweb.datasus.gov.br/helpSistema/SUS0001_AcessoSistema.asp","","width=790, height=540, left=0, top=0")		
		}
		/** ========== ---- ==========**/
	  	function oPopGlobal(target,w,h,t){
			  window.open(target,'Relatorio','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width='+w+',height='+h+',top=10,left='+t+'');  
	  	}
		function relogio(){
			var params = "Param=Relogio";
			$.ajax({
				type: "POST",
				url: "controller/controller.php",
				data: params,
				success: function(data){
					$("#Relogio").html(data);		
				}
			});
			setTimeout("relogio()",12000);
		}