rates = { 5: 1.5, 10: 1.56, 20: 1.84, 25: 1.84, 50: 2.19, 75: 2.54 }

function doCalculate()

{ 
	var form = document.forms.calculator
	var amount = parseInt(form.amount.value = form.amount.value.replace(/[^0-9]/g, ''));
	var invested = form.invested.options[form.invested.selectedIndex].value;
	var investedI = parseInt(invested, 10);
	var resultEle = document.getElementById('cResultH');
	var result, pounds, pence;
	var image = document.getElementById('piggyBank');
	
	if (isNaN(amount)||(amount<=0)) {
		alert('Please enter a valid investment amount.');
		return;
	}
	
	result = Math.round(amount*investedI*rates[invested]);
	pounds = Math.floor(result/100);
	pence = result%100;
	if (pence < 10) pence='0'+pence;
	result = '&pound;'+pounds+'.'+pence;
	
	if (image) image.src = 'images/_GDP4012a_full.jpg';
	DHTMLSound();
	resultEle.innerHTML = result;
}

function resetForm()

{
	var image = document.getElementById('piggyBank');
	var resultEle = document.getElementById('cResultH');

	image.src = 'images/_GDP4012a.jpg';
	resultEle.innerHTML = '&pound;000.00';
}

function DHTMLSound() {
	document.getElementById("soundEle").innerHTML='<embed src="sound/kerching.mp3" hidden="true" autostart="true" loop="false">';
}
