function CheckAddress () { 
    var errorMsg = "";
    
    if (document.address.ecom_billto_postal_name_first.value == "") {
        errorMsg += "\nPlease enter your first name.\n";    
    }

    if (document.address.ecom_billto_postal_name_last.value == "") {
        errorMsg += "\nPlease enter your last name.\n"; 
    }

    if (document.address.ecom_billto_postal_street_line1.value == "") {
        errorMsg += "\nPlease enter your address.\n";   
    }

    if (document.address.ecom_billto_postal_city.value == "") {
        errorMsg += "\nPlease enter your city.\n";  
    }

    if (document.address.ecom_billto_postal_postalcode.value == "") {
        errorMsg += "\nPlease enter your zip code.\n";  
    } else {
        if (isNaN(document.address.ecom_billto_postal_postalcode.value)) {
            errorMsg += "\nPlease enter a valid billing zip code.\n";
        }
    }

    if (document.address.ecom_billto_postal_countrycode.value == "") {
        errorMsg += "\nPlease select your country.\n";  
    }else {
        if ((document.address.ecom_billto_postal_countrycode.value == "US") || (document.address.ecom_billto_postal_countrycode.value == "CA")) {
            if (document.address.us_canada_billing_state.value == "NA") {
                errorMsg += "\nPlease select the correct billing State/Province from the drop down menu.\n";
            }
        } else {
            if (document.address.other_billing_state.value == "") {
                errorMsg += "\nPlease enter your billing state in the text box.\n";
            }
        }
    }

    if ((document.address.ecom_billto_online_email.value == "") || (document.address.ecom_billto_online_email.value.length > 0 && (document.address.ecom_billto_online_email.value.indexOf("@",0) == - 1 || document.address.ecom_billto_online_email.value.indexOf(".",0) == - 1))) {
        errorMsg += "\nPlease enter your email address.\n";
    }

    if (document.address.brickText.value == "") {
        errorMsg += "\nPlease enter your brick text.\n";
    }

    if (!document.address.same_address.checked) {
        
        if (document.address.ecom_shipto_postal_name_first.value == "") {
            errorMsg += "\nPlease enter shipping first name.\n";    
        }

        if (document.address.ecom_shipto_postal_name_last.value == "") {
            errorMsg += "\nPlease enter shipping last name.\n"; 
        }

        if (document.address.ecom_shipto_postal_street_line1.value == "") {
            errorMsg += "\nPlease enter shipping address.\n";   
        }

        if (document.address.ecom_shipto_postal_city.value == "") {
            errorMsg += "\nPlease enter shipping city.\n";  
        }

        if (document.address.ecom_shipto_postal_postalcode.value == "") {
            errorMsg += "\nPlease enter shipping zip code.\n";  
        } else {
            if (isNaN(document.address.ecom_shipto_postal_postalcode.value)) {
                errorMsg += "\nPlease enter a valid shipping zip code.\n";
            } else {
                if ((document.address.ecom_shipto_postal_postalcode.value > 99999) || (document.address.ecom_shipto_postal_postalcode.value < 1)) {
                    errorMsg += "\nPlease enter a valid shipping zip code.\n";
                }
            }
        }

        if (document.address.ecom_shipto_postal_countrycode.value == "") {
        errorMsg += "\nPlease select your shipping country.\n";  
        }else {
            if ((document.address.ecom_shipto_postal_countrycode.value == "US") || (document.address.ecom_shipto_postal_countrycode.value == "CA")) {
                if (document.address.us_canada_shipping_state.value == "NA") {
                    errorMsg += "\nPlease select the correct shipping State/Province from the drop down menu.\n";
                }
            } else {
                if (document.address.other_shipping_state.value == "") {
                    errorMsg += "\nPlease enter your shipping state in the text box.\n";
                }
            }
        }


    }

    if (errorMsg != "") {
        errorMsg += alert(errorMsg + "\n\n");
        return false;
    }

    return true;
}


function CheckPaymentInfo () { 
    var errorMsg = "";
    
    if (document.PaymentInfo.ecom_payment_card_name.value == "") {
        errorMsg += "\nPlease enter your name as it appears on the credit card.\n";    
    }

    if (document.PaymentInfo.ecom_payment_card_number.value == "") {
        errorMsg += "\nPlease enter your credit card number.\n"; 
    }

    var dateObj = new Date(); // creates object with current GMT date
    
    if (dateObj.getFullYear() > document.PaymentInfo.ecom_payment_card_expdate_year.value) {
        errorMsg += "\nThe expiration date you entered is invalid.\n";
    } else {
        if (dateObj.getFullYear() == document.PaymentInfo.ecom_payment_card_expdate_year.value) {
            if (dateObj.getMonth() + 1 > document.PaymentInfo.ecom_payment_card_expdate_month.value) {
                errorMsg += "\nThe expiration date you entered is invalid.\n";
            }
        }
        
    }

    if (errorMsg != "") {
        errorMsg += alert(errorMsg + "\n\n");
        return false;
    }

    return true;
}



function SameAddress () {
    if (document.address.same_address.checked) {
        document.address.ecom_shipto_postal_name_first.value = document.address.ecom_billto_postal_name_first.value
        document.address.ecom_shipto_postal_name_last.value = document.address.ecom_billto_postal_name_last.value;
        document.address.ecom_shipto_postal_street_line1.value = document.address.ecom_billto_postal_street_line1.value;
        document.address.ecom_shipto_postal_street_line2.value = document.address.ecom_billto_postal_street_line2.value;
        document.address.ecom_shipto_postal_city.value = document.address.ecom_billto_postal_city.value;
        document.address.ecom_shipto_postal_postalcode.value = document.address.ecom_billto_postal_postalcode.value;
        document.address.us_canada_shipping_state.value = document.address.us_canada_billing_state.value;
        document.address.other_shipping_state.value = document.address.other_billing_state.value;
        document.address.ecom_shipto_postal_countrycode.value = document.address.ecom_billto_postal_countrycode.value;
        document.address.ecom_shipto_telecom_phone_number.value = document.address.ecom_billto_telecom_phone_number.value;
    } else {
        document.address.ecom_shipto_postal_name_first.value = "";
        document.address.ecom_shipto_postal_name_last.value = "";
        document.address.ecom_shipto_postal_street_line1.value = "";
        document.address.ecom_shipto_postal_street_line2.value = "";
        document.address.ecom_shipto_postal_city.value = "";
        document.address.ecom_shipto_postal_postalcode.value = "";
        document.address.us_canada_shipping_state.value = "";
        document.address.other_shipping_state.value = "";
        document.address.ecom_shipto_postal_countrycode.value = "";
        document.address.ecom_shipto_telecom_phone_number.value = "";
    }
}
