

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
 <link href="content/LoanCalc.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
    <script src="scripts/jquery-1.7.1.js"></script>

    <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
     <script type="text/javascript">
        function graph() {
            $(document).ready(function () {
             //   $('#dvTable').hide()
                installment();
                
                
            });

        }
        function addCommas(amount) {

            var result = amount.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
            return result;
        }
        function removeCommas(amount) {
            var result = amount.toString().replace(/\,/g, '');
            return result;

        }
        function installment() {
            $(document).ready(function () {

                var principle = document.getElementById('txtAmount').value;
                principle = removeCommas(principle);
                document.getElementById('txtAmount').value = addCommas(principle);
                var term = document.getElementById('txtTerm').value;
                var interestRate = document.getElementById('txtInterest').value;
                if (principle != '' && term != '' && interestRate != '') {
                  
                    //caclculated every time for graph
                    var interestRateForMonthlyForGraph = interestRate / 1200;
                    var actTimeForMonthlyForGraph = parseFloat(term) * 12;
                    var installmentForMonthlyForGraph = Math.round(principle * interestRateForMonthlyForGraph / (1 - (Math.pow(1 / (1 + interestRateForMonthlyForGraph), actTimeForMonthlyForGraph))));
                    //document.getElementById('lblInstallment').innerHTML = "Monthly Repayment $" + installmentForMonthlyForGraph.toFixed(2);
                    //document.getElementById('lblInsMonOrFornght').innerHTML ="Repayment  " +" $" + parseFloat(installmentForMonthlyForGraph).toFixed(2);
                    document.getElementById('txtInsMonOrFornght1').value = addCommas(parseFloat(installmentForMonthlyForGraph).toFixed(2));
                    
                    var installment = Math.round(principle * interestRate / (1 - (Math.pow(1 / (1 + interestRate), actTimeForMonthlyForGraph))));
                    document.getElementById('hdnIntall').value = installmentForMonthlyForGraph;
                    callGraph(0);
                    installmentChange();
                    
                }
            });
        }
        function installmentChange() {
            $(document).ready(function () {
                var selectedValue = 1;//document.getElementById('slctInstallment').value;
                if (selectedValue != '0') {

                    var principle = document.getElementById('txtAmount').value;
                    principle = removeCommas(principle)
                    var amount = principle;
                    var openingBalance = parseFloat(amount).toFixed(2);
                    var closingBalance = parseFloat(amount).toFixed(2);
                    document.getElementById('txtAmount').value = addCommas(principle);
                    var term = document.getElementById('txtTerm').value;
                    var interestRate = document.getElementById('txtInterest').value;
                    var intS = parseFloat(interestRate);
                    var selectedValue =1;// document.getElementById('slctInstallment').value;
                    var actTime = 0;
                    var factor = 0;
                    var interest = 0;
                    var installment = 0;
                    if (selectedValue == '1') {

                        interestRate = interestRate / 1200;
                        actTime = parseFloat(term) * 12;
                        factor = 12;

                    }
                    if (selectedValue == '2') {

                        //interestRate = interestRate / 2600;
                        //actTime = parseFloat(term) * 26;
                        //factor = 26;
                        interestRate = interestRate / 2608.8;
                        actTime = parseFloat(term) * 26.088;
                        factor = 26.088;
                    }
                    installment = Math.round(principle * interestRate / (1 - (Math.pow(1 / (1 + interestRate), actTime))));
                    //document.getElementById('lblInsMonOrFornght').innerHTML = "Repayment  "+"$" + addCommas(parseFloat(installment).toFixed(2));
                    
                    document.getElementById('txtInsMonOrFornght1').value=addCommas(parseFloat(installment).toFixed(2));
                    //find new term
                    var upFrontCom = .005;
                    var trailCom = .002;
                    var newTerm = 0;
                    var countInt = 0;
                    var detUpFront = Math.round(parseFloat(amount) * parseFloat(upFrontCom));
                    amount = parseFloat(amount) + 990;
                    var newPriciple = 0;
                    if (selectedValue == "1")
                    { 
                    for (var i = amount; i >= 0;) {
                        if (i == amount) {
                            i = Math.round(parseFloat(amount) - parseFloat(detUpFront));
                        }
                        var interst = Math.round((parseFloat(i) * parseFloat(intS)) / parseFloat(parseFloat(factor * 100)));
                        countInt = parseFloat(interst) + parseFloat(countInt);
                        var pricSide = Math.round((parseFloat(installment)) - parseFloat(interst));
                        i = Math.round(parseFloat(i) - parseFloat(pricSide));
                        var trailComVal = Math.round(parseFloat(i) * parseFloat(trailCom)) / 12;
                        i = parseFloat(i) - parseFloat(trailComVal);
                        newTerm = parseFloat(newTerm) + 1;
                    }
                    }
                        //term for fortnight only
                    else if (selectedValue == "2") {
                        var fortnightcount = 1;
                        for (var i = amount; i >= 0;) {
                            if (i == amount) {
                                i = Math.round(parseFloat(amount) - parseFloat(detUpFront));
                            }
                            var interst = Math.round((parseFloat(i) * parseFloat(intS)) / parseFloat(parseFloat(factor * 100)))
                            countInt = parseFloat(interst) + parseFloat(countInt);
                            var pricSide = Math.round((parseFloat(installment)) - parseFloat(interst))
                            i = Math.round(parseFloat(i) - parseFloat(pricSide));
                            if (fortnightcount == 2) {
                                var trailComVal = Math.round(parseFloat(i) * parseFloat(trailCom)) / 12;
                                i = parseFloat(i) - parseFloat(trailComVal);
                                fortnightcount = 1;
                            }
                            else {
                                fortnightcount = parseFloat(fortnightcount) + 1;
                            }
                            newTerm = parseFloat(newTerm) + 1;

                        }
                    }

                    var actTerm = newTerm;
                    if (selectedValue == "2") {
                        actTerm = Math.round(parseFloat(newTerm) / 2.174);
                        //statement
                        var tableCreate = "";
                        var fortNightCheck = 1;
                        var today = new Date();
                        var stringdate = today.toString();
                        stringdate = stringdate.substring(0, 10);
                        var date = today.getDate();
                        var month = today.getMonth();
                        var monthToDis = month + 1;
                        var year = today.getFullYear();
                        
                        closingBalance = parseFloat(parseFloat(closingBalance) - parseFloat(detUpFront)).toFixed(2)
                        openingBalance = parseFloat(closingBalance).toFixed(2);
                        //fintrackfee
                        closingBalance = parseFloat(parseFloat(openingBalance) + 1980).toFixed(2);
                        openingBalance = parseFloat(closingBalance).toFixed(2);
                        var count = 0;
                        var monthcount = 0;
                        var fortNightCount=0;
                        //fintrackfee
                        for (i = newTerm; i >= 0; i--) {
                            if (amount >= 0) {

                                if (i == newTerm) {
                                    amount = Math.round(parseFloat(amount) - parseFloat(detUpFront));


                                    count++;
                                }
                                else {
                                    fortNightCount = parseFloat(fortNightCount) + 1;
                                    var interst = Math.round((parseFloat(amount) * parseFloat(intS)) / parseFloat(parseFloat(factor * 100)))
                                    interst = parseFloat(interst).toFixed(2)
                                    //newInt = Math.round(parseFloat(newInt) + parseFloat(interst));
                                    var pricSide = Math.round((parseFloat(installment)) - parseFloat(interst))
                                    pricSide = parseFloat(pricSide).toFixed(2)
                                    amount = Math.round(parseFloat(amount) - parseFloat(pricSide))
                                    //row for intallment credit
                                    closingBalance = (parseFloat(amount).toFixed(2));
                                    //set date
                        
                                    openingBalance = parseFloat(closingBalance).toFixed(2);

                                    //monthly trail
                                    if (fortNightCheck == 2) {
                                        monthcount = parseFloat(monthcount) + 1;
                                        var trailComVal = Math.round(parseFloat(amount) * parseFloat(trailCom) / 12);
                                        trailComVal = parseFloat(trailComVal).toFixed(2)
                                        amount = amount - trailComVal;
                        
                                        //row for trail credit
                                        //   trailTotCom = parseFloat(trailTotCom) + parseFloat(trailComVal);
                                        closingBalance = parseFloat(amount).toFixed(2);
                                        openingBalance = closingBalance;
                                        fortNightCheck = 1;
                                    } else {
                                        fortNightCheck =parseFloat(fortNightCheck) + 1;
                                    }
                                    //row for monthly credit ends
                                    count++;
                                }
                            }

                        }
                        //statement
                    }
                    else {

                        callGraph(0);
                    }
                    interest = countInt;
                    var actInt = 0;//document.getElementById('lblOriginalIntrest').innerHTML;
                    //actInt = actInt.replace('$', 0);
                   // actInt = removeCommas(actInt);
                    interest = Math.round(interest);
                    interest = parseFloat(interest).toFixed(2);
                    differentInt = parseFloat(actInt) - parseFloat(interest);
                    differentInt = differentInt.toFixed(2);
                    //document.getElementById('lblCashBachIntest').innerHTML = "$" + addCommas(interest);
                    //document.getElementById('lblInterestSaved').innerHTML = "$" + addCommas(differentInt);
                    var loanWithSavingTotal = parseFloat(principle) + parseFloat(interest);
                    loanWithSavingTotal = parseFloat(loanWithSavingTotal).toFixed(2);
                   // document.getElementById('lblLoanWithSavingTotal').innerHTML = "$" + addCommas(loanWithSavingTotal);
                   // document.getElementById('lblCashBaOffTime').innerHTML =parseFloat(parseFloat(actTerm)/12).toFixed(2) + " years";
                    //calculate time save
                    var fac = parseFloat(term) * 12;
                    var diffTimeF = parseFloat(fac) - parseFloat(actTerm);
                    diffTime = parseFloat(diffTimeF) / 12;
                    var year = diffTime.toString().split(".")[0]; ///before
                    var month = parseFloat(diffTimeF) % 12;
                    //document.getElementById('lblTimeSaved').innerHTML = year + " years " + month + " months"
                    //caculate time save
                    //document.getElementById('lblSaveStatement').innerHTML = "You could save " + "<b style=color:red>$" + addCommas(Math.round(parseFloat(differentInt)).toFixed(2)) + "</b> in interest or<b style=color:red> " + year + ' Years ' + Math.ceil(month) + ' Months' + "</b> with a cash back loan"
                   
                }
            });
        }
        function onlyNumbers(evt) {
            var e = event || evt; // for trans-browser compatibility
            var charCode = e.which || e.keyCode;

            if (charCode != 46 && charCode > 31
              && (charCode < 48 || charCode > 57))
                return false;

            return true;
        }
        $(function() {
            $( "#txtDate" ).datepicker({dateFormat: 'dd/mm/yy'});
          });
        window.onload = graph()
    </script>
</head>
<body style="font-family: Calibri;">
  <input type="hidden" Id="hdnIntall"> 
    <div id="wraper">
       <div class="clear"></div>
          <div class="superbox">
    <div class="topbox">
         <div class="clname1">
   <div class="nme1">
  <h1>Date</h1></div>
  <div class="clear"></div>
  <div class="nmebox1"><input name="txtDate" id="txtDate" type="text" class="mac" style="width: 75px" /></div>
  </div>
   <div class="clname">
   <div class="nme">
  <h1>Given Name</h1></div>
  <div class="clear"></div>
  <div class="nmebox"><input name="txtClientname" id="txtClientname" type="text" class="mac"/></div>
  </div>
    <div class="clname" style="margin-left: 22px;">
   <div class="nme" style="width: 99px;">
  <h1>Surname Name</h1></div>
  <div class="clear"></div>
  <div class="nmebox"><input name="txtClientsurname" id="txtClientsurname" type="text" class="mac"/></div>
  </div><div class="calc" >Calculate</div> <div class="calc" onclick="enablediv(0)">Reset</div>
    <table width="98%" align="center" class="table">
    <tr style="background-color: black;font-size: 18px;">
    <td colspan="5" >Loan Details</td>
    </tr>
    <tr class="thead">
    <td>
     
    </td>
    <td>
    Standard Loan
    </td>
    <td>
    Lender 1
    </td>
    <td>
    Lender 2
    </td>
    <td>
    Lender 3
    </td>
    </tr>
    <tr>
    <td>
    Lender Name
    </td>
    <td>
    
    </td>   
    <td>
    <?php 
  include('config.php');
  $query = "SELECT  id, `lender_name` FROM  `tbllenders` order by `lender_name`";
   // Execute it, or return the error message if there's a problem.
  $result = mysql_query($query) or die(mysql_error());
  $dropdown = "<select name='ddllender1' class='mac' id='ddllender1' style='width: 150px;' ><option value='0'>--Select Lender--</option>";
  $dropdown2 = "<select name='ddllender2' class='mac' id='ddllender2' style='width: 150px;'><option value='0'>--Select Lender--</option>";
  $dropdown3 = "<select name='ddllender3' class='mac' id='ddllender3' style='width: 150px;'><option value='0'>--Select Lender--</option>";
  while($row = mysql_fetch_assoc($result)) {
  	$dropdown .= "\r\n<option value='{$row['id']}'>{$row['lender_name']}</option>";
  	$dropdown2 .= "\r\n<option value='{$row['id']}'>{$row['lender_name']}</option>";
  	$dropdown3 .= "\r\n<option value='{$row['id']}'>{$row['lender_name']}</option>";
  }
  $dropdown .= "\r\n</select>";
  $dropdown2 .= "\r\n</select>";
  $dropdown3 .= "\r\n</select>";
  echo $dropdown;
  
  ?>
    </td>
    <td>
     <?php echo $dropdown2 ?>
    </td>
    <td>
    <?php echo $dropdown3 ?>
    </td>
    </tr>
    <tr>
    <td>
    Interest Rate
    </td>
    <td>
       <input name="Interest" id="txtInterest" type="text" style="width: 30px;" class="mac" onkeypress="return onlyNumbers();" onchange="graph()" value="5">
    </td>
    <td>
       <input id="txtl1Interest" type="text" style="width: 30px;" class="mac" onkeypress="return onlyNumbers();" value="5">
    </td>
    <td>
       <input id="txtl2Interest" type="text" style="width: 30px;" class="mac" onkeypress="return onlyNumbers();" value="5">
    </td>
    <td>
       <input id="txtl3Interest" type="text" style="width: 30px;" class="mac" onkeypress="return onlyNumbers();" value="5">
    </td>
    </tr>
    <tr>
    <td>
    Loan Amount
    </td>
    <td>
       <input name="Amount" id="txtAmount" type="text" style="width: 92px;" class="mac" value="500000" onkeypress="return onlyNumbers();" onchange="graph()">
    </td>
    <td>
       <label id="lbl1la">$0.00</label>
    </td>
    <td>
       <label id="lbl2la">$0.00</label>
    </td>
    <td>
       <label id="lbl3la">$0.00</label>
    </td>
    </tr>
    <tr>
    <td>
    Loan Term (Years)
    </td>
    <td>
       <input name="Term" id="txtTerm" type="text" style="width: 30px;" class="mac" value="30" onkeypress="return onlyNumbers();" onchange="graph()">
    </td>
    <td>
       <label id="lbl1lt">0</label>
    </td>
    <td>
       <label id="lbl2lt">0</label>
    </td>
    <td>
       <label id="lbl3lt">0</label>
    </td>
    </tr>
     <tr>
    <td>
    Repayment
    </td>
    <td>
       <input name="Interest" id="txtInsMonOrFornght1" type="text" style="width: 80px;" class="mac" readonly="">
    </td>
    <td>
       <label id="lbl1mr">$0.00</label>
    </td>
    <td>
       <label id="lbl2mr">$0.00</label>
    </td>
    <td>
       <label id="lbl3mr">$0.00</label>
    </td>
    </tr>
    <tr>
    <td>
    Total P&I
    </td>
     <td>
      <label id="lbotlr">$00.00</label>
    </td>
     <td>
      <label id="lbl1tlr">$00.00</label>
    </td>
     <td>
       <label id="lbl2tlr">$00.00</label>
    </td>
     <td>
       <label id="lbl3tlr">$00.00</label>
    </td>
    </tr>
    <tr>
    <td>
    Total Interest
    </td>
     <td>
      <label id="lboip">$00.00</label>
    </td>
     <td>
      <label id="lbl1ti">$00.00</label>
    </td>
     <td>
       <label id="lbl2ti">$00.00</label>
    </td>
     <td>
       <label id="lbl3ti">$00.00</label>
    </td>
    </tr>
    <tr style="background-color: black;font-size: 18px;">
    <td colspan="5" >Cash Back Details</td>
    </tr>
     <tr>
     <td>
     Commission Upfront $
     </td>
     <td>
     $0
     </td>
     <td>
     <label id="lbl1cup">
     </td>
     <td>
     <label id="lbl2cup">
     </td>
     <td>
     <label id="lbl3cup">
     </td>
     </tr>
      <tr>
     <td>
     Commission Trail $
     </td>
     <td>
     $0
     </td>
     <td>
     <label id="lbl1ctt">
     </td>
     <td>
     <label id="lbl2ctt">
     </td>
     <td>
     <label id="lbl3ctt">
     </td>
     </tr>
        <tr>
     <td>
     Estimated Cash Back
     </td>
     <td>
     $0
     </td>
     <td>
     <label id="lbl1cmt">
     </td>
     <td>
     <label id="lbl2cmt">
     </td>
     <td>
     <label id="lbl3cmt">
     </td>
     </tr>
    </table>
  <div class="clear"></div>
   </div>
    </div> 
        <div class="clear"></div>
          <div id="hearder">
                <div class="topoart">
                 <div class="bckclr">
                 <div class="firstlinelst">
                  <h1>Lender Name</h1>
                  <div class="whiteboxlst" style="width:124px; margin-right:10px;text-align: right;">
                        <label id="lbllender" ></label>
                  </div>
                </div>
                <div class="firstlinebtm">
                  <h1>Interest Saved</h1>
                  <div class="whiteboxbtm">
                        <label id="lblInstsaved">$000000</label>
                  </div>
                </div>
                 </div>
                  <div class="firstline00" id="divExport">
                    <h1>Export to PDF</h1>
                    <div class="whitebox001">
                  <p style="margin:0px; padding:0px; float:left;">
            <input type="image" src="pdf-icon.png" alt="Save as PDF" id="buttonExport"  width="45px" height="51px"/>
            </p></div>
                </div>
                <div style="float: right; padding-left: 5px; font-size: 10pt;  color: white;  padding-bottom: 4px;">Send as Attachment <input type="checkbox" id="chkemail"></div>
            </div>
        </div>
          <div class="graph">
          <div id="container" style="width:98%; border-radius:10px;"></div>
     </div>
     <!--
        <div class="textarea textarea-small">
            <div class="nav">
                <h1>Export to PDF</h1>
            </div>
            <p>
            <input type="image" src="pdf-icon.png" alt="Save as PDF" id="buttonExport"  width="45px" height="55px"/>
            </p>
        </div>
         -->
        
        
<div class="textarea" style="height: 185px;">
            <div class="nav">
                <h1>Disclaimer</h1>
            </div>
            <p>
               This is an illustration of potential interest savings only and assumes average levels of commission payments available from our Lenders as they advise from time to time. Interest costs have been rounded to the nearest whole dollar. Your individual interest savings may be more or less than the results shown here. The modeled outcomes are valid only for the inputs shown and assume interest rates remain constant and that you maintain your loan in good standing and pay minimum scheduled payments. No attempt has been made to analyse costs associated with switching Lenders including discharge fees, applications fees, or Lender's Mortgage Insurance. This is not a recommendation or offer of finance. You should not make a decision to refinance any loan or to engage our services based purely on this illustrated calculation. Should detail of your particular situation be wrong or have changed please contact us so that we may reassess and provide a more accurate illustration.
            </p>
        </div>
</div>
<input type="hidden" id="hduf" value="0">
<input type="hidden" id="hdt1" value="0">
<input type="hidden" id="hdt2" value="0">
<input type="hidden" id="hdt3" value="0">
<input type="hidden" id="hdt4" value="0">
<input type="hidden" id="hdt5" value="0">
    <script type="text/javascript">
    var name='',uf=0,t1=0,t2=0,t3=0,t4=0,t5=0;
    function BestLoan(xArray,yArray){

    	Array.min = function( array ){
    	    return Math.min.apply( Math, array );
    	};
    	var min = Array.min(xArray);
    	var index = xArray.indexOf(min) ;
    	var n,m;
   	     n = yArray[index];
   	     m = min;

 	     return [n,m];
	}
    function getsavingsdata()
    {
    	
    	
    	 
    	var v1,v2,v3;
    	var oip;
    	v1 = removeCommas($("#lbl1ti").text());
    	v1 = v1.substring(1,v1.length);
    	v2 = removeCommas($("#lbl2ti").text());
    	v2 = v2.substring(1,v2.length);
    	v3 = removeCommas($("#lbl3ti").text());
    	v3 = v3.substring(1,v3.length);
    	oip = removeCommas($("#lboip").text());
    	oip = oip.substring(1,oip.length);

    	oip = parseFloat(oip);
    	v1 = parseFloat(v1);
    	v2 = parseFloat(v2);
    	v3 = parseFloat(v3);
    	var result;
        if(v1!=0 & v2!=0 & v3!=0)
        {
        	
    	   result= BestLoan([v1,v2,v3],['v1','v2','v3']);
        }
        else if (v1!=0 & v2!=0 & v3==0)
        {
        	result= BestLoan([v1,v2],['v1','v2']);
        } 
        else if (v1!=0 & v2==0 & v3!=0)
        {
        	result= BestLoan([v1,v3],['v1','v3']);
        }
        else if (v1==0 & v2!=0 & v3!=0)
        {
        	result= BestLoan([v2,v3],['v2','v3']);
        }
        else if (v1==0 & v2==0 & v3!=0)
        {
            result =["v3",v3];
        }
        else if (v1==0 & v2!=0 & v3==0)
        {
            result =["v2",v2];
        }
        else if (v1!=0 & v2==0 & v3==0)
        {
            result =["v1",v1];
        }
        else if (v1==0 & v2==0 & v3==0)
        {
            return;
        }
        
    	if(result[0]=="v1")
    	{
        	var saveint=0;
        	saveint = oip - parseFloat(result[1]);
    	  	$("#lbllender").text($("#ddllender1 option:selected").text());
    	  	$("#lblInstsaved").text("$" + addCommas(saveint.toFixed(2)));
        }
    	else if (result[0]=="v2")
    	{
    		var saveint=0;
        	saveint = oip - parseFloat(result[1]);
    		$("#lbllender").text($("#ddllender2 option:selected").text()); 
    		$("#lblInstsaved").text("$" + addCommas(saveint.toFixed(2)));
        }
    	else if (result[0] == "v3")
    	{
    		var saveint=0;
        	saveint = oip - parseFloat(result[1]);
        	$("#lblInstsaved").text("$" + addCommas(saveint.toFixed(2)));
    		$("#lbllender").text($("#ddllender3 option:selected").text());
		}
        
    }
    
    function enablediv(id)
    {
        var name="";
             name = $("#ddllender1 option:selected").text();
             var chart = $('#container').highcharts();

         	for (var i = 0; i < chart.series.length; i++) {
         	         if(chart.series[i].name==name)
         	         {
         	              chart.series[i].remove();
     	                      break;
         	         } 
         	      }
            $("#ddllender1").val(0);
        	$("#ddllender1").removeAttr("disabled");
        	$("#txtl1Interest").removeAttr("disabled");
        	//$("#ld1").html("<div class='nav3'><h1>Lender 1</h1></div>"); 
        	$("#lbl1cup").text("$0.00");
        	$("#lbl1ctt").text("$0.00");
        	$("#lbl1cmt").text("$0.00"); 
        	$("#lbl1la").text("$0.00");
        	$("#lbl1mr").text("$0.00");
        	$("#lbl1ir").text("");
        	$("#lbl1ti").text("$0.00");
        	$("#lbtl1lr").text("$0.00");
        	$("#lbl1lt").text("0");
        	$("#lbl2lt").text("0");
        	$("#lbl3lt").text("0");
        	$("#lbl1tlr").text("$0.00");
        	$("#lbl2tlr").text("$0.00");
        	$("#lbl3tlr").text("$0.00");
        
        	name = $("#ddllender2 option:selected").text();
            $("#ddllender2").val(0);
        	$("#ddllender2").removeAttr("disabled");
        	$("#txtl2Interest").removeAttr("disabled");
        	//$("#ld2").html("<div class='nav3'><h1>Lender 2</h1></div>");
        	$("#lbl2cup").text("$0.00");
        	$("#lbl2ctt").text("$0.00");
        	$("#lbl2cmt").text("$0.00"); 
        	$("#lbl2la").text("$0.00");
        	$("#lbl2mr").text("$0.00");
        	$("#lbl2ir").text("");
        	$("#lbl2ti").text("$0.00");
        	$("#lbt21lr").text("$0.00");

        	for (var i = 0; i < chart.series.length; i++) {
    	         if(chart.series[i].name==name)
    	         {
    	              chart.series[i].remove();
	                      break;
    	         } 
    	      }
            
        	name = $("#ddllender3 option:selected").text();
            $("#ddllender3").val(0);
        	$("#ddllender3").removeAttr("disabled");
        	$("#txtl3Interest").removeAttr("disabled");
        	$("#ld3").html("<div class='nav3'><h1>Lender 3</h1></div>");
        	$("#lbl3cup").text("$0.00");
        	$("#lbl3ctt").text("$0.00");
        	$("#lbl3cmt").text("$0.00"); 
        	$("#lbl3la").text("$0.00");
        	$("#lbl3mr").text("$0.00");
        	$("#lbl3ir").text("");
        	$("#lbl3ti").text("$0.00");
        	$("#lbt31lr").text("$0.00");

        	for (var i = 0; i < chart.series.length; i++) {
    	         if(chart.series[i].name==name)
    	         {
    	              chart.series[i].remove();
	                      break;
    	         } 
    	      }
    }
    
    $("#ddllender1").change(function(){
    	GetLenderDetails($('#ddllender1 option:selected').val() ,$('#ddllender1 option:selected').text());
    	uf= parseFloat($("#hduf").val());
    	t1= parseFloat($("#hdt1").val());
    	t2= parseFloat($("#hdt2").val());
    	t3= parseFloat($("#hdt3").val());
    	t4= parseFloat($("#hdt4").val());
    	t5= parseFloat($("#hdt5").val());
    	$("#lbl1lt").text($("#txtTerm").val());
    	name=$("#ddllender1 option:selected").text();
    	AddNewChartData(name,uf,t1,t2,t3,t4,t5,'cb1');
    	$("#ddllender1").attr("disabled","true");
    	$("#txtl1Interest").attr("disabled","true");
    	getsavingsdata();
    	});  
    $("#ddllender2").change(function(){
    	GetLenderDetails($('#ddllender2 option:selected').val() ,$('#ddllender2 option:selected').text());
    	uf= parseFloat($("#hduf").val());
    	t1= parseFloat($("#hdt1").val());
    	t2= parseFloat($("#hdt2").val());
    	t3= parseFloat($("#hdt3").val());
    	t4= parseFloat($("#hdt4").val());
    	t5= parseFloat($("#hdt5").val());
    	name=$("#ddllender2 option:selected").text();
    	$("#lbl2lt").text($("#txtTerm").val());
    	AddNewChartData(name,uf,t1,t2,t3,t4,t5,'cb2');
    	$("#ddllender2").attr("disabled","true");
    	$("#txtl2Interest").attr("disabled","true");
    	getsavingsdata();
    	});  
    $("#ddllender3").change(function(){
    	GetLenderDetails($('#ddllender3 option:selected').val() ,$('#ddllender3 option:selected').text());
    	uf= parseFloat($("#hduf").val());
    	t1= parseFloat($("#hdt1").val());
    	t2= parseFloat($("#hdt2").val());
    	t3= parseFloat($("#hdt3").val());
    	t4= parseFloat($("#hdt4").val());
    	t5= parseFloat($("#hdt5").val());
    	name=$("#ddllender3 option:selected").text();
    	$("#lbl3lt").text($("#txtTerm").val());
    	AddNewChartData(name,uf,t1,t2,t3,t4,t5,'cb3');
    	$("#ddllender3").attr("disabled","true");
    	$("#txtl3Interest").attr("disabled","true");
    	getsavingsdata();
    	});  
        function callGraph(Newterm) {
            $(document).ready(function () {
                var prevInt = 0;
                var newInt = 0;
                var amount = document.getElementById('txtAmount').value;
                amount = removeCommas(amount);
                var openingBalance = parseFloat(amount).toFixed(2);
                var closingBalance = parseFloat(amount).toFixed(2);
                var term = document.getElementById('txtTerm').value;
                var interestRate = document.getElementById('txtInterest').value;
                var firstInstall = document.getElementById('txtInsMonOrFornght1').value;
                firstInstall = removeCommas(firstInstall);
                firstInstall = parseFloat(firstInstall).toFixed(2);
                var Points = [];
                var i, count = 0;
                var totalIntrpaid = 0;
                var trailTotCom = 0;
                var today = new Date();
                var stringdate = today.toString();
                stringdate = stringdate.substring(0, 10);
                var date = today.getDate();
                var month = today.getMonth();
                var monthToDis = month + 1;
                var year = today.getFullYear();
                var fac = Math.ceil(parseFloat(term) * 12);
                for (i = fac; i >= 0; i--) {
                    if (amount >= 0) {
                        if (i == fac) {
                            Points.push([count, parseFloat(amount)]);
                            count++;
                        }
                        else {
                            var interst = (parseFloat(amount) * parseFloat(interestRate)) / 1200;
                            totalIntrpaid = totalIntrpaid + interst;
                            prevInt = Math.round(parseFloat(prevInt) + parseFloat(interst));
                            var pricSide = (parseFloat(firstInstall)) - parseFloat(interst);
                            amount = Math.round(parseFloat(amount) - parseFloat(pricSide));
                            amount= parseFloat(amount).toFixed(2);
                            if (amount <= 0) {
                                Points.push([count, 0]);
                                break;

                            }
                            if(count==fac)
                            {
                            	Points.push([count, parseFloat(0)]);	
                            }
                            else
                            {
                            Points.push([count, parseFloat(amount)]);
                            }
                            count++;
                        }
                    }

                }
                $("#lboip").text("$" + addCommas(parseFloat(totalIntrpaid).toFixed(2)));
                var tterm= parseFloat(fac / 12).toFixed(2);
                $("#lbopot").text( tterm + " Years");
                var tlr =parseFloat(firstInstall) * fac;
                $("#lbotlr").text("$" + addCommas(parseFloat(tlr).toFixed(2)));
                $("#lbola").text("$" +document.getElementById('txtAmount').value);
                $("#lborp").text("$" +addCommas(parseFloat(firstInstall).toFixed(2)));
                
                count = 0;
               
                //closingBalance = parseFloat(parseFloat(amount) - parseFloat(detUpFront)).toFixed(2);
                openingBalance = parseFloat(closingBalance).toFixed(2);
                amount = document.getElementById('txtAmount').value;
                amount = removeCommas(amount);
               
                //..............Savings
                //principal
              
                amount = parseFloat(amount).toFixed(2);

               
                //..............Savings 
                window.chart = new Highcharts.Chart({
                    chart: {
                        renderTo: 'container',
                        type: 'line'
                    },
                    title: {
                        text: 'LOAN ASSESSMENT WITH CASH BACK'
                    },
                    subtitle: {

                    },
                    xAxis: {
                        title: {
                            text: 'Time (Years)'
                        },
                        labels: {
                            formatter: function () {

                                return this.value / 12 + ' years';
                            }

                        },
                        showLastLabel: true,
                        tickInterval: 60
                    },
                    yAxis: {
                        min:0,
                        title: {
                            text: 'Loan Balance($)'
                        },
                        labels: {
                            formatter: function () {

                                return '$'+this.value;
                            }
                        }
                    },
                    tooltip: {
                        // pointFormat: '<b>${point.y:,.0f}</b><br/>  in {point.x} Months'
                        formatter: function () {
                            return '<b>Remaining $' + this.point.y + ' in </b><br/><b>' + this.point.x + ' months<b/>';
                        }
                    },
                    plotOptions: {

                        area: {

                            pointStart: parseFloat(amount).toFixed(2),
                            marker: {
                                enabled: false,
                                symbol: 'circle',
                                radius: 1,
                                states: {
                                    hover: {
                                        enabled: true

                                    }
                                }
                            }
                        }
                    },
                    series: [{
                        name: 'Standard Loan',
                        data: Points
                    }],
                    exporting: {
                        enabled: false
                    }
                });
                
                $('#buttonExport').click(function () {
                	var imageURL = '';
                	var svg = chart.getSVG();
                	var dataString = 'type=image/jpeg&filename=results&width=500&svg='+svg;
                	$.ajax({
                	    type: 'POST',
                	    data: dataString,
                	    url: 'http://fintrack.com.au/loancal/export/',
                	    async: false,
                	    success: function(data){
                	        imageURL = data;
                	        
							var blender = $("#lbllender").text();
							var intsaved = $("#lblInstsaved").text();
							var client =  $("#txtClientname").val() + ' ' + $("#txtClientsurname").val();
							var date = $("#txtDate").val();
							var la = $("#txtAmount").val(); 
							var lt = $("#txtTerm").val() ;
							var lir = $("#txtInterest").val() ;
							var oip  = $("#lboip").text();
							var otlr = $("#lbotlr").text();
							var repayment = $("#txtInsMonOrFornght1").val();
                            var l1n = $("#ddllender1 option:selected").text();
                            var l1ir = $("#txtl1Interest").val();
                            var l1repay = $("#lbl1mr").text() ;
                            var l1totalpi = $("#lbl1tlr").text() ;
                            var l1totali = $("#lbl1ti").text() ;
                            var l1cup = $("#lbl1cup").text()  ;
                            var l1ct = $("#lbl1ctt").text() ;
                            var l1totcom = $("#lbl1cmt").text() ;

                            var l2n = $("#ddllender2 option:selected").text();
                            var l2ir = $("#txtl2Interest").val();
                            var l2repay = $("#lbl2mr").text() ;
                            var l2totalpi = $("#lbl2tlr").text() ;
                            var l2totali = $("#lbl2ti").text() ;
                            var l2cup = $("#lbl2cup").text()  ;
                            var l2ct = $("#lbl2ctt").text() ;
                            var l2totcom = $("#lbl2cmt").text() ;

                            var l3n = $("#ddllender3 option:selected").text();
                            var l3ir = $("#txtl3Interest").val();
                            var l3repay = $("#lbl3mr").text() ;
                            var l3totalpi = $("#lbl3tlr").text() ;
                            var l3totali = $("#lbl3ti").text() ;
                            var l3cup = $("#lbl3cup").text()  ;
                            var l3ct = $("#lbl3ctt").text() ;
                            var l3totcom = $("#lbl3cmt").text() ;
                            
                	        var qstring = "?img=" + imageURL+"&blender=" + blender + "&intsaved=" + intsaved + "&client=" + client + "&date=" + date;
                	        qstring = qstring + "&la=" + la + "&lt=" + lt + "&lir=" + lir + "&repayment=" + repayment + "&oip=" + oip + "&otlr=" + otlr;
                	        qstring = qstring + "&l1n=" + l1n + "&l1ir=" + l1ir + "&l1repay=" + l1repay + "&l1totalpi="+ l1totalpi + "&l1totali=" + l1totali;
                	        qstring = qstring + "&l1cup=" + l1cup + "&l1ct=" + l1ct + "&l1totcom=" + l1totcom;
                	        qstring = qstring + "&l2n=" + l2n + "&l2ir=" + l2ir + "&l2repay=" + l2repay + "&l2totalpi="+ l2totalpi + "&l2totali=" + l2totali;
                	        qstring = qstring + "&l2cup=" + l2cup + "&l2ct=" + l2ct + "&l2totcom=" + l2totcom;
                	        qstring = qstring + "&l3n=" + l3n + "&l3ir=" + l3ir + "&l3repay=" + l3repay + "&l3totalpi="+ l3totalpi + "&l3totali=" + l3totali;
                	        qstring = qstring + "&l3cup=" + l3cup + "&l3ct=" + l3ct + "&l3totcom=" + l3totcom ;	

                            if($("#chkemail").attr("checked")=="checked")
                            {
                            	window.open('/loancal/tcpdf/examples/rhexportemail.php' + qstring,"_blank");
                            }
                            else
                            {
                	        window.open('/loancal/tcpdf/examples/rhexport.php' + qstring,"_blank");
                            }
                	    }
                	});
                });
            });
        }
		function GetLenderDetails(lender,name)
		{
			
			var dataString = 'id='+ lender;
			//var tabledata='<div class="nav3"><h1>'+ name +'</h1></div><table style="margin:0 auto;width:180px">';
			
			$.ajax({
        	    type: 'POST',
        	    data: dataString,
        	    url: 'lenderdetails.php',
        	    async: false,
        	    success: function(data){
        	    	data = $.parseJSON(data);
        	    	jQuery.each(data, function(i, val) {
            	    	    $("#hduf").val(val.upfront);
            	    	    $("#hdt1").val(val.trail1);
            	    	    $("#hdt2").val(val.trail2);
            	    	    $("#hdt3").val(val.trail3);
            	    	    $("#hdt4").val(val.trail4);
            	    	    $("#hdt5").val(val.trail5);
        	    		   // tabledata = tabledata + '<tr><td style="font-weight: bold;"> Upfront </td><td><label id="lbuf" value="' + val.upfront + '">' + val.upfront + '</label>%</td></tr>' ;
        	    		   // tabledata = tabledata + '<tr><td style="font-weight: bold;"> Trail Year 1 </td><td><label id="lbt1" value="' + val.trail1 + '">' + val.trail1 + '</label>%</td></tr>' ;
        	    		   // tabledata = tabledata + '<tr><td style="font-weight: bold;"> Trail Year 2 </td><td><label id="lbt2" value="' + val.trail2 + '">' + val.trail2 + '</label>%</td></tr>' ;
        	    		   // tabledata = tabledata + '<tr><td style="font-weight: bold;"> Trail Year 3 </td><td><label id="lbt3" value="' + val.trail3 + '">' + val.trail3 + '</label>%</td></tr>' ;
        	    		   // tabledata = tabledata + '<tr><td style="font-weight: bold;"> Trail Year 4 </td><td><label id="lbt4" value="' + val.trail4 + '">' + val.trail4 + '</label>%</td></tr>' ;
        	    		   // tabledata = tabledata + '<tr><td style="font-weight: bold;"> Trail Year 5~30</td><td><label id="lbt5" value="' + val.trail5 + '">' + val.trail5 + '</label>%</td></tr>' ;
        	    			 //$('body').addClass("loading"); 
        	    		    // AddNewChartData(name,val.upfront,val.trail1,val.trail2,val.trail3,val.trail4,val.trail5);
        	    			 //$('body').removeClass("loading"); 
			 		});
        	    	//tabledata = tabledata + '</table>';
        	    }
			});
			return "";
		}

		function AddNewChartData(name,uf,t1,t2,t3,t4,t5,divid)
		{
		    var chart = $('#container').highcharts();
		    var Points = [];
		  Points= GetMonthlyCalculation(uf,t1,t2,t3,t4,t5,divid);
		    
		    chart.addSeries({
	            name: name,
	            data: Points
	        });
		}

		function GetMonthlyCalculation(uf,t1,t2,t3,t4,t5,divid)
		{
			var Points = [];
			 var amount = document.getElementById('txtAmount').value;
             amount = removeCommas(amount);
             amount = parseFloat(amount) + 990; // Adding Fintrack Fee
             var openingBalance = parseFloat(amount).toFixed(2);
             var closingBalance = parseFloat(amount).toFixed(2);
             var term = document.getElementById('txtTerm').value;
             var detUpFront = Math.round(parseFloat(amount) * parseFloat(uf/100));
             var interestRate = document.getElementById('txtInterest').value;
             if(divid=='cb1')
             {
            	 interestRate = document.getElementById('txtl1Interest').value;
            	 $("#lbl1cup").text("$" + addCommas(detUpFront.toFixed(2))); 
             } else if (divid=='cb2')
             {
            	 interestRate = document.getElementById('txtl2Interest').value;
            	 $("#lbl2cup").text("$" +addCommas(detUpFront.toFixed(2)));
                 }  else if(divid=='cb3')
             {
            	 interestRate = document.getElementById('txtl3Interest').value;
            	 $("#lbl3cup").text("$" +addCommas(detUpFront.toFixed(2)));
             }
             
             
             var factor = 12;	
                      
             var fac = Math.ceil(parseFloat(term) * factor);
             var calintrest =  interestRate/1200;
             var firstInstall = Math.round(amount * parseFloat(calintrest) / (1 - (Math.pow(1 / (1 + parseFloat(calintrest)), fac))));
             //firstInstall = removeCommas(firstInstall);
             firstInstall = parseFloat(firstInstall).toFixed(2);     
             
             //Loop to calculate new term 
             var count=0;
             var countInt=0;
             var newTerm=0;
             var totalTrail=0;
             var trailComVal=0;
             for (var i = amount; i >= 0;) {
                 
                 if (i == amount) {
                	 Points.push([count,parseFloat(amount)]);
                     i = Math.round(parseFloat(amount) - parseFloat(detUpFront));
                     Points.push([count,parseFloat(i)]);
                 }
                 if(count <=12)
                 {
                	 var interst = Math.round((parseFloat(i) * parseFloat(interestRate)) / parseFloat(parseFloat(factor * 100)));
                     countInt = parseFloat(interst) + parseFloat(countInt);
                     var pricSide = Math.round((parseFloat(firstInstall)) - parseFloat(interst));
                     i = Math.round(parseFloat(i) - parseFloat(pricSide));
                     if(i<=0)
                     {
                    	 Points.push([count,0]);
                    	 break;
                      }
                     trailComVal = Math.round(parseFloat(i) * parseFloat(t1/100)) / 12;
                     totalTrail = parseFloat(totalTrail) + parseFloat(trailComVal);
                     i = parseFloat(i) - parseFloat(trailComVal);
                     if(i<=0)
                     {
                    	 Points.push([count,0]);
                    	 break;
                      }
                     Points.push([count,parseFloat(i)]);
                  }
                 else if(count>12 && count<=24)
                 {
                     var interst = Math.round((parseFloat(i) * parseFloat(interestRate)) / parseFloat(parseFloat(factor * 100)));
                     countInt = parseFloat(interst) + parseFloat(countInt);
                     var pricSide = Math.round((parseFloat(firstInstall)) - parseFloat(interst));
                     i = Math.round(parseFloat(i) - parseFloat(pricSide));
                     if(i<=0)
                     {
                    	 Points.push([count,0]);
                    	 break;
                      }
                     trailComVal = Math.round(parseFloat(i) * parseFloat(t2/100)) / 12;
                     totalTrail = parseFloat(totalTrail) + parseFloat(trailComVal);
                     i = parseFloat(i) - parseFloat(trailComVal);
                     if(i<=0)
                     {
                    	 Points.push([count,0]);
                    	 break;
                      }
                     Points.push([count,parseFloat(i)]);
                 }
                 else if(count>24 && count <=36)
                 {
                	 var interst = Math.round((parseFloat(i) * parseFloat(interestRate)) / parseFloat(parseFloat(factor * 100)));
                     countInt = parseFloat(interst) + parseFloat(countInt);
                     var pricSide = Math.round((parseFloat(firstInstall)) - parseFloat(interst));
                     i = Math.round(parseFloat(i) - parseFloat(pricSide));
                     if(i<=0)
                     {
                    	 Points.push([count,0]);
                    	 break;
                      }
                     trailComVal = Math.round(parseFloat(i) * parseFloat(t3/100)) / 12;
                     totalTrail = parseFloat(totalTrail) + parseFloat(trailComVal);
                     i = parseFloat(i) - parseFloat(trailComVal);
                     if(i<=0)
                     {
                    	 Points.push([count,0]);
                    	 break;
                      }
                     Points.push([count,parseFloat(i)]);
                 }
                 else if(count>36 && count <=48)
                 {
                	 var interst = Math.round((parseFloat(i) * parseFloat(interestRate)) / parseFloat(parseFloat(factor * 100)));
                     countInt = parseFloat(interst) + parseFloat(countInt);
                     var pricSide = Math.round((parseFloat(firstInstall)) - parseFloat(interst));
                     i = Math.round(parseFloat(i) - parseFloat(pricSide));
                     if(i<=0)
                     {
                    	 Points.push([count,0]);
                    	 break;
                      }
                     trailComVal = Math.round(parseFloat(i) * parseFloat(t4/100)) / 12;
                     totalTrail = parseFloat(totalTrail) + parseFloat(trailComVal);
                     i = parseFloat(i) - parseFloat(trailComVal);
                     if(i<=0)
                     {
                    	 Points.push([count,0]);
                    	 break;
                      }
                     Points.push([count,parseFloat(i)]);
                 }
                 else if(count>48)
                 { 
                	 
                 var interst = Math.round((parseFloat(i) * parseFloat(interestRate)) / parseFloat(parseFloat(factor * 100)));
                 countInt = parseFloat(interst) + parseFloat(countInt);
                 var pricSide = Math.round((parseFloat(firstInstall)) - parseFloat(interst));
                 i = Math.round(parseFloat(i) - parseFloat(pricSide));
                 if(i<=0)
                 {
                	 Points.push([count,0]);
                	 break;
                  }
                 trailComVal = Math.round(parseFloat(i) * parseFloat(t5/100)) / 12;
                 totalTrail = parseFloat(totalTrail) + parseFloat(trailComVal);
                 i = parseFloat(i) - parseFloat(trailComVal);
                 if(i<=0)
                 {
                	 Points.push([count,0]);
                	 break;
                  }
                 Points.push([count,parseFloat(i)]);
                 }

                 count ++;
             }
            
             $('#lblCashBachIntest').text(addCommas(parseFloat(countInt).toFixed(2)));
             $('#hdnl1Term').val(count);
             $('#hdnl1Saving').val(count);
             var trm = count/12;
             if(divid=='cb1')
             {
            	 $("#lbl1ctt").text("$" +addCommas(totalTrail.toFixed(2)));
                 var tcomm = parseFloat(totalTrail) + parseFloat(detUpFront);
                 $("#lbl1cmt").text("$" +addCommas(tcomm.toFixed(2)));
            	 $("#lbl1la").text("$" + document.getElementById('txtAmount').value);
            	 $("#lbl1mr").text("$" + addCommas(firstInstall));
            	 $("#lbl1ir").text(interestRate + " %");
            	 $("#lbl1ti").text("$" + addCommas(parseFloat(countInt).toFixed(2)));
            	 $("#lbl1tlr").text("$" + addCommas(parseFloat(count * firstInstall).toFixed(2)));
            	
             } else if (divid=='cb2')
             {
            	 $("#lbl2ctt").text("$" + addCommas(totalTrail.toFixed(2)));
                 var tcomm = parseFloat(totalTrail) + parseFloat(detUpFront);
                 $("#lbl2cmt").text("$" + addCommas(tcomm.toFixed(2)));
            	 $("#lbl2la").text("$" + document.getElementById('txtAmount').value);
            	 $("#lbl2mr").text("$" + addCommas(firstInstall));
            	 $("#lbl2ir").text(interestRate + " %");
            	 $("#lbl2ti").text("$" + addCommas(parseFloat(countInt).toFixed(2)));
            	 $("#lbl2tlr").text("$" + addCommas(parseFloat(count * firstInstall).toFixed(2)));
             }  else if(divid=='cb3')
             {
            	 $("#lbl3ctt").text("$" + addCommas(totalTrail.toFixed(2)));
                 var tcomm = parseFloat(totalTrail) + parseFloat(detUpFront);
                 $("#lbl3cmt").text("$" + addCommas(tcomm.toFixed(2)));
            	 $("#lbl3la").text("$" + document.getElementById('txtAmount').value);
            	 $("#lbl3mr").text("$" + addCommas(firstInstall));
            	 $("#lbl3ir").text(interestRate + " %");
            	 $("#lbl3ti").text("$" + addCommas(parseFloat(countInt).toFixed(2)));
            	 $("#lbl3tlr").text("$" + addCommas(parseFloat(count * firstInstall).toFixed(2)));
             }
             return Points; // Array of Values for chart binding
		}
  </script>
    <script type="text/javascript" src="scripts/highcharts.js"></script>
    <script type="text/javascript" src="scripts/highcharts-more.js"></script>
    <script type="text/javascript" src="scripts/exporting.js"></script>
</body>
</html>