<style type="text/css">
.body_lightbox {
width:100%;
background-color:#e7e7e7;
position:absolute;
left:280px;
top:95px;
padding-left:5px;
padding-right:5px;
border:#666666 solid 3px;
}
</style>

<?php
$modid=$_REQUEST['modid'];
$frmid=$_REQUEST['frmid'];
$rurl="&modid=".$modid."&frmid=".$frmid;
/*if($_REQUEST['Save'])
{
	$fstatus=true;
	if($_REQUEST['site']=='0')
	{
	$msgErr[]="Please Select Branch Name";
	$fstatus=false;
	}
	if($_REQUEST['bomno']=='')
	{
	$msgErr[]="Please Enter Bom No";
	$fstatus=false;
	}	
	if($_REQUEST['Description']=='')
	{
	$msgErr[]="Please Enter Descriptions";
	$fstatus=false;
	}
	if($_REQUEST['bomtype']=='0')
	{
	$msgErr[]="Must Select Bom Type";
	$fstatus=false;
	}
	if($_REQUEST['bomlocation']=='0')
	{
	$msgErr[]="Must Select Bom Locations";
	$fstatus=false;
	}
	if($_REQUEST['prepared_date']=='')
	{
	$msgErr[]="Must Entet Prepared Date";
	$fstatus=false;
	}
	if($_REQUEST['prepared_by']=='')
	{
	$msgErr[]="Please  Entet Prepared By";
	$fstatus=false;
	}
	if($_REQUEST['approved_by']=='')
	{
	$msgErr[]="Please  Entet Approved By";
	$fstatus=false;
	}
	if($_REQUEST['procsstotal']=='')
	{
	$msgErr[]="Total Operational Cost ";
	$fstatus=false;
	}
	if($_REQUEST['overheadcost']=='')
	{
	$msgErr[]="Total Overhead Cost";
	$fstatus=false;
	}
	if($_REQUEST['total_qty']=='')
	{
	$msgErr[]="Total Raw Material Item Qty";
	$fstatus=false;
	}
	if($_REQUEST['landedprice']=='')
	{
	$msgErr[]="Total Raw Material Cost Landed Price";
	$fstatus=false;
	}
	if($_REQUEST['totalamount']=='')
	{
	$msgErr[]="Total Production Rate of Bill of Material";
	$fstatus=false;
	}
	
	if($_REQUEST['part_code']=='')
	{
	$msgErr[]="Please Enter Part Code for finished Product Details";
	$fstatus=false;
	} 
	if($_REQUEST['product_name']=='')
	{
	$msgErr[]="Please Enter Product Name for finished Product Details";
	$fstatus=false;
	} 
	if($_REQUEST['finished_uom']=='')
	{
	$msgErr[]="Please Enter Finished UOM for finished Product Details";
	$fstatus=false;
	} 
	$qtydata=$_REQUEST['itemcode'];
	for($i=0;$i<count($qtydata);$i++)
	{
	if($_REQUEST['itemcode'][$i]=='')
	{
	$msgErr[]="Please Select Item Code for Raw Material And Assemble  ";
	$fstatus=false;
	} 	
	
	}
	$qtydata1=$_REQUEST['processid'];
	for($i=0;$i<count($qtydata1);$i++)
	{
	if($_REQUEST['processid'][$i]=='0')
	{
	$msgErr[]="Please Select Process Name for Process Operational  ";
	$fstatus=false;
	} 	
	if($_REQUEST['procesper'][$i]=='')
	{
	$msgErr[]="Please Enter Process Percentage for Process Operational  ";
	$fstatus=false;
	} 	
	if($_REQUEST['procesamt'][$i]=='')
	{
	$msgErr[]="Please Enter Process Amount for Process Operational  ";
	$fstatus=false;
	} 	
	
	}
	
	$qtydata2=$_REQUEST['process_overhead'];
	for($i=0;$i<count($qtydata2);$i++)
	{
	if($_REQUEST['process_overhead'][$i]=='0')
	{
	$msgErr[]="Please Select Process Name for Overhead Operational  ";
	$fstatus=false;
	} 	
	if($_REQUEST['procesoverper'][$i]=='')
	{
	$msgErr[]="Please Enter Process Percentage for Overhead Operational  ";
	$fstatus=false;
	} 	
	if($_REQUEST['procesoveram'][$i]=='')
	{
	$msgErr[]="Please Enter Process Amount for Overhead Operational  ";
	$fstatus=false;
	} 	
	
	} 
	
}*/
if($_REQUEST['Save']!='')
	{   

	$sitepre=DB_query("select prefix from locations where loccode='".$_REQUEST['site']."'",$db);
	$prefix=DB_fetch_array($sitepre);
	$chkSQL=DB_query("select * from bill_material where brach_code='".$_REQUEST['site']."'",$db);					   	       
	if(DB_num_rows($chkSQL)>0)
	{
	$Getsql=DB_query("select Bom_no as MAXBOMNO from bill_material where brach_code='".$_REQUEST['site']."' order by id desc limit 1",$db);
	$GetMax=DB_fetch_array($Getsql);
	$MaxId=substr($GetMax['MAXBOMNO'],-4);
	$FinalMaxId=$MaxId+1;
	$finalCode=$prefix['prefix']."/BOM-".str_pad($FinalMaxId,4,0,STR_PAD_LEFT);
	}
	else
	{
	$finalCode=$prefix['prefix']."/BOM-0001";
	}
	
	
	$data2['brach_code']=$_REQUEST['site'];
	$data2['bom_no']=$finalCode;
	$data2['bom_type']=$_REQUEST['bomtype'];
	$data2['description']=$_REQUEST['Description'];
	$data2['bom_location']=$_REQUEST['bomlocation'];
	$data2['revision_no']=$_REQUEST['revisionno'];
	$data2['revision_date']=FormatDateForSQL($_REQUEST['revisiondate']);
	$data2['prepared_date']=FormatDateForSQL($_REQUEST['prepared_date']);
	$data2['prepared_by']=$_REQUEST['prepared_by'];
	$data2['approved_by']=$_REQUEST['approved_by'];
	$data2['part_code']=$_REQUEST['part_code'];
	$data2['part_id']=$_REQUEST['partid'];
	$data2['subcatid']=$_REQUEST['subcatid'];
	$data2['product_name']=$_REQUEST['product_name'];
	$data2['product_size']=$_REQUEST['product_size'];
	$data2['uom']=$_REQUEST['finished_uom'];
	$data2['total_qty']=$_REQUEST['total_qty'];
	$data2['CompanyId']=$_SESSION['ACGCompanyId'];
	$s->RecordInsert('bill_material', $data2);
	$Lastreq_id=DB_Last_Insert_ID($db,'bill_material','id');
	
	$qty=$_REQUEST['itemcode'];
	$qty1=count($qty);
	if($Lastreq_id!='')
	{
		for($i=0;$i<$qty1;$i++)
		{
			$data1['bill_material_id']=$Lastreq_id;
			$data1['production_process']=$_REQUEST['product_process'][$i];
			$data1['mst_itemid']=$_REQUEST['itemid'][$i];
			$data1['part_code']=$_REQUEST['itemcode'][$i];
			$data1['bom_description']=$_REQUEST['desc'][$i];
			$data1['product_size1']=$_REQUEST['product_sizes'][$i];
			$data1['bom_uom']=$_REQUEST['uom'][$i];
			$data1['bom_qty']=$_REQUEST['qty'][$i];
			$data1['bom_sec_qty']=$_REQUEST['qty1'][$i];
			$data1['bom_costlanded_price']=$_REQUEST['costlandprice'][$i];
			$data1['bom_amount']=$_REQUEST['amount'][$i];
			$data1['status']='0';
			$s->RecordInsert('bill_raw_material', $data1);
		}		
	}
	
	$s->pageLocation('index.php?route=bill_of_materiallist&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].$rurl);
}
else 
{
	  $ErrMsg = _('Priviously occurred Record Note Save') . '. ' . _('The error says');
}
?>
<link rel="stylesheet" href="css/new_mxerp.css">
<style type="text/css">
<!--
.style1 {
	color: #FF0000;
	font-weight: bold;
}
-->
</style>
<div class="body_contain">
<div class="tab_div">
<h1>Bill Of Material</h1>
<form action="" method="post">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr class="row1">
    <td colspan="6"><?php
   for($i=0;$i<count($msgErr);$i++)
   {
     echo "<div class='error'>".$msgErr[$i].'</div>';
   }
    ?></td>
    </tr>
	
  <tr>
    <td style="width:250px;" class="tabledata1">Branch <span class="style1">* </span></td>
    <td colspan="5"><select name="site" id="site" style="width:130px;">
     <?php 
		$site_sql = "Select * from locations where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."')";
		$site_result = DB_query($site_sql,$db);
		while($site_row = DB_fetch_array($site_result))
		{
		?>
         <option value="<?php echo $site_row['loccode']; ?>" ><?php echo $site_row['locationname']; ?></option>
            <?php } ?>
    </select></td>
    </tr>
  <tr class="row1">
    <td class="tabledata1">BOM No.</td>
    <td id="hotfoil" style="padding-right:5px;">
      <input type="text" name="bomno" id="bomno" style="width:130px;" value="Auto Generated" readonly></td>
    <td class="tabledata1">Type Of BOM <span class="style1">*</span></td>
    <td style="padding-right:5px;"><select name="bomtype" id="bomtype" style="width:130px;">
    <option value="0">Select</option>
     <?php 
		$site_sql2 = "SELECT id,bom_type from bom_type";
		$site_result1 = DB_query($site_sql2,$db);
		while($site_row2 = DB_fetch_array($site_result1))
		{
		?>
         <option value="<?php echo $site_row2['id']; ?>" ><?php echo $site_row2['bom_type']; ?></option>
            <?php } ?>
    </select></td>
    <td class="tabledata1">Description</td>
    <td><input type="text" name="Description" id="Description" style="width:130px;"></td>
    </tr>
  <tr class="row1">
    <td class="tabledata1">Location Of BOM <span class="style1">*</span></td>
    <td><select name="bomlocation" id="bomlocation" style="width:130px;">
    <option value="0">Select</option>
     <?php 
		$site_sql3 = "SELECT id,bom_location from bom_location";
		$site_result2 = DB_query($site_sql3,$db);
		while($site_row2 = DB_fetch_array($site_result2))
		{
		?>
         <option value="<?php echo $site_row2['id']; ?>" ><?php echo $site_row2['bom_location']; ?></option>
            <?php } ?>
    </select></td>
    <td class="tabledata1">Revision No.</td>
    <td><input type="text" name="revisionno" id="v" style="width:130px;"></td>
    <td class="tabledata1">Revision Date</td>
    <td><input type="text" name="revisiondate" id="revisiondate" style="width:130px;" class="datepicker"></td>
    </tr>
  <tr class="row1">
    <td class="tabledata1">Prepared Date</td>
    <td><input type="text" name="prepared_date" id="prepared_date" style="width:130px;" class="datepicker"></td>
    <td class="tabledata1">Prepared By</td>
    <td><input type="text" name="prepared_by" id="prepared_by" style="width:130px;"></td>
    <td class="tabledata1">Approved By</td>
    <td><input type="text" name="approved_by" id="approved_by" style="width:130px;"></td>
    </tr>
  <tr class="row1">
    <td colspan="6" ><h3 style="color:#000000; font-size:12px;"><strong>Product Details</strong></h3></td>
    </tr>
  <tr class="row1">
    <td colspan="6" class="tabledata1">
	<div id="pickitems">
	<table width="100%%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td colspan="7" class="tabledata1">Pick Item
      <input type="text" name="item_popup"  id="item_popup"  onkeyup="opendata(this.value);" class="search"/></td>
    </tr>
	  <tr><th ><input type="text" name="partid" id="partid" />
        <input name="subcatid" id="subcatid" type="hidden" />
        <span class="style1">*</span>Part Code </th>
	    <td><input type="text" name="part_code" id="part_code" style="width:120px;" value="" readonly="readonly"></td>
    <th ><span class="style1">*</span>Product Name</th>
    <td><input type="text" name="product_name" id="product_name" style="width:120px;" value="" readonly="readonly"></td>
	<th>Category</th>
    <td><input type="text" name="subcatname" id="subcatname" style="width:120px;" value="" readonly="readonly"></td>
      <th><span class="style1">*</span>UOM</th>
    <td id="abc">
	<select name="finished_uom" id="finished_uom" style="width:120px;" onfocus="getproductUnits(this.value,this.id)">
	<option>Select</option>
	</select>
	</td>
	<!--<th ><span class="style1">*</span>Product Size</th>
    <td><div id="ps"><input type="text" name="product_size" id="product_size" style="width:120px;" value="" readonly="readonly" onchange="getproductsize(this.value,this.id)" onfocus="getproductsize(this.value,this.id)"></div></td>-->
</tr>
</table></div>
</td>
    </tr>
</table>
 <div class="body_lightbox" id="lightbox" style="overflow:auto; width:600px; height:250px; display:none;"></div>
<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"/>
<input type="button" name="profile_popup" value="+" id="profile_popup"  onclick="openPopupProfile(this.id)" />
</p>
<div id="bomdetails">
<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
  <tr>
    <td class="tabledata1" colspan="14"><h3 style="color:#000000; font-size:12px;"><strong>Raw Material And Assembly Item Details</strong></h3></td></tr>
	  <tr>
  	<td class="tabledata">Select</td>
    <td class="tabledata">Process</td>
	<td class="tabledata">&nbsp;</td>
    <td class="tabledata">Part Code</td>
    <td class="tabledata">Description</td>
	<!--<td class="tabledata">&nbsp;</td>-->
<!--	<td class="tabledata">Size</td>
-->	<td colspan="5" class="tabledata" style="text-align:center"><span class="tabledata" style="text-align:center">Quantity</span></td>
  </tr>
   <tbody id="dataTable">
  <tr>
  	<td class="tabledata"><input type="checkbox" name="chk" /><input type="hidden" value="" id="user_shipping" name="user_shipping[]" /></td>
	
        <td class="tabledata"><select name="product_process[]" id="prodcut_process" style="width:100%">
		
    	<option value="0">---Select </option>
    	<?php $productrow=DB_query("select * from production_process_master",$db);
		while($product_row1=DB_fetch_array($productrow))
		{
			?>
			<option value="<?php echo $product_row1['id']; ?>"><?php echo $product_row1['manuf_process_name'];?></option>
		}
    	
    	<?php } ?>
    	
    </select></td>
	<td class="tabledata"><input type="hidden" name="itemid[]" id="itemid" /></td>
    <td class="tabledata"><input type="text" name="itemcode[]" id="itemcode" style="width:100%" readonly></td>
    <td class="tabledata"><input type="text" name="desc[]" id="desc" style="width:100%" readonly></td>
	<!--<td class="tabledata">--><input type="hidden" name="psize[]" id="psize" value="" onblur="getproductsize1(this.value,this.id)" onfocus="getproductsize2(this.value,this.id)" style="height:20px; width:20px;" /><!--</td>-->
	<!--<td class="tabledata"><select name="product_sizes[]" id="product_sizes" style="width:100%;"><option value="">Select</option></select></td>-->
    <td class="tabledata"><input type="text" name="qty[]" id="qty" style="width:100%" />      </td>
	<td class="tabledata"><input type="text" name="uom[]" id="uom" style="width:100%" readonly /></td>
	<td class="tabledata"><input type="hidden" name="confac[]" id="confac" /></td>
	<td class="tabledata"><input type="text" name="qty1[]" id="qty1" style="width:100%" ></td><!--onkeyup="calprimaryqty(this.id,this.value)" -->
	<td class="tabledata"><input type="text" name="uom1[]" id="uom1" style="width:100%" readonly /></td>
    
  </tr>
   </tbody>
</table>
<input type="hidden" name="hiditemcount" id="hiditemcount" value="" />
<input type="hidden" name="" value="" id="edit_cnt" />
<br />
</div>
<div  id="rawmaterial">
<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
  <tr>
    <td class="tabledata"><strong>Total Raw Material And Assembly Item Qty</strong></td>
    <td><input type="text" name="total_qty" id="total_qty" style="width:100%" onfocus="calqty(this);"></td>
    
  </tr>
</table>
</div>
<br />
<p align="center"><input type="submit" value="Save" name="Save" class="search" onclick="return validdata();" /></p>
</form>
</div></div>



<script language="javascript" type="text/javascript">
function openPopupProfile(i)
{ 
	window.open("pickrawmaterial.php?rowcount="+i,"profiles_popup_window","height=570,width=700,toolbar=no,menubar=no,dependent=yes,resizable=yes");
}

function calqty(str)
{    	
	var rowCount = document.getElementById('dataTable').rows.length;
	 var obj1=document.getElementById('qty').value;
	 			
    var obj=document.getElementById('qty');
	     var arr = obj.id.split("_");
	     var rowx1=0;
	   if (arr[1]==undefined)
	   {
	    var nm='';
	   }
	   else
	 {
	 var nm='_'+arr[1];
	 }
    for(var i=1;i<rowCount;i++)
	{  
		
	rowx1=parseFloat(document.getElementById('qty_'+i).value)+parseFloat(rowx1) ;
   }
   rowx1=parseFloat(rowx1)+parseFloat(obj1)
   
   document.getElementById('total_qty').value=rowx1.toFixed(2);
   }
   
   
   function calprimaryqty(str,str1)
   {
   var k=str.split("_");
   if(k[1]==undefined)
   {
   if(document.getElementById("confac").value!='0')
   {
   var confac=document.getElementById("confac").value;
   var qty=parseFloat(str1)*confac;
   }
   else
   {
   var qty=0;
   }
   if(str1=='')
    document.getElementById("qty").value=0;
	else
   document.getElementById("qty").value=qty.toFixed(2);
   }
   else
   {
   var i=k[1];
   if(document.getElementById("confac_"+i).value!='0')
   {
   var confac=document.getElementById("confac_"+i).value;
   var qty=parseFloat(str1)*confac;
   }
   else
   {
   var qty=0;
   }
   if(str1=='')
    document.getElementById("qty_"+i).value=0;
	else
   document.getElementById("qty_"+i).value=qty.toFixed(2);
   
   
   }
   
   
   
   }
   
   
   
   
   
   
  
  
   
	  
function opendata(str)
{
 
 if (str.length ==0)
    {    	
     document.getElementById("lightbox").innerHTML="";
     document.getElementById("lightbox").style.border="0px";
      return;
    }	

var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("lightbox").style.display='block';	
	document.getElementById("lightbox").innerHTML=xmlhttp.responseText;
	
   // document.getElementById("textitem").innerHTML=data[1];
	
    }
  }
  
  xmlhttp.open("GET","showboqitems.php?site="+str,false);
	xmlhttp.send();
	
}

function getproductsize(str,strid)
{
if (str.length==0 || str=='')
    {    	
         return;
    }	

var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("ps").innerHTML=xmlhttp.responseText;
	
   // document.getElementById("textitem").innerHTML=data[1];
	
    }
  }
  
  xmlhttp.open("GET","getproductsize.php?psc="+str,false);
	xmlhttp.send();
	
}



function getproductUnits(str,strid)
{
	var partid=document.getElementById("partid").value;
if (str.length==0 || str=='')
    {    	
         return;
    }	

var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("finished_uom").innerHTML=xmlhttp.responseText;
	
   // document.getElementById("textitem").innerHTML=data[1];
	
    }
  }
  
  xmlhttp.open("GET","getproductunits.php?item="+partid,false);
	xmlhttp.send();
	
}



function getproductsize2(){
 	var fitm = document.getElementById("hiditemcount").value;
 	for(var ii=1;ii<=fitm;ii++){
		if(document.getElementById("psize_"+ii).value==''){
			continue;
		}else{
 			document.getElementById("psize_"+ii).focus();
		}	
 	}
	document.getElementById("qty1").focus();
}

function getproductsize1(str,strid)
{
if (str.length==0 || str=='')
    {    	
         return;
    }	

var idi = strid.split("_");
if(idi[1]==undefined){
	strid1="product_sizes";
}else{
	strid1="product_sizes_"+idi[1];
}
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById(strid1).innerHTML=xmlhttp.responseText;
	document.getElementById(strid).type='hidden';
   // document.getElementById("textitem").innerHTML=data[1];
	
    }
  }
  
  xmlhttp.open("GET","getproductsize.php?psc="+str,false);
	xmlhttp.send();
	
}


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;
		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 hidedata()
{
document.getElementById("lightbox").style.display='none';
}

function getItemsList1(id,code,shade,netrate,subcatname,subcatid,ctr)
{ 
   
  
	document.getElementById('partid').value = id;
	document.getElementById('part_code').value = code;
	document.getElementById('product_name').value = shade;
	//document.getElementById('finished_uom').value = netrate;
	document.getElementById('finished_uom').focus();
	document.getElementById('subcatname').value = subcatname;
	document.getElementById('subcatid').value = subcatid;
	//document.getElementById('product_size').value = subcatid;
	
	//}
	
	document.getElementById("lightbox").style.display='none';
	document.getElementById('product_size').focus();
	
}

function validdata()
{
if(document.getElementById("site").value=='0')
{
alert("Please Select Site First");
return false;
}
if(document.getElementById("bomtype").value=='0')
{
alert("Please Select Bom Type");
return false;
}
if(document.getElementById("bomlocation").value=='0')
{
alert("Please Select Bom Locations First");
return false;
}
if(document.getElementById("revisiondate").value=='')
{
alert("Please Enter Revision Date First");
return false;
}
if(document.getElementById("prepared_date").value=='')
{
alert("Please Enter Prepared  Date First");
return false;
}
if(document.getElementById("part_code").value=='')
{
alert("Must Enter Part Code");
return false;
}
if(document.getElementById("product_name").value=='')
{
alert("Must Enter Part Name");
return false;
}
if(document.getElementById("finished_uom").value=='')
{	
alert("Must Enter UOM");
return false;
}
if(document.getElementById("finished_uom").value=='')
{	
alert("Must Enter UOM");
return false;
}



}

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>
