// JavaScript Document
var __idl = 0;
var __ntel = '';
var __datosUsuario = '';
var __sistemasAccesados = "";
var __movil = "";

jQuery(document).ready(
	function(){
		jQuery('input, select, textarea')
		.filter(
			function (index) {
            	return jQuery(this).hasClass('lectura') == false;
         	}
		)
		.live({
			focusin: function(){ jQuery(this).addClass('focus'); },
			focusout: function(){ jQuery(this).removeClass('focus'); }
		});
		
		jQuery(".mayusculas").live('focusout', function(){ jQuery(this).val(jQuery(this).val().toUpperCase()); });

		var _url = '/intranet/index/index';
		var _data = { cache: Math.random() * 999999 };
		jQuery.ajaxSetup({async:true});
		jQuery.post(_url, _data,
			function(_rtnAjax){
					innerHTML('content', _rtnAjax);
				
					jQuery('#txt__LoginUsuario').focus();
				
					jQuery('#btn__LoginIniciar').click(Intranet_Login);
					
					jQuery(".opcion_sistema")
					.live("click",
						function(){
							Intranet_MenuOpcion(jQuery(this).attr("id"));
						}
					);
				Intranet_DetectaMovil();
			}
		);
	}
);

function Intranet_DetectaMovil(){
	var _url = '/intranet/index/detectamovil';
	var _data = { cache: Math.random() * 999999	};
	jQuery.post(_url, _data,
		function(_rtnAjax){
			__movil = jQuery.trim(_rtnAjax);
		}
	);
}

function Intranet_Login(){
	var _url = '/intranet/index/login';
	var _data = { cache: Math.random() * 999999
				, pUsuario : jQuery("#txt__LoginUsuario").val()
				, pClave : hex_md5(jQuery("#txt__LoginClave").val())
				};
	jQuery.post(_url, _data,
		function(_rtnAjax){	
			var _html = _rtnAjax.split('&yen;');

			if( jQuery.trim(_html[0]) != "" ){ jAlert(_html[0], "MENSAJE DEL SISTEMA"); return false; }
			if( jQuery.trim(_html[1]) != "0" ){ jAlert("USUARIO &oacute; CONTRASE&Ntilde;A ingresada <strong>NO SON VALIDAS</strong>", "MENSAJE DEL SISTEMA"); return false; }

			__datosUsuario = _html[2].split("|");
			__sistemasAccesados = _html[3];
			
			Intranet_Sistemas();
		}
	);	
}

function Intranet_Sistemas(){
	var _url = "/intranet/index/sistemas";
	var _data = { cache: Math.random() * 999999 };
	jQuery.ajaxSetup({async:true});
	jQuery.post(_url, _data,
		function(rtnAjax){
			innerHTML("content", rtnAjax);
			jQuery(__sistemasAccesados)
			.each(
				function(){
					jQuery("#td__" + jQuery(this).attr("id")).removeClass("intranet_Inactiva");
				}
			);
			jQuery(__sistemasAccesados).addClass("opcion_sistema");
			
			jQuery("#span_piap_usuario").html(__datosUsuario[1].toUpperCase());
			jQuery("#span_piap_idusuario").html(__datosUsuario[0]);
			jQuery("#span_piap_area").html(__datosUsuario[2]);
			jQuery("#span_piap_nomusuario").html(__datosUsuario[4]);
			jQuery("#span_piap_areageneral").html(__datosUsuario[3]);
			jQuery("#span_piap_areadescripcion").html(__datosUsuario[3]);
			session = __datosUsuario[6].split("<br />");
			
			jQuery("#span_piap_idareageneral").html(session[0]);
			
			jQuery(window).resize(Intranet_Resize);
			
			Intranet_Resize();
		}	
	);
}

function Intranet_Resize(){
	if( __movil == "" ){
		jQuery("#div__Intranet-Sistemas-contenido")
		.css("overflow", "scroll")
		.css("overflow-x", "hidden")
		.css(
			{ height:jQuery(window).height() - jQuery("#div__Intranet-Sistemas-header1").outerHeight() - jQuery("#div__Intranet-Sistemas-header2").outerHeight() 
			, width:jQuery(window).width() 
			}
		);
	}
}

function Intranet_MenuOpcion(opc){
	var _VentanaExterna = _VentanaURL = _VentanaNombre = _VentanaParametros = "";
	switch( opc ){
		case "ftp":
			_VentanaExterna = "VentSistema_FTP";
			_VentanaURL = "ftp://192.168.10.210/areas";
			_VentanaNombre = "FTP";
			_VentanaParametros = "width=1024,height=720,resizable=1";
			break;
		case "ftp_iso":
			_VentanaExterna = "VentSistema_FTPISO";
			_VentanaURL = "ftp://192.168.10.210/iso";
			_VentanaNombre = "FTPiso";
			_VentanaParametros = "width=1024,height=720,resizable=1";
			break;
		case "SIST_INFODISTRITAL":
			_VentanaExterna = "VentSistema_InfoDistrital";
			_VentanaURL = "../../mapas/sinc2.htm";
			_VentanaNombre = "InfoDistrital";
			_VentanaParametros = "width=1024,height=720,resizable=1";
			break;
		case "SIST_ADMINISTRATIVO":
			_VentanaExterna = "VentSistema_Admi";
			_VentanaURL = "http://192.168.10.195/sig/";
			_VentanaNombre = "Administrativo";
			_VentanaParametros = "width=1024,height=720,resizable=1";
			break;
		case "SIST_ADMIN2010":
			_VentanaExterna = "VentSistema_Admi2010";
			_VentanaURL = "../../sispresupuestal/contenido/index.php";
			_VentanaNombre = "Administrativo2010";
			_VentanaParametros = "width=900,height=720,resizable=1";
			break;
		case "SIST_MULTASADM":
			_VentanaExterna = "VentModulo_Multas";
			_VentanaURL = "../../multas/contenido/index.php";
			_VentanaNombre = "ModduloMultas";
			_VentanaParametros = "width=1024,height=720,resizable=1";
			break;
		case "SIST_INFOLINEA":
			_VentanaExterna = "VentSistema_Inflinea";
			_VentanaURL = "../../sis_gerencial/index.php";
			_VentanaNombre = "InformacionLinea";
			_VentanaParametros = "width=1024,height=720,resizable=1";
			break;
		case "SIST_SEGURIDAD":
			_VentanaExterna = "VentSistema_Seguridad";
			_VentanaURL = "/?IniModule=SIST_SEGURIDAD";
			_VentanaNombre = "Seguridad";
			_VentanaParametros = "width=1024,height=720,resizable=1";
			break;
		case "SIST_OBSERVATORIOSOCIAL":
			_VentanaExterna = "VentSistema_ObservatorioSocial";
			_VentanaURL = "/?IniModule=SIST_OBSERVATORIOVECINAL";
			_VentanaNombre = "Observatoriosocial";
			_VentanaParametros = "width=1024,height=720,resizable=1";
			break;			
		case "SIST_PIAP":
			_VentanaExterna = "VentSistema_PIAP";
			_VentanaURL = "../../sig/piap.php";
			_VentanaNombre = "PIAP";
			_VentanaParametros = "width=1000,height=720,resizable=1";
			break;
		case "SIST_TRAMITE":
			_VentanaExterna = "VentSistema_Tramite";
			_VentanaURL = "../../tramite_msb/index.php";
			//if( __IPCliente == "192.168.12.9"  )	_VentanaURL = "/?IniModule=SIST_TRAMITE";
			_VentanaNombre = "Tramite";
			_VentanaParametros = "width=1024,height=720,resizable=1";
			break;
		case "SIST_CARGOS":
			_VentanaExterna = "VentSistema_Cargos";
			_VentanaURL = "../../sist_cargos/index.php";
			_VentanaNombre = "CargosNotificacion";
			_VentanaParametros = "width=1024,height=720,resizable=0";
			break;
		case "SIST_QUEJAS":
			_VentanaExterna = "VentSistema_Quejas";
			_VentanaURL = "../../sist_quejas/index.php";
			_VentanaNombre = "Quejas";
			_VentanaParametros = "width=1024,height=720,resizable=0";
			break;
		case "SIST_SAM":
			_VentanaExterna = "VentSistema_SAM";
			_VentanaURL = "/?IniModule=SIST_SAM";
			_VentanaNombre = "Sam";
			_VentanaParametros = "width=1024,height=720,resizable=0";
			break;
		case "SIST_SISTEMAS":
			_VentanaExterna = "VentSistema_Sistemas";
			_VentanaURL = "../../sistemas/index.php";
			_VentanaNombre = "Sistemas";
			_VentanaParametros = "width=1024,height=720,resizable=0";
			break;
		case "SIST_CATASTRO":
			_VentanaExterna = "VentSistema_Catastro";
			_VentanaURL = "/?IniModule=SIST_CATASTRO";
			_VentanaNombre = "Catastro";
			_VentanaParametros = "width=1024,height=720,resizable=0";
			break;
		case "SIST_REGISTROTRIBUTARIO":
			_VentanaExterna = "VentSistema_RegistroTributario";
			_VentanaURL = "/?IniModule=SIST_REGISTROTRIBUTARIO";
			_VentanaNombre = "RegistroTributario";
			_VentanaParametros = "width=1024,height=720,resizable=0";
			break;
		case "SIST_RECAUDACION":
			_VentanaExterna = "VentSistema_Recaudacion";
			_VentanaURL = "/?IniModule=SIST_RECAUDACION";
			_VentanaNombre = "RecaudacionTributaria";
			_VentanaParametros = "width=1024,height=720,resizable=0";
			break;
		case "SIST_COACTIVO":
			_VentanaExterna = "VentSistema_Coactivo";
			_VentanaURL = "/?IniModule=SIST_COACTIVO";
			_VentanaNombre = "CobranzaCoactiva";
			_VentanaParametros = "width=1024,height=720,resizable=0";
			break;
		case "SIST_REQUERIMIENTO":
			_VentanaExterna = "VentSistema_Requerimiento";
			_VentanaURL = "../../req_software/index.php";
			_VentanaNombre = "RequerimientoSoftware";
			_VentanaParametros = "width=1024,height=720,resizable=0";
			break;
		case "SIST_CTRLURBANO":
			_VentanaExterna = "VentSistema_ControlUrbano";
			_VentanaURL = "/?IniModule=SIST_CTRLURBANO";
			_VentanaNombre = "ControlUrbano";
			_VentanaParametros = "width=1024,height=720,resizable=0";
			break;
		case "SIST_OBRASPRIVADAS":
			_VentanaExterna = "VentSistema_ObrasPrivadas";
			_VentanaURL = "/?IniModule=SIST_OBRASPRIVADAS";
			_VentanaNombre = "ObrasPrivadas";
			_VentanaParametros = "width=1024,height=720,resizable=0";
			break;
		case "SIST_MULTAS":
			_VentanaExterna = "VentSistema_NotificacionesMultas";
			_VentanaURL = "/?IniModule=SIST_MULTAS";
			_VentanaNombre = "NotificacionesMultas";
			_VentanaParametros = "width=1024,height=720,resizable=0";
			break;
		case "SIST_AGENDAACTIVIDAD":
			_VentanaExterna = "VentSistema_AgendaActividad";
			_VentanaURL = "/?IniModule=SIST_AGENDAACTIVIDAD";
			_VentanaNombre = "AgendaActividad";
			_VentanaParametros = "width=1024,height=720,resizable=0";
			break;
		case "SIST_CUNA":
			_VentanaExterna = "VentSistema_CunaMunicipal";
			_VentanaURL = "../../cuna2/index.php";
			_VentanaNombre = "CunaMunicipal";
			_VentanaParametros = "width=1024,height=720,resizable=0";
			break;
	}
	
	if( __movil == "" ){
		eval(_VentanaExterna + " = window.open('" + _VentanaURL + "', '" + _VentanaNombre + "', '" + _VentanaParametros + "'); " + _VentanaExterna + " .focus();");
	} else{ 
		eval("location.href = '" + _VentanaURL +"';");
	}
}
