﻿
function selectStateCoverage(SupplierCoverage) {
    var i = SupplierCoverage.selectedIndex;
    var value = SupplierCoverage.value;
    if (value == '_USA') {
        SupplierCoverage.options[i].selected = false;
        for (var x = 0; x < SupplierCoverage.options.length; x++) {
            var thisVal = SupplierCoverage.options[x].value;
            if (thisVal.indexOf('SelState_') != -1) {
                SupplierCoverage.options[x].selected = true;
            }
        }
    }
    else if (value == '_CAN') {
        SupplierCoverage.options[i].selected = false;
        for (var x = 0; x < SupplierCoverage.options.length; x++) {
            var thisVal = SupplierCoverage.options[x].value;
            if (thisVal.indexOf('SelProv_') != -1) {
                SupplierCoverage.options[x].selected = true;
            }
        }
    }
}

function loadCityCheckBoxes(list) {
    var selected = new Array();
    var index = 0;
    for (var i = 0; i < list.options.length; i++) {
        if (list.options[i].selected) {
            selected[index++] = list.options[i].text;
        }
    }

    var citylist = $get('geoCurrentSelections');
    clearChildren(citylist);
    var nd = document.createTextNode('Loading...');
    citylist.appendChild(nd);

    WorkOasis.GeographicCoverage.GetCityNames(selected, onLoadCityCheckBoxes);
}

function onLoadCityCheckBoxes(results) {
    var citylist = $get('geoCurrentSelections');
    clearChildren(citylist);
    for (var i = 0; i < results.length; i++) {
        var check = document.createElement('input');
        var label = document.createElement('label');
        var lb = document.createElement('br');
        var checkName = 'cityselection' + i;
        check.setAttribute('type', 'checkbox');
        check.setAttribute('id', checkName);
        label.setAttribute('for', checkName);
        label.appendChild(document.createTextNode(results[i]));
        citylist.appendChild(check);
        citylist.appendChild(label);
        citylist.appendChild(lb);
    }
}

function warnUser(length, type) {
    return confirm('You have selected ' + length + ' states.\nThis may take'
            + ' several seconds to retrieve all of the ' + type + '.\n\nAre you sure you wish to continue?');
}

function clearChildren(list) {
    while (list.childNodes.length > 0)
        list.removeChild(list.childNodes[0]);
}

function clearList(list) {
    while (list.options.length > 0)
        list.options[0] = null;
}