<?php 
session_start();
require_once("../../includes/display_internal_user_dryout.inc.php");
require_once("../../includes/functions_internal_user_dryout.inc.php");
$obj = new data();
$connect = $obj->funConnect();
$display = new display();
$display->logout_iu();
$page 	= $_REQUEST['page'];
$coaid 	= $_REQUEST['coaid'];
$id 	= $_REQUEST['id'];
if(@$_REQUEST['action'] == 'submit')
{
	$msg = $obj->updateCOAestimatesDetails($id);
	header('Location:./coa_list.php?msg='.$msg);
}

$estimatetype = $_SESSION['selBType'];
$obj->viewFreightCostEstimationTempleteRecordsNew($id);
$rdoEstimateType = $obj->getFun158();
$result = mysql_query("select * from coa_master where COAID='".$coaid."'") or die;
$rows   = mysql_fetch_assoc($result);
$currencttoshow = $rows['CURRENCY'];
$rdoQtyType = 1;
$rdoQtyMar = 1;

$pagename = basename($_SERVER['PHP_SELF'])."?coaid=".$coaid."&id=".$id."&page=".$page;
$rdoCap = $rdoQty = 1;
?><!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title><?php $display->title(); ?></title>
<?php $display->favicon(); ?>
<meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
<?php $display->css(); ?>
<?php $display->js(); ?>
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
  <script src="../js/html5shiv.js"></script>
  <script src="../js/respond.min.js"></script>
<![endif]-->
<style>
.animated {
	vertical-align: top; 
	transition: height 0.2s;
	-webkit-transition: height 0.2s; 
	-moz-transition: height 0.2s; 
}

form.cmxform label.error, label.error {
	/* remove the next line when you have trouble in IE6 with labels in list */
	font-family:Verdana, Arial, Helvetica, sans-serif;
	font-size:10px;
	color: red;
	font-style:normal;
	font-weight:lighter;
	margin:5px;
	vertical-align:top;
}
table {border-collapse:separate;}
select{height:19px;}
.select {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 11px;
    font-weight: bold;
    color: #333333;
    /* color: #FBC763; */
    text-decoration: none;
    line-height: 13px;
	height:13px;
}

.input-text {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
	font-weight: normal;
	color: #333333;
	text-decoration: none;
	/*text-transform:uppercase;
	line-height: 15px;*/
}

.input-textsmall {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 9px;
	font-weight: normal;
	color: #333333;
	text-decoration:none;
	text-transform:uppercase;
}


.input 
{
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
font-weight: normal;
color: #333333;
text-decoration: none;
}
</style>
</head>
	<div id="basic-modal-content" style="display:none;" align="center">
	<table cellpadding="1" cellspacing="4" border="0" align="center">
	<tr><td align="center"><img src="../../img/loading.gif" /><br /></td></tr>
	</table>
	</div>
	<body class="skin-blue fixed">
		<a href="#" id="trigger1" title="Calculate" onClick="getFinalCalculation();">Calculate</a>
        <!-- header logo: style can be found in header.less -->
        <?php $display->header_tag(); ?>
		<div class="wrapper row-offcanvas row-offcanvas-left">
            <?php $display->leftmenu(20); ?>
			<aside class="right-side">                
                <!-- Content Header (Page header) -->
                 <section class="content-header">
                    <h1>
                        <i class="fa fa-leaf"></i>&nbsp;COA&nbsp;&nbsp;&nbsp;&nbsp;<small><div class="headline text-center" id="time" style="color:#000; font-weight:bold; font-size:12px;"></div></small>
                    </h1>
                    <ol class="breadcrumb">
                        <li><a href="../"><i class="fa fa-home"></i> Home</a></li>
                        <li class="active">COA</li>
                    </ol>
                </section>
                <div align="right" style="margin-top:5px;margin-bottom:5px;margin-right:5px;"><a href="coa_list.php"><button class="btn btn-info btn-flat">Back</button></a></div>
                <form role="form" name="frm1" id="frm1" enctype="multipart/form-data" action="<?php echo $pagename;?>" method="post">
                <table width="100%" style="margin-bottom:5px; padding:0px 5px 0px 5px;">
                   <tr>
                       <td width="12%" class="input-text" style="color:#175c84;"><strong >Fixture&nbsp;Type&nbsp;:</strong>&nbsp;COA&nbsp;<input type="hidden" name="selFType" id="selFType" value="2"><input type="hidden" name="rdoEstimateType" id="rdoEstimateType" value="<?php echo $_SESSION['selBType'];?>"/></td>&nbsp;&nbsp;
                       <td class="input-text" style="color:#175c84;"><strong>COA&nbsp;ID.:</strong><input type="text" name="txtCOAID" id="txtCOAID" style="width:100px;color:#175c84;background-color:#E1E1E1;" class="input-text" readonly value="<?php echo $rows['COA_ID']; ?>" /></td>
                       <td class="input-text" style="color:#175c84;"><strong>COA&nbsp;No.:</strong><input type="text" name="txtCOAno" id="txtCOAno" style="width:100px;color:#175c84;background-color:#E1E1E1;" class="input-text" readonly value="<?php echo $rows['COA_NO']; ?>" /></td>
                       <td class="input-text" style="color:#175c84;">
                       <strong>Vessel&nbsp;:</strong><select name="selVName" class="input-text" id="selVName" style="width:120px;color:#175c84;" onChange="getData();">
                            <?php 
                            $obj->getVesselTypeListMemberWise($estimatetype);
                            ?>
                            </select>
                       </td>
                       <td class="input-text" style="color:#175c84;"><strong>Vessel&nbsp;Type&nbsp;:</strong><input type="text" name="txtVType" id="txtVType" style="width:95px;color:#175c84;background-color:#E1E1E1;" class="input-text" readonly value="<?php echo $obj->getFun6();?>" />
                        <select  name="selCharterer" style="display:none;"  id="selCharterer">
                        <?php $obj->getVendorListNewForCOA('7,11,10');?>
                        </select> 
                        <select  name="selVendor" style="display:none;"  id="selVendor">
                        <?php $obj->getVendorListNewUpdate();	?>
                        </select> 
                        <select  name="selPort" style="display:none;" id="selPort">
                            <?php $obj->getPortList(); ?>
                        </select>
                        <select name="selOwnerCost" id="selOwnerCost" style="display:none;">
                        <?php $obj->getOwnerRelatedCostList();?>
                        </select>
                        <select name="selMaterial1" id="selMaterial1" style="display:none;">
                        <?php $obj->getCargoNameListForMultiple(1);?>
                        </select>
                        <select name="selMaterial2" id="selMaterial2" style="display:none;">
                        <?php $obj->getCargoNameListForMultiple(2);?>
                        </select>
                        <select name="selMaterial3" id="selMaterial3" style="display:none;">
                        <?php $obj->getCargoNameListForMultiple(3);?>
                        </select>
                       </td>
                       <td class="input-text" style="color:#175c84;"><strong>Date&nbsp;:</strong><input type="text" name="txtDate" id="txtDate" style="width:90px;color:#175c84;" class="input-text" value="<?php echo date("d-m-Y",time($obj->getFun3()));?>" placeholder"dd-mm-yy" /><input type="hidden" name="txtCPDate" id="txtCPDate" value="<?php echo date("d-m-Y",strtotime($rows['COA_DATE']));?>"/></td>
                        <td class="input-text" style="color:#367fa9;"><strong>Voyage&nbsp;No.&nbsp;:</strong><input type="text" name="txtVNo" id="txtVNo" style="width:90px;color:#175c84;" class="input-text" value="<?php echo $obj->getFun8();?>" autocomplete="off" placeholder"" /></td>
                   </tr>
               </table>
                <div id="tabs" class="nav-tabs-custom">
                    <ul class="nav nav-tabs">
                        <li class="active"><a href="#tabs_2" data-toggle="tab">Voyage Financials : Estimate</a></li>
                        <li><a href="#tabs_3" data-toggle="tab">Commercial Parameters</a></li>
                    </ul>
                    
                    <div class="tab-content">
                    
                    <!----------------------------------------------- Start 1------------------------------------------------->
                    <div id="tabs_2" class="tab-pane active" style="overflow:auto;">
                       <table class='tablesorter' width="100%">
						  <tr><td><strong style="font-size:12px;">Main Cargo Details</strong></td></tr>    
					   </table>
					   <table id="maincargodetail" class='tablesorter' width="100%">
						<tbody id="tblmaincargodetail">
							<tr id="maincargodetailrow1_1">
							   <td>#</td>
							   <td><strong>Shipper/Charterer</strong></td>
							   <td><strong>Cargo(CBM)</strong></td>
							   <td><strong>Cargo (MT)</strong></td>
							   <td><strong>Rate <?php echo $currencttoshow;?>/MT</strong></td>
							   <td><strong>Amount(<?php echo $currencttoshow;?>)</strong></td>
							</tr>
                            <?php 
								$sql1 = "select * from freight_cost_estimete_slave10 where FCAID='".$obj->getFun1()."' and STATUS=1";
								
								$res1 = mysql_query($sql1);
								$num1 = mysql_num_rows($res1);
								if($num1==0)
								{$num1 =1;
								?>	 
							 <tr id="maincargodetailrow2_1">
							   <td width="50px;"></td>
							   <td><select name="selCharterers_1" class="input-text" style="width:120px;" id="selCharterers_1" onChange="getFinalCalculation();"></select></td>
							   <td><input type="text" name="txtCargocbm_1" id="txtCargocbm_1" class="input-text" autocomplete="off" value="" placeholder="0.00" onKeyUp="getFinalCalculation();"/></td>
							   <td><input type="text" name="txtCargomt_1" id="txtCargomt_1" class="input-text" autocomplete="off" value="" placeholder="0.00" onKeyUp="getFinalCalculation();"/></td>
							   <td><input type="text" name="txtRateUSDmt_1" id="txtRateUSDmt_1" class="input-text" autocomplete="off" value="" placeholder="0.00" onKeyUp="getFinalCalculation();"/></td>
							   <td><input type="text" name="txtAmountUSD_1" id="txtAmountUSD_1" class="input-text" autocomplete="off" value="" placeholder="0.00" onKeyUp="getFinalCalculation();" readonly style="background-color:#E1E1E1;"/></td>
							   <script>$("#selCharterers_1").html($("#selCharterer").html());</script>
							</tr>
                            <?php }else{$i = 0;
								while($rows1 = mysql_fetch_assoc($res1)){$i++;?>
                              <tr id="maincargodetailrow2_<?php echo $i;?>">
							   <td width="50px;"><?php if($i>1){?><a href="#tb1" onClick="deleteMainCargoDetails(<?php echo $i;?>);" ><i class="fa fa-times" style="color:red;"></i></a><?php }?></td>
							   <td><select name="selCharterers_<?php echo $i;?>" class="input-text" style="width:120px;" id="selCharterers_<?php echo $i;?>" onChange="getFinalCalculation();"></select></td>
							   <td><input type="text" name="txtCargocbm_<?php echo $i;?>" id="txtCargocbm_<?php echo $i;?>" class="input-text" autocomplete="off" value="<?php echo $rows1['CARGO_CBM'];?>" placeholder="0.00" onKeyUp="getFinalCalculation();"/></td>
							   <td><input type="text" name="txtCargomt_<?php echo $i;?>" id="txtCargomt_<?php echo $i;?>" class="input-text" autocomplete="off" value="<?php echo $rows1['CARGO_MT'];?>" placeholder="0.00" onKeyUp="getFinalCalculation();"/></td>
							   <td><input type="text" name="txtRateUSDmt_<?php echo $i;?>" id="txtRateUSDmt_<?php echo $i;?>" class="input-text" autocomplete="off" value="<?php echo $rows1['RATE_USD_MT'];?>" placeholder="0.00" onKeyUp="getFinalCalculation();"/></td>
							   <td><input type="text" name="txtAmountUSD_<?php echo $i;?>" id="txtAmountUSD_<?php echo $i;?>" class="input-text" autocomplete="off" value="<?php echo $rows1['AMOUNT_USD'];?>" placeholder="0.00" onKeyUp="getFinalCalculation();" readonly style="background-color:#E1E1E1;"/></td>
							   <script>$("#selCharterers_<?php echo $i;?>").html($("#selCharterer").html());$("#selCharterers_<?php echo $i;?>").val('<?php echo $rows1['SHIPPER_CHARTER'];?>');</script>
							</tr>  
                            <?php }}?>
						</tbody>
							 
						<tfoot style="background-color:#fff;">
                          <tr><td ><button type="button" onClick="addMainCargoDetails();" >Add</button>
                          <input type="hidden" name="txtMainCargoDetailID" id="txtMainCargoDetailID" value="<?php echo $num1;?>" /></td>
                              <td><strong>Total</strong></td>
                               <td><span id="spancargoCBM"></span></td>
                               <td><span id="spancargoMT"></span></td>
                               <td></td>
                               <td><span id="spanAmountUSD"></span></td>
                              </tr>
                            </tfoot>
                        </table>
        <!------------------------- Start 1----OVERAGE DETAILS------------------------------>
                       <table class='tablesorter' width="100%">
                          <tr><td><strong style="font-size:12px;">Overage</strong></td></tr>    
                       </table>
                       <table id="overagedetail" class='tablesorter' width="100%">
                        <tbody id="tbloveragedetail">
                            <tr id="overagedetailrow1_1">
                               <td>#</td>
                               <td><strong>Shipper/Charterer</strong></td>
                               <td><strong>Cargo(CBM)</strong></td>
                               <td><strong>Cargo (MT)</strong></td>
                               <td><strong>Rate <?php echo $currencttoshow;?>/MT</strong></td>
                               <td><strong>Amount(<?php echo $currencttoshow;?>)</strong></td>
                            </tr>
                            <?php 
								$sql1 = "select * from freight_cost_estimete_slave10 where FCAID='".$obj->getFun1()."' and STATUS=2";
								
								$res1 = mysql_query($sql1);
								$num1 = mysql_num_rows($res1);
								if($num1==0)
								{$num1 =1;
								?>	 
							 <tr id="overagedetailrow2_1">
                               <td width="50px;"><a href="#tb1" onClick="deleteoveragedetail(1);" ><i class="fa fa-times" style="color:red;"></i></a></td>
                               <td><select name="selCharterers2_1" class="input-text" style="width:120px;" id="selCharterers2_1" onChange="getFinalCalculation();"></select></td>
                               <td><input type="text" name="txtCargocbm2_1" id="txtCargocbm2_1" class="input-text" autocomplete="off" value="" placeholder="0.00" onKeyUp="getFinalCalculation();"/></td>
                               <td><input type="text" name="txtCargomt2_1" id="txtCargomt2_1" class="input-text" autocomplete="off" value="" placeholder="0.00" onKeyUp="getFinalCalculation();"/></td>
                               <td><input type="text" name="txtRateUSDmt2_1" id="txtRateUSDmt2_1" class="input-text" autocomplete="off" value="" placeholder="0.00" onKeyUp="getFinalCalculation();"/></td>
                               <td><input type="text" name="txtAmountUSD2_1" id="txtAmountUSD2_1" class="input-text" autocomplete="off" value="" placeholder="0.00" onKeyUp="getFinalCalculation();" readonly style="background-color:#E1E1E1;"/></td>
                               <script>$("#selCharterers2_1").html($("#selCharterer").html());</script>
                            </tr>
                            <?php }else{$i = 0;
								while($rows1 = mysql_fetch_assoc($res1)){$i++;?>
                              <tr id="overagedetailrow2_<?php echo $i;?>">
							   <td width="50px;"><a href="#tb1" onClick="deleteoveragedetail(<?php echo $i;?>);" ><i class="fa fa-times" style="color:red;"></i></a></td>
							   <td><select name="selCharterers2_<?php echo $i;?>" class="input-text" style="width:120px;" id="selCharterers2_<?php echo $i;?>" onChange="getFinalCalculation();"></select></td>
							   <td><input type="text" name="txtCargocbm2_<?php echo $i;?>" id="txtCargocbm2_<?php echo $i;?>" class="input-text" autocomplete="off" value="<?php echo $rows1['CARGO_CBM'];?>" placeholder="0.00" onKeyUp="getFinalCalculation();"/></td>
							   <td><input type="text" name="txtCargomt2_<?php echo $i;?>" id="txtCargomt2_<?php echo $i;?>" class="input-text" autocomplete="off" value="<?php echo $rows1['CARGO_MT'];?>" placeholder="0.00" onKeyUp="getFinalCalculation();"/></td>
							   <td><input type="text" name="txtRateUSDmt2_<?php echo $i;?>" id="txtRateUSDmt2_<?php echo $i;?>" class="input-text" autocomplete="off" value="<?php echo $rows1['RATE_USD_MT'];?>" placeholder="0.00" onKeyUp="getFinalCalculation();"/></td>
							   <td><input type="text" name="txtAmountUSD2_<?php echo $i;?>" id="txtAmountUSD2_<?php echo $i;?>" class="input-text" autocomplete="off" value="<?php echo $rows1['AMOUNT_USD'];?>" placeholder="0.00" onKeyUp="getFinalCalculation();" readonly style="background-color:#E1E1E1;"/></td>
							   <script>$("#selCharterers2_<?php echo $i;?>").html($("#selCharterer").html());$("#selCharterers2_<?php echo $i;?>").val('<?php echo $rows1['SHIPPER_CHARTER'];?>');</script>
							</tr>  
                            <?php }}?>
                        </tbody>
                             
                        <tfoot style="background-color:#fff;">
                          <tr><td ><button type="button" onClick="addoveragedetail();" >Add</button>
                          <input type="hidden" name="txtoveragedetailID" id="txtoveragedetailID" value="<?php echo $num1;?>" /></td>
                              <td><strong>Total</strong></td>
                               <td><span id="spancargoCBM2"></span></td>
                               <td><span id="spancargoMT2"></span></td>
                               <td></td>
                               <td><span id="spanAmountUSD2"></span></td>
                              </tr>
                            </tfoot>
                        </table>
            <!------------------------- Start 1----DEAD FREIGHT DETAILS------------------------------>			
                       <table class='tablesorter' width="100%">
                          <tr><td><strong style="font-size:12px;">Dead-freight</strong></td></tr>    
                       </table>
                       <table id="deadfreightdetail" class='tablesorter' width="100%">
                        <tbody id="tbldeadfreight">
                            <tr id="deadfreightdetailrow1_1">
                               <td>#</td>
                               <td><strong>Shipper/Charterer</strong></td>
                               <td><strong>Cargo(CBM)</strong></td>
                               <td><strong>Cargo (MT)</strong></td>
                               <td><strong>Rate <?php echo $currencttoshow;?>/MT</strong></td>
                               <td><strong>Amount(<?php echo $currencttoshow;?>)</strong></td>
                            </tr>	 
                            <?php 
								$sql1 = "select * from freight_cost_estimete_slave10 where FCAID='".$obj->getFun1()."' and STATUS=3";
								
								$res1 = mysql_query($sql1);
								$num1 = mysql_num_rows($res1);
								if($num1==0)
								{$num1 =1;
								?>	 
							 <tr id="deadfreightdetailrow2_1">
                               <td width="50px;"><a href="#tb1" onClick="deletedeadfreightdetail(1);" ><i class="fa fa-times" style="color:red;"></i></a></td>
                               <td><select name="selCharterers3_1" class="input-text" style="width:120px;" id="selCharterers3_1" onChange="getFinalCalculation();"></select></td>
                               <td><input type="text" name="txtCargocbm3_1" id="txtCargocbm3_1" class="input-text" autocomplete="off" value="" placeholder="0.00" onKeyUp="getFinalCalculation();"/></td>
                               <td><input type="text" name="txtCargomt3_1" id="txtCargomt3_1" class="input-text" autocomplete="off" value="" placeholder="0.00" onKeyUp="getFinalCalculation();"/></td>
                               <td><input type="text" name="txtRateUSDmt3_1" id="txtRateUSDmt3_1" class="input-text" autocomplete="off" value="" placeholder="0.00" onKeyUp="getFinalCalculation();"/></td>
                               <td><input type="text" name="txtAmountUSD3_1" id="txtAmountUSD3_1" class="input-text" autocomplete="off" value="" placeholder="0.00" onKeyUp="getFinalCalculation();" readonly style="background-color:#E1E1E1;"/></td>
                               <script>$("#selCharterers3_1").html($("#selCharterer").html());</script>
                            </tr>
                            <?php }else{$i = 0;
								while($rows1 = mysql_fetch_assoc($res1)){$i++;?>
                              <tr id="deadfreightdetailrow2_<?php echo $i;?>">
							   <td width="50px;"><a href="#tb1" onClick="deletedeadfreightdetail(<?php echo $i;?>);" ><i class="fa fa-times" style="color:red;"></i></a></td>
							   <td><select name="selCharterers3_<?php echo $i;?>" class="input-text" style="width:120px;" id="selCharterers3_<?php echo $i;?>" onChange="getFinalCalculation();"></select></td>
							   <td><input type="text" name="txtCargocbm3_<?php echo $i;?>" id="txtCargocbm3_<?php echo $i;?>" class="input-text" autocomplete="off" value="<?php echo $rows1['CARGO_CBM'];?>" placeholder="0.00" onKeyUp="getFinalCalculation();"/></td>
							   <td><input type="text" name="txtCargomt3_<?php echo $i;?>" id="txtCargomt3_<?php echo $i;?>" class="input-text" autocomplete="off" value="<?php echo $rows1['CARGO_MT'];?>" placeholder="0.00" onKeyUp="getFinalCalculation();"/></td>
							   <td><input type="text" name="txtRateUSDmt3_<?php echo $i;?>" id="txtRateUSDmt3_<?php echo $i;?>" class="input-text" autocomplete="off" value="<?php echo $rows1['RATE_USD_MT'];?>" placeholder="0.00" onKeyUp="getFinalCalculation();"/></td>
							   <td><input type="text" name="txtAmountUSD3_<?php echo $i;?>" id="txtAmountUSD3_<?php echo $i;?>" class="input-text" autocomplete="off" value="<?php echo $rows1['AMOUNT_USD'];?>" placeholder="0.00" onKeyUp="getFinalCalculation();" readonly style="background-color:#E1E1E1;"/></td>
							   <script>$("#selCharterers3_<?php echo $i;?>").html($("#selCharterer").html());$("#selCharterers3_<?php echo $i;?>").val('<?php echo $rows1['SHIPPER_CHARTER'];?>');</script>
							</tr>  
                            <?php }}?>
                             
                        </tbody>
                             
                        <tfoot style="background-color:#fff;">
                      <tr><td ><button type="button" onClick="adddeadfreightdetail();" >Add</button>
                      <input type="hidden" name="txtdeadfreightdetailID" id="txtdeadfreightdetailID" value="<?php echo $num1;?>" /></td>
                          <td><strong>Total</strong></td>
                           <td><span id="spancargoCBM3"></span></td>
                           <td><span id="spancargoMT3"></span></td>
                           <td></td>
                           <td><span id="spanAmountUSD3"></span></td>
                          </tr>
                        </tfoot>
                    </table>
                       <table width="100%">
                       
                       <tr><td colspan="2"><div><strong style="font-size:13px;">Passage & Ports</strong></div></td></tr>
                       <tr>
                           <td width="55%" style="vertical-align:top;">
                          
                              <table class='tablesorter'>
                                <thead>
                                    <tr>
                                        <th>#</th>
                                        <th>From Port</th>
                                        <th>To Port</th>
                                        <th>Distance Type</th>
                                        <th>Passage Type</th>
                                        <th>Distance</th>
                                        <th>Speed Type</th>
                                        <th>Speed Adj.</th>
                                        <th>Margin Dist. <span style="font-size:10px; font-style:italic;">(%)</span></th>
                                        
                                    </tr>
                                </thead>
                                <tbody id="tblPortRotation">
                                <?php 
								$sql1 = "select * from freight_cost_estimete_slave1 where FCAID='".$obj->getFun1()."'";
								
								$res1 = mysql_query($sql1);
								$num1 = mysql_num_rows($res1);
								if($num1==0)
								{$num1 =1;
								?>
                                    <tr id="pr_Row_1">
                                        <td align="center" class="input-text" >
                                          <a href="#pr1" id="spcancel_1" onClick="removePortRotation(1);" ><i class="fa fa-times" style="color:red;"></i></a>
                                        </td>
                                        <td align="left" class="input-text" >
                                           <select  name="selFPort_1" class="input-text" style="width:100px;" id="selFPort_1" onChange="getDistance(1);">
                                         
                                           </select> 
                                        </td>
                                        <td align="left" class="input-text" >
                                           <select  name="selTPort_1" class="input-text" style="width:100px;" id="selTPort_1" onChange="getDistance(1);">
                                                
                                            </select>
                                            <script>$("#selFPort_1,#selTPort_1").html($("#selPort").html());</script>
                                        </td>
                                        <td align="left" class="input-text" >
                                            <select  name="selDType_1" class="input-text" style="width:90px;" id="selDType_1" onChange="getDistance(1);">
                                                <?php $obj->getPortDistanceType(); ?>
                                            </select>
                                        </td>
                                        <td align="left" class="input-text" >
                                            <select  name="selPType_1" class="input-text" style="width:90px;" id="selPType_1" onChange="getVoyageTime()"; >
                                                <?php $obj->getPassageType(); ?>
                                            </select>
                                        </td>
                                        <td align="left" class="input-text" >
                                            <input type="text" name="txtDistance_1" id="txtDistance_1" style="width:70px;" class="input-text"  value="" placeholder="0.00" onKeyUp="getVoyageTime()"; /><span id="ploader_1" style="display:none;"><img src="../../img/ajax-loader2.gif" /></span>
                                        </td>
                                        <td align="left" class="input-text" >
                                            <select  name="selSSpeed_1" class="input-text" style="width:90px;" id="selSSpeed_1" onChange="getVoyageTime()"; >
                                                <?php $obj->getSelectSpeedList(); ?>
                                            </select>
                                        </td>
                                        <td align="left" class="input-text" >
                                            <input type="text" name="txtWeather_1" id="txtWeather_1" style="width:70px;" class="input-text" autocomplete="off" placeholder="0.00"  onKeyUp="getVoyageTime()"; />
                                        </td>
                                        <td align="left" class="input-text" >
                                            <input type="text" name="txtMargin_1" style="width:70px;" id="txtMargin_1" class="input-text" autocomplete="off" placeholder="0.00"  onKeyUp="getVoyageTime()"; />
                                            <input type="hidden" name="txtVoyageTime_1" id="txtVoyageTime_1" class="input-text" autocomplete="off" value="0.00" />
                                            <input type="hidden" name="txtTTLVoyageDays_1" id="txtTTLVoyageDays_1" class="input-text" autocomplete="off" value="0.00" />
                                            <input type="hidden" name="txtTTLFoConsp_1" id="txtTTLFoConsp_1" class="input-text" readonly value="0.00"  />
                                            <input type="hidden" name="txtTTLDoConsp_1" id="txtTTLDoConsp_1" class="input-text" readonly value="0.00"  />
                                        </td>
                                    </tr>	
                                 <?php }
								  else
								  {$i=0;$num1 = $num1;
									  while($rows1 = mysql_fetch_assoc($res1))
									  {$i = $i + 1;
									  ?>
                                     <tr id="pr_Row_<?php echo $i;?>">
                                        <td align="center" class="input-text" >
                                          <a href="#pr<?php echo $i;?>" id="spcancel_1" onClick="removePortRotation(<?php echo $i;?>);" ><i class="fa fa-times" style="color:red;"></i></a><input type="hidden" name="txtFCASlaveID_<?php echo $i;?>" id="txtFCASlaveID_<?php echo $i;?>" value="<?php echo $rows1['FCA_SLAVEID'];?>"/><input type="hidden" name="txtFCASlaveRandomID_<?php echo $i;?>" id="txtFCASlaveRandomID_<?php echo $i;?>" value="<?php echo $rows1['RANDOMID'];?>"/>
                                        </td>
                                        <td align="left" class="input-text" >
                                           <select  name="selFPort_<?php echo $i;?>" class="input-text" style="width:100px;" id="selFPort_<?php echo $i;?>" onChange="getDistance(<?php echo $i;?>);">
                                         
                                           </select> 
                                        </td>
                                        <td align="left" class="input-text" >
                                           <select  name="selTPort_<?php echo $i;?>" class="input-text" style="width:100px;" id="selTPort_<?php echo $i;?>" onChange="getDistance(<?php echo $i;?>);">
                                                
                                            </select>
                                            <script>$("#selFPort_<?php echo $i;?>,#selTPort_<?php echo $i;?>").html($("#selPort").html());$("#selFPort_<?php echo $i;?>").val(<?php echo $rows1['FROM_PORT'];?>);$("#selTPort_<?php echo $i;?>").val(<?php echo $rows1['TO_PORT'];?>);</script>
                                        </td>
                                        <td align="left" class="input-text" >
                                            <select  name="selDType_<?php echo $i;?>" class="input-text" style="width:90px;" id="selDType_<?php echo $i;?>" onChange="getDistance(<?php echo $i;?>);">
                                                <?php $obj->getPortDistanceType(); ?>
                                            </select>
                                            <script>$("#selDType_<?php echo $i;?>").val(<?php echo $rows1['DIS_TYPE'];?>);</script>
                                        </td>
                                        <td align="left" class="input-text" >
                                            <select  name="selPType_<?php echo $i;?>" class="input-text" style="width:90px;" id="selPType_<?php echo $i;?>" onChange="getVoyageTime()"; >
                                                <?php $obj->getPassageType(); ?>
                                            </select>
                                            <script>$("#selPType_<?php echo $i;?>").val(<?php echo $rows1['PASSAGE_TYPE'];?>);</script>
                                        </td>
                                        <td align="left" class="input-text" >
                                            <input type="text" name="txtDistance_<?php echo $i;?>" id="txtDistance_<?php echo $i;?>" style="width:70px;" class="input-text"  value="<?php echo $rows1['DISTANCE'];?>" placeholder="0.00" onKeyUp="getVoyageTime()"; /><span id="ploader_<?php echo $i;?>" style="display:none;"><img src="../../img/ajax-loader2.gif" /></span>
                                        </td>
                                        <td align="left" class="input-text" >
                                            <select  name="selSSpeed_<?php echo $i;?>" class="input-text" style="width:90px;" id="selSSpeed_<?php echo $i;?>" onChange="getVoyageTime()"; >
                                                <?php $obj->getSelectSpeedList(); ?>
                                            </select>
                                            <script>$("#selSSpeed_<?php echo $i;?>").val(<?php echo $rows1['SPEED_TYPE'];?>);</script>
                                        </td>
                                        <td align="left" class="input-text" >
                                            <input type="text" name="txtWeather_<?php echo $i;?>" id="txtWeather_<?php echo $i;?>" style="width:70px;" class="input-text" autocomplete="off" placeholder="0.00" value="<?php echo $rows1['SPEED_ADJ'];?>"  onKeyUp="getVoyageTime()"; />
                                        </td>
                                        <td align="left" class="input-text" >
                                            <input type="text" name="txtMargin_<?php echo $i;?>" style="width:70px;" id="txtMargin_<?php echo $i;?>" class="input-text" autocomplete="off" placeholder="0.00" value="<?php echo $rows1['MARGIN_DISTANCE'];?>" onKeyUp="getVoyageTime()"; />
                                            <input type="hidden" name="txtVoyageTime_<?php echo $i;?>" id="txtVoyageTime_<?php echo $i;?>" class="input-text" autocomplete="off" value="0.00" />
                                            <input type="hidden" name="txtTTLVoyageDays_<?php echo $i;?>" id="txtTTLVoyageDays_<?php echo $i;?>" class="input-text" autocomplete="off" value="0.00" />
                                            <input type="hidden" name="txtTTLFoConsp_<?php echo $i;?>" id="txtTTLFoConsp_<?php echo $i;?>" class="input-text" readonly value="0.00"  />
                                            <input type="hidden" name="txtTTLDoConsp_<?php echo $i;?>" id="txtTTLDoConsp_<?php echo $i;?>" class="input-text" readonly value="0.00"  />
                                        </td>
                                    </tr>  
                                      
                                 <?php }}
								  ?>									
                                </tbody>
                                <tfoot>
                                <tr>
                                <th colspan="9"><button type="button" onClick="addPortRotationDetails()" >Add</button><input type="hidden" name="p_rotationID" id="p_rotationID" class="input" value="<?php echo $num1;?>" /></th>
                                </tr>
                                </tfoot>
                            </table>
                            <table class='tablesorter'>
                                <thead>
                                    <tr>
                                        <th>Load Port(s)</th>
                                        <th>Port&nbsp;Costs<span style="font-size:10px; font-style:italic;">(<?php echo $currencttoshow;?>)</span>&nbsp;</th>
                                        <th>Qty&nbsp;<span id="loadqtylabel">(MT)</span>&nbsp;&nbsp;</th>
                                        <th>Rate&nbsp;<span style="font-size:10px; font-style:italic;" id="loadtablelebel">(MT/Day)</span></th>
                                        <th>LP/Terms&nbsp;&nbsp;</th>
                                        <th>Work&nbsp;Days&nbsp;&nbsp;</th>
                                        <th>Idle&nbsp;Days&nbsp;</th>
                                        <th>No Dem/Disp?</th>
                                    </tr>
                                </thead>
                                <tbody id="tblLoadPort">
                                <?php 
								$sql1 = "select * from freight_cost_estimete_slave1 where FCAID='".$obj->getFun1()."'";
								
								$res1 = mysql_query($sql1);
								$num1 = mysql_num_rows($res1);
								if($num1==0)
								{$num1 =1;
								?>
                                    <tr id="lp_Row_1">
                                        <td align="center" class="input-text" >
                                            <span id="spanLoadPort_1"></span>
                                        </td>
                                        <td align="left" class="input-text" >
                                            <input type="text" name="txtPCosts_1" id="txtPCosts_1" style="width:80px;" class="input-text" autocomplete="off" value="" placeholder="0.00" onKeyUp="getFinalCalculation();"/>
                                        </td>
                                        <td align="left" class="input-text" >
                                            <input type="text" name="txtQMT_1" id="txtQMT_1" class="input-text" style="width:80px;" onKeyUp="getPortCalculation();" autocomplete="off" value="" placeholder="0.00" />
                                        </td>
                                        <td align="left" class="input-text" >
                                            <input type="text" name="txtRate_1" id="txtRate_1" class="input-text" style="width:80px;" onKeyUp="getPortCalculation();" autocomplete="off" value="" placeholder="0.00" />
                                        </td>
                                        <td align="left" class="input-text" >
                                            <select  name="selLPTerms_1" class="input-text" id="selLPTerms_1" style="width:80px;" onChange="getLPRemoveDaysAttr(1),getPortCalculation();"><?php $obj->getLPTermsList(0);?></select>
                                        </td>
                                        <td align="left" class="input-text" >
                                            <input type="text" name="txtWDays_1" id="txtWDays_1" class="input-text" style="width:80px;" autocomplete="off" readonly value="" onKeyUp= "getVoyageTime();" />
                                        </td>
                                        <td align="left" class="input-text" >
                                            <input type="text" name="txtIDays_1" id="txtIDays_1" class="input-text" style="width:80px;" autocomplete="off" value="" placeholder="0.00" onKeyUp="getVoyageTime();"/>
                                        </td>
                                        <td align="left" class="input-text" style="width:80px;">
                                            <input name="ChkShowDDCLP_1" class="checkbox" id="ChkShowDDCLP_1" type="checkbox" value="1" />
                                        </td>
                                    </tr>
                                 <?php }
								 else
								  {$i=0;$num1 = $num1;
								  while($rows1 = mysql_fetch_assoc($res1))
								  {$i = $i + 1;
								  ?>
                                  <tr id="lp_Row_<?php echo $i;?>">
                                    <td align="center" class="input-text" >
                                        <span id="spanLoadPort_<?php echo $i;?>"><?php echo $obj->getPortNameBasedOnID($rows1['FROM_PORT']);?></span>
                                    </td>
                                    <td align="left" class="input-text" >
                                        <input type="text" name="txtPCosts_<?php echo $i;?>" id="txtPCosts_<?php echo $i;?>" style="width:80px;" class="input-text" autocomplete="off" value="<?php echo $rows1['LOAD_PORT_COST'];?>" placeholder="0.00" onKeyUp="getFinalCalculation();"/>
                                    </td>
                                    <td align="left" class="input-text" >
                                        <input type="text" name="txtQMT_<?php echo $i;?>" id="txtQMT_<?php echo $i;?>" class="input-text" style="width:80px;" onKeyUp="getPortCalculation();" autocomplete="off" value="<?php echo $rows1['LOAD_PORT_QTY'];?>" placeholder="0.00" />
                                    </td>
                                    <td align="left" class="input-text" >
                                        <input type="text" name="txtRate_<?php echo $i;?>" id="txtRate_<?php echo $i;?>" class="input-text" style="width:80px;" onKeyUp="getPortCalculation();" autocomplete="off" value="<?php echo $rows1['LOAD_PORT_RATE'];?>" placeholder="0.00" />
                                    </td>
                                    <td align="left" class="input-text" >
                                        <select  name="selLPTerms_<?php echo $i;?>" class="input-text" id="selLPTerms_<?php echo $i;?>" style="width:80px;" onChange="getLPRemoveDaysAttr(<?php echo $i;?>),getPortCalculation();"><?php $obj->getLPTermsList($rows1['LOAD_PORT_TERMS']);?></select>
                                    </td>
                                    <?php if($rows1['LOAD_PORT_TERMS']==4){$readonly="";}else{$readonly="readonly";}?>
                                    <td align="left" class="input-text" >
                                        <input type="text" name="txtWDays_<?php echo $i;?>" id="txtWDays_<?php echo $i;?>" class="input-text" style="width:80px;" <?php echo $readonly;?> autocomplete="off" value="<?php echo $rows1['LOAD_PORT_WORK_DAYS'];?>" onKeyUp= "getVoyageTime();" />
                                    </td>
                                    <td align="left" class="input-text" >
                                        <input type="text" name="txtIDays_<?php echo $i;?>" id="txtIDays_<?php echo $i;?>" class="input-text" style="width:80px;" autocomplete="off" value="<?php echo $rows1['LOAD_PORT_IDEAL_DAYS'];?>" placeholder="0.00" onKeyUp="getVoyageTime();"/>
                                    </td>
                                    <td align="left" class="input-text" style="width:80px;">
                                        <input name="ChkShowDDCLP_<?php echo $i;?>" class="checkbox" id="ChkShowDDCLP_<?php echo $i;?>" type="checkbox" <?php if($rows1['IS_SHOW_DDCLP'] > 0) echo "checked"; ?> value="<?php echo $i;?>" />
                                    </td>
                                </tr>
                                  
                              <?php }}?>										
                                </tbody>
                              </table>
                              <table class='tablesorter'>
                                <thead>
                                    <tr>
                                        <th>Discharge Port</th>
                                        <th>Port&nbsp;Costs<span style="font-size:10px; font-style:italic;">(<?php echo $currencttoshow;?>)</span>&nbsp;</th>
                                        <th>Qty&nbsp;<span id="dischargeqtylabel">(MT)</span></th>
                                        <th>Rate&nbsp;<span style="font-size:10px; font-style:italic;" id="dischargetablelebel">(MT/Day)</span>&nbsp;&nbsp;&nbsp;</th>
                                        <th>&nbsp;DP/Terms</th>
                                        <th>Work&nbsp;Days&nbsp;&nbsp;</th>
                                        <th>Idle&nbsp;Days&nbsp;</th>
                                        <th>No Dem/Disp?</th>
                                    </tr>
                                </thead>
                                <tbody id="tblDisPort">
									<?php 
                                    $sql1 = "select * from freight_cost_estimete_slave1 where FCAID='".$obj->getFun1()."'";
                                    
                                    $res1 = mysql_query($sql1);
                                    $num1 = mysql_num_rows($res1);
                                    if($num1==0)
                                    {$num1 =1;
                                    ?>
                                    <tr id="dp_Row_1">
                                        <td align="center" class="input-text" >
                                            <span id="spanDisPort_1"></span>
                                        </td>
                                        <td align="left" class="input-text" >
                                            <input type="text" name="txtDCosts_1" id="txtDCosts_1" style="width:80px;" class="input-text" autocomplete="off" value="" placeholder="0.00" onKeyUp="getFinalCalculation();"/>
                                        </td>
                                        <td align="left" class="input-text" >
                                            <input type="text" name="txtDQMT_1" id="txtDQMT_1" style="width:80px;" class="input-text" onKeyUp="getPortCalculation();" autocomplete="off" value="" placeholder="0.00" />
                                        </td>
                                        <td align="left" class="input-text" >
                                            <input type="text" name="txtDRate_1" id="txtDRate_1" style="width:80px;" class="input-text" onKeyUp="getPortCalculation();" autocomplete="off" value="" placeholder="0.00" />
                                        </td>
                                        <td align="left" class="input-text" >
                                            <select  name="selDPTerms_1" class="input-text" style="width:80px;" id="selDPTerms_1" onChange="getDPRemoveDaysAttr(1),getPortCalculation();"><?php $obj->getLPTermsList(0);?></select>
                                        </td>
                                        <td align="left" class="input-text" >
                                            <input type="text" name="txtDWDays_1" id="txtDWDays_1" style="width:80px;" class="input-text" autocomplete="off" readonly value="" onKeyUp= "getVoyageTime();"/>
                                        </td>
                                        <td align="left" class="input-text" >
                                            <input type="text" name="txtDIDays_1" id="txtDIDays_1" style="width:80px;" class="input-text" autocomplete="off" value="" placeholder="0.00"  onKeyUp="getVoyageTime();"/>
                                        </td>
                                        <td align="left" class="input-text" style="width:80px;">
                                            <input name="ChkShowDDCDP_1" class="checkbox" id="ChkShowDDCDP_1" type="checkbox" value="1" />
                                        </td>
                                    </tr>
                                    <?php }
									 else
									  {$i=0;$num1 = $num1;
									  while($rows1 = mysql_fetch_assoc($res1))
									  {$i = $i + 1;
									 ?>
                                    <tr id="dp_Row_1">
                                        <td align="center" class="input-text" >
                                            <span id="spanDisPort_<?php echo $i;?>"><?php echo $obj->getPortNameBasedOnID($rows1['TO_PORT']);?></span>
                                        </td>
                                        <td align="left" class="input-text" >
                                            <input type="text" name="txtDCosts_<?php echo $i;?>" id="txtDCosts_<?php echo $i;?>" style="width:80px;" class="input-text" autocomplete="off" value="<?php echo $rows1['DISC_PORT_COST'];?>" placeholder="0.00" onKeyUp="getFinalCalculation();"/>
                                        </td>
                                        <td align="left" class="input-text" >
                                            <input type="text" name="txtDQMT_<?php echo $i;?>" id="txtDQMT_<?php echo $i;?>" style="width:80px;" class="input-text" onKeyUp="getPortCalculation();" autocomplete="off" value="<?php echo $rows1['DISC_PORT_QTY'];?>" placeholder="0.00" />
                                        </td>
                                        <td align="left" class="input-text" >
                                            <input type="text" name="txtDRate_<?php echo $i;?>" id="txtDRate_<?php echo $i;?>" style="width:80px;" class="input-text" onKeyUp="getPortCalculation();" autocomplete="off" value="<?php echo $rows1['DISC_PORT_RATE'];?>" placeholder="0.00" />
                                        </td>
                                        <td align="left" class="input-text" >
                                            <select  name="selDPTerms_<?php echo $i;?>" class="input-text" style="width:80px;" id="selDPTerms_<?php echo $i;?>" onChange="getDPRemoveDaysAttr(<?php echo $i;?>),getPortCalculation();"><?php $obj->getLPTermsList($rows1['DISC_PORT_TERMS']);?></select>
                                        </td>
                                        <?php if($rows1['DISC_PORT_TERMS']==4){$readonly="";}else{$readonly="readonly";}?>
                                        <td align="left" class="input-text" >
                                            <input type="text" name="txtDWDays_<?php echo $i;?>" id="txtDWDays_<?php echo $i;?>" style="width:80px;" class="input-text" autocomplete="off" readonly value="<?php echo $rows1['DISC_PORT_WORK_DAYS'];?>" onKeyUp= "getVoyageTime();"/>
                                        </td>
                                        <td align="left" class="input-text" >
                                            <input type="text" name="txtDIDays_<?php echo $i;?>" id="txtDIDays_<?php echo $i;?>" style="width:80px;" class="input-text" autocomplete="off" value="<?php echo $rows1['DISC_PORT_IDEAL_DATE'];?>" placeholder="0.00"  onKeyUp="getVoyageTime();"/>
                                        </td>
                                        <td align="left" class="input-text" style="width:80px;">
                                            <input name="ChkShowDDCDP_<?php echo $i;?>" class="checkbox" id="ChkShowDDCDP_<?php echo $i;?>" <?php if($rows1['IS_SHOW_DDCDP'] > 0) echo "checked"; ?> type="checkbox" value="<?php echo $i;?>" />
                                        </td>
                                    </tr>
                                  <?php }}?>												
                                </tbody>
                                
                              </table>
                                 <table class='tablesorter'>
                                    <thead>
                                        <tr>
                                            <th>Transit Port</th>
                                            <th>Port Costs<span style="font-size:10px; font-style:italic;">(<?php echo $currencttoshow;?>)</span></th>
                                            <th>Idle Days</th>
                                        </tr>
                                    </thead>
                                    <tbody id="tblTransitPort">
                                        <?php 
										$sql1 = "select * from freight_cost_estimete_slave1 where FCAID='".$obj->getFun1()."'";
										
										$res1 = mysql_query($sql1);
										$num1 = mysql_num_rows($res1);
										if($num1==0)
										{$num1 =1;
										?>
                                        <tr id="tp_Row_1">
                                            <td align="center" class="input-text" >
                                                <span id="TranDisPort_1"></span>
                                            </td>
                                            <td align="left" class="input-text" >
                                                <input type="text" name="txtTLPCosts_1" id="txtTLPCosts_1" style="width:80px;" class="input-text" autocomplete="off" value="" placeholder="0.00" onKeyUp="getPortCalculation();"/>
                                            </td>
                                            <td align="left" class="input-text" >
                                                <input type="text" name="txtTLIDays_1" id="txtTLIDays_1" style="width:80px;" class="input-text" autocomplete="off" value="" placeholder="0.00" onKeyUp="getPortCalculation();"/>
                                            </td>
                                        </tr>
									<?php }
                                     else
                                      {$i=0;$num1 = $num1;
                                      while($rows1 = mysql_fetch_assoc($res1))
                                      {$i = $i + 1;
                                      ?>
                                      <tr id="tp_Row_<?php echo $i;?>">
                                        <td align="center" class="input-text" >
                                            <span id="TranDisPort_<?php echo $i;?>"><?php echo $obj->getPortNameBasedOnID($rows1['FROM_PORT']);?></span>
                                        </td>
                                        <td align="left" class="input-text" >
                                            <input type="text" name="txtTLPCosts_<?php echo $i;?>" id="txtTLPCosts_<?php echo $i;?>" style="width:80px;" class="input-text" autocomplete="off" value="<?php echo $rows1['TRANSIT_PORT_COST'];?>" placeholder="0.00" onKeyUp="getPortCalculation();"/>
                                        </td>
                                        <td align="left" class="input-text" >
                                            <input type="text" name="txtTLIDays_<?php echo $i;?>" id="txtTLIDays_<?php echo $i;?>" style="width:80px;" class="input-text" autocomplete="off" value="<?php echo $rows1['TRANSIT_PORT_IDLE_DAYS'];?>" placeholder="0.00" onKeyUp="getPortCalculation();"/>
                                        </td>
                                    </tr>	
                                      <?php }}?>															
                                    </tbody>
                                </table>
                                
                                <table>
                                  <tr class="input-text">
                                     <td>Laden Dist</td><td>&nbsp;:&nbsp;</td><td><input type="text" name="txtLDist" id="txtLDist" class="input-text" style="width:100px;" readonly value="<?php echo $obj->getFun55();?>" /></td><td>&nbsp;&nbsp;&nbsp;&nbsp;Ballast Dist</td><td>&nbsp;:&nbsp;</td><td><input type="text" name="txtBDist" id="txtBDist" style="width:100px;" class="input-text" readonly value="<?php echo $obj->getFun56();?>" /></td><td>&nbsp;&nbsp;&nbsp;&nbsp;Total Dist</td><td>&nbsp;:&nbsp;</td><td><input type="text" name="txtTDist" id="txtTDist" class="input-text" style="width:100px;" readonly value="<?php echo $obj->getFun63();?>" /></td>
                                  </tr>
                                  <tr class="input-text">
                                     <td>Laden Days</td><td>&nbsp;:&nbsp;</td><td><input type="text" name="txtLDays" id="txtLDays" class="input-text" style="width:100px;" readonly value="<?php echo $obj->getFun57();?>" /></td><td>&nbsp;&nbsp;&nbsp;&nbsp;Ballast Days</td><td>&nbsp;:&nbsp;</td><td><input type="text" name="txtBDays" id="txtBDays" style="width:100px;" class="input-text" readonly value="<?php echo $obj->getFun58();?>" /></td><td>&nbsp;&nbsp;&nbsp;&nbsp;Total Sea Days</td><td>&nbsp;:&nbsp;</td><td><input type="text" name="txtTSDays" id="txtTSDays" class="input-text" style="width:100px;" readonly value="<?php echo $obj->getFun59();?>" /></td>
                                  </tr>
                                  <tr class="input-text">
                                     <td>Ttl Port Idle Days</td><td>&nbsp;:&nbsp;</td><td><input type="text" name="txtTtPIDays" id="txtTtPIDays" class="input-text" style="width:100px;" readonly value="<?php echo $obj->getFun60();?>" /></td><td>&nbsp;&nbsp;&nbsp;&nbsp;Ttl Port Work Days</td><td>&nbsp;:&nbsp;</td><td><input type="text" name="txtTtPWDays" id="txtTtPWDays" style="width:100px;" class="input-text" readonly value="<?php echo $obj->getFun61();?>" /></td><td>&nbsp;&nbsp;&nbsp;&nbsp;Total Days</td><td>&nbsp;:&nbsp;</td><td><input type="text" name="txtTDays" id="txtTDays" class="input-text" style="width:100px;" readonly value="<?php echo $obj->getFun62();?>" /></td>
                                  </tr>
                                  <tr class="input-text">
                                     <td>Ttl FO Consp MT</td><td>&nbsp;:&nbsp;</td><td><input type="text" name="txtTFUMT" id="txtTFUMT" class="input-text" style="width:100px;" readonly value="<?php echo $obj->getFun64();?>" /></td><td>&nbsp;&nbsp;&nbsp;&nbsp;Ttl DO Consp MT</td><td>&nbsp;:&nbsp;</td><td><input type="text" name="txtTDUMT" id="txtTDUMT" style="width:100px;" class="input-text" readonly value="<?php echo $obj->getFun65();?>" /></td><td></td><td></td><td></td>
                                  </tr>
                                </table>
                                <div><strong style="font-size:13px;">Demurrage Dispatch</strong></div>
								    <table class='tablesorter'>
										<thead>
											<tr>
												<th width="20%"></th>
												<th width="15%">Estimated(<?php echo $currencttoshow;?>)</th>
                                                <th width="15%">Actual(<?php echo $currencttoshow;?>)</th>
                                                <th width="15%">Add Comm(%)</th>
												<th width="15%">Nett Value(<?php echo $currencttoshow;?>)</th>
											</tr>
										</thead>
										<tbody id="tbDDCBody">
                                        
                                        <?php 
											$mysql2 = "select * from freight_cost_estimete_slave1 where FCAID='".$id."'";
											$myres2 = mysql_query($mysql2);
											$myrec2 = mysql_num_rows($myres2);
											if($myrec2 ==0)
											{?>
										      <tr id="DDCLProw_1"> 
												<td>Load Port <span id="spanDDCLPort_1"></span></td>
												<td><input type="text"  name="txtEstDDCLPCost_1" id="txtEstDDCLPCost_1" class="input-text" value="" placeholder="0.00" autocomplete="off" onKeyUp="getFinalCalculation();" /><input type="hidden" name="txtLPLayTimeIs_1" id="txtLPLayTimeIs_1" value="" /></td>
												<td><input type="text"  name="txtDDCLPCost_1" id="txtDDCLPCost_1" class="input-text" value="" placeholder="0.00" onKeyUp="getFinalCalculation();" readonly autocomplete="off"/></td>
                                                <td><input type="text"  name="txtLPADDComm_1" id="txtLPADDComm_1" class="input-text" value="" placeholder="0.00" autocomplete="off" onKeyUp="getFinalCalculation();" /></td>
                                                <td><input type="text" name="txtDDCLPNetCostMT_1" id="txtDDCLPNetCostMT_1" class="input-text" readonly value="" /><input type="hidden" name="txtDDCLPCostMT_1" id="txtDDCLPCostMT_1" class="input-text" readonly value="0" /></td>
                                              </tr>	
                                              <tr id="DDCDProw_1"> 
												<td>Discharge Port <span id="spanDDCDPort_1"></span></td>
												<td><input type="text"  name="txtEstDDCDPCost_1" id="txtEstDDCDPCost_1" class="input-text" value="" placeholder="0.00" autocomplete="off" onKeyUp="getFinalCalculation();" /><input type="hidden" name="txtDPLayTimeIs_1" id="txtDPLayTimeIs_1" value="" /></td>
												<td><input type="text"  name="txtDDCDPCost_1" id="txtDDCDPCost_1" class="input-text" value="" placeholder="0.00" onKeyUp="getFinalCalculation();" readonly autocomplete="off"/></td>
                                                <td><input type="text"  name="txtDPADDComm_1" id="txtDPADDComm_1" class="input-text" value="" placeholder="0.00" autocomplete="off" onKeyUp="getFinalCalculation();" /></td>
                                                <td><input type="text" name="txtDDCDPNetCostMT_1" id="txtDDCDPNetCostMT_1" class="input-text" readonly value="" /><input type="hidden" name="txtDDCDPCostMT_1" id="txtDDCDPCostMT_1" class="input-text" readonly value="0" /></td>
											 </tr>
									 <?php }
											else
											{$i=1;
											while($myrows2 = mysql_fetch_assoc($myres2))
											{
											$laytime_valLP = $obj->getLayTimeValuesBasedOnComID($mappingid,$myrows2['LOADPORTID'],"LP",$i);
											$laytime_valLP = explode('@#@',$laytime_valLP);
											if($laytime_valLP[1]== 0){$laytimeLP = $laytime_valLP[2];}else{$laytimeLP = $laytime_valLP[1];}
											if($laytime_valLP[0]== 0){$readonlyLP = "";}else{$readonlyLP = "readonly";}
											
											$laytime_valDP = $obj->getLayTimeValuesBasedOnComID($comid,$myrows2['LOADPORTID'],"DP",$i);
											$laytime_valDP = explode('@#@',$laytime_valDP);
											if($laytime_valDP[1]== 0){$laytimeDP = $laytime_valDP[2];}else{$laytimeDP = $laytime_valDP[1];}
											if($laytime_valDP[0]== 0){$readonlyDP = "";}else{$readonlyDP = "readonly";}
											if($myrows2['IS_SHOW_DDCDP'] > 0){$display1 = 'style="display:none;"';}else{$display1 = '';}
											if($myrows2['IS_SHOW_DDCLP'] > 0){$display2 = 'style="display:none;"';}else{$display2 = '';}
											?>
											<tr id="DDCLProw_<?php echo $i;?>" <?php echo $display2;?>> 
												<td>Load Port <span id="spanDDCLPort_<?php echo $i;?>"><?php echo $obj->getPortNameBasedOnID($myrows2['FROM_PORT']);?></span></td>
												<td><input type="text"  name="txtEstDDCLPCost_<?php echo $i;?>" id="txtEstDDCLPCost_<?php echo $i;?>" class="input-text" value="<?php echo $myrows2['DDCLP_ESTCOST'];?>" autocomplete="off" onKeyUp="getFinalCalculation();" <?php echo $readonlyLP;?>/><input type="hidden" name="txtLPLayTimeIs_<?php echo $i;?>" id="txtLPLayTimeIs_<?php echo $i;?>" value="<?php echo $laytime_valLP[0];?>" /></td>
												
												<td><input type="text"  name="txtDDCLPCost_<?php echo $i;?>" id="txtDDCLPCost_<?php echo $i;?>" class="input-text" value="<?php echo $myrows2['DDCLP_REALCOST'];?>" onKeyUp="getFinalCalculation();" readonly autocomplete="off"/></td>
                                                <td><input type="text"  name="txtLPADDComm_<?php echo $i;?>" id="txtLPADDComm_<?php echo $i;?>" class="input-text" value="<?php echo $myrows2['DDCLP_COMM'];?>" placeholder="0.00" autocomplete="off" onKeyUp="getFinalCalculation();" /></td>
                                                <?php $omcvalueLP = $myrows2['DDCLP_ESTCOST'] - (($myrows2['DDCLP_ESTCOST'] * $myrows2['DDCLP_COMM'])/100);?>
												<td><input type="text" name="txtDDCLPNetCostMT_<?php echo $i;?>" id="txtDDCLPNetCostMT_<?php echo $i;?>" class="input-text" readonly value="<?php echo $omcvalueLP;?>" /><input type="hidden" name="txtDDCLPCostMT_<?php echo $i;?>" id="txtDDCLPCostMT_<?php echo $i;?>" class="input-text" readonly value="<?php echo $myrows2['DDCLP_NETCOST'];?>" /></td>
                                              </tr>	
                                              <tr id="DDCDProw_<?php echo $i;?>" <?php echo $display1;?>> 
												<td>Discharge Port <span id="spanDDCDPort_<?php echo $i;?>"><?php echo $obj->getPortNameBasedOnID($myrows2['TO_PORT']);?></span></td>
												<td><input type="text"  name="txtEstDDCDPCost_<?php echo $i;?>" id="txtEstDDCDPCost_<?php echo $i;?>" class="input-text" value="<?php echo $myrows2['DDCDP_ESTCOST'];?>" autocomplete="off" onKeyUp="getFinalCalculation();" <?php echo $readonlyDP;?>/><input type="hidden" name="txtDPLayTimeIs_<?php echo $i;?>" id="txtDPLayTimeIs_<?php echo $i;?>" value="<?php echo $laytime_valDP[0];?>" /></td>
												
												<td><input type="text"  name="txtDDCDPCost_<?php echo $i;?>" id="txtDDCDPCost_<?php echo $i;?>" class="input-text" value="<?php echo $myrows2['DDCDP_REALCOST'];?>" onKeyUp="getFinalCalculation();" readonly autocomplete="off"/></td>
                                                <td><input type="text"  name="txtDPADDComm_<?php echo $i;?>" id="txtDPADDComm_<?php echo $i;?>" class="input-text" value="<?php echo $myrows2['DDCDP_COMM'];?>" placeholder="0.00" autocomplete="off" onKeyUp="getFinalCalculation();" /></td>
                                                <?php $omcvalueDP = $myrows2['DDCDP_ESTCOST'] - (($myrows2['DDCDP_ESTCOST'] * $myrows2['DDCDP_COMM'])/100);?>
												<td><input type="text" name="txtDDCDPNetCostMT_<?php echo $i;?>" id="txtDDCDPNetCostMT_<?php echo $i;?>" class="input-text" readonly value="<?php echo $omcvalueDP;?>" /><input type="hidden" name="txtDDCDPCostMT_<?php echo $i;?>" id="txtDDCDPCostMT_<?php echo $i;?>" class="input-text" readonly value="<?php echo $myrows2['DDCDP_NETCOST'];?>" /></td>
                                              </tr>		
									<?php $i++;}} ?>
                                        
                                        
                                        
										    	
									 	</tbody>
									</table>
                           </td>
                           <td width="45%" id="parenttdID" style="border-left:1px solid #D8D8D8;vertical-align:top;">
                               
                                <input type="hidden" name="txtBunkerWidth" id="txtBunkerWidth" readonly value=""/>
                                <input type="hidden" name="txtBunkerWidth1" id="txtBunkerWidth1" readonly value="1"/>
                                <div style="overflow:auto; max-width:520px;" id="bunkercontainer">
                                <table class='tablesorter'>
                                    <thead>
                                        <tr class="GridviewScrollHeader">
                                            <th colspan="1">Bunkers</th>
                                            <?php
                                                
                                                $sql = "SELECT * FROM bunker_grade_master where MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and STATUS=1";
                                                $res = mysql_query($sql);
                                                $rec = mysql_num_rows($res);
                                                
                                                if($rec == 0)
                                                {
                                            ?>
                                            <tr>
                                                <td valign="top" align="center" colspan="6" style="color:red;">First fill the Bunker Grade Master Data.</td>
                                            </tr>
                                            <?php	
                                            }else{
                                            ?>
                                            <?php $m=0; while($rows = mysql_fetch_assoc($res)){
                                                $ttl_bg[]  = $rows['NAME'];
												$ttl_bgtype[]  = $rows['BUNKERTYPE'];
                                                $ttl_bg1[] = $rows['BUNKERGRADEID'];
                                            ?>
                                                 <th colspan="3" style="text-align:center;"><?php echo $rows['NAME'];?>&nbsp;&nbsp;</th>
                                            <?php $m++; ?>
                                        <?php } ?>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr class="GridviewScrollHeader">
                                            <td>&nbsp;</td>
                                            <?php for($i=0;$i<count($ttl_bg);$i++){?>
                                            <td style="text-align:center;">MT</td>
                                            <td style="text-align:center;">Price</td>
                                            <td style="text-align:center;">Cost<input type="hidden" name="txtBunkerRec" id="txtBunkerRec" class="input-text" readonly value="<?php echo $rec;?>"/>			 
                                            <input type="hidden" name="txtBunkerGradeName_<?php echo $i+1;?>" id="txtBunkerGradeName_<?php echo $i+1;?>" class="input-text" readonly value="<?php echo $ttl_bg[$i];?>"/>	
                                            <input type="hidden" name="txtBunkerGradeType_<?php echo $i+1;?>" id="txtBunkerGradeType_<?php echo $i+1;?>" class="input-text" readonly value="<?php echo $ttl_bgtype[$i];?>"/>	
                                            <input type="hidden" name="txtBunkerGradeID_<?php echo $i+1;?>" id="txtBunkerGradeID_<?php echo $i+1;?>" class="input-text" readonly value="<?php echo $ttl_bg1[$i];?>"/>
                                             <input type="hidden" name="txtBHID_<?php echo $ttl_bg1[$i];?>" id="txtBHID_<?php echo $ttl_bg1[$i];?>" value="<?php echo $ttl_bg[$i];?>" class="input-text"/>
                                             <input type="hidden" name="txtBHID1[]" id="txtBHID1_<?php echo $ttl_bg1[$i];?>" value="<?php echo $ttl_bg1[$i];?>" class="input-text"/>
                                             </td>
                                            <?php }?>
                                        </tr>
    
                                        <tr class="GridviewScrollItem">
                                            <td class="fixed-column">Estimated</td>
                                            <?php $j=$k=0; for($i=0;$i<count($ttl_bg);$i++){			
                                            ?>
                                            <td>
                                            <input type="text"  name="txt<?php echo $ttl_bg[$i];?>_1_1" id="txt<?php echo $ttl_bg[$i];?>_1_1" style="width:60px;" onKeyUp="getBunkerCalculation();" value="<?php echo $obj->getBunkerValuesEstimate($obj->getFun1(),$ttl_bg1[$i],"EST_MT");?>" class="input-text" autocomplete="off" readonly/>
                                            </td>
                                            <td><input type="text"  name="txt<?php echo $ttl_bg[$i];?>_1_2" id="txt<?php echo $ttl_bg[$i];?>_1_2" onKeyUp="getBunkerCalculation();" value="<?php echo $obj->getBunkerValuesEstimate($obj->getFun1(),$ttl_bg1[$i],"EST_PRICE");?>" class="input-text" autocomplete="off" style="width:60px;" /></td>
                                            <td><input type="text"  name="txt<?php echo $ttl_bg[$i];?>_1_3" id="txt<?php echo $ttl_bg[$i];?>_1_3" value="<?php echo $obj->getBunkerValuesEstimate($obj->getFun1(),$ttl_bg1[$i],"EST_COST");?>" onKeyUp="getBunkerCalculation();" class="input-text" autocomplete="off" style="width:60px;" readonly /><input type="hidden"  name="txtBunkerCost_<?php echo $ttl_bg[$i];?>" id="txtBunkerCost_<?php echo $ttl_bg[$i];?>" class="input-text" readonly value="<?php echo $qrows['COST'];?>"/></td>
                                            <?php }?>
                                        </tr>
                                    <?php }?>									
                                    </tbody>
                                </table>
                                </div>
                                
                                <div><strong style="font-size:13px;">Operational Costs (Others)</strong></div>
								
                                <table class='tablesorter'>
                                    <tbody>
                                        <tr>
                                            <td colspan="2">Address Commission</td>
                                            <td><input type="text"  name="txtFrAdjPerAC" id="txtFrAdjPerAC" class="input-text" autocomplete="off" size="12" value="<?php echo $obj->getFun74();?>" onKeyUp="getFinalCalculation();" placeholder="0.00"/></td>
                                            <td><input type="text"  name="txtFrAdjUsdAC" id="txtFrAdjUsdAC" class="input-text" readonly value="<?php echo $obj->getFun75();?>" size="12" /></td>
                                            <td></td>
                                        </tr>
                                    </tbody>
                                    <tbody id="tbodyBrokerage">
                                    <?php 
									$sql_brok = "select * from freight_cost_estimete_slave4 where FCAID='".$obj->getFun1()."'";
									
									$res_brok = mysql_query($sql_brok);
									$num_brok = mysql_num_rows($res_brok);
									if($num_brok==0)
									{$num_brok =1;
									?>
									 <tr id="tbrRow_1">
                                        <td><a href="#tb1'" onClick="removeBrokerage(1);" ><i class="fa fa-times" style="color:red;"></i></a></td>
                                        <td>Brokerage Commission <span style="font-size:10px; font-style:italic;">(%)</span></td>
                                        
                                        <td><input type="text" name="txtBrCommPercent_1" id="txtBrCommPercent_1" class="input-text" autocomplete="off" size="12" value="" placeholder="0.00" onKeyUp="getFinalCalculation();"  /></td>
                                        <td><input type="text" name="txtBrComm_1" id="txtBrComm_1" class="input-text" readonly value="0.00" size="12" /></td>
                                        <td></td>
                                    </tr>
									<?php }
									     else
									      {$i=0;$num_brok = $num_brok;
										  while($rows_brok = mysql_fetch_assoc($res_brok))
										  {$i = $i + 1;?>
										     <tr id="tbrRow_<?php echo $i;?>">
                                                <td><a href="#tb1'" onClick="removeBrokerage(<?php echo $i;?>);" ><i class="fa fa-times" style="color:red;"></i></a></td>
												<td>Brokerage Commission <span style="font-size:10px; font-style:italic;">(%)</span></td>
												<td><input type="text" name="txtBrCommPercent_<?php echo $i;?>" id="txtBrCommPercent_<?php echo $i;?>" class="input-text" autocomplete="off" size="12" value="<?php echo $rows_brok['BROKAGE_PERCENT'];?>" onKeyUp="getFinalCalculation();" placeholder="0.00"/></td>
												<td><input type="text" name="txtBrComm_<?php echo $i;?>" id="txtBrComm_<?php echo $i;?>" class="input-text" readonly size="12" value="<?php echo $rows_brok['BROKAGE_AMT'];?>" /></td>
												<td></td>
											 </tr>
										  <?php }} ?>
                                     
                                    </tbody>
                                    
                                    <tbody>
                                    <tr>
                                        <td><button type="button" onClick="addBrokerageRow()">Add</button><input type="hidden" name="txtBRokageCount" id="txtBRokageCount" value="<?php echo $num_brok;?>"/></td>
                                        <td>Total&nbsp;Brokerage Commission <span style="font-size:10px; font-style:italic;">(%)</span></td>
                                        
                                        <td><input type="text" name="txtBrCommPercent" id="txtBrCommPercent" class="input-text" size="12" autocomplete="off" value="0.00" onKeyUp="getFinalCalculation();" readonly/></td>
                                        <td><input type="text" name="txtBrComm" id="txtBrComm" class="input-text" readonly size="12" value="0.00" /></td>
                                        <td>
                                        </td>
                                    </tr>
                                   </tbody>
                                 </table>
								
                                <table class='tablesorter'>
                                    <thead>
                                        <tr>
                                            <th width="20%"></th>
                                            <th width="20%"></th>
                                            <th width="20%">Cost</th>
                                        </tr>
                                   </thead>
                                   <tbody id="OWCBody">
                                   <?php $sql1 = "select * from freight_cost_estimete_slave3 where FCAID='".$id."' and IDENTIFY='ORC' and RAW_AMOUNT>0";
								   $res1 = mysql_query($sql1) or die($sql1);
								   $num1 = mysql_num_rows($res1);
								   if($num1==0)
								   {$num1 = 1;?>
									<tr id="OWCRow_1">
                                        <td><a href="#tb1'" onClick="removeCC(1);" ><i class="fa fa-times" style="color:red;"></i></a></td>
                                        <td><select name="txtHidORCID_1" id="txtHidORCID_1" style="width:130px;" >
                                        <?php $obj->getOwnerRelatedCostList(0);?>
                                        </select></td>
                                        <td><input type="text" name="txtORCAmt_1" id="txtORCAmt_1" onKeyUp="getORCCalculate(1);" class="input-text" autocomplete="off" value="" placeholder="0.00" size="12"  /></td>
                                     </tr> 
								 <?php }else
								   {$i = 0;
								   while($rows1 = mysql_fetch_assoc($res1))
								   {
										$i = $i + 1;
										?>
									 <tr id="OWCRow_<?php echo $i;?>">
                                        <td><a href="#tb1'" onClick="removeCC(<?php echo $i;?>);" ><i class="fa fa-times" style="color:red;"></i></a></td>
                                        <td><select name="txtHidORCID_<?php echo $i;?>" id="txtHidORCID_<?php echo $i;?>" style="width:130px;" >
                                        <?php $obj->getOwnerRelatedCostList($rows1['IDENTY_ID']);?>
                                        </select></td>
                                        <td><input type="text" name="txtORCAmt_<?php echo $i;?>" id="txtORCAmt_<?php echo $i;?>" onKeyUp="getORCCalculate(<?php echo $i;?>);" class="input-text" autocomplete="off" value="<?php echo $rows1['RAW_AMOUNT'];?>" placeholder="0.00" size="12"  /></td>
                                    </tr>
									 <?php }}?>
									</tbody>
                                    <tfoot>
                                        <tr>
                                        <th colspan="3" align="left"><button type="button" onClick="addORCRow()">Add</button><input type="hidden" name="txtOWCCount" id="txtOWCCount" value="<?php echo $num1;?>"/></th>
                                        </tr>
                                    </tfoot>
                                 </table>
                                 <table width="100%" class='tablesorter'>
                                     <tbody>
                                         <tr>
                                            <td>CVE <span style="font-size:10px; font-style:italic;">(/Month)</span></td>
                                            <td><input type="text" name="txtCVE" style="width:90px;" id="txtCVE" onKeyUp="getFinalCalculation();" class="input-text" autocomplete="off" value="<?php echo $obj->getFun142();?>" placeholder="0.00"></td>
                                            <td>CVE <span style="font-size:10px; font-style:italic;">(<?php echo $currencttoshow;?>)</span></td>
                                            <td><input type="text" name="txtCVEAmt" style="width:90px;" id="txtCVEAmt" class="input-text" autocomplete="off" value="<?php echo $obj->getFun143();?>" placeholder="0.00" readonly><input type="hidden" name="txtHidCVEAmt" style="width:90px;" id="txtHidCVEAmt" autocomplete="off" value="<?php echo $obj->getFun143();?>"></td>
                                        </tr>
                                     </tbody>
                                 </table>
                                 <div><strong style="font-size:13px;">Other Income</strong></div>
                                <table class='tablesorter'>
                                    <thead>
                                        <tr>
                                            <th width="5%"></th>
                                            <th width="35%">Description</th>
                                            <th width="20%">Amount(<?php echo $currencttoshow;?>)</th>
                                            <th width="20%">Add Comm(%)</th>
                                            <th width="20%">Net Amount(<?php echo $currencttoshow;?>)</th>
                                        </tr>
                                   </thead>
                                   <tbody id="OthInBody">
                                   <?php $sql3 = "select * from freight_cost_estimete_slave3 where FCAID='".$id."' and IDENTIFY='OTHERINCOME' and RAW_AMOUNT>0";
								   $res3 = mysql_query($sql3) or die($sql3);
								   $num3 = mysql_num_rows($res3);
								   if($num3==0)
								   {$num3 = 1;?>
                                     <tr id="OthInRow_1">
                                        <td><a href="#tb1'" onClick="removeOtherIncome(1);" ><i class="fa fa-times" style="color:red;"></i></a></td>
                                        <td><input type="text" name="txtDesc_1" id="txtDesc_1" class="input-text" autocomplete="off" value="" placeholder="Description" size="29"  /></td>
                                        <td><input type="text" name="txtOtherAmt_1" id="txtOtherAmt_1" onKeyUp="getFinalCalculation();" class="input-text" autocomplete="off" value="" placeholder="0.00" size="12"  /></td>
                                        <td><input type="text" name="txtOtherAddComm_1" id="txtOtherAddComm_1" onKeyUp="getFinalCalculation();" class="input-text" autocomplete="off" value="" placeholder="0.00" size="12"  /></td>
                                        <td><input type="text" name="txtOtherNetAmt_1" id="txtOtherNetAmt_1"  class="input-text" autocomplete="off" size="12" value="0.00"  readonly /></td>
                                    </tr>
                                 <?php }else
								   {$i = 0;
								   while($rows3 = mysql_fetch_assoc($res3))
								   {$i = $i + 1;?>
                                     <tr id="OthInRow_<?php echo $i;?>">
                                        <td><a href="#tb1'" onClick="removeOtherIncome(<?php echo $i;?>);" ><i class="fa fa-times" style="color:red;"></i></a></td>
                                        <td><input type="text" name="txtDesc_<?php echo $i;?>" id="txtDesc_<?php echo $i;?>" class="input-text" autocomplete="off" value="<?php echo $rows3['IDENTY_ID'];?>" placeholder="Description" size="29"  /></td>
                                        <td><input type="text" name="txtOtherAmt_<?php echo $i;?>" id="txtOtherAmt_<?php echo $i;?>" onKeyUp="getFinalCalculation();" class="input-text" autocomplete="off" value="<?php echo $rows3['COST'];?>" placeholder="0.00" size="12"  /></td>
                                        <td><input type="text" name="txtOtherAddComm_<?php echo $i;?>" id="txtOtherAddComm_<?php echo $i;?>" onKeyUp="getFinalCalculation();" class="input-text" autocomplete="off" value="<?php echo $rows3['ADDCOMM'];?>" placeholder="0.00" size="12"  /></td>
                                        <td><input type="text" name="txtOtherNetAmt_<?php echo $i;?>" id="txtOtherNetAmt_<?php echo $i;?>"  class="input-text" autocomplete="off" size="12" value="<?php echo $rows3['RAW_AMOUNT'];?>"  readonly /></td>
                                    </tr>
                                 <?php }}?>
                                    </tbody>
                                    <tfoot>
                                        <tr>
                                        <th colspan="5" align="left"><button type="button" onClick="addOtherInRow()">Add</button><input type="hidden" name="txtOthInCount" id="txtOthInCount" value="<?php echo $num3;?>"/></th>
                                        </tr>
                                    </tfoot>
                                </table>
                                    <div><strong>Hire</strong></div>
                                    <table class='tablesorter'>
                                        <tbody>
                                            <tr>
                                                <td>Daily Time Charter (<?php echo $currencttoshow;?>/Day)</td>
                                                
                                                <td></td>
                                                <td></td>
                                                <td><input type="text"  name="txtDailyVesselOperatingExpenses" style="width:90px;" id="txtDailyVesselOperatingExpenses" class="input-text" autocomplete="off" value="<?php echo $obj->getFun91();?>" placeholder="0.00" onKeyUp="getFinalCalculation();" /></td>
                                                <td></td>
                                            </tr>
                                            
                                            <tr>
                                                <td>Hireage</td>
                                                <td><input type="text"  name="txtHireargeAmt" id="txtHireargeAmt" style="width:90px;" class="input-text" value="<?php echo $obj->getFun132();?>" placeholder="0.00" readonly /></td>
                                                <td>Ballast Bonus</td>
                                                <td><input type="text" name="txtBallastBonus" id="txtBallastBonus" style="width:90px;" onKeyUp="getFinalCalculation();" class="input-text" autocomplete="off" value="<?php echo $obj->getFun145();?>" placeholder="0.00"></td>
                                                <td></td>
                                            </tr>
                                            <tr>
                                                <td>Add Comm <span style="font-size:10px; font-style:italic;">(%)</span></td>
                                                <td><input type="text"  name="txtHireargePercent" style="width:90px;" id="txtHireargePercent" class="input-text" value="<?php echo $obj->getFun129();?>" placeholder="%" onKeyUp="getFinalCalculation();"/></td>
                                                <td>Add Comm <span style="font-size:10px; font-style:italic;">(<?php echo $currencttoshow;?>)</span></td>
                                                <td><input type="text"  name="txtHireargePercentAmt" style="width:90px;" id="txtHireargePercentAmt" class="input-text" value="<?php echo $obj->getFun130();?>" placeholder="0.00" readonly /></td>
                                                <td></td>
                                            </tr>
                                            
                                            <tr>
                                                <td></td>
                                                <td></td>
                                                <td>Nett Hireage</td>
                                                <td><input type="text"  name="txtNettHireargeAmt" style="width:90px;" id="txtNettHireargeAmt" class="input-text" value="<?php echo $obj->getFun131();?>" placeholder="0.00" readonly /></td>
                                                <td></td>
                                            </tr>
                                            
                                        </tbody>
                                    </table>
									<div ><strong>Results</strong></div>
									<table class='tablesorter'>
										
										<tbody>
											<tr>
												<td>Revenue (Final Nett Freight)</td>
												<td><input type="text"  name="txtRevenue" style="width:90px;" id="txtRevenue" class="input-text" readonly placeholder="0.00" /></td>
												<td>Operational Expenses</td>
												<td><input type="text"  name="txtTotalOperationalCost" style="width:90px;" id="txtTotalOperationalCost" class="input-text" readonly value="<?php echo $obj->getFun84();?>" autocomplete="off"/></td>
											</tr>
                                            <tr>
                                                <td>Port Expenses</td>
                                                <td><input type="text"  name="txtTotalPortCost" style="width:90px;" id="txtTotalPortCost" class="input-text" readonly value=""/></td>
                                                <td>Bunker Expenses</td>
												<td><input type="text"  name="txtTotalBunkerCost" style="width:90px;" id="txtTotalBunkerCost" class="input-text" readonly value=""/></td>
                                                
                                            </tr>
                                            
											<tr>
												<td></td>
												<td></td>
												<td>Voyage Earnings</td>
												<td><input type="text"  name="txtVoyageEarnings" style="width:90px;" id="txtVoyageEarnings" class="input-text" readonly placeholder="0.00" /></td>
											</tr>
											
											<tr>
                                                <td>G Total Voyage Earnings&nbsp;&nbsp;&nbsp;<span style="font-size:10px; font-style:italic;">(Voyage Earnings + Demurrage)</span></td>
												<td><input type="text"  name="txtGTTLVoyageEarnings" style="width:90px;" id="txtGTTLVoyageEarnings" class="input-text" readonly  placeholder="0.00" /></td>
												<td style="color:#dc631e;" >Daily Earnings / TCE</td>
												<td><input type="text"  name="txtDailyEarnings" style="width:90px;" id="txtDailyEarnings" class="input-text" readonly placeholder="0.00" /></td>
												
											</tr>
											
											<tr>
												<td style="color:#dc631e;">Nett Daily Profit</td>
												<td><input type="text"  name="txtNettDailyProfit" style="width:90px;" id="txtNettDailyProfit" class="input-text" readonly placeholder="0.00" /></td>
												<td>P/L</td>
												<td><input type="text"  name="txtPL" id="txtPL" style="width:90px;" class="input-text" readonly placeholder="0.00" /></td>
											</tr>
											<tr>
												<td style="color:#dc631e;"></td>
												<td></td>
												<td></td>
												<td></td>
											</tr>
										</tbody>
									</table>
                           </td>
                       </tr>
                       </table>
                    
                    
                    </div>
                    <!-- /.tab_1-pane -->
                    <div id="tabs_3" class="tab-pane">
                         <table width="100%" style="margin-top:2px;">
                           <tr>
                               <td class="input-text">&nbsp;DWT<span style="font-size:10px; font-style:italic;">(Summer)</span>&nbsp;:&nbsp;<input type="text" name="txtDWTS" id="txtDWTS" style="width:90px;" class="input-text" autocomplete="off" readonly value="<?php echo $obj->getFun10();?>" placeholder="0.00" />
                               </td>
                               <td class="input-text"></td>
                                <td class="input-text" id="tankgasnot1"><input name="rdoCap" id="rdoCap1" type="radio" style="cursor:pointer;" value="1"  <?php if($rdoCap == 1) echo "checked"; ?> onClick="showCapField(1);"  />&nbsp;Grain Cap.<span style="font-size:10px; font-style:italic;">(CBM)</span><input type="text" name="txtGCap" id="txtGCap" style="width:90px;" class="input-text" autocomplete="off" readonly value="<?php echo $obj->getFun13();?>" /></td>
                                <td class="input-text" id="tankgasnot2"><input name="rdoCap" id="rdoCap2" type="radio" style="cursor:pointer;" value="2"  <?php if($rdoCap == 2) echo "checked"; ?> onClick="showCapField(2);" />&nbsp;Bale&nbsp;Cap.<span style="font-size:10px; font-style:italic;">(CBM)</span><input type="text" name="txtBCap" id="txtBCap" style="width:90px;" class="input-text" autocomplete="off" readonly value="<?php echo $obj->getFun14();?>" disabled="disabled" /></td>
                                <td class="input-text" id="tankgasnot3">SF<span style="font-size:10px; font-style:italic;">(ft3/lt)</span><input type="text" name="txtSF" id="txtSF"  autocomplete="off" style="width:90px;" class="input-text" value="<?php echo $obj->getFun15();?>"  onkeyup="getTotalDWT(),getTotalDWT1()" /></td>
                                <td class="input-text" id="tankgasnot4">Loadable<span style="font-size:10px; font-style:italic;">(MT)</span><input type="text" name="txtLoadable" id="txtLoadable" autocomplete="off" style="width:90px;" class="input-text" readonly value="<?php echo $obj->getFun16();?>" /></td>
                           </tr>
                       </table>
                         <table cellpadding="1" cellspacing="1" border="0" width="100%"  class='tablesorter' >
						<tr height="10"><td colspan="10" align="left" class="text" valign="top" ></td></tr>	
						<tr height="10"><td colspan="10" align="left" class="text" valign="top" >
						<table width="100%" cellpadding="1" cellspacing="1" border="0">
						<thead>
                        <tr>
						<td width="25%" align="left" class="text">GRT<br/><input type="text" name="txtGNRT" id="txtGNRT" class="input-text" readonly value="<?php echo $obj->getFun17();?>" /></td>
						<td width="25%" align="left" valign="top" class="text">LOA<br/><input type="text" name="txtLOA" id="txtLOA" class="input-text" readonly value="<?php echo $obj->getFun18();?>" /></td>
						<td width="25%" align="left" valign="top" class="text">Built Year<br/><input type="text" name="txtBuiltYear" id="txtBuiltYear" class="input-text" readonly value="<?php echo $obj->getFun20();?>" /></td>
						<td width="25%" align="left" valign="top" class="text"></td>
						</tr>
                        <tr>
						<td width="25%" align="left" class="text">BEAM(m)<br/><input type="text" name="txtBeam" id="txtBeam" class="input-text" readonly value="<?php echo $obj->getFun21();?>" /></td>
						<td width="25%" align="left" valign="top" class="text">TPC<br/><input type="text" name="txtTPC" id="txtTPC" class="input-text" readonly value="<?php echo $obj->getFun22();?>" /></td>
						<td width="25%" align="left" valign="top" class="text"></td>
						<td width="25%" align="left" valign="top" class="text"></td>
						</tr>
						<tr>
						<td width="25%" align="left" class="text" style="color:#dc631e;">Speed Data</td>
						<td width="25%" align="right" valign="top" class="text" style="color:#1b77a6;">Full Speed</td>
						<td width="25%" align="right" valign="top" class="text" style="color:#1b77a6;">Service Speed</td>
						<td width="25%" align="right" valign="top" class="text" style="color:#1b77a6;">Most Eco Speed</td>
						</tr>
						</thead>
						<tbody>
						<tr>
						<td width="25%" align="left" class="input-text">Ballast Speed <span style="font-size:10px; font-style:italic;">(Knots)</span></td>
						<td width="25%" align="right" valign="top" class="text"><input type="text" name="txtBFullSpeed" id="txtBFullSpeed" class="input-text" value="<?php echo $obj->getFun23();?>" /></td>
						<td width="25%" align="right" valign="top" class="text"><input type="text" name="txtBEcoSpeed1" id="txtBEcoSpeed1" class="input-text" value="<?php echo $obj->getFun24();?>" /></td>
						<td width="25%" align="right" valign="top" class="text"><input type="text" name="txtBEcoSpeed2" id="txtBEcoSpeed2" class="input-text" value="<?php echo $obj->getFun25();?>" /></td>
						</tr>
						<tr>
						<td width="25%" align="left" class="input-text">Laden Speed <span style="font-size:10px; font-style:italic;">(Knots)</span></td>
						<td width="25%" align="right" valign="top" class="text"><input type="text" name="txtLFullSpeed" id="txtLFullSpeed" class="input-text" value="<?php echo $obj->getFun26();?>" /></td>
						<td width="25%" align="right" valign="top" class="text"><input type="text" name="txtLEcoSpeed1" id="txtLEcoSpeed1" class="input-text" value="<?php echo $obj->getFun27();?>" /></td>
						<td width="25%" align="right" valign="top" class="text"><input type="text" name="txtLEcoSpeed2" id="txtLEcoSpeed2" class="input-text" value="<?php echo $obj->getFun28();?>" /></td>
						</tr>
						</tbody>
						</table>
						</td></tr>
						<tr height="10"><td colspan="10" align="left" class="text" valign="top" ></td></tr>	
						<tr height="10"><td colspan="10" align="left" class="text" valign="top" >
						<table width="100%" cellpadding="1" cellspacing="1" border="0">
						<thead>
						<tr>
						<td width="45%" align="left" class="text" style="color:#dc631e;">FO Consumption MT/Day</td>
						<td width="20%" align="right" valign="top" class="text" style="color:#1b77a6;">Full Speed</td>
						<td width="17%" align="right" valign="top" class="text" style="color:#1b77a6;">Service Speed</td>
						<td width="1%" align="left" class="text"></td>
						<td width="16%" align="right" valign="top" class="text" style="color:#1b77a6;">Most Eco Speed</td>
						<td width="1%" align="left" class="text"></td>
						</tr>
						</thead>
						<tbody>
						<tr>
						<td width="45%" align="left" class="input-text">Ballast Passage</td>
						<td width="20%" align="right" valign="top" class="text"><input type="text" name="txtBFOFullSpeed" id="txtBFOFullSpeed" class="input-text" value="<?php echo $obj->getFun29();?>" /></td>
						<td width="17%" align="right" valign="top" class="text"><input type="text" name="txtBFOEcoSpeed1" id="txtBFOEcoSpeed1" class="input-text" value="<?php echo $obj->getFun30();?>" /></td>
						<td width="1%" align="left" class="text"></td>
						<td width="16%" align="right" valign="top" class="text"><input type="text" name="txtBFOEcoSpeed2" id="txtBFOEcoSpeed2" class="input-text" value="<?php echo $obj->getFun31();?>" /></td>
						<td width="1%" align="left" class="text"></td>
						</tr>
						<tr>
						<td width="45%" align="left" class="input-text">Laden Passage</td>
						<td width="20%" align="right" valign="top" class="text"><input type="text" name="txtLFOFullSpeed" id="txtLFOFullSpeed" class="input-text" value="<?php echo $obj->getFun32();?>" /></td>
						<td width="17%" align="right" valign="top" class="text"><input type="text" name="txtLFOEcoSpeed1" id="txtLFOEcoSpeed1" class="input-text" value="<?php echo $obj->getFun33();?>" /></td>
						<td width="1%" align="left" class="text"></td>
						<td width="16%" align="right" valign="top" class="text"><input type="text" name="txtLFOEcoSpeed2" id="txtLFOEcoSpeed2" class="input-text" value="<?php echo $obj->getFun34();?>" /></td>
						<td width="1%" align="left" class="text"></td>
						</tr>
						<tr>
						<td colspan="7" align="left" class="text">
						<table width="100%" cellpadding="1" cellspacing="1" border="0">
						<thead>
						<tr>
						<td width="45%" align="left" class="text"></td>
						<td width="20%" align="right" valign="top" class="text">In Port - Idle</td>
						<td width="17%" align="right" valign="top" class="text">In Port - Working</td>
						<td width="1%" align="left" class="text"></td>
						<td width="16%" align="right" valign="top" class="text"></td>
						<td width="1%" align="left" class="text"></td>
						</tr>
						</thead>
						<tbody>
						<tr>
						<td width="45%" align="left" class="text"></td>
						<td width="20%" align="right" valign="top" class="text"><input type="text" name="txtPIFOFullSpeed" id="txtPIFOFullSpeed" class="input-text" value="<?php echo $obj->getFun35();?>" /></td>
						<td width="17%" align="right" valign="top" class="text"><input type="text" name="txtPWFOFullSpeed" id="txtPWFOFullSpeed" class="input-text" value="<?php echo $obj->getFun36();?>" /></td>
						<td width="1%" align="left" class="text"></td>
						<td width="16%" align="right" valign="top" class="text"></td>
						<td width="1%" align="left" class="text"></td>
						</tr>
						</tbody>
						</table>
						</td>
						</tr>
						
						</tbody>
						</table>
						</td></tr>	
						
						<tr height="10"><td colspan="10" align="left" class="text" valign="top" ></td></tr>	
						<tr height="10"><td colspan="10" align="left" class="text" valign="top" >
						<table width="100%" cellpadding="1" cellspacing="1" border="0">
						<thead>
						<tr>
						<td width="45%" align="left" class="text" style="color:#dc631e;">DO Consumption per MT/Day</td>
						<td width="20%" align="right" valign="top" class="text" style="color:#1b77a6;">Full Speed</td>
						<td width="17%" align="right" valign="top" class="text" style="color:#1b77a6;">Service Speed</td>
						<td width="1%" align="left" class="text"></td>
						<td width="16%" align="right" valign="top" class="text" style="color:#1b77a6;">Most Eco Speed</td>
						<td width="1%" align="left" class="text"></td>
						</tr>
						</thead>
						<tbody>
						<tr>
						<td width="45%" align="left" class="input-text">Ballast Passage</td>
						<td width="20%" align="right" valign="top" class="text"><input type="text" name="txtBDOFullSpeed" id="txtBDOFullSpeed" class="input-text"  value="<?php echo $obj->getFun37();?>" /></td>
						<td width="17%" align="right" valign="top" class="text"><input type="text" name="txtBDOEcoSpeed1" id="txtBDOEcoSpeed1" class="input-text" value="<?php echo $obj->getFun38();?>" /></td>
						<td width="1%" align="left" class="text"></td>
						<td width="16%" align="right" valign="top" class="text"><input type="text" name="txtBDOEcoSpeed2" id="txtBDOEcoSpeed2" class="input-text" value="<?php echo $obj->getFun39();?>" /></td>
						<td width="1%" align="left" class="text"></td>
						</tr>
						<tr>
						<td width="45%" align="left" class="input-text">Laden Passage</td>
						<td width="20%" align="right" valign="top" class="text"><input type="text" name="txtLDOFullSpeed" id="txtLDOFullSpeed" class="input-text" value="<?php echo $obj->getFun40();?>" /></td>
						<td width="17%" align="right" valign="top" class="text"><input type="text" name="txtLDOEcoSpeed1" id="txtLDOEcoSpeed1" class="input-text" value="<?php echo $obj->getFun41();?>" /></td>
						<td width="1%" align="left" class="text"></td>
						<td width="16%" align="right" valign="top" class="text"><input type="text" name="txtLDOEcoSpeed2" id="txtLDOEcoSpeed2" class="input-text" value="<?php echo $obj->getFun42();?>" /></td>
						<td width="1%" align="left" class="text"></td>
						</tr>
						
						<tr>
						<td colspan="7" align="left" class="text">
						<table width="100%" cellpadding="1" cellspacing="1" border="0">
						<thead>
						<tr>
						<td width="45%" align="left" class="text"></td>
						<td width="20%" align="right" valign="top" class="text">In Port - Idle</td>
						<td width="17%" align="right" valign="top" class="text">In Port - Working</td>
						<td width="1%" align="left" class="text"></td>
						<td width="16%" align="right" valign="top" class="text"></td>
						<td width="1%" align="left" class="text"></td>
						</tr>
						</thead>
						<tbody>
						<tr>
						<td width="45%" align="left" class="text"></td>
						<td width="20%" align="right" valign="top" class="text"><input type="text" name="txtPIDOFullSpeed" id="txtPIDOFullSpeed" class="input-text" value="<?php echo $obj->getFun43();?>" /></td>
						<td width="17%" align="right" valign="top" class="text"><input type="text" name="txtPWDOFullSpeed" id="txtPWDOFullSpeed" class="input-text" value="<?php echo $obj->getFun44();?>" /></td>
						<td width="1%" align="left" class="text"></td>
						<td width="16%" align="right" valign="top" class="text"></td>
						<td width="1%" align="left" class="text"></td>
						</tr>
						</tbody>
						</table>
						</td>
						</tr>
						</tbody>
						</table>
						
						</td></tr>	
						
						<tr height="10"><td colspan="10" align="left" class="text" valign="top" ></td></tr>	
						</table>
                    </div>
                    
                    <!-- /.tab_2-pane -->
                    </div><!-- /.tab-content -->
                </div>
                <div style="text-align:center;">
                            <button type="submit" class="btn btn-primary btn-flat" onClick="return getValidate(0);">Submit to Edit</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button type="submit" class="btn btn-primary btn-flat" onClick="return getValidate(1);">Send to Ops</button>
							<input type="hidden" name="action" id="action" value="submit" />
                            <input type="hidden" name="vesselrec" id="vesselrec" class="input-text" value="" />
                            <input type="hidden" name="txtStatus" id="txtStatus" class="input-text" value="0" /></div>
                <!-- Main content -->
                
                </form>
            </aside><!-- /.right-side -->
			
        </div><!-- ./wrapper -->
<?php $display->footer(); ?>

<link href="../../css/jquery.alerts.css" rel="stylesheet" type="text/css" />
<link href="../../css/sort.css" rel="stylesheet" type="text/css" />
<script src='../../js/jquery.autosize.js'></script>
<script language="JavaScript" type="text/javascript" src="../../js/jquery.alerts.js"></script>
<script src="../../js/timer.js" type="text/javascript"></script>
<link href="../../css/datepicker/datepicker.css" rel="stylesheet" type="text/css" />
<script src="../../js/bootstrap-datepicker.js" type="text/javascript"></script>
<script language="JavaScript" type="text/javascript" src="../../js/jquery.numeric.js"></script>
<script language="JavaScript" type="text/javascript" src="../../js/jquery.calculation-min.js"></script>
<script type='text/javascript' src='../../js/jquery.simplemodal.js'></script>
<link type='text/css' href='../../css/basic.css' rel='stylesheet' media='screen' />
<script src="../../js/chosen.jquery.js" type="text/javascript"></script>
<link type="text/css" href="../../css/chosen.css" rel="stylesheet" />
<script type="text/javascript">
$(document).ready(function(){ 
$("#selVName").val(<?php echo $obj->getFun5();?>);
$("#frm1").validate({
	rules: {
		txtENo:"required",
		txtDate:"required",
		selCharterers_1:"required",
		txtCargomt_1:"required",
		txtRateUSDmt_1:"required",
		selVName:"required",
		txtVNo:"required"
		},
	messages: {
		selVName:"*",
		},
submitHandler: function(form)  {
	    if($("#txtStatus").val()==1)
		{
		   jConfirm('Are you sure you want to send this estimate to ops ?', 'Confirmation', function(r) {
			if(r){
				jAlert('<b style="font-size:25px;">Please wait . . .</b><br><br><img src="../../img/loading.gif"  />', 'Alert');
				$("#popup_container").css({"background": "rgba(255,255,255,0.1)","border": "10px solid rgba(255,255,255,0.1)","width": "100%"});
				$("#popup_content").css({"background":"none","text-align":"center"});
				$("#popup_ok,#popup_title").hide();  
				frm1.submit();
				}
				else{return false;}
			});
		}
		else
		{
		   jConfirm('Are you sure you have checked each entry ?', 'Confirmation', function(r) {
			if(r){
				jAlert('<b style="font-size:25px;">Please wait . . .</b><br><br><img src="../../img/loading.gif"  />', 'Alert');
				$("#popup_container").css({"background": "rgba(255,255,255,0.1)","border": "10px solid rgba(255,255,255,0.1)","width": "100%"});
				$("#popup_content").css({"background":"none","text-align":"center"});
				$("#popup_ok,#popup_title").hide();  
				frm1.submit();
				}
				else{return false;}
			});
		}
	}
});

$("[id^=txtDQMT_],[id^=txtDRate_],[id^=txtDIDays_],[id^=txtDCosts_],#txtDWTS,#txtSF, #txtFreightQty,[id^=txtORCAmt_],[id^=txtDistance_],[id^=txtWeather_],[id^=txtMargin_],[id^=txtPCosts_],[id^=txtQMT_],[id^=txtRate_],[id^=txtIDays_], [id^=txtDWDays_],[id^=txtWDays_],[id^=txtTLPCosts_],[id^=txtTLIDays_],#txtFrAdjPerAC,#txtFrAdjPerAgC,[id^=txtBrCommPercent_],[id^=txtORCAmt_],[id^=txtCCAbs_],#txtDailyVesselOperatingExpenses,[id^=txtEstDDCLPCost_],[id^=txtEstDDCDPCost_], #txtHireargePercent,#txtBallastBonus,#txtCVE,#txtBFullSpeed,#txtBEcoSpeed1,#txtBEcoSpeed2,#txtBFOFullSpeed,#txtBFOEcoSpeed1,#txtBFOEcoSpeed2,#txtBDOFullSpeed,#txtBDOEcoSpeed1,#txtBDOEcoSpeed2,#txtLFullSpeed,#txtLEcoSpeed1,#txtLEcoSpeed2,#txtLFOFullSpeed,#txtLFOEcoSpeed1,#txtLFOEcoSpeed2,#txtLDOFullSpeed,#txtLDOEcoSpeed1,#txtLDOEcoSpeed2,#txtPIFOFullSpeed,#txtPWFOFullSpeed,#txtPIDOFullSpeed,#txtPWDOFullSpeed,#txtBalticRate,#txtAdnlPrenium,#txtGasCQMT,#txtGASLumpsum,#txtFixedDiff,[id^=txtLPADDComm_],[id^=txtDPADDComm_],[id^=txtOtherAmt_],[id^=txtOtherAddComm_],[id^=txtCargocbm_],[id^=txtCargomt_],[id^=txtRateUSDmt_],[id^=txtAmountUSD_],[id^=txtCargocbm2_],[id^=txtCargomt2_],[id^=txtRateUSDmt2_],[id^=txtAmountUSD2_],[id^=txtCargocbm3_],[id^=txtCargomt3_],[id^=txtRateUSDmt3_],[id^=txtAmountUSD3_]").numeric();

$("#txtDate").datepicker({
	format: 'dd-mm-yyyy',
	autoclose: true
});




$('[id^=ChkShowDDCDP_]').on('ifChecked', function () { 
   $("#DDCDProw_"+$(this).val()).hide();
});
 
$('[id^=ChkShowDDCDP_]').on('ifUnchecked', function () { 
   $("#DDCDProw_"+$(this).val()).show();
});
 
$('[id^=ChkShowDDCLP_]').on('ifChecked', function () { 
    $("#DDCLProw_"+$(this).val()).hide();
});
 
$('[id^=ChkShowDDCLP_]').on('ifUnchecked', function () { 
    $("#DDCLProw_"+$(this).val()).show();
});

function getString(var1)
{
  var var2 = var1.split('-');  
  return var2[2]+'/'+var2[1]+'/'+var2[0];
}

<?php
$sql = "SELECT * FROM bunker_grade_master where MODULEID='".$_SESSION['moduleid']."' AND MCOMPANYID='".$_SESSION['company']."' and STATUS=1";
$res = mysql_query($sql);
$rec = mysql_num_rows($res);
$m=0; 
while($rows = mysql_fetch_assoc($res)){
?>
$("#txt<?php echo $rows['NAME'];?>_1_2").numeric();
<?php } ?>
$(".navbar-btn").on('click',function(){getDivwidthAsParent(2)});
getDivwidthAsParent(1);
showHideEstimateTypeDiv();
getPortCalculation();
});

function getValue()
{
	
}

function getDivwidthAsParent(val)
{
	if(val==1)
	{
	    var widths = parseInt($('#parenttdID').width());
	    $("#bunkercontainer").css( "maxWidth", widths+"px" );
		$("#txtBunkerWidth").val(widths);
	}
	else
	{
		var widthidentity = $("#txtBunkerWidth1").val();
		if(widthidentity == 1)
		{
			var widths = $('#parenttdID').width();
			$("#bunkercontainer").css( "maxWidth", widths+"px" );
			$("#txtBunkerWidth1").val(2);
		}
		else
		{
			var widths = $('#txtBunkerWidth').val();
			$("#bunkercontainer").css( "maxWidth", widths+"px" );
			$("#txtBunkerWidth1").val(1);
		}
	}
}


function getData()
{
	  if($("#selVName").val()!="")
	  {
		  $.post("options.php?id=42",{vessel1d:""+$("#selVName").val()+""}, function(data) 
			{
				    var vsldata = JSON.parse(data);
					$.each(vsldata[$("#selVName").val()], function(index, array) {
					if(array['num'] == "" || array['num']==0)
					{
						jAlert('Please ensure commercial parameters are completed before proceeding', 'Alert', function(r) {
						if(r){ 
							window.location="commercial_parameter.php?id="+$("#selVName").val();
							}
							else{return false;}
							});	
					}
					else
					{
						$('#txtVType').val(array['type']);
						$('#txtDWTS').val(array['dwtsum']);
						$('#txtGCap').val(array['grain']);
						$('#txtBCap').val(array['bale']);
						
						$('#txtBFullSpeed').val(array['bfs']);
						$('#txtBEcoSpeed1').val(array['bes1']);
						$('#txtBEcoSpeed2').val(array['bes2']);
						$('#txtBFOFullSpeed').val(array['fobfs']);
						$('#txtBFOEcoSpeed1').val(array['fobes1']);
						$('#txtBFOEcoSpeed2').val(array['fobes2']);
						$('#txtBDOFullSpeed').val(array['dobfs']);
						$('#txtBDOEcoSpeed1').val(array['dobes1']);
						$('#txtBDOEcoSpeed2').val(array['dobes2']);
						
						$('#txtLFullSpeed').val(array['lfs']);
						$('#txtLEcoSpeed1').val(array['les1']);
						$('#txtLEcoSpeed2').val(array['les2']);
						$('#txtLFOFullSpeed').val(array['folfs']);
						$('#txtLFOEcoSpeed1').val(array['foles1']);
						$('#txtLFOEcoSpeed2').val(array['foles2']);
						$('#txtLDOFullSpeed').val(array['dolfs']);
						$('#txtLDOEcoSpeed1').val(array['doles1']);
						$('#txtLDOEcoSpeed2').val(array['doles2']);
						
						$('#txtPIFOFullSpeed').val(array['foidle']);
						$('#txtPWFOFullSpeed').val(array['fwking']);
						$('#txtPIDOFullSpeed').val(array['ddle']);
						$('#txtPWDOFullSpeed').val(array['dwking']);
						$('#vesselrec').val(array['num']);
						$('#txtFlag').val(array['flag']);
						$('#txtBuiltYear').val(array['year']);
						$('#txtGNRT').val(array['gnrt']);
						$('#txtLOA').val(array['loa']);
						$('#txtGear').val(array['gear']);
						$('#txtBeam').val(array['beam']);
						$('#txtTPC').val(array['tpc']);
						$("#cargotypespan").html(array['btypename']);
						showHideEstimateTypeDiv(2);
						getVoyageTime();
					}
				});
			});  
	  }
	  else
	  {
		  $('#txtVType,#txtDWTS,#txtGCap,#txtBCap,#txtBFullSpeed,#txtBEcoSpeed1,#txtBEcoSpeed2,#txtBFOFullSpeed,#txtBFOEcoSpeed1,#txtBFOEcoSpeed2,#txtBDOFullSpeed,#txtBDOEcoSpeed1,#txtBDOEcoSpeed2,#txtLFullSpeed,#txtLEcoSpeed1,#txtLEcoSpeed2,#txtLFOFullSpeed,#txtLFOEcoSpeed1,#txtLFOEcoSpeed2,#txtLDOFullSpeed,#txtLDOEcoSpeed1,#txtLDOEcoSpeed2,#txtPIFOFullSpeed,#txtPWFOFullSpeed,#txtPIDOFullSpeed,#txtPWDOFullSpeed,#vesselrec,#txtFlag,#txtGear,#txtBuiltYear,#txtGNRT,#txtLOA,#rdoEstimateType').val("");
	  }
}




function getBunkerCalculation()
{
	    var noOfBunker = $("#txtBunkerRec").val();
		var sum = "";
		for(var i=1;i<=noOfBunker;i++)
		{
		   var bunkergrade = $("#txtBunkerGradeName_"+i).val();
		   var bunkergradetype = $("#txtBunkerGradeType_"+i).val();
		   var str = bunkergradetype.substr(0,3);
		   if(str == 'IFO')
			{
					$("#txt"+bunkergrade+"_1_1").val($("#txtTFUMT").val());
			}
			else if(str == 'MDO')
			{
					$("#txt"+bunkergrade+"_1_1").val($("#txtTDUMT").val());
			}
			else if(str == 'MGO')
			{
					$("#txt"+bunkergrade+"_1_1").val($("#txtTDUMT").val());
			}
			else
			{
				$("#txt"+bunkergrade+"_1_1").val('0.00');
			}
			
			var var3 = $("#txt"+bunkergrade+"_1_1").val();
			if(var3 == ""){var first = 0;}else{var first = var3;}
			if($("#txt"+bunkergrade+"_1_2").val() == ""){var second = 0;}else{var second = $("#txt"+bunkergrade+"_1_2").val();}
			var calc = parseFloat(first) * parseFloat(second);
			$("#txt"+bunkergrade+"_1_3").val(calc.toFixed(2));
			$("#txtBunkerCost_"+bunkergrade).val($("#txt"+bunkergrade+"_1_3").val());
		}
		$("#txtTotalBunkerCost").val($("[id^=txtBunkerCost_]").sum().toFixed(2));
	getFinalCalculation();
}


function getDistance(i)
{
	
		$("#txtDistance_"+i).val("");
		$("#ploader_"+i).show();
		var loadporttext = disporttext = "";
		if($("#selFPort_"+i).val()!=""){loadporttext = $("#selFPort_"+i+" option:selected").text();}else{loadporttext = "";}
		if($("#selTPort_"+i).val()!=""){disporttext = $("#selTPort_"+i+" option:selected").text();}else{disporttext = "";}
		$("#spanLoadPort_"+i).html(loadporttext);
		$("#spanDisPort_"+i).html(disporttext);
		$("#TranDisPort_"+i).html(loadporttext);
		$("#spanDDCLPort_"+i).html(loadporttext);
		$("#spanDDCDPort_"+i).html(disporttext);
		if($('#selFPort_'+i).val() != "" && $('#selTPort_'+i).val() != "" && $('#selDType_'+i).val() != "")
		{
			$("#txtDistance_"+i).val(0);
			$.post("options.php?id=10",{selFPort:""+$("#selFPort_"+i).val()+"",selTPort:""+$("#selTPort_"+i).val()+"",selDType:""+$("#selDType_"+i).val()+""}, function(data) 
			{
					$('#txtDistance_'+i).val(data);
					$("#ploader_"+i).hide();
					getVoyageTime();
			});
		}
		else
		{
			$('#txtDistance_'+i).val(0);
			$("#ploader_"+i).hide();
			getVoyageTime();
		}
}

function getVoyageTime()
{
	var id = $("#p_rotationID").val();
	$("#txtBDays,#txtLDays").val(0);
	$("#txtLDist,#txtBDist,#txtTDUMT,#txtTFUMT").val(0);
	var ladendays = ballastdays = idealdays = workingdays = consumptiondo = consumptionfo =  0;
	for(var i=1;i<=id;i++)
	{
	    if($("#txtMargin_"+i).val() == ""){var margin = 0;}else{var margin = $("#txtMargin_"+i).val();}
		if($("#txtDistance_"+i).val() == ""){var distance = 0;}else{var distance = $("#txtDistance_"+i).val();}
		if($("#txtWeather_"+i).val() == ""){var speed_adj = 0;}else{var speed_adj = $("#txtWeather_"+i).val();}
		if($("#selPType_"+i).val() == 1)
		{
			if($("#selSSpeed_"+i).val() == 1)
			{
				var ballast = $("#txtBFullSpeed").val();
				var fo_ballast = $("#txtBFOFullSpeed").val();
				var do_ballast = $("#txtBDOFullSpeed").val();
			}
			if($("#selSSpeed_"+i).val() == 2)
			{
				var ballast = $("#txtBEcoSpeed1").val();
				var fo_ballast = $("#txtBFOEcoSpeed1").val();
				var do_ballast = $("#txtBDOEcoSpeed1").val();
			}
			if($("#selSSpeed_"+i).val() == 3)
			{
				var ballast = $("#txtBEcoSpeed2").val();
				var fo_ballast = $("#txtBFOEcoSpeed2").val();
				var do_ballast = $("#txtBDOEcoSpeed2").val();
			}
			var spd = ($("#txtDistance_"+i).val() /  (parseFloat(ballast) + parseFloat(speed_adj)));
			var calc = spd/24;
			var ttl_days = parseFloat(calc) + parseFloat(parseFloat(parseFloat(calc)*parseFloat(margin))/100);
			ballastdays = ballastdays + parseFloat(ttl_days.toFixed(3));
		
			var consp_fo = parseFloat((parseFloat(calc) + parseFloat(parseFloat(parseFloat(calc)*parseFloat(margin))/100)) *  parseFloat(fo_ballast));
			var consp_do = parseFloat((parseFloat(calc) + parseFloat(parseFloat(parseFloat(calc)*parseFloat(margin))/100)) *  parseFloat(do_ballast));	
			if(isNaN(consp_do) || consp_do=="")
	        {consp_do = 0;	}
			if(isNaN(consp_fo) || consp_fo=="")
	        {consp_fo = 0;	}
			consumptiondo = parseFloat(consumptiondo) + parseFloat(consp_do.toFixed(2));
			consumptionfo = parseFloat(consumptionfo) + parseFloat(consp_fo.toFixed(2));
			
			var ttl_dis = parseFloat(distance) + parseFloat($("#txtBDist").val());
			$("#txtBDist").val(ttl_dis.toFixed(2));
			$("#txtTDist").val($("#txtBDist,#txtLDist").sum().toFixed(2));
		}
		if($("#selPType_"+i).val() == 2)
		{
			if($("#selSSpeed_"+i).val() == 1)
			{
				var ladan = $("#txtLFullSpeed").val();
				var fo_ladan = $("#txtLFOFullSpeed").val();
				var do_ladan = $("#txtLDOFullSpeed").val();
			}
			if($("#selSSpeed_"+i).val() == 2)
			{
				var ladan = $("#txtLEcoSpeed1").val();
				var fo_ladan = $("#txtLFOEcoSpeed1").val();
				var do_ladan = $("#txtLDOEcoSpeed1").val();
			}
			if($("#selSSpeed_"+i).val() == 3)
			{
				var ladan = $("#txtLEcoSpeed2").val();
				var fo_ladan = $("#txtLFOEcoSpeed2").val();
				var do_ladan = $("#txtLDOEcoSpeed2").val();
			}
			
			var spd = ($("#txtDistance_"+i).val() /  (parseFloat(ladan) + parseFloat(speed_adj)));
			var calc = spd/24;
			var ttl_days = parseFloat(calc) + parseFloat(parseFloat(parseFloat(calc)*parseFloat(margin))/100);
			ladendays = parseFloat(ladendays) + parseFloat(ttl_days.toFixed(3));
			
			var consp_fo = parseFloat((parseFloat(calc) + parseFloat(parseFloat(parseFloat(calc)*parseFloat(margin))/100)) *  parseFloat(fo_ladan));
			var consp_do = parseFloat((parseFloat(calc) + parseFloat(parseFloat(parseFloat(calc)*parseFloat(margin))/100)) *  parseFloat(do_ladan));
			if(isNaN(consp_do) || consp_do=="")
	        {consp_do = 0;	}
			if(isNaN(consp_fo) || consp_fo=="")
	        {consp_fo = 0;	}	
			consumptiondo = parseFloat(consumptiondo) + parseFloat(consp_do.toFixed(2));
			consumptionfo = parseFloat(consumptionfo) + parseFloat(consp_fo.toFixed(2));
			
			var ttl_dis = parseFloat(distance) + parseFloat($("#txtLDist").val());
			$("#txtLDist").val(ttl_dis.toFixed(2));
			$("#txtTDist").val($("#txtBDist,#txtLDist").sum().toFixed(2));
		}
		
		
		if($("#txtIDays_"+i).val() == ""){var idle_days = 0;}else{var idle_days = $("#txtIDays_"+i).val();}
		if($("#txtWDays_"+i).val() == ""){var w_days = 0;}else{var w_days = $("#txtWDays_"+i).val();}	
		idealdays = parseFloat(idealdays) + parseFloat(idle_days);
		var ttl_days1 = parseFloat(w_days);
		var ttl_days = parseFloat(ttl_days1);
		workingdays = parseFloat(workingdays) + parseFloat(ttl_days);

		var margin_fo = parseFloat(idle_days) * parseFloat($("#txtPIFOFullSpeed").val());
		var wrkingdays_fo = parseFloat(w_days) * parseFloat($("#txtPWFOFullSpeed").val());
		var consp_fo =  parseFloat(margin_fo.toFixed(2)) + parseFloat(wrkingdays_fo.toFixed(2));
		
		var margin_do = parseFloat(idle_days) * parseFloat($("#txtPIDOFullSpeed").val());
		var wrkingdays_do = parseFloat(w_days) * parseFloat($("#txtPWDOFullSpeed").val());			
		var consp_do = parseFloat(margin_do.toFixed(2)) + parseFloat(wrkingdays_do.toFixed(2));	
		if(isNaN(consp_do) || consp_do=="")
		{consp_do = 0;	}
		if(isNaN(consp_fo) || consp_fo=="")
		{consp_fo = 0;	}
		consumptiondo = parseFloat(consumptiondo) + parseFloat(consp_do.toFixed(2));
		consumptionfo = parseFloat(consumptionfo) + parseFloat(consp_fo.toFixed(2));
		
		//Dis Port
		if($("#txtDIDays_"+i).val() == ""){var idle_days = 0;}else{var idle_days = $("#txtDIDays_"+i).val();}
		if($("#txtDWDays_"+i).val() == ""){var w_days = 0;}else{var w_days = $("#txtDWDays_"+i).val();}
		idealdays = parseFloat(idealdays) + parseFloat(idle_days);
		var ttl_days1 = parseFloat(w_days);
		var ttl_days = parseFloat(ttl_days1);
		workingdays = parseFloat(workingdays) + parseFloat(ttl_days);
		
		var margin_fo = parseFloat(idle_days) * parseFloat($("#txtPIFOFullSpeed").val());
		var wrkingdays_fo = parseFloat(w_days) * parseFloat($("#txtPWFOFullSpeed").val());
		var consp_fo =  parseFloat(margin_fo.toFixed(2)) + parseFloat(wrkingdays_fo.toFixed(2));
		
		var margin_do = parseFloat(idle_days) * parseFloat($("#txtPIDOFullSpeed").val());
		var wrkingdays_do = parseFloat(w_days) * parseFloat($("#txtPWDOFullSpeed").val());	
		var consp_do =  parseFloat(margin_do.toFixed(2)) + parseFloat(wrkingdays_do.toFixed(2));
		if(isNaN(consp_do) || consp_do=="")
		{consp_do = 0;	}
		if(isNaN(consp_fo) || consp_fo=="")
		{consp_fo = 0;	}
		consumptiondo = parseFloat(consumptiondo) + parseFloat(consp_do.toFixed(2));
		consumptionfo = parseFloat(consumptionfo) + parseFloat(consp_fo.toFixed(2));
		
		//transit 
		if($("#txtTLIDays_"+i).val() == ""){var idle_days = 0;}else{var idle_days = $("#txtTLIDays_"+i).val();}
		idealdays = parseFloat(idealdays) + parseFloat(idle_days);
		
		var margin_fo = parseFloat(idle_days) * parseFloat($("#txtPIFOFullSpeed").val());
		var margin_do = parseFloat(idle_days) * parseFloat($("#txtPIDOFullSpeed").val());
		if(isNaN(margin_do) || margin_do=="")
		{margin_do = 0;	}
		if(isNaN(margin_fo) || margin_fo=="")
		{margin_fo = 0;	}
		consumptiondo = parseFloat(consumptiondo) + parseFloat(margin_do.toFixed(2));
		consumptionfo = parseFloat(consumptionfo) + parseFloat(margin_fo.toFixed(2));
	}
	if(isNaN(consumptionfo) || consumptionfo=="")
	{consumptionfo = 0;	}
	$("#txtTFUMT").val(consumptionfo.toFixed(2));
	if(isNaN(consumptiondo) || consumptiondo=="")
	{consumptiondo = 0;	}
	$("#txtTDUMT").val(consumptiondo.toFixed(2));
	if(isNaN(ladendays) || ladendays=="")
	{ladendays = 0;	}
	$("#txtLDays").val(ladendays.toFixed(3));
	if(isNaN(ballastdays) || ballastdays=="")
	{ballastdays = 0;	}
	$("#txtBDays").val(ballastdays.toFixed(3));
	if(isNaN(idealdays) || idealdays=="")
	{idealdays = 0;	}
	if(isNaN(workingdays) || workingdays=="")
	{workingdays = 0;	}
	$("#txtTtPIDays").val(parseFloat(idealdays.toFixed(3)));$("#txtTtPWDays").val(parseFloat(workingdays.toFixed(3)));
	$("#txtTSDays").val($("#txtBDays,#txtLDays").sum().toFixed(3));
	$("#txtTDays").val($("#txtTSDays,#txtTtPIDays,#txtTtPWDays").sum().toFixed(2));
	getBunkerCalculation();
}



function addPortRotationDetails()
{
	var id = idd = $("#p_rotationID").val();
	if($("#selFPort_"+id).val() != "" && $("#selTPort_"+id).val() != "" && $("#selPType_"+id).val() != "" && $("#txtDistance_"+id).val() != "" && $("#selSSpeed_"+id).val() != "")
	{
		id = (id - 1) + 2;
		$('<tr id="pr_Row_'+id+'"><td align="center" class="input-text" ><a href="#pr'+id+'" id="spcancel_'+id+'" onclick="removePortRotation('+id+');" ><i class="fa fa-times" style="color:red;"></i></a></td><td align="left" class="input-text" ><select name="selFPort_'+id+'" style="width:100px;" class="input-text" id="selFPort_'+id+'" onChange="getDistance('+id+');"></select></td><td align="left" class="input-text" ><select  name="selTPort_'+id+'" class="input-text" style="width:100px;" id="selTPort_'+id+'" onChange="getDistance('+id+');"></select></td><td align="left" class="input-text" ><select  name="selDType_'+id+'" class="input-text" style="width:90px;" id="selDType_'+id+'" onChange="getDistance('+id+');"><?php $obj->getPortDistanceType(); ?></select></td><td align="left" class="input-text" ><select name="selPType_'+id+'" class="input-text" style="width:90px;" id="selPType_'+id+'" onChange="getVoyageTime()"; ><?php $obj->getPassageType(); ?></select></td><td align="left" class="input-text" ><input type="text" name="txtDistance_'+id+'" style="width:70px;" id="txtDistance_'+id+'" class="input-text"  value="" placeholder="0.00" onKeyUp="getVoyageTime()"; /><span id="ploader_'+id+'" style="display:none;"><img src="../../img/ajax-loader2.gif" /></span></td><td align="left" class="input-text" ><select  name="selSSpeed_'+id+'" class="input-text" id="selSSpeed_'+id+'" style="width:90px;" onChange="getVoyageTime()"; ><?php $obj->getSelectSpeedList(); ?></select></td><td align="left" class="input-text" ><input type="text" name="txtWeather_'+id+'" id="txtWeather_'+id+'" style="width:70px;" class="input-text" autocomplete="off" placeholder="0.00" onKeyUp="getVoyageTime()"; /></td><td align="left" class="input-text" ><input type="text" name="txtMargin_'+id+'" id="txtMargin_'+id+'" style="width:70px;" class="input-text" autocomplete="off" placeholder="0.00" onKeyUp="getVoyageTime()"; /><input type="hidden" name="txtVoyageTime_'+id+'" id="txtVoyageTime_'+id+'" class="input-text" autocomplete="off" value="" placeholder="0.00" /><input type="hidden" name="txtTTLVoyageDays_'+id+'" id="txtTTLVoyageDays_'+id+'" class="input-text" autocomplete="off" value="" placeholder="0.00" /><input type="hidden" name="txtTTLFoConsp_'+id+'" id="txtTTLFoConsp_'+id+'" class="input-text" readonly value="0.00"  /><input type="hidden" name="txtTTLDoConsp_'+id+'" id="txtTTLDoConsp_'+id+'" class="input-text" readonly value="0.00"  /></td></tr>').appendTo("#tblPortRotation");
		
		$('<tr id="lp_Row_'+id+'"><td align="center" class="input-text" ><span id="spanLoadPort_'+id+'"></span></td><td align="left" class="input-text" ><input type="text" name="txtPCosts_'+id+'" id="txtPCosts_'+id+'" class="input-text" autocomplete="off" value="" style="width:80px;" placeholder="0.00" onKeyUp="getFinalCalculation();"/></td><td align="left" class="input-text" ><input type="text" name="txtQMT_'+id+'" id="txtQMT_'+id+'" class="input-text" style="width:80px;" onKeyUp="getPortCalculation();" autocomplete="off" value="" placeholder="0.00" /></td><td align="left" class="input-text" ><input type="text" name="txtRate_'+id+'" id="txtRate_'+id+'" class="input-text" style="width:80px;" onKeyUp="getPortCalculation();" autocomplete="off" value="" placeholder="0.00" /></td><td align="left" class="input-text" ><select  name="selLPTerms_'+id+'" class="input-text" style="width:80px;" id="selLPTerms_'+id+'" onChange="getLPRemoveDaysAttr('+id+'),getPortCalculation();"><?php $obj->getLPTermsList(0);?></select></td><td align="left" class="input-text"><input type="text" name="txtWDays_'+id+'" id="txtWDays_'+id+'" class="input-text"  style="width:80px;"  autocomplete="off" readonly value="" onKeyUp= "getVoyageTime();"/></td><td align="left" class="input-text"><input type="text" name="txtIDays_'+id+'" id="txtIDays_'+id+'" class="input-text"  style="width:80px;"  autocomplete="off" value="" placeholder="0.00" onKeyUp="getVoyageTime();"/></td><td align="left" class="input-text" ><input name="ChkShowDDCLP_'+id+'" class="checkbox" id="ChkShowDDCLP_'+id+'" type="checkbox" value="'+id+'"/></td></tr>').appendTo("#tblLoadPort");
		
		
		$('<tr id="dp_Row_'+id+'"><td align="center" class="input-text" ><span id="spanDisPort_'+id+'"></span></td><td align="left" class="input-text" ><input type="text" name="txtDCosts_'+id+'" id="txtDCosts_'+id+'" class="input-text" style="width:80px;" autocomplete="off" value="" placeholder="0.00" onKeyUp="getFinalCalculation();"/></td><td align="left" class="input-text" ><input type="text" name="txtDQMT_'+id+'" id="txtDQMT_'+id+'" class="input-text" style="width:80px;" onKeyUp="getPortCalculation();" autocomplete="off" value="" placeholder="0.00" /></td><td align="left" class="input-text" ><input type="text" name="txtDRate_'+id+'" id="txtDRate_'+id+'" class="input-text" style="width:80px;" onKeyUp="getPortCalculation();" autocomplete="off" value="" placeholder="0.00" /></td><td align="left" class="input-text" ><select  name="selDPTerms_'+id+'" class="input-text" style="width:80px;" id="selDPTerms_'+id+'" onChange="getDPRemoveDaysAttr('+id+'),getPortCalculation();"><?php $obj->getLPTermsList(0);?></select></td><td align="left" class="input-text" ><input type="text" name="txtDWDays_'+id+'" id="txtDWDays_'+id+'" class="input-text" style="width:80px;" autocomplete="off" readonly value="" onKeyUp= "getVoyageTime();"/></td><td align="left" class="input-text" ><input type="text" name="txtDIDays_'+id+'" id="txtDIDays_'+id+'" class="input-text" style="width:80px;" autocomplete="off" value="" placeholder="0.00" onKeyUp="getVoyageTime();"/></td><td align="left" class="input-text" ><input name="ChkShowDDCDP_'+id+'" class="checkbox" id="ChkShowDDCDP_'+id+'" type="checkbox" value="'+id+'"/></td></tr>').appendTo("#tblDisPort");
		
		
		$('<tr id="tp_Row_'+id+'"><td align="center" class="input-text" ><span id="TranDisPort_'+id+'"></span></td><td align="left" class="input-text" ><input type="text" name="txtTLPCosts_'+id+'" id="txtTLPCosts_'+id+'" class="input-text" style="width:80px;" autocomplete="off" value="" placeholder="0.00" onKeyUp= "getPortCalculation();"/></td><td align="left" class="input-text" ><input type="text" name="txtTLIDays_'+id+'" id="txtTLIDays_'+id+'" class="input-text" style="width:80px;" autocomplete="off" value="" placeholder="0.00" onKeyUp="getVoyageTime();"/></td></tr>').appendTo("#tblTransitPort");
		
		
		$('<tr id="DDCLProw_'+id+'"><td>Load Port <span id="spanDDCLPort_'+id+'"></span></td><td><input type="text"  name="txtEstDDCLPCost_'+id+'" id="txtEstDDCLPCost_'+id+'" class="input-text" value="" placeholder="0.00" autocomplete="off" onKeyUp="getFinalCalculation();" /><input type="hidden" name="txtLPLayTimeIs_'+id+'" id="txtLPLayTimeIs_'+id+'" value="" /></td><td><input type="text"  name="txtDDCLPCost_'+id+'" id="txtDDCLPCost_'+id+'" class="input-text" value="0" onKeyUp="getFinalCalculation();" readonly autocomplete="off"/></td><td><input type="text"  name="txtLPADDComm_'+id+'" id="txtLPADDComm_'+id+'" class="input-text" value="" placeholder="0.00" autocomplete="off" onKeyUp="getFinalCalculation();" /></td><td><input type="text" name="txtDDCLPNetCostMT_'+id+'" id="txtDDCLPNetCostMT_'+id+'" class="input-text" readonly value="" /><input type="hidden" name="txtDDCLPCostMT_'+id+'" id="txtDDCLPCostMT_'+id+'" class="input-text" readonly value="0" /></td></tr><tr id="DDCDProw_'+id+'"><td>Discharge Port <span id="spanDDCDPort_'+id+'"></span></td><td><input type="text"  name="txtEstDDCDPCost_'+id+'" id="txtEstDDCDPCost_'+id+'" class="input-text" value="" placeholder="0.00" autocomplete="off" onKeyUp="getFinalCalculation();" /><input type="hidden" name="txtDPLayTimeIs_'+id+'" id="txtDPLayTimeIs_'+id+'" value="" /></td><td><input type="text"  name="txtDDCDPCost_'+id+'" id="txtDDCDPCost_'+id+'" class="input-text" value="" placeholder="0.00" onKeyUp="getFinalCalculation();" readonly autocomplete="off"/></td><td><input type="text"  name="txtDPADDComm_'+id+'" id="txtDPADDComm_'+id+'" class="input-text" value="" placeholder="0.00" autocomplete="off" onKeyUp="getFinalCalculation();" /></td><td><input type="text" name="txtDDCDPNetCostMT_'+id+'" id="txtDDCDPNetCostMT_'+id+'" class="input-text" readonly value="" /><input type="hidden" name="txtDDCDPCostMT_'+id+'" id="txtDDCDPCostMT_'+id+'" class="input-text" readonly value="0" /></td></tr>').appendTo("#tbDDCBody");
		$("[id^=txtDistance_],[id^=txtWeather_],[id^=txtMargin_],[id^=txtPCosts_],[id^=txtQMT_],[id^=txtRate_],[id^=txtIDays_],[id^=txtDWDays_],[id^=txtWDays_],[id^=txtTLPCosts_],[id^=txtTLIDays_],[id^=txtEstDDCLPCost_],[id^=txtEstDDCDPCost_],[id^=txtLPADDComm_],[id^=txtDPADDComm_],[id^=txtDQMT_],[id^=txtDRate_],[id^=txtDIDays_],[id^=txtDCosts_]").numeric();
		$("input[type='checkbox']").iCheck({
			checkboxClass: 'icheckbox_minimal',
			radioClass: 'iradio_minimal'
		});
		$("#selFPort_"+id+",#selTPort_"+id).html($("#selPort").html());
		$("#selFPort_"+id).val($("#selTPort_"+idd).val());
		$("#TranDisPort_"+id).html($("#selFPort_"+id+" option:selected").text());
		//.........ends...................
		$("#p_rotationID").val(id);
		if($("#selFPort_"+id).val()!=''){$("#spanLoadPort_"+id).html($("#selFPort_"+id+" option:selected").text());}
		if($("#selTPort_"+id).val()!=''){$("#spanDisPort_"+id).html($("#selTPort_"+id+" option:selected").text());}
		
		$('[id^=ChkShowDDCDP_]').on('ifChecked', function () { 
		   $("#DDCDProw_"+$(this).val()).hide();
		});
		 
		$('[id^=ChkShowDDCDP_]').on('ifUnchecked', function () { 
		   $("#DDCDProw_"+$(this).val()).show();
		});
		 
		$('[id^=ChkShowDDCLP_]').on('ifChecked', function () { 
			$("#DDCLProw_"+$(this).val()).hide();
		});
		 
		$('[id^=ChkShowDDCLP_]').on('ifUnchecked', function () { 
			$("#DDCLProw_"+$(this).val()).show();
		});
	}
	else
	{
		jAlert('Please fill all the records for Sea Passage', 'Alert');
	}
}

function removePortRotation(var1)
{
		jConfirm('Are you sure you want to remove this entry permanently ?', 'Confirmation', function(r) {
			if(r){
					$("#pr_Row_"+var1).remove();
					$("#lp_Row_"+var1).remove();
					$("#dp_Row_"+var1).remove();
					$("#tp_Row_"+var1).remove();
					$("#DDCDProw_"+var1).remove();
					$("#DDCLProw_"+var1).remove();
					getPortCalculation();		
				 }
			else{return false;}
			});
}


function getPortCalculation()
{
	var id = $("#p_rotationID").val();
	if($("#rdoEstimateType").val()==1)
	{
		var divideby = 24;
	}
	if($("#rdoEstimateType").val()==2)
	{
		var divideby = 24;
	}
	if($("#rdoEstimateType").val()==3)
	{
		var divideby = 1;
	}
	for(var i=1;i<=id;i++)
	{
		if($("#txtQMT_"+i).val() != "" && $("#txtRate_"+i).val() != "") 
		{
			var value = 0;
			if($("#selLPTerms_"+i).val() == 1)
			{
				value = parseFloat(parseFloat($("#txtQMT_"+i).val() / $("#txtRate_"+i).val())/parseInt(divideby));
			}
			else if($("#selLPTerms_"+i).val() == 2)
			{
				value = parseFloat(parseFloat($("#txtQMT_"+i).val() / $("#txtRate_"+i).val())/parseInt(divideby)) * 1.262 ;
			}
			else if($("#selLPTerms_"+i).val() == 3)
			{
				value = parseFloat(parseFloat($("#txtQMT_"+i).val() / $("#txtRate_"+i).val())/parseInt(divideby)) * 1.405 ;
			}
			else
			{
				value = parseFloat(parseFloat($("#txtQMT_"+i).val() / $("#txtRate_"+i).val())/parseInt(divideby));
			}
			
			if($("#selLPTerms_"+i).val() != 4)
			{
				if(isNaN(value) || value=="" || value=="Infinity")
				{
					value =0;
				}
				$("#txtWDays_"+i).val(value.toFixed(3));
			}
		}
		else
		{
			$("#txtWDays_"+i).val('0.00');
		}
		
		if($("#txtDQMT_"+i).val() != "" && $("#txtDRate_"+i).val() != "") 
		{
			var value = 0;
			if($("#selDPTerms_"+i).val() == 1)
			{
				value = parseFloat(parseFloat($("#txtDQMT_"+i).val() / $("#txtDRate_"+i).val())/parseInt(divideby));
			}
			else if($("#selDPTerms_"+i).val() == 2)
			{
				value = parseFloat(parseFloat($("#txtDQMT_"+i).val() / $("#txtDRate_"+i).val())/parseInt(divideby)) * 1.262 ;
			}
			else if($("#selDPTerms_"+i).val() == 3)
			{
				value = parseFloat(parseFloat($("#txtDQMT_"+i).val() / $("#txtDRate_"+i).val())/parseInt(divideby)) * 1.405 ;
			}
			else
			{
				value = parseFloat(parseFloat($("#txtDQMT_"+i).val() / $("#txtDRate_"+i).val())/parseInt(divideby));
			}
			
			if($("#selDPTerms_"+i).val() != 4)
			{
				if(isNaN(value) || value=="" || value=="Infinity")
				{
					value =0;
				}
				$("#txtDWDays_"+i).val(value.toFixed(3));
			}
		}
		else
		{
			$("#txtDWDays"+i+",#txtDWDays1_"+i).val('0.00');
		}
	}
	getVoyageTime();
}


function getLPRemoveDaysAttr(i)
{
	if($("#selLPTerms_"+i).val() == 4)
	{
		$("#txtWDays_"+i).removeAttr('readonly');
		$("#txtWDays_"+i).val(0);
	}
	else
	{
		$("#txtWDays_"+i).attr('readonly',true);
	}
}

function getDPRemoveDaysAttr(i)
{
	if($("#selDPTerms_"+i).val() == 4)
	{
		$("#txtDWDays_"+i).removeAttr('readonly');
		$("#txtDWDays_"+i).val(0);
	}
	else
	{
		$("#txtDWDays_"+i).attr('readonly',true);
	}	
}


function getFinalCalculation()
{
	var txtMainCargoDetailID = $("#txtMainCargoDetailID").val();
	var txtCargocbmsum  = txtCargomtsum = txtAmountUSDsum = 0;
	for(var i =1;i<=txtMainCargoDetailID;i++)
	{
		var txtCargocbm = parseFloat($("#txtCargocbm_"+i).val());if(isNaN(txtCargocbm) || txtCargocbm==''){txtCargocbm = 0;}
		var txtCargomt  = parseFloat($("#txtCargomt_"+i).val());if(isNaN(txtCargomt) || txtCargomt==''){txtCargomt = 0;}
		var txtRateUSDmt = parseFloat($("#txtRateUSDmt_"+i).val());if(isNaN(txtRateUSDmt) || txtRateUSDmt==''){txtRateUSDmt = 0;}
		
		txtCargocbmsum 		= parseFloat(txtCargocbmsum) + parseFloat(txtCargocbm);
		txtCargomtsum    	= parseFloat(txtCargomtsum) + parseFloat(txtCargomt);
		var amount 			= parseFloat(txtCargomt)*parseFloat(txtRateUSDmt);
		
		if(isNaN(amount) || amount==''){amount = 0;}
		$("#txtAmountUSD_"+i).val(parseFloat(amount).toFixed(2));
		txtAmountUSDsum 		= parseFloat(txtAmountUSDsum) + parseFloat(amount);
		
		$("#spancargoCBM").text(txtCargocbmsum.toFixed(2));
		$("#spancargoMT").text(txtCargomtsum.toFixed(2));
		$("#spanAmountUSD").text(txtAmountUSDsum.toFixed(2));
	}
	
	var txtoveragedetailID = $("#txtoveragedetailID").val();
	var txtCargocbmsum2  = txtCargomtsum2 = txtAmountUSDsum2 = 0;
	for(var i =1;i<=txtoveragedetailID;i++)
	{
		var txtCargocbm = parseFloat($("#txtCargocbm2_"+i).val());if(isNaN(txtCargocbm) || txtCargocbm==''){txtCargocbm = 0;}
		var txtCargomt  = parseFloat($("#txtCargomt2_"+i).val());if(isNaN(txtCargomt) || txtCargomt==''){txtCargomt = 0;}
		var txtRateUSDmt = parseFloat($("#txtRateUSDmt2_"+i).val());if(isNaN(txtRateUSDmt) || txtRateUSDmt==''){txtRateUSDmt = 0;}
		
		txtCargocbmsum2 		= parseFloat(txtCargocbmsum2) + parseFloat(txtCargocbm);
		txtCargomtsum2    	= parseFloat(txtCargomtsum2) + parseFloat(txtCargomt);
		var amount 			= parseFloat(txtCargomt)*parseFloat(txtRateUSDmt);
		
		if(isNaN(amount) || amount==''){amount = 0;}
		$("#txtAmountUSD2_"+i).val(parseFloat(amount).toFixed(2));
		txtAmountUSDsum2 		= parseFloat(txtAmountUSDsum2) + parseFloat(amount);
		
		$("#spancargoCBM2").text(txtCargocbmsum2.toFixed(2));
		$("#spancargoMT2").text(txtCargomtsum2.toFixed(2));
		$("#spanAmountUSD2").text(txtAmountUSDsum2.toFixed(2));
	}
	
	var txtdeadfreightdetailID = $("#txtdeadfreightdetailID").val();
	var txtCargocbmsum3  = txtCargomtsum3 = txtAmountUSDsum3 = 0;
	for(var i =1;i<=txtdeadfreightdetailID;i++)
	{
		var txtCargocbm = parseFloat($("#txtCargocbm3_"+i).val());if(isNaN(txtCargocbm) || txtCargocbm==''){txtCargocbm = 0;}
		var txtCargomt  = parseFloat($("#txtCargomt3_"+i).val());if(isNaN(txtCargomt) || txtCargomt==''){txtCargomt = 0;}
		var txtRateUSDmt = parseFloat($("#txtRateUSDmt3_"+i).val());if(isNaN(txtRateUSDmt) || txtRateUSDmt==''){txtRateUSDmt = 0;}
		
		txtCargocbmsum3 		= parseFloat(txtCargocbmsum3) + parseFloat(txtCargocbm);
		txtCargomtsum3    	= parseFloat(txtCargomtsum3) + parseFloat(txtCargomt);
		var amount 			= parseFloat(txtCargomt)*parseFloat(txtRateUSDmt);
		
		if(isNaN(amount) || amount==''){amount = 0;}
		$("#txtAmountUSD3_"+i).val(parseFloat(amount).toFixed(2));
		txtAmountUSDsum3 		= parseFloat(txtAmountUSDsum3) + parseFloat(amount);
		
		$("#spancargoCBM3").text(txtCargocbmsum3.toFixed(2));
		$("#spancargoMT3").text(txtCargomtsum3.toFixed(2));
		$("#spanAmountUSD3").text(txtAmountUSDsum3.toFixed(2));
	}
	var rev = parseFloat(txtAmountUSDsum) + parseFloat(txtAmountUSDsum2) + parseFloat(txtAmountUSDsum3);
	for(var l = 1;l<=$("#txtBRokageCount").val();l++)
	{
		if($("#txtBrCommPercent_"+l).val() == ""){var brokerage_comm = 0;}else{var brokerage_comm = $("#txtBrCommPercent_"+l).val();}
		var brokerage_comm_usd = (parseFloat(rev) * parseFloat(brokerage_comm))/100;
		$("#txtBrComm_"+l).val(brokerage_comm_usd.toFixed(2));
	}
	$("#txtBrCommPercent").val($("[id^=txtBrCommPercent_]").sum().toFixed(2));
	$("#txtBrComm").val($("[id^=txtBrComm_]").sum().toFixed(2));
	
	if($("#txtFrAdjPerAC").val() == ""){var ac_per = 0;}else{var ac_per = $("#txtFrAdjPerAC").val();}

	var address_commission = (parseFloat(rev) * parseFloat(ac_per)) / 100;
	$("#txtFrAdjUsdAC").val(address_commission.toFixed(2));
	rev = parseFloat(rev) - parseFloat(address_commission);
	
	var otherincomeAmt = 0;
	for(var l = 1;l<=$("#txtOthInCount").val();l++)
	{
		if($("#txtOtherAmt_"+l).val() == ""){var otheramt = 0;}else{var otheramt = $("#txtOtherAmt_"+l).val();}
		if($("#txtOtherAddComm_"+l).val() == "" && isNaN($("#txtOtherAddComm_"+l).val())){var otherpercent = 100;}else{var otherpercent = $("#txtOtherAddComm_"+l).val();}
		var other_usd = parseFloat(otheramt) - parseFloat(parseFloat(parseFloat(otheramt) * parseFloat(otherpercent))/100);
		if(isNaN(other_usd)){other_usd = 0;}
		$("#txtOtherNetAmt_"+l).val(other_usd.toFixed(2));
		otherincomeAmt = parseFloat(otherincomeAmt) + parseFloat(other_usd);
	}
	rev = parseFloat(rev) + parseFloat(otherincomeAmt);
	$("#txtRevenue").val(rev.toFixed(2));
	
	if($("#txtCVE").val() == ""){var txtCVE = 0;}else{var txtCVE = $("#txtCVE").val();}
	if($("#txtTDays").val() == ""){var txtTDays = 0;}else{var txtTDays = $("#txtTDays").val();}
	var calmul = parseFloat(parseFloat(parseFloat(txtCVE)/30)*parseFloat(txtTDays));
	if(isNaN(calmul) || calmul=="" || calmul=="Infinity"){calmul = 0;}
	$("#txtCVEAmt").val(calmul.toFixed(2));
	$("#txtHidCVEAmt").val(calmul.toFixed(2));
	
	
	if($("#txtDailyVesselOperatingExpenses").val() == ""){var daily_vessel_exp = 0;}else{var daily_vessel_exp = $("#txtDailyVesselOperatingExpenses").val();}
	var hireage_amt = parseFloat(parseFloat(daily_vessel_exp)*parseFloat($("#txtTDays").val())).toFixed(2);
	if(hireage_amt=="" || isNaN(hireage_amt)){hireage_amt =0;}
	$("#txtHireargeAmt").val(parseFloat(hireage_amt).toFixed(2));
	if($("#txtBallastBonus").val() == ""){var txtBallastBonus = 0;}else{var txtBallastBonus = $("#txtBallastBonus").val();}
	if($("#txtHireargePercent").val() == ""){var txtHireargePercent = 0;}else{var txtHireargePercent = $("#txtHireargePercent").val();}
	var ballast_hireage = parseFloat(hireage_amt) + parseFloat(txtBallastBonus);
	var txtHireargePercentAmt = parseFloat(parseFloat(parseFloat(ballast_hireage)*parseFloat(txtHireargePercent))/100);
	if(txtHireargePercentAmt=="" || isNaN(txtHireargePercentAmt)){txtHireargePercentAmt =0;}
	$("#txtHireargePercentAmt").val(parseFloat(txtHireargePercentAmt).toFixed(2));
	var txtNettHireargeAmt = parseFloat(parseFloat(ballast_hireage) -  parseFloat(txtHireargePercentAmt));
	$("#txtNettHireargeAmt").val(parseFloat(txtNettHireargeAmt).toFixed(2));	
	$("#txtTotalOperationalCost").val($("[id^=txtORCAmt_],#txtBrComm,#txtHidCVEAmt").sum());
	
	$("#txtTotalPortCost").val($("[id^=txtPCosts_],[id^=txtDCosts_],[id^=txtTLPCosts_]").sum().toFixed(2));
	
	var totalexpenses = $("#txtTotalOperationalCost,#txtTotalPortCost,#txtTotalBunkerCost").sum().toFixed(2);
	if($("#txtRevenue").val() == ""){var revenue = 0;}else{var revenue = $("#txtRevenue").val();}
	var costbeforebamarage = parseFloat(revenue) - parseFloat(totalexpenses);
	var voyage_earning = parseFloat(revenue) - parseFloat(totalexpenses) + parseFloat(getDDCOwnerCalculation());
	
	$("#txtVoyageEarnings").val(costbeforebamarage.toFixed(2));
	$("#txtGTTLVoyageEarnings").val(voyage_earning.toFixed(2));
	voyage_earning = parseFloat(voyage_earning) - parseFloat(txtNettHireargeAmt);
	if($("#txtTDays").val() == 0){var ttl_days = 1;}else{var ttl_days = $("#txtTDays").val();}
	var daily_earnings = parseFloat(voyage_earning) / parseFloat(ttl_days);
	var costbeforebamarage_erning = parseFloat(costbeforebamarage) / parseFloat(ttl_days);
	$("#txtDailyEarnings").val(daily_earnings.toFixed(2));
		
	
	var netprofilt = parseFloat(voyage_earning);
	var nett_daily_profit = parseFloat(parseFloat(voyage_earning)/parseFloat(ttl_days));
	if(nett_daily_profit=="" || isNaN(nett_daily_profit) || nett_daily_profit=="Infinity"){nett_daily_profit =0;}
	$("#txtNettDailyProfit").val(parseFloat(nett_daily_profit).toFixed(2));
	$("#txtPL").val(parseFloat(netprofilt).toFixed(2));
	
	$('[id^=txtLPOSCCost_]').each(function(index) {
				var rowid = this.id;
				var lasrvar1 = rowid.split('_').slice(1).join('_');
				var costMT = this.value / parseFloat(per_mt);
				$("#txtLPOSCCostMT_"+lasrvar1).val(costMT.toFixed(2));
			});
	$('[id^=txtDPOSCCost_]').each(function(index) {
				var rowid = this.id;
				var lasrvar1 = rowid.split('_').slice(1).join('_');
				var costMT = this.value / parseFloat(per_mt);
				$("#txtDPOSCCostMT_"+lasrvar1).val(costMT.toFixed(2));
			});
	$('[id^=txtTPOSCCost_]').each(function(index) {
				var rowid = this.id;
				var lasrvar1 = rowid.split('_').slice(1).join('_');
				var costMT = this.value / parseFloat(per_mt);
				$("#txtTPOSCCostMT_"+lasrvar1).val(costMT.toFixed(2));
			});
}


function addBrokerageRow()
{
	var id = $("#txtBRokageCount").val();
	if($("#txtBrCommPercent_"+id).val() != "")
	{
		id = (id - 1) + 2;
		$('<tr id="tbrRow_'+id+'"><td><a href="#tb1" onclick="removeBrokerage('+id+');" ><i class="fa fa-times" style="color:red;"></a></td><td>Brokerage Commission <span style="font-size:10px; font-style:italic;">(%)</span></td><td><input type="text" name="txtBrCommPercent_'+id+'" id="txtBrCommPercent_'+id+'" size="12" class="input-text" autocomplete="off" value="" onKeyUp="getFinalCalculation();" placeholder="0.00" /></td><td><input type="text" name="txtBrComm_'+id+'" size="12" id="txtBrComm_'+id+'" class="input-text" readonly value="0.00" /></td><td></td></tr>').appendTo("#tbodyBrokerage");
	    $("#selBroVList_"+id).html($("#selVendor").html());$("#selBroVList_"+id).val('');
		$("[id^=txtBrCommPercent_]").numeric();	
		$("#txtBRokageCount").val(id);
	}
	else
	{
		jAlert('Please fill previous data', 'Alert');
		return false;
	}
}

function removeBrokerage(var1)
{
		jConfirm('Are you sure you want to remove this entry permanently ?', 'Confirmation', function(r) {
			if(r){
					$("#tbrRow_"+var1).remove();
					getFinalCalculation();			
				 }
			else{return false;}
			});
}

function getTotalDWT()
{
	var dwt = $("#txtDWTS").val();
	
	if($("#rdoCap1").is(":checked"))
	{
		if($("#txtGCap").val() == ""){var gcap = 0;}else{var gcap = $("#txtGCap").val();}
		if($("#txtSF").val() != "" || $("#txtSF").val() != 0)
		{
			var ttl = parseFloat(parseFloat(gcap)*35.3146) / parseFloat($("#txtSF").val());
			if(parseFloat($("#txtSF").val())>0)
			{
				$("#txtLoadable").val(ttl.toFixed(2));
			}
			else
			{
				$("#txtLoadable").val(0);
			}
		}
	}
	
}



function getTotalDWT1()
{
	var dwt = $("#txtDWTS").val();
	
	if($("#rdoCap2").is(":checked"))
	{
		if($("#txtBCap").val() == ""){var bcap = 0;}else{var bcap = $("#txtBCap").val();}
		
		if($("#txtSF").val() != "" || $("#txtSF").val() != 0)
		{			
			var ttl = parseFloat(parseFloat(bcap)*35.3146) / parseFloat($("#txtSF").val());
			if(parseFloat($("#txtSF").val())>0)
			{
				$("#txtLoadable").val(ttl.toFixed(2));
			}
			else
			{
				$("#txtLoadable").val(0);
			}
		}
	}
	getFinalCalculation();
}

function getORCCalculate(var1)
{
	var cargo_qty = $("[id^=txtCargomt_],[id^=txtCargomt2_],[id^=txtCargomt3_]").sum().toFixed(2);
	if($("#txtORCAmt_"+var1).val() == ""){var cc_abs = 0;}else{var cc_abs = $("#txtORCAmt_"+var1).val();}
	var calc = parseFloat(cc_abs) / parseFloat(cargo_qty);
	$("#txtORCAmtMT_"+var1).val(calc.toFixed(2));
	getFinalCalculation();	
}

function getValidate(val)
{
	$("#txtStatus").val(val);
	getFinalCalculation();
	
}


function getDDCOwnerCalculation(){
	
	var cargo_qty = $("[id^=txtCargomt_],[id^=txtCargomt2_],[id^=txtCargomt3_]").sum().toFixed(2);
	
	$('[id^=txtDDCLPCost_]').each(function(index) {
		var rowid       = this.id;
		var ddswLP1     = rowid.split('_')[1];
		if($("#txtLPLayTimeIs_"+ddswLP1).val()==0)
		{
			$("#txtDDCLPCost_"+ddswLP1).val($("#txtEstDDCLPCost_"+ddswLP1).val());
		}
		if($("#txtDDCLPCost_"+ddswLP1).val() == ""){var addLPcost = 0;}else{var addLPcost = $("#txtDDCLPCost_"+ddswLP1).val();}
		var addcomm = $("#txtLPADDComm_"+ddswLP1).val();
		if(isNaN(addcomm) || addcomm==''){addcomm =0;}
		var addcommamt = parseFloat(parseFloat(parseFloat(addLPcost)*parseFloat(addcomm))/100);
		var remLpAmt  = parseFloat(addLPcost) - parseFloat(addcommamt);
		$('#txtDDCLPNetCostMT_'+ddswLP1).val(remLpAmt.toFixed(2));
		var ddswLPCCost = parseFloat(remLpAmt)/parseFloat(cargo_qty);
		$('#txtDDCLPCostMT_'+ddswLP1).val(ddswLPCCost.toFixed(2));
	});
	
	$('[id^=txtDDCDPCost_]').each(function(index) {
		var rowid       = this.id;
		var ddswDP1     = rowid.split('_')[1];
		if($("#txtDPLayTimeIs_"+ddswDP1).val()==0)
		{
			$("#txtDDCDPCost_"+ddswDP1).val($("#txtEstDDCDPCost_"+ddswDP1).val());
		}
		if($("#txtDDCDPCost_"+ddswDP1).val() == ""){var addDPcost = 0;}else{var addDPcost = $("#txtDDCDPCost_"+ddswDP1).val();}
		var addcomm = $("#txtDPADDComm_"+ddswDP1).val();
		if(isNaN(addcomm) || addcomm==''){addcomm =0;}
		var addcommamt = parseFloat(parseFloat(parseFloat(addDPcost)*parseFloat(addcomm))/100);
		var remLpAmt  = parseFloat(addDPcost) - parseFloat(addcommamt);
		$('#txtDDCDPNetCostMT_'+ddswDP1).val(remLpAmt.toFixed(2));
		var ddswDPCCost = parseFloat(remLpAmt)/parseFloat(cargo_qty);
		$('#txtDDCDPCostMT_'+ddswDP1).val(ddswDPCCost.toFixed(2));
	});
	var LPDPttl = parseFloat($('[id^=txtDDCLPNetCostMT_]').sum().toFixed(2)) + parseFloat($('[id^=txtDDCDPNetCostMT_]').sum().toFixed(2));
	return LPDPttl;
}


function getSubmitForm()
{
	$("#action").val("");
	document.frm1.submit();
}



function addORCRow()
{
	var id = $("#txtOWCCount").val();
	if($("#txtHidORCID_"+id).val() != "" && $("#txtORCAmt_"+id).val() != "")
	{
		id = (id - 1) + 2;
		$('<tr id="OWCRow_'+id+'"><td><a href="#tb1" onClick="removeCC('+id+');" ><i class="fa fa-times" style="color:red;"></i></a></td><td><select name="txtHidORCID_'+id+'" id="txtHidORCID_'+id+'" style="width:130px;" ></select></td><td><input type="text" name="txtORCAmt_'+id+'" id="txtORCAmt_'+id+'" onKeyUp="getORCCalculate('+id+');" class="input-text" autocomplete="off" value="" placeholder="0.00" size="12"  /></td></tr>').appendTo("#OWCBody");
		$("[id^=txtORCAmt_]").numeric();	
		$("#txtHidORCID_"+id).html($("#selOwnerCost").html());	
		$("#txtOWCCount").val(id);
	}
	else
	{
		jAlert('Please fill previous data', 'Alert');
		return false;
	}
}

function removeCC(var1)
{
		jConfirm('Are you sure you want to remove this entry permanently ?', 'Confirmation', function(r) {
			if(r){
					$("#OWCRow_"+var1).remove();
					getFinalCalculation();			
				 }
			else{return false;}
			});
}



function addOtherInRow()
{
	var id = $("#txtOthInCount").val();
	if($("#txtDesc_"+id).val() != "" && $("#txtOtherAmt_"+id).val() != "")
	{
		id = (id - 1) + 2;
		$('<tr id="OthInRow_'+id+'"><td><a href="#tb1" onClick="removeOtherIncome('+id+');" ><i class="fa fa-times" style="color:red;"></i></a></td><td><input type="text" name="txtDesc_'+id+'" id="txtDesc_'+id+'" class="input-text" autocomplete="off" value="" placeholder="Description" size="29"/></td><td><input type="text" name="txtOtherAmt_'+id+'" id="txtOtherAmt_'+id+'" onKeyUp="getFinalCalculation();" class="input-text" autocomplete="off" value="" placeholder="0.00" size="12"/></td><td><input type="text" name="txtOtherAddComm_'+id+'" id="txtOtherAddComm_'+id+'" onKeyUp="getFinalCalculation();" class="input-text" autocomplete="off" value="" placeholder="0.00" size="12"/></td><td><input type="text" name="txtOtherNetAmt_'+id+'" id="txtOtherNetAmt_'+id+'"  class="input-text" autocomplete="off" size="12" value="0.00"  readonly /></td></tr>').appendTo("#OthInBody");
		$("[id^=txtOtherAmt_],[id^=txtOtherAddComm_]").numeric();		
		$("#txtOthInCount").val(id);
	}
	else
	{
		jAlert('Please fill previous data', 'Alert');
		return false;
	}
}

function removeOtherIncome(var1)
{
		jConfirm('Are you sure you want to remove this entry permanently ?', 'Confirmation', function(r) {
			if(r){
					$("#OthInRow_"+var1).remove();
					getFinalCalculation();			
				 }
			else{return false;}
			});
}


function addMainCargoDetails()
{
	var id = $("#txtMainCargoDetailID").val();
	if($("#selCharterers_"+id).val() != "" && $("#txtCargocbm_"+id).val() != "" && $("#txtCargomt_"+id).val() != "" && $("#txtRateUSDmt_"+id).val() != "" && $("#txtAmountUSD_"+id).val() != "" )
	{
		id = (id - 1) + 2;
		$('<tr id="maincargodetailrow2_'+id+'"><td width="50px;"><a href="#tb1" onClick="deleteMainCargoDetails('+id+');" ><i class="fa fa-times" style="color:red;"></i></a></td><td><select name="selCharterers_'+id+'" class="input-text" style="width:120px;" id="selCharterers_'+id+'" onChange="getFinalCalculation();"></select></td><td><input type="text" name="txtCargocbm_'+id+'" id="txtCargocbm_'+id+'" class="input-text" autocomplete="off" value="" placeholder="0.00" onKeyUp="getFinalCalculation();"/></td><td><input type="text" name="txtCargomt_'+id+'" id="txtCargomt_'+id+'" class="input-text" autocomplete="off" value="" placeholder="0.00" onKeyUp="getFinalCalculation();"/></td><td><input type="text" name="txtRateUSDmt_'+id+'" id="txtRateUSDmt_'+id+'" class="input-text" autocomplete="off" value="" placeholder="0.00" onKeyUp="getFinalCalculation();"/></td><td><input type="text" name="txtAmountUSD_'+id+'" id="txtAmountUSD_'+id+'" class="input-text" autocomplete="off" value="" placeholder="0.00" onKeyUp="getFinalCalculation();" readonly="true" style="background-color:#E1E1E1;"/></td></tr>').appendTo("#tblmaincargodetail");
		$("#txtMainCargoDetailID").val(id);
		$("[id^=txtCargocbm_],[id^=txtCargomt_],[id^=txtRateUSDmt_],[id^=txtAmountUSD_]").numeric();
		$("#selCharterers_"+id).html($("#selCharterer").html());
	}
	else
	{
		jAlert('Please fill All details', 'Alert');
		return false;
	}
}


function deleteMainCargoDetails(var1)
{
		jConfirm('Are you sure you want to remove this entry permanently ?', 'Confirmation', function(r) {
			if(r){
					$("#maincargodetailrow1_"+var1).remove();
					$("#maincargodetailrow2_"+var1).remove();
					getFinalCalculation();	
				 }
			else{return false;}
			});
}

function addoveragedetail()
{
	var id = $("#txtoveragedetailID").val();
	if($("#selCharterers2_"+id).val() != "" && $("#txtCargocbm2_"+id).val() != "" && $("#txtCargomt2_"+id).val() != "" && $("#txtRateUSDmt2_"+id).val() != "" && $("#txtAmountUSD2_"+id).val() != "" )
	{
		id = (id - 1) + 2;
		$('<tr id="overagedetailrow2_'+id+'"><td width="50px;"><a href="#tb1" onClick="deleteoveragedetail('+id+');" ><i class="fa fa-times" style="color:red;"></i></a></td><td><select name="selCharterers2_'+id+'" class="input-text" style="width:120px;" id="selCharterers2_'+id+'" onChange="getFinalCalculation();"></select></td><td><input type="text" name="txtCargocbm2_'+id+'" id="txtCargocbm2_'+id+'" class="input-text" autocomplete="off" value="" placeholder="0.00" onKeyUp="getFinalCalculation();"/></td><td><input type="text" name="txtCargomt2_'+id+'" id="txtCargomt2_'+id+'" class="input-text" autocomplete="off" value="" placeholder="0.00" onKeyUp="getFinalCalculation();"/></td><td><input type="text" name="txtRateUSDmt2_'+id+'" id="txtRateUSDmt2_'+id+'" class="input-text" autocomplete="off" value="" placeholder="0.00" onKeyUp="getFinalCalculation();"/></td><td><input type="text" name="txtAmountUSD2_'+id+'" id="txtAmountUSD2_'+id+'" class="input-text" autocomplete="off" value="" placeholder="0.00" onKeyUp="getFinalCalculation();" readonly="true" style="background-color:#E1E1E1;"/></td></tr>').appendTo("#tbloveragedetail");
		$("#txtoveragedetailID").val(id);
		$("[id^=txtCargocbm2_],[id^=txtCargomt2_],[id^=txtRateUSDmt2_],[id^=txtAmountUSD2_]").numeric();
		$("#selCharterers2_"+id).html($("#selCharterer").html());
	}
	else
	{
		jAlert('Please fill All details', 'Alert');
		return false;
	}
}

function deleteoveragedetail(var1)
{
		jConfirm('Are you sure you want to remove this entry permanently ?', 'Confirmation', function(r) {
			if(r){
					$("#overagedetailrow1_"+var1).remove();
					$("#overagedetailrow2_"+var1).remove();
					getFinalCalculation();	
				 }
			else{return false;}
			});
}

function adddeadfreightdetail()
{
	var id = $("#txtdeadfreightdetailID").val();
	if($("#selCharterers3_"+id).val() != "" && $("#txtCargocbm3_"+id).val() != "" && $("#txtCargomt3_"+id).val() != "" && $("#txtRateUSDmt3_"+id).val() != "" && $("#txtAmountUSD3_"+id).val() != "" )
	{
		id = (id - 1) + 2;
		$('<tr id="deadfreightdetailrow2_'+id+'"><td width="50px;"><a href="#tb1" onClick="deletedeadfreightdetail('+id+');" ><i class="fa fa-times" style="color:red;"></i></a></td><td><select name="selCharterers3_'+id+'" class="input-text" style="width:120px;" id="selCharterers3_'+id+'" onChange="getFinalCalculation();"></select></td><td><input type="text" name="txtCargocbm3_'+id+'" id="txtCargocbm3_'+id+'" class="input-text" autocomplete="off" value="" placeholder="0.00" onKeyUp="getFinalCalculation();"/></td><td><input type="text" name="txtCargomt3_'+id+'" id="txtCargomt3_'+id+'" class="input-text" autocomplete="off" value="" placeholder="0.00" onKeyUp="getFinalCalculation();"/></td><td><input type="text" name="txtRateUSDmt3_'+id+'" id="txtRateUSDmt3_'+id+'" class="input-text" autocomplete="off" value="" placeholder="0.00" onKeyUp="getFinalCalculation();"/></td><td><input type="text" name="txtAmountUSD3_'+id+'" id="txtAmountUSD3_'+id+'" class="input-text" autocomplete="off" value="" placeholder="0.00" onKeyUp="getFinalCalculation();" readonly="true" style="background-color:#E1E1E1;"/></td></tr>').appendTo("#tbldeadfreight");
		$("#txtdeadfreightdetailID").val(id);
		$("[id^=txtCargocbm3_],[id^=txtCargomt3_],[id^=txtRateUSDmt3_],[id^=txtAmountUSD3_]").numeric();
		$("#selCharterers3_"+id).html($("#selCharterer").html());
	}
	else
	{
		jAlert('Please fill All details', 'Alert');
		return false;
	}
}

function deletedeadfreightdetail(var1)
{
		jConfirm('Are you sure you want to remove this entry permanently ?', 'Confirmation', function(r) {
			if(r){
					$("#deadfreightdetailrow1_"+var1).remove();
					$("#deadfreightdetailrow2_"+var1).remove();
					getFinalCalculation();	
				 }
			else{return false;}
			});
}


function showHideEstimateTypeDiv()
{
	if($("#rdoEstimateType").val()==1)
	{
		$("#loadtablelebel").html('(CBM/Hr)');
	    $("#dischargetablelebel").html('(CBM/Hr)');
		$("#loadqtylabel,#dischargeqtylabel").html('(MT)');
	}
	if($("#rdoEstimateType").val()==2)
	{
		$("#loadtablelebel").html('(MT/Hr)');
	    $("#dischargetablelebel").html('(MT/Hr)');
		$("#loadqtylabel,#dischargeqtylabel").html('(MT)');
	}
	
	if($("#rdoEstimateType").val()==3)
	{
		$("#loadtablelebel").html('(MT/Day)');
	    $("#dischargetablelebel").html('(MT/Day)');
		$("#loadqtylabel,#dischargeqtylabel").html('(MT)');
	}
}

</script>
    </body>
</html>