// test if a field has had anything entered into it
function blank(entry,entryVal){

	if(entryVal == "" )
	{	
	alert('Please put a value in this field');
	entry.value = "0";
	entry.select(); 
	return(false); 
	}	
}


// test that entry is made up of numbers
// also used to validate telephone numbers
// by allowing brackeets, dashes, commas, periods
function numbers(entry,entryVal)
{
	if(entryVal == "" )
	{	
		alert('Please put a value in this field')
		entry.value = "0"
		entry.select()
		return(false)
	}
	
	var checkOK = "0123456789"; //.,-()";
	var checkStr = entryVal;
	var allValid = true;
	var allNum = "";

	for (i = 0;  i < checkStr.length;  i++)
	{

	ch = checkStr.charAt(i);

		for (j = 0;  j < checkOK.length;  j++)

		if (ch == checkOK.charAt(j))
		break;

		if (j == checkOK.length)
		{
		allValid = false;
		break;
		}

		if (ch != ",")
		allNum += ch;
	}

	if (!allValid)
	{
		alert("Please enter only digit characters in this field.");
		entry.value = "0"		
		entry.select();
		return (false);
	}
}


	// test that entry is made up of numbers
	// also used to validate telephone numbers
	// by allowing brackets, dashes, commas, periods
function phoneNumbers(entry,entryVal)
{
	if(entryVal == "" )
	{	
		alert('Please put a value in this field')
		entry.value = "0"
		entry.select()
		return(false)
	}
	
	var checkOK = "0123456789//.,-()";
	var checkStr = entryVal;
	var allValid = true;
	var allNum = "";

	for (i = 0;  i < checkStr.length;  i++)
	{

	ch = checkStr.charAt(i);

		for (j = 0;  j < checkOK.length;  j++)

		if (ch == checkOK.charAt(j))
		break;

		if (j == checkOK.length)
		{
		allValid = false;
		break;
		}

		if (ch != ",")
		allNum += ch;
	}

	if (!allValid)
	{
		alert("Please enter only digit characters in this field.");
		entry.value = "0"		
		entry.select();
		return (false);
	}
}

		// require at least one radio button be selected
		// this version of the function is form specific to LEN100
function radio(entry,name){
	var radioSelected = -1;
	for (i = 0;  i < LEN100.button.length;  i++)
		{
		if (LEN100.button[i].checked){
		radioSelected = true;
		}
	}
	if (radioSelected == -1)
	{
	alert("Please select one of the choices.");
	return (false);
	}	
}

	//test for valid email address entry
function validEmail(entry, entryVal )
{
	var valid = true;
	
	invalidChars = "/:,;";
	if(entryVal == "")
	{
		valid = false;
	}

	for (i = 0 ; i < invalidChars.length; i ++ )
	{
		badChar = invalidChars.charAt(i);
		if ( entryVal.indexOf(badChar,0)> -1)
		{ 
		valid = false;
		}
	}

	atPos = entryVal.indexOf("@",1);

	if (atPos == -1)
	{
	valid = false;
	}
	
	if (entryVal.indexOf("@",atPos+1) > -1)
	{
	valid = false;
	}

	periodPos = entryVal.indexOf(".",atPos+1);

	if ( periodPos == -1)
	{
	valid = false;
	}

	if (periodPos + 4 < entryVal.length)
	{
	valid = false;
	}
	
	if (valid == false)
	{
	alert("Invalid e-mail address.");
	entry.value = 'name@domain.com';
	entry.select();
	}	
	
}


// function to determine how much a couple can borrow
// works specifically for form LEN102
function howMuch(){
	
	var total1 = 0;
	var total2 = 0;

	for(i = 0; i < 8 ; i = i+2)
	{
		if(document.LEN102.elements[i].value == 0)
		{ }						
		else
		{
		total1 = total1 + Number(document.LEN102.elements[i].value);
		}
	}

	for(j = 1; j < 8 ; j = j+2)
	{
		if(document.LEN102.elements[j].value == 0)
		{ }						
		else
		{
		total2 = total2 + Number(document.LEN102.elements[j].value);
		}
	}

	total1 *= 3;

	total = (total1 + total2);

	return total;
}


// function specific to the budget calculator page (LEN104)
// this fuction calculates the monthly surplus from the details entered
function budget(){
	
	var income = 0;
	var outgoings = 0;
	var surplus = 0;

	for(i = 0 ; i < 10 ; i++)
	{	
		income = income + Number(document.LEN104.elements[i].value);
	}

	for(j = 10 ; j < 30 ; j++)
	{
		outgoings = outgoings + Number(document.LEN104.elements[j].value);
	}

	surplus = Number(income - outgoings);

	return surplus;
}

// function specific to the budget calculator page (LEN114)
// this fuction calculates the monthly surplus from the details entered
function budgetCar(){
	
	var income = 0;
	var outgoings = 0;
	var surplus = 0;

	for(i = 0 ; i < 10 ; i++)
	{	
		income = income + Number(document.LEN114.elements[i].value);
	}

	for(j = 10 ; j < 30 ; j++)
	{
		outgoings = outgoings + Number(document.LEN114.elements[j].value);
	}

	surplus = Number(income - outgoings);

	return surplus;
}

// function specific to the budget calculator page (LEN119)
// this fuction calculates the monthly surplus from the details entered
function budgetPersonal(){
	
	var income = 0;
	var outgoings = 0;
	var surplus = 0;

	for(i = 0 ; i < 10 ; i++)
	{	
		income = income + Number(document.LEN119.elements[i].value);
	}

	for(j = 10 ; j < 30 ; j++)
	{
		outgoings = outgoings + Number(document.LEN119.elements[j].value);
	}

	surplus = Number(income - outgoings);

	return surplus;
}
// function to calculate the equity in a house
// specific to LEN108
function equity(){
	currValue = LEN108.currValue.value;
	outstanding = LEN108.outstanding.value;
	equityIn = currValue - outstanding;
	return equityIn;
}


// function to calculate a person additional borrowing capacity
// specific to LEN108
function additional(){
	capacity = ((LEN108.currValue.value) * .9) - (LEN108.outstanding.value);
	return parseInt(capacity);
}


// function to calculate proceeds from selling one's house
// specific to LEN107
function movingHouse(){
	sellingPrice = Number(LEN107.sellingPrice.value);
	outstanding = Number(LEN107.outstanding.value);
	solicitor = Number(LEN107.solicitor.value);
	estate = Number(LEN107.estate.value);
	other = Number(LEN107.other.value);
	costs = Number(outstanding + solicitor + estate + other);
	proceeds = sellingPrice - costs;
	return proceeds;
}

// function to determine the cost of changing house
// specific to LEN107
function newAmount(){
	amount = Number(LEN107.costNew.value) - Number(movingHouse()); 
	return amount;
}

// function specific to LEN18. Calculates the size of the mortgage required
function mortgageRequired(){
	var purchaseCosts = 0
	var sourceFunds = 0

	for(i=0;i<6;i++)
	{purchaseCosts = purchaseCosts + Number(document.LEN18.elements[i].value);}

	for(j=7;j<12;j++)
	{sourceFunds = sourceFunds + Number(document.LEN18.elements[j].value);}

	amount = purchaseCosts - sourceFunds;

	return amount;
}


// function specific to LEN18. Calculates the total cost of the proposed purchase
function totalRequired(){
	var purchaseCosts = 0

	for(i=0;i<6;i++)
	{purchaseCosts = purchaseCosts + Number(document.LEN18.elements[i].value);}
	return purchaseCosts;
}


// function specific to LEN18. Calculates the total amount of source funds available
function sourceFunds(){

	var source = 0

	for(j=7;j<12;j++)
	{source = source + Number(document.LEN18.elements[j].value);}
	
	return source;
}

// function specific to LEN105
// Generates dummy values for the amount of tax relief available
// as a result of particular loans

function taxRelief(){
	loanAmount = Number(LEN105.loanAmount.value);
	interestRate = Number(LEN105.interestRate.value);
	term = LEN105.term.value;
	
	taxReliefAmount = loanAmount * (interestRate/10000) * term;

	return taxReliefAmount ;
}	


// function specific to LEN106
// calculates the cost of buying a house
function depositRequired(){

	purchasePrice = Number(LEN106.purchasePrice.value);
	mortgageAmount = Number(LEN106.mortgageAmount.value);

	deposit = purchasePrice - mortgageAmount;

	return deposit;
}



//gregs functions
//************************************************************************************************
// validates that a text field contains something, at least a 0
function checkInput(greg, greg2) {
  if (greg2 == "") {
    alert("Please enter a value!");
	greg.value="0";
	greg.select();
  }
}


// together with a path name in value, jumps to another location from
// each element in a combo box
function jumpPage(newLoc){
	newPage = newLoc.options[newLoc.selectedIndex].value

	if(newPage!=""){
	window.location.href = newPage
	}
}


// validates a phone number
function validPhone(greg, greg2)
{
	if (greg2 == "")
	{
		alert("Please enter a phone no");
		greg.value="0";
		greg.select();
	}

var checkOK = "0123456789-/().";
var checkStr = greg2;
var allValid = true;
var allNum = "";
	for(i = 0; i < checkStr.length; i++)
	{
		ch = checkStr.charAt(i);
		for (j = 0; j < checkOK.length; j++)
			if (ch == checkOK.charAt(j))
			break;
			if (j == checkOK.length)
			{
				allValid = false;
				break;
			}
		if (ch != ",")
			allNum += ch;
	}
		if (!allValid)
		{
			alert("Please enter a valid phone no");
			greg.select();
			greg.focus();
		}

}




// check if no drop down has been selected
function dropDown(entry, entryVal){

	if (entry.selectedIndex == 0)
	{
	alert("Please select one of the options.");
	entry.selectedIndex = 1;
	//return (false);
	}
}

function plastic(greg)
{
	if (greg.aggressive.value == "regions")
	{
		alert("this is plastic ");
	}
}


//**********************************************************************************************

// function for SAV102 to detrmine which fund to direct the customer towards

function fundSelection(){

if(SAV102.profile[5].checked && document.SAV102.sectorList.value == 0)
{	alert('Please select which sector you are interested in');
	document.SAV102.profile[5].focus(); 
 	return 0;
}

if(SAV102.profile[4].checked && document.SAV102.regionList.value == 0)
{	alert('Please select which region you are interested in');
	document.SAV102.profile[4].focus();
 	return 0;
}

if(SAV102.profile[9].checked && document.SAV102.risk.value == 0)
{	alert('Please select which degree of risk suits you');
	document.SAV102.profile[9].focus();
 	return 0; 
}

	
var growth = false
var income = false
var priority = false
var access = false
var fallRise = false
var guaranteed = false
var market = false
var overFive = true
var regular = false
var property= false
var profile = 'None Selected'
var regionList = SAV102.regionList.value
var sectorList = SAV102.sectorList.value

for(i=0;i<1;i++){
	if(SAV102.growth[i].checked && SAV102.growth[i].value == 'yes')
	{
		var growth = true;
	}
	
	if(SAV102.income[i].checked && SAV102.income[i].value == 'yes')
	{
		var income = true;
	}

	if(SAV102.priority[i].checked && SAV102.priority[i].value == 'yes')
	{
		var priority = true;
	}

	if(SAV102.access[i].checked && SAV102.access[i].value == 'yes')
	{
		var access = true;
	}

	if(SAV102.fallRise[i].checked && SAV102.fallRise[i].value == 'yes')
	{
		var fallRise = true;
	}

	if(SAV102.guaranteed[i].checked && SAV102.guaranteed[i].value == 'yes')
	{
		var guaranteed = true;
	}

	if(SAV102.market[i].checked && SAV102.market[i].value == 'yes')
	{
		var market = true;
	}

	if(SAV102.overFive[i].checked && SAV102.overFive[i].value == 'no')
	{
		var overFive = false; 
	}

	if(SAV102.regular[i].checked && SAV102.regular[i].value == 'yes')
	{
		var regular = true;
	}

	if(SAV102.property[i].checked && SAV102.property[i].value == 'yes')
	{
		var property = true;
	}
}

for(j=0;j<11;j++){
	if(SAV102.profile[j].checked)
	{
		var profile = SAV102.profile[j].value ;
	}
}


// Fund 1
	if(!fallRise && guaranteed && !market && profile == 'secureRegardless')
	{
		alert('Fixed interest')
	}
	
//Fund 2 is below

// Fund3
	else if(growth && income && priority && !access && !guaranteed && profile == 'secureRegardless')
	{
		alert('With Profit');
	}

// Fund4
	else if(growth && !access && !guaranteed && overFive && profile == 'secureRegardless')
	{
		alert('With Profit');
	}

// Fund2 this is out of sequence because the criteria for funds 3 and 4 cause it to execute
	else if(!access && !fallRise && overFive && profile == 'secureRegardless')
	{
		alert('Guaranteed');
	}

// Fund5
	else if(growth && !access && !guaranteed && market && overFive && profile == 'lowRisk')
	{
		alert('Cautiously managed');
	}

// Fund6
	else if(growth && !access && !guaranteed && market && !overFive && profile == 'mediumLow')
	{
		alert('Managed funds');
	}

// Fund7 these criteria are the same as those for fund 12
	else if(growth && !access && !guaranteed && market && overFive && profile == 'mediumHigh')
	{
		alert('International Equity');
	}

// Fund8 
	else if(growth && !access && !guaranteed && market && overFive && profile == 'regions' && regionList == 3)   
	{
		alert('European Equity');
	}

// Fund9 
	else if(growth && !access && !guaranteed && market && overFive && profile == 'regions' && regionList == 4)   
	{
		alert('American Equity');
	}

// Fund10 
	else if(growth && !access && !guaranteed && market && overFive && profile == 'regions' && regionList == 6)   
	{
		alert('Far East');
	}

// Fund11 
	else if(growth && !access && !guaranteed && market && overFive && profile == 'regions' && regionList == 5)   
	{
		alert('Japaneese');
	}

// Fund12 same criteria as Fund7 'General Equity'

// Fund13 region 
	else if(growth && !access && !guaranteed && market && overFive && profile == 'regions' && regionList == 1)   
	{
		alert('Irish Equity');
	}
 
// Fund14
	else if(growth && !access && fallRise && !guaranteed && market && property && overFive && profile =='mediumLow')
	{
		alert('Property');
	}

/////////////////////////////////////
// Fund15 which of the 4 options available under 'E'  'Property'
// this test overlaps the criteria for regions/sectors/focus/hedge
//	else if(growth && !access && !guaranteed && market && overFive && (profile == 'regions'|| profile =='sectors'||profile=='focus'||profile=='hedge'))   
//	{
//		alert('Property');
//	}
///////////////////////////////////////

// Fund16 
	else if(growth && !access && !guaranteed && market && overFive && profile == 'regions' && regionList == 2)   
	{
		alert('United Kingdom');
	}
	
// Fund17 generic test for any of the sectors
	else if(growth && !access && fallRise && !guaranteed && market && overFive && profile == 'sectors' && sectorList == 1)
	{
		alert('Telecommunications');
	}

// Fund18 sector 'Telecommunictions'
	else if(growth && !access && fallRise && !guaranteed && market && overFive && profile == 'sectors' && sectorList == 2)
	{
		alert('Technology');
	}
	
// Fund19
	else if(growth && !access && fallRise && !guaranteed && market && overFive && profile == 'focus')
	{
		alert('Focus Funds');
	}

////////////////////////////////////////////////////////////
// Fund20 option'C' OR which of 4 options available under 'E'  
// this test overlaps the criteria for regions/sectors/focus/hedge
//	else if(growth && !access && !guaranteed && market && overFive && (profile == 'regions'|| profile =='sectors'||profile=='focus'||profile=='hedge'||profile=='mediumLow'))   
//	{
//		alert('Special Saving Funds');
//	}
////////////////////////////////////////////////////////////

// Fund21 
	else if(income && priority && !access && fallrise && !guaranteed && market && overFive && profile == 'mediumLow')
	{
		alert('Income Funds');
	}

// Fund22 yet to take account of th level of risk the investor is willing to take!
	else if(growth && !access && fallRise && !guaranteed && market && overFive && profile == 'varyingYes')
	{
		alert('Fund categories as per user');
	}

// Fund23
	else if(growth && !access && fallRise && !guaranteed && market && overFive && profile == 'hedge')
	{
		alert('Hedge Funds');
	}

// Fund24
	else if(growth && !access && fallRise && !guaranteed && market && overFive && profile == 'useBroker')
	{
		alert('Direct Equities');
	}

// default if no fund has been selected
	else
	{
		alert('The criteria do not match a specific fund!!');
		window.location = 'LEN105.htm';
	}

}// end of fundSelection


// function specific to SAV102 to reset sector/risk lists
function resetList(){
	document.SAV102.sectorList.value = 0;
	document.SAV102.risk.value = 0;
}

// function specific to SAV102 to reset regions/risk lists
function resetList2(){
	document.SAV102.regionList.value = 0;
	document.SAV102.risk.value = 0;
}

// function specific to SAV102 to reset regions/sector lists
function resetList3(){
	document.SAV102.regionList.value = 0;
	document.SAV102.sectorList.value = 0;
}

// function specific to SAV102 to reset region/sector/risk lists
function resetBoth(){
	document.SAV102.sectorList.value = 0;
	document.SAV102.regionList.value = 0;
	document.SAV102.risk.value = 0;
}

// function to select radio button when corresponding combobox is clicked
function holdRisk(){
	if(!SAV102.profile[9].checked){
	document.SAV102.risk.value = 0;
	SAV102.profile[9].checked = true;
	resetList3(this);
}
}

// function to select radio button when corresponding combobox is clicked
function holdRegion(){
	if(!SAV102.profile[4].checked){
	document.SAV102.regionList.value = 0;
	SAV102.profile[4].checked = true;
	resetList(this);
}
}

// function to select radio button when corresponding combobox is clicked
function holdSector(){
	if(!SAV102.profile[5].checked){
	document.SAV102.sectorList.value = 0;
	SAV102.profile[5].checked = true;
	resetList2(this);
}
}
//***********************************************************************************************

//check if total of percentages equals 100
function validPercent(SAV101)
{
propertyDI = Number(SAV101.PortfolioDirectInvestmentsProperty.value)
irishDI = Number(SAV101.PortfolioDirectInvestmentsIrish.value)
internationalDI = Number(SAV101.PortfolioDirectInvestmentsInternational.value)
cashDI = Number(SAV101.PortfolioDirectInvestmentsCash.value)
bondsDI = Number(SAV101.PortfolioDirectInvestmentsBonds.value)
totalDI = propertyDI + irishDI + internationalDI + cashDI + bondsDI
totalDInv = Number(SAV101.PortfolioDirectInvestmentsTotal.value)

property = Number(SAV101.PortfolioInvestmentFundsProperty.value)
irish = Number(SAV101.PortfolioInvestmentFundsIrish.value)
international = Number(SAV101.PortfolioInvestmentFundsInternational.value)
cash = Number(SAV101.PortfolioInvestmentFundsCash.value)
bonds = Number(SAV101.PortfolioInvestmentFundsBonds.value)
total = property + irish + international + cash + bonds
totalElse = Number(SAV101.PortfolioInvestmentFundsTotal.value)
	
	if (totalDI != totalDInv && totalDI >= 0)
	{
		alert("Direct Investments: values do not add up to total entered");
		SAV101.PortfolioDirectInvestmentsTotal.focus();
		return (false);
	}

	if (total != totalElse && total >= 0)
	{
		alert("Investment Funds: values do not add up to total entered");
		SAV101.PortfolioInvestmentFundsTotal.focus();
		return (false);
	}


propertyTemp = 0;
irishTemp = 0;
internationalTemp = 0;
cashTemp = 0;
bondsTemp = 0;

propertyTemp = parseInt((property  + propertyDI));
irishTemp = parseInt((irish + irishDI));
internationalTemp = parseInt((international + internationalDI));
cashTemp = parseInt((cash + cashDI));
bondsTemp = parseInt((bonds + bondsDI));


SAV101.propertyP.value = propertyTemp
SAV101.irishP.value = irishTemp
SAV101.intlP.value = internationalTemp
SAV101.cashP.value = cashTemp
SAV101.bondsP.value = bondsTemp
SAV101.avgTotal.value = totalElse + totalDInv

return true;
}

function dispTotal() {
propertyDI = Number(document.SAV101.PortfolioDirectInvestmentsProperty.value)
irishDI = Number(document.SAV101.PortfolioDirectInvestmentsIrish.value)
internationalDI = Number(document.SAV101.PortfolioDirectInvestmentsInternational.value)
cashDI = Number(document.SAV101.PortfolioDirectInvestmentsCash.value)
bondsDI = Number(document.SAV101.PortfolioDirectInvestmentsBonds.value)
totalDI = propertyDI + irishDI + internationalDI + cashDI + bondsDI
document.SAV101.PortfolioDirectInvestmentsTotal.value = totalDI
totalDInv = Number(document.SAV101.PortfolioDirectInvestmentsTotal.value)

property = Number(document.SAV101.PortfolioInvestmentFundsProperty.value)
irish = Number(document.SAV101.PortfolioInvestmentFundsIrish.value)
international = Number(document.SAV101.PortfolioInvestmentFundsInternational.value)
cash = Number(document.SAV101.PortfolioInvestmentFundsCash.value)
bonds = Number(document.SAV101.PortfolioInvestmentFundsBonds.value)
total = property + irish + international + cash + bonds
document.SAV101.PortfolioInvestmentFundsTotal.value = total
totalElse = Number(document.SAV101.PortfolioInvestmentFundsTotal.value)
	
var propertyTemp = parseInt(property + propertyDI);
var irishTemp = parseInt(irish + irishDI);
var internationalTemp = parseInt(international + internationalDI);
var cashTemp = parseInt(cash + cashDI);
var bondsTemp = parseInt(bonds + bondsDI);


document.SAV101.PortfolioTotalValue.value = totalElse + totalDInv;
document.SAV101.PortfolioPercentProperty.value = propertyTemp*100/(document.SAV101.PortfolioTotalValue.value);
document.SAV101.PortfolioPercentIrish.value = irishTemp*100/(document.SAV101.PortfolioTotalValue.value);
document.SAV101.PortfolioPercentInternational.value = internationalTemp*100/(document.SAV101.PortfolioTotalValue.value);
document.SAV101.PortfolioPercentCash.value = cashTemp*100/(document.SAV101.PortfolioTotalValue.value);
document.SAV101.PortfolioPercentBonds.value = bondsTemp*100/(document.SAV101.PortfolioTotalValue.value);
}

            // work out percentage for segment of piecharts etc.
            //
function percent(grandTotal, colTotal){
	return colTotal * 100 / grandTotal;
}

//*********************************************************************************************

// ************
// globals 
// ************

var numCountries = 100
var EuroToIEP = 0.787564

DbnonEu= new Array(new Array("--------",0),
					new Array("GB Pound",1),
					new Array("D.Mark",2),
					new Array("Fr Franc",3),
					new Array("Guilder",4),
					new Array("B Fr",5),
					new Array("It Lira",6),
					new Array("Irish Pound",7),
					new Array("Cz. Krone",8),
					new Array("Nor Krone",9),
					new Array("Swiss Franc",10),
					new Array("Cyprus Pound",11),
					new Array("Hun Forints",12),
					new Array("Zloty",13),
					new Array("Bul Dinar",14),
					new Array("Slovenia",15))

DbEu= new Array(new Array("--------",0),
					new Array("GB Pound",1),
					new Array("D.Mark",2),
					new Array("Fr Franc",3),
					new Array("Guilder",4),
					new Array("B Fr",5),
					new Array("It Lira",6),
					new Array("",7),
					new Array("",8))

// ************

function EuroVal(curr) {
var currencyTable = new Array();

for (j = 0;  j < numCountries;  j++) 
	currencyTable[j]=0;

currencyTable[1]= 1.6039;	
currencyTable[2]= 0.5113;	
currencyTable[3]= 0.11;	
currencyTable[4]= 0.22;	
currencyTable[5]= 0.05;	
currencyTable[6]= 0.0005;	
currencyTable[7]= 1.269738;
currencyTable[8]= 0.04;	
currencyTable[9]= 0.12;	
currencyTable[10]= 0.15;	
currencyTable[11]= 0.14;	
currencyTable[12]= 0.12;	
currencyTable[13]= 0.08;	
currencyTable[14]= 0.05;	
currencyTable[15]= 0.04;	

if (currencyTable[curr]== 0 )
	return (-1)
else 
	return currencyTable[curr];
}


// ************

function EuroConvert(curr) {
var currencyTable = new Array();

for (j = 0;  j < numCountries;  j++) 
	currencyTable[j]=0;

currencyTable[1]= 0.6235;	
currencyTable[2]= 1.9557;	
currencyTable[3]= 9.0909;	
currencyTable[4]= 4.5454;	
currencyTable[5]= 20;	
currencyTable[6]= 2000;	
currencyTable[7]= 0.787564;
currencyTable[8]= 25;	
currencyTable[9]= 8.3333;	
currencyTable[10]= 6.6666;	
currencyTable[11]= 7.1428;	
currencyTable[12]= 8.3333;	
currencyTable[13]= 12.5;	
currencyTable[14]= 20;	
currencyTable[15]= 25;	

if (currencyTable[curr]== 0 )
	return (-1)
else 
	return currencyTable[curr];
}


// ************

function IrlVal(curr) {
var temp = 0;
temp = EuroVal(curr)
if (temp == -1)
	return (-1)
else 
	return temp * EuroToIEP;
}

// ************

function fivedecimal(value) {
temp = value * 100000;
converted = parseInt(temp);
return converted / 100000;
}

//*****************************************************

function convert(amountC,indexFrom,indexTo) {
var temp=0;
temp = EuroVal(indexFrom)* amountC		// convert 'From currency' to Euros
return temp * EuroConvert(indexTo)		// convert Euros to 'To currency'
}

//*****************************************************

function initialise() {
		for (j = 0;  j < DbnonEu.length;  j++) {
			document.theForm.selectCountry.options[j].text= DbnonEu[j][0]
			document.theForm.selectCountry.options[j].value= DbnonEu[j][1]			
		}
	    document.theForm.selectCountry.selectedIndex=0
}

 function changeList(target, newIndex) {

	if (target=='noneu') {
		for (j = 0;  j < DbnonEu.length;  j++) {
			document.theForm.selectCountry.options[j].text= DbnonEu[j][0]
			document.theForm.selectCountry.options[j].value= DbnonEu[j][1]
			document.theForm.selectCountry.selectedIndex=newIndex
			document.theForm.selecteu.selectedIndex=0  // reset other list
		}
	} else if (target=='eu') {
		for (j = 0;  j < DbEu.length;  j++) {
			document.theForm.selecteu.options[j].text= DbEu[j][0]
			document.theForm.selecteu.options[j].value= DbEu[j][1]
			document.theForm.selecteu.selectedIndex=newIndex
			document.theForm.selectCountry.selectedIndex=0  // reset other list
		}
	}
 }

 function copyIndex(indexNon,sts){
 	document.theForm.index_sel.value=indexNon 	
	document.theForm.status.value=sts
 }

//******************************************************************************



function emailOk()
{
     // check if email field is blank
     if (healthInfoForm.mail.value == "")
     {
         alert("Please enter a value for the \"Email\" field.");
         healthInfoForm.mail.focus();
         return (false);
     }
// test if valid email address, must have @ and .

    var checkEmail = "@.";
    var checkStr = healthInfoForm.mail.value;
    var EmailValid = false;
    var EmailAt = false;
    var EmailPeriod = false;
   
    for (i = 0;  i < checkStr.length;  i++)
    {
        ch = checkStr.charAt(i);
        for (j = 0;  j < checkEmail.length;  j++)
       {
           if (ch == checkEmail.charAt(j) && ch == "@")
           EmailAt = true;
           if (ch == checkEmail.charAt(j) && ch == ".")
           EmailPeriod = true;
	  
           if (EmailAt && EmailPeriod)
		break;
	   if (j == checkEmail.length)
		break;
	}
	// if both the @ and . were in the string

           if (EmailAt && EmailPeriod)
          {
		EmailValid = true
		break;
	 }
   }
        if (!EmailValid)
       {
           alert("The \"email\" field must contain an \"@\" and a \".\".");
           healthInfoForm.mail.focus();
           return (false);
      }
}

//check for blank fields
function checkIt(element)
{
	if (element.value =="")
	{
		alert("Please fill out the field before continuing")
		element.focus()
		element.value="0"
		return (false)
	}
}

/* **********************************************************
WIP Leo 5 July 2001

prevent nondigits being echoed to the screen
function checkNum2(this) {
	var v= parseFloat(this.value);
	if(isNaN(v)) {
		alert("got to here");
		this.value=this.value-1
		}
}
********************************************/


// Either only allow 0-9, hyphen and comma be entered
// or 0-9 and hyphen.
function checkNum(entry,entryval,typeCheck)
{
var checkOK = "";

if (typeCheck = digit) {
	checkOK = "0123456789-"; 
	}
else if (typeCheck = number) {         // WIP Leo 5 July 2001
	checkOK = "0123456789-,"; 
	}

	var checkStr = entryval;
	var allValid = true;
	var decPoints = 0;
	var allNum = "";
        
        if(entry.value=="")
	{
		alert("Please fill out the field before continuing")
		entry.focus()
		entry.value="0"
		return (false)
	}

	for (i = 0;  i < checkStr.length;  i++)
	{
		ch = checkStr.charAt(i);
		//alert(ch)
		for (j = 0;  j < checkOK.length;  j++)
		
		if (ch == checkOK.charAt(j))
			break;
		
		if (j == checkOK.length)
		{
			allValid = false;
			break;
		}
		if (ch != ",")
			allNum += ch;
	}
		if (!allValid)
		{
			alert("Please enter only digit characters in the \"NumberText\" field.");
			entry.select();
			return (false);
		}
}

// check that a drop down menu option selected

function drop(entry,entryval)
{
	if(entry.selectedIndex==0)
	{
		alert("Please select an option before continuing")
		entry.selectedIndex=1
		entry.focus()
	}
}

 function getParm(string,parm) {
     // returns value of parm from string
     var startPos = string.indexOf(parm + "=");
     if (startPos > -1) {
         startPos = startPos + parm.length + 1;
         var endPos = string.indexOf("&",startPos);
         if (endPos == -1)
             endPos = string.length;
         return unescape(string.substring(startPos,endPos));
     }
     return '';
 }

//******************************************************************************************
//calculate the salary replacement rate

function score()
{
	var A=salary.less5.value * 1
	var B=salary.less10.value * 0.9
	var C=salary.less15.value * 0.8
	var D=salary.less21.value * 0.7

	var rate=A+B+C+D
	//alert(rate)
	salary1=salary.gross1.value
	//alert(salary1)

	if( !salary.checkbox.checked)
	{
		if (rate >= 2)
			{var replacementRate1 = 0.75*salary1}
		if (rate >= 1 && rate < 2)
			{var replacementRate1 = 0.6*salary1}
		if (rate >=0 && rate <1)
			{var replacementRate1 = 0.5*salary1}

		//alert(replacementRate1)

		var salary2= salary.gross2.value
		//alert(salary2)

		if(salary2 ==0)
			{replacementRate2=0}
	
		if(rate >=3 && salary2 >0)
			{var replacementRate2= salary2*.5}
	
		if(rate>=2 && rate <3 && salary2 > 0)
			{var replacementRate2= salary2*.4}

		if(rate>=1 && rate <2 && salary2 > 0)
			{var replacementRate2= salary2*.3}

		if(rate>=0 && rate <1 && salary2 > 0)
			{var replacementRate2= salary2*.2}
	
		//alert ("replacementRate2 = " + replacementRate2)
		var replacementRateTotal=replacementRate1 + replacementRate2
		//alert(replacementRateTotal)
	}
	else
	{
		//alert("the checkbox has been ticked")

		var A=salary.less5.value * 1
		var B=salary.less10.value * 0.9
		var C=salary.less15.value * 0.8
		var D=salary.less21.value * 0.7

		var rate=A+B+C+D
		//alert(rate)
		salary1=salary.gross2.value
	
		if (rate >= 2)
			{var replacementRate1 = 0.75*salary1}
		if (rate >= 1 && rate < 2)
			{var replacementRate1 = 0.6*salary1}
		if (rate >=0 && rate <1)
			{var replacementRate1 = 0.5*salary1}

		//alert(replacementRate1)

		var salary2= salary.gross1.value
		//alert(salary2)

		if(salary2 ==0)
			{replacementRate2=0}

		if(rate >=3 && salary2 >0)
			{var replacementRate2= salary2*.5}
	
		if(rate>=2 && rate <3 && salary2 > 0)
			{var replacementRate2= salary2*.4}
	
		if(rate>=1 && rate <2 && salary2 > 0)
			{var replacementRate2= salary2*.3}

		if(rate>=0 && rate <1 && salary2 > 0)
			{var replacementRate2= salary2*.2}

		//alert ("replacementRate2 = " + replacementRate2)
		var replacementRateTotal=replacementRate1 + replacementRate2
		//alert(replacementRateTotal)
	}
	
	//calculate the income generation capacity of the assetts
	var total=0
	
	for(i=7;i<31;i=i+3)
	{
		total=total+ Number(document.salary.elements[i].value)
	}
	
	var ans1
	var ans2
	var ans3
	var ans4
	var ans5
	var ans6
	var ans7
	var ans8
	
	ans1=salary.propValue.value*salary.prop.value
	ans2=salary.sharesValue.value*salary.shares.value
	ans3=salary.cashValue.value*salary.cash.value
	ans4=salary.managedFundsVal.value*salary.managed.value
	ans5=salary.pensionValue.value*salary.pension.value
	ans6=salary.lifecoverval.value*salary.life.value
	ans7=salary.deathPayment.value*salary.death.value
	ans8=salary.miscellaneous.value*salary.misc.value

	/*for(j=9;j<31;j=j+3)
	n=1
	{
		document.salary.elements[j].value=ans(n)
		n++
	
	}*/
	
	
	salary.propRet.value=ans1
	salary.sharesRet.value=ans2
	salary.cashRet.value=ans3
	salary.fundsRet.value=ans4
	salary.pensionRet.value=ans5
	salary.lifeRet.value=ans6

	var totalRet = 0;
	
	for(k=9;k<31;k=k+3)
	{
		totalRet=totalRet+ Number(document.salary.elements[k].value)
		
	}
	var salaryLoss=replacementRateTotal *3  // 3 being life planner % from the parameter table!!!!!
	//alert(salaryLoss)

	var surplus=total-salaryLoss
	return surplus
	//alert("the surplus/deficit is  "+surplus)
	//salary.valueTotal.value=total
	//salary.retsTotal.value=totalRet
	//alert("hold page")
}

function total()
{
	var total=0
	
	for(i=7;i<31;i=i+3)
	{
		total=total+ Number(document.salary.elements[i].value)
	}
	
	
	
	
	var ans1
	var ans2
	var ans3
	var ans4
	var ans5
	var ans6
	var ans7
var ans8
	
	ans1=salary.propValue.value*salary.prop.value
	ans2=salary.sharesValue.value*salary.shares.value
	ans3=salary.cashValue.value*salary.cash.value
	ans4=salary.managedFundsVal.value*salary.managed.value
	ans5=salary.pensionValue.value*salary.pension.value
	ans6=salary.lifecoverval.value*salary.life.value
	ans7=salary.deathPayment.value*salary.death.value
	ans8=salary.miscellaneous.value*salary.misc.value
	
	
	salary.propRet.value=ans1/100
	salary.sharesRet.value=ans2/100
	salary.cashRet.value=ans3/100
	salary.fundsRet.value=ans4/100
	salary.pensionRet.value=ans5/100
	salary.lifeRet.value=ans6/100
	salary.deathRet.value=ans7/100
	salary.miscRet.value=ans8/100
	
	var totalRet=0
	
	for(k=9;k<31;k=k+3)
	{
		totalRet=totalRet+ Number(document.salary.elements[k].value)
		//alert(totalRet)
	}
	
	salary.valueTotal.value=total
	salary.retsTotal.value=totalRet
}
//	salary.deathRet.value=ans7;
//	 salary.miscRet.value=ans8;
//	
//	var totalRet=0
//}


function TickerContents() {	
   //				for home page
   //
   // this array simulates the dynamic table that will be loaded via ASP 
   //
   table= new Array(new Array("Smurfit",210,"-10"),
					new Array("Eircom",255,"+7"),
					new Array("AIB",1215,"+17"),
					new Array("Bank of Ireland",1078,"+1"),
					new Array("CRH",890,"+5"))
	marqueeStr=""
	for (j = 0;  j < table.length;  j++) {
		marqueeStr = marqueeStr + table[j][0]
		marqueeStr = marqueeStr + " " + table[j][1] 
		marqueeStr = marqueeStr + " ("		
		marqueeStr = marqueeStr + " " + table[j][2] 
		marqueeStr = marqueeStr + "),"		
		marqueeStr = marqueeStr + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
		}      
	return marqueeStr
}

function showTotal() {
	document.RET125.OtherRetirementIncomeTotal.value = Number(document.RET125.OtherRetirementIncomeRental.value) + Number(document.RET125.OtherRetirementIncomeInvestment.value) + Number(document.RET125.OtherRetirementIncomeOther.value);
}

function showTotalLoans() {
	document.PLA106.ClientOtherLoansTotal.value = Number(document.PLA106.ClientMortgageBalance.value) + Number(document.PLA106.ClientOtherMortgageBalanceOutstanding.value) + Number(document.PLA106.ClientCarLoansBalanceOutstanding.value) +
 Number(document.PLA106.ClientPersonalLoansBalanceOutstanding.value) +
 Number(document.PLA106.ClientOtherLoansBalanceOutstanding.value);
}

// shws total for  2000 - 2001 Tax year
function showTaxTotal() {
	document.TAX129.ClientDaysAbroad2000.value = Number(document.TAX129.ClientDaysAbroadApril2000.value) +
	Number(document.TAX129.ClientDaysAbroadMay2000.value) +
	Number(document.TAX129.ClientDaysAbroadJune2000.value) +
	Number(document.TAX129.ClientDaysAbroadJuly2000.value) +
	Number(document.TAX129.ClientDaysAbroadAugust2000.value) +
	Number(document.TAX129.ClientDaysAbroadSeptember2000.value) +
	Number(document.TAX129.ClientDaysAbroadOctober2000.value) +
	Number(document.TAX129.ClientDaysAbroadNovember2000.value) +
	Number(document.TAX129.ClientDaysAbroadDecember2000.value) +
	Number(document.TAX129.ClientDaysAbroadJanuary2001.value) +
	Number(document.TAX129.ClientDaysAbroadFebruary2001.value) +
	Number(document.TAX129.ClientDaysAbroadMarch2001.value) +
	Number(document.TAX129.ClientDaysAbroadApril2001a.value);
}

// shws total for 2001 Tax year
function showTaxTotal1() {
	document.TAX129.ClientDaysAbroad2001.value = Number(document.TAX129.ClientDaysAbroadApril2001.value) +
	Number(document.TAX129.ClientDaysAbroadMay2001.value) +
	Number(document.TAX129.ClientDaysAbroadJune2001.value) +
	Number(document.TAX129.ClientDaysAbroadJuly2001.value) +
	Number(document.TAX129.ClientDaysAbroadAugust2001.value) +
	Number(document.TAX129.ClientDaysAbroadSeptember2001.value) +
	Number(document.TAX129.ClientDaysAbroadOctober2001.value) +
	Number(document.TAX129.ClientDaysAbroadNovember2001.value) +
	Number(document.TAX129.ClientDaysAbroadDecember2001.value);
}

// shws total for 2002 Tax year
function showTaxTotal2() {
	document.TAX129.ClientDaysAbroad2002.value = Number(document.TAX129.ClientDaysAbroadApril2002.value) +
	Number(document.TAX129.ClientDaysAbroadMay2002.value) +
	Number(document.TAX129.ClientDaysAbroadJune2002.value) +
	Number(document.TAX129.ClientDaysAbroadJuly2002.value) +
	Number(document.TAX129.ClientDaysAbroadAugust2002.value) +
	Number(document.TAX129.ClientDaysAbroadSeptember2002.value) +
	Number(document.TAX129.ClientDaysAbroadOctober2002.value) +
	Number(document.TAX129.ClientDaysAbroadNovember2002.value) +
	Number(document.TAX129.ClientDaysAbroadDecember2002.value) +
	Number(document.TAX129.ClientDaysAbroadJanuary2002.value) +
	Number(document.TAX129.ClientDaysAbroadFebruary2002.value) +
	Number(document.TAX129.ClientDaysAbroadMarch2002.value);
}



// shws total for  2000 - 2001 Tax year Tax172
function showTaxTotal172() {
	document.TAX172.ClientDaysAbroad2000.value = Number(document.TAX172.ClientDaysAbroadApril2000.value) +
	Number(document.TAX172.ClientDaysAbroadMay2000.value) +
	Number(document.TAX172.ClientDaysAbroadJune2000.value) +
	Number(document.TAX172.ClientDaysAbroadJuly2000.value) +
	Number(document.TAX172.ClientDaysAbroadAugust2000.value) +
	Number(document.TAX172.ClientDaysAbroadSeptember2000.value) +
	Number(document.TAX172.ClientDaysAbroadOctober2000.value) +
	Number(document.TAX172.ClientDaysAbroadNovember2000.value) +
	Number(document.TAX172.ClientDaysAbroadDecember2000.value) +
	Number(document.TAX172.ClientDaysAbroadJanuary2001.value) +
	Number(document.TAX172.ClientDaysAbroadFebruary2001.value) +
	Number(document.TAX172.ClientDaysAbroadMarch2001.value) +
	Number(document.TAX172.ClientDaysAbroadApril2001a.value);
}

// shws total for 2001 Tax year TAX172
function showTaxTotal1172() {
	document.TAX172.ClientDaysAbroad2001.value = Number(document.TAX172.ClientDaysAbroadApril2001.value) +
	Number(document.TAX172.ClientDaysAbroadMay2001.value) +
	Number(document.TAX172.ClientDaysAbroadJune2001.value) +
	Number(document.TAX172.ClientDaysAbroadJuly2001.value) +
	Number(document.TAX172.ClientDaysAbroadAugust2001.value) +
	Number(document.TAX172.ClientDaysAbroadSeptember2001.value) +
	Number(document.TAX172.ClientDaysAbroadOctober2001.value) +
	Number(document.TAX172.ClientDaysAbroadNovember2001.value) +
	Number(document.TAX172.ClientDaysAbroadDecember2001.value);
}

// shws total for 2002 Tax year TAX172
function showTaxTotal2172() {
	document.TAX172.ClientDaysAbroad2002.value = Number(document.TAX172.ClientDaysAbroadApril2002.value) +
	Number(document.TAX172.ClientDaysAbroadMay2002.value) +
	Number(document.TAX172.ClientDaysAbroadJune2002.value) +
	Number(document.TAX172.ClientDaysAbroadJuly2002.value) +
	Number(document.TAX172.ClientDaysAbroadAugust2002.value) +
	Number(document.TAX172.ClientDaysAbroadSeptember2002.value) +
	Number(document.TAX172.ClientDaysAbroadOctober2002.value) +
	Number(document.TAX172.ClientDaysAbroadNovember2002.value) +
	Number(document.TAX172.ClientDaysAbroadDecember2002.value) +
	Number(document.TAX172.ClientDaysAbroadJanuary2002.value) +
	Number(document.TAX172.ClientDaysAbroadFebruary2002.value) +
	Number(document.TAX172.ClientDaysAbroadMarch2002.value);
}











// shws total for 2001 Tax year TAX130
function showTaxTotal1130() {
	document.TAX130.ClientDaysAbroad2001.value = Number(document.TAX130.ClientDaysAbroadApril2001.value) +
	Number(document.TAX130.ClientDaysAbroadMay2001.value) +
	Number(document.TAX130.ClientDaysAbroadJune2001.value) +
	Number(document.TAX130.ClientDaysAbroadJuly2001.value) +
	Number(document.TAX130.ClientDaysAbroadAugust2001.value) +
	Number(document.TAX130.ClientDaysAbroadSeptember2001.value) +
	Number(document.TAX130.ClientDaysAbroadOctober2001.value) +
	Number(document.TAX130.ClientDaysAbroadNovember2001.value) +
	Number(document.TAX130.ClientDaysAbroadDecember2001.value);
}

// shws total for 2002 Tax year TAX130
function showTaxTotal2130() {
	document.TAX130.ClientDaysAbroad2002.value =     Number(document.TAX130.ClientDaysAbroadApril2002.value) +
	Number(document.TAX130.ClientDaysAbroadMay2002.value) +
	Number(document.TAX130.ClientDaysAbroadJune2002.value) +
	Number(document.TAX130.ClientDaysAbroadJuly2002.value) +
	Number(document.TAX130.ClientDaysAbroadAugust2002.value) +
	Number(document.TAX130.ClientDaysAbroadSeptember2002.value) +
	Number(document.TAX130.ClientDaysAbroadOctober2002.value) +
	Number(document.TAX130.ClientDaysAbroadNovember2002.value) +
	Number(document.TAX130.ClientDaysAbroadDecember2002.value) +
	Number(document.TAX130.ClientDaysAbroadJanuary2002.value) +
	Number(document.TAX130.ClientDaysAbroadFebruary2002.value) +
	Number(document.TAX130.ClientDaysAbroadMarch2002.value);
}









function GetTotalDays1() {

	document.TAX129.ClientDaysAbroad1.value = Number(document.TAX129.January1.value) +
	Number(document.TAX129.February1.value) +
	Number(document.TAX129.March1.value) +
	Number(document.TAX129.April1.value) +
	Number(document.TAX129.May1.value) +
	Number(document.TAX129.June1.value) +
	Number(document.TAX129.July1.value) +
	Number(document.TAX129.August1.value) +
	Number(document.TAX129.September1.value) +
	Number(document.TAX129.October1.value) +
	Number(document.TAX129.November1.value) + 
	Number(document.TAX129.December1.value) ;
}


function GetTotalDays2() {
	document.TAX129.ClientDaysAbroad2.value = Number(document.TAX129.January2.value) +
	Number(document.TAX129.February2.value) +
	Number(document.TAX129.March2.value) +
	Number(document.TAX129.April2.value) +
	Number(document.TAX129.May2.value) +
	Number(document.TAX129.June2.value) +
	Number(document.TAX129.July2.value) +
	Number(document.TAX129.August2.value) +
	Number(document.TAX129.September2.value) +
	Number(document.TAX129.October2.value) +
	Number(document.TAX129.November2.value) + 
	Number(document.TAX129.December2.value) ;
}

function GetTotalDays3() {

	document.TAX129.ClientDaysAbroad3.value = Number(document.TAX129.January3.value) +
	Number(document.TAX129.February3.value) +
	Number(document.TAX129.March3.value) +
	Number(document.TAX129.April3.value) +
	Number(document.TAX129.May3.value) +
	Number(document.TAX129.June3.value) +
	Number(document.TAX129.July3.value) +
	Number(document.TAX129.August3.value) +
	Number(document.TAX129.September3.value) +
	Number(document.TAX129.October3.value) +
	Number(document.TAX129.November3.value) + 
	Number(document.TAX129.December3.value) ;}
	
	


function GetTotalDaysTax1721() {

	document.TAX172.ClientDaysAbroad1.value = Number(document.TAX172.January1.value) +
	Number(document.TAX172.February1.value) +
	Number(document.TAX172.March1.value) +
	Number(document.TAX172.April1.value) +
	Number(document.TAX172.May1.value) +
	Number(document.TAX172.June1.value) +
	Number(document.TAX172.July1.value) +
	Number(document.TAX172.August1.value) +
	Number(document.TAX172.September1.value) +
	Number(document.TAX172.October1.value) +
	Number(document.TAX172.November1.value) + 
	Number(document.TAX172.December1.value) ;
}


function GetTotalDaysTax1722() {
	document.TAX172.ClientDaysAbroad2.value = Number(document.TAX172.January2.value) +
	Number(document.TAX172.February2.value) +
	Number(document.TAX172.March2.value) +
	Number(document.TAX172.April2.value) +
	Number(document.TAX172.May2.value) +
	Number(document.TAX172.June2.value) +
	Number(document.TAX172.July2.value) +
	Number(document.TAX172.August2.value) +
	Number(document.TAX172.September2.value) +
	Number(document.TAX172.October2.value) +
	Number(document.TAX172.November2.value) + 
	Number(document.TAX172.December2.value) ;
}

function GetTotalDaysTax1723() {

	document.TAX172.ClientDaysAbroad3.value = Number(document.TAX172.January3.value) +
	Number(document.TAX172.February3.value) +
	Number(document.TAX172.March3.value) +
	Number(document.TAX172.April3.value) +
	Number(document.TAX172.May3.value) +
	Number(document.TAX172.June3.value) +
	Number(document.TAX172.July3.value) +
	Number(document.TAX172.August3.value) +
	Number(document.TAX172.September3.value) +
	Number(document.TAX172.October3.value) +
	Number(document.TAX172.November3.value) + 
	Number(document.TAX172.December3.value) ;}
	
	
