function validate(form)
{
  if (form.name.value.length == 0)
  {
    alert('Please enter your name.');
    form.name.focus();
    form.name.select();
    return false;
  }

  if (!checkZipCode(form.zip.value))
  {
    alert("Please enter your zip code in one of the following formats: 12345 or 12345-9992.");
    form.zip.focus();
    form.zip.select();
    return false;
  }

  if (!checkEmail(form.email.value))
  {
    alert('Please enter a valid email.');
    form.email.focus();
    form.email.select();
    return false;
  }

  form.name.value    = form.name.value.Trim();
  form.address.value = form.address.value.Trim();
  form.city.value    = form.city.value.Trim();
  form.state.value   = form.state.value.Trim();
  form.zip.value     = form.zip.value.Trim();
  form.phone.value   = form.phone.value.Trim();
  form.email.value   = form.email.value.Trim();
  form.submit.disabled = true;

  return true;
}

function isPhone(element)
{
  var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
  //strip out acceptable non-numeric characters

  if (isNaN(parseInt(stripped)))
    return false;

  if (!(stripped.length == 10))
    return false;
}

function checkZipCode(strng)
{
  var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
  //strip out acceptable non-numeric characters

  if (isNaN(parseInt(stripped)))
    return false;

  if (stripped.length == 5) return true;
  if (stripped.length == 9) return true;

//  if (!(stripped.length == 5) || !(stripped.length == 9))
    return false;
}

function checkEmail(strng)
{
  var emailFilter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
//  var emailFilter=/^.+@.+\..{2,3,4,6}$/;

  if (!(emailFilter.test(strng)))
    return false;

  return true;
}

String.prototype.Trim = function() // trims white space off both ends of this string
{
  return((ar=/^\s*([\s\S]*\S+)\s*$/.exec(this)) ? ar[1] : "");
}
