//Show The ListBox Add Window
function ListBoxWindowOpen(ControlID, ControlID2, left, top)
{
    obj = eval( "document.forms[0]." + ControlID2);
	var strTarget =  "/RIAC/Scripts/AddLegislacaoToListBoxIFrame.aspx?id=" + ControlID + "&itens=" + obj.value;
	var resStr = window.showModalDialog(strTarget, "" , "dialogTop:" + top + "; dialogLeft:" + left + "; dialogWidth: 468px ; dialogHeight: 442px ; scroll : yes ; resizable : no ; status : yes; help : yes; unadorned : yes");
	if(resStr!=undefined){
		var arrPairs = resStr.split("#");
		var items = "", guids = "";
		for(i=0; i<arrPairs.length; i++)
		{
		    var arrNamesAndGuids = arrPairs[i].split(":");
		    items += arrNamesAndGuids[0] + "\r\n";
		    guids += arrNamesAndGuids[1] + "\r\n";
		}
		window.document.all[ControlID].readOnly = false;
		window.document.all[ControlID].value = items;
		window.document.all[ControlID].readOnly = true;
        window.document.all[ControlID2].value = guids;
	}
}

function removeOption(ControlID)
{
    if(window.document.all[ControlID].selectedIndex != -1)
    {
        deleteOption(window.document.all[ControlID], window.document.all[ControlID].selectedIndex);
    }
}

function addOption(listBox, optionText, optionValue)
{
    if (!exists(listBox, optionText, optionValue)) 
    {
        var optionObject = new Option(optionText, optionValue);
        var optionPos = listBox.options.length;
        listBox.options[optionPos] = optionObject;
    }
}


function deleteOption(listBox, optionPos) {
    if (listBox.options.length != 0) 
    { 
        listBox.options[optionPos] = null;
    }
}

function exists(listBox, optionText, optionValue)
{
    var bool = false;
    for (i=0; i<listBox.options.length; i++)
    {
        if (optionValue == listBox.options[i].value )
        {
            bool = true;
            break;
        }
    }
    return bool;
}