/*
==================================================================
LTrim(string) : Returns a copy of a string without leading spaces.
==================================================================
*/
function LTrim(str)
/*
   PURPOSE: Remove leading blanks from our string.
   IN: str - the string we want to LTrim
*/
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      // We have a string with leading blank(s)...

      var j=0, i = s.length;

      // Iterate from the far left of string until we
      // don't have any more whitespace...
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;

      // Get the substring from the first non-whitespace
      // character to the end of the string...
      s = s.substring(j, i);
   }
   return s;
}

/*
==================================================================
RTrim(string) : Returns a copy of a string without trailing spaces.
==================================================================
*/
function RTrim(str)
/*
   PURPOSE: Remove trailing blanks from our string.
   IN: str - the string we want to RTrim

*/
{
   // We don't want to trip JUST spaces, but also tabs,
   // line feeds, etc.  Add anything else you want to
   // "trim" here in Whitespace
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      // We have a string with trailing blank(s)...

      var i = s.length - 1;       // Get length of string

      // Iterate from the far right of string until we
      // don't have any more whitespace...
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;


      // Get the substring from the front of the string to
      // where the last non-whitespace character is...
      s = s.substring(0, i+1);
   }

   return s;
}

/*
=============================================================
Trim(string) : Returns a copy of a string without leading or trailing spaces
=============================================================
*/
function Trim(str)
/*
   PURPOSE: Remove trailing and leading blanks from our string.
   IN: str - the string we want to Trim

   RETVAL: A Trimmed string!
*/
{
   return RTrim(LTrim(str));
}

function isMail(_email) {
     var emailReg = /^[a-z][a-z-_0-9\.]+@[a-z-_=>0-9\.]+\.[a-z]{2,3}$/i
     return emailReg.test(_email);
}

function isInteger(str)
{ 
   if (str.length==0) return false;
   for (var i = 0; i < str.length; i++ )  { 
    var ch = str.charAt (i)  
    if (ch < "0" || ch > "9") return false;
   } 
   return true;
}


function checkForm()
{
	var name = Trim(order.name.value);
	var company = Trim(order.company.value);
	var address = Trim(order.address.value);
	var city= Trim(order.city.value);
	var state = Trim(order.state.value);
	var zip = Trim(order.zip.value);
	var country = Trim(order.country.value);
	var phone = Trim(order.phone.value);
	var email = Trim(order.email.value);
	var numemployees = Trim(order.numemployees.value);
	var salutation = Trim(order.salutation.value);
	var allok=true;
         
if ((allok) && name==''){
 alert('Please enter your name');
 order.name.focus();
 allok=false;
}

if ((allok) && (company=='')){
 alert('Please fill in the "Company" field.');
 order.company.focus();
 allok=false;
}

if ((allok) && (''==phone)){
 alert('Please fill in the "Phone" field.');
 order.phone.focus();
 allok=false;
}

if ((allok) && (!isMail(email))){
 alert('Please enter a valid email address.');
 order.email.focus();
 allok=false;
}


if ((allok) && (!isInteger(numemployees))){
 alert('Please fill in the "Number of Employees" field.');
 order.numemployees.focus();
 allok=false;
}

if ((allok) && (''==address)){
 alert('Please fill in the "Address" field');
 order.address.focus();
 allok=false;
}
if ((allok) && (''==city)) {
   alert('Please fill in the "City" field.');
   order.city.focus();
   allok=false;
}
if ((allok) && (''==state)){
 alert('Please fill in the "State/Province" field.');
 order.state.focus();
 allok=false;
}
  
if ((allok) && (''==zip)){
 alert('Please fill in the "ZIP" field ');
 order.zip.focus();
 allok=false;
}
if ((allok) && (''==country)){
 alert('Please fill in the "Country" field.');
 order.country.focus();
 allok=false;
}

if (allok)
{
order.formsent.value="1";
 alert('Thank you for submitting the form.');
}
else
{
 alert('Thank you!');
}
return allok;
}
