Adding 2 more disocunt option to the existing code

Hi,

The below code currently calculates the school fees by applying a 10.5% discount for the siblings. No Sibling discount on the first child or child in the highest grade. 10% Sibling discount only eligible for the 2nd Child, 13.5% Sibling discount only eligible for the 3rd Child, 20% Sibling discount only eligible for the 4th Child or more per family who study at our college

<html lang="en-gb" dir="ltr">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    <base href="https://test.edu" />
    <meta name="description" content="test" />
    <meta name="generator" content="Joomla! - Open Source Content Management" />
    <title>Home</title>
    <meta name="copyright" content="Test Edu">
    <link href="/templates/flex/images/favicon.ico" rel="shortcut icon" type="image/vnd.microsoft.icon" />
	<link href="http://test.edu/index.php/component/search/?Itemid=101&amp;id=64:fees-calculator&amp;format=opensearch" rel="search" title="Search ICB test" type="application/opensearchdescription+xml" />
	<link href="//fonts.googleapis.com/css?family=Open+Sans:300,300italic,regular,italic,600,600italic,700,700italic,800,800italic&amp;subset=latin,latin-ext" rel="stylesheet" type="text/css" />
	<link href="//fonts.googleapis.com/css?family=Raleway:100,100italic,200,200italic,300,300italic,regular,italic,500,500italic,600,600italic,700,700italic,800,800italic,900,900italic&amp;subset=latin" rel="stylesheet" type="text/css" />
	<link href="/templates/flex/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
	<link href="/templates/flex/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
	<link href="/templates/flex/css/legacy.css" rel="stylesheet" type="text/css" />
	<link href="/templates/flex/css/template.css" rel="stylesheet" type="text/css" />
	<link href="/templates/flex/css/presets/preset1.css" rel="stylesheet" type="text/css" class="preset" />
	<link href="/components/com_virtuemart/assets/css/jquery.fancybox-1.3.4.css?vmver=d5774e2d" rel="stylesheet" type="text/css" />
	<link href="/components/com_virtuemart/assets/css/vm-ltr-common.css?vmver=d5774e2d" rel="stylesheet" type="text/css" />
	<link href="/components/com_virtuemart/assets/css/vm-ltr-site.css?vmver=d5774e2d" rel="stylesheet" type="text/css" />
	<link href="/components/com_virtuemart/assets/css/vm-ltr-reviews.css?vmver=d5774e2d" rel="stylesheet" type="text/css" />
	<style type="text/css">
body.site {background-color:#ffffff;}
body{font-family:Open Sans, sans-serif; font-size:15px; font-weight:normal; }
h1{font-family:Raleway, sans-serif; font-size:40px; font-weight:100; }
h2{font-family:Raleway, sans-serif; font-size:33px; font-weight:300; }
h3{font-family:Raleway, sans-serif; font-size:27px; font-weight:normal; }
h4{font-family:Raleway, sans-serif; font-size:23px; font-weight:normal; }
h5{font-family:Raleway, sans-serif; font-size:20px; font-weight:500; }
h6{font-family:Raleway, sans-serif; font-size:17px; font-weight:600; }
.sp-megamenu-parent{font-family:Open Sans, sans-serif; font-size:15px; font-weight:normal; }
#sp-top-bar{ background-color:#3d3d3d;color:#d4d4d4;padding:5px 0 4px; }
#sp-top-bar a{color:#b3b3b3;}
#sp-top-bar a:hover{color:#d1d1d1;}
#sp-header{ background-color:#303030;color:#f0f0f0; }
#sp-header a{color:#ededed;}
#sp-header a:hover{color:#ffffff;}
#sp-footer{ background-color:#363839;color:#b0b0b0; }
#sp-footer a{color:#d6d6d6;}
#sp-footer a:hover{color:#f0f0f0;}
.offcanvas-menu{}.offcanvas-menu ul li a{color: }.offcanvas-menu .offcanvas-inner .search input.inputbox{border-color: }
#sp-header .top-search-wrapper .icon-top-wrapper,#sp-header .top-search-wrapper .icon-top-wrapper >i:before,.sp-megamenu-wrapper > .sp-megamenu-parent >li >a,.sp-megamenu-wrapper #offcanvas-toggler,#sp-header .modal-login-wrapper span,#sp-header .ap-my-account i.pe-7s-user,#sp-header .ap-my-account .info-text,#sp-header .mod-languages,.logo,#cart-menu,#cd-menu-trigger,.cd-cart,.cd-cart > i{height:90px;line-height:90px;}.total_products{top:calc(90px / 2 - 22px);}#sp-header,.transparent-wrapper{height:90px;}.transparent,.sticky-top{}#sp-header #sp-menu .sp-megamenu-parent >li >a,#sp-header #sp-menu .sp-megamenu-parent li .sp-dropdown >li >a,#sp-header .top-search-wrapper .icon-top-wrapper i,#sp-header #cd-menu-trigger i,#sp-header .cd-cart i,#sp-header .top-search-wrapper{}#sp-header #sp-menu .sp-dropdown .sp-dropdown-inner{}#sp-header #sp-menu .sp-dropdown .sp-dropdown-inner li.sp-menu-item >a,#sp-header #sp-menu .sp-dropdown .sp-dropdown-inner li.sp-menu-item.separator >a,#sp-header #sp-menu .sp-dropdown .sp-dropdown-inner li.sp-menu-item.separator >a:hover,#sp-header .sp-module-content ul li a,#sp-header .vm-menu .vm-title{}.sticky .logo,.sticky #cart-menu,.sticky #cd-menu-trigger,.sticky .cd-cart,.sticky .cd-cart >i,.sticky .menu-is-open >i,#sp-header.sticky .modal-login-wrapper span,#sp-header.sticky .ap-my-account i.pe-7s-user,#sp-header.sticky .ap-my-account .info-text,#sp-header.sticky .mod-languages,#sp-header.sticky .top-search-wrapper .icon-top-wrapper,#sp-header.sticky .top-search-wrapper .icon-top-wrapper >i:before,.sticky .sp-megamenu-wrapper > .sp-megamenu-parent >li >a,.sticky .sp-megamenu-wrapper #offcanvas-toggler,.sticky #sp-logo a.logo{ height:70px;line-height:70px; } .sticky .total_products{top: calc(70px / 2 - 22px);} .sticky .sticky__wrapper{ height:70px; -webkit-animation-name:fade-in-down;animation-name:fade-in-down;}.sticky .sticky__wrapper .sp-sticky-logo {height:70px;}.sticky.onepage .sticky__wrapper,.sticky.white .sticky__wrapper,.sticky.transparent .sticky__wrapper{} #sp-header.sticky #sp-menu .sp-megamenu-wrapper .sp-megamenu-parent >li >a,#sp-header.sticky .top-search-wrapper,#sp-header.sticky .top-search-wrapper .icon-top-wrapper i,#sp-header.sticky #cd-menu-trigger i,#sp-header.sticky .cd-cart i{;}#sp-header.sticky #sp-menu .sp-megamenu-wrapper .sp-megamenu-parent >li.active>a,#sp-header.sticky #sp-menu .sp-megamenu-wrapper .sp-megamenu-parent >li.current-item>a,#sp-header.sticky #sp-menu .sp-megamenu-wrapper .sp-megamenu-parent >li.sp-has-child.active>a,.sticky #offcanvas-toggler >i,.sticky #offcanvas-toggler >i:hover{color:;} 
	</style>
	<script type="application/json" class="joomla-script-options new">{"csrf.token":"0526e5f544e6f59b65a03e868e1afb6c","system.paths":{"root":"\/2020","base":"\/2020"},"system.keepalive":{"interval":3600000,"uri":"\/2020\/index.php\/component\/ajax\/?format=json"}}</script>
    
    
    
    <script src="/media/jui/js/jquery.min.js?94071cac4e5a7d105962954c805861dc"></script>
    <script src="/media/jui/js/jquery-noconflict.js?94071cac4e5a7d105962954c805861dc"></script>
    <script src="/media/jui/js/jquery-migrate.min.js?94071cac4e5a7d105962954c805861dc"></script>
    <script src="/media/system/js/caption.js?94071cac4e5a7d105962954c805861dc"></script>
    <script src="/media/system/js/mootools-core.js?94071cac4e5a7d105962954c805861dc"></script>
    <script src="/media/system/js/core.js?94071cac4e5a7d105962954c805861dc"></script>
    <script src="/media/system/js/mootools-more.js?94071cac4e5a7d105962954c805861dc"></script>
    <script src="/media/jui/js/bootstrap.min.js?94071cac4e5a7d105962954c805861dc"></script>
    <script src="/templates/beez3/javascript/md_stylechanger.js?94071cac4e5a7d105962954c805861dc"></script>
    <script src="/templates/beez3/javascript/hide.js?94071cac4e5a7d105962954c805861dc"></script>
    <script src="/templates/beez3/javascript/respond.src.js?94071cac4e5a7d105962954c805861dc"></script>
    <script src="/templates/beez3/javascript/template.js?94071cac4e5a7d105962954c805861dc"></script>
    <!--[if lt IE 9]><script src="/joomla/media/jui/js/html5.js?94071cac4e5a7d105962954c805861dc"></script><![endif]-->
</head>

<body id="shadow">

                <h3>Fees Calculator</h3>


<div class="well " id="child" border="1px"> 

<select class="form-control" style="width: 170px;">

<option value="0">Prep</option>

<option value="1">Year 1</option>

<option value="2">Year 2</option>

<option value="3">Year 3</option>

<option value="4">Year 4</option>

<option value="5">Year 5</option>

<option value="6">Year 6</option>

<option value="7">Year 7</option>

<option value="8">Year 8</option>

<option value="9">Year 9</option>

<option value="10">Year 10</option>

<option value="11">Year 11</option>

<option value="12">Year 12</option>

</select>

<!--<input type="name" name="name" class="input-large" placeholder="Enter Child Name">

<input type="submit" name="sub" value="Submit" class="btn btn-primary login-button">-->

<input type="button" name="add" id="add" value="Add & See Result " class="btn btn-primary login-button">

</div>



<div class="well " id="result">

	

<div class=""> 

<!--div class="result-header">
	<lable>Is this new enrollment?: </lable>
	<input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios1" value="0">Yes
	<input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios2" value="1" checked>No
</div-->



<table class="table">

  <thead>

    <tr>

      <th scope="col">Grade</th>

      <th scope="col">Textbook Rent Scheme</th>

      <th scope="col">Teaching Resources Levy</th>

      <th scope="col">Sport Levy</th>

	  <th scope="col">Excursion</th>

	  <th scope="col">Graduation Levy</th>

	  <!--th scope="col">Application Fee</th-->

	  <th scope="col">Total Annual Levies</th>

	  <th scope="col">Tuition Fee</th>
	  <th>Action</th>

    </tr>

  </thead>

  <tbody>

       

  </tbody>

</table>



</div>

 </div>

 

<div id="Total" class="well" style="text-align: right;">
<h4 id="Total" class="well" style="text-align: left;"><span style="font-size: 12pt;"><strong><span style="color: #339966;"><label><span style="color: #0000ff;">Sibling Discount:</span> <span id="sibling"></span></label></span> </strong></span></h4>
<h1 class="well" style="text-align: left;"><span style="font-size: 18pt;"><strong><label><span style="color: #339966;">Total Fees:</span> <span id="Total-fees"></span><br /><span id="Msg"></span></label> </strong></span></h3>
</div>

 

 <!--div class="well" id="milestone">
 	<label>How many months installments</label>

		<input type="number"  id="month"> <input type="button" id="mile" class="btn btn-primary login-button" value="submit">

		<p>Per Month: <span id="divied"></span></p>

		

 </div-->

<script>

jQuery(document).ready(function() {

	

		var tuttotal = 0;

		 var totalanu = 0;

		 var prescount = 0;

		 var plus = 0;

		 var siblingf = 0;

		 var Total =0;

		 var Totalanual = 0;
		 
		 var check = 0;
		 var pres = 0;
		 var maxval = 0;
		 
		 var totalprescount = 0;
		 
		var  prescountnew  = 0;
		 
		  function arrayMax(arr) {
					 if (arr.length === 0) {
						return -1;
						}

					var max = arr[0];
					var maxIndex = 0;

				for (var i = 1; i < arr.length; i++) {
						if (arr[i] > max) {
							maxIndex = i;
							max = arr[i];
						}
						
					}
					return max;
		 }; 
			function formatNumber (num) {
		return num.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,")
				}
	 jQuery("#add").click(function() {

		 var years = jQuery('select').val();

		

		 if(years==0){

                                jQuery("tbody").append("<tr><th>Prep</th><td>$35 </td><td>$301</td><td>$118</td>  <td>$183</td><td></td><td class='tal'>$637</td><td class='tf''>$2830</td><td><input type='button' class='rem' value='Remove'></td></tr>");



                            }

                            else if(years==1){



                                jQuery("tbody").append("<tr><th>1</th><td>$35</td><td>$272</td><td>$118</td>  <td>$126</td><td></td><td class='tal'>$551</td><td class='tf'>$2830</td><td><input type='button' class='rem' value='Remove'></td></tr>");

                            }else if(years==2){



                                jQuery("tbody").append("<tr><th>2</th><td>$20</td><td>$195</td><td>$118</td>  <td>$88</td><td></td><td class='tal'>$421</td><td class='tf'>$2830</td><td><input type='button' class='rem' value='Remove'></td></tr>");

                            }else if(years==3){



                                jQuery("tbody").append("<tr><th>3</th><td>$10</td><td>$235</td><td>$146</td>  <td>$149</td><td></td><td class='tal'>$540</td><td class='tf'>$2830</td><td><input type='button' class='rem' value='Remove'></td></tr>");

                            }else if(years==4){



                                jQuery("tbody").append("<tr><th>4</th><td>$10</td><td>$243</td><td>$146</td>  <td>$209</td><td></td><td class='tal'>$608</td><td class='tf'>$2830</td><td><input type='button' class='rem' value='Remove'></td></tr>");

                            }else if(years==5){



                                jQuery("tbody").append("<tr><th>5</th><td>$10</td><td>$263</td><td>$146</td>  <td>$270</td><td></td><td class='tal'>$689</td><td class='tf'>$2830</td><td><input type='button' class='rem' value='Remove'></td></tr>");

                            }else if(years==6){



                                jQuery("tbody").append("<tr><th>6</th><td>$10</td><td>$273</td><td>$146</td>  <td>$388</td><td></td><td class='tal'>$817</td><td class='tf'>$2830</td><td><input type='button' class='rem' value='Remove'></td></tr>");

                            }else if(years==7){



                                jQuery("tbody").append("<tr><th>7</th><td>$10</td><td>$435</td><td>$241</td>  <td>$10</td><td></td><td class='tal'>$696</td><td class='tf'>$3143</td><td><input type='button' class='rem' value='Remove'></td></tr>");

                            }else if(years==8){



                                jQuery("tbody").append("<tr><th>8</th><td>$10</td><td>$435</td><td>$241</td>  <td>$10</td><td></td><td class='tal'>$696</td><td class='tf'>$3143</td><td><input type='button' class='rem' value='Remove'></td></tr>");

                            }else if(years==9){



                                jQuery("tbody").append("<tr><th>9</th><td>$10</td><td>$375</td><td>$193</td>  <td>$40</td><td></td><td class='tal'>$618</td><td class='tf'>$3143</td><td><input type='button' class='rem' value='Remove'></td></tr>");

                            }else if(years==10){



                                jQuery("tbody").append("<tr><th>10</th><td>$10</td><td>$375</td><td>$449</td>  <td>$0</td><td></td><td class='tal'>$834</td><td class='tf'>$3538</td><td><input type='button' class='rem' value='Remove'></td></tr>");

                            }else if(years==11){



                                jQuery("tbody").append("<tr><th>11</th><td>$10</td><td>$389</td><td>$198</td>  <td>$60</td><td></td><td class='tal'>$657</td><td class='tf'>$3538</td><td><input type='button' class='rem' value='Remove'></td></tr>");

                            }else if(years==12){



                                jQuery("tbody").append("<tr><th>12</th><td>$150</td><td>$155</td><td>$158</td>  <td>$70</td><td>$300</td><td class='tal'>$833</td><td class='tf'>$3538</td><td><input type='button' class='rem' value='Remove'></td></tr>");

                            }

		 
			var arr = [];
				i = 0;
			var highest = -Infinity;
			
			
			
			jQuery("table tr td:nth-child(8)").each(function(){

			 var tutfee = jQuery(this).text();

			 var avoid = "$";

			
			var pres1 = parseInt(tutfee.replace(avoid, ''));
			
			highest = Math.max(highest, parseFloat(pres1));
			});
		  
		  
				var test = 0;
				prescountnew = 0;
				tuttotal =0;
			jQuery("table tr td:nth-child(8)").each(function(){
				
                 prescount = 0;
			 var tutfee = jQuery(this).text();

			 var avoid = "$";

			 var lenght = jQuery("table tbody tr").length;
			 
			 var maxvl = parseInt(tutfee.replace(avoid, ''));
				arr[i++] = maxvl;
				maxval = arrayMax(arr);
				
			 if(lenght>1){

				
						
				  pres = parseInt(tutfee.replace(avoid, ''));
					//console.log(highest+'----'+pres);
					//alert(highest);
					if(parseInt(highest)==pres && test == 0){
						
						//prescountnew = prescountnew - highest;
						
						
						//alert(test);
						if(test == 1){
							prescount =0;
							
						}else{
							 prescount += (pres*10.5)/100;
						}
						test = 1;
						
						
					}
					else{
				   	
						//alert(plus);
						 prescount += (pres*10.5)/100;
						 //prescountnew += pres;
						 //alert(prescount);
						  prescountnew+=	prescount;	
						
					}
					
				   		
				 }

			 
			
				
			   tuttotal += parseInt(tutfee.replace(avoid, ''));


			 });
			
				
			 Total = tuttotal;
			
			 

			 siblingf += parseInt(prescount);

			
			totalanu = 0;
		jQuery("table tr td:nth-child(7)").each(function(){
				
			 var totfee = jQuery(this).text();

			 var avoidt = "$";

			  totalanu += parseInt(totfee.replace(avoidt, ''));

			 

			 });

			 

			 Totalanual = totalanu;

			 

			 //console.log(totalanu);

			 var TotalFees = parseFloat((Total+Totalanual)-prescountnew).toFixed(2);

			 

			 jQuery("#sibling").html('$'+formatNumber(prescountnew.toFixed(2)));
				if(jQuery('[name="exampleRadios"]:checked').val()==0){
					 jQuery("#Total-fees").html(parseFloat('$'+TotalFees+250.00));
				}
				else{
			 jQuery("#Total-fees").html('$'+formatNumber(TotalFees));
				}
			 
				var ToTal = 0;
				var SibLingf =0;
				var TutTotal = 0;
				
			jQuery(".rem").click(function(){ 
			jQuery(this).parents('tr ').remove();
					var tf1 = jQuery(this).closest("tr").children('.tf').text();	
					var tal1 = jQuery(this).closest("tr").children('.tal').text();
					
					var avoidt = "$";

					var tf = parseInt(tf1.replace(avoidt, ''));
					var tal = parseInt(tal1.replace(avoidt, ''));
					
					var pp = (tf*10.5)/100;
					
					var lenght = jQuery("table tbody tr").length;
					var remove =0;
					var highest1 = -Infinity;
					if(lenght>1){
						
						remove = (tf+tal)-pp;
						
						
					}else{
						
						remove = tf+tal;
						 
					}
					console.log(highest1);
					
					jQuery("table tr td:nth-child(8)").each(function(){

							var tutfee = jQuery(this).text();

							var avoid = "$";

			
							var pres1 = parseInt(tutfee.replace(avoid, ''));
			
							highest1 = Math.max(highest1, parseFloat(pres1));
							
							});
					
					console.log(highest1);
					var test = 0;
					prescountnew = 0;
					TutTotal = 0;
			jQuery("table tr td:nth-child(8)").each(function(){
				
              prescount = 0;
			 var tutfee = jQuery(this).text();

			 var avoid = "$";

			 var lenght = jQuery("table tbody tr").length;
			 
			 var maxvl = parseInt(tutfee.replace(avoid, ''));
				arr[i++] = maxvl;
				maxval = arrayMax(arr);
				
			 if(lenght>1){

				  pres = parseInt(tutfee.replace(avoid, ''));
					
					if(parseInt(highest1)==pres && test == 0){
						if(test == 1){
							prescount =0;
						}else{
							 prescount += (pres*10.5)/100;
						}
						test = 1;
						}
					else{			   	
						 prescount += (pres*10.5)/100;
						 prescountnew+=	prescount;	
						}
					
				 }				
			   TutTotal += parseInt(tutfee.replace(avoid, ''));			  

			 });
			 
			  ToTal = TutTotal;

			 //console.log(ToTal);

			 SibLingf += parseInt(prescount);
			 
					//console.log(prescountnew);
				
			var TotalAnu = 0;		
			var TotalAnuaL = 0;		
			jQuery("table tr td:nth-child(7)").each(function(){

			 var totfee = jQuery(this).text();

			 var avoidt = "$";

			  TotalAnu += parseInt(totfee.replace(avoidt, ''));			 

			 });		 

			 TotalAnuaL = TotalAnu;
		
			var RemoveFees = parseFloat((ToTal+TotalAnuaL)-prescountnew).toFixed(2);
			
			console.log();
			
			 jQuery("#sibling").html('$'+formatNumber(prescountnew.toFixed(2)));
				if(jQuery('[name="exampleRadios"]:checked').val()==0){
					
					jQuery("#Total-fees").html(parseFloat('$'+formatNumber(RemoveFees)+250.00));
				}else{
			 jQuery("#Total-fees").html('$'+formatNumber(RemoveFees));
				}
					
						
						
				
				}); 

		 

	 });

	 

	

	 

			

	  jQuery('[name="exampleRadios"]').change(function() {

		 		  

		  var a = jQuery('[name="exampleRadios"]:checked').val();

		  if(a==0){

			  

			  var j = parseInt(jQuery("#Total-fees").html());

			  jQuery("#Total-fees").html(j+250);
			  jQuery("#Msg").html('*New Enrollment Fees 250');

		  }else if(a==1){

			  

			  var j = parseInt(jQuery("#Total-fees").html());

			  jQuery("#Total-fees").html(j-250);
			  jQuery("#Msg").html('');

		  }

	  });

	  

	  jQuery('#mile').click(function(){		  

				var d = parseInt(jQuery("#Total-fees").html());

				var e = parseInt(jQuery("#month").val());

				var mile = d/e;

				

				jQuery('#divied').html(mile);

		  

	  });
	  
	 jQuery(".rem").click(function(){ 
		jQuery(this).parents('tr').remove();
				});

	

});

</script>




            </div>
        		<p>No Sibling discount on the first child or child in the highest grade. 10% Sibling discount only eligible for the 2nd Child, 13.5% Sibling discount only eligible for the 3rd Child, 20% Sibling discount only eligible for the 4th Child or more per family who study at our college.</p>

        </body>