function checkState(form)
{
  form.State.value = trim(form.State.value);
  form.chkTax.checked = (form.State.value.toUpperCase() == "MO" ||
                         form.State.value.toUpperCase() == "MISSOURI");
  updatePrice(form);
}

function checkCountry(form)
{
  form.Country.value = trim(form.Country.value);
  form.chkShipping.checked = (form.Country.value.toUpperCase() != "US" &&
                              form.Country.value.toUpperCase() != "USA" &&
                              form.Country.value.toUpperCase() != "CAN" &&
                              form.Country.value.toUpperCase() != "CANADA");
  updatePrice(form);
}

function validPhone(num)
{
  // Checks for the following:
  // Can only contain digits, spaces, hyphens, dots, parentheses
  // Must have 7 or more digits
  n=0;
  for (i=0; i<num.length; i++)
  {
    a=num.charAt(i);
    if ("0123456789".indexOf(a) >= 0) n++;
    else if (" -.()".indexOf(a) < 0) return false;
  }
  if (n < 7) return false;
  else return true;
}

function validEmail(email)
{
  // Checks for the following:
  // One occurance of "@"
  // Characters before "@"
  // Characters between "@" and "."
  // Characters between "." and end
  // Does not included spaces, "\", "/"
  iat=-1;
  idot=-1;
  for (i=0; i<email.length; i++)
  {
    a=email.charAt(i);
    if (a==" " || a=="\\" || a=="/") return false;
    if (a=="@" && iat>=0) return false;
    if (a=="@") iat=i;
    if (a=="." && idot<0 && iat>=0) idot=i;
  }
  if (iat<=0) return false;
  if (idot<=iat+1) return false;
  if (email.charAt(email.length-1)==".") return false;
  return true;
}

function validCreditCard(num)
{
  // Checks for the following:
  // Can only contain digits, spaces, hyphens, dots, parentheses
  // Must have 16 digits and start with "4" or "5"
  // Or must have 15 digits and start with "3"
  var n=0;
  var cn="";
  var ct="";
  for (var i=0; i<num.length; i++)
  {
    var a=num.charAt(i);
    if ("0123456789".indexOf(a) >= 0)
    {
      n++;
      cn+=a;
      if (n==1) ct=a;
      if ((ct=="4" || ct=="5") && (n==4 || n==8 || n==12)) cn+="-";
      if (ct=="3" && (n==4 || n==10)) cn+="-";
    }
    else if (" -.()".indexOf(a) < 0)
      return "";
  }
  if (ct=="3" && n!=15) cn="";
  if (ct=="4" && n!=16) cn="";
  if (ct=="5" && n!=16) cn="";
  if (ct!="3" && ct!="4" && ct!="5") cn="";
  return cn;
}

function validSerNo(s, q)
{
  if (q==0) return true;
  n=0; d=0;
  start="Cc,ANDand& ";
  next=start;
  for (i=0; i<s.length; i++)
  {
    a=s.charAt(i);
    if (next.indexOf(a)<0) return false;
    else if (a=="C" || a=="c") next="Ff";
    else if (a=="F" || a=="f") next="Ss";
    else if (a=="S" || a=="s") next="-";
    else if (a=="-") {next="0123456789"; d=0;}
    else if (next!=start)
      {d++; if (d==3) {n++; next=start;}}
  }
  return (n>=q);
}

function updatePrice(form)
{
  t=0;

  i=eval(form.Qty1.selectedIndex);
  q=eval("0"+form.Qty1.options[i].text);
  if (q>=1) {p=q*595; form.Price1.value = fix(p,2); t=t+p;}
  else form.Price1.value = "";

  i=eval(form.Qty2.selectedIndex);
  q=eval("0"+form.Qty2.options[i].text);
  if (q>=1) {p=q*295; form.Price2.value = fix(p,2); t=t+p;}
  else form.Price2.value = "";

  i=eval(form.QtyN.selectedIndex);
  q=eval("0"+form.QtyN.options[i].text);
  if (q>=1) {p=q*595; form.PriceN.value = fix(p,2); t=t+p;}
  else form.PriceN.value = "";

  i=eval(form.Qty35.selectedIndex);
  q=eval("0"+form.Qty35.options[i].text);
  if (q>=1) {p=q*125; form.Price35.value = fix(p,2); t=t+p;}
  else form.Price35.value = "";

  i=eval(form.Qty30.selectedIndex);
  q=eval("0"+form.Qty30.options[i].text);
  if (q>=1) {p=q*200; form.Price30.value = fix(p,2); t=t+p;}
  else form.Price30.value = "";

  i=eval(form.Qty22.selectedIndex);
  q=eval("0"+form.Qty22.options[i].text);
  if (q>=1) {p=q*300; form.Price22.value = fix(p,2); t=t+p;}
  else form.Price22.value = "";

  i=eval(form.QtyDLL.selectedIndex);
  q=eval("0"+form.QtyDLL.options[i].text);
  if (q>=1) {p=q*500; form.PriceDLL.value = fix(p,2); t=t+p;}
  else form.PriceDLL.value = "";

  form.SubTotal.value = "";
  form.Tax.value = "";
  form.Shipping.value = "";
  form.Total.value = "";
  if (t>0)
  {
    form.SubTotal.value = fix(t,2);
    if (form.chkTax.checked) {p=t*0.07600; t=t+p;} else p=0;
    form.Tax.value = fix(p,2);
    if (form.chkShipping.checked) {p=50; t=t+p;} else p=0;
    form.Shipping.value = fix(p,2);
    form.Total.value = fix(t,2);
  }
}

function updatePrice5(form)
{
  var t=0;

  var state = trim(form.State.value).toUpperCase();
  var country = trim(form.Country.value).toUpperCase();
  var shipping = 60;
  if (country == "US" || country == "USA")
  {
    shipping = 15;
    if (state == "HI" || state == "HAWAII" || state == "AK" || state == "ALASKA")
      shipping = 20;
  }
  else if (country == "CA" || country == "CAN" || country == "CANADA")
    shipping = 30;

  i=eval(form.Qty1.selectedIndex);
  q=eval("0"+form.Qty1.options[i].text);
  if (q>=1) {p=q*595; form.Price1.value = fix(p,2); t=t+p;}
  else form.Price1.value = "";

  i=eval(form.Qty2.selectedIndex);
  q=eval("0"+form.Qty2.options[i].text);
  if (q>=1) {p=q*295; form.Price2.value = fix(p,2); t=t+p;}
  else form.Price2.value = "";

  i=eval(form.QtyS.selectedIndex);
  q=eval("0"+form.QtyS.options[i].text);
  if (q>=1) {p=q*595; form.PriceS.value = fix(p,2); t=t+p;}
  else form.PriceS.value = "";

  i=eval(form.Qty41.selectedIndex);
  q=eval("0"+form.Qty41.options[i].text);
  if (q>=1) {p=q*125; form.Price41.value = fix(p,2); t=t+p;}
  else form.Price41.value = "";

  i=eval(form.Qty35.selectedIndex);
  q=eval("0"+form.Qty35.options[i].text);
  if (q>=1) {p=q*250; form.Price35.value = fix(p,2); t=t+p;}
  else form.Price35.value = "";

  i=eval(form.Qty41S.selectedIndex);
  q=eval("0"+form.Qty41S.options[i].text);
  if (q>=1) {p=q*125; form.Price41S.value = fix(p,2); t=t+p;}
  else form.Price41S.value = "";

  i=eval(form.Qty35S.selectedIndex);
  q=eval("0"+form.Qty35S.options[i].text);
  if (q>=1) {p=q*250; form.Price35S.value = fix(p,2); t=t+p;}
  else form.Price35S.value = "";

  i=eval(form.QtyUSBKey.selectedIndex);
  q=eval("0"+form.QtyUSBKey.options[i].text);
  i=eval(form.QtyParKey.selectedIndex);
  q+=eval("0"+form.QtyParKey.options[i].text);
  if (q>=1) {p=q*80; form.PriceKey.value = fix(p,2); t=t+p;}
  else {form.PriceKey.value = ""; shipping = 0;}

  i=eval(form.QtyDLL.selectedIndex);
  q=eval("0"+form.QtyDLL.options[i].text);
  if (q>=1) {p=q*500; form.PriceDLL.value = fix(p,2); t=t+p;}
  else form.PriceDLL.value = "";

  form.SubTotal.value = "";
  form.Tax.value = "";
  form.Shipping.value = "";
  form.Total.value = "";
  if (t>0)
  {
    form.SubTotal.value = fix(t,2);
    if (state == "MO" || state == "MISSOURI") {p=t*0.07600; t=t+p;} else p=0;
    form.Tax.value = fix(p,2);
    t=t+shipping;
    form.Shipping.value = fix(shipping,2);
    form.Total.value = fix(t,2);
  }
}

function updatePrice6(form)
{
  var t=0;

  var state = trim(form.State.value).toUpperCase();
  var country = trim(form.Country.value).toUpperCase();
  var shipping = 60;
  if (country == "US" || country == "USA")
  {
    shipping = 15;
    if (state == "HI" || state == "HAWAII" || state == "AK" || state == "ALASKA")
      shipping = 20;
  }
  else if (country == "CA" || country == "CAN" || country == "CANADA")
    shipping = 30;

  i=eval(form.Qty1.selectedIndex);
  q=eval("0"+form.Qty1.options[i].text);
  if (q>=1) {p=q*595; form.Price1.value = fix(p,2); t=t+p;}
  else form.Price1.value = "";

  i=eval(form.Qty2.selectedIndex);
  q=eval("0"+form.Qty2.options[i].text);
  if (q>=1) {p=q*295; form.Price2.value = fix(p,2); t=t+p;}
  else form.Price2.value = "";

  i=eval(form.QtyS.selectedIndex);
  q=eval("0"+form.QtyS.options[i].text);
  if (q>=1) {p=q*595; form.PriceS.value = fix(p,2); t=t+p;}
  else form.PriceS.value = "";

  i=eval(form.Qty50P.selectedIndex);
  q=eval("0"+form.Qty50P.options[i].text);
  if (q>=1) {p=q*125; form.Price50P.value = fix(p,2); t=t+p;}
  else form.Price50P.value = "";

  i=eval(form.Qty41P.selectedIndex);
  q=eval("0"+form.Qty41P.options[i].text);
  if (q>=1) {p=q*250; form.Price41P.value = fix(p,2); t=t+p;}
  else form.Price41P.value = "";

  i=eval(form.Qty50S.selectedIndex);
  q=eval("0"+form.Qty50S.options[i].text);
  if (q>=1) {p=q*125; form.Price50S.value = fix(p,2); t=t+p;}
  else form.Price50S.value = "";

  i=eval(form.Qty50PS.selectedIndex);
  q=eval("0"+form.Qty50PS.options[i].text);
  if (q>=1) {p=q*125; form.Price50PS.value = fix(p,2); t=t+p;}
  else form.Price50PS.value = "";

  i=eval(form.Qty41PS.selectedIndex);
  q=eval("0"+form.Qty41PS.options[i].text);
  if (q>=1) {p=q*250; form.Price41PS.value = fix(p,2); t=t+p;}
  else form.Price41PS.value = "";

  i=eval(form.QtyUSBKey.selectedIndex);
  q=eval("0"+form.QtyUSBKey.options[i].text);
  i=eval(form.QtyParKey.selectedIndex);
  q+=eval("0"+form.QtyParKey.options[i].text);
  if (q>=1) {p=q*80; form.PriceKey.value = fix(p,2); t=t+p;}
  else {form.PriceKey.value = ""; shipping = 0;}

  i=eval(form.QtyDLL.selectedIndex);
  q=eval("0"+form.QtyDLL.options[i].text);
  if (q>=1) {p=q*500; form.PriceDLL.value = fix(p,2); t=t+p;}
  else form.PriceDLL.value = "";

  form.SubTotal.value = "";
  form.Tax.value = "";
  form.Shipping.value = "";
  form.Total.value = "";
  if (t>0)
  {
    form.SubTotal.value = fix(t,2);
    if (state == "MO" || state == "MISSOURI") {p=t*0.07600; t=t+p;} else p=0;
    form.Tax.value = fix(p,2);
    t=t+shipping;
    form.Shipping.value = fix(shipping,2);
    form.Total.value = fix(t,2);
  }
}

function fix(x, n)
{
  f = "";
  if (x < 0) {s="-"; x=-x;} else s="";
  if (n < 0) n=0; else n = Math.round(n);
  x = Math.round(x * Math.pow(10, n));
  while (x > 0) {r=(x % 10); f=""+r+f; x=(x-r)/10;}
  while (f.length <= n) {f="0"+f;}
  if (n > 0) f = f.substr(0,f.length-n) + "." + f.substr(f.length-n,n);
  return s+f;
}

function checkForm(form)
{
  form.Users.value = trim(form.Users.value);
  form.Company.value = trim(form.Company.value);
  form.Address.value = trim(form.Address.value);
  form.City.value = trim(form.City.value);
  form.State.value = trim(form.State.value);
  form.Country.value = trim(form.Country.value);
  form.Zip.value = trim(form.Zip.value);
  form.Phone.value = trim(form.Phone.value);
  form.Fax.value = trim(form.Fax.value);
  form.Email.value = trim(form.Email.value);
  form.CardNumber.value = trim(form.CardNumber.value);
  form.CardName.value = trim(form.CardName.value);

  msg="";
  msg = msg + msgLength(form.Users.value, "User Name", 3);
  msg = msg + msgLength(form.Company.value, "Organization", 3);
  msg = msg + msgLength(form.Address.value, "Address", 3);
  msg = msg + msgLength(form.City.value, "City", 3);
  msg = msg + msgLength(form.State.value, "State/Province", 2);
  msg = msg + msgLength(form.Country.value, "Country", 2);
  msg = msg + msgLength(form.Zip.value, "Zip/Postal Code", 4);
  if (form.Phone.value.length==0)
    msg += "Phone number is required.\n";
  else if (! validPhone(form.Phone.value))
    msg += "Phone number is invalid.\n";
  if (form.Email.value.length==0)
    msg += "Email is required.\n";
  else if (! validEmail(form.Email.value))
    msg += "Email address is invalid.\n";
  if (form.Total.value.length==0)
    msg += "You have not ordered anything yet.\n";
  //Count upgrade orders
  i = eval(form.Qty35.selectedIndex);
  q = eval("0"+form.Qty35.options[i].text);
  i = eval(form.Qty30.selectedIndex);
  q = q + eval("0"+form.Qty30.options[i].text);
  i = eval(form.Qty22.selectedIndex);
  q = q + eval("0"+form.Qty22.options[i].text);
  if (! validSerNo(form.SerNo.value, q))
    msg += "You must provide a hardware lock serial number\n  for each upgrade (format: CFS-000).\n";
  msg += msgLength(form.CardName.value, "Name on card", 3);
  cn = validCreditCard(form.CardNumber.value);
  if (form.CardNumber.value.length==0)
    msg += "Credit card number is required.\n";
  else if (cn.length==0)
    msg += "Credit card number is invalid.\nYou must use VISA or MasterCard.\n";
  else
    form.CardNumber.value = cn
  if (form.CardMonth.selectedIndex==0)
    msg += "Credit card expiration month is required.\n";
  if (form.CardYear.selectedIndex==0)
    msg += "Credit card expiration year is required.\n";
  if (msg.length==0)
    form.submit();
  else
    alert(msg);
}

function checkForm5(form)
{
  form.Users.value = trim(form.Users.value);
  form.Company.value = trim(form.Company.value);
  form.Address.value = trim(form.Address.value);
  form.City.value = trim(form.City.value);
  form.State.value = trim(form.State.value);
  form.Country.value = trim(form.Country.value);
  form.Zip.value = trim(form.Zip.value);
  form.Phone.value = trim(form.Phone.value);
  form.Fax.value = trim(form.Fax.value);
  form.Email.value = trim(form.Email.value);
  form.OldKey.value = trim(form.OldKey.value);
  form.CardNumber.value = trim(form.CardNumber.value);
  form.CardName.value = trim(form.CardName.value);

  msg = "";
  msg += msgLength(form.Users.value, "User Name", 3);
  msg += msgLength(form.Company.value, "Organization", 3);
  msg += msgLength(form.Address.value, "Address", 3);
  msg += msgLength(form.City.value, "City", 3);
  msg += msgLength(form.State.value, "State/Province", 2);
  msg += msgLength(form.Country.value, "Country", 2);
  msg += msgLength(form.Zip.value, "Zip/Postal Code", 4);
  if (form.Phone.value.length==0)
    msg += "Phone number is required.\n";
  else if (! validPhone(form.Phone.value))
    msg += "Phone number is invalid.\n";
  if (form.Email.value.length==0)
    msg += "Email is required.\n";
  else if (! validEmail(form.Email.value))
    msg += "Email address is invalid.\n";
  if (form.Total.value.length==0)
    msg += "You have not ordered anything yet.\n";

  //Count upgrade orders
  i = eval(form.Qty41.selectedIndex);
  q = eval("0"+form.Qty41.options[i].text);
  i = eval(form.Qty35.selectedIndex);
  q += eval("0"+form.Qty35.options[i].text);
  i = eval(form.Qty41S.selectedIndex);
  q += eval("0"+form.Qty41S.options[i].text);
  i = eval(form.Qty35S.selectedIndex);
  q += eval("0"+form.Qty35S.options[i].text);
  if (q > 0 && form.OldKey.value.length < 6)
    msg += "You must provide your current license codes or hardware key serial numbers.\n";

  //Check for personal license outside US or Canada
  i = eval(form.Qty1.selectedIndex);
  q = eval("0"+form.Qty1.options[i].text);
  i = eval(form.Qty2.selectedIndex);
  q += eval("0"+form.Qty2.options[i].text);
  i = eval(form.Qty41.selectedIndex);
  q += eval("0"+form.Qty41.options[i].text);
  i = eval(form.Qty35.selectedIndex);
  q += eval("0"+form.Qty35.options[i].text);
  var country = trim(form.Country.value).toUpperCase();
  if (q > 0 && country != "US" && country != "USA"  && country != "CA" && country != "CAN" && country != "CANADA")
    msg += "Personal licenses are only available in the US and Canada.\n";

  //Check for key purchase
  i = eval(form.QtyS.selectedIndex);
  q = eval("0"+form.QtyS.options[i].text);
  i = eval(form.Qty41S.selectedIndex);
  q += eval("0"+form.Qty41S.options[i].text);
  i = eval(form.Qty35S.selectedIndex);
  q += eval("0"+form.Qty35S.options[i].text);
  i = eval(form.QtyUSBKey.selectedIndex);
  k = eval("0"+form.QtyUSBKey.options[i].text);
  i = eval(form.QtyParKey.selectedIndex);
  k += eval("0"+form.QtyParKey.options[i].text);
  if (q == 1 && k == 0)
    msg += "You must choose a USB key or Parallel Port key.\n";
  else if (q > 1 && k == 0)
    msg += "You must choose at least one USB key or Parallel Port key.\n";
  else if (q == 0 && k > 0)
    msg += "License keys may only be purchased with a shareable license.\n";
  else if (k > q)
    msg += "You have chosen too many license keys.\n";

  cn = validCreditCard(form.CardNumber.value);
  if (form.CardNumber.value.length==0)
    msg += "Credit card number is required.\n";
  else if (cn.length==0)
    msg += "Credit card number is invalid.\nYou must use VISA, MasterCard, or American Express.\n";
  else
    form.CardNumber.value = cn
  if (form.CardMonth.selectedIndex==0)
    msg += "Credit card expiration month is required.\n";
  if (form.CardYear.selectedIndex==0)
    msg += "Credit card expiration year is required.\n";
  msg += msgLength(form.CardName.value, "Name on card", 3);
  if (msg.length==0)
    form.submit();
  else
    alert(msg);
}

function checkForm6(form)
{
  form.Users.value = trim(form.Users.value);
  form.Company.value = trim(form.Company.value);
  form.Address.value = trim(form.Address.value);
  form.City.value = trim(form.City.value);
  form.State.value = trim(form.State.value);
  form.Country.value = trim(form.Country.value);
  form.Zip.value = trim(form.Zip.value);
  form.Phone.value = trim(form.Phone.value);
  form.Fax.value = trim(form.Fax.value);
  form.Email.value = trim(form.Email.value);
  form.OldKey.value = trim(form.OldKey.value);
  form.CardNumber.value = trim(form.CardNumber.value);
  form.CardName.value = trim(form.CardName.value);

  msg = "";
  msg += msgLength(form.Users.value, "User Name", 3);
  msg += msgLength(form.Company.value, "Organization", 3);
  msg += msgLength(form.Address.value, "Address", 3);
  msg += msgLength(form.City.value, "City", 3);
  msg += msgLength(form.State.value, "State/Province", 2);
  msg += msgLength(form.Country.value, "Country", 2);
  msg += msgLength(form.Zip.value, "Zip/Postal Code", 4);
  if (form.Phone.value.length==0)
    msg += "Phone number is required.\n";
  else if (! validPhone(form.Phone.value))
    msg += "Phone number is invalid.\n";
  if (form.Email.value.length==0)
    msg += "Email is required.\n";
  else if (! validEmail(form.Email.value))
    msg += "Email address is invalid.\n";
  if (form.Total.value.length==0)
    msg += "You have not ordered anything yet.\n";

  //Count upgrade orders
  i = eval(form.Qty50P.selectedIndex);
  q = eval("0"+form.Qty50P.options[i].text);
  i = eval(form.Qty41P.selectedIndex);
  q += eval("0"+form.Qty41P.options[i].text);
  i = eval(form.Qty50S.selectedIndex);
  q += eval("0"+form.Qty50S.options[i].text);
  i = eval(form.Qty50PS.selectedIndex);
  q += eval("0"+form.Qty50PS.options[i].text);
  i = eval(form.Qty41PS.selectedIndex);
  q += eval("0"+form.Qty41PS.options[i].text);
  if (q > 0 && form.OldKey.value.length < 6)
    msg += "You must provide your current license codes or hardware key serial numbers.\n";

  //Check for personal license outside US or Canada
  i = eval(form.Qty1.selectedIndex);
  q = eval("0"+form.Qty1.options[i].text);
  i = eval(form.Qty2.selectedIndex);
  q += eval("0"+form.Qty2.options[i].text);
  i = eval(form.Qty50P.selectedIndex);
  q += eval("0"+form.Qty50P.options[i].text);
  i = eval(form.Qty41P.selectedIndex);
  q += eval("0"+form.Qty41P.options[i].text);
  var country = trim(form.Country.value).toUpperCase();
  if (q > 0 && country != "US" && country != "USA"  && country != "CA" && country != "CAN" && country != "CANADA")
    msg += "Personal licenses are only available in the US and Canada.\n";

  //Check for key purchase
  i = eval(form.QtyS.selectedIndex);
  q = eval("0"+form.QtyS.options[i].text);
  i = eval(form.Qty50PS.selectedIndex);
  q += eval("0"+form.Qty50PS.options[i].text);
  i = eval(form.Qty41PS.selectedIndex);
  q += eval("0"+form.Qty41PS.options[i].text);
  i = eval(form.QtyUSBKey.selectedIndex);
  k = eval("0"+form.QtyUSBKey.options[i].text);
  i = eval(form.QtyParKey.selectedIndex);
  k += eval("0"+form.QtyParKey.options[i].text);
  if (q == 1 && k == 0)
    msg += "You must choose a USB key or Parallel Port key.\n";
  else if (q > 1 && k == 0)
    msg += "You must choose at least one USB key or Parallel Port key.\n";
  else if (q == 0 && k > 0)
    msg += "License keys may only be purchased with a shareable license.\n";
  else if (k > q)
    msg += "You have chosen too many license keys.\n";

  cn = validCreditCard(form.CardNumber.value);
  if (form.CardNumber.value.length==0)
    msg += "Credit card number is required.\n";
  else if (cn.length==0)
    msg += "Credit card number is invalid.\nYou must use VISA, MasterCard, or American Express.\n";
  else
    form.CardNumber.value = cn
  if (form.CardMonth.selectedIndex==0)
    msg += "Credit card expiration month is required.\n";
  if (form.CardYear.selectedIndex==0)
    msg += "Credit card expiration year is required.\n";
  msg += msgLength(form.CardName.value, "Name on card", 3);
  if (msg.length==0)
    form.submit();
  else
    alert(msg);
}

function checkDownload(form)
{
  form.Name.value = trim(form.Name.value);
  form.Company.value = trim(form.Company.value);
  form.Address.value = trim(form.Address.value);
  form.City.value = trim(form.City.value);
  form.State.value = trim(form.State.value);
  form.Country.value = trim(form.Country.value);
  form.Zip.value = trim(form.Zip.value);
  form.Phone.value = trim(form.Phone.value);
  form.Email.value = trim(form.Email.value);

  msg="";
  msg += msgLength(form.Name.value, "Name", 3);
  msg += msgLength(form.Company.value, "Organization", 3);
  msg += msgLength(form.Address.value, "Street Address", 3);
  msg += msgLength(form.City.value, "City", 3);
  msg += msgLength(form.State.value, "State/Province", 2);
  msg += msgLength(form.Country.value, "Country", 2);
  msg += msgLength(form.Zip.value, "Zip/Postal Code", 4);
  if (form.Phone.value.length==0)
    msg += "Phone number is required.\n";
  else if (! validPhone(form.Phone.value))
    msg += "Phone number is invalid.\n";
  if (form.Email.value.length==0)
    msg += "Email is required.\n";
  else if (! validEmail(form.Email.value))
    msg += "Email address is invalid.\n";

  if (msg.length==0)
    form.submit();
  else
    alert(msg);
}

function trim(s)
{
  while (s.length > 0)
  {
    if (s.charAt(0)==" ") s=s.substr(1);
    else break;
  }
  while (s.length > 0)
  {
    if (s.charAt(s.length-1)==" ") s=s.substr(0,s.length-1);
    else break;
  }
  return s;
}

function msgLength(v, f, n)
{
  if (v.length==0) return f + " is required.\n";
  else if (v.length<n) return f + " is invalid.\n";
  else return "";
}
