function Comma(SS) { var T='', S=String(SS), L=S.length-1, C, j
  for (j=0; j<=L; j++) {
    T+=C=S.charAt(j)
    if ((j < L) && ((L-j)%3 == 0) && (C != '-')) T+=',' }
  return T
}

function mailIt() {
	targetMail=sliderForm.inputTarget.value
    Mail="mailto:Please input the appropriate email address here?subject=Retirement Planning&body=My projected pension income is "+outputSLPension.innerHTML+". Based on the income I'd like at retirement, I have a shortfall of "+outputShortfall.innerHTML+"\r\r\n\n\n"
    window.location.href=Mail;
} 

function doTheCalc() {

if (sliderForm.sexVal[0].checked) {
	sexValue="male"
} else {
	sexValue="female"
}
stripCommas();
if (!validInputs()) {
	setCommas();
	return false;
}

var eeTotal=parseFloat(parseFloat(sliderForm.existingPayment.value)+parseFloat(sliderForm.eeInput.value));
doCalc(sliderForm.ageInput.value,sexValue,sliderForm.retAgeInput.value, sliderForm.lumpsumInput.value,sliderForm.salaryInput.value,eeTotal,sliderForm.erInput.value,sliderForm.inputTarget.value,sliderForm.yearlyInput.value);
setCommas();
}

  var slider1 = new Slider("Slider1");
  slider1.onchange = "document.sliderForm.inputTarget.value = '£'+Comma( (Math.round(slider1.getValue()/500)*500) )";
  slider1.buttonHiliteImg = "static/img/sliderbutton.gif";
  slider1.maxSlide = 200; 
  slider1.buttonWidth = 22;
  slider1.buttonHeight = 28; 
  slider1.leftValue = 1000;
  slider1.rightValue = 100000;
  slider1.defaultValue = 20000;  
  slider1.onmouseup = "doTheCalc()" 
  
  
  var slider2 = new Slider("Slider2");
  slider2.onchange = "document.sliderForm.retAgeInput.value = Math.round(slider2.getValue())";
  slider2.buttonHiliteImg = "static/img/sliderbutton.gif";
  slider2.maxSlide = 200; 
  slider2.buttonWidth = 22;
  slider2.buttonHeight = 28; 
  slider2.leftValue = 55;
  slider2.rightValue = 74;
  slider2.defaultValue = 65;
  slider2.onmouseup = "prepCalc()"  
  
  var slider3 = new Slider("Slider3");
  slider3.onchange = "document.sliderForm.eeInput.value =Math.round(slider3.getValue()*10)/10";
  slider3.buttonHiliteImg = "static/img/sliderbutton.gif";
  slider3.maxSlide = 200;
  slider3.buttonWidth = 22;
  slider3.buttonHeight = 28; 
  slider3.leftValue = 0;
  slider3.rightValue = 100;
  slider3.defaultValue = 0;  
  slider3.onmouseup = "doTheCalc()"  
  
  var slider4 = new Slider("Slider4");
  slider4.onchange = "document.sliderForm.erInput.value = Math.round(slider4.getValue()*10)/10";
  slider4.buttonHiliteImg = "static/img/sliderbutton.gif";
  slider4.maxSlide = 200;
  slider4.buttonWidth = 22;
  slider4.buttonHeight = 28; 
  slider4.leftValue = 0.0;
  slider4.rightValue = 30.0;
  slider4.defaultValue = 0;  
  slider4.onmouseup = "doTheCalc()"  
  
function resetForm() {
	sliderForm.incomeAge.value=65
	sliderForm.eeInput.value=0
	sliderForm.erInput.value=splashER.value
	sliderForm.existingPayment.value=splashEE.value
	sliderForm.retAgeInput.value=65

	sliderForm.yearlyInput.value=0
	sliderForm.lumpsumInput.value=0
	sliderForm.ageInput.value=splashAge.value
	sliderForm.salaryInput.value=splashSalary.value
	if (splashSex[0].checked) {
		document.sliderForm.sexVal[0].checked=true
	} else {
		document.sliderForm.sexVal[1].checked=true
	}
	setTarget(splashSalary.value)
slider2.setValue(65)	
	slider3.setValue(0)
    slider4.setValue(splashER.value)  
	doTheCalc()
	
}
function prepCalc() {
	stripCommas();
		sliderForm.yearlyInput.className="inputBox"
		sliderForm.incomeAge.className="inputBoxSmall"	
	if (sliderForm.retAgeInput.value==sliderForm.ageInput.value || sliderForm.retAgeInput.value < sliderForm.ageInput.value || parseInt(sliderForm.retAgeInput.value) ==parseInt(sliderForm.ageInput.value)+1) {
		window.alert("Sorry, we are unable to provide you with a quote within one year of your chosen retirement date. Please contact your employer or financial adviser.")
		return;
	}
	if (sliderForm.yearlyInput.value>0 && (sliderForm.incomeAge.value>sliderForm.retAgeInput.value)) {
		window.alert("Sorry, the date your yearly income starts must be less than or equal to your chosen retirement date.\nPlease either decrease the start date or convert your yearly income to a lump sum before proceeding.");
		sliderForm.yearlyInput.className="inputBoxHi"
		sliderForm.incomeAge.className="inputBoxSmallHi"
		return;
	}


	if(validInputs()) 
	{  

//paul devlin added the following code to allow BSP to be shown for females
		if (sliderForm.sexVal[0].checked) 
		{
			//male
			StatePensionAge="65";
		} 
		else
		{
			//female
			StatePensionAge="60";
		}

		if (sliderForm.retAgeInput.value < StatePensionAge) 
		{
			exclude.style.display="none"
			sliderForm.excludeBSP.checked=true
		}
		else 
		{
			exclude.style.display="none"
			sliderForm.excludeBSP.checked=false
		}
		doTheCalc()
	}
}

function doSal(salary) {
document.onkeydown = function() {
		if (event.keyCode == 13) {
			setTarget(salary);
			prepCalc()
		}
	}
}

function doOnEnter() {
document.onkeydown = function() {
		if (event.keyCode == 13) {
			prepCalc()
		}
	}
}

function do1OnEnter(what) {
document.onkeydown = function() {
		if (event.keyCode == 13) {
stripCommas();if(validInputs()) {slider1.setValue(what);doTheCalc()}
		}
	}
}
function do2OnEnter(what) {
document.onkeydown = function() {
		if (event.keyCode == 13) {
stripCommas();if(validInputs()) {slider2.setValue(what);doTheCalc()}
		}
	}
}
function doEEOnEnter(what) {
document.onkeydown = function() {
		if (event.keyCode == 13) {
			stripCommas();
			if(validInputs()) { 
				setIncreaseLimits(what);
				doTheCalc() 
			}
		}
	}
}

function doEEPOnEnter(what) {
document.onkeydown = function() {
		if (event.keyCode == 13) {
stripCommas();if(validInputs()) {doTheCalc()}
		}
	}
}
function doEROnEnter(what) {
document.onkeydown = function() {
		if (event.keyCode == 13) {
stripCommas();if(validInputs()) {doTheCalc()}
		}
	}
}

function setTarget(toWhat) {
toWhat=Math.round(parseFloat(toWhat)*0.75)
slider1.setValue(toWhat)
}

function setIncreaseLimits(toWhat) {
	toWhat=parseFloat(toWhat)
	if (toWhat+slider3.getValue()>100) {
		slider3.setValue(100-toWhat)
	}
	slider3.rightValue=(100-toWhat)
	slider3.setValue(document.sliderForm.eeInput.value)
	erLimit.innerText=(100-toWhat)+"%"
}

function showSplash() {
splashBox0.style.display=""
}

function setCommas() {
	document.sliderForm.salaryInput.value="£"+Comma(document.sliderForm.salaryInput.value)
	document.sliderForm.yearlyInput.value="£"+Comma(document.sliderForm.yearlyInput.value)
	document.sliderForm.lumpsumInput.value="£"+Comma(document.sliderForm.lumpsumInput.value)	
	document.sliderForm.inputTarget.value="£"+Comma(document.sliderForm.inputTarget.value)	
	outputShortfall.innerText="£"+Comma(sliderForm.hiddenShortfall.value)
	outputSLPension.innerText="£"+Comma(sliderForm.hiddenPension.value)			
	outputPension.innerText="£"+Comma(document.sliderForm.hiddenIMV.value)			

		
}

function stripCommas() {
	document.sliderForm.salaryInput.value=stringFilter(document.sliderForm.salaryInput.value)
	document.sliderForm.yearlyInput.value=stringFilter(document.sliderForm.yearlyInput.value)
	document.sliderForm.lumpsumInput.value=stringFilter(document.sliderForm.lumpsumInput.value)	
	document.sliderForm.inputTarget.value=stringFilter(document.sliderForm.inputTarget.value)	
		

}

function stringFilter (s) {

filteredValues = ",£%";     
var i;
var returnString = "";
for (i = 0; i < s.length; i++) {  
var c = s.charAt(i);
if (filteredValues.indexOf(c) == -1) returnString += c;
}
return returnString;
}




function closeSplash(age,sal,male,female,ee,er) {

	var validInputs=true;
	var errorMessage="";
	if ((age<16) || (age>74)) {
		errorMessage+="- your age must be between 16 and 74.\n"
		validInputs=false
	}
	if (!IsNumeric(age)) {
		errorMessage+="- your age must be between 16 and 74.\n"
		validInputs=false
	}	
	if ((parseFloat(sal)<0) || (parseFloat(sal)>225000)) {
		errorMessage+="- your salary must be between £0 and £225,000.\n"
		validInputs=false
	}
	if (!IsNumeric(sal)) {
		errorMessage+="- your salary must be between £0 and £225,000.\n"
		validInputs=false
	}	
	if ((male==false) && (female==false)) {
		errorMessage+="- please select your gender.\n"
		validInputs=false
	}
	if ((ee<0) || (ee>100)) {
		errorMessage+="- your payment must be between 0% and 100%.\n"
		validInputs=false
	}
	if (!IsNumeric2(ee)) {
		errorMessage+="- your payment must be between 0% and 100%.\n"
		validInputs=false
	}	
	if ((er<0) || (er>30)) {
		errorMessage+="- your employer's payment must be between 0% and 30%.\n"
		validInputs=false
	}
	if (!IsNumeric2(ee)) {
		errorMessage+="- your employer's payment must be between 0% and 100%.\n"
		validInputs=false
	}	
	if (parseInt(ee)+parseInt(er)>100) {
		errorMessage+="- your payment plus your employer's payment cannot exceed 100%.\n"
		validInputs=false
	}			
	if (!validInputs) {
		window.alert("Please correct the following before proceeding:\n\n"+errorMessage)
		return false
	}
	introTextOnly.style.display="none"
	sal=parseFloat(sal)
	sliderForm.existingPayment.value=ee
	sliderForm.erInput.value=er
	sliderForm.ageInput.value=age
	sliderForm.salaryInput.value=sal
	setTarget(sal)
	if (male) {
		document.sliderForm.sexVal[0].checked=true
	} else {
		document.sliderForm.sexVal[1].checked=true
	}
	splashBox0.style.display="none"
	setIncreaseLimits(ee)
	doTheCalc()
}


function doCalc(curAge,sx,retAge,lumpsum,salary,ee,er,target,yearlyPen) {

// constants / assumptions

var annualInflationRate=0.025
var annualEarningsInflation=0.025
var annualManagementCharge=0.01
var annualInvestmentGrowthRate=0.07
var annuityExpenseRate=0.04
var annuityEscalationRate=0.0
var annuityPaymentFrequency=12
var RPI=0.025
//paul devlin changed this rate to 0.006, 01/04/2008
//var annuityInterestRate=0.008
var annuityInterestRate=0.004
var spousePercentage=0.5
var annualCreationOfUnit=0.0
var basicStatePension=97.65

// user inputs

if ((retAge=="") || (retAge==null)) {
	retAge="0"
}
if ((lumpsum=="") || (lumpsum==null)) {
	lumpsum="0"
}
if ((yearlyPen=="") || (yearlyPen==null)) {
	yearlyPen="0"
}
if ((ee=="") || (ee==null)) {
	ee="0"
}
if ((er=="") || (er==null)) {
	er="0"
}

var currentAge=parseInt(curAge)
var sex=sx
var retirementAge=parseInt(retAge)
var existingFund=parseFloat(lumpsum)
var grossSalary=parseFloat(salary)
var eeCont=parseFloat(ee)
var erCont=parseFloat(er)
var inputTarget=parseFloat(target)

if (!validAge(currentAge)) {
	return false;
}

if (!validRetAge(retirementAge)) {
	return false;
}

if (!validSalary(grossSalary)) {
	return false;
}

if (!validTarget(inputTarget)) {
	return false;
}



// get date of birth

var YOB=getYOB(curAge)
//tested correct

var spouseYOB=0
var spouseCurrAge=0
var spouseRetirementAge=0

if (sex=="male") {
	spouseYOB=YOB+3
	spouseCurrAge=currentAge-3
	spouseRetirementAge=retirementAge-3
} else {
	spouseYOB=YOB-3
	spouseCurrAge=currentAge+3
	spouseRetirementAge=retirementAge+3	
}
//tested correct
<!-- window.alert("Year of birth:"+YOB+"\nSpouse YOB:"+spouseYOB+"\nSpouse current age:"+spouseCurrAge+"\nSpouse retirement age:"+spouseRetirementAge) -->
	
// calculate monthly contribution
var monthlyCont=((eeCont+erCont)*(grossSalary/12)) / 100
//looks ok
<!-- window.alert("Monthly contribution:"+monthlyCont) -->

// set fund starting value to be existing fund value

var fund=existingFund
<!-- window.alert("Existing fund:"+fund) -->

// set value for Single Life calculation

var j=(1.0+annuityInterestRate) / (1.0+annuityEscalationRate) - 1.0

<!-- window.alert("Rate for single life calc:"+j) -->

// get PMA / PFA denominator
var denom=0.0
if (sex=="male") {
	denom=getPMA(retirementAge,YOB)
} else {
	denom=getPFA(retirementAge,YOB)
}
<!-- window.alert("Value from mortality table:"+denom) -->


//tested correct

// calculate single life - this could be wrong
var sigmaValue=0
for (t=0;t<=(120-retirementAge);t++) {
	if (sex=="male") {
		sigmaValue+=( getPMA(retirementAge+t,YOB) / Math.pow((1+j),t))
	} else {
		sigmaValue+=( getPFA(retirementAge+t,YOB) / Math.pow((1+j),t))
	}
}

<!-- window.alert("Single life - before mort rate applied:"+sigmaValue) -->

sigmaValue=sigmaValue / denom

<!-- window.alert("Single life divided by mort rate:"+sigmaValue) -->


sigmaValue=(1+annuityExpenseRate)*(sigmaValue-(annuityPaymentFrequency-1)/(2*annuityPaymentFrequency))

<!-- window.alert("Single life after annuity expense rate applied:"+sigmaValue) -->

//calculate reversionary factor
var denom2=0.0
if (sex=="male") {
	denom2=getPFA(spouseRetirementAge,spouseYOB)
} else {
	denom2=getPMA(spouseRetirementAge,spouseYOB)
}

var maxAge=0
if (spouseRetirementAge>retirementAge) {
	maxAge=spouseRetirementAge
} else {
	maxAge=retirementAge
}

var reversionaryFactor=0
for (u=0;u<(120-maxAge);u++) {
if (sex=="male") {
	retAge1=getPMA(retirementAge,YOB)
	retAge2=getPMA(retirementAge+u,YOB)
	retAge3=getPFA(spouseRetirementAge+u,spouseYOB)
	reversionaryFactor+=(retAge1-retAge2)*retAge3 / Math.pow((1+j),u)
} else {
	retAge1=getPFA(retirementAge,YOB)
	retAge2=getPFA(retirementAge+u,YOB)
	retAge3=getPMA(spouseRetirementAge+u,spouseYOB)
	reversionaryFactor+=(retAge1-retAge2)*retAge3 / Math.pow((1+j),u)
}
}



reversionaryFactor=reversionaryFactor/(denom*denom2)


reversionaryFactor=(1+annuityExpenseRate)*reversionaryFactor
<!-- window.alert("Reversionary factor:"+reversionaryFactor) -->


sigmaValue=sigmaValue+((0.5)*(reversionaryFactor))
<!-- window.alert("Single life with reversionary factor applied:"+sigmaValue) -->


// calculate factor
var amcPower=Math.pow((1-annualManagementCharge/365),365)
var factor=Math.pow( (1+annualInvestmentGrowthRate)*(amcPower),(1/12))
factor=factor*(1+annualCreationOfUnit/12)

<!-- window.alert("Factor:"+factor) -->

//calculate term
var term=retirementAge-currentAge
term2=term
term=(term*12)-6

<!-- window.alert("Term:"+term) -->

//calculate fund
var fund=existingFund
var fundSig=0
for (x=0;x<term;x++) {
//	fund=fund+monthlyCont*(Math.pow((1+annualInflationRate),(x/12)))*factor
	effectOfInf=Math.pow(1+annualInflationRate,parseInt(x/12))
	fundSig=(fund+monthlyCont*effectOfInf)*factor
	fund=fundSig
}


//discount to today's term

for (y=1;y<=((term2*2)-1);y++) {
	fund=fund / Math.pow((1+RPI),(1/2))
}

<!-- window.alert("Fund (post RPI):"+fund) -->

var pension=fund/sigmaValue
<!-- window.alert("Annual pension:"+pension) -->
<!-- outputPension.value=parseInt(fund) -->
<!-- outputPensionAnnual.value=parseInt(pension) -->
var prevBenTot=0
<!--if (!sliderForm.excludeBSP.checked) { -->
<!--	prevBenTot=basicStatePension*52; -->
<!-- } -->
if (retirementAge >= parseInt(sliderForm.incomeAge.value) ) {
 prevBenTot+=parseInt(yearlyPen) 
}

var shortFall=parseInt(inputTarget-(pension+prevBenTot))
if (shortFall<0) shortFall=0
outputShortfall.innerText=shortFall
sliderForm.hiddenShortfall.value=shortFall

outputEEMonthly.innerText="£"+Comma(parseInt( (grossSalary/12)*(eeCont/100)))
sliderForm.hiddenEEMonthly.value=parseInt( (grossSalary/12)*(eeCont/100))
outputERMonthly.innerText="£"+Comma(parseInt( (grossSalary/12)*(erCont/100)))
sliderForm.hiddenERMonthly.value=parseInt( (grossSalary/12)*(erCont/100))

totalCylinders=(prevBenTot+pension+shortFall)
if (shortFall>0) {totalCylinders=parseInt(sliderForm.inputTarget.value) }
cNum1=parseInt(totalCylinders/1000*1000)
cNum2=parseInt(((totalCylinders/3)*2)/1000*1000)
cNum3=parseInt(((totalCylinders/3))/1000*1000)

cn1.innerText="£"+parseInt(cNum1/100)*100
cn2.innerText="£"+parseInt(cNum2/100)*100
cn3.innerText="£"+parseInt(cNum3/100)*100

percentPrevBen=parseInt((prevBenTot/totalCylinders)*100)
percentPension=parseInt((pension/totalCylinders)*100)
percentShortfall=parseInt((shortFall/totalCylinders)*100)

var filler=(100-(percentPrevBen+percentPension+percentShortfall))
if (filler<0) { percentPension-=filler }
if (filler>0) { percentPension+=filler }


height1=parseInt((2*percentPrevBen))
height2=parseInt((2*percentPension))
height3=parseInt((2*percentShortfall))

prevbenBlock.style.height=height1
pensionBlock.style.height=height2
shortfallBlock.style.height=height3

if (height1==0) { prevbenBlock.style.display="none" } else { prevbenBlock.style.display="" }
if (height2==0) { pensionBlock.style.display="none" } else { pensionBlock.style.display="" }
if (height3==0) { shortfallBlock.style.display="none" } else { shortfallBlock.style.display="" }

if (prevBenTot<=0 && pension<=0 && shortFall>0) {
	//red only - working
	green_top.style.display="none"
	green_top2.style.display="none"	
	red_green.style.display="none"	
	red_bottom.style.display="none"		
	green_bottom.style.display="none"
	prevbenBlock.style.display="none"
	blue_top.style.display="none"
	blue_bottom.style.display="none"
	pensionBlock.style.display="none"	
	red_top.style.display="block"
	shortfallBlock.style.display="block"	
	red_bottom2.style.display="block"
	shortfallBlock.style.height=(height3+27)	
}

if (prevBenTot>0 && pension<=0 && shortFall>0) {
	// green red - working
	green_top.style.display="none"
	green_top2.style.display="none"	
	red_green.style.display="block"	
	red_bottom.style.display="none"		
	green_bottom.style.display="block"
	prevbenBlock.style.display="block"
	blue_top.style.display="none"
	blue_bottom.style.display="none"
	pensionBlock.style.display="none"	
	red_top.style.display="block"
	shortfallBlock.style.display="block"	
	red_bottom2.style.display="none"
	shortfallBlock.style.height=(height3+15)
}

if (prevBenTot<=0 && pension>0 && shortFall>0) {
	// blue red - working
	green_top.style.display="none"
	green_top2.style.display="none"	
	red_green.style.display="none"	
	red_bottom.style.display="block"		
	green_bottom.style.display="none"
	prevbenBlock.style.display="none"
	blue_top.style.display="none"
	blue_bottom.style.display="block"
	pensionBlock.style.display="block"	
	red_top.style.display="block"
	shortfallBlock.style.display="block"	
	red_bottom2.style.display="none"
	shortfallBlock.style.height=(height3+7)	
	pensionBlock.style.height=(height2+8)
}

if (prevBenTot>0 && pension>0 && shortFall>0) {
	// all 3 - working
	green_top.style.display="none"
	green_top2.style.display="block"	
	red_green.style.display="none"	
	red_bottom.style.display="block"		
	green_bottom.style.display="block"
	prevbenBlock.style.display="block"
	blue_top.style.display="none"
	blue_bottom.style.display="none"
	pensionBlock.style.display="block"	
	red_top.style.display="block"
	shortfallBlock.style.display="block"	
	red_bottom2.style.display="none"
}

if (prevBenTot>0 && pension>0 && shortFall<=0) {
	// green blue - working
	green_top.style.display="none"
	green_top2.style.display="block"	
	red_green.style.display="none"	
	red_bottom.style.display="none"		
	green_bottom.style.display="block"
	prevbenBlock.style.display="block"
	blue_top.style.display="block"
	blue_bottom.style.display="none"
	pensionBlock.style.display="block"	
	red_top.style.display="none"
	shortfallBlock.style.display="none"	
	red_bottom2.style.display="none"
	pensionBlock.style.height=(height2+15)	
}

if (prevBenTot<=0 && pension>0 && shortFall<=0) {
	// blue only - working
	green_top.style.display="none"
	green_top2.style.display="none"	
	red_green.style.display="none"	
	red_bottom.style.display="none"		
	green_bottom.style.display="none"
	prevbenBlock.style.display="none"
	blue_top.style.display="block"
	blue_bottom.style.display="block"
	pensionBlock.style.display="block"	
	red_top.style.display="none"
	shortfallBlock.style.display="none"	
	red_bottom2.style.display="none"
	pensionBlock.style.height=(height2+27)	
}

if (prevBenTot>0 && pension<=0 && shortFall<=0) {
	// green only
	green_top.style.display="block"
	green_top2.style.display="none"	
	red_green.style.display="none"	
	red_bottom.style.display="none"		
	green_bottom.style.display="block"
	prevbenBlock.style.display="block"
	blue_top.style.display="none"
	blue_bottom.style.display="none"
	pensionBlock.style.display="none"	
	red_top.style.display="none"
	shortfallBlock.style.display="none"	
	red_bottom2.style.display="none"
	prevbenBlock.style.height=(height1+27)
}


document.sliderForm.hiddenPension.value=to3SigFig(pension+prevBenTot)
outputSLPension.innerText=to3SigFig(pension+prevBenTot)
document.sliderForm.hiddenIMV.value=to3SigFig(pension)

pension=to3SigFig(pension)
outputPension.innerText=to3SigFig(pension)
pensionBlock.title="The value of your pension is £"+pension
shortfallBlock.title="Your shortfall is £"+shortFall
prevbenBlock.title="The total value of your existing benefits is £"+parseInt(prevBenTot)
}

function to3SigFig(what) {
	valRounded=""
	valToRound=parseInt(what)+""
	for (i=0;i<valToRound.length;i++) {
		if (i<3) {
			valRounded+=valToRound.charAt(i)
		} else {
			valRounded+="0"
		}
	}
	return parseInt(valRounded)
}

// function to calculate year of birth (assumes age is age last birthday)

function getYOB(age) {

var now=new Date()
var year=now.getYear()
var month=now.getMonth()
year=year-age
if (month < 7) {
	year=year-1
} 
return year

}

// function to get a specified entry of the PMA table, based on retirement age and DOB

function getPMA(retAge,yearOfBirth) {

	var YOBArray=PMA[retAge].split(",");
	
	yearOfBirth=yearOfBirth-1925
	
	return PMAresult=YOBArray[yearOfBirth]

}
	
function getPFA(retAge,yearOfBirth) {

	var fYOBArray=PFA[retAge].split(",");
	
	fyearOfBirth=yearOfBirth-1925
	
	return PFAresult=fYOBArray[fyearOfBirth]

}	
function validInputs() {
	if (!validTotalConts(sliderForm.eeInput.value,sliderForm.erInput.value,sliderForm.existingPayment.value)) {
		return false
	}
	if (!validAge(sliderForm.ageInput.value)) {
		sliderForm.ageInput.focus()
		return false;
	}
	if (!validSalary(sliderForm.salaryInput.value)) {
		sliderForm.salaryInput.focus()	
		return false;
	}
	if (!validRetAge(sliderForm.retAgeInput.value)) {
		sliderForm.retAgeInput.focus()	
		return false;
	}	
	if (!validYearly(sliderForm.yearlyInput.value)) {
		sliderForm.yearlyInput.focus()		
		return false;
	}	
	if (!validIncAge(sliderForm.incomeAge.value)) {
		sliderForm.incomeAge.focus()		
		return false;
	}			
	if (!validLumpsum(sliderForm.lumpsumInput.value)) {
		sliderForm.lumpsumInput.focus()		
		return false;
	}	
	if (!validYearly(sliderForm.yearlyInput.value)) {
		sliderForm.yearlyInput.focus()		
		return false;
	}
	if (!validTarget(sliderForm.inputTarget.value)) {
		sliderForm.inputTarget.focus()		
		return false;
	}			
	if (!validEE(sliderForm.existingPayment.value)) {
		sliderForm.existingPayment.focus()		
		return false;
	}		
	if (!validER(sliderForm.erInput.value)) {
		sliderForm.erInput.focus()		
		return false;
	}	
	if (!validIncreasedEE(sliderForm.eeInput.value)) {
		sliderForm.eeInput.focus()		
		return false;
	}				
	return true;
}
	
function validTotalConts(val1, val2, val3) {
	if (parseInt(val1)+parseInt(val2)+parseInt(val3)>100)	 {
		window.alert("The total contribution of your and your employer's payments cannot exceed 100%")
		return false;
	}
	return true;
}
	
function validAge(toVal) {
	if (!IsNumeric1(toVal)) {
		window.alert("Your age must be a number between 16 and 74")
		return false;
	}
	if ((toVal<16) || (toVal>74)) {
		window.alert("Please enter an age between 16 and 74")	
		return false;
	} else {
		return true;
	}
} 

function validRetAge(toVal) {
	if (!IsNumeric1(toVal)) {
		window.alert("Your retirement age must be a number between 55 and 74")
		return false;
	}
	if ((toVal<55) || (toVal>74)) {
		window.alert("Please enter a retirement age between 55 and 74")	
		return false;
	} else {
		return true;
	}
} 

function validIncAge(toVal) {
	if (!IsNumeric1(toVal)) {
		window.alert("The age your yearly pension income takes effect must be a number between 50 and 75")
		return false;
	}
	if ((toVal<50) || (toVal>75)) {
		window.alert("The age your yearly pension income takes effect must be a number between 50 and 75")	
		return false;
	} else {
		return true;
	}
} 

function validSalary(toVal) {
	if (!IsNumeric(toVal)) {
		window.alert("Your salary should be a figure between £0 and £225,000 in whole pounds.")
		return false;
	}
	if ((toVal<0) || (toVal>225000)) {
		window.alert("Your salary should be a figure between £0 and £225,000 in whole pounds.")	
		return false;
	} else {
		return true;
	}
} 

function validYearly(toVal) {
	if (toVal=="0") return true;
	if (!IsNumeric(toVal)) {
		window.alert("Your existing pension income should be a figure between £500 and £100,000 in whole pounds.")
		return false;
	}	
	toVal=parseFloat(toVal)
	if ((toVal<500.00) || (toVal>100000.00)) {
		window.alert("Your existing pension income should be a figure between £500 and £100,000 in whole pounds.")	
		return false;
	} else {
		return true;
	}
} 
function validLumpsum(toVal) {
	if (toVal=="0") return true;
	if (!IsNumeric(toVal)) {
		window.alert("Your existing pension lump sum should be a figure between £1,000 and £2,000,000 in whole pounds.")
		return false;
	}		
	toVal=parseFloat(toVal)
	if ((toVal<1000.00) || (toVal>2000000.00)) {
		window.alert("Your existing pension lump sum should be a figure between £1,000 and £2,000,000 in whole pounds.")	
		return false;
	} else {
		return true;
	}
} 

function validEE(toVal) {
	if (!IsNumeric2(toVal)) {
		window.alert("Your existing payment should be a percentage between 0 and 100.")
		return false;
	}		
	toVal=parseFloat(toVal)
	if ((toVal<0) || (toVal>100)) {
		window.alert("Your existing payment should be a percentage between 0 and 100.")	
		return false;
	} else {
		return true;
	}
} 

function validER(toVal) {
	if (!IsNumeric2(toVal)) {
		window.alert("Your employer's payment should be a percentage between 0 and 30.")
		return false;
	}		
	toVal=parseFloat(toVal)
	if ((toVal<0) || (toVal>30)) {
		window.alert("Your employer's payment should be a percentage between 0 and 30.")	
		return false;
	} else {
		return true;
	}
} 

function validIncreasedEE(toVal) {
	if (!IsNumeric2(toVal)) {
		window.alert("Your increased payment should be a percentage between 0 and 100.")
		return false;
	}		
	toVal=parseFloat(toVal)
	if ((toVal<0) || (toVal>100)) {
		window.alert("Your increased payment should be a percentage between 0 and 100.")	
		return false;
	} else {
		return true;
	}
} 


function validTarget(toVal) {
	if (!IsNumeric(toVal)) {
		window.alert("Your target income should be a figure between £1,000 and £100,000 in whole pounds.")
		return false;
	}	
	if ((toVal<1000.00) || (toVal>100000.00)) {
		window.alert("Your target income should be a figure between £1,000 and £100,000 in whole pounds.")	
		return false;
	} else {
		return true;
	}
} 

function mandatoryFields(age,salary) {
	if ((age==null) || (age=="")) {
		return false;
	}
	if ((salary==null) || (salary="")) {
		return false;
	}
	return true;
}

function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789,";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }
function IsNumeric1(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }   

function IsNumeric2(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789.";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }  
   
   

		var textSquirt="'hidden'"   
function showHelp(forWhat) {
	if (forWhat=="salary") {
		helpWindow.style.visibility="visible"
		helpWindow.innerHTML="This is usually your basic annual salary before tax.  (If you receive additional payments such as bonuses and shift payments, please speak to your employer to determine if these can be included in your pensionable earnings).<br/><br/><a href='#' onclick=helpWindow.style.visibility="+textSquirt+"><img src='static/img/help_stop.gif' border='0'/></a>"
	}
	if (forWhat=="age") {
		helpAge.style.visibility="visible"
		helpAge.innerHTML="Please type your current age.<br/><br/><a href='#' onclick=helpAge.style.visibility="+textSquirt+"><img src='static/img/help_stop.gif' border='0'/></a>"
	}
	if (forWhat=="sex") {
		helpSex.style.visibility="visible"	
		helpSex.innerHTML="Please select the relevant button (M for Male, F for Female)<br/><br/><a href='#' onclick=helpSex.style.visibility="+textSquirt+"><img src='static/img/help_stop.gif' border='0'/></a>"
	}
	if (forWhat=="existingIncome") {
		helpIncome.style.visibility="visible"
		helpIncome.innerHTML="If you have been a member of a Final Salary or Defined Benefit pension scheme and you wish to include this:<br/>Enter the amount of pension income you expect to receive each year. You will find this on a statement from the trustees who run the scheme.<br/>Please note: you should include the pension income amount given in today's terms, not the projected amount that will be paid on your retirement age, often described as the 'revalued pension.'<br/>Please also input the age this pension is due to start.  This age will also be shown on the statement from the trustees.  Note: If you retire before or after this age the amount of this pension could change.<br/>Other yearly incomes can be included in this section. For example:- Rental income, inheritance monies etc.<br/><br/><a href='#' onclick=helpIncome.style.visibility="+textSquirt+"><img src='static/img/help_stop.gif' border='0'/></a>"
	}	
	if (forWhat=="existingLump") {
		helpLump.style.visibility="visible"
		helpLump.innerHTML="If you have any other money purchase plans which you would like to have included in the calculation, please enter the transfer value or fund value. (This figure will be shown on your most recent statement for that plan). If you have more than one plan pension plan please add the transfer values together and input the total into this field.<br/><br/><a href='#' onclick=helpLump.style.visibility="+textSquirt+"><img src='static/img/help_stop.gif' border='0'/></a>"
	}
	if (forWhat=="bsp") {
		helpBSP.style.visibility="visible"	
		helpBSP.innerHTML="Tick this box to exclude the basic state pension from the calculations (you can tick it again later to include it)<br/><br/><a href='#' onclick=helpBSP.style.visibility="+textSquirt+"><img src='static/img/help_stop.gif' border='0'/></a>"
	}	
	if (forWhat=="target") {
		helpTarget.style.visibility="visible"	
		helpTarget.innerHTML="Initially the target income field will default to 75% of  your current annual salary. Please overtype the default income or use the slider bar to increase/decrease this amount by moving the dial.<br/>You may be able to convert some of this pension to a tax-free lump sum.<br/><br/><a href='#' onclick=helpTarget.style.visibility="+textSquirt+"><img src='static/img/help_stop.gif' border='0'/></a>"
	}	
	if (forWhat=="shortfall") {
		helpShortfall.style.visibility="visible"
		helpShortfall.innerHTML="This figure will be displayed after the calculation routine has run. The figure can be increased/decreased by using the various slider bars provided or by changing the different figures in the interactive fields.<br/><br/><a href='#' onclick=helpShortfall.style.visibility="+textSquirt+"><img src='static/img/help_stop.gif' border='0'/></a>"
	}				
	if (forWhat=="totalIMV") {
		helpIMV.style.visibility="visible"		
		helpIMV.innerHTML="This figure has been created using the information you have given in the fields provided. This figure will change when you change the information you have provided on this screen.<br/><br/><a href='#' onclick=helpIMV.style.visibility="+textSquirt+"><img src='static/img/help_stop.gif' border='0'/></a>"
	}	
		
	if (forWhat=="nrd") {
		helpRetAge.style.visibility="visible"		
		helpRetAge.innerHTML="Please enter an age between 55 and 74. (The minimum pension age is increasing to age 55 from 6 April 2010) Note that certain types of company pension scheme may have rules on the age at which you wish to retire - please speak to your employer if you require further information.<br/>If you have selected a normal retirement age of 65 years old, basic state pension can be included in the final projected income on retirement.<br/>This amount can be overtyped or you can increase/decrease the amount using the slider bar provided.<br/><br/><a href='#' onclick=helpRetAge.style.visibility="+textSquirt+"><img src='static/img/help_stop.gif' border='0'/></a>"
	}		
	if (forWhat=="existEE") {
		helpInitialEE.style.visibility="visible"
		helpInitialEE.innerHTML="The calculator assumes your payments are a percentage of your gross annual salary. It will also assume that your payments increase each year in line with the Retail Price Index (RPI) - currently this is assumed to be 2.5%. The minimum amount you can pay will be determined by the type of pension contract you have and your employer if you are in a group scheme.<br/><br/><a href='#' onclick=helpInitialEE.style.visibility="+textSquirt+"><img src='static/img/help_stop.gif' border='0'/></a>"
	}		
	if (forWhat=="plusEE") {
		helpIncrEE.style.visibility="visible"	
		helpIncrEE.innerHTML="This will show the revised projection taking this additional payment into account.<br/>It is also assumed that this payment will increase each year in line with the Retail Price Index (RPI) - currently assumed to be 2.5%.<br/>This amount can be overtyped or you can increase/decrease the amount by using the slider bar provided.<br/><br/><a href='#' onclick=helpIncrEE.style.visibility="+textSquirt+"><img src='static/img/help_stop.gif' border='0'/></a>"
	}	
	if (forWhat=="flatEE") {
		helpFlatEE.style.visibility="visible"	
		helpFlatEE.innerHTML="This field displays your proposed percentage in a flat amount.<br/><br/><a href='#' onclick=helpFlatEE.style.visibility="+textSquirt+"><img src='static/img/help_stop.gif' border='0'/></a>"
	}		
	if (forWhat=="helpItself") {
		helpItself.style.visibility="visible"	
		helpItself.innerHTML="Please hover over each field for detailed help and explanation of each item on the calculator.<br/><br/><a href='#' onclick=helpItself.style.visibility="+textSquirt+"><img src='static/img/help_stop.gif' border='0'/></a>"
	}			
	
	if (forWhat=="ER") {
		helpER.style.visibility="visible"		
		helpER.innerHTML="If your employer will make payments to your pension, you can enter the percentage or flat amount here.<br/>It is also assumed that this payment will increase each year in line with the Retail Price Index (RPI) - currently assumed to be 2.5% a year.<br/>Your employer or financial adviser can tell you the rules and limits for any employer payments. It is possible to overtype or use the slider bar to increase/decrease the amount.<br/>Some employers may offer to 'match' employee payments. You can use a combination of the employer and your own payments sliders to see what different 'matching' payments provide at retirement.<br/><br/><a href='#' onclick=helpER.style.visibility="+textSquirt+"><img src='static/img/help_stop.gif' border='0'/></a>"
	}	
	if (forWhat=="flatamnt") {
		footer.innerHTML="This field displays your proposed percentage in a flat amount.<br/><br/><a href='javascript:hideHelp()'><img src='static/img/help_stop.gif' border='0'/></a>"
	}			
	if (forWhat=="imv") {
		footer.innerHTML="This is your total projected pension income, including any income you may have from previous penions and the basic state pension.<br/><br/><a href='javascript:hideHelp()'><img src='static/img/help_stop.gif' border='0'/></a>"
	}				
					
}
