<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Language=VBScript %>
<!--#INCLUDE file="ADOVBS.inc"-->
<% 
Response.Buffer=true
DIM clave, fullName, status, wichPage
dim userId, userName, userPasswd
DIM sqlQuery, action, titlePage, contacto, telefono, passwd
DIM int_w, int_h
int_w="100%"
int_h="100%"

str_bd= application("bd_sieps")

SET rs = server.CreateObject("ADODB.Recordset")
SET rsUsers = server.CreateObject("ADODB.Recordset")
SET connection = SERVER.CreateObject("ADODB.CONNECTION")

connection.Open str_bd

wichPage = Request.QueryString("wichPage")
clave= Request.QueryString("clave")
action=Request.QueryString("action")

if action="edit" then ' Consultar los datos preferidos y presentarlos
	'set mail = server.CreateObject("CDONTS.NewMail")
	sqlQuery = witchInbox(wichPage)
	On Error Resume Next		
	rs.Open sqlQuery, connection, adOpenStatic, adLockReadOnly, 1
	sendError(connection.Errors)
	if (rs.EOF = false) then
		clave = rs.Fields("clave")
		fullName = rs.Fields("nombre")
		status = rs.Fields("status")
		contacto = rs.Fields("contacto")
		telefono = rs.Fields("telefono")
		passwd = rs.Fields("password")
	end if
	'Consulto al usuario maestro de la empresa
	sqlQuery = getQueryUser("255", clave)
	On Error Resume Next		
	rsUsers.Open sqlQuery, connection, adOpenStatic, adLockReadOnly, 1
	sendError(connection.Errors)
	if (rsUsers.EOF = false) then
		userId = rsUsers.Fields("clave")
		userName = rsUsers.Fields("userName")
		userPasswd = rsUsers.Fields("password")
	end if
	'sendMensajeToConsole("Empresa: "&)
end if

' clean up
If rs.State = adStateOpen then
	rs.Close
End If
if rsUsers.State = adStateOpen then
	rsUsers.Close
End If
If connection.State = adStateOpen then
	connection.Close
End If
Set rs = Nothing
Set connection = Nothing

function witchInbox(inbox)
	dim sql 
	select case inbox
	case "empresa"		
		sql = "SELECT empr_clave AS clave, empr_idx AS index, empr_nombre AS nombre, "
		sql = sql & "empr_contacto AS contacto, empr_telefonos AS telefono, empr_estatus AS status, empr_password AS password "
		sql = sql & "FROM empresa WHERE empr_clave='" & clave & "'"
	case "division"		
	end select	
	witchInbox = sql
end function

function getQueryUser(userType, enterpriseId)
	dim sql 
	sql = "SELECT usua_clave AS clave, usua_nombre AS userName, usua_password AS password "		
	sql = sql & "FROM usuario WHERE empr_clave='" & enterpriseId & "' AND tipo_usuario="&userType
	getQueryUser = sql
end function

sub sendError(errors)
	dim objErr
	dim str_c
	dim strrr
	for each objErr in errors
		str_c=str_c&"Description: "
		str_c=str_c&objErr.Description  
	  
		str_c=str_c&"Native error: "
		str_c=str_c&objErr.NativeError 
		  
		str_c=str_c&"SQL state: "
		str_c=str_c&objErr.SQLState
	next
	if Len(str_c) > 1 then
		strrr="uti_console.asp?mensaje=" & "Error: " & str_c 
		Response.Redirect(strrr)
	end if
end sub

sub sendMensajeToConsole(mensaje)
	dim strrr
	strrr="uti_console.asp?mensaje=" & mensaje
	Response.Redirect(strrr)
end sub
%>
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>SIEPS WEB</title>
		<script type="text/javascript" src="js/lib/prototype-1.6.0.2.js"></script>
		<script type="text/javascript" src="js/lib/validation.js"></script>
		<script type="text/javascript" src="js/funciones/functionsAjax.js"></script>
		<link REL="stylesheet" TYPE="text/css" HREF="stylesheet.css">
		<link REL="stylesheet" TYPE="text/css" HREF="css/styleValidator.css">
		<!--#INCLUDE FILE="uti_utilerias_cliente.asp"-->
		<script LANGUAGE="javascript">
		<!--
		function iniciar()
		{
			var image1
			image1= new Image;
			image1.scr="images/btn_aceptar_1.gif";
			image2= new Image;
			image2.scr="images/btn_cancelar_1.gif";
			image3= new Image;
			image3.scr="images/btn_eliminar_1.gif";

			$('TXT_CLAVE').focus();
		}

		function sendForm()
		{
			var str_valida;					
			/*str_valida =valida_espacio($('TXT_CLAVE').value)
			if (str_valida==true){
				alert("Clave no válida...");
				$('TXT_CLAVE').focus();
				return (false);
			} */

			/*str_valida =valida_espacio($('TXT_NOMBRE').value)
			if (str_valida==true){
				alert("Nombre no válido...");
				$('TXT_NOMBRE').focus();
				return (false);
			}
			*/
			var valid = new Validation('formNew');
			if(valid.validate()){
				if ($('action').value=='edit') {
					$('action').value = 'update'
				} else {
					$('action').value = 'save';
				}			
				$('formNew').submit();	
			}

			
		}

		function delRegister()
		{
			if (confirm("¿Desea eliminar el registro?")) {
				$('action').value="del";                                                  
				$('formNew').submit();
			}
		}
		
		function toogleImage(idx) {
			$('btn_delete').src = 'images/btn_eliminar_'+idx+'.gif';		
		}
		-->
		</script>
	</head>
	<body onload="iniciar();">
	<!--#INCLUDE FILE="uti_fondo.asp"-->
	<form action="save.asp" id="formNew" name="formNew" method="post">
	<table valign="center" border="0" width="100%" cellspacing="0" cellpadding="2">
		<tr>
			<td width="100%" align="middle" valign="top">
				<table border="0" width="100%" cellspacing="2" cellpadding="0">
					<tr>
						<td width="80%" align="left">
							<table border="0" width="100%" cellspacing="0" cellpadding="2">
								<tr>
									<td width="100%" align="left">
										<font class="etiqueta_roja"><%=fullName%></font>
									</td>
								</tr>
								<tr>
									<td width="100%" align="left">
										<font class="titulo_modulo">
										<% if action="new" then%>
										Alta de <%=wichPage%>
										<% else%>
										Actualización de <%=wichPage%>
										<%end if%>									
										</font>
									</td>
								</tr>
					</table>
						</td>
						<td width="20%" align="right" valign="center">
							<img alt="Ayuda en línea" style="border-color: DarkBlue; margin:0;margin-right:4px; cursor:hand" src="images/img_ayuda.gif" onclick="ver_ayuda()" WIDTH="24" HEIGHT="24">&nbsp;
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr  bgColor="#EFEFEF">
			<td align="right" >
				&nbsp;
			</td>
		</tr>
	</table>
	<table border="0" width="100%" height="100%" cellspacing="0" cellpadding="2" background="images/imagen_sieps.jpg" style="BACKGROUND-POSITION: 5px 0px; BACKGROUND-REPEAT: no-repeat">
		<tr>
			<td align="center" valign="top">
				<table border="0" height="100%" width="99%" valign="top" bordercolor="dimgray" bgColor="white" cellspacing="0" cellpadding="2" background borderColorDark="white">
					<tr>
						<td width="100%" align="middle" valign="top">
							<table align="center" border="0" width="570">
								<tr>
									<td>
										<table id="tableDatos" >
											<tr>
												<td align="left" NOWRAP><font class="titulo-listado">Datos</font></td>
												<td align="left" bgcolor="#ffffff" width="100%"></td>
											</tr>
										</table>
										<hr style="margin:0">										
									   <table id="tableContenido" style="width:100% text-align:left; background:white;">
											<tr>
												<td style="width:30%; text-align:right; background:#EFEFEF;" >
													<font class="etiqueta">* Clave <%=wichPage%></font>
												</td>
												<td style="width:70%; text-align:left;">
													<input type="text" id="TXT_CLAVE" class="required validate-alpha" size="10" maxlength="10" onblur="checkExist('<%=action%>', this);" size="10" name="clave" maxlength="10" value="<%=clave%>" <%if action<> "new" then Response.Write("readonly=true")%> />
													<span id="clave-error" style="display:none;"></span>
												</td>
											</tr>
											<tr>
												<td style="width:30%; text-align:right; background:#EFEFEF;">
													<font class="etiqueta">* Nombre <%=wichPage%></font>
												</td>
												<td style="width:70%; text-align:left;">
													<input type="text" id="TXT_NOMBRE" class="required"  size="55" maxlength="40" name="name" value="<%=fullName%>">
												</td>
											</tr>
											<%if wichPage = "empresa" then%>
												<tr>
													<td style="width:30%; text-align:right; background:#EFEFEF;">
														<font class="etiqueta">* Contacto</font>
													</td>
													<td style="width:70%; text-align:left;">
														<input type="text" id="TXT_CONTACTO" class="required"  size="55" maxlength="40" name="contact" value="<%=contacto%>" >
													</td>
												</tr>
												<tr>
													<td style="width:30%; text-align:right; background:#EFEFEF;">
														<font class="etiqueta">* Contrase&ntilde;a</font>
													</td>
													<td style="width:70%; text-align:left;">
														<input type="password" id="TXT_PASSWORD" class="required" size="10" maxlength="10" name="passwd" value="<%=passwd%>" >
													</td>
												</tr>
											<%end if%>	
											<tr>
												<td style="width:30%; text-align:right; background:#EFEFEF;">
													<font class="etiqueta">Estatus</font>
												</td>
												<td style="width:70%; text-align:left;">
													<input type="radio" name="statusEna" value="1" <%if status = "Activo" then Response.write("Checked")%> />
													<font class="input">Activo</font>&nbsp;	
													<input type="radio" name="statusDis" value="0" <%if status = "Desactivo" then Response.write("Checked")%> />
													<font class="input">Desactivo</font>&nbsp;
												</td>														
											</tr>
										</table>
										<%if wichPage = "empresa" then%>
											<div id="usuarioMaster" style="width:570px;">
												<table style="width:100%; border:0px; border-spacing: 0px; padding:0px;">
													<tr>
														<td>
															<table >
																<tr>
																	<td align="left" NOWRAP><font class="titulo-listado">Datos usuario maestro </font></td>
																	<td align="left" bgcolor="#ffffff" width="100%"></td>
																</tr>
															</table>
															<hr style="margin:0">
														   <table style="width:100% text-align:left; background:white;">
																<tr>
																	<td style="width:30%; text-align:right; background:#EFEFEF;">
																		<font class="etiqueta">* Clave</font>
																	</td>
																	<td style="width:70%; text-align:left;">
																		<input name="userId" id="userId" size="10" maxlength="10" value="<%=userId%>" <%if action<> "new" then Response.Write("readonly=true")%> />
																	</td>
																</tr>
																<tr>
																	<td style="width:30%; text-align:right; background:#EFEFEF;">
																		<font class="etiqueta">* Nombre</font>
																	</td>
																	<td style="width:70%; text-align:left;">
																		<input name="userName" id="userName" size="55" maxlength="40" value="<%=userName%>" />
																	</td>
																</tr>
																<tr>
																	<td style="width:30%; text-align:right; background:#EFEFEF;">
																		<font class="etiqueta">* Contrase&ntilde;a</font>
																	</td>
																	<td style="width:70%; text-align:left;">
																		<input name="userPasswd" id="userPasswd" type="password" size="10" maxlength="10" value="<%=userPasswd%>" />
																	</td>
																</tr>
															</table>
															<hr style="margin:0">															
														</td>
													</tr>
													<tr>
														<td>
														* Campos obligatorios
														</td>
													</tr>
												</table>
											</div>
										<%end if%>			
										<br>										
										<table id="tableBotonera" align="center" width="100%" border="0" bgcolor="#EFEFEF" cellspacing="0" cellpadding="0">
											<tr>
												<td align="center" valign="middle">													
													<img onclick="sendForm()" src="images/btn_aceptar_0.gif" style="vertical-align:middle" WIDTH="74" HEIGHT="26"/>
													<a href="inbox.asp?inbox=<%=wichPage%>" >
														<img name="pic_cancelar" src="images/btn_cancelar_0.gif" style="vertical-align:middle" WIDTH="74" HEIGHT="26"/>
													</a>
													<%if action="edit" then %>
														<img onclick="delRegister()" id="btn_delete" src="images/btn_eliminar_0.gif" style="vertical-align:middle" WIDTH="74" HEIGHT="26"
															 onmouseover="toogleImage(1)" onmouseout="toogleImage(0)"/>
													<%end if%>
												</td>
											</tr>
										</table>
									</td>
								</tr>
							</table>
							<br>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
		<!--#INCLUDE FILE="uti_calce.asp"-->
		<input id="wichPage" type="hidden" name="wichPage" value="<%=wichPage%>" />
		<input id="action" type="hidden" name="action" value="<%=action%>" />
	</form>
	<%	int_ancho_ayuda="370"%>

	<!--#INCLUDE FILE="uti_ayuda_inicio.asp"-->
	<div id="help" style="display:none;" >
		<!--#INCLUDE FILE="uti_ayuda.asp"-->
	</div>
	
	<table Align="center" width="96%" border="0" cellspacing="0" cellpadding="4">
		<tr>
			<td width="100%" align="left" valign="top" cellspacing="0" cellpadding="0">
				<font class="titulo-listado">Actualización de Divisiones:</font>
					<br><br>
					<font class="etiqueta_normal">
					Capture los datos.
					<br><br>
					<b>Datos:</b>
					<br><br>
					<b><i>Clave:</i></b><br>
					Capture la clave que identifica a la división. Puede utilizar hasta 10 dígitos alfanuméricos (letras y/o números). Procure utilizar una clave que al verla identifique fácilmente a la división.
					<br><br>
					<b><i>Nombre:</i></b><br>
					Capture el nombre de la división.
					<br><br>
					<b><i>Estatus:</i></b><br>
					Seleccione el estatus de la división: Activo o Desactivo.
					<br><br>
					<b>Opciones:</b>
					<br><br>
					<b><i>Aceptar:</i></b><br>
					Grabar los datos.
					<br><br>
					<b><i>Cancelar:</i></b><br>
					Regresar a la pantalla anterior sin grabar cambios.
					<br><br>
					<b><i>Eliminar:</i></b><br>
					Eliminar el registro actual.
					<br><br>
					
				</font>
			</td>
		</tr>
	</table>
	<!--#INCLUDE FILE="uti_ayuda_fin.asp"-->
	</body>
</html>

