//function to validate the account information on form
function IsValidAccountInfo(frmFormName) {

   var intIndex
   var intStrippedNum

//validate first name
    if (isWhitespace(frmFormName.txtFirstName.value)) {
      return warnInvalid(frmFormName.txtFirstName, "Your First Name must be entered.")
      }
//validate last name
   if (isWhitespace(frmFormName.txtLastName.value)) {
      return warnInvalid(frmFormName.txtLastName,"Your Last Name must be entered.")
      }
//validate street address
   if ((isWhitespace(frmFormName.txtStreet1.value)) &&
         (isWhitespace(frmFormName.txtStreet2.value))) {
      return warnInvalid(frmFormName.txtStreet1,"A Street Address must be entered.")
      }
//validate city
   if (isWhitespace(frmFormName.txtCity.value)) {
      return warnInvalid(frmFormName.txtCity,"A City must be entered.")
      }
//validate state
   intIndex = (frmFormName.selState.selectedIndex)
   if (frmFormName.selState.options[intIndex].text == "- -") {
      return warnInvalid(frmFormName.selState,"A State must be selected.")
      }
//validate zipcode
   if (isWhitespace(frmFormName.txtZip.value)) {
      return warnInvalid(frmFormName.txtZip,"A Zip Code must be entered.")
      }

   intIndex = (frmFormName.selCountry.selectedIndex)
   switch (frmFormName.selCountry.options[intIndex].text) {
      case "US":
         if (!ValidUSZip(frmFormName.txtZip)) {
            return warnInvalid(frmFormName.txtZip,"An invalid United States Zip Code was entered.  Please re-enter now.")
            }
         frmFormName.txtZip.value = stripCharsNotInBag(frmFormName.txtZip.value, reInteger)
         break;
      case "CA":
         if (!ValidCAZip(frmFormName.txtZip)) {
            return warnInvalid(frmFormName.txtZip,"An invalid Canada Zip Code was entered.  Please re-enter now.")
            }
            break;
      case "MX":
         if (!ValidMXZip(frmFormName.txtZip)) {
            return warnInvalid(frmFormName.txtZip,"An invalid Mexico Zip Code was entered.  Please re-enter now.")
            }
            break;
      default:
         return warnInvalid(frmFormName.selCountry,"An invalid Country was selected.")
      }
//validate email address
   if (isWhitespace(frmFormName.txtEmailAddr.value)) {
      return warnInvalid(frmFormName.txtEmailAddr,"An E-mail Address must be entered.")
      }
   else{
      if (!ValidEMail(frmFormName.txtEmailAddr.value)) {
         return warnInvalid(frmFormName.txtEmailAddr,"An invalid E-email Address was entered. Please re-enter now.")
         }
      }
//validate daytime phone
   if (isWhitespace(frmFormName.txtDayPhoneNum.value)) {
      return warnInvalid(frmFormName.txtDayPhoneNum,"A Daytime Phone number must be entered in the form (111) 222-3333.")
      }
   intStrippedNum = stripCharsNotInBag (frmFormName.txtDayPhoneNum.value, reInteger)
   intIndex = (frmFormName.selCountry.selectedIndex)
   if (frmFormName.selCountry.options[intIndex].text == "US") {
      if (isUSPhoneNumber(intStrippedNum)) {
         frmFormName.txtDayPhoneNum.value = reformatUSPhone(intStrippedNum)
         }
      else {
         return warnInvalid(frmFormName.txtDayPhoneNum,"An invalid Daytime Phone number was entered.  Please re-enter in the form (111) 222-3333.")
         }
      }
   else
      {
      if (!isInternationalPhoneNumber(intStrippedNum)) {
         return warnInvalid(frmFormName.txtDayPhoneNum,"An invalid Daytime Phone number was entered.  Please re-enter now in the form (111) 222-3333.")
         }
      }
//validate evening phone
   if (!isWhitespace(frmFormName.txtEveningPhoneNum.value)) {
      intStrippedNum = stripCharsNotInBag (frmFormName.txtEveningPhoneNum.value, reInteger)
      intIndex = (frmFormName.selCountry.selectedIndex)
      if (frmFormName.selCountry.options[intIndex].text == "US") {
         if (isUSPhoneNumber(intStrippedNum)) {
            frmFormName.txtEveningPhoneNum.value = reformatUSPhone(intStrippedNum)
            }
         else {
            return warnInvalid(frmFormName.txtEveningPhoneNum,"An invalid Evening Phone number was entered.  Please re-enter in the form (111) 222-3333.")
            }
         }
      else {
         if (!isInternationalPhoneNumber(intStrippedNum)) {
            return warnInvalid(frmFormName.txtEveningPhoneNum,"An invalid Evening Phone number was entered.  Please re-enter in the form (111) 222-3333.")
            }
         }
      }
//validate fax number
   if (!isWhitespace(frmFormName.txtFaxNum.value)) {
      intStrippedNum = stripCharsNotInBag (frmFormName.txtFaxNum.value, reInteger)
      intIndex = (frmFormName.selCountry.selectedIndex)
      if (frmFormName.selCountry.options[intIndex].text == "US") {
         if (isUSPhoneNumber(intStrippedNum)) {
            frmFormName.txtFaxNum.value = reformatUSPhone(intStrippedNum)
            }
         else {
            return warnInvalid(frmFormName.txtFaxNum,"An invalid Fax Number was entered.  Please re-enter now.")
            }
         }
      else {
         if (!isInternationalPhoneNumber(intStrippedNum)) {
            return warnInvalid(frmFormName.txtFaxNum,"An invalid Fax Number was entered.  Please re-enter now.")
            }
         }
      }
   return (true)

   }  //end function


function IsValidUserid(txtUserid) {
  if (isWhitespace(txtUserid.value)) {
     return warnInvalid(txtUserid,"Your User ID must be entered")
     }
  return (true)
  }

function IsValidPassword(pasPassword) {
   if ((pasPassword.value == "") || (pasPassword.value.substring(0,1) == " ")) {
      return warnInvalid(pasPassword,"You must enter a Password.")
      }
   if ((pasPassword.value.length < 6) || (pasPassword.value.length > 20)) {
      pasPassword.value = ""
      return warnInvalid(pasPassword,"Your Password must be between six and twenty characters in length.  Please re-enter now.")
      }
   if (containsInvalidCharacters(pasPassword.value)) {
   		pasPassword.value = "";
   		return warnInvalid(pasPassword, "Your Password contains an invalid character (\", <, >).  Please re-enter now.");
      }
   return (true);
   }

function IsValidPassConfirm(pasPassword,pasPasswordConfirm) {
   if ((pasPassword.value == "") ||
         (pasPassword.value.substring(0,1) == " ")) {
      return warnInvalid(pasPassword,"You must enter a Password.")
      }
   if (!(IsValidPassword(pasPassword))) {
      return (false)
      }
   if ((pasPasswordConfirm.value == "") ||
         (pasPasswordConfirm.value.substring(0,1) == " ")) {
      return warnInvalid(pasPasswordConfirm,"Your Password must be entered and confirmed.  Please re-enter now.")
      }
   if (pasPassword.value != pasPasswordConfirm.value) {
      pasPassword.value = ""
      pasPasswordConfirm.value = ""
      return warnInvalid(pasPassword,"Your Password and Password Confirmation did not equal each other.  Please re-enter now.")
      }
   return (true)
}

//function to validate a user's credit card information
function IsValidCreditCardInfo(frmFormName) {
   var today = new Date()
   var strStrippedAddCreditCardNum
//validate credit card number
   if (!isWhitespace(frmFormName.txtAddCreditCardNum.value)) {
      //removed any spaces in credit card
      strStrippedAddCreditCardNum = stripWhitespace(frmFormName.txtAddCreditCardNum.value)
      intIndex = (frmFormName.selAddCreditCardType.selectedIndex)
      switch (frmFormName.selAddCreditCardType.options[intIndex].text) {
         case "Visa":
            if (!isVisa(strStrippedAddCreditCardNum)) {
               return warnInvalid(frmFormName.txtAddCreditCardNum,frmFormName.txtAddCreditCardNum.value + " is an invalid Visa number.  Please re-enter now.")
               }
            break;
         case "MasterCard":
            if (!isMasterCard(strStrippedAddCreditCardNum)) {
               return warnInvalid(frmFormName.txtAddCreditCardNum,frmFormName.txtAddCreditCardNum.value + " is an invalid MasterCard number.  Please re-enter now.")
               }
            break;
         case "American Express":
            if (!isAmericanExpress(strStrippedAddCreditCardNum)) {
               return warnInvalid(frmFormName.txtAddCreditCardNum,frmFormName.txtAddCreditCardNum.value + " is an invalid American Express number.  Please re-enter now.")
               }
            break;
         case "Discover Card":
            if (!isDiscover(strStrippedAddCreditCardNum)) {
               return warnInvalid(frmFormName.txtAddCreditCardNum,frmFormName.txtAddCreditCardNum.value + " is an invalid Discover card number.  Please re-enter now.")
               }
            break;
         default:
            return warnInvalid("","An invalid Credit Card Type was selected.  Please re-select now.")

         }    //end switch

//validate credit card expiration date
      intIndex = (frmFormName.selAddCreditCardExpMonth.selectedIndex)
      if (isWhitespace(frmFormName.selAddCreditCardExpMonth.options[intIndex].text)) {
         return warnInvalid(frmFormName.selAddCreditCardExpMonth,"A Credit Card Expiration Month must be entered")
         }
      intIndex = (frmFormName.selAddCreditCardExpYear.selectedIndex)
      if (isWhitespace(frmFormName.selAddCreditCardExpYear.options[intIndex].text)) {
         return warnInvalid(frmFormName.selAddCreditCardExpYear,"A Credit Card Expiration Year must be entered")
         }
      if (frmFormName.selAddCreditCardExpYear.options[intIndex].text <= y2kFmt(today.getFullYear())) {
         intIndex = (frmFormName.selAddCreditCardExpMonth.selectedIndex)
         if (frmFormName.selAddCreditCardExpMonth.options[intIndex].value < today.getMonth()) {
            return warnInvalid(frmFormName.selAddCreditCardExpMonth,"The Credit Card Expiration date is in the past.  Either re-enter the Expiration Date or a new Credit Card Number")
            }
         }

//validate credit card name
      if (isWhitespace(frmFormName.txtAddCreditCardName.value)) {
         return warnInvalid(frmFormName.txtAddCreditCardName,"Your name as it appears on the credit card must be entered.")
         }
      }   //end if statement
      return (true)
   }  //end function