<?php 	
$PageSecurity = 1;
$tabindex=0;
//echo $_SESSION['dealerid'];
include('includes/DefinePaymentClass.php');
$title = _('Telephonic Order Memo');
include('includes/SQL_CommonFunctions.inc');
?>
<link rel="stylesheet" href="css/new_mxerp.css">
<link rel="stylesheet" href="/css/jquery.ui.all.css">
<!--	<script src="js1/jquery-1.7.2.js"></script>-->
<script src="js1/jquery.ui.widget.js"></script>
<script src="js1/jquery.ui.tabs.js"></script>
<script>
	$(function() {
		$( "#tabs" ).tabs();
	});
	
	function GetTables(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)
	{
	var data=xmlhttp.responseText.split("__");
	//document.getElementById("typeid").innerHTML=data[0];
	document.getElementById("ITEMSDETAILS").innerHTML=data[0];
	//document.getElementById("quotationType").value=data[2];
	////document.getElementById("quotationMailDate").value=data[3];
	document.getElementById("SERVICEDETAILS").innerHTML=data[1];
	}
	}
	xmlhttp.open("GET","CRM_GetLeadsRecordDirect.php?branch="+str,true);
	xmlhttp.send();
	
}
	</script>
<?php
	date_default_timezone_set('Asia/Kolkata');
	if(($_REQUEST['Save']))
	{
           
	$startYr = explode('-', $_SESSION['financialYrStart']);
		$endYr = explode('-', $_SESSION['financialYrEnd']);
		$startYr[0];
		$endYr[0];
		$financial=substr($startYr[0],-2)."-".substr($endYr[0],-2); 
	 
	 
	 if($_SESSION['dealerid'])
	 {
	 	$prefSql="select prefix_code from prefix_tbl where prefix_name = 'Order Management'";
		$resultPrfx = DB_query($prefSql,$db);
		$Prefxrow=DB_Fetch_array($resultPrfx);
		$prefixcode=$Prefxrow['prefix_code'];
		
		 $sql="select orderNo from salesorder where branch = '".$_REQUEST['Site']."' and dealerid='0' and CompanyId='".$_SESSION['ACGCompanyId']."' and INSTR(`orderNo`, '$financial') > 0 order by id DESC LIMIT 0,1";
		 
		$result = DB_query($sql,$db);
		$numrows = DB_num_rows($result);
		if($numrows>0)
		{
			$myrow=DB_Fetch_array($result);
			$ExplBill=explode("/",$myrow['orderNo']);
			 $maxval = $ExplBill[3]; 
		}
		else
		{$maxval=0;}
	 }
	 else
	 {
	 	$prefSql="select prefix_code from prefix_tbl where prefix_name = 'Order Management'";
		$resultPrfx = DB_query($prefSql,$db);
		$Prefxrow=DB_Fetch_array($resultPrfx);
		$prefixcode=$Prefxrow['prefix_code'];
		
		
	 	$sql="select orderNo from salesorder where branch = '".$_REQUEST['Site']."' and dealerid='0' and CompanyId='".$_SESSION['ACGCompanyId']."' and INSTR(`orderNo`, '$financial') > 0 order by id DESC LIMIT 0,1";
		$result = DB_query($sql,$db);
		$numrows = DB_num_rows($result);
		if($numrows>0)
		{
			$myrow=DB_Fetch_array($result);
			$ExplBill=explode("/",$myrow['orderNo']);
			$maxval = $ExplBill[3];
		}
		else
		{$maxval=0;}
	 }
	 

		$strChar=$_REQUEST['Site']."/".$prefixcode."/".$financial."/";
		$strFinal = $maxval+1;
		 $strBothFinal = $strChar.str_pad($strFinal,5,"0",STR_PAD_LEFT); 
                
                $prefix_sql=DB_query("Select prefix from locations where loccode='".$_REQUEST['Site']."'
	and CompanyId='".$_SESSION['ACGCompanyId']."' ",$db);
	$prefix_row=DB_fetch_array($prefix_sql);
	$branchPrefix=$prefix_row['prefix'];
	 $orderNo_sql="Select id,orderNo from salesorder where branch='".$_REQUEST['Site']."'
	 and CompanyId='".$_SESSION['ACGCompanyId']."'";
	$orderResult=DB_query($orderNo_sql,$db);
	if(DB_num_rows($orderResult)>0)
	{
		$GetMxSql=DB_query("SELECT orderNo AS MAXON FROM salesorder where branch='".$_REQUEST['Site']."'
		and CompanyId='".$_SESSION['ACGCompanyId']."' order by orderNo desc limit 0,1",$db);
		$GetMaxId=DB_fetch_array($GetMxSql);
		$MaxOrdNo=substr($GetMaxId['MAXON'],-2);
		$FinalMaxOrdNo=$MaxOrdNo+1;
		$GetMaxCN=DB_query("SELECT cost_center AS MAXCCN FROM salesorder where branch='".$_REQUEST['Site']."'
		and CompanyId='".$_SESSION['ACGCompanyId']."' order by cost_center desc limit 0,1",$db);
		$GetMaxCN1=DB_fetch_array($GetMaxCN);
		$MaxCCNO=substr($GetMaxCN1['MAXCCN'],-2);
		$FinalMaxCCNO=$MaxCCNO+1;
		$FinalOrdNo=$branchPrefix."/"."SO/".str_pad($FinalMaxOrdNo,5,"0",STR_PAD_LEFT);
		$FinalCostCeNo="CostCenter/".$branchPrefix."/".str_pad($FinalMaxCCNO,5,"0",STR_PAD_LEFT);
	}
	else
	{
		$FinalOrdNo=$branchPrefix."/SO/00001";
		$FinalCostCeNo="CostCenter/".$branchPrefix."/00001";
	}	
	
	$data['branch']=$_REQUEST['Site']; 
	$data['orderDate']=FormatDateForSQL($_REQUEST['TelephonicDate']);
	$data['orderNo']=$strBothFinal;
	$data['cost_center']=$FinalCostCeNo; 
	$data['client']=$_REQUEST['Client'];
	$data['Sale_Key_Exec']=$_REQUEST['Sale_Key_Exec'];  
	$data['PORefNo']=$_REQUEST['PONo']; 
	$data['Type']=$_REQUEST['type_id']; 
	$data['customerPODate']=FormatDateForSQL($_REQUEST['PODate']);  
	$data['SalesOrderType']='Direct';
	$data['quoteNo']=$_REQUEST['against_quots'];
	$data['DeliveryDate']=FormatDateForSQL($_REQUEST['DelieveryDate']);
	$data['RoadPermit']=$_REQUEST['RoadPermit'];
	$data['Transport']=$_REQUEST['Transport'];
	$data['freight']=$_REQUEST['freight'];
	$data['PendingPayment']=$_REQUEST['PendingPayment']; 
	$data['TelStatus']=$_REQUEST['Status'];
	$data['ContactPerson']=$_REQUEST['contact_person'];
        $data['quotationType']=$_REQUEST['quotationType'];
        
	//Service Tax
	$data['basicAmountSer']=$_REQUEST['basicAmountSer'];
	$data['EDBillRate']=$_REQUEST['EDBillRate'];
	$data['totalDiscountedPrice']=$_REQUEST['totalDiscountedPrice'];
	$data['ECessPercentage']=$_REQUEST['ECessPercentage'];
	$data['ECessValue']=$_REQUEST['ECessValue'];
	$data['SAHCessPercentage']=$_REQUEST['SAHCessPercentage'];
	$data['SAHCessValue']=$_REQUEST['SAHCessValue'];
	$data['taxableAmount']=$_REQUEST['taxableAmount'];
	$data['VatCst']=$_REQUEST['VatCst'];  
	$data['VatCstValue']=$_REQUEST['VatCstValue'];  
	$data['sales_tax_taxabelamt']=$_REQUEST['total_taxable_amt'];
	$data['roundOffSer']=$_REQUEST['roundOffSer'];
	$data['pluMinSer']=$_REQUEST['pluMinSer'];  
	$data['grandTotal']=$_REQUEST['grandTotalSer']; 

	// supply tax
	$data['basicAmountSup']=$_REQUEST['basicAmountSup'];
	$data['pkgPrc']=$_REQUEST['pkgPrc'];
	$data['pkgCharg']=$_REQUEST['pkgCharg'];
	$data['EDBillRateSup']=$_REQUEST['EDBillRateSup']; 
	$data['totalDiscountedPriceSup']=$_REQUEST['totalDiscountedPriceSup'];
	$data['ECessPercentageSup']=$_REQUEST['ECessPercentageSup'];
	$data['ECessValueSup']=$_REQUEST['ECessValueSup'];
	$data['SAHCessPercentageSup']=$_REQUEST['SAHCessPercentageSup']; 
	$data['SAHCessValueSup']=$_REQUEST['SAHCessValueSup'];
	$data['taxableAmountSup']=$_REQUEST['taxableAmountSup'];
	$data['VatCstSup']=$_REQUEST['VatCstSup'];
	$data['VatCstValueSup']=$_REQUEST['VatCstValueSup'];   
	$data['total_taxable_amt_Sup']=$_REQUEST['total_taxable_amt_Sup'];
	$data['freight_Sup']=$_REQUEST['freight_Sup'];
	$data['handCharges_sup']=$_REQUEST['handCharges_sup'];
	$data['miscCharge_sup']=$_REQUEST['miscCharge_sup'];  
	$data['roundValSup']=$_REQUEST['roundValSup'];
	$data['pluMinSup']=$_REQUEST['pluMinSup'];
	$data['grandTotalSup']=$_REQUEST['grandTotalSup'];
	$data['termsid']=$_REQUEST['Sales_Terms'];
        $data['otherTerms']=$_REQUEST['otherTerms'];
        $data['dealerid']=$_SESSION['dealerid'];
	$data['createdBy']=$_SESSION['UserID'];
	$data['CompanyId']=$_SESSION['ACGCompanyId'];
	//$data['hrdtotalAmt']=$_REQUEST['hrdtotalAmt'];
	$data['cate']=$_REQUEST['cate'];
	//echo "<pre>";
	//print_r($data);
	$data['quotation_site']=$_REQUEST['consignee_id'];
	$data['createdDate']=date("Y-m-d H:i:s");
        $data['poid']=$_REQUEST['poid'];
        
	$s->RecordInsert('salesorder', $data);
	$SalesId=DB_Last_Insert_ID($db,'salesorder','id');
        
        if(isset($SalesId))
	{
		for($cnt=0;$cnt<count($_REQUEST['item_id']);$cnt++)
		{	
			if($_REQUEST['item_id'][$cnt]!=''){
                         
			$dataArr['masterId']=$SalesId;
			$dataArr['ItemCode']=$_REQUEST['item_code'][$cnt];
			$dataArr['size']=$_REQUEST['size'][$cnt];
			$dataArr['grade']=$_REQUEST['grade'][$cnt];
			$dataArr['Quantity']=$_REQUEST['stock_qty'][$cnt];
			$dataArr['Amount']=$_REQUEST['stock_price'][$cnt];
			$dataArr['PerUnits']=$_REQUEST['stock_perunit'][$cnt];
			$dataArr['totalValue']=$_REQUEST['stock_value'][$cnt];
			$dataArr['DiscountType']=$_REQUEST['PerAmoSupply'][$cnt];
			$dataArr['discount_per']=$_REQUEST['DiscountSuply'][$cnt];
			$dataArr['after_dis']=$_REQUEST['perc'][$cnt];
			$dataArr['stock_value']=$_REQUEST['value_dis_supply'][$cnt];
			$dataArr['requisitionDate']=date('Y-m-d');
			$dataArr['est_qty_prm_sec']=$_REQUEST['qtytype'][$cnt];
			$dataArr['secondary_qty']=$_REQUEST['secondary_qty'][$cnt];
			$dataArr['item_id']=$_REQUEST['item_id'][$cnt];
			$dataArr['item_name']=$_REQUEST['item_name'][$cnt];
			$dataArr['infFactor']=$_REQUEST['infFactor'][$cnt];
			$dataArr['total_stock']=$_REQUEST['total_stock'][$cnt];
			$data_arr['ApprovalStatus']="1";			
			$s->RecordInsert('salesorder_details',$dataArr);
			}
          
		}
		
		
			/*for($cnt1=0;$cnt1<count($_REQUEST['act_id']);$cnt1++)
			{	
				if($_REQUEST['act_id'][$cnt1]!=''){
				$dataArr2['parent_id']=$SalesId;
				$dataArr2['act_id']=$_REQUEST['act_id'][$cnt1];
				$dataArr2['act_name']=$_REQUEST['act_name'][$cnt1];
				$dataArr2['act_code']=$_REQUEST['act_code'][$cnt1];
				$dataArr2['act_unit']=$_REQUEST['act_unit'][$cnt1];
				$dataArr2['act_rate']=$_REQUEST['act_rate'][$cnt1];
				$dataArr2['act_qty']=$_REQUEST['act_qty'][$cnt1];
				$dataArr2['total_amt']=$_REQUEST['total_amt'][$cnt1];
				$dataArr2['Discount']=$_REQUEST['Discount'][$cnt1];
				$dataArr2['PerAmo']=$_REQUEST['PerAmoSer'][$cnt1];
				$dataArr2['value_dis']=$_REQUEST['value_dis'][$cnt1];
				$dataArr2['ApprovalStatus']="1";
				//echo "<pre>";
				//print_r($dataArr);
				
				$s->RecordInsert('salesorder_service_details',$dataArr2);
				}
			}
		
		
		for($k=0;$k<count($_REQUEST['Terms_Condition']);$k++)
	    {
		$dataterm['parant_id']=$SalesId;
		$dataterm['termsid']=$_REQUEST['terms'][$k];
		$dataterm['condid']=$_REQUEST['Terms_Condition'][$k];
		$dataterm['frm_id']=$_REQUEST['frmid'];
		$dataterm['company_id']=$_SESSION['ACGCompanyId'];
		$dataterm['type']="Order";
		$s->RecordInsert('quotation_terms_cond', $dataterm);
	   }
		
		for($z=0; $z<count($_REQUEST['hrditemid']);$z++)
		{
		//if($_REQUEST['addhrdAmt'][$z]!='0')
		//$cnt=1;
		//else
		$cnt=$_REQUEST['addhrdAmt'][$z];
		
		$hrddata['parant_id']=$SalesId;
		$hrddata['hardwarepart']=$_REQUEST['hardwarepart'][$z];
		$hrddata['itemCode']=$_REQUEST['hrditemid'][$z];
		$hrddata['quantity']=$_REQUEST['hrd_qty'][$z];
		$hrddata['price']=$_REQUEST['hrd_price'][$z];
		$hrddata['PerUnits']=$_REQUEST['hrd_perunit'][$z];
		$hrddata['totalValue']=$_REQUEST['hrd_value'][$z];
		$hrddata['discount_type']=$_REQUEST['hrdPerAmo'][$z];
		$hrddata['discount_per']=$_REQUEST['hrdDiscount'][$z];
		$hrddata['after_dis']=$_REQUEST['hrdperc'][$z];
		$hrddata['stock_value']=$_REQUEST['hrdvalue_dis'][$z];
		$hrddata['isChecked']=$cnt;
		
		//echo "<pre>";
		//print_r($hrddata);
		$s->RecordInsert('salesorder_hardware_items',$hrddata);
		
		}*/
		
		
		
	}
	if(isset($SalesId))
	{
		$sql_comment="insert into salesorder_comments set
		sopno='".$SalesId."',
		user='".$_SESSION['UserID']."',
		comment='".$_REQUEST['comt']."',
		posted_date=now()";
		if($_REQUEST['comt']!='')
		{
		$res_comment=DB_query($sql_comment,$db);
		}			  
	}
	//$update=DB_query("update quotation set ConvertIntoSales='Y' where id='".$_REQUEST['against_quots']."'",$db);
        DB_query("update direct_po set sostatus='1' where id='".$_REQUEST['poid']."' ",$db);
         $frm= $s->getField('modules_form','frm_url','CRM/ViewSalesOrder','id'); 
          
	echo "<script>location.href='index.php?route=CRM/ViewSalesOrder&modid=".$_REQUEST['modid']."&frmid=".$frm."'</script>";
	//prnMsg( _('Sales Order inserted successfully'),'success');
	}
?>
<script type="text/javascript">

function validation()
{
if(document.getElementById('Site').value=='0')
{alert('Please Select a branch');
document.getElementById('Site').focus();
return false;
}
if(document.getElementById('dealer').value=='')
{alert('Please Select a Delear');
document.getElementById('dealer').focus();
return false;
}
	
if(document.getElementById("TelephonicDate").value=='')
{
alert('Please enter the memo date');
document.getElementById('TelephonicDate').focus();
return false;
}

if(document.getElementById('po_no').value==''){
alert('PO No cannot be empty');
document.getElementById('po_no').focus();
return false;
}
	
if(document.getElementById('Client').value=='0'){
alert('Please choose a client');
document.getElementById('Client').focus();
return false;}
	
if(document.getElementById('Sale_Key_Exec').value=='0'){
alert('Please choose a Sales Executive');
document.getElementById('Sale_Key_Exec').focus();
return false;}


if(document.getElementById('PODate').value==''){
alert('Please enter PO Date');
document.getElementById('PODate').focus();
return false;
}

if(document.getElementById('cat').value=='0'){
alert('Please choose a category');
document.getElementById('cat').focus();
return false;}		
		
if(document.getElementById('basicAmount').value==''){
alert('Basic Amount cannot be empty');
document.getElementById('basicAmount').focus();
return false;
}
	
if(document.getElementById('taxableAmount').value==''){
alert('Taxable AMount cannot be empty');
document.getElementById('taxableAmount').focus();
return false;
}

if(document.getElementById('grandTotal').value==''){
alert('Grand Total cannot be empty');
document.getElementById('grandTotal').focus();
return false;
}
return true;
}	

function getContactName(str)
{
	
if(str.length==0)
{
	document.getElementById("ContactName").innerHTML="";
	return;
	
}
if(window.XMLHttpRequest)
{
	xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp	=new ActiveXobject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
	if(xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	  	
		document.getElementById("ContactName").innerHTML=xmlhttp.responseText;
 	}
 }
xmlhttp.open("GET","getContact.php?Client="+str,true);
xmlhttp.send();	
	
	
} 
function getPhoneNo(str)
{
	
if(window.XMLHttpRequest)
{
	xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp	=new ActiveXobject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
	if(xmlhttp.readyState==4 && xmlhttp.status==200)
	{
		document.getElementById("PhoneNo").value=xmlhttp.responseText;
		
	}
	
}
xmlhttp.open("GET","getPhone.php?Contact="+str,true);
xmlhttp.send();	
	
	
} 
function openPopupProfile2()
{
	window.open("TelephonicItems.php?modid=<?php echo $_REQUEST['modid']?>&frmid=<?php echo $_REQUEST['frmid']?>");
}
function calculateTotalAmt(val,id)
{
		var id_brk=id.split('_');
		var i=id_brk[1];
		if(id_brk.length>1)
		{
			var qty=document.getElementById("qty_"+i).value;
			var tot_amt=qty*val;
			document.getElementById("totalamt_"+i).value=tot_amt.toFixed(2);
		}
		else
		{
			var qty=document.getElementById("qty").value;
			var tot_amt=qty*val;
			document.getElementById("totalamt").value=tot_amt.toFixed(2);
		}
}

function calassprice(val,id)
{
	
		var id_brk=id.split('_');
		var i=id_brk[1];
		if(id_brk.length>1)
		{
			
			var tot_amt=(70*val)/100;
			document.getElementById("ass_price_"+i).value=tot_amt.toFixed(2);
		}
		else
		{
			
			var tot_amt=(70*val)/100;
			document.getElementById("ass_price").value=tot_amt.toFixed(2);
		}
}

function calass_amount(id)
{
	var id_brk=id.split('_');
		var i=id_brk[1];
		if(id_brk.length>1)
		{ 
			
			var qty=document.getElementById("qty_"+i).value;
			var ass_value=document.getElementById("ass_price_"+i).value;
			var tot_amt=ass_value*qty;
			document.getElementById("totalassamt_"+i).value=tot_amt.toFixed(2);
		}
		else
		{
			
			var qty=document.getElementById("qty").value;
			var ass_value=document.getElementById("ass_price").value;
			var tot_amt=ass_value*qty;
			
			document.getElementById("totalassamt").value=tot_amt.toFixed(2);
		}
	
}

function calculateEDAmt(i)
{

    
 		
	var EDRate = document.getElementById("EDRate_"+i).value;
	alert("EDRate");
	if(EDRate=='0')
	{
		
		//var stock_price = document.getElementById("stock_qty_"+i).value;
		//alert(stock_price);
		document.getElementById("EDAmt_"+i).value='0.00';
		
	}
	else{
		
	
	 
 	var stock_price = document.getElementById("stock_qty_"+i).value;
 
	var EDAmt=((parseFloat(EDRate)*parseFloat(stock_price) )/100);
 	 document.getElementById("EDAmt_"+i).value=EDAmt.toFixed(2);
 	}
	 
 
}


function calculateBasic()
{
	var totalBasic=0;
	var first_row=document.getElementById("totalamt").value;
	//if(first_row==''){first_row=0;}
	var cnt=document.getElementById("hiditemcount").value;
	var newcount=parseInt(cnt)+1;
	for(var i=1;i<newcount;i++)
	{
	 	var totalBasic1=document.getElementById("totalamt_"+i).value;
	 	var totalBasic=(parseFloat(totalBasic)+parseFloat(totalBasic1)).toFixed(2);
	}
	  document.getElementById("basicAmount").value=parseFloat(totalBasic)+parseFloat(first_row);
}

function calculateDiscounted()
{
	var totalDiscounted=0;
	var cnt=document.getElementById("hiditemcount").value;
       for(var i=0;i<cnt;i++)
      {
 	    var totalDiscounted1=document.getElementById("EDAmt_"+i).value;
 	    
 	    var totalDiscounted=(parseFloat(totalDiscounted)+parseFloat(totalDiscounted1)).toFixed(2);
  	 }
	 if(totalDiscounted1!=='0')
	 {
 	document.getElementById("totalDiscountedPrice").value=totalDiscounted;
	}
	else{
		var total=document.getElementById("basicAmount").value;
		
		var Edrate=document.getElementById("EDRate_"+i).value;
		var discountEdrate=((parseFloat(Edrate)*parseFloat(total) )/100);
		document.getElementById("totalDiscountedPrice").value=discountEdrate.toFixed(2);
	}
}

function calculateECess()
{
	var exciseValue=document.getElementById("totalDiscountedPrice").value;
	var ECessPercentage=document.getElementById("ECessPercentage").value;
	var total=exciseValue*(ECessPercentage/100);
	document.getElementById("ECessValue").value=total.toFixed(2);
}

function calculateSAHCess()
{
	var exciseValue=document.getElementById("totalDiscountedPrice").value;
	var SAHCessPercentage=document.getElementById("SAHCessPercentage").value;
	var total=exciseValue*(SAHCessPercentage/100);
	document.getElementById("SAHCessValue").value=total.toFixed(2);
}
function calculateTaxable()

{
	var Basic=document.getElementById("basicAmount").value;
	var totalDiscountedPrice=document.getElementById("totalDiscountedPrice").value;
	
	
	var ECessValue=document.getElementById("ECessValue").value;
	var SAHCessValue=document.getElementById("SAHCessValue").value;
	
	
	
	if(totalDiscountedPrice==''){totalDiscountedPrice=0;}
	
	if(ECessValue==''){ECessValue=0;}
	if(SAHCessValue==''){SAHCessValue=0;}
	
	var TOTAL=parseFloat(totalDiscountedPrice)+parseFloat(ECessValue)+parseFloat(SAHCessValue)+parseFloat(Basic);
	document.getElementById("taxableAmount").value=TOTAL.toFixed(2);
}




 </script>
<!--<blockquote>&nbsp;</blockquote> -->
<div class="body_contain">
<h1><?php echo $title; ?></h1>
<div class="insideclass">
<div style="z-index:-1000em;">
<div class="demo">
<div id="tabs">
<!--<ul>
<li><a href="#tabs-1">Order Details</a></li>
<li><a href="#tabs-2">More Information</a></li>
</ul> -->

<?php 
$podet=DB_fetch_assoc(DB_query("select * from direct_po where id='".$_REQUEST['poid']."'",$db));
?>
<div id="tabs-1">
<div class="tab_div">
<form action="" method="post" onsubmit="return validation();">
<div id="InfluDispaly2" style="display:none;background-color:#ffffff; cursor:pointer; height:100px; background:#CCCCCC; overflow:auto; width:150px;border:1px #666666 solid; position:absolute; top:630;"></div>
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr class="row1">
      <td class="tabledata1" width="210">Branch</td>
      <td class="tabledata1" style="padding-left:0px;"><select style="width:200px;" name="Site" id="Site"  <!--onchange="showstorecode(this.value)"-->  >
          <?php
					$SQL="Select * from locations where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in ('".$_SESSION['AssignedBranch']."') ";
					$Res=DB_query($SQL,$db);
					while($Row=DB_fetch_array($Res))
					{
					
					?>
          <option value="<?php echo $Row['loccode']?>"<?php echo($_SESSION['Site']==$Row['loccode'] ? 'selected':'');?> ><?php echo $Row['locationname']?></option>
          <?php  } ?>
      </select></td>
	  <td width="13%"><span class="tabledata1">SOP No
          <label><font color="#FF0000">*</font></label>
	  </span></td>
	  <td width="20%"><div id="orderid"><input type="text" name="orderNo" id="orderNo" value="<?php  if($_REQUEST['orderNo']=='') echo "Auto Generated"; else $_REQUEST['orderNo'] ;?>" style="width:180px;" readonly="" /></div></td>
      <td class="tabledata1">Date
        <label><font color="#FF0000">*</font></label></td>
      <td class="tabledata1"><div id="dealer">
          <input type="text" name="TelephonicDate" id="TelephonicDate" value="<?php if(isset($_SESSION['Telephonic'])){echo $_SESSION['TelephonicDate'];}else {echo date('d/m/Y');}?>"  class="datepicker" style="width:180px;" />
      </div></td>
    </tr>
    
    <tr class="row1">
      <td class="tabledata1"><label>Client</label></td>
      <td><select style="width:200px;" name="Client" id="Client" onchange="showrecords(this.value)">
		  <option value="<?php echo $podet['dealerid'];  ?>"><?php echo $s->getField('dbl_dealer','id',$podet['dealerid'],'dealer_name'); ?></option>
        </select></td>
      <!--<td  class="tabledata1">Consignee</td>
      <td><select name="select" style="width:180px;">
        <option>Select</option>
      </select>          </td>-->
        <?php  $types=$s->getField('direct_po','id',$_REQUEST['poid'],'type');
       echo $s->getField('direct_po','id',$_REQUEST['poid'],'soid');
       ?>
	<td width="13%" align="left" valign="top" class="tabledata1">Type of Order<font color="#FF0000">*</font></td>
<td width="20%" align="left" valign="top" class="tabledata1"><?php if($types=='direct') { ?><select disabled title="Direct PO" name="quotationType" style="width:180px;" onchange="GetTables(this.value)">	
	<option value="<?php echo $s->getField('salesorder','id',$s->getField('direct_po','id',$_REQUEST['poid'],'soid'),'quotationType');  ?>"><?php echo $s->getField('salesorder','id',$s->getField('direct_po','id',$_REQUEST['poid'],'soid'),'quotationType');  ?></option>
</select>
    <?php } else { ?>
    <select  name="quotationType" style="width:180px;" onchange="GetTables(this.value)">	
	<option value="<?php echo $s->getField('salesorder','id',$s->getField('direct_po','id',$_REQUEST['poid'],'soid'),'quotationType');  ?>"><?php echo $s->getField('salesorder','id',$s->getField('direct_po','id',$_REQUEST['poid'],'soid'),'quotationType');  ?></option>
</select><?php } ?></td>
    </tr>
    <tr  class="row1">
      <td class="tabledata1">Cost Center </td>
      <td><input type="text" name="cost_center" id="cost_center" value="Auto Generated" style="width:200px;" readonly="" /></td>
      <td class="tabledata1">Contact Person</td>
      <td id="ContactPerson"><select style="width:180px;" name="contact_person" onchange="javascript:get_mobile_num(this.value)"><option>--Select--</option>
          <?php 
          echo $contactQry="SELECT * FROM dbl_dealer_contact_information_maste where master_code='".$podet['dealerid']."' and person!=''";
          $consql=DB_query($contactQry,$db);  while($conres=DB_fetch_assoc($consql)){ ?>
              <option value="<?php echo $conres['id']; ?>"><?php echo $conres['person']; ?></option>
              <?php } ?>
          </select> </td>
	  <td><span class="tabledata1" style="width:200px;">Phone No</span></td>
	  <td class="tabledata1"><input id="PhoneNo" name="PhoneNo" value="" style="width:180px;" readonly="true" /></td>
    </tr>
    <tr class="row1">
      <td class="tabledata1">Address</td>
      <td style="width:283px;" id="add1"><input type="text" readonly  style="width:200px;" id="Address1" name="Address1"  value="<?php echo $s->getField('dbl_dealer','id',$podet['dealerid'],'pin_no');  ?>"/></td>
      <td class="tabledata1" style="width:200px;">Address </td>
      <td id="Address2"><input type="text" name="Address2" readonly style="width:180px;" id="Address2" value="<?php echo $s->getField('dbl_dealer','id',$podet['dealerid'],'pre_address1');  ?>" /></td>
      <td class="tabledata1">Category
        <label><font color="#FF0000">*</font></label></td>
	  <td class="tabledata1">
              <?php if($types=='direct') { ?><select name="cate" title="Direct PO" disabled id="cat" style="width:180px;">
        <option value="<?php echo $s->getField('salesorder','id',$s->getField('direct_po','id',$_REQUEST['poid'],'soid'),'quotationType');  ?>"><?php echo $s->getField('salesorder','id',$s->getField('direct_po','id',$_REQUEST['poid'],'soid'),'cate');  ?></option>
      </select>
              <?php } else { ?>
              <select name="cate"  id="cat" style="width:180px;">
        <option value="<?php echo $s->getField('salesorder','id',$s->getField('direct_po','id',$_REQUEST['poid'],'soid'),'quotationType');  ?>"><?php echo $s->getField('salesorder','id',$s->getField('direct_po','id',$_REQUEST['poid'],'soid'),'cate');  ?></option>
      </select>
              <?php } ?></td>
    </tr>
    
    <tr class="row1">
      <td class="tabledata1">Client P.O. No.
        <label><font color="#FF0000">*</font></label></td>
      <td><input type="text" name="PONo" id="po_no" style="width:200px;" readonly  value="<?php echo $s->getField('direct_po','id',$podet['id'],'pr_no'); ?>" /></td>
      <td class="tabledata1">P.O. Date
        <label><font color="#FF0000">*</font></label></td>
      <td><input type="text" name="PODate" id="PODate" style="width:180px;" class="" readonly value="<?php  echo ConvertSQLDate($podet['pr_date']); ?>" /></td>
	  <td><span class="tabledata1">Delivery Date</span></td>
	  <td class="tabledata1"><input type="text" name="DelieveryDate" id="DelieveryDate" style="width:180px;" class="" value="<?php  echo ConvertSQLDate($podet['delivery_date']); ?>" readonly /></td>
    </tr>
    <tr class="row1">
      <td class="tabledata1">Transport</td>
      <td><select style="width:200px;" name="Transport">
        <option value="0">--Select--</option>
        <?php
        if($_SESSION['dealerid'])
	 {
	$SQL="Select * from transport_master where CompanyId='".$_SESSION['ACGCompanyId']."' and dealerid='".$_SESSION['dealerid']."'";
         }
         else
         {
         $SQL="Select * from transport_master where CompanyId='".$_SESSION['ACGCompanyId']."' and dealerid='0'";    
         }
	$Res=DB_query($SQL,$db);
	while($Row=DB_fetch_array($Res))
	{					
	?>
        <option value="<?php echo $Row['id']?>" <?php echo($_SESSION['Transport']==$Row['id']?'selected':'' );?>  ><?php echo $Row['TransportName']?></option>
        <?php  } ?>
      </select></td>
      <td class="tabledata1">Road Permit</td>
      <td><input name="RoadPermit" type="text"   style="width:180px;"   value="<?php echo $_SESSION['RoadPermit']?>"  /></td>
	  <td><span class="tabledata1">Freight Type</span></td>
	  <td class="tabledata1"><select style="width:180px;" name="freight">
        <option value="0">Select</option>
        <option value="Paid">Paid</option>
        <option value="topay">To Pay</option>
        <option value="Nill">Nill</option>
      </select></td>
    </tr>
    
    <tr class="row1">
      <td class="tabledata1">Sales Executive<font color='red'>*</font></td>
      <td><?php 
	//echo "SELECT id FROM deptmaster WHERE deptcode='MKT' OR deptcode='sal'";
	//$Dept=DB_query("SELECT id FROM deptmaster WHERE deptcode='MKT' OR deptcode='sal'",$db);
	//if(DB_num_rows($Dept)>0)
	//{
	//while($DeptRow=DB_fetch_array($Dept))
	//{
	//$DCode[]=$DeptRow['id'];
	//}
	//$Dept_id=implode(',',$DCode);
	$Sale_key_Exe=DB_query("select realname from www_users where companyid='".$_SESSION['ACGCompanyId']."' and id ='".$_SESSION['UserID']."'",$db);
	$Sale_keyRow=DB_fetch_array($Sale_key_Exe);
	?>
          <!--<select name="Sale_Key_Exec" id="Sale_Key_Exec" style="width:180px;">
            <option value="0">Select</option>
            <?php //while($Sale_keyRow=DB_fetch_array($Sale_key_Exe))
	//{
	?>
            <option value="<?php echo $Sale_keyRow['id'] ?>"<?php echo ($_SESSION['Sale_Key_Exec']==$Sale_keyRow['id']?'selected':'')?>><?php echo $Sale_keyRow['userid']; ?></option>
            <?php// } }?>
          </select>  -->  <input type="text" name="Sale_Key_Exec" id="Sale_Key_Exec" style="width:200px;" readonly  value="<?php echo $Sale_keyRow['realname']; ?>" />  </td>
		  <td>&nbsp;</td>
	      <td>&nbsp;</td>
	      <td class="tabledata1"></td>
      <td></td>
    </tr>
    
	<tr class="row1">
      <!--<td class="tabledata1">Pending Payments (if any)</td>-->
     <td class="tabledata1">Subject</td>
      <td colspan="5"><textarea name="PendingPayment" id="PendingPayment" style="width:100%; height:60px;"><?php echo $_SESSION['PendingPayment'];?></textarea></td>
	  </tr>
	</table>
<div id="ITEMSDETAILS" style="width:100%; overflow:auto;">
    
    <table width="100%" border="0" cellspacing="0" cellpadding="3">
		<tr class="row1">
    		<td colspan="8"><h3 style="color:#003399"> Product Information</h3></td>
  		</tr>
  </table> 

<div id="InfluDispaly2" style="display:none;background-color:#ffffff; cursor:pointer; width:150px;border:1px #666666 solid; position:absolute; top:800;"></div>
<table align="center" width="100%;" border="1"  cellpadding="2" cellspacing="0">
<tr class="row1">
	<th class="tabledata" width="3%">Sr. No.</th>
	<th  class="tabledata" width="1%">&nbsp;</th>
    <th class="tabledata" width="7%">Item Code</th>
    <th  class="tabledata" width="7%">Item Name</th>
   <!-- <td  class="tabledata" width="9%">Influencing Factor</td>-->
	<blockquote>&nbsp;</blockquote>
	<th  class="tabledata" width="20%" colspan='5' style="text-align:center;">Quantity</th>
   	<!--<td  class="tabledata" width="8%">Primary Unit</span></td>
	<td colspan="2" class="tabledata" style="text-align:center;" width="120">Secondary Quantity</td>
	<td  class="tabledata" width="10%">Secondary Unit</span></td>-->
	<th class="tabledata" width="7%">Price</th>
    <th  class="tabledata"  width="7%">Value</th>
	<th class='tabledata' colspan='2' width='10%'>Discount</th>
	<th class='tabledata' width="8%">Discounted Amt</th>
    <th  class="tabledata" width="8%">Balance Stock </th>
	
</tr>
<tbody id="dataTable">
    <?php 
    $itemDetailsQry="select * from direct_po_details where parent_id='".$_REQUEST['poid']."'";
    $itm_det=DB_query($itemDetailsQry,$db); 
    $i=0;
    while($itm_res=DB_fetch_assoc($itm_det))
    { 
        $i++;
        $dis_amt=$itm_res['basic'];
$confact=$s->getField('item_master','id',$itm_res['mst_itemid'],'conv_factor');?>
<tr class="row1">
<td style="white-space:nowrap;" class="tabledata"><?php echo $i.'. '; ?></td>	
<td class="tabledata"><input type="hidden" name="item_id[]" value="<?php echo $itm_res['mst_itemid']; ?>" id="itemid" /></td>

<td class="tabledata"><input type="text" name="item_code[]" id="itemcode" value="<?php  echo $s->getField('item_master','id',$itm_res['mst_itemid'],'StockID');?>" style="width:100%;" readonly/></td>

<td class="tabledata" style="white-space:nowrap"><input type="text" name="itemname[]" value="<?php  echo $s->getField('item_master','id',$itm_res['mst_itemid'],'item_name');?>" id="itemname" style="width:100%;" readonly/></td>

<!--<td class="tabledata" style="white-space:nowrap"><input type="text" name="infFactor[]" value="" autocomplete="off" id="infFactor" style="width:100%;" onkeyup="GetInfluFactor2(this.value,this.id)" />
</td>-->

<td class="tabledata"><input type="text" name="stock_qty[]" autocomplete="off"  id="stock_qty" style="width:100%;" value="<?php echo $itm_res['qty']; ?>"  /></td>

<td class="tabledata" style="white-space:nowrap"><input type="text" name="unit[]" value="<?php  echo $s->getField('unitsofmeasure','unitid',$s->getField('item_master','id',$itm_res['mst_itemid'],'mst_unitid'),'unitname');?>" id="unit" style="width:100%;" readonly/></td>

<td class="tabledata"><input type="hidden" name="conv_fac" id="convfact" /></td>

<td class="tabledata"><input type="text" name="secondary_qty[]" value="<?php echo  $sec_qty=$confact * $itm_res['qty']  ?>" autocomplete="off"  id="secondary_qty" style="width:100%;"/></td>

<td class="tabledata"><input type="text" name="secUnit[]" autocomplete="off" value="<?php  echo $s->getField('unitsofmeasure','unitid',$s->getField('item_master','id',$itm_res['mst_itemid'],'conv_unit'),'unitname');?>"  id="secUnit" style="width:100%;" readonly/></td>

<td class="tabledata"><input type="text" name="stock_perunit[]" autocomplete="off" value="<?php echo  $itm_res['rate'] ?>" id="stock_perunit" readonly style="width:100%;" /></td>

<td class="tabledata"><input type="text" readonly name="stock_value[]" autocomplete="off" value="<?php echo  $itm_res['amt'] ?>" id="stock_value" style="width:100%;"/></td>

<td class="tabledata"><input type="text" style="width:100%" autocomplete="off" value="<?php echo  $itm_res['dis_per'] ?>" readonly  name="DiscountSuply[]" id="Discount" /></td>

<td class="tabledata"><select style="width:60px;" name="PerAmoSupply[]" id="PerAmo" >
            <option value='PercentAmt'>%</option>
          </select></td>
		  
<td class='tabledata'><input type='text' style='width:100%' name='value_dis_supply[]' value="<?php echo $dis_amt ?>" id='value_dis'  readonly='true' /></td>

<td class="tabledata"><input type="text" name="total_stock[]" onchange="abc()" id="total_stock" style="width:100%;"  readonly="true" /></td>

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

<div style="width:100%; background:#e7e7e7;">
<div style="width:50%; margin-top:10px; overflow:auto; float:left;">
<table width="100%" cellpadding="3" cellspacing="0" border="0">
	<tr class="row1">
		<td align="center" style="text-align:;"> <strong>Terms and Conditions</strong> </td>
		<td  align="left" valign="top" >	
		<table width="100%" border="0" cellspacing="0" cellpadding="3" align="left">
			<tr class="row1">
				<td><select name="Sales_Terms" id="Sales_Terms_Condition" onchange="show_all_conditions(this.value)">
						<option value="">Select</option>
						<?php $SQLTERMS=DB_query("SELECT * FROM terms_and_conditions where parant_id='0' AND CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
						while($GetTerms=DB_fetch_array($SQLTERMS)){?>
						<option value="<?php echo $GetTerms['id']; ?>"><?php echo $GetTerms['terms_conditions']; ?></option>
						<?php }?>
				</select>
                              </td>
			</tr>
		</table>
		</td>
	</tr>
        <tr class="row1">
		<td colspan="2" align="left" valign="top" id="all_conditions" >	</td>
	</tr>
	<tr class="row1">
		<td colspan="2">
			<div id="tabs-2">
<div style="width:auto; background:#e7e7e7;">
<p style="margin:0px; padding:0px; text-align:left; font-weight:bold">Other Terms and Conditions</p>
<p style="margin:0px; padding:0px; text-align:left;">
<textarea name="otherTerms" style="width:100%;" ></textarea>
</p>
<p style="margin:0px; padding:0px; text-align:left; color:#003366">&nbsp;</p>
</div>
</div>
		</td>
	</tr>
		</table>
		</div>
<?php  $tot= $s->getField('direct_po','id',$_REQUEST['poid'],'grand_total');?>
<div id="SERVICEDETAILS" style="width:50%; margin-top:10px; overflow:auto; float:right;"><?php 
$data5.="<table width='100%' border='0' cellspacing='0' cellpadding='3' align='right'>";
			$data5.="<tr class='row1'>";
				$data5.="<td class='tabledata1' style='text-align:center;' colspan='4'><strong>Supply Taxes</strong></td>";
			$data5.="</tr>";
			$data5.="<tr class='row1'>";
					$data5.="<td class='tabledata1'>Basic Amount<label><font color='#FF0000'>*</font></label></td>";
					$data5.="<td colspan='3'><input name='basicAmountSup' readonly type='text' style='width:150px;' onfocus='calculateBasic()' value='".$tot."' id='basicAmount'/></td>";
			 $data5.="</tr>";
			$data5.="<tr class='row1'>";
					$data5.="<td class='tabledata1'>Packaging Charges</td>";
					$data5.="<td colspan='3'><input name='pkgPrc' type='text' style='width:50px;' value='0' onkeyup='calculatePakg(this.value)' id='pkgPrc'/><input readonly name='pkgCharg' readonly type='text' value='0.00' style='width:100px;' id='pkgCharg'/></td>";
			$data5.="</tr>";
			//$data5.="<tr class='row1'>";
					//$data5.="<td class='tabledata1'>Excise Duty</td>";
					//$data5.="<td colspan='3'>";
				 //$data5.="<select name='EDBillRateSup' id='EDRate' style='width:150px' onchange='calculateBillExcise21(this.value)'>";
				//$data5.="<option value='0'>--Select--</option>";
				//$ServiceSql="select * from  excise_tax WHERE caption LIKE '%excise%'" ;
				//$ServiceRes=DB_query($ServiceSql,$db);
				//while($ServiceRow=DB_fetch_array($ServiceRes))
				//{
				//$data5.="<option value='".$ServiceRow['id']."'>'".$ServiceRow['caption']."'</option>";
				//}
				//$data5.="</select>";							
				//$data5.="</td>";
			//	//$data5.="</tr>";
			//$data5.="<tr class='row1'>";
				    //$data5.="<td>Excise Amt </td>";
				    //$data5.="<td colspan='3'><input name='totalDiscountedPriceSup' readonly id='totalDiscountedPrice' 
				//type='text'  style='width:150px;' readonly onfocus='calculateTotalExcise()'/></td>";
			//$data5.="</tr>";
			//$cessSql=DB_query("Select caption from excise_tax where caption like '%cess%'",$db);
			//$k=1;
			//while($cessRow=DB_fetch_array($cessSql))
			//{
			//$caption[$k]=$cessRow['caption']; 
			
			//$rate_sql=DB_query("Select def_rate,id from excise_tax where caption='".$caption[$k]."'",$db);
			//while($rate_row=DB_fetch_array($rate_sql))
			//{
			//$rate[$k]=$rate_row['def_rate'];
			//$rate_id[$k]=$rate_row['id'];
			//}
			//$k++;
			//} 
			//$data5.="<tr class='row1'>";
					//$data5.="<td class='tabledata1'>E-Cess</td>";
					////$data5.="<td colspan='3'><input type='hidden' name='ecessidSup' value='".$rate_id[1]."'/><input name='ECessPercentageSup' id='ECessPercentage' type='text' value='".$rate[1]."' style='width:50px;' readonly /> <input name='ECessValueSup' id='ECessValue' type='text' value='".$ECessValue."' style='width:100px;' readonly />";						
					$data5.="</td>";
			//$data5.="</tr>";
			//$data5.="<tr class='row1'>";
					//$data5.="<td class='tabledata1' >SAH-E Cess </td>";
					//$data5.="<td colspan='3'><input type='hidden' name='sahecessidSup' value='".$rate_id[2]."' /><input name='SAHCessPercentageSup' id='SAHCessPercentage' type='text' value='".$rate[2]."' style='width:50px;' readonly/> <input name='SAHCessValueSup' id='SAHCessValue' type='text' value='".$SAHCessValue."' style='width:100px;' readonly />";					
					//$data5.="</td>";
			//$data5.="</tr>";
			$data5.="<tr class='row1'>";
			$data5.="<td class='tabledata1'>Taxable Amount<label><font color='#FF0000'>*</font></label></td>";
			$data5.="<td><input name='taxableAmountSup' readonly id='taxableAmount' type='text' value='".$tot."' style='width:150px;' readonly/></td>";
			$data5.="</tr>";
		 
			$data5.="<tr class='row1'>";
					$data5.="<td class='tabledata1'>Sales Tax (Taxable Amt) </td>";
					$data5.="<td>";
					$data5.="<select name='VatCstSup' id='value3' style='width:150px;' onchange='calculateVATCST(this.value)'>";
				$data5.="<option value=''>--Select--</option>";
				$salesSql=DB_query("Select * from sales_tax_master",$db);
				while($salesRow=DB_fetch_array($salesSql))
				{
				$data5.="<option value='".$salesRow['salestax_id']."'>'".$salesRow['tax_code']."'</option>";
				}
				$data5.="</select>";
				$data5.="<div id='VATId'><input name='VatCstValueSup' id='VatCstValue' type='text' value='".$VatCstValue."' style='width:150px;' readonly /></div>";
				$data5.="<input type='hidden' name='' id='rate' value='' /></td>";
			$data5.="</tr>";
				$data5.="<tr class='row1'>";
					$data5.="<td class='tabledata1'>Total Amt I </td>";
					$data5.="<td ><input type='text' name='total_taxable_amt_Sup' readonly id='total_taxable_amt' style='width:150px;' value='".$tot."' onfocus='calculatetaxable_tax()'/></td>";
					
				$data5.="</tr>";
				
				$data5.="<tr class='row1'>";
					$data5.="<td class='tabledata1'>Freight Amt </td>";
					$data5.="<td colspan='3'><input type='text' name='freight_Sup' id='freight' onkeyup='calculateGrandSup()'  style='width:150px;' /></td>";
				$data5.="</tr>";
				
				  $data5.="<tr class='row1'>";
					$data5.="<td class='tabledata1'>Handling Charges</td>";
					$data5.="<td><input name='handCharges_sup' id='handCharges' onkeyup='calculateGrandSup()' type='text' value='".$packagingCharges."' style='width:150px;' /></td>";
				$data5.="</tr>";
				$data5.="<tr class='row1'>";
					$data5.="<td class='tabledata1'>Misc. Charges</td>";
					$data5.="<td><input name='miscCharge_sup' id='miscCharge' onkeyup='calculateGrandSup()' type='text' style='width:150px;' /></td>";
					
				$data5.="</tr>";
				 $data5.="<tr class='row1'>";
					$data5.="<td class='tabledata1'>Round Off</td>";
					$data5.="<td colspan='3'><input name='pluMinSup' id='pluMin'  type='text' readonly='true' style='width:50px;' /> <input name='roundValSup' id='roundVal'  type='text' readonly='true' style='width:100px;' /></td>";
					
				$data5.="</tr>";
			$data5.="<tr class='row1'>";
					$data5.="<td class='tabledata1'>Grand Total<label><font color='#FF0000'>*</font></label></td>";
					$data5.="<td colspan='3'><input name='grandTotalSup' id='grandTotal' type='text'  style='width:150px;' onfocus='calculateGrandSup()' readonly='readonly' value='".$grandTotal."' /><input name='orig_grand_tot1' id='orig_grand_tot1' type='hidden' style='width:150px;'/></td>";
			  $data5.="</tr>";
			$data5.="</table>";
                        echo $data5;
?></div>

<div style="clear:both;"></div>
</div>

 <div style="clear:both;"></div>
 

<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr class="row1">
	<td colspan="11">
		<p align="center">
			<input type="submit" name="Save" value="SUBMIT" onclick="return confirm('ARE YOU WANT TO PROCEED?')" class="search" />
                    <input type="button" name="Cancel" value="CLOSE" class="search"  />
                    </a>           
		</p>
	
	</td>
</tr>
</table>
            <!-- Tab 2 Close -->
          </form>
		  </div>
 </div>
        </div>
      </div>
    </div>
  </div>
  <!-- inside div close -->
</div>
<!-- Main div close -->
<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;
		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;	
			}
		}
	}
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()
{

	if(document.getElementById("order_type").value=='')
	{
	alert("Must Select Order Type First");	
	}
	else
	{	
		window.open("directTelephonicItems.php?modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'] ?>&action=<?php echo $_REQUEST['action']?>","itempopup_window","height=500,width=600,left=1000,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");
	}
}

function calculateExcise(str,id)
{
	
	var id_brk=id.split('_');
	var i=id_brk[1];
	if(id_brk.length>1)
	{
		divid="excisevalue_"+i;
		var amount=document.getElementById("totalamt_"+i).value;
	}
	else
	{
		divid="excisevalue";
		var amount=document.getElementById("totalamt").value;
	}
	if(str.length==0)
	{
		document.getElementById(divid).value="";
		return;
	}
	if(window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest();
	}
	else
	{
		xmlhttp	=new ActiveXobject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if(xmlhttp.readyState==4 && xmlhttp.status==200)
	{
		document.getElementById(divid).value=xmlhttp.responseText;
		
	}
	
}
xmlhttp.open("GET","calculateExcise.php?type=TELORD&amount="+amount+"&q="+str,true);
xmlhttp.send();	
	} 
	
function calculateExcise1(str,id)	
{
var id_brk=id.split('_');
	var i=id_brk[1];
	if(id_brk.length>1)
	{
		divid="excisevalue_"+i;
		var amount=document.getElementById("totalassamt_"+i).value;
	}
	else
	{
		divid="excisevalue";
		var amount=document.getElementById("totalassamt").value;
	}
	if(str.length==0)
	{
		document.getElementById(divid).value="";
		return;
	}
	if(window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest();
	}
	else
	{
		xmlhttp	=new ActiveXobject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if(xmlhttp.readyState==4 && xmlhttp.status==200)
	{
		document.getElementById(divid).value=xmlhttp.responseText;
		
	}
	
}
xmlhttp.open("GET","calculateExcise.php?type=TELORD&amount="+amount+"&q="+str,true);
xmlhttp.send();	
	} 	
	
function calculateBillExcise21(str)
{
	var pkgCharges=document.getElementById("pkgCharg").value;
	if(pkgCharges=='') { pkgCharges=0; }
	var basicAmt=document.getElementById("basicAmount").value;
	if(basicAmt=='') { basicAmt=0; }
	var value=parseFloat(basicAmt)+parseFloat(pkgCharges);
	if(str.length==0)
	{
		document.getElementById("totalDiscountedPrice").innerHTML="";
		return;
	}
	if(window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest();
	}
	else
	{
	xmlhttp	=new ActiveXobject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if(xmlhttp.readyState==4 && xmlhttp.status==200)
	{
		var data=xmlhttp.responseText.split('__');
		document.getElementById("totalDiscountedPrice").value=data[0];
		document.getElementById("ECessValue").value=data[1];
		document.getElementById("SAHCessValue").value=data[2];
		document.getElementById("taxableAmount").value=data[3];
 	}
 }
xmlhttp.open("GET","calculateExcise.php?type=bill&id="+str+"&value="+value,true);
xmlhttp.send();	}
function calculateTotalExcise()
{
	var EDRate=document.getElementById("EDRate").value;
	if(EDRate==0){
	var totalExcise=0;
	var first_row=document.getElementById("excisevalue").value;
	//if(first_row==''){first_row=0;}
	var cnt=document.getElementById("hiditemcount").value;
	var newcount=parseInt(cnt)+1;
	for(var i=1;i<newcount;i++)
	{
	 	var totalExcise1=document.getElementById("excisevalue_"+i).value;
	 	var totalExcise=(parseFloat(totalExcise)+parseFloat(totalExcise1)).toFixed(2);
	}
	  document.getElementById("totalDiscountedPrice").value=parseFloat(totalExcise)+parseFloat(first_row);
	}
	else{return false;}
}

function calculateEditVATCST()
{
	var rate=document.getElementById("rate").value;
	var taxableAmount=document.getElementById("taxableAmount").value;
	var vat_cst=taxableAmount*(rate/100);
	document.getElementById("VatCstValue").value=vat_cst.toFixed(2);
}

/*function validate()
{
	if(document.getElementById("Site").value=='0')
	{alert('Please choose a branch before saving'); document.getElementById("Site").focus();  return false;}
	
	if(document.getElementById("orderNo").value=='')
	{alert('SOP No. cannot be empty'); document.getElementById("orderNo").focus(); return false;}
	
	if(document.getElementById("Client").value=='0')
	{alert('Please choose a client before saving'); document.getElementById("Client").focus(); return false;}
	
	if(document.getElementById("PONo").value=='')
	{alert('Client PO No. cannot be empty'); document.getElementById("PONo").focus(); return false;}
		
	return false;
}*/

function getorder(str)
{
	if(str!='Consolidate')
	document.getElementById("EDRate").setAttribute('disabled',true);
	else
	document.getElementById("EDRate").removeAttribute('disabled');
	if(str.length==0)
	{
	document.getElementById("showdata").innerHTML="";
	return;
	}
	if(window.XMLHttpRequest)
	{
	xmlhttp=new XMLHttpRequest();
	}
	else
	{
	xmlhttp	=new ActiveXobject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if(xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	document.getElementById("showdata").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","gettelephonicdata.php?id="+str,true);
	xmlhttp.send();
}

function showstore(str)
{

if(str.length==0)
  		{
  			document.getElementById("dealer").innerHTML="";
  			return;
  		}
		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("dealer").innerHTML=xmlhttp.responseText;
    		}
  		}
		xmlhttp.open("GET","dealercode.php?salesId="+str,true);
		xmlhttp.send();



}

function showstorecode(str)
{
	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("Client").innerHTML=xmlhttp.responseText;
	//document.getElementById("empdta").innerHTML=data[1];
	
	}
	}
	xmlhttp.open("GET","ajax_quotation.php?site="+str,true);
	xmlhttp.send();
}
function calcValue1(str,id)
{

	var brk=id.split('_');
	if(brk.length==1)
	{
	   if(parseFloat(str)>parseFloat(document.getElementById("total_stock").value))
	   {
	   alert("Qty Should be less or equal then Stock Qty");
	   document.getElementById("qty").value='';
	   return false;
	   }
       
	}
	else
	{
	  if(parseFloat(str)>parseFloat(document.getElementById("total_stock_"+brk[1]).value))
	   {
	   alert("Qty Should be less or equal then Stock Qty");
	   document.getElementById("qty_"+brk[1]).value='';
	   return false;
	   }
		
	}
}


function showrecords(str)
{
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)
	{
	var data=xmlhttp.responseText.split("__");	
	//alert(data[5]);
	document.getElementById("add1").innerHTML=data[0];
	document.getElementById("ContactPerson").innerHTML=data[1];
	document.getElementById("Address2").innerHTML=data[2];
	//document.getElementById("Telephone").innerHTML=data[3];
	document.getElementById("Address3").innerHTML=data[4];
	//document.getElementById("empdta").innerHTML=data[1];
	document.getElementById("consignee").innerHTML=data[5];
	document.getElementById("PhoneNo").value="";
	}
	}
	xmlhttp.open("GET","getContact_new.php?site="+str,true);
	xmlhttp.send();



}

function displayHardwareBox()
{
document.getElementById("showhardware").style.display='block';

}

function addRow1(tableID) 
{
	if(document)
	var table = document.getElementById(tableID);
	var rowCount = table.rows.length;
	var row = table.insertRow(rowCount);
	document.getElementById("hiditemcount1").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;	
	case "radio":
	newcell.childNodes[0].checked = false;
	var nod_id = newcell.childNodes[0].id;
	newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
	break;	
	
	}
	}
}

	
function getItemList(str,id)
{
	
	var id_brk=id.split('_');
	//alert(id_brk.length);
	if (str=="")
	{
		if(id_brk.length>1){document.getElementById("item_"+id_brk[1]).innerHTML="";}
		else{document.getElementById("item").innerHTML="";}
		return;
	} 
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			var data=xmlhttp.responseText;
			if(id_brk.length>1){document.getElementById("item_"+id_brk[1]).innerHTML=data;}
			else{
			document.getElementById("item").innerHTML=data;}
		}
		
		
	}
	xmlhttp.open("GET","get_item_list.php?i="+str,true);
	xmlhttp.send();
}


//***************************** checking data***************************//

function itemBomDetails(str,id)
{
	var id_brk=id.split('_');
	
	var size_array= new Array();
	var count_size=document.getElementById("hiditemcount").value;
	size_array[0]=document.getElementById("bomsize").value;
	for(var i=1; i<=count_size; i++)
	{
		size_array[i]=document.getElementById("bomsize_"+i).value;
	}
	
	alert(size_array);
	
	if (str=="")
	{
		if(id_brk.length>1){
		document.getElementById("basicrateA_"+id_brk[1]).value="";
		document.getElementById("uomA_"+id_brk[1]).value='';
		document.getElementById("asmbly_item_qtyA_"+id_brk[1]).value='';
		}
		else
		{		
		document.getElementById("basicrateA").value='';
		document.getElementById("uomA").value='';
		document.getElementById("asmbly_item_qtyA").value='';
		}
		return;
	} 
	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 data_brk=xmlhttp.responseText.split('__');
			

			if(id_brk.length>1)
			{	
			var totalamount=0;
			document.getElementById("basicrateA_"+id_brk[1]).value=data_brk[0];
			document.getElementById("uomA_"+id_brk[1]).value=data_brk[1];
			document.getElementById("asmbly_item_qtyA_"+id_brk[1]).value=data_brk[2];				
			}
			else
			{	
			var totalamount=0;		
			document.getElementById("basicrateA").value=data_brk[0];
			document.getElementById("uomA").value=data_brk[1];
			document.getElementById("asmbly_item_qtyA").value=data_brk[2];
			for(var k=0;k<count_size;k++)
			{
			if(document.getElementById("totalA_"+k).value!='')
			var amount=parseFloat(document.getElementById("totalA_"+k).value)+parseFloat(data3[k]);
			else
			var amount=parseFloat(data3[k]);	
			document.getElementById("asmbly_item_qtyA_"+k).value=data2[k];
			document.getElementById("asmbly_item_amtA_"+k).value=data3[k];
			document.getElementById("totalA_"+k).value=amount.toFixed(2);
			
			var subtotal_b=document.getElementById("total_hw_amt_id_"+k).value;
			if(subtotal_b==''){subtotal_b=0;}
			var totalAB=parseFloat(amount)+parseFloat(subtotal_b);
			document.getElementById("totalC_"+k).value=totalAB.toFixed(2);
			
			var subtotal_c=document.getElementById("totalC_"+k).value;
			if(subtotal_c==''){subtotal_c=0;}
			
			var totalqty=document.getElementById("totalqtyabc_"+k).value;
			if(totalqty==''){totalqty=0;}
			
			var totalABC=parseFloat(totalqty)*parseFloat(subtotal_c);
			document.getElementById("totalD_"+k).value=totalABC.toFixed(2);
			 totalamount=parseFloat(totalamount)+parseFloat(document.getElementById("totalD_"+k).value);
			
			}
			document.getElementById("entire_amt").value=totalamount.toFixed(2);

			}
			
			
		}
	}
	if(id_brk.length>1)
	var frame=document.getElementById("itemsubcat_"+id_brk[1]).value;
	else
	var frame=document.getElementById("itemsubcat").value;
	
	xmlhttp.open("GET","get_item_bomdetails_directorder.php?i="+str+"&frame="+frame+"&size="+size_array,true);
	xmlhttp.send();
	}


function showconvac(str,id)
{
var brk=id.split('_');

if(str=='0')
{

if(brk[1]==undefined)
{
var conf=document.getElementById('conf').value;
	document.getElementById("conv_fac").value=conf;
	}
	else
	{
	var conf=document.getElementById('conf_'+brk[1]).value;
	document.getElementById("conv_fac_"+brk[1]).value=conf;
	}
}
else
{
var brk=id.split('_');

 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)
	{
	if(brk[1]==undefined)
	document.getElementById("conv_fac").value=xmlhttp.responseText;
	else
	document.getElementById("conv_fac_"+brk[1]).value=xmlhttp.responseText;
	//document.getElementById("empdta").innerHTML=data[1];
	
	}
	}
	if(brk[1]==undefined)
	{
	var str2=document.getElementById("itemid").value;
	}
	else
	{
	var str2=document.getElementById("itemid_"+brk[1]).value;
	}
	xmlhttp.open("GET","convactor.php?site="+str+"&itemid="+str2,true);
	xmlhttp.send();

}




}
function calcValue1(str,id)
{


	var brk=id.split('_');
	if(brk.length==2)
	{
	  /* if(parseFloat(str)>parseFloat(document.getElementById("total_stock").value))
	   {
	   alert("Qty Should be less or equal then Stock Qty");
	   document.getElementById("stock_qty").value='';
	   return false;
	   }
       else
	   {*/	
	   if(str!='')
	   {
		var price=document.getElementById("conv_fac").value;
		if(price=='')
		var price=0;
		var tot=parseFloat(str)*parseFloat(price);
		}
		else
		var tot=0;
		
		document.getElementById("secondary_qty").value=tot.toFixed(3);
				/*}*/
	}
	else
	{
	  /*if(parseFloat(str)>parseFloat(document.getElementById("total_stock_"+brk[2]).value))
	   {
	   alert("Qty Should be less or equal then Stock Qty");
	   document.getElementById("stock_qty_"+brk[2]).value='';
	   return false;
	   }*/
	     if(str!='')
	   {
	   var price=document.getElementById("conv_fac_"+brk[2]).value;
	    if(price=='')
		var price=0;
		var tot=parseFloat(str)*parseFloat(price);
		}
		else
		var tot=0;
		document.getElementById("secondary_qty_"+brk[2]).value=tot.toFixed(3);
	   
		
	}
	
}
function calculateTotalAmt(val,id)
{
	var id_brk=id.split('_');
	var i=id_brk[1];
	if(id_brk.length>1)
	{
	var qty=document.getElementById("stock_qty_"+i).value;
	var tot_amt=qty*val;
	document.getElementById("totalamt_"+i).value=tot_amt.toFixed(2);
	}
	else
	{
	var qty=document.getElementById("stock_qty").value;
	var tot_amt=qty*val;
	document.getElementById("totalamt").value=tot_amt.toFixed(2);
	}
}


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


}

function calculateTotalhrdAmt(val,id)
{
	var id_brk=id.split('_');
	var i=id_brk[1];
	if(id_brk.length>1)
	{
	var qty=document.getElementById("hrdqty_"+i).value;
	var tot_amt=qty*val;
	document.getElementById("hrdvalue_"+i).value=tot_amt.toFixed(2);
	}
	else
	{
	var qty=document.getElementById("hrdqty").value;
	var tot_amt=qty*val;
	document.getElementById("hrdvalue").value=tot_amt.toFixed(2);
	}
}

function getColorValue2(str,id)
{
		if(document.getElementById("InfluDispaly2").style.display=="none")
		{
		document.getElementById("InfluDispaly2").style.display="block";
		}
		else
		{
		document.getElementById("InfluDispaly2").style.display="none";
		}
		
	if (window.XMLHttpRequest)
  	{// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}
	else
  	{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
		xmlhttp.onreadystatechange=function()
  	{
  	if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
		var data=xmlhttp.responseText.split("__");
		if(id==undefined)
		{
		document.getElementById("infFactor").value=data[0];
		}
		else
		{
		document.getElementById("infFactor_"+id).value=data[0];
		}
	 }
  }
xmlhttp.open("GET","ajax_get_color.php?q="+str,true);
xmlhttp.send();
}	

function additems(str)
{
if(document.getElementById(str).checked==true)
{
var str1;
var str2;
var s=str.split("_");
			if(s[1]==undefined)
			{
						if(document.getElementById("hrdtype").value=='Y')
						{
							if(document.getElementById("hrdvalue").value!='')
							str1=document.getElementById("hrdvalue").value;
							else  str1=0;
							var str2=0;
							var data=calculateBasic();
							
						}
						else
						{
						
							if(document.getElementById("hrdvalue").value!='')
							str2=document.getElementById("hrdvalue").value;
							else  str2=0;
							var str1=0
							
						}
			}
			else
			{
							if(document.getElementById("hrdtype_"+s[1]).value=='Y')
							{
								if(document.getElementById("hrdvalue_"+s[1]).value!='')
								str1=document.getElementById("hrdvalue_"+s[1]).value;
								else
								str1=0;
								var str2=0;
								var data=calculateBasic();
								
							}
							else
							{
								if(document.getElementById("hrdvalue_"+s[1]).value!='')
								str2=document.getElementById("hrdvalue_"+s[1]).value;
								else
								str2=0;
								var str1=0;
								
							}
			}
			
								if(document.getElementById("hardamt").value!='')
								var amt=document.getElementById("hardamt").value;
								else
								var amt=0;
								
							
								var amount=parseFloat(amt)+parseFloat(str2);
								
								if(document.getElementById("basicAmount").value!='')
								var amt1=document.getElementById("basicAmount").value;
								else
								var amt1=0;
			
								var amount1=parseFloat(amt1)+parseFloat(str1);

document.getElementById("hardamt").value=amount.toFixed(2);
document.getElementById("basicAmount").value=amount1.toFixed(2);

document.getElementById(str).value=1;
}
else
{

var str1;
var s=str.split("_");
			if(s[1]==undefined)
			{
						if(document.getElementById("hrdtype").value=='Y')
						{
						if(document.getElementById("hrdvalue").value!='')
						 str1=document.getElementById("hrdvalue").value;
						else  str1=0;
						var str2=0;
						var data=calculateBasic();
						}
							else
							{
										if(document.getElementById("hrdvalue").value!='')
										str2=document.getElementById("hrdvalue").value;
										else  str2=0;
										var str1=0;
										}
							}
			else
			{
					if(document.getElementById("hrdtype_"+s[1]).value=='Y')
					{
					if(document.getElementById("hrdvalue_"+s[1]).value!='')
					str1=document.getElementById("hrdvalue_"+s[1]).value;
					else
					str1=0;
					var data=calculateBasic();
					}
					else
					{
						if(document.getElementById("hrdvalue_"+s[1]).value!='')
						str2=document.getElementById("hrdvalue_"+s[1]).value;
						else
						str2=0;
						
					}
			}
			
				if(document.getElementById("hardamt").value!='')
				var amt=document.getElementById("hardamt").value;
				else
				var amt=0;
				
				
				var amount=parseFloat(amt)-parseFloat(str2);				
				
				if(document.getElementById("basicAmount").value!='')
				var amt1=document.getElementById("basicAmount").value;
				else
				var amt1=0;
				
				
				var amount1=parseFloat(amt1);				
				
				document.getElementById("hardamt").value=amount.toFixed(2);
				document.getElementById("basicAmount").value=amount1.toFixed(2);

				document.getElementById(str).value=0;

}
}

</script>
<script language="JavaScript" type="text/javascript">
function enquiryDetails(str)
{
	var branch=document.getElementById("site").value;
	if (str.length==0)
	{
	document.getElementById("enquiryId").innerHTML="";
	return;
	}
	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("enquiryId").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","showEnquiryDetails.php?party="+str+"&branch="+branch,true);
	xmlhttp.send();
}


function showEnqDetails(str)
{
	if (str.length==0)
	{
	document.getElementById("enqdetailsId").innerHTML="";
	return;
	}
	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("enqdetailsId").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","showEnquiryDetails.php?enquiryNo="+str,true);
	xmlhttp.send();
}


function calculateDiscount(str,a)
{
	var discType=document.getElementById("discountType_"+a).value;
	var value=document.getElementById("totalValue_"+a).value;
	if(str==''){str=0;}
	if(discType=='A') 
	{
	var discount=str;
	}
	else
	if(discType=='P') 
	{
	var discount=value*(str/100);	
	}
	document.getElementById("valueAfterDisc_"+a).value=(parseFloat(value)-parseFloat(discount)).toFixed(2);
}



function calculateBasic()
{
	var totalBasic=0;
	var totalBasic2=0;
	if(document.getElementById("hiditemcount").value!='')
	{
	var cnt=parseFloat(document.getElementById("hiditemcount").value);
	}
	else
	{
		cnt=0
	}
	
	if(document.getElementById("count1").value!='')
	{
	var cnt1=parseFloat(document.getElementById("count1").value);
	}
	else
	{
		cnt1=0;
	}
	
	
	var fincount=cnt+cnt1;
	
	
	//alert(fincount);
	//if(document.getElementById("value_dis").value!='')
//	{
//	var totalBasic4=document.getElementById("value_dis").value;
//	}
//	else
//	{
//	var totalBasic4=0;
//	}
	
	for(var i=0;i<fincount;i++)
	{
	if(document.getElementById("itemid1_"+i).value!=''){
	if(document.getElementById("value_dis_"+i).value!='')
	{	
	var totalBasic1=document.getElementById("value_dis_"+i).value;
	}
	else
	{
	var totalBasic1=0;
	}
	var totalBasic=parseFloat(totalBasic)+parseFloat(totalBasic1);
	}
	}
	//var totalBasic3=parseFloat(totalBasic)+parseFloat(totalBasic4);	
	var totalBasic3=parseFloat(totalBasic);	
	document.getElementById("basicAmount").value=totalBasic3;
}



function calculateDiscounted()
{
	var totalDiscounted=0;
	var cnt=document.getElementById("hiditemcount").value;
	for(var i=0;i<=cnt;i++)
	{
	var totalDiscounted1=document.getElementById("valueAfterDisc_"+i).value;
	var totalDiscounted=parseFloat(totalDiscounted)+parseFloat(totalDiscounted1);
	}
	document.getElementById("totalDiscountedPrice").value=totalDiscounted;
}



function checkApplicable(str)
{
	/*	for(var i=1; i<6;i++)
	{
	if(document.getElementById("menu"+i).value=='NA')
	{
	document.getElementById("remarks"+i).disabled=true;
	document.getElementById("value"+i).disabled=true;
	}
	else
	if(document.getElementById("menu"+i).value=='AS')
	{
	document.getElementById("remarks"+i).disabled=false;
	document.getElementById("value"+i).disabled=false;
	}
	}
	*/
}


function ValueAfterDiscount(i)
{
	var disc=document.getElementById("discount_"+i).value;
	var disctype=document.getElementById("discountType_"+i).value;
	if(disc=='')
	{
	var stockvalue=document.getElementById("stock_value_"+i).value;
	document.getElementById("valueAfterDisc_"+i).value=stockvalue;
	}
	else
	{
	if(disctype=='A')
	{
	var stockvalue=document.getElementById("stock_value_"+i).value;
	var valueafterdisc=parseFloat(stockvalue)-parseFloat(disc);
	document.getElementById("valueAfterDisc_"+i).value=valueafterdisc;
	}
	if(disctype=='P')
	{
	var stockvalue=document.getElementById("stock_value_"+i).value;
	var discpercvalue=(parseFloat(stockvalue)*parseFloat(disc))/100;
	var finalValue=(parseFloat(stockvalue)-parseFloat(discpercvalue)).toFixed(2);
	document.getElementById("valueAfterDisc_"+i).value=finalValue;
	}
	}
}



function claculateExcise(str)
{
	var discounted=document.getElementById("totalDiscountedPrice").value;
	if (str.length==0)
	{
	document.getElementById("exciseId").innerHTML="";
	return;
	}
	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("exciseId").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","calculateExcise.php?taxId="+str+"&discounted="+discounted,true);
	xmlhttp.send();
}



function calculateVATCST(str)
{
	var taxAmt=document.getElementById("taxableAmount").value;
	if (str=='')
	{
	document.getElementById("VatCstValue").value="";
	return;
	}
	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);
            document.getElementById("VatCstValue").value=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","calculateExcise.php?salesId="+str+"&taxAmount="+taxAmt,true);
	xmlhttp.send();
}

function calculateVATCSTser(str)
{
	var taxAmt=document.getElementById("taxableAmountSer").value;
	if (str=='')
	{
	document.getElementById("rate").innerHTML="";
	return;
	}
	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("VatCstValueSer").value=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","calculateExcise.php?salesId="+str+"&taxAmount="+taxAmt,true);
	xmlhttp.send();
}


function calculateVATCST_hrd(str)
{
	if (str=='')
	{
	document.getElementById("rate1").innerHTML="";
	return;
	}
	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("rate1").value=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","calculateExcise_hrd.php?salesId="+str,true);
	xmlhttp.send();
}



function calculateECess()
{
	var exciseValue=document.getElementById("totalDiscountedPrice").value;
	var ECessPercentage=document.getElementById("ECessPercentage").value;
	var total=exciseValue*(ECessPercentage/100);
	document.getElementById("ECessValue").value=total.toFixed(2);
}



function calculateSAHCess()
{
	var exciseValue=document.getElementById("totalDiscountedPrice").value;
	var SAHCessPercentage=document.getElementById("SAHCessPercentage").value;
	var total=exciseValue*(SAHCessPercentage/100);
	document.getElementById("SAHCessValue").value=total.toFixed(2);
}



function calculateTaxable()
{
    var afterdiscount=document.getElementById("afterdiscountprice").value;
	var totalDiscountedPrice=document.getElementById("totalDiscountedPrice").value;
	var ECessValue=document.getElementById("ECessValue").value;
	var SAHCessValue=document.getElementById("SAHCessValue").value;
	
	if(totalDiscountedPrice==''){totalDiscountedPrice=0;}
	if(afterdiscount==''){afterdiscount=0;}
	if(ECessValue==''){ECessValue=0;}
	if(SAHCessValue==''){SAHCessValue=0;}
	
	var TOTAL=parseFloat(totalDiscountedPrice)+parseFloat(ECessValue)+parseFloat(SAHCessValue)+parseFloat(afterdiscount);
	document.getElementById("taxableAmount").value=TOTAL.toFixed(2);
}



function calculateGrand()
{
	//var a=document.getElementById("basicAmount").value;
	//var b=document.getElementById("totalDiscountedPrice").value;
	//var c=document.getElementById("ECessValue").value;
	//var d=document.getElementById("SAHCessValue").value;
	//var e=document.getElementById("taxableAmount").value;
	var f=document.getElementById("total_taxable_amtSer").value;
        //alert(f);
	var c1=document.getElementById("miscCharge").value;
	var c2=document.getElementById("handCharges").value;
	var c3=document.getElementById("freight").value;
	var c4=document.getElementById("total_taxable_amt").value;
	//if(a==''){a=0;}
	//if(b==''){b=0;}
	//if(c==''){c=0;}
	//if(d==''){d=0;}
	//if(e==''){e=0;}
	if(f==''){f=0;}
	if(c1==''){c1=0;}
	if(c2==''){c2=0;}
	if(c3==''){c3=0;}
	if(c4==''){c4=0;}
	//var GRAND=parseFloat(a)+parseFloat(b)+parseFloat(c)+parseFloat(d)+parseFloat(e)+parseFloat(f)+parseFloat(g);
	var GRAND=parseFloat(c1)+parseFloat(c2)+parseFloat(c3)+parseFloat(c4)+parseFloat(f);
	//grandBrk=GRAND.toFixed(2).split('.');
	//grandA=grandBrk[0];
	//grandB=grandBrk[1];
	//alert(grandA);
	//alert(grandB);
	//if(grandB>'50' || grandB=='50')
	//{
		//GRAND11=parseInt(GRAND)+1;
	//}
	//else
	//if(grandB<'50')
	//{
		//GRAND11=parseInt(GRAND);
	//}	
	document.getElementById("grandTotal").value=GRAND.toFixed(2);
	document.getElementById("orig_grand_tot1").value = GRAND.toFixed(2);
var GrandTotAmt = document.getElementById("grandTotal").value;
var gtotal_brk=GrandTotAmt.split('.');
	if(gtotal_brk[1]>=50)
	{
	var finalAmt=parseInt(gtotal_brk[0])+1;
	}
	else if(gtotal_brk[1]<50)
	{
	var finalAmt=parseInt(gtotal_brk[0]);
	}
	else if(gtotal_brk[1]==00)
	{
	var finalAmt=parseInt(gtotal_brk[0]);
	}
	document.getElementById("grandTotal").value=finalAmt.toFixed(2);
	
	var OrigGrandTotAmt = document.getElementById("orig_grand_tot1").value;
	var NewGrandTotAmt = document.getElementById("grandTotal").value;
	
	if(NewGrandTotAmt>OrigGrandTotAmt)
	{
	document.getElementById("roundVal").value=(parseFloat(NewGrandTotAmt)-parseFloat(OrigGrandTotAmt)).toFixed(2);
	document.getElementById("pluMin").value='+';
	}
	else if(NewGrandTotAmt<OrigGrandTotAmt)
	{
	document.getElementById("roundVal").value=(parseFloat(OrigGrandTotAmt)-parseFloat(NewGrandTotAmt)).toFixed(2);
	document.getElementById("pluMin").value='-';
	}
	else if(NewGrandTotAmt==OrigGrandTotAmt)
	{
	document.getElementById("roundVal").value=(parseFloat(OrigGrandTotAmt)-parseFloat(NewGrandTotAmt)).toFixed(2);
	document.getElementById("pluMin").value='No Round';
	}
}

function calculateGrandSup()
{
	//var a=document.getElementById("basicAmount").value;
	//var b=document.getElementById("totalDiscountedPrice").value;
	//var c=document.getElementById("ECessValue").value;
	//var d=document.getElementById("SAHCessValue").value;
	//var e=document.getElementById("taxableAmount").value;
	//var f=document.getElementById("total_taxable_amtSer").value;
        //alert(f);
	var c1=document.getElementById("miscCharge").value;
	var c2=document.getElementById("handCharges").value;
	var c3=document.getElementById("freight").value;
	var c4=document.getElementById("total_taxable_amt").value;
	//if(a==''){a=0;}
	//if(b==''){b=0;}
	//if(c==''){c=0;}
	//if(d==''){d=0;}
	//if(e==''){e=0;}
	//if(f==''){f=0;}
	if(c1==''){c1=0;}
	if(c2==''){c2=0;}
	if(c3==''){c3=0;}
	if(c4==''){c4=0;}
	//var GRAND=parseFloat(a)+parseFloat(b)+parseFloat(c)+parseFloat(d)+parseFloat(e)+parseFloat(f)+parseFloat(g);
	var GRAND=parseFloat(c1)+parseFloat(c2)+parseFloat(c3)+parseFloat(c4);
	//grandBrk=GRAND.toFixed(2).split('.');
	//grandA=grandBrk[0];
	//grandB=grandBrk[1];
	//alert(grandA);
	//alert(grandB);
	//if(grandB>'50' || grandB=='50')
	//{
		//GRAND11=parseInt(GRAND)+1;
	//}
	//else
	//if(grandB<'50')
	//{
		//GRAND11=parseInt(GRAND);
	//}	
	document.getElementById("grandTotal").value=GRAND.toFixed(2);
	document.getElementById("orig_grand_tot1").value = GRAND.toFixed(2);
var GrandTotAmt = document.getElementById("grandTotal").value;
var gtotal_brk=GrandTotAmt.split('.');
	if(gtotal_brk[1]>=50)
	{
	var finalAmt=parseInt(gtotal_brk[0])+1;
	}
	else if(gtotal_brk[1]<50)
	{
	var finalAmt=parseInt(gtotal_brk[0]);
	}
	else if(gtotal_brk[1]==00)
	{
	var finalAmt=parseInt(gtotal_brk[0]);
	}
	document.getElementById("grandTotal").value=finalAmt.toFixed(2);
	
	var OrigGrandTotAmt = document.getElementById("orig_grand_tot1").value;
	var NewGrandTotAmt = document.getElementById("grandTotal").value;
	
	if(NewGrandTotAmt>OrigGrandTotAmt)
	{
	document.getElementById("roundVal").value=(parseFloat(NewGrandTotAmt)-parseFloat(OrigGrandTotAmt)).toFixed(2);
	document.getElementById("pluMin").value='+';
	}
	else if(NewGrandTotAmt<OrigGrandTotAmt)
	{
	document.getElementById("roundVal").value=(parseFloat(OrigGrandTotAmt)-parseFloat(NewGrandTotAmt)).toFixed(2);
	document.getElementById("pluMin").value='-';
	}
	else if(NewGrandTotAmt==OrigGrandTotAmt)
	{
	document.getElementById("roundVal").value=(parseFloat(OrigGrandTotAmt)-parseFloat(NewGrandTotAmt)).toFixed(2);
	document.getElementById("pluMin").value='No Round';
	}
}

/*function calculateGrand()
{
	//var a=document.getElementById("basicAmount").value;
	//var b=document.getElementById("totalDiscountedPrice").value;
	//var c=document.getElementById("ECessValue").value;
	//var d=document.getElementById("SAHCessValue").value;
	//var e=document.getElementById("taxableAmount").value;
	//var f=document.getElementById("VatCstValue").value;
	var c1=document.getElementById("miscCharge").value;
	var c2=document.getElementById("handCharges").value;
	var c3=document.getElementById("freight").value;total_taxable_amt
	var c4=document.getElementById("total_taxable_amt").value;
	//if(a==''){a=0;}
	//if(b==''){b=0;}
	//if(c==''){c=0;}
	//if(d==''){d=0;}
	//if(e==''){e=0;}
	//if(f==''){f=0;}
	if(c1==''){c1=0;}
	if(c2==''){c2=0;}
	if(c3==''){c3=0;}
	if(c4==''){c4=0;}
	//var GRAND=parseFloat(a)+parseFloat(b)+parseFloat(c)+parseFloat(d)+parseFloat(e)+parseFloat(f)+parseFloat(g);
	var GRAND=parseFloat(c1)+parseFloat(c2)+parseFloat(c3)+parseFloat(c4);
	//grandBrk=GRAND.toFixed(2).split('.');
	//grandA=grandBrk[0];
	//grandB=grandBrk[1];
	//alert(grandA);
	//alert(grandB);
	//if(grandB>'50' || grandB=='50')
	//{
		//GRAND11=parseInt(GRAND)+1;
	//}
	//else
	//if(grandB<'50')
	//{
		//GRAND11=parseInt(GRAND);
	//}	
	document.getElementById("grandTotal").value=GRAND.toFixed(2);
	//document.getElementById("roundOff").value="."+grandB;
}*/
function GetLeads(str)
{
	var site=document.getElementById("site").value;
	var clientid=document.getElementById("party").value;
	if (str.length==0)
	{
	document.getElementById("hid_Leads").innerHTML="";
	return;
	}
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	 var data=xmlhttp.responseText.split("__");
	 document.getElementById("hid_Leads").innerHTML=data[0];
	//document.getElementById("mobile_check").innerHTML=data[1];
	
	}
	}
	xmlhttp.open("GET","CRM_GetLeads.php?str="+str+"&site="+site+"&client_id="+clientid,true);
	xmlhttp.send();
}

function DiscountAmounts(DA,id)
{
	id1=id.split("_");
	i=id1[1];
	if(i==undefined)
	{
		var totValue = document.getElementById("stock_value").value;
		var discType = document.getElementById("PerAmo").value;
		var disct = document.getElementById("Discount").value;
		if(totValue==''){totValue=0;}
		if(DA==""){DA=0;}
		 var totalamt=0;
		if(discType=='Amount')
		{
			var subTotal = parseFloat(totValue)-parseFloat(disct);
			document.getElementById("value_dis").value=subTotal.toFixed(2);
			
			var countcharges = document.getElementById("hiditemcount").value;
			for(var l=1;l<=countcharges;l++){
			if(document.getElementById("value_dis_"+l)!=null){
			if(document.getElementById("value_dis_"+l).value!='')
			var totalamt=parseFloat(totalamt)+parseFloat(document.getElementById("value_dis_"+l).value);
			}}
			var firstRow=document.getElementById("value_dis").value;
			var finalAmt= parseFloat(firstRow)+parseFloat(totalamt);
			document.getElementById("basicAmount").value=finalAmt.toFixed(2);
		}
		else
		{
			var subTotal = parseFloat(totValue)-parseFloat((disct*totValue)/100);
			document.getElementById("value_dis").value=subTotal.toFixed(2);
			
			var countcharges = document.getElementById("hiditemcount").value;
			for(var l=1;l<=countcharges;l++)
			{
			if(document.getElementById("value_dis_"+l)!=null){
			if(document.getElementById("value_dis_"+l).value!='')
			var totalamt=parseFloat(totalamt)+parseFloat(document.getElementById("value_dis_"+l).value);
			}}
			var firstRow=document.getElementById("value_dis").value;
			var finalAmt= parseFloat(firstRow)+parseFloat(totalamt);
			document.getElementById("basicAmount").value=finalAmt.toFixed(2);		
		}
	}
	else
	{
		var totValue = document.getElementById("stock_value_"+i).value;
		var discType = document.getElementById("PerAmo_"+i).value;
		var disct = document.getElementById("Discount_"+i).value;
		if(totValue==''){totValue=0;}
		if(DA==""){DA=0;}
		 var totalamt=0;
		if(discType=='Amount')
		{
			var subTotal = parseFloat(totValue)-parseFloat(disct);
			document.getElementById("value_dis_"+i).value=subTotal.toFixed(2);
			
			var countcharges = document.getElementById("hiditemcount").value;
			for(var l=1;l<=countcharges;l++){
			if(document.getElementById("value_dis_"+l)!=null){
			if(document.getElementById("value_dis_"+l).value!='')
			var totalamt=parseFloat(totalamt)+parseFloat(document.getElementById("value_dis_"+l).value);
			}}
			var firstRow=document.getElementById("value_dis").value;
			var finalAmt= parseFloat(firstRow)+parseFloat(totalamt);
			document.getElementById("basicAmount").value=finalAmt.toFixed(2);
		}
		else
		{
			var subTotal = parseFloat(totValue)-parseFloat((disct*totValue)/100);
			document.getElementById("value_dis_"+i).value=subTotal.toFixed(2);
			
			var countcharges = document.getElementById("hiditemcount").value;
			for(var l=1;l<=countcharges;l++)
			{
			if(document.getElementById("value_dis_"+l)!=null){
			if(document.getElementById("value_dis_"+l).value!='')
			var totalamt=parseFloat(totalamt)+parseFloat(document.getElementById("value_dis_"+l).value);
			}}
			var firstRow=document.getElementById("value_dis").value;
			var finalAmt= parseFloat(firstRow)+parseFloat(totalamt);
			document.getElementById("basicAmount").value=finalAmt.toFixed(2);		
		}
	}
}


function DiscountAmountsServ(DA,id)
{
	id1=id.split("_");
	i=id1[1];
	if(i==undefined)
	{
		var totValue = document.getElementById("total_amt").value;
		var discType = document.getElementById("PerAmoSer").value;
		var disct = document.getElementById("DiscountSer").value;
		if(totValue==''){totValue=0;}
		if(DA==""){DA=0;}
		 var totalamt=0;
		if(discType=='Amount')
		{
			var subTotal = parseFloat(totValue)-parseFloat(disct);
			document.getElementById("value_disSer").value=subTotal.toFixed(2);
			
			var countcharges = document.getElementById("hiditemcount2").value;
			for(var l=0;l<=countcharges;l++){
			if(document.getElementById("value_disSer_"+l)!=null){
			if(document.getElementById("value_disSer_"+l).value!='')
			var totalamt=parseFloat(totalamt)+parseFloat(document.getElementById("value_disSer_"+l).value);
			}}
			var firstRow=document.getElementById("value_disSer").value;
			var finalAmt=parseFloat(totalamt)+parseFloat(firstRow);
			document.getElementById("basicAmountSer").value=finalAmt.toFixed(2);
		}
		else
		{
			var subTotal = parseFloat(totValue)-parseFloat((disct*totValue)/100);
			document.getElementById("value_disSer").value=subTotal.toFixed(2);
			
			var countcharges = document.getElementById("hiditemcount2").value;
			for(var l=0;l<=countcharges;l++)
			{
			if(document.getElementById("value_disSer_"+l)!=null){
			if(document.getElementById("value_disSer_"+l).value!='')
			var totalamt=parseFloat(totalamt)+parseFloat(document.getElementById("value_disSer_"+l).value);
			}}
			var firstRow=document.getElementById("value_disSer").value;
			var finalAmt=parseFloat(totalamt)+parseFloat(firstRow);
			document.getElementById("basicAmountSer").value=finalAmt.toFixed(2);		
		}
	}
	else
	{
		var totValue = document.getElementById("total_amt_"+i).value;
		var discType = document.getElementById("PerAmoSer_"+i).value;
		var disct = document.getElementById("DiscountSer_"+i).value;
		if(totValue==''){totValue=0;}
		if(DA==""){DA=0;}
		 var totalamt=0;
		if(discType=='Amount')
		{
			var subTotal = parseFloat(totValue)-parseFloat(disct);
			document.getElementById("value_disSer_"+i).value=subTotal.toFixed(2);
			
			var countcharges = document.getElementById("hiditemcount2").value;
			for(var l=0;l<=countcharges;l++){
			if(document.getElementById("value_disSer_"+l)!=null){
			if(document.getElementById("value_disSer_"+l).value!='')
			var totalamt=parseFloat(totalamt)+parseFloat(document.getElementById("value_disSer_"+l).value);
			}}
			var firstRow=document.getElementById("value_disSer").value;
			var finalAmt=parseFloat(totalamt)+parseFloat(firstRow);
			document.getElementById("basicAmountSer").value=finalAmt.toFixed(2);
		}
		else
		{
			var subTotal = parseFloat(totValue)-parseFloat((disct*totValue)/100);
			document.getElementById("value_disSer_"+i).value=subTotal.toFixed(2);
			
			var countcharges = document.getElementById("hiditemcount2").value;
			for(var l=1;l<=countcharges;l++)
			{
			if(document.getElementById("value_disSer_"+l)!=null){
			if(document.getElementById("value_disSer_"+l).value!='')
			var totalamt=parseFloat(totalamt)+parseFloat(document.getElementById("value_disSer_"+l).value);
			}}
			var firstRow=document.getElementById("value_disSer").value;
			var finalAmt=parseFloat(totalamt)+parseFloat(firstRow);
			document.getElementById("basicAmountSer").value=finalAmt.toFixed(2);	
		}
	}
}

function open_items()
{
//var site=document.getElementById("mst_branchid").value;
//var store=document.getElementById("store").value;
//var date=document.getElementById("lead_date").value;
window.open("leadTelephonicItems.php?modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'] ?>&action=<?php echo $_REQUEST['action']?>","itempopup_window","height=500,width=600,left=1000,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");
}

function calcConvFact(str,id)
{
id1=id.split("_");
	i=id1[2];
	if(i==undefined)
	{
		var conVfact=document.getElementById("convfact").value;
		if(conVfact==""){conVfact=0;}
		var final=parseFloat(conVfact)*parseFloat(str);
		document.getElementById("secondary_qty").value=final.toFixed(2);
	}
	else
	{
		var conVfact=document.getElementById("convfact_"+i).value;
		if(conVfact==""){conVfact=0;}
		var final=parseFloat(conVfact)*parseFloat(str);
		document.getElementById("secondary_qty_"+i).value=final.toFixed(2);
	}
}
function GetTables(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)
	{
	var data=xmlhttp.responseText.split("__");
	//document.getElementById("typeid").innerHTML=data[0];
	document.getElementById("ITEMSDETAILS").innerHTML=data[0];
        
	//document.getElementById("quotationType").value=data[2];
	////document.getElementById("quotationMailDate").value=data[3];
	document.getElementById("SERVICEDETAILS").innerHTML=data[1];
	}
	}
	xmlhttp.open("GET","CRM_GetLeadsRecordDirect.php?branch="+str,true);
	xmlhttp.send();
	
}

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

function addRow2(tableID) 
{
	if(document)
		var table = document.getElementById(tableID);
		var rowCount = table.rows.length;
		var row = table.insertRow(rowCount);
		document.getElementById("hiditemcount2").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;	
			}
		}
	}
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("hiditemcount2").value=parseInt(rowCount)-1;		
	}
	catch(e) 
	{
		alert(e);
	}

}


function GetEstimationRecord(str)
{
	var site=document.getElementById("leadid").value;
	if (str==0)
	{
	document.getElementById("leadid").innerHTML="";
	document.getElementById("ITEMSDETAILS").innerHTML="";
	document.getElementById("HARDWAREDETAILS").innerHTML="";
	return;
	}
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	var data=xmlhttp.responseText.split("__");
	document.getElementById("typeid").innerHTML=data[0];
	document.getElementById("ITEMSDETAILS").innerHTML=data[1];
	document.getElementById("HARDWAREDETAILS").innerHTML=data[2];
	
	}
	}
	xmlhttp.open("GET","CRM_GetEstimationRecord.php?estimationid="+str,true);
	xmlhttp.send();
	
}


function GetEstimationRecord2(str)
{
	var site=document.getElementById("leadid").value;
	if (str==0)
	{
	document.getElementById("leadid").innerHTML="";
	document.getElementById("ITEMSDETAILS").innerHTML="";
	document.getElementById("HARDWAREDETAILS").innerHTML="";
	document.getElementById("basicAmount").value='';
	document.getElementById("hrdtotalAmt").value='';
	document.getElementById("afterdiscountprice").value='';
	return;
	}
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	var data=xmlhttp.responseText.split("__");
	document.getElementById("basicAmount").setAttribute("onfocus","calculateBasic_estimation()");
	
	document.getElementById("typeid").innerHTML=data[0];
	document.getElementById("ITEMSDETAILS").innerHTML=data[1];
	document.getElementById("HARDWAREDETAILS").innerHTML=data[2];
	document.getElementById("basicAmount").value=data[3];
	document.getElementById("hrdtotalAmt").value=data[4];
	document.getElementById("afterdiscountprice").value=data[3];
	//document.getElementById("typeid").innerHTML=data[0];
	
	
	
	}
	}
	xmlhttp.open("GET","CRM_GetEstimationRecord_against_bom.php?estimationid="+str,true);
	xmlhttp.send();
	
}





function CalculateTotalLeadAmt(val,id)
{
	var id_brk=id.split('_');
	var i=id_brk[2];
	
	// var stock_perunit = document.getElementById("stock_perunit_+"+i).value;
	if(id_brk.length>2)
	{
	var stock_perunit = document.getElementById("stock_perunit_"+i).value;
	
	
	var stock_price = document.getElementById("stock_price_"+i).value;
	if(document.getElementById("qtyprim_"+i))
	{
	if(document.getElementById("qtyprim_"+i).checked==true)
	var stock_qty = document.getElementById("qtyprim_"+i).value;
	//alert( document.getElementById("qtyprim_"+i).value);
	else
	var stock_qty = document.getElementById("qtysec_"+i).value;
	}
	else
		//alert(document.getElementById("qtysec_"+i).value);
   var stock_qty = document.getElementById("stockqty_"+i).value;
	document.getElementById("stock_value_"+i).value=round((stock_price*stock_qty )/stock_perunit);
	//document.getElementById("total_stock_"+i).value=document.getElementById("stock_qty_"+i).value;
	}
	else
	{
	var stock_perunit = document.getElementById("stock_perunit").value;
	var stock_price = document.getElementById("stock_price").value;
	var stock_qty = document.getElementById("stockqty").value;
	document.getElementById("stock_value").value=(stock_price*stock_qty )/stock_perunit;
	//document.getElementById("total_stock").value=document.getElementById("stock_qty").value;
	}
	
	
	
	
}


function CalculateTotalLeadAmt1(val,i)
{
	
	// var stock_perunit = document.getElementById("stock_perunit_+"+i).value;
	
	var stock_perunit = document.getElementById("stock_perunit1_"+i).value;
	var stock_price = document.getElementById("stock_price1_"+i).value;
	var stock_qty = document.getElementById("stock_qty2_"+i).value;
	document.getElementById("stock_value1_"+i).value=(stock_price*stock_qty )/stock_perunit;
	//document.getElementById("total_stock_"+i).value=document.getElementById("stock_qty_"+i).value;
}




function CalculateTotalLeadAmt2(val,i)
{
	
	// var stock_perunit = document.getElementById("stock_perunit_+"+i).value;
	
	var stock_perunit = document.getElementById("hrdstock_perunit1_"+i).value;
	var stock_price = document.getElementById("hrdstock_price1_"+i).value;
	var stock_qty = document.getElementById("hrdstock_qty2_"+i).value;
	document.getElementById("hrdstock_value1_"+i).value=(stock_price*stock_qty )/stock_perunit;
	//document.getElementById("total_stock_"+i).value=document.getElementById("stock_qty_"+i).value;
}





function calculateEditVATCST()
{
	//if(document.getElementById("hrdtotalAmt").value!='')
	//{
	//var hrdamt=parseFloat(document.getElementById("hrdtotalAmt").value);
	//}
	//else
	//{
		hrdamt=0;
	//}
	
	var rate=document.getElementById("rate").value;
	if(document.getElementById("taxableAmount").value!='')
	{
	var taxableAmount=parseFloat(document.getElementById("taxableAmount").value);
	}
	else
	{
		taxableAmount=0;
	}
	
	if(rate=='') { rate=0; }
	var fintotal=taxableAmount+hrdamt;
	var vat_cst=fintotal*(rate/100);
	document.getElementById("VatCstValue").value=vat_cst.toFixed(2);
}



function calculateEditVATCST_hrd()
{
	if(document.getElementById("hrdtotalAmt").value!='')
	{
	var hrdamt=parseFloat(document.getElementById("hrdtotalAmt").value);
	}
	else
	{
		hrdamt=0;
	}
	
	var rate=document.getElementById("rate1").value;
	
	if(rate=='') { rate=0; }
	
	var fintotal=hrdamt;
	var vat_cst=fintotal*(rate/100);
	document.getElementById("VatCstValue1").value=vat_cst.toFixed(2);
}



function calculateTaxVal(str)
{
var finalAmt=str*(document.getElementById("basicAmountSer").value/100);
document.getElementById("totalDiscountedPrice").value=finalAmt.toFixed(2);

var ecessAmt=finalAmt*(document.getElementById("ECessPercentage").value/100);
document.getElementById("ECessValue").value=ecessAmt.toFixed(2);

var secessAmt=ecessAmt*(document.getElementById("SAHCessPercentage").value/100);
document.getElementById("SAHCessValue").value=secessAmt.toFixed(2);

var tottaxAmount=parseFloat(document.getElementById("basicAmountSer").value)+parseFloat(finalAmt)+parseFloat(ecessAmt)+parseFloat(secessAmt);
document.getElementById("total_taxable_amtSer").value=tottaxAmount.toFixed(2);

document.getElementById("grandTotal").value=tottaxAmount.toFixed(2);
document.getElementById("orig_grand_tot").value = tottaxAmount.toFixed(2);

var GrandTotAmt = document.getElementById("grandTotal").value;
var gtotal_brk=GrandTotAmt.split('.');
	if(gtotal_brk[1]>=50)
	{
	var finalAmt=parseInt(gtotal_brk[0])+1;
	}
	else if(gtotal_brk[1]<50)
	{
	var finalAmt=parseInt(gtotal_brk[0]);
	}
	else if(gtotal_brk[1]==00)
	{
	var finalAmt=parseInt(gtotal_brk[0]);
	}
	document.getElementById("grandTotal").value=finalAmt.toFixed(2);
	
	var OrigGrandTotAmt = document.getElementById("orig_grand_tot").value;
	var NewGrandTotAmt = document.getElementById("grandTotal").value;
	
	if(NewGrandTotAmt>OrigGrandTotAmt)
	{
	document.getElementById("roundOff").value=(parseFloat(NewGrandTotAmt)-parseFloat(OrigGrandTotAmt)).toFixed(2);
	document.getElementById("pluMin").value='+';
	}
	else if(NewGrandTotAmt<OrigGrandTotAmt)
	{
	document.getElementById("roundOff").value=(parseFloat(OrigGrandTotAmt)-parseFloat(NewGrandTotAmt)).toFixed(2);
	document.getElementById("pluMin").value='-';
	}
	else if(NewGrandTotAmt==OrigGrandTotAmt)
	{
	document.getElementById("roundOff").value=(parseFloat(OrigGrandTotAmt)-parseFloat(NewGrandTotAmt)).toFixed(2);
	document.getElementById("pluMin").value='No Round';
	}
}

function calculateTaxValSer(str)
{
var finalAmt=str*(document.getElementById("basicAmountSer").value/100);
document.getElementById("totalDiscountedPriceSer").value=finalAmt.toFixed(2);

var ecessAmt=finalAmt*(document.getElementById("ECessPercentageSer").value/100);
document.getElementById("ECessValueSer").value=ecessAmt.toFixed(2);

var secessAmt=ecessAmt*(document.getElementById("SAHCessPercentageSer").value/100);
document.getElementById("SAHCessValueSer").value=secessAmt.toFixed(2);

var tottaxAmount=parseFloat(document.getElementById("basicAmountSer").value)+parseFloat(finalAmt)+parseFloat(ecessAmt)+parseFloat(secessAmt);
document.getElementById("total_taxable_amtSer").value=tottaxAmount.toFixed(2);
}

function calculateBillExcise(str)
{
	var value=document.getElementById("basicAmount").value;
	var ecess=document.getElementById("ECessPercentage").value;
	var secess=document.getElementById("SAHCessPercentage").value;
	var pkgVal=document.getElementById("pkgCharg").value;
	if(str.length==0)
	{
	document.getElementById("totalDiscountedPrice").innerHTML="";
	return;
	}
	if(window.XMLHttpRequest)
	{
	xmlhttp=new XMLHttpRequest();
	}
	else
	{
	xmlhttp	=new ActiveXobject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if(xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	var data=xmlhttp.responseText.split("__");
	document.getElementById("totalDiscountedPrice").value=data[0];
	document.getElementById("ECessValue").value=data[1];
	document.getElementById("SAHCessValue").value=data[2];
	document.getElementById("taxableAmount").value=data[3];
	}
	}
	xmlhttp.open("GET","calculateExcise.php?type=bill&id="+str+"&value="+value+"&eces="+ecess+"&secess="+secess+"&pakValue="+pkgVal,true);
	xmlhttp.send();	
}

function calculateBillExcise2(str)
{
	var pkgCharges=document.getElementById("pkgCharg").value;
	if(pkgCharges=='') { pkgCharges=0; }
	var basicAmt=document.getElementById("basicAmount").value;
	if(basicAmt=='') { basicAmt=0; }
	
	var value=parseFloat(basicAmt)+parseFloat(pkgCharges);
	var ecess=document.getElementById("ECessPercentage").value;
	var secess=document.getElementById("SAHCessPercentageSup").value;
	var pkgVal=document.getElementById("pkgCharg").value;
	if(str.length==0)
	{
	document.getElementById("totalDiscountedPrice").innerHTML="";
	return;
	}
	if(window.XMLHttpRequest)
	{
	xmlhttp=new XMLHttpRequest();
	}
	else
	{
	xmlhttp	=new ActiveXobject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if(xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	var data=xmlhttp.responseText.split("__");
	document.getElementById("totalDiscountedPrice").value=data[0];
	document.getElementById("ECessValue").value=data[1];
	document.getElementById("SAHCessValue").value=data[2];
	document.getElementById("taxableAmount").value=data[3];
	}
	}
	xmlhttp.open("GET","calculateExcise.php?type=bill&id="+str+"&value="+value+"&eces="+ecess+"&secess="+secess+"&pakValue="+pkgVal,true);
	xmlhttp.send();	
}


/*function calcValue1(str,id)
{
	var id_brk=id.split('_');
	var i=id_brk[1];
	
	if(id_brk[1]==undefined)
	{
	 if(parseFloat(str)>parseFloat(document.getElementById("total_stock").value))
	   {
	   alert("Qty Should be less or equal then Stock Qty");
	   document.getElementById("stockqty").value='';
	   return false;
	   }
	}
	else
	   {	
	  
	   if(parseFloat(str)>parseFloat(document.getElementById("total_stock_"+i).value))
	   {
	   alert("Qty Should be less or equal then Stock Qty");
	   document.getElementById("stockqty_"+i).value='';
	   return false;
	   }
	   }
      
}*/



function calcValue(str,i)
{
  
	var stockqty=parseFloat(str);
	var originalstock=parseFloat(document.getElementById("stockqty1_"+i).value);
	var stockvalue=parseFloat(document.getElementById("total_stock1_"+i).value);
	if(stockqty>stockvalue)
	{
		alert("Qty Should be less or equal then Stock Qty");
		document.getElementById("stock_qty2_"+i).value=originalstock;
		return false;
	}
	

	
}



function addtotadhrdamt(i)
{
	var counthrd=document.getElementById("hrdcount1").value;
	var sum=0;
	for(var i=0; i < counthrd; i++)
	{
		if(document.getElementById("addhrdAmt_"+i).checked==true)
		{
			if(document.getElementById("hrdvalue_dis1_"+i).value!='')
			{
			var discamt=parseFloat(document.getElementById("hrdvalue_dis1_"+i).value);
			}
			else
			{
			discamt=0;
			}
			sum=sum+discamt;
		}
		
	}
	
	document.getElementById("hrdtotalAmt").value=sum;
	
}
function ChangeLabel(str)
{
	if(str=='Shipping')
	{
	document.getElementById("sa").innerHTML='Shipping Address';
	document.getElementById("sc").innerHTML='Shipping Country';
	document.getElementById("ss").innerHTML='Shipping State';
	document.getElementById("sci").innerHTML='Shipping City';
	document.getElementById("spc").innerHTML='Shipping Postal Code';
	}
	else
	{
	document.getElementById("sa").innerHTML='Dispatch Address';
	document.getElementById("sc").innerHTML='Dispatch Country';
	document.getElementById("ss").innerHTML='Dispatch State';
	document.getElementById("sci").innerHTML='Dispatch City';
	document.getElementById("spc").innerHTML='Dispatch Postal Code';
	}
}


function calculatePakg(str)
{
if(str!='')
	{
	var tota_amt=document.getElementById("basicAmount").value;
	var pckgng_val=(str/100)*tota_amt;
	document.getElementById("pkgCharg").value=pckgng_val.toFixed(2);
        
        var pkgCharges=document.getElementById("pkgCharg").value;
        if(pkgCharges=='') { pkgCharges=0; }
        var basicAmt=document.getElementById("basicAmount").value;
        if(basicAmt=='') { basicAmt=0; }
        var FinalAmount=parseFloat(tota_amt)+parseFloat(pkgCharges);
        
        document.getElementById("taxableAmount").value=FinalAmount.toFixed(2);
	}
}
</script>

<script>
function validate()
{
	//alert("hello");
	var testing=document.getElementById("validTill").value;
	var collection = document.getElementById("quotationDate").value;
    
     
       
       var collection1 =   collection.split("/");
             
       var DobDate   = collection1[0];
       var DobMonth = collection1[1];       
       var DobYear   = collection1[2];
   
       var testing1 =   testing.split("/");
              
       var SysDate   = testing1[0];
       var SysMonth = testing1[1];
       var SysYear   = testing1[2];
       
       
    // alert("DobYear="+DobYear+"SysYear ="+SysYear +"DobMonth="+DobMonth+"SysMonth="+SysMonth+"DobDate="+DobDate+"SysDate="+SysDate);
       
       
	   
	   if(document.getElementById("site").value=='0')
	   {
	   alert("Must Select Site First");
	   return false;
	   }
	   if(document.getElementById("quotationDate").value=='')
	   {
	   alert("Must Enter Quotations Date First");
	   return false;
	   }
	   if(document.getElementById("party").value=='0')
	   {
	   alert("Must Select  Account Name First");
	   return false;
	   }
	    if(document.getElementById("ContactPerson").value=='')
	   {
	   alert("Must Select Contact Person First");
	   return false;
	   }
	   if(document.getElementById("leadid").value=='0')
	   {
	   alert("Must Select  Against Enquiry First");
	   return false;
	   }
	   if(document.getElementById("validTill").value=='')
	   {
	   alert("Must Select  Valid Till date First");
	   return false;
	   }
	   if(document.getElementById("quotationSite").value=='')
	   {
	   alert("Must Enter Quotation Site");
	   return false;
	   }
	 
	   if(DobYear > SysYear)
       {
         alert("Till Date  cannot be less than Quotations Date ");
		 document.getElementById("validTill").value='';
		 document.getElementById("validTill").focus();
         return false;      
       }
       else if((DobYear == SysYear) && (DobMonth > SysMonth))
       {
         alert("Till Date  cannot be less than Quotations Date ");
		 document.getElementById("validTill").value='';
		 document.getElementById("validTill").focus();
         return false; 
       }
       
        else if((DobYear == SysYear) && (DobMonth == SysMonth) && (DobDate > SysDate))
       {
         alert("Till Date  cannot be less than Quotations Date ");
		 document.getElementById("validTill").value='';
		 document.getElementById("validTill").focus();
         return false;
       }
	   
      
         return true;

}
function selectDate()
{
	//alert("hello");
	var testing=document.getElementById("validTill").value;
	var collection = document.getElementById("quotationDate").value;
    
     
       
       var collection1 =   collection.split("/");
             
       var DobDate   = collection1[0];
       var DobMonth = collection1[1];       
       var DobYear   = collection1[2];
   
       var testing1 =   testing.split("/");
              
       var SysDate   = testing1[0];
       var SysMonth = testing1[1];
       var SysYear   = testing1[2];
       
       
    // alert("DobYear="+DobYear+"SysYear ="+SysYear +"DobMonth="+DobMonth+"SysMonth="+SysMonth+"DobDate="+DobDate+"SysDate="+SysDate);
       
       
	   
	  
	 
	   if(DobYear > SysYear)
       {
         alert("Till Date  cannot be less than Quotations Date ");
		 document.getElementById("validTill").value='';
		 document.getElementById("validTill").focus();
         return false;      
       }
       else if((DobYear == SysYear) && (DobMonth > SysMonth))
       {
         alert("Till Date  cannot be less than Quotations Date ");
		 document.getElementById("validTill").value='';
		 document.getElementById("validTill").focus();
         return false; 
       }
       
        else if((DobYear == SysYear) && (DobMonth == SysMonth) && (DobDate > SysDate))
       {
         alert("Till Date  cannot be less than Quotations Date ");
		 document.getElementById("validTill").value='';
		 document.getElementById("validTill").focus();
         return false;
       }
	   
      
         return true;

}

function DiscountAmount(DA,i)
{
	var discount_percent = document.getElementById("PerAmo1_"+i).value;
	var discount = document.getElementById("Discount1_"+i).value;
	var total = document.getElementById("stock_value1_"+i).value;
	
	if(discount_percent=='PercentAmt')
	{
		if(discount==''){discount=0;var percent=0;}
		else
		{
		var percent = parseFloat(DA) * parseFloat(total)/100;
		}
		var subTotal = parseFloat(total)-parseFloat(percent);
	}
	else if(discount_percent=='Amount')
	{ 
	
	if(discount==''){discount=0;
	var percent=0;
	}
	else
	{
	 percent = parseFloat(DA);
	 }
	var subTotal = parseFloat(total)-percent;
	
	}	
	
	document.getElementById("perc1_"+i).value=percent.toFixed(2);
	document.getElementById("value_dis1_"+i).value=subTotal.toFixed(2);
	
	
}



function DiscountAmount2(DA,i)
{
	var discount_percent = document.getElementById("hrdPerAmo1_"+i).value;
	var discount = document.getElementById("hrdDiscount1_"+i).value;
	var total = document.getElementById("hrdstock_value1_"+i).value;
	
	if(discount_percent=='PercentAmt')
	{
		if(discount==''){discount=0;var percent=0;}
		else
		{
		var percent = parseFloat(DA) * parseFloat(total)/100;
		}
		var subTotal = parseFloat(total)-parseFloat(percent);
	}
	else if(discount_percent=='Amount')
	{ 
	
	if(discount==''){discount=0;
	var percent=0;
	}
	else
	{
	 percent = parseFloat(DA);
	 }
	var subTotal = parseFloat(total)-percent;
	
	}	
	var data=calculateBasic_estimation();
	
	document.getElementById("hrdperc1_"+i).value=percent.toFixed(2);
	document.getElementById("hrdvalue_dis1_"+i).value=subTotal.toFixed(2);
	
	
}








function DiscountAmount1(DA,str)
{
  var k=str.split("_");
  
  if(k[1]==undefined)
  {
   
	var discount_percent = document.getElementById("PerAmo").value;
	var discount = document.getElementById("Discount").value;
	var total = document.getElementById("stock_value").value;
	}
	else
	{
	var i=k[1];
	
	var discount_percent = document.getElementById("PerAmo_"+i).value;
	var discount = document.getElementById("Discount_"+i).value;
	var total = document.getElementById("stock_value_"+i).value;
	}
	if(discount_percent=='PercentAmt')
	{
		if(discount==''){discount=0; var percent=0;}
		else
		{
		var percent = parseFloat(DA) * parseFloat(total)/100;
		}
		var subTotal = parseFloat(total)-parseFloat(percent);
	}
	else if(discount_percent=='Amount')
	{ 
	
	if(discount==''){discount=0; var percent=0;}
	else
	{
	var percent = parseFloat(DA);
	}
	var subTotal = parseFloat(total)-percent;
	
	}	
	if(k[1]==undefined)
	{
	document.getElementById("perc").value=percent.toFixed(2);
	document.getElementById("value_dis").value=subTotal.toFixed(2);
	}
	else
	{
	document.getElementById("perc_"+i).value=percent.toFixed(2);
	document.getElementById("value_dis_"+i).value=subTotal.toFixed(2);
	}
	
}
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;
				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 deleteRow(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 ship_data()
{
if(document.getElementById("shipping_data").checked==true)
{
document.getElementById("showship").style.display="none";
document.getElementById("show1ship").style.display="block";
document.getElementById("shipcity").style.display="none";
document.getElementById("shipcity1").style.display="block";
document.getElementById("shipbill").style.display="none";
document.getElementById("shipbill1").style.display="block";

var billing_add=document.getElementById("address1").value;
var e=document.getElementById("country");
var billing_country=e.options[e.selectedIndex].text;
var f=document.getElementById("state");
var state=f.options[f.selectedIndex].text;
var g=document.getElementById("city");
var city=g.options[g.selectedIndex].text;
var zipcode=document.getElementById("zipcode").value;
document.getElementById("Shipping_address").value=billing_add;
document.getElementById("Shipping_country").value=billing_country;
document.getElementById("Shipping_state").value=state;
document.getElementById("Shipping_city").value=city;
document.getElementById("Shipping_zipcode").value=zipcode;
}
else
{
document.getElementById("showship").style.display="block";
document.getElementById("show1ship").style.display="none";
document.getElementById("shipcity").style.display="block";
document.getElementById("shipcity1").style.display="none";
document.getElementById("shipbill").style.display="block";
document.getElementById("shipbill1").style.display="none";
document.getElementById("Shipping_address").value='';
document.getElementById("Shipping_country").value='';
document.getElementById("Shipping_state").value='';
document.getElementById("Shipping_city").value='';
document.getElementById("Shipping_zipcode").value='';
}
}

function calculateTotalPrice(id,idd)
{
id1=idd.split("_");
	i=id1[2];
	var totalamt=0;
	if(i==undefined)
	{
		Quantity = document.getElementById("act_qty").value;
		Rate= document.getElementById("act_rate").value;
		if(Quantity==''){Quantity=0}
		if(Rate==''){Rate=0}
		var Total=parseFloat(Quantity)*parseFloat(Rate);
		document.getElementById("total_amt").value=Total.toFixed(2);	
		
		var discAmt=document.getElementById("DiscountSer").value;
		if(discAmt=='') {discAmt=0}
		var discType=document.getElementById("PerAmoSer").value;
		
		if(discType=='Amount')
		{
			var discntdAmt=parseFloat(document.getElementById("total_amt").value)-parseFloat(discAmt);
			document.getElementById("value_disSer").value=discntdAmt.toFixed(2);	
		}
		else
		{
			var discPer=parseFloat(document.getElementById("total_amt").value)-((parseFloat(discAmt)/100)*document.getElementById("total_amt").value);
			document.getElementById("value_disSer").value=discPer.toFixed(2);
		}
		
		var FirstRow=document.getElementById("value_disSer").value;
		
		
		var count=document.getElementById("hiditemcount2").value;
		
		for(var l=0;l<=count;l++){
			if(document.getElementById("value_disSer_"+l)!=null){
			if(document.getElementById("value_disSer_"+l).value!='')
			
			var totalamt=parseFloat(totalamt)+parseFloat(document.getElementById("value_disSer_"+l).value);
			}}
			var finalAmt=parseFloat(FirstRow)+parseFloat(totalamt);
			document.getElementById("basicAmountSer").value=finalAmt.toFixed(2); 	
	}
	else
	{
		var FirstRow=document.getElementById("total_amt").value;
		
		
		Quantity = document.getElementById("act_qty_"+i).value;
		Rate= document.getElementById("act_rate_"+i).value;
		if(Quantity==''){Quantity=0}
		if(Rate==''){Rate=0}
		var Total=parseFloat(Quantity)*parseFloat(Rate);
		document.getElementById("total_amt_"+i).value=Total.toFixed(2);	
		
		var discAmt=document.getElementById("DiscountSer_"+i).value;
		if(discAmt=='') {discAmt=0}
		var discType=document.getElementById("PerAmoSer_"+i).value;
		
		if(discType=='Amount')
		{
			var discntdAmt=parseFloat(document.getElementById("total_amt_"+i).value)-parseFloat(discAmt);
			document.getElementById("value_disSer_"+i).value=discntdAmt.toFixed(2);	
		}
		else
		{
			var discPer=parseFloat(document.getElementById("total_amt_"+i).value)-((parseFloat(discAmt)/100)*document.getElementById("total_amt_"+i).value);
			document.getElementById("value_disSer_"+i).value=discPer.toFixed(2);
		}
		
		var count=document.getElementById("hiditemcount2").value;
		
		for(var l=0;l<=count;l++){
			if(document.getElementById("value_disSer_"+l)!=null){
			if(document.getElementById("value_disSer_"+l).value!='')
			
			var totalamt=parseFloat(totalamt)+parseFloat(document.getElementById("value_disSer_"+l).value);
			}}
			var finalAmt=parseFloat(FirstRow)+parseFloat(totalamt);
			document.getElementById("basicAmountSer").value=finalAmt.toFixed(2); 
	}
}

function GetInfluFactor2(str,id)
{
var brk=id.split('_');
document.getElementById("InfluDispaly2").style.display="block";
	if (window.XMLHttpRequest)
  	{// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}
	else
  	{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
		xmlhttp.onreadystatechange=function()
  	{
  	if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
		var data=xmlhttp.responseText.split("__");
    	document.getElementById("InfluDispaly2").innerHTML=data;
    }
  }
xmlhttp.open("GET","ajax_get_influence2.php?q="+str+"&id="+brk[1],true);
xmlhttp.send();
}

function DiscountAmountvalue(DA)
{

var discount_percent = document.getElementById("PerAmount").value;
	var discount = document.getElementById("Discount_amount").value;
	var total = document.getElementById("basicAmount").value;
	
	if(discount_percent=='PercentAmt')
	{
		if(discount==''){discount=0;var percent=0;}
		else
		{
		var percent = parseFloat(DA) * parseFloat(total)/100;
		}
		var subTotal = parseFloat(total)-parseFloat(percent);
	}
	else if(discount_percent=='Amount')
	{ 
	
	if(discount==''){discount=0;
	var percent=0;
	}
	else
	{
	 percent = parseFloat(DA);
	 }
	var subTotal = parseFloat(total)-percent;
	
	}		
	document.getElementById("discountperc").value=percent.toFixed(2);
	document.getElementById("afterdiscountprice").value=subTotal.toFixed(2);
	
}

function showdata(str)
{
    
    var site=document.getElementById("leadid").value;
	if (str.length==0)
	{	
	}
	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("ITEMSDETAILS").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","restrecords.php?id="+str+"&site="+site,true);
	xmlhttp.send();
}

function undo()
{
  var site=document.getElementById("leadid").value;
	
	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("ITEMSDETAILS").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","undodata.php?id="+site,true);
	xmlhttp.send();

}


function open_items()
{
//var site=document.getElementById("mst_branchid").value;
//var store=document.getElementById("store").value;
//var date=document.getElementById("lead_date").value;
window.open("leadTelephonicItems.php?modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'] ?>&action=<?php echo $_REQUEST['action']?>","itempopup_window","height=500,width=600,left=1000,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");
}

function calcValue1New(str,id)
	{
	var brk=id.split('_');
	if(brk.length==2)
	{
	  	var tot=0;
		var price=document.getElementById("convfact").value;
		if(price=='') {price=0}
		var tot=parseFloat(str)*parseFloat(price);
		document.getElementById("secondary_qty").value=tot.toFixed(3);
	}
	else
	{
	   	var tot=0;
	   	var price=document.getElementById("convfact_"+brk[2]).value;
	  	if(price=='') {price=0}
		var tot=parseFloat(str)*parseFloat(price);
		document.getElementById("secondary_qty_"+brk[2]).value=tot.toFixed(3);
	}
}

function calcValue2(str,id)
{
	var brk=id.split('_');
	if(brk.length==2)
	{
		var qty=document.getElementById("stock_qty").value;
		if(qty!=''){
		var perunit=document.getElementById("stock_perunit").value;
		var tot=qty*(str/perunit);
		document.getElementById("stock_value").value=tot;}
	}
	else
	{
		var qty=document.getElementById("stock_qty_"+brk[2]).value;
		if(qty!=''){
		var perunit=document.getElementById("stock_perunit_"+brk[2]).value;
		var tot=qty*(str/perunit);
		document.getElementById("stock_value_"+brk[2]).value=tot;}
	}
}

function calcValue3(str,id)
{
	var brk=id.split('_');
	i=brk[2];
	if(str==''){str=1;}
	var totalamt=0;
	if(i==undefined)
	{
		var qty=document.getElementById("stock_qty").value;
		if(qty!=''){
		var tot=parseFloat(qty)*parseFloat(str);
		document.getElementById("stock_value").value=tot;}
		
		var discAmt=document.getElementById("Discount").value;
		if(discAmt=='') {discAmt=0}
		var discType=document.getElementById("PerAmo").value;
		
		if(discType=='Amount')
		{
			var discntdAmt=parseFloat(document.getElementById("stock_value").value)-parseFloat(discAmt);
			document.getElementById("value_dis").value=discntdAmt.toFixed(2);	
		}
		else
		{
			var discPer=parseFloat(document.getElementById("stock_value").value)-((parseFloat(discAmt)/100)*document.getElementById("stock_value").value);
			document.getElementById("value_dis").value=discPer.toFixed(2);
		}
		
		var FirstRow=document.getElementById("value_dis").value;
		if(FirstRow=='') { FirstRow=0; }
		
		var count=document.getElementById("hiditemcount").value;
		
		for(var l=0;l<=count;l++){
			if(document.getElementById("value_dis_"+l)!=null){
			if(document.getElementById("value_dis_"+l).value!='')
			
			var totalamt=parseFloat(totalamt)+parseFloat(document.getElementById("value_dis_"+l).value);
			}}
			var finalAmt=parseFloat(FirstRow)+parseFloat(totalamt);
			document.getElementById("basicAmount").value=finalAmt.toFixed(2); 
	}
	else
	{
		var qty=document.getElementById("stock_qty_"+brk[2]).value;
		if(qty!=''){
		var tot=parseFloat(qty)*parseFloat(str);
		document.getElementById("stock_value_"+brk[2]).value=tot;}
		
		var FirstRow=document.getElementById("value_dis").value;
		if(FirstRow=='') { FirstRow=0; }
		
		var discAmt=document.getElementById("Discount_"+i).value;
		if(discAmt=='') {discAmt=0}
		var discType=document.getElementById("PerAmo_"+i).value;
		
		if(discType=='Amount')
		{
			var discntdAmt=parseFloat(document.getElementById("stock_value_"+i).value)-parseFloat(discAmt);
			document.getElementById("value_dis_"+i).value=discntdAmt.toFixed(2);	
		}
		else
		{
			var discPer=parseFloat(document.getElementById("stock_value_"+i).value)-((parseFloat(discAmt)/100)*document.getElementById("stock_value_"+i).value);
			document.getElementById("value_dis_"+i).value=discPer.toFixed(2);
		}
		
		var count=document.getElementById("hiditemcount").value;
		
		for(var l=0;l<=count;l++){
			if(document.getElementById("value_dis_"+l)!=null){
			if(document.getElementById("value_dis_"+l).value!='')
			
			var totalamt=parseFloat(totalamt)+parseFloat(document.getElementById("value_dis_"+l).value);
			}}
			var finalAmt=parseFloat(FirstRow)+parseFloat(totalamt);
			document.getElementById("basicAmount").value=finalAmt.toFixed(2); 
	}
}

function deactivate(str)
{
	 var confirmText = "Are you sure you want to delete this Item?";
    if(confirm(confirmText))
	{
		var qty=document.getElementById("hrdqty1A_"+str).value;
		var n=qty.split(",");
		var count=n.length;
		for(var j=0;j<count;j++)
		{
			var fin=parseFloat(n[j]);
			var hrdqty=parseFloat(document.getElementById("hrdstock_qty2_"+j).value);
			var diff=hrdqty-fin;
			document.getElementById("hrdstock_qty2_"+j).value=diff;
			
		}
		//document.getElementById("itemid1_"+str).value='';
		//document.getElementById("active_"+str).style.display='block';
		document.getElementById("itemid1_"+str).value='';
		document.getElementById("deactive_"+str).style.display='none';
		document.getElementById("hide_"+str).style.display='none';
		//alert('Item removed');
		//calqty(str);
		//caltotal(str);basicAmount
		var totalamt=0;
		var countcharges=document.getElementById("hiditemcount2").value;
		for(var l=1;l<=countcharges;l++){
			if(document.getElementById("total_amt_"+l)!=null){
			if(document.getElementById("total_amt_"+l).value!='')
			var totalamt=parseFloat(totalamt)+parseFloat(document.getElementById("total_amt_"+l).value);
			}
			document.getElementById("totalService").value=totalamt.toFixed(2);
		}
	}
}

function deactivate1(str)
{
	 var confirmText = "Are you sure you want to delete this Item?";
    if(confirm(confirmText))
	{
		//var qty=document.getElementById("hrdqty1A_"+str).value;
		//var n=qty.split(",");
//		var count=n.length;
//		for(var j=0;j<count;j++)
//		{
//			var fin=parseFloat(n[j]);
//			var hrdqty=parseFloat(document.getElementById("hrdstock_qty2_"+j).value);
//			var diff=hrdqty-fin;
//			document.getElementById("hrdstock_qty2_"+j).value=diff;
//		}
		//document.getElementById("itemid1_"+str).value='';
		//document.getElementById("active_"+str).style.display='block';
		document.getElementById("itemid1_"+str).value='';
		document.getElementById("deactive_"+str).style.display='none';
		document.getElementById("hide_"+str).style.display='none';
		//alert('Item removed');
		//calqty(str);
		//caltotal(str);
		calculateBasic();
	}
}

function deactivateSer(str)
{
	 var confirmText = "Are you sure you want to delete this Item?";
    if(confirm(confirmText))
	{
		//var qty=document.getElementById("hrdqty1A_"+str).value;
		//var n=qty.split(",");
//		var count=n.length;
//		for(var j=0;j<count;j++)
//		{
//			var fin=parseFloat(n[j]);
//			var hrdqty=parseFloat(document.getElementById("hrdstock_qty2_"+j).value);
//			var diff=hrdqty-fin;
//			document.getElementById("hrdstock_qty2_"+j).value=diff;
//		}
		//document.getElementById("itemid1_"+str).value='';
		//document.getElementById("active_"+str).style.display='block';
		document.getElementById("act_id_"+str).value='';
		document.getElementById("deactiveSer_"+str).style.display='none';
		document.getElementById("hideServ_"+str).style.display='none';
		//alert('Item removed');
		//calqty(str);
		//caltotal(str);
		calculateBasic();
	}
}

//function showalldata(str)
//{
//	if (str.length==0)
//	{	
//	}
//	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("ITEMSDETAILS").innerHTML=xmlhttp.responseText;
//	}
//	}
//	xmlhttp.open("GET","restrecords.php?id="+str+"&site="+site,true);
//	xmlhttp.send();
//
//
//
//
//}

function showalldata(str)
{
	if (str.length==0)
	{	
	}
	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 data=xmlhttp.responseText.split("__");
	document.getElementById("address1").value=data[0];
	document.getElementById("country").innerHTML=data[1];
	document.getElementById("state").innerHTML=data[2];
	document.getElementById("city").innerHTML=data[3];
	document.getElementById("zipcode").innerHTML=data[4];
	document.getElementById("ContactPerson").innerHTML=data[5];	
	document.getElementById("Consignee").innerHTML=data[6];
	//document.getElementById("ITEMSDETAILS").innerHTML=xmlhttp.responseText;
	document.getElementById("Shipping").checked=true;
	document.getElementById("Shipping_address").value=document.getElementById("address1").value;
document.getElementById("Shipping_country").innerHTML=data[1];
document.getElementById("Shipping_state").innerHTML=data[2];
document.getElementById("Shipping_city").innerHTML=data[3];
document.getElementById("Shipping_zipcode").innerHTML=data[4];
	}
	}
	xmlhttp.open("GET","restrecords_client.php?id="+str,true);
	xmlhttp.send();

}



function showqty2(id)
{
 var k=id.split("_");
var amt=document.getElementById("stockqty_"+k[1]).value;
if(amt=='') { amt=0; } 
var totalamt=document.getElementById("stock_value_"+k[1]).value;
if(totalamt=='') { totalamt=0; } 

var price=parseFloat(totalamt)/parseFloat(amt);
document.getElementById("stock_price_"+k[1]).value=price.toFixed(2);

}
function showqty4(id)
{
 var k=id.split("_");
var amt=document.getElementById("secondary_"+k[1]).value;
if(amt=='') { amt=0; } 
var totalamt=document.getElementById("stock_value_"+k[1]).value;
if(totalamt=='') { totalamt=0; } 

var price=parseFloat(totalamt)/parseFloat(amt);
document.getElementById("stock_price_"+k[1]).value=price.toFixed(2);

}


function showrecordsdata(j)
{
  
   if(document.getElementById("addhrdAmt_"+j).checked==true)
   {
   document.getElementById("addhrdAmt_"+j).value=1;
   }
   else
   {
    document.getElementById("addhrdAmt_"+j).value=0;
   
   }
  
	        var size_array= new Array();
			//var item_array=new Array();
myCheckboxArray = document.frm1.elements["addhrdAmt[]"];
var t=myCheckboxArray.length;
if(t!=undefined)
{
	for(var i=0;i<=t+1;i++)
	{
	   if(document.getElementById("addhrdAmt_"+i))
	   {
		if(document.getElementById("addhrdAmt_"+i).checked==true)
		{
		size_array[i]=document.getElementById("hrdid_"+i).value;
		}
		}
	}
}	
else
{
 if(document.getElementById("addhrdAmt_"+j).checked==true)
		{
        size_array[0]=document.getElementById("hrdid_"+j).value;
        }
}	
	
	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("ITEMSDETAILS").innerHTML=xmlhttp.responseText;
	//document.getElementById("HARDWAREDETAILS").innerHTML=data[2];
	
	}
	}
	var leadid=document.getElementById("leadid").value;
	xmlhttp.open("GET","crm_getEstimationrecord_hardware_remove.php?estimationid="+size_array+"&estid="+leadid,true);
	xmlhttp.send();

}


function calculateBasic_estimation()
{
	var totalBasic_excise=0;
	var totalBasic2_nonexciseble=0;
	
	var fincount=document.getElementById("hrdcount1").value;
	for(var i=0;i<fincount;i++)
	{
	if(document.getElementById("hrdvalue_dis1_"+i).value!='')
	{
	if(document.getElementById("itemtype_"+i).value=='Y')
	{  
	if(document.getElementById("hrdvalue_dis1_"+i).value!='')
	{	
	var totalBasic1=document.getElementById("hrdvalue_dis1_"+i).value;
	}
	else
	{
	var totalBasic1=0;
	}
	var totalBasic_excise=parseFloat(totalBasic_excise)+parseFloat(totalBasic1);
	}
	else
	{
	if(document.getElementById("hrdvalue_dis1_"+i).value!='')
	{	
	var totalBasic2=document.getElementById("hrdvalue_dis1_"+i).value;
	}
	else
	{
	var totalBasic2=0;
	}
	var totalBasic2_nonexciseble=parseFloat(totalBasic2_nonexciseble)+parseFloat(totalBasic2);
	
	}
	}
	}
	//var totalBasic3=parseFloat(totalBasic)+parseFloat(totalBasic4);	
	
	document.getElementById("basicAmount").value=totalBasic_excise;
	document.getElementById("hrdtotalAmt").value=totalBasic2_nonexciseble;
}

function calculatetaxable_tax()
{
var salestaxamt=document.getElementById("VatCstValue").value;
var taxableamt=document.getElementById("taxableAmount").value;
	if(salestaxamt==''){salestaxamt=0;}
	if(taxableamt==''){taxableamt=0;}
	
var totalamt=parseFloat(salestaxamt)+parseFloat(taxableamt);	
document.getElementById("total_taxable_amt").value=totalamt.toFixed(2);
document.getElementById("grandTotal").value=totalamt.toFixed(2);
document.getElementById("orig_grand_tot").value = totalamt.toFixed(2);

var GrandTotAmt = document.getElementById("grandTotal").value;
var gtotal_brk=GrandTotAmt.split('.');
	if(gtotal_brk[1]>=50)
	{
	var finalAmt=parseInt(gtotal_brk[0])+1;
	}
	else if(gtotal_brk[1]<50)
	{
	var finalAmt=parseInt(gtotal_brk[0]);
	}
	else if(gtotal_brk[1]==00)
	{
	var finalAmt=parseInt(gtotal_brk[0]);
	}
	document.getElementById("grandTotal").value=finalAmt.toFixed(2);
	
	var OrigGrandTotAmt = document.getElementById("orig_grand_tot").value;
	var NewGrandTotAmt = document.getElementById("grandTotal").value;
	
	if(NewGrandTotAmt>OrigGrandTotAmt)
	{
	document.getElementById("roundOff").value=(parseFloat(NewGrandTotAmt)-parseFloat(OrigGrandTotAmt)).toFixed(2);
	document.getElementById("pluMin").value='+';
	}
	else if(NewGrandTotAmt<OrigGrandTotAmt)
	{
	document.getElementById("roundOff").value=(parseFloat(OrigGrandTotAmt)-parseFloat(NewGrandTotAmt)).toFixed(2);
	document.getElementById("pluMin").value='-';
	}
	else if(NewGrandTotAmt==OrigGrandTotAmt)
	{
	document.getElementById("roundOff").value=(parseFloat(OrigGrandTotAmt)-parseFloat(NewGrandTotAmt)).toFixed(2);
	document.getElementById("pluMin").value='No Round';
	}
}

function calculatetaxable_taxSer()
{
var salestaxamt=document.getElementById("VatCstValueSer").value;
var taxableamt=document.getElementById("taxableAmountSer").value;
	if(salestaxamt==''){salestaxamt=0;}
	if(taxableamt==''){taxableamt=0;}
	
var totalamt=parseFloat(salestaxamt)+parseFloat(taxableamt);	
document.getElementById("total_taxable_amtSer").value=totalamt.toFixed(2);
document.getElementById("grandTotalSer").value=totalamt.toFixed(2);
document.getElementById("orig_grand_totSer").value=totalamt.toFixed(2);


var GrandTotAmt = document.getElementById("grandTotalSer").value;
var gtotal_brk=GrandTotAmt.split('.');
	if(gtotal_brk[1]>=50)
	{
	var finalAmt=parseInt(gtotal_brk[0])+1;
	}
	else if(gtotal_brk[1]<50)
	{
	var finalAmt=parseInt(gtotal_brk[0]);
	}
	else if(gtotal_brk[1]==00)
	{
	var finalAmt=parseInt(gtotal_brk[0]);
	}
	document.getElementById("grandTotalSer").value=finalAmt.toFixed(2);

var OrigGrandTotAmt = document.getElementById("orig_grand_totSer").value;
	var NewGrandTotAmt = document.getElementById("grandTotalSer").value;
	
	if(NewGrandTotAmt>OrigGrandTotAmt)
	{
	document.getElementById("roundValser").value=(parseFloat(NewGrandTotAmt)-parseFloat(OrigGrandTotAmt)).toFixed(2);
	document.getElementById("pluMinSer").value='+';
	}
	else if(NewGrandTotAmt<OrigGrandTotAmt)
	{
	document.getElementById("roundValser").value=(parseFloat(OrigGrandTotAmt)-parseFloat(NewGrandTotAmt)).toFixed(2);
	document.getElementById("pluMinSer").value='-';
	}
	else if(NewGrandTotAmt==OrigGrandTotAmt)
	{
	document.getElementById("roundValser").value=(parseFloat(OrigGrandTotAmt)-parseFloat(NewGrandTotAmt)).toFixed(2);
	document.getElementById("pluMinSer").value='No Round';
	}
}


function calculatetaxable_hrd()
{
var salestaxamt_hrd=document.getElementById("VatCstValue1").value;
var taxableamt_hrd=document.getElementById("hrdtotalAmt").value;
	if(salestaxamt_hrd==''){salestaxamt_hrd=0;}
	if(taxableamt_hrd==''){taxableamt_hrd=0;}
	
var totalamt=parseFloat(salestaxamt_hrd)+parseFloat(taxableamt_hrd);	
document.getElementById("total_taxable_hrd").value=totalamt.toFixed(2);

}
</script>
<script>
function clientselection(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("party").innerHTML=xmlhttp.responseText;			
		}
	}
	//var order=document.getElementById("order_id").value;
	xmlhttp.open("POST","ajax_quotation.php?site="+str,true);
	xmlhttp.send();
}

function get_mobilenumber(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("partyContact2").value=xmlhttp.responseText;			
		}
	}
	//var order=document.getElementById("order_id").value;
	xmlhttp.open("POST","getPhone.php?Contact="+str,true);
	xmlhttp.send();
}

function show_all_conditions(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)
		{
                   // alert(xmlhttp.responseText);
			document.getElementById("all_conditions").innerHTML=xmlhttp.responseText;			
		}
	}
	//var order=document.getElementById("order_id").value;
	xmlhttp.open("POST","check_data_ajax.php?section=show_all_conditions&str="+str,true);
	xmlhttp.send();
}


function get_mobile_num(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("PhoneNo").value=xmlhttp.responseText;
	}
    }
	//var order=document.getElementById("order_id").value;
	xmlhttp.open("POST","get_mobile_num_assoc.php?cid="+str,true);
	xmlhttp.send();
    
}
</script>
