// This file contains javascript used by the MultiValued CI Ilist Uihandler

// helps build XML for Multiple Object Opperations
//function getMooMode(name)
//{
//   var modeControl = eval("document.forms[0]._" + name + "_mode");
//   return (modeControl ? "mode='" + modeControl[modeControl.selectedIndex].value + "'" : "");
//}

function uih_multivaluedCIList(name, uiControl, xmlControl)
{
   var sel = document.getElementById("MVCIList_Editor");

   var xml = "<attribute "+getMooMode(name)+">";

   for(var i=0; i<sel.options.length; i++)
   {
      xml += "<value>" + sel.options[i].value + "</value>";
   }

   xml += "</attribute>";
   xmlControl.value = xml;
   
   return true;
}

function openMVCIListPopup(mode, returnMethodName, list)
{
   var width = 450;
   var height = 450;
   var x = (screen.availWidth-width)/2;
   var y =  (screen.availHeight-height)/3;
   var params = "left="+x+",top="+y+",height="+height+",width="+width+",resizable,scrollbars";
   var url = "webacc?taskId=dev.Empty&merge=fw.MVCIListEditorPopup&mode="+mode + "&returnMethodName=" + returnMethodName;

   if(mode == "edit")
   {
      url += "&listItems=" + list;
   }
   var w = window.open(url,"MVCIList_Editor", params);
}

function addMVCIListItem()
{
   openMVCIListPopup("add", "returnFromAdd");
}

function deleteMVCIListItem()
{
   var sel = document.forms[0].MVCIList_Editor;
   if(sel.selectedIndex == -1){
   		alert(selectToDel);
   		return;
   }else{
	    sel.options[sel.selectedIndex] = null;
	}     

}

function editMVCIListItem()
{
   var sel = document.forms[0].MVCIList_Editor;
   editingIndex = sel.selectedIndex;
   if(editingIndex == -1){
   		alert(selectToEdit);
   		return;
   }	
   var list = sel.options[editingIndex].value;
   openMVCIListPopup("edit", "returnFromEdit", list);
}

function returnFromAdd(packedMVCIList)
{
   if(packedMVCIList==null || packedMVCIList.length==0) 
   		return;

   var list = unpack(packedMVCIList);
   var showValue = "";
   var sel = document.forms[0].MVCIList_Editor;
   for(var i=0;i< list.length; i++){
    if(i>0) 
      showValue += " - ";
      showValue += iman.xmlDecode(list[i]);
    }
   sel.options[sel.options.length] = new Option(showValue, packedMVCIList); 
   sel.options[sel.options.length-1].value = packedMVCIList;
}

function returnFromEdit(packedMVCIList)
{
   if(editingIndex<0) return;
   if(packedMVCIList==null || packedMVCIList.length==0) return;
   var list = unpack(packedMVCIList);
   
   var showValue = "";
   var sel = document.forms[0].MVCIList_Editor;
   for(var i=0;i< list.length; i++){
    if(i>0) 
      showValue += " - ";
    showValue += iman.xmlDecode(list[i]);
    }
   sel.options[editingIndex] = new Option(showValue, packedMVCIList);
   sel.options[editingIndex].value = packedMVCIList;
}