<?php

session_start();
header("Content-type: text/html; charset=".$_SESSION['encodingmode']);
if($_SESSION['dbName']==""){
header("location:../index.php");
}


include("config.inc.php");
include("function.inc.php");
include("Functions_Sales.php");
include("Forms_DataGrid_Manifest.php");



$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass']) or die("Could not connect to DB");
mysql_select_db($_SESSION['dbName'],$connection) or die("Could not find DB");


$module 	= $_POST["module"]; if ($module == ""){$module = $_GET["module"];} 	

if(	$_SESSION['encodingmode'] == 'utf8' || $_SESSION['encodingmode'] == 'utf-8'){
	mysql_query("SET NAMES 'utf8'"); 
	mysql_query('SET CHARACTER SET utf8'); 
	mysql_set_charset('utf8', $connection);
}

class tabs {
	var $name;
	var $tabs;
	var $active;
	var $current;
function start($name){
		if (empty($this->active)){ $this->active = $name; }
		$this->current = $name;
		ob_start();
	}
	function end(){
		$this->tabs[$this->current] = ob_get_contents();
		ob_end_clean();
	}
	function run(){
	
		if (count($this->tabs) > 0){
			echo "<DIV CLASS='tabs'>\n";
			$jsClear = "";
			foreach($this->tabs as $tabname => $tabcontent){
				$tabid = "tab_".$this->name."_$tabname";
				$contentid = "tabcontent_".$this->name."_$tabname";
				$jsClear .= "\tdocument.getElementById('$tabid').className = 'tab_inactive';\n";
				$jsClear .= "\tdocument.getElementById('$contentid').style.display = 'none';\n";
			}
			echo "<script type=\"text/javascript\">\n";
			echo "function tab_".$this->name."(id,fieldname){\n";
			
			
			
			echo "$jsClear";
			echo "\tdocument.getElementById('tab_".$this->name."_'+id).className = 'tab_active';\n";
			echo "\tdocument.getElementById('tabcontent_".$this->name."_'+id).style.display = '';\n";
			echo"	
				//alert(fieldname);
				if(fieldname!='' && fieldname!=undefined)
					
					document.salesman[fieldname].focus();
				";
			echo "}\n";
			echo "</script>\n";
			foreach($this->tabs as $tabname => $tabcontent){
				$tabid = "tab_".$this->name."_$tabname";
				$contentid = "tabcontent_".$this->name."_$tabname";
				echo "<DIV CLASS='";
				if ($this->active == $tabname){ echo "tab_active"; }else{ echo "tab_inactive"; }
				echo "' ID='$tabid' ";
				echo "onClick=\"tab_".$this->name."('$tabname');\">$tabname</DIV>\n";
			}
			echo "<DIV STYLE='float: center; clear:both;'></DIV>\n";
			foreach($this->tabs as $tabname => $tabcontent){
				$contentid = "tabcontent_".$this->name."_$tabname";
				echo "<DIV ID = '$contentid' CLASS='tab_content' STYLE='display: ";
				if ($this->active == $tabname){ echo "block"; }else{ echo "none"; }
				echo ";'>$tabcontent</DIV>\n";
			}
			echo "</DIV>\n";
			echo "<DIV STYLE='clear: both;'></DIV>\n";
		}}
}	

$querylog="SELECT FI_Salesmen as loginaccess ,language from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' 	and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."')	";
	$resultlog=mysql_query($querylog,$connection) or die(mysql_error());
	while($rows=mysql_fetch_array($resultlog)){
		extract($rows);
	}
	
	
	$querylang="select  language, creationdate, code, name, description,
	currency, credit_limit, manager, manager_ref, deactivate_date, bonus,
	 managercheck, address, sequenceprefix, area, warehouse, 
	cash_account, fax, phone1, email, phone2, tab1, tab2, tab3, tab4, Title, 
	First_Name, Father_Name, Last_Name, tel1, tel2, tel3, supp_email, reference, 
	city1, city2, city3, Start_Date, End_Date, Target_Amount, Target_Commission,
	client_code, client_name,commission
	from ".$_SESSION['dbLabel'].".salesman_label where 
	language='$language'";

//echo $querylang;
$resultlang=mysql_query($querylang,$connection) or die(mysql_error());
	while($rows=mysql_fetch_array($resultlang)){
		//extract($rows);
		
		$creationdate_label=$rows[1];
		$code_label=$rows[2];
		$name_label=$rows[3];
		
		$description_label=$rows[4];
		$currency_label=$rows[5];
		$credit_limit_label=$rows[6];
		$manager_label=$rows[7];
		$manager_ref_label=$rows[8];
		$deactivate_date_label=$rows[9];
		$bonus_label=$rows[10];
		$managercheck_label=$rows[11];
		$address_label =$rows[12];
		$sequenceprefix_label =$rows[13];
		$area_label =$rows[14];	
		$warehouse_label =$rows[15];
		$cash_account_label =$rows[16];
	
	
		
		$fax_label =$rows[17];
		$phone1_label =$rows[18];
		$email_label =$rows[19];
		$phone2_label =$rows[20];
		$tab1_label =$rows[21];
		$tab2_label =$rows[22];
		$tab3_label =$rows[23];
		$tab4_label =$rows[24];
			
	
		$Title_label =$rows[25];
		$First_Name_label =$rows[26];
		$Father_Name_label =$rows[27];
		$Last_Name_label =$rows[28];
		$tel1_label =$rows[29];
		$tel2_label =$rows[30];
		$tel3_label =$rows[31];
		$supp_email_label =$rows[32];
		$reference =$rows[33];
		
		$city1_label =$rows[34];
		$city2_label =$rows[35];
		$city3_label =$rows[36];
		$Start_Date_label =$rows[37];
		$End_Date_label =$rows[38];
		$Target_Amount =$rows[39];
		
		$Target_Commission_label =$rows[40];
		$client_code_label =$rows[41];
		$client_name_label =$rows[42];
		$commission_label =$rows[43];

		
	}

$querylang="select language, buttonclear, save, print, find, clear, results, page,
Add_button,check_button,remainchar,submit_button
 from ".$_SESSION['dbLabel'].".buttons_label 
where language='$language'";


$resultlang=mysql_query($querylang,$connection) or die(mysql_error());
	while($rows=mysql_fetch_array($resultlang)){
		//extract($rows);
		
		$buttonclear=$rows[1];
		$save=$rows[2];
		$print=$rows[3];
		$find=$rows[4];
		$clear=$rows[5];
		$results=$rows[6];
		$page=$rows[7];
		$add=$rows[8];
		$check=$rows[9];
		$remainchar=$rows[10];
		$submit_button=$rows[11];
		
	}

	
	
	
if ($loginaccess=='' or $loginaccess==0)
	header("location:menu.php");




//User Access
$querylog=" select ifNull(FI_SalesmenApp,0) As FI_SalesmenApp, ifNull(FI_SalesmenMod,0) As FI_SalesmenMod, ".
          " ifNull(FI_SalesmenDel,0) As FI_SalesmenDel from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."')  ";
$resultlog=mysql_query($querylog,$connection) or die(mysql_error());

while($rows=mysql_fetch_array($resultlog)){
	extract($rows);
}

$AddMode='';

if($FI_SalesmenApp==0)
$AddMode = ' disabled ';

$querysetup="select SalesmenFirstDigit,NbrOfDigitInLedger from setup";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
extract($rowsetup);
}



//Read From Setup Table							
$querysetup= " select grid_color1, grid_color2,maxperpage,DecimalBase,Salesman_DefaultCur from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}

//Read From module Table							
$querysetup= " select module_services,Module_AdvancedProduction,Module_CommissionByGroup from module ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}


$deactivatesalesmen 	= $_POST["deactivatesalesmen"]; if ($deactivatesalesmen == ""){$deactivatesalesmen = $_GET["deactivatesalesmen"];} 	

$actionmode = $_POST["actionmode"]; if ($actionmode == ""){$actionmode = $_GET["actionmode"];}   
$mainmode   = $_POST["mainmode"]; if ($mainmode == ""){$mainmode = $_GET["mainmode"];}   
$message 	= $_POST["message"]; if ($message == ""){$message = $_GET["message"];}   
$txtKeyword = $_POST["txtKeyword"]; if ($txtKeyword == ""){$txtKeyword = $_GET["txtKeyword"];}   
$perpage 	= $_POST["perpage"]; if ($perpage == ""){$perpage = $_GET["perpage"];} 
$startrange	= $_POST["startrange"]; if ($startrange == ""){$startrange = $_GET["startrange"];} 
$vTabFocus 	= $_POST["vTabFocus"]; if ($vTabFocus == ""){$vTabFocus = $_GET["vTabFocus"];} 

$checkcode    		= $_POST["checkcode"]; if ($checkcode == ""){$checkcode = $_GET["checkcode"];} 
$fill_ledger 		= $_POST["fill_ledger"]; if ($fill_ledger == ""){$fill_ledger = $_GET["fill_ledger"];} 
$fromledger   		= $_POST["fromledger"]; if ($fromledger == ""){$fromledger = $_GET["fromledger"];} 
$ledger_numberPrv  	= $_POST["ledger_numberPrv"]; if ($ledger_numberPrv == ""){$ledger_numberPrv = $_GET["ledger_numberPrv"];} 
$increment			= $_POST["increment"]; if ($increment == ""){$increment = $_GET["increment"];} 

$SalesComm_Id			= $_POST["SalesComm_Id"]; if ($SalesComm_Id == ""){$SalesComm_Id = $_GET["SalesComm_Id"];} 
$telephone_increment	= $_POST["telephone_increment"]; if ($telephone_increment == ""){$telephone_increment = $_GET["telephone_increment"];} 
$SalesCommByClient_Id	= $_POST["SalesCommByClient_Id"]; if ($SalesCommByClient_Id == ""){$SalesCommByClient_Id = $_GET["SalesCommByClient_Id"];} 
$Salesmandt_id			= $_POST["Salesmandt_id"]; if ($Salesmandt_id == ""){$Salesmandt_id = $_GET["Salesmandt_id"];} 
$ReceiptBook_ID			= $_POST["ReceiptBook_ID"]; if ($ReceiptBook_ID == ""){$ReceiptBook_ID = $_GET["ReceiptBook_ID"];} 
$SalesmenGroup_id		= $_POST["SalesmenGroup_id"]; if ($SalesmenGroup_id == ""){$SalesmenGroup_id = $_GET["SalesmenGroup_id"];} 


$ledger_number 		= $_POST["ledger_number"]; if ($ledger_number == ""){$ledger_number = $_GET["ledger_number"];} 
$ledger_name 		= $_POST["ledger_name"]; if ($ledger_name == ""){$ledger_name = $_GET["ledger_name"];} 
$ledger_description = $_POST["ledger_description"]; if ($ledger_description == ""){$ledger_description = $_GET["ledger_description"];} 
$currency 			= $_POST["currency"]; if ($currency == ""){$currency= $_GET["currency"];} 
$currency_code 		= $_POST["currency_code"]; if ($currency_code == ""){$currency_code = $_GET["currency_code"];} 
$credit_limit 		= $_POST["credit_limit"]; if ($credit_limit == ""){$credit_limit = $_GET["credit_limit"];} 
$salesman_bonus 	= $_POST["salesman_bonus"]; if ($salesman_bonus == ""){$salesman_bonus = $_GET["salesman_bonus"];} 
$salesman_commission= $_POST["salesman_commission"]; if ($salesman_commission == ""){$salesman_commission = $_GET["salesman_commission"];} 
$area_code 			= $_POST["area_code"]; if ($area_code == ""){$area_code = $_GET["area_code"];} 
$areaname 			= $_POST["areaname"]; if ($areaname == ""){$areaname = $_GET["areaname"];} 
$manager_code 		= $_POST["manager_code"]; if ($manager_code == ""){$manager_code = $_GET["manager_code"];} 
$manager_name 		= $_POST["manager_name"]; if ($manager_name == ""){$manager_name = $_GET["manager_name"];} 
$salesman_mref 		= $_POST["salesman_mref"]; if ($salesman_mref == ""){$salesman_mref = $_GET["salesman_mref"];} 
$salesman_ismanager	= $_POST["salesman_ismanager"]; if ($salesman_ismanager == ""){$salesman_ismanager = $_GET["salesman_ismanager"];} 
$warehouse_code		= $_POST["warehouse_code"]; if ($warehouse_code == ""){$warehouse_code = $_GET["warehouse_code"];} 
$warehouse_desc		= $_POST["warehouse_desc"]; if ($warehouse_desc == ""){$warehouse_desc = $_GET["warehouse_desc"];} 
$salesman_cashaccount= $_POST["salesman_cashaccount"]; if ($salesman_cashaccount == ""){$salesman_cashaccount = $_GET["salesman_cashaccount"];} 
$salesman_cashdesc	= $_POST["salesman_cashdesc"]; if ($salesman_cashdesc == ""){$salesman_cashdesc = $_GET["salesman_cashdesc"];} 
$Address 			= $_POST["Address"]; if ($Address == ""){$Address = $_GET["Address"];} 
$salesman_invoicesequence	= $_POST["salesman_invoicesequence"]; if ($salesman_invoicesequence == ""){$salesman_invoicesequence = $_GET["salesman_invoicesequence"];} 

$fax 		 = $_POST["fax"]; if ($fax == ""){$fax = $_GET["fax"];} 
$email 		 = $_POST["email"]; if ($email == ""){$email = $_GET["email"];} 
$phone1	  	 = $_POST["phone1"]; if ($phone1 == ""){$phone1 = $_GET["phone1"];} 
$phone2 	 = $_POST["phone2"]; if ($phone2 == ""){$phone2 = $_GET["phone2"];} 

$telephoneno_title 	= $_POST["telephoneno_title"]; if ($telephoneno_title == ""){$telephoneno_title = $_GET["telephoneno_title"];} 
$telephone_name		= $_POST["telephone_name"]; if ($telephone_name == ""){$telephone_name = $_GET["telephone_name"];} 
$telephone_fname 	= $_POST["telephone_fname"]; if ($telephone_fname == ""){$telephone_fname = $_GET["telephone_fname"];} 
$telephone_lname 	= $_POST["telephone_lname"]; if ($telephone_lname == ""){$telephone_lname = $_GET["telephone_lname"];} 
$telephone_no 		= $_POST["telephone_no"]; if ($telephone_no == ""){$telephone_no = $_GET["telephone_no"];} 
$telephone_no2 		= $_POST["telephone_no2"]; if ($telephone_no2 == ""){$telephone_no2 = $_GET["telephone_no2"];} 
$telephone_no3 		= $_POST["telephone_no3"]; if ($telephone_no3 == ""){$telephone_no3 = $_GET["telephone_no3"];} 
$telephone_email	= $_POST["telephone_email"]; if ($telephone_email == ""){$telephone_email = $_GET["telephone_email"];} 
$telephone_reference= $_POST["telephone_reference"]; if ($telephone_reference == ""){$telephone_reference = $_GET["telephone_reference"];} 
$telephone_city1 	= $_POST["telephone_city1"]; if ($telephone_city1 == ""){$telephone_city1 = $_GET["telephone_city1"];} 
$telephone_city2 	= $_POST["telephone_city2"]; if ($telephone_city2 == ""){$telephone_city2 = $_GET["telephone_city2"];} 
$telephone_city3 	= $_POST["telephone_city3"]; if ($telephone_city3 == ""){$telephone_city3 = $_GET["telephone_city3"];} 

$start_date 	 = $_POST["start_date"]; if ($start_date == ""){$start_date = $_GET["start_date"];} 
$end_date 		 = $_POST["end_date"]; if ($end_date == ""){$end_date = $_GET["end_date"];} 
$target_amount	 = $_POST["target_amount"]; if ($target_amount == ""){$target_amount = $_GET["target_amount"];} 
$currencycom	 = $_POST["currencycom"]; if ($currencycom == ""){$currencycom = $_GET["currencycom"];} 
$target_amountcom	 = $_POST["target_amountcom"]; if ($target_amountcom == ""){$target_amountcom = $_GET["target_amountcom"];} 
$commission  	 = $_POST["commission"]; if ($commission == ""){$commission = $_GET["commission"];} 

$client_code 		= $_POST["client_code"]; if ($client_code == ""){$client_code = $_GET["client_code"];} 
$client_name		= $_POST["client_name"]; if ($client_name == ""){$client_name = $_GET["client_name"];} 
$commissionbyclient = $_POST["commissionbyclient"]; if ($commissionbyclient == ""){$commissionbyclient = $_GET["commissionbyclient"];} 

$area_codedt	= $_POST["area_codedt"]; if ($area_codedt == ""){$area_codedt = $_GET["area_codedt"];} 
$area_namedt	= $_POST["area_namedt"]; if ($area_namedt == ""){$area_namedt = $_GET["area_namedt"];} 

$start_daterec 		= $_POST["start_daterec"]; if ($start_daterec == ""){$start_daterec = $_GET["start_daterec"];} 
$end_daterec		= $_POST["end_daterec"]; if ($end_daterec == ""){$end_daterec = $_GET["end_daterec"];} 
$from_reference		= $_POST["from_reference"]; if ($from_reference == ""){$from_reference = $_GET["from_reference"];} 
$to_reference		= $_POST["to_reference"]; if ($to_reference == ""){$to_reference = $_GET["to_reference"];} 
$receipt_serialno	= $_POST["receipt_serialno"]; if ($receipt_serialno == ""){$receipt_serialno = $_GET["receipt_serialno"];} 

$group_codedt 	= $_POST["group_codedt"]; if ($group_codedt == ""){$group_codedt = $_GET["group_codedt"];} 
$group_namedt 	= $_POST["group_namedt"]; if ($group_namedt == ""){$group_namedt = $_GET["group_namedt"];} 	




function get_titles($connection)
{
		$query = "select title_id,title_name,title_description from titles ".
				" order by title_description";
			
		$result=mysql_query($query, $connection);
		return $result;
}

$result_title=get_titles($connection);

if(!isset($mainmode))
$mainmode='';

if($start_date=='')
	$start_date=date('d-m-Y');


//// Currency
	function get_currency($connection)
{		$query_cr = "select currency_code,currency_name from currency";
//echo$query_cr;
		$result_cr=mysql_query($query_cr, $connection);
		return $result_cr;
}
$curr = get_currency($connection);
$currcom = get_currency($connection);


		
if($mainmode=='editmode' or $mainmode=='view'){

	$query_edit="select salesmen.Ledger_number, salesmen.Ledger_name, salesmen.Ledger_Desc, Salesman_address, Salesman_Fax, Salesman_Email, Salesman_commission, 
				Salesman_CreditLimit,Salesman_Bonus,salesmen.Area_Code, salesmen.Currency_Code, salesmen.Manager_Code, 
				Salesman_IsManager,Salesman_MRef,date_format(salesman_CreationDate,'%d-%m-%Y'),Salesman_Telephone1,
				Salesman_Telephone2, salesmen.Salesman_WarehouseCode, warehouse.Warehouse_Name, salesmen.Salesman_CashAccount, Ledger.Ledger_Name as Salesman_CashDesc,
				Salesman_InvoiceSequence,salesmen_deactivate,date_format(Salesmen_DeactivateDate,'%d-%m-%Y')
				from salesmen 
				left join warehouse on warehouse.warehouse_code=salesmen.Salesman_WarehouseCode
				left join ledger on ledger.Ledger_number=salesmen.Salesman_CashAccount
				where salesmen.ledger_number='".$ledger_number."'";
								
	//echo$query_edit;
	$resultedit = mysql_query($query_edit, $connection);
	while($row=mysql_fetch_array($resultedit)){
		$ledger_number=$row[0];
		$ledger_numberPrv=$row[0];
		$ledger_name=$row[1];
		$ledger_description=$row[2];
		$Address=$row[3];
		$fax=$row[4];
		$email=$row[5];
		$salesman_commission=$row[6];
		$credit_limit=$row[7];
		$salesman_bonus=$row[8];
		$area_code=$row[9];
		$currency_code=$row[10];
		$manager_code=$row[11];
		$salesman_ismanager=$row[12];
		$salesman_mref=$row[13];
		$phone1=$row[15];
		$phone2=$row[16];
		$salesmen_CreationDate=$row[14];
		$warehouse_code = $row[17];
		$warehouse_desc = $row[18];
		$salesman_cashaccount = $row[19];
		$salesman_cashdesc = $row[20];
		$salesman_invoicesequence = $row[21];
		$deactivatesalesmen=$row[22];
		$deactivatedate=$row[23];
	
		
	}

	$query4="select area_code,area_name from area where area_code='$area_code'";
	$result=mysql_query($query4, $connection);
	$row=mysql_fetch_row($result);
	$areaname=$row[1];

	$query5="select ledger_number,ledger_name from salesmen where ledger_number='$manager_code'";
	$result=mysql_query($query5, $connection);
	$row=mysql_fetch_row($result);
	$manager_name=$row[1];
	
	$mainmode='edit';
}

if($telephone_increment!='' && $checkcode!=1){

	$query="select TelephoneNo_ContactTitle,Telephone_name,telephoneno_fname,telephoneno_lname,TelephoneNo,TelephoneNo2,TelephoneNo3,telephoneno_email,telephoneno_reference,
										telephoneno_city1,telephoneno_city2,telephoneno_city3 from telephoneno where telephone_increment='".$telephone_increment."'";
	$result=mysql_query($query, $connection);
	$row=mysql_fetch_row($result);
	
	$telephoneno_title=$row[0];
	$telephone_name=$row[1];
	$telephone_fname=$row[2];
	$telephone_lname=$row[3];
	$telephone_no=$row[4];
	$telephone_no2=$row[5];
	$telephone_no3=$row[6];
	$telephone_email=$row[7];
	$telephone_reference=$row[8];
	$telephone_city1=$row[9];
	$telephone_city2=$row[10];
	$telephone_city3=$row[11];
}

if($SalesComm_Id!='' && $checkcode!=1){

	$query="select date_format(SalesComm_StartDate,'%d-%m-%Y'),date_format(SalesComm_EndDate,'%d-%m-%Y'),SalesComm_TargetAmnt,SalesComm_TargetComm,Currency_Code,SalesComm_Commission from salescomm where SalesComm_Id='".$SalesComm_Id."'";
	$result=mysql_query($query, $connection);
	$row=mysql_fetch_row($result);
	
	$start_date=$row[0];
	$end_date=$row[1];
	$target_amount=$row[2];
	$target_amountcom=$row[3];
	$currencycom=$row[4];
	$commission=$row[5];
}

if($SalesCommByClient_Id!='' && $checkcode!=1){

	$query="select Client_Code,SalesmanByClient_Comm,ledger_name from salescommbyclient 
			left join ledger on ledger.ledger_number=salescommbyclient.client_code
			where SalesCommByClient_Id='".$SalesCommByClient_Id."'";
	$result=mysql_query($query, $connection);
	$row=mysql_fetch_row($result);
	$client_code=$row[0];
	$commissionbyclient=$row[1];
	$client_name=$row[2];
}

if($Salesmandt_id!='' && $checkcode!=1){

	$query="select salesmandt.area_Code,area_name from salesmandt 
			left join area on area.area_code=salesmandt.area_Code
			where Salesmandt_id='".$Salesmandt_id."'";
	$result=mysql_query($query, $connection);
	$row=mysql_fetch_row($result);
	$area_codedt=$row[0];
	$area_namedt=$row[1];
	
}

if($ReceiptBook_ID!='' && $checkcode!=1){

	$query="select date_format(ReceiptBook_FromDate,'%d-%m-%Y'),date_format(ReceiptBook_ToDate,'%d-%m-%Y'),ReceiptBook_FromSequence,ReceiptBook_ToSequence,ReceiptBook_SerialNo from receiptbooks 
			where ReceiptBook_ID='".$ReceiptBook_ID."'";
			
	$result=mysql_query($query, $connection);
	$row=mysql_fetch_row($result);
	$start_daterec=$row[0];
	$end_daterec=$row[1];
	$from_reference=$row[2];
	$to_reference=$row[3];
	$receipt_serialno=$row[4];
}

if($SalesmenGroup_id!='' && $checkcode!=1){

	$query="select salesmengroup.group_code,group_name from salesmengroup 
			left join grouping on grouping.group_code=salesmengroup.group_code
			where SalesmenGroup_id='".$SalesmenGroup_id."'";
			
	$result=mysql_query($query, $connection);
	$row=mysql_fetch_row($result);
	$group_codedt=$row[0];
	$group_namedt=$row[1];
}

if($mainmode=='') $mainmode='insert';
if($currency=='' && $mainmode=='insert')
		$currency_code=$Salesman_DefaultCur;

if($currencycom=='' && $mainmode=='insert')
		$currencycom=$Salesman_DefaultCur;		
		
print <<<HERE

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
<meta name="viewport" content="width=device-width, initial-scale=1.0"> 
<LINK REL="stylesheet" TYPE="text/css" MEDIA="all" HREF="css/tabs.css">
<link rel="stylesheet" type="text/css" media="all" href="css-v2/style.css">

<script type="text/javascript" src="jquery-1.9.1.js"></script>
<script type="text/javascript" language="javascript">



function deactivesalesmen() {
if(document.salesman.deactivate.checked){
document.salesman.deactivatesalesmen.value=1;
document.salesman.deactivatedate.disabled=false;}

else
{
document.salesman.deactivatesalesmen.value=0;
document.salesman.deactivatedate.value='';
document.salesman.deactivatedate.disabled=true;
}

var m;
m=document.salesman.mainmode.value;
	document.salesman.action='Form_Salesmen.php?mainmode='+m;
	document.salesman.submit();

}

function PrintPreview(){
	if (confirm ( "Do you want to Print List of Salesmen?")){
		var str = '';
		str = 'Form_SalesmenPreview.php';
		window.open(str);
	}
}

function checkmanager() {
	if(document.salesman.ismanager.checked){
		document.salesman.salesman_ismanager.value=1;
		
	}
	else{
		document.salesman.salesman_ismanager.value=0;
	}
}

function fill_curr(){
	document.salesman.currency_code.value=document.salesman.currency.value;
}


function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters center' counter
else {
countfield.value = maxlimit - field.value.length;}

}

function showlistarea(str){

  window.open('List_Area.php?str='+str,'mywindow','width=850,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function showlistgroup(str){

  window.open('List_Grouping.php?str='+str,'mywindow','width=850,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}



function showlistmanagers(){

  window.open('List_Managers.php','mywindow','width=850,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function showlistwarehouse(str){
	window.open('List_Warehouses.php?str='+str,'List_Warehouses','width=850,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function showlistledger(str){
	window.open('List_Agents_orderbycode.php?str='+str,'mywindow','width=850,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function editmode () {

			document.salesman.mainmode.value='editmode';
			var l=document.salesman.ledger_number.value;
			document.salesman.action="Form_Salesmen.php?ledger_number="+l;
			document.salesman.submit();
}

function AddSalesman () {
	//document.salesman.check_ledgergrp.value=1;	
	document.salesman.mainmode.value='insert';	
	document.salesman.action="Form_Salesmen.php";
	document.salesman.submit();
}


function SubmitRecord(option) {


	var checkOK = "0123456789.";
	var checkStr = salesman.salesman_bonus.value;
	var allValid = true;
	var allNum = "";
	for (i = 0;  i < checkStr.length;  i++)
	{
	ch = checkStr.charAt(i);
	for (j = 0;  j < checkOK.length;  j++)
	if (ch == checkOK.charAt(j))
	break;
	if (j == checkOK.length)
	{
	allValid = false;
	break;
	}
	if (ch != ",")
	allNum += ch;
	}
	if (!allValid)
	{
	alert("Please enter only digit characters in the \"Bonus\" field.");
	salesman.salesman_bonus.focus();
	return (false);
	}

	var checkStr = salesman.salesman_commission.value;
	var allValid = true;
	var allNum = "";
	for (i = 0;  i < checkStr.length;  i++)
	{
	ch = checkStr.charAt(i);
	for (j = 0;  j < checkOK.length;  j++)
	if (ch == checkOK.charAt(j))
	break;
	if (j == checkOK.length)
	{
	allValid = false;
	break;
	}
	if (ch != ",")
	allNum += ch;
	}
	if (!allValid)
	{
	alert("Please enter only digit characters in the \"Commission\" field.");
	salesman.salesman_commission.focus();
	return (false);
	}


	var checkStr = salesman.credit_limit.value;
	var allValid = true;
	var allNum = "";
	for (i = 0;  i < checkStr.length;  i++)
	{
	ch = checkStr.charAt(i);
	for (j = 0;  j < checkOK.length;  j++)
	if (ch == checkOK.charAt(j))
	break;
	if (j == checkOK.length)
	{
	allValid = false;
	break;
	}
	if (ch != ",")
	allNum += ch;
	}
	if (!allValid)
	{
	alert("Please enter only digit characters in the \"Credit\" field.");
	salesman.credit_limit.focus();
	return (false);
	}
	
		var checkStr = salesman.commissionbyclient.value;
	var allValid = true;
	var allNum = "";
	for (i = 0;  i < checkStr.length;  i++)
	{
	ch = checkStr.charAt(i);
	for (j = 0;  j < checkOK.length;  j++)
	if (ch == checkOK.charAt(j))
	break;
	if (j == checkOK.length)
	{
	allValid = false;
	break;
	}
	if (ch != ",")
	allNum += ch;
	}
	if (!allValid)
	{
	alert("Please enter only digit characters in the \"Commission\" field.");
	salesman.commissionbyclient.focus();
	return (false);
	}
	
	

	var m=document.salesman.mainmode.value;
	var chk=document.salesman.checkcode.value;
	
	
	if(document.salesman.ledger_number.value==''){
		alert('Unable to save : Code is Mandatory ');
		tab_('Main Page','ledger_number');
	}
	else if(document.salesman.ledger_name.value==''){
		alert('Unable to save : Name is Mandatory ');
		tab_('Main Page','ledger_name');
	}
	
	else 	if (option==2 && document.salesman.telephoneno_title.value=='' )
	{
		alert('Unable to save : check missing field Title in Contact Page');
		tab_('Contact','telephoneno_title');
	}
	else 	if (option==2 && document.salesman.telephone_fname.value=='' )
	{
		alert('Unable to save : check missing field First Name in Contact Page');
		tab_('Contact','telephone_fname');
	}
	else 	if (option==2 && document.salesman.telephone_lname.value=='' )
	{
		alert('Unable to save : check missing field Last Name in Contact Page');
		tab_('Contact','telephone_lname');
	}
	else 	if (option==2 && document.salesman.telephone_name.value=='' )
	{
		alert('Unable to save : check missing field Name in Contact Page');
		tab_('Contact','telephone_name');
	}
	else 	if (option==2 && document.salesman.telephone_no.value=='' )
	{
		alert('Unable to save : check missing field Tel No in Contact Page');
		tab_('Contact','telephone_no');
	}
	else 	if (option==3 && document.salesman.start_date.value=='' )
	{
		alert('Unable to save : check missing field Start Date in Sales Com Page');
		tab_('Sales Commission','start_date');
	}
	else 	if (option==3 && document.salesman.currencycom.value=='' )
	{
		alert('Unable to save : check missing field Currency in Sales Com Page');
		tab_('Sales Commission','currencycom');
	}
	else 	if (option==3 && document.salesman.currencycom.value=='' )
	{
		alert('Unable to save : check missing field Currency in Sales Com Page');
		tab_('Sales Commission','currencycom');
	}
	else 	if (option==4 && document.salesman.client_code.value=='' )
	{
		alert('Unable to save : check missing field Client in Sales Com by Client Page');
		tab_('Sales Commission By Client','client_code');
	}
	else{
		if(option==2)
			document.salesman.actionmode.value='submitcontact';
			
		if(option==3)
			document.salesman.actionmode.value='submitcom';
		
		if(option==4)
			document.salesman.actionmode.value='submitcombyclient';
			
		if(option==5)
			document.salesman.actionmode.value='submitarea';	
		
		if(option==6)
			document.salesman.actionmode.value='submitreceipt';	
		
		if(option==7)
			document.salesman.actionmode.value='submitgroup';
			
		document.salesman.checkcode.value='1';
		document.salesman.action='Form_Salesmen_Actions.php';
		document.salesman.submit();
	}	
	
}


function ClearPage(){
	if (confirm ( "Are you sure you want to Clear Page?"))
	{
		ClearForm('All');
		
		x.mainmode.value='';
		x.action='Form_Salesmen.php';
		x.submit();
	}	
}

//All= All form; D= Detail Part
function ClearForm(Option){

    x = document.salesman;
	x.message.value='';
	x.manager_name.value='';
	x.phone2.value='';
	x.phone1.value='';
	x.ledger_number.value='';
	x.ledger_name.value='';
	x.ledger_description.value='';
	x.Address.value='';
	x.fax.value='';
	x.email.value='';
	x.salesman_commission.value='';
	x.credit_limit.value='';
	x.salesman_bonus.value='';
	x.area_code.value='';
	x.areaname.value='';
	x.Address.value='';
	x.currency_code.value='';
	x.manager_code.value='';
	x.salesman_ismanager.value='';
	x.salesman_mref.value='';
	x.warehouse_code.value="";
	x.warehouse_desc.value="";
	x.salesman_cashaccount.value="";
	x.salesman_cashdesc.value="";
	x.salesman_invoicesequence.value="";
	x.checkcode.value='';
	x.mainmode.value='';
	
	x.deactivatesalesmen.value='';
		x.deactivatedate.value='';
		
		
	cleardetail();
	
	if(x.module_services.value==1)
		cleardetailarea(); 
	
	if(x.Module_AdvancedProduction.value==1)
		cleardetailreceipt();
	
	if(x.Module_CommissionByGroup.value==1)
		cleardetailgroup();

	cleardetailcombyclient(); 
	cleardetailcom(); 

}

function cleardetail(){
	 x = document.salesman;

	x.telephoneno_title.value='';
	x.telephone_name.value='';
	x.telephone_fname.value='';
	x.telephone_lname.value='';
	x.telephone_no.value='';
	x.telephone_no2.value='';
	x.telephone_no3.value='';
	x.telephone_email.value='';
	x.telephone_reference.value='';
	x.telephone_city1.value='';
	x.telephone_city2.value='';
	x.telephone_city3.value='';
	x.telephone_increment.value='';
	x.actionmode.value='';
	x.submit();	
}

function cleardetailcom(){
	 x = document.salesman;

	x.start_date.value='';
	x.end_date.value='';
	x.target_amount.value='';
	x.target_amountcom.value='';
	x.currencycom.value='';
	x.commission.value='';
	x.SalesComm_Id.value='';
	x.actionmode.value='';
	x.submit();	
}

function cleardetailcombyclient(){
	 x = document.salesman;

	x.client_code.value='';
	x.client_name.value='';
	x.commissionbyclient.value='';
	
	x.SalesCommByClient_Id.value='';
	x.actionmode.value='';
	x.submit();	
}

function cleardetailarea(){
	x = document.salesman;
	x.area_codedt.value='';
	x.area_namedt.value='';
	x.Salesmandt_id.value='';
	x.actionmode.value='';
	x.submit();	
}

function cleardetailreceipt(){
	x = document.salesman;
	x.start_daterec.value='';
	x.end_daterec.value='';
	x.from_reference.value='';
	x.to_reference.value='';
	x.receipt_serialno.value='';
	x.receipt_serialno.value='';
	x.ReceiptBook_ID.value='';
	x.actionmode.value='';
	x.submit();	
}

function cleardetailgroup(){
	x = document.salesman;
	x.group_codedt.value='';
	x.group_namedt.value='';
	x.SalesmenGroup_id.value='';

	x.actionmode.value='';
	x.submit();	
}


/*
function SearchForSalesman(){
    ClearForm('All');
    x = document.salesman;
    win = window.open('Form_SalesmenSearch.php', 'Form_SalesmenSearch', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=775,height=450,top=100,left=100');		
	win.creator = self;
	win.focus();		
			
}*/

function SetSales(SalesId){
	
	document.salesman.ledger_number.value=SalesId;
	document.salesman.message.value='';
	
	document.salesman.actionmode.value='';
	document.salesman.mainmode.value='editmode';
	document.salesman.submit();
}

function SetNextPage(startrange,perpage){
	document.salesman.action='Form_Salesmen.php?startrange='+startrange+'&perpage='+perpage;
	document.salesman.submit();
}

function SetPrvPage(startrange,perpage){
	document.salesman.action='Form_Salesmen.php?startrange='+startrange+'&perpage='+perpage;
	document.salesman.submit();
}

function SearchForSalesmen(){
	x = document.salesman;
	document.salesman.action='Form_Salesmen.php?startrange=0';
	document.salesman.submit();
}

function ClearKeyword(){
	x = document.salesman;
	x.txtKeyword.value='';
	document.salesman.action='Form_Salesmen.php?startrange=0';
	document.salesman.submit();
}

function submitenter(myfield,e){
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   	document.salesman.action='Form_Salesmen.php?startrange=0';
	document.salesman.submit();
  
   return false;
   }
else
   return true;
}

function confirm_delete(Code) {

	if (confirm ( "Are you sure you want to Delete this Record " + "?")) {
		//window.event.returnValue = true;
		document.salesman.mainmode.value='delete';	
		
		document.salesman.action='Form_Salesmen_Actions.php?ledgernumber='+Code;
		document.salesman.submit();
	}
					
}

function set_limit(){

	perpage=document.salesman.perpage.value;
	document.salesman.action='Form_Salesmen.php?perpage='+perpage+'&startrange=0';
	document.salesman.submit();
}

function UpdateDetail(TelephoneId){
	 x = document.salesman;
	 x.telephone_increment.value=TelephoneId;
	x.actionmode.value='refresh';
	x.action='Form_Salesmen.php?vTabFocus=Contact';
	x.submit();
}	

function UpdateDetailCom(salescomid){
	 x = document.salesman;
	 x.SalesComm_Id.value=salescomid;
	x.actionmode.value='refresh';
	x.action='Form_Salesmen.php?vTabFocus=Sales Commission';
	x.submit();
}	

function UpdateDetailComByClient(salescomid){
	 x = document.salesman;
	 x.SalesCommByClient_Id.value=salescomid;
	x.actionmode.value='refresh';
	x.action='Form_Salesmen.php?vTabFocus=Sales Commission By Client';
	x.submit();
	
	
	
	
}

function UpdateDetailArea(salescomid){
	 x = document.salesman;
	 x.Salesmandt_id.value=salescomid;
	x.actionmode.value='refresh';
	x.action='Form_Salesmen.php?vTabFocus=Area';
	x.submit();
}

function UpdateDetailRec(salesrecid){
	 x = document.salesman;
	 x.ReceiptBook_ID.value=salesrecid;
	x.actionmode.value='refresh';
	x.action='Form_Salesmen.php?vTabFocus=Receipt Books';
	x.submit();
}

function UpdateDetailGroup(salesgroupid){
	 x = document.salesman;
	x.SalesmenGroup_id.value=salesgroupid;
	x.actionmode.value='refresh';
	x.action='Form_Salesmen.php?vTabFocus=Groups';
	x.submit();
}


function DeleteDetail(TelephoneId){

	if (confirm ( "Are you sure you want to Delete record?"))
	{
		
		document.salesman.telephone_increment.value = TelephoneId;
		document.salesman.actionmode.value = 'deletecontact';
		
		document.salesman.action="Form_Salesmen_Actions.php";
		document.salesman.submit();
		
	}	

}

function DeleteDetailCom(salescomid){
	 x = document.salesman;
	if (confirm ( "Are you sure you want to Delete record?"))
	{
		x.SalesComm_Id.value=salescomid;
		x.actionmode.value = 'deletesalescom';
		
		document.salesman.action="Form_Salesmen_Actions.php";
		document.salesman.submit();
	}	
}

function DeleteDetailComByClient(salescomid){
	 x = document.salesman;
	if (confirm ( "Are you sure you want to Delete record?"))
	{
		x.SalesComm_Id.value=salescomid;
		x.actionmode.value = 'deletesalescombyclient';
		
		
		document.salesman.action="Form_Salesmen_Actions.php";
		document.salesman.submit();
	}	
}

function DeleteDetailArea(salescomid){
	 x = document.salesman;
	if (confirm ( "Are you sure you want to Delete record?"))
	{
		x.Salesmandt_id.value=salescomid;
		x.actionmode.value = 'deletesalesarea';
		
		document.salesman.action="Form_Salesmen_Actions.php";
		document.salesman.submit();
	}	
}

function DeleteDetailRec(salesrecid){
	 x = document.salesman;
	if (confirm ( "Are you sure you want to Delete record?"))
	{
		x.ReceiptBook_ID.value=salesrecid;
		x.actionmode.value = 'deletesalesrec';
		
		document.salesman.action="Form_Salesmen_Actions.php";
		document.salesman.submit();
	}	
}

function DeleteDetailGroup(salesgroupid){
	 x = document.salesman;
	if (confirm ( "Are you sure you want to Delete record?"))
	{
		x.SalesmenGroup_id.value=salesgroupid;
		x.actionmode.value = 'deletesalesgroup';
		
		document.salesman.action="Form_Salesmen_Actions.php";
		document.salesman.submit();
	}	
}


function showlistclient(str){

  window.open('List_Agents_orderbycode.php?str='+str,'mywindow','width=850,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function addserial(){
	var ledgernumber= document.salesman.ledger_number.value;
	//alert(ledgernumber);
//	alert(ledgernumber.toString().length);
	if(ledgernumber.toString().length<4 || ledgernumber.toString().length>=8){
			alert("Minimum Code */Name of digits is 4");
			return;
	}
	
	document.salesman.action='Form_Salesmen_Actions.php?actionmode=getledgergroup&ledger_number='+ledgernumber;
	document.salesman.submit();
	
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Add Salesman</title>

<style type="text/css">

body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
}
body {
	margin-top: 2px;
	margin-left: 1px;
}
a:link {
	text-decoration: none;
	color: #0000FF;
}
a:visited {
	text-decoration: none;
	color: #0000FF;
}
a:hover {
	text-decoration: none;
	color: #0000FF;
}
a:active {
	text-decoration: none;
	color: #0000FF;
}

.style12 {
	font-size: 9px;
	color: #999999;
	font-weight: bold;
}
.style15 {color: #5151FF; font-size: 10px;}
.style16 {
	font-size: 16px;
	color: #FF0000;
	font-weight: bold;
	font-family: "Times New Roman", Times, serif;
}
.style17 {font-size: 9px}
.style25 {color: #999999; font-weight: bold; font-size: 10px; }
.style26 {color: #FF0000}
.style27 {color: #999999 ;font-size: 10px;}
.style28 {color: #FFFFFF ;font-size: 10px;}

</style>

<link type="text/css" rel="stylesheet" href="dhtmlgoodies_calendar.css?random=20051112" media="screen"></LINK>
<SCRIPT type="text/javascript" src="dhtmlgoodies_calendar.js?random=20060118"></script>
</head>
<body >
<form name='salesman' method='post'>
<input type=hidden name='mainmode' value='$mainmode'>
<input type=hidden name='actionmode' value='$actionmode'>
<input type=hidden name='increment' value='$increment'>
<input type=hidden name='checkcode' value='$checkcode'>
<input type='hidden' name='fill_ledger' value='$fill_ledger'>
<input type=hidden name='message' value='$message'>
<input type=hidden name='fromledger' value='$fromledger'>
<input type='hidden' name='ledger_numberPrv' value='$ledger_numberPrv'>

<input type='hidden' name='SalesComm_Id' value='$SalesComm_Id'>
<input type='hidden' name='telephone_increment' value='$telephone_increment'>
<input type='hidden' name='SalesCommByClient_Id' value='$SalesCommByClient_Id'>
<input type='hidden' name='Salesmandt_id' value='$Salesmandt_id'>
<input type='hidden' name='ReceiptBook_ID' value='$ReceiptBook_ID'>
<input type='hidden' name='SalesmenGroup_id' value='$SalesmenGroup_id'>
<input type='hidden' name='module_services' value='$module_services'>
<input type='hidden' name='Module_AdvancedProduction' value='$Module_AdvancedProduction'>
<input type='hidden' name='Module_CommissionByGroup' value='$Module_CommissionByGroup'>

HERE;

if($salesman_ismanager=='')
	$salesman_ismanager=0;

if($salesman_ismanager=='1')
$selectedmanager='checked';

if($mainmode==''){
	$status='disabled';
	$dis='disabled';
	$statuscode='disabled';
}

if($mainmode=='view'){

	$status='readonly';
	$dis='disabled';
	$statuscode='readonly';
}


if($mainmode=='edit')
	$statuscode='readonly';
	
if($mainmode=='insert')
$status='';



//$style= "style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'";

echo"		<table cellpadding='0' cellspacing='0' border='0'  align='center' class='layout-width'>";
include_once("header.php");
echo" 			<tr>
					<td  valign='top'>";

include_once("sidemenu.php");
echo"  				</td>
				</tr>";
				
echo" 			<tr style='height:26px;'>
					<td  valign='top' id='content-top'>
						<table border='0' cellpadding='0' cellspacing='0' style='table-layout:fixed; height:26px;' class='layout-width'>
							<tr style='height:26px;'>
								<td style='width:38px; height:26px;'>&nbsp;</td>
								<td valign='middle' style='width:300px; height:26px;'><span class='title'>SALESMEN</span></td>
								<td class='message' valign='middle' style='height:26px;'>".htmlspecialchars($message, ENT_QUOTES)."</td>
							</tr>
						</table>
					</td>
				</tr>";
							$querysearch="select ledger_number,ledger_name from salesmen ";
							$querysearch=$querysearch." where (ledger_number like"."('%".$txtKeyword."%') or ledger_name like"."('%".$txtKeyword."%')) ";

							$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());
							$totalrows = mysql_num_rows($resultsearch);

							if ($startrange=='')
								$startrange = 0;
							if ($perpage=='')
								$perpage = 20;

							$querysearch = $querysearch." limit ".$startrange.",".$perpage;
																
echo"			<tr>
					<td  height='34'  valign='top' id='content-top2'>
						<table border='0' cellpadding='0' cellspacing='0' class='layout-width' width='1100px'>
							<col width='450'>
							<col width='200'>
							<col width='200'>
							<col width='200'>
							<col width='200'>
							<col width='200'>
						<tr>
							<td valign='right' height='34' style='padding-left:52px'>";
echo"							<button type='button' id='btnClear' name='btnClear' onclick='ClearPage(); return false;' title='Clear Page'><span><span>$buttonclear</span></span></button>";
echo"							<button type='button' id='btnPost' name='btnPost' onclick='SubmitRecord(); return false;' title='Save Changes' $Insmode><span><span>$save</span></span></button>";
echo"							<button type='button' id='btnPrt' name='btnPrt' onclick='PrintPreview(); return false;' title='Print' ><span><span>$print</span></span></button>";
echo"							<button type='button' id='btnadd' name='btnadd' onclick='addserial(); return false;' title='Print' ><span><span>$add</span></span></button>";

echo"  						 </td>

							<td align='center'>";
								$diff= $startrange - $perpage;
								if (($diff) >= 0 ){
									$prvstartrange = $startrange - $perpage;
									echo"<img src='img/arrowleft.png' title='Previous' onMouseOver=\"style.cursor='hand'\"  onclick=SetPrvPage('".$prvstartrange."','".$perpage."')>";
								}
								else
									echo "&nbsp;";
									
echo"						</td>
							<td  align='center'>";
								if ($startrange <= $totalrows){
									$startrange = $startrange + $perpage;
									if  ($startrange <= $totalrows)
										echo"<img src='img/arrowright.png' title='Next' onMouseOver=\"style.cursor='hand'\" onclick=SetNextPage('".$startrange."','".$perpage."')>";
								} else
									echo "&nbsp;";			
echo"						</td>



							<td align='left' width='356px'>
								<input type='text' name='txtKeyword' value='$txtKeyword' style='width:110px;' onKeyPress='return submitenter(this,event)'>&nbsp;
								<button type='button' id='btnSearch' name='btnSearch' onclick='SearchForSalesmen(); return false;' title='Search Salesmen'><span><span>$find</span></span></button>
								<button type='button' id='btnClear' name='btnClear' onclick='ClearKeyword(); return false;' title='Clear Keyword'><span><span>$clear</span></span></button>
							</td>
							<td align='left'>
								<span class='style1'><b>$results/$page</b></span>
								<span class='style1'><select name='perpage' id='perpage' value='$perpage' onchange=set_limit();>";
	 
									if ($startrange=='')
										$startrange = 0;
									if ($perpage=='')
										$perpage = 20;
										
									//row limit loop
									foreach ($config['trowlimit'] as $value) {
										echo "<option value='$value' ";
												if($value==$perpage) echo "selected";
													echo " >$value</option>";
									}
echo"						</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>	
				<td id='content-body'>";
$tabs = new tabs("Manifest");	
$tabs->start("Main Page");
	echo "		<table border='0'  align='center' valign='top'  class='tablecontent' >
							<col width=100%>
							<tr bgcolor='#F7F7F7' >
								<td valign='top' align='left' >
									<table border='1' style='table-layout:fixed; width=20000px' align='left' valign='top' cellspacing=0>
										<col width=10>
										<col width=350>
										<col width=130>
										<col width=170>
										<col width=150>
										<col width=150>";
										
										
								echo "<input type=hidden name='stamp1' value='$stamp1'>";
								echo "<input type=hidden name='stamp2' value='$stamp2'>";
								echo "<input type=hidden name='stamp3' value='$stamp3'>";
								echo "<input type=hidden name='stamp4' value='$stamp4'>";
								echo "<input type=hidden name='stamp5' value='$stamp5'>";
								echo "<input type=hidden name='stamp6' value='$stamp6'>";
				
				
					echo "
										<tr bgcolor='#F7F7F7' height='40'>
										<td><span class='style1'>Shipper</span></td>
											<td valign='center' align='left' >
											<table border=0>
											<tr><td align='left'> &#9679;<input type='text' name='shipper1' id='shipper1' ".$KeyDown." value='".htmlspecialchars($shipper1, ENT_QUOTES)."'    style='width:330; border:none;'/></td>
										</tr>
										<tr><td align='left'> &#9679;<input type='text' name='shipper2' id='shipper2' ".$KeyDown." value='".htmlspecialchars($shipper2, ENT_QUOTES)."'    style='width:330; border:none;'/></td>
										</tr>
										<tr><td align='left'> &#9679;<input type='text' name='shipper3' id='shipper3' ".$KeyDown." value='".htmlspecialchars($shipper3, ENT_QUOTES)."'   $status  style='width:330; border:none;'/></td>
										</tr>
										<tr><td align='left'> &#9679;<input type='text' name='shipper4' id='shipper4'".$KeyDown." value='".htmlspecialchars($shipper4, ENT_QUOTES)."'   $status  style='width:330; border:none;'/></td>
										</tr>
										</table>
										</td>";
										echo "	<td valign='top'>
										<table border=0><tr><td>
										<span class='style1'>Voy Year</span> </td>
										<td><input type='text' name='voyage_year'  size=2 maxlength='2' value='".htmlspecialchars($voyage_year, ENT_QUOTES)."'>
									</td></tr>
									<tr><td>
										<span class='style1'>Voy No  </span></td>
										<td>
										<input type='text' name='voyage_number'  size=3 maxlength='3' value='".htmlspecialchars($voyage_number, ENT_QUOTES)."'>
										</td>
									
									
									
									</tr>
										<tr><td>
											<span class='style1'>Status</span>
										</td>
										<td><select name='status'>
										<option value=''></option>
										<option value='P'";
										if($status=='P')echo "selected";
										echo ">P</option>
										<option value='S'";
										if($status=='S')echo "selected";
										echo "
										>S</option>
										<option value='X'
										";
										if($status=='X')echo "selected";
										echo ">X</option>
										</select>
										</td></tr></table></td>
										
										<td valign='top'>
										<table><tr><td><span class='style1'>BL No </span></td>
										<td><input type='text' name='bol_number' size=3  maxlength='3' value='".htmlspecialchars($bol_number, ENT_QUOTES)."'>
										</td></tr>
										<tr><td><span class='style1'>BL Type </span></td>
										<td><select name='voyage_type' >
										<option value=''></option>
										<option value='I'";
										if ($voyage_type=='I')
											echo "selected";
											echo ">I</option>
										<option value='E'";
										if ($voyage_type=='E')
											echo "selected";
										echo ">E</option>
										<option value='G'
										";
										if ($voyage_type=='G')
											echo "selected";
										echo ">G</option>
										</select></td></tr>
										<tr><td>
										<span class='style1' >BL P.No </span></td>
										<td><input type='text' name='voyage_pagenumber' value='".htmlspecialchars($voyage_pagenumber, ENT_QUOTES)."' maxlength='2' size=2>
										</td>
										
										
										
										
										</tr></table></td>
										
										<td valign='top' >
										<table><tr><td>
										
										<span class='style1'>Voy Dest </span>
										</td>
										<td>
										<input type='text' name='voyage_destination' size=3 maxlength='3' value='".htmlspecialchars($voyage_destination, ENT_QUOTES)."'>
										</td></tr>
										<tr><td>
										<span class='style1'>Nb Of Teus</span></td>
										<td><input type='text' name='nbofteus' size=3 value='".htmlspecialchars($nbofteus, ENT_QUOTES)."'>
										</td></tr>
										<tr><td>
										<span class='style1'>Free T. D.</span>
										</td>
										<td>
										<input type='text' name='freetimedays' size=3 value='".htmlspecialchars($freetimedays, ENT_QUOTES)."'>
										</td>
										</tr>
										</table></td>
										<td>
										<table>
										<tr>
										<td>
											
										<span class='style1'>BL</span></td>
										<td><input type='text' name='billoflading' size=13 maxlength='13' value='".htmlspecialchars($billoflading, ENT_QUOTES)."' >
										</td></tr>
										<tr><td>
										<span class='style1'>Vessel</span></td>
										<td><input type='text' name='vessel_id' size=13 value='".htmlspecialchars($vessel_id, ENT_QUOTES)."'>
										</td></tr>
										<tr><td>
										<span class='style1'>Offer</span></td>
										
										<td><input type='text' name='offer_number'  size=13 value='".htmlspecialchars($offer_number, ENT_QUOTES)."'>
										</td>									
										</tr>
										</tr></table></td></tr>";
										
										echo "
										<tr bgcolor='#F7F7F7' height='40'><td><span class='style1'>Consignee</span></td>
											<td valign='center' align='left'   colspan='1'>
											<table border=0>
											
											
											<tr><td align='left'> &#9679;<input type='text' id='consignee1' ".$KeyDown."  name='consignee1'  value='".htmlspecialchars($consignee1, ENT_QUOTES)."'    style='width:330;border:none;'/></td>
										</tr>
										<tr><td align='left'> &#9679;<input type='text' id='consignee2' ".$KeyDown." name='consignee2'  value='".htmlspecialchars($consignee2, ENT_QUOTES)."'    style='width:330;border:none;'/></td>
										</tr>
										<tr><td align='left'> &#9679;<input type='text' id='consignee3'  ".$KeyDown." name='consignee3'  value='".htmlspecialchars($consignee3, ENT_QUOTES)."'   $status  style='width:330;border:none;'/></td>
										</tr>
										<tr><td align='left'> &#9679;<input type='text' id='consignee4' ".$KeyDown."  name='consignee4'  value='".htmlspecialchars($consignee4, ENT_QUOTES)."'   $status  style='width:330;border:none;'/></td>
										</tr>
										</table>
										</td>
										
										<td colspan=2 >
										<table ><tr>										
										<td  align='left' ><span class='style1'> PRECARRIAGE/CARRIAGE</span>
											</td><td><input type='text' name='precarriage' style='width:160px;'  value='".htmlspecialchars($precarriage, ENT_QUOTES)."' ></td>
										</tr><tr>
										<td  align='left' ><span class='style1' >PLACE OF RECEIPT</span></td><td>
											<input type='text' name='recieptplace' style='width:160px;' value='".htmlspecialchars($recieptplace)."' ></td>
										</tr><tr>
										<td <span class='style1' >PORT OF LOADING</span></td><td>	

										<select name='portlading' style='width:160px'>";
											$query="select port_name from port";
											$res=mysql_query($query,$connection);
											echo "<option value=''></option>";
											while($row=mysql_fetch_array($res)){
												echo "<option value='$row[0]'";
											
											if ($row[0]==$portlading)echo "selected";
											echo ">$row[0]</option>";
											}
											echo "</select>
											";  
											//<input type='text' name='portlading' value='".htmlspecialchars($portlading, ENT_QUOTES)."'  style='width:160px'></td>
										//<td>Number Of NegotiableB/L Issued <input type='text' name='nonegotiable' value='".htmlspecialchars($nonegotiable, ENT_QUOTES)."'    >
										//</span></td>
										echo"</tr>
										</table></td>
										<td colspan=2 >
										<table ><tr>	
										<td align=left>
										
										<span class='style1' >
											PLACE OF DELIVERY</span></td><td><input type='text' name='placedelivery' value='".htmlspecialchars($placedelivery, ENT_QUOTES)."' ></td>
										</tr><tr>
                                        <td  align='left' ><span class='style1' >PORT OF DISCHARGE</span></td><td>
											<select name='portdischarge' style='width:160px'>";
											$query="select port_name from port";
											$res=mysql_query($query,$connection);
											echo "<option value=''></option>";
											while($row=mysql_fetch_array($res)){
												echo "<option value='$row[0]'";
											
											if ($row[0]==$portdischarge)echo "selected";
											echo ">$row[0]</option>";
											}
											echo "</select></td></tr><tr><td  align='left' ><span class='style1' ></span></td></td></table></td>";
											
					
										echo "
										<tr bgcolor='#F7F7F7' height='40'>
										<td><span class='style1'>Notify</span></td>
											<td valign='center' align='left' colspan=1>
											<table border=0>
											
											<tr><td align='left'> &#9679;<input type='text' id='notify1' ".$KeyDown."  name='notify1'  value='".htmlspecialchars($notify1, ENT_QUOTES)."'    style='width:330;border:none;'/></td>
										</tr>
										<tr><td align='left'> &#9679;<input type='text' id='notify2'  ".$KeyDown."  name='notify2'  value='".htmlspecialchars($notify2, ENT_QUOTES)."'    style='width:330;border:none;'/></td>
										</tr>
										<tr><td align='left'> &#9679;<input type='text' id='notify3' ".$KeyDown."  name='notify3'  value='".htmlspecialchars($notify3, ENT_QUOTES)."'   $status  style='width:330;border:none;'/></td>
										</tr>
										<tr><td align='left'> &#9679;<input type='text' id='notify4'  ".$KeyDown." name='notify4'  value='".htmlspecialchars($notify4, ENT_QUOTES)."'   $status  style='width:330;border:none;'/></td>
										</tr>
										</table>
										</td>
											
											
											";
											
										
										
										echo"	
											<td colspan=2 >
										      <table ><tr>

										<td><span class='style1'>Client</span></td>
										<td>";
										
										
										echo "<select name='client_name' style='width:250px;'>";
											$query="select ledger_name,ledger_number from clients";
											$res=mysql_query($query,$connection);
											echo "<option value=''></option>";
											while($row=mysql_fetch_array($res)){
												echo "<option value='$row[1]'";
											
											if ($row[1]==$client_name)echo "selected";
											echo ">$row[0]</option>";
											}
											echo "</select>";
										
										
										
										//<input type='text' name='client_name'  value='".htmlspecialchars($client_name, ENT_QUOTES)." ' style='width:250px;'>
										echo "</td>
										</tr><tr>
										 <td><span class='style1'>Agent Name</span></td><td>";
										 echo "<select name='agent_id' >";
											$query="select agent1 from agent";
											$res=mysql_query($query,$connection);
											echo "<option value=''></option>";
											while($row=mysql_fetch_array($res)){
												echo "<option value='$row[0]'";
											
											if ($row[0]==$agent_id)echo "selected";
											echo ">$row[0]</option>";
											}
											echo "</select>";
										 
										
										//<input type='text' name='agent_id' size=6 value='".htmlspecialchars($agent_id, ENT_QUOTES)."'style='width:250px;'>
										echo "</td></tr>	
										
										
										<tr><td>
										<span class='style1'>Freight</span></td><td>
											<input type='text' name='freight_type'  size=3  value='".htmlspecialchars($freight_type, ENT_QUOTES)."'>
										
										</td></tr><tr><td>
										<span class='style1'>BL Freight</span></td><td>								
										
											<input type='text' name='freight'   value='".htmlspecialchars($freight, ENT_QUOTES)."'></td>
											  
										</tr></table></td>";
										
										
										echo"	
											<td colspan=2 >
										      <table  border=0><tr>
                                         <td>
										<span class='style1' >Issue At</td><td>
										<input type='text' name='issuedat' value='".htmlspecialchars($issuedat)."'
										style='width:125px;'>&nbsp;&nbsp;
																			<button type='button' id='stamp' name='stamp' onclick='addstamp(); return false;' title='Clear Page'><span><span>add stamp</span></span></button>
										
										</td></tr>
										<tr><td>
										<span class='style1' >On </td><td>
										<input type='text' name='issuedon' size=8 value='".htmlspecialchars($issuedon)."'>
										<a HREF='#' onClick=\"displayCalendar(document.Manifest.issuedon,'dd-mm-yyyy',this); return false;\" NAME=\"anchor1\" ID=\"anchor1\" >";

										echo"<image src='./img/cal.gif' border=0 align=center ></image></a></td>
 
										</tr><tr>";
										echo "<td>
										<span class='style1'>Date</span> </td>
										<td><input type='text' name='manifest_date' size='7' value='".htmlspecialchars($manifest_date, ENT_QUOTES)."'>
										<a HREF='#' onClick=\"displayCalendar(document.Manifest.manifest_date,'dd-mm-yyyy',this); return false;\" NAME=\"anchor1\" ID=\"anchor1\" >";

										echo"<image src='./img/cal.gif' border=0 align=center ></image></a>
									  &nbsp;&nbsp;&nbsp;<span class='style1'>Currency</span>
										</td>
										<td><input type='text' name='currency' size='3' value='".htmlspecialchars($currency, ENT_QUOTES)."'>
										</td>
										
										
										</tr><tr> <td><span class='style1'>received date</span></td>
										<td>
										
										<input type='text' name='received_date' size='7' value='".htmlspecialchars($received_date, ENT_QUOTES)."'>
										<a HREF='#' onClick=\"displayCalendar(document.Manifest.received_date,'dd-mm-yyyy',this); return false;\" NAME=\"anchor1\" ID=\"anchor1\" >";

										echo"<image src='./img/cal.gif' border=0 align=center ></image></a>
									  &nbsp;&nbsp;&nbsp;
										
										</td>
										
										
											  
										</tr></table></td>";
											
											
										
										echo "<tr>";
										
										
										echo "<td></td>
										<td valign='center' align='left' >
											<table border=0><tr><td>
											<span class='style1'>Tax Description&nbsp;</span></td></tr>";
											echo "<tr><td><select name='desc1' style='width:330px'>";
											$query="select item_description from items where SubGroup_Code='TARROS'";
											$res=mysql_query($query,$connection);
											echo "<option value='$desc1'>$desc1</option>";
											while($row=mysql_fetch_array($res)){
												echo "<option value='$row[0]'";
											
											if ($row[0]==$desc1)echo "selected";
											echo ">$row[0]</option>";
											}
											echo "</select></td></tr>";
											echo "
										<tr><td>";
											echo "<select name='desc2' style='width:330px'>";
											$query="select item_description from items where SubGroup_Code='TARROS'";
											$res=mysql_query($query,$connection);
											echo "<option value='$desc2'>$desc2</option>";
											while($row=mysql_fetch_array($res)){
												echo "<option value='$row[0]'";
											
											if ($row[0]==$desc2)echo "selected";
											echo ">$row[0]</option>";
											}
											echo "</select></td></tr>";
										
										
										
											echo "
										<tr><td>";
											echo "<select name='desc3' style='width:330px'>";
											$query="select item_description from items where SubGroup_Code='TARROS'";
											$res=mysql_query($query,$connection);
											echo "<option value='$desc3'>$desc3</option>";
											while($row=mysql_fetch_array($res)){
												echo "<option value='$row[0]'";
											
											if ($row[0]==$desc3)echo "selected";
											echo ">$row[0]</option>";
											}
											echo "</select></td></tr>";
											echo "
										<tr><td>";
											echo "<select name='desc4' style='width:330px'>";
											$query="select item_description from items where SubGroup_Code='TARROS'";
											$res=mysql_query($query,$connection);
											echo "<option value='$desc4'>$desc4</option>";
											while($row=mysql_fetch_array($res)){
												echo "<option value='$row[0]'";
											
											if ($row[0]==$desc4)echo "selected";
											echo ">$row[0]</option>";
											}
											echo "</select></td></tr>";
											echo "
										<tr><td>";
											echo "<select name='desc5' style='width:330px'>";
											$query="select item_description from items where SubGroup_Code='TARROS";
											$res=mysql_query($query,$connection);
											echo "<option value='$desc5'>$desc5</option>";
											while($row=mysql_fetch_array($res)){
												echo "<option value='$row[0]'";
											
											if ($row[0]==$desc5)echo "selected";
											echo ">$row[0]</option>";
											}
											echo "</select></td></tr>";
											echo "
										<tr><td>";
											echo "<select name='desc6' style='width:330px'>";
											$query="select item_description from items where SubGroup_Code='TARROS";
											$res=mysql_query($query,$connection);
											echo "<option value='$desc6'>$desc6</option>";
											while($row=mysql_fetch_array($res)){
												echo "<option value='$row[0]'";
											
											if ($row[0]==$desc6)echo "selected";
											echo ">$row[0]</option>";
											}
											echo "</select></td></tr>";
										
											
											
											/*<tr><td align='left'> &#9679;<input type='text' name='desc1'  value='".htmlspecialchars($desc1, ENT_QUOTES)."'    style='width:330;border:none;'/></td>
										</tr>
										<tr><td align='left'> &#9679;<input type='text' name='desc2'  value='".htmlspecialchars($desc2, ENT_QUOTES)."'    style='width:330;border:none;'/></td>
										</tr>
										<tr><td align='left'> &#9679;<input type='text' name='desc3'  value='".htmlspecialchars($desc3, ENT_QUOTES)."'   $status  style='width:330;border:none;'/></td>
										</tr>
										<tr><td align='left'> &#9679;<input type='text' name='desc4'  value='".htmlspecialchars($desc4, ENT_QUOTES)."'   $status  style='width:330;border:none;'/></td>
										</tr>
										<tr><td align='left'> &#9679;<input type='text' name='desc5'  value='".htmlspecialchars($desc5, ENT_QUOTES)."'   $status  style='width:330;border:none;'/></td>
										</tr>
										<tr><td align='left'> &#9679;<input type='text' name='desc6'  value='".htmlspecialchars($desc6, ENT_QUOTES)."'   $status  style='width:330;border:none;'/></td>
										</tr>*/
										echo"</table>
										</td>
										
										
										<td valign='center' align='left' >
											<table border=0><tr><td>
											<span class='style1'>Tax Amount&nbsp;<span class='style26'></span></span></td></tr>
											<tr><td align='left'> &#9679;<input type='text' name='amount1'  value='".htmlspecialchars($amount1, ENT_QUOTES)."'    style='width:120;border:none;'/></td>
										</tr>
										<tr><td align='left'> &#9679;<input type='text' name='amount2'  value='".htmlspecialchars($amount2, ENT_QUOTES)."'    style='width:120;border:none;'/></td>
										</tr>
										<tr><td align='left'> &#9679;<input type='text' name='amount3'  value='".htmlspecialchars($amount3, ENT_QUOTES)."'   $status  style='width:120;border:none;'/></td>
										</tr>
										<tr><td align='left'> &#9679;<input type='text' name='amount4'  value='".htmlspecialchars($amount4, ENT_QUOTES)."'   $status  style='width:120;border:none;'/></td>
										</tr>
										<tr><td align='left'> &#9679;<input type='text' name='amount5'  value='".htmlspecialchars($amount5, ENT_QUOTES)."'   $status  style='width:120;border:none;'/></td>
										</tr>
										<tr><td align='left'> &#9679;<input type='text' name='amount6'  value='".htmlspecialchars($amount6, ENT_QUOTES)."'   $status  style='width:120;border:none;'/></td>
										</tr>
										</table>
										</td>
											
											<td valign='center' align='left' >
											<table border=0><tr><td>
											<span class='style1'>Evidence&nbsp;<span class='style26'></span></span></td></tr>
											<tr><td align='left'> &#9679;<input type='text' name='evidence1'  value='".htmlspecialchars($evidence1, ENT_QUOTES)."'    style='width:150;border:none;'/></td>
										</tr>
										<tr><td align='left'> &#9679;<input type='text' name='evidence2'  value='".htmlspecialchars($evidence2, ENT_QUOTES)."'    style='width:150;border:none;'/></td>
										</tr>
										<tr><td align='left'> &#9679;<input type='text' name='evidence3'  value='".htmlspecialchars($evidence3, ENT_QUOTES)."'   $status  style='width:150;border:none;'/></td>
										</tr>
										<tr><td align='left'> &#9679;<input type='text' name='evidence4'  value='".htmlspecialchars($evidence4, ENT_QUOTES)."'   $status  style='width:150;border:none;'/></td>
										</tr>
										<tr><td align='left'> &#9679;<input type='text' name='evidence5'  value='".htmlspecialchars($evidence5, ENT_QUOTES)."'   $status  style='width:150;border:none;'/></td>
										</tr>
										<tr><td align='left'> &#9679;<input type='text' name='evidence6'  value='".htmlspecialchars($evidence6, ENT_QUOTES)."'   $status  style='width:150;border:none;'/></td>
										</tr>
										</table>
										</td>
										
										
										<td colspan=2 align='left' >
											<table border=0><tr>
										<td ><span class='style1' >Carrier Signature/the Agent of the carrier</span></td></tr><tr><td>
										<input type='text' name='carriersign' value='".htmlspecialchars($carriersign, ENT_QUOTES)."' size=10></td>";
										$query="select code from toc";
											//echo $query;
										$res=mysql_query($query,$connection) or die(mysql_error());	
										echo "</tr>";
										echo "</td><tr>
											<td >
											<span class='style1' >Number Of NegotiableB/L Issued</span></td></tr><tr><td> <input type='text' name='nonegotiable' value='".htmlspecialchars($nonegotiable, ENT_QUOTES)."' >
										</span>";
										
										echo "</td>	</tr><tr>
                                        <td  align='left' ><span class='style1' >TOC</span>
											<SELECT name='termcarriage' >";
										echo "<option value=''></option>";
											while($row=mysql_fetch_array($res)){
										echo "<option value='$row[0]' ";
									
									
									    if ($row[0]==$termcarriage) echo selected;
									        echo ">$row[0]</option>";
											}
										//<input type='text' name='termcarriage' value='".htmlspecialchars($termcarriage)."' style='width:150px' ></td>
										
								   	   echo "</select></td></tr><tr>
                                        <td>
										<span class='style1'>Linear Meters</span>
										
										<input type='text' name='linearmeter' size=6 value='".htmlspecialchars($linearmeter, ENT_QUOTES)."'>
										</td>
									   
										
										</tr></table></td>";
									echo "
									</table>
								</td>
							</tr>
							
							<tr><td>";
							
							
							echo "<div id='datagriditem' class='grid' style='width:1090px;' >";




//Show Items Grid
ShowitemGrid($connection,'Manifest_Dt',$Manifest_Auto,$_SESSION['gdl_parameters'],$_SESSION['gdl_arrayaccess'],'ManifestDt.DeliveryDt_ID');

echo"	  </div>"; 
							
							echo "<div id='datagrid' class='grid' style='width:1090px;' >";




//Show Items Grid
ShowDeliveryDtGrid($connection,'Manifest_Dt',$Manifest_Auto,$_SESSION['gdl_parameters'],$_SESSION['gdl_arrayaccess'],'ManifestDt.DeliveryDt_ID');

echo"	  </div>"; 
							
							echo "</td></tr>
							<tr>
								
							
										<tr>
											<td>";
											
										
												
echo "											</td>
											</tr>
									
									</table>
									
									
									
									
								</td>
								
							</tr>
							
							
							
						</td>
					</tr></table>";	
$tabs->end();

$tabs->start("Contact");

echo"		<table border='0' width='1100px'  align='left' valign='top'>
				<col width='50'>
				<col width='100'>
				<col width='50'>
				<col width='100'>
				<col width='50'>
				<col width='100'>
				<col width='50'>
				<col width='100'>";
				
echo"			<tr bgcolor='#F7F7F7' height='25' align=left>
					<td>
						<table border='0' width='1100px'  align='left' valign='top'>
							<col width='50'>
							<col width='100'>
							<col width='50'>
							<col width='100'>
							<col width='50'>
							<col width='100'>
							<col width='50'>
							<col width='100'>
							<tr>
								<td><span class='style1'>$phone1_label </span>";
									if($module=='1')
									echo"<span class='style26'>*</span>";
			echo"				</td>";
			echo"				<td><input type='text' name='phone1'  value='".htmlspecialchars($phone1, ENT_QUOTES)."' maxlength='25' $status style='font-size:12px;'></td>
								<td align=left><span class='style1'>$phone2_label </span></td>
								<td><input type='text' name='phone2'  value='".htmlspecialchars($phone2, ENT_QUOTES)."' maxlength='25' $status style='font-size:12px;'></td>
								<td align=left ><span class='style1'>$fax_label </span></td>
								<td><input type='text' name='fax' value='".htmlspecialchars($fax, ENT_QUOTES)."'  maxlength='25' $status style='font-size:12px;'></td>
								<td align=left><span class='style1'>$email_label </span></td>
								<td><input type='text' name='email' value='".htmlspecialchars($email, ENT_QUOTES)."'  maxlength='30' $status style='font-size:12px;'></td>
							</tr>
						</table>
					</td>
				</tr>";
				
echo"			<tr >
					<td >
						<div style='overflow:scroll;height:150px;width:1100px;border:0px solid #000000;'>
							<table width='1100px' border='0'>
								<col width='200'>
								<col width='200'>
								<col width='200'>
								<col width='200'>
								<col width='200'>
								<col width='200'>
								<col width='200'>
								<col width='200'>
								<col width='200'>
								<col width='200'>
								<col width='200'>
								<col width='200'>
								<col width='200'>
								<tr bgcolor='#D0D0D0' height='25px'>
									<td >&nbsp;&nbsp;</td>
									<td >&nbsp;&nbsp;</td>
									<td align='center'><span class='style27'>$Title_label <span class='style26'>*</span></span></td>
									<td align='center'><span class='style27'> $First_Name_label<span class='style26'>*</span></span></td>
									<td align='center'><span class='style27'>$Father_Name_label<span class='style26'>*</span></span></td>
									<td align='center'><span class='style27'>$Last_Name_label<span class='style26'>*</span></span></td>
									<td align='center'><span class='style27'>$tel1_label<span class='style26'>*</span></span></td>
									<td align='center'><span class='style27'>$tel2_label</span></td>
									<td align='center'><span class='style27'>$tel3_label</span></td>
									<td align='center'><span class='style27'>$email_label</span></td>
									<td align='center'><span class='style27'>$reference_label</span></td>
									<td align='center'><span class='style27'>$city1_label</span></td>
									<td><span align='center' class='style27'>$city2_label</span></td>
									<td><span align='center' class='style27'>$city2_label</span></td>
								</tr>";

				echo"			<tr>
									<td align=center>";
echo"									<button type='button' style='width:60px;' id='btnPost' name='btnPost' onclick='SubmitRecord(2); return false;' title='Save Changes' $Insmode><span><span>$submit_button</span></span></button>";
echo"								</td>
									<td valign='bottom'>	
										<button type='button' style='width:60px;' id='clearbutton' name='clearbutton' onclick='cleardetail(); return false;' title='Clear Detail'><span><span>$clear</span></span></button>";
echo"									&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
									</td>
									<td valign='top'>&nbsp;
										<select name='telephoneno_title'  $dis>";
											echo"<option value=''></option>";
											while ($rowwp=mysql_fetch_row($result_title)){
												if ($telephoneno_title==$rowwp[1])
													echo "<option value='$rowwp[1]' selected>$rowwp[1]</option>";
												else
													echo "<option value='$rowwp[1]'>$rowwp[1]</option>";
											}
echo"									</select>
									</td>
									
									<td>&nbsp;<input type='text' name='telephone_name' value='$telephone_name' $status maxlength='45' style='width:150px;'>&nbsp;</td>
									<td>&nbsp;<input type='text' name='telephone_fname' value='$telephone_fname' $status maxlength='50' style='width:150px;'>&nbsp;</td>
									<td>&nbsp;<input type='text' name='telephone_lname' value='$telephone_lname' $status maxlength='45' style='width:150px;'>&nbsp;</td>
									<td>&nbsp;<input type='text' name='telephone_no' value='$telephone_no' $status maxlength='15' style='width:120px;'>&nbsp;</td>
									<td>&nbsp;<input type='text' name='telephone_no2' value='$telephone_no2' $status maxlength='15' style='width:120px;'>&nbsp;</td>
									<td>&nbsp;<input type='text' name='telephone_no3' value='$telephone_no3' $status maxlength='15' style='width:120px;'>&nbsp;</td>
									<td>&nbsp;<input type='text' name='telephone_email' value='$telephone_email' $status maxlength='45' style='width:180px;'>&nbsp;</td>
									<td>&nbsp;<input type='text' name='telephone_reference' value='$telephone_reference' $status maxlength='15' style='width:180px;'>&nbsp;</td>
									<td>&nbsp;<input type='text' name='telephone_city1' value='$telephone_city1' $status maxlength='45' style='width:120px;'>&nbsp;</td>
									<td>&nbsp;<input type='text' name='telephone_city2' value='$telephone_city2' $status maxlength='45' style='width:120px;'>&nbsp;</td>
									<td>&nbsp;<input type='text' name='telephone_city3' value='$telephone_city3' $status maxlength='45' style='width:120px;'>&nbsp;</td>
								</tr>";


									$querydt = " select Telephone_increment, TelephoneNo_ContactTitle,Telephone_name,telephoneno_fname,telephoneno_lname,TelephoneNo,TelephoneNo2,TelephoneNo3,telephoneno_email,".
											   " telephoneno_reference,telephoneno_city1,telephoneno_city2,telephoneno_city3 ".
											   " from telephoneno ".
											   " where Ledger_number='".$ledger_number."'";

									//echo $querydt;
									$resultdt = mysql_query($querydt, $connection);
									while($rowsdt=mysql_fetch_array($resultdt)){
													
										$ct+=1;

										if($ct%2==0)
											$Color="style='background-color:".$grid_color1."'";
										else			
											$Color="style='background-color:".$grid_color2."'";	
															
								
							echo "<tr ".$Color." >";
							echo "	<td align='center' valign='center'><span class='style15'><img src='img/button_edit.png'  onMouseOver=\"style.cursor='hand'\" onclick=UpdateDetail('".$rowsdt[0]."') title='Edit Record'  ></span></td>";
							echo "	<td align='center' valign='center'><span class='style15'><img src='img/c_delete.png'  onMouseOver=\"style.cursor='hand'\" onclick=DeleteDetail('".$rowsdt[0]."') title='Delete Record'  ></span></td>";
							echo "	<td align='center'><span class='style15'>".$rowsdt[1]."</span></td>";
							echo "	<td align='left'><span class='style15'>".$rowsdt[2]."</span></td>";
							echo "	<td align='left'><span class='style15'>".$rowsdt[3]."</span></td>";
							echo "	<td align='left'><span class='style15'>".$rowsdt[4]."</span></td>";
							echo "	<td align='left'><span class='style15'>".$rowsdt[5]."</span></td>";
							echo "	<td align='left'><span class='style15'>".$rowsdt[6]."</span></td>";
							echo "	<td align='left'><span class='style15'>".$rowsdt[7]."</span></td>";
							echo "	<td align='left'><span class='style15'>".$rowsdt[8]."</span></td>";
							echo "	<td align='left'><span class='style15'>".$rowsdt[9]."</span></td>";
							echo "	<td align='left'><span class='style15'>".$rowsdt[10]."</span></td>";
							echo "	<td align='left'><span class='style15'>".$rowsdt[11]."</span></td>";
							echo "	<td align='left'><span class='style15'>".$rowsdt[12]."</span></td>";
							echo "	<td align='left'><span class='style15'>&nbsp;</span></td>";
							echo "</tr>";
												
						}					
echo"						</table>
						</div>
					</td>
				</tr>
				
				
				<tr>
					<td width='1100px' valign='top'>
						<table style='width:1100px;' border='0' cellspacing=0>
							<col width=100>
							<col width=150>
							<tr>
								<td>
									<table style='width:1100px;' border='0' cellspacing=0>
										<col width=30>
										<col width=80>
										<col width=140>
										<col width=130>
										<tr height='30px' style='background-color:darkgray;'>
											<td>&nbsp;</td>
											<td align='center'><span class='style1'><b>$code_label</b></td>
											<td align='center'><span class='style1'><b>$name_label</b></td>
										</tr>
										<tr>
											<td colspan=3>";
											//	<div style='overflow-y:scroll;height:320px;width:370px;border:0px solid #000000;padding-left:5px;'>
echo"											<table  border='0' width='1100px'>
													<col width=30>
													<col width=160>
													<col width=170>";
																

													$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());	
													while($rows=mysql_fetch_array($resultsearch)){
														$ct+=1;
														$stylefont='style15';
														if($ct%2==0)
															$Color="style='background-color:".$grid_color1."'";
														else			
															$Color="style='background-color:".$grid_color2."'";	
																
														if($mainmode=='edit' && $ledger_numberPrv==$rows[0]){
															
															$Color="style='background-color:#1e87a5'";
															$stylefont='style28';
														}	
	
echo'													<tr '.$Color.' height="20px" >';
															if($FI_SalesmenDel==1)	
print<<<HERE
															<td align=center ><img border='0' src='img/c_delete.png' width='9' height='10' title='Delete Detail' onmouseover="this.style.cursor='pointer'" OnClick="confirm_delete('$rows[0]')" $DelMode></td>
HERE;
else
	print<<<HERE
															<td align=center >&nbsp;</td>
HERE;
	echo"													<td style='cursor:pointer;' ";if($FI_SalesmenMod==1) echo " onclick=SetSales('$rows[0]');";echo"><span class='$stylefont' >$rows[0]&nbsp;</span></font></td>
															<td style='cursor:pointer;' ";if($FI_SalesmenMod==1) echo " onclick=SetSales('$rows[0]');";echo"><font face='Arial' size='2' color='#186194'><span class='$stylefont'>$rows[1]&nbsp;</span></font></td>";
				echo"";
				echo"									</tr>";
																}		
				echo"								</table>";
												//	</div>
				echo"							</td>
											</tr>
										</table>
									</td>
								</tr>
							</table>
						</td>
					</tr>
				</table>";			  
$tabs->end();  

$tabs->start("Sales Commission");

echo"		<table border='0' width='1100px'  align='left' valign='top'>";
echo"			<tr>
					<td colspan=6>
						<table  border='0' width='1100px'>
							<col width='50'>
							<col width='50'>
							<col width='150'>
							<col width='150'>
							<col width='150'>
							<col width='150'>
							<col width='150'>
							<col width='150'>
							<tr bgcolor='#D0D0D0' height='25px'>
								<td>&nbsp;&nbsp;</td>
								<td>&nbsp;&nbsp;</td>
								<td align='center'><span class='style27'>$Start_Date_label<span class='style26'>*</span></span></td>
								<td align='center'><span class='style27'>$End_Date_label</span></td>
								<td align='center'><span class='style27'>$Target_Amount</span></td>
								<td align='center'><span class='style27'>$currency_label<span class='style26'>*</span></span></td>
								<td align='center'><span class='style27'>$Target_Commission_label  %</span></td>
								<td align='center'><span class='style27'>$commission_label %</span></td>
							</tr>";

echo"						<tr>
								<td align=center>";
 echo"								<button type='button' id='btnPost' name='btnPost' onclick='SubmitRecord(3); return false;' title='Save Changes' $Insmode><span><span>$submit_button</span></span></button>";
 echo"							</td>
								<td valign='bottom'>
									<button type='button' id='clearbutton' name='clearbutton' onclick='cleardetailcom(); return false;' title='Clear Detail'><span><span>$clear</span></span></button>";
echo"							</td>
								<td>&nbsp;<input type='text' name='start_date' value='$start_date' readonly style='width:100px;'>";	
print<<<HERE
									&nbsp;&nbsp;<A HREF="#" onClick="displayCalendar(document.salesman.start_date,'dd-mm-yyyy',this); return false;" NAME="anchor1" ID="anchor1"><image src='./img/cal.gif' border=0 align=center></image></A>
HERE;
echo"							</td>
								<td>&nbsp;<input type='text' name='end_date' value='$end_date'  readonly style='width:100px;'>";
print<<<HERE
									&nbsp;&nbsp;<A HREF="#" onClick="displayCalendar(document.salesman.end_date,'dd-mm-yyyy',this); return false;" NAME="anchor1" ID="anchor1"><image src='./img/cal.gif' border=0 align=center></image></A>
HERE;
										
							echo"</td>
								<td>&nbsp;<input type='text' name='target_amount' value='$target_amount' $status  style='width:150px;text-align:right;'>&nbsp;</td>
								<td>&nbsp;<select  name='currencycom'   $dis>
										<option value=''></option>";
										while ($cr=mysql_fetch_row($currcom))
										{
										if ($cr[0]==$currencycom)
										echo"<option selected value='$cr[0]'>$cr[0]</option>";
										else
										echo"<option value='$cr[0]'>$cr[0]</option>";
										}	
									echo"</select>&nbsp;</td>
								<td>&nbsp;<input type='text' name='target_amountcom' value='$target_amountcom' $status maxlength='15' style='width:120px;text-align:right;'>&nbsp;</td>
								<td>&nbsp;<input type='text' name='commission' value='$commission' $status maxlength='15' style='width:120px;text-align:right;'>&nbsp;</td>
						</tr>";


							$querydt = " select SalesComm_Id,date_Format(SalesComm_StartDate,'%d/%m/%Y'),date_Format(SalesComm_EndDate,'%d/%m/%Y'),SalesComm_TargetAmnt,Currency_Code,SalesComm_TargetComm,SalesComm_Commission ".
									   " from salescomm ".
									   " where Salesman_Code='".$ledger_number."'";

									//echo $querydt;
									$resultdt = mysql_query($querydt, $connection);
									while($rowsdt=mysql_fetch_array($resultdt)){
													
										$ct+=1;

										if($ct%2==0)
											$Color="style='background-color:".$grid_color1."'";
										else			
										$Color="style='background-color:".$grid_color2."'";	
										
								
								echo "<tr ".$Color." >";
								echo "	<td align='center' valign='center'><span class='style15'><img src='img/button_edit.png'  onMouseOver=\"style.cursor='hand'\" onclick=UpdateDetailCom('".$rowsdt[0]."') title='Edit Record'  ></span></td>";
								echo "	<td align='center' valign='center'><span class='style15'><img src='img/c_delete.png'  onMouseOver=\"style.cursor='hand'\" onclick=DeleteDetailCom('".$rowsdt[0]."') title='Delete Record'  ></span></td>";
								echo "	<td align='center'><span class='style15'>".$rowsdt[1]."</span></td>";
								echo "	<td align='center'><span class='style15'>".$rowsdt[2]."</span></td>";
								echo "	<td align='right'><span class='style15'>".number_format($rowsdt[3], $DecimalBase, '.', ',')."</span></td>";
								echo "	<td align='center'><span class='style15'>".$rowsdt[4]."</span></td>";
								echo "	<td align='right'><span class='style15'>".$rowsdt[5]."</span></td>";
								echo "	<td align='right'><span class='style15'>".$rowsdt[6]."</span></td>";
								echo "</tr>";
										
									}					

						echo"</table>
							</td>
						</tr>
						<tr height='25px'></tr>
						<tr>
							<td width='1100px' valign='top'>
								<table style='width:1100px;' border='0' cellspacing=0>
									<col width=100>
									<col width=150>
									<tr>
										<td>
											<table style='width:1100px;' border='0' cellspacing=0>
												<col width=30>
												<col width=80>
												<col width=140>
												<col width=130>
												<tr height='30px' style='background-color:darkgray;'>
													<td>&nbsp;</td>
													<td align='center'><span class='style1'><b>$code_label</b></td>
													<td align='center'><span class='style1'><b>$Name_label</b></td>
												</tr>
												<tr>
													<td colspan=3>";
													//	<div style='overflow-y:scroll;height:320px;width:370px;border:0px solid #000000;padding-left:5px;'>
echo"														<table  border='0' width='1100px'>
																<col width=30>
																<col width=160>
																<col width=170>";
																

																$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());	
																while($rows=mysql_fetch_array($resultsearch)){
																	$ct+=1;
																	$stylefont='style15';
																	if($ct%2==0)
																		$Color="style='background-color:".$grid_color1."'";
																	else			
																		$Color="style='background-color:".$grid_color2."'";	
																			
																	if($mainmode=='edit' && $ledger_numberPrv==$rows[0]){
																		
																		$Color="style='background-color:#1e87a5'";
																		$stylefont='style28';
																	}	
				
		echo'														<tr '.$Color.' height="20px" >';
																		if($FI_SalesmenDel==1)	
print<<<HERE
																		<td align=center ><img border='0' src='img/c_delete.png' width='9' height='10' title='Delete Detail' onmouseover="this.style.cursor='pointer'" OnClick="confirm_delete('$rows[0]')" $DelMode></td>
HERE;
else
	print<<<HERE
																		<td align=center >&nbsp;</td>
HERE;
				echo"													<td style='cursor:pointer;' ";if($FI_SalesmenMod==1) echo " onclick=SetSales('$rows[0]');";echo"><span class='$stylefont' >$rows[0]&nbsp;</span></font></td>
																		<td style='cursor:pointer;' ";if($FI_SalesmenMod==1) echo " onclick=SetSales('$rows[0]');";echo"><font face='Arial' size='2' color='#186194'><span class='$stylefont'>$rows[1]&nbsp;</span></font></td>";
				echo"";
				echo"												</tr>";
																}		
				echo"										</table>";
													//	</div>
				echo"								</td>
												</tr>
											</table>
										</td>
									</tr>
								</table>
							</td>
						</tr>
						
					</table>";
								  
$tabs->end(); 

$tabs->start("Sales Commission By Client");

echo"			<table border='0' width='1100px' align='left' valign='top'>";
echo"				<tr >
						<td colspan=6>
							<table  border='0' width='1100px'>
								<col width='50'>
								<col width='50'>
								<col width='200'>
								<col width='200'>
								<tr bgcolor='#D0D0D0' height='25px'>
									<td>&nbsp;&nbsp;</td>
									<td>&nbsp;&nbsp;</td>
									<td align='center'><span class='style27'>$client_code_label / $client_name_label<span class='style26'>*</span></span></td>
									<td align='center'><span class='style27'>&nbsp;$commission_label %&nbsp;</span></td>
								</tr>";
echo"							<tr>
									<td align=center>";
echo"									<button type='button' id='btnPost' name='btnPost' onclick='SubmitRecord(4); return false;' title='Save Changes' $Insmode><span><span>$submit_button</span></span></button>";
echo"								</td>
									<td valign='bottom'>
										<button type='button' id='clearbutton' name='clearbutton' onclick='cleardetailcombyclient(); return false;' title='Clear Detail'><span><span>$clear</span></span></button>";			
echo"								</td>
									<td align=left>
										<input type=text name='client_code' value='$client_code' maxlength='10'  readonly size='10' style='font-size:12px; width:100px; '>&nbsp;";
echo"									<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Agent '  width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistclient(7); return false' /></span></label>";
echo"&nbsp;								<input type=text name='client_name' value='$client_name'   readonly size='10' style='font-size:12px; width:200px; '>
									</td>";
echo"								<td>&nbsp;<input type='text' name='commissionbyclient' value='$commissionbyclient' $status maxlength='15' style='width:120px;text-align:right;'>&nbsp;</td>
								</tr>";

									$querydt = " select SalesCommByClient_Id,Client_Code,SalesmanByClient_Comm,ledger_name ".
											   " from salescommbyclient left join ledger on ledger.ledger_number=salescommbyclient.client_code ".
											   " where Salesman_Code='".$ledger_number."'";

									//echo $querydt;
									$resultdt = mysql_query($querydt, $connection);
									while($rowsdt=mysql_fetch_array($resultdt)){
								
									$ct+=1;

									if($ct%2==0)
										$Color="style='background-color:".$grid_color1."'";
									else			
										$Color="style='background-color:".$grid_color2."'";	
										
								
							echo "<tr ".$Color." >";
							echo "	<td align='center' valign='center'><span class='style15'><img src='img/button_edit.png'  onMouseOver=\"style.cursor='hand'\" onclick=UpdateDetailComByClient('".$rowsdt[0]."') title='Edit Record'  ></span></td>";
							echo "	<td align='center' valign='center'><span class='style15'><img src='img/c_delete.png'  onMouseOver=\"style.cursor='hand'\" onclick=DeleteDetailComByClient('".$rowsdt[0]."') title='Delete Record'  ></span></td>";
							echo "	<td align='left'><span class='style15'>".$rowsdt[1].'   &nbsp;  '.$rowsdt[3]."</span></td>";
							echo "	<td align='right'><span class='style15'>".$rowsdt[2]."</span></td>";
							echo "</tr>";
											
									}					
echo"						</table>
						</td>
					</tr>
					
					<tr height='25px'></tr>
						<tr>
							<td width='1100px' valign='top'>
								<table style='width:1100px;' border='0' cellspacing=0>
									<col width=100>
									<col width=150>
									<tr>
										<td>
											<table style='width:1100px;' border='0' cellspacing=0>
												<col width=30>
												<col width=80>
												<col width=140>
												<col width=130>
												<tr height='30px' style='background-color:darkgray;'>
													<td>&nbsp;</td>
													<td align='center'><span class='style1'><b>$code_label</b></td>
													<td align='center'><span class='style1'><b>$name_label</b></td>
												</tr>
												<tr>
													<td colspan=3>";
													//	<div style='overflow-y:scroll;height:320px;width:370px;border:0px solid #000000;padding-left:5px;'>
echo"														<table  border='0' width='1100px'>
																<col width=30>
																<col width=160>
																<col width=170>";
																

																$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());	
																while($rows=mysql_fetch_array($resultsearch)){
																	$ct+=1;
																	$stylefont='style15';
																	if($ct%2==0)
																		$Color="style='background-color:".$grid_color1."'";
																	else			
																		$Color="style='background-color:".$grid_color2."'";	
																			
																	if($mainmode=='edit' && $ledger_numberPrv==$rows[0]){
																		
																		$Color="style='background-color:#1e87a5'";
																		$stylefont='style28';
																	}	
				
		echo'														<tr '.$Color.' height="20px" >';
																		if($FI_SalesmenDel==1)	
print<<<HERE
																		<td align=center ><img border='0' src='img/c_delete.png' width='9' height='10' title='Delete Detail' onmouseover="this.style.cursor='pointer'" OnClick="confirm_delete('$rows[0]')" $DelMode></td>
HERE;
else
	print<<<HERE
																		<td align=center >&nbsp;</td>
HERE;
				echo"													<td style='cursor:pointer;' ";if($FI_SalesmenMod==1) echo " onclick=SetSales('$rows[0]');";echo"><span class='$stylefont' >$rows[0]&nbsp;</span></font></td>
																		<td style='cursor:pointer;' ";if($FI_SalesmenMod==1) echo " onclick=SetSales('$rows[0]');";echo"><font face='Arial' size='2' color='#186194'><span class='$stylefont'>$rows[1]&nbsp;</span></font></td>";
				echo"";
				echo"												</tr>";
																}		
				echo"										</table>";
													//	</div>
				echo"								</td>
												</tr>
											</table>
										</td>
									</tr>
								</table>
							</td>
						</tr>";
						
echo"		</table>";
						  
$tabs->end();  

		if($module_services==1){
			
$tabs->start("Area");

					echo"<table border='0'  align='left' valign='top'>";
					echo"<tr ><td colspan=6><table  border='0'>
											<tr bgcolor='#D0D0D0' height='25px'><td colspan=2>&nbsp;&nbsp;</td>
											<td align='center'><span class='style27'>$area_label $code_label/$name_label<span class='style26'>*</span></span></td>
											
					</tr>";

					echo"<tr><td align=center colspan=2>";
					
					 echo"<button type='button' id='btnPost' name='btnPost' onclick='SubmitRecord(5); return false;' title='Save Changes' $Insmode><span><span>$submit_button</span></span></button>";
				 echo"<button type='button' id='clearbutton' name='clearbutton' onclick='cleardetailarea(); return false;' title='Clear Detail'><span><span>$clear</span></span></button>";
				 

					echo"&nbsp;&nbsp;</td>
					<td align=left><input type=text name='area_codedt' value='$area_codedt' maxlength='10'  readonly size='10' style='font-size:12px; width:100px; '>&nbsp;";
							
					echo"<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Agent '  width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistarea(5); return false' /></span></label>";
							
					echo"&nbsp;<input type=text name='area_namedt' value='$area_namedt'   readonly size='10' style='font-size:12px; width:200px; '></td>";
					echo"
					</tr>";

					$querydt = " select Salesmandt_id,salesmandt.Area_code,Ledger_number,area_name ".
							   " from salesmandt  ".
							   " left join area on area.area_code=salesmandt.Area_code ".
							   " where ledger_number='".$ledger_number."'";

					//echo $querydt;
					$resultdt = mysql_query($querydt, $connection);
					while($rowsdt=mysql_fetch_array($resultdt)){
									
						$ct+=1;

						if($ct%2==0)
							$Color="style='background-color:".$grid_color1."'";
						else			
							$Color="style='background-color:".$grid_color2."'";	
											
									
						echo "<tr ".$Color." >";
						echo "	<td align='center' valign='center'><span class='style15'><img src='img/button_edit.png'  onMouseOver=\"style.cursor='hand'\" onclick=UpdateDetailArea('".$rowsdt[0]."') title='Edit Record'  ></span></td>";
						echo "	<td align='center' valign='center'><span class='style15'><img src='img/c_delete.png'  onMouseOver=\"style.cursor='hand'\" onclick=DeleteDetailArea('".$rowsdt[0]."') title='Delete Record'  ></span></td>";
						echo "	<td align='left'><span class='style15'>".$rowsdt[1].'   &nbsp;  '.$rowsdt[3]."</span></td>";
						
						echo "</tr>";
											
					}					

					echo"</table></td></tr>";
					echo"</table>";
							  
					$tabs->end();  
				}

				if($Module_AdvancedProduction==1){

				$tabs->start("Receipt Books");

				echo"<table border='0'  align='left' valign='top'>";

				echo"<tr ><td colspan=6><table  border='0'>
										<tr bgcolor='#D0D0D0' height='25px'><td colspan=2>&nbsp;&nbsp;</td>
										<td align='center'><span class='style27'>Start Date<span class='style26'>*</span></span></td>
										<td align='center'><span class='style27'>End Date</span></td>
										<td align='center'><span class='style27'>From Reference</span></td>
										<td align='center'><span class='style27'>To Reference</span></td>
										<td align='center'><span class='style27'>Serial No</span></td>
									
				</tr>";

				echo"<tr><td align=center colspan=2>";

				 echo"<button type='button' id='btnPost' name='btnPost' onclick='SubmitRecord(6); return false;' title='Save Changes' $Insmode><span><span>$submit_button</span></span></button>";
				 echo"<button type='button' id='clearbutton' name='clearbutton' onclick='cleardetailreceipt(); return false;' title='Clear Detail'><span><span>$clear</span></span></button>";

				echo"&nbsp;&nbsp;</td>
					<td>&nbsp;<input type='text' name='start_daterec' value='$start_daterec' readonly style='width:100px;'>";
					
print<<<HERE
				&nbsp;&nbsp;<A HREF="#" onClick="displayCalendar(document.salesman.start_daterec,'dd-mm-yyyy',this); return false;" NAME="anchor1" ID="anchor1"><image src='./img/cal.gif' border=0 align=center></image></A>
HERE;

				echo"</td>
					<td>&nbsp;<input type='text' name='end_daterec' value='$end_daterec'  readonly style='width:100px;'>";
print<<<HERE
				&nbsp;&nbsp;<A HREF="#" onClick="displayCalendar(document.salesman.end_daterec,'dd-mm-yyyy',this); return false;" NAME="anchor1" ID="anchor1"><image src='./img/cal.gif' border=0 align=center></image></A>
HERE;
										
				echo"</td>
					<td>&nbsp;<input type='text' name='from_reference' value='$from_reference' $status  style='width:150px;text-align:right;'>&nbsp;</td>
					<td>&nbsp;<input type='text' name='to_reference' value='$to_reference' $status  style='width:150px;text-align:right;'>&nbsp;</td>
					<td>&nbsp;<input type='text' name='receipt_serialno' value='$receipt_serialno' $status maxlength='15' style='width:120px;text-align:right;'>&nbsp;</td>
				</tr>";

					$querydt = " select ReceiptBook_ID,date_Format(ReceiptBook_FromDate,'%d/%m/%Y'),date_Format(ReceiptBook_ToDate,'%d/%m/%Y'),ReceiptBook_FromSequence,ReceiptBook_ToSequence,ReceiptBook_SerialNo ".
						   " from receiptbooks ".
						   " where Ledger_Number='".$ledger_number."'";

					//echo $querydt;
					$resultdt = mysql_query($querydt, $connection);
					while($rowsdt=mysql_fetch_array($resultdt)){
									
						$ct+=1;

						if($ct%2==0)
							$Color="style='background-color:".$grid_color1."'";
						else			
							$Color="style='background-color:".$grid_color2."'";	
											
									
						echo "<tr ".$Color." >";
						echo "	<td align='center' valign='center'><span class='style15'><img src='img/button_edit.png'  onMouseOver=\"style.cursor='hand'\" onclick=UpdateDetailRec('".$rowsdt[0]."') title='Edit Record'  ></span></td>";
						echo "	<td align='center' valign='center'><span class='style15'><img src='img/c_delete.png'  onMouseOver=\"style.cursor='hand'\" onclick=DeleteDetailRec('".$rowsdt[0]."') title='Delete Record'  ></span></td>";
						echo "	<td align='center'><span class='style15'>".$rowsdt[1]."</span></td>";
						echo "	<td align='center'><span class='style15'>".$rowsdt[2]."</span></td>";
						echo "	<td align='right'><span class='style15'>".$rowsdt[3]."</span></td>";
						echo "	<td align='right'><span class='style15'>".$rowsdt[4]."</span></td>";
						echo "	<td align='right'><span class='style15'>".$rowsdt[5]."</span></td>";
						echo "	<td align='right'><span class='style15'>".$rowsdt[6]."</span></td>";
						echo "</tr>";
					}					
					echo"</table></td></tr>";
					echo"</table>";
					$tabs->end(); 
				}


				if($Module_CommissionByGroup==1){
					$tabs->start("Groups");

					echo"<table border='0'  align='left' valign='top'>";
					echo"<tr ><td colspan=6><table  border='0'>
											<tr bgcolor='#D0D0D0' height='25px'><td colspan=2>&nbsp;&nbsp;</td>
											<td align='center'><span class='style27'>Group $code_label/$name_label<span class='style26'>*</span></span></td>
											
					</tr>";

					echo"<tr><td align=center colspan=2><input type='button'  name='submitrecord' value='Submit'";

					 echo " onclick='SubmitRecord(7)'  title='Submit Record' $style>";
					   
					echo " <input type='button'  name='clearbutton' value='Clear'";
					if($mainmode=='' or $mainmode=='view')
								echo "disabled ";
					echo " onclick='cleardetailgroup();'  title='Clear Detail'  $style>";
					echo"&nbsp;&nbsp;</td>
					<td align=left><input type=text name='group_codedt' value='$group_codedt' maxlength='10'  readonly size='10' style='font-size:12px; width:100px; '>&nbsp;";
							
					echo"<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Agent '  width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistgroup(3); return false' /></span></label>";
							
					echo"&nbsp;<input type=text name='group_namedt' value='$group_namedt'   readonly size='10' style='font-size:12px; width:200px; '></td>";
					echo"
					</tr>";

					$querydt = " select SalesmenGroup_id,salesmengroup.group_code,group_name ".
							   " from salesmengroup  ".
							   " left join grouping on grouping.group_code=salesmengroup.group_code ".
							   " where salesman_code='".$ledger_number."'";

					//echo $querydt;
					$resultdt = mysql_query($querydt, $connection);
					while($rowsdt=mysql_fetch_array($resultdt)){
									
						$ct+=1;

						if($ct%2==0)
							$Color="style='background-color:".$grid_color1."'";
						else			
							$Color="style='background-color:".$grid_color2."'";	
											
									
						echo "<tr ".$Color." >";
						echo "	<td align='center' valign='center'><span class='style15'><img src='img/button_edit.png'  onMouseOver=\"style.cursor='hand'\" onclick=UpdateDetailGroup('".$rowsdt[0]."') title='Edit Record'  ></span></td>";
						echo "	<td align='center' valign='center'><span class='style15'><img src='img/c_delete.png'  onMouseOver=\"style.cursor='hand'\" onclick=DeleteDetailGroup('".$rowsdt[0]."') title='Delete Record'  ></span></td>";
						echo "	<td align='left'><span class='style15'>".$rowsdt[1].'   &nbsp;  '.$rowsdt[2]."</span></td>";
						
						echo "</tr>";
											
					}					

					echo"</table></td></tr>";
					echo"</table>";
							  
					$tabs->end();  
				}

				$tabs->run();
				/*	
				echo"<table border=0 align=center width=100%> <tr bgcolor=#D8D8D8 height='35'>";
				echo"<td align=center><input type='button'  value='Add Salesman'";  	
							
				if($mainmode=='insert' or $mainmode=='edit' or $mainmode=='view')
						echo "disabled ";
						echo"onclick='AddSalesman()' $style title='Add Salesman' '".$AddMode."'>&nbsp;";
								
				echo"<input type='button' id='btnClear' name='BtnClear' value='Clear Page'   onclick='ClearPage();' $style title='Clear Page'>";

								
								
				if($mainmode=='view'){
					echo"           <input type='button' name='btnEdit' id='btnEdit' value='Edit' ";//Edit
					echo" onclick='editmode();' $style	title='Edit Salesman' />";
				}
				else	{
				echo"           <input type='button' name='btnPost' id='btnPost' value='Save' ";//post
								if ($mainmode=='')
										echo " disabled ";
								
								echo" onclick='SubmitRecord();' $style	title='Save Changes' />";}

				//echo"           <input name='btnSearch' type='button' id='btnSearch' value='Search' onclick='SearchForSalesman();' $style title='Search Salesman' ";
					 //           if ($mainmode=='edit' or $mainmode=='insert') 
					//			    echo " disabled ";
						//        echo " />
								
								
						echo"		<input  type='button'  value='Print' onclick='PrintPreview();' $style title='Print' ";
				if ($mainmode!='') 
					echo " disabled ";
								echo " />
				</td>";
				echo"  </tr></table>";*/
						  
print <<< HERE
					   </td>
					  </tr>
					  <tr height='30'><td align='center' id='content-bottom' ></td></tr>
					  </table>
HERE;

				if($vTabFocus!=''){
					echo'<script type="text/javascript" language="javascript">';
					echo"tab_('$vTabFocus','');";
					echo'</script>';	
				}	

				//// Checking if code already exists or not
				if($checkcode=='1'){
					$ledger_numberPrv=trim($ledger_numberPrv);
					$ledger_number=trim($ledger_number);

					if($mainmode=='insert' || ($mainmode=='edit' && $ledger_number!=$ledger_numberPrv)){
						$query_client="select count(*) from salesmen where ledger_number=".$ledger_number;
						//echo$query_client;exit;
						$result=mysql_query($query_client, $connection);
						$row_code=mysql_fetch_row($result);
						$num=$row_code[0];
					
					}
					else $num=0;
					
					

					if($num>0){
						$message="Code Already exists";
						
						echo"<script type='text/javascript'>";
						echo"	document.salesman.message.value='Code Already Exists';";
						echo"	document.salesman.checkcode.value='0';";
						echo"	document.salesman.submit();";	
						echo"</script>";
							
					}

					else{
						echo"<script type='text/javascript'>";
						echo"	document.salesman.action='Form_Salesmen_Actions.php';";
						echo"	document.salesman.submit();";
						echo"</script>";
					}
				}




print <<<HERE
				</form>
				</body>

HERE;

?>

