<!DOCTYPE html>
<%@include file="/jsp/common/taglibs.jsp"%>

<c:set var="contextPath" value="${pageContext.request.contextPath}" scope="request" />

<%@ page import="java.util.List, java.text.DecimalFormat, java.util.Random, java.util.Date, java.text.SimpleDateFormat, 
                 com.mx.dla.admin.dtos.MenuDTO, com.mx.dla.admin.dtos.UsuarioDTO"%>

<%
	UsuarioDTO usuario 	= (UsuarioDTO) session.getAttribute("usuario");

	String pmnReturn 	= session.getAttribute("pmnReturn") != null ? session.getAttribute("pmnReturn").toString() : "";	
	String pmnSn 		= session.getAttribute("pmn") != null ? session.getAttribute("pmn").toString() : "";
	String idContrato 	= session.getAttribute("idContrato") != null ? session.getAttribute("idContrato").toString() : "";
	String estudio		= session.getAttribute("estudio") != null ? session.getAttribute("estudio").toString() : "";
	String numContrato	= session.getAttribute("numContrato") != null ? session.getAttribute("numContrato").toString() : "";
	boolean bandera=true;
	String titulo="";
	List<MenuDTO> menus = (List<MenuDTO>) session.getAttribute("menus");
	int totalMenus		= menus.size();

	String pmn	= (String) request.getParameter("pmn");
	
	if( pmn == null )
		pmn = pmnSn;
	
	MenuDTO menuPadre 	= null;
	MenuDTO menuHnos 	= null;
	MenuDTO menuActual 	= null;
	
	String actionMenu 	= "";
	String menuDestino	= "";
	String paramDestino	= "";	
	
	String contextPath 	= request.getContextPath();
	Random r = new Random();		 	
	String versionJS    = new DecimalFormat("#.##").format(r.nextDouble() * 999999);
	session.setAttribute("versionJS", versionJS);
%>

<html lang="es">
<head>
<title>DLA - Derechos de Autor</title>
<meta charset="iso-8859-1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">

<!-- ===== FAVICON =====-->
<link rel="shortcut icon" href="${contextPath}/design/favicon.ico">

<!-- ===== CSS =====-->
<!-- General-->
<link rel="stylesheet" href="${contextPath}/css/styles.css">

<link rel="stylesheet" href="${contextPath}/design/css/basic.css">
<link rel="stylesheet" href="${contextPath}/design/css/general.css">
<link rel="stylesheet" href="${contextPath}/design/css/theme.css" class="style-theme">

<!-- Specific-->
<link rel="stylesheet" href="${contextPath}/design/css/addons/fonts/artill-clean-icons.css" />

<link rel="stylesheet" href="${contextPath}/css/common/jquery-jqgrid/ui.jqgrid.css" />
<link rel="stylesheet" href="${contextPath}/css/common/jquery-jqgrid/ui.jqgrid-bootstrap.css" />

<!-- BootStrap -->
<link rel="stylesheet" href="${contextPath}/design/pestanas/bootstrap.css" />
<link rel="stylesheet" href="${contextPath}/css/common/jquery-ui/jquery-ui.min.css" />
<link rel="stylesheet" href="${contextPath}/css/common/jquery-ui/jquery-ui.structure.css" />
<link rel="stylesheet" href="${contextPath}/css/common/jquery-ui/jquery-ui.theme.min.css" />

<!-- Especificos del portal -->
<link rel="stylesheet" href="${contextPath}/css/styles.css">

<link rel="stylesheet" href="${contextPath}/css/common/jquery-upload/uploadfile.css" />
<link rel="stylesheet" href="${contextPath}/css/common/typeahead/typeahead.bundle.css" />




<!-- ===== JS =====-->

<!-- jQuery-->    
<script src="${contextPath}/design/js/basic/jquery.min.js"></script>
<script src="${contextPath}/design/js/basic/jquery-migrate.min.js"></script>

<script src="${contextPath}/js/common/jquery/jquery-ui/jquery-ui.min.js"></script>
<script src="${contextPath}/js/common/jquery/jquery-ui/jquery.alerts.js"></script>

<!-- Para el validador -->
<script src="${contextPath}/js/common/jquery/jquery-validation/jquery.validate.min.js"></script>
<script src="${contextPath}/js/common/jquery/jquery-validation/additional-methods.min.js"></script>
<script src="${contextPath}/js/common/jquery/jquery-validation/localization/messages_es.js"></script>
<script src="${contextPath}/js/common/jquery/jquery-upload/jquery.form.js"></script>
<script src="${contextPath}/js/common/jquery/jquery-upload/jquery.uploadfile.js"></script>
<script src="${contextPath}/js/common/jquery/dynTable/dynamicTable.js"></script>
<script src="${contextPath}/js/common/jquery/dynSelect/dynSelect.js"></script>
<script src="${contextPath}/js/common/jquery/tableToJson/tableToJson.js"></script>
<script src="${contextPath}/js/dda/excelMapper/excelMapper.js"></script>



<script src="${contextPath}/js/common/typeahead/typeahead.bundle.js"></script>

<!-- Para DataTables -->
<script src="${contextPath}/design/js/plugins/table/jquery.dataTables.min.js"></script>

<script src="${contextPath}/js/common/jquery/jquery-jqgrid/jquery.jqGrid.min.js"></script>
<script src="${contextPath}/js/common/jquery/jquery-jqgrid/i18n/grid.locale-es.js"></script>

<script src="${contextPath}/js/common/perfil/perfilService.js?v=${versionJS}"></script>
<script src="${contextPath}/js/common/perfil/perfilController.js?v=${versionJS}"></script>
<script src="${contextPath}/js/common/moment/moment.min.js"></script>

<script>

$().ready(function() {
	$("#perfilLink").hide();
	var perfilController = new PerfilController();
	perfilController.ejecutarPerfil(1);
});

var contextPath = '${contextPath}'; 

//-- Calendario
$.datepicker.regional['es'] = {
		closeText: 'Cerrar',
		prevText: '&#x3c;Ant',
		nextText: 'Sig&#x3e;',
		currentText: 'Hoy',
		monthNames: ['Enero','Febrero','Marzo','Abril','Mayo','Junio',
		'Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'],
		monthNamesShort: ['Ene','Feb','Mar','Abr','May','Jun',
		'Jul','Ago','Sep','Oct','Nov','Dic'],
		dayNames: ['Domingo','Lunes','Martes','Mi&eacute;rcoles','Jueves','Viernes','S&aacute;bado'],
		dayNamesShort: ['Dom','Lun','Mar','Mi&eacute;','Juv','Vie','S&aacute;b'],
		dayNamesMin: ['Do','Lu','Ma','Mi','Ju','Vi','S&aacute;'],
		weekHeader: 'Sm',
		dateFormat: 'mm/dd/yy',
		firstDay: 1,
		isRTL: false,
		showMonthAfterYear: false,
		yearSuffix: ''};
		
$.datepicker.setDefaults($.datepicker.regional['es']);	

//-- Validador

$.validator.setDefaults({
		errorClass: "text-danger" 
	});

$.validator.addMethod("date", function (value, element) {
	if(value != ''){
		try{
			$.datepicker.parseDate("mm/dd/yy",value);
			return true;
		}catch(e)
		{
			return false;
		}
	}
	return true;
	}, "Formato de fecha incorrecta");

$.validator.addClassRules({
	  required: {
		  required: true
	  },
	  datepicker: {
		  date : true
	  },
	  digit: {
		  digits: true
	  },
	  number: {
		  number: true
	  }
	});

$(function() {
    $( ".datepicker" ).datepicker();
});

function parseMessage(msg){
	var texto="";
	if(typeof(msg)=="string"){
		return msg;
	}else{
		for(var i=0;i<msg.length;i++){
					texto+=msg[i]+"<br/>";	
		}
		return texto;
		
	}
}
	
function showError(msg)
{
	$("html, body").animate({ scrollTop: 0 }, "slow");
	$("#divError").html("<div class='alert alert-dismissible alert-danger'> <button type='button' class='close' data-dismiss='alert'>×</button> <h4>Error</h4>"+parseMessage(msg)+"</div>");
	closeDialog("divError");
};

function showMessage(msg)
{
	$("html, body").animate({ scrollTop: 0 }, "slow");
	$("#divMessage").html("<div class='alert alert-dismissible alert-info'> <button type='button' class='close' data-dismiss='alert'>×</button> <h4>Mensajes</h4>"+parseMessage(msg)+"</div>");
	closeDialog("divMessage");
};

function showWarn(msg)
{
	
	$("html, body").animate({ scrollTop: 0 }, "slow");
	$("#divWarn").html("<div class='alert alert-dismissible alert-warning'> <button type='button' class='close' data-dismiss='alert'>×</button> <h4>Advertencia</h4>"+parseMessage(msg)+"</div>");
	closeDialog("divWarn");
	
};

function showAdv(msg)
{
	
	$("html, body").animate({ scrollTop: 0 }, "slow");
	$("#divWarn").html("<div class='alert alert-dismissible alert-warning'> <button type='button' class='close' data-dismiss='alert'>×</button> <h4>Aviso</h4>"+parseMessage(msg)+"</div>");
	closeDialog("divWarn");
	
};

function closeDialog(id)
{
	$("#"+id).show();
	setTimeout(function() {
		$("#"+id).slideUp("slow");
		}, 5000);
};

/**
 * Number.prototype.format(n, x, s, c)
 * 
 * @param integer n: length of decimal
 * @param integer x: length of whole part
 * @param mixed   s: sections delimiter
 * @param mixed   c: decimal delimiter
 */
Number.prototype.format = function(n, x, s, c) {
    var re = '\\d(?=(\\d{' + (x || 3) + '})+' + (n > 0 ? '\\D' : '$') + ')',
        num = this.toFixed(Math.max(0, ~~n));

    return (c ? num.replace('.', c) : num).replace(new RegExp(re, 'g'), '$&' + (s || ','));
};

Number.prototype.formatDLA = function() {
	return this.format('2','3',',','.');
};

function deformatDLA (numeroDlaParseado){
	  return numeroDlaParseado.replace(/ /g, "").replace(/,/g,"").replace("$","");
};

function getRandom(min, max) {
	 return Math.random() * (max - min) + min;
}

Number.prototype.toFixedDown = function(digits) {
	  var n = this - Math.pow(10, -digits)/2;
	  n += n / Math.pow(2, 53); // added 1360765523: 17.56.toFixedDown(2) === "17.56"
	  return n.toFixed(digits);
}

</script>

</head>

<body class="l-dashboard" >

	<s:if test="%{usuario.nombre==null}">
		<script>
			alert('Su sesión ha expirado.');
			//window.location ="${contextPath}/";
		</script>
	</s:if>
	<s:else>
	</s:else>

	<!--HEADER SLIDE-->
	<header id="header"
		class="l-header-slide l-header-slide-3 t-header-slide-3"> </header>

	<!--SECTION-->
	<section class="l-main-container">
		<!--Left Sidebar Content-->
		<aside id="sb-left" class="l-sidebar l-sidebar-1 t-sidebar-1">
			<!--Switcher-->
			<div class="l-side-box">
				<a href="#" data-ason-type="sidebar" data-ason-to-sm="sidebar"
					data-ason-target="#sb-left"
					class="sidebar-switcher switcher t-switcher-side ason-widget"><i
					class="fa fa-bars"></i></a>
			</div>
			<!-- Profile in sidebar-->
			<div class="widget-profile-2 profile-2-in-side-2 t-profile-2-3">
				<div class="profile-2-wrapper">
					<div class="profile-2-chart">
						<div class="hide rickshaw-visitors"></div>
						<div id="rickshawVisitors"></div>
						<div id="rickshawVisitorsLegend" class="visitors_rickshaw_legend"></div>
					</div>
				</div>
			</div>
			<!-- Logo in Sidebar-->
			<div class="l-side-box">
				<!--Logo-->
				<div class="widget-logo logo-in-side">
					<h1>
						<a href="inicio"><span
							class="logo-default visible-default-inline-block"><img
								src="${contextPath}/design/img/logo_side.png" alt="DLA"></span><span
							class="logo-medium visible-compact-inline-block"><img
								src="${contextPath}/design/img/logo_medium.png" alt="DLA"
								title="DLA"></span> <spanl
								class="logo-small visible-collapsed-inline-block">
							<img src="${contextPath}/design/img/logo_small.png" alt="DLA"
								title="DLA"></spanl></a>
					</h1>
				</div>
			</div>
			<!--Main Menu-->
			<div class="l-side-box">
				<!--MAIN NAVIGATION MENU-->
				<nav class="navigation">
					<ul data-ason-type="menu" class="ason-widget">					
						
						<%
							for (MenuDTO menu : menus)
							{
								
								if( menuActual == null && menu != null)
									menuActual = menu.obtenerMenu( pmn );
								
								if( menuPadre == null && menuActual != null )
								{
									String idPadre = menuActual.getIdMenuPadre(); 
									menuPadre = menu.obtenerMenu( idPadre );									
								}
									

								if (!menu.getTipoMenu().equals("0")) 
								{
						%>
						
								  <li>
									<a href="${contextPath}/<%=menu.getScript() + "?pmn=" + menu.getIdMenu() + "&" + menu.getParametros()%>">
										<i class="<%=menu.getIconClass()%>"></i> 
									 	<span class="title">
									 		<%=menu.getNombre()%>
									 	</span>
								 		<span class="arrow">
								 			<i class="fa fa-angle-right"></i>
								 		</span>
									</a>												 
								  <%
						 			List<MenuDTO> hijos = menu.getHijos();
						
						 			if (hijos != null)
						 				out.println("<ul>");
						
						 			for (MenuDTO hijo : hijos) 
						 			{						 				
						 				List<MenuDTO> nietos = hijo.getHijos();
						 				
						 				actionMenu 		= hijo.getScript();
						 				menuDestino		= hijo.getIdMenu();
						 				paramDestino	= hijo.getParametros();
						 				
						 				if( nietos != null && nietos.size() > 0) {
						 					actionMenu 		= nietos.get( 0 ).getScript();
						 					menuDestino 	= nietos.get( 0 ).getIdMenu();
						 					paramDestino 	= nietos.get( 0 ).getParametros();
						 					
						 					if( !paramDestino.isEmpty() )
						 						paramDestino = '&' + paramDestino;
						 			}
						 		%>
								<li>
									<a href="${contextPath}/<%=actionMenu + "?pmn=" + menuDestino + paramDestino%>">
								<span class="title">
									<%=hijo.getNombre()%>
								</span>
							</a>
						</li>
						<%
							}
									if (hijos != null)
										out.println("</ul>");

									out.println("</li>");
								}
							}
						%>
					</ul>
				</nav>
			</div>
		</aside>
		<!--Main Content-->
		<section class="l-container">
			<!--HEADER-->
			<header class="l-header l-header-1 t-header-1">
				<div class="navbar navbar-ason">
					<div class="container-fluid">
						<div class="navbar-header">
							<button type="button" data-toggle="collapse"
								data-target="#ason-navbar-collapse"
								class="navbar-toggle collapsed">
								<span class="sr-only">Toggle navigation</span><span
									class="icon-bar"></span><span class="icon-bar"></span><span
									class="icon-bar"></span>
							</button>
							<a href="inicio" class="navbar-brand widget-logo"><span
								class="logo-default-header"><img
									src="${contextPath}/design/img/logo_dark.png" alt="DLA"></span></a>
						</div>
						<div id="ason-navbar-collapse" class="collapse navbar-collapse">
							<ul class="nav navbar-nav navbar-right">
								<li>
									<!-- Profile Widget-->
									<div class="widget-profile profile-in-header">
										<button type="button" data-toggle="dropdown"
											class="btn dropdown-toggle">
											<span class="name">
												<%= usuario.getNombre() + " " + usuario.getPaterno() + " " + usuario.getMaterno() %>
											</span>
										</button>

										<ul role="menu" class="dropdown-menu">
											<li><a id="perfilLink" href="${contextPath}/admin/usuarios/perfil/index.action"><i
													class="fa fa-user"></i>Perfil</a></li>
											<s:if test="%{false}"><li><a href="#"><i class="fa fa-cog"></i>Configuraci&oacute;n</a></li></s:if>
											<li class="power">
												<a href="<c:url value="/j_spring_security_logout"/>">
													<i class="fa fa-power-off"></i>Salir</a>
												</li>
										</ul>
									</div>
								</li>
							</ul>
						</div>
					</div>
				</div>
			</header>
			
			<div id="lphead"></div>

			<%
			if(menuActual != null)
			{
			%>
			<div class="l-page-header" style="height: 57px;">
				<h2 class="l-page-title" style="margin-top: 9px;  height: 12px;">
					<span><%= menuActual.getDescripcion()%></span>
				</h2>
				<!--BREADCRUMB-->
				<ul class="breadcrumb t-breadcrumb-page" style="margin-top: -6px;  margin-bottom: 43px;">
					Home <%=menuActual.getRuta()%>
				</ul>
							<%
							if( menuActual.getTipoMenu().equals("2") &&
								!menuActual.getIdMenu().equals("16") &&
								!menuActual.getIdMenu().equals("24") &&
								!menuActual.getIdMenu().equals("32")
							  )
							{
							%>
								<div style="position: relative; left: 70%; top: -94px; font-size: 13px;">
								
									<div ><label class="control-label" style="padding-top: 3px;"><label style="color: black;">Estudio:</label>&nbsp;<%=estudio%></label></div>
									
									
									<div style="position: relative; right: 8px; bottom: 16px;"><label class="control-label" style="padding-top: 6px;"><label style="color: black;">Contrato:</label>&nbsp;<%=numContrato%></label></div>
									
								</div>
							<%} %>	
						
			</div>
			<%
			}
			%>	
			
			<div style="margin:10px;">
				<ul class="nav nav-tabs">
				    <%
						if( 
							menuPadre != null && menuActual.getTipoMenu().equals("2") ||
							menuPadre != null && menuActual.getTipoMenu().equals("3")
						  ) {
							List<MenuDTO> hermanos = menuPadre.getHijos();
							
							if( hermanos != null && hermanos.size() > 1 ) 
							{
								for (MenuDTO pestana : hermanos) 
								{
									actionMenu 		= pestana.getScript();
				 					menuDestino 	= pestana.getIdMenu();
				 					paramDestino 	= pestana.getParametros();
				 					
				 					String classLi = "";
				 					String url = contextPath + "/" + actionMenu + "?pmn=" + menuDestino + "&" + paramDestino;
				 					
				 					if( menuActual.getTipoMenu().equals("2") ){
					 					if( idContrato.isEmpty() && paramDestino.isEmpty() ){
					 						classLi = "class='disabled'";
					 						url = "#";
					 					}
				 					}
				 					else
				 					{
				 						session.setAttribute("pmnReturn", null);
				 						session.setAttribute("pmn", null);
				 						session.setAttribute("idContrato", null);
				 					}
				 					
									if( pestana.getIdMenu().equals(pmn) ) {
									%>
										<li class="active">
											<a href="#"><%=pestana.getNombre()%></a>
										</li>
										<%if(pestana.getNombre().equals("Listado")||pestana.getNombre().equals("Generales")||pestana.getNombre().equals("")){bandera=false;}else{bandera=true;} %>
									<%
									}
									else {
									%>
										<li <%= classLi %>>
											<a href="<%=url%>">
											<%=pestana.getNombre()%>
											</a>
										</li>
									<%
									}
								}
							}
						}
					%>			    					    
				  </ul>	
			</div>
				<!-- aqui estaba -->
			  
					
			<div class="l-spaced">
				<div class="l-box l-spaced-bottom">	
				
					<div class="l-box-header">
					
						<h2 class="l-box-title">
						<%
						if(menuActual != null)
						{
						%>
							<span><%= menuActual.getDescripcion() %></span>
						<%
						}
						%>
						</h2>
						<ul class="l-box-options">
							<li><a href="#" data-ason-type="fullscreen"
								data-ason-target=".l-box" data-ason-content="true"
								class="ason-widget"></a></li>
								
							<li><a href="#" data-ason-type="toggle"
								data-ason-find=".l-box" data-ason-target=".l-box-body"
								data-ason-content="true" data-ason-duration="200"
								class="ason-widget"></a></li>
						</ul>
					</div>
					
					<div class="l-box-body l-spaced form-horizontal" style="height:100%">
					
						<div id="divMessage">
							<s:if test="hasActionMessages()">
								  	<div class='alert alert-dismissible alert-info'> 
								  		<button type='button' class='close' data-dismiss='alert'>×</button> 
								  		<s:actionmessage/>	
								  	</div>
								  	<script type="text/javascript">
								  	closeDialog("divMessage");
								  	</script>
							</s:if>
						</div>
						<div id="divWarn"></div>
						<div id="divError">
							<s:if test="hasActionErrors()">
								  	<div class="alert alert-dismissible alert-danger">
		 								 <button type="button" class="close" data-dismiss="alert">×</button>
		 								 <h4>Error</h4>
								    	 <s:actionerror/>
								  	</div>
								  	<script type="text/javascript">
								  	closeDialog("divError");
								  	</script>
							</s:if>
						</div>					 