<?php 
session_start();


// print_r($_SESSION);


// die();


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();
$id 		        = $_REQUEST['id'];
$selTCOUTList 		= $_REQUEST['selTCOUTList'];

if(@$_REQUEST['action'] == 'submit')
{
	$msg = $obj->updateTCEstimateCal($id);
	header('Location:./estimate_tc_list.php?msg='.$msg);
}

$obj->viewTCEstimationTempleteRecordsNew($id);


$pagename = basename($_SERVER['PHP_SELF'])."?&id=".$id."&selTCOUTList=".$selTCOUTList;
?>
<!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(8); ?>
			<aside class="right-side">                
                <!-- Content Header (Page header) -->
                 <section class="content-header">
                    <h1>
                        <i class="fa fa-leaf"></i>&nbsp;TC Estimates&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">TC Estimates</li>
						<select  name="selVendor" style="display:none;"  id="selVendor" >
						<?php $obj->getVendorListNewUpdate();	?>
						</select> 
                    </ol>
                </section>
                
				<div align="right" style="margin-top:5px;margin-bottom:5px;margin-right:5px;"><a href="estimate_tc_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="padding:0px 5px 0px 5px;">
                       <tr class="input-text">
                           <td width="50px;"><strong>Fixture&nbsp;Type&nbsp;:</strong></td>
                           <td>&nbsp;TC&nbsp;Out&nbsp;<input name="selFType" type="hidden" id="selFType" value="1"></td>
                           <td>
                           <strong>Vessel&nbsp;:</strong></td>
						   <td><select name="selVName" id="selVName" class="input-text" style="width:110px;color:#175c84;background-color:#EAEAEA;" onChange="getData();" disabled="disabled">
                           <?php
                                $obj->getVesselTypeListMemberWise($_SESSION['selBType']);
                                ?>
                           </select>
                           </td>
                           <td><strong>Vessel&nbsp;Type&nbsp;:</strong></td>
                           <td><input type="text" name="txtVType" id="txtVType" style="width:110px;color:#175c84;background-color:#EAEAEA;" class="input-text" readonly value="<?php echo $obj->getFun4();?>" />
                            <select  name="selBunker" style="display:none;" id="selBunker">
                                <?php $obj->getBunkerList(); ?>
                            </select>
                            
                            <select name="selExpenseType" id="selExpenseType" style="display:none;">
                            <?php $obj->getExpenseTypeList();?>
                            </select>


							<select name="selOwRel" id="selOwRel" style="display:none;">
                            <?php $obj->getOwnerRelatedCostListForTallyInvoice();?>
                            </select>



                           </td>
                           <td><strong>Flag&nbsp;:</strong></td>
                           <td><input type="text" name="txtFlag" id="txtFlag" style="width:110px;color:#175c84;background-color:#EAEAEA;" class="input-text" readonly value="<?php echo $obj->getFun5();?>" /></td>
                            <td><strong>Date&nbsp;:</strong></td>
                            <td><input type="text" name="txtDate" id="txtDate" style="width:110px;color:#175c84;background-color:#EAEAEA;" class="input-text" value="<?php echo date("d-m-Y",strtotime($obj->getFun6()));?>" placeholder"dd-mm-yy" readonly="true" /></td>
                            <td ><strong>TC&nbsp;No.&nbsp;:</strong></td>
                            <td><input type="text" name="txtTCNo" id="txtTCNo" style="width:110px;color:#175c84;background-color:#EAEAEA;" class="input-text" value="<?php echo $obj->getFun7();?>" readonly/></td>
                       </tr>
                       <tr class="input-text">
                          <td >CP&nbsp;Date&nbsp;:</td>
                          <td><input autocomplete="off" type="text" name="txtCPdate2" id="txtCPdate2" class="input-text" value="<?php echo date("d-m-Y", strtotime($obj->getFun9())); ?>" style="width:110px;background-color:#EAEAEA;" placeholder="dd-mm-yy" readonly /></td>
                          <td >CP&nbsp;Type&nbsp;:&nbsp;&nbsp;&nbsp;</td>
                          <td><input autocomplete="off" type="text" name="txtCPType" id="txtCPType" class="input-text" style="width:110px; background-color:#EAEAEA;" readonly value="<?php echo $obj->getContractTypeMasterData($obj->getFun10(),'CONTRACT_TYPE');?>"/></td>
                          
                        <td ><span id="tripspan_2">Trip TC&nbsp;:</span><input name="selFType" type="hidden" id="selFType" value="1"></td>
                           <td><span id="tripspan_3"><input autocomplete="off" type="text" name="txtTripTC1" id="txtTripTC1" class="input-text" style="width:110px;background-color:#EAEAEA;" placeholder="Trip TC" value="<?php echo $obj->getFun74(); ?>" readonly/></span></td>
                           <td><span id="periodspan_2">Period&nbsp;:</span></td>
                           <td><span id="periodspan_3"><input autocomplete="off" type="text" name="txtPeriod1" id="txtPeriod1" style="width:110px;background-color:#EAEAEA;" class="input-text" placeholder="Period" value="<?php echo $obj->getFun75(); ?>" readonly/></span></td>
                           <td><span id="noOfTripspan_2">No. Of Trips&nbsp;:</span></td>
                           <td><span id="noOfTripspan_3"><input autocomplete="off" type="text" name="txtNoOfTrips1" id="txtNoOfTrips1" class="input-text" style="width:110px;background-color:#EAEAEA;" placeholder="No. Of Trips" value="<?php echo $obj->getFun76(); ?>" readonly/></span></td>
                           <td >Charterers&nbsp;:&nbsp;&nbsp;&nbsp;</td>
                          <td><input autocomplete="off" type="text" name="txtCharterers" id="txtCharterers" class="input-text" style="width:200px;background-color:#EAEAEA;" readonly value="<?php echo $obj->getVendorListNewData($obj->getFun11(),'NAME');?>"/></td>
                       </tr>
                       
                   </table>
				   <hr style="margin-bottom:2px; margin-top:8px; color:#000;">
	<!---------------------------------------------------------------------------------------------------------------->
	            <div><strong style="font-size:14px;">&nbsp;&nbsp;Estimates</strong></div>
         			
	<!---------------START--------------------------Tab_1->TC Estimate------------------------------------------------>	
				
	                   <?php
						$sql2 = "select * from chartering_tc_estimate_slave1 where TCOUTID = '".$id."'";
						$res2 = mysql_query($sql2) or die($sql2);
						$num  = mysql_num_rows($res2);$mx=1;

						// echo $sql2;
						$rows = mysql_fetch_assoc($res2)
						
				        ?>
                           <table width="100%" style="margin-bottom:5px; padding:0px 5px 0px 5px;">
						   <tr class="input-text">
							      <td colspan="12">
								    <table width="100%">
										<tbody id="tcDelRedeltbody_<?php echo $mx;?>">
										<tr>
										    <td width="5%">#</td>
											<td width="12%">Del Date/Time</td>
											<td width="12%">Re Del Date/Time</td>
											<td width="12%">TC Days</td>
											<td width="12%">Hire Rate (USD)</td>
											<td width="12%">Hire Amount (USD)</td>
											<td width="30%"></td>
										</tr>
									<?php $sql8 = "select * from chartering_estimate_tc_slave8 where TC_SLAVE1ID = '".$rows['TC_SLAVE1ID']."'";
										  $result8 = mysql_query($sql8);
										  $num8 = mysql_num_rows($result8);
										  $rr = 0;
										  if($num8 > 0)
										  {
										  while($rows8 = mysql_fetch_assoc($result8))
										  {$rr++;?>
										<tr id="delredel_row_<?php echo $mx;?>_<?php echo $rr;?>">	
											<td><a href="#tbl1" onClick="removeDelRedelRow(<?php echo $mx;?>,<?php echo $rr;?>);" ><i class="fa fa-times" style="color:red;"></i></a><input type="hidden" name="txtDelSlaveRandomID_<?php echo $mx;?>_<?php echo $rr;?>" id="txtDelSlaveRandomID_<?php echo $mx;?>_<?php echo $rr;?>" value="<?=$rows8['RANDOMID'];?>"></td>
											<td><input autocomplete="off" type="text" name="txtDeldate_<?php echo $mx;?>_<?php echo $rr;?>" id="txtDeldate_<?php echo $mx;?>_<?php echo $rr;?>" class="input-text datetimepicker" value="<?php if(date("d-m-Y", strtotime($rows8['DEL_DATE']))!='01-01-1970'){echo date("d-m-Y H:i", strtotime($rows8['DEL_DATE']));}?>" style="width:100px;" placeholder="dd-mm-yy hh:mm" /></td>
											<td><input autocomplete="off" type="text" name="txtReDeldate_<?php echo $mx;?>_<?php echo $rr;?>" id="txtReDeldate_<?php echo $mx;?>_<?php echo $rr;?>" class="input-text datetimepicker" value="<?php if(date("d-m-Y", strtotime($rows8['RE_DEL_DATE']))!='01-01-1970'){echo date("d-m-Y H:i", strtotime($rows8['RE_DEL_DATE']));}?>" style="width:100px;" placeholder="dd-mm-yy hh:mm" /></td>
											<td><input autocomplete="off" type="text" name="txtTCdays_<?php echo $mx;?>_<?php echo $rr;?>" id="txtTCdays_<?php echo $mx;?>_<?php echo $rr;?>" class="input-text" placeholder="TC Days" style="width:100px;background-color:#EAEAEA;" readonly value="<?php echo $rows8['HIRE_DAYS'];?>"/></td>
											<td><input autocomplete="off" type="text" name="txtHireRate_<?php echo $mx;?>_<?php echo $rr;?>" id="txtHireRate_<?php echo $mx;?>_<?php echo $rr;?>" class="input-text numeric" placeholder="Hire Rate" style="width:100px;" value="<?php echo $rows8['HIRE_RATE'];?>" onKeyUp="getFinalCalculation(<?php echo $mx;?>);"/></td>
											<td><input autocomplete="off" type="text" name="txtHireAmt_<?php echo $mx;?>_<?php echo $rr;?>" id="txtHireAmt_<?php echo $mx;?>_<?php echo $rr;?>" class="input-text" placeholder="Hire Amount" style="width:100px;background-color:#EAEAEA;" readonly value="<?php echo $rows8['HIRE_AMT'];?>"/></td>
											<td></td>
						                </tr>
									<?php }}else{$rr++; ?>
										<tr id="delredel_row_<?php echo $mx;?>_1">	
											<td><a href="#tbl1" onClick="removeDelRedelRow(<?php echo $mx;?>,1);" ><i class="fa fa-times" style="color:red;"></i></a></td>
											<td><input autocomplete="off" type="text" name="txtDeldate_<?php echo $mx;?>_1" id="txtDeldate_<?php echo $mx;?>_1" class="input-text datetimepicker" value="<?php if($obj->getFun46()=="" || $obj->getFun46()=="0000-00-00 00:00:00"  || $obj->getFun46()=="1970-01-01 08:00:00"){$txtDeliveryDate = "";}else{$txtDeliveryDate = date('d-m-Y H:i',strtotime($obj->getFun46()));}echo $txtDeliveryDate;?>" style="width:100px;" placeholder="dd-mm-yy hh:mm" /></td>
											<td><input autocomplete="off" type="text" name="txtReDeldate_<?php echo $mx;?>_1" id="txtReDeldate_<?php echo $mx;?>_1" class="input-text datetimepicker" value="<?php if($obj->getFun47()=="" || $obj->getFun47()=="0000-00-00 00:00:00"  || $obj->getFun47()=="1970-01-01 08:00:00"){$txtReDeliveryDate = "";}else{$txtReDeliveryDate = date('d-m-Y H:i',strtotime($obj->getFun47()));} echo $txtReDeliveryDate;?>" style="width:100px;" placeholder="dd-mm-yy hh:mm" /></td>
											<td><input autocomplete="off" type="text" name="txtTCdays_<?php echo $mx;?>_1" id="txtTCdays_<?php echo $mx;?>_1" class="input-text" placeholder="TC Days" style="width:100px;background-color:#EAEAEA;" readonly value="<?php echo $rows['TC_DAYS_EST'];?>"/></td>
											
											<td><input autocomplete="off" type="text" name="txtHireRate_<?php echo $mx;?>_1" id="txtHireRate_<?php echo $mx;?>_1" class="input-text numeric" placeholder="Hire Rate" style="width:100px;" value="<?php echo $obj->getFun54();?>" onKeyUp="getFinalCalculation(<?php echo $mx;?>);"/></td>
											<td><input autocomplete="off" type="text" name="txtHireAmt_<?php echo $mx;?>_1" id="txtHireAmt_<?php echo $mx;?>_1" class="input-text" placeholder="Hire Amount" style="width:100px;background-color:#EAEAEA;" readonly value=""/></td>
											<td></td>
						                </tr>
									<?php }?>
										</tbody>
										<tfoot>
										<tr>
											<td colspan="2"><button type="button" onClick="AddNewDelRedelRow(<?php echo $mx;?>);">Add</button><input type="hidden" name="txtDELREDELID_<?php echo $mx;?>" id="txtDELREDELID_<?php echo $mx;?>" value="<?php echo $rr;?>"/></td>
											<td></td>
											<td</td>
											<td></td>
											<td></td>
											<td></td>
											<td></td>
												
										</tr>
										</tfoot>
									</table>
								  </td>
							   </tr>
							  
							   <tr>
							<td>
								&nbsp;
							
							</td>
						</tr>
							   <tr>
							  
							<td style="width:10%;"><strong>Chartering Team&nbsp;:</strong></td>
							<td style="width:27%;" colspan="2">
							<select name="chartering_pic" class="input-text" id="chartering_pic" <?php if($_SESSION['iutype']=='mgmt_user'){ echo '';}else{
																		echo 'readonly';
																	}?> style="width:200px;color:#175c84;" onChange="" >										
							<?php
												// $obj->getFun261()

								echo $obj->getCountyListForChartering($obj->getFun147());

							?>					
							</select>				
							</td>
							<td style="width:10%;"><strong>Chartering&nbsp; PIC 1&nbsp;:</strong></td>
							<td style="width:27%;" colspan="2">
							<select name="chartering_pic_1" class="input-text" id="chartering_pic_1" <?php if($_SESSION['iutype']=='mgmt_user'){ echo '';}else{
																		echo 'readonly';
																	}?> style="width:200px;color:#175c84;" onChange="" >										
							<?php
												// $obj->getFun261()

								echo $obj->getUserListForChartering($obj->getFun148());

							?>	
							<input type="hidden" name="chTeam_1" id="chTeam_1" value="<?= $obj->getFun148()?>">							
							</select>	
							</td>
							<td style="width:10%;"><strong>Chartering&nbsp; PIC 2&nbsp;:</strong></td>
							<td style="width:27%;" colspan="2">
							<select name="chartering_pic_2" class="input-text" id="chartering_pic_2" <?php if($_SESSION['iutype']=='mgmt_user'){ echo '';}else{
																		echo 'readonly';
																	}?> style="width:200px;color:#175c84;" onChange="" >										
							<?php
												// $obj->getFun261()

								echo $obj->getUserListForChartering($obj->getFun149());

							?>
							<input type="hidden" name="chTeam_2" id="chTeam_2" value="<?= $obj->getFun149()?>">				
							</select>	

							</td>
							

							</tr>
							<tr>
							<td>
								&nbsp;
							
							</td>
						</tr>


                               <tr class="input-text">
                                  <td colspan="6">
                                     <table width="100%">
                                         <tr class="input-text">
                                            <td colspan="5"><strong>Delivery</strong></td>
                                         </tr>
                                         <tr class="input-text">
                                           <td>#</td>
                                           <td>Bunker Grade</td>
                                           <td>Qty(MT)</td>
                                           <td>Bunker Date</td>
                                           <td>Price USD/MT)</td>
                                           <td>Amount(USD)</td>
                                         </tr>
                                         <tbody id="bunkerdelivery">
                                        <?php 
										 if($num == 0){
											 $sql3 = "select * from chartering_estimate_tc_slave4 where TCOUTID='".$id."' and IDENTITY='DEL'";
											 $result3 = mysql_query($sql3);
											 $num3 = mysql_num_rows($result3);
										 }else{
										     $sql3 = "select * from chartering_estimate_tc_slave5 where TC_SLAVE1ID='".$rows['TC_SLAVE1ID']."' and IDENTITY='DEL'";
											 $result3 = mysql_query($sql3);
											 $num3 = mysql_num_rows($result3);
										 }
										 $k = 0;
                                         if($num3==0){$k++;?>
                                            <tr class="input-text" id="row_del_1">
                                               <td><a href="#tbl1" onClick="removeDelBunker(1);" ><i class="fa fa-times" style="color:red;"></i></a>&nbsp;&nbsp;</td>
                                               <td><select name="selDelBunker_1" class="input-text" style=" width:90px;" id="selDelBunker_1"></select></td>
                                               <td><input type="text" name="txtDelQty_1" id="txtDelQty_1_1" class="input-text numeric" style="width:85px;" value="" placeholder="0.00" onKeyUp="getFinalCalculation(1);" autocomplete="off" /></td>
                                               <td><input type="text" name="txtDelBunDate_1" id="txtDelBunDate_1_1" class="input-text" style="width:85px;" value="" placeholder="DD-MM-YYYY" autocomplete="off" /></td>
                                               <td><input type="text" name="txtDelPrice_1" id="txtDelPrice_1_1" class="input-text numeric" style="width:85px;" value="" placeholder="0.00" onKeyUp="getFinalCalculation(1);" autocomplete="off" /></td>
                                               <td><input type="text" name="txtDelAmount_1" id="txtDelAmount_1_1" readonly class="input-text numeric" style="width:85px;background-color:#E1E1E1;" value="" placeholder="0.00" autocomplete="off"/></td>
                                            </tr>
                                            <script>$("#selDelBunker_1").html($("#selBunker").html());</script>
                                       <?php }else{
                                           while($rows3 = mysql_fetch_assoc($result3))
                                           {$k++;
                                           if($rows3['BUNKER_DATE']=="" || $rows3['BUNKER_DATE']=="0000-00-00"  || $rows3['BUNKER_DATE']=="1970-01-01"){$txtDelBunDate = "";}else{$txtDelBunDate = date('d-m-Y',strtotime($rows3['BUNKER_DATE']));}
                                           ?>
                                             <tr class="input-text" id="row_del_<?php echo $k;?>">
                                               <td><a href="#tbl<?php echo $k;?>" onClick="removeDelBunker(<?php echo $k;?>);" ><i class="fa fa-times" style="color:red;"></i></a>&nbsp;&nbsp;</td>
                                               <td><select name="selDelBunker_<?php echo $k;?>" class="input-text" style=" width:90px;" id="selDelBunker_<?php echo $k;?>"></select></td>
                                               <td><input type="text" name="txtDelQty_<?php echo $k;?>" id="txtDelQty_1_<?php echo $k;?>" class="input-text numeric" style="width:85px;" value="<?php echo $rows3['QTY'];?>" placeholder="0.00" onKeyUp="getFinalCalculation(1);" autocomplete="off" /></td>
                                               <td><input type="text" name="txtDelBunDate_<?php echo $k;?>" id="txtDelBunDate_<?php echo $k;?>" class="input-text" style="width:85px;" value="<?php echo $txtDelBunDate;?>" placeholder="DD-MM-YYYY" autocomplete="off" /></td>
                                               <td><input type="text" name="txtDelPrice_<?php echo $k;?>" id="txtDelPrice_1_<?php echo $k;?>" class="input-text numeric" style="width:85px;" value="<?php echo $rows3['PRICE'];?>" placeholder="0.00" onKeyUp="getFinalCalculation(1);" autocomplete="off" /></td>
                                               <td><input type="text" name="txtDelAmount_<?php echo $k;?>" id="txtDelAmount_1_<?php echo $k;?>" readonly class="input-text numeric" style="width:85px;background-color:#E1E1E1;" value="<?php echo $rows3['AMOUNT'];?>" placeholder="0.00" autocomplete="off"/></td>
                                            </tr>
                                           <script>$("#selDelBunker_<?php echo $k;?>").html($("#selBunker").html());$("#selDelBunker_<?php echo $k;?>").val(<?php echo $rows3['BUNKERID'];?>)</script>
                                       <?php }}?>
                                        </tbody>
                                        <tbody>		
                                        <tr class="input-text">
                                            <td colspan="2"><button type="button" onClick="AddNewDel();">Add</button><input type="hidden" name="txtDELID" id="txtDELID_1" value="<?php echo $k;?>"/></td>
                                            <td ></td>
                                            <td ></td>
                                            <td ></td>
                                            <td ><input type="text" name="txtTotalDelAmount_1" id="txtTotalDelAmount_1" readonly class="input-text numeric" style="width:85px;background-color:#E1E1E1;" value="" placeholder="0.00" autocomplete="off"/></td>
                                            
                                        </tr>
                                     </table>
                                  
                                  </td>
                                  <td colspan="6">
                                     <table width="100%">
                                        <tr class="input-text">
                                            <td colspan="5"><strong>Re-Delivery</strong></td>
                                        </tr>
                                        <tr class="input-text">
                                           <td>#</td>
                                           <td>Bunker Grade</td>
                                           <td>Qty(MT)</td>
                                           <td>Bunker Date</td>
                                           <td>Price USD/MT)</td>
                                           <td>Amount(USD)</td>
                                        </tr>
                                        <tbody id="bunkerRedelivery">
                                        <?php 
										 
										 if($num == 0){
											 $sql3 = "select * from chartering_estimate_tc_slave4 where TCOUTID='".$id."' and IDENTITY='REDEL'";
											 $result3 = mysql_query($sql3);
											 $num3 = mysql_num_rows($result3);
										 }else{
										     $sql3 = "select * from chartering_estimate_tc_slave5 where TC_SLAVE1ID='".$rows['TC_SLAVE1ID']."' and IDENTITY='REDEL'";
											 $result3 = mysql_query($sql3);
											 $num3 = mysql_num_rows($result3);
										 }
										 $k = 0;
                                         if($num3==0){$k++;?>
                                            <tr class="input-text" id="row_Redel_1">
                                               <td><a href="#tbl1" onClick="removeReDelBunker(1);" ><i class="fa fa-times" style="color:red;"></i></a>&nbsp;&nbsp;</td>
                                               <td><select name="selReDelBunker_1" class="input-text" style=" width:90px;" id="selReDelBunker_1"></select></td>
                                               <td><input type="text" name="txtReDelQty_1" id="txtReDelQty_1_1" class="input-text numeric" style="width:85px;" value="" placeholder="0.00" onKeyUp="getFinalCalculation();" autocomplete="off" /></td>
                                               <td><input type="text" name="txtReDelBunDate_1" id="txtReDelBunDate_1" class="input-text" style="width:85px;" value="" placeholder="DD-MM-YYYY" autocomplete="off" /></td>
                                               <td><input type="text" name="txtReDelPrice_1" id="txtReDelPrice_1_1" class="input-text numeric" style="width:85px;" value="" placeholder="0.00" onKeyUp="getFinalCalculation();" autocomplete="off" /></td>
                                               <td><input type="text" name="txtReDelAmount_1" id="txtReDelAmount_1_1" readonly class="input-text numeric" style="width:85px;background-color:#E1E1E1;" value="" placeholder="0.00" autocomplete="off"/></td>
                                            </tr>
                                            <script>$("#selReDelBunker_1").html($("#selBunker").html());</script>
                                            <?php }else{
                                           while($rows3 = mysql_fetch_assoc($result3))
                                           {$k++;
                                           if($rows3['BUNKER_DATE']=="" || $rows3['BUNKER_DATE']=="0000-00-00"  || $rows3['BUNKER_DATE']=="1970-01-01"){$txtReDelBunDate = "";}else{$txtReDelBunDate = date('d-m-Y',strtotime($rows3['BUNKER_DATE']));}
                                           ?>
                                             <tr class="input-text" id="row_Redel_<?php echo $k;?>">
                                               <td><a href="#tbl<?php echo $k;?>" onClick="removeReDelBunker(<?php echo $k;?>);" ><i class="fa fa-times" style="color:red;"></i></a>&nbsp;&nbsp;</td>
                                               <td><select name="selReDelBunker_<?php echo $k;?>" class="input-text" style=" width:90px;" id="selReDelBunker_<?php echo $k;?>"></select></td>
                                               <td><input type="text" name="txtReDelQty_<?php echo $k;?>" id="txtReDelQty_1_<?php echo $k;?>" class="input-text numeric" style="width:85px;" value="<?php echo $rows3['QTY'];?>" placeholder="0.00" onKeyUp="getFinalCalculation(1);" autocomplete="off" /></td>
                                               <td><input type="text" name="txtReDelBunDate_<?php echo $k;?>" id="txtReDelBunDate_<?php echo $k;?>" class="input-text" style="width:85px;" value="<?php echo $txtReDelBunDate;?>" placeholder="DD-MM-YYYY" autocomplete="off" /></td>
                                               <td><input type="text" name="txtReDelPrice_<?php echo $k;?>" id="txtReDelPrice_1_<?php echo $k;?>" class="input-text numeric" style="width:85px;" value="<?php echo $rows3['PRICE'];?>" placeholder="0.00" onKeyUp="getFinalCalculation(1);" autocomplete="off" /></td>
                                               <td><input type="text" name="txtReDelAmount_<?php echo $k;?>" id="txtReDelAmount_1_<?php echo $k;?>" readonly class="input-text numeric" style="width:85px;background-color:#E1E1E1;" value="<?php echo $rows3['AMOUNT'];?>" placeholder="0.00" autocomplete="off"/></td>
                                            </tr>
                                           <script>$("#selReDelBunker_<?php echo $k;?>").html($("#selBunker").html());$("#selReDelBunker_<?php echo $k;?>").val(<?php echo $rows3['BUNKERID'];?>)</script>
                                       <?php }}?>
                                        </tbody>
                                        <tbody>		
                                        <tr class="input-text">
                                            <td colspan="2"><button type="button" onClick="AddNewReDel();">Add</button><input type="hidden" name="txtREDELID" id="txtREDELID_1" value="<?php echo $k;?>"/></td>
                                            <td ></td>
                                            <td ></td>
                                            <td ></td>
                                            <td ><input type="text" name="txtTotalReDelAmount" id="txtTotalReDelAmount_1" readonly class="input-text numeric" style="width:85px;background-color:#E1E1E1;" value="" placeholder="0.00" autocomplete="off"/></td>
                                        </tr>
                                        </tbody>
                                     </table>
                                  
                                  </td>
                               </tr>
                               
                               <tr class="input-text">
                                <td colspan="12">&nbsp;</td>
                               </tr>
                                <tr class="input-text">
                                   <td></th>
                                   <td>Off Hire Reason</td>
                                   <td>Off Hire From</td>
                                   <td>Off Hire To</td>
                                   <td>Off Hire Days</td>
                                   <td>Off Hire Rate/Day(USD)</td>
                                   <td>Off Hire(USD)</td>
                                   <td></td>
                                   <td >Utilisation Days&nbsp;</td>
                                   <td><input autocomplete="off" type="text" name="txtUtilisationDays" id="txtUtilisationDays_1" class="input-text" placeholder="Utilisation Days" style="width:90px;background-color:#EAEAEA;" readonly value="<?php echo $rows['UTILISATION_DAY_EST'];?>"></td>
                                   <td >HFO/MGO Diff.(USD)&nbsp;</td>
                                   <td><input autocomplete="off" type="text" name="txtBunkerDifference" id="txtBunkerDifference" class="input-text" placeholder="0.00" style="width:90px;background-color:#EAEAEA;" readonly value="<?php echo $rows['BUNKER_DIFF_AMT'];?>"></td>
                                   <td ></td>
                                </tr>
                                <tbody id="offhirebody">
								 <?php $sql3 = "select * from chartering_estimate_tc_slave3 where TC_SLAVE1ID='".$rows['TC_SLAVE1ID']."'";
                                 $result3 = mysql_query($sql3);
                                 $num3 = mysql_num_rows($result3);$k = 0;
                                 if($num3==0){$k++;?>
                                    <tr class="input-text" id="row_offhire_<?php echo $k;?>">
                                        <td><a href="#tb1" onClick="removeOffHire(<?php echo $k;?>);" ><i class="fa fa-times" style="color:red;"></i></a></td>
                                        <td valign="top"><textarea class="input-text areasize" name="txtOffHireReason_<?php echo $k;?>" style="width:120px;" id="txtOffHireReason_<?php echo $k;?>" rows="3" placeholder="Off Hire Reason..."><?php echo $rows2['OFFHIRE_REASON'];?></textarea></td>
                                        <td valign="top"><input autocomplete="off" type="text" name="txtOffHireFrom_<?php echo $k;?>" id="txtOffHireFrom_<?php echo $k;?>" class="input-text" value="" style="width:100px;" placeholder="dd-mm-yyyy HH:MM" /></td>
                                        <td valign="top"><input autocomplete="off" type="text" name="txtOffHireTo_<?php echo $k;?>" id="txtOffHireTo_<?php echo $k;?>" class="input-text" value="" style="width:100px;" placeholder="dd-mm-yyyy HH:MM" /></td>
                                        <td valign="top"><input autocomplete="off" type="text" name="txtOffHireDays_<?php echo $k;?>" id="txtOffHireDays_<?php echo $k;?>" class="input-text numeric" placeholder="Off Hire Days" style="width:90px;" value="" ></td>
                                        <td valign="top"><input autocomplete="off" type="text" name="txtOffHireRate_<?php echo $k;?>" id="txtOffHireRate_<?php echo $k;?>" class="input-text" placeholder="Rate/Day(USD)" style="width:100px;" onKeyUp="getFinalCalculation();" value="" ></td>
                                        <td valign="top"><input autocomplete="off" type="text" name="txtOffHireAmt_<?php echo $k;?>" id="txtOffHireAmt_<?php echo $k;?>" class="input-text" placeholder="Off Hire(USD)" style="width:90px;background-color:#EAEAEA;" readonly value="" ></td>
                                        <td></td><td></td><td></td><td></td><td></td>
                                    </tr>
                                <?php }else{
                                   while($rows3 = mysql_fetch_assoc($result3))
                                   {$k++;?>
                                     <tr class="input-text" id="row_offhire_<?php echo $k;?>">
                                        <td><a href="#tb1" onClick="removeOffHire(<?php echo $k;?>);" ><i class="fa fa-times" style="color:red;"></i></a></td>
                                        <td valign="top"><textarea class="input-text areasize" name="txtOffHireReason_<?php echo $k;?>" style="width:120px;" id="txtOffHireReason_<?php echo $k;?>" rows="2" placeholder="Off Hire Reason..."><?php echo $rows3['OFF_REASON'];?></textarea></td>
                                        <?php if($rows3['OFF_FROM']=='0000-00-00 00:00:00' || $rows3['OFF_FROM']=='1970-01-01 08:00:00'){$offfrom = '';}else{$offfrom = date('d-m-Y H:i',strtotime($rows3['OFF_FROM']));}?>
                                        <?php if($rows3['OFF_TO']=='0000-00-00 00:00:00' || $rows3['OFF_TO']=='1970-01-01 08:00:00'){$offto = '';}else{$offto = date('d-m-Y H:i',strtotime($rows3['OFF_TO']));}?>
                                        <td valign="top"><input autocomplete="off" type="text" name="txtOffHireFrom_<?php echo $k;?>" id="txtOffHireFrom_<?php echo $k;?>" class="input-text" value="<?php echo $offfrom;?>" style="width:100px;" placeholder="dd-mm-yyyy HH:MM" /></td>
                                        <td valign="top"><input autocomplete="off" type="text" name="txtOffHireTo_<?php echo $k;?>" id="txtOffHireTo_<?php echo $k;?>" class="input-text" value="<?php echo $offto;?>" style="width:100px;" placeholder="dd-mm-yyyy HH:MM" /></td>
                                        <td valign="top"><input autocomplete="off" type="text" name="txtOffHireDays_<?php echo $k;?>" id="txtOffHireDays_<?php echo $k;?>" class="input-text numeric" placeholder="Off Hire Days" style="width:90px;" value="<?php echo $rows3['OFF_DAYS'];?>" ></td>
                                        <td valign="top"><input autocomplete="off" type="text" name="txtOffHireRate_<?php echo $k;?>" id="txtOffHireRate_<?php echo $k;?>" class="input-text" placeholder="Rate/Day(USD)" style="width:100px;" onKeyUp="getFinalCalculation();" value="<?php echo $rows3['HIRE_RATE'];?>" ></td>
                                        <td valign="top"><input autocomplete="off" type="text" name="txtOffHireAmt_<?php echo $k;?>" id="txtOffHireAmt_<?php echo $k;?>" class="input-text" placeholder="Off Hire(USD)" style="width:90px;background-color:#EAEAEA;" readonly value="<?php echo $rows3['OFF_HIRE'];?>" ></td>
                                        <td></td><td></td><td></td><td></td><td></td>
                                    </tr>
                                <?php }}?>
                                </tbody>
                                <tbody>		
                                <tr class="input-text">
                                    <td ><button type="button" onClick="AddNewOffHire();">Add</button><input type="hidden" name="txtOFFID" id="txtOFFID" value="<?php echo $k;?>"/></td>
                                    <td colspan="11"></td>
                                    
                                </tr>
                             </table>
						  <hr style="margin-bottom:4px; margin-top:8px; color:#000;">
		<!----------------------/////////------------LEFT SIDE PART------------/////////------------------------------>	
					   <table width="100%" style="margin-bottom:5px; padding:0px 5px 0px 5px;">
                       <tr class="input-text">
                           <td width="50%"><strong>Revenue Calculations - USD</strong></td>
                           <td width="50%"><strong>Expense Calculations - USD</strong></td>
                       </tr>
                       <tr>
                           <td width="50%" style="padding-top:4px; vertical-align:top;">
                             <table width="100%">
							    <tbody>
                                <tr class="input-text">
                                	<td width="30%">Hire PDPR Currency</td>
                                    <td width="25%"></td>
									<td width="25%"><select  name="selExchangeCurrency" id="selExchangeCurrency" class="input-text" style="width:120px;background-color:#EAEAEA;" disabled="disabled"><?php $obj->getCurrencyList();?></select><input type="hidden" name="txtExchangeCurrency" id="txtExchangeCurrency" value="<?php echo $obj->getFun137(); ?>"/></td>
									<script>$("#selExchangeCurrency").val('<?php echo $obj->getFun137(); ?>');</script>
								</tr>
                                <tr class="input-text">
                                	<td width="30%">Exchange Rate To USD</td>
									<td width="25%"></td>
									<td width="25%"><input type="text" name="txtExchangeRate" id="txtExchangeRate" class="input-text numeric" style="width:120px;background-color:#EAEAEA;" value="<?php echo $obj->getFun138(); ?>" placeholder="Exchange Rate To USD" autocomplete="off" readonly /></td>
									
                                </tr>
                                <tr class="input-text">
                                	<td width="30%">Hire Fixed Period PDPR <span id="currencyspan"></span></td>
									<td width="25%"></td>
									<td width="25%"><input autocomplete="off" type="text" name="txtDailyGrossHireUSD" id="txtDailyGrossHireUSD" class="input-text" style="width:120px;background-color:#EAEAEA;" value="<?php echo $obj->getFun54();?>" readonly/>
									</td>
                                </tr>
                                <tr class="input-text">
                                	<td width="30%">Hire Fixed Period PDPR (USD)</td>
									<td width="25%"></td>
									<td width="25%"><input autocomplete="off" type="text" name="txtDailyGrossHireUSD1" id="txtDailyGrossHireUSD1" class="input-text" style="width:120px;background-color:#EAEAEA;" value="<?php echo number_format(($obj->getFun54()*$obj->getFun138()),2,'.','');?>" readonly/>
									</td>
                                </tr>

								<tr class="input-text">
                                        <td >Ballast Bonus(USD)</td>
										<td></td>
                                        <td><input autocomplete="off" type="text" name="txtBallastBonusAMT_<?php echo $mx;?>" id="txtBallastBonusAMT_<?php echo $mx;?>" class="input-text" value="<?php echo $rows['BALLAST_BONUS_AMT']; ?>" style="width:100px;" onKeyUp="getFinalCalculation(<?php echo $mx;?>);"></td>
                                        <td></td>
                                    </tr>


									



                                <tr class="input-text">
                                	<td >Add Comm(%)</td>
									
									<td><input autocomplete="off" type="text" name="txtAddCommPerct" id="txtAddCommPerct_1" class="input-text" style="width:120px;" value="<?php if($num==0){ echo $obj->getFun68();}else{echo $rows['ADD_COMM_EST'];} ?>" onkeyup="getFinalCalculation(1);"/></td>
									<td><input autocomplete="off" type="text" name="txtAddComm1" id="txtAddComm1_1" class="input-text" style="width:120px;background-color:#EAEAEA;" readonly value="<?php echo $rows['ADD_COMM_CAL_EST']; ?>"/></td>
                                </tr>
								<tr class="input-text">
                                	<td >Charterers side Broker Comm.(%)</td>
									
									<td><input autocomplete="off" type="text" name="txtChartererAcc" id="txtChartererAcc_1" class="input-text" style="width:120px;" value="<?php if($num==0){echo $obj->getFun69();} else{ echo $rows['BROKER_COMM_EST'];}?>" onkeyup="getFinalCalculation(1);"/></td>
									<td><input autocomplete="off" type="text" name="txtBrokerComm" id="txtBrokerComm_1" class="input-text" style="width:120px;background-color:#EAEAEA;" readonly value="<?php echo $rows['BROKER_COMM_CAL_EST']; ?>"/></td>
                                </tr>
								<tr class="input-text">
                                	<td >Nett Hire(USD/day)</td>
									
									<td></td>
									<td><input autocomplete="off" type="text" name="txtNettHire" id="txtNettHire_1" class="input-text" style="width:120px;background-color:#EAEAEA;" readonly value="<?php echo $rows['NETT_HIRE_EST']; ?>" ></td>
                                </tr>
								<tr class="input-text">
                                	<td >Nett Rev(USD)</td>
									
									<td></td>
									<td><input autocomplete="off" type="text" name="txtNettRev" id="txtNettRev_1" class="input-text" style="width:120px;background-color:#EAEAEA;" readonly value="<?php echo $rows['NETT_REV_EST']; ?>" /></td>
                                </tr>
								<tr class="input-text">
                                	<td >Less Off hire</td>
									
									<td></td>
									<td><input autocomplete="off" type="text" name="txtLessOffHire" id="txtLessOffHire_1" class="input-text" style="width:120px;background-color:#EAEAEA;" readonly value="<?php echo $rows['LESS_OFF_HIRE_EST']; ?>" ></td>
                                </tr>
								<tr class="input-text">
                                	<td >CVE(USD/Month)</td>
									
									<td><input autocomplete="off" type="text" name="txtCVEM" id="txtCVEM_1" class="input-text" style="width:120px;background-color:#EAEAEA;" readonly value="<?php if($num==0){echo $obj->getFun63();} else{ echo $rows['CVE_MONTH'];}?>"/></td>
									<td><input autocomplete="off" type="text" name="txtCVE" id="txtCVE_1" class="input-text" style="width:120px;background-color:#EAEAEA;" readonly value="<?php echo $rows['CVE_EST']; ?>"/></td>
                                </tr>

								<tr class="input-text">
                                        <td >ILOHC(USD)</td>
										<td></td>
                                        <td><input autocomplete="off" type="text" name="txtIlohcAMT_<?php echo $mx;?>" id="txtIlohcAMT_<?php echo $mx;?>" class="input-text" value="<?php echo $obj->getfun65();?>" style="width:100px;" onKeyUp="getFinalCalculation(<?php echo $mx;?>);"></td>
                                        <td></td>
                                    </tr>



                                <tr class="input-text">
                                    <td ><strong>Nett Hire to invoice(USD)</strong></td>
                                  
									<td></td>
                                    <td><input autocomplete="off" type="text" name="txtNETHire" id="txtNETHire_1" class="input-text" style="width:120px;background-color:#EAEAEA;" readonly value="<?php if($num==0){echo 0;} else{ echo $rows['NET_HIRE_AMT'];}?>"/></td>
                                    
                                </tr>
								<tr class="input-text">
                                	<td ><strong>Other Income</strong></td>
									
									<td></td>
									<td></td>
								</tr>
							</tbody>		
							<tbody id="otherIncomebody">
							 <?php $sql3 = "select * from chartering_estimate_tc_slave2 where STATUS=1 and TC_SLAVE1ID='".$rows['TC_SLAVE1ID']."'";
							 $result3 = mysql_query($sql3);
							 $num3 = mysql_num_rows($result3);$k = 0;
							 if($num3==0){$k++;?>
							    <tr class="input-text" id="row_otherincome_1">
								    <td><a href="#tb1" onClick="removeOtherIncome(1);" ><i class="fa fa-times" style="color:red;"></i></a></td>
                                	<td><input autocomplete="off" type="text" name="txtOtherIncomeText_1" id="txtOtherIncomeText_1" class="input-text" style="width:150px;" placeholder="Description" value="" /></td>
									<td><input autocomplete="off" type="text" name="txtOtherIncome_1" id="txtOtherIncome_1_1" class="input-text" style="width:120px;" onKeyUp="getFinalCalculation(1);" placeholder="Other Income(USD)" value="" /></td>
								</tr>
							<?php }else{
							   while($rows3 = mysql_fetch_assoc($result3))
							   {$k++;?>
							   <tr class="input-text" id="row_otherincome_<?php echo $k;?>">
							        <td><a href="#tb1" onClick="removeOtherIncome(<?php echo $k;?>);" ><i class="fa fa-times" style="color:red;"></i></a></td>
                                	<td ><input autocomplete="off" type="text" name="txtOtherIncomeText_<?php echo $k;?>" id="txtOtherIncomeText_<?php echo $k;?>" class="input-text" style="width:150px;" placeholder="Description" value="<?php echo $rows3['DESCRIPTION']; ?>" /></td>
									<td><input autocomplete="off" type="text" name="txtOtherIncome_<?php echo $k;?>" id="txtOtherIncome_1_<?php echo $k;?>" class="input-text" style="width:120px;" onKeyUp="getFinalCalculation(1);" placeholder="Other Income(USD)" value="<?php echo $rows3['OTHER_AMT']; ?>" /></td>
								</tr>
							<?php }}?>
							</tbody>
							<tbody>		
								<tr class="input-text">
                                	<td ><button type="button" onClick="addOtherIncomeRow();">Add</button><input type="hidden" name="hddnOtherID" id="hddnOtherID" value="<?php echo $k;?>"/></td>
									
									<td></td>
								</tr>
								<tr class="input-text">
                                	<td><strong>Total Rev</strong></td>
								
									<td></td>
									<td><input autocomplete="off" type="text" name="txtTotalRev" id="txtTotalRev_1" class="input-text" style="width:120px;background-color:#EAEAEA;" readonly value="<?php echo $rows['TOTAL_REV_EST']; ?>" /></td>
                                </tr>
							</tbody>
                             </table>
                           </td>
						   
	<!---------------------------------------------RIGHT SIDE PART----------------------------------------------------->					   
                           <td width="50%" style="padding-top:4px; vertical-align:top;">
						        <table width="100%">
								
                                <tr class="input-text">
                                	<td colspan="5"><strong>Other Expense</strong></td>
								</tr>
                                <tr class="input-text">
                                	<td></td>
									<td>Expense Descp.</td>
									<td>Expense Type</td>
								
                                    <td>Expense Descp.</td>
									<td>Add to TTL</td>
                                    <td>Expense Amt</td>
								</tr>
                               
								<tbody id="otherExpensebody">
								 <?php $sql3 = "select * from chartering_estimate_tc_slave2 where STATUS=2 and TC_SLAVE1ID='".$rows['TC_SLAVE1ID']."'";
								 $result3 = mysql_query($sql3);
								 $num3 = mysql_num_rows($result3);$k = 0;
								 if($num3==0){$k++;?>
									<tr class="input-text" id="row_otherExpense_1">
										<td><a href="#tb1" onClick="removeOtherExpense(1);" ><i class="fa fa-times" style="color:red;"></i></a></td>

										<td ><select name="selExpOwnerRelated_1" id="selExpOwnerRelated_1" class="input-text" style="width:110px;" onchange="markCheckBox(this)" ></select></td>


										<td ><select name="selExpenseType_1" id="selExpenseType_1_1" class="input-text" style="width:110px;"></select></td>
                                        <td><input autocomplete="off" type="text" name="txtExpenseDesc_1" id="txtExpenseDesc_1" class="input-text" style="width:110px;" placeholder="Expense Descp." value="" readonly/></td>
									<td><input name="ChkAddToTTL_1" class="checkbox" id="ChkAddToTTL_1" type="checkbox" value="1"/><input type="hidden" class="checkval" name="chkVal_1" id="chkVal_1_1" value="" /></td>
                                        <td><input autocomplete="off" type="text" name="txtOtherExpense_1" id="txtOtherExpense_1_1" class="input-text" style="width:110px;" onKeyUp="getFinalCalculation(1);" placeholder="Other Income(USD)" value="" /></td>
									</tr>
                                    <script>
									
									$("#selExpenseType_1_1").html($("#selExpenseType").html());
									$("#selExpOwnerRelated_1").html($("#selOwRel").html());
								
								</script>
								<?php }else{
								   while($rows3 = mysql_fetch_assoc($result3))
								   {$k++;?>
								   <tr class="input-text" id="row_otherExpense_<?php echo $k;?>">
										<td><a href="#tb1" onClick="removeOtherExpense(<?php echo $k;?>);" ><i class="fa fa-times" style="color:red;"></i></a></td>

										<td ><select name="selExpOwnerRelated_<?php echo $k;?>" id="selExpOwnerRelated_<?php echo $k;?>" class="input-text" style="width:110px;" onchange="markCheckBox(this)"></select></td>

										
										<td ><select name="selExpenseType_<?php echo $k;?>" id="selExpenseType_1_<?php echo $k;?>" class="input-text" style="width:110px;"></select></td>
                                        <td><input autocomplete="off" type="text" name="txtExpenseDesc_<?php echo $k;?>" id="txtExpenseDesc_<?php echo $k;?>" class="input-text" style="width:110px;" placeholder="Expense Descp." value="<?php echo $rows3['DESCRIPTION']; ?>" readonly/></td>
                                        <td><input name="ChkAddToTTL_<?php echo $k;?>" class="checkbox" id="ChkAddToTTL_<?php echo $k;?>" type="checkbox" value="1" <?php if($rows3['CHK_ADDTTL']==1){echo "checked";}?>/><input type="hidden" class="checkval" name="chkVal_<?php echo $k;?>" id="chkVal_1_<?php echo $k;?>" value="<?php if($rows3['CHK_ADDTTL']==1){echo "1";}?>" /></td>
										<td><input autocomplete="off" type="text" name="txtOtherExpense_<?php echo $k;?>" id="txtOtherExpense_1_<?php echo $k;?>" class="input-text" style="width:110px;" onKeyUp="getFinalCalculation(1);" placeholder="Other Income(USD)" value="<?php echo $rows3['OTHER_AMT']; ?>" /></td>
									</tr>
                                    <script>$("#selExpenseType_1_<?php echo $k;?>").html($("#selExpenseType").html());$("#selExpenseType_1_<?php echo $k;?>").val(<?php echo $rows3['EXPENSETYPEID']; ?>);
								
									

								$("#selExpOwnerRelated_<?php echo $k;?>").html($("#selOwRel").html());$("#selExpOwnerRelated_<?php echo $k;?>").val('<?php echo $rows3['DESCRIPTION']; ?>');

									
								
								</script>
								<?php }}?>
								</tbody>
								<tr class="input-text">
                                	<td colspan="5"><button type="button" onClick="addOtherExpenseRow();">Add</button><input type="hidden" name="hddnOtherExID" id="hddnOtherExID_1" value="<?php echo $k;?>"/></td>
								</tr>
                                <tr class="input-text">
                                	<td colspan="5">&nbsp;</td>
								</tr>
                                <tr class="input-text">
                                	<td colspan="5"><strong>TC In Expenses</strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button type="button" data-toggle="modal" data-target="#compose-modal_TC" class="btn-danger btn-flat" style="font-size:12px;">TC In Expenses</button></td>
                                </tr>
                                <tr class="input-text">
                                	<td colspan="5">&nbsp;</td>
								</tr>
								<tr class="input-text">
                                	<td ><strong>Total Expenses</strong></td>
									<td></td>
                                    <td><input autocomplete="off" type="text" name="txtTotalExpenses" id="txtTotalExpenses_1" class="input-text" style="width:110px;background-color:#EAEAEA;" placeholder="Total Expenses" readonly value="<?php echo $rows['TOTAL_EXP_EST']; ?>"/></td>
                                    <td></td>
									<td></td>
                                    
                                </tr>
                                <tr class="input-text">
                                	<td ><strong>TC Earnings</strong></td>
                                    <td></td>
									<td><input autocomplete="off" type="text" name="txtVoyageEarnings" id="txtVoyageEarnings_1" class="input-text" style="width:110px;background-color:#EAEAEA;" placeholder="Voyage Earnings" value="<?php echo $rows['VOYAGE_EARN_EST']; ?>"/></td>
                                    <td></td>
                                    <td></td>
                                </tr>

								<?php 

								// var_dump($_SESSION['disPL']=='1');

									
								// echo '<h1>'.$obj->getFun150();

								
								?>
                                <tr class="input-text">
									<td ><strong><span style="display:<?php if($_SESSION['iutype']=='mgmt_user' || ($_SESSION['disPL']=='1' && $_SESSION['uid']==$obj->getFun150())){echo '';}else{echo 'none';}?>;">Profit / Day</span>&nbsp;</strong></td>
                                    <td></td>
									<td><span style="display:<?php if($_SESSION['iutype']=='mgmt_user' || ($_SESSION['disPL']=='1' && $_SESSION['uid']==$obj->getFun150())){echo '';}else{echo 'none';}?>;"><input autocomplete="off" type="text" name="txtProfitPerDay" id="txtProfitPerDay_1" class="input-text" style="width:110px;background-color:#EAEAEA;" placeholder="Voy Earnings/Utilisation Days" value="<?php echo $rows['PROFIT_PER_DAY_EST']; ?>"/></span></td>
                                    <td></td>
                                    <td></td>
                                </tr>
                            </table>
                           </td>
                       </tr>
					   </table>
					   
					   <div class="modal fade" id="compose-modal_TC" tabindex="-1" role="dialog" aria-hidden="true">
						<div class="modal-dialog" style="width:90%;">
							 <div class="modal-content">
								<div class="modal-header">
									<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
									<h4 class="modal-title"><i class="fa fa-file-text-o"></i>&nbsp;&nbsp;TC Hire Details</h4>
								</div>
								<div class="modal-body" >
								<table width="100%">
								   <thead>
									  <tr>
										 <th><strong>Vessel :</strong></th>
										 <th><span id="vesselnamespan"></span></th>
										 <th><strong>CP Date :</strong></th>
										 <?php if(date("d-m-Y",strtotime($rows['TC_CP_DATE']))!='01-01-1970'){$cpdate = date("d-m-Y",strtotime($rows['TC_CP_DATE']));}else{$cpdate = date("d-m-Y", strtotime($obj->getFun9()));}?>
										 <th><input type="text" name="txtTCCPDate" id="txtTCCPDate" class="input-text" style="width:120px;" value="<?php echo $cpdate;?>" placeholder="DD-MM-YYYY" autocomplete="off"></th>
										 <th><strong>Contract Ref. :</strong></th>
										 <th><input type="text" name="txtTCCPNumber" id="txtTCCPNumber" class="input-text" style="width:120px;" value="<?=$rows['TC_CP_NUMBER'];?>" placeholder="Contract Ref." autocomplete="off"></th>
										 <th>Port/Region of Delivery :</th>
										 <th><input type="text" name="txtTCDeliveryPort" id="txtTCDeliveryPort" class="input-text" style="width:180px;" value="<?=$rows['TC_PORT_DELIVERY']?>" placeholder="" autocomplete="off" ></th>
										 <th>Port/Region of Re-Delivery :</th>
										 <th><input type="text" name="txtTCReDeliveryPort" id="txtTCReDeliveryPort" class="input-text" style="width:180px;" value="<?=$rows['TC_PORT_REDELIVERY']?>" placeholder="" autocomplete="off">
										 </th>
									  </tr>
								   </thead>
								</table>
								<table width="100%" class="tablesorter" style="margin-top:20px;">
								   <tbody id="hostTCDIV">
								   <?php
								   $sql5 = "select * from chartering_tc_estimate_slave2 where TC_SLAVE1ID='".$rows['TC_SLAVE1ID']."'"; 
								   $result5 = mysql_query($sql5);
								   $num5 = mysql_num_rows($result5);$km = 0;
								   if($num5 >0)
								   {
									  while($rows5 = mysql_fetch_assoc($result5))
									  {$km++;
										$sql_random = "SELECT * from invoice_hiretc_slave3 inner join invoice_hiretc_master on invoice_hiretc_master.INVOICEID = invoice_hiretc_slave3.INVOICEID where invoice_hiretc_master.COMID='".$comid."' and invoice_hiretc_slave3.RANDOMID='".$rows5['RANDOMID']."' and invoice_hiretc_master.STATUS=1";
										$res_random 	= mysql_query($sql_random) or die($sql_random);
										$rec_random 	= mysql_num_rows($res_random);
										if($rec_random>0){$invoicedval = 1;}else{$invoicedval = 0;}
									  ?>
										 <tr id="hostTCtr1_<?=$km;?>">
											<td width="5%" valign="top"><?php if($invoicedval==0){?><a href="#tb1" onClick="removeHostTCtr(<?=$km;?>);" ><i class="fa fa-times" style="color:red;"></i></a><?php }?><input type="hidden" name="txtTCINSlaveRandomID_<?=$km;?>" id="txtTCINSlaveRandomID_<?=$km;?>" value="<?=$rows5['RANDOMID'];?>"></td>
											<td  width="10%">Date of Delivery&nbsp;:</td>
											<td  width="10%"><?php if(date("d-m-Y",strtotime($rows5['TC_DELIVERY_DATE']))!='01-01-1970'){$deldate = date("d-m-Y H:i",strtotime($rows5['TC_DELIVERY_DATE']));}else{$deldate = '';}?>
												 <input type="text" name="txtTCDeliveryDate_<?=$km;?>" id="txtTCDeliveryDate_1_<?=$km;?>" class="input-text <?php if($invoicedval==10){?>datetimepicker<?php }?>" style="width:110px;" value="<?php echo $deldate;?>" placeholder="dd-mm-yy hh:mm" autocomplete="off" <?php if($invoicedval==1){?> readonly="true"<?php }?>>
											</td>
											<td  width="10%">Date of Re-Delivery&nbsp;:</td>
											<td  width="10%"><?php if(date("d-m-Y",strtotime($rows5['TC_REDELIVERY_DATE']))!='01-01-1970'){$redeldate = date("d-m-Y H:i",strtotime($rows5['TC_REDELIVERY_DATE']));}else{$redeldate = '';}?>
												 <input type="text" name="txtTCReDeliveryDate_<?=$km;?>" id="txtTCReDeliveryDate_1_<?=$km;?>" class="input-text <?php if($invoicedval==0){?>datetimepicker<?php }?>" style="width:110px;" value="<?php echo $redeldate;?>" placeholder="dd-mm-yy hh:mm" autocomplete="off" <?php if($invoicedval==1){?> readonly="true"<?php }?>>
											</td>
											<td>Total Voyage Days&nbsp;:</td>
											<td><input type="text"  name="txtTotalVoyageDays_<?=$km;?>" style="width:110px;" id="txtTotalVoyageDays_1_<?=$km;?>" class="input-text" autocomplete="off" readonly="true" value="<?php echo $rows5['TD_DAYS']; ?>" placeholder="0.00"/></td>
											<td>Daily Hire(USD/Day)&nbsp;:</td>
											<td><input type="text"  name="txtTCinDailyHire_<?=$km;?>" style="width:110px;" id="txtTCinDailyHire_1_<?=$km;?>" class="input-text numeric" autocomplete="off" value="<?php echo $rows5['TC_RATE']; ?>" placeholder="0.00" onKeyUp="getFinalCalculation(1);" <?php if($invoicedval==1){?> readonly="true"<?php }?>/></td>
											
											<td>Hireage (USD):</td>
											<td><input type="text"  name="txtHireargeAmt_<?=$km;?>" id="txtHireargeAmt_1_<?=$km;?>" style="width:110px;" class="input-text" value="<?php echo $rows5['HIERAGE']; ?>" placeholder="0.00" readonly /></td>
										</tr>
										<tr id="hostTCtr2_<?=$km;?>">
											<td></td>
											<td>Ballast Bonus (USD):</td>
											<td><input type="text" name="txtBallastBonus_<?=$km;?>" id="txtBallastBonus_1_<?=$km;?>" style="width:110px;" onKeyUp="getFinalCalculation(1);" class="input-text numeric" autocomplete="off" value="<?php echo $rows5['BALLAST_BONUS']; ?>" placeholder="0.00" <?php if($invoicedval==1){?> readonly="true"<?php }?>></td>
											<td>Gross Hire-age (USD):</td>
											<td><input type="text"  name="txtGrossHireargeAmt_<?=$km;?>" id="txtGrossHireargeAmt_1_<?=$km;?>" style="width:110px;" class="input-text numeric" value="<?php echo $rows5['GROSS_HIERAGE']; ?>" placeholder="0.00" readonly /></td>
											<td>Add Comm <span style="font-size:10px; font-style:italic;">(%)</span>:</td>
											<td><input type="text"  name="txtHireargePercent_<?=$km;?>" style="width:110px;" id="txtHireargePercent_1_<?=$km;?>" class="input-text numeric" value="<?php echo $rows5['ADD_COMM']; ?>" placeholder="%" onKeyUp="getFinalCalculation(1);" <?php if($invoicedval==1){?> readonly="true"<?php }?>/></td>
											<td>Add Comm <span style="font-size:10px; font-style:italic;">(USD)</span>:</td>
											<td><input type="text"  name="txtHireargePercentAmt_<?=$km;?>" style="width:110px;" id="txtHireargePercentAmt_1_<?=$km;?>" class="input-text" value="<?php echo $rows5['ADD_COMM_AMT']; ?>" placeholder="0.00" readonly /></td>
											<td>Add Comm Vendor:</td>
											<td><select name="selTCAddCoVendor_<?=$km;?>" class="input-text" style="width:110px;" id="selTCAddCoVendor_<?=$km;?>" ></select></td>
											<script>$("#selTCAddCoVendor_<?=$km;?>").html($("#selVendor").html());$("#selTCAddCoVendor_<?=$km;?>").val('<?php echo $rows5['ADD_COMM_VENDOR']; ?>');</script>
										 </tr>
										 <tr id="hostTCtr3_<?=$km;?>">
											<td></td>
											<td></td>
											<td></td>
											<td></td>
											<td></td>
											<td>Owners side Brokerage commission:</td>
											<td><input type="text"  name="txtHireargeBroPercent_<?=$km;?>" style="width:110px;" id="txtHireargeBroPercent_1_<?=$km;?>" class="input-text numeric" value="<?php echo $rows5['BROKERAGE_COMM']; ?>" placeholder="%" onKeyUp="getFinalCalculation();" <?php if($invoicedval==1){?> readonly="true"<?php }?>/></td>
											<td>Brokerage <span style="font-size:10px; font-style:italic;">(USD)</span>:</td>
											<td><input type="text"  name="txtHireargeBroPercentAmt_<?=$km;?>" style="width:110px;" id="txtHireargeBroPercentAmt_1_<?=$km;?>" class="input-text" value="<?php echo $rows5['BROKERAGE_COMM_AMT']; ?>" placeholder="0.00" readonly /></td>
											<td>Broker :</td>
											<td><select name="selTCBroComVendor_<?=$km;?>" class="input-text" style="width:110px;" id="selTCBroComVendor_<?=$km;?>" ></select></td>
											<script>$("#selTCBroComVendor_<?=$km;?>").html($("#selVendor").html());$("#selTCBroComVendor_<?=$km;?>").val('<?php echo $rows5['BRO_COMM_VENDOR']; ?>');</script>
										</tr>
										<tr id="hostTCtr4_<?=$km;?>">
											<td></td>
											<td>Nett Hire-age (USD) :</td>
											<td><input type="text"  name="txtNettHireargeAmt_<?=$km;?>" id="txtNettHireargeAmt_1_<?=$km;?>" style="width:110px;" class="input-text" value="<?php echo $rows5['NET_HIERAGE']; ?>" placeholder="0.00" readonly /></td>
											<td>CVE <span style="font-size:10px; font-style:italic;">(Per Month)</span> :</td>
											<td><input type="text"  name="txtTCHireargeCVE_<?=$km;?>" style="width:110px;" id="txtTCHireargeCVE_1_<?=$km;?>" class="input-text numeric" value="<?php echo $rows5['CVE_MONTH']; ?>" placeholder="0.00" onKeyUp="getFinalCalculation(1);" <?php if($invoicedval==1){?> readonly="true"<?php }?>/></td>
											<td>CVE (USD) :</td>
											<td><input type="text"  name="txtTCHireargeCVEAMT_<?=$km;?>" style="width:110px;" id="txtTCHireargeCVEAMT_1_<?=$km;?>" class="input-text" value="<?php echo $rows5['CVE_AMOUNT']; ?>" placeholder="0.00" onKeyUp="getFinalCalculation(1);"/></td>
											<td></td>
											<td></td>
											<td></td>
											<td></td>
										 </tr>
										 <tr id="hostTCtr5_<?=$km;?>" height="7">	
											<td colspan="11"></td>
										 </tr>
										 <tr id="hostTCtr6_<?=$km;?>" height="7">
											<td></td>
											<td colspan="10" style="border-top:2px solid #C5C5C5;"></td>
										 </tr>
								<?php }?>
							 <?php }else{$km = 1;?>	
										 <tr id="hostTCtr1_1">
											<td width="5%" valign="top"><a href="#tb1" onClick="removeHostTCtr(1);" ><i class="fa fa-times" style="color:red;"></i></a><input type="hidden" name="txtTCINSlaveRandomID_1" id="txtTCINSlaveRandomID_1" value=""></td>
											
											<td  width="10%">Date of Delivery&nbsp;:</td>
											<td  width="10%"><input type="text" name="txtTCDeliveryDate_1" id="txtTCDeliveryDate_1_1" class="input-text datetimepicker" style="width:110px;" value="<?=date("d-m-Y H:i", strtotime($obj->getFun46()));?>" placeholder="dd-mm-yy hh:mm" autocomplete="off">
											</td>
											<td  width="10%">Date of Re-Delivery&nbsp;:</td>
											<td  width="10%"><input type="text" name="txtTCReDeliveryDate_1" id="txtTCReDeliveryDate_1_1" class="input-text datetimepicker" style="width:110px;" value="<?=date("d-m-Y H:i", strtotime($obj->getFun47()));?>" placeholder="dd-mm-yy hh:mm" autocomplete="off">
											</td>
											<td>Total Voyage Days&nbsp;:</td>
											<td><input type="text"  name="txtTotalVoyageDays_1" style="width:110px;" id="txtTotalVoyageDays_1_1" class="input-text" autocomplete="off" readonly="true" value="" placeholder="0.00"/></td>
											<td>Daily Hire(USD/Day)&nbsp;:</td>
											<td><input type="text"  name="txtTCinDailyHire_1" style="width:110px;" id="txtTCinDailyHire_1_1" class="input-text numeric " autocomplete="off" value="<?php if(!empty($obj->getFun143())){ echo $obj->getFun54();}else{ echo $rows['TC_RATE'];} ?>" placeholder="0.00" onKeyUp="getFinalCalculation(1);" /></td>
											
											<td>Hireage (USD):</td>
											<td><input type="text"  name="txtHireargeAmt_1" id="txtHireargeAmt_1_1" style="width:110px;" class="input-text" value="" placeholder="0.00" readonly /></td>
										</tr>
										<tr id="hostTCtr2_1">
											<td></td>
											<td>Ballast Bonus (USD):</td>
											<td><input type="text" name="txtBallastBonus_1" id="txtBallastBonus_1_1" style="width:110px;" onKeyUp="getFinalCalculation(1);" class="input-text numeric" autocomplete="off" value="" placeholder="0.00"></td>
											<td>Gross Hire-age (USD):</td>
											<td><input type="text"  name="txtGrossHireargeAmt_1" id="txtGrossHireargeAmt_1_1" style="width:110px;" class="input-text numeric" value="" placeholder="0.00" readonly /></td>
											<td>Add Comm <span style="font-size:10px; font-style:italic;">(%)</span>:</td>
											<td><input type="text"  name="txtHireargePercent_1" style="width:110px;" id="txtHireargePercent_1_1" class="input-text numeric" value="<?php echo $rows['ADD_COMM'];?>" placeholder="%" onKeyUp="getFinalCalculation();"/></td>
											<td>Add Comm <span style="font-size:10px; font-style:italic;">(USD)</span>:</td>
											<td><input type="text"  name="txtHireargePercentAmt_1" style="width:110px;" id="txtHireargePercentAmt_1_1" class="input-text" value="" placeholder="0.00" readonly /></td>
											<td>Add Comm Vendor:</td>
											<td><select name="selTCAddCoVendor_1" class="input-text" style="width:110px;" id="selTCAddCoVendor_1" ></select></td>
											<script>$("#selTCAddCoVendor_1").html($("#selVendor").html());</script>
										 </tr>
										 <tr id="hostTCtr3_1">
											<td></td>
											<td></td>
											<td></td>
											<td></td>
											<td></td>
											<td>Owners side Brokerage commission:</td>
											<td><input type="text"  name="txtHireargeBroPercent_1" style="width:110px;" id="txtHireargeBroPercent_1_1" class="input-text numeric" value="" placeholder="%" onKeyUp="getFinalCalculation(1);"/></td>
											<td>Brokerage <span style="font-size:10px; font-style:italic;">(USD)</span>:</td>
											<td><input type="text"  name="txtHireargeBroPercentAmt_1" style="width:110px;" id="txtHireargeBroPercentAmt_1_1" class="input-text" value="" placeholder="0.00" readonly /></td>
											<td>Broker :</td>
											<td><select name="selTCBroComVendor_1" class="input-text" style="width:110px;" id="selTCBroComVendor_1" ></select></td>
											<script>$("#selTCBroComVendor_1").html($("#selVendor").html());</script>
										</tr>
										<tr id="hostTCtr4_1">
											<td></td>
											<td>Nett Hire-age (USD) :</td>
											<td><input type="text"  name="txtNettHireargeAmt_1" id="txtNettHireargeAmt_1_1" style="width:110px;" class="input-text" value="" placeholder="0.00" readonly /></td>
											<td>CVE <span style="font-size:10px; font-style:italic;">(Per Month)</span> :</td>
											<td><input type="text"  name="txtTCHireargeCVE_1" style="width:110px;" id="txtTCHireargeCVE_1_1" class="input-text numeric" value="" placeholder="0.00" onKeyUp="getFinalCalculation(1);"/></td>
											<td>CVE (USD) :</td>
											<td><input type="text"  name="txtTCHireargeCVEAMT_1" style="width:110px;" id="txtTCHireargeCVEAMT_1_1" class="input-text" value="" placeholder="0.00" onKeyUp="getFinalCalculation(1);"/></td>
											<td></td>
											<td></td>
											<td></td>
											<td></td>
										 </tr>
										 <tr id="hostTCtr5_1" height="7">	
											<td colspan="11"></td>
										 </tr>
										 <tr id="hostTCtr6_1" height="7">
											<td></td>
											<td colspan="10" style="border-top:2px solid #C5C5C5;"></td>
										 </tr>
							 <?php }?>  
								   </tbody>
								   <tfoot> 
									 <tr>
										 <td colspan="11"><button type="button" class="btn btn-warning btn-flat" onClick="AddNewTCDivToHost();">Add New Trip/Period</button>
											 <input type="hidden" name="txtTCHOSTID" id="txtTCHOSTID_1" value="<?=$km;?>"/> </td>
										
									 </tr>
								   </tfoot>
								</table>
								
								<div class="row" style="margin-top:20px;margin-bottom:20px;">
									 <div class="col-md-5">
										 <table class='tablesorter'>
											<tbody>
												<tr class="input-text">
												  <td>
													 <table width="100%">
														 <tr class="input-text">
															<td colspan="5"><strong>Delivery Bunkers</strong></td>
														 </tr>
														 <tr class="input-text">
														   <td>#</td>
														   <td>Bunker Grade</td>
														   <td>Qty(MT)</td>
														   <td>Bunker Date</td>
														   <td>Price USD/MT)</td>
														   <td>Amount(USD)</td>
														 </tr>
														 <tbody id="bunkerTCdelivery">
													<?php $sql6 = "select * from chartering_tc_estimate_slave3 where TC_SLAVE1ID='".$rows['TC_SLAVE1ID']."' and IDENTIFY='DEL'";
														  $result6 = mysql_query($sql6);$lm=0;
														  
														  if($num>0)
														  {
														  while($rows6 = mysql_fetch_assoc($result6))
														  {$lm++;?>
															<tr class="input-text" id="TCrow_del_<?=$lm?>">
															   <td><a href="#tbl1" onClick="removeTCDelBunker(<?=$lm?>);" ><i class="fa fa-times" style="color:red;"></i></a>&nbsp;&nbsp;</td>
															   <td><select name="selTCDelBunker_<?=$lm?>" class="input-text" style=" width:90px;" id="selTCDelBunker_<?=$lm?>"><?php $obj->getBunkerList();?></select></td>
															   <script>$("#selTCDelBunker_<?=$lm?>").val(<?=$rows6['BUNKERID'];?>);</script>
															   <td><input type="text" name="txtTCDelQty_<?=$lm?>" id="txtTCDelQty_<?=$lm?>" class="input-text numeric" style="width:85px;" value="<?=$rows6['BUNKER_QTY'];?>" placeholder="0.00" onKeyUp="getDelBunkerCalculation();" autocomplete="off" /></td>
															   <?php if(date("d-m-Y",strtotime($rows6['BUNKER_DATE']))!='01-01-1970'){$bunkerdate = date("d-m-Y",strtotime($rows6['BUNKER_DATE']));}else{$bunkerdate = '';}?>
															   <td><input type="text" name="txtTCDelBunDate_<?=$lm?>" id="txtTCDelBunDate_<?=$lm?>" class="input-text" style="width:85px;" value="<?=$bunkerdate;?>" placeholder="DD-MM-YYYY" autocomplete="off" /></td>
															   <td><input type="text" name="txtTCDelPrice_<?=$lm?>" id="txtTCDelPrice_<?=$lm?>" class="input-text numeric" style="width:85px;" value="<?=$rows6['BUNKER_PRICE'];?>" placeholder="0.00" onKeyUp="getDelBunkerCalculation();" autocomplete="off" /></td>
															   <td><input type="text" name="txtTCDelAmount_<?=$lm?>" id="txtTCDelAmount_1_<?=$lm?>" readonly class="input-text numeric" style="width:85px;background-color:#E1E1E1;" value="<?=$rows6['BUNKER_AMT'];?>" placeholder="0.00" autocomplete="off"/></td>
															</tr>
														<?php }}else{
														$sql6 = "select * from chartering_estimate_tc_slave4 where TCOUTID='".$id."' and IDENTITY='DEL'";
														$result6 = mysql_query($sql6);
														while($rows6 = mysql_fetch_assoc($result6))
														{$lm++;?>
														    <tr class="input-text" id="TCrow_del_<?=$lm?>">
															   <td><a href="#tbl1" onClick="removeTCDelBunker(<?=$lm?>);" ><i class="fa fa-times" style="color:red;"></i></a>&nbsp;&nbsp;</td>
															   <td><select name="selTCDelBunker_<?=$lm?>" class="input-text" style=" width:90px;" id="selTCDelBunker_<?=$lm?>"><?php $obj->getBunkerList();?></select></td>
															   <script>$("#selTCDelBunker_<?=$lm?>").val(<?=$rows6['BUNKERID'];?>);</script>
															   <td><input type="text" name="txtTCDelQty_<?=$lm?>" id="txtTCDelQty_<?=$lm?>" class="input-text numeric" style="width:85px;" value="<?=$rows6['QTY'];?>" placeholder="0.00" onKeyUp="getDelBunkerCalculation();" autocomplete="off" /></td>
															   <?php if(date("d-m-Y",strtotime($rows6['BUNKER_DATE']))!='01-01-1970'){$bunkerdate = date("d-m-Y",strtotime($rows6['BUNKER_DATE']));}else{$bunkerdate = '';}?>
															   <td><input type="text" name="txtTCDelBunDate_<?=$lm?>" id="txtTCDelBunDate_<?=$lm?>" class="input-text" style="width:85px;" value="<?=$bunkerdate;?>" placeholder="DD-MM-YYYY" autocomplete="off" /></td>
															   <td><input type="text" name="txtTCDelPrice_<?=$lm?>" id="txtTCDelPrice_<?=$lm?>" class="input-text numeric" style="width:85px;" value="<?=$rows6['PRICE'];?>" placeholder="0.00" onKeyUp="getDelBunkerCalculation();" autocomplete="off" /></td>
															   <td><input type="text" name="txtTCDelAmount_<?=$lm?>" id="txtTCDelAmount_1_<?=$lm?>" readonly class="input-text numeric" style="width:85px;background-color:#E1E1E1;" value="<?=$rows6['AMOUNT'];?>" placeholder="0.00" autocomplete="off"/></td>
															</tr>
													<?php }}?>
														
														</tbody>
														<tbody>		
														<tr class="input-text">
															<td colspan="2"><button type="button" onClick="AddNewTCDel();">Add Bunkers</button><input type="hidden" name="txtTCDELID" id="txtTCDELID" value="<?=$lm?>"/></td>
															<td ></td>
															<td ></td>
															<td ></td>
															<td ><input type="text" name="txtTotalTCDelAmount" id="txtTotalTCDelAmount" readonly class="input-text numeric" style="width:85px;background-color:#E1E1E1;" value="" placeholder="0.00" autocomplete="off"/></td>
															
														</tr>
													 </table>
												  </td>
												</tr>
												<tr class="input-text">
												  <td>
													 <table width="100%">
														<tr class="input-text">
															<td colspan="5"><strong>Re-Delivery Bunkers</strong></td>
														</tr>
														<tr class="input-text">
														   <td>#</td>
														   <td>Bunker Grade</td>
														   <td>Qty(MT)</td>
														   <td>Bunker Date</td>
														   <td>Price USD/MT)</td>
														   <td>Amount(USD)</td>
														</tr>
														<tbody id="bunkerTCRedelivery">
													<?php $sql6 = "select * from chartering_tc_estimate_slave3 where TC_SLAVE1ID='".$rows['TC_SLAVE1ID']."' and IDENTIFY='REDEL'";
														  $result6 = mysql_query($sql6);$lm=0;
														  if($num>0)
														  {
														  while($rows6 = mysql_fetch_assoc($result6))
														  {$lm++;?>
															<tr class="input-text" id="TCrow_Redel_<?=$lm?>">
															   <td><a href="#tbl1" onClick="removeTCReDelBunker(<?=$lm?>);" ><i class="fa fa-times" style="color:red;"></i></a>&nbsp;&nbsp;</td>
															   <td><select name="selTCReDelBunker_<?=$lm?>" class="input-text" style=" width:90px;" id="selTCReDelBunker_<?=$lm?>"><?php $obj->getBunkerList();?></select></td>
															   <script>$("#selTCReDelBunker_<?=$lm?>").val(<?=$rows6['BUNKERID'];?>);</script>
															   <td><input type="text" name="txtTCReDelQty_<?=$lm?>" id="txtTCReDelQty_<?=$lm?>" class="input-text numeric" style="width:85px;" value="<?=$rows6['BUNKER_QTY'];?>" placeholder="0.00" onKeyUp="getReDelBunkerCalculation();" autocomplete="off" /></td>
															   <?php if(date("d-m-Y",strtotime($rows6['BUNKER_DATE']))!='01-01-1970'){$bunkerdate = date("d-m-Y",strtotime($rows6['BUNKER_DATE']));}else{$bunkerdate = '';}?>
															   <td><input type="text" name="txtTCReDelBunDate_<?=$lm?>" id="txtTCReDelBunDate_<?=$lm?>" class="input-text" style="width:85px;" value="<?=$bunkerdate?>" placeholder="DD-MM-YYYY" autocomplete="off" /></td>
															   <td><input type="text" name="txtTCReDelPrice_<?=$lm?>" id="txtTCReDelPrice_<?=$lm?>" class="input-text numeric" style="width:85px;" value="<?=$rows6['BUNKER_PRICE'];?>" placeholder="0.00" onKeyUp="getReDelBunkerCalculation();" autocomplete="off" /></td>
															   <td><input type="text" name="txtTCReDelAmount_<?=$lm?>" id="txtTCReDelAmount_1_<?=$lm?>" readonly class="input-text numeric" style="width:85px;background-color:#E1E1E1;" value="<?=$rows6['BUNKER_AMT'];?>" placeholder="0.00" autocomplete="off"/></td>
															</tr>
														<?php }}else{
														$sql6 = "select * from chartering_estimate_tc_slave4 where TCOUTID='".$id."' and IDENTITY='REDEL'";
														$result6 = mysql_query($sql6);
														while($rows6 = mysql_fetch_assoc($result6))
														{$lm++;?>
														    <tr class="input-text" id="TCrow_Redel_<?=$lm?>">
															   <td><a href="#tbl1" onClick="removeTCReDelBunker(<?=$lm?>);" ><i class="fa fa-times" style="color:red;"></i></a>&nbsp;&nbsp;</td>
															   <td><select name="selTCReDelBunker_<?=$lm?>" class="input-text" style=" width:90px;" id="selTCReDelBunker_<?=$lm?>"><?php $obj->getBunkerList();?></select></td>
															   <script>$("#selTCReDelBunker_<?=$lm?>").val(<?=$rows6['BUNKERID'];?>);</script>
															   <td><input type="text" name="txtTCReDelQty_<?=$lm?>" id="txtTCReDelQty_<?=$lm?>" class="input-text numeric" style="width:85px;" value="<?=$rows6['QTY'];?>" placeholder="0.00" onKeyUp="getReDelBunkerCalculation();" autocomplete="off" /></td>
															   <?php if(date("d-m-Y",strtotime($rows6['BUNKER_DATE']))!='01-01-1970'){$bunkerdate = date("d-m-Y",strtotime($rows6['BUNKER_DATE']));}else{$bunkerdate = '';}?>
															   <td><input type="text" name="txtTCReDelBunDate_<?=$lm?>" id="txtTCReDelBunDate_<?=$lm?>" class="input-text" style="width:85px;" value="<?=$bunkerdate?>" placeholder="DD-MM-YYYY" autocomplete="off" /></td>
															   <td><input type="text" name="txtTCReDelPrice_<?=$lm?>" id="txtTCReDelPrice_<?=$lm?>" class="input-text numeric" style="width:85px;" value="<?=$rows6['PRICE'];?>" placeholder="0.00" onKeyUp="getReDelBunkerCalculation();" autocomplete="off" /></td>
															   <td><input type="text" name="txtTCReDelAmount_<?=$lm?>" id="txtTCReDelAmount_1_<?=$lm?>" readonly class="input-text numeric" style="width:85px;background-color:#E1E1E1;" value="<?=$rows6['AMOUNT'];?>" placeholder="0.00" autocomplete="off"/></td>
															</tr>
													<?php }}?>
														</tbody>
														<tbody>		
														<tr class="input-text">
															<td colspan="2"><button type="button" onClick="AddNewTCReDel();">Add Bunkers</button><input type="hidden" name="txtTCREDELID" id="txtTCREDELID" value="<?=$lm?>"/></td>
															<td ></td>
															<td ></td>
															<td ></td>
															<td ><input type="text" name="txtTotalTCReDelAmount" id="txtTotalTCReDelAmount" readonly class="input-text numeric" style="width:85px;background-color:#E1E1E1;" value="" placeholder="0.00" autocomplete="off"/></td>
														</tr>
														</tbody>
													 </table>
												  
												  </td>
												</tr>
											</tbody>
										</table>
									 </div><!-- /.col -->
									 <div class="col-md-7">
										<table width="100%">
										<tr class="input-text">
											<td colspan="5"><strong>Off Hire</strong></td>
										 </tr>
										<tr class="input-text">
										   <td></th>
										   <td>Off Hire Reason</td>
										   <td>Off Hire From</td>
										   <td>Off Hire To</td>
										   <td>Off Hire Days</td>
										   <td>Off Hire Rate/Day(USD)</td>
										   <td>Off Hire(USD)</td>
										   
										</tr>
										<tbody id="TCoffhirebody">
									<?php $sql7 = "select * from chartering_tc_estimate_slave4 where TC_SLAVE1ID='".$rows['TC_SLAVE1ID']."'";
										  $result7 = mysql_query($sql7);$lm=0;
										  while($rows7 = mysql_fetch_assoc($result7))
										  {$lm++;
										  
											$sql_random = "SELECT * from invoice_hiretc_slave4 where COMID='".$comid."' and RANDOMID='".$rows7['RANDOMID']."' and (select STATUS from invoice_hiretc_master where invoice_hiretc_master.INVOICEID=invoice_hiretc_slave4.INVOICEID)=1";
											$res_random 	= mysql_query($sql_random) or die($sql_random);
											$rec_random 	= mysql_num_rows($res_random);
											if($rec_random>0){$invoicedval = 1;}else{$invoicedval = 0;}
										  ?>
										<tr class="input-text" id="TCrow_offhire_<?=$lm?>">
											<td><?php if($invoicedval==0){?><a href="#tb1" onClick="removeTCOffHire(<?=$lm?>);" ><i class="fa fa-times" style="color:red;"></i></a><?php }?></td>
											<td valign="top"><textarea class="input-text areasize" name="txtTCOffHireReason_<?=$lm?>" style="width:120px;" id="txtTCOffHireReason_<?=$lm?>" rows="3" placeholder="Off Hire Reason..." <?php if($invoicedval==1){?>readonly="true"<?php }?>><?=$rows7['OFFHIRE_REASON']?></textarea><input type="hidden" name="txtTCOffHireRandomID_<?=$lm?>" id="txtTCOffHireRandomID_<?=$lm?>" value="<?=$rows7['RANDOMID'];?>"/></td>
									<?php if(date("d-m-Y", strtotime($rows7['OFF_HIRE_FROM']))!='01-01-1970'){$fromdate = date("d-m-Y H:i", strtotime($rows7['OFF_HIRE_FROM']));}else{$fromdate = '';}?>
									<?php if(date("d-m-Y", strtotime($rows7['OFF_HIRE_TO']))!='01-01-1970'){$todate = date("d-m-Y H:i", strtotime($rows7['OFF_HIRE_TO']));}else{$todate = '';}?>
											<td valign="top"><input autocomplete="off" type="text" name="txtTCOffHireFrom_<?=$lm?>" id="txtTCOffHireFrom_<?=$lm?>" class="input-text <?php if($invoicedval==0){?>datetimepicker<?php }?>" value="<?=$fromdate?>" style="width:100px;" placeholder="dd-mm-yyyy HH:MM" <?php if($invoicedval==1){?>readonly="true"<?php }?> /></td>
											<td valign="top"><input autocomplete="off" type="text" name="txtTCOffHireTo_<?=$lm?>" id="txtTCOffHireTo_<?=$lm?>" class="input-text <?php if($invoicedval==0){?>datetimepicker<?php }?>" value="<?=$todate?>" style="width:100px;" placeholder="dd-mm-yyyy HH:MM" <?php if($invoicedval==1){?>readonly="true"<?php }?>/></td>
											<td valign="top"><input autocomplete="off" type="text" name="txtTCOffHireDays_<?=$lm?>" id="txtTCOffHireDays_<?=$lm?>" class="input-text" placeholder="Off Hire Days" style="width:90px;background-color:#EAEAEA;" readonly value="<?=$rows7['OFF_HIRE_DAYS']?>" ></td>
											<td valign="top"><input autocomplete="off" type="text" name="txtTCOffHireRate_<?=$lm?>" id="txtTCOffHireRate_1_<?=$lm?>" class="input-text" placeholder="Rate/Day(USD)" style="width:100px;" onKeyUp="getFinalCalculation(1);" value="<?=$rows7['OFF_HIRE_RATE']?>" ></td>
											<td valign="top"><input autocomplete="off" type="text" name="txtTCOffHireAmt_<?=$lm?>" id="txtTCOffHireAmt_<?=$lm?>" class="input-text" placeholder="Off Hire(USD)" style="width:90px;background-color:#EAEAEA;" readonly value="<?=$rows7['OF_HIRE_AMT']?>" ></td>
										   
										</tr>
										<tr id="TCrow_offhireBunker_<?=$lm?>">
										<td></td>
										<td colspan="6">
											<table width="100%" class='tablesorter'>
											  <tr>
												<td></td>
												<td>Bunker Grade</td>
												<td>Qty(MT)</td>
												<td>Price(USD)</td>
												<td>Amount(USD)</td>
												<td>On Owner's Account</td>
											  </tr>
											  <tbody id="TCConbunkerTBody_<?=$lm?>">
										<?php $sql8 = "select * from chartering_tc_estimate_slave5 where TC_SLAVE1ID='".$rows['TC_SLAVE1ID']."' and TC_SLAVE4ID='".$rows7['TC_SLAVE4ID']."'";
											  $result8 = mysql_query($sql8);$mm=0;
											  while($rows8 = mysql_fetch_assoc($result8))
											  {$mm++;?>
											  <tr id="DivTCConBunkeractual_<?=$lm?>_<?=$mm?>">
												<td><?php if($invoicedval==0){?><a href="#tb1'" onClick="removeTCConBunkerRows(<?=$lm?>,<?=$mm?>);" ><i class="fa fa-times" style="color:red;"></i></a><?php }?></td>
												<td><select name="selTCConBunker_<?=$lm?>_<?=$mm?>" id="selTCConBunker_<?=$lm?>_<?=$mm?>" style="width:90px;" class="input-text"><?php $obj->getBunkerList();?></select></td>
												<script>$("#selTCConBunker_<?=$lm?>_<?=$mm?>").val(<?=$rows8['BUNKERID'];?>);</script>
												<td><input type="text" name="txtTCConBunkerQty_<?=$lm?>_<?=$mm?>" id="txtTCConBunkerQty_1_<?=$lm?>_<?=$mm?>" style="width:90px;" class="input-text numeric" onKeyUp="getFinalCalculation(1);" placeholder="0.00" autocomplete="off" value="<?=$rows8['BUNKER_QTY']?>" <?php if($invoicedval==1){?> readonly="true"<?php }?>/></td>
												<td><input type="text" name="txtTCConBunkerPrice_<?=$lm?>_<?=$mm?>" id="txtTCConBunkerPrice_1_<?=$lm?>_<?=$mm?>" style="width:90px;" class="input-text numeric" onKeyUp="getFinalCalculation(1);" placeholder="0.00" autocomplete="off" value="<?=$rows8['BUNKER_PRICE']?>" <?php if($invoicedval==1){?> readonly="true"<?php }?>/></td>
												<td><input type="text" name="txtTCConBunkerAmt_<?=$lm?>_<?=$mm?>" id="txtTCConBunkerAmt_<?=$lm?>_<?=$mm?>" style="width:90px;background-color:#EAEAEA;" class="input-text"  placeholder="0.00" readonly autocomplete="off" value="<?=$rows8['IS_OWNER_ACCOUNT']?>"/></td>
												<td><input name="ChkOFFHireCal_<?=$lm?>_<?=$mm?>" class="checkbox" id="ChkOFFHireCal_<?=$lm?>_<?=$mm?>" type="checkbox" value="1" <?php if($rows8['IS_OWNER_ACCOUNT']==1){echo 'checked';}?>/></td>
											  </tr>
										<?php }?>
										   
											</tbody>
											<?php if($invoicedval==0){?>
											  <tr>
												<td colspan="6"><button type="button" onClick="addTCConBunkerRow(<?=$lm?>)">Add Bunkers</button></td>
											  </tr>
											<?php }?> 
											<input type="hidden" name="txtTCConBunkerCount_<?=$lm?>" id="txtTCConBunkerCount_<?=$lm?>" value="<?=$mm?>"/>
											</table>
										 </td>
									  </tr>
									<?php }?>
										</tbody>
										<tbody>		
											<tr class="input-text">
												<td ><button type="button" onClick="AddNewTCOffHire();">Add Off-Hire</button><input type="hidden" name="txtTCOFFID" id="txtTCOFFID" value="<?=$lm?>"/></td>
												<td colspan="7"></td>
												
											</tr>
										</tbody>
										</table>
									 </div><!-- /.col -->
								</div>
								
								<table class='tablesorter'>
									<tbody>
										<tr>
											<td>CVE Off Hire <span style="font-size:10px; font-style:italic;">(Per Month)</span></td>
											<td>:</td>
											<td><input type="text"  name="txtTCOffHireCVE" style="width:90px;" id="txtTCOffHireCVE_1" class="input-text numeric" value="<?php echo $rows['TC_CVE_MONTH_OFFHIRE']; ?>" placeholder="0.00" onKeyUp="getFinalCalculation();"/></td>
											<td><input type="text"  name="txtTCOffHireCVEAMT" style="width:90px;" id="txtTCOffHireCVEAMT_1" class="input-text" value="<?php echo $rows['TC_CVE_AMOUNT_OFFHIRE']; ?>" placeholder="0.00" readonly="true"/></td>
											
											<td>Bunker on Owner's Account</td>
											<td>:</td>
											<td><input type="text"  name="txtTCBunkerOnOwnerAmt" style="width:90px;" id="txtTCBunkerOnOwnerAmt_1" class="input-text" value="<?php echo $rows['TC_BUNKERS_ON_OWNER']; ?>" placeholder="0.00" readonly /></td>
											
											<td><strong>Off Hire</strong></td>
											<td><strong>:</strong></td>
											<td><input type="text"  name="txtTCLessOffHire" style="width:90px;" id="txtTCLessOffHire_1" class="input-text" value="<?php echo $rows['TC_OFF_HIRE']; ?>" placeholder="0.00" readonly /></td>
											<td></td>
										
											<td></td>
											<td></td>
											<td></td>
											<td></td>
										</tr>


										<tr>
											<td>ILOHC </td>
											<td>:</td>
											<td><input type="text"  name="txtTcILOHC" style="width:90px;" id="txtTcILOHC_1" class="input-text numeric" value="<?php echo $rows['TXT_ILOHC_TC']; ?>" placeholder="0.00" onKeyUp="getFinalCalculation();"/></td>
											<td></td>
											
											<td></td>
											<td></td>
											<td></td>
											
											<td></td>
											<td></td>
											<td></td>
											<td></td>
										
											<td></td>
											<td></td>
											<td></td>
											<td></td>
										</tr>


										
										<tr>
											
										
											<td><strong>Final Hire-age</strong></td>
											<td><strong>:</strong></td>
											<td><input type="text"  name="txtFinalHireargeAmt" style="width:90px;" id="txtFinalHireargeAmt_1" class="input-text" value="<?php echo $rows['TC_FINAL_HIERAGE']; ?>" placeholder="0.00" readonly /></td>
											<td><select name="selTCVendor" class="input-text" style="width:120px;" id="selTCVendor" ></select></td>
											<script>$("#selTCVendor").html($("#selVendor").html());$("#selTCVendor").val('<?php echo $rows['TC_FINAL_HIERAGE_VENDOR']; ?>');</script>
											<td></td>
											<td></td>
											<td></td>
											<td></td>
											
											<td></td>
											<td></td>
											<td></td>
											
											<td></td>
											<td></td>
											<td></td>
											<td></td>
										</tr>
										
										</tbody>
									</table>                 
									 <div class="row">
										 <div class="col-xs-6" style="text-align:left;">
												   
										 </div><!-- /.col -->
										 <div class="col-xs-6" style="text-align:right;">
											 <button type="button" class="btn btn-primary btn-flat" data-dismiss="modal">Close</button>       
										 </div><!-- /.col -->
									</div>
								</div>
							 </div>
						</div>
					</div>
                
                        <div style="text-align:center;">
                        <button type="submit" class="btn btn-primary btn-flat" onClick="return getValidate();">Submit</button>
                        <input autocomplete="off" type="hidden" name="action" id="action" value="submit" />
                        <input type="hidden" name="vesselrec" id="vesselrec" class="input-text" value="" /></div>
                        <!-- some hidden fields start -->
                        <input type="hidden" name="selDurFixPeriod" id="selDurFixPeriod"/>
                        <input type="hidden" name="txtCVEmonth" id="txtCVEmonth" value="<?php echo $obj->getFun63();?>"/>
                        <input type="hidden" name="txtBrokCommPayableBy" id="txtBrokCommPayableBy"/>
                         </div>
                    
					
					
				<!-- some hidden fields ends -->
                </form>
            </aside><!-- /.right-side -->
			
        </div><!-- ./wrapper -->
<?php $display->footer(); ?>
<link href="../../css/sort.css" rel="stylesheet" type="text/css" />
<link href="../../css/jquery.alerts.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>
<link type='text/css' href='../../css/basic.css' rel='stylesheet' media='screen' />
<script src="../../js/chosen.jquery.js" type="text/javascript"></script>
<link href="../../css/datetimepicker/bootstrap-datetimepicker.css" rel="stylesheet" type="text/css" />
<script src="../../js/plugins/datetimepicker/bootstrap-datetimepicker.min.js" type="text/javascript"></script>
<link type="text/css" href="../../css/chosen.css" rel="stylesheet" />
<script type="text/javascript">

$(document).ready(function(){

// pasteCharteing();
let numRowsTcExpense = <?= $num5?>;

// console.log(numRowsTcExpense);
getFinalCalculation(1);
var periodVess = 0;
<?php 

if(!empty($obj->getFun143())){?>

	var periodVess = 1;
	<?php
}?>
if(numRowsTcExpense==0){

	if(periodVess==1){

	loadPeriodDetails();
	}


}


$('.sidebar-toggle').click();
$(".areasize").autosize({append: "\n"});
$("#selVName").val(<?php echo $obj->getFun3();?>);
$("#selCPType").val(<?php echo $obj->getFun10();?>);
$("#selCharterers").val('<?php echo $obj->getFun11();?>');
$("#selCharOperation").val('<?php echo $obj->getFun12();?>');
$("#selLawArbit").val(<?php echo $obj->getFun13();?>);
$("#selDurFixPeriod").val(<?php echo $obj->getFun45();?>);
$("#txtBrokCommPayableBy").val('<?php echo $obj->getFun67();?>');
$("#txtBankingDetails").val(<?php echo $obj->getFun70();?>);

	
	$('#txtDelLtTimeGMT,#txtReDelLtTimeGMT').datetimepicker({
		format: 'dd-mm-yyyy hh:ii',
		todayBtn: true,
		minuteStep: 1,
		autoclose:true
	});
	
	$('[id^=txtOffHireFrom_],[id^=txtOffHireTo_],#txtDeldate,#txtReDeldate').datetimepicker({
		format: 'dd-mm-yyyy hh:ii',
		autoclose: true,
		todayBtn: true,
		minuteStep: 1
		}).on('changeDate', function(){
		getFinalCalculation();
	});
	
	var numoff = $("#txtTCHOSTID_1").val();
	for(var i =1;i <=numoff;i++)
	{
		$('#txtTCDeliveryDate_1_'+i+',#txtTCReDeliveryDate_1_'+i).datetimepicker({
			format: 'dd-mm-yyyy hh:ii',
			autoclose: true,
		
			minuteStep: 1
			}).on('changeDate', function(){
				var idd = $(this).attr('id');
				var iddd = idd.split("_");
				getFinalCalculation(1);
		});
	}
	
	var numoff = $("#txtTCOFFID").val();
	for(var i =1;i <=numoff;i++)
	{
		$('#txtTCOffHireFrom_'+i+',#txtTCOffHireTo_'+i).datetimepicker({
			format: 'dd-mm-yyyy hh:ii',
			autoclose: true,
			todayBtn: true,
			minuteStep: 1
			}).on('changeDate', function(){
				var idd = $(this).attr('id');
				var iddd = idd.split("_");
				getFinalCalculation();
		});
	}
		
	$('#tripspan_1,#tripspan_2,#tripspan_3,#periodspan_1,#periodspan_2,#periodspan_3,#noOfTripspan_1,#noOfTripspan_2,#noOfTripspan_3').hide();
		
	if($("#selDurFixPeriod").val() == 1)
	{
		$('#tripspan_1,#tripspan_2,#tripspan_3').show();
		$('#periodspan_1,periodspan_2,#periodspan_3,#noOfTripspan_1,#noOfTripspan_2,#noOfTripspan_3').hide();
	}
	else if($("#selDurFixPeriod").val() == 2)
	{
		$('#periodspan_1,#periodspan_2,#periodspan_3,#noOfTripspan_1,#noOfTripspan_2,#noOfTripspan_3').show();
		$('#tripspan_1,#tripspan_2,#tripspan_3').hide();
	}
	else
	{
		$('#tripspan_1,#tripspan_2,#tripspan_3,#periodspan_1,#periodspan_2,#periodspan_3,#noOfTripspan_1,#noOfTripspan_2,#noOfTripspan_3').hide();
	}
	
	if($("#txtDailyGrossHireUSD").val()!="")
	{
		var addComm 		= $("#txtAddCommPerct").val();
		var exchangeRate	= $("#txtExchangeRate").val();
		var dailyGrossHire  = $("#txtDailyGrossHireUSD").val();
		var addComm1		= ((addComm*dailyGrossHire*exchangeRate)/100);
		$("#txtAddComm1").val(parseFloat(addComm1).toFixed(2));	
		
		var brokerComm		= $("#txtChartererAcc").val();
		var calBrokerComm	= ((brokerComm*dailyGrossHire)/100);
		$("#txtBrokerComm").val(parseFloat(calBrokerComm).toFixed(2));	
	}
	
	if($("#txtBrokCommPayableBy").val() == 'Charterer')
	{
		var exchangeRate	 = $("#txtExchangeRate").val();
		var dailyGrossHire1  = $("#txtDailyGrossHireUSD").val();
		var dailyGrossHire2  = (exchangeRate*dailyGrossHire1);
		var addComm2		 = $("#txtAddComm1").val();
		var brokerComm1		 = $("#txtBrokerComm").val();
		var cal1			 = parseFloat(addComm2) + parseFloat(brokerComm1);
	  	var cal2			 = parseFloat(dailyGrossHire2) - parseFloat(cal1);
		if(isNaN(cal2)){cal2 = 0.00;}
		$("#txtNettHire").val(parseFloat(cal2).toFixed(2));
	}
	
	if($("#txtBrokCommPayableBy").val() == 'Operator')
	{
		var exchangeRate	 = $("#txtExchangeRate").val();
		var dailyGrossHire1  = $("#txtDailyGrossHireUSD").val();
		var dailyGrossHire2  = (exchangeRate*dailyGrossHire1);
		var addComm3		 = $("#txtAddComm1").val();
		var cal1			 = parseFloat(dailyGrossHire2) - parseFloat(addComm3);
		if(isNaN(cal1)){cal1 = 0.00;}
		$("#txtNettHire").val(parseFloat(cal1).toFixed(2));
	}
	
	
	
	$("#txtVoyageEarnings, #txtDeliveryHFO, #txtDeliveryMGO, #txtPriceDelHFO, #txtPriceDelMGO, #txtSupercargoMeals, #txtHoldCleanInterm, #txtILOHCtcFix, #txtAddComm, #txtBrokerCommTCfix, #txtTCdays, #txtOffHireDays, #txtUtilisationDays, #txtOffHireRate, #txtNoOfTrips, #txtHireFixPerUSD, #txtOtherIncome, #txtDelHFOmt, #txtReDelHFOmt, #txtDelHFOusdmt, #txtReDelHFOusdmt, #txtDelMGOmt, #txtReDelMGOmt, #txtDelMGOusdmt, #txtReDelMGOusdmt, [id^=txtOtherIncome_1_], [id^=txtOtherExpense_], [id^=txtOffHireRate_], #txtTCPerDay, #txtAddComm").numeric();
	
	$('[id^=ChkAddToTTL_]').on('ifChecked', function () { 
	   var idd = $(this).attr('id');
	   var iddd = idd.split("_");
	   $("#chkVal_1_"+iddd[1]).val(1);
	   getFinalCalculation();
	});
	 
	$('[id^=ChkAddToTTL_]').on('ifUnchecked', function () { 
	   var idd = $(this).attr('id');
	   var iddd = idd.split("_");
	   $("#chkVal_1_"+iddd[1]).val('');
	   getFinalCalculation();
	});
	
	$("#txtDate,#txtCPdate,[id^=txtDelBunDate_],[id^=txtReDelBunDate_],#txtTCCPDate,[id^=txtTCDelBunDate_],[id^=txtTCReDelBunDate_]").datepicker({
		format: 'dd-mm-yyyy',
		autoclose: true
	});
	
	
	$("#frm1").validate({
		rules: {
			selVName:"required",
			txtTCNo:"required"
			},
		messages: {
			selVName:"*",
			},
	submitHandler: function(form)  {
		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;}
				});
		}
	});
	getCurrencySpan();
	
	getDailyGrossHire();
	getDelBunkerCalculation();
	getReDelBunkerCalculation();
	getFinalCalculation();
});

function getValue()
{
	
}


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

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) {
				
					$('#txtVType').val(array['type']);
					$('#txtDWTS').val(array['dwtsum']);
					$('#txtDWTT').val(array['dwttrop']);
					$('#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']);
					
					$('#txtBuildYard').val(array['BuildYard']);
					$('#txtYearBuild').val(array['year']);
					$('#txtFlag1').val(array['flag']);
					$('#txtPortOfRegis').val(array['txtPortOfRegis']);
					$('#txtIMOnum').val(array['txtIMOnum']);
					$('#txtOwnerPandI').val(array['txtOwnerPandI']);
					$('#txtCallSign').val(array['txtCallSign']);
					$('#txtInmarsatTel').val(array['txtInmarsatTel']);
					$('#txtInmarsatEmail').val(array['txtInmarsatEmail']);
					$('#txtLOA1').val(array['loa']);
					$('#txtBreadth').val(array['beam']);
					$('#txtSummerDWT').val(array['dwtsum']);
					$('#txtSummerDraft').val(array['txtSummerDraft']);
					$('#txtTPC1').val(array['tpc']);
					$('#txtClassID').val(array['txtClassID']);
					$('#txtLastSpSurvey').val(array['txtLastSpSurvey']);
					$('#txtLastDD').val(array['txtLastDD']);
					$('#txtGrossTonnage').val(array['gnrt']);
					$('#txtNetTonnage').val(array['txtNetTonnage']);
					$('#txtSuezGRT').val(array['txtSuezGRT']);
					$('#txtSuezNRT').val(array['txtSuezNRT']);
					$('#txtPanamaNRT').val(array['PanamaNRT']);
					$('#txtGrainCap').val(array['txtGrainCap']);
					$('#txtBaleCap').val(array['txtBaleCap']);
					$('#txtCranes').val(array['txtCranes']);
					$('#txtGrabs').val(array['txtGrabs']);
					$('#txtKeelTopMast').val(array['KeelTopMast']);
					$('#txtWaterlineTopMast').val(array['WaterlineTopMast']);
					$('#txtCTankCap').val(array['CTankCap']);
					$('#txtCTankNoOfGrades').val(array['CTankNoOfGrades']);
					$('#txtCPumpCap').val(array['CPumpCap']);
					$('#txtCTotalSBTCap').val(array['CTotalSBTCap']);
				});
			});  
	  }
	  else
	  {
		  $('#txtVType,#txtDWTS,#txtDWTT,#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,#txtBuildYard,#txtYearBuild,#txtFlag1,#txtPortOfRegis,#txtIMOnum,#txtOwnerPandI,#txtCallSign,#txtInmarsatTel,#txtInmarsatEmail,#txtLOA1,#txtBreadth,#txtSummerDWT,#txtSummerDraft,#txtTPC1,#txtClassID,#txtLastSpSurvey,#txtLastDD,#txtGrossTonnage,#txtNetTonnage,#txtSuezGRT,#txtSuezNRT,#txtPanamaNRT,#txtGrainCap,#txtBaleCap,#txtCranes,#txtGrabs,#txtKeelTopMast,#txtWaterlineTopMast').val("");
	  }
	 getFinalCalculation();
}


function getValidate()
{
	getFinalCalculation();
}


function getChartererData()
{
	if($("#selCharOperation").val()!='')
	{
		$.post("options.php?id=59",{selCharOperation:""+$("#selCharOperation").val()+""}, function(data) 
			{
					$('#txtAddress').val(data);

			});
	}
	else
	{
		$('#txtAddress').val('');
	}
}

function getTimeDiff(date2,date1)
{	
	if(date1 != '' &&  date2 != '')
	{
		end_actual_time  	 =  getDateWithSpecificFormat(date2);
		start_actual_time    =  getDateWithSpecificFormat(date1);
		
		start_actual_time 	= new Date(start_actual_time);
		end_actual_time 	= new Date(end_actual_time);
	
		var diff 			= end_actual_time - start_actual_time;
		var days			= (diff) / 86400000;
		return days.toFixed(5);	
	}
}

function getDateWithSpecificFormat(sep)
{
	var dateSplit1  = sep.split(' ');
	var dateSplit   = dateSplit1[0].split('-');
	var currentDate = dateSplit[2] + '-' + dateSplit[1] + '-' + dateSplit[0]+' '+dateSplit1[1];
	return currentDate;
}


function getFinalCalculation(rval)
{	
	rval=1;
	var txtDailyGrossHireUSD      = parseFloat($("#txtDailyGrossHireUSD_"+rval).val());if(isNaN(txtDailyGrossHireUSD)){txtDailyGrossHireUSD = 0.00;}
	var txtExchangeRate           = parseFloat($("#txtExchangeRate_"+rval).val());if(isNaN(txtExchangeRate)){txtExchangeRate = 0.00;}
	$("#txtDailyGrossHireUSD1_"+rval).val(parseFloat(parseFloat(txtDailyGrossHireUSD)*parseFloat(txtExchangeRate)).toFixed(2));
	
	var txtBallastBonusAMT = parseFloat($("#txtBallastBonusAMT_"+rval).val());if(isNaN(txtBallastBonusAMT)){txtBallastBonusAMT = 0;}
	txtDailyGrossHireUSD = parseFloat(txtDailyGrossHireUSD) + parseFloat(txtBallastBonusAMT);
    
	var txtDELREDELID = $("#txtDELREDELID_"+rval).val();
	var totaltcdays = 0;

	// console.log('asdlkn',txtDELREDELID);
	for(var i =1;i <=txtDELREDELID;i++)
	{
		var tcdays = parseFloat(getTimeDiff($("#txtReDeldate_"+rval+"_"+i).val(),$("#txtDeldate_"+rval+"_"+i).val()));if(isNaN(tcdays)){tcdays = 0.00;}
		totaltcdays = parseFloat(totaltcdays) + parseFloat(tcdays);
		$("#txtTCdays_"+rval+"_"+i).val(tcdays.toFixed(4));
		var txtHireRate      = parseFloat($("#txtHireRate_"+rval+"_"+i).val());if(isNaN(txtHireRate)){txtHireRate = 0.00;}
		var txtHireAmt       =   parseFloat(parseFloat(txtHireRate)*parseFloat(tcdays));if(isNaN(txtHireAmt)){txtHireAmt = 0.00;}

		// console.log('ceck',txtHireAmt);
		$('#txtHireAmt_'+rval+'_'+i).val(parseFloat(txtHireAmt).toFixed(2));
	}
	
	var txtDELID = $("#txtDELID_"+rval).val();
	for(var i =1;i <=txtDELID;i++)
	{
		var txtDelQty      = parseFloat($("#txtDelQty_"+rval+"_"+i).val());if(isNaN(txtDelQty)){txtDelQty = 0.00;}
		var txtDelPrice    = parseFloat($("#txtDelPrice_"+rval+"_"+i).val());if(isNaN(txtDelPrice)){txtDelPrice = 0.00;}
		var amount          =   parseFloat(parseFloat(txtDelQty)*parseFloat(txtDelPrice));if(isNaN(amount)){amount = 0.00;}
		$('#txtDelAmount_'+rval+'_'+i).val(parseFloat(amount).toFixed(2));
	}
	$("#txtTotalDelAmount_"+rval).val($('[id^=txtDelAmount_'+rval+'_]').sum());
	
    var txtREDELID = $("#txtREDELID_"+rval).val();
	for(var i =1;i <=txtREDELID;i++)
	{
		var txtReDelQty      = parseFloat($("#txtReDelQty_"+rval+"_"+i).val());if(isNaN(txtDelQty)){txtDelQty = 0.00;}
		var txtReDelPrice    = parseFloat($("#txtReDelPrice_"+rval+"_"+i).val());if(isNaN(txtDelPrice)){txtDelPrice = 0.00;}
		var amount          =   parseFloat(parseFloat(txtReDelQty)*parseFloat(txtReDelPrice));if(isNaN(amount)){amount = 0.00;}
		$('#txtReDelAmount_'+rval+'_'+i).val(parseFloat(amount).toFixed(2));
	}
	$("#txtTotalReDelAmount_"+rval).val($('[id^=txtReDelAmount_'+rval+'_]').sum());
	
	var delbunker          = $('#txtTotalDelAmount_'+rval).sum();
	var redelbunker        = $('#txtTotalReDelAmount_'+rval).sum();
	
	$("#txtBunkerDifference_"+rval).val(parseFloat(parseFloat(delbunker) - parseFloat(redelbunker)).toFixed(2));
	
	var dailygrosshire = parseFloat($("#txtDailyGrossHireUSD1_"+rval).val());if(isNaN(dailygrosshire)){dailygrosshire = 0.00;}
	var txtBallastBonusAMT = parseFloat($("#txtBallastBonusAMT_"+rval).val());if(isNaN(txtBallastBonusAMT)){txtBallastBonusAMT = 0;}

	var nettHire = parseFloat($('[id^=txtHireAmt_'+rval+'_]').sum());if(isNaN(nettHire)){nettHire = 0.00;}
	var nettHire1 = parseFloat(nettHire) + parseFloat(txtBallastBonusAMT);

	//var txtBallastBonusAMT1 = parseFloat(txtBallastBonusAMT)/parseFloat(tcdays);if(isNaN(txtBallastBonusAMT1)){txtBallastBonusAMT1 = 0;}
	//var dailygrosshire1 = parseFloat(dailygrosshire) + parseFloat(txtBallastBonusAMT1);
	
	var addcomm        = parseFloat($("#txtAddCommPerct_"+rval).val());if(isNaN(addcomm)){addcomm = 0.00;}
	var addcommamt     = parseFloat(parseFloat(nettHire1)*parseFloat(addcomm))/100;if(isNaN(addcommamt)){addcommamt = 0.00;}
	$("#txtAddComm1_"+rval).val(parseFloat(addcommamt).toFixed(2));
	
	var brokercomm        = parseFloat($("#txtChartererAcc_"+rval).val());if(isNaN(brokercomm)){brokercomm = 0.00;}
	var brokercommamt     = parseFloat(parseFloat(nettHire1)*parseFloat(brokercomm))/100;if(isNaN(brokercommamt)){brokercommamt = 0.00;}
	$("#txtBrokerComm_"+rval).val(parseFloat(brokercommamt).toFixed(2));
	$("#txtNettHire_"+rval).val(parseFloat((parseFloat(nettHire)) - parseFloat(addcommamt) - parseFloat(brokercommamt)).toFixed(2));
	
	var numoff = $("#txtOFFID_"+rval).val();
	var offhiredays = 0;
	var offhirebunkercal = 0;
	for(var i =1;i <=numoff;i++)
	{

		// console.log();

		if(typeof($("#txtOffHireFrom_"+rval+"_"+i).val())!='undefined' && $("#txtOffHireFrom_"+rval+"_"+i).val().length!=0)
		{
			var timediff = parseFloat(getTimeDiff($("#txtOffHireTo_"+rval+"_"+i).val(),$("#txtOffHireFrom_"+rval+"_"+i).val()));
			if(isNaN(timediff)){timediff = 0.00;}
			$("#txtOffHireDays_"+rval+"_"+i).val(parseFloat(timediff).toFixed(4))
			var offrate  = parseFloat($("#txtOffHireRate_"+rval+"_"+i).val());
			if(isNaN(offrate)){offrate = 0.00;}
			offhiredays =   parseFloat(parseFloat(offhiredays) + parseFloat(timediff));
			$("#txtOffHireAmt_"+rval+"_"+i).val(parseFloat(parseFloat(timediff)*parseFloat(offrate)).toFixed(2));
			
			var txtOFFConBunkerCount = $("#txtOFFConBunkerCount_"+rval+"_"+i).val();
			for(var k =1;k <=txtOFFConBunkerCount;k++)
			{
				if(typeof($("#selConBunker_"+rval+"_"+i+"_"+k).val())!='undefined')
				{
					var txtConBunkerQty = parseFloat($("#txtConBunkerQty_"+rval+"_"+i+"_"+k).val());
					if(isNaN(txtConBunkerQty)){txtConBunkerQty = 0.00;}
					var txtConBunkerPrice = parseFloat($("#txtConBunkerPrice_"+rval+"_"+i+"_"+k).val());
					if(isNaN(txtConBunkerPrice)){txtConBunkerPrice = 0.00;}
					var txtConBunkerAmt = parseFloat(parseFloat(txtConBunkerQty)*parseFloat(txtConBunkerPrice));
					$("#txtConBunkerAmt_"+rval+"_"+i+"_"+k).val(parseFloat(txtConBunkerAmt).toFixed(2));
					offhirebunkercal = parseFloat(offhirebunkercal) + parseFloat(txtConBunkerAmt);
				}
			}
		}

		var timediff = $("#txtOffHireDays_"+rval+"_"+i).val();
		if(isNaN(timediff)){timediff = 0.00;}
		var offrate  = parseFloat($("#txtOffHireRate_"+rval+"_"+i).val());
		if(isNaN(offrate)){offrate = 0.00;}
		$("#txtOffHireAmt_"+rval+"_"+i).val(parseFloat(parseFloat(timediff)*parseFloat(offrate)).toFixed(2));

		var txtOFFConBunkerCount = $("#txtOFFConBunkerCount_"+rval+"_"+i).val();
			for(var k =1;k <=txtOFFConBunkerCount;k++)
			{
				if(typeof($("#selConBunker_"+rval+"_"+i+"_"+k).val())!='undefined')
				{
					var txtConBunkerQty = parseFloat($("#txtConBunkerQty_"+rval+"_"+i+"_"+k).val());
					if(isNaN(txtConBunkerQty)){txtConBunkerQty = 0.00;}
					var txtConBunkerPrice = parseFloat($("#txtConBunkerPrice_"+rval+"_"+i+"_"+k).val());
					if(isNaN(txtConBunkerPrice)){txtConBunkerPrice = 0.00;}
					var txtConBunkerAmt = parseFloat(parseFloat(txtConBunkerQty)*parseFloat(txtConBunkerPrice));
					$("#txtConBunkerAmt_"+rval+"_"+i+"_"+k).val(parseFloat(txtConBunkerAmt).toFixed(2));
					offhirebunkercal = parseFloat(offhirebunkercal) + parseFloat(txtConBunkerAmt);
				}
		}


	}	



	
	if(isNaN(offhiredays)){offhiredays = 0.00;}
	var txtOffHireAmt = parseFloat(offhirebunkercal) + parseFloat($('[id^=txtOffHireAmt_'+rval+'_]').sum());
	$("#txtLessOffHire_"+rval).val(parseFloat(txtOffHireAmt).toFixed(2));
	
	var utilisationDays1 = parseFloat(totaltcdays) - parseFloat(offhiredays);
	if(isNaN(utilisationDays1)){utilisationDays1 = 0.00;}
	$("#txtUtilisationDays_"+rval).val(parseFloat(utilisationDays1).toFixed(4));
	
	var txtNettRev			 = parseFloat(nettHire) + parseFloat(txtBallastBonusAMT) - parseFloat(addcommamt) - parseFloat(brokercommamt);
	if(isNaN(txtNettRev)){txtNettRev = 0.00;}
	$("#txtNettRev_"+rval).val(parseFloat(txtNettRev).toFixed(2));
	
	if($("#txtCVEM_"+rval).val() == ""){var txtCVE = 0;}else{var txtCVE = $("#txtCVEM_"+rval).val();}
	var calmul = parseFloat(parseFloat(parseFloat(txtCVE)/30)*parseFloat(utilisationDays1));if(isNaN(calmul)){calmul = 0.00;}
	$("#txtCVE_"+rval).val(parseFloat(calmul).toFixed(2));
	
	//-----------------otherIncome-----------
	var txtBunkerDifference  	 = parseFloat($("#txtBunkerDifference_"+rval).val());if(isNaN(txtBunkerDifference)){txtBunkerDifference = 0.00;}
	var lessOffHire  			 = parseFloat($("#txtLessOffHire_"+rval).val());if(isNaN(lessOffHire)){lessOffHire = 0.00;}
	var cVE  		             = parseFloat($("#txtCVE_"+rval).val());if(isNaN(cVE)){cVE = 0.00;}
	var otherIncome              = parseFloat($('[id^=txtOtherIncome_'+rval+'_]').sum());if(isNaN(otherIncome)){otherIncome = 0.00;}

	var txtIlohcAMT  		             = parseFloat($("#txtIlohcAMT_"+rval).val());if(isNaN(txtIlohcAMT)){txtIlohcAMT = 0.00;}
	
	var cal1		             = parseFloat(txtNettRev) - parseFloat(lessOffHire) + parseFloat(cVE) + parseFloat(txtBunkerDifference) + parseFloat(txtIlohcAMT);
	if(isNaN(cal1)){cal1 = 0.00;}
	$("#txtNETHire_"+rval).val(parseFloat(cal1).toFixed(2));
	var cal2		             = parseFloat(cal1) + parseFloat(otherIncome);
	$("#txtTotalRev_"+rval).val(parseFloat(cal2).toFixed(2));
	//--------------------------------------------
	
	//---------------otherExpense------------------
	var hddnOtherExID = $("#hddnOtherExID_"+rval).val();
	var otherexpense = 0;
	for(var i =1;i <=hddnOtherExID;i++)
	{
		if(typeof($("#selExpenseType_"+rval+"_"+i).val())!='undefined')
		{   
		    if($("#chkVal_"+rval+"_"+i).val()==1)
	        {
				var otherexpense1 = parseFloat($("#txtOtherExpense_"+rval+"_"+i).val());
				if(isNaN(otherexpense1)){otherexpense1 = 0.00;}
				otherexpense =   parseFloat(parseFloat(otherexpense) + parseFloat(otherexpense1));
			}
		}
	}
	
	
	var txtTCHOSTID = $("#txtTCHOSTID_"+rval).val();
	for(var j =1;j <=txtTCHOSTID;j++)
	{
	
	
	    var tcdays = parseFloat(getTimeDiff($("#txtTCReDeliveryDate_"+rval+"_"+j).val(),$("#txtTCDeliveryDate_"+rval+"_"+j).val()));if(isNaN(tcdays)){tcdays = 0.00;}

		// console.log('testing',tcdays)
		$("#txtTotalVoyageDays_"+rval+"_"+j).val(tcdays);
		if($("#txtTCinDailyHire_"+rval+"_"+j).val() == ""){var daily_vessel_exp = 0;}else{var daily_vessel_exp = $("#txtTCinDailyHire_"+rval+"_"+j).val();}
		var hireage_amt = parseFloat(parseFloat(daily_vessel_exp)*parseFloat(tcdays)).toFixed(2);
		if(hireage_amt=="" || isNaN(hireage_amt)){hireage_amt =0;}
		$("#txtHireargeAmt_"+rval+"_"+j).val(parseFloat(hireage_amt).toFixed(2));
		
		if($("#txtBallastBonus_"+rval+"_"+j).val() == ""){var txtBallastBonus = 0;}else{var txtBallastBonus = $("#txtBallastBonus_"+rval+"_"+j).val();}
		var txtGrossHireargeAmt = parseFloat(parseFloat(txtBallastBonus) + parseFloat($("#txtHireargeAmt_"+rval+"_"+j).val())).toFixed(2);
		if(txtGrossHireargeAmt=="" || isNaN(txtGrossHireargeAmt)){txtGrossHireargeAmt =0;}
		$("#txtGrossHireargeAmt_"+rval+"_"+j).val(parseFloat(txtGrossHireargeAmt).toFixed(2));
		
		if($("#txtHireargePercent_"+rval+"_"+j).val() == ""){var txtHireargePercent = 0;}else{var txtHireargePercent = $("#txtHireargePercent_"+rval+"_"+j).val();}
		if($("#txtHireargeBroPercent_"+rval+"_"+j).val() == ""){var txtHireargeBroPercent = 0;}else{var txtHireargeBroPercent = $("#txtHireargeBroPercent_"+rval+"_"+j).val();}
		
		var txtHireargePercentAmt = parseFloat(parseFloat(parseFloat(txtGrossHireargeAmt)*parseFloat(txtHireargePercent))/100);
		var txtHireargeBroPercentAmt = parseFloat(parseFloat(parseFloat(hireage_amt)*parseFloat(txtHireargeBroPercent))/100);
		if(txtHireargePercentAmt=="" || isNaN(txtHireargePercentAmt)){txtHireargePercentAmt =0;}
		if(txtHireargeBroPercentAmt=="" || isNaN(txtHireargeBroPercentAmt)){txtHireargeBroPercentAmt =0;}
		$("#txtHireargePercentAmt_"+rval+"_"+j).val(parseFloat(txtHireargePercentAmt).toFixed(2));
		$("#txtHireargeBroPercentAmt_"+rval+"_"+j).val(parseFloat(txtHireargeBroPercentAmt).toFixed(2));
		
		var txtNettHireargeAmt = parseFloat(parseFloat(txtGrossHireargeAmt) -  parseFloat(txtHireargePercentAmt) -  parseFloat(txtHireargeBroPercentAmt));
		$("#txtNettHireargeAmt_"+rval+"_"+j).val(parseFloat(txtNettHireargeAmt).toFixed(2));
			
		var txtHireargeCVE = $("#txtTCHireargeCVE_"+rval+"_"+j).val();
		if(txtHireargeCVE=="" || isNaN(txtHireargeCVE)){txtHireargeCVE =0;}
		var txtHireargeCVEAMT = parseFloat(parseFloat(parseFloat(parseFloat(txtHireargeCVE)*12)/365)*parseFloat(tcdays));
		if(txtHireargeCVEAMT=="" || isNaN(txtHireargeCVEAMT)){txtHireargeCVEAMT =0;}
		$("#txtTCHireargeCVEAMT_"+rval+"_"+j).val(parseFloat(txtHireargeCVEAMT).toFixed(2));
	}
	
	var numoff = $("#txtTCOFFID_"+rval).val();
	var offhiredays = 0;var offhirebunker = 0;
	var ownersbunkercal = 0;
	for(var i =1;i <=numoff;i++)
	{
		if(typeof($("#txtTCOffHireFrom_"+rval+"_"+i).val())!='undefined')
		{
			if($("#txtTCOffHireTo_"+rval+"_"+i).val()!='' && $("#txtTCOffHireFrom_"+rval+"_"+i).val()!='')
			{
				var timediff = parseFloat(getTimeDiff($("#txtTCOffHireTo_"+rval+"_"+i).val(),$("#txtTCOffHireFrom_"+rval+"_"+i).val()));
				if(isNaN(timediff)){timediff = 0.00;}
				$("#txtTCOffHireDays_"+rval+"_"+i).val(parseFloat(timediff).toFixed(4));
			}else{
			    var timediff = $("#txtTCOffHireDays_"+rval+"_"+i).val();
				if(timediff=="" || isNaN(timediff)){timediff =0;}
			}
			
			var offrate  = parseFloat($("#txtTCOffHireRate_"+rval+"_"+i).val());
			if(isNaN(offrate)){offrate = 0.00;}
			offhiredays =   parseFloat(parseFloat(offhiredays) + parseFloat(timediff));
			$("#txtTCOffHireAmt_"+rval+"_"+i).val(parseFloat(parseFloat(timediff)*parseFloat(offrate)).toFixed(2));
			
			var numoffbunker = $("#txtTCConBunkerCount_"+rval+"_"+i).val();
			for(var k =1;k <=numoffbunker;k++)
			{
				if(typeof($("#selTCConBunker_"+rval+"_"+i+"_"+k).val())!='undefined')
				{
					var txtTCConBunkerQty = parseFloat($("#txtTCConBunkerQty_"+rval+"_"+i+"_"+k).val());
					if(isNaN(txtTCConBunkerQty)){txtTCConBunkerQty = 0.00;}
					var txtTCConBunkerPrice = parseFloat($("#txtTCConBunkerPrice_"+rval+"_"+i+"_"+k).val());
					if(isNaN(txtTCConBunkerPrice)){txtTCConBunkerPrice = 0.00;}
					var txtTCConBunkerAmt = parseFloat(parseFloat(txtTCConBunkerQty)*parseFloat(txtTCConBunkerPrice));
					var offhirebunker =   parseFloat(parseFloat(offhirebunker) + parseFloat(txtTCConBunkerAmt));
					$("#txtTCConBunkerAmt_"+rval+"_"+i+"_"+k).val(parseFloat(txtTCConBunkerAmt).toFixed(2));
					if($("#ChkOFFHireCal_"+rval+"_"+i+"_"+k).is(":checked"))
					{
					   ownersbunkercal = parseFloat(ownersbunkercal) + parseFloat(txtTCConBunkerAmt);
					}
				}
			}
		}
	}	
	var OffhireDays = $("[id^=txtTCOffHireDays_"+rval+"_]").sum().toFixed(2)
	var txtOffHireCVE = $("#txtTCOffHireCVE_"+rval).val();
	var txtTcILOHC = $("#txtTcILOHC_"+rval).val();
	if(txtTcILOHC=="" || isNaN(txtTcILOHC)){txtTcILOHC =0;}
	if(txtOffHireCVE=="" || isNaN(txtOffHireCVE)){txtOffHireCVE =0;}
	var txtOffHireCVEAMT = parseFloat(parseFloat(parseFloat(parseFloat(txtOffHireCVE)*12)/365)*parseFloat(OffhireDays));
	if(txtOffHireCVEAMT=="" || isNaN(txtOffHireCVEAMT)){txtOffHireCVEAMT =0;}
	$("#txtTCOffHireCVEAMT_"+rval).val(parseFloat(txtOffHireCVEAMT).toFixed(2));
	var txtOffHireAmt = $('[id^=txtTCOffHireAmt_'+rval+'_]').sum();
	var OffhireDaysAMT = parseFloat(txtOffHireAmt) + parseFloat(txtOffHireCVEAMT) + parseFloat(ownersbunkercal) ;
	$("#txtTCBunkerOnOwnerAmt_"+rval).val(parseFloat(ownersbunkercal).toFixed(2));
	if(isNaN(OffhireDaysAMT)){OffhireDaysAMT = 0.00;}
	$("#txtTCLessOffHire_"+rval).val(parseFloat(OffhireDaysAMT).toFixed(2));
	
	var txtNettHireargeAmt = $("[id^=txtNettHireargeAmt_"+rval+"_]").sum() + $("[id^=txtTCHireargeCVEAMT_"+rval+"_]").sum();if(isNaN(txtNettHireargeAmt)){txtNettHireargeAmt = 0.00;}
	
	var txtFinalHireargeAmt = parseFloat(parseFloat(txtNettHireargeAmt) + $("[id^=txtTCDelAmount_"+rval+"_]").sum()) - $("[id^=txtTCReDelAmount_"+rval+"_]").sum() - parseFloat(OffhireDaysAMT) + parseFloat(txtTcILOHC);   
	if(isNaN(txtFinalHireargeAmt)){txtFinalHireargeAmt = 0.00;}
	$("#txtFinalHireargeAmt_"+rval).val(parseFloat(txtFinalHireargeAmt).toFixed(2));
	
	var cal2		 		= parseFloat(otherexpense) + parseFloat($("#txtFinalHireargeAmt_"+rval).val());
	if(isNaN(cal2)){cal2 = 0.00;}
	

	// console.log('dpk1',otherexpense);
	$("#txtTotalExpenses_"+rval).val(parseFloat(cal2).toFixed(2));
	
	var totalRev1  	 	= parseFloat($("#txtTotalRev_"+rval).val());if(isNaN(totalRev1)){totalRev1 = 0.00;}
	var totalExpenses  	= parseFloat($("#txtTotalExpenses_"+rval).val());if(isNaN(totalExpenses)){totalExpenses = 0.00;}
	var cal2		 	= parseFloat(totalRev1) - parseFloat(totalExpenses);
	if(isNaN(cal2)){cal2 = 0.00;}
	$("#txtVoyageEarnings_"+rval).val(parseFloat(cal2).toFixed(2));
	
	
	var voyageEarnings  	= parseFloat($("#txtVoyageEarnings_"+rval).val());if(isNaN(voyageEarnings)){voyageEarnings = 0.00;}
	var utilisationDays  	= parseFloat($("#txtUtilisationDays_"+rval).val());if(isNaN(utilisationDays)){utilisationDays = 0.00;}
	var cal2		 		= parseFloat(voyageEarnings) / parseFloat(utilisationDays);
	if(isNaN(cal2) || cal2 == "-Infinity" || cal2 == "Infinity"){cal2 = 0.00;}
	$("#txtProfitPerDay_"+rval).val(parseFloat(cal2).toFixed(2));
	//------------------------------------------------------------
	var txtTripID = $("#txtTripID").val();
	var totaldays = totalvoyageearning = 0;
	for(var i =1;i <=txtTripID;i++)
	{
		if($("#tripdiv_"+i).is(':visible'))
		{   
			var days           = parseFloat($("#txtUtilisationDays_"+i).val());if(isNaN(voyageEarnings)){voyageEarnings = 0.00;}
			var earning        = parseFloat($("#txtVoyageEarnings_"+i).val());if(isNaN(earning)){earning = 0.00;}
			totaldays          =   parseFloat(parseFloat(totaldays) + parseFloat(days));
			totalvoyageearning =   parseFloat(parseFloat(totalvoyageearning) + parseFloat(earning));
		}
	}
	$("#txtTotalUdays").val(parseFloat(totaldays).toFixed(4));
	$("#txtTotalVoyageEarning").val(parseFloat(totalvoyageearning).toFixed(2));
}



function AddNewDelRedelRow(val)
{
	var id = $("#txtDELREDELID_"+val).val();
	if($("#txtDeldate_"+val+"_"+id).val() != "" && $("#txtReDeldate_"+val+"_"+id).val() != "" && $("#txtHireRate_"+val+"_"+id).val() != "")
	{
		id = (id - 1) + 2;
		$('<tr id="delredel_row_'+val+'_'+id+'"><td><a href="#tbl_'+val+'_'+id+'" onClick="removeDelRedelRow('+val+', '+id+');" ><i class="fa fa-times" style="color:red;"></i></a></td><td><input autocomplete="off" type="text" name="txtDeldate_'+val+'_'+id+'" id="txtDeldate_'+val+'_'+id+'" class="input-text datetimepicker" value="" style="width:100px;" placeholder="dd-mm-yy hh:mm" /></td><td><input autocomplete="off" type="text" name="txtReDeldate_'+val+'_'+id+'" id="txtReDeldate_'+val+'_'+id+'" class="input-text datetimepicker" value="" style="width:100px;" placeholder="dd-mm-yy hh:mm" /></td><td><input autocomplete="off" type="text" name="txtTCdays_'+val+'_'+id+'" id="txtTCdays_'+val+'_'+id+'" class="input-text" placeholder="TC Days" style="width:100px;background-color:#EAEAEA;" readonly value=""/></td><td><input autocomplete="off" type="text" name="txtHireRate_'+val+'_'+id+'" id="txtHireRate_'+val+'_'+id+'" class="input-text numeric" placeholder="Hire Rate" style="width:100px;" value="" onKeyUp="getFinalCalculation('+val+');"/></td><td><input autocomplete="off" type="text" name="txtHireAmt_'+val+'_'+id+'" id="txtHireAmt_'+val+'_'+id+'" class="input-text" placeholder="Hire Amount" style="width:100px;background-color:#EAEAEA;" readonly value=""/></td><td></td></tr>').appendTo("#tcDelRedeltbody_"+val);
		
		$("#txtDELREDELID_"+val).val(id);	
		$(".numeric").numeric();
		
		$('#txtDeldate_'+val+'_'+id+',#txtReDeldate_'+val+'_'+id).datetimepicker({
			format: 'dd-mm-yyyy hh:ii',
			autoclose: true,
			todayBtn: true,
			minuteStep: 1
			}).on('changeDate', function(){

				AddNewTCDivToHost();
				$('#txtTCDeliveryDate_'+val+'_'+id).val($('#txtDeldate_'+val+'_'+id).val())
				$('#txtTCReDeliveryDate_'+val+'_'+id).val($('#txtReDeldate_'+val+'_'+id).val())
				getFinalCalculation(val);
		});
	}
	else
	{
		jAlert('Please fill previous data', 'Alert');
		return false;
	}
}



$('#txtDeldate_1_1,#txtReDeldate_1_1').datetimepicker({
			format: 'dd-mm-yyyy hh:ii',
			autoclose: true,
			todayBtn: true,
			minuteStep: 1
			}).on('changeDate', function(){

				$('#txtTCDeliveryDate_1_1').val($('#txtDeldate_1_1').val())
				$('#txtTCReDeliveryDate_1_1').val($('#txtReDeldate_1_1').val())
				getFinalCalculation(1);
		});


		$('[id^=txtDeldate_1_],[id^=txtReDeldate_1_]').datetimepicker({
		format: 'dd-mm-yyyy hh:ii',
		autoclose: true,
		todayBtn: true,
		minuteStep: 1
		}).on('changeDate', function(){
			var idd = $(this).attr('id');
			var iddd = idd.split("_");
			getFinalCalculation(iddd[1]);
	});



		
function addOtherIncomeRow()
{
    var idd = $("#hddnOtherID").val();
	if($("#txtOtherIncomeText_1_"+idd).val()!='' && $("#txtOtherIncome_1_"+idd).val()!='')
	{
	    idd = parseInt(idd) + 1;
	    $('<tr class="input-text" id="row_otherincome_'+idd+'"><td><a href="#tb1" onClick="removeOtherIncome('+idd+');" ><i class="fa fa-times" style="color:red;"></i></a></td><td><input autocomplete="off" type="text" name="txtOtherIncomeText_'+idd+'" id="txtOtherIncomeText_'+idd+'" class="input-text" style="width:150px;" placeholder="Description" value="" /></td><td><input autocomplete="off" type="text" name="txtOtherIncome_'+idd+'" id="txtOtherIncome_1_'+idd+'" class="input-text" style="width:110px;" onKeyUp="getFinalCalculation();" placeholder="Other Income(USD)" value="" /></td></tr>').appendTo("#otherIncomebody");
		$("#hddnOtherID").val(idd);
		$("[id^=txtOtherIncome_1_]").numeric();
	}
	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){
					$("#row_otherincome_"+var1).remove();
					getFinalCalculation();			
				 }
			else{return false;}
			});
}


function addOtherExpenseRow()
{
    var idd = $("#hddnOtherExID_1").val();
	if($("#selExpenseType_1_"+idd).val()!='' && $("#txtOtherExpense_1_"+idd).val()!='')
	{
	    idd = parseInt(idd) + 1;
	    $('<tr class="input-text" id="row_otherExpense_'+idd+'"><td><a href="#tb1" onClick="removeOtherExpense('+idd+');" ><i class="fa fa-times" style="color:red;"></i></a></td><td ><select name="selExpOwnerRelated_'+idd+'" id="selExpOwnerRelated_'+idd+'" class="input-text" style="width:110px;" onchange="markCheckBox(this)"></select></td><td ><select name="selExpenseType_'+idd+'" id="selExpenseType_1_'+idd+'" class="input-text" style="width:110px;"></select></td><td><input autocomplete="off" type="text" name="txtExpenseDesc_'+idd+'" id="txtExpenseDesc_'+idd+'" class="input-text" style="width:110px;" placeholder="Expense Descp." value="" readonly/></td><td><input name="ChkAddToTTL_'+idd+'" class="checkbox" id="ChkAddToTTL_'+idd+'" type="checkbox" value="1"/><input type="hidden" name="chkVal_'+idd+'"  class="checkval" id="chkVal_1_'+idd+'" value="" /></td><td><input autocomplete="off" type="text" name="txtOtherExpense_'+idd+'" id="txtOtherExpense_1_'+idd+'" class="input-text" style="width:110px;" onKeyUp="getFinalCalculation();" placeholder="Other Expense(USD)" value="" /></td></tr>').appendTo("#otherExpensebody");
		$("#hddnOtherExID_1").val(idd);
		$("input[type='checkbox']").iCheck({
			checkboxClass: 'icheckbox_minimal',
			radioClass: 'iradio_minimal'
		});
		$("#selExpenseType_1_"+idd).html($("#selExpenseType").html());
		$("#selExpOwnerRelated_"+idd).html($("#selOwRel").html());
		$("[id^=txtOtherExpense_1_]").numeric();
		
		$('[id^=ChkAddToTTL_]').on('ifChecked', function () { 
		   var idd = $(this).attr('id');
		   var iddd = idd.split("_");
		   $("#chkVal_1_"+iddd[1]).val(1);
		   getFinalCalculation();
		});
		 
		$('[id^=ChkAddToTTL_]').on('ifUnchecked', function () { 
		   var idd = $(this).attr('id');
		   var iddd = idd.split("_");
		   $("#chkVal_1_"+iddd[1]).val('');
		   getFinalCalculation();
		});
	}
	else
	{
		jAlert('Please fill previous data', 'Alert');
		return false;
	}
}

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


function AddNewOffHire()
{
	var id = $("#txtOFFID").val();
	if($("#txtOffHireReason_"+id).val() != "" && (($("#txtOffHireFrom_"+id).val() != "" && $("#txtOffHireTo_"+id).val() != "") || $("#txtOffHireDays_"+id).val() != ""))
	{
		id = (id - 1) + 2;
		$('<tr id="row_offhire_'+id+'" class="input-text"><td><a href="#pr'+id+'" onclick="removeOffHire('+id+');"><i class="fa fa-times" style="color:red;"></i></a></td><td valign="top"><textarea class="input-text areasize" name="txtOffHireReason_'+id+'" style="width:120px;" id="txtOffHireReason_'+id+'" rows="3" placeholder="Off Hire Reason..."></textarea></td><td valign="top"><input type="text" name="txtOffHireFrom_'+id+'" id="txtOffHireFrom_'+id+'" class="input-text" placeholder="dd-mm-yyyy HH:MM" style="width:100px;" autocomplete="off" value=""></td><td valign="top"><input type="text" name="txtOffHireTo_'+id+'" id="txtOffHireTo_'+id+'" class="input-text" placeholder="dd-mm-yyyy HH:MM" autocomplete="off" value="" style="width:100px;"></td><td valign="top"><input type="text" name="txtOffHireDays_'+id+'" id="txtOffHireDays_'+id+'" class="input-text numeric"  placeholder="Off Hire Days" style="width:90px;" autocomplete="off" value=""/></td><td valign="top"><input type="text" name="txtOffHireRate_'+id+'" id="txtOffHireRate_'+id+'" class="input-text" style="width:100px;"  placeholder="Rate/Day" autocomplete="off" value="" onKeyUp="getFinalCalculation();"/></td><td valign="top"><input type="text" name="txtOffHireAmt_'+id+'" id="txtOffHireAmt_'+id+'" class="input-text"  placeholder="Off Hire(USD)" style="width:90px;background-color:#EAEAEA;" autocomplete="off" value=""/></td></tr>').appendTo("#offhirebody");
		$("#txtOFFID").val(id);
		$("[id^=txtOffHireRate_]").numeric();	
		$(".areasize").autosize({append: "\n"});
		$('#txtOffHireFrom_'+id+',#txtOffHireTo_'+id).datetimepicker({
		format: 'dd-mm-yyyy hh:ii',
	    autoclose: true,
        todayBtn: true,
        minuteStep: 1
		}).on('changeDate', function(){  getFinalCalculation(); });
	}
}


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



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


function AddNewDel()
{
	var id = $("#txtDELID_1").val();
	if($("#selDelBunker_"+id).val() != "" && $("#txtDelQty_"+id).val() != "" && $("#txtDelBunDate_"+id).val() != "" && $("#txtDelPrice_"+id).val() != "")
	{
		id = (id - 1) + 2;
		$('<tr class="input-text" id="row_del_'+id+'"><td><a href="#tbl'+id+'" onClick="removeDelBunker('+id+');" ><i class="fa fa-times" style="color:red;"></i></a>&nbsp;&nbsp;</td><td><select name="selDelBunker_'+id+'" class="input-text" style=" width:90px;" id="selDelBunker_'+id+'"></select></td><td><input type="text" name="txtDelQty_'+id+'" id="txtDelQty_1_'+id+'" class="input-text numeric" style="width:85px;" value="" placeholder="0.00" onKeyUp="getFinalCalculation();" autocomplete="off" /></td><td><input type="text" name="txtDelBunDate_'+id+'" id="txtDelBunDate_'+id+'" class="input-text" style="width:85px;" value="" placeholder="DD-MM-YYYY" autocomplete="off" /></td><td><input type="text" name="txtDelPrice_'+id+'" id="txtDelPrice_1_'+id+'" class="input-text numeric" style="width:85px;" value="" placeholder="0.00" onKeyUp="getFinalCalculation();" autocomplete="off" /></td><td><input type="text" name="txtDelAmount_'+id+'" id="txtDelAmount_1_'+id+'" class="input-text numeric" style="width:85px;background-color:#E1E1E1;" value="" placeholder="0.00" readonly="true" autocomplete="off"/></td></tr>').appendTo("#bunkerdelivery");
		$("#txtDELID_1").val(id);
		$(".numeric").numeric();	
		$("#selDelBunker_"+id).html($("#selBunker").html());
		$("[id^=txtDelBunDate_]").datepicker({
			format: 'dd-mm-yyyy',
			autoclose: true
		});
	}
	else
	{
		jAlert('Please fill previous data', 'Alert');
		return false;
	}
}


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


function AddNewReDel()
{
	var id = $("#txtREDELID_1").val();
	if($("#selReDelBunker_"+id).val() != "" && $("#txtReDelQty_"+id).val() != "" && $("#txtReDelBunDate_"+id).val() != "" && $("#txtReDelPrice_"+id).val() != "")
	{
		id = (id - 1) + 2;
		$('<tr class="input-text" id="row_Redel_'+id+'"><td><a href="#tbl'+id+'" onClick="removeReDelBunker('+id+');" ><i class="fa fa-times" style="color:red;"></i></a>&nbsp;&nbsp;</td><td><select name="selReDelBunker_'+id+'" class="input-text" style=" width:90px;" id="selReDelBunker_'+id+'"></select></td><td><input type="text" name="txtReDelQty_'+id+'" id="txtReDelQty_1_'+id+'" class="input-text numeric" style="width:85px;" value="" placeholder="0.00" onKeyUp="getFinalCalculation();" autocomplete="off" /></td><td><input type="text" name="txtReDelBunDate_'+id+'" id="txtReDelBunDate_'+id+'" class="input-text" style="width:85px;" value="" placeholder="DD-MM-YYYY" autocomplete="off" /></td><td><input type="text" name="txtReDelPrice_'+id+'" id="txtReDelPrice_1_'+id+'" class="input-text numeric" style="width:85px;" value="" placeholder="0.00" onKeyUp="getFinalCalculation();" autocomplete="off" /></td><td><input type="text" name="txtReDelAmount_'+id+'" id="txtReDelAmount_1_'+id+'" class="input-text numeric" style="width:85px;background-color:#E1E1E1;" value="" placeholder="0.00" readonly="true" autocomplete="off"/></td></tr>').appendTo("#bunkerRedelivery");
		$("#txtREDELID_1").val(id);
		$(".numeric").numeric();	
		$("#selReDelBunker_"+id).html($("#selBunker").html());
		$("[id^=txtReDelBunDate_]").datepicker({
			format: 'dd-mm-yyyy',
			autoclose: true
		});
	}
	else
	{
		jAlert('Please fill previous data', 'Alert');
		return false;
	}
}
 
 
function getCurrencySpan()
{
	if($("#selExchangeCurrency").val()!="")
	{
		$("#currencyspan").text("("+$("#selExchangeCurrency").val()+")");
	}
	else
	{
		$("#currencyspan").text('');
	}
}

function getDailyGrossHire()
{
	if($("#txtDailyGrossHireUSD").val()!='' && $("#txtExchangeRate").val()!='')
	{
		$('#txtDailyGrossHireUSD1').val(parseFloat($("#txtDailyGrossHireUSD").val()*$("#txtExchangeRate").val()).toFixed(2));
	}
	else
	{
		$('#txtDailyGrossHireUSD1').val(0);
	}
}
 
 
 

function AddNewTCDivToHost(val)
{
    var id = $("#txtTCHOSTID_1").val();
	if($("#txtTCDeliveryDate_1_"+id).val() != "" && $("#txtTCReDeliveryDate_1_"+id).val() != "" && $("#txtTCinDailyHire_1_"+id).val() != "")
	{
		id = (id - 1) + 2;
		$('<tr id="hostTCtr1_'+id+'"><td width="5%" valign="top"><a href="#tb1" onClick="removeHostTCtr('+id+');" ><i class="fa fa-times" style="color:red;"></i></a><input type="hidden" name="txtTCINSlaveRandomID_'+id+'" id="txtTCINSlaveRandomID_'+id+'" value=""></td><td  width="10%">Date of Delivery&nbsp;:</td><td  width="10%"><input type="text" name="txtTCDeliveryDate_'+id+'" id="txtTCDeliveryDate_1_'+id+'" class="input-text datetimepicker" style="width:110px;" value="" placeholder="dd-mm-yy hh:mm" autocomplete="off"></td><td  width="10%">Date of Re-Delivery&nbsp;:</td><td  width="10%"><input type="text" name="txtTCReDeliveryDate_'+id+'" id="txtTCReDeliveryDate_1_'+id+'" class="input-text datetimepicker" style="width:110px;" value="" placeholder="dd-mm-yy hh:mm" autocomplete="off"></td><td>Total Voyage Days&nbsp;:</td><td><input type="text"  name="txtTotalVoyageDays_'+id+'" style="width:110px;" id="txtTotalVoyageDays_1_'+id+'" class="input-text" autocomplete="off" readonly="true" value="" placeholder="0.00"/></td><td>Daily Hire(USD/Day)&nbsp;:</td><td><input type="text"  name="txtTCinDailyHire_'+id+'" style="width:110px;" id="txtTCinDailyHire_1_'+id+'" class="input-text numeric" autocomplete="off" value="" placeholder="0.00" onKeyUp="getFinalCalculation('+val+');" /></td><td>Hireage (USD):</td><td><input type="text"  name="txtHireargeAmt_'+id+'" id="txtHireargeAmt_1_'+id+'" style="width:110px;" class="input-text" value="" placeholder="0.00" readonly /></td></tr><tr id="hostTCtr2_'+id+'"><td></td><td>Ballast Bonus (USD):</td><td><input type="text" name="txtBallastBonus_'+id+'" id="txtBallastBonus_1_'+id+'" style="width:110px;" onKeyUp="getFinalCalculation('+val+');" class="input-text numeric" autocomplete="off" value="" placeholder="0.00"></td><td>Gross Hire-age (USD):</td><td><input type="text"  name="txtGrossHireargeAmt_'+id+'" id="txtGrossHireargeAmt_1_'+id+'" style="width:110px;" class="input-text numeric" value="" placeholder="0.00" readonly /></td><td>Add Comm <span style="font-size:10px; font-style:italic;">(%)</span>:</td><td><input type="text"  name="txtHireargePercent_'+id+'" style="width:110px;" id="txtHireargePercent_1_'+id+'" class="input-text numeric" value="" placeholder="%" onKeyUp="getFinalCalculation('+val+');"/></td><td>Add Comm <span style="font-size:10px; font-style:italic;">(USD)</span>:</td><td><input type="text"  name="txtHireargePercentAmt_'+id+'" style="width:110px;" id="txtHireargePercentAmt_1_'+id+'" class="input-text" value="" placeholder="0.00" readonly /></td><td>Add Comm Vendor:</td><td><select name="selTCAddCoVendor_'+id+'" class="input-text" style="width:110px;" id="selTCAddCoVendor_'+id+'" ></select></td></tr><tr id="hostTCtr3_'+id+'"><td></td><td></td><td></td><td></td><td></td><td>Owners side Brokerage commission:</td><td><input type="text"  name="txtHireargeBroPercent_'+id+'" style="width:110px;" id="txtHireargeBroPercent_1_'+id+'" class="input-text numeric" value="" placeholder="%" onKeyUp="getFinalCalculation('+val+');"/></td><td>Brokerage <span style="font-size:10px; font-style:italic;">(USD)</span>:</td><td><input type="text"  name="txtHireargeBroPercentAmt_'+id+'" style="width:110px;" id="txtHireargeBroPercentAmt_1_'+id+'" class="input-text" value="" placeholder="0.00" readonly /></td><td>Broker :</td><td><select name="selTCBroComVendor_'+id+'" class="input-text" style="width:110px;" id="selTCBroComVendor_'+id+'" ></select></td></tr><tr id="hostTCtr4_'+id+'"><td></td><td>Nett Hire-age (USD) :</td><td><input type="text"  name="txtNettHireargeAmt_'+id+'" id="txtNettHireargeAmt_1_'+id+'" style="width:110px;" class="input-text" value="" placeholder="0.00" readonly /></td><td>CVE <span style="font-size:10px; font-style:italic;">(Per Month)</span> :</td><td><input type="text"  name="txtTCHireargeCVE_'+id+'" style="width:110px;" id="txtTCHireargeCVE_1_'+id+'" class="input-text numeric" value="" placeholder="0.00" onKeyUp="getFinalCalculation('+val+');"/></td><td>CVE (USD) :</td><td><input type="text"  name="txtTCHireargeCVEAMT_'+id+'" style="width:110px;" id="txtTCHireargeCVEAMT_1_'+id+'" class="input-text" value="" placeholder="0.00" onKeyUp="getFinalCalculation('+val+');"/></td><td></td><td></td><td></td><td></td></tr><tr id="hostTCtr5_'+id+'" height="7">												    <td colspan="11"></td></tr><tr id="hostTCtr6_'+id+'" height="7"><td></td><td colspan="10" style="border-top:2px solid #C5C5C5;"></td></tr>').appendTo("#hostTCDIV");
		
		$("#txtTCHOSTID_1").val(id);	
		$(".numeric").numeric();
		$(".areasize").autosize({append: "\n"});
		$("#selTCAddCoVendor_"+id).html($("#selVendor").html());
		$("#selTCBroComVendor_"+id).html($("#selVendor").html());
		
		$('#txtTCDeliveryDate_1_'+id+',#txtTCReDeliveryDate_1_'+id).datetimepicker({
			format: 'dd-mm-yyyy hh:ii',
			autoclose: true,
			todayBtn: true,
			minuteStep: 1
			}).on('changeDate', function(){
				getFinalCalculation(1);
		});
	}
	else
	{
		jAlert('Please fill previous data', 'Alert');
		return false;
	}
}

function removeHostTCtr(val1)
{
	jConfirm('Are you sure you want to remove this entry permanently ?', 'Confirmation', function(r) {
		if(r){
				$("#hostTCtr1_"+val1).remove();
				$("#hostTCtr2_"+val1).remove();
				$("#hostTCtr3_"+val1).remove();
				$("#hostTCtr4_"+val1).remove();
				$("#hostTCtr5_"+val1).remove();
				$("#hostTCtr6_"+val1).remove();
				getFinalCalculation();
			 }
		else{return false;}
		});
}


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


function AddNewTCDel()
{
	var id = $("#txtTCDELID").val();
	if($("#selTCDelBunker_"+id).val() != "" && $("#txtTCDelQty_"+id).val() != "" && $("#txtTCDelBunDate_"+id).val() != "" && $("#txtTCDelPrice_"+id).val() != "")
	{
		id = (id - 1) + 2;
		$('<tr class="input-text" id="TCrow_del_'+id+'"><td><a href="#tbl'+id+'" onClick="removeTCDelBunker('+id+');" ><i class="fa fa-times" style="color:red;"></i></a>&nbsp;&nbsp;</td><td><select name="selTCDelBunker_'+id+'" class="input-text" style=" width:90px;" id="selTCDelBunker_'+id+'"><?php $obj->getBunkerList();?></select></td><td><input type="text" name="txtTCDelQty_'+id+'" id="txtTCDelQty_'+id+'" class="input-text numeric" style="width:85px;" value="" placeholder="0.00" onKeyUp="getDelBunkerCalculation();" autocomplete="off" /></td><td><input type="text" name="txtTCDelBunDate_'+id+'" id="txtTCDelBunDate_'+id+'" class="input-text" style="width:85px;" value="" placeholder="DD-MM-YYYY" autocomplete="off" /></td><td><input type="text" name="txtTCDelPrice_'+id+'" id="txtTCDelPrice_'+id+'" class="input-text numeric" style="width:85px;" value="" placeholder="0.00" onKeyUp="getDelBunkerCalculation();" autocomplete="off" /></td><td><input type="text" name="txtTCDelAmount_'+id+'" id="txtTCDelAmount_1_'+id+'" class="input-text numeric" style="width:85px;background-color:#E1E1E1;" value="" placeholder="0.00" readonly="true" autocomplete="off"/></td></tr>').appendTo("#bunkerTCdelivery");
		$("#txtTCDELID").val(id);
		$(".numeric").numeric();	
		$("[id^=txtTCDelBunDate_]").datepicker({
			format: 'dd-mm-yyyy',
			autoclose: true
		});
	}
	else
	{
		// jAlert('Please fill previous data', 'Alert');
		console.log('Please fill previous data');
		return false;
	}
}


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


function AddNewTCReDel()
{
	var id = $("#txtTCREDELID").val();
	if($("#selTCReDelBunker_"+id).val() != "" && $("#txtTCReDelQty_"+id).val() != "" && $("#txtTCReDelBunDate_"+id).val() != "" && $("#txtTCReDelPrice_"+id).val() != "")
	{
		id = (id - 1) + 2;
		$('<tr class="input-text" id="TCrow_Redel_'+id+'"><td><a href="#tbl'+id+'" onClick="removeTCReDelBunker('+id+');" ><i class="fa fa-times" style="color:red;"></i></a>&nbsp;&nbsp;</td><td><select name="selTCReDelBunker_'+id+'" class="input-text" style=" width:90px;" id="selTCReDelBunker_'+id+'"><?php $obj->getBunkerList();?></select></td><td><input type="text" name="txtTCReDelQty_'+id+'" id="txtTCReDelQty_'+id+'" class="input-text numeric" style="width:85px;" value="" placeholder="0.00" onKeyUp="getReDelBunkerCalculation();" autocomplete="off" /></td><td><input type="text" name="txtTCReDelBunDate_'+id+'" id="txtTCReDelBunDate_'+id+'" class="input-text" style="width:85px;" value="" placeholder="DD-MM-YYYY" autocomplete="off" /></td><td><input type="text" name="txtTCReDelPrice_'+id+'" id="txtTCReDelPrice_'+id+'" class="input-text numeric" style="width:85px;" value="" placeholder="0.00" onKeyUp="getReDelBunkerCalculation();" autocomplete="off" /></td><td><input type="text" name="txtTCReDelAmount_'+id+'" id="txtTCReDelAmount_1_'+id+'" class="input-text numeric" style="width:85px;background-color:#E1E1E1;" value="" placeholder="0.00" readonly="true" autocomplete="off"/></td></tr>').appendTo("#bunkerTCRedelivery");
		$("#txtTCREDELID").val(id);
		$(".numeric").numeric();	
		$("[id^=txtTCReDelBunDate_]").datepicker({
			format: 'dd-mm-yyyy',
			autoclose: true
		});
	}
	else
	{
		// jAlert('Please fill previous data', 'Alert');
		console.log('Please fill previous data');
		return false;
	}
}


function AddNewTCOffHire()
{
	var id = $("#txtTCOFFID").val();
	if($("#txtTCOffHireReason_"+id).val() != "" && $("#txtTCOffHireFrom_"+id).val() != "" && $("#txtTCOffHireTo_"+id).val() != "")
	{
		id = (id - 1) + 2;
		$('<tr id="TCrow_offhire_'+id+'" class="input-text"><td><a href="#pr'+id+'" onclick="removeTCOffHire('+id+');"><i class="fa fa-times" style="color:red;"></i></a></td><td valign="top"><textarea class="input-text areasize" name="txtTCOffHireReason_'+id+'" style="width:120px;" id="txtTCOffHireReason_'+id+'" rows="3" placeholder="Off Hire Reason..."></textarea></td><td valign="top"><input type="text" name="txtTCOffHireFrom_'+id+'" id="txtTCOffHireFrom_'+id+'" class="input-text datetimepicker" placeholder="dd-mm-yyyy HH:MM" style="width:100px;" autocomplete="off" value=""></td><td valign="top"><input type="text" name="txtTCOffHireTo_'+id+'" id="txtTCOffHireTo_'+id+'" class="input-text datetimepicker" placeholder="dd-mm-yyyy HH:MM" autocomplete="off" value="" style="width:100px;"></td><td valign="top"><input type="text" name="txtTCOffHireDays_'+id+'" id="txtTCOffHireDays_'+id+'" class="input-text"  placeholder="Off Hire Days" style="width:90px;background-color:#EAEAEA;" autocomplete="off" value=""/></td><td valign="top"><input type="text" name="txtTCOffHireRate_'+id+'" id="txtTCOffHireRate_'+id+'" class="input-text numeric" style="width:100px;"  placeholder="Rate/Day" autocomplete="off" value="" onKeyUp="getFinalCalculation();"/></td><td valign="top"><input type="text" name="txtTCOffHireAmt_'+id+'" id="txtTCOffHireAmt_'+id+'" class="input-text"  placeholder="Off Hire(USD)" style="width:90px;background-color:#EAEAEA;" autocomplete="off" value=""/></td></tr><tr id="TCrow_offhireBunker_'+id+'"><td></td><td colspan="6"><table width="100%" class="tablesorter"><tr><td></td><td>Bunker Grade</td><td>Qty(MT)</td><td>Price(USD)</td><td>Amount(USD)</td><td>On Owner\'s Account</td></tr><tbody id="TCConbunkerTBody_'+id+'"></tbody><tr><td colspan="6"><button type="button" onClick="addTCConBunkerRow('+id+',1)">Add Bunkers</button><input type="hidden" name="txtTCConBunkerCount_'+id+'" id="txtTCConBunkerCount_'+id+'" value="1"/></td></tr></table></td></tr>').appendTo("#TCoffhirebody");
		$("#txtTCOFFID").val(id);
		$("[id^=txtTCOffHireRate_]").numeric();	
		$(".numeric").numeric();
		$(".areasize").autosize({append: "\n"});
		
		$('#txtTCOffHireFrom_'+id+',#txtTCOffHireTo_'+id).datetimepicker({
			format: 'dd-mm-yyyy hh:ii',
			autoclose: true,
			todayBtn: true,
			minuteStep: 1
			}).on('changeDate', function(){
				getFinalCalculation();
		});
		
		$('#ChkOFFHireCal_'+id+'_1').iCheck({
		checkboxClass: 'icheckbox_minimal',
		radioClass: 'iradio_minimal'
		});
		
		$('#ChkOFFHireCal_'+id+'_1').on('ifChecked', function () { 
		   $('#ChkOFFHireCal_'+id+'_1').attr('checked', true);
		   getFinalCalculation();
		});
		 
		$('#ChkOFFHireCal_'+id+'_1').on('ifUnchecked', function () { 
		   $('#ChkOFFHireCal_'+id+'_1').attr('checked', false);
		   getFinalCalculation();
		});
	}
}


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


function addTCConBunkerRow(val2)
{
	var id = $("#txtTCConBunkerCount_"+val2).val();
	if($("#txtTCConBunkerQty_"+val2+"_"+id).val() != "" && $("#selTCConBunker_"+val2+"_"+id).val() != "" && $("#txtTCConBunkerPrice_"+val2+"_"+id).val() != "")
	{
		id = (id - 1) + 2;
		$('<tr id="DivTCConBunkeractual_'+val2+'_'+id+'"><td><a href="#tbb'+id+'" onclick="removeTCConBunkerRows('+val2+','+id+');"><i class="fa fa-times" style="color:red;"></i></a></td><td><select name="selTCConBunker_'+val2+'_'+id+'" id="selTCConBunker_'+val2+'_'+id+'" style="width:90px;" class="input-text"><?php $obj->getBunkerList();?></select></td><td><input type="text" name="txtTCConBunkerQty_'+val2+'_'+id+'" id="txtTCConBunkerQty_'+val2+'_'+id+'" style="width:90px;" class="input-text numeric" onkeyup="getFinalCalculation();" placeholder="0.00" autocomplete="off" value=""></td><td><input type="text" name="txtTCConBunkerPrice_'+val2+'_'+id+'" id="txtTCConBunkerPrice_'+val2+'_'+id+'" style="width:90px;" class="input-text numeric" onkeyup="getFinalCalculation();" placeholder="0.00" autocomplete="off" value=""></td><td><input type="text" name="txtTCConBunkerAmt_'+val2+'_'+id+'" id="txtTCConBunkerAmt_'+val2+'_'+id+'" style="width:90px;" class="input-text" placeholder="0.00" readonly="" autocomplete="off" value=""></td><td><input name="ChkOFFHireCal_'+val2+'_'+id+'" class="checkbox" id="ChkOFFHireCal_'+val2+'_'+id+'" type="checkbox" value="1"/></td></tr>').appendTo("#TCConbunkerTBody_"+val2);
		$("#txtTCConBunkerCount_"+val2).val(id);
		$(".numeric").numeric();	
		$('#ChkOFFHireCal_'+val2+'_'+id).iCheck({
		checkboxClass: 'icheckbox_minimal',
		radioClass: 'iradio_minimal'
		});
		
		$('#ChkOFFHireCal_'+val2+'_'+id).on('ifChecked', function () { 
		   $(this).attr('checked', true);
		   getFinalCalculation();
		});
		 
		$('#ChkOFFHireCal_'+val2+'_'+id).on('ifUnchecked', function () { 
		   $(this).attr('checked', false);
		   getFinalCalculation();
		});
	}
	else
	{
		jAlert('Please fill previous data', 'Alert');
		return false;
	}
}

function removeTCConBunkerRows(val2,val3)
{
	jConfirm('Are you sure you want to remove this entry permanently ?', 'Confirmation', function(r) {
		if(r){
				$("#DivTCConBunkeractual_"+val2+"_"+val3).remove();
				getBunkerCalculation();			
			 }
		else{return false;}
		});
}


function getDelBunkerCalculation()
{
    var txtREDELID = $("#txtTCDELID").val();
	for(var i =1;i <=txtREDELID;i++)
	{
		var txtReDelQty      = parseFloat($("#txtTCDelQty_"+i).val());if(isNaN(txtReDelQty)){txtReDelQty = 0.00;}
		var txtReDelPrice    = parseFloat($("#txtTCDelPrice_"+i).val());if(isNaN(txtReDelPrice)){txtReDelPrice = 0.00;}
		var amount          =   parseFloat(parseFloat(txtReDelPrice)*parseFloat(txtReDelQty));if(isNaN(amount)){amount = 0.00;}
		$("#txtTCDelAmount_1_"+i).val(parseFloat(amount).toFixed(2));
	}
	$("#txtTotalTCDelAmount").val($('[id^=txtTCDelAmount_1_]').sum());
	getFinalCalculation();
}
 
 
function getReDelBunkerCalculation()
{
   	var txtREDELID = $("#txtTCREDELID").val();
	for(var i =1;i <=txtREDELID;i++)
	{
		var txtReDelQty      = parseFloat($("#txtTCReDelQty_"+i).val());if(isNaN(txtReDelQty)){txtReDelQty = 0.00;}
		var txtReDelPrice    = parseFloat($("#txtTCReDelPrice_"+i).val());if(isNaN(txtReDelPrice)){txtReDelPrice = 0.00;}
		var amount          =   parseFloat(parseFloat(txtReDelPrice)*parseFloat(txtReDelQty));if(isNaN(amount)){amount = 0.00;}
		$("#txtTCReDelAmount_1_"+i).val(parseFloat(amount).toFixed(2));
	}
	$("#txtTotalTCReDelAmount").val($('[id^=txtTCReDelAmount_1_]').sum());
	getFinalCalculation();
}



function loadPeriodDetails()
{
	

		// console.log('siodufh');
		// console.log(("#selPeriodContract").val());


		$.post("options.php?id=103",{periodid:"<?=$obj->getFun143();?>"}, function(data) 
		{


			// console.log(data);


			var jsondata = JSON.parse(data);
			var period_hire_details = jsondata['period_hire_details'];
			var period_bunker_details = jsondata['period_bunker_details'];
			var period_offhire_details = jsondata['period_offhire_details'];
			var hirenum = jsondata['hirenum'];
			var bunkernum = jsondata['bunkernum'];
			var offhirenum = jsondata['offhirenum'];
			
			// console.log(hirenum);
			$("#TCoffhirebody").empty();
			$("#txtTCOFFID").val(0);
			$("#bunkerTCdelivery,#bunkerTCRedelivery").empty();
			$("#txtTCDELID,#txtTCREDELID").val(0);
			$("#hostTCDIV").empty();
			$("#txtTCHOSTID_1").val(0);
				
			if(offhirenum > 0)
			{
			    $("#TCoffhirebody").empty();
				$("#txtTCOFFID").val(0);
				$.each(period_offhire_details, function(index, array) 
				{
				     AddNewTCOffHire();
					 var txtTCOFFID = $("#txtTCOFFID").val();
					 $("#txtTCOffHireReason_"+txtTCOFFID).val(array['OFF_HIRE_REASON']);
					 $("#txtTCOffHireFrom_"+txtTCOFFID).val(array['OFF_HIRE_FROM']);
					 $("#txtTCOffHireTo_"+txtTCOFFID).val(array['OFF_HIRE_TO']);
					 $("#txtTCOffHireDays_"+txtTCOFFID).val(array['OFF_HIRE_DAYS']);
					 $("#txtTCOffHireRate_"+txtTCOFFID).val(array['OFF_HIRE_RATE']);
					 $("#txtTCOffHireAmt_"+txtTCOFFID).val(array['OFF_HIRE_AMT']);
					 
					 $.each(array['OFF_HIRE_BUNKER'], function(index1, array1) 
				     {
					     addTCConBunkerRow(txtTCOFFID);
						 var txtTCConBunkerCount = $("#txtTCConBunkerCount_"+txtTCOFFID).val();
						 $("#selTCConBunker_"+txtTCOFFID+"_"+txtTCConBunkerCount).val(array1['BUNKERGRADEID']);
						 $("#txtTCConBunkerQty_"+txtTCOFFID+"_"+txtTCConBunkerCount).val(array1['BUNKER_QTY']);
						 $("#txtTCConBunkerPrice_"+txtTCOFFID+"_"+txtTCConBunkerCount).val(array1['BUNKER_PRICE']);
						 $("#txtTCConBunkerAmt_"+txtTCOFFID+"_"+txtTCConBunkerCount).val(array1['BUNKER_AMT']);
						 if(array1['CHK_OWNER_ACCOUNT'] == "1")
						 {
						     $("#ChkOFFHireCal_"+txtTCOFFID+"_"+txtTCConBunkerCount).attr('checked', true);
							 $("#ChkOFFHireCal_"+txtTCOFFID+"_"+txtTCConBunkerCount).iCheck({
								 checkboxClass: 'icheckbox_minimal',
								 radioClass: 'iradio_minimal'
							 });
							 $('[id^=ChkOFFHireCal_]').on('ifChecked', function () { 
							    $(this).attr('checked', true);
								getFinalCalculation();
							 });
							 
							 $('[id^=ChkOFFHireCal_]').on('ifUnchecked', function () { 
							    $(this).attr('checked', false);
							    getFinalCalculation();
							 });
							 
						 }
						 
					 });
					 getFinalCalculation();
				});
			}
			
			if(hirenum > 0)
			{
			    $("#hostTCDIV").empty();
				$("#txtTCHOSTID_1").val(0);
				$.each(period_hire_details, function(index, array) 
				{
				     AddNewTCDivToHost();
					 var txtTCHOSTID = $("#txtTCHOSTID_1").val();

					
					 $("#txtTCDeliveryDate_1_"+txtTCHOSTID).val(array['HIRE_FROM']);
					 $("#txtTCReDeliveryDate_1_"+txtTCHOSTID).val(array['HIRE_TO']);
					 $("#txtTotalVoyageDays_1_"+txtTCHOSTID).val(array['HIRE_DAYS']);
					 $("#txtTCinDailyHire_1_"+txtTCHOSTID).val(array['HIRE_RATE']);
					 $("#txtHireargePercent_1_"+txtTCHOSTID).val(array['ADD_COMM']);
					 
					//  console.log( $("#txtTCDeliveryDate_"+txtTCHOSTID).val(),'sd213')
					
					
					 getFinalCalculation();
				});
			}
			
			if(bunkernum > 0)
			{
			    $("#bunkerTCdelivery,#bunkerTCRedelivery").empty();
				$("#txtTCDELID,#txtTCREDELID").val(0);
				$.each(period_bunker_details, function(index, array) 
				{
				     if(array['IDENTITY']=='DEL')
					 {
						 AddNewTCDel();
						 var txtTCDELID = $("#txtTCDELID").val();
						 $("#selTCDelBunker_1_"+txtTCDELID).val(array['BUNKERGRADEID']);
						 $("#txtTCDelQty_1_"+txtTCDELID).val(array['BUNKER_QTY']);
						 $("#txtTCDelBunDate_1_"+txtTCDELID).val(array['BUNKER_DATE']);
						 $("#txtTCDelPrice_1_"+txtTCDELID).val(array['BUNKER_RATE']);
						 $("#txtTCDelAmount_1_"+txtTCDELID).val(array['BUNKER_AMT']);
						 getDelBunkerCalculation();
					 }
					 if(array['IDENTITY']=='REDEL')
					 {
						 AddNewTCReDel();
						 var txtTCREDELID = $("#txtTCREDELID").val();
						 $("#selTCReDelBunker_1_"+txtTCREDELID).val(array['BUNKERGRADEID']);
						 $("#txtTCReDelQty_1_"+txtTCREDELID).val(array['BUNKER_QTY']);
						 $("#txtTCReDelBunDate_1_"+txtTCREDELID).val(array['BUNKER_DATE']);
						 $("#txtTCReDelPrice_1_"+txtTCREDELID).val(array['BUNKER_RATE']);
						 $("#txtTCReDelAmount_1_"+txtTCREDELID).val(array['BUNKER_AMT']);
						 getReDelBunkerCalculation();
					 }
				});
			}
				
		});  
	
}


function pasteCharteing(){


$.post("options.php?id=117",{ID:""+$('#chartering_pic').val()+"",CHTEAM1:""+$('#chTeam_1').val()+"",CHTEAM2:""+$('#chTeam_2').val()+""}, function(data){


	// var obj = JSON.parse(data);

	$('#chartering_pic_1').html(data)

	// $('#chartering_pic_2').html(data)

	});


	$.post("options.php?id=118",{ID:""+$('#chartering_pic').val()+"",CHTEAM1:""+$('#chTeam_1').val()+"",CHTEAM2:""+$('#chTeam_2').val()+""}, function(data){


		// $('#chartering_pic_1').html(data)

		$('#chartering_pic_2').html(data)

		});


	


}


function markCheckBox(elx){

	$(elx).parent().next().next().next().find('.icheckbox_minimal').addClass("checked");
	$(elx).parent().next().next().next().find('.checkbox').attr("checked",true);
	$(elx).parent().next().next().next().find('.icheckbox_minimal').attr("aria-checked",'true');
	$(elx).parent().next().next().next().find('.checkval').val(1);

}


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