var LISTUtil = new Object(); LISTUtil.getSelectedIndexes = function (oListbox) { var arrIndexes = new Array; for (var i=0; i < oListbox.options.length; i++) { if (oListbox.options[i].selected) { arrIndexes.push(i); } } return arrIndexes; }; LISTUtil.add = function (oListbox, sName, sValue) { var oListbox = $(oListbox); var oOption = document.createElement("option"); DOMUtil.createText(oOption,sName); if (arguments.length == 3) { oOption.setAttribute("value", sValue); } oListbox.appendChild(oOption); return oOption; } LISTUtil.addGroup = function (oListbox, sLabel) { var oListbox = $(oListbox); var oOption = document.createElement("optgroup"); oOption.setAttribute('label',sLabel); oListbox.appendChild(oOption); return oOption; } LISTUtil.removeOption = function (oListbox, sValue) { alert('removeOption is not available at this time'); /* alert('hit'); alert(oListBox); var oListbox = $(oListbox); alert(sValue); for(var i = 0; i < oListbox.options.length; i++) { alert(oListbox.options[i].value); if(oListbox.options[i].value == sValue) { var iIndex = i; } } oListbox.remove(iIndex); */ }; /** oListbox str | obj targetted select object bZero bool whether to clear any "0" values (for default options typically) */ LISTUtil.clear = function (oListbox,bZero) { var oListbox = $(oListbox); if (oListbox.options.length == 0) { return false; } for (var i = oListbox.options.length-1; i >= 0; i--) { if (bZero && bZero == true) { oListbox.removeChild(oListbox.options[i]); } else if (oListbox.options[i].value > 0) { oListbox.removeChild(oListbox.options[i]); } } }; LISTUtil.move = function (oListboxFrom, oListboxTo, iIndex) { var oOption = oListboxFrom.options[iIndex]; if (oOption != null) { oListboxTo.appendChild(oOption); //oListboxTo.options[oListboxTo.options.length - 1].selected = false; } }; LISTUtil.shiftUp = function (oListbox, iIndex) { if (iIndex > 0) { var oOption = oListbox.options[iIndex]; var oPrevOption = oListbox.options[iIndex-1]; oListbox.insertBefore(oOption, oPrevOption); } }; LISTUtil.shiftDown = function (oListbox, iIndex) { if (iIndex < oListbox.options.length - 1) { var oOption = oListbox.options[iIndex]; var oNextOption = oListbox.options[iIndex+1]; oListbox.insertBefore(oNextOption, oOption); } }; LISTUtil.setSelected = function (oListbox, sValue) { var oListbox = $(oListbox); for(var i = 0; i < oListbox.options.length; i++) { if(oListbox.options[i].value == sValue) { if (isIE) { oListbox.options[i].setAttribute('selected',true); } else { oListbox.options[i].selected = true; } } } };