// JavaScript Document

var count=1;
var rows= new Array(150);
var chargearray= new Array(150)	;
var	interestowedarray= new Array(150);
var	totaltoclaimarray= new Array(150);	
var rowsprint=new Array(150);

var	date= new Array(150);	

function calculateValues(){
	year=document.getElementById('year').selectedIndex
	year=1999+year;
	strDate1=document.getElementById('month').value+ "/" +document.getElementById('day').value + "/" +year
	
	datDate1= Date.parse(strDate1);
	var now = new Date();
	datDate2= Date.parse(now);
	charge= document.getElementById('charge').value*1;
	noofdays=((datDate2-datDate1)/(24*60*60*1000));
	interestowed=charge*0.000219178*noofdays;
	totaltoclaim=charge+interestowed;
	document.getElementById('interestowed').value = Math.round(interestowed*100)/100;
	document.getElementById('totaltoclaim').value=Math.round(totaltoclaim*100)/100;

}


function printVersion(){


var generator=window.open('','name','height=400,width=500');
  
  generator.document.write('<html><head><title>Bank Charges Interest Calculations</title>');
  generator.document.write('<link rel="stylesheet" href="style.css">');
  generator.document.write('</head><body><h1>Bank Charges Interest Calculations</h1>');
  var totalinterestowed=0;
var totalcharge=0;
var fulltotaltoclaim=0;
var data='';
  for (x=1;x<=150;x++){
	if (rows[x]!=null){
	data +=rowsprint[x] ;
	totalinterestowed=totalinterestowed+(interestowedarray[x]*1);
	totalcharge=totalcharge+(chargearray[x]*1);
	fulltotaltoclaim=fulltotaltoclaim+(totaltoclaimarray[x]*1);
	}

}
 total = "<tr><td><b>Total</b></td><td><b>£"+Math.round(totalcharge*100)/100+"</b></td><td>&nbsp;</td><td><b>£"+Math.round(totalinterestowed*100)/100+"</b></td><td><b>£"+Math.round(fulltotaltoclaim*100)/100+"</b></td></tr>";
  
  generator.document.write( "<table width=\"100%\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\" style=\"text-align:center;font-size:10pt;\"><tr><td>&nbsp;</td><td>Charge Value </td><td>Date</td><td>Interest</td><td>Total</td></tr>"+ data + total +"</table>");

  generator.document.write('\<script\>window.print();\</script\></body></html>');
  
  generator.document.close();

}
function clearlist(){
	var count=1;
	for (x=1;x<=150;x++){

	rows[x]= null;
	chargearray[x]= null;
	interestowedarray[x]= null;
	totaltoclaimarray[x]= null;}
	document.getElementById('calculator').innerHTML ="";

}

function remove(value){
	rows[value]= null;
	chargearray[value]= null;
	interestowedarray[value]= null;
	totaltoclaimarray[value]= null;
var totalinterestowed=0;
var totalcharge=0;
var fulltotaltoclaim=0;
var data='';
for (x=1;x<=150;x++){
	if (rows[x]!=null){
	data +=rows[x] ;
	totalinterestowed=totalinterestowed+(interestowedarray[x]*1);
	totalcharge=totalcharge+(chargearray[x]*1);
	fulltotaltoclaim=fulltotaltoclaim+(totaltoclaimarray[x]*1);
	}

}
 total = "<tr><td><b>Total</b></td><td><b>£"+Math.round(totalcharge*100)/100+"</b></td><td>&nbsp;</td><td><b>£"+Math.round(totalinterestowed*100)/100+"</b></td><td><b>£"+Math.round(fulltotaltoclaim*100)/100+"</b></td><td>&nbsp;</td></tr>";

count=count+1;


	document.getElementById('calculator').innerHTML = "<table width=\"100%\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\" style=\"text-align:center;font-size:10pt;\"><tr><td>&nbsp;</td><td>Charge Value </td><td>Date</td><td>Interest</td><td>Total</td><td>&nbsp;</td></tr>"+ data + total +"</table>";


}

function addToRHS(){
	calculateValues();
	charge= document.getElementById('charge').value*1;
	interestowed=document.getElementById('interestowed').value*1;
	totaltoclaim=document.getElementById('totaltoclaim').value*1;
	year=document.getElementById('year').selectedIndex
	year=1999+year;
	date=document.getElementById('day').value+ "/" +document.getElementById('month').value + "/" +year
	
	
	chargearray[count]=charge;
	interestowedarray[count]=interestowed;
	date[count]=date

	totaltoclaimarray[count]=totaltoclaim;
	rows[count] = "<tr><td><b>&nbsp;</b></td><td>£"+charge+"</td><td>"+date+"</td><td>£"+interestowed+"</td><td>£"+totaltoclaim+"</td><td><input type=\"button\"value=\"X\" onclick=\"remove("+count+")\"></td></tr>";
	rowsprint[count] = "<tr><td><b>&nbsp;</b></td><td>£"+charge+"</td><td>"+date+"</td><td>£"+interestowed+"</td><td>£"+totaltoclaim+"</td></tr>";
	
var totalinterestowed=0;
var totalcharge=0;
var fulltotaltoclaim=0;
var data='';
for (x=1;x<=150;x++){
	if (rows[x]!=null){
	data +=rows[x] ;
	totalinterestowed=totalinterestowed+(interestowedarray[x]*1);
	totalcharge=totalcharge+(chargearray[x]*1);
	fulltotaltoclaim=fulltotaltoclaim+(totaltoclaimarray[x]*1);
	}

}
 total = "<tr><td><b>Total</b></td><td><b>£"+Math.round(totalcharge*100)/100+"</b></td><td>&nbsp;</td><td><b>£"+Math.round(totalinterestowed*100)/100+"</b></td><td><b>£"+Math.round(fulltotaltoclaim*100)/100+"</b></td><td>&nbsp;</td></tr>";

count=count+1;


	document.getElementById('calculator').innerHTML = "<table width=\"100%\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\" style=\"text-align:center;font-size:10pt;\"><tr><td>&nbsp;</td><td>Charge Value </td><td>Date</td><td>Interest</td><td>Total</td><td>&nbsp;</td></tr>"+ data + total +"</table>";

}
