<!--
function calculate(bReverse) {
     var select1 = document.forms['curconvert'].covertfrom;
     var select2 = document.forms['curconvert'].covertto;
     var select1_text = select1[select1.selectedIndex].text;
     var select2_text = select2[select2.selectedIndex].text;
     var fromval;
     var toval;

     //these error messages are hidden values in the templates
     //they get translated into foreign languages
     var errmsg1 = "An error has occurred with this selection. Please select two currencies and try again.";
     var errmsg2 = "Please enter a valid amount.";

     if (fromval == null && toval == null)
     {
 	 fromval = rate[select1[select1.selectedIndex].value];
     	 toval = rate[select2[select2.selectedIndex].value];
     }

	if (fromval == null || toval == null)
	{
		document.forms['curconvert'].amount2.value="0.00";
		return true;
	}

	 if (fromval == "" || toval == "" || isNaN(fromval) || isNaN(toval)) {
		alert(errmsg1);
		return false;
     }
     if (bReverse)
		var amount = removecommas(document.forms['curconvert'].amount2.value);
	else
		var amount = removecommas(document.forms['curconvert'].amount.value);

	 if (isNaN(amount)){
	 	alert(errmsg2);
		document.forms['curconvert'].amount.focus();
		return false;
	}
     var pattern = /,/g;
     amount = amount.replace(pattern, "");

  	showConversion(fromval, toval, amount, bReverse);


}


function showConversion(fromval, toval, amount, bReverse) {
	var totval;
	if (bReverse)
	{
		totval = amount * fromval/toval;
		document.forms['curconvert'].amount.value=toCurrency(totval);
	}
	else
	{
		totval = amount * toval / fromval;
		document.forms['curconvert'].amount2.value=toCurrency(totval);
	}
}

function round(num) {
	var x = num * 10000;
	return (Math.round(x) / 10000);
}

function removecommas(amount)
{
  var length=amount.length;
  var s=amount.toString();
  var returnval = "";
  for (var i=0;i<=length;i++) {
	if (amount.substr(i, 1)!=',')
		returnval=returnval+amount.substr(i, 1);
	}
  return returnval;
}

function toCurrency(num) {
	num = round(num);
	var currstring = num.toString();
	if (currstring.match(/\./)) {
		var curr = currstring.split('.');
	} else {
		var curr = [currstring, "00"];
	}
	curr[1] += "00";
	curr[2] = "";
	var returnval = "";
	var length = curr[0].length;

	// add 0 to decimal if necessary
	for (var i = 0; i < 2; i++)
		curr[2] += curr[1].substr(i, 1);

	// insert commas for readability
	for (i = length; (i - 3) > 0; i = i - 3) {
		returnval = "," + curr[0].substr(i - 3, 3) + returnval;
	}
	returnval = curr[0].substr(0, i) + returnval + "." + curr[1].substr(0, 4);
	return (returnval);
}
-->