<? include("../../header_subnivel2.php");?>
<? //= $_SESSION[perfil];?>
<script type="text/javascript" src="../../js/jquery.js"></script>
<script type="text/javascript" src="../../js/funciones.js"></script>
<script type="text/javascript" src="../../js/validator.js"></script>
<script>
function llenar(forma) {
		var laDatos = valores_forma(forma);
		// Envio de peticion
		$.post( "usuarios_llenado.php",
				$(laDatos),
				function FuncionRecepcion(respuesta) {
					var laRespuesta = eval('(' + respuesta + ')');
					if ( laRespuesta != null ) {
						var laActions = laRespuesta["actions"];
						var liIdx;
						for ( liIdx=0 ; liIdx<laActions.length ; liIdx++ )
							eval( laActions[liIdx] );
					}
				});
}

function Guardar(forma) {
	
	mens='';
	if($('#name').val()==''){
		mens+='* Ingrese el nombre'+'\n';
		 
	}
	
	if($('#area').val()==''){
		mens+='* Ingrese el area'+'\n';
	}
	
	if($('#user').val()==''){
		mens+='* Ingrese el usuario'+'\n';
	}
	if($('#password').val()==''){
		mens+='* Ingrese el password'+'\n';
	}
	if($('#email').val()==''){
		mens+='* Ingrese el email'+'\n';
	}
	if($('#activo').val()==''){
		mens+='* Seleccione si esta activo o no'+'\n';
	}
	if($('#perfil').val()==''){
		mens+='* Seleccione el perfil'+'\n';
	}
	if(mens!=''){
	alert(mens)
	return
	}
		var laDatos = valores_forma(forma);
		// Envio de peticion
		$.post( "usuarios_procesar.php",
				$(laDatos),
				function FuncionRecepcion(respuesta) {
					var laRespuesta = eval('(' + respuesta + ')');
					if ( laRespuesta != null ) {
						var laActions = laRespuesta["actions"];
						var liIdx;
						for ( liIdx=0 ; liIdx<laActions.length ; liIdx++ )
							eval( laActions[liIdx] );
					}
				});
}

function Nuevo(forma) {
	disable_campos(false);
	//limpia_forma();
	$('#menu_editar').hide();
  	$('#menu_guardar').show();
	//$('#menu_eliminar').hide();
	$('#menu_cancelar').show();

	// Crear
	limpia_forma();
	$('#operacion').val('ALTA');

	$('#name').focus();

  }

  function disable_campos(valor) {
	$('#email').attr('disabled', valor);
	$('#area').attr('disabled', valor);
	$('#funcion').attr('disabled', valor);
	$('#activo').attr('disabled', valor);
	$('#password').attr('disabled', valor);
	$('#activo').attr('disabled', valor);
	$('#perfil').attr('disabled', valor);
	$('#rol').attr('disabled', valor);
	$('#compania').attr('disabled', valor);
	$('#user').attr('disabled', valor);
	$('#name').attr('disabled', valor);
  }

 function limpia_forma() {
	$('#email').val('');
	$('#area').val('');
	$('#funcion').val('');
	$('#usuarios_int').val('')
	$('#activo').val('');
	$('#password').val('');
	$('#activo').val('');
	$('#perfil').val('');
	$('#rol').val('');
	$('#compania').val('');
	$('#user').val('');
	$('#name').val('');
  }

function Cancelar(forma){
	limpia_forma(forma);
	disable_campos(true);
	$('#menu_crear').show();
	$('#menu_guardar').hide();
	$('#menu_editar').show();
	//$('#menu_eliminar').hide();
	$('#name').focus();
}

function Editar(forma) {
    if ( $('#usuarios_int').val() == "" ) {
    	alert("Por favor seleccione el usuario a editar.");
    	return;
    } else {
  		disable_campos(false);
  		$('#menu_editar').hide();
  		$('#menu_guardar').show();
		//$('#menu_eliminar').show();
		forma.operacion.value = 'CAMBIO';
  	}
}
$(document).ready( function() {
	$('#menu_guardar').hide();
	//$('#menu_eliminar').hide();
  });

</script>
   
<div align="justify" style="line-height:18px;margin-top:-20px; position:absolute;width: 960px; height:100% ">
<span style="color:#00AF4B">Perfiles/Privilegios &raquo;</span>
<div id="Formato"  ></div>

<form id="forma" name="forma">
 <input type="hidden" id="operacion" name="operacion" />
 <input type="hidden" id="idcontacto" name="idcontacto"/>
   <input name="valor" id="valor" value="1"  type="hidden" 
   onchange="genericAjax('divusuarios_int','lista_de_usuarios.php');Cancelar(document.forma)">
   <input name="logged" id="logged" type="hidden" value="<?=$_SESSION[idusuario] ?>">
<br />
<table width="951">
  
   <tr>
     <td colspan="5" >&nbsp;&nbsp;</td>
   </tr>
  
   <tr>
     <td id="t_contacto" align="left">Usuario</td>
     <td align="left">
     <div id="divusuarios_int"><? include('lista_de_usuarios.php')?></div>
	
     </td>
     <td>&nbsp;</td>
     <td  align="left" >&nbsp;</td>
     <td align="left">&nbsp;</td>
   </tr>
   <tr>
     <td align="left">&nbsp;</td>
     <td align="left">&nbsp;</td>
     <td>&nbsp;</td>
     <td  align="left">&nbsp;</td>
     <td align="left">&nbsp;</td>
   </tr>
   <tr>
     <td align="left">Nombre</td>
     <td align="left"><input name="name" id="name"  class="aa" size="40" disabled="disabled" /></td>
     <td>&nbsp;</td>
     <td  align="left">&nbsp;</td>
     <td align="left">&nbsp;</td>
   </tr>
   <tr>
     <td align="left">&nbsp;</td>
     <td align="left">&nbsp;</td>
     <td>&nbsp;</td>
     <td  align="left">&nbsp;</td>
     <td align="left">&nbsp;</td>
   </tr>
   <tr>
     <td align="left">Area</td>
     <td align="left"><select name="area" id="area" disabled="disabled" class="aa">
       <option value="">[Seleccionar]</option>
       <option value="I">Importación</option>
       <option value="E">Exportación</option>
       <option value="C">Comercial</option>
     </select></td>
     <td>&nbsp;</td>
     <td  align="left">&nbsp;</td>
     <td align="left">&nbsp;</td>
   </tr>
   <tr>
     <td id="t_email_contacto2" align="left">&nbsp;</td>
     <td align="left">&nbsp;</td>
     <td>&nbsp;</td>
     <td  align="left">&nbsp;</td>
     <td align="left">&nbsp;</td>
   </tr>
   <tr>
     <td id="t_email_contacto5" align="left">User</td>
     <td align="left"><input name="user" id="user"  class="aa" size="40" disabled="disabled" /></td>
     <td>&nbsp;</td>
     <td  align="left">&nbsp;</td>
     <td align="left">&nbsp;</td>
   </tr>
   <tr>
     <td id="t_email_contacto4" align="left">&nbsp;</td>
     <td align="left">&nbsp;</td>
     <td>&nbsp;</td>
     <td  align="left">&nbsp;</td>
     <td align="left">&nbsp;</td>
   </tr>
   <tr>
     <td id="t_email_contacto7" align="left">Password</td>
     <td align="left"><input name="password" id="password"  class="aa" size="40" disabled="disabled" /></td>
     <td>&nbsp;</td>
     <td  align="left">&nbsp;</td>
     <td align="left">&nbsp;</td>
   </tr>
   <tr>
     <td id="t_email_contacto6" align="left">&nbsp;</td>
     <td align="left">&nbsp;</td>
     <td>&nbsp;</td>
     <td  align="left">&nbsp;</td>
     <td align="left">&nbsp;</td>
   </tr>
   <tr>
     <td id="t_email_contacto9" align="left">Email</td>
     <td align="left"><input name="email" id="email"  class="aa" size="40" disabled="disabled" /></td>
     <td>&nbsp;</td>
     <td  align="left">&nbsp;</td>
     <td align="left">&nbsp;</td>
   </tr>
   <tr>
     <td id="t_email_contacto8" align="left">&nbsp;</td>
     <td align="left">&nbsp;</td>
     <td>&nbsp;</td>
     <td  align="left">&nbsp;</td>
     <td align="left">&nbsp;</td>
   </tr>
   <tr>
     <td align="left">Activo</td>
     <td align="left"><select name="activo" id="activo" disabled="disabled" class="aa">
       <option value="">[Seleccionar]</option>
       <option value="1">SI</option>
       <option value="0">NO</option>
     </select></td>
     <td>&nbsp;</td>
     <td  align="left">&nbsp;</td>
     <td align="left">&nbsp;</td>
   </tr>
   <tr>
     <td id="t_email_contacto10" align="left">&nbsp;</td>
     <td align="left">&nbsp;</td>
     <td>&nbsp;</td>
     <td  align="left">&nbsp;</td>
     <td align="left">&nbsp;</td>
   </tr>
   <tr>
     <td id="t_email_contacto13" align="left">Compañía</td>
     <td align="left"><input name="compania" id="compania"  class="aa" size="40" disabled="disabled" /></td>
     <td>&nbsp;</td>
     <td  align="left">&nbsp;</td>
     <td align="left">&nbsp;</td>
   </tr>
   <tr>
     <td id="t_email_contacto12" align="left">&nbsp;</td>
     <td align="left">&nbsp;</td>
     <td>&nbsp;</td>
     <td  align="left">&nbsp;</td>
     <td align="left">&nbsp;</td>
   </tr>
   <tr>
     <td id="t_email_contacto15" align="left">Función</td>
     <td align="left"><input name="funcion" id="funcion"  class="aa" size="40" disabled="disabled" /></td>
     <td>&nbsp;</td>
     <td  align="left">&nbsp;</td>
     <td align="left">&nbsp;</td>
   </tr>
   <tr>
     <td id="t_email_contacto14" align="left">&nbsp;</td>
     <td align="left">&nbsp;</td>
     <td>&nbsp;</td>
     <td  align="left">&nbsp;</td>
     <td align="left">&nbsp;</td>
   </tr>
   <tr>
     <td id="t_email_contacto" align="left">Perfil de usuario</td>
     <td align="left"><select name="perfil" id="perfil" disabled="disabled" class="aa">
        <option value="">[Seleccionar]</option>
       <option value="General">General</option>
       <option value="Consulta">Consulta</option>
       <option value="Personalizado">Personalizado</option>
     </select></td>
     <td>&nbsp;</td>
     <td  align="left">&nbsp;</td>
     <td align="left">&nbsp;</td>
   </tr>
   <tr>
     <td id="t_nombre4" align="left">&nbsp;</td>
     <td align="left">&nbsp;</td>
     <td>&nbsp;</td>
     <td  align="left">&nbsp;</td>
     <td align="left">&nbsp;</td>
   </tr>
   
   <tr>
     <td colspan="5" align="left" id="t_nombre7"><input type="button" id="menu_crear" value="Alta"  class="ab" onClick="Nuevo(document.forma)" />
       <input type="button" id="menu_editar" value="Modificar" class="ab" onClick="Editar(document.forma)" />
       <input type="button" id="menu_guardar" value="Guardar cambios" class="ab" onClick="Guardar(document.forma) "/>
       <!-- <input type="button" id="menu_eliminar" value="Eliminar" class="ab"  onclick="Eliminar(document.forma) "/>-->
       <input type="button" id="menu_buscar" value="Buscar" class="ab" onclick="if(document.getElementById('idalias').value=='' ) {alert('Ingrese el alias'); return; };genericAjax('divBuscar','buscar_contactos.php?idcliente='+$('#idcliente').val()+'&idalias='+$('#idalias').val()) " />
       <input type="button" id="menu_cancelar" value="Cancelar" class="ab" onClick="Cancelar(document.forma)" /></td>
   </tr>
   <tr>
    <td width="203" id="t_nombre" align="left">&nbsp;</td>
    <td width="255" align="left">&nbsp;</td>
    <td width="17">&nbsp;</td>
    <td width="190"  align="left">&nbsp;</td>
    <td width="262" align="left">&nbsp;</td>
  </tr>
  
  <tr>
    <td width="203" id="t_nombre" align="left">&nbsp;</td>
    <td width="255" align="left">&nbsp;</td>
    <td width="17">&nbsp;</td>
    <td width="190"  align="left">&nbsp;</td>
    <td width="262" align="left">&nbsp;</td>
  </tr>
</table>
</form>
<br /> 

<script>
genericAjax('divusuarios_int','lista_de_usuarios.php');
</script>
<? include("../../pie_subnivel2.php");?>
