<?php

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

include("config.inc.php");
include("supplier_function.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");
 


$vatstatus     		= $_POST["vatstatus"]; 			if ($vatstatus == ""){			$vatstatus 			= $_GET["vatstatus"];}  
$editactivation     = $_POST["editactivation"]; 	if ($editactivation == ""){		$editactivation 	= $_GET["editactivation"];}  
$module     		= $_POST["module"]; 			if ($module == ""){				$module 			= $_GET["module"];}  
$pcurrencycode     	= $_POST["pcurrencycode"]; 		if ($pcurrencycode == ""){		$pcurrencycode 		= $_GET["pcurrencycode"];}  
$sellingpriceb1     = $_POST["sellingpriceb1"]; 	if ($sellingpriceb1 == ""){		$sellingpriceb1 	= $_GET["sellingpriceb1"];}  
$sellingpriceb2     = $_POST["sellingpriceb2"]; 	if ($sellingpriceb2 == ""){		$sellingpriceb2 	= $_GET["sellingpriceb2"];}  
$sellingprice_id    = $_POST["sellingprice_id"]; 	if ($sellingprice_id == ""){	$sellingprice_id 	= $_GET["sellingprice_id"];}  
$start_date     	= $_POST["start_date"]; 		if ($start_date ==""){			$start_date 		= $_GET["start_date"];}  


if(	$_SESSION['encodingmode'] == 'utf8' || $_SESSION['encodingmode'] == 'utf-8'){
	mysql_query("SET NAMES 'utf8'"); 
	mysql_query('SET CHARACTER SET utf8'); 
	mysql_set_charset('utf8', $connection);
}
$querylog="SELECT Clients 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, creation_date as creationdate, deactivate_date, client_group as groupclient, 
			code as code_label, name as name_label,  
			namearabic, description, salesman, projet as projet_label, costcenter, checkacc, currency, customer_type,
			legal_type, discount as discount_label, credit_limit as creditlimit, vat_date as vatdate, selling_price as sellingprice, payement_type, type1, terms, term2,
			cl_mode, tc, frof_cisits, commission, discount_inv, financialno, profit_Center, budgetlimit, 
			checkdueterm, crlimit, export, sentmail, vat as vat_label, wht, showm, matdate, cl_local, cashmode, vatno, 
			whtper, country as country_label, state as state_label, home_page, phone1 as phone1_label, phone2 as phone2_label, phone3 as phone3_label, area, bos, fax as fax_label, technicalper as technicalperson,
			
			technical_email as technicalemail, address as address_label, address2 as address2_label, address3 as address3_label, Title as title_label, First_Name as firstname_label, Father_Name as father_name_label, Last_Name last_name_label, 
			tel1 as telephoneNo_label, tel2 as telephoneNo2_label, tel3 as telephoneNo3_label, reference as reference_label
			, city1 as city1_label, city2 as city2_label, city3 as city3_label, seeling_group, category, sugroup as subgroup_label, items as items_label,
			agent, mother_company, bussiness_type, owner, referredby, sd1no, assistant, work_title, 
			warehouse as warehouse_label, home, gcnumber, archivefile, invoicelanguage, delivery, majorstrenght, weakness as weakness_label,
			tips, remark, invoice_rounded, product, ratio, start_date as startdate, end_date as enddate, business_sector, business_type1, 
			business_type2, business_type3, tobcode, multiple_sales, clientip_startdate, clientip_enddate, 
			lasttransdate, periodbymonth, installmonth, techinicianname, subscriber_name as subsname_label, clientip, clienttc,
			clientip_category, client_ipservice, clientip_currency, uploadip, downloadip, macip, portip, 
			modemip, projectip, costcenterip, reasonip, collection_name as collection_label, subscriber_address as subscriber_address_label, tab1, tab2,
			tab3, tab4, tab5,
			tab6, tab7, tab8, tab9, tab10, tab11,pobox as pobox_label , amount_label,city as city_label,email as email_label from ".$_SESSION['dbLabel'].".clients_label where 
			language='$language'";
			
			
		//	echo $querylang;exit;

//echo $querylang;
$resultlang=mysql_query($querylang,$connection) or die(mysql_error());
	while($rows=mysql_fetch_array($resultlang)){
		extract($rows);
		
	}

$querylang="select language, buttonclear, save, print, find, clear, results, page,
Add_button,check_button,remainchar,excel
 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];
		$Remaining=$rows[10];
		$excel=$rows[11];
		
	}

	

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

	//maroun
$querysalesmen=" select distinct clientsalesmen 
			from ".$_SESSION['dbLabel'].".loginstk ".
			  " where user_account='".$_SESSION['useraccount']."' 
			  and clientsalesmen<>'' 
			  or clientsalesmen <> null
			  "  ;
//echo $querysalesmen;			  
$salesmenresult = mysql_query($querysalesmen,$connection) or die(mysql_error());
$salesmenexist   = mysql_num_rows($salesmenresult);

	//maroun
$querymasterproject=" select distinct Masterproject from ".$_SESSION['dbLabel'].".loginstk ".
					" where loginstk.user_account='".$_SESSION['useraccount']."' ".
					" and (Masterproject is not null and Masterproject != '') ";
														 
$projectmasterresult = mysql_query($querymasterproject,$connection) or die(mysql_error());
$projectmasterexist   = mysql_num_rows($projectmasterresult);

//maroun
$querymastercostcenter=" select distinct Mastercostcenter from ".$_SESSION['dbLabel'].".loginstk ".
					   " where loginstk.user_account='".$_SESSION['useraccount']."' ".
					   " and (Mastercostcenter is not null and Mastercostcenter != '') ";


$costcentermasterresult = mysql_query($querymastercostcenter,$connection) or die(mysql_error());
$costcentermasterexist   = mysql_num_rows($costcentermasterresult);


$querysetup="select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, grid_color1, grid_color2 ,Setup_Tax1Active ,Setup_Tax2Active,Setup_Tax3Active,Setup_Tax4Active,Setup_Tax5Active,ClientFirstDigit,NbrOfDigitInLedger,maxperpage,Client_DefaultCur 
,client_creditlimit ,client_paymentterms
from setup";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
extract($rowsetup);
}


//User Access
$querylog=" select ifNull(ClientsApp,0) As ClientsApp, ifNull(ClientsMod,0) As ClientsMod, ifnull(FA_ClientCreditLimit,0) As FA_ClientCreditLimit,".
          " ifNull(ClientsDel,0) As ClientsDel, ifnull(FL_Logistic,0) as FL_Logistic 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($ClientsApp==0)
$AddMode = ' readonly ';

$saveEnabled = 0;
if ( ($ClientsMod == 1 && $mainmode=='editmode') || ($ClientsApp == 1))
	$saveEnabled = 1;

	$query_ledgergrp="select module_ledgergrp,module_project,module_costcenter, ifnull(module_sellingbyclient,0) as module_sellingbyclient, ifnull(module_saleswht,0) as module_saleswht,ifnull(module_clientContract,0) as module_clientContract
					from module";
	$resultledgergrp=mysql_query($query_ledgergrp,$connection) or die(mysql_error());
	$row_ledger=mysql_fetch_row($resultledgergrp);
	$module_ledgergrp=$row_ledger[0];
	$module_project=$row_ledger[1];
	$module_costcenter=$row_ledger[2];
	$module_sellingbyclient=$row_ledger[3];
	$module_saleswht = $row_ledger[4];
	$module_clientContract=$row_ledger[5];
	
$HideMenu   = $_POST["HideMenu"]; if ($HideMenu == ""){$HideMenu = $_GET["HideMenu"];}   
$actionmode = $_POST["actionmode"]; if ($actionmode == ""){$actionmode = $_GET["actionmode"];}   
$mainmode   = $_POST["mainmode"]; if ($mainmode == ""){$mainmode = $_GET["mainmode"];}   
$maintab    = $_POST["maintab"]; if ($maintab == ""){$maintab = $_GET["maintab"];} 
$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"];} 

$clientact_id 		= $_POST["clientact_id"]; if ($clientact_id == ""){$clientact_id = $_GET["clientact_id"];} 
$edittelephone    	= $_POST["edittelephone"]; if ($edittelephone == ""){$edittelephone = $_GET["edittelephone"];} 
$editcompetitor 	= $_POST["editcompetitor"]; if ($editcompetitor == ""){$editcompetitor = $_GET["editcompetitor"];} 
$telephone_increment = $_POST["telephone_increment"]; if ($telephone_increment == ""){$telephone_increment = $_GET["telephone_increment"];} 
$competitor_id 	   	= $_POST["competitor_id"]; if ($competitor_id == ""){$competitor_id = $_GET["competitor_id"];} 
$checkcode    		= $_POST["checkcode"]; if ($checkcode == ""){$checkcode = $_GET["checkcode"];} 
$fromledger 	   	= $_POST["fromledger"]; if ($fromledger == ""){$fromledger = $_GET["fromledger"];} 
$fill_ledger 		= $_POST["fill_ledger"]; if ($fill_ledger == ""){$fill_ledger = $_GET["fill_ledger"];} 
$title_name 	   	= $_POST["title_name"]; if ($title_name == ""){$title_name = $_GET["title_name"];} 
$title_owner		= $_POST["title_owner"]; if ($title_owner == ""){$title_owner = $_GET["title_owner"];} 
$title_refered 	   	= $_POST["title_refered"]; if ($title_refered == ""){$title_refered = $_GET["title_refered"];} 
$title_assistant   	= $_POST["title_assistant"]; if ($title_assistant == ""){$title_assistant = $_GET["title_assistant"];} 
$addresstab 	   	= $_POST["addresstab"]; if ($addresstab == ""){$addresstab = $_GET["addresstab"];} 
$check_ledgergrp   	= $_POST["check_ledgergrp"]; if ($check_ledgergrp == ""){$check_ledgergrp = $_GET["check_ledgergrp"];} 
$ledger_numberPrv  	= $_POST["ledger_numberPrv"]; if ($ledger_numberPrv == ""){$ledger_numberPrv = $_GET["ledger_numberPrv"];} 
$Clientip_id 	   	= $_POST["Clientip_id"]; if ($Clientip_id == ""){$Clientip_id = $_GET["Clientip_id"];} 


$creation_date 		= $_POST["creation_date"]; if ($creation_date == ""){$creation_date = $_GET["creation_date"];} 
$deactivateclient 	= $_POST["deactivateclient"]; if ($deactivateclient == ""){$deactivateclient = $_GET["deactivateclient"];} 
$deactivatedate 	= $_POST["deactivatedate"]; if ($deactivatedate == ""){$deactivatedate = $_GET["deactivatedate"];} 
$client_tc 			= $_POST["client_tc"]; if ($client_tc == ""){$client_tc = $_GET["client_tc"];} 
$client_groupcode	= $_POST["client_groupcode"]; if ($client_groupcode == ""){$client_groupcode = $_GET["client_groupcode"];} 
$client_groupname	= $_POST["client_groupname"]; if ($client_groupname == ""){$client_groupname = $_GET["client_groupname"];} 
$client_tax0 		= $_POST["client_tax0"]; if ($client_tax0 == ""){$client_tax0 = $_GET["client_tax0"];} 
$client_tax1 		= $_POST["client_tax1"]; if ($client_tax1 == ""){$client_tax1 = $_GET["client_tax1"];} 
$client_tax2 		= $_POST["client_tax2"]; if ($client_tax2 == ""){$client_tax2 = $_GET["client_tax2"];} 
$client_tax3 		= $_POST["client_tax3"]; if ($client_tax3 == ""){$client_tax3 = $_GET["client_tax3"];} 
$client_tax4 		= $_POST["client_tax4"]; if ($client_tax4 == ""){$client_tax4 = $_GET["client_tax4"];} 
$client_tax5 		= $_POST["client_tax5"]; if ($client_tax5 == ""){$client_tax5 = $_GET["client_tax5"];} 
$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_namef		= $_POST["ledger_namef"]; if ($ledger_namef == ""){$ledger_namef = $_GET["ledger_namef"];} 
$ledger_description = $_POST["ledger_description"]; if ($ledger_description == ""){$ledger_description = $_GET["ledger_description"];} 
$salesman_code 		= $_POST["salesman_code"]; if ($salesman_code == ""){$salesman_code = $_GET["salesman_code"];} 
$salesman_name 		= $_POST["salesman_name"]; if ($salesman_name == ""){$salesman_name = $_GET["salesman_name"];} 
$client_export 		= $_POST["client_export"]; if ($client_export == ""){$client_export = $_GET["client_export"];} 
$client_local 		= $_POST["client_local"]; if ($client_local == ""){$client_local = $_GET["client_local"];} 
$client_frequencyofvisit = $_POST["client_frequencyofvisit"]; if ($client_frequencyofvisit == ""){$client_frequencyofvisit = $_GET["client_frequencyofvisit"];} 
$salesman_com 		= $_POST["salesman_com"]; if ($salesman_com == ""){$salesman_com = $_GET["salesman_com"];} 
$sent_email 		= $_POST["sent_email"]; if ($sent_email == ""){$sent_email = $_GET["sent_email"];} 
$client_cashmode 	= $_POST["client_cashmode"]; if ($client_cashmode == ""){$client_cashmode = $_GET["client_cashmode"];} 
$selling_price 		= $_POST["selling_price"]; if ($selling_price == ""){$selling_price = $_GET["selling_price"];} 
$client_sellingprice= $_POST["client_sellingprice"]; if ($client_sellingprice == ""){$client_sellingprice = $_GET["client_sellingprice"];} 
$discount 			= $_POST["discount"]; if ($discount == ""){$discount = $_GET["discount"];} 
$credit_control 	= $_POST["credit_control"]; if ($credit_control == ""){$credit_control = $_GET["credit_control"];} 
$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"];} 
$budget_limit 		= $_POST["budget_limit"]; if ($budget_limit == ""){$budget_limit = $_GET["budget_limit"];} 
$client_group 		= $_POST["client_group"]; if ($client_group == ""){$client_group = $_GET["client_group"];} 
$client_rating 		= $_POST["client_rating"]; if ($client_rating == ""){$client_rating = $_GET["client_rating"];} 
$client_vat 		= $_POST["client_vat"]; if ($client_vat == ""){$client_vat = $_GET["client_vat"];} 
$client_vatno 		= $_POST["client_vatno"]; if ($client_vatno == ""){$client_vatno = $_GET["client_vatno"];} 
$vat_date 			= $_POST["vat_date"]; if ($vat_date == ""){$vat_date = $_GET["vat_date"];} 
$legaltype 			= $_POST["legaltype"]; if ($legaltype == ""){$legaltype = $_GET["legaltype"];} 
$client_legaltype	= $_POST["client_legaltype"]; if ($client_legaltype == ""){$client_legaltype = $_GET["client_legaltype"];} 
$client_checkaccount= $_POST["client_checkaccount"]; if ($client_checkaccount == ""){$client_checkaccount = $_GET["client_checkaccount"];} 
$client_chterms 	= $_POST["client_chterms"]; if ($client_chterms == ""){$client_chterms = $_GET["client_chterms"];} 
$project_code 		= $_POST["project_code"]; if ($project_code == ""){$project_code = $_GET["project_code"];} 
$project_name 		= $_POST["project_name"]; if ($project_name == ""){$project_name = $_GET["project_name"];} 
$paymenttype		= $_POST["paymenttype"]; if ($paymenttype == ""){$paymenttype = $_GET["paymenttype"];} 
$client_paytermtype	= $_POST["client_paytermtype"]; if ($client_paytermtype == ""){$client_paytermtype = $_GET["client_paytermtype"];} 
$client_paymentterm = $_POST["client_paymentterm"]; if ($client_paymentterm == ""){$client_paymentterm = $_GET["client_paymentterm"];} 
$client_paymentterm2 = $_POST["client_paymentterm2"]; if ($client_paymentterm2 == ""){$client_paymentterm2 = $_GET["client_paymentterm2"];} 
$client_paymentmode = $_POST["client_paymentmode"]; if ($client_paymentmode == ""){$client_paymentmode = $_GET["client_paymentmode"];} 
$costcenter_code 	= $_POST["costcenter_code"]; if ($costcenter_code == ""){$costcenter_code = $_GET["costcenter_code"];} 
$costcenter_name	= $_POST["costcenter_name"]; if ($costcenter_name == ""){$costcenter_name = $_GET["costcenter_name"];} 
$profit_code		= $_POST["profit_code"]; if ($profit_code == ""){$profit_code = $_GET["profit_code"];} 
$client_financialno	= $_POST["client_financialno"]; if ($client_financialno == ""){$client_financialno = $_GET["client_financialno"];} 
$client_discountonInvoice	= $_POST["client_discountonInvoice"]; if ($client_discountonInvoice == ""){$client_discountonInvoice = $_GET["client_discountonInvoice"];} 
$client_wht 		= $_POST["client_wht"]; if ($client_wht == ""){$client_wht = $_GET["client_wht"];} 

$country 	 = $_POST["country"]; if ($country == ""){$country = $_GET["country"];} 
$state 		 = $_POST["state"]; if ($state == ""){$state = $_GET["state"];} 
$city_client = $_POST["city_client"]; if ($city_client == ""){$city_client = $_GET["city_client"];} 
$area_code	 = $_POST["area_code"]; if ($area_code == ""){$area_code = $_GET["area_code"];} 
$areaname 	 = $_POST["areaname"]; if ($areaname == ""){$areaname = $_GET["areaname"];} 
$Address 	 = $_POST["Address"]; if ($Address == ""){$Address = $_GET["Address"];} 
$Address2  	 = $_POST["Address2"]; if ($Address2 == ""){$Address2 = $_GET["Address2"];} 
$Address3 	 = $_POST["Address3"]; if ($Address3 == ""){$Address3 = $_GET["Address3"];} 
$email 		 = $_POST["email"]; if ($email == ""){$email = $_GET["email"];} 
$homepage 	 = $_POST["homepage"]; if ($homepage == ""){$homepage = $_GET["homepage"];} 
$phone1	  	 = $_POST["phone1"]; if ($phone1 == ""){$phone1 = $_GET["phone1"];} 
$phone2 	 = $_POST["phone2"]; if ($phone2 == ""){$phone2 = $_GET["phone2"];} 
$phone3 	 = $_POST["phone3"]; if ($phone3 == ""){$phone3 = $_GET["phone3"];} 
$pobox 		 = $_POST["pobox"]; if ($pobox == ""){$pobox = $_GET["pobox"];} 
$fax 		 = $_POST["fax"]; if ($fax == ""){$fax = $_GET["fax"];} 
$technical_person 	= $_POST["technical_person"]; if ($technical_person == ""){$technical_person = $_GET["technical_person"];} 
$technical_email 	= $_POST["technical_email"]; if ($technical_email == ""){$technical_email = $_GET["technical_email"];} 

$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"];} 


$agent_code 	= $_POST["agent_code"]; if ($agent_code == ""){$agent_code = $_GET["agent_code"];} 
$agent_name 	= $_POST["agent_name"]; if ($agent_name == ""){$agent_name = $_GET["agent_name"];} 
$client_mothercompany 		 = $_POST["client_mothercompany"]; if ($client_mothercompany == ""){$client_mothercompany = $_GET["client_mothercompany"];} 
$client_companyname 		 = $_POST["client_companyname"]; if ($client_companyname == ""){$client_companyname = $_GET["client_companyname"];} 
$bussiness_type 			 = $_POST["bussiness_type"]; if ($bussiness_type == ""){$bussiness_type = $_GET["bussiness_type"];} 
$titleowner_description		 = $_POST["titleowner_description"]; if ($titleowner_description == ""){$titleowner_description = $_GET["titleowner_description"];} 
$client_companyowner 		 = $_POST["client_companyowner"]; if ($client_companyowner == ""){$client_companyowner = $_GET["client_companyowner"];} 
$titlerefered_description	 = $_POST["titlerefered_description"]; if ($titlerefered_description == ""){$titlerefered_description = $_GET["titlerefered_description"];} 
$client_referedby  			 = $_POST["client_referedby"]; if ($client_referedby == ""){$client_referedby = $_GET["client_referedby"];} 


$client_sdino = $_POST["client_sdino"]; if ($client_sdino == ""){$client_sdino = $_GET["client_sdino"];} 
$titleassistant_description	 = $_POST["titleassistant_description"]; if ($titleassistant_description == ""){$titleassistant_description = $_GET["titleassistant_description"];} 
$client_deliveryassistant	 = $_POST["client_deliveryassistant"]; if ($client_deliveryassistant == ""){$client_deliveryassistant = $_GET["client_deliveryassistant"];} 
$client_dlvworktitle 		 = $_POST["client_dlvworktitle"]; if ($client_dlvworktitle == ""){$client_dlvworktitle = $_GET["client_dlvworktitle"];} 
$delivery_phone 		 	 = $_POST["delivery_phone"]; if ($delivery_phone == ""){$delivery_phone = $_GET["delivery_phone"];} 
$delivery_areacode			 = $_POST["delivery_areacode"]; if ($delivery_areacode == ""){$delivery_areacode = $_GET["delivery_areacode"];} 
$delivery_areaname 			 = $_POST["delivery_areaname"]; if ($delivery_areaname == ""){$delivery_areaname = $_GET["delivery_areaname"];} 
$warehouse 					 = $_POST["warehouse"]; if ($warehouse == ""){$warehouse = $_GET["warehouse"];} 
$client_deliveryaddress 	 = $_POST["client_deliveryaddress"]; if ($client_deliveryaddress == ""){$client_deliveryaddress = $_GET["client_deliveryaddress"];} 
$client_deliveryaddress2 	 = $_POST["client_deliveryaddress2"]; if ($client_deliveryaddress2 == ""){$client_deliveryaddress2 = $_GET["client_deliveryaddress2"];} 
$client_deliveryaddress3 	 = $_POST["client_deliveryaddress3"]; if ($client_deliveryaddress3 == ""){$client_deliveryaddress3 = $_GET["client_deliveryaddress3"];} 

$client_gcino 	 	= $_POST["client_gcino"]; if ($client_gcino == ""){$client_gcino = $_GET["client_gcino"];} 
$client_archivefileno 		= $_POST["client_archivefileno"]; if ($client_archivefileno == ""){$client_archivefileno = $_GET["client_archivefileno"];} 
$client_evaluationpoints 	= $_POST["client_evaluationpoints"]; if ($client_evaluationpoints == ""){$client_evaluationpoints = $_GET["client_evaluationpoints"];} 
$client_weakness 	= $_POST["client_weakness"]; if ($client_weakness == ""){$client_weakness = $_GET["client_weakness"];} 
$client_tips 	 	= $_POST["client_tips"]; if ($client_tips == ""){$client_tips = $_GET["client_tips"];} 
$client_remark 	 	= $_POST["client_remark"]; if ($client_remark == ""){$client_remark = $_GET["client_remark"];} 
$client_invrounded  = $_POST["client_invrounded"]; if ($client_invrounded == ""){$client_invrounded = $_GET["client_invrounded"];} 
$invoice_language 	= $_POST["invoice_language"]; if ($invoice_language == ""){$invoice_language = $_GET["invoice_language"];} 
$delivsof 	 		= $_POST["delivsof"]; if ($delivsof == ""){$delivsof = $_GET["delivsof"];} 

$competitor_name 	 = $_POST["competitor_name"]; if ($competitor_name == ""){$competitor_name = $_GET["competitor_name"];} 
$competitor_product  = $_POST["competitor_product"]; if ($competitor_product == ""){$competitor_product = $_GET["competitor_product"];} 
$competitor_ratio 	 = $_POST["competitor_ratio"]; if ($competitor_ratio == ""){$competitor_ratio = $_GET["competitor_ratio"];} 
$competitor_salesman = $_POST["competitor_salesman"]; if ($competitor_salesman == ""){$competitor_salesman = $_GET["competitor_salesman"];} 

$clientact_startdate = $_POST["clientact_startdate"]; if ($clientact_startdate == ""){$clientact_startdate = $_GET["clientact_startdate"];} 
$clientact_enddate 	 = $_POST["clientact_enddate"]; if ($clientact_enddate == ""){$clientact_enddate = $_GET["clientact_enddate"];} 
$clientact_remark 	 = $_POST["clientact_remark"]; if ($clientact_remark == ""){$clientact_remark = $_GET["clientact_remark"];} 

$client_businesssector		 = $_POST["client_businesssector"]; if ($client_businesssector == ""){$client_businesssector = $_GET["client_businesssector"];} 
$client_businesssectordesc 	 = $_POST["client_businesssectordesc"]; if ($client_businesssectordesc == ""){$client_businesssectordesc = $_GET["client_businesssectordesc"];} 
$client_tobcode 	  = $_POST["client_tobcode"]; if ($client_tobcode == ""){$client_tobcode = $_GET["client_tobcode"];} 
$client_multiplesales = $_POST["client_multiplesales"]; if ($client_multiplesales == ""){$client_multiplesales = $_GET["client_multiplesales"];} 
$client_btype2 	 	  = $_POST["client_btype2"]; if ($client_btype2 == ""){$client_btype2 = $_GET["client_btype2"];} 
$client_btype3 	 	  = $_POST["client_btype3"]; if ($client_btype3 == ""){$client_btype3 = $_GET["client_btype3"];} 
$Client_BusinessType  = $_POST["Client_BusinessType"]; if ($Client_BusinessType == ""){$Client_BusinessType = $_GET["Client_BusinessType"];} 

$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"];} 
$ClientIP_LastTransDate	 = $_POST["ClientIP_LastTransDate"]; if ($ClientIP_LastTransDate == ""){$ClientIP_LastTransDate = $_GET["ClientIP_LastTransDate"];} 
$ClientIP_PeriodByMonth	 = $_POST["ClientIP_PeriodByMonth"]; if ($ClientIP_PeriodByMonth == ""){$ClientIP_PeriodByMonth = $_GET["ClientIP_PeriodByMonth"];} 
$Client_Inst_Month 	= $_POST["Client_Inst_Month"]; if ($Client_Inst_Month == ""){$Client_Inst_Month = $_GET["Client_Inst_Month"];} 
$technician_name 	= $_POST["technician_name"]; if ($technician_name == ""){$technician_name = $_GET["technician_name"];} 
$subscriber_name 	= $_POST["subscriber_name"]; if ($subscriber_name == ""){$subscriber_name = $_GET["subscriber_name"];} 
$Clientip_IP 		= $_POST["Clientip_IP"]; if ($Clientip_IP == ""){$Clientip_IP = $_GET["Clientip_IP"];} 
$clientip_tc 	 	= $_POST["clientip_tc"]; if ($clientip_tc == ""){$clientip_tc = $_GET["clientip_tc"];} 
$category_name 	 	= $_POST["category_name"]; if ($category_name == ""){$category_name = $_GET["category_name"];} 
$service_name 	 	= $_POST["service_name"]; if ($service_name == ""){$service_name = $_GET["service_name"];} 
$clientiparea_code 	= $_POST["clientiparea_code"]; if ($clientiparea_code == ""){$clientiparea_code = $_GET["clientiparea_code"];} 
$clientip_amount 	= $_POST["clientip_amount"]; if ($clientip_amount == ""){$clientip_amount = $_GET["clientip_amount"];} 
$currencyip 	 	= $_POST["currencyip"]; if ($currencyip == ""){$currencyip = $_GET["currencyip"];} 
$upload_ip 	 		= $_POST["upload_ip"]; if ($upload_ip == ""){$upload_ip = $_GET["upload_ip"];} 
$download_ip 	 	= $_POST["download_ip"]; if ($download_ip == ""){$download_ip = $_GET["download_ip"];} 
$client_macaddress 	= $_POST["client_macaddress"]; if ($client_macaddress == ""){$client_macaddress = $_GET["client_macaddress"];} 
$client_port 	 	= $_POST["client_port"]; if ($client_port == ""){$client_port = $_GET["client_port"];} 
$client_modemip 	= $_POST["client_modemip"]; if ($client_modemip == ""){$client_modemip = $_GET["client_modemip"];} 
$clientipproject_code 	 = $_POST["clientipproject_code"]; if ($clientipproject_code == ""){$clientipproject_code = $_GET["clientipproject_code"];} 
$clientipcostcent_code	 = $_POST["clientipcostcent_code"]; if ($clientipcostcent_code == ""){$clientipcostcent_code = $_GET["clientipcostcent_code"];} 
$clientip_reason 	= $_POST["clientip_reason"]; if ($clientip_reason == ""){$clientip_reason = $_GET["clientip_reason"];} 
$collection_name 	= $_POST["collection_name"]; if ($collection_name == ""){$collection_name = $_GET["collection_name"];} 
$Subscriber_Address = $_POST["Subscriber_Address"]; if ($Subscriber_Address == ""){$Subscriber_Address = $_GET["Subscriber_Address"];} 
$client_showcreditlimit = $_POST["client_showcreditlimit"]; if ($client_showcreditlimit == ""){$client_showcreditlimit = $_GET["client_showcreditlimit"];} 
$client_showmaturitydate = $_POST["client_showmaturitydate"]; if ($client_showmaturitydate == ""){$client_showmaturitydate = $_GET["client_showmaturitydate"];} 
$subgroup_code = $_POST["subgroup_code"]; if (subgroup_code){$subgroup_code = $_GET["subgroup_code"];} 
$subgroup_name = $_POST["subgroup_name"]; if ($subgroup_name == ""){$subgroup_name = $_GET["subgroup_name"];} 
$itemcategory_name = $_POST["itemcategory_name"]; if (itemcategory_name){$itemcategory_name = $_GET["itemcategory_name"];} 
$item_description = $_POST["item_description"]; if ($item_description == ""){$item_description = $_GET["item_description"];} 
$item_code = $_POST["item_code"]; if ($item_code == ""){$item_code = $_GET["item_code"];} 
$itemcategory_code = $_POST["itemcategory_code"]; if ($itemcategory_code == ""){$itemcategory_code = $_GET["itemcategory_code"];} 
	
/// Gilbert  5- 11- 2011

if($vTabFocus == '') $vTabFocus="Main Page";
if($check_ledgergrp=='1'){

	///Making Client code Readonly
	//$statuscode='readonly';

	
	if($module_ledgergrp=='0'){
		if($ledger_number != ''){
			$query = "select max(ledger_number)+1 from clients where ledger_number like '$ledger_number%' ";
			$res = mysql_query($query,$connection);
			$rw = mysql_fetch_row($res);
			if($rw[0] != ''){
				$ledger_number=$rw[0];
				$ledger_numberPrv=$ledger_number;
			} else {
				$length_client=strlen($ledger_number);
				$left_length=$NbrOfDigitInLedger-$length_client;
				$client_increment=str_pad('0', $left_length, '0', STR_PAD_LEFT);
				$ledger_number=$ledger_number.$client_increment;
				$ledger_numberPrv=$ledger_number;
			}			
		} 
		else 
		{
			///Getting length of Client first digit + Total of length for ledger number should be
			$length_client_firstdigit=strlen($ClientFirstDigit);
			$left_length=$NbrOfDigitInLedger-$length_client_firstdigit;
			
			/// Client Increment
			$query_increment="select client_increment from sequence";
			$resultincrement=mysql_query($query_increment,$connection) or die(mysql_error());
			$row_increment=mysql_fetch_row($resultincrement);
			$client_increment=$row_increment[0];
			$client_increment=$client_increment+1;
			
			$client_increment=str_pad($client_increment, $left_length, '0', STR_PAD_LEFT);
			$ledger_number=$ClientFirstDigit.''.$client_increment;
			$ledger_numberPrv=$ledger_number;
		}
	}
	
	else if($module_ledgergrp=='1'){
			$message='Please Start By Choosing A Group';
			$check_ledgergrp='0';
	}
}


/// Gilbert  5- 11- 2011
	if($fill_ledger=='1'){
		
		$length_client_groupcode=strlen($client_groupcode);
		$left_length=$NbrOfDigitInLedger-$length_client_groupcode;
		
		$query_reference="select LedgerGrp_reference from ledgergrp where LedgerGrp_Code='".$client_groupcode."'";
		//echo$query_reference;
		$resultreference=mysql_query($query_reference,$connection) or die(mysql_error());
		$row_reference=mysql_fetch_row($resultreference);
		$ledgergrp_reference=$row_reference[0];
		$ledgergrp_reference=$ledgergrp_reference+1;
		$ledgergrp_reference=str_pad($ledgergrp_reference, $left_length, '0', STR_PAD_LEFT);
		$ledger_number=$client_groupcode.$ledgergrp_reference;
		$ledger_numberPrv=$ledger_number;
	}


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

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.clientdt[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";
		}}
}	


$query_module="select module_AdvancedProduction ,Module_AdditionalTaxes from module ";
$moduleresult=mysql_query($query_module, $connection);
$row=mysql_fetch_row($moduleresult);
$module=$row[0];
$ModuleAdditionalTax = $row[1];

$query10 = "select paymentmode_code, paymentmode_desc from payment_mode"; 
$resultclientpay= mysql_query($query10,$connection);

if($mainmode=='editmode' or $mainmode=='view'){
//if ($ledger_number != '' && $checkcode!=1) { 
	$query_edit="select date_format(Client_CreationDate,'%d-%m-%Y'),Client_deactivate,date_format(Client_DeactivateDate,'%d-%m-%Y'),Client_TC,ClientGrp_Code,Ledger_number,ledger_name,Ledger_Desc,Salesmen_Code,Client_FrequencyOfVisit,
			Salesmen_Commission,Client_Rating,Client_VAT,Client_VatNo,date_format(Client_VatDate,'%d-%m-%Y'),Client_SellingPrice,Client_DiscountPer,Client_CreditControl,Client_budgetlimit,
			Currency_Code,Client_CreditLimit,Client_Group,Project_Code,Client_PayTermType,Client_PaymentTerms,Client_paymentTerms2,Client_PaymentMode,CostCenter_code,Client_checkAccount,Client_ChkTerms,
			Client_CashMode,Client_sentEmail,Client_tax,Client_Tax1,Client_Tax2,Client_Tax3,Client_Tax4,Client_Tax5,client_export,client_local,Client_CompLegalType,Client_Country,Client_State,Client_City,
			Area_Code,Client_Address,Client_Address2,Client_Email,Client_Homepage,Client_Telephone1,Client_Telephone2,Client_Fax,Client_Pobox,Client_AgentAccount,Client_MotherCompany,Client_Work,Client_CompOwnerTitle,
			Client_ReferedByTitle,Client_ReferedBy,Client_SDINo,Client_DlvAssistantTitle,Client_DeliveryAssistant,Client_DlvWorkTitle,Client_DeliveryPhone,Client_DlvFax,
			Client_DlvAreaCode,Client_DeliveryAddress,Client_DeliveryAddress2,warehouse_code,Client_GCIno,Client_ArchiveFileNo,Client_EvaluationPoints,client_Weakness,
			Client_Tips,Client_InvRounded,Client_InvLanguage,
			Client_BusinessSector,Client_BusinessSectorDesc,Client_TOBcode,Client_MultipleSales,
			Client_BType2,Client_BType3,Client_BusinessType,Client_BelongsToGroup,Client_CompOwner,client_remark,
			Client_Address3,Client_DeliveryAddress3,client_technicalRepresentative,client_technicalemail,Client_INVDLV,ProfitCenter_CODE,ledger_namef, client_financialno
			,client_showcreditlimit,client_showmaturitydate,client_discountonInvoice, WHTchecked, WHTPercentage, ifNull(Client_EndofMonthPay, 0) as Client_EndofMonthPay, ifNull(Client_priceatcost, 0) as Client_priceatcost
		from clients
	where ledger_number='$ledger_number'";

//echo $query_edit;

$resultedit=mysql_query($query_edit,$connection) or die(mysql_error());
while($row=mysql_fetch_array($resultedit)){
	$creation_date=$row[0];
	$deactivateclient=$row[1];
	$deactivatedate=$row[2];
	$client_tc=$row[3];
	$client_groupcode=$row[4];
	$ledger_number=$row[5];
	$ledger_numberPrv=$row[5];
	$ledger_name=$row[6];
	$ledger_namef=$row[92];
	$ledger_description=$row[7];
	$salesman_code=$row[8];
	$client_frequencyofvisit=$row[9];
	$salesman_com=$row[10];
	$client_rating=$row[11];
	$client_vat=$row[12];
	$client_vatno=$row[13];
	$vat_date=$row[14];
	$client_sellingprice=$row[15];
	$discount=$row[16];
	$credit_control=$row[17];
	$budget_limit=$row[18];
	$currency_code=$row[19];
	$credit_limit=$row[20];
	$client_group=$row[21];
	$project_code=$row[22];
	$client_paytermtype=$row[23];
	$client_paymentterm=$row[24];
	$client_paymentterm2=$row[25];
	$client_paymentmode=$row[26];
	$costcenter_code=$row[27];
	$client_checkaccount=$row[28];
	$client_chterms=$row[29];
	$client_cashmode=$row[30];
	$sent_email=$row[31];
	$client_tax0=$row[32];
	$client_tax1=$row[33];
	$client_tax2=$row[34];
	$client_tax3=$row[35];
	$client_tax4=$row[36];
	$client_tax5=$row[37];
	$client_export=$row[38];
	$client_local=$row[39];
	$client_legaltype=$row[40];
	$country=$row[41];
	$state=$row[42];
	$city_client=$row[43];
	$area_code=$row[44];
	$Address=$row[45];
	$Address2=$row[46];
	$email=$row[47];
	$homepage=$row[48];
	$phone1=$row[49];
	$phone2=$row[50];
	$fax=$row[51];
	$pobox=$row[52];
	$agent_code=$row[53];
	$client_mothercompany=$row[54];
	$bussiness_type=$row[55];
	$title_owner=$row[56];
	$title_refered=$row[57];
	$client_referedby=$row[58];
	$client_sdino=$row[59];
	$title_assistant=$row[60];
	$client_deliveryassistant=$row[61];
	$client_dlvworktitle=$row[62];
	$delivery_phone=$row[63];
	$phone3=$row[64];
	$delivery_areacode=$row[65];
	$client_deliveryaddress=$row[66];
	$client_deliveryaddress2=$row[67];
	$warehouse=$row[68];
	$client_gcino=$row[69];
	$client_archivefileno=$row[70];
	$client_evaluationpoints=$row[71];
	$client_weakness=$row[72];
	$client_tips=$row[73];
	$client_invrounded=$row[74];
	$invoice_language=$row[75];
	$client_businesssector=$row[76];
	$client_businesssectordesc=$row[77];
	$client_tobcode=$row[78];
	$client_multiplesales=$row[79];
	$client_btype2=$row[80];
	$client_btype3=$row[81];
	$Client_BusinessType=$row[82];
	$client_companyowner=$row[84];
	$client_remark=$row[85];
	$Address3=$row[86];
	$client_deliveryaddress3=$row[87];
	$technical_person=$row[88];
	$technical_email=$row[89];
	$delivsof=$row[90];
	$profit_code=$row[91];
	$client_financialno=$row[93];
	$client_showcreditlimit=$row[94];
	$client_showmaturitydate=$row[95];
	$client_discountonInvoice=$row[96];
	$client_wht=$row[97];
	$whtpercentage=$row[98];
	$Client_EndofMonthPay = $row[99];
	$Client_priceatcost = $row[100];
	
}
	$query2="select Project_code,Project_name from project where project_code='$project_code'";
	$result=mysql_query($query2, $connection);
	$row=mysql_fetch_row($result);
	$project_name=$row[1];

	$query3="select costcent_code,costcent_name from costcent where costcent_code='$costcenter_code'";
	$result=mysql_query($query3, $connection);
	$row=mysql_fetch_row($result);
	$costcenter_name=$row[1];

	$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 group_code,group_name from grouping where group_code='$client_groupcode'";
	$result=mysql_query($query5, $connection);
	$row=mysql_fetch_row($result);
	$client_groupname=$row[1];

	$query6="select Ledger_number,Ledger_name, salesman_commission ".
			" from salesmen where ledger_number='$salesman_code'";		
	$result=mysql_query($query6, $connection);
	$row=mysql_fetch_row($result);
	$salesman_name=$row[1];

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


	$query7="select Ledger_number,Ledger_name ".
			" from ledger where ledger_number='$agent_code'";
			//echo$query7;
			
	$result=mysql_query($query7, $connection);
	$row=mysql_fetch_row($result);
	$agent_name=$row[1];

	$query8="select Ledger_number,Ledger_name ".
			" from ledger where ledger_number='$client_mothercompany'";		
	$result=mysql_query($query8, $connection);
	$row=mysql_fetch_row($result);
	$client_companyname=$row[1];

	$query9="select LedgerGrp_Code,LedgerGrp_name ".
			" from ledgergrp where LedgerGrp_Code='$client_groupcode'";
		
	$result=mysql_query($query9, $connection);
	$row=mysql_fetch_row($result);
	$client_groupname=$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($competitor_id!='' && $checkcode!=1){
	$query_competitor="select Ledger_Number,Competitor_Ratio,Competitor_Product,Competitor_Salesman,Competitor_Name,competitor_id
					from competitors where competitor_id=".$competitor_id;
									
	//echo$query_competitor;
	$resultcompetitor=mysql_query($query_competitor,$connection) or die(mysql_error());		
	
	while($rows=mysql_fetch_array($resultcompetitor)){						
		$ledger_number=$rows[0];
		$competitor_ratio=$rows[1];
		$competitor_product=$rows[2];
		$competitor_salesman=$rows[3];
		$competitor_name=$rows[4];			
		$competitor_id=$rows[5];								
	}				
}

if($clientact_id!='' && $checkcode!=1){
	$query_activation="select Ledger_Number,date_format(ClientAct_StartDate,'%d-%m-%Y'),date_format(ClientAct_EndDate,'%d-%m-%Y'),
						ClientAct_Remark,clientact_id
						from clientactivationhistoric where ClientAct_ID='$clientact_id'";
	//echo$query_activation;
	$resultactivation=mysql_query($query_activation,$connection) or die(mysql_error());		
	while($rows=mysql_fetch_array($resultactivation)){						
		$ledger_number=$rows[0];
		$clientact_startdate=$rows[1];
		$clientact_enddate=$rows[2];
		$clientact_remark=$rows[3];
		$clientact_id==$rows[4];
	}
}

if($Clientip_id!='' && $checkcode!=1){
	$query="select CLIENT_TC,CLIENT_CATEGORY,SUBSCRIBER_NAME,ClientIP_PeriodByMonth,date_format(Client_Inst_Month,'%d-%m-%Y'),Clientip_amount,Currency_code,date_format(Clientip_startDate,'%d-%m-%Y'),date_format(ClientIP_EndDate,'%d-%m-%Y')".
						",date_format(ClientIP_LastTransDate,'%d-%m-%Y'),Reason_disabled,Technician_Name,Collection_name,Subscriber_Address,Clientip_upload,Clientip_download,Project_Code,Costcenter_code,Area_Code,".
						"Client_MacAddress,Client_port,Modem_IP,service_name,Clientip_IP
						from clientsip where Clientip_id='$Clientip_id'";
	//echo$query;
	$result=mysql_query($query,$connection) or die(mysql_error());		
	while($rows=mysql_fetch_array($result)){						
		
		$clientip_tc=$rows[0];
		$category_name=$rows[1];
		$subscriber_name=$rows[2];
		$ClientIP_PeriodByMonth=$rows[3];
		$Client_Inst_Month=$rows[4];
		$clientip_amount=$rows[5];
		$currencyip=$rows[6];
		$start_date=$rows[7];
		$end_date=$rows[8];
		$ClientIP_LastTransDate=$rows[9];
		$clientip_reason=$rows[10];
		$technician_name=$rows[11];
		$collection_name=$rows[12];
		$Subscriber_Address=$rows[13];
		$upload_ip=$rows[14];
		$download_ip=$rows[15];
		$clientipproject_code=$rows[16];
		$clientipcostcent_code=$rows[17];
		$clientiparea_code=$rows[18];
		$client_macaddress=$rows[19];
		$client_port=$rows[20];
		$client_modemip=$rows[21];
		$service_name=$rows[22];
		$Clientip_IP=$rows[23];
	}
}



$query="select 1 from journaldt where ledger_number='".$ledger_numberPrv."'
	union
	select 1 from deliveries where client_code='".$ledger_numberPrv."'
	union
	select 1 from sales where client_code='".$ledger_numberPrv."'
	union
	select 1 from sorder where client_code='".$ledger_numberPrv."'
	union
	select 1 from salesjv where client_code='".$ledger_numberPrv."'
";

$result=mysql_query($query,$connection);
$row=mysql_fetch_row($result);
$countLedger=$row[0];

if($countLedger==1){
	$statuscode='readonly';
}

//if($mainmode=='') $mainmode='insert';

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 changeshow(choice){
if(choice==1){
	if(document.clientdt.chk_client_showcreditlimit.checked)
		document.clientdt.client_showcreditlimit.value=1;
	else
		document.clientdt.client_showcreditlimit.value=0;	
	}
else {
	if(document.clientdt.chk_client_showmaturitydate.checked)
		document.clientdt.client_showmaturitydate.value=1;
	else
		document.clientdt.client_showmaturitydate.value=0;
	}


}

function showlistProject(str){

	vProjectCode = encodeURIComponent(document.getElementById('txtProjectCode').value);
	window.open('List_SorProject.php?frm=46&item='+str+'&PProject_Code='+vProjectCode,'mywindow','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function kd(e)
{ 

	x=document.clientdt;
    var intKey = (window.Event) ? e.which : e.keyCode;

    if (intKey == 13) { //enter key
	
        x.btnPost.click();
		
		/*el = x.elements;
		var w = '';
		for(var i=0;i<el.length;i++){
		
			el[i].getfocus=function(){
				w=this.name;
				alert(w);
			}
		}*/
		

		return false;
    }
    return true;
}

function PrintPreview()
{

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

function ExportExcel() {
	var str = '';
	str = 'Form_ClientExcel.php';
	window.open(str);
}

function editcontact (code) {
				
			document.clientdt.keepcontact.value='1';
			document.clientdt.mainmode.value='edit';
			document.clientdt.telephone_increment.value=code;
			document.clientdt.edittelephone.value=1;
			
			var l=document.clientdt.ledger_number.value;

			document.clientdt.action="Form_Clients.php?ledger_number="+l;
				document.clientdt.submit();
}

function editactive (code) {
				
	
	document.clientdt.mainmode.value='edit';
	document.clientdt.clientact_id.value=code;

	var l=document.clientdt.ledger_number.value;
	document.clientdt.action="Form_Clients.php?vTabFocus=Activation";
	document.clientdt.submit();
}

function editcomp (code) {
				
	
	document.clientdt.mainmode.value='edit';
	document.clientdt.competitor_id.value=code;
	
	var l=document.clientdt.ledger_number.value;
	document.clientdt.action="Form_Clients.php?vTabFocus=Competitor";
	document.clientdt.submit();
}

function editip (code) {
	
	document.clientdt.Clientip_id.value=code;

	document.clientdt.action="Form_Clients.php?vTabFocus=ClientsIP";
	document.clientdt.submit();
}

function Deleteip(Deleteip){

	if (confirm ( "Are you sure you want to Delete record?"))
	{
		
		document.clientdt.Clientip_id.value = Deleteip;
		document.clientdt.actionmode.value = 'deleteip';
		
		document.clientdt.action="Form_Client_Actions.php";
		document.clientdt.submit();
	}	
}



function editmode () {
				
	document.clientdt.mainmode.value='editmode';
	var l=document.clientdt.ledger_number.value;
	document.clientdt.action="Form_Clients.php?ledger_number="+l;
	document.clientdt.submit();
}
function printClient(ledger_number){
	var str = "Form_ClientPreview.php?ledger_number="+ledger_number;
	window.open(str);
}

function clearcontact(){

	document.clientdt.edittelephone.value=0;
	document.clientdt.title_name.value='';
	document.clientdt.name.value='';
	document.clientdt.work_title.value='';
	document.clientdt.client_type.value='';
	document.clientdt.telephoneno.value='';
	document.clientdt.telephoneno2.value='';
	document.clientdt.telephoneno3.value='';
	document.clientdt.action="Form_Clients.php?mainmode=edit";
	document.clientdt.submit();
}

function clearclientip(){

	
	document.clientdt.clientip_tc.value='';
	document.clientdt.category_name.value='';
	document.clientdt.subscriber_name.value='';
	document.clientdt.ClientIP_PeriodByMonth.value='';
	document.clientdt.Client_Inst_Month.value='';
	document.clientdt.clientip_amount.value='';
	document.clientdt.currencyip.value='';
	document.clientdt.start_date.value='';
	document.clientdt.end_date.value='';
	document.clientdt.ClientIP_LastTransDate.value='';
	document.clientdt.clientip_reason.value='';
	document.clientdt.technician_name.value='';
	document.clientdt.collection_name.value='';
	document.clientdt.Subscriber_Address.value='';
	document.clientdt.upload_ip.value='';
	document.clientdt.download_ip.value='';
	document.clientdt.clientipproject_code.value='';
	document.clientdt.clientipcostcent_code.value='';
	document.clientdt.clientiparea_code.value='';
	document.clientdt.client_macaddress.value='';
	document.clientdt.client_port.value='';
	document.clientdt.client_modemip.value='';
	document.clientdt.service_name.value='';
	document.clientdt.Clientip_IP.value='';
	document.clientdt.Clientip_id.value='';
		
	
	document.clientdt.action="Form_Clients.php?vTabFocus=ClientsIP";
	document.clientdt.submit();
}



function clearcompetitor(){

	document.clientdt.competitor_ratio.value='';
	document.clientdt.competitor_product.value='';
	document.clientdt.competitor_salesman.value='';
	document.clientdt.competitor_name.value='';
	document.clientdt.competitor_id.value='';
	document.clientdt.action="Form_Clients.php?vTabFocus=Competitor";
	document.clientdt.submit();
}

function clearactivation(){
	
	document.clientdt.clientact_startdate.value='';
	document.clientdt.clientact_enddate.value='';
	document.clientdt.clientact_remark.value='';
	document.clientdt.clientact_id.value='';
	document.clientdt.action="Form_Clients.php?vTabFocus=Activation";
	document.clientdt.submit();
}


function AddClients () {

	document.clientdt.check_ledgergrp.value=1;
	document.clientdt.mainmode.value='insert';
	document.clientdt.action='Form_Clients.php';
	document.clientdt.submit();
}

//mycode

function addserial(){
	var ledgernumber= document.clientdt.ledger_number.value;
	var check_ledgergrp=document.clientdt.check_ledgergrp.value=1;
	var mainmode=document.clientdt.mainmode.value='insert';
	var check_ledgergrp= document.clientdt.check_ledgergrp.value=1;
	if(ledgernumber.toString().length<4 || ledgernumber.toString().length>=8){
			alert("Minimum Number/Name of digits is 4");
			return;
	}

	document.clientdt.action='Form_Client_Actions.php?actionmode=getledgergroup&ledger_number='+ledgernumber+'&check_ledgergrp='+check_ledgergrp+'&check_ledgergrp='+check_ledgergrp+'&mainmode='+mainmode;
	document.clientdt.submit();
}


function SubmitRecord(option) {



var checkOK = "0123456789";
	
var checkStr = clientdt.ledger_number.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 \"Client Code\" field.");
	tab_('Main Page','ledger_number');
	
return (false);
}*/


var checkStr = clientdt.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 Limit\" field.");		
	tab_('Main Page','credit_limit');
				
return (false);
}

var checkOK = "0123456789";
var checkStr = clientdt.client_paymentterm.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 \"Payment Term\" field.");
	tab_('Main Page','client_paymentterm');
return (false);
}

var checkOK = "0123456789";
var checkStr = clientdt.client_paymentterm2.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 \"Payment Term 2\" field.");
	tab_('Main Page','client_paymentterm2');
	return (false);
}


var checkOK = "0123456789.";
var checkStr = clientdt.salesman_com.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.");
	tab_('Main Page','salesman_com');
				
return (false);
}

var checkOK = "0123456789";
var checkStr = clientdt.discount.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 \"discount\" field.");
	tab_('Main Page','discount');
return (false);
}


	var checkOK = "0123456789";
var checkStr = clientdt.client_chterms.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 \"Check Due Term\" field.");
	tab_('Main Page','client_chterms');
return (false);
}

var checkOK = "0123456789";
var checkStr = clientdt.client_frequencyofvisit.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 \"Fr of Visits\" field.");
	tab_('Main Page','client_frequencyofvisit');
return (false);
}


var checkOK = "0123456789";
var checkStr = clientdt.budget_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 \"Budget Limit\" field.");
	tab_('Main Page','budget_limit');
	
return (false);
}

var checkOK = "0123456789";
var checkStr = clientdt.client_gcino.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 \"GCI No.\" field.");
	tab_('Others','client_gcino');
	return (false);
}

var checkOK = "0123456789";
var checkStr = clientdt.client_tobcode.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 \"T.O.B Code.\" field.");
	tab_('BusinessSector','client_tobcode');
	return (false);
}

var checkStr = clientdt.clientip_amount.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 \"Amount .\" field.");
	tab_('ClientsIP','clientip_amount');
	return (false);
}

var checkStr = clientdt.ClientIP_PeriodByMonth.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 \"Period By Month .\" field.");
	tab_('ClientsIP','ClientIP_PeriodByMonth');
	return (false);
}


////////////////////////////////////// end of number fields validation

	if (document.clientdt.ledger_number.value=='' ){
		alert('Unable to save : check missing field Code in Main Page');
		tab_('Main Page','ledger_number');
	}
		
	else if (document.clientdt.ledger_name.value=='' ){	
		alert('Unable to save : check missing field Client Name in Main Page');
		tab_('Main Page','ledger_name');
	}

	else if (document.clientdt.salesmenexist.value>'0' && document.clientdt.salesman_code.value=='' ){
		alert('Unable to save : check missing field Salesman in Main Page');
		tab_('Main Page','salesman_code');
	}
	
	else if (document.clientdt.projectmasterexist.value > 0 && document.clientdt.project_code.value=='' )	{
		alert('Unable to save : check missing field Project in Main Page');
		tab_('Main Page','project_code');
	}	
		
	else if (document.clientdt.costcentermasterexist.value > 0 && document.clientdt.costcenter_code.value=='' )	{
			
		alert('Unable to save : check missing field Costcenter in Main Page');
		tab_('Main Page','costcenter_code');
	}		
	
		
	else if (document.clientdt.creation_date.value=='' && document.clientdt.module.value=='1'){
		alert('Unable to save : check missing field Creation Date');
		tab_('Main Page','creation_date');
	}
	
	else if (document.clientdt.salesman_code.value=='' && document.clientdt.module.value=='1'){
			
		alert('Unable to save : check missing field Salesman in Main Page');
		tab_('Main Page','salesman_code');
	}
	
		else if (document.clientdt.client_rating.value=='' && document.clientdt.module.value=='1'){					
			alert('Unable to save : check missing field Customer Type in Main Page');
			tab_('Main Page','client_rating');
		}
		else if (document.clientdt.currency_code.value=='' && document.clientdt.module.value=='1'){					
			alert('Unable to save : check missing field Currency in Main Page');
			tab_('Main Page','currency');
		}
		
		else if (document.clientdt.credit_limit.value==''  && clientdt.credit_limit.readOnly==false){
			alert('Unable to save : check missing field Credit Limit in Main Page');
			tab_('Main Page','credit_limit');
		}
		
		else if (document.clientdt.client_paytermtype.value=='' && document.clientdt.module.value=='1'){					
			
			alert('Unable to save : check missing field Type in Main Page');
			tab_('Main Page','client_paytermtype');
		}
	
		else if (document.clientdt.client_paymentterm.value=='' && document.clientdt.module.value=='1' && clientdt.client_paymentterm.readOnly==false){					
			alert('Unable to save : check missing field Terms in Main Page');
			tab_('Main Page','client_paymentterm');
		}
		
		else if (document.clientdt.client_legaltype.value=='' && document.clientdt.module.value=='1'){					
			alert('Unable to save : check missing field Legal in Main Page');
			tab_('Main Page','legaltype');
		}
		
		else if (document.clientdt.area_code.value=='' && document.clientdt.module.value=='1'){					
			alert('Unable to save : check missing field Area in Address Page');
			tab_('Address','area_code');
		}
		
		else if (document.clientdt.Address.value==''){	
			alert('Unable to save : check missing field Address in Address Page');
			tab_('Address','Address');
		}
		
		else if (document.clientdt.phone1.value=='' ){					
			alert('Unable to save : check missing field Phone 1 in Address Page');
			tab_('Address','phone1');
		}
		else if (document.clientdt.client_gcino.value=='' && document.clientdt.module.value=='1'){					
			alert('Unable to save : check missing field GCI No. in Others Page');
			tab_('Others','client_gcino');
		}
		else if (document.clientdt.delivery_areacode.value=='' && document.clientdt.module.value=='1'){	
			alert('Unable to save : check missing field Area in Delivery Page');
			tab_('Delivery','delivery_areacode');
		}
		else if (document.clientdt.client_deliveryaddress.value=='' && document.clientdt.module.value=='1'){
			alert('Unable to save : check missing field Address in Delivery Page');
			tab_('Delivery','client_deliveryaddress');
		}
		
		else if ((document.clientdt.client_local.value=='0') && (document.clientdt.client_export.value=='0') && document.clientdt.module.value=='1'){
			tab_('Main Page','');
			alert('Unable to save : check missing field Local or Export in Main Page');
		}
		
		else if (document.clientdt.client_businesssector.value=='' && document.clientdt.module.value=='1'){
			alert('Unable to save : check missing field Business Sector in Business Sector Page');
			tab_('BusinessSector','businesssector');
		}
		else if (document.clientdt.client_tobcode.value=='' && document.clientdt.module.value=='1'){
			alert('Unable to save : check missing field T.O.B code in Business Sector Page');
			tab_('BusinessSector','client_tobcode');
		}
		
		else if (document.clientdt.Client_BusinessType.value=='' && document.clientdt.module.value=='1'){
			alert('Unable to save : check missing field Business Type in Business Sector Page');
			tab_('BusinessSector','Client_BusinessType');
		}
		
		else 	if (option==2 && document.clientdt.telephoneno_title.value=='' )
	{
		alert('Unable to save : check missing field Title in Contact Page');
		tab_('contact/Assistant','telephoneno_title');
	}
	else 	if (option==2 && document.clientdt.telephone_fname.value=='' )
	{
		alert('Unable to save : check missing field First Name in Contact Page');
		tab_('contact/Assistant','telephone_fname');
	}
	else 	if (option==2 && document.clientdt.telephone_lname.value=='' )
	{
		alert('Unable to save : check missing field Last Name in Contact Page');
		tab_('contact/Assistant','telephone_lname');
	}
	else 	if (option==2 && document.clientdt.telephone_name.value=='' )
	{
		alert('Unable to save : check missing field Name in Contact Page');
		tab_('contact/Assistant','telephone_name');
	}
	else 	if (option==2 && document.clientdt.telephone_no.value=='' )
	{
		alert('Unable to save : check missing field Tel No in Contact Page');
		tab_('contact/Assistant','telephone_no');
	}
	else 	if (option==3 && document.clientdt.competitor_name.value=='' )
	{
		alert('Unable to save : check missing field Name in Competitor Page');
		tab_('Competitor','competitor_name');
	}
	else 	if (option==3 && document.clientdt.competitor_ratio.value=='' )
	{
		alert('Unable to save : check missing field Ratio in Competitor Page');
		tab_('Competitor','competitor_ratio');
	}
	else 	if (option==3 && document.clientdt.competitor_salesman.value=='' )
	{
		alert('Unable to save : check missing field Salesmen in Competitor Page');
		tab_('Competitor','competitor_salesman');
	}
	else 	if (option==4 && document.clientdt.clientact_startdate.value=='' )
	{
		alert('Unable to save : check missing field Start Date in Activation Page');
		tab_('Activation','clientact_startdate');
	}
	else 	if (option==4 && document.clientdt.clientact_enddate.value=='' )
	{
		alert('Unable to save : check missing field End Date in Activation Page');
		tab_('Activation','clientact_enddate');
	}
	else 	if (option==4 && document.clientdt.clientact_remark.value=='' )
	{
		alert('Unable to save : check missing field Remark in Activation Page');
		tab_('Activation','clientact_remark');
	}
	
	else 	if (option==5 && document.clientdt.subscriber_name.value=='' )
	{
		alert('Unable to save : check missing field Subscriber ');
		tab_('ClientsIP','subscriber_name');
	}
	else 	if (option==5 && document.clientdt.Clientip_IP.value=='' )
	{
		alert('Unable to save : check missing field IP ');
		tab_('ClientsIP','Clientip_IP');
	}
	else 	if (option==5 && document.clientdt.start_date.value=='' )
	{
		alert('Unable to save : check missing field Start Date ');
		tab_('ClientsIP','start_date');
	}
	
	
	else{
		if(option==2)
			document.clientdt.actionmode.value='submitcontact';
			
		if(option==3)
			document.clientdt.actionmode.value='submitcompetitor';

		if(option==4)
			document.clientdt.actionmode.value='submitactivation';	
		
		if(option==5)
			document.clientdt.actionmode.value='submitclientip';	
			
		document.clientdt.checkcode.value='1';
		
		document.clientdt.check_ledgergrp.value=0;	
		document.clientdt.fill_ledger.value=0;	
		
		document.clientdt.action='Form_Clients.php';
		document.clientdt.submit();
	}
}

//////////////////////////////////////////////////// end of client submit 

function SubmitContractdt(){
	if (document.clientdt.txtProjectCode.value=='' )
		{alert('Unable to save : check missing fields Project Code');
		document.getElementById("txtProjectCode").focus();
		}

else if (document.clientdt.clientcontact_amount.value=='' )
{alert('Unable to save : check missing fields Contract amount');
document.getElementById("clientcontact_amount").focus();
}

else if (document.clientdt.txtcontractdate.value=='' )
{alert('Unable to save : check missing fields Contract Start Date');
document.getElementById("txtcontractdate").focus();
}

else if (document.clientdt.contractterm.value=='' )
{alert('Unable to save : check missing fields Contrct Term');
document.getElementById("contractterm").focus();
}
else{
var m;
	document.clientdt.actionmode.value = 'insertcontract';
	document.clientdt.action='Form_Client_Actions.php';
	document.clientdt.submit();}
}

function addcompetitor(str){

if (document.clientdt.competitor_name.value=='' )
		{alert('Unable to save : check missing fields Name');
		document.getElementById("competitor_name").focus();
		}

else 

if (document.clientdt.competitor_ratio.value=='' )
		{alert('Unable to save : check missing fields Ratio');
		document.getElementById("competitor_ratio").focus();
		}

else 

if (document.clientdt.competitor_salesman.value=='' )
		{alert('Unable to save : check missing fields Salesman');
		document.getElementById("competitor_salesman").focus();
		}
else {
				document.clientdt.action='Form_Competitor_Actions.php?str='+str;
				document.clientdt.submit();
}
}





function checkexport(){

if(document.clientdt.exportchk.checked){
document.getElementById("client_export").value=1;
}

else
 document.getElementById("client_export").value='0';

}

function checklocal(){

if(document.clientdt.localchk.checked){
document.clientdt.client_local.value=1;
}

else
 document.clientdt.client_local.value='0';

}

function deactiveclient() {
if(document.clientdt.deactivate.checked){
document.clientdt.deactivateclient.value=1;
document.clientdt.deactivatedate.disabled=false;}

else
{
document.clientdt.deactivateclient.value=0;
document.clientdt.deactivatedate.value='';
document.clientdt.deactivatedate.disabled=true;
}

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

}


function sentmail() {
	if(document.clientdt.sent_mail.checked){
		document.clientdt.sent_email.value=1;

	}
	else
	{
	document.clientdt.sent_email.value=0;

	}
}

function checkinvoice() {
	if(document.clientdt.invoice_rounded.checked){
		document.clientdt.client_invrounded.value=1;

	}
	else
	{
	document.clientdt.client_invrounded.value=0;
	}
}



function checkcash() {
if(document.clientdt.cashmode.checked){
document.clientdt.client_cashmode.value=1;

}
else
{
document.clientdt.client_cashmode.value=0;

}
}



function checksales() {
if(document.clientdt.client_sales.checked){
document.clientdt.client_multiplesales.value=1;

}
else
{
document.clientdt.client_multiplesales.value=0;

}
}


function showlistagentscode(str){

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

function showlistagentsname(str){

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

function showlistip(str){

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




function showlistcompaniescode(str){

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

function showlistcompaniesname(str){

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


function showlistgroups(str){

	var module=document.clientdt.module_ledgergrp.value;
  window.open('List_Groups.php?str='+str+'&module_ledgergrp='+module,'List_Groups','width=850,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');

}


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


function showlistsalesmenCompetitor(str){

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



function showlistarea(str){

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



function showlistareaDelivery(str){ 


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





function showlistprojects(str){

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

function showlistprojectsname(str){

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

function showlistcostcenter(str){

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


function showlistcostcentercode(str){

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

function showlistcostcentername(str){

  window.open('List_CostCenter_orderbyname.php?str='+str,'List_CostCenter_orderbyname','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 showlistchkaccount(str){

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





function changetax(value) {

var tax;
tax='tax'+value;


if(document.clientdt["tax"+value].checked){
document.clientdt["client_tax"+value].value=1;

}
else
{
document.clientdt["client_tax"+value].value=0;

}
}

function set_rating(){
document.clientdt.client_rating.value=document.clientdt.customertype.value;
}

function set_paymenttype(){
document.clientdt.client_paytermtype.value=document.clientdt.paymenttype.value;
}

function set_legaltype(){

document.clientdt.client_legaltype.value=document.clientdt.legaltype.value;

}

function set_warehouse(){

document.clientdt.warehouse.value=document.clientdt.warehouse_description.value;

}

function set_selling(){

document.clientdt.client_sellingprice.value=document.clientdt.selling_price.value;

}

function set_clienttype(){

document.clientdt.client_type.value=document.clientdt.clienttype.value;

}


function set_businesssector(){
document.clientdt.client_businesssector.value=document.clientdt.businesssector.value;
}





function set_language(){

document.clientdt.invoice_language.value=document.clientdt.language.value;


}



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

function set_title(){


document.clientdt.title_name.value=document.clientdt.title_description.value;

}


function set_titleowner(){
document.clientdt.title_owner.value=document.clientdt.titleowner_description.value;

}

function set_titlerefered(){
document.clientdt.title_refered.value=document.clientdt.titlerefered_description.value;

}

function set_titleassistant(){
document.clientdt.title_assistant.value=document.clientdt.titleassistant_description.value;

}


function changevat(){
if(document.clientdt.vat.checked){
document.clientdt.client_vat.value=1;
document.clientdt.vatstatus.value='enabled';
}
else
{
document.clientdt.client_vat.value=0;
document.clientdt.vat_date.value='';
document.clientdt.client_vatno.value=' ';
document.clientdt.vatstatus.value='disabled';
}

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

}



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 ClearPage(){
	 x = document.clientdt;
	if (confirm ( "Are you sure you want to Clear Page?"))
	{
		ClearForm();
		x.mainmode.value='';
		document.clientdt.vTabFocus.value="Main Page";
		x.action='Form_Clients.php';
		x.submit();
	}	
}

function cleardetail(){
	 x = document.clientdt;

	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 DeleteDetail(TelephoneId){

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

function DeleteContractdt(ContractId){
	if (confirm ( "Are you sure you want to Delete record?"))
	{
		
		document.clientdt.actionmode.value = 'deletecontract';
		
		document.clientdt.action="Form_Client_Actions.php?contractid="+ContractId;
		document.clientdt.submit();
	}
}

function DeleteComp(CompId){

	if (confirm ( "Are you sure you want to Delete record?"))
	{
		document.clientdt.competitor_id.value = CompId;
		document.clientdt.actionmode.value = 'deletecomp';
		
		document.clientdt.action="Form_Client_Actions.php";
		document.clientdt.submit();
	}	
}

function DeleteAct(ActId){

	if (confirm ( "Are you sure you want to Delete record?"))
	{
		document.clientdt.clientact_id.value = ActId;
		document.clientdt.actionmode.value = 'deleteact';
		
		document.clientdt.action="Form_Client_Actions.php";
		document.clientdt.submit();
	}	
}


//All= All form; D= Detail Part
function ClearForm(Option){
   var x = document.clientdt;
	
	//var vmode = x.mainmode.value;
	
	
		x.message.value='';
		x.creation_date.value='';
		x.deactivateclient.value='';
		x.deactivatedate.value='';
		x.ledger_number.value='';
		x.client_tc.value='';
		x.client_groupcode.value='';
		x.ledger_name.value='';
		x.ledger_namef.value='';
		x.ledger_description.value='';
		x.salesman_code.value='';
		x.salesman_name.value='';
		x.currency.value='';
		x.client_frequencyofvisit.value='';
		x.salesman_com.value='';
		x.client_rating.value='';
		x.client_vat.value='';
		x.client_vatno.value='';
		x.vat_date.value='';
		x.client_sellingprice.value='';
		x.discount.value='';
		if(x.credit_control)
		x.credit_control.value='';
		x.budget_limit.value='';
		x.currency_code.value='';
		x.credit_limit.value='';
		x.client_group.value='';
		x.project_code.value='';
		x.client_paytermtype.value='';
		x.client_paymentterm.value='';
		x.client_paymentterm2.value='';
		x.client_paymentmode.value='';
		x.costcenter_code.value='';
		x.costcenter_name.value='';
		x.client_checkaccount.value='';
		x.client_chterms.value='';
		x.client_cashmode.value='';
		x.sent_email.value='';
		x.client_tax0.value='';
		x.client_tax1.value='';
		x.client_tax2.value='';
		x.client_tax3.value='';
		x.client_tax4.value='';
		x.client_tax5.value='';
		x.client_export.value='';
		x.client_local.value='';
		x.client_legaltype.value='';
		x.country.value='';
		x.state.value='';
		x.city_client.value='';
		x.area_code.value='';
		x.areaname.value='';
		x.Address.value='';
		x.Address2.value='';
		x.homepage.value='';
		x.phone1.value='';
		x.email.value='';
		x.phone2.value='';
		x.fax.value='';
		x.pobox.value='';
		x.fax.value='';
		x.agent_code.value='';
		x.client_mothercompany.value='';
		x.bussiness_type.value='';
		x.title_owner.value='';
		x.title_refered.value='';
		x.client_referedby.value='';
		x.client_sdino.value='';
		x.title_assistant.value='';
		x.client_deliveryassistant.value='';
		x.client_dlvworktitle.value='';
		x.delivery_phone.value='';
		x.delivery_areacode.value='';
		x.delivery_areaname.value='';	
		x.client_deliveryaddress.value='';
		x.client_deliveryaddress2.value='';
		x.warehouse.value='';
		x.client_gcino.value='';
		x.client_archivefileno.value='';
		x.client_evaluationpoints.value='';
		x.client_weakness.value='';
		x.client_tips.value='';
		x.client_invrounded.value='';
		x.invoice_language.value='';
		x.client_businesssector.value='';
		x.client_businesssectordesc.value='';
		x.client_tobcode.value='';
		x.client_multiplesales.value='';
		x.client_btype2.value='';
		x.client_btype3.value='';
		x.Client_BusinessType.value='';
		x.title_name.value='';
		x.name.value='';
		x.competitor_ratio.value='';
		x.competitor_product.value='';
		x.competitor_salesman.value='';
		x.competitor_name.value='';
		x.clientact_startdate.value='';
		x.clientact_enddate.value='';
		x.clientact_remark.value='';
		x.edittelephone.value='0';
		x.editcompetitor.value='0';
		x.mainmode.value = '';
		x.client_groupname.value='';
		x.project_name.value='';
		x.check_ledgergrp.value='0';
		x.fill_ledger.value='0';
		x.module_ledgergrp.value='';
		x.client_remark.value='';
		x.Address3.value='';
		x.client_deliveryaddress3.value='';
		x.technical_person.value='';
		x.technical_email.value='';
		x.delivsof.value='';
		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.competitor_ratio.value='';
		x.competitor_product.value='';
		x.competitor_salesman.value='';
		x.competitor_name.value='';
		x.competitor_id.value=''; 
		x.clientact_startdate.value='';
		x.clientact_enddate.value='';
		x.clientact_remark.value='';
		x.clientact_id.value='';
		x.ledger_numberPrv.value='';
		x.profit_code.value='';
		x.client_financialno.value='';
		x.client_discountonInvoice.value='';

		x.clientip_tc.value='';
	x.category_name.value='';
	x.subscriber_name.value='';
	x.ClientIP_PeriodByMonth.value='';
	x.Client_Inst_Month.value='';
	x.clientip_amount.value='';
	x.currencyip.value='';
	x.start_date.value='';
	x.end_date.value='';
	x.ClientIP_LastTransDate.value='';
	x.clientip_reason.value='';
	x.technician_name.value='';
	document.clientdt.collection_name.value='';
	x.Subscriber_Address.value='';
	x.upload_ip.value='';
	x.download_ip.value='';
	x.clientipproject_code.value='';
	x.clientipcostcent_code.value='';
	x.clientiparea_code.value='';
	x.client_macaddress.value='';
	x.client_port.value='';
	x.client_modemip.value='';
	x.service_name.value='';
	x.Clientip_IP.value='';
	x.Clientip_id.value='';
	if(x.whtchecked){
		x.client_wht.value='';
		x.whtpercentage.value='';
	}
}

/*
function SearchForClient(){
	ClearForm('All');
    x = document.clientdt;
    win = window.open('Form_ClientSearch.php', 'Form_ClientSearch', '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 AppendClient(){


	if (confirm ( "Are you sure you want to Append Clients?"))
	{

		x = document.clientdt;
		x.action='Form_Clients_Append.php';
		x.submit();
	}	

}

	
function SetClient(Clientd){

	document.clientdt.ledger_number.value=Clientd;
	document.clientdt.message.value='';
	document.clientdt.check_ledgergrp.value='0';
	document.clientdt.actionmode.value='';
	document.clientdt.mainmode.value='editmode';
	document.clientdt.submit();
}

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

function SetPrvPage(startrange,perpage){
	document.clientdt.action='Form_Clients.php?startrange='+startrange+'&perpage='+perpage;
	document.clientdt.submit();
}
function SetPrvPage2(startrange,perpage){
	document.clientdt.action='Form_Clients.php?startrange2='+startrange+'&perpage='+perpage;
	document.clientdt.submit();
}
function SetNextPage2(startrange,perpage){
	document.clientdt.action='Form_Clients.php?startrange2='+startrange+'&perpage='+perpage;
	document.clientdt.submit();
}

function SearchForClient(){
	x = document.clientdt;
	document.clientdt.action='Form_Clients.php?startrange=0';
	document.clientdt.submit();
}

function ClearKeyword(){
	x = document.clientdt;
	x.txtKeyword.value='';
	document.clientdt.action='Form_Clients.php?startrange=0';
	document.clientdt.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.clientdt.action='Form_Clients.php?startrange=0';
	document.clientdt.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.clientdt.mainmode.value='delete';	
		
		document.clientdt.action='Form_Client_Actions.php?ledgernumber='+Code;
		document.clientdt.submit();
	}
					
}

function set_limit(){

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

function UpdateDetail(TelephoneId){
	 x = document.clientdt;
	 x.telephone_increment.value=TelephoneId;
	x.actionmode.value='refresh';
	x.action='Form_Clients.php?vTabFocus=contact/Assistant';
	x.submit();
}

function showpricelistgroups(str){
	window.open('List_Grouping.php?str='+str,'List_Grouping','width=850,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}		
function showpricelistsubgroups(str){
	window.open('List_SubGroup.php?str='+str,'List_SubGroup','width=850,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}
function showpricelistcategory(str){
	window.open('List_Categories.php?str='+str,'categorywindow','width=850,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}
function showlistItems(str){

	window.open('select_item.php?item='+str,'List_SorItems','width=850,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}
function clearSelling(){
	var x = document.clientdt;
	x.group_code.value='';
	x.group_name.value='';
	x.subgroup_code.value='';
	x.subgroup_name.value='';
	x.itemcategory_code.value='';
	x.itemcategory_name.value='';
	x.item_code.value='';
	x.item_description.value='';
	document.clientdt.vTabFocus.value="Selling Price";
	x.action='Form_Clients.php?startrange2=';
	x.submit();
	
}

function deleteSellingPrice(sellingprice_id){
	if(sellingprice_id != ''){
	var xmlhttp = new XMLHttpRequest();
	 $("#loading").show();
	xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{ 	
				var data = xmlhttp.responseText;
				 $("#loading").hide();
				if(data != 0)  {
					alert(data);
				 } else {
					 document.clientdt.vTabFocus.value="Selling Price";
					document.clientdt.submit();
				 }
				
					
			}
		}
	
	
	xstr = "actionmode=deleteSellingPrice&sellingprice_id="+sellingprice_id;
	xmlhttp.open("GET","Form_Client_Actions.php?"+xstr);
	xmlhttp.send();
	}
	
}

function submitSellprice(indx,sellingprice_id){
	var clientcode = document.clientdt.ledger_number.value;   
	var str = 'itemcode'+indx;
	var itemcode = document.getElementById(str).value;
	
	var str1 = 'pcurrencycode'+indx;
	var currencycode = document.getElementById(str1).value;
		
	var str2 = 'sellingprice'+indx;
	var sellingprice = document.getElementById(str2).value;
	sellingprice = parseFloat(sellingprice);
	
	var str3 = 'sellingpriceb1'+indx;
	var sellingpriceb1 = document.getElementById(str3).value;
	sellingpriceb1 = parseFloat(sellingpriceb1);
	
	var str4 = 'sellingpriceb2'+indx;
	var sellingpriceb2 = document.getElementById(str4).value;
	sellingpriceb2 = parseFloat(sellingpriceb2);
	
		var xmlhttp = new XMLHttpRequest();
	 $("#loading").show();
	xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{ 	
				var data = xmlhttp.responseText;
				 $("#loading").hide();
				if(data != 0)  {
					alert(data);
				 }
				
					
			}
		}
	
	
	xstr = "actionmode=sellingprice&pitemcode="+itemcode+"&pcurrencycode="+currencycode+"&psellingprice="+sellingprice+"&psellingpriceb1="+sellingpriceb1
		+"&psellingpriceb2="+sellingpriceb2+"&sellingprice_id="+sellingprice_id+"&clientcode="+clientcode;
	xmlhttp.open("GET","Form_Client_Actions.php?"+xstr);
	xmlhttp.send();
	
}

function setAmountbase(dec1, dec2,base1, base2, pdate, indx){
	
	var vAmount1,vAmount2;
	dec1  = parseInt(dec1);
	dec2  = parseInt(dec2);
	
	var xmlhttp = new XMLHttpRequest();
	
	xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{ 	
				var data = xmlhttp.responseText.split("[BRK]");
				
				vAmount1 = data[0];
				vAmount2 = data[1];
				
				var str3 = 'sellingpriceb1'+indx;
				document.getElementById(str3).value=vAmount1;
	
				var str4 = 'sellingpriceb2'+indx;
				document.getElementById(str4).value=vAmount2;
				
					
			}
		}
	
	var str1 = 'pcurrencycode'+indx;
	var currencycode = document.getElementById(str1).value;
	
	var str2 = 'sellingprice'+indx;
	var sellingprice = document.getElementById(str2).value;
	
	if(sellingprice == '') sellingprice=0;
	sellingprice = parseFloat(sellingprice);
	if(currencycode == ''){
		alert("Please choose a currency first!");
		return 0;
	} else{
	xstr = "actionmode=changeamount&pcurrencycode="+currencycode+"&sellingprice="+sellingprice+"&curb1="+base1+"&curb2="+base2+"&pdate="+pdate+"&dec1="+dec1+"&dec2="+dec2;  
	xmlhttp.open("GET","Form_Client_Actions.php?"+xstr);
	xmlhttp.send();
	}
}

function searchSelling(){ 
	document.clientdt.vTabFocus.value="Selling Price";
	document.clientdt.action='Form_Clients.php?startrange2=';
	document.clientdt.submit();
}

function viewHistory(){
	if(document.getElementById("item_code").value != '')
		var itemcode = document.getElementById("item_code").value;
	else var itemcode='';
	var clientcode = document.clientdt.ledger_number.value;
	window.open("Form_SellingPrice.php?clientcode="+clientcode+"&item_code="+itemcode,'_blank');
}
function setWHT(){
	if(document.getElementById("whtchecked").checked)
		document.clientdt.client_wht.value = 1;
	else 
		document.clientdt.client_wht.value = 0;
}
function chkClientEndOfMonthPay(){
	if(document.getElementById('chk_Client_EndofMonthPay').checked){
		document.getElementById('Client_EndofMonthPay').value = 1;
	}
	else{
		document.getElementById('Client_EndofMonthPay').value = 0;
	}
}
function chkClient_priceatcost(){
	if(document.getElementById('chk_Client_priceatcost').checked){
		document.getElementById('Client_priceatcost').value = 1;
	}
	else{
		document.getElementById('Client_priceatcost').value = 0;
	}
}

function returnMsg(){
	alert('Access Denied!');
	return 0;
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Add Client</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;}
#loading { 
	display:none;position:fixed; left:50%; top:50%; width:100%; height:100%;
 }
</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='clientdt' method='post' action=''>
<input type='hidden' name='HideMenu' value='$HideMenu'>
<input type='hidden' name='salesmenexist' value='$salesmenexist'>
<input type='hidden' name='costcentermasterexist' value='$costcentermasterexist'>
<input type='hidden' name='projectmasterexist' value='$projectmasterexist'>
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='mainmode' value='$mainmode'>
<input type=hidden name='maintab' value='$maintab'>
<input type=hidden name='vatstatus' value='$vatstatus'>
<input type=hidden name='clientact_id' value='$clientact_id'>
<input type=hidden name='editactivation' value='$editactivation'>
<input type=hidden name='edittelephone' value='$edittelephone'>
<input type=hidden name='editcompetitor' value='$editcompetitor'>
<input type='hidden' name='telephone_increment' value='$telephone_increment'>
<input type=hidden name='competitor_id' value='$competitor_id'>
<input type=hidden name='checkcode' value='$checkcode'>
<input type=hidden name='fromledger' value='$fromledger'>
<input type='hidden' name='fill_ledger' value='$fill_ledger'>
<input type='hidden' name='module_ledgergrp' value='$module_ledgergrp'>
<input type=hidden name='module' value='$module'>
<input type=hidden name='title_name' value='$title_name'>
<input type=hidden name='title_owner' value='$title_owner'>
<input type=hidden name='title_refered' value='$title_refered'>
<input type=hidden name='title_assistant' value='$title_assistant'>
<input type=hidden name='addresstab' value='$addresstab'>
<input type='hidden' name='message' value='$message'>
<input type='hidden' name='check_ledgergrp' value='$check_ledgergrp'>
<input type='hidden' name='ledger_numberPrv' value='$ledger_numberPrv'>
<input type='hidden' name='Clientip_id' value='$Clientip_id'>
<input type='hidden' name='vTabFocus' value='$vTabFocus'>



HERE;

if($client_vat=='' && $mainmode=='insert')
	$client_vat=1;
	
if($client_vat!='1')
	$vatstatus='disabled';

else $vatstatus='enabled';

if($client_vat=='1')
$selectedvat='checked';

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

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

if($addclient == 1){
	echo "<script>AddClients();</script>";
	$addclient == 0;
}

//$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'>";
if ($HideMenu != 1) 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'>CLIENTS</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 , Client_Telephone1 from clients ";
$querysearch=$querysearch." where (ledger_number like"."('%".$txtKeyword."%') or ledger_name like"."('%".$txtKeyword."%')  
or  Client_Telephone1 like"."('%".$txtKeyword."%') or Salesmen_Code  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;

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

echo"		<tr>
				<td  height='34'  valign='top' id='content-top2'>
					<table border='0' cellpadding='0' cellspacing='0' class='layout-width' width='1100px'>
						<col width='700'>
						<col width='130'>
						<col width='200'>
						<col width='180'>
						<col width='210'>
						<col width='200'>
						<tr>
							<td height='34'style='padding-left:52px;'>";
echo"							<button type='button' id='btnClear' name='btnClear' onclick='ClearPage(); return false;' title='Clear Page'><span><span>Clear Page</span></span></button>";
								if ($ClientsApp == 1)
echo"							<button type='button' id='btnAddClient' name='btnAddClient' onclick='AddClients(); return false;' title='Add Client'><span><span>Add</span></span></button>";
echo"							<button type='button' id='btnPost' name='btnPost' onclick=\"";
if ($saveEnabled ==1)
	echo"SubmitRecord();";
else 
	echo "returnMsg(); ";	
echo "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='btnExcel' name='btnExcel' onclick='ExportExcel(); return false;' title='Export Excel' ><span><span>$excel</span></span></button>
								<button  type='button'  value='Check' onclick='addserial();return false;' title='Check'><span><span>Check</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='SearchForClient(); return false;' title='Search Client'><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>";
echo"			</table>";
echo"		</td>
		</tr>";
echo"	<tr>
			<td id='content-body'>";	
$tabs = new tabs("Clients");	
	
$tabs->start("$tab1");

echo"	<table border='0'  align='left' valign='top' class='tablecontent'>
			<col width=65%>";
echo"   	<tr bgcolor='#F7F7F7' height='25' ><td valign='top'>";	 
echo" 			<table border='0' style='table-layout:fixed' align='left' width='1100px' valign='top' >
					<col width=100>
					<col width=120>
					<col width=130>
					<col width=130>
					<col width=150>
					<col width=150>
					<col width=150>
					<col width=150>";
				
					 if($showalert=='1'){
						$message="Code Already Exists";
					}	
							
	echo"						<tr bgcolor='#F7F7F7' height='25'>
						<td valign='center' align='left' ><span class='style1'>$creationdate&nbsp;</span>";
							if($module=='1')
								echo"<span class='style26'>*</span>";
	echo"							</td>";
						//echo $mainmode."df"; 
					 //if($mainmode!=''){
						// echo $creation_date;
						if (empty($creation_date)){
							$today = date('d-m-Y');
							$creation_date = $today;
						}
					//}
	echo"							<td><input type='text' name='creation_date'  value='$creation_date' style='font-size:12px; width:90px; '  readonly />";
							if($mainmode!='view' && $mainmode!='')
							print<<< HERE
	&nbsp;<A HREF="#" onClick="displayCalendar(document.clientdt.creation_date,'dd-mm-yyyy',this); return false;" NAME="anchor1" ID="anchor1"><image src='./img/cal.gif' border=0 align=center></image></A></td>
HERE;
	echo" 							</td>";

							if($deactivateclient=='1') {
								$selecteddeactivate='checked';
							}

	echo" 							 <td valign='center' align='center' ><span class='style1'>$deactivate_date</td>
						 <td ><input type=checkbox name='deactivate' onclick='deactiveclient()'  $dis $selecteddeactivate>
							<input type='hidden' name='deactivateclient' value='$deactivateclient'>
							<input type='text' readonly name='deactivatedate' value='$deactivatedate' maxlength='10' size='10' style='font-size:12px; width:100px; '>&nbsp;";
							if($mainmode!='view' && $mainmode!='' && $deactivateclient=='1')
							print<<< HERE
	<A HREF="#" onClick="displayCalendar(document.clientdt.deactivatedate,'dd-mm-yyyy',this); return false;" NAME="anchor1" ID="anchor1"><image src='./img/cal.gif' border=0 align=center></image></A>
HERE;
	echo"							 </td>";
	echo" 							</span>
						<td valign='center' align='right' ><span class='style1'>$tc &nbsp</td> 
						<td><input type='text' name='client_tc' value='".htmlspecialchars($client_tc, ENT_QUOTES)."'  maxlength='10' size='10' $status style='font-size:12px; width:100px; '></td>";
	echo"							<td align='right'><span class='style1'>$crlimit </span>&nbsp;&nbsp;
							<input type='checkbox' name='chk_client_showcreditlimit' id='chk_client_showcreditlimit' onclick='changeshow(1)' $checked>
							<input type='hidden' name='client_showcreditlimit' value='$client_showcreditlimit'  $status >
						</td>
						<td align='right'>
							<span class='style1'>$matdate</span> 
							<input type='checkbox' name='chk_client_showmaturitydate' id='chk_client_showmaturitydate'  onclick='changeshow(2)' $checked>
							<input type='hidden'   name='client_showmaturitydate' id='client_showmaturitydate' value='$client_showmaturitydate'  $status >
						</td>
					</tr>";	 

				//If module true , show group fields	
				//Gilbert 7/3/2013
						if($module_ledgergrp=='1'){
	echo"						<tr bgcolor='#F7F7F7' height='25'>";
	echo"							<td valign='center' align='left' ><span class='style1'>$groupclient</span></td>
						<td align=left> <input type='text' name='client_groupcode' value='$client_groupcode' maxlength='15' style='font-size:12px; width:90px; ' readonly />";
							 
							if($mainmode!='view' && $mainmode!='')
							echo" <label><span class='style1'><img src='img/btnopen.jpg' title=' Select Group '  width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistgroups(1);  return false'/></span></label>";
	echo"							</td>
						<td ><input type='text' name='client_groupname' value='$client_groupname' maxlength='32' style='font-size:12px; width:257px; ' readonly /></td>";
						}
						else {
							echo"<input type='hidden' name='client_groupcode' value='$client_groupcode'><input type='hidden' name='client_groupname' value='$client_groupname'>";
						}
							if($client_tax0=='1')$selectedtax0='checked';
							if($client_tax1=='1')$selectedtax1='checked';
							if($client_tax2=='1')$selectedtax2='checked';
							if($client_tax3=='1')$selectedtax3='checked';
							if($client_tax4=='1')$selectedtax4='checked';
							if($client_tax5=='1')$selectedtax5='checked';
							
							$Setup_Tax1Active=1;
							$Setup_Tax2Active=1;
							$Setup_Tax3Active=1;
							$Setup_Tax4Active=1;
							$Setup_Tax5Active=1;

							if ($ModuleAdditionalTax==1){
								$Tax0Text = 'checkbox';
								if ($Setup_Tax1Active==1)	$Tax1Text = 'checkbox';	else	$Tax1Text = 'hidden';
								if ($Setup_Tax2Active==1)	$Tax2Text = 'checkbox';	else	$Tax2Text = 'hidden';
								if ($Setup_Tax3Active==1)	$Tax3Text = 'checkbox';	else	$Tax3Text = 'hidden';
								if ($Setup_Tax4Active==1)	$Tax4Text = 'checkbox';	else	$Tax4Text = 'hidden';
								if ($Setup_Tax5Active==1)	$Tax5Text = 'checkbox';	else	$Tax5Text = 'hidden';
							}
						else{
							$Tax0Text = 'hidden';
							$Tax1Text = 'hidden';
							$Tax2Text = 'hidden';
							$Tax3Text = 'hidden';
							$Tax4Text = 'hidden';
							$Tax5Text = 'hidden';
						}
							if($module_ledgergrp==0)
	echo"							<td colspan=5></td>";
	echo"							<td align=left>
							<input type=$Tax0Text name='tax0' onclick='changetax(0)'  $dis $selectedtax0><input type='hidden' name='client_tax0' value='$client_tax0'>
							<span class='style1'>";
								if ($Tax0Text=='checkbox')
									echo"Tax &nbsp;&nbsp;";
	echo"</span>					</td>
						<td align=left >
							<input type=$Tax1Text name='tax1' onclick='changetax(1)'  $dis $selectedtax1 ><input type='hidden' name='client_tax1' value='$client_tax1'>
							<span class='style1'>";
							if ($Tax1Text=='checkbox') echo" Tax 1 ";
	echo"</span>					</td> 
					</tr>	 
					
					<tr bgcolor='#F7F7F7' height='25'>
						<td valign='center' align='left' ><span class='style1'>$code_label <span class='style26'>*</span>/ $name_label</span>";
							if($module=='1')
								echo"<span class='style26'>*</span>";
	echo"				</td>";

							if(isset($_GET['msg'])){$msg=$_GET['msg'];$ledger_number_plus=$_GET['ledger_number_plus']; $ledgetdtserial=$_GET['ledgetdtserial'];}
							if($msg=='hasledger'){
	echo "								<span class='style1' style='color:red;'>Auto Ledger Number</span>
						<td ><input type='text' name='ledger_number' value='$ledger_number_plus'   maxlength='10' style='font-size:12px; width:90px; ' $statuscode/></td>";	
							}
							if($msg==''){
	echo"				<td ><input type='text' name='ledger_number' value='$ledger_number'   maxlength='10' style='font-size:12px; width:90px; ' $statuscode/></td>";	
							}
							if($msg=='notfound'){
	echo "								<span class='style1' style='color:red;'>Ledger Not found</span>
						<td ><input type='text' name='ledger_number' value='$ledgetdtserial'   maxlength='10' style='font-size:12px; width:90px; ' $statuscode/></td>";	
							}
	echo"				<td ><input type='text' name='ledger_name' value='".htmlspecialchars($ledger_name, ENT_QUOTES)."' maxlength='50' style='font-size:12px; width:257px; ' $status /></td>";
							if($client_showcreditlimit == 1)
								$checked = ' checked ';
							else	
								$checked = ' ';
	echo"				<td align=left><input type=$Tax2Text name='tax2' onclick='changetax(2)'  $dis $selectedtax2><input type='hidden' name='client_tax2' value='$client_tax2'>
							<span class='style1'>";
							if ($Tax2Text=='checkbox') echo" Tax 2 ";
	echo"</span>		</td> 
						<td align='right'><span class='style1'>$frof_cisits&nbsp</td>
						<td><input type=text name='client_frequencyofvisit' value='$client_frequencyofvisit' $status  maxlength='5'  style='font-size:12px; width:100px; '></span></td>						

							<span class='style1'>";
							if ($Tax3Text=='checkbox') echo" Tax 3";
								echo"</span>
						
						<input type=$Tax3Text name='tax3' onclick='changetax(3)'  $dis $selectedtax3>
						<input type='hidden' name='client_tax3' value='$client_tax3'>
						<input type='hidden' name='client_export' id='client_export' value='$client_export'  $status >
						<input type='hidden' name='client_local' value='$client_local'  $status >";
						
							if($client_export=='1')$selectedexport='checked';
							if($client_local=='1')$selectedlocal='checked';
							
	echo"							<td align='right'>
							<span class='style1' align='right'>$export</span>&nbsp;
							<input type=checkbox name='exportchk' onclick='checkexport()'  $dis $selectedexport>
						</td>	
						
						<td align='right'>
							<span class='style1'>$cl_local</span><input type=checkbox name='localchk' onclick='checklocal()'  $dis $selectedlocal>
							
						</td>
					</tr>	
					
					<tr bgcolor='#F7F7F7' height='25'> 
						<td valign='center' align='left' ><span class='style1'>$namearabic</span></td>
						<td colspan=3><input type='text' name='ledger_namef' value='".htmlspecialchars($ledger_namef, ENT_QUOTES)."' maxlength='50' style='font-size:12px; width:379px;'  $status /></td>";
							if($client_showmaturitydate == 1)
								$checked = ' checked ';
							else	
								$checked = ' ';
	echo"							<td align='right'><span class='style1'> $commission %&nbsp</td>
						<td ><input type=text name='salesman_com' value='$salesman_com' $status size='3' maxlength='5' style='font-size:12px; width:100px; '></span></td>
						<td align='right'>
							<span class='style1'>$sentmail</span>&nbsp;&nbsp;&nbsp;
							<input type=checkbox name='sent_mail' onclick='sentmail()'  $dis ";if($sent_email==1) echo " checked ";echo">
							<input type='hidden' name='sent_email' value='$sent_email'></td>";
							if($client_cashmode=='1')$selectedcash='checked';
							
	echo"				<td align='right' >
							<span class='style1'>$cashmode</span>&nbsp;
							<input type=checkbox name='cashmode' onclick='checkcash()'  $dis $selectedcash>
							<input type='hidden' name='client_cashmode' value='$client_cashmode'  $status >
						 </td>
					</tr>	

					<tr bgcolor='#F7F7F7' height='25'>
						<td valign='center' align='left' ><span class='style1'>$description</span></td>
						<td><input type='text' name='ledger_description' value='".htmlspecialchars($ledger_description, ENT_QUOTES)."' maxlength='255' style='font-size:12px; width:380px;'  $status /></td>
						<td align=left><input type=$Tax4Text name='tax4' onclick='changetax(4)'  $dis $selectedtax4><input type='hidden' name='client_tax4' value='$client_tax4' >
							<span class='style1'>";
							if ($Tax4Text=='checkbox') echo" Tax 4 ";
							echo"</span>
						</td> 
						<td align=left><input type=$Tax5Text name='tax5' onclick='changetax(5)'  $dis $selectedtax5><input type='hidden' name='client_tax5' value='$client_tax5'>
							<span class='style1'>";
							if ($Tax5Text=='checkbox') echo" Tax 5 ";
								echo"</span>
						</td>
						<td align='right' bgcolor='#F7F7F7' height='25' ><span class='style1'>$discount_inv</span></td>
						<td><input type='text' name='client_discountonInvoice' value='$client_discountonInvoice' maxlength='10' $status  size='10' style='font-size:12px; width:101px; '></td>
						<td align=right>
							<span class='style1'> $vat_label</span><input type=checkbox name='vat' onclick='changevat()'  $dis $selectedvat>
							
						</td>
						<td align='right'>
						<span class='style1'>$vatno&nbsp;<input type='hidden' name='client_vat' value='$client_vat'>	
						<input type='text' name='client_vatno' value='".htmlspecialchars($client_vatno, ENT_QUOTES)."'  maxlength=20 style='font-size:12px; width:80px; ' $status $vatstatus>
							 </span>
						</td>
					</tr>	
                    <tr>
					<td colspan=6></td>
					<td style='text-align: right; font-size: 11px; font-weight: bold'>End of Month Pay <input type='hidden' name='Client_EndofMonthPay' id='Client_EndofMonthPay' value='$Client_EndofMonthPay' /><input type='checkbox' name='chk_Client_EndofMonthPay' id='chk_Client_EndofMonthPay'"; if($Client_EndofMonthPay == 1) echo "checked";  echo" onclick=\"chkClientEndOfMonthPay()\" /></td>
					<td style='text-align: right; font-size: 11px; font-weight: bold'>Price at Cost<input type='hidden' name='Client_priceatcost' id='Client_priceatcost' value='$Client_priceatcost' /><input type='checkbox' name='chk_Client_priceatcost' id='chk_Client_priceatcost'"; if($Client_priceatcost == 1) echo "checked";  echo" onclick=\"chkClient_priceatcost()\" /></td>
					</tr>
					<tr  bgcolor='#F7F7F7' height='25'>
						<td><span class='style1'>$salesman</span>";
							if($module=='1')
								echo"<span class='style26'>*</span>";
	echo "							</td>
						<td align=left>
							<input type=text name='salesman_code' value='$salesman_code' maxlength='10' $status readonly size='10' style='font-size:12px; width:90px; '>";
							if($mainmode!='view' && $mainmode!='')
							 echo"  <label><span class='style1'><img src='img/btnopen.jpg' title=' Select Salesman '  width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistsalesmen(1); return false' /></span></label>";
	echo"							</td>
						<td colspan=2>
							<input type=text name='salesman_name' value='$salesman_name' maxlength='15' $status readonly size='24' style='font-size:12px; width:258px; '>
						</td>
						<td align='right' bgcolor='#F7F7F7' height='25' ><span class='style1'>$financialno</span></td>
						<td><input type=text name='client_financialno' value='$client_financialno' maxlength='20' style='font-size:12px; width:100px; '></td>";
	if($module_saleswht == 1){	
	if($client_wht == '') $client_wht = 0;
	echo "	<td align='right' bgcolor='#F7F7F7'><span class='style1'>$wht<input type='checkbox' name='whtchecked' id='whtchecked' ".($client_wht == 1?'checked':'')." $status onclick=\"setWHT();\"> 
		 <input type='hidden' name='client_wht' value='$client_wht'></span> </td>";			
	echo "	<td align='right' bgcolor='#F7F7F7'><span class='style1'>$wht % <input type='text' name='whtpercentage' id='whtpercentage' value='$whtpercentage' $status style='font-size:12px; width:90px; '> </span> </td>";		 					
	 					
	
	} 					
	echo"			</tr>";
							if(!isset($client_sellingprice)) $client_sellingprice='I';
							if(!isset($discount))$discount=0;
							if(!isset($budget_limit))$budget_limit=0;
							if($client_sellingprice=='I')$selectedprice1='selected';
							if($client_sellingprice=='II')$selectedprice2='selected';
							if($client_sellingprice=='III')$selectedprice3='selected';
							if($client_sellingprice=='IV')$selectedprice4='selected';
							if($client_sellingprice=='V')$selectedprice5='selected';
							if($client_sellingprice=='VI')$selectedprice6='selected';

	echo"							<tr>
							<td align='left' bgcolor='#F7F7F7' height='25' <span class='style1'>$projet_label $code_label/$name_label</span></td>
							<td align=left colspan=3 bgcolor='#F7F7F7' height='25'><input type=text name='project_code' value='$project_code' maxlength='30' $status readonly  style='font-size:12px; width:90px; '>";
								if($mainmode!='view' && $mainmode!='')
									echo" <label><span class='style1'><img src='img/btnopen.jpg' title=' Select Project '  width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistprojects(1); return false' /></span></label>";
									echo" &nbsp;<input type=text name='project_name' value='$project_name' maxlength='100' $status readonly size='24' style='font-size:12px; width:282px; '>";			
								if($mainmode!='view' && $mainmode!='')
									echo"&nbsp;<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Project '  width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistprojectsname(1); return false' /></span></label>

							
							 <td align='right' bgcolor='#F7F7F7' height='25'><span class='style1'> Credit Control </span></td>
							 <td colspan=2  bgcolor='#F7F7F7' height='25'>
								<input type='text' name='credit_control' value='".htmlspecialchars($credit_control, ENT_QUOTES)."'  maxlength='50' $status  style='font-size:12px; width:100px; '></td>";
										 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);

										if($currency=='' && $mainmode=='insert')
											$currency_code=$Client_DefaultCur;
	echo"								
						</tr>
						<tr>
							<td align='left' bgcolor='#F7F7F7' height='25' ><span class='style1'>$costcenter $code_label/$name_label</span></td>
							<td colspan=3> <input type=text name='costcenter_code' value='$costcenter_code' maxlength='30'  readonly size='24' style='font-size:12px; width:90px; '>";
								if($mainmode!='view' && $mainmode!='')
	echo" 									<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Costcenter '  width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistcostcentercode(1); return false' /></span></label> ";
	echo" 									&nbsp;<input type=text name='costcenter_name' value='$costcenter_name' maxlength='100'  readonly size='24' style='font-size:12px; width:282px; '>";			
								if($mainmode!='view' && $mainmode!='')
										echo"&nbsp;<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Costcenter '  width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistcostcentername(1); return false' /></span></label>
							</td>";
								if($sent_email=='1')$selectedmail='checked';
	echo"								<td align='right' bgcolor='#F7F7F7' height='25' ><span class='style1'>$profit_Center</span></td>
							<td> <input type=text name='profit_code' value='$profit_code' maxlength='15'   size='24' style='font-size:12px; width:100px; '></td>
						</tr>";
						
	echo "				<tr bgcolor='#F7F7F7'>
							<td align='left'><span class='style1'>$checkacc</span></td>
							<td><input type=text name='client_checkaccount' value='".htmlspecialchars($client_checkaccount, ENT_QUOTES)."'  maxlength='10' readonly  style='font-size:12px; width:90px; '>";
								if($mainmode!='view' && $mainmode!='')
								echo"&nbsp;<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Check Account '  width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistchkaccount(1); return false' /></span></label>";
	echo"								</td>
							
							 <td align='right' bgcolor='#F7F7F7' height='25'><span class='style1'> $discount_label % </span></td>
							 <td  bgcolor='#F7F7F7' height='25'><input type='text' name='discount' value='$discount' maxlength='3' $status size='3' style='font-size:12px; width:127px; '></td>
							 <td align='right' bgcolor='#F7F7F7' height='25'><span class='style1'>$budgetlimit </span></td>
							 <td colspan= bgcolor='#F7F7F7'><input type='text' name='budget_limit' value='$budget_limit' maxlength='6' $status size='10' style='font-size:12px; width:100px; '></td>";
	echo"								 <input type='hidden' name='client_group' value='$client_group' maxlength='30' readonly size='24' style='font-size:12px; width:80px; '>	
						</tr>";
	
	echo"					<tr bgcolor='#F7F7F7'>
							<td align='left' bgcolor='#F7F7F7' height='25'><span class='style1'>$clientip_currency</span>";
							  if($module=='1')
								 echo"<span class='style26'>*</span>";
	echo"								</td>
							<td  bgcolor='#F7F7F7' height='25'>
								<select  name='currency' onchange='fill_curr();' $status $dis style='width:91px;'>
									<option value=''></option>";
									while ($cr=mysql_fetch_row($curr))
									{
									if (strtoupper($cr[0])==strtoupper($currency_code))
									echo"<option selected value='$cr[0]'>$cr[0]</option>";
									else
									echo"<option value='$cr[0]'>$cr[0]</option>";
									}	
									if($FA_ClientCreditLimit==0)		
										$discreditlimit = ' readonly ';
									else	
										$discreditlimit = '  ';

									if($credit_limit=='' and $actionmode=='')		
										$credit_limit = $client_creditlimit ;
										//,client_paymentterms		
										echo"<input type='hidden' name='currency_code' value='$currency_code'>
							</td>
							<td align='right' bgcolor='#F7F7F7' height='25'><span class='style1'>  $creditlimit </span>";
								if($module=='1')
									echo"<span class='style26'>*</span>";
	echo"								</td>
							<td bgcolor='#F7F7F7'><input type='text' name='credit_limit' value='$credit_limit' $discreditlimit maxlength='15' $status size='14' style='font-size:12px; width:127px; '></td>
							<td  align='right'><span class='style1'>$checkdueterm</span></td>
							<td ><input type=text name='client_chterms' value='$client_chterms' maxlength='6' $status  size='10' style='font-size:12px; width:100px; '></td>
							";
	echo"				</tr>
					</tr>
					
					<tr bgcolor='#F7F7F7' height='25'> 
						<td valign='center' align='left' ><span class='style1'>$customer_type&nbsp;</span>";
							if($module=='1')
								 echo"<span class='style26'>*</span>";
									 
								//if(!isset($client_rating))$client_rating='A';
								if($client_rating=='MM')$selectedtype1='selected';
								if($client_rating=='SM')$selectedtype2='selected';
								if($client_rating=='SMC')$selectedtype3='selected';
								if($client_rating=='WS')$selectedtype4='selected';
								if($client_rating=='PL')$selectedtype5='selected';
								if($client_rating=='EX')$selectedtype6='selected';

	echo"							</td> 
						<td>
						 <select name='customertype' onchange='set_rating();' $dis style='width:91px;'>
							 <option value='' $selectedtype0></option>
							 <option value='MM' $selectedtype1>MM</option>
							 <option value='SM' $selectedtype2>SM</option>
							 <option value='SMC' $selectedtype3>SMC</option>
							 <option value='WS' $selectedtype4>WS</option>
							 <option value='PL' $selectedtype5>PL</option>
							 <option value='EX' $selectedtype5>EX</option>
							</select>
							<input type='hidden' name='client_rating' value='$client_rating'    maxlength='10' style='font-size:12px; width:110px; ' $status>
						</td>";
	echo"							<td align=right><span class='style1'>$vatdate</span></td>
						<td colspan=2><input type='text' readonly name='vat_date' value='$vat_date' maxlength='10' size='8' style='font-size:12px; width:127px; '>&nbsp;";
							if($mainmode!='view' && $mainmode!='' && $client_vat=='1'){
											
							print<<< HERE
	<A HREF="#" onClick="displayCalendar(document.clientdt.vat_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>
					</tr> ";
	echo"						<tr bgcolor='#F7F7F7'>
						<td><span class='style1'>$legalype</span>";
							if($module=='1')echo"<span class='style26'>*</span>";
							if($client_legaltype=='SAL') $selectedlegal1='selected';
							if($client_legaltype=='SARL')$selectedlegal2='selected';
							if($client_legaltype=='LTD')$selectedlegal3='selected';
							if($client_legaltype=='Other') $selectedlegal4='selected';
	echo"							</td>
						<td>
							<select name='legaltype' onchange='set_legaltype();' $dis style='width:91px;'>
								<option value=''>&nbsp;</option>
								<option value='SAL' $selectedlegal1>SAL</option>
								<option value='SARL' $selectedlegal2>SARL</option>
								<option value='LTD' $selectedlegal3>LTD</option> 
								<option value='Other' $selectedlegal4>Other</option>
							</select>";
	echo"							</td>
						<td align='right' bgcolor='#F7F7F7' height='25'><span class='style1'> $sellingprice </span></td>
						<td  bgcolor='#F7F7F7' height='25'>
							<select name='selling_price'  $dis onchange='set_selling();' style='width:127px;'>
								<option value='I' $selectedprice1>Whole Sale</option>
								<option value='II' $selectedprice2>HORECA 1</option>
								<option value='III' $selectedprice3>HORECA 2</option>
								<option value='IV' $selectedprice4>Abuja</option>
								<option value='V' $selectedprice5>Supermarkets</option>
								<option value='VI' $selectedprice6>VI</option>
								<input type='hidden' name='client_sellingprice' value='$client_sellingprice'>
							</select>
						</td>";
	echo"		</tr>";
					
		echo"	<tr bgcolor='#F7F7F7'> ";
		echo"			<td colspan=8 align='left' align='right' bgcolor='#F7F7F7' rowspan=3>
							<table border=0  bgcolor='#d0d0d0' width='500px'>
								<tr>
									<td colspan=4><span class='style1'>$payement_type</span></td>
								<tr>
								<tr>
									<td><span class='style1'>$type1</span>";
										 if($module=='1')
											 echo"<span class='style26'>*</span>";
			echo"										</td>
									<td><span class='style1'>$terms</span>";
										 if($module=='1')
											echo"<span class='style26'>*</span>";
										if(!isset($client_cashmode)) $client_cashmode=0;

			echo"										</td>
									<td><span class='style1'>$term2</span></td>
									<td><span class='style1'>$cl_mode</span></td>
								</tr> ";
									if(!isset($client_paytermtype)) $client_paytermtype='A';
									if($client_paytermtype=='A') $selectedpayment1='selected';
									if($client_paytermtype=='B') $selectedpayment2='selected';
									if($client_paytermtype=='O')$selectedpayment3='selected';
									if($client_paymentterm=='' and $mainmode=='insert' )  
										$client_paymentterm  = $client_paymentterms;		  
			echo"									<tr>
									<td>
										<select name='paymenttype' $discreditlimit onchange='set_paymenttype();' $dis>
											<option value='A' $selectedpayment1>A</option>
											<option value='B' $selectedpayment2>B</option>
											<option value='O' $selectedpayment3>O</option>
											<input type='hidden' name='client_paytermtype' value='$client_paytermtype' maxlength='1' $status  size='1' style='font-size:12px; width:40px; '>
									</td>
									<td><input type=text  $discreditlimit name='client_paymentterm' value='$client_paymentterm' maxlength='6' $status  size='6' style='font-size:12px; width:40px; '></td>
									<td><input type=text  $discreditlimit name='client_paymentterm2' value='$client_paymentterm2' maxlength='6' $status  size='6' style='font-size:12px; width:50px; '></td>
									<td>
									<select name='client_paymentmode' id='client_paymentmode' style='width: 100px'>
									<option value=''></option>";
											
									while($pmd=mysql_fetch_row($resultclientpay)){
									echo"<option ";
									if ($client_paymentmode==$pmd[0])
									echo " selected ";
									echo" value='$pmd[0]'>$pmd[0] | $pmd[1]</option>";
									}
									echo"</select>
									</td>
								</table>
							</td>
						</tr>";

						
	echo"			<tr bgcolor='#F7F7F7'>
						<td colspan=7><input type='hidden' name='client_legaltype' value='$client_legaltype' maxlength='10' $status  size='10' style='font-size:12px; width:80px; '></td>
					</tr>";
	echo" 		</table>
			</td>
		</tr>";
		//fetch table
echo"	<tr>
			<td  valign='top' align='left'>";
	echo"		<table style='width:1100px;' border='0' cellspacing=0>";
	echo"			<tr>
						<td  valign='top' colspan=9  style='width:1100px;'>
							<table style='width:1094px;' border='0' cellspacing=0>
								<col width=10%>
								<col width=10%>
								<col width=26%>
								<col width=26%>
								<col width=26%>
								<tr height='30px' style='background-color:darkgray;'>
									<td>&nbsp;</td>
									<td>&nbsp;</td>
									<td align='left'><span class='style1'><b>$code_label</b></td>
									<td align='center'><span class='style1'><b>$name_label</b></td> 
									<td align='center'><span class='style1'><b>$phone1_label</b></td> 
								</tr>";
	echo"						<tr>
									<td colspan=5>";
									//	<div style='overflow-y:scroll;height:320px;width:1100px;border:0px solid #000000;padding-left:5px;'>
echo"										<table  border='0' width='1100px'>
												<col width=30>
												<col width=30>
												<col width=160>
												<col width=170>
												<col width=170>";

													$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());
													
												//	echo $querysearch;exit;
													$totalrows = mysql_num_rows($resultsearch);
													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' width='1100px' >";
		echo "<td align=center ><img border='0' src='img/print.png' width='13' height='14' title='Delete Detail' onmouseover=\"this.style.cursor='pointer'\" OnClick=\"printClient('$rows[0]')\"></td>";
													if($ClientsDel==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($ClientsMod==1) echo " onclick=SetClient('$rows[0]');";echo"><span class='$stylefont' >$rows[0]&nbsp;</span></font></td>
													<td style='cursor:pointer;' ";if($ClientsMod==1) echo " onclick=SetClient('$rows[0]');";echo"><font face='Arial' size='2' color='#186194'><span class='$stylefont'>$rows[1]&nbsp;</span></font></td>";
	echo"";
	echo"					<td> <span class=\"style15\" style = 'cursor:pointer;' ";
	
	if($ClientsMod==1) echo " onclick=SetClient('$rows[0]');";
echo "	> $rows[2] </span> </td>					</tr>";
												}		
		
	echo"									</table>";
									//	</div>
	echo"							</td>
								</tr>
							</table>
						</td>
					</tr>";	
	echo"		</table>
			</td>
		</tr>
	</table>";

$tabs->end();
	
$tabs->start("$tab2");

		
echo"	<table border='0' style='table-layout:fixed' align='left' width='1100px' valign='top'>";
echo"		<col width=60>
			<col width=80>
			<col width=50>
			<col width=80>
			<col width=50>
			<col width=80>
			<col width=50>
			<col width=80>";
			
echo"		<tr bgcolor='#F7F7F7' height='35'>
				<td><span class='style1'>$country_label</span></td>
				<td ><input type=text name='country' value='".htmlspecialchars($country, ENT_QUOTES)."'  maxlength='32' $status size=32 style='font-size:12px; width:183px '></td>
				<td align=right><span class='style1'>$state_label</span></td>
				<td ><input type=text name=state value='".htmlspecialchars($state, ENT_QUOTES)."'  maxlength='32' $status style='font-size:12px; '></td>
				<td align=right><span class='style1'>$city_label</span></td>
				<td ><input type='text' name='city_client' value='".htmlspecialchars($city_client, ENT_QUOTES)."'  maxlength='32' $status size=25 style='font-size:12px; '></td>
				<td align='right'><span class='style1'>$email_label </span></td>
				<td><input type='text' name='email' value='".htmlspecialchars($email, ENT_QUOTES)."' size='25' maxlength='100' $status style='font-size:12px; '></td>
			</tr>";
			
echo"		<tr bgcolor='#F7F7F7' height='35'>
				<td><span class='style1'>$home_page</span></td>
				<td><input type='text' name='homepage' value='".htmlspecialchars($homepage, ENT_QUOTES)."'  size='32' maxlength='100' $status style='font-size:12px; width:183px;'></td>
				<td align='right'> <span class='style1'>$phone1_label </span>";
					 if($module=='1')
						echo"<span class='style26'>*</span>";
echo"			</td>
				<td><input type='text' name='phone1' value='$phone1' maxlength='25'  $status style='font-size:12px;'></td>
				<td align='right'><span class='style1'>$phone2_label </span></td>
				<td ><input type='text' name='phone2' value='$phone2' maxlength='25' size='25' $status style='font-size:12px;'></td>
				<td align='right'><span class='style1'>$phone3_label </span></td>
				<td><input type='text' name='phone3' value='$phone3' maxlength='25' size='25' $status style='font-size:12px;' ></td>
			</tr>";
echo"		<tr bgcolor='#F7F7F7' height='35'>
				<td><span class='style1'>$area</span>";
					 if($module=='1')
						 echo"<span class='style26'>*</span>";
echo"			</td>"; 

echo"			<td colspan=3>
					<input type='text' name='area_code' value='".htmlspecialchars($area_code, ENT_QUOTES)."'  readonly style='font-size:12px; width:183px; '>&nbsp;";
					if($mainmode!='view' && $mainmode!='')
						echo"<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Area '  width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistarea(1); return false' /></span></label>&nbsp;";	
echo"					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<input type='text' name='areaname' value='".htmlspecialchars($areaname, ENT_QUOTES)."' readonly size='31' style='font-size:12px; width:157px; '>
				</td>
				
				<td align='right'><span class='style1'>$pobox_label</span> </td>
				<td><input  type='text' name='pobox' size='25' value='".htmlspecialchars($pobox, ENT_QUOTES)."' maxlength='20' $status style='font-size:12px; '></td>
				<td align='right'><span class='style1'>$fax_label</span></td>
				<td ><input type='text' name='fax' size='25' value='".htmlspecialchars($fax, ENT_QUOTES)."'  maxlength='25' $status style='font-size:12px;'></td>
			</tr> ";
			
echo"		<tr bgcolor='#F7F7F7' height='35'>
				<td><span class='style1'>$technicalperson</span></td>
				<td><input  type='text' name='technical_person' size='30' value='".htmlspecialchars($technical_person, ENT_QUOTES)."' maxlength='60' $status style='font-size:12px; width:183px'></td>
				<td></td>
				<td colspan=2 align='right'><span class='style1'>$technicalemail</span></td>
				<td><input  type='text' name='technical_email' size='25'  value='".htmlspecialchars($technical_email, ENT_QUOTES)."' maxlength='100' $status style='font-size:12px; '></td>
			</tr>";		
			
echo"		<tr bgcolor='#F7F7F7' height='55'>
				<td><span class='style1'><span class='style1'>$address_label</span>";
				   if($module=='1')
					 echo"<span class='style26'>*</span>";

echo"			</td>
				<td colspan=2 ><textarea name='Address'  size=100% maxlength='100' cols=46 rows=3 $status onKeyDown='textCounter(this.form.Address,this.form.remLenaddress,100);' onKeyUp='textCounter(this.form.Address,this.form.remLenaddress,100)';>".htmlspecialchars($Address, ENT_QUOTES)."</textarea></td>
				<td></td>
				<td align='right'><span class='style1'><span class='style1'>$address2_label</span></td>
				<td ><textarea name='Address2'  size=100% cols=52 rows=3 maxlength='100' $status onKeyDown='textCounter(this.form.Address2,this.form.remLenaddress2,100);' onKeyUp='textCounter(this.form.Address2,this.form.remLenaddress2,100)';>".htmlspecialchars($Address2, ENT_QUOTES)."</textarea></td>
				
			</tr>";   
			
				$lenAddress=strlen($Address);
				$restaddress=100-$lenAddress;
				
				$lenAddress2=strlen($Address2);
				$restaddress2=100-$lenAddress2;	

				$lenAddress3=strlen($Address3);
				$restaddress3=100-$lenAddress3;	
	
echo"	  	<tr bgcolor='#F7F7F7' height='25'>
				<td></td>
				<td colspan=4 align=center valign='top'><span class='style12'>Remaining Chars</span>&nbsp;<input readonly type=text name=remLenaddress size=1 maxlength=3 value='$restaddress' style='font-size:11px; width:25px;  border:none; background-color:#F7F7F7; '></td>
				<td colspan=2 align=center valign='top'><span class='style12'>Remaining Chars</span>&nbsp;&nbsp;<input readonly type=text name=remLenaddress2 size=1 maxlength=3 value='$restaddress2' style='font-size:11px; width:25px;  border:none; background-color:#F7F7F7; '></td>
			</tr>";  

 echo"		<tr bgcolor='#F7F7F7' height='35'>
				<td><span class='style1'><span class='style1'>$address3_label</span></td>
				<td ><textarea name='Address3'  size=100% cols=46 rows=3 maxlength='100' $status onKeyDown='textCounter(this.form.Address3,this.form.remLenaddress3,100);' onKeyUp='textCounter(this.form.Address3,this.form.remLenaddress3,100)';>".htmlspecialchars($Address3, ENT_QUOTES)."</textarea></td>

			</tr>";  
				$lenAddress3=strlen($Address3);
				$restaddress3=100-$lenAddress3;	
echo"		<tr bgcolor='#F7F7F7' height='35'>
				<td></td>
				<td colspan=3 align=center valign='top'><span class='style12'>Remaining Chars</span>&nbsp;&nbsp;<input readonly type=text name=remLenaddress3 size=1 maxlength=3 value='$restaddress3' style='font-size:11px; width:25px;  border:none; background-color:#F7F7F7; '></td>
			</tr>";

			//fetch table
echo"	<tr>
			<td  valign='top' align='left'>";
	echo"		<table style='width:1100px;' border='0' cellspacing=0>";
	echo"			<tr>
						<td  valign='top' colspan=9  style='width:1100px;'>
							<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>";
	echo"						<tr>
									<td colspan=3>";
									//	<div style='overflow-y:scroll;height:320px;width:1100px;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());
													$totalrows = mysql_num_rows($resultsearch);
													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' width='1100px' >";
		
													if($ClientsDel==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($ClientsMod==1) echo " onclick=SetClient('$rows[0]');";echo"><span class='$stylefont' >$rows[0]&nbsp;</span></font></td>
													<td style='cursor:pointer;' ";if($ClientsMod==1) echo " onclick=SetClient('$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>";	
	echo"		</table>
			</td>
		</tr>";
		
echo"	</table>";
$tabs->end();

if($module_sellingbyclient == 1){
$tabs->start(" $tab3");

echo "<div id='loading'><img src='js\grid\ajax-loader.gif' /></div>";
echo"	<table border='0'  align='left' valign='top' width='1080px'>";
echo"<col width=80><col width=460><col width=80><col width=460>";	

echo "<tr><td colspan='2'><button type='button' id='btnPClear' name='btnPClear' onclick=\"clearSelling();\" title='Clear'><span><span>Clear</span></span></button>
		<button type='button' id='btnPSearch' name='btnPSearch' onclick=\"searchSelling();\" title='Search'><span><span>Search</span></span></button>
		<button type='button' id='btnPHistory' name='btnPHistory' onclick=\"viewHistory();\" title='History'><span><span>History</span></span></button></td></tr>";

echo "<tr bgcolor='#F7F7F7' height='25px'><td><span class='style1'>$groupclient</span></td><td><input type='text' name='group_code' id='group_code' value='$group_code' readonly style='width:160px;' >
<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Group ' width='15' height='15' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showpricelistgroups(6); '  /></span></label>
<input type='text' name='group_name' id='group_name' value='$group_name' readonly style='width:260px;'></td>";
echo "<td><span class='style1'>$subgroup_label</span></td>";
echo "<td><input type='text' name='subgroup_code' id='subgroup_code' value='$subgroup_code' readonly style='width:160px;'>
	<label><span class='style1'><img src='img/btnopen.jpg' title=' Select SubGroup ' width='15' height='15' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showpricelistsubgroups(4); '  /></span></label>
	<input type='text' name='subgroup_name' id='subgroup_name' value='$subgroup_name' readonly style='width:260px;'>
	</td>";
echo"</tr>";

echo "<tr bgcolor='#F7F7F7'><td><span class='style1'>$category</td><td><input type='text' name='itemcategory_code' id='itemcategory_code' value='$itemcategory_code'  style='width:160px;' readonly>
	<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Category ' width='15' height='15' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showpricelistcategory(2); '  /></span></label>
	<input type='text' name='itemcategory_name' id='itemcategory_name' value='$itemcategory_name' readonly style='width:260px;' ></td>";	
echo "<td><span class='style1'>$items_label</span></td><td><input type='text' name='item_code' id='item_code' value='$item_code'  style='width:160px;' readonly>
<label><span class='style1'><img src='img/btnopen.jpg' title='Select Item' id='lstItem' width='15' height='15' border='0' onMouseOver=\"style.cursor='hand'\"  onClick='showlistItems(8);' /></span></label>
		<input type='text' name='item_description' id='item_description' value='$item_description' readonly style='width:260px;'></td>";	
echo "</tr>";


echo "<tr bgcolor='#F7F7F7' height='30px'><td colspan='4'></td></tr>";	

if($ledger_number != ''){
$queryitems = "select items.Item_Code as itemcode,Item_Description,sellingprice,sellingpriceb1,sellingpriceb2,sp.currency_code as selling_currency,sellingprice_id
				from items
				left join sellingPriceByClient sp on sp.item_code = items.Item_Code and client_code = '$ledger_number'
				where 1=1 ";
if ($group_code != '')
		$queryitems = $queryitems." and Group_code = '$group_code' "; 
if ($subgroup_code != '')
		$queryitems = $queryitems." and SubGroup_Code = '$subgroup_code' "; 	
if ($itemcategory_code != '')
		$queryitems = $queryitems." and Category_code = '$itemcategory_code' "; 
if ($item_code != '')
		$queryitems = $queryitems." and items.Item_Code = '$item_code' "; 	
	$queryitems = $queryitems." order by items.item_code ";
	$resultsearch=mysql_query($queryitems,$connection) or die(mysql_error());
	$totalrows2 = mysql_num_rows($resultsearch);

if ($group_code == '' && $subgroup_code == '' && $itemcategory_code == '' && $item_code == ''){	
if ($startrange2=='')
$startrange2 = 0;
if ($perpage=='')
$perpage = 20;
$queryitems = $queryitems." limit ".$startrange2.",".$perpage;
}
	
$resitems = mysql_query($queryitems,$connection);				
echo "<tr bgcolor='#F7F7F7'><td colspan='4'><table border='0'  align='left' valign='top' width='1080px'>";
echo "<col width='35px'><col width='350px'><col width='90px'><col width='190px'><col width='190px'><col width='190px'><col width='35px'>";
echo "<tr><td></td><td><span class='style1'>$items_label $code_label / $description</span></td><td><span class='style1'>$clientip_currency</span></td><td><span class='style1'>Selling Price</span></td>
		<td><span class='style1'>$sellingprice $base1</span></td><td><span class='style1'>$sellingprice $base2</span></td><td></td>";
echo "</tr>";
$i=0;		
while($rwsitems = mysql_fetch_array($resitems)){
	extract($rwsitems);
	
	$pitemcode = "itemcode".$i;
	$pItem_Description = "Item_Description".$i;
	$pcurrencycode = "pcurrencycode".$i;
	$psellingprice = "sellingprice".$i;
	$psellingpriceb1 = "sellingpriceb1".$i;
	$psellingpriceb2 = "sellingpriceb2".$i;
	if($selling_currency == '') $selling_currency=$Client_DefaultCur;
	
	echo "<tr><td><img src='img/undo-1.png' width='20' height='20' border='0' onmouseover=\"style.cursor='pointer'\" onclick=\"deleteSellingPrice('$sellingprice_id');\" title='Delete Record' style='vertical-align: bottom; cursor: pointer;'></td>";
	echo "<td><input type='text' name='$pitemcode' id='$pitemcode' value='$itemcode' readonly style='width:110px;'> - <input type='text' name='$pItem_Description' id='$pItem_Description' value='$Item_Description' readonly style='width:210px;'></td>";
	echo "<td><select name='$pcurrencycode' id='$pcurrencycode' onchange=\"setAmountbase('$DecimalBase1', '$DecimalBase2','$base1', '$base2', '$creation_date', '$i');\">";
		$query_currency="select currency_code from currency";
		$result_currency=mysql_query($query_currency,$connection)	or die( mysql_error());
		echo "<option>&nbsp;</option>";
	while ($row_currency=mysql_fetch_row($result_currency)){
		echo "<option value='$row_currency[0]'  ".($row_currency[0]==$selling_currency?'selected':'').">$row_currency[0]</option>";
	}
	echo "</select></td>";
	echo "<td><input type='text' name='$psellingprice' id='$psellingprice' value='$sellingprice' onkeyup=\"setAmountbase('$DecimalBase1', '$DecimalBase2','$base1', '$base2', '$creation_date', '$i');\"></td>";
	echo "<td><input type='text' name='$psellingpriceb1' id='$psellingpriceb1' value='$sellingpriceb1' readonly ></td>";
	echo "<td><input type='text' name='$psellingpriceb2' id='$psellingpriceb2' value='$sellingpriceb2' readonly></td>";
	echo "<td><input type='button' id='imgSubmit[0]' onclick=\"submitSellprice('$i','$sellingprice_id')\" title='Submit Record' style='width:20px; height:20px; vertical-align:bottom; cursor:pointer; outline:none; border:0px; background-image:url(img/confirm-1.png)'></td>";
	echo "</tr>";
	$i++;
}	
echo "</table></td></tr>";
echo "<tr><td align='center'>";
							$diff= $startrange2 - $perpage;
							if (($diff) >= 0 ){
								$prvstartrange = $startrange2 - $perpage;
								echo"<img src='img/arrowleft.png' title='Previous' onMouseOver=\"style.cursor='hand'\"  onclick=SetPrvPage2('".$prvstartrange."','".$perpage."')>";
							}
							else
								echo "&nbsp;";
echo"					</td>
						<td  align='center' width='150px'>";
								if ($startrange2 <= $totalrows2){
									$startrange2 = $startrange2 + $perpage;
									if  ($startrange2 <= $totalrows2)
										echo"<img src='img/arrowright.png' title='Next' onMouseOver=\"style.cursor='hand'\" onclick=SetNextPage2('".$startrange2."','".$perpage."')>";
								} else
									echo "&nbsp;";
echo "					</td></tr>";
}
echo "</table>";			
$tabs->end();
}					
					
$tabs->start("Contact");
		
echo"	<table border='0'  align='left' valign='top'>";
			echo"<col width=90>
				 <col width=140>
				 <col width=90>
				 <col width=140>
				 <col width=60>
				 <col width=140> 
				 <col width=15>";	


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);

$result_titleowner=get_titles($connection);
$result_titlerefered=get_titles($connection);
$result_titleassistant=get_titles($connection);


 if(!isset($client_type)) $client_type='A';
		  
	echo"	<tr>
				<td colspan=7>
					<div style='overflow:scroll;height:200px;width:1100px;border:0px solid #000000;'>
						<table  border='0' width='1100px'>
							<col width='100'>
							<col width='100'>
							<col width='100'>
							<col width='100'>
							<col width='100'>
							<col width='100'>
							<col width='100'>
							<col width='100'>
							<col width='100'>
							<col width='100'>
							<col width='100'>
							<col width='100'>
							<col width='100'>
							<col width='100'>
						<tr bgcolor='#D0D0D0' height='25px'>
							<td></td>
							<td></td>
							<td align='center'><span class='style27'>$title_label<span class='style26'>*</span></span></td>
							<td align='center'><span class='style27'> $firstname_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'>$telephoneNo_label<span class='style26'>*</span></span></td>
							<td align='center'><span class='style27'>$telephoneNo2_label</span></td>
							<td align='center'><span class='style27'>$telephoneNo3_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'>$city3_label</span></td>
						</tr>";
echo"					<tr>
							<td valign=center>";
								echo"<button type='button' id='btnPost' name='btnPost' onclick='SubmitRecord(2); return false;' title='Save Changes' $Insmode><span><span>Submit</span></span></button>";
			echo"			</td>";	
						echo"<td valign=bottom>
								<button type='button' id='clearbutton' name='clearbutton' onclick='cleardetail(); return false;' title='Clear Detail'><span><span>Clear</span></span></button>";
echo"&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>";
echo "<tr height='15px'></tr>";
				//fetch table
echo"	<tr>
			<td  valign='top' align='left'>";
	echo"		<table style='width:1100px;' border='0' cellspacing=0>";
	echo"			<tr>
						<td  valign='top' colspan=9  style='width:1100px;'>
							<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>";
	echo"						<tr>
									<td colspan=3>";
									//	<div style='overflow-y:scroll;height:320px;width:1100px;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());
													$totalrows = mysql_num_rows($resultsearch);
													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' width='1100px' >";
		
													if($ClientsDel==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($ClientsMod==1) echo " onclick=SetClient('$rows[0]');";echo"><span class='$stylefont' >$rows[0]&nbsp;</span></font></td>
													<td style='cursor:pointer;' ";if($ClientsMod==1) echo " onclick=SetClient('$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>";	
	echo"		</table>
			</td>
		</tr>";
		

echo"</table>";
$tabs->end();
					  
$tabs->start("$tab5");				  
echo"	<table border='0' style='table-layout:fixed' align='left' valign='top' width='100%'>
			<col width=150>
			<col width=150>
			<col width=250>
			<col width=200>
			<col width=50>
			<col width=100>";
	
echo"		<tr bgcolor='#F7F7F7' height='35'>
				<td><span class='style1'>$agent $code_label/$name_label</span></td>
				<td align=left><input type=text name='agent_code' value='$agent_code' maxlength='10' $status readonly size='10' style='font-size:12px; width:100px; '>&nbsp;";
		
					if($mainmode!='view' && $mainmode!='')
					echo"<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Agent '  width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistagentscode(1); return false' /></span></label>";
echo"			</td>
				<td align=left><input type=text name='agent_name' value='$agent_name' maxlength='10' $status readonly size='10' style='font-size:12px; width:176px; '>";

					if($mainmode!='view' && $mainmode!='')
						 echo" <label><span class='style1'><img src='img/btnopen.jpg' title=' Select Agent '  width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistagentsname(1); return false' /></span></label>";
echo" 			</td>
				<td align='left'><span class='style1'>$owner $title_label/$name_label</span></td>
				<td>
					<select name='titleowner_description' onchange='set_titleowner()' $dis>";
					echo"<option value=''></option>";
					while ($rowwp=mysql_fetch_row($result_titleowner)){
						if ($title_owner==$rowwp[1])
							echo "<option value='$rowwp[1]' selected>$rowwp[1]</option>";
						else
							echo "<option value='$rowwp[1]'>$rowwp[1]</option>";
					}
							
echo"				</select>
				</td>
				<td align=left><input type=text name='client_companyowner' value='".htmlspecialchars($client_companyowner, ENT_QUOTES)."' maxlength='50' $status  size='20' style='font-size:12px; width:200px; '></td>";
echo"		</tr>";
echo"		<tr bgcolor='#F7F7F7' height='35'>
				<td><span class='style1'>$mother_company $code_label/$name_label</span></td>
				<td align=left><input type=text name='client_mothercompany' value='$client_mothercompany' maxlength='10' $status readonly size='30' style='font-size:12px; width:100px; '>&nbsp;";
						  
					if($mainmode!='view' && $mainmode!='')
						  echo"<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Company '  width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistcompaniescode(1); return false' /></span></label>";
  echo"			</td>
				<td align=left ><input type=text name='client_companyname' value='$client_companyname' maxlength='10' $status readonly size='30' style='font-size:12px; width:176px; '>";
					if($mainmode!='view' && $mainmode!='')
						 echo"&nbsp;<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Company '  width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistcompaniesname(1); return false' /></span></label>";
echo"			</td>
				<td ><span class='style1'>$referredby $title_label/$name_label</span></td>
				<td>
					<select name='titlerefered_description' onchange='set_titlerefered()' $dis>";
						echo"<option value=''></option>";
						while ($rowwp=mysql_fetch_row($result_titlerefered)){
							if ($title_refered==$rowwp[1])
							echo "<option value='$rowwp[1]' selected>$rowwp[1]</option>";
							else
							echo "<option value='$rowwp[1]'>$rowwp[1]</option>";
						}
			
echo"				</select>
				</td>
				<td align=left><input type=text name='client_referedby' value='".htmlspecialchars($client_referedby, ENT_QUOTES)."'  maxlength='50' $status  size='20' style='font-size:12px; width:200px; '></td>";
echo"		</tr>";

echo"		<tr bgcolor='#F7F7F7' height='70'>
				<td><span class='style1'><span class='style1'>$business_type1</span>";
					$lenbussiness_type=strlen($bussiness_type);
					$restbussiness=50-$lenbussiness_type;
echo"			</td>
				<td colspan=3>
					<textarea name='bussiness_type'  size=100% maxlength='100' cols=40 rows=3 $status onKeyDown='textCounter(this.form.bussiness_type,this.form.remLenbusiness,50);' onKeyUp='textCounter(this.form.bussiness_type,this.form.remLenbusiness,50)';>".htmlspecialchars($bussiness_type, ENT_QUOTES)."</textarea></td>
			</tr>";     
echo"	 	<tr bgcolor='#F7F7F7' height='25'>
				<td colspan=3 align=center valign=top><span class='style12'>Remaining Chars</span>&nbsp;<input readonly type=text name=remLenbusiness size=1 maxlength=3 value='$restbussiness' style='font-size:11px; width:25px;  border:none; background-color:#F7F7F7; '></td><td>&nbsp;</td>
			</tr>";  

	
echo"		<tr bgcolor='#F7F7F7' height='35'></tr>";
			
							//fetch table
echo"	<tr>
			<td  valign='top' align='left'>";
	echo"		<table style='width:1100px;' border='0' cellspacing=0>";
	echo"			<tr>
						<td  valign='top' colspan=9  style='width:1100px;'>
							<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>";
	echo"						<tr>
									<td colspan=3>";
									//	<div style='overflow-y:scroll;height:320px;width:1100px;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());
													$totalrows = mysql_num_rows($resultsearch);
													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' width='1100px' >";
		
													if($ClientsDel==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($ClientsMod==1) echo " onclick=SetClient('$rows[0]');";echo"><span class='$stylefont' >$rows[0]&nbsp;</span></font></td>
													<td style='cursor:pointer;' ";if($ClientsMod==1) echo " onclick=SetClient('$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>";	
	echo"		</table>
			</td>
		</tr>";
			
echo"</table>";
	
$tabs->end();
	
	
$tabs->start("$tab6");				  
	echo"<table border='0' style='table-layout:fixed' align='left' valign='top' width='1100px'>
			<col width=100>
			<col width=250>
			<col width=170>
			<col width=300>
			<col width=80> 
			<col width=150>";
		  
echo"		<tr bgcolor='#F7F7F7' height='35'>
				<td align=left ><span class='style1'>$sd1no</span></td>
				<td align=left><input type=text name='client_sdino' value='$client_sdino' maxlength='30' $status  size='20' style='font-size:12px; width:120px; '>
				<td align='right' colspan='2'><span class='style1'>$assistant $title_label/$name_label</span>
					<select name='titleassistant_description' onchange='set_titleassistant()' $dis>";
	echo"				<option value=''></option>";
						while ($rowwp=mysql_fetch_row($result_titleassistant)){
							if ($title_assistant==$rowwp[1])
							echo "<option value='$rowwp[1]' selected>$rowwp[1]</option>";
							else
							echo "<option value='$rowwp[1]'>$rowwp[1]</option>";
						}
			
echo"				</select>&nbsp;
					<input type=text name='client_deliveryassistant' value='".htmlspecialchars($client_deliveryassistant, ENT_QUOTES)."'  maxlength='50' $status  size='20' style='font-size:12px; width:160px; '>
				</td>
				<td align='center'><span class='style1'>$work_title &nbsp;</span></td>
				<td><input type=text name='client_dlvworktitle' value='".htmlspecialchars($client_dlvworktitle, ENT_QUOTES)."'  maxlength='30' $status  size='20' style='font-size:12px; width:157px; '></td>	
			</tr>";
			
			$querywarehouse="select warehouse_code,warehouse_name from warehouse order by warehouse_code";
			$resultwarehouse=mysql_query($querywarehouse,$connection) or die(mysql_error());
				
echo"		<tr bgcolor='#F7F7F7' height='35'>";
//<td align='center'><span class='style1'>Fax &nbsp;</td><td></span><input type='text' name='delivery_fax' value='".htmlspecialchars($delivery_fax, ENT_QUOTES)."'  maxlength='25' $status style='font-size:12px; width:120px; '>

echo"			<td><span class='style1'>$area</span>";
					 if($module=='1')
						echo"<span class='style26'>*</span>";
echo"			</td>"; 
echo"			<td colspan=2>
					<input type='text' name='delivery_areacode' maxlength=20 value='$delivery_areacode' readonly style='font-size:12px;'>";
					if($mainmode!='view' && $mainmode!='')
						echo"&nbsp;<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Area '  width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistareaDelivery(2); return false' /></span></label>";
						echo"";				
						echo"&nbsp;<input type='text' name='delivery_areaname' value='$delivery_areaname' readonly size='35' style='font-size:12px;'>
				</td>
				<td align='right'><span class='style1'>$warehouse_label</span>&nbsp;<input size='80' type='text' name='warehouse' value='$warehouse' maxlength='15' $status style='font-size:12px; width:160px; '>";
					if($mainmode!='view' && $mainmode!='')
						echo"&nbsp;<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Warehouse '  width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistwarehouse(2); return false' /></span></label>";   
echo" 			</td>
				<td><span class='style1'> &nbsp;$delivery  </span></td>
				<td ><input type='text' name='delivery_phone' value='".htmlspecialchars($delivery_phone, ENT_QUOTES)."'  maxlength='25' $status style='font-size:12px; '></td>				
			</tr>"; 

				$lendeliveryaddress=strlen($client_deliveryaddress);
				$restdeliveryaddress=100-$lendeliveryaddress;

				$lendeliveryaddress2=strlen($client_deliveryaddress2);
				$restdeliveryaddress2=100-$lendeliveryaddress2;

				$lendeliveryaddress3=strlen($client_deliveryaddress3);
				$restdeliveryaddress3=100-$lendeliveryaddress3;

echo"		<tr bgcolor='#F7F7F7' height='70'>
				<td><span class='style1'><span class='style1'>$address_label</span>";
					if($module=='1')
						echo"<span class='style26'>*</span>";
echo"			</td>
				<td colspan=1><textarea name='client_deliveryaddress' maxlength='100' cols=40 rows=4 $status onKeyDown='textCounter(this.form.client_deliveryaddress,this.form.remLen,100);' onKeyUp='textCounter(this.form.client_deliveryaddress,this.form.remLen,100)';>".htmlspecialchars($client_deliveryaddress, ENT_QUOTES)."</textarea></td>
				<td align='right'><span class='style1'><span class='style1'>$address2_label</span></td>
				<td ><textarea name='client_deliveryaddress2'  maxlength='100' cols=40 rows=4 $status onKeyDown='textCounter(this.form.client_deliveryaddress2,this.form.remLen2,100);' onKeyUp='textCounter(this.form.client_deliveryaddress2,this.form.remLen2,100)';>".htmlspecialchars($client_deliveryaddress2, ENT_QUOTES)."</textarea></td>
				
			</tr>";

				
echo"		<tr bgcolor='#F7F7F7' height='25'>
				<td  align=center colspan=2><span class='style12'>Remaining Char</span>&nbsp;<input readonly type=text name=remLen size=1 maxlength=3 value='$restdeliveryaddress' style='font-size:11px; width:25px;  border:none; background-color:#F7F7F7;' ></td>
				<td  align=center colspan=4><span class='style12'>Remaining Char</span>&nbsp;<input readonly type=text name=remLen2 size=1 maxlength=3 value='$restdeliveryaddress2' style='font-size:11px; width:25px;  border:none; background-color:#F7F7F7;' ></td>
			</tr>";    

echo"		<tr bgcolor='#F7F7F7' height='70'>
				<td><span class='style1'><span class='style1'>$address3_label</span></td>
				<td colspan=3><textarea name='client_deliveryaddress3'  size=100% maxlength='100' cols=40 rows=4 $status onKeyDown='textCounter(this.form.client_deliveryaddress3,this.form.remLen3,100);' onKeyUp='textCounter(this.form.client_deliveryaddress3,this.form.remLen3,100)';>".htmlspecialchars($client_deliveryaddress3, ENT_QUOTES)."</textarea></td>
			</tr>";    
echo"		<tr bgcolor='#F7F7F7' height='25'>
				<td  align=center colspan=2><span class='style12'>Remaining Char</span>&nbsp;<input readonly type=text name=remLen3 size=1 maxlength=3 value='$restdeliveryaddress3' style='font-size:11px; width:25px;  border:none; background-color:#F7F7F7;' ></td>
			</tr>";
echo"<tr height='15px'></tr>";								

	//fetch table
echo"	<tr>
			<td  valign='top' align='left'>";
	echo"		<table style='width:1100px;' border='0' cellspacing=0>";
	echo"			<tr>
						<td  valign='top' colspan=9  style='width:1100px;'>
							<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>";
	echo"						<tr>
									<td colspan=3>";
									//	<div style='overflow-y:scroll;height:320px;width:1100px;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());
													$totalrows = mysql_num_rows($resultsearch);
													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' width='1100px' >";
		
													if($ClientsDel==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($ClientsMod==1) echo " onclick=SetClient('$rows[0]');";echo"><span class='$stylefont' >$rows[0]&nbsp;</span></font></td>
													<td style='cursor:pointer;' ";if($ClientsMod==1) echo " onclick=SetClient('$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>";	
	echo"		</table>
			</td>
		</tr>";
echo"</table>";  

$tabs->end();
				
//// Others Tab			
$tabs->start("$tab7");		
		  
echo"	<table border='0' style='table-layout:fixed' align='left' valign='top' width='1100px'>
			<col width=111>
			<col width=100>
			<col width=120>
			<col width=150>
			<col width=135> 
			<col width=150>";
			
			  	if(!isset($invoice_language))$invoice_language='Arabic';
				if($invoice_language=='Arabic')$selectedarabic='selected';
				if($invoice_language=='French')$selectedfrench='selected';

				if($invoice_language=='English')$selectedenglish='selected';
				
echo"		<tr bgcolor='#F7F7F7' height='35'>
				<td align=left style='width:100px'><span class='style1'>$sd1no</span>";
		  
					 if($module=='1')
						 echo"<span class='style26'>*</span>";
echo"			</td>
				<td align=left ><input type=text name='client_gcino' value='$client_gcino' maxlength='6' $status  size='10' style='font-size:12px;'></td>
				<td align=left ><span class='style1'>$archivefile.</span></td>
				<td align=left ><input type=text name='client_archivefileno' value='".htmlspecialchars($client_archivefileno, ENT_QUOTES)."' maxlength='20' $status  size='30' style='font-size:12px; width:150px; '></td>
			`	<td align=left ><span class='style1'>$invoicelanguage</span></td>
				<td >
					<select name='language'  $status $dis onchange='set_language();' style='width:80px;'>
						<option value='Arabic' $selectedarabic>Arabic</option>
						<option value='French' $selectedfrench>French</option>
						<option value='English' $selectedenglish>English</option>
					</select>
					<input type='hidden' name='invoice_language' value='$invoice_language'>
				</td>
				<td align=left ><span class='style1'>$delivery_label/SOF</span></td>
				<td >
					<select name='delivsof' $dis style='width:80px;'>
						<option value=''></option>
						<option value='delivery';";if(strtoupper($delivsof)=='DELIVERY') echo " selected ";echo" >Delivery</option>
						<option value='sof';";if(strtoupper($delivsof)=='SOF') echo " selected ";echo">SOF</option>
					</select>
					<input type='hidden' name='invoice_language' value='$invoice_language'>
				</td>
			</tr>
			
			<tr bgcolor='#F7F7F7' height='45' > 
				<td>
					<table border='0' style='table-layout:fixed' align='left' valign='top' width='1100px'>
						<col width=100>
						<col width=400>
						<col width=115>
						<col width=400>
						<tr bgcolor='#F7F7F7'>
							<td align=left ><span class='style1'>$majorstrenght</span></td>
							<td ><textarea name='client_evaluationpoints'  size=100% maxlength='100' cols=45 rows=2 $status onKeyDown='textCounter(this.form.client_evaluationpoints,this.form.remLenevaluation,100);' onKeyUp='textCounter(this.form.client_evaluationpoints,this.form.remLenevaluation,100)';>".htmlspecialchars($client_evaluationpoints, ENT_QUOTES)."</textarea></td>
							<td align=left ><span class='style1'>$weakness_label</span></td>
							<td ><textarea name='client_weakness'  size=100% maxlength='100' cols=45 rows=2 $status onKeyDown='textCounter(this.form.client_weakness,this.form.remLenweakness,50);' onKeyUp='textCounter(this.form.client_weakness,this.form.remLenweakness,50)';>".htmlspecialchars($client_weakness, ENT_QUOTES)."</textarea></td>
						</tr>";
						$lenevaluation=strlen($client_evaluationpoints);
						$restevaluation=100-$lenevaluation;
						$lenweakness=strlen($client_weakness);
						$restweakness=50-$lenweakness;
						$lentips=strlen($client_tips);
						$remLentips=1000-$lentips;
echo"					<tr bgcolor='#F7F7F7'>
							<td>&nbsp;&nbsp;&nbsp;</td>
							<td align=center><span class='style12'>Remaining Char</span>&nbsp;<input readonly type=text name=remLenevaluation size=1 maxlength=3 value='$restevaluation' style='font-size:11px; width:25px;  border:none; background-color:#F7F7F7;' ></td>
							<td>&nbsp;&nbsp;&nbsp;</td>";
							if($client_invrounded=='1')$selectedinvoice='checked';
echo"						
							<td align=center><span class='style12'>Remaining Char</span>&nbsp;<input readonly type=text name=remLenweakness size=1 maxlength=3 value='$restweakness' style='font-size:11px; width:25px;  border:none; background-color:#F7F7F7;' ></td>
						</tr>
						<tr bgcolor='#F7F7F7' height='40'>
							<td align=left ><span class='style1'>$tips</span></td>
							<td ><textarea name='client_tips'  size=100% maxlength='1000' cols=45 rows=2 $status onKeyDown='textCounter(this.form.client_tips,this.form.remLentips,1000);' onKeyUp='textCounter(this.form.client_tips,this.form.remLentips,1000)';>".htmlspecialchars($client_tips, ENT_QUOTES)."</textarea></td>
							<td align=left ><span class='style1'>$remark</span></td>
							<td align=left ><input type=text name='client_remark' value='".htmlspecialchars($client_remark, ENT_QUOTES)."'  maxlength='100' $status   style='font-size:12px; width:383px; '></td>
						</tr>
						<tr bgcolor='#F7F7F7' height='35'>
							<td></td>
							<td align=center><span class='style12'>Remaining Char</span>&nbsp;<input readonly type=text name=remLentips size=1 maxlength=3 value='$remLentips' style='font-size:11px; width:25px;  border:none; background-color:#F7F7F7;' ></td>
							<td align=left ><span class='style1'>$invoice_rounded_label</span></td>
							<td align=left colspan=3>
								<input type=checkbox name='invoice_rounded' onclick='checkinvoice()' $dis $selectedinvoice>
								<input type='hidden' name='client_invrounded' value='$client_invrounded' >
							</td>
						</tr>	
					</table>
				</td>
			</tr>";
			
echo"		<tr height='15xp'> </tr>";

	//fetch table
echo"	<tr>
			<td  valign='top' align='left'>";
	echo"		<table style='width:1100px;' border='0' cellspacing=0>";
	echo"			<tr>
						<td  valign='top' colspan=9  style='width:1100px;'>
							<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>";
	echo"						<tr>
									<td colspan=3>";
									//	<div style='overflow-y:scroll;height:320px;width:1100px;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());
													$totalrows = mysql_num_rows($resultsearch);
													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' width='1100px' >";
		
													if($ClientsDel==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($ClientsMod==1) echo " onclick=SetClient('$rows[0]');";echo"><span class='$stylefont' >$rows[0]&nbsp;</span></font></td>
													<td style='cursor:pointer;' ";if($ClientsMod==1) echo " onclick=SetClient('$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>";	
	echo"		</table>
			</td>
		</tr>";

echo"</table>";
$tabs->end();
				
$tabs->start("$tab8");		
		  
echo"	<table border='0' style='table-layout:fixed' align='left' valign='top' width='1100px'>
			<col width=50>
			<col width=200>
			<col width=50>
			<col width=200>
			<col width=50>
			<col width=200>
			<col width=70>
			<col width=200>";
			  
echo"		<tr bgcolor='#F7F7F7' height='25'>
				<td align=left ><span class='style1'> $name_label<span class='style26'>*</span></span></td>";
echo"			<td ><input type=text name='competitor_name' value='".htmlspecialchars($competitor_name, ENT_QUOTES)."' maxlength='50' $status  size='30' style='font-size:12px; width:200px; '></td>
				<td align=left ><span class='style1'> $product</span></td>";
echo"			<td> <input type=text name='competitor_product' value='".htmlspecialchars($competitor_product, ENT_QUOTES)."' maxlength='30' $status  size='30' style='font-size:12px; width:200px; '></td>
				<td align=left ><span class='style1'> $ratio<span class='style26'>*</span></span></td>";
echo"			<td ><input type=text name='competitor_ratio'  value='".htmlspecialchars($competitor_ratio, ENT_QUOTES)."' maxlength='30' $status  size='70' style='font-size:12px; width:200px; '></td>
				<td><span class='style1'>$salesman<span class='style26'>*</span></span></td>
				<td align=left><input type=text name='competitor_salesman' value='$competitor_salesman' maxlength='30' $status readonly size='20' style='font-size:12px; width:150px; '>";
					if($mainmode!='view' && $mainmode!='')
						   echo"<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Competitor '  width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistsalesmenCompetitor(2); return false' /></span></label>";
echo"			</td>";
			
echo"			</tr>";
echo" 			<tr>	";
echo"				<button type='button' id='btnPost' name='btnPost' onclick='SubmitRecord(3); return false;' title='Save Changes' $Insmode><span><span>Submit</span></span></button>";
echo"				<button type='button' id='clearbutton' name='clearbutton' style='width:67px' onclick='clearcompetitor(); return false;' title='Clear Detail'><span><span>Clear</span></span></button>";
echo"			</td></tr>";
				if($mainmode!='insert' && $mainmode!=''){
echo"		<tr height=20px>
				<td colspan=10></td>
			</tr>";
echo"		<tr  bgcolor='F7F7F7' >
				<td colspan=10>
					<table border='0' style='table-layout:fixed' width=100%>";
echo"					<tr>
							<td width='3%'></td>
							<td width='3%'></td>
							<td><span class='style27'>$name_label</span></td>
							<td><span class='style1'>$product</span></td>
							<td><span class='style1'>$ratio</span></td>
							<td><span class='style1'>$salesman </span></td>
						</tr>";
							$query_competitor="select Ledger_Number,Competitor_Ratio,Competitor_Product,Competitor_Salesman,Competitor_Name,Competitor_id
												from competitors where ledger_number='$ledger_number'";
									
							//echo$query_competitor;
							$resultcompetitor=mysql_query($query_competitor,$connection) or die(mysql_error());		
							$i=1;
							while($rows=mysql_fetch_array($resultcompetitor)){						
								if($i%2==0)
									$Color="style='background-color:".$grid_color1."'";
								else			
									$Color="style='background-color:".$grid_color2."'";	
								
echo'					<tr '.$Color.'>';
							$code = ereg_replace(" ","%20",$rows[0]);	
							if($mainmode!='view' && $mainmode!='')
								print<<<HERE
							
							<td align=center width='3%'><a onmouseover="this.style.cursor='pointer'" onclick='editcomp($rows[5]);' ><img border='0' src='img/button_edit.png' width='12' height='13' title='Edit Detail' style='display:$upd_state' ></a></td>
							<td align=center width='3%'><a onmouseover=this.style.cursor='pointer' OnClick=DeleteComp("$rows[5]",'2');><img border='0' src='img/c_delete.png' width='9' height='10' title='Delete Detail' style='display:$del_state'></td>
HERE;
								else 
echo"						<td align=center width='3%'>&nbsp;</td><td align=center width='3%'>&nbsp;</td>";
echo"						<td><font face='Arial' size='2' color='#186194'><span class='style15'>$rows[4]&nbsp;</span></font></td>
							<td><font face='Arial' size='2' color='#186194'><span class='style15'>$rows[2]&nbsp;</span></font></td>
							<td><font face='Arial' size='2' color='#186194'><span class='style15'>$rows[1]&nbsp;</span></font></td>
							<td><font face='Arial' size='2' color='#186194'><span class='style15'>$rows[3]&nbsp;</span></font></td>";
echo"					</tr>";
							$i=$i+1;
							}
echo"				</table>
				</td>
			</tr>";
			}
				//fetch table
echo"	<tr height='15px'></tr>
		<tr>
			<td  valign='top' align='left'>";
	echo"		<table style='width:1100px;' border='0' cellspacing=0>";
	echo"			<tr>
						<td  valign='top' colspan=9  style='width:1100px;'>
							<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>";
	echo"						<tr>
									<td colspan=3>";
									//	<div style='overflow-y:scroll;height:320px;width:1100px;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());
													$totalrows = mysql_num_rows($resultsearch);
													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' width='1100px' >";
		
													if($ClientsDel==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($ClientsMod==1) echo " onclick=SetClient('$rows[0]');";echo"><span class='$stylefont' >$rows[0]&nbsp;</span></font></td>
													<td style='cursor:pointer;' ";if($ClientsMod==1) echo " onclick=SetClient('$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>";	
	echo"		</table>
			</td>
		</tr>";
echo"</table>";
$tabs->end();
				
$tabs->start("$tab9");		
echo"	<table border='0' style='table-layout:fixed' align='left' valign='top' width='1100px'>
			<col width='100'>
			<col width='150'>
			<col width='100'>
			<col width='150'>
			<col width='50'>
			<col width='200'>
			<col width=''120'>";	
echo"   	<tr bgcolor='#F7F7F7' height='25'>
				<td valign='center' align='left' ><span class='style1'>$startdate&nbsp;</span>";
					echo"<span class='style26'>*</span>"; 
echo"			</td>";
 echo"			 <td> <input type='text' name='clientact_startdate'  value='$clientact_startdate' style='font-size:12px; width:100px; '  readonly />";
					if($mainmode!='view' && $mainmode!='')	  
							  print<<< HERE
&nbsp;<A HREF="#" onClick="displayCalendar(document.clientdt.clientact_startdate,'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 valign='center' align='left' ><span class='style1'>$enddate&nbsp;</span>";
echo"				<span class='style26'>*</span>";
echo"			</td>";
echo"			<td > <input type='text' name='clientact_enddate'  value='$clientact_enddate' style='font-size:12px; width:100px; '  readonly />";
					if($mainmode!='view' && $mainmode!='')
					print<<< HERE
&nbsp;<A HREF="#" onClick="displayCalendar(document.clientdt.clientact_enddate,'dd-mm-yyyy',this); return false;" NAME="anchor1" ID="anchor1"><image src='./img/cal.gif' border=0 align=center></image></A></td>
HERE;
echo" 			</td>
				<td align=left ><span class='style1'>$remark</span>";
					 if($module=='1')
						 echo"<span class='style26'>*</span>";
echo"			</td>
				<td align=left ><input type=text name='clientact_remark' value='".htmlspecialchars($clientact_remark, ENT_QUOTES)."' maxlength='100' $status  size='100' style='font-size:12px; width:500px; '>
			</tr>";
			

echo"		<tr bgcolor='#F7F7F7' height='35' > ";
					//Add Activation Historic
echo"				<button type='button' id='btnPost' name='btnPost' onclick='SubmitRecord(4); return false;' title='Save Activation' $Insmode><span><span>Save</span></span></button>";
echo"				<button type='button' id='btnClr' name='btnClr' onclick='clearactivation(); return false;' title='Clear Activation' ><span><span>Clear</span></span></button>";
echo"			</td>";
echo"		</tr>";
	
					if($mainmode!='insert' && $mainmode!=''){

echo"		<tr  bgcolor='#F7F7F7' >
				<td colspan=10>
					<table border='0' style='table-layout:fixed' width=100% cellspacing='1'> ";

echo"		<tr>
				<td width='3%'></td>
				<td width='3%'></td>
				<td><span class='style1'>$startdate</span></td>
				<td><span class='style1'>$enddate</span></td>
				<td><span class='style1'>$remark</span></td>
			</tr>";

				$query_activation="select Ledger_Number,date_format(ClientAct_StartDate,'%d-%m-%Y'),date_format(ClientAct_EndDate,'%d-%m-%Y'),ClientAct_Remark,clientact_id
								from clientactivationhistoric where ledger_number='$ledger_number'";
						//echo$query_activation;
				$resultactivation=mysql_query($query_activation,$connection) or die(mysql_error());		

				$i=1;
				while($rows=mysql_fetch_array($resultactivation)){						

				if($i%2==0)
					$Color="style='background-color:".$grid_color1."'";
				else			
					$Color="style='background-color:".$grid_color2."'";	
				
echo'			<tr '.$Color.'>';
					$code = ereg_replace(" ","%20",$rows[0]);	

					if($mainmode!='view' && $mainmode!='')
print<<<HERE
					<td align=center width='3%'><a onmouseover="this.style.cursor='pointer'" onclick='editactive($rows[4]);'  ><img border='0' src='img/button_edit.png' width='12' height='13' title='Edit Detail' style='display:$upd_state' ></a></td>
					<td align=center width='3%'><a onmouseover=this.style.cursor='pointer' OnClick=DeleteAct("$rows[4]",'3'); ><img border='0' src='img/c_delete.png' width='9' height='10' title='Delete Detail' style='display:$del_state'></td>
HERE;
					else 
echo"				<td align=center width='3%'>&nbsp;</td><td align=center width='3%'>&nbsp;</td>";
echo"				<td><font face='Arial' size='2' color='#186194'><span class='style15'>$rows[1]&nbsp;</span></font></td>
					<td><font face='Arial' size='2' color='#186194'><span class='style15'>$rows[2]&nbsp;</span></font></td>
					<td><font face='Arial' size='2' color='#186194'><span class='style15'>$rows[3]&nbsp;</span></font></td>";
echo"			</tr>";

					$i=$i+1;

				}
echo"		</table>
		</td>
	</tr>";
					}
	//fetch table
echo"	<tr height='15px'></tr>
		<tr>
			<td  valign='top' align='left'>";
	echo"		<table style='width:1100px;' border='0' cellspacing=0>";
	echo"			<tr>
						<td  valign='top' colspan=9  style='width:1100px;'>
							<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>";
	echo"						<tr>
									<td colspan=3>";
									//	<div style='overflow-y:scroll;height:320px;width:1100px;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());
													$totalrows = mysql_num_rows($resultsearch);
													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' width='1100px' >";
		
													if($ClientsDel==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($ClientsMod==1) echo " onclick=SetClient('$rows[0]');";echo"><span class='$stylefont' >$rows[0]&nbsp;</span></font></td>
													<td style='cursor:pointer;' ";if($ClientsMod==1) echo " onclick=SetClient('$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>";	
	echo"		</table>
			</td>
		</tr>";
echo"</table>";			
$tabs->end();	
				
$tabs->start("$tab10");		
echo"	<table border='0' style='table-layout:fixed' align='left' valign='top' width=1100px>
			<col width=100>
			<col width=150>
			<col width=100>
			<col width=160>
			<col width=80>
			<col width=150>
			<col width=120>
			<col width=50> ";	
		
			if(!isset($client_businesssector))$client_businesssector='A';
			if($client_businesssector=='A')$selectedA='selected';
			if($client_businesssector=='I')$selectedI='selected';
			if($client_businesssector=='O')$selectedO='selected';

echo"		<tr bgcolor='#F7F7F7'>
				<td>";
echo"				<span class='style1'>$business_sector</span>";
					 if($module=='1')
						 echo"<span class='style26'>*</span>";
echo"			</td>
				<td>
					<select name='businesssector' onchange='set_businesssector()' $dis>
						<option value='' > &nbsp;</option>
						<option value='A' $selectedA> Agriculture</option>
						<option value='I' $selectedI>Industrial </option>
						<option value='O' $selectedO>Other </option>
					</select> 
					<input type='hidden' name='client_businesssector' value='".htmlspecialchars($client_businesssector, ENT_QUOTES)."' >							
				</td>

				<td><span class='style1'>Desc</span></td>
				<td>
					<input type='text' name='client_businesssectordesc' value='$client_businesssectordesc' maxlength='10' $status>
				</td>
				
				<td>
					<span class='style1'>$tobcode</span>";
					if($module=='1')
						echo"<span class='style26'>*</span>";
					if($client_multiplesales=='1')$selectedmultiple='checked';
echo"			</td>
				<td>
					<input type='text' name='client_tobcode' value='".htmlspecialchars($client_tobcode, ENT_QUOTES)."'  $status>
				</td>
				<td><span class='style1'>$multiple_sales</span></td>
				<td>
					<input type='checkbox' name='client_sales' onclick='checksales()' $dis $selectedmultiple>
					<input type='hidden' name='client_multiplesales' value='$client_multiplesales' $status>
				</td>
			</tr>

			<tr bgcolor='#F7F7F7'>
				<td><span class='style1'>$business_type2</span></td>
				<td ><input type='text' name='client_btype2' value='".htmlspecialchars($client_btype2, ENT_QUOTES)."'   maxlength='50' $status></td>
				<td><span class='style1'>$business_type3</span></td>
				<td ><input type='text' name='client_btype3' value='".htmlspecialchars($client_btype3, ENT_QUOTES)."' maxlength='50' $status></td>
				<td><span class='style1'>$business_type1</span>";
					 if($module=='1')
					 echo"<span class='style26'>*</span>";

echo"			</td>
				<td >
					<input type='text' name='Client_BusinessType' value='".htmlspecialchars($Client_BusinessType, ENT_QUOTES)."'  maxlength='20' $status>
				</td>
			</tr>";
			
			//fetch table
echo"	<tr height='15px'></tr>
		<tr>
			<td  valign='top' align='left'>";
	echo"		<table style='width:1100px;' border='0' cellspacing=0>";
	echo"			<tr>
						<td  valign='top' colspan=9  style='width:1100px;'>
							<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>";
	echo"						<tr>
									<td colspan=3>";
									//	<div style='overflow-y:scroll;height:320px;width:1100px;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());
													$totalrows = mysql_num_rows($resultsearch);
													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' width='1100px' >";
		
													if($ClientsDel==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($ClientsMod==1) echo " onclick=SetClient('$rows[0]');";echo"><span class='$stylefont' >$rows[0]&nbsp;</span></font></td>
													<td style='cursor:pointer;' ";if($ClientsMod==1) echo " onclick=SetClient('$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>";	
	echo"		</table>
			</td>
		</tr>";
			
echo"</table>";			
$tabs->end();		
				
$tabs->start("$tab11");		
		  
echo"	<table border='0' style='table-layout:fixed' align='left' valign='top' width=1100px>
			<col width=140>
			<col width=180>
			<col width=120>
			<col width=180>
			<col width=120>
			<col width=160>
			<col width=100>
			<col width=100>";
		  
echo"		<tr bgcolor='#F7F7F7' height='25'>
				<td align=left ><span class='style1'> $startdate<span class='style26'>*</span></span></td>";
echo"			<td ><input type=text name='start_date' value='".htmlspecialchars($start_date, ENT_QUOTES)."' readonly   style='font-size:12px; width:150px; '>";
					if($mainmode!='view' && $mainmode!='')
print<<< HERE
					&nbsp;<A HREF="#" onClick="displayCalendar(document.clientdt.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 align=left ><span class='style1'> $enddate</td>";
echo"			<td><input type=text name='end_date' value='".htmlspecialchars($end_date, ENT_QUOTES)."' readonly   style='font-size:12px; width:150px; '>";
					if($mainmode!='view' && $mainmode!='')
print<<< HERE
					&nbsp;<A HREF="#" onClick="displayCalendar(document.clientdt.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 align=left ><span class='style1'> $lasttransdate</td>";
echo"			<td ><input type=text name='ClientIP_LastTransDate' value='".htmlspecialchars($ClientIP_LastTransDate, ENT_QUOTES)."' readonly   style='font-size:12px; width:120px; '></td>
				<td>&nbsp;</td><td>&nbsp;</td>
			</tr>";

echo" 		<tr  bgcolor='#F7F7F7' height='25'>
				<td><span class='style1'>$periodbymonth</span></td>
				<td ><input type=text name='ClientIP_PeriodByMonth' value='".htmlspecialchars($ClientIP_PeriodByMonth, ENT_QUOTES)."' maxlength='20' $status  size='30' style='font-size:12px; width:150px; '></td>
				<td><span class='style1'>$installmonth</span></td>
				<td ><input type=text name='Client_Inst_Month' value='".htmlspecialchars($Client_Inst_Month, ENT_QUOTES)."' maxlength='20' readonly  size='30' style='font-size:12px; width:150px; '>";
					if($mainmode!='view' && $mainmode!='')
print<<< HERE
					&nbsp;<A HREF="#" onClick="displayCalendar(document.clientdt.Client_Inst_Month,'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><span class='style1'>$techinicianname</span></td>
				<td ><input type=text name='technician_name' value='".htmlspecialchars($technician_name, ENT_QUOTES)."' maxlength='30' $status  size='30' style='font-size:12px; width:120px; '></td>
				<td>&nbsp;</td><td>&nbsp;</td>
			</tr>";

echo"		<tr bgcolor='#F7F7F7' height='25'>
				<td align=left ><span class='style1'> $subsname_label</span><span class='style26'>*</span></td>";
echo"			<td ><input type=text name='subscriber_name' value='".htmlspecialchars($subscriber_name, ENT_QUOTES)."' maxlength='60' $status  size='30' style='font-size:12px; width:150px; '></td>
				<td align=left ><span class='style1'> $clientip</span><span class='style26'>*</span></td>";
echo"			<td ><input type=text name='Clientip_IP' value='".htmlspecialchars($Clientip_IP, ENT_QUOTES)."' maxlength='15'   size='30' style='font-size:12px; width:150px; '>";
					if($mainmode!='view' && $mainmode!='')
echo"					&nbsp;<label><span class='style1'><img src='img/btnopen.jpg' title=' Select IP '  width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistip(1); return false' /></span></label>";
		   
echo"			 </td>
				<td align='center'><span class='style1'>$tc</span></td>
				<td><input type=text name='clientip_tc' value='".htmlspecialchars($clientip_tc, ENT_QUOTES)."' maxlength='10' $status  size='30' style='font-size:12px; width:120px; '></td>
				<td>&nbsp;</td><td>&nbsp;</td>
			</tr>
			<tr bgcolor='#F7F7F7' height='25'>
				<td align=left ><span class='style1'>$category</span></td>";
echo"			<td ><input type=text name='category_name' value='".htmlspecialchars($category_name, ENT_QUOTES)."' maxlength='20' $status  size='30' style='font-size:12px; width:150px; '></td>
				<td align=left ><span class='style1'>$client_ipservice</span></td>";
echo"			<td ><input type=text name='service_name' value='".htmlspecialchars($service_name, ENT_QUOTES)."' maxlength='60' $status  size='30' style='font-size:12px; width:150px; '></td>
				<td align='center'><span class='style1'>$area</span></td>
				<td align=left ><input type=text name='clientiparea_code' value='$clientiparea_code' maxlength='30' $status readonly size='20' style='font-size:12px; width:120px; '>";
						if($mainmode!='view' && $mainmode!='')
echo"					&nbsp;<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Area '  width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistarea(6); return false' /></span></label>";
echo"			</td><td>&nbsp;</td><td>&nbsp;</td>
			</tr>";
echo"		<tr bgcolor='#F7F7F7' height='25'>
				<td align=left ><span class='style1'>$amount_label</span></td>";
echo"			<td ><input type=text name='clientip_amount' value='".htmlspecialchars($clientip_amount, ENT_QUOTES)."' maxlength='20' $status  size='30' style='font-size:12px; width:150px; '></td>";
					$curr = get_currency($connection);
echo"			<td align=left ><span class='style1'>$clientip_currency</span></td>
				<td  bgcolor='#F7F7F7' height='25'>
					<select  name='currencyip'  $dis style='width:150px;'>
						<option value=''></option>";
						while ($cr=mysql_fetch_row($curr))
						{
						if ($cr[0]==$currencyip)
						echo"<option selected value='$cr[0]'>$cr[0]</option>";
						else
						echo"<option value='$cr[0]'>$cr[0]</option>";
						}				
echo"				</select>
				</td>
				<td>&nbsp;</td>
				<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
			</tr>";
	
echo" 		<tr  bgcolor='#F7F7F7' height='25'>
				<td><span class='style1'>$uploadip</span></td>
				<td ><input type=text name='upload_ip' value='".htmlspecialchars($upload_ip, ENT_QUOTES)."' maxlength='50' $status  size='30' style='font-size:12px; width:150px; '></td>
				<td><span class='style1'>$downloadip</span></td>
				<td ><input type=text name='download_ip' value='".htmlspecialchars($download_ip, ENT_QUOTES)."' maxlength='50' $status  size='30' style='font-size:12px; width:150px; '></td>";
echo"			<td><span class='style1'>$macip </span></td>
				<td ><input type=text name='client_macaddress' value='".htmlspecialchars($client_macaddress, ENT_QUOTES)."' maxlength='30' $status  size='30' style='font-size:12px; width:120px; '></td>				
			<td>&nbsp;</td><td>&nbsp;</td>
			</tr>
			<tr bgcolor='#F7F7F7' height='25'>
				<td><span class='style1'>$portip</span></td>
				<td ><input type=text name='client_port' value='".htmlspecialchars($client_port, ENT_QUOTES)."' maxlength='20' $status  size='30' style='font-size:12px; width:150px; '></td>";
echo" 			<td><span class='style1'>$modemip</span></td>
				<td ><input type=text name='client_modemip' value='".htmlspecialchars($client_modemip, ENT_QUOTES)."' maxlength='20' $status  size='30' style='font-size:12px; width:150px; '></td>
				<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
			</tr>";				

				if($module_project==1 || $module_costcenter==1){	
echo" 		<tr  bgcolor='#F7F7F7' height='25'>";
				if($module_project==1){
echo"			<td><span class='style1'>$projectip</span></td>
				<td align=left ><input type=text name='clientipproject_code' value='$clientipproject_code' maxlength='30' $status readonly size='20' style='font-size:12px; width:150px; '>";
					if($mainmode!='view' && $mainmode!='')
					echo"&nbsp;<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Project '  width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistprojects(10); return false' /></span></label>";
echo"			</td>";
				}
				else 
echo "			<td colspan='2'>&nbsp;</td><input type='text' name='clientipproject_code' value='$clientipproject_code'>";	
					if($module_costcenter==1){
echo" 			<td><span class='style1'>$costcenter</span></td>
				<td align=left ><input type=text name='clientipcostcent_code' value='$clientipcostcent_code' maxlength='30' $status readonly size='20' style='font-size:12px; width:150px; '>";
					if($mainmode!='view' && $mainmode!='')
					echo"&nbsp;<label><span class='style1'><img src='img/btnopen.jpg' title=' Select CostCenter '  width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistcostcentercode(8); return false' /></span></label>";
echo"			</td>";
					}
					else 
echo "			<td colspan='2'>&nbsp;</td><input type='hidden' name='clientipcostcent_code' value='$clientipcostcent_code'>";
echo"			<td colspan=3>&nbsp;</td><td>&nbsp;</td>
			</tr>";
					}
					else 	
						echo"<input type='hidden' name='clientipproject_code' value='$clientipproject_code'><input type='hidden' name='clientipcostcent_code' value='$clientipcostcent_code'>";
		   
echo" 		<tr  bgcolor='#F7F7F7' height='25'>
				<td><span class='style1'>$reasonip</span></td>
				<td colspan=2><input type=text name='clientip_reason' value='".htmlspecialchars($clientip_reason, ENT_QUOTES)."' maxlength='255' $status  size='30' style='font-size:12px; width:295px; '></td>
				<td><span class='style1'>$collection_label</span></td>
				<td colspan=3><input type=text name='collection_name' value='".htmlspecialchars($collection_name, ENT_QUOTES)."' maxlength='50' $status  size='30' style='font-size:12px; width:250px; '></td>
				<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
			</tr>";
				
echo" 		<tr  bgcolor='#F7F7F7' height='25'>
				<td><span class='style1'>$subscriber_address_label</span></td>
				<td colspan='3'><input type=text name='Subscriber_Address' value='".htmlspecialchars($Subscriber_Address, ENT_QUOTES)."' maxlength='100' $status  size='30' style='font-size:12px; width:450px; '></td>";				
echo"			 <td>
					<button type='button' id='btnPost' name='btnPost' onclick='SubmitRecord(5); return false;' title='Save IP' $Insmode><span><span>Save</span></span></button>";
echo"				<button type='button' id='btnClr' name='btnClr' onclick='clearclientip(); return false;' title='Clear IP' ><span><span>Clear</span></span></button>";
echo" 			</td>
				<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
			<tr></tr>";
		
				if($mainmode!='insert' && $mainmode!=''){

echo"		<tr>
				<td colspan=10>
					<div style='overflow:scroll;height:150px;width:1100px;border:0px solid #000000;'>
						<table border='0' style='table-layout:fixed' width='1800px'>
							<col width=30><col width=30><col width=100><col width=100><col width=70><col width=70>
							<col width=70><col width=80><col width=80><col width=80><col width=60><col width=60><col width=60><col width=80><col width=80>
							<col width=80><col width=80><col width=80><col width=80><col width=80><col width=80><col width=80><col width=80><col width=80>";
echo"						<tr bgcolor='d0d0d0'>
								<td ></td>
								<td ></td>
								<td><span class='style27'>$subsname_label</span></td>
								<td><span class='style27'>$ip</span></td><td><span class='style27'>$startdate</span></td>
								<td><span class='style27'>$enddate </span></td><td><span class='style27'>$asttransdate</span></td>
								<td><span class='style27'>$clientip_category</span></td><td><span class='style27'>$client_ipservice</span></td>
								<td><span class='style27'>$amount_label</span></td><td><span class='style27'>$clientip_currency</span></td><td><span class='style27'>$tc</span></td>
								<td><span class='style27'>$periodbymonth</span></td><td><span class='style27'>$installmonth</span></td><td><span class='style27'>$area</span></td>
								<td><span class='style27'>$projectip</span></td><td><span class='style27'>$costcenter</span></td>
								<td><span class='style27'>$uploadiP</span></td><td><span class='style27'>$downloadip</span></td><td><span class='style27'>$macip</span></td>
								<td><span class='style27'>$portip</span></td><td><span class='style27'>$modemip</span></td>
								<td><span class='style27'>$reasonip</span></td><td><span class='style27'>$techinicianname</span></td>
								<td><span class='style27'>$collection_name</span></td>
							</tr>";

								$query_ip="select Clientip_id,Subscriber_Name,Clientip_IP,date_format(Clientip_startDate,'%d-%m-%Y'),date_format(ClientIP_EndDate,'%d-%m-%Y'),date_format(ClientIP_LastTransDate,'%d-%m-%Y'),
											CLIENT_CATEGORY,service_name,Clientip_amount,Currency_code,CLIENT_TC,ClientIP_PeriodByMonth,date_format(Client_Inst_Month,'%d-%m-%Y'),Area_Code,Project_Code,Costcenter_code,".
											" Clientip_upload,Clientip_download,Client_MacAddress,Client_port,Modem_IP,Reason_disabled,Technician_Name,Collection_name ".
										
										" from clientsip where ledger_number='$ledger_number'";
									
									//echo$query_ip;
									$resultip=mysql_query($query_ip,$connection) or die(mysql_error());		
									$i=1;
									while($rows=mysql_fetch_array($resultip)){						
										if($i%2==0)
											$Color="style='background-color:".$grid_color1."'";
										else			
											$Color="style='background-color:".$grid_color2."'";	
										
echo'						<tr '.$Color.'>';
								$code = ereg_replace(" ","%20",$rows[0]);	
								if($mainmode!='view' && $mainmode!='')
	print<<<HERE
								<td align=center width='3%'><a onmouseover="this.style.cursor='pointer'" onclick='editip($rows[0]);' ><img border='0' src='img/button_edit.png' width='12' height='13' title='Edit Detail' style='display:$upd_state' ></a></td>
								<td align=center width='3%'><a onmouseover=this.style.cursor='pointer' OnClick=Deleteip("$rows[0]");><img border='0' src='img/c_delete.png' width='9' height='10' title='Delete Detail' style='display:$del_state'></td>

HERE;
								else 
echo"							<td align=center width='3%'>&nbsp;</td><td align=center width='3%'>&nbsp;</td>";
echo"							<td><font face='Arial' size='2' color='#186194'><span class='style15'>$rows[1]&nbsp;</span></font></td>
								<td><font face='Arial' size='2' color='#186194'><span class='style15'>$rows[2]&nbsp;</span></font></td>
								<td><font face='Arial' size='2' color='#186194'><span class='style15'>$rows[3]&nbsp;</span></font></td>
								<td><font face='Arial' size='2' color='#186194'><span class='style15'>$rows[4]&nbsp;</span></font></td>
								<td><font face='Arial' size='2' color='#186194'><span class='style15'>$rows[5]&nbsp;</span></font></td>
								<td><font face='Arial' size='2' color='#186194'><span class='style15'>$rows[6]&nbsp;</span></font></td>
								<td><font face='Arial' size='2' color='#186194'><span class='style15'>$rows[7]&nbsp;</span></font></td>
								<td><font face='Arial' size='2' color='#186194'><span class='style15'>$rows[8]&nbsp;</span></font></td>
								<td><font face='Arial' size='2' color='#186194'><span class='style15'>$rows[9]&nbsp;</span></font></td>
								<td><font face='Arial' size='2' color='#186194'><span class='style15'>$rows[10]&nbsp;</span></font></td>
								<td><font face='Arial' size='2' color='#186194'><span class='style15'>$rows[11]&nbsp;</span></font></td>
								<td><font face='Arial' size='2' color='#186194'><span class='style15'>$rows[12]&nbsp;</span></font></td>
								<td><font face='Arial' size='2' color='#186194'><span class='style15'>$rows[13]&nbsp;</span></font></td>
								<td><font face='Arial' size='2' color='#186194'><span class='style15'>$rows[14]&nbsp;</span></font></td>
								<td><font face='Arial' size='2' color='#186194'><span class='style15'>$rows[15]&nbsp;</span></font></td>
								<td><font face='Arial' size='2' color='#186194'><span class='style15'>$rows[16]&nbsp;</span></font></td>
								<td><font face='Arial' size='2' color='#186194'><span class='style15'>$rows[17]&nbsp;</span></font></td>
								<td><font face='Arial' size='2' color='#186194'><span class='style15'>$rows[18]&nbsp;</span></font></td>
								<td><font face='Arial' size='2' color='#186194'><span class='style15'>$rows[19]&nbsp;</span></font></td>
								<td><font face='Arial' size='2' color='#186194'><span class='style15'>$rows[20]&nbsp;</span></font></td>
								<td><font face='Arial' size='2' color='#186194'><span class='style15'>$rows[21]&nbsp;</span></font></td>
								<td><font face='Arial' size='2' color='#186194'><span class='style15'>$rows[22]&nbsp;</span></font></td>
								<td><font face='Arial' size='2' color='#186194'><span class='style15'>$rows[23]&nbsp;</span></font></td>";
echo"						</tr>";
							$i=$i+1;
										}
echo"					</table>
					</div>
				</td>
			</tr>";
echo" 		<tr  bgcolor='#F7F7F7' height='25'></tr>";
}

//fetch table
echo"	<tr height='15px'></tr>
		<tr>
			<td  valign='top' align='left'>";
	echo"		<table style='width:1100px;' border='0' cellspacing=0>";
	echo"			<tr>
						<td  valign='top' colspan=9  style='width:1100px;'>
							<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>";
	echo"						<tr>
									<td colspan=3>";
									//	<div style='overflow-y:scroll;height:320px;width:1100px;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());
													$totalrows = mysql_num_rows($resultsearch);
													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' width='1100px' >";
		
													if($ClientsDel==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($ClientsMod==1) echo " onclick=SetClient('$rows[0]');";echo"><span class='$stylefont' >$rows[0]&nbsp;</span></font></td>
													<td style='cursor:pointer;' ";if($ClientsMod==1) echo " onclick=SetClient('$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>";	
	echo"		</table>
			</td>
		</tr>";
echo"</table>";
$tabs->end();



if ($FL_Logistic == 1){
	$tabs->start("Access");	
		draw_ClientAccess($ledger_number, $config['EncryptPassMod'], $connection);	
	$tabs->end();	
}

if($module_clientContract==1 && $ledger_number!=''){
	$tabs->start("Contract");	
	
	echo"	<table border='0'  align='left' valign='top'>";
	echo"<col width=90>
		 <col width=140>
		 <col width=90>
		 <col width=140>
		 <col width=60>
		 <col width=140> 
		 <col width=15>";	

		 $query = " select clients.ledger_number,clients.ledger_name from clients".
		 " where Ledger_number='".$ledger_number."'";

		//echo $query;
		$result = mysql_query($query, $connection);
		$rows=mysql_fetch_array($result);
  
echo"	<tr>
		<td colspan=7>
				<table  border='0' width='1100px'>
					<col width='100'>
					<col width='100'>
					<col width='100'>
					<col width='100'>
					<col width='100'>
					<col width='100'>
					<col width='30'>
				
				<tr bgcolor='#D0D0D0' height='25px'>
					<td align='center'><span class='style27'>Client Code<span class='style26'>*</span></span></td>
					<td align='center'><span class='style27'>Client Name<span class='style26'>*</span></span></td>
					<td align='center'><span class='style27'>Project Code<span class='style26'>*</span></span></td>
					<td align='center'><span class='style27'>Contract Amount<span class='style26'>*</span></span></td>
					<td align='center'><span class='style27'> Start Date<span class='style26'>*</span></span></td>
					<td align='center'><span class='style27'>Contract Terms<span class='style26'>*</span></span></td>
					<td align='center'></td>

				</tr>";

echo"					<tr>
					<td align=center><input type='text' style='font-size:12px; width:90px; ' name='clientcontact_code' value='$rows[0]'   readonly>&nbsp;</td>
					<td align=center><input type='text' style='font-size:12px; width:120px; ' name='clientcontact_name' value='$rows[1]'  readonly>&nbsp;</td>";	
echo"			 <td align='left' > <span class='style1'>
						<input type='text' name='txtProjectCode' id='txtProjectCode' value='$txtProjectCode' style='width:120px;' maxlength='20' onchange=\"CheckLookup('chkcodeexists','project','project_code',this.value,'lstProjectCodeH');\" /></span>
						<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Project ' id='lstProjectCodeH' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistProject(46); '  /></span></label></td>
					<td><input type='text' style='font-size:12px; width:90px; ' name='clientcontact_amount' value='$clientcontact_amount' ></td>
					<td><input type='text' name='txtcontractdate' id='txtcontractdate' value='$txtcontractdate' style='width:90px;'>
						<a href='#' onclick=\"displayCalendar(document.clientdt.txtcontractdate,'dd/mm/yyyy',this);  return false; \" name='anchor1' id='anchor1'>
						<img src='./img/cal.gif' border=0 align='center'></a>
					</td>
					<td align='left' ><select name='contractterm' id='contractterm' value='$contractterm' style='width:120px;'>";
					echo "<option value='' ".($contractterm==''?'selected':'')."></option>";
					
						echo "<option value='Annual' ".($contractterm=='Annual'?'selected':'').">Annual</option>";
						echo "<option value='Monthly' ".($contractterm=='Monthly'?'selected':'').">Monthly</option>";
						echo "<option value='Quarterly' ".($contractterm=='Quarterly'?'selected':'').">Quarterly</option>";
						echo "<option value='Half year' ".($contractterm=='Half year'?'selected':'').">Half year</option>";
							
					echo "</select></td>
					<td valign=center>";
								echo"<button type='button' id='btnPost' name='btnPost' onclick='SubmitContractdt(); return false;' title='Save Changes' $Insmode><span><span>Submit</span></span></button>";
			echo"			</td>
					
				</tr>";

					$querydt = " select id,project_code, amount,contract_startdate,contract_terms".
							   " from clientscontract ".
							   " 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'><span class='style15'>".$rows[0]."</span></td>";
		echo "	<td align='center'><span class='style15'>".$rows[1]."</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='center'><span class='style15'>".$rowsdt[3]."</span></td>";
		echo "	<td align='center'><span class='style15'>".$rowsdt[4]."</span></td>";
		echo "	<td align='center' valign='center'><span class='style15'><img src='img/c_delete.png'  onMouseOver=\"style.cursor='hand'\" onclick=DeleteContractdt('".$rowsdt[0]."') title='Delete Record'  ></span></td>";
		echo "</tr>";
				
					}					

echo"			</table>

</td>
</tr>";
echo "<tr height='15px'></tr>";
		//fetch table
echo"	<tr>
	<td  valign='top' align='left'>";
echo"		<table style='width:1100px;' border='0' cellspacing=0>";
echo"			<tr>
				<td  valign='top' colspan=9  style='width:1100px;'>
					<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>";
echo"						<tr>
							<td colspan=3>";
							//	<div style='overflow-y:scroll;height:320px;width:1100px;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());
											$totalrows = mysql_num_rows($resultsearch);
											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' width='1100px' >";

											if($ClientsDel==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($ClientsMod==1) echo " onclick=SetClient('$rows[0]');";echo"><span class='$stylefont' >$rows[0]&nbsp;</span></font></td>
											<td style='cursor:pointer;' ";if($ClientsMod==1) echo " onclick=SetClient('$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>";	
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' id='btnAddClient' name='btnAddClient' value='Add Client'";  	
			
	if($mainmode=='insert' or $mainmode=='edit' or $mainmode=='view')
		echo "disabled ";
			
	echo"onclick='AddClients()' $style title='Add Client' '".$AddMode."'>";
				
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 Client' />";
	}
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='SearchForClient();' $style title='Search Client' ";
                if ($mainmode=='edit' or $mainmode=='insert') 
				    echo " disabled ";
		        echo " />";*/
				/*
				echo"<input name='btnSearch' type='button' id='btnSearch' value='Append' onclick='AppendClient();' $style hidden title='Append' ";
                if ($mainmode=='edit' or $mainmode=='insert')
				    echo " disabled ";
		        echo " />";
				*/
/*echo"&nbsp;<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' && $ledger_number!=$ledger_numberPrv) || ($mainmode=='edit' && $ledger_number!=$ledger_numberPrv)){
		$query_client="select count(*) from clients 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.clientdt.message.value='Code Already Exists';";
		echo"	document.clientdt.checkcode.value='0';";
		echo"	document.clientdt.submit();";	
		echo"</script>";
			
	}

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


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

HERE;

?>