// YOU LOAD 'GENERALVALIDATE.JS' BEFORE
// THIS FILE IN YOUR HTML PAGE

// ERROR CHECK HOLDER FOR FIELD CHECKING FUNCTIONS BELOW
var isOkay = true;

function CheckShipping(){
    // IF THE SHIPPING CHECKBOX IS NOT CHECKED VALIDATE INFO
    // OTHERWISE PLACE CURRENT USER BILLING INFO IN THE CC FIELDS
    if(!document.forms["myform"].ShippingAddressSame.checked){
        // define another array to cycle through billing info
        aShippingFields = new Array();
        aShippingFields[0] = "isAlpha(document.forms[\"myform\"].UserShippingStreetAddress1, \"a shipping street address\\nif different from your mailing address\\nor uncheck the box above\");"
        aShippingFields[1] = "isLetter(document.forms[\"myform\"].UserShippingCity, \"a shipping city\\nif different from your mailing address\\nor uncheck the box above\");"
        aShippingFields[2] = "isZipCode(document.forms[\"myform\"].UserShippingZipCode, \"a shipping zip code\\nif different from your mailing address\\nor uncheck the box above\");"
        aShippingFields[3] = "isLetter(document.forms[\"myform\"].UserShippingCountryName, \"a shipping country\\nif different from your mailing address\\nor uncheck the box above\");"
        iLength = aShippingFields.length;
        for(i = 0; i < iLength; i++){
            if(isOkay){
                isOkay = eval(aShippingFields[i]);
            }
        }
    } else {
        document.forms["myform"].UserShippingStreetAddress1.value = document.forms["myform"].UserStreetAddress1.value;
        document.forms["myform"].UserShippingCity.value = document.forms["myform"].UserCity.value;
        document.forms["myform"].UserShippingState.options[document.forms["myform"].UserShippingState.selectedIndex].value = document.forms["myform"].UserState.options[document.forms["myform"].UserState.selectedIndex].value;
        document.forms["myform"].UserShippingZipCode.value = document.forms["myform"].UserZipCode.value;
        document.forms["myform"].UserShippingCountryName.value = document.forms["myform"].UserCountryName.value;
    }
} // END C h e c k S h i p p i n g ( )

function CheckBilling(){
    // IF THE SHIPPING CHECKBOX IS NOT CHECKED VALIDATE INFO
    // OTHERWISE PLACE CURRENT USER BILLING INFO IN THE CC FIELDS
    if(!document.forms["myform"].BillingAddresSame.checked){
        // define another array to cycle through billing info
        aBillingFields = new Array();
        aBillingFields[0] = "isAlpha(document.forms[\"myform\"].UserBillingStreetAddress1, \"a billing street address\\nif different from your mailing address\\nor uncheck the box above\");"
        aBillingFields[1] = "isLetter(document.forms[\"myform\"].UserBillingCity, \"a billing city\\nif different from your mailing address\\nor uncheck the box above\");"
        aBillingFields[2] = "isZipCode(document.forms[\"myform\"].UserBillingZipCode, \"a billing zip code\\nif different from your mailing address\\nor uncheck the box above\");"
        aBillingFields[3] = "isLetter(document.forms[\"myform\"].UserBillingCountryName, \"a billing country\\nif different from your mailing address\\nor uncheck the box above\");"
        iLength = aBillingFields.length;
        for(i = 0; i < iLength; i++){
            if(isOkay){
                isOkay = eval(aBillingFields[i]);
            }
        }
    } else {
        document.forms["myform"].UserBillingStreetAddress1.value = document.forms["myform"].UserStreetAddress1.value;
        document.forms["myform"].UserBillingCity.value = document.forms["myform"].UserCity.value;
        document.forms["myform"].UserBillingState.options[document.forms["myform"].UserBillingState.selectedIndex].value = document.forms["myform"].UserState.options[document.forms["myform"].UserState.selectedIndex].value;
        document.forms["myform"].UserBillingZipCode.value = document.forms["myform"].UserZipCode.value;
        document.forms["myform"].UserBillingCountryName.value = document.forms["myform"].UserCountryName.value;
    }
} // END C h e c k B i l l i n g ( )
aFieldList = new Array();
aFieldList[0] = "isLetter(document.forms[\"myform\"].UserFirstName, \"a first name\");"
// aFieldList[1] = "isLetter(document.forms[\"myform\"].UserMiddleName, \"a middle name\");"
aFieldList[1] = "isLetter(document.forms[\"myform\"].UserLastName, \"a last name\");"
aFieldList[2] = "isPhone(document.forms[\"myform\"].ContactPhoneAreaCode, document.forms[\"myform\"].ContactPhonePrefix, document.forms[\"myform\"].ContactPhoneLast4Digits, document.forms[\"myform\"].ContactPhoneNumber)";
aFieldList[3] = "isPhone(document.forms[\"myform\"].DSLPhoneAreaCode, document.forms[\"myform\"].DSLPhonePrefix, document.forms[\"myform\"].DSLPhoneLast4Digits, document.forms[\"myform\"].DSLPhoneNumber)";
aFieldList[4] = "isAlpha(document.forms[\"myform\"].UserStreetAddress1, \"a street address\");"
aFieldList[5] = "isLetter(document.forms[\"myform\"].UserCity, \"a city\");"
aFieldList[6] = "isZipCode(document.forms[\"myform\"].UserZipCode, \"a valid ZIP Code\");"
aFieldList[7] = "isLetter(document.forms[\"myform\"].UserCountryName, \"a country\");"
aFieldList[8] = "isMail(document.forms[\"myform\"].UserEmailAddress);"
aFieldList[9] = "isLetter(document.forms[\"myform\"].UserAccountName, \"an account name\");"
aFieldList[10] = "isPassword(document.forms[\"myform\"].UserAccountPassword, document.forms[\"myform\"].UserAccountPasswordVerify);"
aFieldList[11] = "isLetter(document.forms[\"myform\"].UserAccountReminderWord, \"a reminder word\");"
aFieldList[12] = "isDigit(document.forms[\"myform\"].CCNumber, \"a credit card number\");"
//aFieldList[14] = "isAlpha(document.forms[\"myform\"].CCExpires, \"an expiration date\");"

function CheckForm(){
    iLength = aFieldList.length;
    for(i = 0; i < iLength; i++){
        if(isOkay){
            //alert("i = " + i);
            isOkay = eval(aFieldList[i]);
//        } else {
//            alert("Error in field " + i);    
        }
    }

    if(isOkay){
        CheckShipping();
    }
    
    if(isOkay){
        CheckBilling();
    }
    
// insert month/year select box values into CCExpires field
document.forms["myform"].CCExpires.value = document.forms["myform"].expiresM.options[document.forms["myform"].expiresM.selectedIndex].value + "/" + document.forms["myform"].expiresY.options[document.forms["myform"].expiresY.selectedIndex].value
//alert(document.forms["myform"].CCExpires.value);

if(isOkay){
   document.forms["myform"].submit();
   //alert("Congratulations!\n\nYou successfully completed the form");
    } else {
        isOkay = true;
        return false;
    }

} // END C h e c k F o r m ( )
