
// Handles the Selected event of a RadTabStrip control.
// This function is needed for displaying sIFR headers in RadTabStrip control.
function ShoppingClientTabSelectedHandler(sender, eventArgs) {
    var tabStrip = sender;
    tab = eventArgs.Tab;
    if (typeof redoShoppingFontReplacementForSelectedTab == "function") {
        redoShoppingFontReplacementForSelectedTab();
    }
}

// Following scripts will be used for opening and closing the messagebox
function CloseMessageBox(messageBoxId) {
    document.getElementById(messageBoxId).style.display = 'none';
    document.getElementById("MessageBoxMain").style.display = 'none';
}

function OpenMessageBox(messageBoxId) {
    document.getElementById("MessageBoxMain").style.display = 'block';
    document.getElementById(messageBoxId).style.display = 'block';
    // IE script to cover <select> elements with <iframe>s
    if ($.browser.msie) {
        $("#" + messageBoxId).bgiframe();
    }
}

// Opens a new window
function newPopup(source, name, width, height) {
    if (width) width = width;
    else width = 640;

    if (height) height = height;
    else height = 480;

    xl = (screen.availWidth / 2) - (width / 2);
    tt = (screen.availHeight / 2) - (height / 2);
    newWindowScreen = window.open(source, name, 'toolbar=no,scrolling=auto,resizable=no,location=no,directories=no,status=yes,scrollbars=yes,menubar=no,width=' + width + ',height=' + height + ',left=' + xl + ',top=' + tt);
    newWindowScreen.focus();
}

function openAnimation() {
    newPopup(productAnimationUrl, '', 745, 590);
}

function openDemo() {
    newPopup(productDemoUrl, '', 750, 560);
}

function toggleContractCancelled(contractCancelledRadioButtonListId, dateCancellationRowId, cancellationDateValidator) {
    var radioButtonList = document.getElementById(contractCancelledRadioButtonListId);
    var validator = document.getElementById(cancellationDateValidator);
    var contractCancelled = false;

    var e = radioButtonList.getElementsByTagName('input');
    for (var i = 0; i < e.length; i++) {
        if (e[i].checked && e[i].value.toUpperCase() == 'CONTRACT_CANCELLED') {
            contractCancelled = true;
        }
    }

    if (validator != null) {
        validator.enabled = contractCancelled;
    }

    if (contractCancelled) {
        document.getElementById(dateCancellationRowId).style.display = 'block';
    }
    else {
        document.getElementById(dateCancellationRowId).style.display = 'none';
    }
}

function switchResBus(checkboxresBus, companyDetailsDiv, companyNameValidator, companyContactPersonInitialsValidator, companyContactPersonPrefixValidator, companyContactPersonLastNameValidator, companyZipCodeValidator, companyHouseNumberValidator, companyHouseNumberAdditionValidator) {
    var checkboxResbus = document.getElementById(checkboxresBus);
    var validator1 = document.getElementById(companyNameValidator);
    var validator2 = document.getElementById(companyContactPersonPrefixValidator);
    var validator3 = document.getElementById(companyContactPersonLastNameValidator);
    var validator4 = document.getElementById(companyZipCodeValidator);
    var validator5 = document.getElementById(companyHouseNumberValidator);
    var validator6 = document.getElementById(companyHouseNumberAdditionValidator);

    if (checkboxResbus.checked) {
        document.getElementById(companyDetailsDiv).style.display = 'block';
        validator1.enabled = true;
        validator2.enabled = true;
        validator3.enabled = true;
        validator4.enabled = true;
        validator5.enabled = true;
        validator6.enabled = true;
    }
    else {
        document.getElementById(companyDetailsDiv).style.display = 'none';
        validator1.enabled = false;
        validator2.enabled = false;
        validator3.enabled = false;
        validator4.enabled = false;
        validator5.enabled = false;
        validator6.enabled = false;
    }
}

function isValidBanknumber(sender, args) {
    var banknr = args.Value;
    var waarde;

    banknr = banknr.replace(/[^0-9]/g, "");
    banknr = banknr.replace(/[^0-9]/g, ".");

    while (banknr.length > 1 && banknr.substring(0, 1) == "0") {
        banknr = banknr.substring(1, banknr.length);
    }

    if (banknr == "0") {
        args.IsValid = false;
    }
    else {
        waarde = ((banknr.charAt(0) * 9) + (banknr.charAt(1) * 8) + (banknr.charAt(2) * 7) + (banknr.charAt(3) * 6) + (banknr.charAt(4) * 5) + (banknr.charAt(5) * 4) + (banknr.charAt(6) * 3) + (banknr.charAt(7) * 2) + (banknr.charAt(8) * 1)) / 11;
        args.IsValid = (waarde == parseInt(waarde));
    }
}

function isValidGironumber(bankAccounTextboxId) {
    var gironr = document.getElementById(bankAccounTextboxId).value;
    var reg1 = /^[1-9]{1}[0-9]{5,6}$/;

    gironr = gironr.replace(/[^0-9]/g, "");
    gironr = gironr.replace(/[^0-9]/g, ".");

    document.getElementById(bankAccounTextboxId).value = gironr;

    return (reg1.test(gironr));
}

function SwitchDeliveryAddress(showDeliveryAddress, deliveryAddressSection, zipCodeValidator, houseNumberValidatorForLabel, houseNumberValidatorForTextBox) {
    var checkBox = document.getElementById(showDeliveryAddress);
    var section = document.getElementById(deliveryAddressSection);
    var validator1 = document.getElementById(zipCodeValidator);
    var validator2 = document.getElementById(houseNumberValidatorForLabel);
    var validator3 = document.getElementById(houseNumberValidatorForTextBox);

    if (checkBox.checked) {
        section.style.display = 'block';
        validator1.enabled = true;
        validator2.enabled = true;
        validator3.enabled = true;
    }
    else {
        section.style.display = 'none';
        validator1.enabled = false;
        validator2.enabled = false;
        validator3.enabled = false;
    }
}

function SwitchDeliveryAddressResidential(showDeliveryAddress, deliveryAddressSection, zipCodeValidator, houseNumberValidatorForTextBox, houseNumberAdditionValidatorForTextBox) {
    var checkBox = document.getElementById(showDeliveryAddress);
    var section = document.getElementById(deliveryAddressSection);
    var validator1 = document.getElementById(zipCodeValidator);
    var validator2 = document.getElementById(houseNumberValidatorForTextBox);
    var validator3 = document.getElementById(houseNumberAdditionValidatorForTextBox);

    if (checkBox.checked) {
        section.style.display = 'block';
        validator1.enabled = true;
        validator2.enabled = true;
        validator3.enabled = true;
    }
    else {
        section.style.display = 'none';
        validator1.enabled = false;
        validator2.enabled = false;
        validator3.enabled = false;
    }
}

function switchActivationDate(checkboxNumberPortingId, numberportingdateRowId, otherdateRowId, directRadioButtonId, numberPortingDateRadioButtonId, otherDateRadioButtonId, otherDateValidatorId) {
    var checkboxnumberporting = document.getElementById(checkboxNumberPortingId);
    var numberportingdaterow = document.getElementById(numberportingdateRowId);
    var otherdaterow = document.getElementById(otherdateRowId);
    var directradiobutton = document.getElementById(directRadioButtonId);
    var numberportingdateradiobutton = document.getElementById(numberPortingDateRadioButtonId);
    var otherdateradiobutton = document.getElementById(otherDateRadioButtonId);
    var validator = document.getElementById(otherDateValidatorId);

    if (checkboxnumberporting.checked) {
        directradiobutton.checked = !numberportingdateradiobutton.checked;
        numberportingdaterow.style.display = '';
        otherdaterow.style.display = 'none';
        if (validator != null) {
            validator.enabled = false;
        }
    }
    else {
        directradiobutton.checked = !otherdateradiobutton.checked;
        numberportingdaterow.style.display = 'none';
        otherdaterow.style.display = '';
        if (validator != null) {
            validator.enabled = otherdateradiobutton.checked;
        }
    }
}

function toggleDateValidator(radioButtonToCheckName, validatorName, activationDateDivId) {
    var radioButtonToCheck = document.getElementById(radioButtonToCheckName);
    var validator = document.getElementById(validatorName);
    var activationDateDiv = document.getElementById(activationDateDivId);

    if (typeof (activationDateDiv) != "undefined" && activationDateDiv != null) {
        activationDateDiv.style.display = (radioButtonToCheck.checked) ? 'block' : 'none';
    }
    if (typeof (validator) != "undefined" && validator != null) {
        validator.enabled = radioButtonToCheck.checked;
    }
}

function toggleAttorneySection(checkbox, section, validatorInitials, validatorPrefixes, validatorLastName) {

    var attorneyTheSame = document.getElementById(checkbox);
    var attorneySection = document.getElementById(section);
    var vInitials = document.getElementById(validatorInitials);
    var vPrefixes = document.getElementById(validatorPrefixes);
    var vLastName = document.getElementById(validatorLastName);


    if (attorneyTheSame.checked) {
        attorneySection.style.display = 'NONE';

        if (vInitials != null) vInitials.enabled = false;
        if (vPrefixes != null) vPrefixes.enabled = false;
        if (vLastName != null) vLastName.enabled = false;
    }
    else {
        attorneySection.style.display = 'BLOCK';
        if (vInitials != null) vInitials.enabled = true;
        if (vPrefixes != null) vPrefixes.enabled = true;
        if (vLastName != null) vLastName.enabled = true;
    }
}

function switchActivationDateBusiness(checkboxNumberPorting, activationSection, otherDateRadio, validator) {
    var checkboxnumberporting = document.getElementById(checkboxNumberPorting);
    var activation = document.getElementById(activationSection);
    var otherDateRadioButton = document.getElementById(otherDateRadio);
    var otherDateValidator = document.getElementById(validator);

    if (otherDateValidator != null) {
        otherDateValidator.enabled = false;
    }

    if (checkboxnumberporting.checked) {
        activation.style.display = 'none';
    }
    else {
        activation.style.display = 'inline';
        if (otherDateRadioButton.checked &&
            otherDateValidator != null) {
            otherDateValidator.enabled = true;
        }
    }
}

function ControlDisplay(ctrl, display, displayMode) {
    displayMode = (typeof (displayMode) != "undefined") ? displayMode : "block";
    if (typeof (ctrl) == "object" && ctrl != null) {
        ctrl.style.display = (display) ? displayMode : 'none';
    }
}

function Shopping_ValidatorEnable(val, enable) {
    if (typeof (val) == "object" && val != null) {
        val.enabled = (enable != false);
    }
}

function ValidatorEnableByContainer(container, enable) {
    if (typeof (container) == "object" && container != null) {
        var vals = container.getElementsByTagName('span');
        for (var i = 0; i < vals.length; i++) {
            if (typeof (vals[i].controltovalidate) != "undefined") {
                Shopping_ValidatorEnable(vals[i], enable);
            }
        }
    }
}

function GetSelectedValueFromSingleSelectionList(listID) {
    var selectedValue = '';
    var list = document.getElementById(listID);
    if (typeof (list) != "undefined") {
        var listItems = list.getElementsByTagName('input');
        for (var i = 0; i < listItems.length; i++) {
            if (listItems[i].checked) {
                selectedValue = listItems[i].value;
            }
        }
    }
    return selectedValue;
}

function CompleteControlValue(ctrl, minLength, completionText) {
    var currentText = ctrl.value;
    var text = ctrl.value;
    for (var i = currentText.length; i < minLength; i++) {
        text = completionText + text;
    }
    ctrl.value = text;
}

/* START: PersonalDetails functions */
function Shopping_PersonalDetails_Init() {
    if (typeof (Shopping_PersonalDetails_Companies) != "undefined") {
        for (var i = 0; i < Shopping_PersonalDetails_Companies.length; i++) {
            var company = Shopping_PersonalDetails_Companies[i];

            Shopping_PersonalDetails_Company_Load(i);
        }
    }
}

function Shopping_PersonalDetails_Company_Load(index) {
    if (typeof (Shopping_PersonalDetails_Companies) != "undefined") {
        if (typeof (index) == "undefined") {
            index = 0;
        }
        var company = Shopping_PersonalDetails_Companies[index];

        var foundationDateContainer = document.getElementById(company.foundationDateContainerID);
        var foundationDateAsteriskLabel = document.getElementById(company.foundationDateAsteriskLabelID);
        var foundationDatepicker = document.getElementById(company.foundationDatepickerID);
        var legalFormDropdownList = document.getElementById(company.legalFormDropdownListID);
        var vatNumberContainer = document.getElementById(company.vatNumberContainerID);
        var vatNumberTextBox = document.getElementById(company.vatNumberTextBoxID);
        var cocNumberContainer = document.getElementById(company.cocNumberContainerID);
        var cocNumberTextBox = document.getElementById(company.cocNumberTextBoxID);

        var vatNumberValidator = document.getElementById(company.vatNumberValidatorID);
        var cocNumberValidator = document.getElementById(company.cocNumberValidatorID);
        var cocNumberSuffixValidator = document.getElementById(company.cocNumberSuffixValidatorID);
        var foundationDateValidator = document.getElementById(company.foundationDateValidatorID);

        var selectedLegalForm = legalFormDropdownList.options[legalFormDropdownList.selectedIndex].value;

        var vatNumberRequired = false;
        for (var i = 0; i < Shopping_CompanyDetails_VatNumberRequiredLegalForms.length; i++) {
            var legalForm = Shopping_CompanyDetails_VatNumberRequiredLegalForms[i];
            if (selectedLegalForm == legalForm) {
                vatNumberRequired = true;
                break;
            }
        }
        if (vatNumberRequired) {
            ControlDisplay(vatNumberContainer, true, "");
            Shopping_ValidatorEnable(vatNumberValidator, true);
        }
        else {
            ControlDisplay(vatNumberContainer, false);
            Shopping_ValidatorEnable(vatNumberValidator, false);
        }

        var cocNumberRequired = false;
        for (var i = 0; i < Shopping_CompanyDetails_CocNumberRequiredLegalForms.length; i++) {
            var legalForm = Shopping_CompanyDetails_CocNumberRequiredLegalForms[i];
            if (selectedLegalForm == legalForm) {
                cocNumberRequired = true;
                break;
            }
        }
        if (cocNumberRequired) {
            ControlDisplay(cocNumberContainer, true, "");
            Shopping_ValidatorEnable(cocNumberValidator, true);
            Shopping_ValidatorEnable(cocNumberSuffixValidator, true);

            ControlDisplay(foundationDateAsteriskLabel, true, "");
            Shopping_ValidatorEnable(foundationDateValidator, true);
        }
        else {
            ControlDisplay(cocNumberContainer, false);
            Shopping_ValidatorEnable(cocNumberValidator, false);
            Shopping_ValidatorEnable(cocNumberSuffixValidator, false);

            ControlDisplay(foundationDateAsteriskLabel, false);
            Shopping_ValidatorEnable(foundationDateValidator, false);
        }
    }
}
/* END: PersonalDetails functions */

/* START: Numberporting functions */
var Shopping_Numberporting_PreventReload;

function Shopping_Company_Numberporting_Init() {
    if (typeof (Shopping_Numberporting_Products) != "undefined") {
        for (var i = 0; i < Shopping_Numberporting_Products.length; i++) {
            var product = Shopping_Numberporting_Products[i];

            Shopping_Numberporting_Product_Load(i);
            Shopping_Numberporting_Account_Load(i);
        }
    }
}

function Shopping_Numberporting_Product_Load(index) {
    if (typeof (Shopping_Numberporting_Products) != "undefined") {
        var product = Shopping_Numberporting_Products[index];

        var numberportingCheckBox = document.getElementById(product.numberportingCheckBoxID);
        var portingSelectionContainer = document.getElementById(product.portingSelectionContainerID);
        var noPortingSelectionContainer = document.getElementById(product.noPortingSelectionContainerID);
        var simNumberValidator = document.getElementById(product.simNumberValidatorID);
        var cancellationDateValidator = document.getElementById(product.cancellationDateValidatorID);
        var endCurrentSubscriptionDateValidator = document.getElementById(product.endCurrentSubscriptionDateValidatorID);

        var activationDateRadioButton = document.getElementById(product.activationDateRadioButtonID);
        var activationDateContainer = document.getElementById(product.activationDateContainerID);
        var activationDateValidator = document.getElementById(product.activationDateValidatorID);

        var numberportingAccountInfoContainer = document.getElementById(product.numberportingAccountInfoContainerID);

        // NumberportingAccountInfo validator controls
        var account = Shopping_Numberporting_Accounts[index];
        var currentMsisdnValidator = document.getElementById(account.currentMsisdnValidatorID);
        var accountTypeValidator = document.getElementById(account.accountTypeValidatorID);
        var serviceProviderValidator = document.getElementById(account.serviceProviderValidatorID);
        var networkOperatorValidator = document.getElementById(account.networkOperatorValidatorID);

        var prepaidCurrentSimContainer = document.getElementById(product.prepaidCurrentSimContainerID);
        var addressInformationContainer = document.getElementById(product.addressInformationContainerID);
        var connectionActivationEntryContainer = document.getElementById(product.connectionActivationEntryContainerID);

        if (numberportingCheckBox.checked) {
            ControlDisplay(portingSelectionContainer, true);
            ControlDisplay(noPortingSelectionContainer, false);
            ControlDisplay(numberportingAccountInfoContainer, true);
            ControlDisplay(activationDateContainer, false);

            if (noPortingSelectionContainer) {
                ValidatorEnableByContainer(connectionActivationEntryContainer, false);
            }

            if (prepaidCurrentSimContainer) {
                ControlDisplay(prepaidCurrentSimContainer, true);
                ValidatorEnableByContainer(prepaidCurrentSimContainer, true);
            }

            if (connectionActivationEntryContainer) {
                ControlDisplay(connectionActivationEntryContainer, true);
                ValidatorEnableByContainer(connectionActivationEntryContainer, true);
            }

            if (addressInformationContainer) {
                ControlDisplay(addressInformationContainer, true);
                ValidatorEnableByContainer(addressInformationContainer, true);
            }

            Shopping_ValidatorEnable(simNumberValidator, true);
            Shopping_ValidatorEnable(currentMsisdnValidator, true);
            Shopping_ValidatorEnable(cancellationDateValidator, true);
            Shopping_ValidatorEnable(endCurrentSubscriptionDateValidator, true);
            Shopping_ValidatorEnable(activationDateValidator, false);
            Shopping_ValidatorEnable(accountTypeValidator, true);
            Shopping_ValidatorEnable(serviceProviderValidator, true);
            Shopping_ValidatorEnable(networkOperatorValidator, true);
        }
        else {
            ControlDisplay(portingSelectionContainer, false);
            ControlDisplay(noPortingSelectionContainer, true);
            ControlDisplay(numberportingAccountInfoContainer, false);

            if (noPortingSelectionContainer) {
                ValidatorEnableByContainer(connectionActivationEntryContainer, true);
            }

            if (prepaidCurrentSimContainer) {
                ControlDisplay(prepaidCurrentSimContainer, false);
                ValidatorEnableByContainer(prepaidCurrentSimContainer, false);
            }

            if (connectionActivationEntryContainer) {
                ControlDisplay(connectionActivationEntryContainer, false);
                ValidatorEnableByContainer(connectionActivationEntryContainer, false);
            }

            if (addressInformationContainer) {
                ControlDisplay(addressInformationContainer, false);
                ValidatorEnableByContainer(addressInformationContainer, false);
            }

            Shopping_ValidatorEnable(simNumberValidator, false);
            Shopping_ValidatorEnable(currentMsisdnValidator, false);
            Shopping_ValidatorEnable(cancellationDateValidator, false);
            Shopping_ValidatorEnable(endCurrentSubscriptionDateValidator, false);
            Shopping_ValidatorEnable(accountTypeValidator, false);
            Shopping_ValidatorEnable(serviceProviderValidator, false);
            Shopping_ValidatorEnable(networkOperatorValidator, false);

            if (activationDateRadioButton.checked) {
                ControlDisplay(activationDateContainer, true);
                Shopping_ValidatorEnable(activationDateValidator, true);
            }
            else {
                ControlDisplay(activationDateContainer, false);
                Shopping_ValidatorEnable(activationDateValidator, false);
            }
        }
    }
}

function Shopping_Numberporting_ResetSectionDisplay(index) {
    if (typeof (Shopping_Numberporting_Products) != "undefined") {
        var product = Shopping_Numberporting_Products[index];

        var addressInformationContainer = document.getElementById(product.addressInformationContainerID);
        var connectionActivationEntryContainer = document.getElementById(product.connectionActivationEntryContainerID);
        var prepaidCurrentSimContainer = document.getElementById(product.prepaidCurrentSimContainerID);

        if (typeof (addressInformationContainer) != "undefined") {
            ControlDisplay(addressInformationContainer, false);
        }
        if (typeof (connectionActivationEntryContainer) != "undefined") {
            ControlDisplay(connectionActivationEntryContainer, false);
        }
        if (typeof (prepaidCurrentSimContainer) != "undefined") {
            ControlDisplay(prepaidCurrentSimContainer, false);
        }
    }
}

function Shopping_Residential_Numberporting_Init() {
    if (typeof (Shopping_Numberporting_Accounts) != "undefined") {
        for (var i = 0; i < Shopping_Numberporting_Accounts.length; i++) {
            var account = Shopping_Numberporting_Accounts[i];

            Shopping_Numberporting_Account_Load(i);

            Shopping_ValidatorEnable(document.getElementById(account.currentMsisdnValidatorID), true);
            Shopping_ValidatorEnable(document.getElementById(account.accountTypeValidatorID), true);
            Shopping_ValidatorEnable(document.getElementById(account.serviceProviderValidatorID), true);
            Shopping_ValidatorEnable(document.getElementById(account.networkOperatorValidatorID), true);
        }
    }
}

function Shopping_Numberporting_Account_Load(index) {
    if (typeof (Shopping_Numberporting_Accounts) != "undefined") {
        var account = Shopping_Numberporting_Accounts[index];

        var selectedAccountType = GetSelectedValueFromSingleSelectionList(account.accountTypeRadioButtonListID);

        if (selectedAccountType.length > 0) {
            var serviceProviderDropDownList = document.getElementById(account.serviceProviderDropDownListID);
            var networkOperatorDropDownList = document.getElementById(account.networkOperatorDropDownListID);
            var serviceProviderTextBox = document.getElementById(account.serviceProviderTextBoxID);
            var networkOperatorTextBox = document.getElementById(account.networkOperatorTextBoxID);

            Shopping_Numberporting_UpdateServiceProviderDropDownList(account.accountTypeRadioButtonListID, account.serviceProviderDropDownListID, account.networkOperatorDropDownListID, account.networkOperatorContainerID);
            for (var i = 0; i < serviceProviderDropDownList.options.length; i++) {
                if (serviceProviderDropDownList[i].value == serviceProviderTextBox.value) {
                    serviceProviderDropDownList[i].selected = true;
                    break;
                }
            }

            Shopping_Numberporting_UpdateNetworkOperatorDropDownList(account.accountTypeRadioButtonListID, account.serviceProviderDropDownListID, account.networkOperatorDropDownListID, account.networkOperatorContainerID);
            for (var i = 0; i < networkOperatorDropDownList.options.length; i++) {
                var providerName = networkOperatorDropDownList[i].value.split('|')[0];
                if (Shopping_Numberporting_ProviderTable[providerName] == networkOperatorTextBox.value) {
                    networkOperatorDropDownList[i].selected = true;
                    break;
                }
            }
            Shopping_Numberporting_PreventReload = true;
            networkOperatorDropDownList.options[0] = null;
        }
    }
}

function Shopping_Numberporting_UpdateServiceProviderDropDownList(accountTypeRadioButtonListID, serviceProviderDropDownListID, networkOperatorDropDownListID, networkOperatorContainerID) {
    var accountTypeRadioButtonList = document.getElementById(accountTypeRadioButtonListID);
    var serviceProviderDropDownList = document.getElementById(serviceProviderDropDownListID);
    var networkOperatorDropDownList = document.getElementById(networkOperatorDropDownListID);
    var networkOperatorContainer = document.getElementById(networkOperatorContainerID);

    var selectedAccountType = GetSelectedValueFromSingleSelectionList(accountTypeRadioButtonListID);

    networkOperatorContainer.style.display = 'none';
    serviceProviderDropDownList.options.length = 0;
    networkOperatorDropDownList.options.length = 0;
    serviceProviderDropDownList.options[0] = new Option('');

    for (var c = 0; c < Shopping_Numberporting_Providers.length; ++c) {
        if (Shopping_Numberporting_Providers[c][0].toUpperCase() == selectedAccountType.toUpperCase()) {
            serviceProviderDropDownList.options[serviceProviderDropDownList.options.length] =
                new Option(Shopping_Numberporting_Providers[c][1], Shopping_Numberporting_ProviderTable[Shopping_Numberporting_Providers[c][1]]);
        }
    }
}

function Shopping_Numberporting_UpdateNetworkOperatorDropDownList(accountTypeRadioButtonListID, serviceProviderDropDownListID, networkOperatorDropDownListID, networkOperatorContainerID) {
    var accountTypeRadioButtonList = document.getElementById(accountTypeRadioButtonListID);
    var serviceProviderDropDownList = document.getElementById(serviceProviderDropDownListID);
    var networkOperatorDropDownList = document.getElementById(networkOperatorDropDownListID);
    var networkOperatorContainer = document.getElementById(networkOperatorContainerID);

    var selectedAccountType = GetSelectedValueFromSingleSelectionList(accountTypeRadioButtonListID);

    var selectedServiceProviderText = serviceProviderDropDownList.options[serviceProviderDropDownList.selectedIndex].text;
    networkOperatorDropDownList.options.length = 0;

    serviceProviderDropDownList.options[0] = new Option('');

    if (selectedServiceProviderText == '') {
        networkOperatorContainer.style.display = 'none';
        return;
    }

    networkOperatorDropDownList.options.length = 0;
    networkOperatorDropDownList.options[0] = new Option('');

    for (var c = 0; c < Shopping_Numberporting_Providers.length; ++c) {
        if (Shopping_Numberporting_Providers[c][0].toUpperCase() == selectedAccountType.toUpperCase() &&
           Shopping_Numberporting_Providers[c][1] == selectedServiceProviderText) {
            for (var x = 0; x < Shopping_Numberporting_Providers[c][2].length; ++x) {
                networkOperatorDropDownList.options[networkOperatorDropDownList.options.length] =
                    new Option(Shopping_Numberporting_Providers[c][2][x].split('|')[0], Shopping_Numberporting_Providers[c][2][x]);
            }
        }
    }

    if (networkOperatorDropDownList.options.length == 2) {
        networkOperatorContainer.style.display = 'none';
        networkOperatorDropDownList.options[1].selected = true;
        networkOperatorDropDownList.options[0] = null;
        if (!Shopping_Numberporting_PreventReload) {
            networkOperatorDropDownList.onchange();
        }
    }
    else {
        networkOperatorContainer.style.display = 'block';
    }
}

function Shopping_Numberporting_UpdateProviderSelection(serviceProviderDropDownListID, serviceProviderTextBoxID, networkOperatorDropDownListID, networkOperatorTextBoxID, blockCodeTextBoxID) {
    var serviceProviderDropDownList = document.getElementById(serviceProviderDropDownListID);
    var networkOperatorDropDownList = document.getElementById(networkOperatorDropDownListID);
    var serviceProviderTextBox = document.getElementById(serviceProviderTextBoxID);
    var networkOperatorTextBox = document.getElementById(networkOperatorTextBoxID);
    var blockCodeTextBox = document.getElementById(blockCodeTextBoxID);

    var selectedServiceProvider = serviceProviderDropDownList.options[serviceProviderDropDownList.selectedIndex].value;
    var selectedNetworkOperator = networkOperatorDropDownList.options[networkOperatorDropDownList.selectedIndex].value;

    serviceProviderTextBox.value = selectedServiceProvider;
    networkOperatorTextBox.value = Shopping_Numberporting_ProviderTable[selectedNetworkOperator.split('|')[0]];
    blockCodeTextBox.value = selectedNetworkOperator.split('|')[1];

    if (typeof (serviceProviderTextBox.value) == "undefined") {
        serviceProviderTextBox.value = '';
    }
    if (typeof (networkOperatorTextBox.value) == "undefined") {
        networkOperatorTextBox.value = '';
    }
    if (typeof (blockCodeTextBox.value) == "undefined") {
        blockCodeTextBox.value = '';
    }
}

function Shopping_Numberporting_ResetProviderSelection(serviceProviderTextBoxID, networkOperatorTextBoxID, blockCodeTextBoxID) {
    var serviceProviderTextBox = document.getElementById(serviceProviderTextBoxID);
    var networkOperatorTextBox = document.getElementById(networkOperatorTextBoxID);
    var blockCodeTextBox = document.getElementById(blockCodeTextBoxID);

    serviceProviderTextBox.value = '';
    networkOperatorTextBox.value = '';
    blockCodeTextBox.value = '';
}

/* END: Numberporting functions */

function CheckMaxAccessories(accessoryCheckboxControlId) {
    var numberOfAccessories = 0;
    var accessoryCheckbox;
    var maximumAccessories = false;
    var selectedAccessory = document.getElementById(accessoryCheckboxControlId);

    for (i = 0; i < document.form1.length; i++) {
        if (document.form1[i].type == "checkbox") {
            accessoryCheckbox = document.getElementById(document.form1[i].id);
            if (accessoryCheckbox.checked) {
                numberOfAccessories++;
                if (numberOfAccessories == 5) {
                    maximumAccessories = true;
                    break;
                }
            }
        }
    }

    if (maximumAccessories) {
        OpenMessageBox('MessageBox1');
        selectedAccessory.checked = false;
    }

}

//Show a js-alert when the shop-backend is down/disabled
function shopOrderingDisabledAlert(message) {
    window.alert(message);
}

// Hide/Display formsfor client depending on if client is new or existingew
function changeClientForms(shopFormPersDetailDivId, existingClientHeaderDivId, clientFormDivId,
    existingClientCompanyDetailsDivId, newClientCompanyDetailsDivId, newClientPaymentDetailsDivId,
    agreeCheckBoxId, isNew, isGroup, isTransferData) {
    // Setup of contact info control
    selectContactInfoMode(isNew);

    // We process client validators for IE only
    if (navigator.appName.indexOf("Microsoft") > -1) {
        if (isNew) {
            setupCompanyDetailsEntryValidationState(true);
            setupCompanyDetailsEntryShortValidationState(false);
            setupContactDetailsEntryValidationState(true);
            setupPaymentDetailsEntryValidationState(true);
            Shopping_PersonalDetails_Company_Load(0);
        }
        else {
            setupCompanyDetailsEntryValidationState(false);
            setupCompanyDetailsEntryShortValidationState(true);
            setupContactDetailsEntryValidationState(false);
            setupPaymentDetailsEntryValidationState(false);
        }
    }

    if (isTransferData) {
        if (isNew) {
            transferDataToLongVersion();
        }
        else {
            transferDataToShortVersion();
        }
    }

    // Setup of other controls visibility
    var shopFormPersDetailDiv = document.getElementById(shopFormPersDetailDivId);
    var existingClientHeaderDiv = document.getElementById(existingClientHeaderDivId);
    var clientFormDiv = document.getElementById(clientFormDivId);
    var existingClientCompanyDetailsDiv = document.getElementById(existingClientCompanyDetailsDivId);
    var newClientCompanyDetailsDiv = document.getElementById(newClientCompanyDetailsDivId);
    var newClientPaymentDetailsDiv = document.getElementById(newClientPaymentDetailsDivId);
    var agreeCheckBox = document.getElementById(agreeCheckBoxId);

    existingClientHeaderDiv.style.display = (!isNew) ? "block" : "none";
    clientFormDiv.style.display = (isNew || (!isNew && agreeCheckBox.checked && isGroup) || (!isNew && !isGroup)) ? "block" : "none";
    existingClientCompanyDetailsDiv.style.display = (!isNew) ? "block" : "none";
    newClientCompanyDetailsDiv.style.display = (isNew) ? "block" : "none";
    newClientPaymentDetailsDiv.style.display = (isNew) ? "block" : "none";

    shopFormPersDetailDiv.style.display = "block";
}

function toUpper(field) {
    var txt = field.value;
    field.value = txt.toUpperCase();
}