<%@page import="java.util.*,javax.sql.*,java.sql.*,javax.naming.*,m05bClasses.*, m05bBD.m05bRevision,java.io.PrintWriter" %>
<%@include file="/mantenimientosJSP/includes/m05b.inc"%>

<HTML>
<%
	// _______________________________XLNETs______________________________________
	// Evaluar variable de session que indica si esta conectado a XLNets
	if (session.getAttribute("objetoSeguridad") == null)  { 
		// Verificar que no ha transcurrido el tiempo de sesion (web.xml) %>
			<%@ include file="/m05bControlAcceso.inc"%> 
<%
	} 
	String persona = (String) session.getAttribute("persona");
%>
	<%@ include file="/m05bIdioma.inc"%>
	
<head>
		<title><%= resTit.getString("titRevisiones")%></title>
		<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
		<link rel="stylesheet" href="<%=m05bConstantesPaginas.PATH_ESTILOS%>/m05bestilos.css" type="text/css">
		<script language="javascript1.2" src="<%=m05bConstantesPaginas.PATH_SCRIPTS%>/m05Funciones.js"></script>
		<script language="javascript1.2" src="<%=m05bConstantesPaginas.PATH_SCRIPTS%>/m05Revision.js"></script>
		<script language="javascript1.2" src="<%=m05bConstantesPaginas.PATH_SCRIPTS%>/formateador.js"></script>
</head>
		<%
		    String codigo="", accion="", mat="", fec="", km="", kmp="", fecp="", des="";
		    String realizada="", clave="", mensaje = "";
		    
			m05bFileLog miLog = new m05bFileLog();
		    m05bComun comun= new m05bComun();
			m05bCombo miCombo = new m05bCombo();

		    codigo = request.getParameter("Codigo");
		    
		    m05bRevision revision = null;
		    if (codigo.equals("Nuevo")){
			    m05bGenerarClave genClave = new m05bGenerarClave();
			    clave = genClave.getClave(m05bConstantes.TAB_REVISIONES, m05bConstantes.COL_35_CODIGO );
			    int iClave= Integer.parseInt(clave,10);
			    iClave = iClave+1;
			    clave=""+iClave;
		        codigo = clave;
		        accion = m05bConstantes.ACC_INSERTAR;
		    }
		    else {
		    //else if (!codigo.equals("Nuevo") && !codigo.equals("")){
		        accion=m05bConstantes.ACC_ACTUALIZAR;
		        revision = (m05bRevision)session.getAttribute("m05bRevision");
		        mat = revision.getRevi_matricula();
				miLog.addTraza(persona, "Revision", "MATRICULA: " + mat, m05bConstantes.LOG_NIVEL_BAJO);
		        fec= revision.getRevi_fecha();
				miLog.addTraza(m05bConstantes.LOG_NO_USER, m05bConstantes.LOG_NO_SRC,"Fecha: " + fec, m05bConstantes.LOG_NIVEL_BAJO);
		        des=revision.getRevi_descrip()==null?"":revision.getRevi_descrip();
		        des=des.replaceAll("\"","\'\'");
		        realizada=revision.getRevi_realiza();
		        codigo=revision.getRevi_cod();
				miLog.addTraza(m05bConstantes.LOG_NO_USER, m05bConstantes.LOG_NO_SRC, "CODIGO: " + codigo, m05bConstantes.LOG_NIVEL_BAJO);
		        if (realizada==null || realizada.equals(""))
		          realizada="";
		        km=revision.getRevi_kmre()==null?"":revision.getRevi_kmre();
		        kmp=revision.getRevi_kmpre()==null?"":revision.getRevi_kmpre();
		        fecp=revision.getRevi_fecprox();
		        if (fec==null)
		             fec="";
		        else {
		        	if(idiomaSes.equals("es")){ 
		        		if (fec.substring(4,5).equals("-")) {
				        	fec = fec.split("-")[2].substring(0,2)+"/"+fec.split("-")[1]+"/"+fec.split("-")[0];
				        } else {
				        	fec = fec.split("/")[0]+"/"+fec.split("/")[1]+"/"+fec.split("/")[2];
				        }
		        	}
		        	else{
		        		if (fec.substring(4,5).equals("-")) {
				        	fec = fec.split("-")[0]+"/"+fec.split("-")[1]+"/"+fec.split("-")[2].substring(0,2);
				        } else {
				        	fec = fec.split("/")[2]+"/"+fec.split("/")[1]+"/"+fec.split("/")[0];
				        }		        		
		        	}
				}
				miLog.addTraza(m05bConstantes.LOG_NO_USER, m05bConstantes.LOG_NO_SRC, "Fecha-2: " + fec, m05bConstantes.LOG_NIVEL_BAJO);
				if (fecp==null)
		            fecp="";
		        else {
		        	if(idiomaSes.equals("es")){ 
		        		if (fecp.substring(4,5).equals("-")) {
		        			fecp = fecp.split("-")[2].substring(0,2)+"/"+fecp.split("-")[1]+"/"+fecp.split("-")[0];
				        } else {
				        	fecp = fecp.split("/")[0]+"/"+fecp.split("/")[1]+"/"+fecp.split("/")[2];
				        }
		        	}
		        	else{
		        		if (fecp.substring(4,5).equals("-")) {
		        			fecp = fecp.split("-")[0]+"/"+fecp.split("-")[1]+"/"+fecp.split("-")[2].substring(0,2);
				        } else {
				        	fecp = fecp.split("/")[2]+"/"+fecp.split("/")[1]+"/"+fecp.split("/")[0];
				        }		        		
		        	}
				}//	        	 fecp = fecp.substring(8,10)+"/"+fecp.substring(5,7)+"/"+fecp.substring(0,4);
						miLog.addTraza(m05bConstantes.LOG_NO_USER, m05bConstantes.LOG_NO_SRC, "FechaP-2: " + fecp, m05bConstantes.LOG_NIVEL_BAJO);
		    }
		    if (revision == null){
					revision = new m05bRevision();
					session.setAttribute("m05bRevision",revision);
			}
			
			mensaje = request.getParameter("Mensaje")==null?"":request.getParameter("Mensaje");
			PrintWriter outMsg= response.getWriter();
			if (mensaje.equals(m05bConstantes.MSG_OK)) {
				    outMsg.println("<script>alert(dameAlerta(idioma, 3));</script>");
			} else if (mensaje.equals(m05bConstantes.MSG_EXISTE)) {
					    outMsg.println("<script>alert(dameAlerta(idioma, 142));</script>");
			}
			outMsg.close();
			
    if (!mat.equals("")){
%>
<BODY style="cursor: wait" onkeydown="cancelaEnter();" onload="javascript:alCargar('<%=mat%>','<%=fec%>','<%=km%>','<%=kmp%>','<%=fecp%>','','<%=realizada%>','<%=codigo%>');fncFormatCampos();document.body.style.cursor='default';InitMenu();cargaDes();" onunload="document.body.style.cursor='wait';">
<%
    } else { %>
    	<BODY>
<%	}%>
<div id='p01popUpWindowCalendar' style='position:relative; top:15px left:150px'></div>
		<SCRIPT language=JavaScript>
			var urlIdioma;		//URL recarga en funcion del idioma
			var rutaCabecera;	//Camino de migas
			var detActual;		//Ventana actual
			urlIdioma = "<%=m05bConstantesPaginas.VEH_REV_NUEVA%>";
			detActual = '<%=resCM.getString("cmRevision")%>';
			rutaCabecera = "<%=m05bConstantesPaginas.DATOS_CABECERA%><%=m05bConstantesPaginas.VEH_REV_BUSQUEDA%>" + "'>\\"+'<%=resCM.getString("cmRevBusqueda")%>'+"</a>";
			rutaCabecera += "<%=m05bConstantesPaginas.DATOS_CABECERA%><%=m05bConstantesPaginas.VEH_REV_RELACION%>" + "'>\\"+'<%=resCM.getString("cmRelRevisiones")%>'+"</a>";
			//rutaCabecera = "<%=m05bConstantesPaginas.DATOS_CABECERA%>" + urlIdioma + "'>\\"+detActual+"</a>";
		</SCRIPT>
		<%@ include file="/mantenimientosJSP/includes/m05Cabecera_c.jsp"%>
<p> 	 
<table  width="100%" height="100%" border="0" cellspacing="0" cellpadding="0" align="center">
	<tr><td colspan=3></td></tr>
	<tr valign="top">
		<td width="2%">
			<DIV ID="thessm" style="visibility:hidden;Position : Absolute ;Left : 0 ;Top : 80 ;Z-Index : 20;">
	      		<DIV ID="thessm2" style="Position : Absolute ;Left : (-150) ;Top : 0 ;Z-Index : 20;">
	                <%@ include file="/m05bMenuInicial.inc"%>
	       		</DIV>
			</DIV>
		</td>
		<td>&nbsp</td>
		<td width="98%">
			<FORM NAME="formRevision" METHOD="POST">
					<!-- Calendarios -->
						<%	String m05bCalendarEstilo = comun.leerPropiedad("m05bEstilos.Calendario");  %>
						<%=m05bCalendarEstilo%>
						<%	String m05bCalendarScripts = comun.leerPropiedad("m05bScripts.Calendario");  %>
						<%=m05bCalendarScripts%>
						<input type="hidden" name="Codigo" value="">
						<input type="hidden" name="Situacion" value="">
					    <%  m05bCombo Combo= new m05bCombo();	%>
					    <TABLE class="general">
					    <TR>
						  <% if (mensaje.equals("buscar")) { %>
								  <!--td align="right"><INPUT TYPE="IMAGE" style="cursor:hand" VALUE="Retornar" ONCLICK="JavaScript:history.back();return false" onMouseOver="top.status='Retornar'; return true" onMouseOut="top.status=''; return true" src="<%=m05bConstantesPaginas.PATH_IMAGENES%>/retornar.gif"></td!-->
                                  <td align="right"><input type="button" class="boton" name="<%= res.getString("etBOT_RETORNAR")%>" value="<%= res.getString("etBOT_RETORNAR")%>" ONCLICK="JavaScript:history.back();return false;" onMouseOver="top.status='<%= res.getString("etBOT_STATUSRETORNAR")%>'; return false" onMouseOut="top.status=''; return false" /></td>				      					  								  
					           <% if (!(codigo.equals(request.getParameter("Clave"))) ) { %>
							      <!--td width="10%" align="right"> <INPUT TYPE="IMAGE" style="cursor:hand" VALUE="Nuevo" ONCLICK="JavaScript:fncNuevo('<%=clave%>');return false;" onMouseOver="top.status='Dar de alta una nueva Revision'; return false" onMouseOut="top.status=''; return false" src="<%=m05bConstantesPaginas.PATH_IMAGENES%>/nuevo.gif"/> </td-->
                                  <td width="10%" align="right"><input type="button" class="boton" name="<%= res.getString("etBOT_NUEVO")%>" value="<%= res.getString("etBOT_NUEVO")%>" ONCLICK="JavaScript:fncNuevo('<%=clave%>');return false;" onMouseOver="top.status='<%= res.getString("etBOT_STATUSNUEVO")%>'; return false" onMouseOut="top.status=''; return false" /></td>				      					  							      
						  <% 	  }
						  	 } else if (!(codigo.equals(request.getParameter("Clave"))) ) { %>
							      <!--td width="90%" align="right"> <INPUT TYPE="IMAGE" style="cursor:hand" VALUE="Nuevo" ONCLICK="JavaScript:fncNuevo('<%=clave%>');return false;" onMouseOver="top.status='Dar de alta una nueva Revision'; return false" onMouseOut="top.status=''; return false" src="<%=m05bConstantesPaginas.PATH_IMAGENES%>/nuevo.gif"/> </td-->
                                  <td width="90%" align="right"><input type="button" class="boton" name="<%= res.getString("etBOT_NUEVO")%>" value="<%= res.getString("etBOT_NUEVO")%>" ONCLICK="JavaScript:fncNuevo('<%=clave%>');return false;" onMouseOver="top.status='<%= res.getString("etBOT_STATUSNUEVO")%>'; return false" onMouseOut="top.status=''; return false" /></td>				      					  							      
						  <% } %>
						  <!--td width="10%" align="right"> <INPUT TYPE="IMAGE" style="cursor:hand" VALUE="Grabar" ONCLICK="JavaScript:fncFormatCampos();fncGrabar('<%=codigo%>','<%=accion%>');return false;" onMouseOver="top.status='Grabar'; return true" onMouseOut="top.status=''; return true" src="<%=m05bConstantesPaginas.PATH_IMAGENES%>/grabar.gif"/> </td-->
                          <td width="10%" align="right"><input type="button" class="boton" name="<%= res.getString("etBOT_GRABAR")%>" value="<%= res.getString("etBOT_GRABAR")%>" ONCLICK="JavaScript:fncFormatCampos();fncGrabar('<%=codigo%>','<%=accion%>');return false;" onMouseOver="top.status='<%= res.getString("etBOT_STATUSGRABAR")%>'; return false" onMouseOut="top.status=''; return false" /></td>				      					  						  
					    </TR>
					    </TABLE>
					    <input type="hidden" name="Situacion">
					    <TABLE class="general">
						    <tr>
						      <td class="searchTitle" colspan="4"><%= res.getString("etDatosVehiculo")%></td>
						    </tr>
						    <tr>
						      <td width="15%" class="inputFieldTitle"><%= res.getString("etMatricula")%></td>
						      <td width="25%" class="inputFieldTitle"><%= res.getString("etMarca")%></td>
						      <td width="30%" class="inputFieldTitle"><%= res.getString("etModelo")%></td>
						      <td width="30%" class="inputFieldTitle"><%= res.getString("etColor")%></td>
						    </tr>
						    <tr>
						      <td align="left">
						      	<% if (accion.equals(m05bConstantes.ACC_INSERTAR)) {  %>
							          <select class="inputFieldOblig"  NAME="Matricula" onchange="javascript:fncMatricula();"/>
							                <option value="">  </option>
							                <%=Combo.ComMatricula(m05bConstantes.VEH_ALTA,"")%>
							          </select>
						      	<% } else { %>
								     <INPUT class="inputFieldOblig" TYPE="TEXT" NAME="Matricula" size="20" value="<%=mat%>" readonly/>
						        <% }  %>									 	 						      					
						     </td>
						      <td align="left"><INPUT class="inputField" TYPE="TEXT" NAME="Marca" VALUE="" size="33" readonly/></td>
						      <td align="left"><INPUT class="inputField" TYPE="TEXT" NAME="Modelo" VALUE="" size="30" readonly/></td>
						      <td align="left"><INPUT class="inputField" TYPE="TEXT" NAME="Color" VALUE="" size="28" readonly/></td>
						    </tr>
						    <tr>
						      <td class="inputFieldTitle" colspan="2"><%= res.getString("etRango")%></td>
						      <td class="inputFieldTitle"><%= res.getString("etRevisionKm")%></td>
						      <td class="inputFieldTitle"><%= res.getString("etRevisionMeses")%></td>
						    </tr>
						    <tr>
						      <td align="left" colspan="2"><INPUT class="inputField" TYPE="TEXT" NAME="Rango" VALUE="" size="56" maxlength="10" readonly/></td>
						      <td align="left"><INPUT class="inputField" TYPE="TEXT" NAME="RevKm" VALUE="" size="10" maxlength="10" readonly/></td>
						      <input type="hidden" name="Revikm" value="javascript:this.value=RevKm.value;return false;">
						      <td align="left"><INPUT class="inputField" TYPE="TEXT" NAME="RevMes" VALUE="" size="10" maxlength="10" readonly/></td>
						    </tr>
						    <tr>
						      <td  valign="top" class="searchTitle" colspan="4"><%= res.getString("etDatosRevision")%></td>
						    </tr>
						    <tr>
						      <td class="inputFieldTitle" colspan="2"><%= res.getString("etFechaRevision")%></td>
						      <td class="inputFieldTitle"><%= res.getString("etKmRevision")%></td>
						      <td class="inputFieldTitle"><%= res.getString("etRealizada")%></td>
						   </tr>
						   <tr>
						      <td align="left"><INPUT class="inputFieldOblig" TYPE="TEXT" NAME="Fecha" VALUE="" size="20" maxlength="20" onblur="javascript:formatearFecha(this);javascript:fncSumar();return false;" /></td>
					          <td align="left"><a href='#' name='anchorRev'  onClick='JavaScript:showCalendar("anchorRev",idioma,document.all("Fecha"),true,200,200,2002);return false;' onMouseOver="top.status='Ver Calendario'; return true" onMouseOut="top.status=''; return true" ><img border="0" src='<%=m05bConstantesPaginas.PATH_IMAGENES%>/p01calendario.gif' /></a></td>
						      <td align="left"><INPUT class="inputFieldOblig" TYPE="TEXT" NAME="KmRevision" VALUE="" size="10" maxlength="10" onblur="javascript: Kmrevi.value=trimPointers(this.value); CalculaKm();formatNumero(this);formatNumero(KmProxRevision);return false;"/></td>
						      <input type="hidden" name="Kmrevi">
						      <td align="left"><INPUT class="inputField" TYPE="Checkbox" NAME="Realizada" VALUE="S" <%if (revision.getRevi_realiza()!=null && revision.getRevi_realiza().toUpperCase().equals("S")){%> checked <%}%>/></td>
						    </tr>
					         <tr>
					           <td colspan="2" class="inputFieldTitle"><%= res.getString("etFechaProxRevision")%></td>
					           <td colspan="2" class="inputFieldTitle"><%= res.getString("etKmProxRevision")%></td>
					         </tr>
					         <tr>
					           <td align="left"><INPUT class="inputField" TYPE="TEXT" NAME="FechaProx" size="20" maxlength="10" onblur="javascript:formatearFecha(this);return false;"/></td>
					           <td align="left"><a href='#' name='anchorProx'  onClick='JavaScript:showCalendar("anchorProx",idioma,document.all("FechaProx"),true,200,200,2002);return false;' onMouseOver="top.status='Ver Calendario'; return true" onMouseOut="top.status=''; return true" ><img border="0" src='<%=m05bConstantesPaginas.PATH_IMAGENES%>/p01calendario.gif' /></a></td>
					           <td align="left"colspan="2"><INPUT class="inputField" TYPE="TEXT" NAME="KmProxRevision" VALUE="" size="10" maxlength="10" onblur="javascript: formatNumero(this);return false;"/></td>
					           <!--td align="left"colspan="2"><INPUT class="inputField" TYPE="TEXT" NAME="KmProxRevision" VALUE="" size="10" maxlength="10" onblur="javascript: kmproxrevi.value=this.value;formatNumero(this);return false;"/></td-->
					         </tr>
						     <tr>
						       <td class="inputFieldTitle" colspan="4"><%= res.getString("etDescripcion")%></td>
						     </tr>
						     <tr>
						       <td align="left" colspan="4"><TEXTAREA class="inputField" NAME="Descripcion" WRAP="phisical" rows="6" cols="90"></TEXTAREA></td>
						     </tr>						     
					    </TABLE>
					  <input type="hidden" name="FKmAct">
					  <input type="hidden" name="KmAct">
			</FORM>
		</td>
	</tr>
	<tr>
			<td colspan="3"><%@ include file="/mantenimientosJSP/includes/m05Pie_c.jsp"%></td>
	</tr>
</table>
<SCRIPT language='javascript'>
	function cargaDes(){
		var docu = document.formRevision;
		docu.Descripcion.value= "<%=des%>";
		docu.Descripcion.value = replaceAll(docu.Descripcion.value,"\'\'","\"");
	}
	function  fncProxRev(){
	       var propiedades="left='50',top='50',width='800',height='700',scrollbars=yes";
	       var url ="m05bProxRevisionJsp.jsp";
	       window.open(url,"ProximasRevisiones",propiedades);
	}  // Fin funcion fncProxRev
	
	function  fncFormatCampos(){
		var docu = document.formRevision;
		formatNumero(docu.KmRevision);
		formatNumero(docu.KmProxRevision);
		formatearFecha(docu.Fecha);
		formatearFecha(docu.FechaProx);
	}   // Fin funcion fncFormatCampos
	setTimeout('initSlide();', 1);
</SCRIPT>
<IFRAME src="" width="0" height="0" scrolling="no" frameborder="0" name="cargar">
</IFRAME>
</BODY>
</HTML>