<?php 
if(isset($_POST['Save']))
{

    $prefix_sql=DB_query("Select prefix from locations where loccode='".$_REQUEST['branch']."' ",$db);
	$prefix_row=DB_fetch_array($prefix_sql);
	$branchPrefix=$prefix_row['prefix'];
	$orderNo_sql="Select id,orderNo from salesorder where branch='".$_REQUEST['branch']."'";
	$orderResult=DB_query($orderNo_sql,$db);
	if(DB_num_rows($orderResult)>0)
	{
		$GetMxSql=DB_query("SELECT MAX(mms_no) AS MAXON FROM measurment_sheet_main
		 where site='".$_REQUEST['branch']."'",$db);
		$GetMaxId=DB_fetch_array($GetMxSql);
		$MaxOrdNo=substr($GetMaxId['MAXON'],-2);
		$FinalMaxOrdNo=$MaxOrdNo+1;
		$FinalOrdNo=$branchPrefix."/"."MMS/".str_pad($FinalMaxOrdNo,5,"0",STR_PAD_LEFT);
	}
	else
	{
		$FinalOrdNo=$branchPrefix."/MMS/00001";
	}	
	$data['site']                =$_REQUEST['branch']; 
	$data['mms_date']            =FormatDateForSQL($_REQUEST['mms']);
	$data['mms_no']              =$FinalOrdNo;
	$data['format']              =$_REQUEST['format']; 
	$data['client']              =$_REQUEST['Client'];
	$data['mms_type']            =$_REQUEST['order_type'];  
	$data['type']                =$_REQUEST['type'];  
	$data['order_no']            =$_REQUEST['order_no'];  
	$data['order_date']          =FormatDateForSQL($_REQUEST['order_date']);
	$data['po_no']               =$_REQUEST['po_no'];
	$data['po_date']             =FormatDateForSQL($_REQUEST['po_date']);
	$data['delivery_date']       =FormatDateForSQL($_REQUEST['delivery_date']);
	$data['consignee']           =$_REQUEST['consignee'];
	$data['measurement']         =$_REQUEST['handled_by'];
	$data['mobile_no']           =$_REQUEST['mobile']; 
	$data['total_qty']           =$_REQUEST['totalqty'];
	$data['remarks']             =$_REQUEST['basicAmount'];
	$data['prepared_by']         =$_REQUEST['prepared_by'];
	$data['approved_by']         =$_REQUEST['approved_by'];
	$data['created_date']        =$_REQUEST['ECessPercentage'];
	$data['created_by']          =$_SESSION['UserID'];
	$data['CompanyId']           =$_SESSION['ACGCompanyId'];
	
	//echo "<pre>";
	//print_r($data);
	
	$s->RecordInsert('measurment_sheet_main', $data);
	$SalesId=DB_Last_Insert_ID($db,'measurment_sheet_main','id');

		if(isset($SalesId))
			{
				for($i=0;$i<count($_REQUEST['tower']);$i++)
				{
				
				$data_arr['parent_id']=$SalesId;
				$data_arr['tower']=$_REQUEST['tower'][$i];
				$data_arr['floor']=$_REQUEST['floor'][$i];
				$data_arr['location']=$_REQUEST['location'][$i];
				$data_arr['type']=$_REQUEST['type'][$i];
				$data_arr['size']=$_REQUEST['size'][$i];
				$data_arr['qty']=$_REQUEST['qty'][$i];
				$data_arr['unit']=$_REQUEST['unit'][$i];
				$data_arr['opening_type']=$_REQUEST['openingtype'][$i];
				$rowinsert= $s->RecordInsert('measurment_sheet_details', $data_arr);
				
				
				}
				
				
				
		for($z=0; $z<count($_REQUEST['hardware']);$z++)
		   {
		
		$hrddata['parent_id']=$SalesId;
		$hrddata['hardware']=$_REQUEST['makeid'][$z];
		$hrddata['qty']=$_REQUEST['hardware'][$z];
				
		//echo "<pre>";
		//print_r($hrddata);
		$s->RecordInsert('measurment_hardware_details',$hrddata);
		
		}
				
				
				
				
				
				
			}	




}



$SQLSales=DB_query("select * from salesorder where id='".$_REQUEST['SID']."'",$db);
$GetSalesData=DB_fetch_array($SQLSales);
extract($GetSalesData);

$assing_id=$s->getField('workassignment_creation_assignment','ttid',$_REQUEST['SID'],'technician_id'); 






$Category=DB_query("SELECT * FROM stockmaincategory WHERE (stockmaincategoryid='SF' || stockmaincategoryid='FG') 
                  AND CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
while($categoryId=DB_fetch_array($Category)){
$catId[]=$categoryId['id'];
}
$FinalCatId=implode(",",$catId);
?>

<center> <h2>Measuement Sheet</h2>
</center>
<link rel="stylesheet" href="css/new_mxerp.css">
<form action="" method="post">
<input type="hidden" name="order_id" id="order_id" value="<?php echo $_REQUEST['SID']; ?>" />
<fieldset><legend style="font-size:13px;"><strong>General Details</strong></legend>
<table width="100%" align="center" border="1" cellpadding="2" cellspacing="1">
  <tr>
    <th width="13%"><strong>Branch</strong></th>
    <td width="20%"><select style="width:100%;" name="branch" id="branch">
      <?php 
	  $sql_branch=DB_query("select * from locations where mst_companyid='".$_SESSION['ACGCompanyId']."'",$db);
	  while($row1=DB_fetch_array($sql_branch))
	  {
	  ?>
      <option id="<?php echo $row1['loccode']; ?>"><?php echo $row1['locationname'];  ?></option>
	  <?php } ?>
    </select>
    </td>
    <th width="13%"><strong>MMS No.</strong></th>
    <td width="20%"><input name="mms_no" id="mms_no" value="<?php echo "Auto generated"; ?>" type="text" 
	style="width:100%;" />
    </td>
    <th><strong>MMS Date</strong></th>
    <td width="20%"><input name="mms" id="mms" value="<?php echo date('d/m/Y'); ?>" type="text" class="datepicker" 
	style="width:100%;" /></td>
  </tr>
  <tr>
    <th><strong>Format</strong></th>
    <td><select style="width:100%;" name="format" id="format">
      	   <option value="Standard">Standard</option>
    </select></td>
    <th><strong>Type of MMS</strong></th>
    <td><select style="width:100%;" id="order_type" name="order_type">
			   <option value="Material">Material</option>
			   <option value="Supply">Supply</option>
			   <option value="Composite">Composite</option>
		   </select>
		   </td>
    <th><strong>Type</strong></th>
    <td><?php $SubCatSQl=DB_query("SELECT * FROM stockcategory WHERE stockmaincategory IN($FinalCatId)",$db);?>
		<select name="type" id="type" style="width:100%;">
			<option value="0">Select</option>
	<?php while($SubCatId=DB_fetch_array($SubCatSQl)){ ?>
			<option value="<?php echo $SubCatId['id']; ?>"><?php echo $SubCatId['categorydescription']; ?></option>
	<?php }?>
		</select></td>
  </tr>
  <tr>
    <th><strong>Client</strong></th>
    <td><?php $ClientSQL="Select * from clientmaster where CompanyId='".$_SESSION['ACGCompanyId']."' and  Site in('".$_SESSION['AssignedBranch']."') and Zone in(".$_SESSION['AssignedSites'].") order by c_name ASC"  ;?>
             <select style="width:206px;" name="Client" id="Client" >
                  <option value="0">--Select--</option>
                   <?php $ClientRes=DB_query($ClientSQL,$db);
					while($ClientRow=DB_fetch_array($ClientRes)){?>
                  <option value="<?php echo $ClientRow['id']?>" <?php echo($client==$ClientRow['id']?'selected':'')?>  ><?php echo $ClientRow['c_name']?></option>
                          <?php  } ?>
      </select></td>
    <th><strong>Order No</strong></th>
    <td><input type="text" name="order_no" id="order_no" value="<?php echo $orderNo; ?>" style="width:100%;" />    </td>
    <th><strong>Order Date</strong></th>
    <td><input name="order_date" id="order_date" type="text" class="datepicker" style="width:100%;" value="<?php echo ConvertSQlDate($orderDate); ?>" /></td>
  </tr>
  <tr>
    <th><strong>P.O. No.</strong></th>
    <td><input name="po_no" id="po_no" type="text" class="" style="width:100%;" value="<?php echo $PORefNo; ?>" /></td>
    <th><strong>Po Date</strong></th>
    <td><input name="po_date" id="po_date" type="text" class="datepicker" style="width:100%;" value="<?php echo ConvertSQlDate($customerPODate); ?>" /></td>
    <th><strong>Delivery Date</strong></th>
    <td><input name="delivery_date" id="delivery_date" type="text" class="datepicker" style="width:100%;" value="<?php echo ConvertSQlDate($DeliveryDate); ?>" /></td>
  </tr>
  <tr>
    <th> <strong>Consignee</strong></th>
    <td><select  name="consignee" id="consignee" style="width:100%">
			<option value="0">Select</option>
		<?php $sqlConsi=DB_query("SELECT * FROM clientmaster_consignee_address where client_id='".$client."'",$db);
		while($ConsigneeId=DB_fetch_array($sqlConsi)){?>
			<option value="<?php echo $ConsigneeId['id']; ?>"><?php echo $ConsigneeId['consignee_name']; ?></option>
		<?php }?>
	</select></td>
    <th><strong>Measurement By</strong></th>
			<?php $sqlEmplo=DB_query("SELECT * FROM technicians where id='".$assing_id."'",$db);
			$Handles=DB_fetch_array($sqlEmplo);?>
	<td><input name="handled_by" id="handled_by" readonly="readonly" value="<?php echo $Handles['technician']; ?>" type="text" class="" style="width:100%;" /></td>
    <th><strong>Mobile No. </strong></th>
    <td><input name="mobile" id="mobile" readonly="readonly" type="text" value="<?php echo $Handles['mobile_number']; ?>" class="" style="width:100%;" /></td>
  </tr>
</table>
</fieldset>
<br />
<fieldset><legend style="font-size:13px;"><strong>Product Information</strong></legend>
<p align="left">
<input type="button" class="search" value="Add Rows" onclick="addRowdata('dataTable')" /> 
<input type="button" class="search"  onclick="deleteRowOrder('dataTable')" value="Delete" />
<input type="button" class="search"  onclick="open_items()" value="Pick Items" />
</p>
<div  style="overflow:auto; width:900px; "> 
<table width="100%" border="1" cellspacing="0" cellpadding="2">
  <tr>
    <th>Sr.No</th>
    <th>Tower</th>
	<th>Floor</th>
    <th>Location</th>
    <th>Item Name</th>
    <th>Size</th>
	<th>Width</th>
  	<th>Height</th>
	<th>Qty</th>
    <th>unit</th>
    <th>Opening Type</th>
	<?php 
	$sql=DB_query("select * from product_manufacture where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
	$numrow=DB_num_rows($sql);
	while($row=DB_fetch_array($sql))
	{
	?>
    <th><?php   echo $row['manufacturer']; ?></th>
	<?php } ?>	
    <th>Remarks</th>
  </tr>
  <tbody id="dataTable">
  <tr>
<td style="white-space:nowrap;" class="tabledata"><input name="delitem[]"  type="checkbox" value="" onclick="showdata(this.id)" /></td>	
	<td class="tabledata"><select name="tower[]" id="tower"  onchange="showfloor(this.value,this.id)" style="width:120px;">
	                      <option value="0">Select</option>
						  <?php  $tow=DB_query("select * from  tower_master where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
						   while($tow_row=DB_fetch_array($tow))
						   {
						   ?>
						   <option value="<?php echo $tow_row['id']; ?>"><?php echo $tow_row['group_name']; ?></option>
						   <?php } ?>
                          </select></td>
	<td class="tabledata"><select name="floor[]" id="floor" onchange="showlocation(this.value,this.id)" style="width:120px;">
	                      <option value="0">Select</option>
						  <?php  $tow=DB_query("select * from  tower_floor_master
						   where CompanyId='".$_SESSION['ACGCompanyId']."' and parant_id=0",$db);
						   while($tow_row=DB_fetch_array($tow))
						   {
						   ?>
						   <option value="<?php echo $tow_row['id']; ?>"><?php echo $tow_row['terms_conditions']; ?></option>
						   <?php } ?>
                          </select>	</td>
	<td class="tabledata" style="white-space:nowrap"><select name="location[]" id="location" style="width:120px;" >
	                      <option value="0">Select</option>
						  <?php  $tow=DB_query("select * from  tower_floor_master
						   where CompanyId='".$_SESSION['ACGCompanyId']."' and parant_id!=0",$db);
						   while($tow_row=DB_fetch_array($tow))
						   {
						   ?>
						   <option value="<?php echo $tow_row['id']; ?>"><?php echo $tow_row['terms_conditions']; ?></option>
						   <?php } ?>
                          </select>	</td>
						<?php $approved=DB_query("SELECT * FROM salesorder_details WHERE masterid='".$_REQUEST['SID']."'",$db);
		while($approved_row=DB_fetch_assoc($approved))
		{  
			if($approved_row['ApprovalStatus']=='3' || $approved_row['ApprovalStatus']=='2')
			{
			$item_name[]=DB_fetch_assoc(DB_query("SELECT item_name,id,mst_unitid FROM item_master WHERE id='".$approved_row['ItemCode']."'",$db));
			}
		}
			$new=array_unique($item_name, SORT_REGULAR);
		?>  
	<td class="tabledata"><select name="item_name" id="item_name_id" onchange="javascript:sizeselection(this.value,this.id);">
	<option value="">Select</option>
	<?php
		 foreach($new as $list) {?>
		<option value="<?php echo $list['id']; ?>"><?php echo $list['item_name']; ?></option>
	<?php } ?>
	</select>
	<!--<input type="text" name="type[]" id="type1" readonly  onkeyup="showdata1(this.value,this.id)"  maxlength="1" size="9" />-->
	</td>
	<td class="tabledata"><select id="item_size" name="item_size">
	</select>
		<!--<select name="size[]" id="size" style="width:120px;" >
		  <option value="0">Select</option>
		  <?php /* $size=DB_query("select * from  size_master
		   where CompanyId='".$_SESSION['ACGCompanyId']."' ",$db);
		   while($size_row=DB_fetch_array($size))
		   {*/
		   ?>
		   <option value="<?php // echo $size_row['id']; ?>"><?php // echo $size_row['size']; ?></option>
		   <?php // } ?>
		  </select>-->
	</td>
	<td class="tabledata"><input type="text" name="measure_width" id="measure_width_id" style="width:50px;"/></td>
	<td class="tabledata"><input type="text" name="measure_height" id="measure_height_id" style="width:50px;"/></td>
	<?php 
	
	?>
	<td class="tabledata"><input type="text" name="qty[]" value="" id="qty" size="9" onkeyup="caldispatch(this.id)" /></td>
	<td class="tabledata"><input type="text" name="units" id="units_id" style="width:50px;"  readonly="true" /><!--<select name="unit[]" id="unit"  style="width:54px;" >
	                      <option value="0">Select</option>
						  <?php  /*$unit=DB_query("select * from  unitsofmeasure",$db);
						   while($unit_row=DB_fetch_array($unit))
						   {*/
						   ?>
						   <option value="<?php // echo $unit_row['unitid']; ?>"><?php // echo $unit_row['unitname']; ?></option>
						   <?php // } ?>
                          </select>-->	
						  
						  </td>
	<td class="tabledata"><select name="openingtype[]" id="openingtype"  style="width:54px;" >
	                      <option value="0">Select</option>
					 <?php  $open=DB_query("select * from  type_of_opening where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
						   while($open_row=DB_fetch_array($open))
						   {
						   ?>
						   <option value="<?php echo $open_row['id']; ?>"><?php echo $open_row['group_name']; ?></option>
						   <?php } ?>
                          </select></td> <?php 
						  $u=1;
	$sql1=DB_query("select * from product_manufacture where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
	while($row1=DB_fetch_array($sql1))
	{
	?>
   <td class="tabledata"><input type="text" name="hardware[]" id="<?php echo  $row1['manufacturer']; ?>" style="width:50px;"  onkeyup="caldispatch1(this.id,<?php echo $u; ?>)" /><?php   echo $row['manufacturer']; ?></td>
	<?php $u++; } ?>
		
    <td class="tabledata"><input type="text" name="remarks[]" id="remarks" style="width:50px;"  readonly="true" /></td> 
	
	
	</tr>
  </tbody>
   <tr>
    <td class="tabledata">&nbsp;</td>
    <td class="tabledata">&nbsp;</td>
    <td class="tabledata">&nbsp;</td>
	<td class="tabledata">&nbsp;</td>
	<td class="tabledata">&nbsp;</td>
	<td class="tabledata">&nbsp;</td>
	<td class="tabledata">&nbsp;</td>
    <td class="tabledata"><strong>Total</strong></td>
    <td class="tabledata"><input type="text" name="totalqty" id="totalqty" style="width:50px;" /></td>
    <td class="tabledata">&nbsp;</td>
    <td class="tabledata">&nbsp;</td>
	<?php  
	$t=1;
	$sql1=DB_query("select * from product_manufacture where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
	while($row1=DB_fetch_array($sql1))
	{
	?>   
    <td class="tabledata">
	<input type="hidden" name="makeid[]" value="<?php echo $row1['id']; ?>" />
	
	<input type="text" name="totalamount[]" id="<?php echo $t; ?><?php echo  $row1['manufacturer']; ?>" style="width:50px;" /></td>
	<?php $t++; } ?>
	<input type="hidden" name="totalcount" id="totalcount" value="<?php echo $t; ?>" />
	    <td class="tabledata">&nbsp;</td>

  </tr>
</table>
</div>
<input type="hidden" name="hiditemcount" id="hiditemcount" value="" />
<input type="hidden" name="" value="" id="edit_cnt" />


<br />
<table width="100%" border="1" cellspacing="1" cellpadding="2">
  <tr>
    <th width="20%">Remarks</th>
    <td colspan="3">
	<textarea cols="25" rows="3" style="width:100%;"></textarea>
	</td>
  </tr>
  <tr>
    <th>Prepared By</th>
    <td width="30%"><input name="prepared_by" id="prepared_by" type="hidden"  style="width:100%;" value="<?php echo $_SESSION['UserID']; ?>" />
	<input name="prepared_by1" id="prepared_by1" type="text"  style="width:100%;" value="<?php echo $s->getField('www_users','id',$_SESSION['UserID'],'realname'); ?>" />
	</td>
    <th width="20%">Approved By </th>
    <td><input name="approved_by" id="approved_by" type="text"  style="width:100%;" /></td>
  </tr>
</table>

</fieldset>
<input type="submit" name="Save" value="Save" class="search" />
</form>

<script>
function showmobile(str)
{
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("mobile").value=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","getempmobile.php?personid="+str,true);
	xmlhttp.send()
}


function showfloor(str,str1)
{
var st=str1.split("_");

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)
	{
	if(st[1]==undefined)
	{
	document.getElementById("floor").innerHTML=xmlhttp.responseText;
	}
	else
	{
	document.getElementById("floor_"+st[1]).innerHTML=xmlhttp.responseText;
	}
	}
	}
	xmlhttp.open("GET","getfloor.php?personid="+str,true);
	xmlhttp.send()



}


function showlocation(str,str1)
{
var st=str1.split("_");

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)
	{
	if(st[1]==undefined)
	{
	document.getElementById("location").innerHTML=xmlhttp.responseText;
	}
	else
	{
	document.getElementById("location_"+st[1]).innerHTML=xmlhttp.responseText;
	}
	}
	}
	xmlhttp.open("GET","getlocation.php?personid="+str,true);
	xmlhttp.send()

}

function addRowdata(tableID) 
{
	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;
	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;	
	}
		//document.getElementById("stock_perunit_"+rowCount).value=1;
	}
	
}

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=parseInt(rowCount)-1;		
	}
	catch(e) 
	{
	alert(e);
	}
}

function open_items()
{
	window.open("measuement_sheet_itempopup.php?modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'] ?>&action=<?php echo $_REQUEST['action']?>","itempopup_window","height=500,width=700,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");
}


function caldispatch(str)
{
var count=document.getElementById("hiditemcount").value;
var qry=0;
var i=str.split("_");
if(i[1]==undefined)
{
qry=qry+parseFloat(document.getElementById("qty").value);
for(var j=1;j<=count;j++)
	{
	//alert(value);
if(document.getElementById("qty_"+j).value!='')
var qry=qry+parseFloat(document.getElementById("qty_"+j).value);
}
}
else
{
qry=qry+parseFloat(document.getElementById("qty").value);

for(var j=1;j<=count;j++)
	{
	//alert(value);
if(document.getElementById("qty_"+j).value!='')
var qry=qry+parseFloat(document.getElementById("qty_"+j).value);
}
}
document.getElementById("totalqty").value=qry;

}

function caldispatch1(str,t)
{
var count=document.getElementById("hiditemcount").value;
var qry=0;
var i=str.split("_");
if(i[1]==undefined)
{
qry=qry+parseFloat(document.getElementById(i[0]).value);
document.getElementById(t+i[0]).value=qry;

}
else
{
qry=qry+parseFloat(document.getElementById(i[0]).value);

for(var j=1;j<=count;j++)
	{
	
if(document.getElementById(i[0]+"_"+j).value!='')
var qry=qry+parseFloat(document.getElementById(i[0]+"_"+j).value);

}
document.getElementById(t+i[0]).value=qry;
}
}

function sizeselection(item_id,table_id)
{
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)
		{
			//alert(xmlhttp.responseText);
			var allvalue=table_id.split("_");
			var count_value=allvalue.length;
			//alert((allvalue[count_value-1]));
			if(isNaN(allvalue[count_value-1]))
			{
				var response=xmlhttp.responseText.split("+");
				document.getElementById("item_size").innerHTML=response[0];
				document.getElementById("units_id").value=response[1];
			}
			else
			{
				var response=xmlhttp.responseText.split("+");
				document.getElementById("item_size"+"_"+allvalue[count_value-1]).innerHTML=response[0];
				document.getElementById("units_id"+"_"+allvalue[count_value-1]).value=response[1];
			}
			
		}
	}
	  var order=document.getElementById("order_id").value;
	xmlhttp.open("POST","ajax_item.php?Itemid="+item_id+"&Orderid="+order+"&Unitid="+order,true);
	xmlhttp.send();
}
</script>


