﻿
function SetControlsReadOnlyAndClear(tableId, readOnly) {
    var table = document.getElementById(tableId);
    var controls = table.getElementsByTagName("input");
    var controls2 = table.getElementsByTagName("select");

    for (var i = 0; i < controls.length; i++) {
        controls[i].readOnly = readOnly;
        controls[i].value = "";
    }

    for (var j = 0; j < controls2.length; j++) {
        controls2[j].disabled = readOnly;
        controls2[j].selectedIndex = 0;
    }
}

function ValidateShippingAddress1(source, clientside_arguments) {
    var regExp = new RegExp("(^(p[\s|\.|,]*| ^post[\s|\.]*)(o[\s|\.|,]*| office[\s|\.]*))| (^box[.|\s]*\d+)");
    var result = regExp.test(clientside_arguments.Value);
    clientside_arguments.IsValid = !result;
}

function ShowPopUp() {
    var pop = document.getElementById('popup');

    if (pop.className == "popup") {
        pop.className += ' popupShow';
    }
    else {
        pop.className = 'popup';
    }
}

function ValidatePasswordLength(source, arguments) {
    if (arguments.Value.length < 5)
        arguments.IsValid = false;
    else
        arguments.IsValid = true;
}

function DisablePaymentButton(paymentButton, validationGroup) {
    if (Page_ClientValidate(validationGroup)) {
        paymentButton.value = "Processing...";
        paymentButton.disabled = true;
        __doPostBack();
    }
}

function CopyTextValue(source, destination) {
    var textBoxBilling = document.getElementById(source)
    var textBoxShipping = document.getElementById(destination);
    textBoxShipping.value = textBoxBilling.value;
}

function CopyDropdownValue(source, destination) {
    var dropDownBilling = document.getElementById(source)
    var dropDownShipping = document.getElementById(destination);
    dropDownShipping.selectedIndex = dropDownBilling.selectedIndex;
}

function ValidateShippingAddress1(source, clientside_arguments) {
    var regExp = new RegExp("(^(p[\s|\.|,]*| ^post[\s|\.]*)(o[\s|\.|,]*| office[\s|\.]*))| (^box[.|\s]*\d+)");
    var result = regExp.test(clientside_arguments.Value.toLowerCase());
    clientside_arguments.IsValid = !result;
}

function subscribe(email) {
    var result = jQuery.ajax({
        url: "/AjaxHandlers/subscribeToNewsletter.ashx?email=" + escape(email) + "&Mode=subscribe",
        async: false,
        cache: false
    }).responseText;

    $('#textSubscribe').val(''); 
    $('#divResult').html(result)

}

function unsubscribe(email) {

    var result = jQuery.ajax({
        url: "/AjaxHandlers/subscribeToNewsletter.ashx?email=" + escape(email) + "&Mode=unsubscribe",
        async: false, 
        cache: false
    }).responseText;

    $('#textSubscribe').val('');
    $('#divResult').html(result)
 

}
