//start
if (navigator.appVersion.charAt(0) < 4) {
	document.write = "Requires Netscape Navigator 4 or higher";
}

function two_sign(num){
	str=num;
	i = num+'.';
	ind = i.indexOf('.',0);
	sign = num*100 - i.substr(0,ind)*100;
	if (sign-Math.round(sign/10)*10 == 0){
		if (sign/10<10) {
			if (sign==0){
				str=num+'.00';
			}else{
				str= i.substr(0,ind)+'.'+sign/10+'0';
			}
		}
	}
	return str;
}

function calculate() {
	var select1 = document.currcalc.from;
	var select2 = document.currcalc.to;
	var fromval;
	var action;
	var val;
	var toval;

	if (fromval == null && toval == null && action == null) {
		fromval = select1[select1.selectedIndex].value;
		toval = select2[select2.selectedIndex].value;
	}
	
	if (fromval == 'aud' || fromval == 'cad'){
		select2.value = 'gbp';
		toval = 'gbp';
		if (fromval == null && toval == null && action == null) {
			toval = 'gbp';
		}
	}
	

	if (fromval == ""  || toval == "") {
		alert('                                   *** INVALID ENTRY ***                    \n Please enter an amount and select action and two currencies to use the currency converter.  ');
		return false;
	}
	
	var amount = document.currcalc.amount.value;
	if (amount == "" || isNaN(amount)){
		alert("         *** INVALID AMOUNT ***      \n Use only numbers and decimal points");
		document.currcalc.amount.focus();
		return false;
	}

	var pattern = /,/g;
	amount = amount.replace(pattern, "");

	if (select1[select1.selectedIndex].value == select2[select2.selectedIndex].value){
		document.currcalc.result.value = two_sign(Math.round(amount*100)/100);
	} else {
		if (rates[fromval+'_to_'+toval] < rates[toval+'_to_'+fromval]){
			res = two_sign( amount * rates[fromval + '_to_' + toval]);
		} else {
			res = two_sign( amount / rates[fromval + '_to_' + toval]);
		}
		document.currcalc.result.value = Math.round(res*100)/100;
	}
}