<!--
var strHTML = "";

//Calculate income changes- no change necessary
function incomeChanged(item)
{
	if (isNaN(item.value) || item.value < 0)
	{
		item.value = "";
	}
	processInAndOut('income');
}

//Function to extend creditors input boxes
function numberCreditorsChanged(item)
{
	if (isNaN(item.value) || item.value < 0)
	{
		item.value = "";
	}
	else
	{
		if (item.value <= 12)
		{
			var theCreditorLabel;
			var theCreditorInput;
			var theOwedLabel;
			var theOwedInput;
			var theReasonLabel;
			var theReasonInput; 
			var theMonthlyPaymentLabel;
			var theMonthlyPaymentInput;
			var theTbl;
		
			for (intPos = 1; intPos <= 12; intPos++)
			{
				var tbl = 'tbl'+intPos;
				var spanCreditorLabel = eval('spanCreditorLabel' + intPos);
				var spanCreditorInput = eval('spanCreditorInput' + intPos);
				var spanOwedLabel = eval('spanOwedLabel' + intPos);
				var spanOwedInput = eval('spanOwedInput' + intPos);
	
		
				var spanMonthlyPaymentLabel = eval('spanMonthlyPaymentLabel' + intPos);
				var spanMonthlyPaymentInput = eval('spanMonthlyPaymentInput' + intPos);
			
				if (parseInt(item.value) >= intPos)
				{
					theTbl = "inline";
					theCreditorLabel = "Creditor Name";
					theCreditorInput = "<INPUT type=\"text\" size=\"20\" name=\"inpCreditor" + intPos + "\" id=\"inpCreditor" + intPos + "\" onkeyup=\"creditorNameChanged(this);\">";
					theOwedLabel = " Balance ";
					theOwedInput = "<INPUT type=\"text\" size=\"6\" name=\"inpOwed" + intPos + "\" id=\"inpOwed" + intPos + "\" onkeyup=\"amountOwedChanged(this);\">";
				
					
					theMonthlyPaymentLabel = "Monthly Payment ";
					theMonthlyPaymentInput = "<INPUT  type=\"text\" size=\"6\" name=\"inpMonthlyPayment" + intPos + "\" id=\"inpMonthlyPayment" + intPos + "\" onkeyup=\"monthlyPaymentChanged(this);\">";
				} 
				else
				{
					theTbl = "none";
					var theCreditorLabel = "";
					var theCreditorInput = "";
					var theOwedLabel = "";
					var theOwedInput = "";
				
	
					var theMonthlyPaymentLabel = "";
					var theMonthlyPaymentInput = "";
				}
				
				document.getElementById(tbl).style.display = theTbl;
				spanCreditorLabel.innerHTML = theCreditorLabel;
				spanCreditorInput.innerHTML = theCreditorInput;
				spanOwedLabel.innerHTML = theOwedLabel;
				spanOwedInput.innerHTML = theOwedInput;
				spanMonthlyPaymentLabel.innerHTML = theMonthlyPaymentLabel;
				spanMonthlyPaymentInput.innerHTML = theMonthlyPaymentInput;
				
			}
		} else {
			alert("This page only allows you to enter 12 creditors. Give us a call on our Freephone 0800 043 5135"); 
			item.value = "0";
			numberCreditorsChanged(item);
		}
	}
}

//Function to calculate changes in expenditure- no changes necessary
function expenditureChanged(item)
{
	if (isNaN(item.value) || item.value < 0)
	{
		item.value = "";
	}
	processInAndOut('expenditure');
}

function creditorNameChanged(item)
{
	var theID = "hid_" + item.name;
	eval('document.frmCalculator.' + theID).value = item.value;
}

function amountOwedChanged(item)
{
	if (isNaN(item.value))
	{
		item.value = "";
	}
	
	var theID = "hid_" + item.name;
	eval('document.frmCalculator.' + theID).value = item.value;
	
	processAmountOwed();
}

function monthlyPaymentChanged(item)
{
	if (isNaN(item.value))
	{
		item.value = "";
	}
	
	var theID = "hid_" + item.name;
	eval('document.frmCalculator.' + theID).value = item.value;
	
	processMonthlyPayments();
}

function processInAndOut(direction)
{
	var fltTotalIncome = getTotalIncome();
	var fltTotalExpenditure = getTotalExpenditure();
	var fltDisposableIncome = parseFloat(fltTotalIncome) - parseFloat(fltTotalExpenditure);

	if (direction == "income")
	{	
		document.frmCalculator.inpTotalIncome.value = formatCurrency2(fltTotalIncome);
	}
	else
	{
		document.frmCalculator.inpTotalExpenditure.value = formatCurrency2(fltTotalExpenditure);
	}
	document.frmCalculator.hidDisposableIncome.value = formatCurrency2(fltDisposableIncome);
	disposableIncomeDiv.innerHTML = formatCurrency(fltDisposableIncome);
}

function processAmountOwed()
{
	var fltTotalAmountOwed = getTotalOwed();

	document.frmCalculator.inpTotalDebts.value = formatCurrency2(fltTotalAmountOwed);
	totalOwedCreditorsDiv.innerHTML = formatCurrency(fltTotalAmountOwed);
}

function processMonthlyPayments()
{
	var fltMonthlyPayments = getTotalMonthlyPayments();

	document.frmCalculator.inpTotalPayments.value = formatCurrency2(fltMonthlyPayments);
	monthlyPaymentsCreditorsDiv.innerHTML = formatCurrency(fltMonthlyPayments);
}

//add new labels here for Income items:

function getTotalIncome()
{
	var fltMyPay = parseFloat("0" + document.frmCalculator.inpMyPay.value);
	var fltpartnerpay = parseFloat("0" + document.frmCalculator.inppartnerpay.value);
	var fltincsupport = parseFloat("0" + document.frmCalculator.inpincsupport.value);
	var fltdla = parseFloat("0" + document.frmCalculator.inpdla.value);
	var fltworktaxcred = parseFloat("0" + document.frmCalculator.inpworktaxcred.value);	
	var fltpension = parseFloat("0" + document.frmCalculator.inppension.value);
	var fltchildben = parseFloat("0" + document.frmCalculator.inpchildben.value);
	var fltchildtaxcred = parseFloat("0" + document.frmCalculator.inpchildtaxcred.value);	
	var fltchildmaint = parseFloat("0" + document.frmCalculator.inpchildmaint.value);			
    var fltother = parseFloat("0" + document.frmCalculator.inpother.value);			


	var fltTotalIncome = fltMyPay + fltpartnerpay + fltincsupport + fltdla + fltworktaxcred + fltpension + fltchildben + fltchildtaxcred + fltchildmaint + fltother;
	return fltTotalIncome;
}


//add new labels here for Expenditure items:
function getTotalExpenditure()
{
	var fltMortgageRent = parseFloat("0" + document.frmCalculator.inpMortgageRent.value);
	var fltSecuredLoan = parseFloat("0" + document.frmCalculator.inpSecuredLoan.value);
	var fltContentInsurance = parseFloat("0" + document.frmCalculator.inpContentInsurance.value);
	var fltBuildingInsurance = parseFloat("0" + document.frmCalculator.inpBuildingInsurance.value);
	var fltFoodHousekeeping = parseFloat("0" + document.frmCalculator.inpHousekeeping.value);
	var fltCouncilTax = parseFloat("0" + document.frmCalculator.inpCouncilTax.value);
	var fltWaterRates = parseFloat("0" + document.frmCalculator.inpWaterRates.value);
	var fltElectricity = parseFloat("0" + document.frmCalculator.inpElectricity.value);
	var fltGas = parseFloat("0" + document.frmCalculator.inpGas.value);
	var fltTelephone = parseFloat("0" + document.frmCalculator.inpTelephone.value);
	var fltSkyDigital = parseFloat("0" + document.frmCalculator.inpskyDigital.value);
	var fltInternet = parseFloat("0" + document.frmCalculator.inpInternet.value);
	var fltMobile = parseFloat("0" + document.frmCalculator.inpMobile.value);
	var fltTVLicence = parseFloat("0" + document.frmCalculator.inpTVLicence.value);
	var fltCSA = parseFloat("0" + document.frmCalculator.inpCSA.value);
	var fltLifePolicy = parseFloat("0" + document.frmCalculator.inpLifePolicy.value);
	var fltPersonalPension = parseFloat("0" + document.frmCalculator.inpPersonalPension.value);
	var fltCarPetrol = parseFloat("0" + document.frmCalculator.inpCarPetrol.value);
	var fltCarServicing = parseFloat("0" + document.frmCalculator.inpCarServicing.value);
	var fltCarInsurance = parseFloat("0" + document.frmCalculator.inpCarInsurance.value);
	var fltCarRoadTax = parseFloat("0" + document.frmCalculator.inpCarRoadTax.value);
	var fltCarHP = parseFloat("0" + document.frmCalculator.inpCarHP.value);
	var fltPublicTransport = parseFloat("0" + document.frmCalculator.inpPublicTransport.value);
	var fltChildcare = parseFloat("0" + document.frmCalculator.inpChildcare.value);
	var fltOpticalDental = parseFloat("0" + document.frmCalculator.inpOpticalDental.value);
	var fltClothing = parseFloat("0" + document.frmCalculator.inpClothing.value);
	var fltPets = parseFloat("0" + document.frmCalculator.inpPets.value);
	var fltMedcial = parseFloat("0" + document.frmCalculator.inpMedcial.value);
	var fltHousekeepingMaintenance = parseFloat("0" + document.frmCalculator.inpHouseholdMaintenance.value);


	var fltAddExpenditure1 = parseFloat("0" + document.frmCalculator.inpAddExpenditure1.value);
	var fltAddExpenditure2 = parseFloat("0" + document.frmCalculator.inpAddExpenditure2.value);
	var fltAddExpenditure3 = parseFloat("0" + document.frmCalculator.inpAddExpenditure3.value);
	var fltAddExpenditure4 = parseFloat("0" + document.frmCalculator.inpAddExpenditure4.value);

	var fltTotalExpenditure = fltMortgageRent + fltSecuredLoan + fltBuildingInsurance + fltContentInsurance + fltFoodHousekeeping + fltCouncilTax + fltWaterRates + fltElectricity + fltGas + fltTelephone + fltMobile + fltTVLicence + fltCSA + fltInternet + fltLifePolicy + fltPersonalPension + fltCarPetrol + fltCarServicing + fltCarInsurance + fltCarRoadTax + fltCarHP + fltPublicTransport + fltChildcare + fltOpticalDental + fltClothing + fltPets +fltHousekeepingMaintenance + fltAddExpenditure1 + fltAddExpenditure2 + fltAddExpenditure3 + fltAddExpenditure4 + fltSkyDigital + fltMedcial;
	return fltTotalExpenditure;
}

function getTotalOwed()
{
	var fltTotalOwed = 0;

	for (intPos = 1; intPos <= parseInt(document.frmCalculator.inpNumberCreditors.value); intPos++)
	{
		fltTotalOwed = parseFloat("0" + fltTotalOwed) + parseFloat("0" + eval('document.frmCalculator.inpOwed' + intPos).value);
	}
	return fltTotalOwed;
}

function getTotalMonthlyPayments()
{
	var fltTotalMonthlyPayments = 0;

	for (intPos = 1; intPos <= parseInt(document.frmCalculator.inpNumberCreditors.value); intPos++)
	{
		fltTotalMonthlyPayments = parseFloat("0" + fltTotalMonthlyPayments) + parseFloat("0" + eval('document.frmCalculator.inpMonthlyPayment' + intPos).value);
	}
	return fltTotalMonthlyPayments;
}

function formatCurrency(num)
{
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	pennies = num%100;
	num = Math.floor(num/100).toString();
	if(pennies<10)
	pennies = "0" + pennies;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));

	if ((sign)?fontIs='':fontIs='#CC0000');
		
	return ('<FONT color=' + fontIs + '>' + ((sign)?'':'-') + num + '.' + pennies + '</FONT>');
}

function formatCurrency2(num)
{
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	pennies = num%100;
	num = Math.floor(num/100).toString();
	if(pennies<10)
	pennies = "0" + pennies;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));

	if ((sign)?fontIs='':fontIs='#CC0000');
		
	return (((sign)?'':'-') + num + '.' + pennies);
}


function checkCollectDetails()
{
	if (document.frmCollectDetails.inpName.value == "")
	{
		alert("Please enter your name");
		document.frmCollectDetails.inpName.focus();
		return false;
	}
	if (document.frmCollectDetails.inpTel.value == "")
	{
		alert("Please enter your telephone number");
		document.frmCollectDetails.inpTel.focus();
		return false;
	}
	if (document.frmCollectDetails.inpEmail.value == "")
	{
		alert("Please enter your email address");
		document.frmCollectDetails.inpEmail.focus();
		return false;
	}
	parent.opener.document.frmCalculator.hidName.value = document.frmCollectDetails.inpName.value;
	parent.opener.document.frmCalculator.hidTel.value = document.frmCollectDetails.inpTel.value;
	parent.opener.document.frmCalculator.hidEmail.value = document.frmCollectDetails.inpEmail.value;
	parent.opener.document.frmCalculator.submit();
	window.close();
}
//-->
