<?
session_start();
//session_unset();
//session_destroy();
//session_register('estado');
//session_register('usuario');
//session_register('pass');
//session_register('empresa');
//session_register('empresa_global');
	//para remuneraciones
if (!isset($_POST["usuario"]))
{
		?>
		<script>
			parent.location.href = 'index.php';
		</script>
		<? 

		exit();
}
?>

<form id="form1" name="form1" method="post" action="index2.php" target="_parent">
</form>
<?
$user=$_POST["usuario"];
$clave=$_POST["pass"];
//var_dump($user);
$claveen = md5($clave);
include("conex.php");
$sql_log = "SELECT * FROM usuarios WHERE user = '$user' AND clave = '$claveen'";
$res_log = mysql_query($sql_log, $enlace);

 if (mysql_fetch_object($res_log))
	{

	$id_user = mysql_result($res_log, 0, "id");
	$id_pda = mysql_result($res_log, 0, "pda");
	$sql_em = "SELECT * FROM usuario_empresa WHERE id_usuario = $id_user";
	$res_em = mysql_query($sql_em, $enlace);
	$id_empresa = mysql_result($res_em, 0, "id_empresa");	

	$_SESSION['estado'] = "ON";
	$_SESSION['usuario'] = "$user";
	$_SESSION['pass'] = "$claveen";
	$_SESSION['ss_empresa'] = "$id_empresa";
	//para remuneraciones
	$_SESSION['empresa_global'] = "$id_empresa";
	$_SESSION['ss_user'] ="$id_user";

	?>
	<script language="javascript">
	alert ($id_user);
	alert ($id_empresa);
	alert ($$user);
	</script>
	<?	
	
	if ($id_pda==1 || $id_pda==2 )
  {
        if ($id_pda==1)
	   {
	?>
	<script language="javascript">
	//document.form1.target='_parent';
	//document.form1.action="ventas_netbook/index.php";
	//document.form1.submit();
	parent.location.href = 'ventas_netbook/index.php';
	</script>
	<?	
	   }
	    if ($id_pda==2)
	   {
	?>
	<script language="javascript">
	//document.form1.target='_parent';
	//document.form1.action="ventas_pda/index.php";
	//document.form1.submit();
	parent.location.href = 'ventas_pda/index.php';
	</script>
	<?	
	   }
   }
	else
	
   {
	?>
	<script language="javascript">
	//document.form1.target='_parent';
	//document.form1.action="index2.php";
	//document.form1.submit();
	parent.location.href = 'index2.php';
	</script>
    <?
    }

	}
else
	{
	?>
	<script language="javascript">
	alert ("Usuario no existe");
	//document.form1.action="index.php";
	//document.form1.submit();
	parent.location.href = 'index_sistema.php';
	</script>
	<?	
	}
?>


