﻿function areaListRedirection(baseUrl, controlGroupName, isAgent) {
    // get the collection of checkboxes
    var x = document.getElementsByName(controlGroupName);

    if (x != null) {

        var al = "";
        var checkedCount = 0;

        for (var n = 0; n < x.length; n++) {

            if (x[n].checked) {
                checkedCount++;
                if (al.length > 0) {
                    al += ',';
                }
                al += x[n].value;
                var singleChecked = x[n];
            }
        }

        // If only one was checked then construct an 'areaid' URL, otherwise use 'al'
        if (baseUrl.indexOf("?") == -1) {
            baseUrl += "?";
        } else {
            baseUrl += "&";
        }

        if (checkedCount == 1) {
            if (isAgent) {
                baseUrl += "&areaid=" + al;
                window.location = baseUrl;
            }
            else {
                window.location = $(singleChecked).data('url');
            }


            return false;
        } else {
            if (al.length != 0) {
                baseUrl += "al=" + al;
                window.location = baseUrl;
                return false;
            }
        }

    }

    return true;

}

