// This file contains javascript used by the MultiValued Path 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_multivaluedpath(name, uiControl, xmlControl)
{
   var sel = document.getElementById("MultiValuedPath_Editor");

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

   for(var i=0; i<sel.options.length; i++)
   {
      var list = unpack(sel.options[i].value);
      xml += "<value><type>"+list[0]+"</type><volume>"+list[1]+"</volume><path>"+list[2]+"</path></value>";
   }

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

function openMVPathPopup(mode, returnMethodName, type, volume, path)
{
   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.MultivaluedPathEditorPopup&mode="+mode + "&returnMethodName=" + returnMethodName;

   if(mode == "edit")
   {
      url += "&type=" + type + "&volume=" + volume + "&path=" + path;
   }
   var w = window.open(url,"MultiValuedPath_Editor", params);
}

function addMVPathItem()
{
   openMVPathPopup("add", "returnFromAdd");
}

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

function editMVPathItem()
{
   var sel = document.forms[0].MultiValuedPath_Editor;
   editingIndex = sel.selectedIndex;
   if(editingIndex == -1){
   	alert(selectToEdit);
   	return;
   }
   var list = unpack(sel.value);
   openMVPathPopup("edit", "returnFromEdit", list[0], list[1], list[2]);
}

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

   var list = unpack(packedMVPath);
   var displayMVPath = list[1] + " - " + list[2];
   var sel = document.forms[0].MultiValuedPath_Editor;
   sel.options[sel.options.length] = new Option(displayMVPath, packedMVPath);
   displayMVPath = list[0] + " - " + list[1]  + " - " + list[2];
   sel.options[sel.options.length-1].value = packedMVPath;
}

function returnFromEdit(packedMVPath)
{
   if(editingIndex<0) return;
   if(packedMVPath==null || packedMVPath.length==0) return;

   var list = unpack(packedMVPath);
   var displayMVPath = list[1] + " - " + list[2];
   var sel = document.forms[0].MultiValuedPath_Editor;
   sel.options[editingIndex] = new Option(displayMVPath, packedMVPath);
   displayMVPath = list[0] + " - " + list[1]  + " - " + list[2];
   sel.options[editingIndex].value = packedMVPath;
}