nbsp = 160
emptyString = /^\s*$/

function trim(str)
{
  return str.replace(/^\s+|\s+$/g, '')
};

function msg(fld,     // id of element to display message in
             msgtype, // class to give element ("warn" or "error")
             message) // string to display
{
  // setting an empty string can give problems if later set to a 
  // non-empty string, so ensure a space present. (For Mozilla and Opera one could 
  // simply use a space, but IE demands something more, like a non-breaking space.)
  var dispmessage;
  if (emptyString.test(message)) 
    dispmessage = String.fromCharCode(nbsp);    
  else  
    dispmessage = message;

  var elem = document.getElementById(fld);
  elem.firstChild.nodeValue = dispmessage;  
  
  elem.className = msgtype;
};


function validateAmount (vfld,   // element to be validated
                         ifld)   // id of element to receive info/error msg
{

  var tfld = trim(vfld.value);
  var amountRE = /^\d+(\.\d{1,2})?$/   // allow only digits and two optional decimal points.
  if (!amountRE.test(tfld)) {
    msg (ifld, "error", "Please enter numbers only.");
    vfld.focus();
    return false;
  }

  msg(ifld, "warn", "");
  return true;
};
