function trim(str)  // compatible with all browsers
{
  if (document.getElementById || document.all || document.layers)
    {
      str=str.replace(/^\s+/,"");// REMOVE ANY NUMBER OF ANY WHITE-SPACE CHARS FROM FRONT OF STRING
      str=str.replace(/\s+$/,"");// REMOVE ANY NUMBER OF ANY WHITE-SPACE CHARS FROM END OF STRING
    }
  else
   {
     while (str.charAt(0) == ' ')
       str = str.substring(1);
     while (str.charAt(str.length - 1) == ' ')
       str = str.substring(0, str.length - 1);
   }
  return str;
}

function isempty(elm, minlength)
{
  if (arguments.length < 2) { arguments[1] = 1;}
  elm.value = trim(elm.value);
  return (elm.value == "" || elm.value == null || elm.value.length < minlength);
}

function isemail(elm)
{
  elm.value = trim(elm.value);
  var firstat = elm.value.indexOf("@");
  var lastat = elm.value.lastIndexOf("@");
  var lastdot = elm.value.lastIndexOf(".");
  if (firstat != lastat) { return (false); } // two or more @ characters found
  return (firstat > 0 && elm.value.indexOf(".") > 0 && lastdot > lastat && elm.value != "" && elm.value.length > 5);
}

function isnumber(elm)
{
  elm.value = trim(elm.value);
  var elmnum = elm.value + 0;
  if (elmnum == 0) return false;
  val = parseInt(elm.value);
  if ( (val < 1) || isNaN(val) ) { return false; }
  return true;
}

function checkvalues()
{
  if (isempty(sdialog.fffff,1))  {sdialog.fffff.focus(); sdialog.fffff.select(); alert("First name field is blank or too short.\nRequest not submitted."); return false;}
  if (isempty(sdialog.lllll,2))  {sdialog.lllll.focus(); sdialog.lllll.select(); alert("Last name field is blank or too short.\nRequest not submitted."); return false;}
  if (!isemail(sdialog.eeeee))   {sdialog.eeeee.focus(); sdialog.eeeee.select(); alert("E-mail address field is invalid.\nRequest not submitted."); return false;}
  if (!sdialog.agree.checked)    {sdialog.agree.focus(); sdialog.agree.select(); alert("You must agree to accept email from Velvet da Vinci.\nRequest not submitted."); return false;}
/***
  if (sdialog.postcards.checked)
    {
      if (isempty(sdialog.addr1,5)) {sdialog.addr1.focus(); sdialog.addr1.select(); alert("Invalid address line.\nRequest not submitted."); return false;}
      if (isempty(sdialog.city,2))  {sdialog.city.focus(); sdialog.city.select(); alert("Invalid city.\nRequest not submitted."); return false;}
      if (isempty(sdialog.state,2)) {sdialog.state.focus(); sdialog.state.select();alert("Invalid state/province.\nRequest not submitted."); return false;}
      sdialog.state.value = sdialog.state.value.toUpperCase();
      if (isempty(sdialog.zip,5))   {sdialog.zip.focus(); sdialog.zip.select();  alert("Invalid zip/postal code.\nRequest not submitted."); return false;}
      if (!isnumber(sdialog.zip))   {sdialog.zip.focus(); sdialog.zip.select();  alert("Invalid zip/postal code.\nRequest not submitted."); return false;}
    }
****/
  // passed all the tests so disable the submit button so that it can't be clicked again
  // sdialog.submitbtn.disabled = true;
  return (true);
}