﻿
//global variables that can be used by ALL the functions on this page. 
var inputs;
var imgFalse = '../images/un_checked.jpg';
var imgTrue = '../images/checked.jpg';

function getRadioCheckedValue(oRadio) {
	for(var i = 0; i < oRadio.length; i++) {
		if(oRadio[i].checked) {
		return oRadio[i].value;
		}
	}
	return '';
}

function addCoupon() {
    if (document.CouponForm) {
        if (document.CouponForm.coupon.value.length != 0) {
            document.TheForm.skipupdate.value = "true";
            document.TheForm.coupon.value = document.CouponForm.coupon.value;
        }
    }
}

function AddLearn() {
    if (document.getElementById("Country").value == 'United States') {
        document.TheForm.QTY_Product.value = "36_51_" + document.getElementById("Quantity").value;
    }
    else if (document.getElementById("Country").value == 'Canada') {
        document.TheForm.QTY_Product.value = "36_106_" + document.getElementById("Quantity").value;
    }
    else {
        document.TheForm.QTY_Product.value = "36_107_" + document.getElementById("Quantity").value;
    }
}

function AddLyric() {
    document.TheForm.QTY_Product.value = '';
    var selected = false;
    if (document.getElementById("Country").value == 'United States') {
        if (document.getElementById("Spanish") && document.getElementById("Spanish").checked == true) {
            selected = true;
            document.TheForm.QTY_Product.value = '16_25_1';
        }
        if (document.getElementById("French") && document.getElementById("French").checked == true) {
            selected = true;
            document.TheForm.QTY_Product.value += ',17_26_1';
        }
        if (document.getElementById("Italian") && document.getElementById("Italian").checked == true) {
            selected = true;
            document.TheForm.QTY_Product.value += ',19_28_1';
        }
        if (document.getElementById("German") && document.getElementById("German").checked == true) {
            selected = true;
            document.TheForm.QTY_Product.value += ',18_27_1';
        }
        if (!selected) {
            alert('Please select one or more languages, or click "NO THANKS"');
            return false;
        }
        return true;
    }

    if (document.getElementById("Country").value == 'Canada') {
        if (document.getElementById("Spanish") && document.getElementById("Spanish").checked == true) {
            selected = true;
            document.TheForm.QTY_Product.value = '16_82_1';
        }
        if (document.getElementById("French") && document.getElementById("French").checked == true) {
            selected = true;
            document.TheForm.QTY_Product.value += ',17_76_1';
        }
        if (document.getElementById("Italian") && document.getElementById("Italian").checked == true) {
            selected = true;
            document.TheForm.QTY_Product.value += ',19_80_1';
        }
        if (document.getElementById("German") && document.getElementById("German").checked == true) {
            selected = true;
            document.TheForm.QTY_Product.value += ',18_78_1';
        }
        if (!selected) {
            alert('Please select one or more languages, or click "NO THANKS"');
            return false;
        }
        return true;
    }

    else {
        if (document.getElementById("Spanish") && document.getElementById("Spanish").checked == true) {
            selected = true;
            document.TheForm.QTY_Product.value = '16_83_1';
        }
        if (document.getElementById("French") && document.getElementById("French").checked == true) {
            selected = true;
            document.TheForm.QTY_Product.value += ',17_77_1';
        }
        if (document.getElementById("Italian") && document.getElementById("Italian").checked == true) {
            selected = true;
            document.TheForm.QTY_Product.value += ',19_81_1';
        }
        if (document.getElementById("German") && document.getElementById("German").checked == true) {
            selected = true;
            document.TheForm.QTY_Product.value += ',18_79_1';
        }
        if (!selected) {
            alert('Please select one or more languages, or click "NO THANKS"');
            return false;
        }
        return true;
    }
}

function AddMusic() {
    if (document.getElementById("Country").value == 'United States') {
        document.TheForm.QTY_Product.value = "39_56_" + document.getElementById("Quantity").value;
    }
    else if (document.getElementById("Country").value == 'Canada') {
        document.TheForm.QTY_Product.value = "39_84_" + document.getElementById("Quantity").value;
    }
    else {
        document.TheForm.QTY_Product.value = "39_85_" + document.getElementById("Quantity").value;
    }
}

function AddPotty() {
    document.TheForm.QTY_Product.value = '';
    var selected = false;
    if (document.getElementById("Country").value == 'United States') {
        if (document.getElementById("Animals")) {
            if (document.getElementById("Animals").checked == true) {
                selected = true;
                document.TheForm.QTY_Product.value += '29_42_1,';
            }
        }
        if (document.getElementById("Princess")) {
            if (document.getElementById("Princess").checked == true) {
                selected = true;
                document.TheForm.QTY_Product.value += '28_41_1,';
            }
        }
        if (document.getElementById("MyBag")) {
            if (document.getElementById("MyBag").checked == true) {
                selected = true;
                document.TheForm.QTY_Product.value += '27_40_1,';
            }
        }
        if (document.getElementById("Spelling")) {
            if (document.getElementById("Spelling").checked == true) {
                selected = true;
                document.TheForm.QTY_Product.value += '31_44_1,';
            }
        }
        if (document.getElementById("Stickers")) {
            if (document.getElementById("Stickers").checked == true) {
                selected = true;
                document.TheForm.QTY_Product.value += '34_47_1,';
            }
        }
        if (document.getElementById("Math")) {
            if (document.getElementById("Math").checked == true) {
                selected = true;
                document.TheForm.QTY_Product.value += '30_43_1,';
            }
        }
        if (!selected) {
            alert('Please select one or more products, or click "NO THANKS"');
            return false;
        }
        return true;
    }

    else if (document.getElementById("Country").value == 'Canada') {
        if (document.getElementById("Animals")) {
            if (document.getElementById("Animals").checked == true) {
                selected = true;
                document.TheForm.QTY_Product.value += '29_60_1,';
            }
        }
        if (document.getElementById("Princess")) {
            if (document.getElementById("Princess").checked == true) {
                selected = true;
                document.TheForm.QTY_Product.value += '28_61_1,';
            }
        }
        if (document.getElementById("MyBag")) {
            if (document.getElementById("MyBag").checked == true) {
                selected = true;
                document.TheForm.QTY_Product.value += '27_86_1,';
            }
        }
        if (document.getElementById("Spelling")) {
            if (document.getElementById("Spelling").checked == true) {
                selected = true;
                document.TheForm.QTY_Product.value += '31_94_1,';
            }
        }
        if (document.getElementById("Stickers")) {
            if (document.getElementById("Stickers").checked == true) {
                selected = true;
                document.TheForm.QTY_Product.value += '34_64_1,';
            }
        }
        if (document.getElementById("Math")) {
            if (document.getElementById("Math").checked == true) {
                selected = true;
                document.TheForm.QTY_Product.value += '30_92_1,';
            }
        }
        if (!selected) {
            alert('Please select one or more products, or click "NO THANKS"');
            return false;
        }
        return true;
    }

    else {
        if (document.getElementById("Animals")) {
            if (document.getElementById("Animals").checked == true) {
                selected = true;
                document.TheForm.QTY_Product.value += '29_62_1,';
            }
        }
        if (document.getElementById("Princess")) {
            if (document.getElementById("Princess").checked == true) {
                selected = true;
                document.TheForm.QTY_Product.value += '28_63_1,';
            }
        }
        if (document.getElementById("MyBag")) {
            if (document.getElementById("MyBag").checked == true) {
                selected = true;
                document.TheForm.QTY_Product.value += '27_87_1,';
            }
        }
        if (document.getElementById("Spelling")) {
            if (document.getElementById("Spelling").checked == true) {
                selected = true;
                document.TheForm.QTY_Product.value += '31_95_1,';
            }
        }
        if (document.getElementById("Stickers")) {
            if (document.getElementById("Stickers").checked == true) {
                selected = true;
                document.TheForm.QTY_Product.value += '34_66_1,';
            }
        }
        if (document.getElementById("Math")) {
            if (document.getElementById("Math").checked == true) {
                selected = true;
                document.TheForm.QTY_Product.value += '30_93_1,';
            }
        }
        if (!selected) {
            alert('Please select one or more products, or click "NO THANKS"');
            return false;
        }
        return true;
    }
}

function AddSliding() {
    document.TheForm.QTY_Product.value = document.TheForm.QTY_Product.value + document.getElementById("Quantity").value;
}

function ccnumber_verify() {
    var strNum
    strNum = document.getElementById("CardNumber").value;
    strNum = strNum.replace(/-|\s/g, "");
    if (isNumberValid(strNum) && isCardTypeCorrect(strNum))
        return true;
    else if (isNumberMasked(strNum))
        return true;
    else
        return false;
}

//change the checkbox status and the replacement image 
function checkChange(i) {
    //get all the input fields on the page 
    inputs = document.getElementsByTagName('input');

    //cycle trough the input fields
    for (var j = 0; j < inputs.length; j++) {

        //check if the input is a checkbox 
        if (inputs[j].getAttribute('type') == 'checkbox') {
            inputs[j].checked = '';
            document.getElementById('checkImage' + j).src = imgFalse;
        }
    }
    inputs[i].checked = 'checked';
    document.getElementById('checkImage' + i).src = imgTrue;
} 

function Collapse() {
    document.getElementById("BillingForm").style.display = 'none';
}

function Expand() {
    document.getElementById("BillingForm").style.display = 'block';
}

function ExpandUpdateSection() {
    document.getElementById("ShippingSection").style.display = 'none';
    document.getElementById("ShippingSectionButton").style.display = 'none';
    document.getElementById("BillingSection").style.display = 'none';
    document.getElementById("BillingSectionButton").style.display = 'none';
    document.getElementById("PaymentSection").style.display = 'none';
    document.getElementById("PaymentSectionButton").style.display = 'none';
    document.getElementById("ConfirmButton").style.display = 'none';
    document.getElementById("ShippingSectionEdit").style.display = 'block';
    document.getElementById("BillingSectionEdit").style.display = 'block';
    document.getElementById("PaymentSectionEdit").style.display = 'block';
}

function expdatemonth_verify() {
    var strYear;
    var StrMonth;

    strYear = document.getElementById("ExpirationYear").value;
    strMonth = document.getElementById("ExpirationMonth").value;

    var cDigitMonth = strMonth.charAt(0);
    if (isDigit(cDigitMonth)) {
        var nDigitMonth = parseInt(cDigitMonth, 10);
        if (nDigitMonth == 0) strMonth = strMonth.charAt(1);
    }
    var d = new Date();
    var nMonth = parseInt(strMonth, 10);
    var nYear = parseInt(strYear, 10);
    if (nYear < d.getFullYear()) return false;
    else if (nYear > d.getFullYear()) return true;
    else if (nMonth < d.getMonth() + 1) return false;
    else return true;
}

function expdateyear_verify() {
    var strYear;
    strYear = document.getElementById("ExpirationYear").value;
    var nYear = parseInt(strYear, 10);
    var d = new Date();
    if (nYear < d.getFullYear()) return false;
    else return true;
}

function HideContent(d) {
    if (d.length < 1) { return; }
    document.getElementById(d).style.display = "none";
}

//this function runs when the page is loaded, put all your other onload stuff in here too.
function init() {    
    replaceChecks();
}

function isCardTypeCorrect(strNum) {
    if (strNum.match("^6011[0-9]{12}$") || strNum.match("^3[47][0-9]{13}$") || strNum.match("^4([0-9]{15}$|[0-9]{12}$)") || strNum.match("^5[1-5][0-9]{14}$"))
        return true;
    else
        return false;
}

function isDigit(c) {
    var strAllowed = "1234567890";
    return (strAllowed.indexOf(c) != -1);
}

function isNumberMasked(strNum) {
    if (strNum.indexOf("*") > -1)
        return true;
    else
        return false;
}

function isNumberValid(strNum) {
    var nCheck = 0;
    var nDigit = 0;
    var bEven = false;
    for (n = strNum.length - 1; n >= 0; n--) {
        var cDigit = strNum.charAt(n);
        if (isDigit(cDigit)) {
            var nDigit = parseInt(cDigit, 10);
            if (bEven) {
                if ((nDigit *= 2) > 9) nDigit -= 9;
            }
            nCheck += nDigit;
            bEven = !bEven;
        }
        else if (cDigit != ' ' && cDigit != '.' && cDigit != '-') return false;
    }
    return (nCheck % 10) == 0;
}

function load_customer() {
    var load = window.open('customer.html', '', 'scrollbars=yes,menubar=no,height=265,width=520,resizable=yes,toolbar=no,location=no,status=no');
}

function load_customer_cart() {
    var load = window.open('../customer.html', '', 'scrollbars=yes,menubar=no,height=265,width=520,resizable=yes,toolbar=no,location=no,status=no');
}

function load_cvv() {
    var load = window.open('cvv.html', '', 'scrollbars=yes,menubar=no,height=700,width=542,resizable=no,toolbar=no,location=no,status=no');
}

function load_guarantee() {
    var load = window.open('guarantee.html', '', 'scrollbars=yes,menubar=no,height=300,width=542,resizable=no,toolbar=no,location=no,status=no');
}

function load_privacy() {
    var load = window.open('privacy.html', '', 'scrollbars=yes,menubar=no,height=400,width=522,resizable=no,toolbar=no,location=no,status=no');
}

function load_terms() {
    var load = window.open('terms.html', '', 'scrollbars=yes,menubar=no,height=400,width=542,resizable=no,toolbar=no,location=no,status=no');
}

function load_guarantee_cart() {
    var load = window.open('../guarantee.html', '', 'scrollbars=yes,menubar=no,height=300,width=542,resizable=no,toolbar=no,location=no,status=no');
}

function load_privacy_cart() {
    var load = window.open('../privacy.html', '', 'scrollbars=yes,menubar=no,height=400,width=522,resizable=no,toolbar=no,location=no,status=no');
}

function load_terms_cart() {
    var load = window.open('../terms.html', '', 'scrollbars=yes,menubar=no,height=400,width=542,resizable=no,toolbar=no,location=no,status=no');
}

function replaceChecks() {

    //get all the input fields on the page 
    inputs = document.getElementsByTagName('input');

    //cycle trough the input fields 
    for (var i = 0; i < inputs.length; i++) {

        //check if the input is a checkbox 
        if (inputs[i].getAttribute('type') == 'checkbox' && !(inputs[i].getAttribute('id') == 'noreplace')) {

            //create a new image 
            var img = document.createElement('img');

            //check if the checkbox is checked 
            if (inputs[i].checked) {
                img.src = imgTrue;
            } else {
                img.src = imgFalse;
            }

            //set image ID and onclick action 
            img.id = 'checkImage' + i;
            //set image 
            img.onclick = new Function('checkChange(' + i + ')');
            //place image in front of the checkbox 
            inputs[i].parentNode.insertBefore(img, inputs[i]);

            //hide the checkbox 
            inputs[i].style.display = 'none';
        }
    }
}

function ReverseContentDisplay(d) {
    if (d.length < 1) { return; }
    if (document.getElementById(d).style.display == "none") { document.getElementById(d).style.display = "block"; }
    else { document.getElementById(d).style.display = "none"; }
}

function ShowContent(d) {
    if (d.length < 1) { return; }
    document.getElementById(d).style.display = "block";
}

function Update() {
    document.TheForm.updateconfirm.value = 'true';
    document.TheForm.submit();
}

function UpdateBilling() {
    if (document.getElementById("billingsame0").checked == true) {
        document.getElementById("BillingFirstName").value = document.getElementById("ShippingFirstName").value
        document.getElementById("BillingLastName").value = document.getElementById("ShippingLastName").value
        document.getElementById("BillingAddress1").value = document.getElementById("ShippingAddress1").value
        document.getElementById("BillingAddress2").value = document.getElementById("ShippingAddress2").value
        document.getElementById("BillingCity").value = document.getElementById("ShippingCity").value
        document.getElementById("BillingState").value = document.getElementById("ShippingState").value
        document.getElementById("BillingCountry").value = document.getElementById("ShippingCountry").value
        document.getElementById("BillingZip").value = document.getElementById("ShippingZip").value
        document.getElementById("BillingAreaCode").value = document.getElementById("ShippingAreaCode").value
        document.getElementById("BillingPrefix").value = document.getElementById("ShippingPrefix").value
        document.getElementById("BillingSuffix").value = document.getElementById("ShippingSuffix").value
    }

    if (getRadioCheckedValue(document.credit.elements['sku']) == 'DKW4214') {
        if (document.getElementById("ShippingCountry").value == 'United States') {
            document.credit.QTY_Product.value = '14_23_1';
        }

        else {
            document.credit.QTY_Product.value = '14_96_1';
        }            
        document.credit.firstupsell.value = 'payinfull';
    }
    else {
        if (document.getElementById("ShippingCountry").value == 'United States') {
            document.credit.QTY_Product.value = '15_24_1';
        }
        else if (document.getElementById("ShippingCountry").value == 'Canada') {
            document.credit.QTY_Product.value = '15_98_1';
        }
        else {
            document.credit.QTY_Product.value = '15_99_1';
        }
        document.credit.firstupsell.value = 'holiday';
    }
}

function ValidateHome() {
    document.getElementById("BillingFirstName").value = document.getElementById("ShippingFirstName").value
    document.getElementById("BillingLastName").value = document.getElementById("ShippingLastName").value
    document.getElementById("BillingAddress1").value = document.getElementById("ShippingAddress1").value
    document.getElementById("BillingAddress2").value = document.getElementById("ShippingAddress2").value
    document.getElementById("BillingCity").value = document.getElementById("ShippingCity").value
    document.getElementById("BillingState").value = document.getElementById("ShippingState").value
    document.getElementById("BillingZip").value = document.getElementById("ShippingZip").value
    document.getElementById("BillingCountry").value = document.getElementById("ShippingCountry").value
    document.getElementById("BillingAreaCode").value = document.getElementById("ShippingAreaCode").value
    document.getElementById("BillingPrefix").value = document.getElementById("ShippingPrefix").value
    document.getElementById("BillingSuffix").value = document.getElementById("ShippingSuffix").value
    
    ShippingFirstName = document.getElementById("ShippingFirstName");
    ShippingLastName = document.getElementById("ShippingLastName");
    Email = document.getElementById("EMail");
    ShippingAreaCode = document.getElementById("ShippingAreaCode");
    ShippingPrefix = document.getElementById("ShippingPrefix");
    ShippingSuffix = document.getElementById("ShippingSuffix");
    ShippingAddress1 = document.getElementById("ShippingAddress1");
    ShippingCity = document.getElementById("ShippingCity");
    ShippingState = document.getElementById("ShippingState");
    ShippingZip = document.getElementById("ShippingZip");
    ShippingCountry = document.getElementById("ShippingCountry");        

    errors = false;

    if (!ValidateInputText(ShippingFirstName)) errors = true;
    if (!ValidateInputText(ShippingLastName)) errors = true;
    if (!ValidateEmail(Email)) errors = true;
    if (!ValidateAreaCodeExchange(ShippingAreaCode)) errors = true;
    if (!ValidateAreaCodeExchange(ShippingPrefix)) errors = true;
    if (!ValidateExtension(ShippingSuffix)) errors = true;
    if (!ValidateAddress1(ShippingAddress1)) errors = true;
    if (!ValidateInputText(ShippingCity)) errors = true;
    if (!ValidateSelectText(ShippingState)) errors = true;
    if (!ValidateInputZip(ShippingZip)) errors = true;
    if (!ValidateSelectText(ShippingCountry)) errors = true;

    if (errors) {
        alert("Please correct the indicated fields.");
        return false;
    }
    else {        
        return true;
    }
}

function ValidateAddress1(myElement) {
    var OneDigit = /\d/;
    var OneAlpha = /[a-zA-Z]/;
    var FirstDigitNonZero = /^[^0-9]*[1-9]+.*$/;

    Address = myElement.value;

    if ((Address.replace(/\s/g, '').length < 3) || (!OneDigit.test(Address)) || (!OneAlpha.test(Address)) || (!FirstDigitNonZero.test(Address))) {
        myElement.className = "text_error";
        return false;
    }
    else {
        myElement.className = "text";
        return true;
    }
}

function ValidateAreaCodeExchange(myElement) {
    var AreaCodeExchangePattern = /^\d{3}$/;
    if (!AreaCodeExchangePattern.test(myElement.value)) {
        myElement.className = "text_error";
        return false;
    }
    else {
        myElement.className = "text";
        return true;
    }
}

function ValidateEmail(myElement) {
    var EmailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
    if (!EmailPattern.test(myElement.value)) {
        myElement.className = "text_error";
        return false;
    }
    else {
        myElement.className = "text";
        return true;
    }
}

function ValidateExtension(myElement) {
    var ExtensionPattern = /^\d{4}$/;
    if (!ExtensionPattern.test(myElement.value)) {
        myElement.className = "text_error";
        return false;
    }
    else {
        myElement.className = "text";
        return true;
    }
}

function ValidateInputText(myElement) {
    if (myElement.value.length == 0) {
        myElement.className = "text_error";
        return false;
    }
    else {
        myElement.className = "text";
        return true;
    }
}

function ValidateInputZip(myElement) {
    if (document.getElementById("ShippingCountry")) {
        if ((myElement.name == "ShippingZip") && (document.getElementById("ShippingCountry").value == 'Barbados')) {
            myElement.className = "text";
            myElement.value = "-";
            return true;
        }
    }
    if (document.getElementById("BillingCountry")) {
        if ((myElement.name == "BillingZip") && (document.getElementById("BillingCountry").value == 'Barbados')) {
            myElement.className = "text";
            myElement.value = "-";
            return true;
        }
    }
    if (document.getElementById("Country")) {
        if ((myElement.name == "BillingZip") && (document.getElementById("Country").value == 'Barbados')) {
            myElement.className = "text";
            myElement.value = "-";
            return true;
        }
    }
    if (myElement.value.length == 0) {
        myElement.className = "text_error";
        return false;
    }
    else {
        myElement.className = "text";
        return true;
    }
}

function ValidateSelectText(myElement) {
    if (myElement.value == 0) {
        myElement.className = "text_error";
        return false;
    }
    else {
        myElement.className = "text";
        return true;
    }
}

function ValidateCardCvv(myElement) {
    var CvvPattern = /^\d{3,4}$/;
    if (!CvvPattern.test(myElement.value)) {
        myElement.className = "text_error";
        return false;
    }
    else {
        myElement.className = "text";
        return true;
    }
}

function ValidateCardNumber(myElement) {
    if (!ccnumber_verify()) {
        myElement.className = "text_error";
        return false;
    }
    else {
        myElement.className = "text";
        return true;
    }
}

function ValidateConfirm() {
    ShippingFirstName = document.getElementById("ShippingFirstName");
    ShippingLastName = document.getElementById("ShippingLastName");
    Email = document.getElementById("EMail");
    ShippingAreaCode = document.getElementById("ShippingAreaCode");
    ShippingPrefix = document.getElementById("ShippingPrefix");
    ShippingSuffix = document.getElementById("ShippingSuffix");
    ShippingAddress1 = document.getElementById("ShippingAddress1");
    ShippingCity = document.getElementById("ShippingCity");
    ShippingState = document.getElementById("ShippingState");
    ShippingZip = document.getElementById("ShippingZip");
    ShippingCountry = document.getElementById("ShippingCountry");

    BillingFirstName = document.getElementById("BillingFirstName");
    BillingLastName = document.getElementById("BillingLastName");
    BillingAreaCode = document.getElementById("BillingAreaCode");
    BillingPrefix = document.getElementById("BillingPrefix");
    BillingSuffix = document.getElementById("BillingSuffix");
    BillingAddress1 = document.getElementById("BillingAddress1");
    BillingCity = document.getElementById("BillingCity");
    BillingState = document.getElementById("BillingState");
    BillingZip = document.getElementById("BillingZip");
    BillingCountry = document.getElementById("BillingCountry");

    CardType = document.getElementById("CardType");
    CardName = document.getElementById("CardName");
    CardNumber = document.getElementById("CardNumber");
    CardCvv = document.getElementById("CardCvv");
    ExpirationMonth = document.getElementById("ExpirationMonth");
    ExpirationYear = document.getElementById("ExpirationYear");

    errors = false;

    if (!ValidateInputText(ShippingFirstName)) errors = true;
    if (!ValidateInputText(ShippingLastName)) errors = true;
    if (!ValidateEmail(Email)) errors = true;
    if (!ValidateAreaCodeExchange(ShippingAreaCode)) errors = true;
    if (!ValidateAreaCodeExchange(ShippingPrefix)) errors = true;
    if (!ValidateExtension(ShippingSuffix)) errors = true;
    if (!ValidateAddress1(ShippingAddress1)) errors = true;
    if (!ValidateInputText(ShippingCity)) errors = true;
    if (!ValidateSelectText(ShippingState)) errors = true;
    if (!ValidateInputZip(ShippingZip)) errors = true;
    if (!ValidateSelectText(ShippingCountry)) errors = true;

    if (!ValidateInputText(BillingFirstName)) errors = true;
    if (!ValidateInputText(BillingLastName)) errors = true;
    if (!ValidateAreaCodeExchange(BillingAreaCode)) errors = true;
    if (!ValidateAreaCodeExchange(BillingPrefix)) errors = true;
    if (!ValidateExtension(BillingSuffix)) errors = true;
    if (!ValidateAddress1(BillingAddress1)) errors = true;
    if (!ValidateInputText(BillingCity)) errors = true;
    if (!ValidateSelectText(BillingState)) errors = true;
    if (!ValidateInputZip(BillingZip)) errors = true;
    if (!ValidateSelectText(BillingCountry)) errors = true;

    if (!ValidateSelectText(CardType)) errors = true;
    if (!ValidateInputText(CardName)) errors = true;
    if (!ValidateCardNumber(CardNumber)) errors = true;
    if (!ValidateCardCvv(CardCvv)) errors = true;
    if (!ValidateExpirationMonth(ExpirationMonth)) errors = true;
    if (!ValidateExpirationYear(ExpirationYear)) errors = true;

    if (errors) {
        alert("Please correct the indicated fields.");
        return false;
    }
    else {        
        return true;
    }
}

function ValidateExpirationMonth(myElement) {
    if (!expdatemonth_verify()) {
        myElement.className = "text_error";
        return false;
    }
    else {
        myElement.className = "text";
        return true;
    }
}

function ValidateExpirationYear(myElement) {
    if (!expdateyear_verify()) {
        myElement.className = "text_error";
        return false;
    }
    else {
        myElement.className = "text";
        return true;
    }
}

function ValidatePayment() {
    if (((getRadioCheckedValue(document.credit.elements['sku']) == 'DKW4214')) && (document.getElementById("ShippingCountry").value != "United States") && (document.getElementById("ShippingCountry").value != "Canada")) {
        alert("The $14.95 Trial Offer is only available for shipping to the U.S. and Canada.");
        return false;
    }

    UpdateBilling();

    ShippingFirstName = document.getElementById("ShippingFirstName");
    ShippingLastName = document.getElementById("ShippingLastName");
    Email = document.getElementById("EMail");
    ShippingAreaCode = document.getElementById("ShippingAreaCode");
    ShippingPrefix = document.getElementById("ShippingPrefix");
    ShippingSuffix = document.getElementById("ShippingSuffix");
    ShippingAddress1 = document.getElementById("ShippingAddress1");
    ShippingCity = document.getElementById("ShippingCity");
    ShippingState = document.getElementById("ShippingState");
    ShippingZip = document.getElementById("ShippingZip");
    ShippingCountry = document.getElementById("ShippingCountry");

    BillingFirstName = document.getElementById("BillingFirstName");
    BillingLastName = document.getElementById("BillingLastName");
    BillingAreaCode = document.getElementById("BillingAreaCode");
    BillingPrefix = document.getElementById("BillingPrefix");
    BillingSuffix = document.getElementById("BillingSuffix");
    BillingAddress1 = document.getElementById("BillingAddress1");
    BillingCity = document.getElementById("BillingCity");
    BillingState = document.getElementById("BillingState");
    BillingZip = document.getElementById("BillingZip");
    BillingCountry = document.getElementById("BillingCountry");

    CardType = document.getElementById("CardType");
    CardName = document.getElementById("CardName");
    CardNumber = document.getElementById("CardNumber");
    CardCvv = document.getElementById("CardCvv");
    ExpirationMonth = document.getElementById("ExpirationMonth");
    ExpirationYear = document.getElementById("ExpirationYear");    

    errors = false;

    if (!ValidateInputText(ShippingFirstName)) errors = true;
    if (!ValidateInputText(ShippingLastName)) errors = true;
    if (!ValidateEmail(Email)) errors = true;
    if (!ValidateAreaCodeExchange(ShippingAreaCode)) errors = true;
    if (!ValidateAreaCodeExchange(ShippingPrefix)) errors = true;
    if (!ValidateExtension(ShippingSuffix)) errors = true;
    if (!ValidateAddress1(ShippingAddress1)) errors = true;
    if (!ValidateInputText(ShippingCity)) errors = true;
    if (!ValidateSelectText(ShippingState)) errors = true;
    if (!ValidateInputZip(ShippingZip)) errors = true;
    if (!ValidateSelectText(ShippingCountry)) errors = true;

    if (!ValidateInputText(BillingFirstName)) errors = true;
    if (!ValidateInputText(BillingLastName)) errors = true;
    if (!ValidateAreaCodeExchange(BillingAreaCode)) errors = true;
    if (!ValidateAreaCodeExchange(BillingPrefix)) errors = true;
    if (!ValidateExtension(BillingSuffix)) errors = true;
    if (!ValidateAddress1(BillingAddress1)) errors = true;
    if (!ValidateInputText(BillingCity)) errors = true;
    if (!ValidateSelectText(BillingState)) errors = true;
    if (!ValidateInputZip(BillingZip)) errors = true;
    if (!ValidateSelectText(BillingCountry)) errors = true;
    
    if (!ValidateSelectText(CardType)) errors = true;
    if (!ValidateInputText(CardName)) errors = true;
    if (!ValidateCardNumber(CardNumber)) errors = true;
    if (!ValidateCardCvv(CardCvv)) errors = true;
    if (!ValidateExpirationMonth(ExpirationMonth)) errors = true;
    if (!ValidateExpirationYear(ExpirationYear)) errors = true;

    if (errors) {
        alert("Please correct the indicated fields.");
        return false;
    }
    else {        
        return true;
    }
}

function ValidateDefaultC() {

    if (document.getElementById("billingsame0").checked == true) {
        document.getElementById("BillingFirstName").value = document.getElementById("ShippingFirstName").value
        document.getElementById("BillingLastName").value = document.getElementById("ShippingLastName").value
        document.getElementById("BillingAddress1").value = document.getElementById("ShippingAddress1").value
        document.getElementById("BillingAddress2").value = document.getElementById("ShippingAddress2").value
        document.getElementById("BillingCity").value = document.getElementById("ShippingCity").value
        document.getElementById("BillingState").value = document.getElementById("ShippingState").value        
        document.getElementById("BillingZip").value = document.getElementById("ShippingZip").value
        document.getElementById("BillingAreaCode").value = document.getElementById("ShippingAreaCode").value
        document.getElementById("BillingPrefix").value = document.getElementById("ShippingPrefix").value
        document.getElementById("BillingSuffix").value = document.getElementById("ShippingSuffix").value
    }

    ShippingFirstName = document.getElementById("ShippingFirstName");
    ShippingLastName = document.getElementById("ShippingLastName");
    Email = document.getElementById("EMail");
    ShippingAreaCode = document.getElementById("ShippingAreaCode");
    ShippingPrefix = document.getElementById("ShippingPrefix");
    ShippingSuffix = document.getElementById("ShippingSuffix");
    ShippingAddress1 = document.getElementById("ShippingAddress1");
    ShippingCity = document.getElementById("ShippingCity");
    ShippingState = document.getElementById("ShippingState");
    ShippingZip = document.getElementById("ShippingZip");    

    BillingFirstName = document.getElementById("BillingFirstName");
    BillingLastName = document.getElementById("BillingLastName");
    BillingAreaCode = document.getElementById("BillingAreaCode");
    BillingPrefix = document.getElementById("BillingPrefix");
    BillingSuffix = document.getElementById("BillingSuffix");
    BillingAddress1 = document.getElementById("BillingAddress1");
    BillingCity = document.getElementById("BillingCity");
    BillingState = document.getElementById("BillingState");
    BillingZip = document.getElementById("BillingZip");    

    CardType = document.getElementById("CardType");
    CardName = document.getElementById("CardName");
    CardNumber = document.getElementById("CardNumber");
    CardCvv = document.getElementById("CardCvv");
    ExpirationMonth = document.getElementById("ExpirationMonth");
    ExpirationYear = document.getElementById("ExpirationYear");

    errors = false;

    if (!ValidateInputText(ShippingFirstName)) errors = true;
    if (!ValidateInputText(ShippingLastName)) errors = true;
    if (!ValidateEmail(Email)) errors = true;
    if (!ValidateAreaCodeExchange(ShippingAreaCode)) errors = true;
    if (!ValidateAreaCodeExchange(ShippingPrefix)) errors = true;
    if (!ValidateExtension(ShippingSuffix)) errors = true;
    if (!ValidateAddress1(ShippingAddress1)) errors = true;
    if (!ValidateInputText(ShippingCity)) errors = true;
    if (!ValidateSelectText(ShippingState)) errors = true;
    if (!ValidateInputZip(ShippingZip)) errors = true;

    if (!ValidateInputText(BillingFirstName)) errors = true;
    if (!ValidateInputText(BillingLastName)) errors = true;
    if (!ValidateAreaCodeExchange(BillingAreaCode)) errors = true;
    if (!ValidateAreaCodeExchange(BillingPrefix)) errors = true;
    if (!ValidateExtension(BillingSuffix)) errors = true;
    if (!ValidateAddress1(BillingAddress1)) errors = true;
    if (!ValidateInputText(BillingCity)) errors = true;
    if (!ValidateSelectText(BillingState)) errors = true;
    if (!ValidateInputZip(BillingZip)) errors = true;

    if (!ValidateSelectText(CardType)) errors = true;
    if (!ValidateInputText(CardName)) errors = true;
    if (!ValidateCardNumber(CardNumber)) errors = true;
    if (!ValidateCardCvv(CardCvv)) errors = true;
    if (!ValidateExpirationMonth(ExpirationMonth)) errors = true;
    if (!ValidateExpirationYear(ExpirationYear)) errors = true;

    if (errors) {
        alert("Please correct the indicated fields.");
        return false;
    }
    else {
        return true;
    }
}
