//---------------------------------------------------------
//File Name			: R85Script.js
//Author			: Narendra Mandadapu
//version			: 1.0
//Date Started		: 05/10/2005
//Contact			: Narendra.Mandadapu@hmrcaspire.com.
//----------------------------------------------------------
function ClearAll()
	{
		window.location = "r85.htm"
	}
	
	function prepareForm()
	{
		document.ir85.dobday.focus();
		//document.getElementById("curYear").innerHTML = curYear;
		document.getElementById("curYear1").innerHTML = curYear;
		//document.getElementById("nextYear").innerHTML = nextYear;
		document.getElementById("nextYear1").innerHTML = nextYear;
		
	}
	
	<!-- Begin
		
		var isNN = (navigator.appName.indexOf("Netscape")!=-1);
		//alert(isNN);
		function autoTab(input,len, e) {
		var keyCode = (isNN) ? e.which : e.keyCode; 
		var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
		if(input.value.length >= len && !containsElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % input.form.length].focus();
		}
		function containsElement(arr, ele) {
		var found = false, index = 0;
		while(!found && index < arr.length)
		if(arr[index] == ele)
		found = true;
		else
		index++;
		return found;
		}
		function getIndex(input) {
		var index = -1, i = 0, found = false;
		while (i < input.form.length && index == -1)
		if (input.form[i] == input)index = i;
		else i++;
		return index;
		}
		return true;
		}
//  End -->

	
	function Findage(birthDate, birthMonth, birthYear)
	{
	
		curDate = new Date();
		curDay = curDate.getDate();
		curMonth = curDate.getMonth();
		curYear = curDate.getFullYear();
		
		if (birthMonth == curMonth+1)
		{
			if (birthDate > curDay)
			{
				//alert("Birth date is greater than cur date")
				return curYear - birthYear;
			}
			if (birthDate <= curDay)
			{
				//alert("Birth date is less than cur date")
				return (curYear - birthYear) + 1;	
			}
		}
		
		if (birthMonth < curMonth+1)
		{
			return (curYear - birthYear) + 1;
		}
		
		if (birthMonth > curMonth+1)
		{
			return (curYear - birthYear);
			
		}
			
	}
	
	<!-- Begin
	
	var isNN = (navigator.appName.indexOf("Netscape")!=-1);
	//  End -->
	
function validate(string) 
	{
		if (!string) return false;
		var Chars = "0123456789";

		for (var i = 0; i < string.length; i++) 
		{
			if (Chars.indexOf(string.charAt(i)) == -1)
			return false;
		}
	
		return true;
	} 
	
function lyear(a) {
		if(((a % 4 == 0) && (a % 100 != 0)) || (a % 400 == 0))
		return true;
		else 
		return false;
		}

		
function verifyAll()
	{	

		window.scrollTo(0,0);
		
		document.getElementById('doberror').style.visibility = "hidden";
		document.getElementById('mcaerror').style.visibility = "hidden";
		document.getElementById('bpaerror').style.visibility = "hidden";
		document.getElementById('bankinteresterror').style.visibility = "hidden";
		//document.getElementById('otherinteresterror').style.visibility = "hidden";
		document.getElementById('statepensionerror').style.visibility = "hidden";
		document.getElementById('otherpensionerror').style.visibility = "hidden";
		document.getElementById('taxablebenefitserror').style.visibility = "hidden";
		document.getElementById('earningserror').style.visibility = "hidden";
		document.getElementById('sharedividendserror').style.visibility = "hidden";
		document.getElementById('otherincomeerror').style.visibility = "hidden";
					
		
			
		document.getElementById('results').style.visibility = "hidden";
		document.getElementById('results').innerHTML = "";
		
		//declaration of error vaiables
		
		var E002 = "Please enter a date of birth in the format dd/mm/yyyy";
		var E003 = "For a date of birth, please use numbers only in the format dd/mm/yyyy";
		var E004 = "You have entered a future date as your date of birth. Please re-enter";
		var E006 = "Please enter the total amount of interest before tax was deducted";
		var E007 = "Please enter your income in the appropriate space in whole pounds using numbers only";
		var E008 = "Please select a payment frequency";
		var E009 = "Please select 'Yes' if you claim Married Couple's Allowance";
		var E010 = "Please select 'Yes' if you claim Blind Person's Allowance";
		var E011 = "Please enter a valid date";
				
		//declaration of vaiables
		var dd = document.ir85.dobday.value;
		var mm = document.ir85.dobmonth.value;
		var yy = document.ir85.dobyear.value;
		var age = 0;
		
		var msgString = "";
		var curPosition = 0;
		var curPositionField = "";
			
		var pAllowance = 0;
		var totalAllowance = 0;
		var mca = 0; // married couple allowance
		var bpa = 0; //blind person allowance
		
		var ointerest = 0;
		var spension = 0;
		var opension = 0;
		var tbenefits = 0;
		var earnings = 0;
		var sdividends = 0;
		var otherincome = 0;
		
		var totalIncome = 0;
		
		var ResultedValue = 0;
		var errorMessage = false;
		
		//end of declaration of variables
		
		
		// checking date fields 					
		if( (dd == "") || (mm == "") || (yy == "") )
		{
			msgString = E002 + "\n";
			if (parseInt(curPosition) == "0")
			{
				curPositionField = "dobday";
				curPosition = parseInt(curPosition) + 1;
			}
			
			errorMessage = true;
		}
		
		// checking the length of each field
		if((dd.length < 2) || (mm.length < 2) || (yy.length < 4))
		{
			msgString = E002 + "\n";
			if (parseInt(curPosition) == "0")
			{
				curPositionField = "dobday";
				curPosition = parseInt(curPosition) + 1;
			}
			errorMessage = true;
		}
		
		//if date is not valid
		//see the validate function in this page
		if( (!validate(dd)) || (!validate(mm)) || (!validate(yy)) )
		{
			msgString = E003 + "\n";
			if (parseInt(curPosition) == "0")
			{
				curPositionField = "dobday";
				curPosition = parseInt(curPosition) + 1;
			}
			errorMessage = true;
		}
		
		//if the dob is greater than the current date.
		//see the function "showDateDiff"		
		if(!showDateDiff())
		{
			msgString = E004 + "\n";
			if (parseInt(curPosition) == "0")
			{
				curPositionField = "dobday";
				curPosition = parseInt(curPosition) + 1;
			}
			errorMessage = true;
		}
		
		
			//finding the age code starts here. this code is just build up
			//to find the age. This is very important when you are debugging 
			//application. 
			days = new Date();
			
			//capturing current date values
			gdate = days.getDate();
			gmonth = days.getMonth();
			gyear = days.getFullYear();
			
			//alert(gdate + ", " + gmonth + ", " + gyear);
					
			if ((mm > 4) && (mm <= 12))
			{
				gyear = gyear;
				gdate = 05;
				gmonth = 04;
				//alert(gdate + ", " + gmonth + ", " + gyear);
			}
			else if ((mm == 4) && (dd >= 6))
			{
				gyear = gyear;
				gdate = 05;
				gmonth = 04;
				//alert(gdate + ", " + gmonth + ", " + gyear);
			}
			else
			{
				gyear = gyear + 1;
				gdate = 05;
				gmonth = 04;
				//alert(gdate + ", " + gmonth + ", " + gyear);
			}
			
			var main="valid";

			if (yy > gyear)
			{
			main = "Invalid";
			}
			
			if ((mm < 1) || (mm > 12) || (dd < 1) || (dd > 31) || (yy < 1) ||(mm == "") || (dd == "") || (yy == ""))
				main = "Invalid";
			else 
				if (((mm == 4) || (mm == 6) || (mm == 9) || (mm == 11)) && (dd > 30))
					main = "Invalid";
				else 
				if (mm == 2) {
					if (dd > 29)
						main = "Invalid";
					else if((dd > 28) && (!lyear(yy)))
						main="Invalid";
				}
				else
					if((yy > 9999)||(yy < 1890))
						main = "Invalid";
					else
						main = main;
		
		
		if ((main == "valid")  && (!errorMessage))
		{
			age = gyear - yy;
			
			if(age == 0) age = age;
			
			if (age<65)
			{
				pAllowance = parseInt(underSixtyFiveAllowance, 10);
			}
			else if ((age <= 65) || (age < 75))
			{
				pAllowance = parseInt(sixtyFiveAndSeventyFiveAllowance, 10);
			}
				
			else if (age >= 75)
			{
				pAllowance = parseInt(aboveSeventyFiveAllowance, 10);
			}
				
		}
		
		if ((main == "Invalid")  && (!errorMessage))
		{
			msgString = E011 + "\n";
			
			if (parseInt(curPosition) == "0")
			{
				curPositionField = "dobday";
				curPosition = parseInt(curPosition) + 1;
			}
			
			errorMessage = true;	
		}
		//finding the age code ends here.
		
		
		if ((!document.ir85.mcoupleallow[0].checked) && (!document.ir85.mcoupleallow[1].checked))
		{
			msgString = msgString + E009 + "\n";
			
			if (parseInt(curPosition) == "0")
			{
				curPositionField = "mcoupleallow[0]";
				curPosition = parseInt(curPosition) + 1;
			}
			errorMessage = true;
		}
		
		if ((!document.ir85.blindperallow[0].checked) && (!document.ir85.blindperallow[1].checked))
		{
			msgString = msgString + E010 + "\n";
			
			if (parseInt(curPosition) == "0")
			{
				curPositionField = "blindperallow[0]";
				curPosition = parseInt(curPosition) + 1;
			}
			errorMessage = true;
		
		}
					
		if (document.ir85.mcoupleallow[1].checked)
		{
			mca = parseInt(mca, 10) + parseInt(mcaAllowance, 10);
		}
		
		if (document.ir85.blindperallow[1].checked)
		{
			bpa = parseInt(bpa, 10) + parseInt(bpaAllowance, 10);
		}
		
		totalAllowance = totalAllowance + parseInt(pAllowance) + parseInt(mca) + parseInt(bpa);
				
		
		//bank interest field validation code starts here.
		if (document.ir85.bankinterest.value == "")
		{
			msgString = msgString + E006 + "\n";
			
			if (parseInt(curPosition) == "0")
			{
				curPositionField = "bankinterest";
				curPosition = parseInt(curPosition) + 1;
			}
			
			errorMessage = true;
		}
		
		if ((!document.ir85.bankinterest.value == "")&& (!validate(document.ir85.bankinterest.value)) )
		{
			msgString = msgString + E007 + "\n";
			
			if (parseInt(curPosition) == "0")
			{
				curPositionField = "bankinterest";
				curPosition = parseInt(curPosition) + 1;
			}			
			errorMessage = true;
		
		}
		
		if ((!document.ir85.bankinterest.value == "") && (document.ir85.bankinterest.value != "0") && (document.ir85.bankinterestfrequency.value == "") )
		{
			msgString = msgString + E008 + "\n";
			
			if (parseInt(curPosition) == "0")
			{
				curPositionField = "bankinterestfrequency";
				curPosition = parseInt(curPosition) + 1;
			}
			errorMessage = true;
		}
		
			
		if (!errorMessage)
		{
			var binterest = document.ir85.bankinterest.value;
			var binterestFreq = document.ir85.bankinterestfrequency.options[document.ir85.bankinterestfrequency.selectedIndex].value;
						
			totalIncome = calculateInterest(binterest, binterestFreq, totalIncome);
			
		}
				
		//other interest field validation code starts here.		
//		if ((!document.ir85.otherinterest.value == "") && (!validate(document.ir85.otherinterest.value)) )
//		{
//			msgString = msgString + E007 + "\n";
//			
//			if (parseInt(curPosition) == "0")
//			{
//				curPositionField = "otherinterest";
//				curPosition = parseInt(curPosition) + 1;
//			}
//			errorMessage = true;
//		
//		}
//		
//		if  ((!document.ir85.otherinterest.value == "")  && (validate(document.ir85.otherinterest.value)) && (document.ir85.otherinterestfrequency.value == ""))
//		{
//			msgString = msgString + E008 + "\n";
//			
//			if (parseInt(curPosition) == "0")
//			{
//				curPositionField = "otherinterestfrequency";
//				curPosition = parseInt(curPosition) + 1;
//			}
//			errorMessage = true;
//		
//		}
//		
//		if (!errorMessage)
//		{
//			var ointerest = document.ir85.otherinterest.value;
//			var ointerestFreq = document.ir85.otherinterestfrequency.options[document.ir85.otherinterestfrequency.selectedIndex].value;
//			
//			totalIncome = calculateInterest(ointerest, ointerestFreq, totalIncome);
//			
//		}
//		
//		//other interest field validation code ends here.		
		
		
		//state pension field validation code starts here.		
		if ((!document.ir85.statepension.value == "") && (!validate(document.ir85.statepension.value)) )
		{
			msgString = msgString + E007 + "\n";
			
			if (parseInt(curPosition) == "0")
			{
				curPositionField = "statepension";
				curPosition = parseInt(curPosition) + 1;
			}
			
			errorMessage = true;
		}
		
		if ((!document.ir85.statepension.value == "") && (document.ir85.statepension.value != "0") && (document.ir85.statepensionfrequency.value == ""))
		{
			msgString = msgString + E008 + "\n";
			if (parseInt(curPosition) == "0")
			{
				curPositionField = "statepensionfrequency";
				curPosition = parseInt(curPosition) + 1;
			}
			errorMessage = true;
		}
		
		if (!errorMessage)
		{
			var spension = document.ir85.statepension.value;
			var spensionFreq = document.ir85.statepensionfrequency.options[document.ir85.statepensionfrequency.selectedIndex].value;
			
			
			totalIncome = calculateInterest(spension, spensionFreq, totalIncome);
			
		}
		
		//state pension field validation code ends here.		
		
		
					
		//other pension field validation code starts here.
		if ((!document.ir85.otherpension.value == "") && (!validate(document.ir85.otherpension.value)) )
		{
			msgString = msgString + E007 + "\n";
			if (parseInt(curPosition) == "0")
			{
				curPositionField = "otherpension";
				curPosition = parseInt(curPosition) + 1;
			}
			errorMessage = true;
		}
		
		if ((!document.ir85.otherpension.value == "") && (document.ir85.otherpension.value != "0") && (document.ir85.otherpensionfrequency.value == ""))
		{
			msgString = msgString + E008 + "\n";
			
			if (parseInt(curPosition) == "0")
			{
				curPositionField = "otherpensionfrequency";
				curPosition = parseInt(curPosition) + 1;
			}
			errorMessage = true;
		}
		
		if (!errorMessage)
		{
			var opension = document.ir85.otherpension.value;
			var opensionFreq = document.ir85.otherpensionfrequency.options[document.ir85.otherpensionfrequency.selectedIndex].value;
			
				
			totalIncome = calculateInterest(opension, opensionFreq, totalIncome);
		}
		
		//other pension field validation code ends here.
		
				
		//taxablebenefits field validation code starts here.
		if ((!document.ir85.taxablebenefits.value == "") && (!validate(document.ir85.taxablebenefits.value)) )
		{
			msgString = msgString + E007 + "\n";
			
			if (parseInt(curPosition) == "0")
			{
				curPositionField = "taxablebenefits";
				curPosition = parseInt(curPosition) + 1;
			}
			
			errorMessage = true;
		}
		
		if ((!document.ir85.taxablebenefits.value == "") && (document.ir85.taxablebenefits.value != "0") && (document.ir85.taxablebenefitsfrequency.value == "") )
		{
			msgString = msgString + E008 + "\n";
			if (parseInt(curPosition) == "0")
			{
				curPositionField = "taxablebenefitsfrequency";
				curPosition = parseInt(curPosition) + 1;
			}
			
			errorMessage = true;
		}
		
		if (!errorMessage)
		{
			var tbenefits = document.ir85.taxablebenefits.value;
			var tbenefitsFreq = document.ir85.taxablebenefitsfrequency.options[document.ir85.taxablebenefitsfrequency.selectedIndex].value;
			
		
			totalIncome = calculateInterest(tbenefits, tbenefitsFreq, totalIncome);
			
		}
		
		//taxablebenefits field validation code ends here.
		
		
		//earnings field validation code starts here.
		if ((!document.ir85.earnings.value == "") && (!validate(document.ir85.earnings.value)) )
		{
			msgString = msgString + E007 + "\n";
			
			if (parseInt(curPosition) == "0")
			{
				curPositionField = "earnings";
				curPosition = parseInt(curPosition) + 1;
			}			
			errorMessage = true;
		}
		
		if ((!document.ir85.earnings.value == "") && (document.ir85.earnings.value != "0") && (document.ir85.earningsfrequency.value == ""))
		{
			msgString = msgString + E008 + "\n";
			
			if (parseInt(curPosition) == "0")
			{
				curPositionField = "earningsfrequency";
				curPosition = parseInt(curPosition) + 1;
			}			
			errorMessage = true;
		}
		
		if (!errorMessage)
		{
			var earnings = document.ir85.earnings.value;
			var earningsFreq = document.ir85.earningsfrequency.options[document.ir85.earningsfrequency.selectedIndex].value;
			
			
			totalIncome = calculateInterest(earnings, earningsFreq, totalIncome);
		}
		
		//earnings field validation code ends here.
		
		
				
		//share dividends field validation code starts here.
		if ((!document.ir85.sharedividends.value == "") && (!validate(document.ir85.sharedividends.value)) )
		{
			msgString = msgString + E007 + "\n";
			
			if (parseInt(curPosition) == "0")
			{
				curPositionField = "sharedividends";
				curPosition = parseInt(curPosition) + 1;
			}
			errorMessage = true;
		}
		
		if ((!document.ir85.sharedividends.value == "") &&  (document.ir85.sharedividends.value != "0") && (document.ir85.sharedividendsfrequency.value == ""))
		{
			msgString = msgString + E008 + "\n";
			
			if (parseInt(curPosition) == "0")
			{
				curPositionField = "sharedividendsfrequency";
				curPosition = parseInt(curPosition) + 1;
			}
			errorMessage = true;
		}
		
		if (!errorMessage)
		{
			var sdividends = document.ir85.sharedividends.value;
			var sdividendsFreq = document.ir85.sharedividendsfrequency.options[document.ir85.sharedividendsfrequency.selectedIndex].value;
			
		
			totalIncome = calculateInterest(sdividends, sdividendsFreq, totalIncome);
		}
		
		//share dividends field validation code ends here.
		
		
		
		//Other income field validation code starts here.					
		if ((!document.ir85.otherincome.value == "") && (!validate(document.ir85.otherincome.value)) )
		{
			msgString = msgString + E007 + "\n";
			
			if (parseInt(curPosition) == "0")
			{
				curPositionField = "otherincome";
				curPosition = parseInt(curPosition) + 1;
			}
			errorMessage = true;
		}
		
		if ((!document.ir85.otherincome.value == "") && (document.ir85.otherincome.value != "0") && (document.ir85.otherincomefrequency.value == ""))
		{
			msgString = msgString + E008 + "\n";
			
			if (parseInt(curPosition) == "0")
			{
				curPositionField = "otherincomefrequency";
				curPosition = parseInt(curPosition) + 1;
			}
			errorMessage = true;
		}
				
		if (!errorMessage)
		{
			var otherincome = document.ir85.otherincome.value;
			var otherincomeFreq = document.ir85.otherincomefrequency.options[document.ir85.otherincomefrequency.selectedIndex].value;
			
			totalIncome = calculateInterest(otherincome, otherincomeFreq, totalIncome);
		}
		//Other income field validation code starts here.
		
		
		if (errorMessage)
		{
			alert(msgString);
			if (document.getElementById) 
			{ // DOM3 = IE5, NS6 
				eval("document.forms[0]." + curPositionField + ".focus();");
			
			}
			else
			{
				if (document.layers) 
				
				{ // Netscape 4 
					eval("document." + curPositionField + ".focus();");
				}
				else
				{
					eval("document.all." + curPositionField + ".focus();");
				}
				
			}
			return false; //if any error message occurs from above code the form will not submit
		}
		
		
		ResultedValue = parseInt(totalIncome, 10) - parseInt(totalAllowance, 10);
		
				
		var str = "";
		
		//creating a results table basing on resultedValue.		
		if (ResultedValue > 0)
		{
			//str = str + "<p align=left><b>Result</b></p>";
			str = str + "<TABLE cellSpacing='0' cellPadding='0' width='605' border='0' ID='resDownTable'>";
			str = str + "<TR>";
			
			str = str + "<TD class='tablebg1'><b>Result - </b>The Income you have shown on the checker is more than your tax ";
			str = str + "allowances. Please do <b>not</b> fill in the form R85.";
			str = str + "</TD>";
			str = str + "</TR>";
			str = str + "</TABLE>";
			alert("The Income you have shown on the checker is more than your tax allowances. Please do not fill in the form R85.");
		}
		else
		{
			//str = str + "<p align=left><b>Result</b></p>";
			str = str + "<TABLE cellSpacing='0' cellPadding='0' width='605' border='0' ID='resDownTable'>";
			str = str + "<TR>";
			
			str = str + "<TD class='tablebg1'><b>Result- </b>The Income you have shown on the checker is less than your tax ";
			str = str + "allowances. <b>Please consider filling in the <a href='http://www.hmrc.gov.uk/forms/r85.pdf'>form R85 </a>and sending it to your ";
			str = str + "bank(s) or building society(ies).</b></TD>";
			str = str + "</TR>";
			str = str + "</TABLE>";				
			alert("The Income you have shown on the checker is less than your tax allowances. Please consider filling in the form R85 and sending it to your bank(s) or building society(ies).")
			
		}
		
		str = str + "<BR><BR>"

		str = str + "<TABLE cellSpacing='0' cellPadding='0' width='605' border='0' id=resTable>";
		str = str + "<TR>";
		
		str = str + "<TD class='tablebg1' colSpan='2'>";
		str = str + "<b><u><lable id='summarylb'>Summary of Calculations</lable></u></b>";
		str = str + "</TD>";
		str = str + "<TD width='300' class='tablebg1' colSpan='2'>&nbsp;</TD>";
		str = str + "</TR>";
		str = str + "<TR>";
		
		str = str + "<TD class='tablebg1' colSpan='2'>&nbsp;</TD>";
		str = str + "<TD width='300' class='tablebg1' colSpan='2'>&nbsp;</TD>";
		str = str + "</TR>";
		str = str + "<TR>";
		
		str = str + "<TD class='tablebg1' colSpan='2'>";
		str = str + "Your age next birthday will be <b>" + Findage(dd, mm, yy) + "</b>";
		str = str + "</TD>";
		str = str + "<TD width='300' class='tablebg1' colSpan='2'>&nbsp;</TD>";
		str = str + "</TR>";
		str = str + "<TR>";
		
		str = str + "<TD class='tablebg1' colSpan='2'>&nbsp;</TD>";
		str = str + "<TD width='300' class='tablebg1' colSpan='2'>&nbsp;</TD>";
		str = str + "</TR>";
		str = str + "<TR>";
		
		str = str + "<TD class='tablebg1' colSpan='2'>";
		str = str + "<b>Allowances</b>";
		str = str + "</TD>";
		str = str + "<TD width='300' class='tablebg1' colSpan='2'>&nbsp;</TD>";
		str = str + "</TR>";
		str = str + "<TR>";
		
		str = str + "<TD class='tablebg1' colSpan='2'>";
		str = str + "&nbsp;";
		str = str + "</TD>";
		str = str + "<TD width='300' class='tablebg1' colSpan='2'>&nbsp;</TD>";
		str = str + "</TR>";
		str = str + "<TR>";
		
		str = str + "<TD class='tablebg1' colSpan='2'>";
		str = str + "Personal Allowance";
		str = str + "</TD>";
		str = str + "<TD width='300' class='tablebg1' colSpan='2'>£&nbsp;<input type=text name=t1 readOnly size=6 class=readOnlyTextbox value='" +  pAllowance + "'></TD>";
		str = str + "</TR>";
		str = str + "<TR>";
		
		str = str + "<TD class='tablebg1' colSpan='2'>";
		str = str + "Adjustment for Married Couple's Allowance";
		str = str + "</TD>";
		str = str + "<TD width='300' class='tablebg1' colSpan='2'>£&nbsp;<input type=text name=t2 readOnly size=6 class=readOnlyTextbox value='" + mca + "'></TD>";
		str = str + "</TR>";
		str = str + "<TR>";
		
		str = str + "<TD class='tablebg1' colSpan='2'>";
		str = str + "Blind Person's Allowance";
		str = str + "</TD>";
		str = str + "<TD width='300' class='tablebg1' colSpan='2'>£&nbsp;<input type=text name=t3 readOnly size=6 class=readOnlyTextbox value='"+ bpa + "'></TD>";
		str = str + "</TR>";
		str = str + "<TR>";
		
		str = str + "<TD class='tablebg1' colSpan='2'>";
		str = str + "&nbsp;";
		str = str + "</TD>";
		str = str + "<TD width='300' class='tablebg1' colSpan='2'>&nbsp;</TD>";
		str = str + "</TR>";
		str = str + "<TR>";
		
		str = str + "<TD class='tablebg1' colSpan='2'>";
		str = str + "<b>Total Allowance</b>";
		str = str + "</TD>";
		str = str + "<TD width='300' class='tablebg1' colSpan='2'><b>£</b><input type=text name=t4 readOnly size=6 class=readOnlyTextboxBold value='" + totalAllowance + "'></TD>";
		str = str + "</TR>";
		
		str = str + "<TR>";
		
		str = str + "<TD class='tablebg1' colSpan='2'>";
		str = str + "&nbsp;";
		str = str + "</TD>";
		str = str + "<TD width='300' class='tablebg1' colSpan='2'>&nbsp;</TD>";
		str = str + "</TR>";
		
		str = str + "<TR>";
		
		str = str + "<TD class='tablebg1' colSpan='2'>";
		str = str + "&nbsp;";
		str = str + "</TD>";
		str = str + "<TD width='300' class='tablebg1' colSpan='2'>&nbsp;</TD>";
		str = str + "</TR>";
		
		str = str + "<TR>";
		
		str = str + "<TD class='tablebg1' colSpan='2'>";
		str = str + "<b>Income (Yearly)</b>";
		str = str + "</TD>";
		str = str + "<TD width='300' class='tablebg1' colSpan='2'>&nbsp;</TD>";
		str = str + "</TR>";
		
		str = str + "<TR>";
		
		str = str + "<TD class='tablebg1' colSpan='2'>";
		str = str + "&nbsp;";
		str = str + "</TD>";
		str = str + "<TD width='300' class='tablebg1' colSpan='2'>&nbsp;</TD>";
		str = str + "</TR>";

		str = str + "<TR>";
		
		str = str + "<TD class='tablebg1' colSpan='2'>";
		str = str + "Interest from banks, building societies and National Savings & Investments";
		str = str + "</TD>";
		str = str + "<TD width='300' class='tablebg1' colSpan='2'>£&nbsp;<input type=text name=t5 readOnly size=6 class=readOnlyTextbox value='" + calculateIndividualInterest(binterest, binterestFreq) + "'></TD>";
		str = str + "</TR>";
		
//		str = str + "<TR>";
		
//		str = str + "<TD class='tablebg1' colSpan='2'>";
//		str = str + "Other UK interest for current year";
//		str = str + "</TD>";
//		str = str + "<TD width='300' class='tablebg1' colSpan='2'>£&nbsp;<input type=text name=t6 readOnly size=6 class=readOnlyTextbox value='" + calculateIndividualInterest(ointerest, ointerestFreq) + "'></TD>";
//		str = str + "</TR>";
		
		str = str + "<TR>";
		
		str = str + "<TD class='tablebg1' colSpan='2'>";
		str = str + "State Pension";
		str = str + "</TD>";
		str = str + "<TD width='300' class='tablebg1' colSpan='2'>£&nbsp;<input type=text name=t7 readOnly size=6 class=readOnlyTextbox value='" + calculateIndividualInterest(spension, spensionFreq) + "'></TD>";
		str = str + "</TR>";
		
		str = str + "<TR>";
		
		str = str + "<TD class='tablebg1' colSpan='2'>";
		str = str + "Other Pension";
		str = str + "</TD>";
		str = str + "<TD width='300' class='tablebg1' colSpan='2'>£&nbsp;<input type=text name=t8 readOnly size=6 class=readOnlyTextbox value='" + calculateIndividualInterest(opension, opensionFreq) + "'></TD>";
		str = str + "</TR>";
		
		str = str + "<TR>";
		
		str = str + "<TD class='tablebg1' colSpan='2'>";
		str = str + "Taxable state benefits";
		str = str + "</TD>";
		str = str + "<TD width='300' class='tablebg1' colSpan='2'>£&nbsp;<input type=text name=t9 readOnly size=6 class=readOnlyTextbox value='" + calculateIndividualInterest(tbenefits, tbenefitsFreq) + "'></TD>";
		str = str + "</TR>";
		
		str = str + "<TR>";
		
		str = str + "<TD class='tablebg1' colSpan='2'>";
		str = str + "Earnings";
		str = str + "</TD>";
		str = str + "<TD width='300' class='tablebg1' colSpan='2'>£&nbsp;<input type=text name=t10 readOnly size=6 class=readOnlyTextbox value='" + calculateIndividualInterest(earnings, earningsFreq) + "'></TD>";
		str = str + "</TR>";
		
		str = str + "<TR>";
		
		str = str + "<TD class='tablebg1' colSpan='2'>";
		str = str + "Company share dividends";
		str = str + "</TD>";
		str = str + "<TD width='300' class='tablebg1' colSpan='2'>£&nbsp;<input type=text name=t11 readOnly size=6 class=readOnlyTextbox value='" + calculateIndividualInterest(sdividends, sdividendsFreq) + "'></TD>";
		str = str + "</TR>";
		
		str = str + "<TR>";
		
		str = str + "<TD class='tablebg1' colSpan='2'>";
		str = str + "Other income";
		str = str + "</TD>";
		str = str + "<TD width='300' class='tablebg1' colSpan='2'>£&nbsp;<input type=text name=t12 readOnly size=6 class=readOnlyTextbox value='" + calculateIndividualInterest(otherincome, otherincomeFreq) + "'></TD>";
		str = str + "</TR>";
		
		str = str + "<TR>";
		
		str = str + "<TD class='tablebg1' colSpan='2'>";
		str = str + "&nbsp;";
		str = str + "</TD>";
		str = str + "<TD width='300' class='tablebg1' colSpan='2'>&nbsp;</TD>";
		str = str + "</TR>";
		
		str = str + "<TR>";
		
		str = str + "<TD class='tablebg1' colSpan='2'>";
		str = str + "<b>Total Income</b>";
		str = str + "</TD>";
		str = str + "<TD width='300' class='tablebg1' colSpan='2'><b>£</b><input type=text name=t13 readOnly size=6 class=readOnlyTextboxBold value='" + totalIncome + "'></TD>";
		str = str + "</TR>";
		
		str = str + "<TR>";
		
		str = str + "<TD class='tablebg1' colSpan='2'>";
		str = str + "&nbsp;";
		str = str + "</TD>";
		str = str + "<TD width='300' class='tablebg1' colSpan='2'>&nbsp;</TD>";
		str = str + "</TR>";
		str = str + "<TR>";
		
		str = str + "<TD class='tablebg1' colSpan='2'>";
		str = str + "<b>Total Income - Total Allowances = </b>";
		str = str + "</TD>";
		str = str + "<TD width='300' class='tablebg1' colSpan='2'><b>£</b><input type=text name=t14 readOnly size=6 class=readOnlyTextboxBold value='" + ResultedValue + "'></TD>";
		str = str + "</TR>";
		
		str = str + "<TR>";
		
		str = str + "<TD class='tablebg1' colSpan='2'>";
		str = str + "&nbsp;";
		str = str + "</TD>";
		str = str + "<TD width='300' class='tablebg1' colSpan='2'>&nbsp;</TD>";
		str = str + "</TR>";
		str = str + "</TABLE>";
		str = str + "<BR><BR>"
					
		document.getElementById('results').style.visibility = "visible";
		document.getElementById('results').innerHTML = str; //appending the HTML string to a div
		
		if (document.getElementById) 
		{
			eval("document.all.summarylb.focus();");
		}
		else
		{
			if (document.layers) 
			{ // Netscape 4 
				eval("document.summarylb.focus();");
			}
			else
			{
				eval("document.all.summarylb.focus();");
			}
		}
}//end of verifyAll function.


function showDateDiff()
	{
		today=new Date();
		xday = document.ir85.dobday.value;
		xmonth = document.ir85.dobmonth.value;
		xyear = document.ir85.dobyear.value;
		
		var givenDate=new Date(xyear, xmonth-1, xday) //Month is 0-11 in JavaScript
		//Set 1 day in milliseconds
		var one_day=1000*60*60*24;
		
		if (Math.ceil((givenDate.getTime()-today.getTime())/(one_day)) > 0 )
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	
function calculateInterest(passedValue, selectedFreqValue, tIncome)
{
	var multiplier=1;
	
	switch (selectedFreqValue)
	{
		case "weekly" : multiplier = 52;
			break;
						
		case "fortnightly" : multiplier = 26;
			break;
						
		case "monthly"  : multiplier = 13
			break;
			
		case "calendarmonthly" : multiplier = 12
			break;
			
		case "quarterly" : multiplier = 4
			break;
			
		case "halfyearly": multiplier = 2
			break;

		default: multiplier=1;
				break;
	}

	passedValue*=multiplier;
	tIncome += parseInt(passedValue,10);
	return tIncome;
}

function calculateIndividualInterest(passedValue, selectedFreqValue)
{
	var multiplier=1;
	
	switch (selectedFreqValue)
	{
		case "weekly" : multiplier = 52;
			break;
						
		case "fortnightly" : multiplier = 26;
			break;
						
		case "monthly"  : multiplier = 13
			break;
			
		case "calendarmonthly" : multiplier = 12
			break;
			
		case "quarterly" : multiplier = 4
			break;
			
		case "halfyearly": multiplier = 2
			break;

		default: multiplier=1;
				break;
	}

	passedValue*=multiplier;
	passedValue = parseInt(passedValue,10);
	return passedValue;
}