<?php

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


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

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 FI_Suppliers as loginaccess,language from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' 	and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."')	";
	$resultlog=mysql_query($querylog,$connection) or die(mysql_error());
	while($rows=mysql_fetch_array($resultlog)){
		extract($rows);
	}
	
	
	
	$querylang="select  language, creationdate, supplier_group, code, name, name_arabic, representative,description, area, vat, vat_number, vat_date, currency, credit_limit, pay_terms,
				project_code, project_name, costcenter, check_approved, check_sub, checkexport, check_local, fax, phone1, email, phone2, homepage, tab1, tab2, tab3, tab4, tab5, tab6,
				tab7, Title, First_Name, Last_Name, tel1, tel2, tel3, supp_email, reference, city1, city2, city3, city, state, country, address1, address2, address3, mother_company, reffered,
				owner, gcinumb, buisness_sec, buisness_des, buisness_type2, buisness_type3, item_code, item_desc ,Father_Name
				from ".$_SESSION['dbLabel'].".suppliers_label where language='$language'";

//echo $querylang;
$resultlang=mysql_query($querylang,$connection) or die(mysql_error());
	while($rows=mysql_fetch_array($resultlang)){
		//extract($rows);
		
		$creationdate				= $rows[1];
		$groupsupplier				= $rows[2];
		$sup_code					= $rows[3];

		$sup_name					= $rows[4];
		$name_arabic				= $rows[5];
		$representative_supplier	= $rows[6];
		$supplier_desc				= $rows[7];
		$supplier_area				= $rows[8];
		$suppliervat				= $rows[9];
		$supp_vatNum				= $rows[10];
		
		$supp_vatdate				= $rows[11];
		$supCurrency				= $rows[12];
		$Sup_cred					= $rows[13];
		$sup_payterm  				= $rows[14];	
		$projectcode				= $rows[15];
		$projectname				= $rows[16];
		$costcenter_supp			= $rows[17];
		$chckapp					= $rows[18];
		$checksub					= $rows[19];
		
		$Chkexpor					= $rows[20];
		$Chcklocal					= $rows[21];
		$fax_label					= $rows[22];
		$phone1_label				= $rows[23];
		$email_label				= $rows[24];
		$phone2_label				= $rows[25];
		$home_page					= $rows[26];
		$tab1						= $rows[27];
		$tab2						= $rows[28];
		$tab3						= $rows[29];
		$tab4						= $rows[30];
		$tab5						= $rows[31];
		$tab6						= $rows[32];
		$tab7						= $rows[33];
		$title						= $rows[34];
		$first_namelabel			= $rows[35];
		$lastname_label				= $rows[36];
		$tel1_label					= $rows[37];
		$tel2_label					= $rows[38];
		$tel3_label					= $rows[39];
		$suppemail					= $rows[40];
		$reference_label			= $rows[41];
		$city1_label				= $rows[42];
		$city2_label				= $rows[43];
		$city3_label				= $rows[44];
		$city_label					= $rows[45];
		$state_label				= $rows[46];
		$country					= $rows[47];
		$address1					= $rows[48];
		$address2					= $rows[49];
		$address3					= $rows[50];
		$mother_companylable		= $rows[51];
		$reffered_lable				= $rows[52];
		$owner_lable				= $rows[53];
		$gcinumb					= $rows[54];
		$buisness_sec				= $rows[55];
		$buisness_des				= $rows[56];
		$buisnesstyp2_label			= $rows[57];
		$buisnesstyp3_label			= $rows[58];
		$item_code_label			= $rows[59];
		$item_desc_label			= $rows[56];
		$father_Name_label			= $rows[61];
		
	}

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

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

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

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


$AddMode='';

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

$saveEnabled = 0;
if ( ($FI_SuppliersMod == 1 && $mainmode=='editmode') || ($FI_SuppliersApp == 1))
	$saveEnabled = 1;

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

//Read From Setup Table							
$querysetup= " select grid_color1, grid_color2,maxperpage,Supplier_DefaultCur,Setup_Tax1Active ,Setup_Tax2Active,Setup_Tax3Active,Setup_Tax4Active,Setup_Tax5Active, ifnull(supplier_access,0) as supplier_access
				from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}
	
$query_ledgergrp="select ifnull(module_ledgergrp,0) as module_ledgergrp, ifnull(Module_AdditionalTaxes,0) as Module_AdditionalTaxes 
				 from module";
$resultledgergrp = mysql_query($query_ledgergrp,$connection) or die(mysql_error());
$row_ledger		 = mysql_fetch_row($resultledgergrp);
$module_ledgergrp 				= $row_ledger[0];
$ModuleAdditionalTax 			= $row_ledger[1];
$module_CreateUserFromSupplier  = $row_ledger[2];
	
	
$HideMenu   					= $_POST["HideMenu"]; if ($HideMenu == ""){$HideMenu = $_GET["HideMenu"];}   	
$actionmode 					= $_POST["actionmode"]; if ($actionmode == ""){$actionmode = $_GET["actionmode"];}   
$mainmode   					= $_POST["mainmode"]; if ($mainmode == ""){$mainmode = $_GET["mainmode"];}   
$message 						= $_POST["message"]; if ($message == ""){$message = $_GET["message"];}   
$txtKeyword 					= $_POST["txtKeyword"]; if ($txtKeyword == ""){$txtKeyword = $_GET["txtKeyword"];}   
$perpage 						= $_POST["perpage"]; if ($perpage == ""){$perpage = $_GET["perpage"];} 
$startrange						= $_POST["startrange"]; if ($startrange == ""){$startrange = $_GET["startrange"];} 
$vTabFocus 						= $_POST["vTabFocus"]; if ($vTabFocus == ""){$vTabFocus = $_GET["vTabFocus"];} 

$checkcode    					= $_POST["checkcode"]; if ($checkcode == ""){$checkcode = $_GET["checkcode"];} 
$fill_ledger 					= $_POST["fill_ledger"]; if ($fill_ledger == ""){$fill_ledger = $_GET["fill_ledger"];} 
$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"];} 
$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"];} 
$telephone_increment			= $_POST["telephone_increment"]; if ($telephone_increment == ""){$telephone_increment = $_GET["telephone_increment"];} 


$supplier_groupcode				= $_POST["supplier_groupcode"]; if ($supplier_groupcode == ""){$supplier_groupcode = $_GET["supplier_groupcode"];} 
$supplier_groupname				= $_POST["supplier_groupname"]; if ($supplier_groupname == ""){$supplier_groupname = $_GET["supplier_groupname"];} 
$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"];} 
$representative 				= $_POST["representative"]; if ($representative == ""){$representative = $_GET["representative"];} 
$area_code 						= $_POST["area_code"]; if ($area_code == ""){$area_code = $_GET["area_code"];} 
$areaname 						= $_POST["areaname"]; if ($areaname == ""){$areaname = $_GET["areaname"];} 
$supplier_tax1 					= $_POST["supplier_tax1"]; if ($supplier_tax1 == ""){$supplier_tax1 = $_GET["supplier_tax1"];} 
$supplier_tax2 					= $_POST["supplier_tax2"]; if ($supplier_tax2 == ""){$supplier_tax2 = $_GET["supplier_tax2"];} 
$supplier_tax3 					= $_POST["supplier_tax3"]; if ($supplier_tax3 == ""){$supplier_tax3 = $_GET["supplier_tax3"];} 
$supplier_tax4 					= $_POST["supplier_tax4"]; if ($supplier_tax4 == ""){$supplier_tax4 = $_GET["supplier_tax4"];} 
$supplier_tax5 					= $_POST["supplier_tax5"]; if ($supplier_tax5 == ""){$supplier_tax5 = $_GET["supplier_tax5"];} 
$supplier_vat 					= $_POST["supplier_vat"]; if ($supplier_vat == ""){$supplier_vat = $_GET["supplier_vat"];} 
$supplier_vatno			 		= $_POST["supplier_vatno"]; if ($supplier_vatno == ""){$supplier_vatno = $_GET["supplier_vatno"];} 
$vat_date 						= $_POST["vat_date"]; if ($vat_date == ""){$vat_date = $_GET["vat_date"];} 
$supplier_approved 				= $_POST["supplier_approved"]; if ($supplier_approved == ""){$supplier_approved = $_GET["supplier_approved"];} 
$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"];} 
$supplier_paymentterm 			= $_POST["supplier_paymentterm"]; if ($supplier_paymentterm == ""){$supplier_paymentterm = $_GET["supplier_paymentterm"];} 
$supplier_sub 					= $_POST["supplier_sub"]; if ($supplier_sub == ""){$supplier_sub = $_GET["supplier_sub"];} 
$localexport 					= $_POST["localexport"]; if ($localexport == ""){$localexport = $_GET["localexport"];} 
$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"];} 
$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"];} 

$fax 					 		= $_POST["fax"]; if ($fax == ""){$fax = $_GET["fax"];} 
$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"];} 

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


$country 			 			= $_POST["country"]; if ($country == ""){$country = $_GET["country"];} 
$state 		 					= $_POST["state"]; if ($state == ""){$state = $_GET["state"];} 
$city_supplier	 				= $_POST["city_supplier"]; if ($city_supplier == ""){$city_supplier = $_GET["city_supplier"];} 
$supplier_group		 			= $_POST["supplier_group"]; if ($supplier_group == ""){$supplier_group = $_GET["supplier_group"];} 
$Address 	 					= $_POST["Address"]; if ($Address == ""){$Address = $_GET["Address"];} 
$Address2  	 					= $_POST["Address2"]; if ($Address2 == ""){$Address2 = $_GET["Address2"];} 
$Address3  	 					= $_POST["Address3"]; if ($Address3 == ""){$Address3 = $_GET["Address3"];} 

$supplier_mothercompany 		= $_POST["supplier_mothercompany"]; if ($supplier_mothercompany == ""){$supplier_mothercompany = $_GET["supplier_mothercompany"];} 
$supplier_companyname			= $_POST["supplier_companyname"]; if ($supplier_companyname == ""){$supplier_companyname = $_GET["supplier_companyname"];} 
$titleowner_description 		= $_POST["titleowner_description"]; if ($titleowner_description == ""){$titleowner_description = $_GET["titleowner_description"];} 
$supplier_companyowner 			= $_POST["supplier_companyowner"]; if ($supplier_companyowner == ""){$supplier_companyowner = $_GET["supplier_companyowner"];} 
$titlerefered_description		= $_POST["titlerefered_description"]; if ($titlerefered_description == ""){$titlerefered_description = $_GET["titlerefered_description"];} 
$supplier_referedby 			= $_POST["supplier_referedby"]; if ($supplier_referedby == ""){$supplier_referedby = $_GET["supplier_referedby"];} 

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

$businesssector					= $_POST["businesssector"]; if ($businesssector == ""){$businesssector = $_GET["businesssector"];} 
$supplier_businesssector		= $_POST["supplier_businesssector"]; if ($supplier_businesssector == ""){$supplier_businesssector = $_GET["supplier_businesssector"];} 
$supplier_businesssectordesc	= $_POST["supplier_businesssectordesc"]; if ($supplier_businesssectordesc == ""){$supplier_businesssectordesc = $_GET["supplier_businesssectordesc"];} 
$supplier_btype2 				= $_POST["supplier_btype2"]; if ($supplier_btype2 == ""){$supplier_btype2 = $_GET["supplier_btype2"];} 
$supplier_btype3 				= $_POST["supplier_btype3"]; if ($supplier_btype3 == ""){$supplier_btype3 = $_GET["supplier_btype3"];} 	


//Gilbert 7/3/2013
//echo $SupplierFirstDigit; exit;
/*
if($check_ledgergrp == '')
{
	$check_ledgergrp = 1;
}
*/
if($check_ledgergrp=='1'){
//echo "test";
	///Making Supplier code Readonly
	//$statuscode='readonly';
	//echo$module_ledgergrp;
	if($module_ledgergrp=='0' && $mainmode!='editmode'){
		
		if($ledger_number != ''){
			$usedCode = $ledger_number;
			$query = "select max(ledger_number)+1 from suppliers 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_supplier=strlen($ledger_number);
				$left_length=$NbrOfDigitInLedger-$length_supplier;
				$supplier_increment=str_pad('0', $left_length, '0', STR_PAD_LEFT);
				$ledger_number=$ledger_number.$supplier_increment;
				$ledger_numberPrv=$ledger_number;
			}			
			
		} else {
			///Getting length of Supplier first digit + Total of length for ledger number should be
			$length_supplier_firstdigit=strlen($SupplierFirstDigit);
			$left_length=$NbrOfDigitInLedger-$length_supplier_firstdigit;
			
			/// Supplier Increment
			$query_increment="select Supplier_Increment from sequence";
			$resultincrement=mysql_query($query_increment,$connection) or die(mysql_error());
			$row_increment=mysql_fetch_row($resultincrement);
			$supplier_increment=$row_increment[0];
			$supplier_increment=$supplier_increment+1;
			
			
			$supplier_increment=str_pad($supplier_increment, $left_length, '0', STR_PAD_LEFT);
			$ledger_number=$SupplierFirstDigit.''.$supplier_increment;
			$ledger_numberPrv=$ledger_number;
		}
	}
	
	else if($module_ledgergrp=='1'){
			$message='Please Start By Choosing A Group';
			$check_ledgergrp='0';
	}
}


//Gilbert 7/3/2013
if($fill_ledger=='1'){
		echo "test2";
		$length_supplier_groupcode=strlen($supplier_groupcode);
		$left_length=$NbrOfDigitInLedger-$length_supplier_groupcode;
		
		$query_reference="select LedgerGrp_reference from ledgergrp where LedgerGrp_Code='".$supplier_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=$supplier_groupcode.$ledgergrp_reference;
		$ledger_numberPrv=$ledger_number;
	}
	

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

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

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


if($mainmode=='editmode' or $mainmode=='view'){
//if ($ledger_number != '' && $checkcode!=1) {

	$query_edit="select Ledger_number,Ledger_name, Ledger_Desc, Supplier_Representative,Supplier_Address, Supplier_Telephone1, Supplier_Telephone2, 
			Supplier_Fax, Supplier_Email, Supplier_Homepage, Supplier_CreditLimit,Supplier_PaymentTerms,Area_Code, 
			Currency_Code,Supplier_VatNo, Supplier_Approved,Supplier_Address2, Supplier_city, Supplier_State,
			Supplier_country,Project_Code, Costcenter_Code,Supplier_Group,SupplierGrp_Code,Supplier_Tax1,
			Supplier_Tax2,Supplier_Tax3,Supplier_Tax4,Supplier_Tax5,Supplier_BelongsToGroup,
			date_format(Supplier_VAtDate,'%d-%m-%Y'),Supplier_VAT,supplier_MotherCompany,
			Supplier_CompOwnerTitle,Supplier_CompOwner,Supplier_ReferedByTitle,
			Supplier_ReferedBy,Supplier_GCINO,Supplier_BusinessSector,Supplier_BusinessSectorDesc,
			Supplier_BType2,Supplier_BType3,Supplier_SubContractor,ifnull(supplier_export,0),Supplier_Group,supplier_CreationDate, Ledger_nameF, Supplier_Address3 , paymentcondition
			from suppliers
			where ledger_number='$ledger_number'";
	//ECHO$query_edit;
	$resultedit=mysql_query($query_edit,$connection) or die(mysql_error());
	while($row=mysql_fetch_array($resultedit)){

		$ledger_number=$row[0];
		$ledger_numberPrv=$row[0];
		$ledger_name=$row[1];
		$ledger_namef=$row[46];
		$ledger_description=$row[2];
		$representative=$row[3];
		$Address=$row[4];
		$phone1=$row[5];
		$phone2=$row[6];
		$fax=$row[7];
		$email=$row[8];
		$homepage=$row[9];
		$credit_limit=$row[10];
		$supplier_paymentterm=$row[11];
		$area_code=$row[12];
		$currency_code=$row[13];
		$supplier_vatno=$row[14];
		$supplier_approved=$row[15];
		$Address2=$row[16];
		$Address3=$row[47];
		$city_supplier=$row[17];
		$state=$row[18];
		$country=$row[19];
		$project_code=$row[20];
		$costcenter_code=$row[21];
		$supplier_groupcode=$row[23];
		$supplier_tax1=$row[24];
		$supplier_tax2=$row[25];
		$supplier_tax3=$row[26];
		$supplier_tax4=$row[27];
		$supplier_tax5=$row[28];
		$vat_date=$row[30];
		$supplier_vat=$row[31];
		$supplier_mothercompany=$row[32];
		$title_owner=$row[33];
		$supplier_companyowner=$row[34];
		$title_refered=$row[35];
		$supplier_referedby=$row[36];
		$supplier_gcino=$row[37];
		$supplier_businesssector=$row[38];
		$supplier_businesssectordesc=$row[39];
		$supplier_btype2=$row[40];
		$supplier_btype3=$row[41];
		$supplier_sub=$row[42];
		$localexport=$row[43];
		$supplier_group=$row[44];
		$supplier_CreationDate=$row[45];
		$paymentcondition = $row[48];
	}

	$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 LedgerGrp_Code,LedgerGrp_name ".
			" from ledgergrp where LedgerGrp_Code=".$supplier_groupcode;
	$result=mysql_query($query5, $connection);
	$row=mysql_fetch_row($result);
	$supplier_groupname=$row[1];


	$query8="select Ledger_number,Ledger_name ".
			" from ledger where ledger_number='$supplier_mothercompany'";
			
	$result=mysql_query($query8, $connection);
	$row=mysql_fetch_row($result);
	$supplier_companyname=$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($mainmode=='') $mainmode='insert';

print <<<HERE

<head>
<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 PrintPreview()
{
if (confirm ( "Do you want to Print List of Suppliers?"))
	{
var str = '';
	
	str = 'Form_SupplierPreview.php';
	window.open(str);
}
}

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

function editmode () {
			document.supplierdt.mainmode.value='editmode';
			var l=document.supplierdt.ledger_number.value;
			document.supplierdt.action="Form_Suppliers.php?ledger_number="+l;
			document.supplierdt.submit();
}



function AddSuppliers () {
			
	document.supplierdt.check_ledgergrp.value=1;		
	document.supplierdt.mainmode.value='insert';		
	document.supplierdt.action='Form_Suppliers.php';
	document.supplierdt.submit();
}



function SubmitRecord(option) {
	
	var checkOK = "0123456789";
	
	
var checkStr = supplierdt.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 \"Supplier Code\" field.");
	tab_('Main Page','ledger_number');

	return (false);
}*/

var checkStr = supplierdt.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 checkStr = supplierdt.supplier_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','supplier_paymentterm');		
	return (false);
}


var checkStr = supplierdt.supplier_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)
{				
	document.supplierdt.othertab.value=1;
	alert("Please enter only digit characters in the \"GCI No\" field.");
	tab_('Others','supplier_gcino');
	
	return (false);
}	


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


var m=document.supplierdt.mainmode.value;

	if (document.supplierdt.ledger_number.value=='' ){		
	
		alert('Unable to save : check missing field Code in Main Page');
		tab_('Main Page','ledger_number');
	}
		
	else if (document.supplierdt.ledger_name.value=='' ){	
		
		alert('Unable to save : check missing field Name in Main Page');
		tab_('Main Page','ledger_name');
	}
		
	else if((document.supplierdt.vat.checked) && (document.supplierdt.supplier_vatno.value=='')){
		
		alert('Unable to save : Please Fill Vat No in Main Page');
		tab_('Main Page','supplier_vatno');
	}
	else 	if (document.supplierdt.currency_code.value=='' ){
		alert('Unable to save : check missing field Currency in Main Page');
		tab_('Main Page','currency');
		
	}
		
	/*else 	if (document.supplierdt.credit_limit.value=='' ){
		alert('Unable to save : check missing field Credit Limit in Main Page');
		tab_('Main Page','credit_limit');
	}
		
	
	else 	if (document.supplierdt.supplier_paymentterm.value=='' ){
		alert('Unable to save : check missing field Terms in Main Page');
		tab_('Main Page','supplier_paymentterm');
	}

	else 	if (document.supplierdt.area_code.value=='' ){
		
		alert('Unable to save : check missing field Area in in Main Page');
		tab_('Main Page','area_code');
	}
		
	else 	if (document.supplierdt.phone1.value=='' )
	{
		alert('Unable to save : check missing field Phone 1 in Contact Page');
		tab_('Contact','phone1');
		
	}*/
	
	else 	if (option==2 && document.supplierdt.telephoneno_title.value=='' )
	{
		alert('Unable to save : check missing field Title in Contact Page');
		tab_('Contact','telephoneno_title');
	}
	else 	if (option==2 && document.supplierdt.telephone_fname.value=='' )
	{
		alert('Unable to save : check missing field First Name in Contact Page');
		tab_('Contact','telephone_fname');
	}
	else 	if (option==2 && document.supplierdt.telephone_lname.value=='' )
	{
		alert('Unable to save : check missing field Last Name in Contact Page');
		tab_('Contact','telephone_lname');
	}
	else 	if (option==2 && document.supplierdt.telephone_name.value=='' )
	{
		alert('Unable to save : check missing field Name in Contact Page');
		tab_('Contact','telephone_name');
	}
	else 	if (option==2 && document.supplierdt.telephone_no.value=='' )
	{
		alert('Unable to save : check missing field Tel No in Contact Page');
		tab_('Contact','telephone_no');
	}
	
	
	else{
		if(option==2)
		
		document.supplierdt.actionmode.value='submitcontact';
		
		document.supplierdt.checkcode.value='1';
		document.supplierdt.check_ledgergrp.value=0;	
		document.supplierdt.fill_ledger.value=0;	
		
		document.supplierdt.action='Form_Suppliers_Actions.php?actionmode=submitcontact';
		document.supplierdt.submit();
	}	
	
	

}
//////////////////////////////////////////////////// end of supplier submit 


function showlistgroups(str){
	var module=document.supplierdt.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 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 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 AddClients () {

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



function showlistcostcenter(str){

  window.open('List_CostCenter.php','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 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 set_titleowner(){
	document.supplierdt.title_owner.value=document.supplierdt.titleowner_description.value;
}

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

function set_businesssector(){
	document.supplierdt.supplier_businesssector.value=document.supplierdt.businesssector.value;
}


function changetax(value) {

	var tax;
	tax='tax'+value;


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

	}
	else
	{
	document.supplierdt["supplier_tax"+value].value=0;

	}
}


function checksub (){

	if(document.supplierdt.subcontractor.checked){
	document.supplierdt.supplier_sub.value=1;
	}
	else 

	document.supplierdt.supplier_sub.value=0;

	}
	function checkapproved (){

	if(document.supplierdt.approved.checked){
		document.supplierdt.supplier_approved.value=1;
	}

	else {
		document.supplierdt.supplier_approved.value=0;
			}
}


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



function changevat(){
	if(document.supplierdt.vat.checked){
	document.supplierdt.supplier_vat.value=1;
	document.supplierdt.vatstatus.value='enabled';
	}
	else
	{
	document.supplierdt.supplier_vat.value=0;
	document.supplierdt.vat_date.value='';
	document.supplierdt.supplier_vatno.value=' ';
	document.supplierdt.vatstatus.value='disabled';
	}


	document.supplierdt.action='Form_Suppliers.php';
	document.supplierdt.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(){
	if (confirm ( "Are you sure you want to Clear Page?"))
	{
		ClearForm('All');
		document.supplierdt.action='Form_Suppliers.php';
		document.supplierdt.submit();
	}	
}

//All= All form; D= Detail Part
function ClearForm(Option){
    x = document.supplierdt;
	
	var vmode = x.mainmode.value;
	
	if (Option == 'All') {
		
		x.message.value='';
		x.supplier_sub.value='';
		if(x.supplier_btype2)
		x.supplier_btype2.value='';
		x.supplier_btype3.value='';
		x.supplier_businesssectordesc.value='';
		x.supplier_businesssector.value='';
		x.supplier_gcino.value='';
		x.supplier_referedby.value='';
		x.title_refered.value='';
		x.supplier_companyowner.value='';
		x.title_owner.value='';
		x.supplier_mothercompany.value='';
		x.supplier_companyname.value='';
		x.supplier_approved.value='';
		x.ledger_number.value='';
		x.representative.value='';
		
		x.supplier_groupcode.value='';
		x.ledger_name.value='';
		x.ledger_namef.value='';
		x.ledger_description.value='';
		x.supplier_vat.value='';
		x.supplier_vatno.value='';
		x.vat_date.value='';

		x.currency_code.value='';
		x.credit_limit.value='';
		x.project_code.value='';
		x.supplier_paymentterm.value='';
		x.costcenter_code.value='';
		//if(x.credit_control)
		x.costcenter_name.value='';
	
		x.supplier_tax1.value='';
		x.supplier_tax2.value='';
		x.supplier_tax3.value='';
		x.supplier_tax4.value='';
		x.supplier_tax5.value='';
		x.country.value='';
		x.state.value='';
		x.city_supplier.value='';
		x.area_code.value='';
		x.areaname.value='';
		x.Address.value='';
		x.Address2.value='';
		x.Address3.value='';
		x.homepage.value='';
		x.phone1.value='';
		x.email.value='';
		x.phone2.value='';
		x.fax.value='';

		x.fax.value='';
		x.mainmode.value = '';
		x.supplier_groupname.value='';
		if(x.project_name)
		x.project_name.value='';
		x.fill_ledger.value='0';
		x.module_ledgergrp.value='';
		x.check_ledgergrp.value='';
		x.supplier_group.value='';
		x.localexport.value='0';
		x.ledger_numberPrv.value='';
		
		x.supBankName.value='';
		x.supBankAddr.value='';
		x.supAccNbr.value='';
		x.supSortCode.value='';
		x.supIBAN.value='';
		x.supSwift.value='';
	} 
}


function SearchForSupplier(){
    ClearForm('All');
    x = document.supplierdt;
    win = window.open('Form_SupplierSearch.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 UpdateDetail(TelephoneId){
	 x = document.supplierdt;
	 x.telephone_increment.value=TelephoneId;
	x.actionmode.value='refresh';
	x.action='Form_Suppliers.php?vTabFocus=Contact';
	x.submit();
}	

function DeleteDetail(TelephoneId){

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

}

function cleardetail(PIndex){
	 x = document.supplierdt;

	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='';
	
	if(PIndex==2)
		document.supplierdt.submit();	
}



function SetSup(SupId){
	
	document.supplierdt.ledger_number.value=SupId;
	document.supplierdt.message.value='';
	document.supplierdt.actionmode.value='';
	cleardetail(1);
	document.supplierdt.mainmode.value='editmode';
	document.supplierdt.submit();
}

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

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

function SearchForSup(){
	x = document.supplierdt;
	document.supplierdt.action='Form_Suppliers.php?startrange=0';
	document.supplierdt.submit();
}

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

function set_limit(){

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


//mycode

function addserial(){
	
	var ledgernumber= document.supplierdt.ledger_number.value;
	//document.supplierdt.check_ledgergrp.value=1;
	//alert (ledgernumber.toString().length);
	if(ledgernumber.toString().length<4 || ledgernumber.toString().length>8){
			alert("Minimum Number/Name of digits is 4");
			return;
	}
	document.supplierdt.action='Form_Suppliers_Actions.php?actionmode=getledgergroup&ledger_number='+ledgernumber;
	document.supplierdt.submit();
}


function showlistitem(str){
	window.open('select_item.php?item='+str,'mywindow','width=900,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}
function insertitem (id, ledger_number){
	if(id=='')
		var actionmode='insertitem';
	else var actionmode='updateitem';
	
	itemcode = document.getElementById("item_code").value;
if(ledger_number == '') {
	alert("Please Save Supplier!");
	return 0;
} else if(itemcode == ''){
	alert("Please Select an Item!");
	return 0;
} else {
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			var data = xmlhttp.responseText.split("[BRK]");
			document.getElementById('item_supplier').innerHTML=data[1];
		}
	  }

  
	xmlhttp.open("GET","Form_Suppliers_Actions.php?mainmode=&actionmode="+actionmode+"&itemSupplier_id="+id+"&ledger_number="+ledger_number+"&item_code="+itemcode,true);
	xmlhttp.send();
}
}

function getItem(id, ledger_number){
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			var data = xmlhttp.responseText.split("[BRK]");
			document.getElementById('item_supplier').innerHTML=data[1];
		}
	  }
	xmlhttp.open("GET","Form_Suppliers_Actions.php?mainmode=&actionmode=getItem&itemSupplier_id="+id+"&ledger_number="+ledger_number,true);
	xmlhttp.send();  
}
function deleteItem(id, ledger_number){
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			var data = xmlhttp.responseText.split("[BRK]");
			document.getElementById('item_supplier').innerHTML=data[1];
		}
	  }
	xmlhttp.open("GET","Form_Suppliers_Actions.php?mainmode=&actionmode=deleteItem&itemSupplier_id="+id+"&ledger_number="+ledger_number,true);
	xmlhttp.send();  
}
function showlistgrouping(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 loadItems(ledger_number){
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			var data = xmlhttp.responseText.split("[BRK]");
			document.getElementById('item_supplier').innerHTML=data[1];
		}
	  }
	var group_code = document.supplierdt.group_code.value; 
	xmlhttp.open("GET","Form_Suppliers_Actions.php?mainmode=&actionmode=loadItems&ledger_number="+ledger_number+"&group_code="+group_code,true);
	xmlhttp.send(); 
}

function returnMsg(){
	alert('Access Denied!');
	return 0;
}

</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Add Supplier</title>

<style type="text/css">

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

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

</style>

<link type="text/css" rel="stylesheet" href="dhtmlgoodies_calendar.css?random=20051112" media="screen"></LINK>
<SCRIPT type="text/javascript" src="dhtmlgoodies_calendar.js?random=20060118"></script>

</head>
<body >
<form name='supplierdt' method='post' action=''>
<input type='hidden' name='HideMenu' value='$HideMenu'>
<input type=hidden name='checkcode' value='$checkcode'>
<input type='hidden' name='mainmode' value='$mainmode'>
<input type='hidden' name='actionmode' value='$actionmode'>
<input type=hidden name='vatstatus' value='$vatstatus'>
<input type=hidden name='message' value='$message'>
<input type=hidden name='title_owner' value='$title_owner'>
<input type=hidden name='title_refered' value='$title_refered'>
<input type='hidden' name='check_ledgergrp' value='$check_ledgergrp'>
<input type='hidden' name='fill_ledger' value='$fill_ledger'>
<input type='hidden' name='module_ledgergrp' value='$module_ledgergrp'>
<input type='hidden' name='telephone_increment' value='$telephone_increment'>
<input type='hidden' name='supplier_vat' value='$supplier_vat'>
<input type='hidden' name='ledger_numberPrv' value='$ledger_numberPrv'>
HERE;

$query="select 1 from journaldt where ledger_number='".$ledger_numberPrv."'
	union
	select 1 from purchases where Supplier_code='".$ledger_numberPrv."'
	union
	select 1 from grnpurchases where Supplier_code='".$ledger_numberPrv."'
	union
	select 1 from purchasesjv where Supplier_Code='".$ledger_numberPrv."'";

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

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

if($supplier_vat!='1')
	$vatstatus='disabled';

else $vatstatus='enabled';

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

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

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

/*if($addSupplier == 1){
	echo "<script>addserial();</script>";
	$addSupplier = 0;
}*/
if($supplier_tax1=='1')
	$selectedtax1='checked';

if($supplier_tax2=='1')
	$selectedtax2='checked';	

if($supplier_tax3=='1')
	$selectedtax3='checked';

if($supplier_tax4=='1')
	$selectedtax4='checked';	

if($supplier_tax5=='1')
	$selectedtax5='checked';
			
if($supplier_approved=='1')
	$selectedapprove='checked';

if(empty($supplier_approved))
	$supplier_approved=0;

if(empty($supplier_sub))
	$supplier_sub=0;

if($supplier_sub=='1')
	$selectedsub='checked';

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=$Supplier_DefaultCur;

//$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'>SUPPLIERS</span></td>
						<td class='message' valign='middle' style='height:26px;'>".htmlspecialchars($message, ENT_QUOTES)."</td>
					</tr>
				</table>
			</td>
		</tr>";
					$querysearch="select ledger_number,ledger_name from suppliers ";
					$querysearch=$querysearch." where (ledger_number like"."('%".$txtKeyword."%') or ledger_name like"."('%".$txtKeyword."%')) order by ledger_number ";

					$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());
					$totalrows = mysql_num_rows($resultsearch);
					
					if ($startrange=='')
						$startrange = 0;
					if ($perpage=='')
						$perpage = 20;
					$querysearch = $querysearch." limit ".$startrange.",".$perpage;
	echo"<tr>
			<td  height='34'  valign='top' id='content-top2'>
				<table border='0' cellpadding='0' cellspacing='0' class='layout-width' width='1100px'>
					<col width='450'>
					<col width='200'>
					<col width='200'>
					<col width='200'>
					<col width='200'>
					<col width='200'>
					<tr>
						<td height='34'style='padding-left:52px'>";
	echo"					<button type='button' id='btnClear' name='btnClear' onclick='ClearPage(); return false;' title='Clear Page'><span><span>$buttonclear</span></span></button>";
//	echo"					<button type='button' id='btnAddClient' name='btnAddClient' onclick='AddClients(); return false;' title='Add Client'><span><span>Add</span></span></button>";
	if ($FI_SuppliersApp == 1)
	echo"					<button  type='button'  value='Check' onclick='AddSuppliers();return false;' title='Check'><span><span>$add</span></span></button>";
	
	echo"					<button  type='button'  value='Check' onclick='addserial();return false;' title='Check'><span><span>$check</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"  			 	</td>";
	
			echo"		<td><button type='button' id='btnExcel' name='btnExcel' onclick='ExportExcel(); return false;' title='Export Excel' ><span><span>Excel</span></span></button>";
							$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>";			

	echo"				<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='SearchForSup(); return false;' title='Search Supplier'><span><span>$find</span></span></button>
							<button type='button' id='btnClear' name='btnClear' onclick='ClearKeyword(); return false;' title='Clear Keyword'><span><span>$clear</span></span></button>
		
						</td>
						
						<td align='left'>
							<span class='style1'><b>$results/$page</b></span>
							<span class='style1'><select name='perpage' id='perpage' value='$perpage' onchange=set_limit();>";
							if ($startrange=='')
								$startrange = 0;
							if ($perpage=='')
								$perpage = 20;
								
							//row limit loop
								foreach ($config['trowlimit'] as $value) {
								echo "<option value='$value' ";
										if($value==$perpage) echo "selected";
										echo " >$value</option>";
								}
	echo"				</td>
					</tr>
				</table>
			</td>
		</tr>";

	echo "<tr><td id='content-body'>";

$tabs = new tabs("Suppliers");	
$tabs->start("$tab1");

	echo"	<table border='0'  align='center' valign='top' width='1100px' class='tablecontent'>
				<tr bgcolor='#F7F7F7' height='25' >
					<td valign='top'>
						<table border='0' style='table-layout:fixed' align='left' width='1100px' valign='top'>
							<col width=140>
							<col width=130>
							<col width=80>
							<col width=90>
							<col width=70> 
							<col width=70>
							<tr bgcolor='#F7F7F7' height='25'>
								<td valign='center' align='left' ><span class='style1'>$creationdate &nbsp;</span></td>";
									if($mainmode!=''){
									$today = date('d/m/Y');
									$supplier_CreationDate = $today;
									}
		echo "						<td align='left'><b>$supplier_CreationDate</b></td>
							</tr>
							<tr bgcolor='#F7F7F7' height='25'>";
	//Gilbert 7/3/2013 
	// if module false , hide group fields

									if($module_ledgergrp=='1'){	  
							echo"<td valign='center' align='left' ><span class='style1'>$groupsupplier</span></td>
								 <td align=left> <input type='text' name='supplier_groupcode' value='$supplier_groupcode' maxlength='15' style='font-size:12px; width:100px; ' readonly />";
									 
									if($mainmode!='view' && $mainmode!='')
									echo" <label><span class='style1'><input type='image' src='img/btnopen.jpg' title=' Select Group '  width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistgroups(2); return false;' /></span></label>";
						echo" 	</td>";
												
						echo"	<td colspan=5  bgcolor='#F7F7F7'>
									<input type='text' name='supplier_groupname' value='$supplier_groupname' maxlength='32' style='font-size:12px; width:240px; ' readonly />
								</td>";
									}
									else {
						echo " 	<td><input type='hidden' name='supplier_groupcode' value='$supplier_groupcode'>
								<td><input type='hidden' name='supplier_groupname' value='$supplier_groupname'><td>
								<td><td colspan=2 ><td>";
									}	

									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';
									}
							
	echo"						<td align=left ><input type=$Tax1Text name='tax1' onclick='changetax(1)'  $dis $selectedtax1><input type='hidden' name='supplier_tax1' value='$supplier_tax1'>";
									if ($Tax1Text=='checkbox')
									echo"<span class='style1'>Tax 1</span> &nbsp;&nbsp;";			
				echo"			</td>
							</tr>
							<tr bgcolor='#F7F7F7' height='25'>
								<td valign='center' align='left' ><span class='style1'>$sup_code <span class='style26'>*</span>/ $sup_name</span></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:100px; ' $statuscode/>";
										}
										if($msg==''){
	echo "						<td><input type='text' name='ledger_number' value='$ledger_number' maxlength='10' style='font-size:12px; width:100px; ' $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:100px; ' $statuscode/></td>";
										}
	echo "						<td colspan=5><input type='text' name='ledger_name' value='".htmlspecialchars($ledger_name, ENT_QUOTES)."' maxlength='50' style='font-size:12px; width:240px; ' $status /></td> 
								<td align=left ><input type=$Tax2Text name='tax2' onclick='changetax(2)'  $dis $selectedtax2><input type='hidden' name='supplier_tax2' value='$supplier_tax2'>";
										if ($Tax2Text=='checkbox')
										echo"<span class='style1'>Tax 2</span>";
	echo"						</td>
							</tr>	 
							<tr bgcolor='#F7F7F7' height='25'> 
								<td valign='center' align='left' ><span class='style1'>$name_arabic</span></td>
								<td colspan=6><input type='text' name='ledger_namef' value='".htmlspecialchars($ledger_namef, ENT_QUOTES)."' maxlength='50' style='font-size:12px; width:372px;'  $status /></td>
								<td></td>
							</tr>	
					
							<tr bgcolor='#F7F7F7' height='25'>
								<td align=left><span class='style1'>$representative_supplier</span></td><td colspan=6><input type=text name='representative' value='".htmlspecialchars($representative, ENT_QUOTES)."'  $status style='font-size:12px; width:372px; ' maxlength=50></td> 
								<td align=left><input type=$Tax3Text name='tax3' onclick='changetax(3)'  $dis $selectedtax3><input type='hidden' name='supplier_tax3' value='$supplier_tax3'>";
								if ($Tax3Text=='checkbox')
									echo"<span class='style1'>Tax 3</span>";
		echo"					</td>
							</tr>	";
		echo"				<tr bgcolor='#F7F7F7' height='25'>
								<td valign='center' align='left' ><span class='style1'>$supplier_desc</span></td>
								<td colspan=6>
								<input type='text' name='ledger_description' value='".htmlspecialchars($ledger_description, ENT_QUOTES)."' maxlength='255' style='font-size:12px; width:372px; '  $status />
								</td>
								<td align=left ><input type=$Tax4Text name='tax4' onclick='changetax(4)'  $dis $selectedtax4><input type='hidden' name='supplier_tax4' value='$supplier_tax4' >";

									if ($Tax4Text=='checkbox')
										echo"<span class='style1'>Tax 4</span>";
			echo"				</td>
							</tr>";   
								$lenAddress=strlen($Address);
								$restaddress=100-$lenAddress;
		echo"				<tr bgcolor='#F7F7F7' height='25'>
								<td><span class='style1'>$supplier_area &nbsp;</span>
								<td><input type='text' name='area_code' value='".htmlspecialchars($area_code, ENT_QUOTES)."'  readonly style='font-size:12px; width:100px; '>&nbsp;";
									if($mainmode!='view' && $mainmode!='')
		echo"						<label><span class='style1'><input type='image' src='img/btnopen.jpg' title=' Select Area '  width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistarea(3); return false' /></span></label>
								</td>
								<td colspan=5><input type='text' name='areaname' value='".htmlspecialchars($areaname, ENT_QUOTES)."' readonly size='31' style='font-size:12px; width:240px; '></td>	
								<td align=left colspan=1><input type=$Tax5Text name='tax5' onclick='changetax(5)'  $dis $selectedtax5><input type='hidden' name='supplier_tax5' value='$supplier_tax5'>";
									if ($Tax5Text=='checkbox')
										echo"<span class='style1'>Tax 5</span>
								</td>
							</tr>";
		  
		echo"				<tr bgcolor='#F7F7F7' height='25'>
								<td align='left'><span class='style1'><input type=checkbox name='vat' onclick='changevat()'  $dis $selectedvat>$suppliervat</span>
									<span class='style1'> &nbsp; $supp_vatNum</td><td><input type='text' name='supplier_vatno' value='".htmlspecialchars($supplier_vatno, ENT_QUOTES)."'  maxlength=20 style='font-size:12px; width:100px; ' $status $vatstatus></span> ";
		echo"					<td align='center' ><span class='style1'>$supp_vatdate</span></td>
								<td  colspan='3'><input type='text' readonly name='vat_date' value='$vat_date' maxlength='10' size='10' style='font-size:12px; width:158px; '>&nbsp;&nbsp;";
									if($mainmode!='view' && $mainmode!='' && $supplier_vat=='1'){
print<<< HERE
<A HREF="#" onClick="displayCalendar(document.supplierdt.vat_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>
								<td></td>
								<td>
									<input type=checkbox name='approved'  onclick='checkapproved();' $dis $selectedapprove>
									<input type='hidden' name='supplier_approved' value='$supplier_approved'><span class='style1'>$chckapp</span>
								</td>
							</tr> ";
												 
									if(!isset($discount))
										$discount=0;

		echo"				<tr bgcolor='#F7F7F7' height='25'>
								<td align='left' bgcolor='#F7F7F7' height='25'><span class='style1'>$supCurrency &nbsp;</span>";
			 //if($module=='1')
	echo"							<span class='style26'>*</span>
								</td>	
								<td  bgcolor='#F7F7F7' height='25'>
									<select  name='currency' onchange='fill_curr();' style='width:100px;' $status $dis>
										<option value=''></option>";
										while ($cr=mysql_fetch_row($curr))
										{
										if ($cr[0]==$currency_code)
										echo"<option selected value='$cr[0]'>$cr[0]</option>";
										else
										echo"<option value='$cr[0]'>$cr[0]</option>";
										}	
										echo"<input type='hidden' name='currency_code' value='$currency_code'>
								</td>
								<td align='right' bgcolor='#F7F7F7' height='25'><span class='style1'>$Sup_cred</span>";
										 
									///if($module=='1')
									// echo"<span class='style26'>*</span>";
		echo"					</td>
								<td bgcolor='#F7F7F7'>
									<input type='text' name='credit_limit' value='".htmlspecialchars($credit_limit, ENT_QUOTES)."' maxlength='15' $status size='14' style='font-size:12px; width:80px; '>
								</td>
								<td align=left bgcolor='#F7F7F7' colspan=3><span class='style1'>$sup_payterm &nbsp;</span> 
									<input type=text name='supplier_paymentterm' value='".htmlspecialchars($supplier_paymentterm, ENT_QUOTES)."'  maxlength='3' $status  size='4' style='font-size:12px; width:50px; '></td>
								<td>
									<input type=checkbox name='subcontractor'  onclick='checksub();' $dis $selectedsub>
									<input type='hidden' name='supplier_sub' value='$supplier_sub'><span class='style1'>$checksub</span>
								</td>
							</tr>
							<tr bgcolor='#F7F7F7' height='25'> 
								<td align='left' bgcolor='#F7F7F7' height='25'><span class='style1'>$projectcode / $projectname</span></td>
								<td align=left colspan=6  bgcolor='#F7F7F7' height='25'><input type=text name='project_code' value='$project_code' maxlength='30' $status readonly size='24' style='font-size:12px; width:100px; '>";
												 
									if($mainmode!='view' && $mainmode!='')
										echo" <label><span class='style1'><input type='image' src='img/btnopen.jpg' title=' Select Project '  width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistprojects(2); return false' /></span></label>";
										
										else echo"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";	
												
												echo"&nbsp;<input type=text name='project_name' value='$project_name' maxlength='20' $status readonly size='24' style='font-size:12px; width:240px; '>";			

									if($mainmode!='view' && $mainmode!='') {
										echo"&nbsp;<label><span class='style1'><input type='image' src='img/btnopen.jpg' title=' Select Project '  width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistprojectsname(2); return false' /></span></label></td>";
									}

		echo"					<td><input type='radio' name='localexport' value='1'";if($localexport==1) echo " checked ";echo" $dis><span class='style1'>$Chkexpor</span><br> 
									<input type='radio' name='localexport' value='0'";if($localexport==0) echo " checked ";echo" $dis><span class='style1'>$Chcklocal</span>
								</td>
							</tr>
							<tr bgcolor='#F7F7F7' height='25'>
								<td align='left' bgcolor='#F7F7F7' height='25'><span class='style1'>$costcenter_supp</span></td>
								<td align=left colspan=7  bgcolor='#F7F7F7' height='25'><input type=text name='costcenter_code' value='$costcenter_code' maxlength='30' $status readonly size='24' style='font-size:12px; width:100px; '>";
									if($mainmode!='view' && $mainmode!='')
										echo" <label><span class='style1'><input type='image' src='img/btnopen.jpg' title=' Select Costcenter '  width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistcostcentercode(2); return false' /></span></label>&nbsp;";
										
									else  echo"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";	
										
										echo"<input type=text name='costcenter_name' value='$costcenter_name' maxlength='20' $status readonly size='24' style='font-size:12px; width:240px; '>";			

									 if($mainmode!='view' && $mainmode!='')
										echo"&nbsp;<label><span class='style1'><input type='image' src='img/btnopen.jpg' title=' Select Costcenter '  width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistcostcentername(2); return false' /></span></label></td>";
		echo" 				</tr>";
	 echo" 				</table>
					</td>
				";
				
			//FETCH TABLE
echo "		<tr>
				<td  valign='top'>
					<table style='width:1100px;' border='0' cellspacing=0>
						<col width=100>
						<col width=150>
						<tr>
							<td  style='width:1100px;height:15px;' colspan='4'></td>
						</tr>
						<tr>
							<td  valign='top' colspan=3 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>$sup_code</b></td>
										<td align='center'><span class='style1'><b>$sup_name</b></td>
									</tr>
									<tr>
										<td colspan=3>";
										//	<div style='overflow-y:scroll;height:320px;width:1090px;border:0px solid #000000;padding-left:5px;'>
echo"											<table  border='0' width='1100px'>
													<col width=30>
													<col width=160>
													<col width=170>";
													
													$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());	
													while($rows=mysql_fetch_array($resultsearch)){
														$ct+=1;
														$stylefont='style15';
														if($ct%2==0)
															$Color="style='background-color:".$grid_color1."'";
														else			
															$Color="style='background-color:".$grid_color2."'";	
																
														if($mainmode=='edit' && $ledger_numberPrv==$rows[0]){
															
															$Color="style='background-color:#1e87a5'";
															$stylefont='style28';
													}	
												echo'<tr '.$Color.' height="20px" >';
					
														if($FI_SuppliersDel==1)	
print<<<HERE

														<td align=center ><img border='0' src='img/c_delete.png' width='9' height='10' title='Delete Detail' onmouseover="this.style.cursor='pointer'" OnClick="confirm_delete('$rows[0]')" $DelMode></td>
HERE;
														else
															print<<<HERE
														<td align=center >&nbsp;</td>
HERE;
echo"													<td style='cursor:pointer;' ";if($FI_SuppliersMod==1) echo " onclick=SetSup('$rows[0]');";echo"><span class='$stylefont' >$rows[0]&nbsp;</span></font></td>
														<td style='cursor:pointer;' ";if($FI_SuppliersMod==1) echo " onclick=SetSup('$rows[0]');";echo"><font face='Arial' size='2' color='#186194'><span class='$stylefont'>$rows[1]&nbsp;</span></font></td>";
echo"												</tr>";
													}		
echo"											</table>";
										//	</div>
echo"									</td>
									</tr>
							</tr>
							</table>
						</td>
					</tr>";	
		/*echo"		<tr >
						<td colspan='4'>
							<table width=100% border='0'>
								<tr>
									<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>
								</tr>
							</table>
						</td>
					</tr>";*/

		echo"		<tr>
						<td style='width:380px;height:20px;' colspan='6'></td>
					</tr>
				</table>
			</td>
		</tr>";			
echo"</table>";

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

echo"	<table border='0' style='table-layout:fixed' align='left'width='1100px' valign='top'>
			<col width='50'>
			<col width='100'>
			<col width='50'>
			<col width='200'>
			<col width='50'>
			<col width='200'>";	
echo"		<tr bgcolor='#F7F7F7' height='35'>
				<td align=left><span class='style1'>$fax_label</span></td>
				<td ><input type='text' name='fax' value='".htmlspecialchars($fax, ENT_QUOTES)."'  maxlength='25' $status style='font-size:12px; width:120px; '></td>
				<td><span class='style1'>$email_label </span></td>
				<td><input type='text' name='email' value='".htmlspecialchars($email, ENT_QUOTES)."' size='80' maxlength='100' $status style='font-size:12px; width:300px; '></td>
				<td><span class='style1'>$home_page</span></td>
				<td ><input type='text' name='homepage' value='".htmlspecialchars($homepage, ENT_QUOTES)."'  size='80' maxlength='100' $status style='font-size:12px; width:300px; '></td>
			</tr>";

echo"		<tr bgcolor='#F7F7F7' height='35'>
				<td ><span class='style1'>$phone1_label &nbsp;</span>";
				//  if($module=='1')
				//	echo"<span class='style26'>*</span>";
echo"			</td>
				<td ><input type='text' name='phone1' value='".htmlspecialchars($phone1, ENT_QUOTES)."' maxlength='25' $status style='font-size:12px; width:120px; '></td>
				<td align=left><span class='style1'>$phone2_label </span></td>
				<td  ><input type='text' name='phone2' value='".htmlspecialchars($phone2, ENT_QUOTES)."' maxlength='25' $status style='font-size:12px; width:303px; '></td>
			</tr>";
			

echo"		<tr >
				<td colspan=6>
					<div style='overflow:scroll;height:150px;width:1100px;border:0px solid #000000;'>
						<table width='1100px' border='0'>
							<col width='200'>
							<col width='200'>
							<col width='200'>
							<col width='200'>
							<col width='200'>
							<col width='200'>
							<col width='200'>
							<col width='200'>
							<col width='200'>
							<col width='200'>
							<col width='200'>
							<col width='200'>
							<col width='200'>
							<tr bgcolor='#D0D0D0' height='25px'>
								<td >&nbsp;&nbsp;</td>
								<td >&nbsp;&nbsp;</td>
								<td align='center'><span class='style27'>$title<span class='style26'>*</span></span></td>
								<td align='center'><span class='style27'>$first_namelabel<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'>$lastname_label<span class='style26'>*</span></span></td>
								<td align='center'><span class='style27'>$tel1_label<span class='style26'>*</span></span></td>
								<td align='center'><span class='style27'>$tel2_label</span></td>
								<td align='center'><span class='style27'>$tel3_label</span></td>
								<td align='center'><span class='style27'>$suppemail</span></td>
								<td align='center'><span class='style27'>$reference_label</span></td>
								<td align='center'><span class='style27'>$city1_label 1</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 valing='bottom'>";
echo"								<button type='button' style='width:50px;' id='btnPost' name='btnPost' onclick='SubmitRecord(2); return false;' title='Save Changes' $Insmode><span><span>$save</span></span></button>";
echo"							</td>
								<td valing='bottom'>
									<button type='button' style='width:50px;'id='clearbutton' name='clearbutton' onclick='cleardetail(2); return false;' title='Clear Detail'><span><span>$clear</span></span></button>";
echo"							</td>
								<td valign='top'>&nbsp;
									<select name='telephoneno_title'>";
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'>&nbsp;</td>
								<td>&nbsp;<input type='text' name='telephone_fname' value='$telephone_fname' $status maxlength='50' >&nbsp;</td>
								<td>&nbsp;<input type='text' name='telephone_lname' value='$telephone_lname' $status maxlength='45'>&nbsp;</td>
								<td>&nbsp;<input type='text' name='telephone_no' value='$telephone_no' $status maxlength='15' >&nbsp;</td>
								<td>&nbsp;<input type='text' name='telephone_no2' value='$telephone_no2' $status maxlength='15' >&nbsp;</td>
								<td>&nbsp;<input type='text' name='telephone_no3' value='$telephone_no3' $status maxlength='15' >&nbsp;</td>
								<td>&nbsp;<input type='text' name='telephone_email' value='$telephone_email' $status maxlength='45' >&nbsp;</td>
								<td>&nbsp;<input type='text' name='telephone_reference' value='$telephone_reference' $status maxlength='15'>&nbsp;</td>
								<td>&nbsp;<input type='text' name='telephone_city1' value='$telephone_city1' $status maxlength='45' >&nbsp;</td>
								<td>&nbsp;<input type='text' name='telephone_city2' value='$telephone_city2' $status maxlength='45' >&nbsp;</td>
								<td>&nbsp;<input type='text' name='telephone_city3' value='$telephone_city3' $status maxlength='45'>&nbsp;</td>
							</tr>";

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

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

									if($ct%2==0)
										$Color="style='background-color:".$grid_color1."'";
									else			
										$Color="style='background-color:".$grid_color2."'";	
														
					
echo "						<tr ".$Color." >";
echo "							<td align='center' valign='center'><span class='style15'><img src='img/button_edit.png'  onMouseOver=\"style.cursor='hand'\" onclick=UpdateDetail('".$rowsdt[0]."') title='Edit Record'  ></span></td>";
echo "							<td align='center' valign='center'><span class='style15'><img src='img/c_delete.png'  onMouseOver=\"style.cursor='hand'\" onclick=DeleteDetail('".$rowsdt[0]."') title='Delete Record'  ></span></td>";
echo "							<td align='center'><span class='style15'>".$rowsdt[1]."</span></td>";
echo "							<td align='left'><span class='style15'>".$rowsdt[2]."</span></td>";
echo "							<td align='left'><span class='style15'>".$rowsdt[3]."</span></td>";
echo "							<td align='left'><span class='style15'>".$rowsdt[4]."</span></td>";
echo "							<td align='left'><span class='style15'>".$rowsdt[5]."</span></td>";
echo "							<td align='left'><span class='style15'>".$rowsdt[6]."</span></td>";
echo "							<td align='left'><span class='style15'>".$rowsdt[7]."</span></td>";
echo "							<td align='left'><span class='style15'>".$rowsdt[8]."</span></td>";
echo "							<td align='left'><span class='style15'>".$rowsdt[9]."</span></td>";
echo "							<td align='left'><span class='style15'>".$rowsdt[10]."</span></td>";
echo "							<td align='left'><span class='style15'>".$rowsdt[11]."</span></td>";
echo "							<td align='left'><span class='style15'>".$rowsdt[12]."</span></td>";
echo "							<td align='left'><span class='style15'>&nbsp;</span></td>";
echo "						</tr>";
						
							}		
echo"					</table>
					</div>
				</td>
			</tr>
			<tr>
							<td  valign='top' colspan=3 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>$sup_code</b></td>
										<td align='center'><span class='style1'><b>$sup_name</b></td>
									</tr>
									<tr>
										<td colspan=3>";
										//	<div style='overflow-y:scroll;height:320px;width:1090px;border:0px solid #000000;padding-left:5px;'>
echo"											<table  border='0' width='1100px'>
													<col width=30>
													<col width=160>
													<col width=170>";
													
													$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());	
													while($rows=mysql_fetch_array($resultsearch)){
														$ct+=1;
														$stylefont='style15';
														if($ct%2==0)
															$Color="style='background-color:".$grid_color1."'";
														else			
															$Color="style='background-color:".$grid_color2."'";	
																
														if($mainmode=='edit' && $ledger_numberPrv==$rows[0]){
															
															$Color="style='background-color:#1e87a5'";
															$stylefont='style28';
													}	
												echo'<tr '.$Color.' height="20px" >';
					
														if($FI_SuppliersDel==1)	
print<<<HERE

														<td align=center ><img border='0' src='img/c_delete.png' width='9' height='10' title='Delete Detail' onmouseover="this.style.cursor='pointer'" OnClick="confirm_delete('$rows[0]')" $DelMode></td>
HERE;
														else print<<<HERE
														<td align=center >&nbsp;</td>
HERE;
echo"													<td style='cursor:pointer;' ";if($FI_SuppliersMod==1) echo " onclick=SetSup('$rows[0]');";echo"><span class='$stylefont' >$rows[0]&nbsp;</span></font></td>
														<td style='cursor:pointer;' ";if($FI_SuppliersMod==1) echo " onclick=SetSup('$rows[0]');";echo"><font face='Arial' size='2' color='#186194'><span class='$stylefont'>$rows[1]&nbsp;</span></font></td>";
echo"												</tr>";
													}		
echo"											</table>";
										//	</div>
echo"									</td>
									</tr>
							</tr>
							</table>
						</td>
					</tr>";	
echo"	</table>";
		  
$tabs->end();  

		  
$tabs->start("$tab3");

echo"	<table border='0' style='table-layout:fixed' width='1100px' valign='top'>";
echo"		<col width=85>
			<col width=200>
			<col width=80>
			<col width=200>
			<col width=80>
			<col width=200>
			<col width=50>
			<col width=200>";

echo"		<tr bgcolor='#F7F7F7' height='35'>
				<td><span class='style1'>$city_label</span></td>
				<td><input type='text' name='city_supplier' value='".htmlspecialchars($city_supplier, ENT_QUOTES)."'  maxlength='30' $status size=30 style='font-size:12px; '></td>
				<td  align=left><span class='style1'>$state_label</span></td>
				<td><input type=text name=state value='".htmlspecialchars($state, ENT_QUOTES)."'  maxlength='32' $status  size=30 style='font-size:12px; '></td>
				<td><span class='style1'>$country</span></td>
				<td><input type=text name='country' value='".htmlspecialchars($country, ENT_QUOTES)."'  maxlength='30' $status size=30 style='font-size:12px;'></td>
				<td><span class='style1'>$groupsupplier</span></td>
				<td><input type=text name='supplier_group' value='".htmlspecialchars($supplier_group, ENT_QUOTES)."'  maxlength='31' $status size=30 style='font-size:12px;'></td>
			</tr>";
			
			
echo"		<tr bgcolor='#F7F7F7' >
				<td>
					<table border='0' width='1100px'>
						<col width='80'>
						<col width='200'>
						<col width='80'>
						<col width='200'>
						<col width='80'>
						<col width='200'>
						<tr bgcolor='#F7F7F7' >
							<td><span class='style1'><span class='style1'>$address1</span></td>
							<td><textarea name='Address'  size=100% maxlength='100' cols=30 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><span class='style1'><span class='style1'>$address2</span></td>
							<td ><textarea name='Address2'  size=100% cols=30 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>
							<td><span class='style1'><span class='style1'>$address3</span></td>
							<td ><textarea name='Address3'  size=100% cols=30 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>";
						
							$lenAddress2=strlen($Address2);
							$restaddress2=100-$lenAddress2;

							$lenAddress3=strlen($Address3);
							$restaddress3=100-$lenAddress3;
							
	echo"				<tr bgcolor='#F7F7F7' height='25'>
							<td></td>
							<td align=center><span class='style12'>$Remaining</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></td>
							<td align=center><span class='style12'>$Remaining</span>&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>
							<td></td>
							<td align=center><span class='style12'>$Remaining</span>&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>	
					</table>
				</td>
			</tr>";	 
			
				

echo"		<tr>
				<td  valign='top' colspan=3 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>$sup_code</b></td>
							<td align='center'><span class='style1'><b>$sup_name</b></td>
						</tr>
						<tr>
							<td colspan=3>";
							//	<div style='overflow-y:scroll;height:320px;width:1090px;border:0px solid #000000;padding-left:5px;'>
echo"								<table  border='0' width='1100px'>
										<col width=30>
										<col width=160>
										<col width=170>";
										
										$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());	
										while($rows=mysql_fetch_array($resultsearch)){
											$ct+=1;
											$stylefont='style15';
											if($ct%2==0)
												$Color="style='background-color:".$grid_color1."'";
											else			
												$Color="style='background-color:".$grid_color2."'";	
													
											if($mainmode=='edit' && $ledger_numberPrv==$rows[0]){
												
												$Color="style='background-color:#1e87a5'";
												$stylefont='style28';
										}	
									echo'<tr '.$Color.' height="20px" >';
		
											if($FI_SuppliersDel==1)	
print<<<HERE

											<td align=center ><img border='0' src='img/c_delete.png' width='9' height='10' title='Delete Detail' onmouseover="this.style.cursor='pointer'" OnClick="confirm_delete('$rows[0]')" $DelMode></td>
HERE;
											else print<<<HERE
											<td align=center >&nbsp;</td>
HERE;
echo"													<td style='cursor:pointer;' ";if($FI_SuppliersMod==1) echo " onclick=SetSup('$rows[0]');";echo"><span class='$stylefont' >$rows[0]&nbsp;</span></font></td>
											<td style='cursor:pointer;' ";if($FI_SuppliersMod==1) echo " onclick=SetSup('$rows[0]');";echo"><font face='Arial' size='2' color='#186194'><span class='$stylefont'>$rows[1]&nbsp;</span></font></td>";
echo"												</tr>";
										}		
echo"								</table>";
							//	</div>
echo"						</td>
						</tr>
					</tr>
				</table>
			</td>
		</tr>";				
echo"</table>";
					
$tabs->end();

$tabs->start("Terms");		
echo"		<table border='0' style='table-layout:fixed' align='center' valign='top' width='850px'>
			<col width=630px>";	
			
echo "<tr><td align='center'>";
echo "<textarea name='paymentcondition' id='paymentcondition' cols='115' rows='40'>$paymentcondition</textarea>";
echo "</td></tr>";			
echo "</table>";			
$tabs->end();	
$tabs->start("$tab4");				  
echo"	<table border='0' style='table-layout:fixed' align='center' valign='top' width='1100px'>
			<col width=100>
			<col width=100>
			<col width=160>
			<col width=100>
			<col width=50>
			<col width=100>";
	
echo"		<tr bgcolor='#F7F7F7' height='35'>
				<td><span class='style1'>$mother_companylable</span></td>
				<td align=left><input type=text name='supplier_mothercompany' value='$supplier_mothercompany' maxlength='10' $status readonly size='30' style='font-size:12px; width:100px; '>&nbsp;";
					if($mainmode!='view' && $mainmode!='')
echo"					<label><span class='style1'><input type='image' src='img/btnopen.jpg' title=' Select Company '  width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistcompaniescode(2); return false' /></span></label>";
echo"			</td>
				<td align=left>
					<input type=text name='supplier_companyname' value='$supplier_companyname' maxlength='10' $status readonly size='30' style='font-size:12px; width:200px; '>";
					if($mainmode!='view' && $mainmode!='')
						echo"&nbsp;<label><span class='style1'><input type='image' src='img/btnopen.jpg' title=' Select Company '  width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistcompaniesname(2); return false' /></span></label>";
echo"			</td>
				<td><span class='style1'>$owner_lable</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='supplier_companyowner' value='".htmlspecialchars($supplier_companyowner, ENT_QUOTES)."' maxlength='50' $status  size='20' style='font-size:12px; width:200px; '>
				</td>
			</tr>";	 
			
echo"		<tr bgcolor='#F7F7F7' height='35'>
				<td align=left><span class='style1'>$reffered_lable</span></td>
				<td>	
					<select name='titlerefered_description' style='width:101px' 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 colspan=2>
					<input type=text name='supplier_referedby' value='".htmlspecialchars($supplier_referedby, ENT_QUOTES)."'  maxlength='50' $status  size='20' style='font-size:12px; width:200px; '>
				</td>
			</tr>
			<tr>
				<td  valign='top' colspan=3 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>$sup_code</b></td>
							<td align='center'><span class='style1'><b>$sup_name</b></td>
						</tr>
						<tr>
							<td colspan=3>";
							//	<div style='overflow-y:scroll;height:320px;width:1090px;border:0px solid #000000;padding-left:5px;'>
	echo"						<table  border='0' width='1100px'>
									<col width=30>
									<col width=160>
									<col width=170>";
										
									$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());	
									while($rows=mysql_fetch_array($resultsearch)){
										$ct+=1;
										$stylefont='style15';
										if($ct%2==0)
											$Color="style='background-color:".$grid_color1."'";
										else			
											$Color="style='background-color:".$grid_color2."'";	
												
										if($mainmode=='edit' && $ledger_numberPrv==$rows[0]){
											
											$Color="style='background-color:#1e87a5'";
											$stylefont='style28';
									}	
								echo'<tr '.$Color.' height="20px" >';

										if($FI_SuppliersDel==1)	
	print<<<HERE

										<td align=center ><img border='0' src='img/c_delete.png' width='9' height='10' title='Delete Detail' onmouseover="this.style.cursor='pointer'" OnClick="confirm_delete('$rows[0]')" $DelMode></td>
HERE;
										else print<<<HERE
										<td align=center >&nbsp;</td>
HERE;
echo"									<td style='cursor:pointer;' ";if($FI_SuppliersMod==1) echo " onclick=SetSup('$rows[0]');";echo"><span class='$stylefont' >$rows[0]&nbsp;</span></font></td>
										<td style='cursor:pointer;' ";if($FI_SuppliersMod==1) echo " onclick=SetSup('$rows[0]');";echo"><font face='Arial' size='2' color='#186194'><span class='$stylefont'>$rows[1]&nbsp;</span></font></td>";
echo"								</tr>";
									}		
echo"							</table>";
						//	</div>
echo"						</td>
						</tr>
					</tr>
				</table>
			</td>
		</tr>";	
echo"</table>";
	
$tabs->end();
		
$tabs->start("$tab5");		
echo"	<table border='0' style='table-layout:fixed' align='left' valign='top' width=70%>
			<col width=100>";
echo"		<tr bgcolor='#F7F7F7' height='35'>
				<td align=left ><span class='style1'>$gcinumb</span>";	  
					//if($module=='1')
					// echo"<span class='style26'>*</span>";
echo"			</td>
				<td align=left ><input type=text name='supplier_gcino' value='$supplier_gcino' maxlength='6' $status  size='10' style='font-size:12px; width:100px; '></td>
			</tr>  
			
			<tr>
				<td  valign='top' colspan=3 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>$sup_code</b></td>
							<td align='center'><span class='style1'><b>$sup_name</b></td>
						</tr>
						<tr>
							<td colspan=3>";
							//	<div style='overflow-y:scroll;height:320px;width:1090px;border:0px solid #000000;padding-left:5px;'>
echo"											<table  border='0' width='1100px'>
										<col width=30>
										<col width=160>
										<col width=170>";
										
										$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());	
										while($rows=mysql_fetch_array($resultsearch)){
											$ct+=1;
											$stylefont='style15';
											if($ct%2==0)
												$Color="style='background-color:".$grid_color1."'";
											else			
												$Color="style='background-color:".$grid_color2."'";	
													
											if($mainmode=='edit' && $ledger_numberPrv==$rows[0]){
												
												$Color="style='background-color:#1e87a5'";
												$stylefont='style28';
										}	
									echo'<tr '.$Color.' height="20px" >';
		
											if($FI_SuppliersDel==1)	
print<<<HERE

											<td align=center ><img border='0' src='img/c_delete.png' width='9' height='10' title='Delete Detail' onmouseover="this.style.cursor='pointer'" OnClick="confirm_delete('$rows[0]')" $DelMode></td>
HERE;
											else print<<<HERE
											<td align=center >&nbsp;</td>
HERE;
echo"													<td style='cursor:pointer;' ";if($FI_SuppliersMod==1) echo " onclick=SetSup('$rows[0]');";echo"><span class='$stylefont' >$rows[0]&nbsp;</span></font></td>
											<td style='cursor:pointer;' ";if($FI_SuppliersMod==1) echo " onclick=SetSup('$rows[0]');";echo"><font face='Arial' size='2' color='#186194'><span class='$stylefont'>$rows[1]&nbsp;</span></font></td>";
echo"												</tr>";
										}		
echo"											</table>";
							//	</div>
echo"									</td>
						</tr>
				</tr>
				</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=80>
					 <col width=80>
					 <col width=100>
					 <col width=100>
					 <col width=150>
					 <col width=100>
					 <col width=150>";	
					if(!isset($supplier_businesssector))
						$supplier_businesssector='A';

					if($supplier_businesssector=='A')
						$selectedA='selected';

					if($supplier_businesssector=='I')
						$selectedI='selected';

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

						<td><span class='style1'>$buisness_des</span></td>
						<td>
							<input type='text' name='supplier_businesssectordesc' value='".htmlspecialchars($supplier_businesssectordesc, ENT_QUOTES)."' maxlength='10' $status style='font-size:12px; width:100px; '>
						</td>
						
						<td><span class='style1'>$buisnesstyp2_label</span></td>
						<td>
							<input type='text' name='supplier_btype2' value='".htmlspecialchars($supplier_btype2, ENT_QUOTES)."'   maxlength='50' $status style='font-size:12px; width:175px; '>
						</td>
						<td><span class='style1'>$buisnesstyp3_label</span></td>
						<td>
							<input type='text' name='supplier_btype3' value='".htmlspecialchars($supplier_btype3, ENT_QUOTES)."' maxlength='50' $status style='font-size:12px; width:175px; '>
						</td>
					</tr>
					
					<tr>
						<td  valign='top' colspan=3 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>$sup_code</b></td>
									<td align='center'><span class='style1'><b>$sup_name</b></td>
								</tr>
								<tr>
									<td colspan=3>";
									//	<div style='overflow-y:scroll;height:320px;width:1090px;border:0px solid #000000;padding-left:5px;'>
	echo"								<table  border='0' width='1100px'>
										<col width=30>
										<col width=160>
										<col width=170>";
												
										$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());	
										while($rows=mysql_fetch_array($resultsearch)){
											$ct+=1;
											$stylefont='style15';
											if($ct%2==0)
												$Color="style='background-color:".$grid_color1."'";
											else			
												$Color="style='background-color:".$grid_color2."'";	
													
											if($mainmode=='edit' && $ledger_numberPrv==$rows[0]){
												
												$Color="style='background-color:#1e87a5'";
												$stylefont='style28';
										}	
									echo'<tr '.$Color.' height="20px" >';
				
											if($FI_SuppliersDel==1)	
print<<<HERE

											<td align=center ><img border='0' src='img/c_delete.png' width='9' height='10' title='Delete Detail' onmouseover="this.style.cursor='pointer'" OnClick="confirm_delete('$rows[0]')" $DelMode></td>
HERE;
												else print<<<HERE
											<td align=center >&nbsp;</td>
HERE;
echo"										<td style='cursor:pointer;' ";if($FI_SuppliersMod==1) echo " onclick=SetSup('$rows[0]');";echo"><span class='$stylefont' >$rows[0]&nbsp;</span></font></td>
											<td style='cursor:pointer;' ";if($FI_SuppliersMod==1) echo " onclick=SetSup('$rows[0]');";echo"><font face='Arial' size='2' color='#186194'><span class='$stylefont'>$rows[1]&nbsp;</span></font></td>";
echo"									</tr>";
													}		
echo"								</table>";
										//	</div>
echo"							</td>
							</tr>
						</tr>
					</table>
				</td>
			</tr>";	
					
echo"	</table>";			
				
$tabs->end();		

// Bank info Tab
$tabs->start("Bank Info");	
if ($ledger_number != ''){
	$query = "select Supplier_BankName, Supplier_BankAddress, Supplier_AccountNbr, Supplier_SortCode, Supplier_IBANNo, Supplier_SwiftCode
				from suppliers where Ledger_number = '$ledger_number' ";
	$result = mysql_query($query, $connection);
	$row = mysql_fetch_row($result);
	$supBankName = $row[0];
	$supBankAddr = $row[1];
	$supAccNbr 	 = $row[2];
	$supSortCode = $row[3];
	$supIBAN	 = $row[4];
	$supSwift	 = $row[5];
}
echo "<div >";
echo "<table width=100% cellpadding=0 cellspacing=0><col width=10%><col width=20%><col width=10%><col width=20%><col width=10%><col width=20%>";
echo "<tr height='30px'>
			<td><span class='style1'>Bank Name</span></td>
			<td><input type='text' name='supBankName' id='supBankName' value='$supBankName' style='width:95%;'></td>
			<td><span class='style1'>Bank Address</span></td>
			<td colspan='3'><input type='text' name='supBankAddr' id='supBankAddr' value='$supBankAddr' style='width:98%;'></td>
			
	</tr>
	<tr height='30px'>
			<td><span class='style1'>Account Number</span></td>
			<td><input type='text' name='supAccNbr' id='supAccNbr' value='$supAccNbr' style='width:95%;'></td>
			<td><span class='style1'>Sort Code</span></td>
			<td><input type='text' name='supSortCode' id='supSortCode' value='$supSortCode' style='width:95%;'></td>
			<td><span class='style1'>IBAN No</span></td>
			<td><input type='text' name='supIBAN' id='supIBAN' value='$supIBAN' style='width:95%;'></td>
			
	</tr>
	<tr height='30px'>
		<td><span class='style1'>SWIFT Code</span></td>
		<td><input type='text' name='supSwift' id='supSwift' value='$supSwift' style='width:95%;'></td>
	</tr>";		
echo "</table>";
echo"</div>";
$tabs->end();	
// Bank info end tab

// Items Tab
$tabs->start("$tab7");	
echo "<div id='item_supplier'>";
	draw_itemSupplier($itemSupplier_id,$ledger_number, $connection);	
echo"</div>";
$tabs->end();	
// Items End Tab


if ($supplier_access == '1'){
$tabs->start("Access");		
if($FI_ItemAuction == 1){
echo "<div id='user_supplier'>";
	draw_SupplierAccess($ledger_number, $config['EncryptPassMod'], $connection);	
echo"</div>";
}	
$tabs->end();	
}
$tabs->run();

		  
print <<< HERE
				</td>
			</tr>
			
			<tr height='30' id='content-bottom' width='1100px'>
				<td id='content-bottom' colspan=9></td>
			</tr>
	  </table>
HERE;


if($checkcode=='1'){

//	echo$ledger_number.'    '.$ledger_numberPrv;exit;
	$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 suppliers 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.supplierdt.message.value='Code Already Exists';";
		echo"	document.supplierdt.checkcode.value='0';";
		echo"	document.supplierdt.fill_ledger.value='0';";
		echo"	document.supplierdt.submit();";	
		echo"</script>";
		
	}
	else{
		echo"<script type='text/javascript'>";
		echo"	document.supplierdt.action='Form_Suppliers_Actions.php';";
		echo"	document.supplierdt.submit();";
		echo"</script>";
			
	}
}
if($pageclear == 1){
		echo"<script type='text/javascript'> ";
		echo"	ClearPage(); ";
		echo"</script>";
}

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

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

HERE;

?>