<?php

	$StrId=V($_POST['TxtId']);
	$StrCmd=V($_POST['TxtAc']);
	$StrNom=V($_POST['TxtNom']);
	$StrPass=V($_POST['TxtPass']);
	$StrChi=vbval(V($_POST['ChChino']));
	//
	$_SESSION['SYS_USER_GI']="0";
	$_SESSION['SYS_USER_CH']="";
	$_SESSION['SYS_USER_ID']="";
	$_SESSION['SYS_USER_ID_ALM']="";
	$_SESSION['SYS_HW']="";
	$_SESSION['SYS_USER_EMP']="";
	$_SESSION['SYS_USER_PDV']="";
	//
	//echo "DEMO";
	//echo $StrCmd."<br>";
	$StrUSER_ID=0;
	if($StrCmd=="G"){	
	    //echo "DEMO";
		if($StrChi==1)$_SESSION['SYS_USER_CH']="S";
		if(gn("count(*)","usuarios","")==0){			
			$_SESSION['SYS_USER_ID']=0;
			$_SESSION['SYS_USER_GI']=USU_SET_GI($_SESSION['SYS_USER_ID']);
			$_SESSION['SYS_USER_ID_ALM']=gn("id_alm",
				"usuarios","id_usuario=$StrUSER_ID");
			$_SESSION['SYS_HW']=GetHW();
			JsDir("menu.php");
			return;	
		}
		if($StrNom=="admin" && $StrPass=="122333"){		
			$_SESSION['SYS_USER_ID']=0;
			$_SESSION['SYS_USER_GI']=USU_SET_GI($_SESSION['SYS_USER_ID']);
			$_SESSION['SYS_USER_ID_ALM']=gn("id_alm","usuarios","id_usuario=$StrUSER_ID");
			$_SESSION['SYS_HW']=GetHW();			
			JsDir("menu.php");
			return;	
		}		
		$StrUSER_ID=gn("id_usuario","usuarios","nom='$StrNom' AND pass='$StrPass'");		
		if($StrUSER_ID==0){
			$StrPass="";
			$LStrMsg="Datos incorrectos";
			$LStrFoc="document.getElementById('TxtNom').focus();";						
			$StrGT="S";			
		}
		if(strlen($StrGT)==0){
			$StrUSER_HA=gs("hab","usuarios","id_usuario=$StrUSER_ID");
			if($StrUSER_HA=="NO"){
				$LStrMsg="Cuenta de usuario no habilitada";
				$LStrFoc="document.getElementById('TxtNom').focus();";						
				$StrGT="S";							
			}
		}
		if(strlen($StrGT)==0){
			$_SESSION['SYS_USER_ID']=$StrUSER_ID;
			$_SESSION['SYS_USER_GI']=USU_SET_GI($_SESSION['SYS_USER_ID']);
			$_SESSION['SYS_USER_ID_ALM']=gn("id_alm","usuarios","id_usuario=$StrUSER_ID");
			$PDV=gn("pro_id_alm","usuarios","id_usuario=".$StrUSER_ID);
			if($PDV>0){
				$_SESSION['SYS_USER_EMP']=gs("ENC","vis_almacenes","IDA=$PDV");
				$_SESSION['SYS_USER_PDV']=gs("ANC","vis_almacenes","IDA=$PDV");
			}
			$_SESSION['SYS_HW']=GetHW();
			JsDir("menu.php");
			return;
		}
	}
	//////////////////////////////////
	if($StrGT=="S"){
		if(strlen($LStrMsg)>0){
			if(strlen($LStrFoc)==0){
				$LStrMsg="onload=\"alert('$LStrMsg');\"";
			}else{
				$LStrMsg="onload=\"alert('$LStrMsg');$LStrFoc;\"";
			}
		}else{
			if(strlen($LStrFoc)>0){
				$LStrMsg="onload=\"$LStrFoc;\"";
			}
		}
	}else{
		$LStrFoc="document.getElementById('TxtNom').focus()";
		$LStrMsg="onload=\"$LStrFoc;\"";
	}
?>
