<?php
header("Content-type: text/html; charset=windows-1256");

session_start();

if($_SESSION['dbName']==""){
header("location:../index.php");
}

include("config.inc.php");

$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass'],true,65536) or die("Could not connect to DB");
$connection1 = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass'],true,65536) or die("Could not connect to DB");

mysql_select_db($_SESSION['dbName'],$connection) or die("Could not find DB");
mysql_select_db($_SESSION['dbName'],$connection1) or die("Could not find DB");

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.items[fieldname].focus();
				";
			echo "}\n";
			echo "</script>\n";
			foreach($this->tabs as $tabname => $tabcontent){
				$tabid = "tab_".$this->name."_$tabname";
				$contentid = "tabcontent_".$this->name."_$tabname";
				echo "<DIV CLASS='";
				if ($this->active == $tabname){ echo "tab_active"; }else{ echo "tab_inactive"; }
				echo "' ID='$tabid' ";
				echo "onClick=\"tab_".$this->name."('$tabname');\">$tabname</DIV>\n";
			}
			echo "<DIV STYLE='float: center; clear:both;'></DIV>\n";
			foreach($this->tabs as $tabname => $tabcontent){
				$contentid = "tabcontent_".$this->name."_$tabname";
				echo "<DIV ID = '$contentid' CLASS='tab_content' STYLE='display: ";
				if ($this->active == $tabname){ echo "block"; }else{ echo "none"; }
				echo ";'>$tabcontent</DIV>\n";
			}
			echo "</DIV>\n";
			echo "<DIV STYLE='clear: both;'></DIV>\n";
		}}
}

$query_login="select ifNull(FI_ItemsApp,0) as FI_ItemsApp,ifNull(FI_ItemsMod,0) as FI_ItemsMod,ifNull(FI_ItemsDel,0) as FI_ItemsDel,FI_SellingPriceInItems as FI_SellingPriceInItems,
			FI_CostPriceInItems as FI_CostPriceInItems,RI_SatementofItems as RI_SatementofItems from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."')  ";
//echo $query_login; exit;
$resultlogin=mysql_query($query_login,$connection) or die(mysql_error());

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


$AddMode='';

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

// Currency Code
$query_currency="select currency_code from currency";
$result_currency=mysql_query($query_currency,$connection)	or die( mysql_error());



/// Item Type

$query_itemtype="select item_typecode from itemstype";
//$result_itemtype=mysql_query($query_itemtype,$connection);
$row_type=mysql_fetch_row($result_itemtype);


//Read From Setup Table							
$querysetup= " select grid_color1, grid_color2,maxperpage,base1,base2,DecimalBase,DecimalBase1,DecimalBase2,maxperpage, ifNull(Setup_VatPercentage,0) as Setup_VatPercentage from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}

// Module .Module_Project

$query_project_module="select Module_Project,Module_Costcenter,ifNull(Module_Pack,0)  from module";
$result_project_module=mysql_query($query_project_module,$connection);
$row_module=mysql_fetch_row($result_project_module);
$module_project=$row_module[0];

// Module .Module_Costcent
$module_costcent=$row_module[1];

/// Module Pack
$module_pack=$row_module[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"];} 

$item_id 		   = $_POST["item_id"]; if ($item_id == ""){$item_id = $_GET["item_id"];} 
$checkduplicate    = $_POST["checkduplicate"]; if ($checkduplicate == ""){$checkduplicate = $_GET["checkduplicate"];} 
$setcode 		   = $_POST["setcode"]; if ($setcode == ""){$setcode = $_GET["setcode"];} 
$numrow 		   = $_POST["numrow"]; if ($numrow == ""){$numrow = $_GET["numrow"];} 
$numbertaxes 	   = $_POST["numbertaxes"]; if ($numbertaxes == ""){$numbertaxes = $_GET["numbertaxes"];} 
$item_attribute    = $_POST["item_attribute"]; if ($item_attribute == ""){$item_attribute = $_GET["item_attribute"];} 
$item_policy 	   = $_POST["item_policy"]; if ($item_policy == ""){$item_policy = $_GET["item_policy"];} 
$ItemDt_ID 		   = $_POST["ItemDt_ID"]; if ($ItemDt_ID == ""){$ItemDt_ID = $_GET["ItemDt_ID"];} 
$itemactive 	   = $_POST["itemactive"]; if ($itemactive == ""){$itemactive = $_GET["itemactive"];} 
$item_semifinished = $_POST["item_semifinished"]; if ($item_semifinished == ""){$item_semifinished = $_GET["item_semifinished"];} 
$Itempackdt 	   = $_POST["Itempackdt"]; if ($Itempackdt == ""){$Itempackdt = $_GET["Itempackdt"];} 
$Itempackwarehouse = $_POST["Itempackwarehouse"]; if ($Itempackwarehouse == ""){$Itempackwarehouse = $_GET["Itempackwarehouse"];} 
$barcodeindex 	   = $_POST["barcodeindex"]; if ($barcodeindex == ""){$barcodeindex = $_GET["barcodeindex"];} 

$reverse_production	= $_POST["reverse_production"]; if ($reverse_production == ""){$reverse_production = $_GET["reverse_production"];} 
$nonstock_item 		= $_POST["nonstock_item"]; if ($nonstock_item == ""){$nonstock_item = $_GET["nonstock_item"];} 
$item_production 	= $_POST["item_production"]; if ($item_production == ""){$item_production = $_GET["item_production"];} 


$ttc_include 		= $_POST["ttc_include"]; if ($ttc_include == ""){$ttc_include = $_GET["ttc_include"];} 
$item_pack 			= $_POST["item_pack"]; if ($item_pack == ""){$item_pack = $_GET["item_pack"];} 
$item_promotion 	= $_POST["item_promotion"]; if ($item_promotion == ""){$item_promotion = $_GET["item_promotion"];} 
$item_withserialno 	= $_POST["item_withserialno"]; if ($item_withserialno == ""){$item_withserialno = $_GET["item_withserialno"];} 
$EvaluateQtyUnit 	= $_POST["EvaluateQtyUnit"]; if ($EvaluateQtyUnit == ""){$EvaluateQtyUnit = $_GET["EvaluateQtyUnit"];} 
$item_print 		= $_POST["item_print"]; if ($item_print == ""){$item_print = $_GET["item_print"];} 

$item_code 	= $_POST["item_code"]; if ($item_code == ""){$item_code = $_GET["item_code"];} 
$item_vat 	= $_POST["item_vat"]; if ($item_vat == ""){$item_vat = $_GET["item_vat"];} 
$item_vattype 	= $_POST["item_vattype"]; if ($item_vattype == ""){$item_vattype = $_GET["item_vattype"];} 
$currency 	= $_POST["currency"]; if ($currency == ""){$currency = $_GET["currency"];} 
$item_description 	= $_POST["item_description"]; if ($item_description == ""){$item_description = $_GET["item_description"];} 
$item_descriptionf1	= $_POST["item_descriptionf1"]; if ($item_descriptionf1 == ""){$item_descriptionf1 = $_GET["item_descriptionf1"];} 
$item_descriptionf2	= $_POST["item_descriptionf2"]; if ($item_descriptionf2 == ""){$item_descriptionf2 = $_GET["item_descriptionf2"];} 
$supplier_code 		= $_POST["supplier_code"]; if ($supplier_code == ""){$supplier_code = $_GET["supplier_code"];} 
$supplier_name 		= $_POST["supplier_name"]; if ($supplier_name == ""){$supplier_name = $_GET["supplier_name"];} 
$group_code 		= $_POST["group_code"]; if ($group_code == ""){$group_code = $_GET["group_code"];} 
$group_name 		= $_POST["group_name"]; if ($group_name == ""){$group_name = $_GET["group_name"];} 
$subgroup_code 		= $_POST["subgroup_code"]; if ($subgroup_code == ""){$subgroup_code = $_GET["subgroup_code"];} 
$subgroup_name 		= $_POST["subgroup_name"]; if ($subgroup_name == ""){$subgroup_name = $_GET["subgroup_name"];} 
$costcent_code 		= $_POST["costcent_code"]; if ($costcent_code == ""){$costcent_code = $_GET["costcent_code"];} 
$costcent_name 		= $_POST["costcent_name"]; if ($costcent_name == ""){$costcent_name = $_GET["costcent_name"];} 
$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"];} 
$warehouse_code		= $_POST["warehouse_code"]; if ($warehouse_code == ""){$warehouse_code = $_GET["warehouse_code"];} 
$warehouse_desc		= $_POST["warehouse_desc"]; if ($warehouse_desc == ""){$warehouse_desc = $_GET["warehouse_desc"];} 
$item_remark 		= $_POST["item_remark"]; if ($item_remark == ""){$item_remark = $_GET["item_remark"];} 
$item_package 		= $_POST["item_package"]; if ($item_package == ""){$item_package = $_GET["item_package"];} 
$item_weight 		= $_POST["item_weight"]; if ($item_weight == ""){$item_weight = $_GET["item_weight"];} 
$item_netweight 	= $_POST["item_netweight"]; if ($item_netweight == ""){$item_netweight = $_GET["item_netweight"];} 
$item_color			= $_POST["item_color"]; if ($item_color == ""){$item_color = $_GET["item_color"];} 
$item_volume		= $_POST["item_volume"]; if ($item_volume == ""){$item_volume = $_GET["item_volume"];} 
$item_active 		= $_POST["item_active"]; if ($item_active == ""){$item_active = $_GET["item_active"];} 
$item_minqty 		= $_POST["item_minqty"]; if ($item_minqty == ""){$item_minqty = $_GET["item_minqty"];} 
$item_maxqty 		= $_POST["item_maxqty"]; if ($item_maxqty == ""){$item_maxqty = $_GET["item_maxqty"];} 
$item_unitsales 	= $_POST["item_unitsales"]; if ($item_unitsales == ""){$item_unitsales = $_GET["item_unitsales"];} 
$item_quantity 		= $_POST["item_quantity"]; if ($item_quantity == ""){$item_quantity = $_GET["item_quantity"];} 
$item_unitpurchase	= $_POST["item_unitpurchase"]; if ($item_unitpurchase == ""){$item_unitpurchase = $_GET["item_unitpurchase"];} 
$item_longdescription 	= $_POST["item_longdescription"]; if ($item_longdescription == ""){$item_longdescription = $_GET["item_longdescription"];} 
$item_barcode 		= $_POST["item_barcode"]; if ($item_barcode == ""){$item_barcode = $_GET["item_barcode"];} 
$item_barcode2 		= $_POST["item_barcode2"]; if ($item_barcode2 == ""){$item_barcode2 = $_GET["item_barcode2"];} 
$item_barcode3 		= $_POST["item_barcode3"]; if ($item_barcode3 == ""){$item_barcode3 = $_GET["item_barcode3"];} 
$GeneratedLines 	= $_POST["GeneratedLines"]; if ($GeneratedLines == ""){$GeneratedLines = $_GET["GeneratedLines"];} 
$itemtype 		    = $_POST["itemtype"]; if ($itemtype == ""){$itemtype = $_GET["itemtype"];} 
$cost 				= $_POST["cost"]; if ($cost == ""){$cost = $_GET["cost"];} 
$item_lastcostprice	= $_POST["item_lastcostprice"]; if ($item_lastcostprice == ""){$item_lastcostprice = $_GET["item_lastcostprice"];} 
$item_disporder		= $_POST["item_disporder"]; if ($item_disporder == ""){$item_disporder = $_GET["item_disporder"];} 
$item_minimumprice	= $_POST["item_minimumprice"]; if ($item_minimumprice == ""){$item_minimumprice = $_GET["item_minimumprice"];}
$item_discountper = $_POST["item_discountper"]; if($item_discountper == ""){$item_discountper = $_GET["item_discountper"];}

$item_code2 		= $_POST["item_code2"]; if ($item_code2 == ""){$item_code2 = $_GET["item_code2"];} 
$item_cur2 			= $_POST["item_cur2"]; if ($item_cur2 == ""){$item_cur2 = $_GET["item_cur2"];} 
$item_desc2 		= $_POST["item_desc2"]; if ($item_desc2 == ""){$item_desc2 = $_GET["item_desc2"];} 

$item_code3 		= $_POST["item_code3"]; if ($item_code3 == ""){$item_code3 = $_GET["item_code3"];} 
$item_cur3 			= $_POST["item_cur3"]; if ($item_cur3 == ""){$item_cur3 = $_GET["item_cur3"];} 
$item_desc3 		= $_POST["item_desc3"]; if ($item_desc3 == ""){$item_desc3 = $_GET["item_desc3"];} 
$transfer 			= $_POST["transfer"]; if ($transfer == ""){$transfer = $_GET["transfer"];} 
$Item_ModifySellingPrice= $_POST["Item_ModifySellingPrice"]; if ($Item_ModifySellingPrice == ""){$Item_ModifySellingPrice = $_GET["Item_ModifySellingPrice"];} 
$category_code 		= $_POST["category_code"]; if ($category_code == ""){$category_code = $_GET["category_code"];} 
$category_name 		= $_POST["category_name"]; if ($category_name == ""){$category_name = $_GET["category_name"];} 
$lastcost 			= $_POST["lastcost"]; if ($lastcost == ""){$lastcost = $_GET["lastcost"];} 
$sellingprice1 		= $_POST["sellingprice1"]; if ($sellingprice1 == ""){$sellingprice1 = $_GET["sellingprice1"];} 
$sellingprice1base1	= $_POST["sellingprice1base1"]; if ($sellingprice1base1 == ""){$sellingprice1base1 = $_GET["sellingprice1base1"];} 
$sellingprice1base2	= $_POST["sellingprice1base2"]; if ($sellingprice1base2 == ""){$sellingprice1base2 = $_GET["sellingprice1base2"];} 
$sellingprice2 		= $_POST["sellingprice2"]; if ($sellingprice2 == ""){$sellingprice2 = $_GET["sellingprice2"];} 
$sellingprice2base1 = $_POST["sellingprice2base1"]; if ($sellingprice2base1 == ""){$sellingprice2base1 = $_GET["sellingprice2base1"];} 
$sellingprice2base2 = $_POST["sellingprice2base2"]; if ($sellingprice2base2 == ""){$sellingprice2base2 = $_GET["sellingprice2base2"];} 
$sellingprice3 		= $_POST["sellingprice3"]; if ($sellingprice3 == ""){$sellingprice3 = $_GET["sellingprice3"];} 
$sellingprice3base1	= $_POST["sellingprice3base1"]; if ($sellingprice3base1 == ""){$sellingprice3base1 = $_GET["sellingprice3base1"];} 
$sellingprice3base2	= $_POST["sellingprice3base2"]; if ($sellingprice3base2 == ""){$sellingprice3base2 = $_GET["sellingprice3base2"];} 
$sellingprice4 		= $_POST["sellingprice4"]; if ($sellingprice4 == ""){$sellingprice4 = $_GET["sellingprice4"];} 
$sellingprice4base1 = $_POST["sellingprice4base1"]; if ($sellingprice4base1 == ""){$sellingprice4base1 = $_GET["sellingprice4base1"];} 
$sellingprice4base2 = $_POST["sellingprice4base2"]; if ($sellingprice4base2 == ""){$sellingprice4base2 = $_GET["sellingprice4base2"];} 
$sellingprice5 		= $_POST["sellingprice5"]; if ($sellingprice5 == ""){$sellingprice5 = $_GET["sellingprice5"];} 
$sellingprice5base1 = $_POST["sellingprice5base1"]; if ($sellingprice5base1 == ""){$sellingprice5base1 = $_GET["sellingprice5base1"];} 
$sellingprice5base2 = $_POST["sellingprice5base2"]; if ($sellingprice5base2 == ""){$sellingprice5base2 = $_GET["sellingprice5base2"];} 
$sellingprice6 		= $_POST["sellingprice6"]; if ($sellingprice6 == ""){$sellingprice6 = $_GET["sellingprice6"];} 
$sellingprice6base1 = $_POST["sellingprice6base1"]; if ($sellingprice6base1 == ""){$sellingprice6base1 = $_GET["sellingprice6base1"];} 
$sellingprice6base2 = $_POST["sellingprice6base2"]; if ($sellingprice6base2 == ""){$sellingprice6base2 = $_GET["sellingprice6base2"];} 

$item_code4 		= $_POST["item_code4"]; if ($item_code4 == ""){$item_code4 = $_GET["item_code4"];} 
$item_cur4			= $_POST["item_cur4"]; if ($item_cur4 == ""){$item_cur4 = $_GET["item_cur4"];} 
$item_desc4 		= $_POST["item_desc4"]; if ($item_desc4 == ""){$item_desc4 = $_GET["item_desc4"];} 
$attribute_code 	= $_POST["attribute_code"]; if ($attribute_code == ""){$attribute_code = $_GET["attribute_code"];} 
$attribute_desc 	= $_POST["attribute_desc"]; if ($attribute_desc == ""){$attribute_desc = $_GET["attribute_desc"];} 
$attribute_value 	= $_POST["attribute_value"]; if ($attribute_value == ""){$attribute_value = $_GET["attribute_value"];} 
$attribute_unit 	= $_POST["attribute_unit"]; if ($attribute_unit == ""){$attribute_unit = $_GET["attribute_unit"];} 

$item_code5 			= $_POST["item_code5"]; if ($item_code5 == ""){$item_code5 = $_GET["item_code5"];} 
$item_cur5				= $_POST["item_cur5"]; if ($item_cur5 == ""){$item_cur5 = $_GET["item_cur5"];} 
$item_desc5 			= $_POST["item_desc5"]; if ($item_desc5 == ""){$item_desc5 = $_GET["item_desc5"];} 
$Item_QtyToBeProduced 	= $_POST["Item_QtyToBeProduced"]; if ($Item_QtyToBeProduced == ""){$Item_QtyToBeProduced = $_GET["Item_QtyToBeProduced"];} 
$item_packgroupcode 	= $_POST["item_packgroupcode"]; if ($item_packgroupcode == ""){$item_packgroupcode = $_GET["item_packgroupcode"];} 
$item_packgroupname 	= $_POST["item_packgroupname"]; if ($item_packgroupname == ""){$item_packgroupname = $_GET["item_packgroupname"];} 
$item_packcode 			= $_POST["item_packcode"]; if ($item_packcode == ""){$item_packcode = $_GET["item_packcode"];} 
$item_packdesc	 		= $_POST["item_packdesc"]; if ($item_packdesc == ""){$item_packdesc = $_GET["item_packdesc"];} 
$item_warehousecode 	= $_POST["item_warehousecode"]; if ($item_warehousecode == ""){$item_warehousecode = $_GET["item_warehousecode"];} 
$item_warehousedesc 	= $_POST["item_warehousedesc"]; if ($item_warehousedesc == ""){$item_warehousedesc = $_GET["item_warehousedesc"];} 
$item_packbarcode 		= $_POST["item_packbarcode"]; if ($item_packbarcode == ""){$item_packbarcode = $_GET["item_packbarcode"];} 
$item_packqty 			= $_POST["item_packqty"]; if ($item_packqty == ""){$item_packqty = $_GET["item_packqty"];} 
$item_packcost 			= $_POST["item_packcost"]; if ($item_packcost == ""){$item_packcost = $_GET["item_packcost"];} 
$item_packfromdate 		= $_POST["item_packfromdate"]; if ($item_packfromdate == ""){$item_packfromdate = $_GET["item_packfromdate"];} 
$item_packtodate 		= $_POST["item_packtodate"]; if ($item_packtodate == ""){$item_packtodate = $_GET["item_packtodate"];} 
$item_promoqty 			= $_POST["item_promoqty"]; if ($item_promoqty == ""){$item_promoqty = $_GET["item_promoqty"];} 

$item_code6 		 = $_POST["item_code6"]; if ($item_code6 == ""){$item_code6 = $_GET["item_code6"];} 
$item_cur6			 = $_POST["item_cur6"]; if ($item_cur6 == ""){$item_cur6 = $_GET["item_cur6"];} 
$item_desc6 		 = $_POST["item_desc6"]; if ($item_desc6 == ""){$item_desc6 = $_GET["item_desc6"];} 
$manufacture_code 	 = $_POST["manufacture_code"]; if ($manufacture_code == ""){$manufacture_code = $_GET["manufacture_code"];} 
$manufacture_desc    = $_POST["manufacture_desc"]; if ($manufacture_desc == ""){$manufacture_desc = $_GET["manufacture_desc"];} 
$manufacture_codePrv = $_POST["manufacture_codePrv"]; if ($manufacture_codePrv == ""){$manufacture_codePrv = $_GET["manufacture_codePrv"];} 

$item_code7 		 = $_POST["item_code7"]; if ($item_code7 == ""){$item_code7 = $_GET["item_code7"];} 
$item_cur7			 = $_POST["item_cur7"]; if ($item_cur7 == ""){$item_cur7 = $_GET["item_cur7"];} 
$item_desc7 		 = $_POST["item_desc7"]; if ($item_desc7 == ""){$item_desc7 = $_GET["item_desc7"];} 
$item_code8 		 = $_POST["item_code8"]; if ($item_code8 == ""){$item_code8 = $_GET["item_code8"];} 
$item_cur8			 = $_POST["item_cur8"]; if ($item_cur8 == ""){$item_cur8 = $_GET["item_cur8"];} 
$item_desc8 		 = $_POST["item_desc8"]; if ($item_desc8 == ""){$item_desc8 = $_GET["item_desc8"];} 

$item_code9 		 = $_POST["item_code9"]; if ($item_code9 == ""){$item_code9 = $_GET["item_code9"];} 
$item_cur9			 = $_POST["item_cur9"]; if ($item_cur9 == ""){$item_cur9 = $_GET["item_cur9"];} 
$item_desc9 		 = $_POST["item_desc9"]; if ($item_desc9 == ""){$item_desc9 = $_GET["item_desc9"];} 
$rebate_id 			 = $_POST["rebate_id"]; if ($rebate_id == ""){$rebate_id = $_GET["rebate_id"];} 
$rebate_rangefrom    = $_POST["rebate_rangefrom"]; if ($rebate_rangefrom == ""){$rebate_rangefrom = $_GET["rebate_rangefrom"];} 
$rebate_rangeto 	 = $_POST["rebate_rangeto"]; if ($rebate_rangeto == ""){$rebate_rangeto = $_GET["rebate_rangeto"];} 
$rebate_per			 = $_POST["rebate_per"]; if ($rebate_per == ""){$rebate_per = $_GET["rebate_per"];}



/// Attributes
/*
$query_attributes="select subgroup.SubGroup_Name,s1.SubGroup_Name,attribute_parent,attribute_child,s1.increment from attributes 
					left join subgroup on subgroup.Increment=attributes.attribute_parent
					left join subgroup as s1 on s1.Increment=attributes.attribute_child
					where item_id='".$item_id."'";
//echo$query_attributes;
$result_attributes=mysql_query($query_attributes,$connection);*/

///BarCodes
/*
$query_barcodes="select item_barcode,item_barcode2,item_barcode3 from items where item_id='".$item_id."'";
$resultbarcodes=mysql_query($query_barcodes,$connection) or die(mysql_error());
$row_barcode=mysql_fetch_row($resultbarcodes);
$item_barcode=$row_barcode[0];
$item_barcode2=$row_barcode[1];
$item_barcode3=$row_barcode[2];*/

/// Edit Detail

//if($mainmode=='editmode' && $checkduplicate==0){

if(empty($currency) ){
	$query_setup="select if(Itemcurrency=1,base1,base2) from setup";
	$result_setup=mysql_query($query_setup,$connection);
	$row_defaultcur=mysql_fetch_row($result_setup);
	$currency= $row_defaultcur[0];
}

if(empty($item_vat) and $item_id=='') { 
	$item_vat = $Setup_VatPercentage;
}

if($item_id != ''  && $checkduplicate==0){


	$query_items="select items.Item_Code,Item_Unit,Item_Barcode,items.Ledger_Number,Item_Barcode2,items.Group_code,Item_Barcode3,items.SubGroup_Code,Item_tax,item_printed,items.Project_Code,
				Item_tax1,Item_TTCinclude,items.CostCent_Code,Item_tax2,Item_tax3,ITEM_ACTIVE,Item_tax4,Item_Remark,items.Currency_code,Item_tax5,Item_Package,Item_Vat,Item_Description,
				project_name,group_name,ledger_name,Costcent_name,subgroup_name,item_longdescription,Item_CostMethod,item_id,Item_UnitSalesDesc,item_picture,
				Item_SellingPrice1,	Item_SellingPrice2,	Item_SellingPrice3,	Item_SellingPrice4,	Item_SellingPrice5,	Item_SellingPrice6,
				item_pack,Item_ReverseProduction,Item_Production,item_promotion,Item_NonStock,
				Item_Weight,ITEM_MINQTY,ITEM_MAXQTY,date_Format(Item_LastDatePurchase,'%d-%m-%Y'),item_withserialno,Item_ModifySellingPrice,EvaluateQtyUnit,
				Item_SellingPrice1Base1,Item_SellingPrice1Base2,Item_SellingPrice2Base1,Item_SellingPrice2Base2,Item_SellingPrice3Base1,Item_SellingPrice3Base2,
				Item_SellingPrice4Base1,Item_SellingPrice4Base2,Item_SellingPrice5Base1,Item_SellingPrice5Base2,Item_SellingPrice6Base1,Item_SellingPrice6Base2,
				item_transfer,item_barcode,item_barcode2,item_barcode3,items.category_code,category.category_name,date_Format(item_inactivedate,'%d-%m-%Y'),Item_SemiFinished,
				ifNull(Item_QtyToBeProduced,0),  Item_Volume, Item_UnitPurchaseDesc, item_descriptionf1, item_descriptionf2, Items.Item_WarehouseCode, warehouse.Warehouse_Name, Item_NetWeight, 
				Item_Color, item_lastcostprice, Item_DispOrder, Item_MinimumPrice, item_vattype, item_discountper
				from items 
				left join project on project.project_code=items.project_code
				left join costcent on costcent.costcent_code=items.costcent_code
				left join grouping on grouping.group_code=items.group_code
				left join suppliers on suppliers.ledger_number=items.ledger_number
				left join subgroup on subgroup.subgroup_code=items.subgroup_code
				left join category on category.category_code=items.category_code
				left join warehouse on warehouse.warehouse_code=items.Item_WarehouseCode
				where items.item_id='".$item_id."'";
	//echo$query_items;
	$result_items=mysql_query($query_items,$connection);
	while($row_item=mysql_fetch_row($result_items)){

			$item_code=$row_item[0];
			$item_code2=$row_item[0];
			$item_code3=$row_item[0];
			$item_code4=$row_item[0];
			$item_code5=$row_item[0];
			$item_code6=$row_item[0];
			$item_code7=$row_item[0];
			$item_code8=$row_item[0];
			$item_code9=$row_item[0];
			
			$item_quantity=$row_item[1];
			$item_barcode=$row_item[2];
			$supplier_code=$row_item[3];
			$item_barcode2=$row_item[4];
			$group_code=$row_item[5];
			$item_barcode3=$row_item[6];
			$subgroup_code=$row_item[7];
			$item_tax1=$row_item[8];
			$item_print=$row_item[9];
			$project_code=$row_item[10];
			$item_tax2=$row_item[11];
			$ttc_include=$row_item[12];
			$costcent_code=$row_item[13];
			$item_tax3=$row_item[14];
			$item_tax4=$row_item[15];
			$item_active=$row_item[16];
			$itemactive=$row_item[16];
			$item_tax5=$row_item[17];
			$item_remark=$row_item[18];
			
			$currency=$row_item[19];
			$item_cur2=$row_item[19];
			$item_cur3=$row_item[19];
			$item_cur4=$row_item[19];
			$item_cur5=$row_item[19];
			$item_cur6=$row_item[19];
			$item_cur7=$row_item[19];
			$item_cur8=$row_item[19];
			$item_cur9=$row_item[19];
			
			
			$item_tax6=$row_item[20];
			$item_package=$row_item[21];
			$item_vat=$row_item[22];
			$item_vattype=$row_item[84];
			
			$item_description=$row_item[23];
			$item_descriptionf1=$row_item[75];
			$item_descriptionf2=$row_item[76];
			$item_desc2=$row_item[23];
			$item_desc3=$row_item[23];
			$item_desc4=$row_item[23];
			$item_desc5=$row_item[23];
			$item_desc6=$row_item[23];
			$item_desc7=$row_item[23];
			$item_desc8=$row_item[23];
			$item_desc9=$row_item[23];
			
			
			$project_name=$row_item[24];
			$group_name=$row_item[25];
			$supplier_name=$row_item[26];
			$costcent_name=$row_item[27];
			$subgroup_name=$row_item[28];
			$item_longdescription=$row_item[29];
			$cost=$row_item[30];
			
			$item_id=$row_item[31];
			$item_unitsales=$row_item[32];
			$item_unitpurchase=$row_item[74];
		
			$sellingprice1=$row_item[34];
			$sellingprice2=$row_item[35];
			$sellingprice3=$row_item[36];
			$sellingprice4=$row_item[37];
			$sellingprice5=$row_item[38];
			$sellingprice6=$row_item[39];
			
			
			
			if($radio!=1)	
				$item_pack=$row_item[40];
			
			if($radio!=1)
				$reverse_production=$row_item[41];
			
			if($radio!=1)
				$item_production=$row_item[42];
				
			$item_promotion=$row_item[43];
			$nonstock_item=$row_item[44];
			$item_weight=$row_item[45];
			$item_netweight=$row_item[79];
			$item_color=$row_item[80];
			$item_volume=$row_item[73];
			$item_minqty=$row_item[46];
			$item_maxqty=$row_item[47];
			$Item_LastDatePurchase=$row_item[48];
			$item_withserialno=$row_item[49];
			$Item_ModifySellingPrice=$row_item[50];
			$EvaluateQtyUnit=$row_item[51];
			$item_lastcostprice=$row_item[81];
			$item_disporder=$row_item[82];
			$item_minimumprice=$row_item[83];
			$item_discountper=$row_item[85];
			
			$sellingprice1base1=$row_item[52];
			$sellingprice1base2=$row_item[53];
			
			$sellingprice2base1=$row_item[54];
			$sellingprice2base2=$row_item[55];
			
			$sellingprice3base1=$row_item[56];
			$sellingprice3base2=$row_item[57];
			
			$sellingprice4base1=$row_item[58];
			$sellingprice4base2=$row_item[59];
			
			$sellingprice5base1=$row_item[60];
			$sellingprice5base2=$row_item[61];
			
			$sellingprice6base1=$row_item[62];
			$sellingprice6base2=$row_item[63];
			
			$transfer=$row_item[64];
			
			$item_barcode=$row_item[65];
			$item_barcode2=$row_item[66];
			$item_barcode3=$row_item[67];
			$category_code=$row_item[68];
			$category_name=$row_item[69];
			$inactivedate=$row_item[70];
			$item_semifinished=$row_item[71];
			
			$Item_QtyToBeProduced = $row_item[72];
			
			$warehouse_code = $row_item[77];
			$warehouse_desc = $row_item[78];
			
			if($item_tax1!='' && $item_tax1!=0)
				$numbertaxes=1;
			if($item_tax2!='' && $item_tax2!=0)
				$numbertaxes=2;
			if($item_tax3!='' && $item_tax3!=0)
				$numbertaxes=3;
			if($item_tax4!='' && $item_tax4!=0)
				$numbertaxes=4;
			if($item_tax5!='' && $item_tax5!=0)
				$numbertaxes=5;
			if($item_tax6!='' && $item_tax6!=0)
				$numbertaxes=6;
		
	}
	$mainmode='edit';
}


	$query = "SELECT Curdt_Rate FROM curdt WHERE Currency_Code = '".$currency."' AND Curdt_date = (SELECT MAX(Curdt_date) FROM curdt WHERE Currency_Code = '".$currency."' )";
	$result = mysql_query($query,$connection);
	$row=mysql_fetch_row($result);
	$rate_dt = $row[0];
	//echo $query;
	$query = "SELECT Curdt_Rate FROM curdt WHERE Currency_Code = '".$base1."' AND Curdt_date = (SELECT MAX(Curdt_date) FROM curdt WHERE Currency_Code = '".$base1."' )";
	$result = mysql_query($query,$connection);
	$row=mysql_fetch_row($result);
	$rate_dt1 = $row[0];
	
	$query = "SELECT Curdt_Rate FROM curdt WHERE Currency_Code = '".$base2."' AND Curdt_date = (SELECT MAX(Curdt_date) FROM curdt WHERE Currency_Code = '".$base2."' )";
	$result = mysql_query($query,$connection);
	$row=mysql_fetch_row($result);
	$rate_dt2 = $row[0];	

if($ItemDt_ID!='' && $actionmode!='submitattribute'){

	$query="select itemsdt.ItemParam_Code,itemdt_value,itemsparam.Unit_Code,ItemParam_Name from itemsdt   left join itemsparam on itemsparam.ItemParam_Code=itemsdt.ItemParam_Code where ItemDt_ID='".$ItemDt_ID."'";
	$result = mysql_query($query, $connection);
	while($row=mysql_fetch_array($result)){
		$attribute_code=$row[0];
		$attribute_value=$row[1];
		$attribute_unit=$row[2];
		$attribute_desc=$row[3];
	}
}

if($Itempackdt!='' && $Itempackwarehouse!='' && $actionmode!='submitpack'){

	$query="select packdt.Warehouse_Code,PackDt_Quantity,PackDt_CostPercentage,packdt.BARCODE,date_format(PackDt_FromDate,'%d-%m-%Y'),date_format(PackDt_ToDate,'%d-%m-%Y'),
			packdt.Packdt_PromoQty,packdt.Item_CodePackDt, grouping.group_code, grouping.group_name, items.item_description, warehouse.warehouse_name 
			from packdt  
			inner join items on items.item_code = packdt.Item_CodePackDt
			left join warehouse on warehouse.Warehouse_Code=packdt.Warehouse_Code 
			left join grouping on grouping.group_code=packdt.group_code 
			where packdt.item_code='".$item_code."' and packdt.Item_CodePackDt='".$Itempackdt."' and packdt.warehouse_code='".$Itempackwarehouse."'";
	//echo$query;
	$result = mysql_query($query, $connection);
	while($row=mysql_fetch_array($result)){
		$item_warehousecode=$row[0];
		$item_warehousedesc=$row[11];
		$item_packqty=$row[1];
		$item_packcost=$row[2];
		$item_packbarcode=$row[3];
		$item_packfromdate=$row[4];
		$item_packtodate=$row[5];
		$item_promoqty=$row[6];
		$item_packcode=$row[7];
		$item_packdesc=$row[10];
		$item_packgroupcode=$row[8];
		$item_packgroupname=$row[9];
	}
}


if($manufacture_code!='' && $actionmode!='submitmanufacture'){

	$query="select Item_ManufactureDesc,Item_ManufactureCode from itemmanufacture  where Item_ManufactureCode='".$manufacture_code."'";
	$result = mysql_query($query, $connection);
	while($row=mysql_fetch_array($result)){
		$manufacture_desc=$row[0];
		$manufacture_codePrv=$row[1];
	}

}

if($rebate_id!='' && $actionmode!='submitrebate'){

	$query="select ItemRebate_Id, ItemRebate_RangeFrom, ItemRebate_RangeTo, ItemRebate_Per from ItemsRebate where ItemRebate_Id='".$rebate_id."'";
	$result = mysql_query($query, $connection);
	while($row=mysql_fetch_array($result)){
		$rebate_id=$row[0];
		$rebate_rangefrom=$row[1];
		$rebate_rangeto=$row[2];
		$rebate_per=$row[3];
	}
}

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

if($item_inactive=="")
	$item_inactive='0';

if($ttc_include=="")
	$ttc_include='0';	

if($ttc_include==1)
	$selectedttc='checked';
	
if($item_print=="")
	$item_print='0';		

if($item_print==1)
	$selectedprintitem='checked';
	
if($item_semifinished==1)
	$selectedsemifinished='checked';	
	
if($item_active==""){
	$selectedactive='checked';
	$item_active=1;
	}
	
if($item_active=="")
	$item_active='0';	

if($item_active==1)
	$selectedactive='checked';
		
if($cost=="")
	$cost='0';

if($item_quantity=="")
	$item_quantity='1';	
	
	
if($mainmode=='edit'){
	$codestatus='readonly';
	$statusdisabled='';
	$statusreadonly='';
}
	
if($mainmode==''){
	$codestatus='readonly';
	$statusdisabled='disabled';
	$statusreadonly='readonly';
}

if($numbertaxes=='')
	$numbertaxes='1';
	
if($numbertaxes=='2')
	$selectedtax2='selected';

if($numbertaxes=='3')
	$selectedtax3='selected';

if($numbertaxes=='4')
	$selectedtax4='selected';

if($numbertaxes=='5')
	$selectedtax5='selected';

if($numbertaxes=='6')
	$selectedtax6='selected';

if($numbertaxes=='1')
	$selectedtax1='selected';
	
if($itemtype=='')
	$itemtype='Trading';
	
if($item_sellingprice1=='')
	$item_sellingprice1='0';	

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

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

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

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

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

if($nonstockitem=='')
	$nonstockitem=0;	
	
if($reverse_production=='')
	$reverse_production=0;		

if($item_promotion=='')
	$item_promotion=0;	
	
if($item_pack=='')
	$item_pack=0;	

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

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

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

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

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

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

<link rel="stylesheet" type="text/css" media="all" href="css-v2/style.css">
<script type="text/javascript" src="UI_DataGrid.js"></script>
<script type="text/javascript" src="jquery-1.9.1.js"></script>
<SCRIPT type="text/javascript" src="shortcut.js"></script>
<script type="text/javascript" src="js/jscolor/jscolor.js"></script>
<script type="text/javascript" language="javascript">

if (!Array.prototype.indexOf)
{
	Array.prototype.indexOf = function(obj, start) {
		for (var i = (start || 0), j = this.length; i < j; i++) {
			if (this[i] === obj) { return i; }
		}
		return -1;
	}
}

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

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

function showlistitem(str){
	var vGroupCode = document.items.item_packgroupcode.value;
	window.open('List_Items.php?withoutitemexists=1&item=3&PGroup_Code='+vGroupCode,'itemwindow','width=850,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}


function showlistcategory(str){
	window.open('List_Categories.php?str=1','categorywindow','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 showlistgroups(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 showlistsubgroups(str){
	window.open('List_SubGroup.php?str='+str,'List_SubGroup','width=850,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

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

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

function Insertitemsdetails(){

	var item_id=document.items.item_id.value;
	window.open('Form_Items_Warehouses.php?item_id='+item_id,'warehousedetails','width=850,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function openmap(){
	
	x=document.items;
	var group_code=x.group_code.value;
	if(group_code==""){
		alert('Group Code is Mandatory !');
		x.group_code.focus();
	}
	else{
		window.open('List_Items_AccountingMap.php?group_code='+group_code,'Accountingmap','width=850,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
	}
}

function openinventory(){

	x=document.items;
	var item_id=x.item_id.value;
	window.open('List_Items_Warehouse_Availability.php?item_id='+item_id,'inventory','width=850,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function openbarcode(){

	x=document.items;
	var item_id=x.item_id.value;
	window.open('List_Items_BarCodes.php?item_id='+item_id,'barcodes','width=400,height=300,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}


function show_picture(){

	var item_code=document.items.item_code.value;
	window.open('List_Items_Picture.php?item_code='+item_code,'itempicture','width=850,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function upload_picture(){
	x=document.items;
	
	var item_id=document.items.item_id.value;
	if (item_id != "") {
		x.mainmode.value='uploadimage';
		x.action="Form_Items_Actions.php";
		x.submit();	
	}
}

function showlistvalues(attributeid,num){

	window.open('List_Attributes_Values.php?itemparam_id='+attributeid+'&indexnum='+num,'itempicture','width=850,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function set_itemcode(){
	var max=document.items.numrow.value;
	document.items.item_code.value='';
	document.items.item_description.value='';
	for(i=1;i<=max;i++){
		var attr=document.items['attr_value'+i].value;
		var attrname=document.items['attr_valuename'+i].value;
		var code=document.items.item_code.value;
		var desc=document.items.item_description.value;
		var skip;
				
		if(attr!='' && skip!='1'){
			skip=1;
			code=code+attr;
			desc=desc+attrname;
		}
		else if(attr!='' && skip=='1'){
			code=code+'-'+attr;	
			desc=desc+' '+attrname;
		}	
		document.items.item_code.value=code;
		document.items.item_description.value=desc;
	}
	
}

function set_itemstatus(){
	x=document.items;
	
	if(x.deactivate_item.checked)
		x.item_inactive.value='1';
	else x.item_inactive.value='0';
}

function set_reverse(){
	x=document.items;
	
	if(x.reverse_chk.checked)
		x.reverse_production.value='1';
	else x.reverse_production.value='0';
}

function set_stock(){
	x=document.items;
	
	if(x.stock_item.checked)
		x.nonstock_item.value='1';
	else x.nonstock_item.value='0';
}

function set_fixedasset(){
	x=document.items;
	
	if(x.asset_fixed.checked)
		x.fixed_asset.value='1';
	else x.fixed_asset.value='0';
}

function set_productionitem(){
	x=document.items;
	
	if(x.production_chk.checked)
		x.item_production.value='1';
	else x.item_production.value='0';
}

function set_ttc(){
	x=document.items;
	
	if(x.ttc_chk.checked)
		x.ttc_include.value='1';
	else x.ttc_include.value='0';
}

function set_printitem() {
	x=document.items;
	
	if(x.print_item.checked)
		x.item_print.value='1';
	else x.item_print.value='0';
}



function set_promotion(){
	x=document.items;
	
	if(x.promo_chk.checked)
		x.item_promotion.value='1';
	else x.item_promotion.value='0';
}

function set_pack(){
	x=document.items;
	
	if(x.pack_chk.checked)
		x.item_pack.value='1';
	else x.item_pack.value='0';
}

function set_serial(){
	x=document.items;
	
	if(x.serial_chk.checked)
		x.item_withserialno.value='1';
	else x.item_withserialno.value='0';
}

function set_sel(){
	x=document.items;
	
	if(x.sel_chk.checked)
		x.Item_ModifySellingPrice.value='1';
	else x.Item_ModifySellingPrice.value='0';
}

function set_evaluate(){
	x=document.items;
	
	if(x.evaluate_chk.checked)
		x.EvaluateQtyUnit.value='1';
	else x.EvaluateQtyUnit.value='0';
}


function set_finished(){
	x=document.items;
	
	if(x.finished_chk.checked)
		x.item_semifinished.value='1';
	else x.item_semifinished.value='0';
}

function set_active(){
	x=document.items;
	
	if(x.active_chk.checked)
		x.item_active.value='1';
	else x.item_active.value='0';
}

function set_nonstock(){
	x=document.items;
	
	if(x.nonstock.checked)
		x.nonstock_item.value='1';
	else x.nonstock_item.value='0';
}

function Chk_Last(){
	x=document.items;
	
	if(x.last_cost.checked)
		x.lastcost.value='1';
	else x.lastcost.value='0';
	
	x.action='Form_Items.php?vTabFocus=Selling Price';
	x.submit();
}

function ClearPage() {

	x=document.items;
	if (confirm ( "Are you sure you want to Clear Page?"))
	{
		ClearAll();

		x.mainmode.value='';
		x.action='Form_Items.php';
		x.submit();
	}	
}


function ClearAll(){
	x=document.items;
	x.message.value="";
	x.item_id.value="";
	x.item_code.value="";
	x.item_quantity.value="";
	x.item_barcode.value="";
	x.item_barcode2.value="";
	x.item_barcode3.value="";
	x.supplier_code.value="";
	x.supplier_name.value="";
	x.group_code.value="";
	x.group_name.value="";
	x.subgroup_code.value="";
	x.subgroup_name.value="";
	x.warehouse_code.value="";
	x.warehouse_desc.value="";
	//x.item_tax1.value="";
	x.item_print.value="";
	x.project_code.value="";
	x.project_name.value="";
	//x.item_tax2.value="";
	x.ttc_include.value="";
	x.costcent_code.value="";
	x.costcent_name.value="";
	//x.item_tax3.value="";
	//x.item_tax4.value="";
	x.item_active.value="";
	//x.item_tax5.value="";
	x.item_remark.value="";
	x.currency.value="";
	//x.item_tax6.value="";
	x.item_package.value="";
	x.item_vat.value="";
	x.item_vattype.value="";
	x.item_description.value="";
	x.item_descriptionf1.value="";
	x.item_descriptionf2.value="";
	x.item_longdescription.value="";
	x.cost.value="";
	x.item_unitsales.value="";
	x.item_unitpurchase.value="";
	x.setcode.value=0;
	x.numbertaxes.value=1;
	
	if(x.FI_SellingPriceInItems.value==1){
		x.transfer.value='';
		x.sellingprice1.value='';
		x.sellingprice2.value='';
		x.sellingprice3.value='';
		x.sellingprice4.value='';
		x.sellingprice5.value='';
		x.sellingprice6.value='';
		
		x.sellingprice1base1.value='';
		x.sellingprice2base1.value='';
		x.sellingprice3base1.value='';
		x.sellingprice4base1.value='';
		x.sellingprice5base1.value='';
		x.sellingprice6base1.value='';

		x.sellingprice1base2.value='';
		x.sellingprice2base2.value='';
		x.sellingprice3base2.value='';
		x.sellingprice4base2.value='';
		x.sellingprice5base2.value='';
		x.sellingprice6base2.value='';
		x.category_code.value='';
		x.category_name.value='';
		
		
	}
	
	
	x.numbertaxes.value=1;
	x.item_pack.value='';
	x.reverse_production.value='';
	x.item_production.value='';
	x.item_promotion.value='';
	x.nonstock_item.value='';
	x.item_weight.value='';
	x.item_netweight.value='';
	x.item_volume.value='';
	x.item_disporder.value='';
	x.item_discountper.value='';
	x.item_color.value='';
	x.item_lastcostprice.value='';
	x.item_sellingprice.value='';
	x.item_minimumprice.value='';
	x.item_minqty.value='';
	x.item_maxqty.value='';
	//x.Item_LastDatePurchase.value='';
	x.item_withserialno.value='';
	x.Item_ModifySellingPrice.value='';
	x.EvaluateQtyUnit.value='';
	x.mainmode.value='';
	x.actionmode.value='';
	
	x.item_code2.value='';	
	
	if(x.FI_SellingPriceInItems.value==1)
		x.item_code3.value='';
	
	x.item_code4.value='';	
	
	if(x.item_pack.value==1)
		x.item_code5.value='';
	
	x.item_code6.value='';

	if(x.FI_CostPriceInItems.value==1)
		x.item_code7.value='';
		
	x.item_code8.value='';	
	x.item_code9.value='';	
	
	x.item_desc2.value='';
	
	if(x.FI_SellingPriceInItems.value==1)
		x.item_desc3.value='';
		
	x.item_desc4.value='';

	if(x.item_pack.value==1)
		x.item_desc5.value='';
	x.item_desc6.value='';

	if(x.FI_CostPriceInItems.value==1)
		x.item_desc7.value='';

	x.item_desc8.value='';	
	x.item_desc9.value='';

	x.item_cur2.value='';	
	
	if(x.FI_SellingPriceInItems.value==1)
		x.item_cur3.value='';	
		
	x.item_cur4.value='';	

	if(x.item_pack.value==1)
		x.item_cur5.value='';
	
	x.item_cur6.value='';	
	
	if(x.FI_CostPriceInItems.value==1)
		x.item_cur7.value='';
	x.item_cur7.value='';		
	x.item_cur8.value='';		
	x.item_cur9.value='';
	
	cleardetail();
	cleardetailmanu();
	//cleardetailpack();
	cleardetailrebate();
}

function Additem() {
	//window.open('Form_Item_Type.php','itempicture','addressbar=no,statusbar=0,toolbar=no,location=no,status=0,menubar=no,scrollbars=no,resizable=no,width=320,height=150,top=200,left=350,titlebar=0');
	x = document.items;
	x.mainmode.value='insert';
	x.action='Form_Items.php';
	x.submit();
}

function Searchitems(){
 
	x = document.items;
    win = window.open('Form_ItemsSearch.php', 'Form_ItemSearch', '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 openAttributes(){

	x = document.items;
	var itemid=x.item_id.value;
	
    win = window.open('List_Items_Attributes_Wizard.php?item_id='+itemid+'&editattribute=1', 'Form_ItemAttribute', '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 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 SaveChanges(option){
	x=document.items;

	var error = 0;
	
	var qty=x.item_quantity.value;
	var qty1=parseInt(qty)*1/1;
	
	var fromrange=0, torange=0, rebateper=0;
	if (document.getElementById('rebate_rangefrom')) {
		fromrange = x.rebate_rangefrom.value;
		torange = x.rebate_rangeto.value;
		rebateper = x.rebate_per.value;
	}	
	
	/*var tax1=x.item_tax1.value;

	var itemtax1=parseInt(tax1)*1/1;
	
	var tax2=x.item_tax2.value;
	var itemtax2=parseInt(tax2)*1/1;
	
	var tax3=x.item_tax3.value;
	var itemtax3=parseInt(tax3)*1/1;
	
	var tax4=x.item_tax4.value;
	var itemtax4=parseInt(tax4)*1/1;
	
	var tax5=x.item_tax5.value;
	var itemtax5=parseInt(tax5)*1/1;
	
	var tax6=x.item_tax6.value;
	var itemtax6=parseInt(tax6)*1/1;
	
	var vat=x.item_vat.value;
	var itemvat1=parseInt(vat)*1/1;*/
	
	if(x.item_code.value==''){
		error = 1;
		alert('Item Code is Mandatory');
		x.item_code.focus();
	}

	else if(CheckValue(x.item_code.value)==1){
		error = 1;
		alert('Item Code should not contain signs.');
		x.item_code.focus();
	}
	else if(CheckValue(x.item_barcode.value)==1){
		error = 1;
		alert('Item Barcode should not contain signs.');
		x.item_barcode.focus();
	}
	else if(CheckValue(x.item_barcode2.value)==1){
		error = 1;
		alert('Item Barcode2 should not contain signs.');
		x.item_barcode.focus();
	}
	else if(CheckValue(x.item_barcode3.value)==1){
		error = 1;
		alert('Item Barcode3 should not contain signs.');
		x.item_barcode.focus();
	}
	
	else if(x.currency.value==''){
		error = 1;
		alert('Currency is Mandatory');
		x.currency.focus();
	}

	else if(x.project_code.value==''){
		error = 1;
		alert('Project is Mandatory');
		x.project_code.focus();
	}
	else if(x.group_code.value==''){
		error = 1;
		alert('Group is Mandatory');
		x.group_code.focus();
	}
	
	else if(qty!=qty1 && qty!=""){
		error = 1;
		alert('Quantity Must be A Number !');
		x.item_quantity.focus();
	}
	
	
	/*else if(tax1!=itemtax1 && tax1!=""){
		alert('Tax 1 Must be A Number !');
		x.item_tax1.focus();
	}
	
	else if(tax2!=itemtax2 && tax2!=""){
		alert('Tax 2 Must be A Number !');
		x.item_tax2.focus();
	}
	
	else if(tax3!=itemtax3 && tax3!=""){
		alert('Tax 3 Must be A Number !');
		x.item_tax3.focus();
	}
	else if(tax4!=itemtax4 && tax4!=""){
		alert('Tax 4 Must be A Number !');
		x.item_tax4.focus();
	}
	
	else if(tax5!=itemtax5 && tax5!=""){
		alert('Tax 5 Must be A Number !');
		x.item_tax5.focus();
	}
	
	else if(tax6!=itemtax6 && tax6!=""){
		alert('Tax 6 Must be A Number !');
		x.item_tax6.focus();
	}
	
	else if(vat!=itemvat1 && vat!=""){
		alert('VAT Must be A Number !');
		x.item_vat.focus();
	}*/
	else if (document.getElementById('attribute_code')) { 
		if(x.attribute_code.value=='' && option==2){
			error = 1;
			alert('Attribute Code is Mandatory !');
			x.attribute_code.focus();
		}	
	}
	else if (document.getElementById('attribute_value')) { 
		if(x.attribute_value.value=='' && option==2){
			error = 1;
			alert('Attribute Value is Mandatory !');
			x.attribute_value.focus();
		}	
	}
	else if (document.getElementById('attribute_unit')) { 
		if(x.attribute_unit.value=='' && option==2){
			error = 1;
			alert('Attribute Unit is Mandatory !');
			x.attribute_unit.focus();
		}	
	}
	else if (document.getElementById('manufacture_code')) { 
		if(x.manufacture_code.value=='' && option==3){
			error = 1;
			alert('Manufacture Code is Mandatory !');
			x.manufacture_code.focus();
		}	
	}
	else if (document.getElementById('manufacture_desc')) { 
		if(x.manufacture_desc.value=='' && option==3){
			error = 1;
			alert('Manufacture Description is Mandatory !');
			x.manufacture_desc.focus();
		}	
	}
	else if (document.getElementById('item_packcode')) { 
		if(x.item_packcode.value=='' && option==5){
			error = 1;
			alert('Pack Item is Mandatory !');
			x.item_packcode.focus();
		}	
	}
	else if (document.getElementById('item_warehousecode')) { 
		if(x.item_warehousecode.value=='' && option==5){
			error = 1;
			alert('Pack Item Warehouse is Mandatory !');
			x.item_warehousecode.focus();
		}	
	}
	
	else if (document.getElementById('rebate_rangefrom')) {
		if(x.rebate_rangefrom.value=='' && option==6){
			error = 1;
			alert('Rebate From Range is Mandatory !');
			x.rebate_rangefrom.focus();
		}	
	}
	else if(fromrange*1 != fromrange/1 && fromrange!=""){
		error = 1;
		alert('Rebate From Range Must be Numeric !');
		x.rebate_rangefrom.focus();
	}
	else if (document.getElementById('rebate_rangeto')) {	
		if(x.rebate_rangeto.value=='' && option==6){
			error = 1;
			alert('Rebate To Range is Mandatory !');
			x.rebate_rangeto.focus();
		}	
	}
	else if(torange*1 != torange/1 && torange!=""){
		error = 1;
		alert('Rebate To Range Must be Numeric !');
		x.rebate_rangeto.focus();
	}
	else if (document.getElementById('rebate_per')) {	
		if(x.rebate_per.value=='' && option==6){
			error = 1;
			alert('Rebate % is Mandatory !');
			x.rebate_per.focus();
		}	
	}
	else if(rebateper*1 != rebateper/1 && rebateper!=""){
		error = 1;
		alert('Rebate % Must be Numeric !');
		x.rebate_per.focus();
	}

	//else{
		disc = x.item_discountper.value;
		if(isNaN(disc)){
			error = 1;
			alert('Discount must be a number');
			x.item_discountper.focus();
		}
		else if( disc < 0 || disc > 100){
		error = 1;
		alert('Discount must be a number between 0 and 100');
		x.item_discountper.focus();
		}
	//}

	if (error == 0){
	
		if(option==2)	x.actionmode.value='submitattribute';
		if(option==3)	x.actionmode.value='submitmanufacture';
		if(option==4)	x.actionmode.value='copyreceipes';
		if(option==5) 	x.actionmode.value='submitpack';
		if(option==6) 	x.actionmode.value='submitrebate';
			
		x.checkduplicate.value=1;
		x.action="Form_Items.php";
		x.submit();
	}
}

function showtaxes(){
	x=document.items;
	x.numbertaxes.value=x.numtaxes.value;
	x.action="Form_Items.php";
	x.submit();
}


function SetItem(ItemId){

	document.items.radio.value=0;	
	document.items.item_id.value=ItemId;
	document.items.message.value='';
	document.items.actionmode.value='';
	//cleardetail();
	document.items.mainmode.value='editmode';
	document.items.submit();
}

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

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

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

function ClearKeyword(){
	x = document.items;
	x.txtKeyword.value='';
	document.items.action='Form_Items.php?startrange=0';
	document.items.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.items.action='Form_Items.php?startrange=0';
	document.items.submit();
  
   return false;
   }
else
   return true;
}

function confirm_delete(Code) {

				
	if (confirm ( "Are you sure you want to Delete this Record " + "?")) {
		
		document.items.mainmode.value='delete';	
		
		document.items.action='Form_Items_Actions.php?itemid='+Code;
		document.items.submit();
	}
					
}

function set_limit(){

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

function UpdateDetail(ItemDt_ID){
	 x = document.items;
	 x.ItemDt_ID.value=ItemDt_ID;
	x.actionmode.value='refresh';
	x.action='Form_Items.php?vTabFocus=Attributes';
	x.submit();
}	

function DeleteDetail(ItemDt_ID){

	if (confirm ( "Are you sure you want to Delete record?"))
	{
		
		document.items.ItemDt_ID.value = ItemDt_ID;
		document.items.actionmode.value = 'deleteattribute';
		
		document.items.action="Form_Items_Actions.php";
		document.items.submit();
	}	
}

function UpdateDetailRebate(rebate_id){
	x = document.items;
	x.rebate_id.value=rebate_id;
	x.actionmode.value='refresh';
	x.action='Form_Items.php?vTabFocus=Item Rebate';
	x.submit();
}

function DeleteDetailRebate(rebate_id){

	if (confirm ( "Are you sure you want to Delete record?"))
	{
		
		document.items.rebate_id.value = rebate_id;
		document.items.actionmode.value = 'deleterebate';
		
		document.items.action="Form_Items_Actions.php";
		document.items.submit();
	}	
}

function UpdateDetailPack(Itempackdt,Itempackwarehouse){
	 x = document.items;
	 x.Itempackdt.value=Itempackdt;
	 x.Itempackwarehouse.value=Itempackwarehouse;
	x.actionmode.value='refresh';
	x.action='Form_Items.php?vTabFocus=Pack';
	x.submit();
}	


function DeleteDetailPack(Itempackdt,Itempackwarehouse){
	 x = document.items;
	if (confirm ( "Are you sure you want to Delete record?"))
	{
		
		x.Itempackdt.value=Itempackdt;
		x.Itempackwarehouse.value=Itempackwarehouse;
		document.items.actionmode.value = 'deletepack';
		
		document.items.action="Form_Items_Actions.php";
		document.items.submit();
	}	
}





function UpdateDetailManufacture(manufcode){
	 x = document.items;
	 x.manufacture_code.value=manufcode;
	x.actionmode.value='refresh';
	x.action='Form_Items.php?vTabFocus=Manufactured Code';
	x.submit();
}	

function DeleteDetailManufacture(manufcode){

	if (confirm ( "Are you sure you want to Delete record?"))
	{
		
		document.items.manufacture_code.value = manufcode;
		document.items.actionmode.value = 'deletemanufacture';
		
		document.items.action="Form_Items_Actions.php";
		document.items.submit();
	}	
}



function cleardetail(){
	 x = document.items;

	x.attribute_code.value='';
	x.attribute_value.value='';
	x.attribute_unit.value='';
	x.attribute_desc.value='';
	x.ItemDt_ID.value='';
	x.actionmode.value='';
	x.submit();	
}

function cleardetailmanu(){
	 x = document.items;

	x.manufacture_code.value='';
	x.manufacture_desc.value='';

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

function cleardetailpack(){
	 x = document.items;

	x.item_warehousecode.value='';
	x.item_warehousedesc.value='';
	x.item_packqty.value='';
	x.item_packcost.value='';
	x.item_packbarcode.value='';
	x.item_packfromdate.value='';
	x.item_packtodate.value='';
	x.item_promoqty.value='';
	x.item_packcode.value='';
	x.item_packdesc.value='';
	x.Itempackdt.value='';
	x.Itempackwarehouse.value='';
	x.item_packgroupcode.value='';
	x.item_packgroupname.value='';


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

function cleardetailrebate(){
	 x = document.items;

	x.rebate_rangefrom.value='';
	x.rebate_rangeto.value='';
	x.rebate_per.value='';
	x.rebate_id.value='';
	x.actionmode.value='';
	x.submit();	
}


function Setprices(index){
	 x = document.items;
	var base1=x.base1.value;
	var base2=x.base2.value;
	var cur=x.currency.value;
	
	if (index == 10) {
		index = 1;
		document.items["sellingprice"+index].value = document.items["item_sellingprice"].value;	
		Setprices(1);
	}
	
	if(base1==cur){
		var amount1=document.items["sellingprice"+index].value;
		document.items["sellingprice"+index+"base1"].value=amount1;
	}	

	if(base2==cur){
		var amount2=document.items["sellingprice"+index].value;
		document.items["sellingprice"+index+"base2"].value=amount2;
	}	

	var dec1=x.DecimalBase1.value;
	var dec2=x.DecimalBase2.value;
	
	dec1=parseInt(dec1);
	dec2=parseInt(dec2);
	
	var amount=document.items["sellingprice"+index].value;
	amount=parseFloat(amount);
	
	var rate=x.rate_dt.value;
	rate=parseFloat(rate);
	
	var rate1=x.rate_dt1.value;
	rate1=parseFloat(rate1);
	
	var rate2=x.rate_dt2.value;
	rate2=parseFloat(rate2);
	
	if (amount>=0) {
	
		var amount1=Math.round(((amount*rate)/rate1)*Math.pow(10,dec1))/Math.pow(10,dec1);
		amount1=parseFloat(amount1);
		document.items["sellingprice"+index+"base1"].value=amount1;
			
		var amount2=Math.round(((amount*rate)/rate2)*Math.pow(10,dec2))/Math.pow(10,dec2);
		amount2=parseFloat(amount2);
		//alert(amount2);
		document.items["sellingprice"+index+"base2"].value=amount2;
	}	

}

function Setpricesbase(index,index2){

	x = document.items;
	var base1=x.base1.value;
	var base2=x.base2.value;
	var cur=x.currency.value;
	
	if(index==1){
		if(base1==cur){
		var amount1=document.items["sellingprice"+index2+"base1"].value;
		document.items["sellingprice"+index2].value=amount1;
		}		
	}
	else if(index==2){
		if(base2==cur){
		var amount2=document.items["sellingprice"+index2+"base2"].value;
		document.items["sellingprice"+index2].value=amount2;
		}		
	}
}

function Refreshpage(){
	
x = document.items;
x.submit();
}

function Refreshpage2(value){
	
x = document.items;
x.radio.value=1;
	if(value=='pack'){
		x.reverse_production.value=0;
		x.item_production.value=0;
		x.item_pack.value=1;
		x.item_semifinished.value=0;
	}
	else if(value=='reverse'){
		x.reverse_production.value=1;
		x.item_production.value=0;
		x.item_pack.value=0;
		x.item_semifinished.value=0;
	}
	else if(value=='production'){
		x.reverse_production.value=0;
		x.item_production.value=1;
		x.item_pack.value=0;
	}

	x.action='Form_Items.php?vTabFocus=Others';
	x.submit();
}




function CopyRecepies(){
	x = document.items;

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

function Changecode(){
	x = document.items;
	x.item_code2.value=x.item_code.value;	
	
	if(x.FI_SellingPriceInItems.value==1)
		x.item_code3.value=x.item_code.value;
	
	x.item_code4.value=x.item_code.value;	
	
	if(x.item_pack.value==1)
		x.item_code5.value=x.item_code.value;
	
	x.item_code6.value=x.item_code.value;

	if(x.FI_CostPriceInItems.value==1)
		x.item_code7.value=x.item_code.value;
		
	x.item_code8.value=x.item_code.value;	
	x.item_code9.value=x.item_code.value;	
	
}
function Changedesc(){
	x = document.items;
	x.item_desc2.value=x.item_description.value;
	
	if(x.FI_SellingPriceInItems.value==1)
		x.item_desc3.value=x.item_description.value;
		
	x.item_desc4.value=x.item_description.value;

	if(x.item_pack.value==1)
		x.item_desc5.value=x.item_description.value;
	x.item_desc6.value=x.item_description.value;

	if(x.FI_CostPriceInItems.value==1)
		x.item_desc7.value=x.item_description.value;

	x.item_desc8.value=x.item_description.value;	
	x.item_desc9.value=x.item_description.value;	
}

function Changecur(){
	x = document.items;
	x.item_cur2.value=x.currency.value;	
	
	if(x.FI_SellingPriceInItems.value==1)
		x.item_cur3.value=x.currency.value;	
		
	x.item_cur4.value=x.currency.value;	

	if(x.item_pack.value==1)
		x.item_cur5.value=x.currency.value;
	
	x.item_cur6.value=x.currency.value;	
	
	if(x.FI_CostPriceInItems.value==1)
		x.item_cur7.value=x.currency.value;
	x.item_cur7.value=x.currency.value;		
	x.item_cur8.value=x.currency.value;		
	x.item_cur9.value=x.currency.value;	

	x.submit();
}

function generatebarcode2(){
	x = document.items;
	
	x.actionmode.value='generatebarcode2';
	x.action='Form_Items_Actions.php';
	x.submit();
	
}

function generatetextfile(Pindex){
	x = document.items;
	x.actionmode.value='generatetextfile';
	x.barcodeindex.value=Pindex;
	SaveChanges('1');
}

function CheckValue(val) {
	var str = new Array('\'','"','#','&');
	var result = 0;
	
	for(i=0;i<str.length;i++){
		if(val.indexOf(str[i]) > -1) result = 1;
	}

	return result;
}

function CheckDuplicateItem(e) {
	x = document.items;
	var intKey = (window.Event) ? e.which : e.keyCode;
	
	if (intKey != 13) { //enter key
		return false;
    }
	
	var xmlhttp = getXMLHttpRequest();	
	var getdate = new Date();  //Used to prevent caching during ajax call
	
	var item_id   = document.items.item_id.value;
	var item_code = document.items.item_code.value;
	
	
	var xmlhttp = getXMLHttpRequest();	
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			var data = $.parseJSON(xmlhttp.responseText);
			var msg = data[0].message;
					
			if (msg != "") {
				alert(decodeURIComponent(msg));
			} 
		}
	}
	    
	xmlhttp.open("GET","Form_Items_Actions.php?mainmode=checkduplicate&item_id="+item_id+"&item_code="+item_code);
	xmlhttp.send();
		
}

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

function ExtractReport(minDate, item_code){
	if(minDate == '//') minDate = '01/01/1997';
	var today = new Date();
	var dd = today.getDate();
	var mm = today.getMonth() + 1; //January is 0
	var yyyy = today.getFullYear();
	if(dd < 10) {
   		dd = '0' + dd;
	}
	if(mm < 10) {
	    mm = '0' + mm;
	}
	today = dd + '/' + mm + '/' + yyyy;
	x = document.items;
	window.open("Rep_StatementofItems.php?fromdate=" + minDate + "&todate=" + today + "&fromitem=" + item_code + "&fromheatno=&toheatno=&toitem=" + item_code + "&fromwarehouse=&fromgroup=&togroup=&fromsubgroup=&tosubgroup=&fromcategory=&tocategory=&fromtranswh=&totranswh=&fromproject=&toproject=&fromcostcent=&tocostcent=&prtcost=" + x.FI_CostPriceInItems + "&updmeancost=0&searchserial=0&TransPI=1&TransPR=1&TransSI=1&TransSR=1&TransTR=1&TransPD=1&TransAD=1&curr=USD&vShowProject=$module_project&vShowCostcenter=$module_costcent&vShowHeatno=1&showserials=0", "_blank");
}

</script>

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

<style type="text/css">

body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
}


.style13 {color: #000000; font-weight: bold; }
.style12 {color: #999999; font-weight: bold; font-size: 9px }
.selectstyle {font-size: 11px; font-family:arial,verdana,geneva; color:#000000; width=52px}
.selectstyle1 {font-size: 11px; font-family:arial,verdana,geneva; color:#000000; width=35px}

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>

<link rel="stylesheet" type="text/css" media="all" href="UI_DataGrid.css">

<title>Items</title>
</head>
<body>
<form name='items' method='post' enctype='multipart/form-data'>
<input type='hidden' name='HideMenu' value='$HideMenu'>
<input type='hidden' name='mainmode' value='$mainmode'>
<input type='hidden' name='radio' value='$radio'>
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='message' value='$message'>
<input type='hidden' name='item_id' value='$item_id'>
<input type='hidden' name='checkduplicate' value='$checkduplicate'>
<input type='hidden' name='setcode' value='$setcode'>
<input type='hidden' name='numrow' value='$numrow'>
<input type='hidden' name='numbertaxes' value='$numbertaxes'>

<input type=hidden name='item_attribute'  value='$item_attribute'>
<input type=hidden name='item_policy'  value='$item_policy'>
<input type=hidden name='ItemDt_ID'  value='$ItemDt_ID'>
<input type=hidden name='base1'  value='$base1'>
<input type=hidden name='base2'  value='$base2'>
<input type=hidden name='DecimalBase1'  value='$DecimalBase1'>
<input type=hidden name='DecimalBase2'  value='$DecimalBase2'>
<input type='hidden' name='rate_dt'  value='$rate_dt'>
<input type='hidden' name='rate_dt1'  value='$rate_dt1'>
<input type='hidden' name='rate_dt2'  value='$rate_dt2'>
<input type='hidden' name='lastcost'  value='$lastcost'>
<input type='hidden' name='FI_SellingPriceInItems'  value='$FI_SellingPriceInItems'>
<input type='hidden' name='FI_CostPriceInItems'  value='$FI_CostPriceInItems'>
<input type='hidden' name='RI_SatementofItems' value='$RI_SatementofItems'>
<input type='hidden' name='itemactive'  value='$itemactive'>
<input type='hidden' name='item_semifinished'  value='$item_semifinished'>
<input type='hidden' name='Itempackdt'  value='$Itempackdt'>
<input type='hidden' name='Itempackwarehouse'  value='$Itempackwarehouse'>
<input type='hidden' name='barcodeindex'  value='$barcodeindex'>


HERE;

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'>ITEMS</span></td>
				<td class='message' valign='middle' style='height:26px;'>".htmlspecialchars($message, ENT_QUOTES)."</td>
			</tr></table>
		</td>
	  </tr>";


echo"<tr>
		<td  height='34'  valign='top' id='content-top2'>
			<table border='0' cellpadding='0' cellspacing='0' class='layout-width'>
			<tr>
				<td width='38'  height='34'>&nbsp;</td>
				<td valign='middle' height='34' width='680px'>";
echo"		<button type='button' id='btnClear' name='btnClear' onclick='ClearPage(); return false;' title='Clear Page'><span><span>Clear Page</span></span></button>";


echo"		<button type='button' id='btnPost' name='btnPost' onclick='SaveChanges(); return false;' title='Save Changes' $Insmode><span><span>Save</span></span></button>";
echo"		<button type='button' id='btnExcel' name='btnExcel' onclick='ExportExcel(); return false;' title='Export Excel' ><span><span>Excel</span></span></button>";

				
echo"   </td><td align='left' width='260px'>
	&nbsp;<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 Items'><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;
		
	for($i=10;$i<=$maxperpage;$i=$i+10){
		if($i==$perpage)
			echo "<option value='$i'  selected>$i</option>";
		else echo "<option value='$i'>$i</option>";
		
	} 
	 echo"</td></tr>";
echo"	</table>";
echo"</td></tr>";

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


$tabs = new tabs("Items");	
$tabs->start("Main Page");

echo"<table border='0'  align='center' valign='top' width=100% class='tablecontent'>
	<col width=55%>";

echo"<tr><td  valign='top'>";
echo "<table  border='0' width=100%><col width=150><col width=180>";
	

echo"<tr  bgcolor='#F7F7F7' height='25'><td><span class='style1'>Code<font color='#FF0000'>*</font></span></td>
	<td><input type=text name='item_code' value='$item_code' maxlength='20' size='20' onchange='Changecode();' onkeydown='CheckDuplicateItem(event);'></td>
		<td align='left'><span class='style1'>VAT </span>";
	echo"<input type=text name='item_vat' value='$item_vat' maxlength='3' style='width:30px;' $statusreadonly>
		 <select name='item_vattype' id='item_vattype' $statusdisabled style='width:90px; height:22px;'>";
	echo"	<option value='1'"; if($item_vattype == 1) echo" selected "; echo">Deductable</option>";
	echo"	<option value='2'"; if($item_vattype == 2) echo" selected "; echo">Collactable</option>";
	echo"	<option value='3'"; if($item_vattype == 3) echo" selected "; echo">Not Clear</option>";
	echo" </select>
		 <span class='style1'>Curr<font color='#FF0000'>*</font></span>
		 <select name='currency' $statusdisabled style='width:55px; height:22px;' onchange='Changecur();'>
		 <option>&nbsp;</option>";
		while ($row_currency=mysql_fetch_row($result_currency)){
			if($row_currency[0]==$currency)
				echo "<option value='$row_currency[0]'  selected>$row_currency[0]</option>";
			else echo "<option value='$row_currency[0]'>$row_currency[0]</option>";
		}
	echo"</select></td>";

	/*echo"<td align='center'><span class='style1'>Type</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <select name='itemtype' style=' width:120px; height:18px;' $statusdisabled>";
		if ($itemtype == "Packed" && $module_pack == 1){
				echo "<option selected value='Packed'>Packed</option>";
		}
		else if ($module_pack == 1){
				echo "<option value='Packed'>Packed</option>";
		}
		if ($itemtype == "PromoPacked" && $module_pack == 1){
			echo "<option selected value='PromoPacked'>Promo Packed</option>";
		}
		else{
			echo "<option value='PromoPacked'>Promo Packed</option>";
		}
		if ($itemtype == "Trading"){
			echo "<option selected value='Trading'>Trading</option>";
		}
		else{
			echo "<option value='Trading'>Trading</option>";
		}
		if ($itemtype == "PromoTrading"){
			echo "<option selected value='PromoTrading'>Promo Trading</option>";
		}
		else{
			echo "<option value='PromoTrading'>Promo Trading</option>";
		}
		if ($itemtype == "Production"){
			echo "<option selected value='Production'>Production</option>";
		}
		else{
			echo "<option value='Production'>Production</option>";
		}
		if ($itemtype == "NonStock"){
			echo "<option selected value='NonStock'>Non-Stock</option>";
		}
		else{
			echo "<option value='NonStock'>Non-Stock</option>";
		}
	echo "</select></td>";*/
	
	
	
	echo"</tr>";
	
	$item_picture=$_POST['item_picture'];
	
	echo"<tr  bgcolor='#F7F7F7' height='25'>";
	echo" <td><span class='style1'>Description</span></td>
		  <td colspan='2'><input type='text' name='item_description' value='".htmlspecialchars($item_description, ENT_QUOTES)."'  maxlength='60' size='62' $statusreadonly onchange='Changedesc();'></td>";
	echo"</tr>";
	echo" <td><span class='style1'>Description(Arabic)</span></td>
		  <td colspan='2'><input type='text' name='item_descriptionf1' value='".htmlspecialchars($item_descriptionf1, ENT_QUOTES)."'  maxlength='100' size='62' $statusreadonly ></td>";
	echo"</tr>";
	echo" <td><span class='style1'>Description(French)</span></td>
		  <td colspan='2'><input type='text' name='item_descriptionf2' value='".htmlspecialchars($item_descriptionf2, ENT_QUOTES)."'  maxlength='100' size='62' $statusreadonly ></td>";
	echo"</tr>";
	
	echo"<tr bgcolor='#F7F7F7' height='25'>
		<td><span class='style1'>Supplier Code/Name</span></td>";
	echo"<td><input type='text' name='supplier_code' value='$supplier_code' readonly size='17'>";
	
	if($mainmode!='')
		echo"&nbsp;<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Supplier ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistsupplier(1); '  /></span></label>";
	else echo"&nbsp;&nbsp;&nbsp;&nbsp;";	
	
	echo"</td><td><input type='text' name='supplier_name' value='$supplier_name' readonly size='36'></td>";

	echo"</tr>";  

	
	echo"<tr bgcolor='#F7F7F7' height='25'><td><span class='style1'>Group Code/Name</span></td>
		<td><input type='text' name='group_code' value='$group_code' readonly size='17' >";
		
	if($mainmode!='')
		echo"&nbsp;<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Group ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistgroups(2); '  /></span></label>";
	else echo"&nbsp;";		
			
	echo"</td><td><input type='text' name='group_name' value='$group_name' readonly size='36'></td>
		
		";
	echo"</tr>";


	echo"<tr bgcolor='#F7F7F7' height='25'><td><span class='style1'>SubGroup Code/Name</span></td>";
	echo"<td><input type='text' name='subgroup_code' value='$subgroup_code' readonly size='17'>";
	
	if($mainmode!='')
		echo"&nbsp;<label><span class='style1'><img src='img/btnopen.jpg' title=' Select SubGroup ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistsubgroups(1); '  /></span></label>";
	else echo"&nbsp;";		
	echo"</td><td><input type='text' name='subgroup_name' value='$subgroup_name' readonly size='36'></td></tr>";

	echo"<tr bgcolor='#F7F7F7' height='25'>";	
	
	if($module_costcent=='0'){
		echo"<td><span class='style1'>&nbsp;</span></td>
		<td><input type='hidden' name='costcent_code' value='$costcent_code' readonly size='17'></td>
		<td><input type='hidden' name='costcent_name' value='$costcent_name' readonly size='36'></td>";
	}

	else if($module_costcent=='1'){
		echo"<td><span class='style1'>CostCenter</span></td>
		<td><input type='text' name='costcent_code' value='$costcent_code' readonly size='17'>";
		
		if($mainmode!='')
			echo"&nbsp;<label><span class='style1'><img src='img/btnopen.jpg' title=' Select CostCenter ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistcostcentercode(6); '  /></span></label>";
		else echo"&nbsp;";	
		
		echo"</td><td><input type='text' name='costcent_name' value='$costcent_name' readonly size='36'></td>";
	}
	echo"</tr>";

	echo"<tr bgcolor='#F7F7F7' height='25'>";
	
	if($module_project=='0'){
		echo"	<td><span class='style1'>&nbsp;</span></td>";
		echo"	<td>";
		echo"<input type='hidden' name='project_code' value='$project_code' readonly size='15'></td>
		<td><input type='hidden' name='project_name' value='$project_name' readonly size='36'></td>";
	}

	else if($module_project=='1'){
		echo"<td><span class='style1'>Project</span><font color='#FF0000'>*</font></td>";
		echo"<td>";
		echo"<input type='text' name='project_code' value='$project_code' readonly size='17'>";
		
		if($mainmode!='')
			echo"&nbsp;<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Project ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistprojects(8); '  /></span></label>";
		else echo"&nbsp;";
		echo"</td><td><input type='text' name='project_name' value='$project_name' readonly size='36'></td>";
	}
	echo"";
	
	/*<td align='center'><span class='style1'>No Taxes</span> <select name='numtaxes' onchange='showtaxes()'; $statusdisabled>
										<option value='1' $selectedtax1>1</option>
										<option value='2'  $selectedtax2>2</option>
										<option value='3'  $selectedtax3>3</option>
										<option value='4'  $selectedtax4>4</option>
										<option value='5'  $selectedtax5>5</option>
										<option value='6'  $selectedtax6>6</option></select></td>*/
	echo"</tr>";
	
	echo"<tr bgcolor='#F7F7F7' height='25'>";
	echo"	<td><span class='style1'>Warehouse</span></td>
			<td><input type='text' name='warehouse_code' id='warehouse_code' value='$warehouse_code'  maxlength='15' size='17'>";
	if($mainmode!='')
		echo"&nbsp;<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Warehouse ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistwarehouse(6); '  /></span></label></td>";
	else echo"&nbsp;</td>";
			
	echo"	<td><input type='text' name='warehouse_desc' id='warehouse_desc' value='$warehouse_desc'  readonly size='36'></td>";
	echo"</tr>";

	echo"<tr bgcolor='#F7F7F7' height='25'>";
	echo"<td><span class='style1'>Remark</span></td><td colspan='2'><input type='text' name='item_remark' value='".htmlspecialchars($item_remark, ENT_QUOTES)."' maxlength='100' size='62' $statusreadonly></td>
	";

/*	<td colspan='2' rowspan='2' valign='top'><table border='0' width='100%'><tr>";
	for($i=1;$i<=$numbertaxes;$i++){
	
		$nametax='item_tax'.$i;
		$item_tax='item_tax'.$i;
		
		if($i=='4')
			echo"</tr><tr>";
		echo"<td align='right'><span class='style1'>Tax $i </span></td><td><input type='text'  maxlength='3' size='3' name='$nametax' value=".$$item_tax."></td>";
	}
	
	$lefttaxes=$numbertaxes+1;
	for($i=$lefttaxes;$i<=6;$i++){
	
		$nametax='item_tax'.$i;
		$item_tax='item_tax'.$i;
		$$item_tax='';
		
		if($i=='4')
			echo"</tr><tr>";
		echo"<td align='right'><span class='style1'>Tax $i </span></td><td><input type='text'  size='3' disabled style='background-color: #D0D0D0' name='$nametax' value=".$$item_tax."></td>";
	}
	
	echo"</table></td>*/
	
	echo"</tr>";
	
	echo"<tr bgcolor='#F7F7F7' height='25'>";
	echo"<td><span class='style1'>Package</span></td><td><input type='text' name='item_package' value='".htmlspecialchars($item_package, ENT_QUOTES)."' maxlength='30' size='20' $statusreadonly></td>";
	echo"<td><input type='hidden' name='item_active' value='$item_active'><input type='checkbox' name='active_chk' onclick='set_active()'; $selectedactive $statusdisabled>
			<span class='style1'>Active</span>&nbsp; <span class='style1'>Inactive Date</span>&nbsp; &nbsp;  <b>$inactivedate</b></td>";
		
	echo"<tr bgcolor='#F7F7F7' height='25'><td><span class='style1'>Min Quantity</span></td><td><input type='text' name='item_minqty' value='".htmlspecialchars($item_minqty, ENT_QUOTES)."' maxlength='30' size='20' ></td>
			<td align='left'><span class='style1'>Max Quantity </span><input type='text' name='item_maxqty' value='".htmlspecialchars($item_maxqty, ENT_QUOTES)."' maxlength='30' size='20' ></td>
		</tr>";
		
	echo"<tr bgcolor='#F7F7F7' height='25'>
			<td><span class='style1'>Last Cost Price</span></td><td><input type='text' name='item_lastcostprice' value='$item_lastcostprice' maxlength='30' size='20' ></td>
			<td><span class='style1'>Selling Price </span>&nbsp;<input type='text' name='item_sellingprice' value='$sellingprice1' onchange='Setprices(10);' maxlength='30' size='20' ></td>
		</tr>";
		
	echo"<tr bgcolor='#F7F7F7' height='25'>
			<td><span class='style1'>Disp. Order</span></td><td><input type='text' name='item_disporder' value='$item_disporder' maxlength='30' size='20' ></td>
			<td><span class='style1'>Minimum Price </span>&nbsp;<input type='text' name='item_minimumprice' value='$item_minimumprice' maxlength='30' size='18' ></td>
		</tr>";
	echo"<tr bgcolor='#F7F7F7' height='25'>
			<td><span class='style1'>Discount</span></td><td><input type='text' name='item_discountper' value='$item_discountper' maxlength='30' size='18' >%</td>
			<td></td>
		</tr>";
	
	echo"<tr  bgcolor='#F7F7F7' height='25'>";
	echo"<td align='left' colspan=2><span class='style1'> Unit (</span>&nbsp;";
	echo"<input type='text' name='item_unitsales' value='$item_unitsales'  size='10' maxlength='20'>)=
	<span class='style1'>Quantity(</span>";
	echo"&nbsp;<input type='text' name='item_quantity' value='$item_quantity'  size='10' maxlength='10'>)
	</td><td><span class='style1'>Whole Unit(</span>";
	echo"&nbsp;<input type='text' name='item_unitpurchase' value='$item_unitpurchase'  size='10' maxlength='20'>)</td>";
	/*<td align='center'>&nbsp; <span class='style1'>Last Purchase Date</span></td><td>";
	echo"<input type='text' name='Item_LastDatePurchase' value='$Item_LastDatePurchase'  size='20' maxlength='10'>";
	
	if($mainmode!='view' && $mainmode!=''){
		
print<<< HERE
&nbsp;<A HREF="#" onClick="displayCalendar(document.items.Item_LastDatePurchase,'dd-mm-yyyy',this); return false;" NAME="anchor1" ID="anchor1"><image src='./img/cal.gif' border=0 align=center></image></A></td>
HERE;
}*/

echo"</tr>";

echo"<tr  bgcolor='#F7F7F7' height='25'>
		<td colspan='2'><span class='style1'>G.Weight</span>
			<input type='text' name='item_weight' value='".htmlspecialchars($item_weight, ENT_QUOTES)."' maxlength='30' size='9' >
			<span class='style1'>Net Weight</span>
			<input type='text' name='item_netweight' value='".htmlspecialchars($item_netweight, ENT_QUOTES)."' maxlength='30' size='10' >
		</td>
		<td><span class='style1'>Volume/Box&nbsp;</span><input type='text' name='item_volume' value='".htmlspecialchars($item_volume, ENT_QUOTES)."' maxlength='30' size='20' ></td>
	</tr>";


	/*echo"<td><span class='style1'>Selling Prices</span></td><td colspan='4'>1: <input type='text' name='item_sellingprice1' value='".htmlspecialchars($item_sellingprice1, ENT_QUOTES)."'  size=14>&nbsp;
	2:<input type='text' name='item_sellingprice2' value='".htmlspecialchars($item_sellingprice2, ENT_QUOTES)."'  size=14>&nbsp;
	3:<input type='text' name='item_sellingprice3' value='".htmlspecialchars($item_sellingprice3, ENT_QUOTES)."'  size=14>&nbsp;
	4:<input type='text' name='item_sellingprice4' value='".htmlspecialchars($item_sellingprice4, ENT_QUOTES)."'  size=14>&nbsp;
	5:<input type='text' name='item_sellingprice5' value='".htmlspecialchars($item_sellingprice5, ENT_QUOTES)."' size=14 >&nbsp;
	6:<input type='text' name='item_sellingprice6' value='".htmlspecialchars($item_sellingprice6, ENT_QUOTES)."'  size=14></td>";*/
	
$lendesc=strlen($item_longdescription);
$restdesc=1000-$lendesc;

	echo"<tr  bgcolor='#F7F7F7' height='25'>";
	echo"<td><span class='style1'>Long Description</span></td>
		<td align='left' colspan='2' rowspan='2'>
		<textarea name='item_longdescription'  size=100%  cols=47 rows=4 $status onKeyDown='textCounter(this.form.item_longdescription,this.form.remLenaddress,1000);' onKeyUp='textCounter(this.form.item_longdescription,this.form.remLenaddress,1000)';  $statusreadonly>".htmlspecialchars($item_longdescription, ENT_QUOTES)."</textarea></td>";
	echo"";
	echo"</tr>";
	
	echo"<tr bgcolor='#F7F7F7' height='25'><td  align=center><span class='style1'><span class='style12' >Remaining Chars</span>&nbsp;<input readonly type=text name=remLenaddress size=1 maxlength=3 value='$restdesc' style='font-size:11px; width:25px; height:18px; border:none; background-color:#F7F7F7; '></td>
		
	</tr>";


	
	/*echo"<tr bgcolor='#F7F7F7'>";
	
	//// Displaying item Attributes
	if($item_id!=''){
		$i=1;
		$n=1;
		while($row_attr=mysql_fetch_row($result_attributes)){
		
		///	if($n=='2'){
		//		echo"</tr><tr bgcolor='#F7F7F7'>";
		//		$n=0;
		//	}	
			
			
			if($i=='1')
				echo"<td colspan='5' align='center'><span class='style1'>$n - </span><font face='Verdana' size='2'><b>$row_attr[0]</font></b>";
			else if($row_attr[2]!=$parent && $i!='1'){
				$n=$n+1;
				
				$query_leaf="select subgroup_name,subgroup_policy,subgrouppolicy_startchar,subgrouppolicy_endchar,
				substr(subgroup_name,subgrouppolicy_startchar,subgrouppolicy_endchar) from subgroup
				left join subgrouppolicy on subgrouppolicy.subgrouppolicy_id=subgroup.subgroup_policy
				where increment='".$leafid."'";
				//echo$query_leaf;
				//$result_leaf=mysql_query($query_leaf,$connection);
				$row_attrleaf=mysql_fetch_row($result_leaf);
				
				echo"==><span class='style13'>$row_attrleaf[4]</span></tr><tr bgcolor='#F7F7F7'><td colspan='5' align='center'><span class='style1'>$n - </span><font face='Verdana' size='2'><b>$row_attr[0]</font></b></span>: &nbsp; <span class='style1'>$row_attr[1]</span>";
				
			}	
			else echo": &nbsp;<span class='style1'>".$row_attr[1]."</span>";
			
			$leafid=$row_attr[4];
			$parent=$row_attr[3];
			$leaf=$row_attrleaf[4];
			$i=$i+1;
		}
		
		$query_leaf="select subgroup_name,subgroup_policy,subgrouppolicy_startchar,subgrouppolicy_endchar,
				substr(subgroup_name,subgrouppolicy_startchar,subgrouppolicy_endchar) from subgroup
				left join subgrouppolicy on subgrouppolicy.subgrouppolicy_id=subgroup.subgroup_policy
				where increment='".$leafid."'";
			//	echo$query_leaf;
				//$result_leaf=mysql_query($query_leaf,$connection);
				$row_attrleaf=mysql_fetch_row($result_leaf);
				$numleaf=mysql_num_rows($result_leaf);
			
		if($numleaf>0){
			echo"==><span class='style13'>".$row_attrleaf[4]."</span>";
		}
		echo"</td>";
	}
	
echo"</tr>*/

echo"</table></td><td  valign='top'>";

echo"<table  border='0' style='width:490px;' cellspacing=0><col width=100>
	 <tr><td id='search-topW' style='width:490px;height:15px;' colspan='4'></td>
	</tr>
	 <tr><td  id='search-contentW' colspan=4>
	
	 <div style='overflow:scroll;height:500px;width:470px;border:0px solid #000000;padding-left:10px;' >
	 <table  style='width:1300px;' >
	 	<col width=20>
	 	<col width=20>
		<col width=20>
		<col width=100>
		<col width=200>
		<col width=70>
		<col width=80>
		<col width=100>
		<col width=100>
		<col width=100>
		<col width=130>
		<col width=200>
		<col width=200>
	 <tr height='25px' >
	 	 <td>&nbsp;</td>
		 <td>&nbsp;</td>
		 <td>&nbsp;</td>
		 <td align='center'><span class='style1'><b>Code</b></td>
		 <td align='center'><span class='style1'><b>Name</b></td>
		 <td align='center'><span class='style1'><b>Selling Price 1</b></td>
		 <td align='center'><span class='style1'><b>Qty Exist</b></td>
		 <td align='center'><span class='style1'><b>Barcode 1</b></td>
		 <td align='center'><span class='style1'><b>Barcode 2</b></td>
		 <td align='center'><span class='style1'><b>Barcode 3</b></td>
		 <td align='center'><span class='style1'><b>Group</b></td>
		 <td align='center'><span class='style1'><b>Subgroup</b></td>
		 <td align='center'><span class='style1'><b>Supplier</b></td>
	 </tr>
	";
	
	$querysearch=" select item_id,item_code,item_description,Item_SellingPrice1,Item_barcode,concat(items.Group_Code,'-',Group_name),concat(items.SubGroup_Code,'-',subgroup_name), ".
				 " concat(items.Ledger_Number,'-',suppliers.ledger_name),Item_barcode2,Item_barcode3 from items ".
				 " left join suppliers on suppliers.ledger_number=items.ledger_number ".
				 " left join subgroup on subgroup.subgroup_code=items.subgroup_code ".
				 " left join grouping on grouping.group_code=items.group_code ";
	
	$querysearch=$querysearch." where (item_code like ('%".$txtKeyword."%') or item_description like ('%".$txtKeyword."%') or Item_barcode like ('%".$txtKeyword."%') 
								or Item_barcode2 like ('%".$txtKeyword."%') or Item_barcode3 like ('%".$txtKeyword."%') 
								or items.Group_Code like ('%".$txtKeyword."%') or Group_name like ('%".$txtKeyword."%') or items.SubGroup_Code like ('%".$txtKeyword."%')
								or subgroup_name like ('%".$txtKeyword."%')  or items.Ledger_Number like ('%".$txtKeyword."%') ) ";
	//echo$querysearch;
	$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());
	$totalrows = mysql_num_rows($resultsearch);
	
	if ($startrange=='')
		$startrange = 0;
	if ($perpage=='')
		$perpage = 20;
	
	$querysearch = $querysearch." limit ".$startrange.",".$perpage;
	

	$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());	
	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' && $item_id == $rows[0]) {

			$Color = "style='background-color:#1e87a5'";
			$stylefont = 'style28';
		}

		$query = "select qtyexists('$rows[1]','',now(),null,'','','')";
		$result = mysql_query($query, $connection) or die(mysql_error());
		$row = mysql_fetch_row($result);


		echo '<tr ' . $Color . ' height="20px" >';

		if ($FI_ItemsDel == 1){
			$queryy = "SELECT min(Transaction_Date) FROM stktransaction where Item_code = '$rows[1]'";
			$resultt = mysql_query($queryy,$connection) or die(mysql_error());
			$minDater = mysql_fetch_row($resultt);
			$minDate = explodeword($minDater[0]);

			if($RI_SatementofItems == 1){
				print "<td align='center' valign='center'><span class='style15'><img src='img/checksbills.png'  onmouseover=\"this.style.cursor='pointer'\" onclick=\"ExtractReport('$minDate', '$rows[1]')\" title=' Extract Report '  ></span></td>";
			}
			else{
				echo "<td>&nbsp;</td>";
			}
			print<<<HERE
<td align='center' valign='center'><span class='style15'><img src='img/button_edit.png'  onmouseover="this.style.cursor='pointer'" onclick=SetItem('$rows[0]') title=' Edit Record '  ></span></td>

<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]'); ></td>

HERE;
	}
else print<<<HERE

<td align=center >&nbsp;</td>

HERE;

	echo"<td align='left'><span class='$stylefont' >$rows[1]&nbsp;</span></font></td>
		 <td align='left'><font face='Arial' size='2' color='#186194'><span class='$stylefont'>$rows[2]&nbsp;</span></font></td>";
	echo"<td align='right'><font face='Arial' size='2' color='#186194'><span class='$stylefont'>$rows[3]&nbsp;</span></font></td>";
	echo"<td align='right'><font face='Arial' size='2' color='#186194'><span class='$stylefont'>$row[0]&nbsp;</span></font></td>";
	echo"<td ><font face='Arial' size='2' color='#186194'><span class='$stylefont'>$rows[4] &nbsp;</span></font></td>";
	echo"<td ><font face='Arial' size='2' color='#186194'><span class='$stylefont'>$rows[8] &nbsp;</span></font></td>";
	echo"<td ><font face='Arial' size='2' color='#186194'><span class='$stylefont'>$rows[9] &nbsp;</span></font></td>";
	echo"<td ><font face='Arial' size='2' color='#186194'><span class='$stylefont'>$rows[5] &nbsp;</span></font></td>";
	echo"<td ><font face='Arial' size='2' color='#186194'><span class='$stylefont'>$rows[6] &nbsp;</span></font></td>";
	echo"<td ><font face='Arial' size='2' color='#186194'><span class='$stylefont'>$rows[7] &nbsp;</span></font></td>";
	
	echo"	</tr>";
}		
	
echo"</table></div></td></tr>";

echo"<tr  ><td id='search-contentW' colspan='4'><table width=100% border='0'><tr><td width='120px' ><span class='style1'>&nbsp;<b>Total : $totalrows</b></td><td align='center'>";
		
		$diff= $startrange - $perpage;
		
		if (($diff) >= 0 ){
			$prvstartrange = $startrange - $perpage;
			echo"<img src='img/arrowleft.png' title='Previous' onMouseOver=\"style.cursor='hand'\"  onclick=SetPrvPage('".$prvstartrange."','".$perpage."')>";
		}
		else
			echo "&nbsp;";
		
		echo"</td><td  align='center' width='150px'>";
		
		
		if ($startrange <= $totalrows){
			$startrange = $startrange + $perpage;
			if  ($startrange <= $totalrows)
				echo"<img src='img/arrowright.png' title='Next' onMouseOver=\"style.cursor='hand'\" onclick=SetNextPage('".$startrange."','".$perpage."')>";
		} else
			echo "&nbsp;";
			
		echo"</td><td >&nbsp;</td></tr></table></td></tr>";

echo"<tr>
					<td id='search-bottomW' style='width:490px;height:20px;' colspan='8'></td>
				</tr></table></td></tr></table>";

$tabs->end();


$tabs->start("Others");

echo"<table border='0'  align='center' valign='top' width=100% bgcolor='#F7F7F7' height='25'><col width=160>";
	
echo"<tr><td  align='left' colspan=3>
	<table border=0><tr><td><span class='style1'>Code</span></td><td><input type='text' name='item_code2' value='$item_code2' readonly style='width:150px;'></td>
	<td><span class='style1'>Currency</span></td><td><input type='text' name='item_cur2' value='$item_cur2' readonly style='width:150px;'></td></tr>
	<tr><td><span class='style1'>Description</span></td><td colspan=3><input type='text' name='item_desc2' value='$item_desc2' readonly style='width:370px;'></td></tr>
	</table>
	</td></tr>";

echo"<tr><td  align='left' ><input type='hidden' name='reverse_production' value='$reverse_production'>
		<input value='reverse' type='radio' name='itemtype' onclick=Refreshpage2('reverse'); ";if($reverse_production==1 ) echo " checked ";echo" $statusdisabled>
		<span class='style1'>Reverse Production</span></td>
		
		<td  align='left' ><input type='hidden' name='nonstock_item' value='$nonstock_item'>
		<input type='checkbox' name='nonstock' onclick='set_nonstock()'; ";if($nonstock_item==1) echo " checked ";echo" $statusdisabled>
		<span class='style1'>Non Stock Item</span></td>	</tr>";
		
echo"<tr>		
<td  align='left' ><input type='hidden' name='item_production'  id='item_production' value='$item_production'>
		<input value='production' type='radio' name='itemtype' onclick=Refreshpage2('production'); ";if($item_production==1) echo " checked ";echo" $statusdisabled>
		<span class='style1'>Production</span></td><td align='left'>
		<input type='hidden' name='ttc_include' value='$ttc_include'>";
	echo"	<input type='checkbox' name='ttc_chk' onclick='set_ttc()'; $selectedttc $statusdisabled>
			<span class='style1'>TTC include</span></td>	</tr>";	

echo"<tr>	<td align='left'><input type='hidden' name='item_pack' value='$item_pack'>
		<input value='pack' type='radio' name='itemtype' onclick=Refreshpage2('pack'); ";if($item_pack==1) echo " checked ";echo" $statusdisabled>
		<span class='style1'>Pack</span></td>
		<td align='left'><input type='hidden' name='item_promotion' value='$item_promotion'>
		<input type='checkbox' name='promo_chk' onclick='set_promotion()'; ";if($item_promotion==1) echo " checked ";echo" $statusdisabled>
		<span class='style1'>Promotion</span></td></tr>";

echo"<tr>	
<td align='left'>
	<input type='hidden' name='item_withserialno' value='$item_withserialno'>
		<input type='checkbox' name='serial_chk' onclick='set_serial()'; ";if($item_withserialno==1) echo " checked ";echo" $statusdisabled>
	<span class='style1'>Item with serial no</span></td><td align='left' >
	<input type='hidden' name='EvaluateQtyUnit' value='$EvaluateQtyUnit'>
		<input type='checkbox' name='evaluate_chk' onclick='set_evaluate()'; ";if($EvaluateQtyUnit==1) echo " checked ";echo" $statusdisabled>
	<span class='style1'>Evaluate Qty Unit</span>
	</td></tr>";
	
	
echo"<tr>";

if($item_production==1){

	echo"<td align='left'>
		<input type='checkbox' name='finished_chk' onclick='set_finished()'; $selectedsemifinished $statusdisabled>
		<span class='style1'>Semi Finished</span></td>";
}
else {
	echo"<td>&nbsp;</td>";
}

	echo"<td align='left'><input type='hidden' name='item_print' value='$item_print'>
		<input type='checkbox' name='print_item' onclick='set_printitem()'; $selectedprintitem $statusdisabled>
		<span class='style1'>Print Item</span></td></tr>";	

echo"<tr height=40px>
<td  align='left'  colspan='2'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='style1'>AVERAGE Cost (0) , FIFO (1), LIFO(2)</span><br>
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input $statusdisabled type='radio' name='cost' value='0' ";
	
	if($cost==0)
		echo'checked';
	echo"><span class='style1'> 0  &nbsp;
			<input $statusdisabled type='radio' name='cost' value='1' ";
	if($cost==1)
		echo'checked';		
	echo"> 1 &nbsp;
			<input $statusdisabled type='radio' name='cost' value='2' ";
	if($cost==2)
		echo'checked';
	echo"> 2 &nbsp; </span></td></tr>";
	
echo"<tr>		
		<td align='center'><span class='style1'>Color&nbsp;<input type='text' name='item_color' value='$item_color' class='color' style='width:80px;'></span></td>
		<td><input type='file'  name='photo' id='photo' style='width:200px;' accept='image/jpeg,image/gif,image/png'>
			<input type='button' value='Upload' $style2 onclick='upload_picture()'>
			<input type='button' value='Picture' $style2 onclick='show_picture()'>
		</td>
	</tr>";
	
echo "<tr bgcolor='#F7F7F7' height=25px><td><span class='style1'><input type='button' value='BarCode 1' $style2 onclick='generatetextfile(1);'></span></td><td><input type=text name='item_barcode'  value='".htmlspecialchars($item_barcode, ENT_QUOTES)."' maxlength='20' size='20' >";


echo" <button type='button' id='generate' name='generate' onclick='generatebarcode2(); return false;' title='Generate Barcode 2'><span><span>Generate Barcode 2</span></span></button>
";

if($GeneratedLines=='') $GeneratedLines=1;
echo "</td><td>Quantity <input type='text' name='GeneratedLines' value='$GeneratedLines' maxlength='10'></tr>";


echo"<tr><td align='left'><span class='style1'><input type='button' value='BarCode 2' $style2 onclick='generatetextfile(2);'></span></td><td><input type=text name='item_barcode2'  value='".htmlspecialchars($item_barcode2, ENT_QUOTES)."' maxlength='20' size='20' >
";
echo "</td></tr><tr><td align='left'><span class='style1'><input type='button' value='BarCode 3' $style2 onclick='generatetextfile(3);'></span></td><td><input type=text name='item_barcode3'  value='".htmlspecialchars($item_barcode3, ENT_QUOTES)."' maxlength='20' size='20' ></td>
</tr>";

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

if($FI_SellingPriceInItems==1){
$tabs->start("Selling Price");

echo"<table border='0'  align='center' valign='top' width=100% >
	<col width=80>
	<col width=150>
	<col width=150>";
	
	echo"<tr><td  align='left' colspan=3>
	<table border=0><tr><td><span class='style1'>Code</span></td><td><input type='text' name='item_code3' value='$item_code3' readonly style='width:150px;'></td>
	<td><span class='style1'>Currency</span></td><td><input type='text' name='item_cur3' value='$item_cur3' readonly style='width:150px;'></td></tr>
	<tr><td><span class='style1'>Description</span></td><td colspan=3><input type='text' name='item_desc3' value='$item_desc3' readonly style='width:370px;'></td></tr>
	</table>
	</td></tr>";

	echo"<tr bgcolor='#F7F7F7'><td><span class='style1'>Transfer</span></td><td ><select name='transfer'><option value=''>&nbsp;</option>
			<option value='1'";if($transfer==1) echo " selected ";echo">I</option>
			<option value='2'";if($transfer==2) echo " selected ";echo">II</option>
			<option value='3'";if($transfer==3) echo " selected ";echo">III</option>
			<option value='4'";if($transfer==4) echo " selected ";echo">IV</option>
			<option value='5'";if($transfer==5) echo " selected ";echo">V</option>
			<option value='6'";if($transfer==6) echo " selected ";echo">VI</option></select></td><td align='left' colspan=2>
	<input type='hidden' name='Item_ModifySellingPrice' value='$Item_ModifySellingPrice'>
		<input type='checkbox' name='sel_chk' onclick='set_sel()'; ";if($Item_ModifySellingPrice==1) echo " checked ";echo" $statusdisabled>
	<span class='style1'>Modifying Selling Price (Retail)</span>
	
	
	</td></tr>";

	/*if($category_code!=''){
	
		$date=date('Y-m-d');
		$query="Select MeanCostCur('".$item_code."','".$date."','1','".$currency."','') from dual ";
		$result=mysql_query($query,$connection) or die(mysql_error());
		$row=mysql_fetch_row($result);
		$MeanCost=$row[0];
		
		//Get Last Cost
		if($lastcost==1){
			$subquery="select LastCost('".$item_code."','".$currency."')";
			$resultsub=mysql_query($subquery,$connection) ;	
			$rowsub=mysql_fetch_row($resultsub);
			$Cost=$rowsub[0];
		}
		else $Cost=$MeanCost;
		
		$query="select Category_Price1,Category_Price2,Category_Price3,Category_Price4,Category_Price5,Category_Price6 from category where category_code='".$category_code."'";
		$result=mysql_query($query,$connection) or die(mysql_error());
		while($row=mysql_fetch_row($result)){
			$sellingprice1=($Cost*$row[0])/100;
			$sellingprice1base1=ConvertCurrency($currency, $base1,$date, $sellingprice1, $connection);
			$sellingprice1base2=ConvertCurrency($currency, $base2,$date, $sellingprice1, $connection);
			$sellingprice1=number_format($sellingprice1, $DecimalBase);
			$sellingprice1base1=number_format($sellingprice1base1, $DecimalBase1);
			$sellingprice1base2=number_format($sellingprice1base2, $DecimalBase2);
			
			$sellingprice2=($Cost*$row[1])/100;
			$sellingprice2base1=ConvertCurrency($currency, $base1,$date, $sellingprice2, $connection);
			$sellingprice2base2=ConvertCurrency($currency, $base2,$date, $sellingprice2, $connection);
			$sellingprice2=number_format($sellingprice2, $DecimalBase);
			$sellingprice2base1=number_format($sellingprice2base1, $DecimalBase1);
			$sellingprice2base2=number_format($sellingprice2base2, $DecimalBase2);
			
			$sellingprice3=($Cost*$row[2])/100;
			$sellingprice3base1=ConvertCurrency($currency, $base1,$date, $sellingprice3, $connection);
			$sellingprice3base2=ConvertCurrency($currency, $base2,$date, $sellingprice3, $connection);
			$sellingprice3=number_format($sellingprice3, $DecimalBase);
			$sellingprice3base1=number_format($sellingprice3base1, $DecimalBase1);
			$sellingprice3base2=number_format($sellingprice3base2, $DecimalBase2);
			
			$sellingprice4=($Cost*$row[3])/100;
			$sellingprice4base1=ConvertCurrency($currency, $base1,$date, $sellingprice4, $connection);
			$sellingprice4base2=ConvertCurrency($currency, $base2,$date, $sellingprice4, $connection);
			$sellingprice4=number_format($sellingprice4, $DecimalBase);
			$sellingprice4base1=number_format($sellingprice4base1, $DecimalBase1);
			$sellingprice4base2=number_format($sellingprice4base2, $DecimalBase2);
			
			$sellingprice5=($Cost*$row[4])/100;
			$sellingprice5base1=ConvertCurrency($currency, $base1,$date, $sellingprice5, $connection);
			$sellingprice5base2=ConvertCurrency($currency, $base2,$date, $sellingprice5, $connection);
			$sellingprice5=number_format($sellingprice5, $DecimalBase);
			$sellingprice5base1=number_format($sellingprice5base1, $DecimalBase1);
			$sellingprice5base2=number_format($sellingprice5base2, $DecimalBase2);
			
			$sellingprice6=($Cost*$row[4])/100;
			$sellingprice6base1=ConvertCurrency($currency, $base1,$date, $sellingprice6, $connection);
			$sellingprice6base2=ConvertCurrency($currency, $base2,$date, $sellingprice6, $connection);
			$sellingprice6=number_format($sellingprice6, $DecimalBase);
			$sellingprice6base1=number_format($sellingprice6base1, $DecimalBase1);
			$sellingprice6base2=number_format($sellingprice6base2, $DecimalBase2);
			
		}
	}*/
	
	echo"<tr bgcolor='#F7F7F7'><td><span class='style1'>Category</td><td><input type='text' name='category_code' value='$category_code'  style='width:100px;height:20px;' readonly>";

	if($mainmode!='')
			echo"&nbsp;<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Category ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistcategory(); '  /></span></label>";
		else echo"&nbsp;";
		
	echo"</td><td>	<input type='text' name='category_name' value='$category_name'  style='width:250px;height:20px;'></td><td><input type='checkbox' name='last_cost' onclick='Chk_Last();' ";if($lastcost==1) echo " checked ";echo" $statusdisabled>
	<span class='style1'>Based on Last Cost</td></tr>";
		
	echo"<tr bgcolor='#F7F7F7'><td></td><td><b>Selling Price</b></td><td><b>Selling Price $base1</b></td>
			<td><b>Selling Price $base2</b></td></tr>";
			
	echo"<tr bgcolor='#F7F7F7'><td><span class='style1'>I</span></td><td><input type='text' name='sellingprice1' value='$sellingprice1' onchange='Setprices(1);'></td>
			<td><input type='text' name='sellingprice1base1' value='$sellingprice1base1' onchange='Setpricesbase(1,1);'></td>
			<td><input type='text' name='sellingprice1base2' value='$sellingprice1base2' onchange='Setpricesbase(2,1);'></td></tr>";
	
	echo"<tr bgcolor='#F7F7F7'><td><span class='style1'>II</span></td><td><input type='text' name='sellingprice2' value='$sellingprice2' onchange='Setprices(2);'></td>
			<td><input type='text' name='sellingprice2base1' value='$sellingprice2base1' onchange='Setpricesbase(1,2);'></td>
			<td><input type='text' name='sellingprice2base2' value='$sellingprice2base2' onchange='Setpricesbase(2,2);'></td></tr>";
	
	echo"<tr bgcolor='#F7F7F7'><td><span class='style1'>III</span></td><td><input type='text' name='sellingprice3' value='$sellingprice3' onchange='Setprices(3);'></td>
			<td><input type='text' name='sellingprice3base1' value='$sellingprice3base1' onchange='Setpricesbase(1,3);'></td>
			<td><input type='text' name='sellingprice3base2' value='$sellingprice3base2' onchange='Setpricesbase(2,3);'></td></tr>";
			
	echo"<tr bgcolor='#F7F7F7'><td><span class='style1'>IV</span></td><td><input type='text' name='sellingprice4' value='$sellingprice4' onchange='Setprices(4);'></td>
			<td><input type='text' name='sellingprice4base1' value='$sellingprice4base1' onchange='Setpricesbase(1,4);'></td>
			<td><input type='text' name='sellingprice4base2' value='$sellingprice4base2' onchange='Setpricesbase(2,4);'></td></tr>";		
			
	echo"<tr bgcolor='#F7F7F7'><td><span class='style1'>V</span></td><td><input type='text' name='sellingprice5' value='$sellingprice5' onchange='Setprices(5);'></td>
			<td><input type='text' name='sellingprice5base1' value='$sellingprice5base1' onchange='Setpricesbase(1,5);'></td>
			<td><input type='text' name='sellingprice5base2' value='$sellingprice5base2' onchange='Setpricesbase(2,5);'></td></tr>";

	echo"<tr bgcolor='#F7F7F7'><td><span class='style1'>VI</span></td><td><input type='text' name='sellingprice6' value='$sellingprice6' onchange='Setprices(6);'></td>
			<td><input type='text' name='sellingprice6base1' value='$sellingprice6base1' onchange='Setpricesbase(1,6);'></td>
			<td><input type='text' name='sellingprice6base2' value='$sellingprice6base2' onchange='Setpricesbase(2,6);'></td></tr>";
			
	echo"</table>";

$tabs->end();	
}

if ($HideMenu != 1) {
	$tabs->start("Attributes");


	echo"<table border='0'  align='left' valign='top'>
		<col width=30>
		<col width=30>
		<col width=300>";
		
		echo"<tr><td  align='left' colspan=3>
		<table border=0><tr><td><span class='style1'>Code</span></td><td><input type='text' name='item_code4' value='$item_code4' readonly style='width:150px;'></td>
		<td><span class='style1'>Currency</span></td><td><input type='text' name='item_cur4' value='$item_cur4' readonly style='width:150px;'></td></tr>
		<tr><td><span class='style1'>Description</span></td><td colspan=3><input type='text' name='item_desc4' value='$item_desc4' readonly style='width:370px;'></td></tr>
		</table>
		</td></tr>";

	echo"<tr ><td colspan=6><table  border='0'>
							<tr bgcolor='#D0D0D0' height='25px'><td colspan=2>&nbsp;&nbsp;</td>
							<td align='center'><span class='style1'>Attribute Code/Description<span class='style26'>*</span></span></td>
							
							<td align='center'><span class='style1'>Value<span class='style26'>*</span></span></span></td>
							<td align='center'><span class='style1'>Unit<span class='style26'>*</span></span></td>
							
	</tr>";

	echo"<tr><td align=center colspan=2>
	<button type='button' id='submitrecord' name='submitrecord' onclick='SaveChanges(2); return false;' title='Submit Record' $Insmode><span><span>Submit</span></span></button>";

	echo"		<button type='button' id='clearbutton' name='clearbutton' onclick='cleardetail(); return false;' title='Clear '><span><span>Clear </span></span></button>";

	echo"&nbsp;&nbsp;</td>
		<td>&nbsp;<input type='text' name='attribute_code' id='attribute_code' value='$attribute_code'  style='width:100px;height:20px;' maxlength=10>";

		if($mainmode!='')
				echo"&nbsp;<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Parameter ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistitemparam(); '  /></span></label>";
			else echo"&nbsp;";
			
	echo"&nbsp;<input type='text' name='attribute_desc' id='attribute_desc' value='$attribute_desc'  readonly style='width:180px;height:20px;'>";						
	echo"</td>
		<td>&nbsp;<input type='text' name='attribute_value' id='attribute_value' value='$attribute_value' $status  style='width:150px;height:18px;text-align:right;' maxlength='50'>&nbsp;</td>
		<td>&nbsp;<input type='text' name='attribute_unit' id='attribute_unit' value='$attribute_unit' $status maxlength='15' style='width:120px;height:18px;text-align:left;' readonly>&nbsp;</td>
	</tr>";

	$querydt = " select ItemDt_ID,itemsdt.ItemParam_Code,itemdt_value,unit_code,ItemParam_Name ".
			   " from itemsdt ".
			   " left join itemsparam on itemsparam.ItemParam_Code=itemsdt.ItemParam_Code ".
			   
			   " where Item_Code='".$item_code."'";


	$resultdt = mysql_query($querydt, $connection) or die(mysql_error());
	while($rowsdt=mysql_fetch_row($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='left'><span class='style15'>".$rowsdt[1].'   '.$rowsdt[4]."</span></td>";
		echo "	<td align='right'><span class='style15'>".$rowsdt[2]."</span></td>";
		echo "	<td align='left'><span class='style15'>".$rowsdt[3]."</span></td>";
		echo "</tr>";
							
	}					

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

if($item_pack==1 or $item_production==1){
	$tabs->start("Pack");

	echo"<table border='0'  align='left' valign='top'>";
echo"<tr><td  align='left' colspan=3>
	<table border=0>
	<tr>
		<td><span class='style1'>Code</span></td>
		<td><input type='text' name='item_code5' value='$item_code5' readonly style='width:150px;'></td>
		<td><span class='style1'>Currency</span></td>
		<td><input type='text' name='item_cur5' value='$item_cur5' readonly style='width:150px;'></td>
		<td><span class='style1'>Qty To Be Produced</span></td>
		<td><input type='text' name='Item_QtyToBeProduced' value='$Item_QtyToBeProduced' style='width:70px;'></td>
	</tr>
	<tr><td><span class='style1'>Description</span></td><td colspan=5><input type='text' name='item_desc5' value='$item_desc5' readonly style='width:370px;'></td></tr>
	</table>
	</td></tr>";
	echo"<tr ><td ><table  border='0'><col width=150><col width=150><col width=80>";
	
	echo"<tr bgcolor='#f7f7f7'>
			<td align='left'><span class='style1'>Group Code/Name</span></td>
			<td colspan=6><input type='text' name='item_packgroupcode' value='$item_packgroupcode'  style='width:100px;height:20px;' maxlength=15>";

			if($mainmode!='') echo"&nbsp;<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Group ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistgroups(5); '  /></span></label>";
			else echo"&nbsp;";
			
	echo"&nbsp;<input type='text' name='item_packgroupname' value='$item_packgroupname'  readonly style='width:250px;height:20px;'></td></tr>";
	
	echo"<tr bgcolor='#f7f7f7' height='25px'>
				<td align='left'><span class='style1'>Item Code/Description<span class='style26'>*</span></span></td>
				<td colspan=4><input type='text' name='item_packcode' id='item_packcode' value='$item_packcode'  style='width:100px;height:20px;' maxlength=10>";

				if($mainmode!='') echo"&nbsp;<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Item Pack ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistitem(3); '  /></span></label>";
				else echo"&nbsp;";
			
	echo"&nbsp;<input type='text' name='item_packdesc' value='$item_packdesc'  readonly style='width:250px;height:20px;'></td>";
							
							/*<td align='center'><span class='style1'>Warehouse<span class='style26'>*</span></span></span></td>
							<td align='center'><span class='style1'>Quantity<span class='style26'>*</span></span></td>
							<td align='center'><span class='style1'>Cost %<span class='style26'>*</span></span></td>
							<td align='center'><span class='style1'>Pre Cost %<span class='style26'>*</span></span></td>*/
							
	echo"<td align=center colspan=2>";
	//echo"	<button type='button' id='submitrecord' name='submitrecord' onclick='SaveChanges(4); return false;' title='Copy Recepies' $Insmode><span><span>Copy Recepies</span></span></button>";
	echo"&nbsp;&nbsp;</td></tr>";

	
	echo"<tr bgcolor='#f7f7f7'>";
					
	echo"
		<Td><span class='style1'>Warehouse</td><td colspan=6><input type='text' name='item_warehousecode' id='item_warehousecode' value='$item_warehousecode'  style='width:100px;height:20px;' maxlength=10>";

		if($mainmode!='')
				echo"&nbsp;<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Warehouse ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistwarehouse(3); '  /></span></label>";
			else echo"&nbsp;";
			
	echo"&nbsp;<input type='text' name='item_warehousedesc' value='$item_warehousedesc'  readonly style='width:250px;height:20px;'></td></tr>
	<tr bgcolor='#f7f7f7'><td ><span class='style1'>Qty</td><td colspan=6><input type='text' name='item_packqty' value='$item_packqty' $status maxlength='15' style='width:120px;height:18px;text-align:right;' >&nbsp;</td></tr>
	<tr bgcolor='#f7f7f7'><td><span class='style1'>Cost %</td><td colspan=6><input type='text' name='item_packcost' value='$item_packcost' $status maxlength='15' style='width:120px;height:18px;text-align:right;' >&nbsp;</td></tr>
	<!--<tr bgcolor='#f7f7f7'><td><span class='style1'>Barcode</td><td colspan=6>&nbsp;</td></tr>-->
	<input type='hidden' name='item_packbarcode' value='$item_packbarcode' $status maxlength='20' style='width:120px;height:18px;text-align:right;' >
	<tr bgcolor='#f7f7f7'><td><span class='style1'>From Date</td><td><input type='text' name='item_packfromdate' value='$item_packfromdate' readonly maxlength='15'  style='width:120px;'>";
	
	if($mainmode!='view' && $mainmode!=''){
		
print<<< HERE
&nbsp;<A HREF="#" onClick="displayCalendar(document.items.item_packfromdate,'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><span class='style1'>To Date</td><td ><input type='text' name='item_packtodate' value='$item_packtodate' readonly maxlength='15'  style='width:120px;'>";
	
	if($mainmode!='view' && $mainmode!=''){
		
print<<< HERE
&nbsp;<A HREF="#" onClick="displayCalendar(document.items.item_packtodate,'dd-mm-yyyy',this); return false;" NAME="anchor1" ID="anchor1"><image src='./img/cal.gif' border=0 align=center></image></A>
HERE;
}	
	echo"</td><td colspan=3>&nbsp;</td></tr><tr bgcolor='#f7f7f7'><td ><span class='style1'>Promotion Qty</td><td colspan=4><input type='text' name='item_promoqty' value='$item_promoqty' $status maxlength='15' style='width:120px;height:18px;text-align:right;' >&nbsp;</td>";
	echo"<td align=center colspan=2>
<button type='button' id='submitrecord' name='submitrecord' onclick='SaveChanges(5); return false;' title='Submit Record' $Insmode><span><span>Submit</span></span></button>	
<button type='button' id='clearbutton' name='clearbutton' onclick='cleardetailpack(); return false;' title='Clear Detail' $Insmode><span><span>Clear</span></span></button>";	

echo"&nbsp;&nbsp;</td>";
	echo"</tr></table></td></tr>";
	
	echo"<tr ><td align='left' colspan=7><table border=0><col width=30><col width=30><col width=350><col width=150><col width=100>
	<tr bgcolor='#D0D0D0'>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
		<td><span class='style1'>Item Code/Description</span></td>
		<td align='center'><span class='style1'>Warehouse</span></td>
		<td align='center'><span class='style1'>Group</span></td>
		<td align='center'><span class='style1'>Quantity</span></td>
		<td align='center'><span class='style1'>Cost %</span></td>
		<td align='center'><span class='style1'>Barcode</span></td>
		<td align='center'><span class='style1'>From Date</span></td>
		<td align='center'><span class='style1'>To Date</span></td>
		<td align='center'><span class='style1'>Promotion Qty</span></td></tr>";

			
	$querydt = " select Item_CodePackDt,item_description,packdt.Warehouse_Code,warehouse.warehouse_name,PackDt_Quantity,PackDt_CostPercentage,date_format(PackDt_FromDate,'%d/%m/%Y'),date_format(PackDt_ToDate,'%d/%m/%Y'),Packdt_PromoQty,BARCODE, packdt.group_code ".
			   " from packdt ".
			   " left join items on items.item_code=packdt.Item_CodePackDt ".
			   " left join warehouse on warehouse.warehouse_code=packdt.Warehouse_Code ".
			   " where packdt.Item_Code='".$item_code."'";


	$resultdt = mysql_query($querydt, $connection) or die(mysql_error());
	while($rowsdt=mysql_fetch_row($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=\"UpdateDetailPack('".$rowsdt[0]."','".$rowsdt[2]."');\" 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=\"DeleteDetailPack('".$rowsdt[0]."','".$rowsdt[2]."');\" title='Delete Record'  ></span></td>";
		echo "	<td align='left' ><span class='style15'>".$rowsdt[0]." - ".$rowsdt[1]."&nbsp;&nbsp;&nbsp;</span></td>";
		echo "	<td align='left'><span class='style15'>".$rowsdt[2]." - ".$rowsdt[3]."&nbsp;&nbsp;&nbsp;</span></td>";
		echo "	<td align='right'><span class='style15'>".$rowsdt[10]."</span></td>";
		echo "	<td align='right'><span class='style15'>".$rowsdt[4]."</span></td>";
		echo "	<td align='right'><span class='style15'>".$rowsdt[5]."</span></td>";
		echo "	<td align='left'><span class='style15'>".$rowsdt[9]."</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='right'><span class='style15'>".$rowsdt[8]."</span></td>";
		
		echo "</tr>";
							
	}					

	echo"</table></td></tr></table>";

			  
	$tabs->end(); 
}

if ($HideMenu != 1) {

	$tabs->start("Manufactured Code");

	echo"<table border='0'  align='left' valign='top'>
		<col width=30>
		<col width=30>
		<col width=300>";
	echo"<tr><td  align='left' colspan=3>
		<table border=0><tr><td><span class='style1'>Code</span></td><td><input type='text' name='item_code6' value='$item_code6' readonly style='width:150px;'></td>
		<td><span class='style1'>Currency</span></td><td><input type='text' name='item_cur6' value='$item_cur6' readonly style='width:150px;'></td></tr>
		<tr><td><span class='style1'>Description</span></td><td colspan=3><input type='text' name='item_desc6' value='$item_desc6' readonly style='width:370px;'></td></tr>
		</table>
		</td></tr>";
	echo"<tr ><td colspan=6><table  border='0'>
							<tr bgcolor='#D0D0D0' height='25px'><td colspan=2>&nbsp;&nbsp;</td>
							<td align='center'><span class='style1'> Code<span class='style26'>*</span></span></td>
							<td align='center'><span class='style1'>Description<span class='style26'>*</span></span></span></td>						
	</tr>";

	echo"<tr><td align=center colspan=2><button type='button' id='submitrecord' name='submitrecord' onclick='SaveChanges(3); return false;' title='Submit Record' $Insmode><span><span>Submit</span></span></button>	
	<button type='button' id='clearbutton' name='clearbutton' onclick='cleardetailmanu(); return false;' title='Clear Detail' $Insmode><span><span>Clear</span></span></button>";

	echo"&nbsp;&nbsp;</td>
		<td>&nbsp;<input type='text' name='manufacture_code' id='manufacture_code' value='$manufacture_code'  style='width:100px;height:20px;' maxlength=10>
		<input type='hidden' name='manufacture_codePrv' value='$manufacture_codePrv'  style='width:100px;height:20px;' maxlength=10>";

			
	echo"</td><td><input type='text' name='manufacture_desc' id='manufacture_desc' value='$manufacture_desc'   style='width:250px;height:20px;'  maxlength=60>";						
	echo"</td>
		
	</tr>";

	$querydt = " select Item_ManufactureCode,Item_ManufactureDesc ".
			   " from itemmanufacture ".
			   
			   " where Item_Code='".$item_code."'";


	$resultdt = mysql_query($querydt, $connection) or die(mysql_error());
	while($rowsdt=mysql_fetch_row($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=\"UpdateDetailManufacture('".$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=\"DeleteDetailManufacture('".$rowsdt[0]."');\" title='Delete Record'  ></span></td>";
		echo "	<td align='left'><span class='style15'>".$rowsdt[0]."</span></td>";
		echo "	<td align='left'><span class='style15'>".$rowsdt[1]."</span></td>";

		echo "</tr>";
							
	}					

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

if($FI_CostPriceInItems==1 && $HideMenu != 1){
$tabs->start("Cost Price");

echo"<table border='0'  align='center' valign='top' width=100% >
	<col width=100>
	<col width=100>
	<col width=130>
	<col width=140>
	<col width=130>
	<col width=130>
	<col width=100>
	<col width=130>
	<col width=130>";
	
	echo"<tr><td  align='left' colspan=25>
	<table border=0><tr><td><span class='style1'>Code</span></td><td><input type='text' name='item_code7' value='$item_code7' readonly style='width:150px;'></td>
	<td><span class='style1'>Currency</span></td><td><input type='text' name='item_cur7' value='$item_cur7' readonly style='width:150px;'></td></tr>
	<tr><td><span class='style1'>Description</span></td><td colspan=3><input type='text' name='item_desc7' value='$item_desc7' readonly style='width:370px;'></td></tr>
	</table>
	</td></tr>";
	
	echo"<tr bgcolor='#f0f0f0'><td align='center'>
	 <div style='overflow:scroll;height:390px;width:1080px;border:0px solid #000000;' ><table  style='width:1100px;' >
	<tr><td> <span class='style1'>Reference</span></td><td align='center'><span class='style1'>Date</span></td>
	<td align='center'><span class='style1'>Supplier Code</span></td>
	<td align='center'><span class='style1'>Supplier Name</span></td>
	<td align='center'><span class='style1'>Currency</span></td>
	<td align='center'><span class='style1'>Cost</span></td>
	<td align='center'><span class='style1'>$base1</span></td>
	<td align='center'><span class='style1'>$base2</span></td><td align='center'><span class='style1'>Warehouse</span></td>
	<td align='center'><span class='style1'>Quantity</span></td>
	<td align='center'><span class='style1'>Quantity Return</span></td>
	<td align='center'><span class='style1'>Charges $base1</span></td>
	<td align='center'><span class='style1'>Charges R $base1</span></td>
	<td align='center'><span class='style1'>Charges $base2</span></td>
	<td align='center'><span class='style1'>Charges R $base2</span></td>
	<td align='center'><span class='style1'>Charges per unit $base2</span></td>
	<td align='center'><span class='style1'>Charges per unit $base1</span></td>
	<td align='center'><span class='style1'>Expiry Date</span></td>
	<td align='center'><span class='style1'>Discount %</span></td>
	<td align='center'><span class='style1'>Price</span></td>
	<td align='center'><span class='style1'>Price $base1</span></td>
	<td align='center'><span class='style1'>Price $base2</span></td>
	<td align='center'><span class='style1'>Discount</span></td>
	<td align='center'><span class='style1'>Discount $base1</span></td>
	<td align='center'><span class='style1'>Discount $base2</span></td>
	</tr>";
	
	
	if($item_code!=''){
		
		
		$subquery="select Purchase_Reference,date_format(purchasesdt.Purchase_Date,'%d/%m/%Y'),purchasesdt.Supplier_code,suppliers.ledger_name,purchasesdt.Currency_Code,".
					" (PurchaseDt_Quantity*(PurchaseDt_Price/PurchaseDt_Quantity)*(1-PurchaseDt_DiscountPer))-PurchaseDt_DiscountAmount+PurchaseDt_Charges,Warehouse_Code,PurchaseDt_Quantity, ".
					" PurchaseDt_QuantityReturn,PurchaseDt_ChargesBase1,PurchaseDt_ChargesBase1R,PurchaseDt_ChargesBase2,PurchaseDt_ChargesBase2R,PurchaseDt_ChargesBase1/PurchaseDt_Quantity, ".
					" PurchaseDt_ChargesBase2/PurchaseDt_Quantity,date_format(PurchaseDt_ExpireDate,'%d/%m/%Y'),PurchaseDt_DiscountPer,PurchaseDt_Price,PurchaseDt_PriceBase1,PurchaseDt_PriceBase2, ".
					" PurchaseDt_DiscountAmount,PurchaseDt_DiscountBase1,PurchaseDt_DiscountBase2,purchasesdt.Purchase_Date ".
					" from purchasesdt ".
					" inner join purchases on purchases.purchase_id=purchasesdt.purchase_id ".
					" inner join suppliers on suppliers.ledger_number=purchasesdt.Supplier_code ".
					" where item_code='".$item_code."' and purchases.journal_type='PI' order by purchasesdt.Purchase_Date desc";
					
		$resultsub=mysql_query($subquery,$connection) ;	
		//echo$subquery;
		while($rowsub=mysql_fetch_row($resultsub)){
		$ct+=1;
		if($ct%2==0)
			$Color="style='background-color:".$grid_color1."'";
		else			
			$Color="style='background-color:".$grid_color2."'";	
		
		echo'<tr '.$Color.' height="20px" >';
		echo"<td align='center'>$rowsub[0]</td>";
		echo"<td align='center'>$rowsub[1]</td>";
		echo"<td align='left'>$rowsub[2]</td>";
		echo"<td align='left'>$rowsub[3]</td>";
		echo"<td align='center'>$rowsub[4]</td>";
		echo"<td align='right'>".number_format($rowsub[5], $DecimalBase)."</td>";
		
		$costbase1=ConvertCurrency($rowsub[4], $base1, $rowsub[23], $rowsub[5], $connection);
		echo"<td align='right'>".number_format($costbase1, $DecimalBase1)."</td>";
		
		$costbase2=ConvertCurrency($rowsub[4], $base2, $rowsub[23], $rowsub[5], $connection);
		echo"<td align='right'>".number_format($costbase2, $DecimalBase2)."</td>";
		
		echo"<td align='left'>$rowsub[6]</td>";
		echo"<td align='right'>$rowsub[7]</td>";
		echo"<td align='right'>$rowsub[8]</td>";
		echo"<td align='right'>$rowsub[9]</td>";
		echo"<td align='right'>$rowsub[10]</td>";
		echo"<td align='right'>$rowsub[11]</td>";
		echo"<td align='right'>$rowsub[12]</td>";
		echo"<td align='right'>$rowsub[14]</td>";
		echo"<td align='right'>$rowsub[13]</td>";
		echo"<td align='right'>$rowsub[15]</td>";
		echo"<td align='right'>$rowsub[16]</td>";
		echo"<td align='right'>".number_format($rowsub[17], $DecimalBase)."</td>";
		echo"<td align='right'>".number_format($rowsub[18], $DecimalBase1)."</td>";
		echo"<td align='right'>".number_format($rowsub[19], $DecimalBase2)."</td>";
		echo"<td align='right'>$rowsub[20]</td>";
		echo"<td align='right'>$rowsub[21]</td>";
		echo"<td align='right'>$rowsub[22]</td>";
		echo"</tr>";
		
		}
		
	}
	echo"</table></div></td></tr></table>";

	$tabs->end();	
}

if ($HideMenu != 1) {
	$tabs->start("Warehouse");

	echo"<table border='0'  align='center' valign='top' width=100% >
		<col width=100>
		<col width=100>
		<col width=130>
		<col width=140>
		<col width=130>
		<col width=130>
		<col width=100>
		<col width=130>
		<col width=130>";
		
		echo"<tr><td  align='left' colspan=3>
		<table border=0><tr><td><span class='style1'>Code</span></td><td><input type='text' name='item_code8' value='$item_code8' readonly style='width:150px;'></td>
		<td><span class='style1'>Currency</span></td><td><input type='text' name='item_cur8' value='$item_cur8' readonly style='width:150px;'></td></tr>
		<tr><td><span class='style1'>Description</span></td><td colspan=3><input type='text' name='item_desc8' value='$item_desc8' readonly style='width:370px;'></td></tr>
		</table>
		</td></tr>";
		
		echo"<tr bgcolor='#f0f0f0'><td align='center'><span class='style1'>Warehouse Code</span></td><td align='center'><span class='style1'>Qty Exist</span></td>
		<td align='center'><span class='style1'>Quantity Produce in</span></td>
		<td align='center'><span class='style1'>Quantity Produce Out</span></td><td align='center'><span class='style1'>Quantity Entered</span></td>
		<td align='center'><span class='style1'>Quantity Delivered</span></td><td align='center'><span class='style1'>Quantity Sold</span></td>
		<td align='center'><span class='style1'>Quantity P Ordered</span></td><td align='center'><span class='style1'>Quantity S Ordered</span></td>
		<td align='center'><span class='style1'>Quantity Available</span></td></tr>";
		
		
		if($item_code!=''){
			//fbegin();
			$subquery="call ItemsPerWarehouseView('".$item_code."','%%',now(),0,0,0,0)   ";
			//echo$subquery;
			$resultsub=mysql_query($subquery,$connection1) ;
			
			while($rowsub=mysql_fetch_row($resultsub)){
				$ct+=1;
				if($ct%2==0)
					$Color="style='background-color:".$grid_color1."'";
				else			
					$Color="style='background-color:".$grid_color2."'";	
				
				echo'<tr '.$Color.' height="20px" >';
				echo"<td align='left'>$rowsub[0]</td>";
				echo"<td align='right'>$rowsub[1]</td>";
				echo"<td align='right'>$rowsub[2]</td>";
				echo"<td align='right'>$rowsub[3]</td>";
				echo"<td align='right'>$rowsub[4]</td>";
				echo"<td align='right'>$rowsub[5]</td>";
				echo"<td align='right'>$rowsub[6]</td>";
				echo"<td align='right'>$rowsub[7]</td>";
				echo"<td align='right'>$rowsub[8]</td>";
				echo"<td align='right'>$rowsub[9]</td>";
				echo"</tr>";
			
			}
			//fcommit();
		}
		echo"</table>";

	$tabs->end();	
}

if ($HideMenu != 1) {
	//Items Rebate
	$tabs->start("Item Rebate");
	echo"<table border='0'  align='left' valign='top'>";
		
	echo"<tr><td align='left'>
			<table border=0>
			<tr>
				<td><span class='style1'>Code</span></td>
				<td><input type='text' name='item_code9' value='$item_code9' readonly style='width:150px;'></td>
				<td><span class='style1'>Currency</span></td>
				<td><input type='text' name='item_cur9' value='$item_cur9' readonly style='width:150px;'></td>
			</tr>
			<tr>
				<td><span class='style1'>Description</span></td>
				<td colspan=3><input type='text' name='item_desc9' value='$item_desc9' readonly style='width:370px;'></td>
			</tr>
			</table>
		</td></tr>";

	echo"<tr ><td align='left'>
			<table border='0'>
			<col width=20>
			<col width=20>
			<col width=100>
			<col width=100>
			<col width=100>
			<col width=150>
			<tr bgcolor='#D0D0D0' height='25px'>
				<td align='center'><span class='style1'>&nbsp;</span></td>
				<td align='center'><span class='style1'>&nbsp;</span></td>
				<td align='center'><span class='style1'>Range From<span class='style26'>*</span></span></td>
				<td align='center'><span class='style1'>Range To<span class='style26'>*</span></span></span></td>
				<td align='center'><span class='style1'>Rebate (%)<span class='style26'>*</span></span></td>
				<td align='center'><span class='style1'>&nbsp;</span></td>
			</tr>";

	echo"	<tr>
				<td align='center'><span class='style1'>&nbsp;</span></td>
				<td align='center'><span class='style1'>&nbsp;</span></td>
				<td><input type='text' name='rebate_rangefrom' id='rebate_rangefrom' value='$rebate_rangefrom'  style='width:100px;text-align:right;' maxlength=10>
					<input type='hidden' name='rebate_id' value='$rebate_id' >
				</td>
				<td><input type='text' name='rebate_rangeto' id='rebate_rangeto' value='$rebate_rangeto'   style='width:100px;text-align:right;' maxlength='10'></td>
				<td><input type='text' name='rebate_per' id='rebate_per' value='$rebate_per'  style='width:100px;text-align:right;' maxlength='10'></td>
				<td align=center>
					<button type='button' id='submitrecord' name='submitrecord' onclick='SaveChanges(6); return false;' title='Submit Record' $Insmode><span><span>Submit</span></span></button>
					<button type='button' id='clearbutton' name='clearbutton' onclick='cleardetailrebate(); return false;' title='Clear '><span><span>Clear </span></span></button>
				</td>
			</tr>";

	$queryrebate = " select ItemRebate_Id, ItemRebate_RangeFrom, ItemRebate_RangeTo, ItemRebate_Per ".
				   " from itemsrebate ".
				   " where Item_Code='".$item_code."'";
	//echo $connection; exit;
	$resultrebate = mysql_query($queryrebate, $connection) or die(mysql_error());
	while($rowsrebate=mysql_fetch_array($resultrebate)){
		
		$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=\"UpdateDetailRebate('".$rowsrebate[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=\"DeleteDetailRebate('".$rowsrebate[0]."');\" title='Delete Record'  ></span></td>";
		echo "	<td align='right'><span class='style15'>".$rowsrebate[1]."</span></td>";
		echo "	<td align='right'><span class='style15'>".$rowsrebate[2]."</span></td>";
		echo "	<td align='right'><span class='style15'>".$rowsrebate[3]."</span></td>";
		echo"	<td align='center' colspan='2'><span class='style1'>&nbsp;</span></td>";
		echo "</tr>";
							
	}

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

$tabs->run();

echo"</td></tr>";
	 echo" <tr height='30'><td align='center' id='content-bottom' ></td></tr>";
	include("footer.php");	
	echo"</table>";
	
	// Buttons
	/*echo"<tr><td valign='top' align='center' colspan='11'>";
	echo "<table  border=0 width='100%'>";
	echo"<tr bgcolor='#D8D8D8' height='30'><td  align='center'>";
	
	//Accounting map
	echo"<input name='accountingmap' type='button'  value='Accounting Map'";
	if($mainmode=='')
		echo " disabled";
	 echo"  onclick='openmap()' $style2 title='Accounting Map' ";
	echo " />&nbsp;";
	
	/// Inventory
	echo"<input name='Inventory' type='button'  value='Inventory'";
	if($mainmode=='')
		echo " disabled";
	 echo" onclick='openinventory()' $style2 title='Inventory' ";
	echo " />&nbsp;----&nbsp;";
	
	
	echo"<input name='warehousebutton' type='button'  value='Warehouse Quantity'";
	if($mainmode=='' )
		echo " disabled";
	 echo" onclick='Insertitemsdetails();' $style title='Warehouse Quantity' ";
	echo " />&nbsp; ";

		echo"<input name='Barcodes' type='button'  value='Barcodes'";
	if($mainmode=='')
		echo " disabled";
	 echo" onclick='openbarcode()' $style title='Barcodes' ";
	echo " />&nbsp;";
	echo"</tr></table></td></tr>";*/
	
	
	
	
	/*echo"<tr><td valign='top' colspan='11'>";
	echo "<table  border=0 width='100%'>";
	echo"<tr bgcolor='#D8D8D8' height='30'><td  align='center'>";


		echo"<input type='button'  value='Add Item'"; 
		
		if($mainmode=='insert' or $mainmode=='edit')
			echo "disabled ";
				
		echo"onclick='Additem()' $style title='Add Item' '".$AddMode."'>" ;
		echo" <input type='button'  name='Clearbutton' value='Clear Page'   onclick='ClearPage();' $style title='Clear Page'>";

	echo" <input type='button' name='savebutton' value='Save' ";//post

	if($mainmode=='')
		echo " disabled";
	echo" onclick='SaveChanges();' $style	title='Save Changes' />&nbsp;";
	
	
 
	/*echo"<input name='searchbutton' type='button'  value='Search'";
	if($mainmode!='')
		echo " disabled";
	 echo" onclick='Searchitems();' $style title='Search' ";
	echo " />&nbsp;";
	echo"</td>
	</tr></table></td></tr>";*/
	

	
	//include("toolbar.php");
	
	if($checkduplicate=='1'){
		$query_testcode="select count(*) from items where item_code='".$item_code."'";
		
		if($mainmode=='edit')
			$query_testcode=$query_testcode. " and item_id<>'".$item_id."'";
			
		$result_testcode=mysql_query($query_testcode, $connection);
		$row_code=mysql_fetch_row($result_testcode);
		$num=$row_code[0];

		if($num>0){
			$message="Code Already exists";
			
			echo"<script type='text/javascript'>";
			echo"	document.items.message.value='Code Already Exists';";
			echo"	document.items.checkduplicate.value='0';";
			echo"	document.items.submit();";	
			echo"</script>";
		}
		
		else{
			echo"<script type='text/javascript'>";
			echo"	document.items.action='Form_Items_Actions.php';";
			echo"	document.items.submit();";
			echo"</script>";
		}
	
	}
	
	if($setcode=='1'){
	
		echo"<script type='text/javascript'>";
		echo"var max=document.items.numrow.value;";
		echo"document.items.item_code.value='';";
		echo"document.items.item_description.value='';";
		echo"for(i=1;i<=max;i++){
				var attr=document.items['attr_value'+i].value;
				var attrname=document.items['attr_valuename'+i].value;
				var code=document.items.item_code.value;
				var desc=document.items.item_description.value;
				var skip;
				
				if(attr!='' && skip!='1'){
					skip=1;
					code=code+attr;
					desc=desc+attrname;
				}
				else if(attr!='' && skip=='1'){
					code=code+'-'+attr;	
					desc=desc+' '+attrname;
				}	
				document.items.item_code.value=code;
				document.items.item_description.value=desc;
			}";
		echo"</script>";
	}
	
	if($item_attribute=='1'){
		echo"<script type='text/javascript'>";
		echo"	window.open('List_Items_Attributes_Wizard.php','itempicture','screenX=0,screenY=0,status=no,menubar=no,scrollbars=yes,resizable=yes,width=775,height=450,top=100,left=0');";
		echo"document.items.item_attribute.value=0;";
		echo"</script>";
	}
	
	if($item_attribute=='2'){
		echo"<script type='text/javascript'>";
		echo"document.items.item_code.focus();";
		echo"document.items.item_attribute.value=0;";
		echo"</script>";
	}
	

	echo"</body></html>";


mysql_close($connection);
	
function fbegin()
{
	mysql_query("START TRANSACTION");
}
function fcommit(){
	mysql_query("COMMIT");
}
function frollback()
{
	mysql_query("ROLLBACK");
}	

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

function ConvertCurrency($FromCurr, $ToCurr, $FromDate, $Amount, $connection)
{
	$query = "SELECT ifNull(convertcurfunc('".$FromCurr."', '".$ToCurr."', '".$FromDate."', 0, 0, '', '', ifNull($Amount,0)),0) From Dual ";
	$result = selectData($connection, $query);
	//echo $query;
	Return	$result[0];

}
function selectData($conn, $query){
	$result = mysql_query($query, $conn);
	$cur = mysql_fetch_row($result);		
	return $cur;
}

function explodeword($date)
{
	$trim = explode('-',$date);
	$trim = substr($trim[2],0,2) . "/" . "$trim[1]" . "/" . "$trim[0]";
	return $trim;
}
?>

