<?php 
$PageSecurity = 11;
include('includes/session.inc');
include('includes/function_lib.php');
$site=$_REQUEST['AUTO_NO'];
//$sub_site=substr($site,);
$qry=DB_query("select * from crm_dot_request_form where site='".$site."'",$db);
$NoRows=DB_num_rows($qry);

if($NoRows>0)
{
	$sel_code=DB_query("select max(form_no) AS max_id from crm_dot_request_form where site='".$site."'",$db);
	$sel_codeRow=DB_fetch_array($sel_code);
	$sub_code=substr($sel_codeRow['max_id'],-2);
	$maxid=$sub_code+1;
	$finalCode=$site."/".'SAM'."/".str_pad($maxid,4,"0",STR_PAD_LEFT);
}
else
{
	$finalCode=$site."/".'SAM'."/".'0001';
}

?>
<input type="text" name="form_no" id="form_no" value="<? echo $finalCode; ?>" style="width:50%" />