<?php
	$StrHWND_K=$_SESSION['SYS_HW']."_K";
	//-------------------------
	$StrId=V($_POST['TxtId']);
	$StrCmd=V($_POST['TxtAc']);
	if(strlen($StrCmd)==0){
		$StrCmd=V($_GET['TxtAc']);
		if($StrCmd=="X")$StrCmd="C";
	}
	//-------------------------
	$StrEmp=V($_POST['CboEmp']);
	$StrAlm=V($_POST['CboAlm']);
	//
	if(strlen($StrEmp)==0)$StrEmp=GE("N");
	if(strlen($StrAlm)==0)$StrAlm=GA($StrEmp,"N");	
	//	
	$StrPro_ID=V($_POST['Pro_TxtId']);
	$StrPro_DE=V($_POST['Pro_TxtDes']);
	//----------------------
	$StrIdPro=$StrPro_ID;
	$StrCod=V($_POST['TxtCod']);
	$StrDes=V($_POST['TxtDes']);
	$StrPre=vbval(V($_POST['CboPre']));
	$StrDex=V($_POST['TxtDex']);
	//
	$StrDex_=val_dex($StrDex);
	//
	if(strlen($StrPro_ID)==0 || !is_numeric($StrPro_ID)) $StrPro_ID="0";
	//FUNCIONES DE DESZPLAZAMIENTO
	if(strlen($LStrPag)==0)$LStrPag="0";
	if($StrCmd=="MSig")$LStrPag=($LStrPag+1);
	if($StrCmd=="MAnt")$LStrPag=($LStrPag-1);
	if($StrCmd=="MPri")$LStrPag=0;
	if($StrCmd=="MUlt")$LStrPag=(floor($LStrTR / $VP_RegXPag) );	
	//
	if($StrCmd=="C"){
		ejt("DELETE FROM kardex WHERE hwnd='$StrHWND_K'");
		$StrCod="";
		$StrDes="";
		$StrPro_ID="";
		$StrPro_DE="";
	}
	$cx=0;		
	//FUNCIONES DE ACTUALIZACION
	if($StrCmd=="G" && strlen($StrGT)==0){	
		$StrIdPro=gn("id_producto","productos","pro_codigo='$StrCod'");	
		$StrEmp_=gn("id_emp","empresas","emp_nomc='$StrEmp'");
		$StrIdAlm=gn("id_almacen","almacenes","alm_obs='$StrAlm' AND alm_id_empresa=$StrEmp_");
		ejt("DELETE FROM kardex WHERE hwnd='$StrHWND_K'");
		//INI
		$_STOCK_ACTUAL=gn("sp_cantidad",
						  "stocks_presentaciones",
						   "sp_id_almacen=$StrIdAlm AND 
						   sp_id_producto=$StrIdPro AND 
						   sp_presentacion=$StrPre");
		//echo "SA".$_STOCK_ACTUAL."<br>";
		$_CC=0;
		//COMPRAS
		$K_FE="";
		$K_CO="";
		$K_NU="";
		$K_CP="";
		$K_CA="";
		$K_GI="";		
		$K_SI=0;
		$K_SF=0;
		//
		$TOT_SAI=0;
		//
		$TOT_COM=gn("SUM(CA)","vkar_com","ID_PRO=$StrIdPro AND ID_ALM=$StrIdAlm AND ET='NO' AND UNI=$StrPre AND FEC<'$StrDex_'");
		//echo "FB=".$StrDex_."<br>";
		//echo "TC=".$TOT_COM."<br>";
		$TOT_DEV=gn("SUM(CA)","vkar_devoluciones","ID_PRO=$StrIdPro AND ID_ALM=$StrIdAlm  AND PIE=$StrPre AND FEC<'$StrDex_'");
		//echo "DEV=".$TOT_DEV."<br>";
		$TOT_AJA=gn("SUM(CA)","vkar_aju","ID_PRO=$StrIdPro AND ID_ALM=$StrIdAlm AND ACC='A' AND UNI=$StrPre AND FEC<'$StrDex_'");		
		$TOT_AJP_A=gn("SUM(CA)","vkar_ajup","ID_PRO=$StrIdPro AND ID_ALM=$StrIdAlm AND ACC='Q' AND PIE_N=$StrPre AND FEC<'$StrDex_'");
		$TOT_AXA=gn("SUM(cant)","ajustex","id_producto=$StrIdPro AND id_almacen=$StrIdAlm AND accion='A' AND piezas=$StrPre AND fecha<'$StrDex_'");			
		$TOT_TRA_GE=gn("SUM(GE_KA)","vkar_transformaciones","ID_PRO=$StrIdPro AND ID_ALM=$StrIdAlm AND GE_PIE=$StrPre AND FEC<'$StrDex_'");
		$TOT_TRA_SU=gn("SUM(SU_KA)","vkar_transformaciones","ID_PRO=$StrIdPro AND ID_ALM=$StrIdAlm AND SU_PIE=$StrPre AND FEC<'$StrDex_'");		
		$TOT_TRI=gn("SUM(CA)","vkar_tra","ID_PRO=$StrIdPro AND ID_ALM_D=$StrIdAlm AND VAL='S' AND UNI=$StrPre AND FEC<'$StrDex_'");		
		//
		$TOT_GIN=gn("SUM(CA)","vkar_gui_int","ID_PRO=$StrIdPro AND ID_ALM=$StrIdAlm AND PIE=$StrPre AND FEC<'$StrDex_'");		
		$TOT_AJQ=gn("SUM(CA)","vkar_aju","ID_PRO=$StrIdPro AND ID_ALM=$StrIdAlm AND ACC='Q' AND UNI=$StrPre AND FEC<'$StrDex_'");	
		$TOT_AJP=gn("SUM(CA)","vkar_ajup","ID_PRO=$StrIdPro AND ID_ALM=$StrIdAlm AND ACC='Q' AND PIE=$StrPre AND FEC<'$StrDex_'");
		$TOT_AXQ=gn("SUM(cant)","ajustex","id_producto=$StrIdPro AND id_almacen=$StrIdAlm AND accion='Q' AND piezas=$StrPre AND fecha<'$StrDex_'");	
		$TOT_VEN=gn("SUM(CA)","vkar_ven","ID_PRO=$StrIdPro AND ID_ALM=$StrIdAlm AND UNI=$StrPre AND FEC<'$StrDex_'");			
		$TOT_GIA=gn("SUM(CA)","vkar_gui","ID_PRO=$StrIdPro AND ID_ALM=$StrIdAlm AND UNI=$StrPre AND FEC<'$StrDex_'");		
		$TOT_TRA_SA=gn("SUM(SA_KA)","vkar_transformaciones","ID_PRO=$StrIdPro AND ID_ALM=$StrIdAlm AND SA_PIE=$StrPre AND FEC<'$StrDex_'");
		$TOT_TRA_RE=gn("SUM(RE_KA)","vkar_transformaciones","ID_PRO=$StrIdPro AND ID_ALM=$StrIdAlm AND RE_PIE=$StrPre AND FEC<'$StrDex_'");		
		
		$TOT_TRS=gn("SUM(CA)","vkar_tra","ID_PRO=$StrIdPro AND ID_ALM_O=$StrIdAlm AND VAL='S' AND UNI=$StrPre AND FEC<'$StrDex_'");		
		//
		$TOT_SAI=$TOT_SAI +	($TOT_COM+$TOT_TRI+$TOT_AJA+$TOT_AXA+$TOT_DEV+$TOT_AJP_A+$TOT_TRA_GE+$TOT_TRA_SU) - ($TOT_TRS+$TOT_AJP+$TOT_AJQ+$TOT_AXQ+$TOT_GIN+$TOT_VEN+$TOT_GIA+$TOT_TRA_SA+$TOT_TRA_RE);
		//echo "SI=".	$TOT_SAI."<br>";
		//
		$s="SELECT FEC,COM,NRO,CONCAT(REF_COM,' ',REF_SER,'-',REF_NUM) as REF,CA as TOT_PIE,GI 
			FROM vkar_devoluciones 
			WHERE ID_PRO=$StrIdPro AND ID_ALM=$StrIdAlm  AND PIE=$StrPre AND FEC>='$StrDex_' ORDER BY FEC,GI";
		$result = grs($s);						
		while ($row = $result->fetch_assoc()){
			$cx++;
			$K_FE=$row['FEC'];
			$K_CO=$row['COM'];
			$K_NU=$row['NRO'];
			$K_CP=$row['REF'];
			$K_CA=$row['TOT_PIE'];
			$K_GI=$row['GI'];
			$_CC=$_CC+$K_CA;			
			$s="INSERT INTO kardex VALUES ($cx,'$StrHWND_K',
				'$K_FE','$K_CO','$K_NU','$K_CP',0,$K_CA,0,0,$K_GI)";
			ejt($s);			
		}
		//////////////////////////////////////////////////////////////
		$s="SELECT FEC,COM,NUM,PROV,GE_KA,GI 
			FROM vkar_transformaciones 
			WHERE 
			ID_PRO=$StrIdPro AND 
			ID_ALM=$StrIdAlm AND 
			GE_PIE=$StrPre   AND FEC>='$StrDex_'
			ORDER BY FEC,GI";
		$result = grs($s);						
		while ($row = $result->fetch_row()){
			$cx++;
			$K_FE=$row[0];
			$K_CO=$row[1];
			$K_NU=$row[2];
			$K_CP=$row[3];
			$K_CA=$row[4];
			$K_GI=$row[5];
			$_CC=$_CC+$K_CA;			
			$s="INSERT INTO kardex VALUES ($cx,'$StrHWND_K',
				'$K_FE','$K_CO','$K_NU','$K_CP',0,$K_CA,0,0,$K_GI)";
			ejt($s);			
		}
		
		$s="SELECT FEC,COM,NUM,PROV,SU_KA,GI 
			FROM vkar_transformaciones 
			WHERE 
			ID_PRO=$StrIdPro AND 
			ID_ALM=$StrIdAlm AND 
			SU_PIE=$StrPre   AND FEC>='$StrDex_'
			ORDER BY FEC,GI";
		$result = grs($s);						
		while ($row = $result->fetch_row()){
			$cx++;
			$K_FE=$row[0];
			$K_CO=$row[1];
			$K_NU=$row[2];
			$K_CP=$row[3];
			$K_CA=$row[4];
			$K_GI=$row[5];
			$_CC=$_CC + $K_CA;			
			$s="INSERT INTO kardex VALUES ($cx,'$StrHWND_K',
				'$K_FE','$K_CO','$K_NU','$K_CP',0,$K_CA,0,0,$K_GI)";
			ejt($s);			
		}
							
		//	
		$s="SELECT FEC,COM,NUM,PROV,CA,GI 
			FROM vkar_com 
			WHERE 
			ID_PRO=$StrIdPro AND 
			ID_ALM=$StrIdAlm AND 
			ET='NO' AND 
			UNI=$StrPre AND FEC>='$StrDex_' 
			ORDER BY FEC,GI";
		$result = grs($s);						
		while ($row = $result->fetch_row()){
			$cx++;
			$K_FE=$row[0];
			$K_CO=$row[1];
			$K_NU=$row[2];
			$K_CP=$row[3];
			$K_CA=$row[4];
			$K_GI=$row[5];
			$_CC=$_CC + $K_CA;			
			$s="INSERT INTO kardex VALUES ($cx,'$StrHWND_K',
				'$K_FE','$K_CO','$K_NU','$K_CP',0,$K_CA,0,0,$K_GI)";
			ejt($s);			
		}
		//////////////////////////////////////////////////////////////		
		$s="SELECT FEC,'TRANSFERENCIA' as COM,NUM,ORI,CA,GI,TSER,TNUM,ID_TRA 
			FROM vkar_tra 
			WHERE ID_PRO=$StrIdPro AND ID_ALM_D=$StrIdAlm AND VAL='S' AND UNI=$StrPre AND FEC>='$StrDex_' 
			ORDER BY FEC,GI";			
		$result = grs($s);					
		while ($row = $result->fetch_row()){
			$cx++;
			$K_FE=$row[0];
			$K_CO=$row[1];
			$K_NU=$row[6]."-".$row[7]."(".$row[8].")";
			$K_CP=$row[3];
			$K_CA=$row[4];
			$K_GI=$row[5];
			$_CC=$_CC+$K_CA;						
			$s="INSERT INTO kardex VALUES ($cx,'$StrHWND_K',
				'$K_FE','$K_CO','$K_NU','$K_CP',0,$K_CA,0,0,$K_GI)";
			ejt($s);			
		}
		//////////////////////////////////////////////////////////////		
		//////////////////////////////////////////////////////////////		
		//////////////////////////////////////////////////////////////		
		//////////////////////////////////////////////////////////////		
		//////////////////////////////////////////////////////////////		
		$s="SELECT FEC,'TRANSFERENCIA' as COM,NUM,DES,CA,GI,TSER,TNUM ,ID_TRA 
			FROM vkar_tra 
			WHERE ID_PRO=$StrIdPro AND ID_ALM_O=$StrIdAlm AND VAL='S' AND UNI=$StrPre AND FEC>='$StrDex_' 
			ORDER BY FEC,GI";			
		$result = grs($s);					
		while ($row = $result->fetch_row()){
			$cx++;
			$K_FE=$row[0];
			$K_CO=$row[1];
			$K_NU=$row[6]."-".$row[7]."(".$row[8].")";
			$K_CP=$row[3];
			$K_CA=$row[4];
			$K_GI=$row[5];		
			$_CC=$_CC - $K_CA;				
			$s="INSERT INTO kardex VALUES ($cx,'$StrHWND_K',
				'$K_FE','$K_CO','$K_NU','$K_CP',0,0,$K_CA,0,$K_GI)";
			ejt($s);			
		}
		//////////////////////////////////////////////////////////////		
		$s="SELECT FEC,COM,NUM,ACC,CA as TOT_PIE,GI 
			FROM vkar_ajup 
			WHERE ID_PRO=$StrIdPro AND ID_ALM=$StrIdAlm AND ACC='Q' AND PIE=$StrPre AND FEC>='$StrDex_' 
			ORDER BY FEC,GI";				
		$result = grs($s);					
		while ($row = $result->fetch_assoc()){
			$cx++;
			$K_FE=$row['FEC'];
			$K_CO=$row['COM'];
			$K_NU=$row['NUM'];
			$K_CP="";
			$K_CA=$row['TOT_PIE'];
			$K_GI=$row['GI'];	
			$_CC=$_CC - $K_CA;					
			$s="INSERT INTO kardex VALUES ($cx,'$StrHWND_K',
				'$K_FE','$K_CO','$K_NU','$K_CP',0,0,$K_CA,0,$K_GI)";
			ejt($s);			
		}
		//ADD
		$s="SELECT FEC,COM,NUM,ACC,CA,GI 
			FROM vkar_ajup 
			WHERE ID_PRO=$StrIdPro AND ID_ALM=$StrIdAlm AND ACC='Q' AND PIE_N=$StrPre AND FEC>='$StrDex_' 
			ORDER BY FEC,GI";
		$result = grs($s);					
		while ($row = $result->fetch_row()){
			$cx++;
			$K_FE=$row[0];
			$K_CO=$row[1];
			$K_NU=$row[2];
			$K_CP="";
			$K_CA=$row[4];
			$K_GI=$row[5];		
			$_CC=$_CC + $K_CA;				
			$s="INSERT INTO kardex VALUES ($cx,'$StrHWND_K',
				'$K_FE','$K_CO','$K_NU','$K_CP',0,$K_CA,0,0,$K_GI)";
			ejt($s);			
		}				
		//////////////////////////////////////////////////////////////		
		$s="SELECT FEC,'AJUSTE' as COM,NUM,ACC,CA,GI 
			FROM vkar_aju 
			WHERE ID_PRO=$StrIdPro AND ID_ALM=$StrIdAlm AND ACC='Q' AND UNI=$StrPre AND FEC>='$StrDex_' 
			ORDER BY FEC,GI";				
		$result = grs($s);					
		while ($row = $result->fetch_row()){
			$cx++;
			$K_FE=$row[0];
			$K_CO=$row[1];
			$K_NU=$row[2];
			$K_CP="";
			$K_CA=$row[4];
			$K_GI=$row[5];	
			$_CC=$_CC-$K_CA;					
			$s="INSERT INTO kardex VALUES ($cx,'$StrHWND_K',
				'$K_FE','$K_CO','$K_NU','$K_CP',0,0,$K_CA,0,$K_GI)";
			ejt($s);			
		}				
		
		$s="SELECT fecha,'AJUXTE' as COM,id_ajuste,accion,cant,gi,obs 
			FROM ajustex 
			WHERE id_producto=$StrIdPro AND 
			id_almacen=$StrIdAlm AND accion='Q' AND piezas=$StrPre AND fecha>='$StrDex_'
			ORDER BY fecha";		
		$result = grs($s);					
		while ($row = $result->fetch_row()){
			$cx++;
			$K_FE=$row[0];
			$K_CO=$row[1];
			$K_NU=$row[2];
			$K_CP=$row[6];
			$K_CA=$row[4];
			$K_GI=$row[5];	
			$_CC=$_CC-$K_CA;					
			$s="INSERT INTO kardex VALUES ($cx,'$StrHWND_K',
				'$K_FE','$K_CO','$K_NU','$K_CP',0,0,$K_CA,0,$K_GI)";
			ejt($s);			
		}				
		//ADD
		$KK=0;
		$s="SELECT fecha,'AJUXTE' as COM,id_ajuste,accion,cant,gi,obs
			FROM ajustex 
			WHERE id_producto=$StrIdPro AND 
			id_almacen=$StrIdAlm AND accion='A' AND piezas=$StrPre AND fecha>='$StrDex_'
			ORDER BY fecha";	
		$result = grs($s);					
		while ($row = $result->fetch_row()){
			$cx++;
			$K_FE=$row[0];
			$K_CO=$row[1];
			$K_NU=$row[2];
			$K_CP=$row[6];
			$K_CA=$row[4];
			$K_GI=$row[5];		
			$_CC=$_CC+$K_CA;				
			$s="INSERT INTO kardex VALUES ($cx,'$StrHWND_K',
				'$K_FE','$K_CO','$K_NU','$K_CP',0,$K_CA,0,0,$K_GI)";
			$KK=$KK + $K_CA;
			ejt($s);			
		}				
		//ADD
		$s="SELECT FEC,'AJUSTE' as COM,NUM,ACC,CA,GI 
			FROM vkar_aju 
			WHERE ID_PRO=$StrIdPro AND ID_ALM=$StrIdAlm AND ACC='A' AND UNI=$StrPre AND FEC>='$StrDex_'
			ORDER BY FEC,GI";
		$result = grs($s);					
		while ($row = $result->fetch_row()){
			$cx++;
			$K_FE=$row[0];
			$K_CO=$row[1];
			$K_NU=$row[2];
			$K_CP="";
			$K_CA=$row[4];
			$K_GI=$row[5];		
			$_CC=$_CC+$K_CA;				
			$s="INSERT INTO kardex VALUES ($cx,'$StrHWND_K',
				'$K_FE','$K_CO','$K_NU','$K_CP',0,$K_CA,0,0,$K_GI)";
			ejt($s);			
		}				
		//////////////////////////////////////////////////////////////
		$s="SELECT FEC,COM,NUM,CLI,CA as TOT_PIE,GI,CONCAT(COT_SER,'-',COT_NUM) as REF
			FROM vkar_gui_int 
			WHERE ID_PRO=$StrIdPro AND ID_ALM=$StrIdAlm AND PIE=$StrPre AND FEC>='$StrDex_'
			ORDER BY FEC,GI";
		$result = grs($s);					
		while ($row = $result->fetch_assoc()){
			$cx++;
			$K_FE=$row['FEC'];
			$K_CO=$row['COM'];
			$K_NU=$row['NUM'];
			$K_CP=$row['REF']." | ".$row['CLI'];
			$K_CA=$row['TOT_PIE'];
			$K_GI=$row['GI'];	
			$_CC=$_CC - $K_CA;	
			//echo "$K_CA <br>";				
			$s="INSERT INTO kardex VALUES ($cx,'$StrHWND_K',
				'$K_FE','$K_CO','$K_NU','$K_CP',0,0,$K_CA,0,$K_GI)";
			ejt($s);			
		}	
		//////////////////////////////////////////////////////////////
		$s="SELECT FEC,COM,NUM,PROV,SA_KA,GI 
			FROM vkar_transformaciones  
			WHERE 
			ID_PRO=$StrIdPro AND 
			ID_ALM=$StrIdAlm AND 
			SA_PIE=$StrPre AND FEC>='$StrDex_' 
			ORDER BY FEC,GI";
		$result = grs($s);					
		while ($row = $result->fetch_row()){
			$cx++;
			$K_FE=$row[0];
			$K_CO=$row[1];
			$K_NU=$row[2];
			$K_CP=$row[3];
			$K_CA=$row[4];
			$K_GI=$row[5];	
			$_CC=$_CC - $K_CA;					
			$s="INSERT INTO kardex VALUES ($cx,'$StrHWND_K',
				'$K_FE','$K_CO','$K_NU','$K_CP',0,0,$K_CA,0,$K_GI)";
			ejt($s);			
		}
		
		$s="SELECT FEC,COM,NUM,PROV,RE_KA,GI 
			FROM vkar_transformaciones  
			WHERE 
			ID_PRO=$StrIdPro AND 
			ID_ALM=$StrIdAlm AND 
			RE_PIE=$StrPre AND FEC>='$StrDex_' 
			ORDER BY FEC,GI";
		$result = grs($s);					
		while ($row = $result->fetch_row()){
			$cx++;
			$K_FE=$row[0];
			$K_CO=$row[1];
			$K_NU=$row[2];
			$K_CP=$row[3];
			$K_CA=$row[4];
			$K_GI=$row[5];	
			$_CC=$_CC + $K_CA;					
			$s="INSERT INTO kardex VALUES ($cx,'$StrHWND_K',
				'$K_FE','$K_CO','$K_NU','$K_CP',0,0,$K_CA,0,$K_GI)";
			ejt($s);			
		}
								
		$s="SELECT FEC,COM,CONCAT(SER,'-',NUM),CLI,CA,GI 
			FROM vkar_ven 
			WHERE 
			ID_PRO=$StrIdPro AND 
			ID_ALM=$StrIdAlm AND 
			UNI=$StrPre AND FEC>='$StrDex_' 
			ORDER BY FEC,GI";
		$result = grs($s);					
		while ($row = $result->fetch_row()){
			$cx++;
			$K_FE=$row[0];
			$K_CO=$row[1];
			$K_NU=$row[2];
			$K_CP=$row[3];
			$K_CA=$row[4];
			$K_GI=$row[5];	
			$_CC=$_CC-$K_CA;					
			$s="INSERT INTO kardex VALUES ($cx,'$StrHWND_K',
				'$K_FE','$K_CO','$K_NU','$K_CP',0,0,$K_CA,0,$K_GI)";
			ejt($s);			
		}
		//////////////////////////////////////////////////////////////
		$s="SELECT FEC,COM,CONCAT(SER,'-',NUM),CLI,CA,GI 
			FROM vkar_gui 
			WHERE ID_PRO=$StrIdPro AND ID_ALM=$StrIdAlm AND UNI=$StrPre AND FEC>='$StrDex_' 
			ORDER BY FEC,GI";
		$result = grs($s);				
		while ($row = $result->fetch_row()){
			$cx++;
			$K_FE=$row[0];
			$K_CO=$row[1];
			$K_NU=$row[2];
			$K_CP=$row[3];
			$K_CA=$row[4];
			$K_GI=$row[5];	
			$_CC=$_CC-$K_CA;					
			$s="INSERT INTO kardex VALUES ($cx,'$StrHWND_K',
				'$K_FE','$K_CO','$K_NU','$K_CP',0,0,$K_CA,0,$K_GI)";
			ejt($s);			
		}
		//
		$s="INSERT INTO kardex VALUES (0,'$StrHWND_K','$StrDex_','SALDO INICIAL','','',0,0,0,$TOT_SAI,0)";
		ejt($s);
		//
		$K_SI=$TOT_SAI;	
		$K_SF=0;
		$s="SELECT id,ing,sal FROM kardex 
			WHERE hwnd='$StrHWND_K' ORDER BY fec,gi";
		$result = grs($s);			
		$KK_ING=0;
		$KK_SAL=0;
		$KK_ID=0;
		while ($row = $result->fetch_row()){
			$KK_ID=$row[0];
			$KK_ING=$row[1];
			$KK_SAL=$row[2];
			$K_SF=$K_SI + $KK_ING - $KK_SAL;
			$s="UPDATE kardex SET fin=$K_SF,ini=$K_SI 
				WHERE hwnd='$StrHWND_K' AND id=$KK_ID";
			ejt($s);			
			$K_SI=$K_SF;			
		}
		//////////////////////////////////////////////////////////////		
		$LStrMsg="Proceso terminado";
		$LStrFoc="document.getElementById('TxtCod').focus();";						
		$StrGT="S";		
	}	
	//////////////////////////////////
	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('CboAlm').focus();";	
		$LStrMsg="onload=\"$LStrFoc;\"";	
	}
?>