function validateDate(sVal) {
    // our date regular expression (http://www.regexlib.com)
    var regex = /(((0[13578]|10|12)([-.\/])(0[1-9]|[12][0-9]|3[01])([-.\/])(\d{4}))|((0[469]|11)([-.\/])([0][1-9]|[12][0-9]|30)([-.\/])(\d{4}))|((2)([-.\/])(0[1-9]|1[0-9]|2[0-8])([-.\/])(\d{4}))|((2)(\.|-|\/)(29)([-.\/])([02468][048]00))|((2)([-.\/])(29)([-.\/])([13579][26]00))|((2)([-.\/])(29)([-.\/])([0-9][0-9][0][48]))|((2)([-.\/])(29)([-.\/])([0-9][0-9][2468][048]))|((2)([-.\/])(29)([-.\/])([0-9][0-9][13579][26])))/;

    // do the comparison, if we have a match write thank you or else the date is invalid
    if (regex.test(sVal)) {
        return true
    } else {
        return false;
    }
}

function validateEmail(sVal) {
    // our email regular expression (http://www.regexlib.com)
    var regex = /^[a-zA-Z0-9._+-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;

    // do the comparison, if we have a match write thank you or else the email is invalid
    if (regex.test(sVal)) {
        return true;
    } else {
        return false;
    }
}

function validatePhone(sVal) {
    // Remove anything that isn't a number, then check if it has
    // 10 digits.
    var newPhone = "";
    var stringchars = sVal.split("");
    for (var charIndex in stringchars) {
        if (!isNaN(parseInt(stringchars[charIndex]))) {
            newPhone = newPhone + stringchars[charIndex];
        }
    }
    if (newPhone.length == 10 || (newPhone.length == 11 && newPhone[0] == '1')) {
        return true;
    } else {
        return false;
    }
}

function validateZip(sVal) {
    //
    // Returns false if invalid, otherwise returns normalized postal code
    //
    // US normalized value is 12345 or 12345-9999
    // CA normalized value is A1A-2B2

    var regex = /^(\d{5})(\-|\s*)?(\d{4})?$/;
    var regex_can = /^([a-z]\d[a-z])\s*(\d[a-z]\d)$/i;

    if (regex.test(sVal)) {
        var r1 = sVal.match(regex);
        var new_val = r1[1];
        if (r1[3]) {
            new_val = new_val + "-" + r1[3];
        }
        return new_val;
    } else if (regex_can.test(sVal)) {
        // Return a value with all caps for letters and exactly one space
        // between groups
        var r = sVal.match(regex_can);
        return (r[1] + " " + r[2]).toUpperCase();
    } else {
        return false;
    }
}

function validatePassword(sVal) {
    //Description: The password's first character must be a letter, it must contain at least 4 characters
    //and no more than 15 characters and no characters other than letters, numbers and the underscore may be used
    //Matches: 	[abcd], [aBc45DSD_sdf], [password] (http://www.regexlib.com)
    var regex = /^[a-zA-Z]\w{3,14}$/;

    // do the comparison, if we have a match write thank you or else the email is invalid
    if (regex.test(sVal)) {
        return true;
    } else {
        return false;
    }
}

function validateName(sVal) {
    //This is the simplest RegEx for validating someone's name. The name can contain only alphabets(in either case) & 
    //should be of minimum length 4 & maximum length 32. Only white spaces are allowed apart from alphabets.
    //Matches: 	[some body], [hey there], [hello] (http://www.regexlib.com)
    var regex = /^([a-zA-z\s]{4,32})$/;

    // do the comparison, if we have a match write thank you or else the email is invalid
    if (regex.test(sVal)) {
        return true;
    } else {
        return false;
    }
}

function validateNumeric(sVal) {
    //Input for Numeric values. Handles negatives, and comma formatted values. Also handles a single decimal point
    //Matches: 	[5,000], [-5,000], [100.044] (http://www.regexlib.com)
    var regex = /^(\d|-)?(\d|,)*\.?\d*$/;

    // do the comparison, if we have a match write thank you or else the email is invalid
    if (regex.test(sVal)) {
        return true;
    } else {
        return false;
    }
}

// first Client side validation using JavaScript...
// you have to put to controls one is drop down list (for different credit 
//cards names)and other is textbox (for card number).
//just pass two parameter to this function one is id of dropdownlist and 
//textbox.
function ValidateCC(CCType, CCNum) {
    var cctype = document.getElementById(CCType);
    var ccnum = document.getElementById(CCNum);
    //alert(cctype);	
    var validCCNum = false;
    var validCC = false;

    if (ccnum.value == "") {
        return false;
    }

    validCC = isValidCreditCard(cctype.options[cctype.selectedIndex].value, ccnum.value);
    if (validCC) {
        return true;
    }

    return false;
}

function ValidateCVV(CCType, CVV) {
    var cctype = document.getElementById(CCType);
    var cvv = document.getElementById(CVV);

    var cctypevalue = cctype.options[cctype.selectedIndex].value;
    //alert(cctypevalue);
    if (cctypevalue == "3" || cctypevalue == 'American Express') {
        return cvv.value.length == 4;
    } else {
        return cvv.value.length == 3;
    }
}

// this function is calling another function isValidCreditCard 
//for number validation and it is here...
function isValidCreditCard(type, ccnum) {
    if (type == "2")
        var re = /^[4]([0-9]{15}$|[0-9]{12}$)/;
    else if (type == "1")
        var re = /^[5][1-5][0-9]{14}$/;
    else if (type == "4")
        var re = /^6011-?\d{4}-?\d{4}-?\d{4}$/;
    else if (type == "Diners Club")
        var re = /(^30[0-5][0-9]{11}$)|(^(36|38)[0-9]{12}$)/;
    else if (type == "3")
        var re = /^[34|37][0-9]{14}$/;
    else if (type == "enRoute")
        var re = /^(2014|2149)[0-9]{11}$/;
    else if (type == "JCB")
        var re = /(^3[0-9]{15}$)|(^(2131|1800)[0-9]{11}$)/;

    if (!re.test(ccnum))
        return false;

    ccnum = ccnum.split("-").join("");

    var checksum = 0;
    for (var i = (2 - (ccnum.length % 2)); i <= ccnum.length; i += 2) {
        checksum += parseInt(ccnum.charAt(i - 1));
    }

    for (var i = (ccnum.length % 2) + 1; i < ccnum.length; i += 2) {
        var digit = parseInt(ccnum.charAt(i - 1)) * 2;
        if (digit < 10) {
            checksum += digit;
        } else {
            checksum += (digit - 9);
        }
    }
    if ((checksum % 10) == 0) {
        return true;
    } else {
        return false;
    }
}

function getBetween(str, start, end) {
    var iStart, iEnd;
    iStart = str.indexOf(start);
    if (iStart == -1) {
        return '';
    } else {
        iStart += start.length;
        iEnd = str.indexOf(end, iStart);
        if (iEnd == -1) { iEnd = str.length; }
        return str.substr(iStart, iEnd - iStart);
    }
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var firstName_length = 50;
var lastName_length = 50;
var streetAddress1_length = 100;
var streetAddress2_length = 50;
var city_length = 50;
var postalCode_length = 5;
var phoneNumber_length = 15;
var emailAddress_length = 50;

var creditCardName_length = 50
var creditCardType_length = 50
var creditCardNumber_length = 20
var creditCardCvv_length = 4
var creditCardExpiration_length = 5

function clearText() {
    document.formname.fieldname.value = filterNum(document.formname.fieldname.value)

    function filterNum(str) {
        re = /\$|,|@|#|~|`|\%|\*|\^|\&|\(|\)|\+|\=|\[|\-|\_|\]|\[|\}|\{|\;|\:|\'|\"|\<|\>|\?|\||\\|\!|\$|\./g;
        // remove special characters like "$" and "," etc...
        return str.replace(re, "");
    }
}

function isValidSpecialChar(text) {
    //var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";

    // Allow - , . ' #
    /*
    var iChars = "!@$%^&*()+=[]\\\;/{}|\":<>?";
    for (var i = 0; i < text.length; i++)
    {
    if (iChars.indexOf(text.charAt(i)) != -1)
    {
    return false;
    }
    }
    */

    return true;
}

function isValidFirstName(text) {

    if (text == null || text == "" || text.length > firstName_length || !isValidSpecialChar(text)) {
        return false;
    }

    return true;
}

function isValidLastName(text) {

    if (text == null || text == "" || text.length > lastName_length || !isValidSpecialChar(text)) {
        return false;
    }

    return true;
}

function isValidStreetAddress1(text) {

    if (text == null || text == "" || text.length > streetAddress1_length || !isValidSpecialChar(text)) {
        return false;
    }

    return true;
}

function isValidStreetAddress2(text) {

    if (text == null || text.length > streetAddress2_length || !isValidSpecialChar(text)) {
        return false;
    }

    return true;
}

function isValidCity(text) {

    if (text == null || text == "" || text.length > city_length || !isValidSpecialChar(text)) {
        return false;
    }

    return true;
}

function isValidPostalCode(text) {

    if (text == null || text == "" || text.length <=4 || !isValidSpecialChar(text)) {
        return false;
    }

    return true;
}

function isValidPhoneNumber(text) {

    if (text == null || text == "") {
        return false;
    }

    return true;
}

function isValidEmailAddress(text) {

    if (text == "") return true;

    if (text == null || text != "" || text.length > emailAddress_length) {
        if (!validateEmail(text)) return false;
    }

    return true;
}

function isValidNameOnCard(text) {

    if (text == null || text == "" || text == " " || text.length > creditCardName_length || !isValidSpecialChar(text)) {
        return false;
    }

    return true;
}

function isValidCreditCardNumber(text) {

    if (text == null || text == "" || text.length > creditCardNumber_length || !isValidSpecialChar(text)) {
        return false;
    }

    return true;
}

function isValidCVV(text) {

    if (text == null || text == "" || text.length > creditCardCvv_length || !isValidSpecialChar(text)) {
        return false;
    }

    return true;
}

function removeErrorChar(text) {
    return text.replace(/'/gi, "`");
}


//var textFieldBorderDefaultColor = "#19beea";
var textFieldBorderDefaultColor = "";
var textFieldBorderErrorColor = "white";

var textFieldBackDefaultColor = "white";
var textFieldBackErrorColor = "pink";

var requiredDefaultColor = "pink";
var requiredErrorColor = "red";

// Billing Information
/***************************************************************************************************************/
var firstNameField;
var firstNameValue;
var firstNameRequired;

var lastNameField;
var lastNameValue;
var lastNameRequired;

var streetAddress1Field;
var streetAddress1Value;
var streetAddress1Required;

var streetAddress2Field;
var streetAddress2Value;

var cityField;
var cityValue;
var cityRequired;

var stateField;

var postalCodeField;
var postalCodeValue;
var postalCodeRequired;

var countryField;

var phoneNumberField1;
var phoneNumberField2;
var phoneNumberField3;

var phoneNumberValue;
var phoneNumberRequired;

var emailField;
var emailValue;
var emailRequired;
/***************************************************************************************************************/


// Shipping Information
/***************************************************************************************************************/
var shipping_firstNameField;
var shipping_firstNameValue;
var shipping_firstNameRequired;

var shipping_lastNameField;
var shipping_lastNameValue;
var shipping_lastNameRequired;

var shipping_streetAddress1Field;
var shipping_streetAddress1Value;
var shipping_streetAddress1Required;

var shipping_streetAddress2Field;
var shipping_streetAddress2Value;

var shipping_cityField;
var shipping_cityValue;
var shipping_cityRequired;

var shipping_stateField;

var shipping_postalCodeField;
var shipping_postalCodeValue;
var shipping_postalCodeRequired;

var shipping_countryField;

var shipping_phoneNumberField1;
var shipping_phoneNumberField2;
var shipping_phoneNumberField3;

var shipping_phoneNumberValue;
var shipping_phoneNumberRequired;

var shipping_emailField;
var shipping_emailValue;
var shipping_emailRequired;
/***************************************************************************************************************/


// Credit Card Information
/***************************************************************************************************************/
var CreditCardNameField;
var CreditCardNameFieldValue;
var CreditCardNameRequired;

var CreditCardTypeField;
var CreditCardTypeFieldRequired;

var CreditCardNumberField;
var CreditCardNumberFieldValue;
var CreditCardNumberFieldRequired;

var CreditCardCVVField;
var CreditCardCVVFieldValue;
var CreditCardCVVFieldRequired;

var CreditCardExpirationMonthField;
var CreditCardExpirationYearField;
var CreditCardExpirationFieldRequired;
/***************************************************************************************************************/

function initBillInfo() {
   // alert("first name");
    var theForm = document.frmReg;


    firstNameField = theForm.firstname;
    theForm.firstname.value = removeErrorChar(theForm.firstname.value);
    firstNameValue = theForm.firstname.value;
    lastNameField = theForm.lastname;
    theForm.lastname.value = removeErrorChar(theForm.lastname.value);
    lastNameValue = theForm.lastname.value;

    streetAddress1Field = theForm.streetaddress1;
    theForm.streetaddress1.value = removeErrorChar(theForm.streetaddress1.value);
    streetAddress1Value = theForm.streetaddress1.value;

    streetAddress2Field = theForm.streetaddress2;
    theForm.streetaddress2.value = removeErrorChar(theForm.streetaddress2.value);
    streetAddress2Value = theForm.streetaddress2.value;

    cityField = theForm.city;
    theForm.city.value = removeErrorChar(theForm.city.value);
    cityValue = theForm.city.value;

    stateField = theForm.state;

    postalCodeField = theForm.postalcode;
    theForm.postalcode.value = removeErrorChar(theForm.postalcode.value);
    postalCodeValue = theForm.postalcode.value;

    countryField = theForm.country;

    phoneNumberField = theForm.phone;
    phoneNumberField.value = removeErrorChar(phoneNumberField.value);
	/*
    phoneNumberField2 = theForm.phone2;
    phoneNumberField2.value = removeErrorChar(phoneNumberField2.value);
    phoneNumberField3 = theForm.phone3;
    phoneNumberField3.value = removeErrorChar(phoneNumberField3.value);
*/
    emailField = theForm.email;
    theForm.email.value = removeErrorChar(theForm.email.value);
    emailValue = theForm.email.value;

    firstNameField.style.borderColor = textFieldBorderDefaultColor;
    firstNameField.style.backgroundColor = textFieldBackDefaultColor;

    lastNameField.style.borderColor = textFieldBorderDefaultColor;
    lastNameField.style.backgroundColor = textFieldBackDefaultColor;

    streetAddress1Field.style.borderColor = textFieldBorderDefaultColor;
    streetAddress1Field.style.backgroundColor = textFieldBackDefaultColor;

    streetAddress2Field.style.borderColor = textFieldBorderDefaultColor;
    streetAddress2Field.style.backgroundColor = textFieldBackDefaultColor;

    cityField.style.borderColor = textFieldBorderDefaultColor;
    cityField.style.backgroundColor = textFieldBackDefaultColor;

    postalCodeField.style.borderColor = textFieldBorderDefaultColor;
    postalCodeField.style.backgroundColor = textFieldBackDefaultColor;

    emailField.style.borderColor = textFieldBorderDefaultColor;
    emailField.style.backgroundColor = textFieldBackDefaultColor;

    stateField.style.borderColor = textFieldBorderDefaultColor;
    countryField.style.borderColor = textFieldBorderDefaultColor;

    phoneNumberField.style.borderColor = textFieldBorderDefaultColor;
    phoneNumberField.style.backgroundColor = textFieldBackDefaultColor;
/*
    phoneNumberField2.style.borderColor = textFieldBorderDefaultColor;
    phoneNumberField2.style.backgroundColor = textFieldBackDefaultColor;

    phoneNumberField3.style.borderColor = textFieldBorderDefaultColor;
    phoneNumberField3.style.backgroundColor = textFieldBackDefaultColor;
	*/
}

function initShipInfo() {
    var theForm = document.frmReg;

    shipping_firstNameField = theForm.shipping_firstname;
    theForm.shipping_firstname.value = removeErrorChar(theForm.shipping_firstname.value);
    shipping_firstNameValue = theForm.shipping_firstname.value;

    shipping_lastNameField = theForm.shipping_lastname;
    theForm.shipping_lastname.value = removeErrorChar(theForm.shipping_lastname.value);
    shipping_lastNameValue = theForm.shipping_lastname.value;

    shipping_streetAddress1Field = theForm.shipping_streetaddress1;
    theForm.shipping_streetaddress1.value = removeErrorChar(theForm.shipping_streetaddress1.value);
    shipping_streetAddress1Value = theForm.shipping_streetaddress1.value;

    shipping_streetAddress2Field = theForm.shipping_streetaddress2;
    theForm.shipping_streetaddress2.value = removeErrorChar(theForm.shipping_streetaddress2.value);
    shipping_streetAddress2Value = theForm.shipping_streetaddress2.value;

    shipping_cityField = theForm.shipping_city;
    theForm.shipping_city.value = removeErrorChar(theForm.shipping_city.value);
    shipping_cityValue = theForm.shipping_city.value;

    shipping_stateField = theForm.shipping_state;

    shipping_postalCodeField = theForm.shipping_postalcode;
    theForm.shipping_postalcode.value = removeErrorChar(theForm.shipping_postalcode.value);
    shipping_postalCodeValue = theForm.shipping_postalcode.value;
    shipping_countryField = theForm.shipping_country;

    shipping_phoneNumberField1 = theForm.shipping_phone1;
    shipping_phoneNumberField1.value = removeErrorChar(shipping_phoneNumberField1.value);
    shipping_phoneNumberField2 = theForm.shipping_phone2;
    shipping_phoneNumberField2.value = removeErrorChar(shipping_phoneNumberField2.value);
    shipping_phoneNumberField3 = theForm.shipping_phone3;
    shipping_phoneNumberField3.value = removeErrorChar(shipping_phoneNumberField3.value);
        
    shipping_emailField = theForm.shipping_email;
    theForm.shipping_email.value = removeErrorChar(theForm.shipping_email.value);
    shipping_emailValue = theForm.shipping_email.value;

    shipping_firstNameField.style.borderColor = textFieldBorderDefaultColor;
    shipping_firstNameField.style.backgroundColor = textFieldBackDefaultColor;

    shipping_lastNameField.style.borderColor = textFieldBorderDefaultColor;
    shipping_lastNameField.style.backgroundColor = textFieldBackDefaultColor;

    shipping_streetAddress1Field.style.borderColor = textFieldBorderDefaultColor;
    shipping_streetAddress1Field.style.backgroundColor = textFieldBackDefaultColor;

    shipping_streetAddress2Field.style.borderColor = textFieldBorderDefaultColor;
    shipping_streetAddress2Field.style.backgroundColor = textFieldBackDefaultColor;

    shipping_cityField.style.borderColor = textFieldBorderDefaultColor;
    shipping_cityField.style.backgroundColor = textFieldBackDefaultColor;

    shipping_postalCodeField.style.borderColor = textFieldBorderDefaultColor;
    shipping_postalCodeField.style.backgroundColor = textFieldBackDefaultColor;

    shipping_emailField.style.borderColor = textFieldBorderDefaultColor;
    shipping_emailField.style.backgroundColor = textFieldBackDefaultColor;

    stateField.style.borderColor = textFieldBorderDefaultColor;
    countryField.style.borderColor = textFieldBorderDefaultColor;
    shipping_stateField.style.borderColor = textFieldBorderDefaultColor;
    shipping_countryField.style.borderColor = textFieldBorderDefaultColor;

    shipping_phoneNumberField1.style.borderColor = textFieldBorderDefaultColor;
    shipping_phoneNumberField1.style.backgroundColor = textFieldBackDefaultColor;

    shipping_phoneNumberField2.style.borderColor = textFieldBorderDefaultColor;
    shipping_phoneNumberField2.style.backgroundColor = textFieldBackDefaultColor;

    shipping_phoneNumberField3.style.borderColor = textFieldBorderDefaultColor;
    shipping_phoneNumberField3.style.backgroundColor = textFieldBackDefaultColor;
}

function initCardInfo() {
    var theForm = document.frmReg;

    CreditCardNameField = theForm.CreditCardName;
    theForm.CreditCardName.value = removeErrorChar(theForm.CreditCardName.value);
    CreditCardNameFieldValue = CreditCardNameField.value;

    CreditCardTypeField = theForm.CreditCardType;

    CreditCardNumberField = theForm.CreditCardNumber;
    theForm.CreditCardNumber.value = removeErrorChar(theForm.CreditCardNumber.value);
    CreditCardNumberFieldValue = CreditCardNumberField.value;

    CreditCardCVVField = theForm.CreditCardCVV;
    theForm.CreditCardCVV.value = removeErrorChar(theForm.CreditCardCVV.value);
    CreditCardCVVFieldValue = CreditCardCVVField.value;

    CreditCardExpirationMonthField = theForm.CreditCardExpirationMonth;
    CreditCardExpirationYearField = theForm.CreditCardExpirationYear;

    CreditCardNameField.style.borderColor = textFieldBorderDefaultColor;
    CreditCardNameField.style.backgroundColor = textFieldBackDefaultColor;

    CreditCardNumberField.style.borderColor = textFieldBorderDefaultColor;
    CreditCardNumberField.style.backgroundColor = textFieldBackDefaultColor;

    CreditCardCVVField.style.borderColor = textFieldBorderDefaultColor;
    CreditCardCVVField.style.backgroundColor = textFieldBackDefaultColor;

    CreditCardTypeField.style.borderColor = textFieldBorderDefaultColor;
}

function checkBillInfo() {
    // First Name
    if (isValidFirstName(firstNameValue) == false) {
        firstNameField.style.borderColor = textFieldBorderErrorColor;
        firstNameField.style.backgroundColor = textFieldBackErrorColor;
        alert("Please enter your first name.");
        firstNameField.focus();
        return false;
    }

    // Last Name
    if (isValidLastName(lastNameValue) == false) {
        lastNameField.style.borderColor = textFieldBorderErrorColor;
        lastNameField.style.backgroundColor = textFieldBackErrorColor;
        alert("Please enter your last name.");
        lastNameField.focus();
        return false;
    }

    // Street Address 1
    if (isValidStreetAddress1(streetAddress1Value) == false) {
        streetAddress1Field.style.borderColor = textFieldBorderErrorColor;
        streetAddress1Field.style.backgroundColor = textFieldBackErrorColor;
        alert("A valid address is required.");
        streetAddress1Field.focus();
        return false;
    }

    // Street Address 2
    if (isValidStreetAddress2(streetAddress2Value) == false) {
        streetAddress2Field.style.borderColor = textFieldBorderErrorColor;
        streetAddress2Field.style.backgroundColor = textFieldBackErrorColor;
        streetAddress2Field.focus();
        return false;
    }
    
    // Postal Code
    if (isValidPostalCode(postalCodeValue) == false) {
        postalCodeField.style.borderColor = textFieldBorderErrorColor;
        postalCodeField.style.backgroundColor = textFieldBackErrorColor;
        alert("A zip code is required.");
        postalCodeField.focus();
        return false;
    }
    
    // City
    if (isValidCity(cityValue) == false) {
        cityField.style.borderColor = textFieldBorderErrorColor;
        cityField.style.backgroundColor = textFieldBackErrorColor;
        alert("A city is required.");
        cityField.focus();
        return false;
    }

    // State
    var sVal = stateField.options[stateField.selectedIndex].value;
    if (sVal == "") {
        stateField.style.borderColor = textFieldBorderErrorColor;
        alert("A State is required.");
        stateField.focus();
        return false;
    }

    // Country
    var cVal = countryField.options[countryField.selectedIndex].value;
    if (cVal == "") {
        countryField.style.borderColor = textFieldBorderErrorColor;
        alert("A Country is required.");
        countryField.focus();
        return false;
    }

    // Phone Number1
    if (isValidPhoneNumber(phoneNumberField1.value) == false) {
        phoneNumberField1.style.borderColor = textFieldBorderErrorColor;
        phoneNumberField1.style.backgroundColor = textFieldBackErrorColor;
        alert("A Phone Number is required.");
        phoneNumberField1.focus();
        return false;
    }

    // Phone Number2
    if (isValidPhoneNumber(phoneNumberField2.value) == false) {
        phoneNumberField2.style.borderColor = textFieldBorderErrorColor;
        phoneNumberField2.style.backgroundColor = textFieldBackErrorColor;
        alert("A Phone Number is required.");
        phoneNumberField2.focus();
        return false;
    }
    
    // Phone Number3
    if (isValidPhoneNumber(phoneNumberField3.value) == false) {
        phoneNumberField3.style.borderColor = textFieldBorderErrorColor;
        phoneNumberField3.style.backgroundColor = textFieldBackErrorColor;
        alert("A Phone Number is required.");
        phoneNumberField3.focus();
        return false;
    }

    // Email Address	
    if (isValidEmailAddress(emailValue) == false) {
        emailField.style.borderColor = textFieldBorderErrorColor;
        emailField.style.backgroundColor = textFieldBackErrorColor;
        emailField.focus();
        return false;
    }

    return true;
}

function checkShipInfo() {
    // Shipping First Name
    if (isValidFirstName(shipping_firstNameValue) == false) {
        shipping_firstNameField.style.borderColor = textFieldBorderErrorColor;
        shipping_firstNameField.style.backgroundColor = textFieldBackErrorColor;
        alert("Please enter your first name.");
        shipping_firstNameField.focus();
        return false;
    }

    // Shipping Last Name
    if (isValidLastName(shipping_lastNameValue) == false) {
        shipping_lastNameField.style.borderColor = textFieldBorderErrorColor;
        shipping_lastNameField.style.backgroundColor = textFieldBackErrorColor;
        alert("Please enter your last name.");
        shipping_lastNameField.focus();
        return false;
    }

    // Shipping Street Address 1
    if (isValidStreetAddress1(shipping_streetAddress1Value) == false) {
        shipping_streetAddress1Field.style.borderColor = textFieldBorderErrorColor;
        shipping_streetAddress1Field.style.backgroundColor = textFieldBackErrorColor;
        alert("A Address is required.");
        shipping_streetAddress1Field.focus();
        return false;
    }

    // Shipping Street Address 2
    if (isValidStreetAddress2(shipping_streetAddress2Value) == false) {
        shipping_streetAddress2Field.style.borderColor = textFieldBorderErrorColor;
        shipping_streetAddress2Field.style.backgroundColor = textFieldBackErrorColor;
        shipping_streetAddress2Field.focus();
        return false;
    }

    // Shipping Postal Code
    if (isValidPostalCode(shipping_postalCodeValue) == false) {
        shipping_postalCodeField.style.borderColor = textFieldBorderErrorColor;
        shipping_postalCodeField.style.backgroundColor = textFieldBackErrorColor;
        alert("A zip code is required.");
        shipping_postalCodeField.focus();
        return false;
    }
    
    // Shipping City
    if (isValidCity(shipping_cityValue) == false) {
        shipping_cityField.style.borderColor = textFieldBorderErrorColor;
        shipping_cityField.style.backgroundColor = textFieldBackErrorColor;
        alert("A city is required.");
        shipping_cityField.focus();
        return false;
    }

    // Shipping State
    var sVal = shipping_stateField.options[shipping_stateField.selectedIndex].value;
    if (sVal == "") {
        shipping_stateField.style.borderColor = textFieldBorderErrorColor;
        alert("A State is required.");
        shipping_stateField.focus();
        return false;
    }

    // Shipping Country
    var cVal = shipping_countryField.options[shipping_countryField.selectedIndex].value;
    if (cVal == "") {
        shipping_countryField.style.borderColor = textFieldBorderErrorColor;
        alert("A country is required.");
        shipping_countryField.focus();
        return false;
    }

    // Shipping Phone Number1
    if (isValidPhoneNumber(shipping_phoneNumberField1.value) == false) {
        shipping_phoneNumberField1.style.borderColor = textFieldBorderErrorColor;
        shipping_phoneNumberField1.style.backgroundColor = textFieldBackErrorColor;
        alert("A Phone Number is required.");
        shipping_phoneNumberField1.focus();
        return false;
    }

    // Shipping Phone Number2
    if (isValidPhoneNumber(shipping_phoneNumberField2.value) == false) {
        shipping_phoneNumberField2.style.borderColor = textFieldBorderErrorColor;
        shipping_phoneNumberField2.style.backgroundColor = textFieldBackErrorColor;
        alert("A Phone Number is required.");
        shipping_phoneNumberField2.focus();
        return false;
    }

    // Shipping Phone Number3
    if (isValidPhoneNumber(shipping_phoneNumberField3.value) == false) {
        shipping_phoneNumberField3.style.borderColor = textFieldBorderErrorColor;
        shipping_phoneNumberField3.style.backgroundColor = textFieldBackErrorColor;
        alert("A Phone Number is required.");
        shipping_phoneNumberField3.focus();
        return false;
    }

    
    // Shipping Email Address	
    if (isValidEmailAddress(shipping_emailValue) == false) {
        shipping_emailField.style.borderColor = textFieldBorderErrorColor;
        shipping_emailField.style.backgroundColor = textFieldBackErrorColor;
        shipping_emailField.focus();
        return false;
    }

    return true;
}

function checkCardInfo() {
    // Name On Card
    if (isValidNameOnCard(CreditCardNameFieldValue) == false) {
        CreditCardNameField.style.borderColor = textFieldBorderErrorColor;
        CreditCardNameField.style.backgroundColor = textFieldBackErrorColor;
        alert("The Credit Card Name you have entered is invalid.");
        CreditCardNameField.focus();
        return false;
    }

    // Credit Card Type
    var CreditCardTypeValue = CreditCardTypeField.options[CreditCardTypeField.selectedIndex].value;
    if (CreditCardTypeValue == "") {
        CreditCardTypeField.style.borderColor = textFieldBorderErrorColor;
        alert("The credit card type is invalid.");
        CreditCardTypeField.focus();
        return false;
    }

    // Credit Card Number
    if (isValidCreditCardNumber(CreditCardNumberFieldValue) == false) {
        CreditCardNumberField.style.borderColor = textFieldBorderErrorColor;
        CreditCardNumberField.style.backgroundColor = textFieldBackErrorColor;
        alert("The Credit Card Number you have entered is invalid.");
        CreditCardNumberField.focus();
        return false;
    }

    var CreditCardTypeText;
    switch (CreditCardTypeValue) {
        case "MC":
            CreditCardTypeText = "MasterCard";
            break
        case "VI":
            CreditCardTypeText = "Visa";
            break
        case "AE":
            CreditCardTypeText = "AmEx";
            break
        case "DI":
            CreditCardTypeText = "Discover";
            break
    }

    // CVV
    if (isValidCVV(CreditCardCVVFieldValue) == false) {
        //if (CreditCardCVVFieldValue == "") CreditCardCVVFieldRequired.style.color= requiredErrorColor;

        CreditCardCVVField.style.borderColor = textFieldBorderErrorColor;
        CreditCardCVVField.style.backgroundColor = textFieldBackErrorColor;
        alert("The CVV number you have entered is invalid.");
        CreditCardCVVField.focus();
        return false;
    }

    // Expiration Month
    var eVal = CreditCardExpirationMonthField.options[CreditCardExpirationMonthField.selectedIndex].value;
    if (eVal == "") {
        CreditCardExpirationMonthField.style.borderColor = textFieldBorderErrorColor;
        alert("The expiration date you have entered is not valid.");
        CreditCardExpirationMonthField.focus();
        return false;
    }

    // Expiration Year
    var iVal = CreditCardExpirationYearField.options[CreditCardExpirationYearField.selectedIndex].value;
    if (iVal == "") {
        CreditCardExpirationYearField.style.borderColor = textFieldBorderErrorColor;
        alert("The expiration date you have entered is not valid.");
        CreditCardExpirationYearField.focus();
        return false;
    }

    return true;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



