function isZip(field, Country, errorStringUS, errorStringCanada, errorStringBlank){
var isValid = true;
if (Country.options[Country.selectedIndex].value == "USA"){
  if (field.value.length != 10 && field.value.length != 5) { isValid = false }
  for (i=0; i < field.value.length; i++) {
    if (i == 5) {
      if (field.value.charAt(i) != "-") { isValid = false }
    }
    else {
      if ((field.value.charAt(i) < "0") || (field.value.charAt(i) > "9")){
         isValid = false;
      }
    }
  }
  if (!isValid){
    alert(errorStringUS);
    field.focus();
  }
} else if (Country.options[Country.selectedIndex].value == "Canada"){
  if (field.value.length != 7 && field.value.length != 6) { isValid = false }
  if (!isValid){
    alert(errorStringCanada);
    field.focus();
  }
}
return isValid;
}

// -------------------------------------

function isPhoneNum(field, errorString){
  var isPhone = true;
  var numcount = 0;
  if (field.value.length < 10) { isPhone = false }
  for (i=0; i < field.value.length; i++)
    if ((field.value.charAt(i) >= "0") && (field.value.charAt(i) <= "9")){
      numcount = numcount + 1;
    }


  if (numcount < 10) { isPhone = false }
  if (!isPhone){
    alert(errorString);
    field.focus();
  }
  return isPhone;
}

// -------------------------------------

function LTrim(str){
 var whitespace = new String(" \t\n\r");
 var s = new String(str);
 if (whitespace.indexOf(s.charAt(0)) != -1) {
   var j=0, i = s.length;
   while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
     j++;
   s = s.substring(j, i);
 }
 return s;
}

// -------------------------------------

function isBlank(field, errorString){
 if (LTrim(field.value) == ""){
   alert(errorString);
   field.focus();
   return (true);
 }
 return (false);
}

// -------------------------------------

function isEmail(field, errorString){
  var isEmail = ((field.value.indexOf("@") != -1) && (field.value.indexOf(".") != -1)); 
    if (!isEmail){
    alert(errorString);
    field.focus();
    return (false);
  }
  return (true);
}


// -------------------------------------

function isAlpha(field, errorString){
 var checkOK = " '-ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþ";
 var allValid = true;
 var checkStr = field.value;
 for (i = 0;  i < checkStr.length;  i++)
 {
   ch = checkStr.charAt(i);
   for (j = 0;  j < checkOK.length;  j++)
     if (ch == checkOK.charAt(j))
       break;
   if (j == checkOK.length)
   {
     allValid = false;
     break;
   }
 }
 if (!allValid){
   alert(errorString);
   field.focus();
 }
 return allValid;
}

// -------------------------------------

function noSelectedField(field, errorString){
if (field.selectedIndex == 0){
  alert(errorString);
  field.focus();
  return (true);
}
return (false);
}

// -------------------------------------

function noSelectedState(State, Country){
if (Country.options[Country.selectedIndex].value == "USA" || Country.options[Country.selectedIndex].value == "Canada"){
  if (State.selectedIndex == 0 || State.options[State.selectedIndex].value == "US" || State.options[State.selectedIndex].value == "Canada"){
    alert("Please select your state or province from the menu. This is required information.");
    State.focus();
    return (true);
  }
}
  return (false);
}
// -------------------------------------
function isAlphaNumeric(field, errorString){
 var checkOK = " '-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþ";
 var allValid = true;
 var checkStr = field.value;
 for (i = 0;  i < checkStr.length;  i++)
 {
   ch = checkStr.charAt(i);
   for (j = 0;  j < checkOK.length;  j++)
     if (ch == checkOK.charAt(j))
       break;
   if (j == checkOK.length)
   {
     allValid = false;
     break;
   }
 }
 if (!allValid){
   alert(errorString);
   field.focus();
 }
 return allValid;
}
// -------------------------------------
function isNumeric(field, errorString){
 var checkOK = " '-0123456789";
 var allValid = true;
 var checkStr = field.value;
 for (i = 0;  i < checkStr.length;  i++)
 {
   ch = checkStr.charAt(i);
   for (j = 0;  j < checkOK.length;  j++)
     if (ch == checkOK.charAt(j))
       break;
   if (j == checkOK.length)
   {
     allValid = false;
     break;
   }
 }
 if (!allValid){
   alert(errorString);
   field.focus();
 }
 return allValid;
}
