
var colArray = new Array();
var colbox=null;
var oColPool=null;
nn4 = (document.layers)? true:false
ie4 = (document.all)? true:false
function init()
{
	if(document.forms[0])
	{
		k=0;
		isFirst=true;
		for(j=0; j < document.forms[0].elements.length; j++)
		{
			elem=document.forms[0].elements[j];
			if(elem.type.toLowerCase().indexOf("select")!=-1 && elem.name!="colPool" && elem.name!="fr_colCount" && elem.name!="fr_Templates" && elem.name!="fr_noindex" )
			{
				colArray[k]=elem;
				if (isFirst)
				{
					colbox=elem;
					isFirst=false;
				}
				k=k+1;
			}
		}
		oColPool=document.forms[0].colPool;
	}
  }
function setCol(oColBox)
{
   if (colbox!=oColBox)
   {
      if(colbox!=null && colbox.selectedIndex != -1)
      {
         index = colbox.selectedIndex;
         colbox.selectedIndex = -1;
      }
      colbox= oColBox;
   }
}
function prepareSubmit()
{
   if(document.forms[0].fr_colCount)
		var l_colCount = document.forms[0].fr_colCount.value;
   else
		var l_colCount = colArray.length;
   for(col=0; col<colArray.length; col++)
   {
	  if(col >= l_colCount)
	  {
	  	colNr = l_colCount;
	  }
	  else
	  {
		colNr = col + 1;
	  }
	  var dataField = document.forms[0].elements[colArray[col].name]
	  var dataFieldOut = document.forms[0].elements[colArray[col].name+'Out']
	  var strOut = "";
	  for(k=0; k<dataField.options.length; k++)
      {
        strOut += ('(' + dataField.options[k].value + ',' + colNr + ',' + (k+1) + ')');
      }  
      dataFieldOut.value = strOut;
   }
}
function prepareSubmitAdd()
{
   var l_colNr = document.forms[0].fr_colNr.value;
   for(col=0; col<colArray.length; col++)
   {
	  if(colArray[col].name=='poolPlt')
	  {
		colNr = 0;
	  }
	  else
	  {
		colNr = l_colNr;
	  }
	  var dataField = document.forms[0].elements[colArray[col].name]
	  var dataFieldOut = document.forms[0].elements[colArray[col].name+'Out']
	  var strOut = "";
	  for(k=0; k<dataField.options.length; k++)
      {
		var l_strPltValue = dataField.options[k].value;
		var l_aPltValue = l_strPltValue.split("|");
		switch(l_aPltValue.length) {
		case 2:
				var l_strPltGuid = l_aPltValue[0];
				break;
		case 1:
				var l_strPltGuid = l_aPltValue[0];
				break;
		default:
				var l_strPltGuid = l_strPltValue;
				break;
		}
        strOut += ('(' + l_strPltGuid + ',' + colNr + ',' + (k+1) + ')');
      }  
      dataFieldOut.value = strOut;
   }
}
function insert(strTxt, strValue, intPos)
{
   pos=colbox.selectedIndex;
   len=colbox.length;
   posNew=len;
   if (strTxt==null) return false;
   if (strValue==null) return false;
   if (pos==-1)
   {
      if(intPos==null || intPos>=len || intPos<0)
      {
        posNew=len;
        pos=len;
      }
      else
      {
        pos=intPos-1;
        posNew=pos+1;
      }
   }
   else posNew= pos+1;
   newEntry = new Option();
   colbox.options[len]= newEntry;
   for(i=len; i>pos; i--)
   {
       if (i==0) break;
       colbox.options[i].text=colbox.options[i-1].text;
       colbox.options[i].value=colbox.options[i-1].value;
   }
   colbox.options[posNew].text=strTxt;
   colbox.options[posNew].value= strValue;
   colbox.options[posNew].selected=true;
}
function remove()
{
   pos=colbox.selectedIndex;
   len=colbox.length;
   if (len==0) return;
   if (pos==-1) return;
   posNew=pos;
   if (pos==len-1) posNew=pos-1;
   else posNew=pos;
   for(i=pos; i<len-1; i++)
   {
       colbox.options[i].text=colbox.options[i+1].text;
       colbox.options[i].value=colbox.options[i+1].value;
   }
   colbox.options[len-1]=null;
   if (colbox.length>0) colbox.options[posNew].selected=true;
   return true;
}
function addToPortal(intAddToCol)
{
   if(intAddToCol==null || intAddToCol=="") intAddToCol=0;
   colbox=oColPool;
   pos=colbox.selectedIndex;
   len=colbox.length;
   if (pos==-1) return;
   strTxt=colbox.options[pos].text;
   strValue=colbox.options[pos].value;
   remove();
   colbox.selectedIndex=-1;
   colbox=colArray[intAddToCol];
   insert(strTxt, strValue, -1);
}
function removeFromPortal()
{
   pos=colbox.selectedIndex;
   len=colbox.length;
   if (pos==-1) return;
   strTxt=colbox.options[pos].text;
   strValue=colbox.options[pos].value;
   remove();
   colbox.selectedIndex=-1;
   colbox= oColPool;
   insert(strTxt, strValue, -1);
}
function moveLeft()
{
   pos=colbox.selectedIndex;
   len=colbox.length;
   colIndex=0;
   colIndexNew=0;
   if (pos==-1) return;
   if (colbox==oColPool) return;
   for(i=0; i<colArray.length;i++)
   {
      if (colArray[i]==colbox)
      {
         colIndex=i;
         break;
      }
   }
   if (colIndex==0) colIndexNew= colArray.length-1;
   else colIndexNew= colIndex-1;
   strTxt=colbox.options[pos].text;
   strValue=colbox.options[pos].value;
   remove();
   setCol(colArray[colIndexNew])
   insert(strTxt, strValue, pos);
}
function moveRight()
{
   pos=colbox.selectedIndex;
   len=colbox.length;
   colIndex=0;
   colIndexNew=0;
   if (pos==-1) return;
   if (colbox==oColPool) return;
   for(i=0; i<colArray.length;i++)
   {
      if (colArray[i]==colbox)
      {
         colIndex=i;
         break;
      }
   }
   if (colIndex==colArray.length-1) colIndexNew= 0;
   else colIndexNew= colIndex+1;
   strTxt=colbox.options[pos].text;
   strValue=colbox.options[pos].value;
   remove();
   setCol(colArray[colIndexNew])
   insert(strTxt, strValue, pos);
}
function moveUp()
{
   pos=colbox.selectedIndex;
   len=colbox.length;
   posNew=0;
   if (pos==-1) return;
   if (colbox==oColPool) return;
   textTmp=colbox.options[pos].text;
   valueTmp=colbox.options[pos].value;
   if (pos==0)
   {
     posNew=len-1;
     for(k=1; k<colbox.length; k++)
     {
       colbox.options[k-1].text=colbox.options[k].text;
       colbox.options[k-1].value=colbox.options[k].value;
     }
   }
   else
   {
     posNew= pos-1;
     colbox.options[pos].text=colbox.options[posNew].text;
     colbox.options[pos].value=colbox.options[posNew].value;
   }
   colbox.options[posNew].text=textTmp;
   colbox.options[posNew].value=valueTmp;
   colbox.options[posNew].selected=true;
}
function moveDown()
{
   pos=colbox.selectedIndex;
   len=colbox.length;
   posNew=0;
   if (pos==-1) return;
   if (colbox==oColPool) return;
   textTmp=colbox.options[pos].text;
   valueTmp=colbox.options[pos].value;
   if (pos==len-1)
   {
     posNew=0;
     for(k=colbox.length-2; k>=0; k--)
     {
       colbox.options[k+1].text=colbox.options[k].text;
       colbox.options[k+1].value=colbox.options[k].value;
     }
   }
   else
   {
     posNew= pos+1;
     colbox.options[pos].text=colbox.options[posNew].text;
     colbox.options[pos].value=colbox.options[posNew].value;
   }
   colbox.options[posNew].text=textTmp;
   colbox.options[posNew].value=valueTmp;
   colbox.options[posNew].selected=true;
}
function moveRightMultiple()
{
   pos=colbox.selectedIndex;
   if (pos==-1) return;
   if (colbox==oColPool) return;
   for(i=0; i<colArray.length;i++)
   {
      if (colArray[i]==colbox)
      {
         colIndex=i;
         break;
      }
   }
   if (colIndex==colArray.length-1) colIndexNew= 0;
   else colIndexNew= colIndex+1;
   var l_aSelected = new Array();
	for(i=0;i<colbox.options.length;i++)
	{
		if(colbox.options[i].selected)
		{
			strTxt=colbox.options[i].text;
			strValue=colbox.options[i].value;
			l_aSelected[l_aSelected.length] = new Array(strValue,strTxt);
		}
	}
   removeMultiple();
   setCol(colArray[colIndexNew])
   insertMultiple(l_aSelected);
}
function moveLeftMultiple()
{
   pos=colbox.selectedIndex;
   if (pos==-1) return;
   if (colbox==oColPool) return;
   for(i=0; i<colArray.length;i++)
   {
      if (colArray[i]==colbox)
      {
         colIndex=i;
         break;
      }
   }
	if (colIndex==0) colIndexNew= colArray.length-1;
	 else colIndexNew= colIndex-1;
   var l_aSelected = new Array();
	for(i=0;i<colbox.options.length;i++)
	{
		if(colbox.options[i].selected)
		{
			strTxt=colbox.options[i].text;
			strValue=colbox.options[i].value;
			l_aSelected[l_aSelected.length] = new Array(strValue,strTxt);
		}
	}
   removeMultiple();
   setCol(colArray[colIndexNew])
   insertMultiple(l_aSelected);
}
function moveUpMultiple()
{
	pos=colbox.selectedIndex;
	len=colbox.length;
	posNew=0;
	if (pos==-1) return;
	if (colbox==oColPool) return;
	var l_aRemove = new Array();
	var l_aOption = new Array();
	var l_aOptions = new Array();
	if(!colbox.options[0].selected)
	{
		l_bLastOptIsSelected = false;
		for(i=colbox.options.length-1;i>=0;i--)
		//for(i=0;i<colbox.options.length;i++)
		{
			if(colbox.options[i].selected)
			{
				if(i==colbox.options.length-1)
					l_bLastOptIsSelected = true;
				if(i==0)
				{
					l_bLast = true;
					newPos = colbox.options.length-1;
				}
				else
				{
					l_bLast = false;
					newPos = i-1;
				}
				l_aRemove[l_aRemove.length] = i;
				var l_aOption = new Array();
				l_aOption[0] = newPos;
				l_aOption[1] = colbox.options[i].value;
				l_aOption[2] = colbox.options[i].text;
				l_aOption[3] = l_bLast;
				l_aOptions[l_aOptions.length] = l_aOption;
			}
		}
		for(i=0;i<l_aRemove.length;i++)
		{
			colbox.options[l_aRemove[i]] = null;
		}
		for(i=l_aOptions.length-1;i>=0;i--)
		//for(i=0;i<l_aOptions.length;i++)
		{
			posNew = l_aOptions[i][0];
			if(posNew > colbox.options.length)
				posNew = colbox.options.length;
			else if(!l_aOptions[i][3] && posNew == colbox.options.length)
				posNew--;
			if(posNew < colbox.options.length)
			{	
				for(k=colbox.options.length-1;k>=posNew;k--)
				{
					value = colbox.options[k].value;
					text = colbox.options[k].text;
					selected = colbox.options[k].selected;
					newEntry = new Option();
					//alert("move: " + value );
					colbox.options[k+1]= newEntry;
					colbox.options[k+1].text=text;
					colbox.options[k+1].value= value;
					colbox.options[k+1].selected= selected;
				}
			}
			newEntry = new Option();
			colbox.options[posNew]= newEntry;
			colbox.options[posNew].text=l_aOptions[i][2];
			colbox.options[posNew].value= l_aOptions[i][1];
			colbox.options[posNew].selected=true;
		}
	}
}
function moveDownMultiple()
{
	pos=colbox.selectedIndex;
	len=colbox.length;
	posNew=0;
	if (pos==-1) return;
	if (colbox==oColPool) return;
	var l_aRemove = new Array();
	var l_aOption = new Array();
	var l_aOptions = new Array();
	//for(i=colbox.options.length-1;i>=0;i--)
	if(!colbox.options[colbox.options.length-1].selected)
	{	
		for(i=0;i<colbox.options.length;i++)
		{
			if(colbox.options[i].selected)
			{
				if(i==(colbox.options.length-1))
					newPos = 0;
				else
					newPos = i+1;
				l_aRemove[l_aRemove.length] = i;
				var l_aOption = new Array();
				l_aOption[0] = newPos;
				l_aOption[1] = colbox.options[i].value;
				l_aOption[2] = colbox.options[i].text;
				l_aOptions[l_aOptions.length] = l_aOption;
			}
		}
		//for(i=0;i<l_aRemove.length;i++)
		for(i=l_aOptions.length-1;i>=0;i--)
		{
			colbox.options[l_aRemove[i]] = null;
		}
		//for(i=l_aOptions.length-1;i>=0;i--)
		for(i=0;i<l_aOptions.length;i++)
		{
			posNew = l_aOptions[i][0];
			if(posNew > colbox.options.length)
				posNew = colbox.options.length;
			if(posNew <= colbox.options.length)
			{	
				for(k=colbox.options.length-1;k>=posNew;k--)
				{
					value = colbox.options[k].value;
					text = colbox.options[k].text;
					selected = colbox.options[k].selected;
					newEntry = new Option();
					//alert("move: " + value );
					colbox.options[k+1]= newEntry;
					colbox.options[k+1].text=text;
					colbox.options[k+1].value= value;
					colbox.options[k+1].selected= selected;
				}
			}
			newEntry = new Option();
			colbox.options[posNew]= newEntry;
			colbox.options[posNew].text=l_aOptions[i][2];
			colbox.options[posNew].value= l_aOptions[i][1];
			colbox.options[posNew].selected=true;
		}
	}
}
function moveDown()
{
   pos=colbox.selectedIndex;
   len=colbox.length;
   posNew=0;
   if (pos==-1) return;
   if (colbox==oColPool) return;
   textTmp=colbox.options[pos].text;
   valueTmp=colbox.options[pos].value;
   if (pos==len-1)
   {
     posNew=0;
     for(k=colbox.length-2; k>=0; k--)
     {
       colbox.options[k+1].text=colbox.options[k].text;
       colbox.options[k+1].value=colbox.options[k].value;
     }
   }
   else
   {
     posNew= pos+1;
     colbox.options[pos].text=colbox.options[posNew].text;
     colbox.options[pos].value=colbox.options[posNew].value;
   }
   colbox.options[posNew].text=textTmp;
   colbox.options[posNew].value=valueTmp;
   colbox.options[posNew].selected=true;
}
function removeMultiple()
{
	for(i=colbox.length-1; i>=0;i--)
	{
		if(colbox.options[i].selected)
		{
			colbox.options[i] = null;
		}
	}
   return true;
}
function insertMultiple(p_aSelected)
{
	for(k=0;k<p_aSelected.length;k++)
	{
		if(p_aSelected[k].length == 2)
		{
			newEntry = new Option();
			posNew = colbox.options.length;
			colbox.options[posNew]= newEntry;
			colbox.options[posNew].text=p_aSelected[k][1];
			colbox.options[posNew].value= p_aSelected[k][0];
			colbox.options[posNew].selected=true;
		}
	}
}
function setLinkNewsApp(p_IdAction, p_TargetID, p_AppID, p_RecID, p_NewsID, p_bUsePopup, p_oForm, p_oHidden, p_MarkUrl)
{
	oAction = new upTextActionControl();
	oAction = oAction.biDirectUpHtml(oAction, p_IdAction);
	oAction.oFup = oFUP_Portal;		
	oAction.oTarget = new upTarget();
	oAction.oTarget.rq_TargetId = p_TargetID;
	oAction.oTarget.rq_AppId = p_AppID;
	oAction.oTarget.rq_RecId = p_RecID;
	if(p_bUsePopup)
	{
		oAction.oTarget.newWindow = "1";
		oAction.oTarget.rq_Template ="internal/layout/vm/html/frames/popup.vm";
		oAction.oTarget.windowSettings="500,300,100,100,0,FUP_Portal";
		oAction.oTarget.rq_TargetFrame = "wndNewsPage";
	}
	else
	{
		oAction.oTarget.newWindow = "0";
		oAction.oTarget.rq_LevelCount = "0";
		oAction.oTarget.rq_Template = "internal/layout/vm/html/frames/stage.vm";
		oAction.oTarget.rq_TargetFrame = self.oUp.oRootWin.Stage;
	}
	if(!p_bUsePopup)
		oAction.setMenu();
	doMarkNewsAsRead(p_MarkUrl, p_NewsID, p_oForm, p_oHidden);
	oAction.processRequest();
}
function setLinkAppRecord(p_IdAction, p_TargetID, p_AppID, p_RecID, p_bUsePopup)
{
	oAction = new upTextActionControl();
	oAction = oAction.biDirectUpHtml(oAction, p_IdAction);
	oAction.oFup = oFUP_Portal;
	oAction.oTarget = new upTarget();
	oAction.oTarget.rq_TargetId = p_TargetID;
	oAction.oTarget.rq_AppId = p_AppID;
	oAction.oTarget.rq_RecId = p_RecID;
	if(p_bUsePopup)
	{
		oAction.oTarget.newWindow = "1";
		oAction.oTarget.rq_Template ="internal/layout/vm/html/frames/popup.vm";
		oAction.oTarget.windowSettings="500,300,100,100,0,FUP_Portal";
		oAction.oTarget.rq_TargetFrame = "wndAppRecord";
	}
	else
	{
		oAction.oTarget.newWindow = "0";
		oAction.oTarget.rq_LevelCount = "0";
		oAction.oTarget.rq_Template = "internal/layout/vm/html/frames/stage.vm";
		oAction.oTarget.rq_TargetFrame = self.oUp.oRootWin.Stage;
	}
	if(!p_bUsePopup)
		oAction.setMenu();
	oAction.processRequest();
}
function setLinkNews(p_IdAction, p_NewsID, p_bUsePopup, p_bReload, p_strNewsFile, p_strFup)
{
	oAction = new upTextActionControl();
	oAction = oAction.biDirectUpHtml(oAction, p_IdAction);
	oAction.oFup = oFUP_Portal;
	oAction.oTarget = new upTarget();
	oAction.oTarget.addParam = Helper.setQsValueByParam("rq_NewsId",p_NewsID,oAction.oTarget.addParam);
	oAction.oTarget.addParam = Helper.setQsValueByParam("rq_ActionId","1", oAction.oTarget.addParam);
	oAction.oTarget.addParam = Helper.setQsValueByParam("rq_FupId",p_strFup, oAction.oTarget.addParam);
	if(p_bReload)
		oAction.oTarget.addParam = Helper.setQsValueByParam("rq_Reload","1", oAction.oTarget.addParam);
	else
		oAction.oTarget.addParam = Helper.setQsValueByParam("rq_Reload","0", oAction.oTarget.addParam);
	if(p_bUsePopup)
	{
		oAction.oTarget.newWindow = "1";
		oAction.oTarget.rq_Template ="internal/layout/vm/html/frames/popup.vm";
		oAction.oTarget.addParam = Helper.setQsValueByParam("rq_LoadStaticVm", p_strNewsFile, oAction.oTarget.addParam);
		oAction.oTarget.windowSettings="500,300,100,100,0,FUP_Portal";
		oAction.oTarget.rq_TargetFrame = "wndNewsPage";
	}
	else
	{
		oAction.oTarget.addParam = Helper.setQsValueByParam("rq_Vm", p_strNewsFile, oAction.oTarget.addParam);
		oAction.oTarget.newWindow = "0";
		oAction.oTarget.rq_LevelCount = "0";
		oAction.oTarget.rq_Template = "internal/layout/vm/html/frames/include.vm";
		oAction.oTarget.rq_TargetFrame = self.oUp.oRootWin.Stage;
	}
	oAction.processRequest();
}
function prepareSubmitLstCharStuffing( p_oSelect, p_bText)
{
	var aOptions = new Array();
	for(k=0; k<p_oSelect.options.length; k++)
	{
		if(p_oSelect.options[k].selected)
		{
			if(typeof p_bText == "undefined" || p_bText == false)
				aOptions[aOptions.length] = p_oSelect.options[k].value;
			else
				aOptions[aOptions.length] = p_oSelect.options[k].text;
		}
	}  
	return Helper.doCharStuffing(aOptions);
}
function getNumberOfSelectedItems(p_oSelect)
{
	if(p_oSelect.selectedIndex==-1)
	{
		return -1;
	}
	else
	{
		var l_lCount = 0;
		for(k=0; k<p_oSelect.options.length; k++)
		{
			if(p_oSelect.options[k].selected)
				l_lCount++;
		}  
	}
	return l_lCount;
}
var aPushPop = new Array();
aPushPop[0] = new Array();
function doPushPopInit()
{
	var l_lNewID = aPushPop.length;
	aPushPop[l_lNewID] = new Array();
	return l_lNewID;
} 
function doPushPop(p_lID, p_strName, p_strValue)
{
	if(p_lID != "" && p_strName != "")
	{
		aPushPop[p_lID][p_strName] = p_strValue
	}
}
function getPushPopAsString(p_lID, p_strValue)
{
	if(aPushPop[p_lID])
	{
		var l_strOut = '';
		var l_bAdd = false;
		for (var Member in aPushPop[p_lID])
		{
			l_bAdd = false;
			if(p_strValue != null)
			{
				if(aPushPop[p_lID][Member] == p_strValue)
					l_bAdd = true;
			}
			else
			{
				l_bAdd = true;
			}
			if(l_bAdd)
			{
				if(l_strOut != '')
					l_strOut += '||';
				l_strOut += Member;
			}
		}
		return l_strOut;
	 }
	 else
	 {
	  return "";
	 }
}
function setLinkFav(p_IdAction, p_PageId, p_AppId, p_strUrl)
{
	if(p_PageId==null)
		p_PageId = "-1";
	oAction = new upTextActionControl();
	oAction = oAction.biDirectUpHtml(oAction, p_IdAction);
	oAction.oFup = oFUP_Portal;
	oAction.oTarget = new upTarget();
	if(p_strUrl && p_strUrl != "")
	{
		strUrl = Helper.hexDecodeString(p_strUrl);
		oAction.oTarget.externalUrl = strUrl;
	}
	oAction.oTarget.rq_TargetId = p_PageId;
	oAction.oTarget.rq_AppId = p_AppId;
	oAction.oTarget.rq_LevelCount = "0";
	oAction.oTarget.rq_TargetFrame = self.oUp.oRootWin.Stage
	oAction.oTarget.rq_Template = "internal/layout/vm/html/frames/stage.vm";
	oAction.setMenu();
	oAction.processRequest();
}
function doMarkNewsAsRead(p_strUrl, p_strNews, p_oForm, p_oField)
{
	if(p_strUrl!='')
	{
		p_oField.value = p_strNews;
		p_oForm.target = "hiddenFrame";
		p_oForm.action = p_strUrl;
		p_oForm.submit();
	}
}
function setLinkPltConfig_FromPrtCfg(p_oButton, p_bReload)
{
	if(typeof p_bReload == 'undefined')
		p_bReload = true;
	pos=colbox.selectedIndex;
	len=colbox.length;
	colIndex=0;
	colIndexNew=0;
	if (pos==-1) return;
	if (colbox==oColPool) return;
	for(i=0; i<colArray.length;i++)
	{
		if (colArray[i]==colbox)
		{
			colIndex=i;
			break;
		}
	}
	if (colIndex==colArray.length-1) colIndexNew= 0;
	else colIndexNew= colIndex+1;
	var l_strPltValue = colbox.options[pos].value;
	var l_aPltValue = l_strPltValue.split("|");
	switch(l_aPltValue.length) {
	case 2:
			var l_strPltGuid = l_aPltValue[0];
			break;
	case 1:
			var l_strPltGuid = l_aPltValue[0];
			break;
	default:
			var l_strPltGuid = l_strPltValue;
			break;
	}	
    l_strConfigFile = g_aPltConfigFiles[l_strPltGuid];
	setLinkPltConfig(p_oButton.id, l_strPltGuid, l_strConfigFile, null, p_bReload);
}

