<?php
$PageSecurity = 11;
//echo $_SERVER['QUERY_STRING'];exit;
include('includes/session.inc');

if(isset($_GET['Category']))
{
	  $type=$_GET['Category'];
	 $strChar = "";
	  $sql='select categoryid from stockcategory where stockmaincategory="'.$type.'" order by categoryid desc limit 0,10';
	 $result = DB_query($sql,$db);
	 $numrows = DB_num_rows($result);
	 if($numrows>0)
	 {
			 $i=0;
			 $strmax = "";
			while($myrow=DB_Fetch_array($result))
			{
				if($myrow['categoryid']!="")
				{
					 $val= substr($myrow['categoryid'],2);
			
				  	 $strChar = substr($myrow['categoryid'],0,2);
					 if($val!="")
					 {
						 $arr[$i] = $val;
						 $i++;
					}
				}
				
			}
			if(is_array($arr))
			{ 
				$maxval =  max($arr);
			}
			else
			{
				$maxval=0;
			}
	 }
	 else
	 {
	  	 $sql='select stockmaincategoryid from stockmaincategory  where stockmaincategoryname="'.$type.'" order by stockmaincategoryid desc limit 0,10';
		 $result = DB_query($sql,$db);
		 $myrow=DB_Fetch_array($result);
		 $strChar = $myrow['stockmaincategoryid'];
	 }	 
	 
	$strFinal = $maxval+1;
	//$strBothFinal = $strChar.str_pad($strFinal,2,"0",STR_PAD_LEFT);     
	$strBothFinal = $type.str_pad($strFinal,2,"0",STR_PAD_LEFT);   //19-9-2011 modified date
    echo $strBothFinal ; 
}

if(isset($_GET['Category1']))
{
	   	$type = $_GET['Category1'];
	 	$sql='select categoryid,categorydescription from stockcategory where stockmaincategory ="'.$type.'"';
	 	$result = DB_query($sql,$db); ?>
		<select id="itemcode" name="itemcodeval" onChange="putnumber(this.value)">
		<option value="000">Select Sub Category</option> 
		<?php 
		while($myrow=DB_Fetch_array($result))
		{?>
			<option value="<?php echo $myrow['categoryid'];?>"<?php echo ($_REQUEST['itemcodeval']==$myrow['categoryid']?'selected':'')?>><?php echo $myrow['categorydescription'];?></option>
<?php 	} ?>
</select>
<?php		//echo $m;
		}
		
?>
