<!--

function ValidateShipForm(){
   if(NumClick==0){
      ship_form = document.ccship
      Initialize(ship_form);
      return RunValidation(ship_form);
   }
   else{
      document.getElementById("addressInfo").style.display = "block";
      document.getElementById("continue").style.display = "none";
      return false;
      
   }
}
function ValidateForm(){
   if(NumClick==0){
      val_form = document.forms[0]
      Initialize(val_form);
      return RunValidation(val_form);
   }
   else{
      document.getElementById("addressInfo").style.display = "block";
      document.getElementById("continue").style.display = "none";
      return false;
   }
}
function ValidateCcauthForm(){
   if(NumClick==0){
      valcc_form = document.ccauth
      Initialize(valcc_form);
      return RunValidation(valcc_form);
   }
   else{
      document.getElementById("addressInfo").style.display = "block";
      document.getElementById("continue").style.display = "none";
      return false;

   }
}

var NumClick=0;
var S3Val= "";
var S4Val= "";
var S6Val= "";
var S8Val= "";
var S9Val= "";
var S12Val = "";
var S13Val = "";
var S14Val = "";
var S15Val = "";
var S16Val = "";
var S17Val = "";
var S18Val = "";
var S20Val = "";
var S21Val = "";
var S22Val = "";
var S23Val = "";
var S24Val = "";
var ServMonth = "";
var ServYear = "";
var GiftMessageVal = "";
var GiftEmailAddressVal = "";

var MonthFocusIndex = 0;
var Pswd2FocusIndex = 0;
var ACFocusIndex = 0;
var StateFocusIndex = 0;
var CountryFocusIndex = 0;
var GiftEmailIndex = 0;

function Initialize(my_form){
 for(i=0; i<my_form.elements.length; i++){
 if(my_form.elements[i].name == "p_name"){
 Tmp_Val = my_form.elements[i].value;
 if(Tmp_Val == "S8") // S8- FIRST NAME
 S8Val = my_form.elements[i+1].value;
 else{
if(Tmp_Val == "S9") // S9- LAST NAME
S9Val = my_form.elements[i+1].value;
else{
if(Tmp_Val == "S12") // S12 - ADDRESS 1
S12Val = my_form.elements[i+1].value;
 else{
if(Tmp_Val == "S13") // S13 - CITY
S13Val = my_form.elements[i+1].value;
else{
 if(Tmp_Val == "S14"){ // S14 - STATE
for(j=0; j<my_form.elements[i+1].options.length; j++){
 if(my_form.elements[i+1].options[j].selected){
 S14Val = my_form.elements[i+1].options[j].text;
 StateFocusIndex = i+1;
 break;
 }
}
 }
 else{
if(Tmp_Val == "S15"){ // S15 - COUNTRY
 for(j=0; j<my_form.elements[i+1].options.length; j++){
if(my_form.elements[i+1].options[j].selected){
S15Val = my_form.elements[i+1].options[j].text;
CountryFocusIndex = i+1;
break;
}
 }
}
else{
if(Tmp_Val == "S16") // S16 - ZIP CODE
S16Val = my_form.elements[i+1].value;
 else{
if(Tmp_Val == "S17"){ // S17 - AREA CODE
S17Val = my_form.elements[i+1].value;
ACFocusIndex = i+1;
}
else{
if(Tmp_Val == "S18") // S18 - PHONE 1
S18Val = my_form.elements[i+1].value;
 else{
if(Tmp_Val == "S6") // S6- CREDIT CARD NUMBER
S6Val = my_form.elements[i+1].value;
else{
 if(Tmp_Val == "S20") // S20 - EMAIL ADDRESS
 S20Val = my_form.elements[i+1].value;
 else{
 if(Tmp_Val == "GiftMessage") //Gift Message
  GiftMessageVal = my_form.elements[i+1].value;
 else{
 if(Tmp_Val == "GiftEmailAddress") //Gift Email
  GiftEmailAddressVal = my_form.elements[i+1].value;
 else{
if(Tmp_Val == "S3") // S3- PASSWORD 1
S3Val = my_form.elements[i+1].value;
else{
 if(Tmp_Val == "S4"){ // S3- PASSWORD 2
 S4Val = my_form.elements[i+1].value;
 Pswd2FocusIndex = i+1;
}
 else{
if(Tmp_Val == "SERVER_MONTH") 
ServMonth = my_form.elements[i+1].value;
else{
 if(Tmp_Val == "SERVER_YEAR")
ServYear = my_form.elements[i+1].value;
 else{
if(Tmp_Val == "S22"){ // S22 - MONTH
 for(j=0; j<my_form.elements[i+1].options.length; j++){
if(my_form.elements[i+1].options[j].selected){
S22Val = my_form.elements[i+1].options[j].text;
MonthFocusIndex = i+1;
break;
}
 }
}
else{
 if(Tmp_Val == "S23"){ // S23 - YEAR
for(j=0; j<my_form.elements[i+1].options.length; j++){
 if(my_form.elements[i+1].options[j].selected){
 S23Val = my_form.elements[i+1].options[j].text;
 break;
 }
}
 }
}
 }
}
 }
}
 }
}
 }
}
 }
}
 }
}
 }
}
 }
}
 }
}
 }
}

ErrMsg_FNameNull = " - Please enter your First Name.\n";
ErrMsg_LNameNull = " - Please enter your Last Name.\n";
ErrMsg_AddrssNull= " - Please enter your Address.\n";
ErrMsg_CityNull= " - Please enter your City.\n";
ErrMsg_ZipNull = " - Please enter your Zip Code.\n";
ErrMsg_AreaCodeNull= " - Please enter your Area Code.\n";
ErrMsg_PhoneNull = " - Please enter your Phone Number.\n";
ErrMsg_StateNull = " - Please select a State.\n";
ErrMsg_EmailNull = " - Please enter your Email Address.\n";
ErrMsg_CCardNull = " - Please enter your Credit Card Number.\n";
ErrMsg_CCardAscii= " - Please verify that your credit card number is correct.\n";
ErrMsg_EmailInvalid= " - Please verify that your email address follows the form, jon@aol.com\n";
ErrMsg_GiftEmailInvalid = " - Please verify that your email address for the gift message follows the form, jon@aol.com\n";
ErrMsg_Pswd1Null = " - Please enter a password for verification.\n";
ErrMsg_Pswd1Short= " - Please enter a longer password. Passwords must be at least 4 characters long.\n";
ErrMsg_Pswd1Chars= " - Please use only numbers and letters in your password.\n";
ErrMsg_PasswordSame= "We are having difficulties setting up your account:\n\n - Both your passwords must be the same.";
ErrMsg_CountryState1 = "We are having difficulties setting up your account:\n\n - You have chosen United States as your Country:\n Please select a State.";
ErrMsg_CountryState2 = "We are having difficulties setting up your account:\n\n - You have selected a state in United States.\n Please make sure that you have selected United States as your country.";
ErrMsg_ACodeInvalid= "We are having difficulties setting up your account:\n\n - Please verify that your area code is correct.\n Valid area codes in the US are three digits.\n";
ErrMsg_MonthYear = "We are having difficulties setting up your account:\n\n - Please verify that your Credit Card Expiration date is correct.";
ErrMsg_GiftMailAddrNull = " - Please enter the email address for your gift message.\n";

function RunValidation(my_form){
  errorString = new String("");
  errorMessage = new String("");
  SVal = new String("");
  focusIndex = 0;
  ErrorFlag = false;

//----------------------------------------------
 for(l=0; l<my_form.elements.length; l++){
  errorMessage = "";
  if(my_form.elements[l].name=="L2"){
   if(my_form.elements[l].checked && my_form.elements[l].value =="creditcardpayment"){
    for(a=0; a<my_form.elements.length; a++){
     if(my_form.elements[a].name=="p_name"){
      SVal = my_form.elements[a].value;
      if(SVal == "S6"){
       errorMessage = ValidateCC(S6Val);
       focusIndex = a+1;
      }
     }
    }
   }
  }
  errorString = errorString + errorMessage;
  if(ErrorFlag == false && errorMessage != ""){
       ErrorFlag = true;
    }
  if(ErrorFlag != false){
     alert("We are having difficulties setting up your account:\n\n" + errorString);
     my_form.elements[focusIndex].focus();
     return false;
   }
 }
//-------------------------------------------------------- 


  for(l=0; l<my_form.elements.length; l++){
    errorMessage = "";
    if(my_form.elements[l].name=="p_name"){
      SVal = my_form.elements[l].value;
      if(SVal == "S8")
        errorMessage = CheckNull(S8Val, ErrMsg_FNameNull);
      else{
        if(SVal == "S9")
          errorMessage = CheckNull(S9Val, ErrMsg_LNameNull);
        else{
          if(SVal == "S12")
            errorMessage = CheckNull(S12Val, ErrMsg_AddrssNull);
          else{
            if(SVal == "S13")
              errorMessage = CheckNull(S13Val, ErrMsg_CityNull);
            else{
              if(SVal == "S14")
                errorMessage = ValidateState(S14Val);
              else{
                if(SVal == "S16")
                  errorMessage = CheckNull(S16Val, ErrMsg_ZipNull);
                else{
                  if(SVal == "S18")
                    errorMessage = CheckNull(S18Val, ErrMsg_PhoneNull);
                //else{
                //  if(SVal == "S6")
                //    errorMessage = ValidateCC(S6Val);
                    else{
                      if(SVal == "S20")
                        errorMessage = ValidateEmailAddress(S20Val);
                      else{
                        if(SVal == "S3"){
                          Browser_Version = new String(navigator.appVersion);
                          if(Browser_Version.indexOf("AOL 3.0") == -1){
                            errorMessage = ValidatePassword(S3Val);
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
        //}
        }
      }    
      if(SVal == "GiftEmailAddress"){
        if(GiftMessageVal != ""){
          errorMessage = ValidateGiftEmailAddress(GiftEmailAddressVal);
        }
      }
      errorString = errorString + errorMessage;
      if(ErrorFlag == false && errorMessage != ""){
        ErrorFlag = true;
        focusIndex = l+1;
      }
    }
  }
  if(ErrorFlag != false){
    alert("We are having difficulties setting up your account:\n\n" + errorString);
    document.getElementById("addressInfo").style.display = "block";
    document.getElementById("continue").style.display = "none";
    my_form.elements[focusIndex].focus();
    return false;
  }
  else{
    errorString = MonthYear(S22Val, S23Val);
    if(errorString != ""){
    alert(errorString);
    document.getElementById("addressInfo").style.display = "block";
    document.getElementById("continue").style.display = "none";
    my_form.elements[MonthFocusIndex].focus();
    return false;
  }
  errorString = CountryState(S15Val, S14Val);
  if(errorString != ""){
    alert(errorString);
    document.getElementById("addressInfo").style.display = "block";
    document.getElementById("continue").style.display = "none";
    my_form.elements[StateFocusIndex].focus();
    return false;
  }
  errorString = CountryState1(S15Val, S14Val);
  if(errorString != ""){
      alert(errorString);
      document.getElementById("addressInfo").style.display = "block";
      document.getElementById("continue").style.display = "none";
      my_form.elements[CountryFocusIndex].focus();
      return false;
    }
    errorString = CountryAreaCode(S15Val, S17Val);
    if(errorString != ""){
      alert(errorString);
      document.getElementById("addressInfo").style.display = "block";
      document.getElementById("continue").style.display = "none";
      my_form.elements[ACFocusIndex].focus();
      return false;
    }
    errorString = CkPasswords(S3Val, S4Val);
    if(errorString != ""){
      alert(errorString);
      document.getElementById("addressInfo").style.display = "block";
      document.getElementById("continue").style.display = "none";
      my_form.elements[Pswd2FocusIndex].focus();
      return false;
    }
  }
  NumClick++;
  return true;
}

function isNULL(aString){

 if(aString == "") return true;

 for(m=0; m<aString.length; m++){
if(aString.charAt(m) != ' '){
 document.getElementById("addressInfo").style.display = "block";
 document.getElementById("continue").style.display = "none";
 return false;
}
 }
 return true;
}

function CheckNull(formContents, ErrorString){
 if(isNULL(formContents)){
return ErrorString;
 }
 return "";
}

function ValidateState(formContents){
 if(formContents == "Select"){
return ErrMsg_StateNull;
 }
 return "";
}

function ValidateEmailAddress(formContents){
 if(isNULL(formContents)){;
  return ErrMsg_EmailNull;
 }
 if(formContents.indexOf("@") == -1 || formContents.indexOf(".") == -1){
return ErrMsg_EmailInvalid;
 }
 return "";
}

function ValidateGiftEmailAddress(formContents){
 if(isNULL(formContents)){;
  return ErrMsg_GiftMailAddrNull
 }
 if(formContents.indexOf("@") == -1 || formContents.indexOf(".") == -1){
return ErrMsg_GiftEmailInvalid;
 }
 return "";
}

function ValidatePassword(formContents, FirstOrSecond){
 flag = false;
 AlphaNumeric = new Array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','1','2','3','4','5','6','7','8','9','0');

 if(formContents == ""){
return ErrMsg_Pswd1Null;
 }

 if(formContents.length < 4){
return ErrMsg_Pswd1Short;
 }

 for(m=0; m<formContents.length; m++){
flag = false;
for(n=0; n<AlphaNumeric.length; n++){
 if(formContents.charAt(m) == AlphaNumeric[n]){
flag = true;
 }
}
if(flag == false){
 return ErrMsg_Pswd1Chars;
}
 }

 return "";
}

function CountryState(CountryContents, StateContents){

 if(CountryContents == "United States"){
if(StateContents == "Select" || StateContents == "Non US"){
 errorMessage = ErrMsg_CountryState1;
 return errorMessage;
}
 }

 return "";
}

function CountryState1(CountryContents, StateContents){
 if (CountryContents == "Puerto Rico" && StateContents == "PR")
  return "";
else 
 return "";
}

function CountryAreaCode(CountryContents, AreaCodeContents){
 Numeric = new Array('1','2','3','4','5','6','7','8','9','0');
 flag = false;

 if(CountryContents == "United States"){
if(AreaCodeContents.length != 3){
 errorMessage = ErrMsg_ACodeInvalid;
 return errorMessage;
}
//--><!--

for(m=0; m<AreaCodeContents.length; m++){
 flag = false;
 for(n=0; n<Numeric.length; n++){
if(AreaCodeContents.charAt(m) == Numeric[n]){
 flag = true;
}
 }
 if(flag == false){
return ErrMsg_ACodeInvalid;
 }
}
 }
 return "";
}

function ValidateCC(formContents){
 flag = false;
 Numeric = new Array('1','2','3','4','5','6','7','8','9','0');
 counter = 0;
 if(formContents == ""){
errorMessage = ErrMsg_CCardNull;
return errorMessage;
 }

 for(m=0; m<formContents.length; m++){
flag = false;
if( (formContents.charAt(m) != '-') && 
 (formContents.charAt(m) != '/') && 
 (formContents.charAt(m) != ' ') ) {
 for(n=0; n<Numeric.length; n++){
if(formContents.charAt(m) == Numeric[n]){
 flag = true;
 counter ++;
}
 }
 if(flag == false){
errorMessage = ErrMsg_CCardAscii;
return errorMessage;
 }
}
 }
 if(counter < 12)
return ErrMsg_CCardAscii;
 return "";
}

function MonthYear(MonthInput, YearInput){ 

 if(MonthInput == "" && YearInput == "") 
return ""; 

 if(eval(MonthInput) < eval(ServMonth)){ 
if(eval(YearInput) <= eval(ServYear)){ 
 return ErrMsg_MonthYear; 
} 
 } 
 return ""; 
}

function CkPasswords(Password1, Password2){
 if(Password1 == Password2)
return "";
 else
return ErrMsg_PasswordSame;
}
//-->
