function validate()
{
   if(trim(document.contact.name.value) == "")
   {
      alert("Please fill in a valid name\n");
      document.contact.name.focus();
      return false;
   }

   if(trim(document.contact.email.value) == "")
   {
      alert("Please fill in an e-mail address");
      document.contact.email.focus();
      return false;
   }
   if( !isEmail(document.contact.email.value) )
   {
      alert("Please use a valid e-mail address\n");
      document.contact.email.focus();
      document.contact.email.select();
      return false;
   }
   if(trim(document.contact.subject.value) == "")
   {
      alert("Please fill in a subject\n");
      document.contact.subject.focus();
      return false;
   }

   if(trim(document.contact.message.value) == "")
   {
      alert("Didn't you want to send a message?\n");
      document.contact.message.focus();
      return false;
   }
   
}

function validateOrder()
{
   if(trim(document.order.amount.value) == "")
   {
      alert("Please fill in the desired amount\n");
      document.order.amount.focus();
      return false;
   }
   
   if(trim(document.order.name.value) == "")
   {
      alert("Please fill in a valid name\n");
      document.order.name.focus();
      return false;
   }

   if(trim(document.order.email.value) == "")
   {
      alert("Please fill in an e-mail address");
      document.order.email.focus();
      return false;
   }
   
   if( !isEmail(document.order.email.value) )
   {
      alert("Please use a valid e-mail address\n");
      document.order.email.focus();
      document.order.email.select();
      return false;
   }
   
   if(trim(document.order.address.value) == "")
   {
      alert("Please fill in the address for delivery\n");
      document.order.address.focus();
      return false;
   }
   
   if(trim(document.order.zip.value) == "")
   {
      alert("Please fill in the correct zip code\n");
      document.order.zip.focus();
      return false;
   }
   
   if(trim(document.order.country.value) == "")
   {
      alert("Please fill in the country\n Waldo was here\n");
      document.order.country.focus();
      return false;
   }
   
}

function isEmail(emailstr)
{
   dotchar = emailstr.indexOf(".");
   atchar = emailstr.indexOf("@");
   dotlast = emailstr.lastIndexOf(".");
   spacechar = emailstr.indexOf(" ");
   len = emailstr.length;
   if( (dotchar == -1) || (atchar == -1) || (spacechar != -1) || (dotlast < atchar) || (dotlast == len - 1) )
   {
      return false;
   }
   else
   {
      return true;
   }
}
function trim(str)
{
ch = '';
for(i=0;i<str.length;i++)
{
   cha = str.charAt(i);
   if(cha != ' ')
   {
      ch = ch + cha;
   }
}
return ch;
}
