<?php $PageSecurity = 4;
global  $db;
include('includes/session.inc');
include('includes/SQL_CommonFunctions.inc');
include('includes/function_lib.php');
include('includes/stockcalculation.php');
?>

<link href="css/professional/default.css" rel="stylesheet" type="text/css" />
<h2 align="center">Upload Boxes</h2>
<br />
<p align="left">
<input type="button" onclick="addRow('dataTable')" value="Add More" class="search"/>&nbsp;
<input type="button" class="search"   onclick="deleteRowOrder('dataTable')" value="Delete Rows"/>
</p>
<form name="form1" action="" method="post">
<div style="overflow: scroll; height: 300px" id="ItemListDiv">
<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
  <tr>
    <td class="tabledata1" colspan="3"><h3 style="color:#000000; font-size:16px;"><strong>Goods Received Note (GRN) Boxes Details</strong></h3></td>
	 <td class="tabledata1">
	 	<input type="text" name="hiditemcountrow" id="hiditemcountrow" value="1" readonly="true" />
	 </td>
	 <td class="tabledata1"><input type="button" name="import" value="Import Boxes" /></td>
  </tr>
  <tr>
  	<td class="tabledata">Select</td>
    <td class="tabledata">Package No.</td>
	<td class="tabledata">No. of Packages</td>
    <td class="tabledata">Content</td>
    <td class="tabledata">Layout</td>
  </tr>
   <tbody id="dataTable">
  <tr>
  	<td class="tabledata"><input name="delitem[]" type="checkbox"  id="delitem" /></td>
	<td class="tabledata"><input type="text" name="package_no[]" id="package_no" /></td>
	<td class="tabledata"><input type="text" name="no_of_package[]" id="no_of_package" style="width:100%"></td>
	<td class="tabledata"><input type="text" name="content[]" id="content" style="width:100%"></td>
	<td class="tabledata"><input type="text" name="layout[]" id="layout" style="width:100%"></td>
  </tr>
   </tbody>
</table>
<input type="hidden" name="hiditemcount" id="hiditemcount" value="" />
<input type="hidden" name="" value="" id="edit_cnt" />
<br />
</div>
</form>
<script language="javascript" type="text/javascript">
function addRow(tableID) 
{
	if(document)
		var table = document.getElementById(tableID);
		var rowCount = table.rows.length;
		var row = table.insertRow(rowCount);
		document.getElementById("hiditemcount").value=rowCount;
		document.getElementById("hiditemcountrow").value=rowCount+1;
		var colCount = table.rows[0].cells.length;
		for(var i=0; i<colCount; i++) {	 
            
			var newcell = row.insertCell(i);
           	//newcell.style.background='#e7e7e7';
			  newcell.className='tabledata';
			   newcell.innerHTML = table.rows[0].cells[i].innerHTML;
			   if(newcell.childNodes[0].id=='psize' && newcell.childNodes[0].type=='hidden'){
						newcell.childNodes[0].type='text';
					}
			   	switch(newcell.childNodes[0].type) 
				{
				case "text":
					newcell.childNodes[0].value = "";
					var nod_id = newcell.childNodes[0].id;

					newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
					
					
				break;

				case "hidden":

					newcell.childNodes[0].value = "";

					var nod_id_hidden = newcell.childNodes[0].id;

					newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;

				break;

				case "button":

					var nod_id = newcell.childNodes[0].id;

					newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;

				break;

				case "checkbox":

				newcell.childNodes[0].checked = false;
				var nod_id_chk = newcell.childNodes[0].id;
				newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
				

				break;

				case "select-one":
				newcell.childNodes[0].selectedIndex = 0;
				var nod_id = newcell.childNodes[0].id;
				newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
				break;	
			}
		}
	}
function deleteRowOrder(tableID) 
{
		try 
		{
			var table = document.getElementById(tableID);
			//alert(table);
			var rowCount = table.rows.length;
			//alert(rowCount);
			for(var i=0; i<rowCount; i++) 
				{
					var row = table.rows[i];
					var chkbox = row.cells[0].childNodes[0];
					if(null != chkbox && true == chkbox.checked) 
					{
						if(rowCount <= 1) 
						{
							alert("Cannot delete all the rows.");
							break;
						}
					table.deleteRow(i);
					rowCount--;
					i--;
					}
					
				}
		document.getElementById("hiditemcount").value=parseFloat(rowCount)-1;		
		}
		catch(e) 
		{
			alert(e);
		}

	}	

</script>