function compareText (option1, option2) {
  return option1.text < option2.text ? -1 :
    option1.text > option2.text ? 1 : 0;
}
function compareValue (option1, option2) {
  return option1.value < option2.value ? -1 :
    option1.value > option2.value ? 1 : 0;
}
function compareTextAsFloat (option1, option2) {
  var value1 = parseFloat(option1.text);
  var value2 = parseFloat(option2.text);
  return value1 < value2 ? -1 :
    value1 > value2 ? 1 : 0;
}
function compareValueAsFloat (option1, option2) {
  var value1 = parseFloat(option1.value);
  var value2 = parseFloat(option2.value);
  return value1 < value2 ? -1 :
    value1 > value2 ? 1 : 0;
}
function sortSelect (select, compareFunction) {
  if (!compareFunction)
    compareFunction = compareText;
  var options = new Array (select.options.length);
  for (var i = 0; i < options.length; i++)
    options[i] = 
      new Option (
        select.options[i].text,
        select.options[i].value,
        select.options[i].defaultSelected,
        select.options[i].selected
      );
  options.sort(compareFunction);
  select.options.length = 0;
  for (var i = 0; i < options.length; i++)
    select.options[i] = options[i];
}
function round (n, d) {
  n = n - 0;
  d = d || 2;
  var f = Math.pow(10, d);
  n = Math.round(n * f) / f;
  n += Math.pow(10, - (d + 1));
  n += '';
  return d == 0 ? n.substring(0, n.indexOf('.')) :
      n.substring(0, n.indexOf('.') + d + 1);
}
function ConvertForex(form) {
	if (form)
	{
		rawVal = new String(form.fromAmt.value);
		pureDigit = new String();
		pureDigit = rawVal.replace(/,/g,'');
		localval = new Number(pureDigit);
		if (localval<=0 || form.from.selectedIndex < 0 || form.to.selectedIndex < 0)
		{
			form.output.value="";
			return;
		} 
		else
		{
			fromrate = new Number(form.from.options[form.from.selectedIndex].value);
			torate = new Number(form.to.options[form.to.selectedIndex].value);
			form.output.value = round(fromrate*localval/torate,2);
		}
	}
}
function keyReceive(form) {
  if (window.event && window.event.keyCode == 13) { ConvertForex(form); }
}