var limit = 80;
function getCrtlPrefix() {
    var prefix;
    var objCrtlPrefix = document.getElementById("ctrlPrefix");
    if (objCrtlPrefix)
        prefix = objCrtlPrefix.value;
    return prefix;
}


//this switches expand collapse icons
function filter(imagename, objectsrc) {
    if (document.images) {
        document.images[imagename].src = eval(objectsrc + ".src");
    }
}
function toggleClose2(control) {

    var prefix = getCrtlPrefix();
    var intIndex;
    var intTotalCat = control.value;
    if (document.getElementById) {
        for (intIndex = 0; intIndex < intTotalCat; intIndex++) {
            filter(("imgOpen" + intIndex), 'imgout');
            for (n = 0; n <= limit; n++) {
                var e = document.getElementsByName(prefix + "Open" + intIndex + "-" + n);

                if (e != null) {
                    for (i = 0; i < e.length; i++) {
                        e[i].style.display = "none";
                    }
                }
            }
        }
    }
}
function toggleOpen2(control) {

    var prefix = getCrtlPrefix();
    var intIndex;
    
    var intTotalCat = control.value;
    if (document.getElementById) {
        for (intIndex = 0; intIndex < intTotalCat; intIndex++) {
            filter(("imgOpen" + intIndex), 'imgin');

            for (n = 0; n <= limit; n++) {
                var e = document.getElementsByName(prefix + "Open" + intIndex + "-" + n);

                if (e != null) {
                    for (i = 0; i < e.length; i++) {
                        e[i].style.display = "block";
                    }
                }
            }
        }
    }
}
//show OR hide funtion depends on if element is shown or hidden
function shoh(id) {
    var prefix = getCrtlPrefix();

    if (document.getElementById) { // DOM3 = IE5, NS6

        for (n = 0; n <= limit; n++) {
            var e = document.getElementsByName(prefix + id + "-" + n);
            if (e != null) {
                for (i = 0; i < e.length; i++) {
                    if (e[i].style.display == "none") {
                        e[i].style.display = "block"
                        filter(("img" + id), 'imgin');
                    }
                    else {
                        e[i].style.display = "none"
                        filter(("img" + id), 'imgout');
                    }
                }
            }
        }
    }

}
function increaseByOne2(control) {
    var strQuantity
    var intQuantity
    strQuantity = control.value;
    if (strQuantity != "") {
        if (IsNumeric(strQuantity, true) == false) {
            control.value = 1
        }
        else if (strQuantity > 0) {
            intQuantity = parseInt(strQuantity, 10);
            control.value = intQuantity + 1;
        }
        else {
            control.value = 1
        }
    }
    else {
        control.value = 1
    }
}
function decreaseByOne2(control) {
    var strQuantity
    var intQuantity
    strQuantity = control.value;
    if (strQuantity != "") {
        if (IsNumeric(strQuantity, true) == false) {
            control.value = 0
        }
        else if (strQuantity > 0) {
            intQuantity = parseInt(strQuantity, 10);
            control.value = intQuantity - 1;
        }
    }
    else {
        control.value = 0
    }
}

function IsNumeric(sText) {
    var ValidChars = "0123456789.";
    var IsNumber = true;
    var Char;

    if (sText.length == 0) {
        IsNumber = false;
    }

    for (i = 0; i < sText.length && IsNumber == true; i++) {
        Char = sText.charAt(i);
        if (ValidChars.indexOf(Char) == -1) {
            IsNumber = false;
        }
    }
    return IsNumber;

}


