
// should be called everytime list content is changed
function mvtxtOnChange(mvse)
{
   var list = getValuesAsArray(mvse);
   document.form.elements[mvse.m_name+"_packedValues"].value = pack(list);

   mvCallOnChange(mvse);
}

function mvtxtLoadFromPack(name, str)
{
   var l = getMvtxt(name);
   var list = unpack(str);
   for(i in list) l[i]=list[i];
   setMvtxt(name,l);
   mvtxtUpdateTextbox(name);
}

function mvtxtGetValuesAsPack(name)
{
   var l = getMvtxt(name);
   return pack(l);
}

function getMvtxt(name)
{
   var l=unpack(eval("document.forms[0].__"+name).value);
   return(l!=null? l: new Array())
}

function setMvtxt(name, list)
{
   eval("document.forms[0].__"+name).value=pack(list);
}

function mvtxtReturnFromOS(name, results)
{
   var l=getMvtxt(name);
   for(var i=0; results.length>i; i++)
   {
      l[l.length] = results[i];
   }

   setMvtxt(name,l);
   mvtxtUpdateTextbox(name);
}


function mvtxtAdd(name)
{
   var val = prompt(rc_enterValue, "");
   var l=getMvtxt(name);

   if(val && val.length>0)
      l[l.length] = val;

   setMvtxt(name,l);
   mvtxtUpdateTextbox(name);
}

function mvtxtRemove(name)
{
   var l=getMvtxt(name);

   if(l.length==0)
   {
      alert(rc_noValues);
      return;
   }

   var str = formatMessage(rc_.removePrompt, [l.length]);
   var index = prompt(str,"");

   if(index==null)
      return;

   index = Number(index);
   if(isNaN(index))
      return;

   index--;
   if(index>=0 && l.length>index)
   {
      for(var i=index; l.length>i; i++)
         l[i] = l[i+1];
      l.length--;
   }

   setMvtxt(name,l);
   mvtxtUpdateTextbox(name);
}

function mvtxtUpdateTextbox(name)
{
   var l = getMvtxt(name);
   var textbox = eval("document.forms[0]."+name);
   textbox.value = l.join("; ");
}
