var fields = new Array();
fields['firstName']             = new Array('First Name',                              true);
fields['lastName']              = new Array('Last Name',                               true);
fields['contactNumber']         = new Array('Preferred Contact Number',                true);
fields['email']                 = new Array('Email Addres',                            true);
fields['emailConfirmation']     = new Array('Confirm Email Address',                   true);
fields['password']              = new Array('Password',                                true);
fields['passwordConfirmation']  = new Array('Confirm Password',                        true);
fields['contactNumber']         = new Array('Contact Number',                          true);
fields['billingAddressLine1']   = new Array('Billing Address Line 1',                  true);
fields['billingCity']           = new Array('Billing Address City',                    true);
fields['billingCounty']         = new Array('Billing Address County / Region / State', true);
fields['billingPostCode']       = new Array('Billing Addres Zip or Postal Code',       true);

var formLoaded = false;

function setDeliveryCheck() {
    if ($('differentDeliveryAddress').value == 'yes') {
        fields['deliveryAddressLine1']  = new Array('Delivery Address Line 1',                  true);
        fields['deliveryCity']          = new Array('Delivery Address City',                    true);
        fields['deliveryCounty']        = new Array('Delivery Address County / Region / State', true);
        fields['deliveryPostCode']      = new Array('Delivery Address Zip or Postal Code',      true);
        return;
    }
    fields['deliveryAddressLine1']  = new Array('Delivery Address Line 1',                  false);
    fields['deliveryCity']          = new Array('Delivery Address City',                    false);
    fields['deliveryCounty']        = new Array('Delivery Address County / Region / State', false);
    fields['deliveryPostCode']      = new Array('Delivery Address Zip or Postal Code',      false);
}
function checkRegister(theForm) {
    disableFrontendButtons();
    /*setDeliveryCheck();
    for (i in fields) {
        if (i != 'all' && theForm[i] && fields[i][0] != undefined) {
            if (theForm[i].value == fields[i][0] || theForm[i].value == '' && fields[i][1]) {
                alert('Enter ' + fields[i][0] + ', please.');
                theForm[i].focus();
                enableFrontendButtons();
                return false;
            }
        }
    }
    if (!email_regex.test(theForm.email.value)) {
        alert('You must provide a valid e-mail address, please try again');
        theForm.email.focus();
        enableFrontendButtons();
        return false;
    }
    if (theForm.email.value != theForm.emailConfirmation.value) {
        alert('Email doesn`t match email confirmation');
        theForm.emailConfirmation.focus();
        enableFrontendButtons();
        return false;
    }

    if (theForm.password.value.length < 5) {
        alert('Password must be at least 5 characters long');
        theForm.password.focus();
        enableFrontendButtons();
        return false;
    }
    if (theForm.password.value != theForm.passwordConfirmation.value) {
        alert('Password doesn`t match password confirmation');
        theForm.passwordConfirmation.focus();
        enableFrontendButtons();
        return false;
    }
    if (!$('acceptTermsAndConditions').checked) {
        alert('You must agree to the Terms & Conditions');
        enableFrontendButtons();
        return false;
    }*/
    return true;
}
function checkLogin(theForm) {
    disableFrontendButtons();
    /*if (theForm.customerEmail.value == "" || !email_regex.test(theForm.customerEmail.value)) {
        alert('Please enter a valid value for the \"Email address\" field');
        theForm.customerEmail.focus();
        enableFrontendButtons();
        return false;
    }
    if (theForm.customerPassword.value == "") {
        alert('Please enter a value for the \"Password\" field');
        theForm.customerPassword.focus();
        enableFrontendButtons();
        return false;
    }*/
    return true;
}

var currentTab = 'tabLogin';
function showTab(name) {
    $(currentTab + 'A').className = '';
    $(currentTab).style.display = 'none';
    $(name).style.display = "block";
    $(name + 'A').className = 'activeTab';
    currentTab = name;
}
function toggleShowDeliveryAddressForm() {
    /*if (!formLoaded) {
        return;
    }*/
    if ($('differentDeliveryAddress').value == 'yes') {
        $('deliveryAddressForm').style.display = 'block';
        return;
    }
    $('deliveryAddressForm').style.display = 'none';
}
function toggleShowEmailGroups() {
    var mailingListCheckbox = document.getElementById('addToMailingList');
    if(mailingListCheckbox && mailingListCheckbox.checked) {
        if (document.getElementById('emailGroups')) {
            document.getElementById('emailGroups').style.display = 'block';
        }
    } else {
        if (document.getElementById('emailGroups')) {
            document.getElementById('emailGroups').style.display = 'none';
        }
    }
}
function updateEmailsGroupsList(option_node) {
    newValue    = option_node.value;
    select_node = option_node.parentNode;
    for (var i = 0, element; i < select_node.childNodes.length; i++) {
        element = select_node.childNodes.item(i);
        if(element.nodeName.toLowerCase() == 'option') {
            option = element;
            if(newValue == 0 && option.value !=0) {
                option.selected = false;
            }
            if(newValue != 0 && option.value == 0) {
                option.selected = false;
            }
        }
    }
}