
function upMultiSelectControl()
{
	this.upType = "upMultiSelectControl";
	this.styleType = "Listbox";	
	this.min = "1";
	this.oHtmlNotSel = null;
	this.aFixEntries = new Array();
	this.oHtmlSel = null;
	this.oHtmlOut = null;
	this.moveOpt = MultiSelectMoveOpt;
	this._select = MultiSelect_Select;
	this._deSelect = MultiSelect_DeSelect;
	this.select = MultiSelectSelect;
	this.deSelect = MultiSelectDeSelect;
	this.moveUp = MultiSelectMoveUp;
	this.moveDown = MultiSelectMoveDown;
	this._moveUp = MultiSelect_MoveUp;
	this._moveDown = MultiSelect_MoveDown;
	this.toOutputString = MultiSelectToOutputString;
	this.validateRequiredDo = MultiSelectValidateRequiredDo;
}
upMultiSelectControl.prototype = new upDataControl();
function MultiSelectMoveUp()
{
	if(this.oHtmlSel && this.oHtmlSel != null && this.oHtmlSel.options)
	{
		if(this.oHtmlSel.options.selectedIndex > -1)
		{
			this._moveUp(this.oHtmlSel);
		}
	}
}
function MultiSelectMoveDown()
{
	if(this.oHtmlSel && this.oHtmlSel != null && this.oHtmlSel.options)
	{
		if(this.oHtmlSel.options.selectedIndex > -1)
		{
			this._moveDown(this.oHtmlSel);
		}
	}
}
function MultiSelect_MoveUp(colbox)
{
	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 MultiSelect_MoveDown(colbox)
{
	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 MultiSelectMoveOpt(oSource, oTarget)
{
	var firstSelected = "";
	var selected = "";
	var optNew = null;
	firstSelected = oSource.selectedIndex ;
	if(firstSelected == -1)
	{
		alert(self.oUp.oMessage.MULTI_SEL_NO_SELECT);
		return true;
	}
	while(oSource.selectedIndex != -1)
	{
		indSelected = oSource.selectedIndex;
		if(indSelected == -1)
			break;
		optNew = new Option(oSource.options[indSelected].text,oSource.options[indSelected].value);
		oTarget.options[oTarget.length] = optNew;
		oSource.options[indSelected] = null;
	}
	return true;
}
function MultiSelect_Select()
{	
	this.moveOpt(this.oHtmlNotSel, this.oHtmlSel);
}
function MultiSelect_DeSelect()
{
	this.moveOpt(this.oHtmlSel, this.oHtmlNotSel);
}
function MultiSelectSelect()
{	
	this._select();
	this.toOutputString();	
}
function MultiSelectDeSelect()
{
	this._deSelect();
	this.toOutputString();	
}
function MultiSelectToOutputString()
{
	if(this.oHtmlOut && this.oHtmlOut != null)
	{
		var strOut = "";
		var aOptions = new Array();
		for(var i=0; i < this.oHtmlSel.options.length; i++)
		{
			aOptions[aOptions.length] = this.oHtmlSel.options[i].value;
		}
		for(var j=0; j < this.aFixEntries.length; j++)
		{
			aOptions[aOptions.length] = this.aFixEntries[j];
		}
		this.oHtmlOut.value = Helper.doCharStuffing(aOptions);
		return true;
	}
	else
	{
		return false;
	}
}
function MultiSelectValidateRequiredDo()
{
	if (this.oHtmlSel.options.length < this.min)
	{
		return false;
	}
	return true;
}
function upDistributeControl()
{
	this.upType = "upDistributeControl";
}	
upDistributeControl.prototype = new upMultiSelectControl();
function upDistributeParticipantsControl()
{
	this.upType = "upDistributeParticipantsControl";
}	
upDistributeParticipantsControl.prototype = new upMultiSelectControl();
function upDistributorControl()
{
	this.upType = "upDistributorControl";
}	
upDistributorControl.prototype = new upMultiSelectControl();
function upDistributeOrgUnitsControl()
{
	this.upType		= "upDistributeOrgUnitsControl";
	this.aOrgUnits	= new Array();
	this.setOrgUnit = funcSetOrgUnit;
	this.getOrgUnit = funcGetOrgUnit;
	this.moveOpt	= MultiSelectMoveOptOrgUnit;
}	
upDistributeOrgUnitsControl.prototype = new upMultiSelectControl();
function funcSetOrgUnit(p_strId, p_bHasRight)
{
	if(p_strId)
	{
		this.aOrgUnits[p_strId] = new Array();
		this.aOrgUnits[p_strId]['hasRight'] = p_bHasRight;
	}
}
function funcGetOrgUnit(p_strId)
{
	this.hasRight = funcHasRight;
	if(p_strId)
	{
		this.id			= p_strId;
		this.orgUnit	= this.aOrgUnits[p_strId];
		return this.aOrgUnits[p_strId];
	}
	else
	{
		this.id			= null;
		this.orgUnit	= null;
		return null;
	}
}
function funcHasRight()
{
	return this.orgUnit['hasRight'];
}
function MultiSelectMoveOptOrgUnit(oSource, oTarget)
{
	var firstSelected = "";
	var selected = "";
	var optNew = null;
	var msgNotMoved = "";
	firstSelected = oSource.selectedIndex ;
	if(firstSelected == -1)
	{
		alert(self.oUp.oMessage.MULTI_SEL_NO_SELECT);
		return true;
	}
	while(oSource.selectedIndex != -1)
	{
		indSelected = oSource.selectedIndex;
		if(indSelected == -1)
			break;
		optNew = new Option(oSource.options[indSelected].text,oSource.options[indSelected].value);
		if(this.getOrgUnit(oSource.options[indSelected].value)!=null && this.getOrgUnit(oSource.options[indSelected].value).hasRight)
		{
			oTarget.options[oTarget.length] = optNew;
			oSource.options[indSelected] = null;
		}
		else
		{
			oSource.options[indSelected].selected = false;
			msgNotMoved += "\t" + oSource.options[indSelected].text + "\n";
		}
	}
	if(msgNotMoved!="")
		alert(self.oUp.oMessage.MULTI_SEL_NOTMOVED + "\n\n" + msgNotMoved)
	return true;
}
function upFlipFlopControl()
{
	this.upType             = "upFlipFlopControl";
	this.bUsePictures       = 1;
	this.bCookieOnOpenState = true;
	this.pathOpenPic        = './images/assets/navigation/opened.gif';
	this.pathClosePic       = './images/assets/navigation/closed.gif';
	this.bUseLastFlop       = 0;
	this.sPreSub            = null;
	this.sPrePic            = null;
	this.iLastId            = -1;
	this.isCookie           = Helper.isCookieEnabled();
	this.aFlipStatus        = new Array();
	if (document.layers)
	{
		this.visible  = 'show';
		this.hidden   = 'hide';
	}
	else if (document.all || document.getElementById)
	{
		this.visible  = 'visible';
		this.hidden   = 'hidden';
	}
	this._picOpen   = FFpicOpen;
	this._picClose  = FFpicClose;
	this.flipAll    = FFlipAll;
	this.flopAll    = FFlopAll;
	this.flipFlop   = FFlipFlop;
	this.onlyFlip   = FFonlyFlip;
	this._lastFlop  = FFlastFlop;
	this._flip      = FFlip;
	this._flop      = FFlop;
	this._setCookie = FSetCookie;
	this.getStatus	= FFgetStatus;
}
function FFgetStatus(Id)
{
	subId = this.sPreSub + Id;
	subObject = Browser.getRef(subId);
	if (subObject.style.display == "block") 
		return "open"
	else
		return "closed"
}
function FFpicOpen(Id)
{
	picId = this.sPrePic + Id;
	Browser.getRef(picId).src = this.pathOpenPic;
}
function FFpicClose(Id)
{
	picId = this.sPrePic + Id;
	Browser.getRef(picId).src = this.pathClosePic;
}
function FFlipAll()
{
	if (this.bUseLastFlop == 0)
	{
		for (var Id in this.aFlipStatus)
		{
			subId = this.sPreSub + Id;
			Browser.getRef(subId).style.display = "block";
			Browser.getRef(subId).style.visibility = this.visible;
			if (this.bUsePictures) this._picOpen(Id);
			this._setCookie(Id,true);
			this.aFlipStatus[Id] = true;
		}
	}
}
function FFlopAll()
{
	if (this.bUseLastFlop == 0)
	{
		for (var Id in this.aFlipStatus)
		{
			subId = this.sPreSub + Id;
			Browser.getRef(subId).style.display = "none";
			Browser.getRef(subId).style.visibility = this.hidden;
			if (this.bUsePictures) this._picClose(Id);
			this._setCookie(Id,false);
			this.aFlipStatus[Id] = false;
		}
	}
}
function FFlipFlop(Id)
{
	subId = this.sPreSub + Id;
	subObject = Browser.getRef(subId);
	if (subObject.style.display == "block") this._flop(subObject,Id);
	else this._flip(subObject,Id);
	this.iLastId = Id;
	return void(0);
}
function FFonlyFlip(Id)
{
	subId = this.sPreSub + Id;
	subObject = Browser.getRef(subId);
	if (subObject.style.display != "block") this._flip(subObject,Id);
	this.iLastId = Id;
	return void(0);
}
function FFlastFlop(Id)
{
	subId = this.sPreSub + Id;
	subObject = Browser.getRef(subId);
	if (subObject.style.display == "block") this._flop(subObject,Id);
}
function FFlip(subObj,Id)
{
	subObj.style.display = "block";
	subObj.style.visibility = this.visible;
	this.aFlipStatus[Id] = true;
	this._setCookie(Id,true);
	if (this.bUsePictures) this._picOpen(Id);
	if ((this.bUseLastFlop == 1) && (this.iLastId != Id) && (this.iLastId > -1))
	{
		this._lastFlop(this.iLastId);
	}
}
function FFlop(subObj,Id)
{
	subObj.style.display = "none";
	subObj.style.visibility = this.hidden;
	this.aFlipStatus[Id] = false;
	this._setCookie(Id,false);
	if (this.bUsePictures) this._picClose(Id);
}
function FSetCookie(p_strId,p_bOpen)
{	
	if(!this.isCookie)
		return;
	var l_bSet = false;
	if(p_bOpen && this.bCookieOnOpenState)
		l_bSet = true;
	else if(!p_bOpen && !this.bCookieOnOpenState)
	    l_bSet = true;
	if(l_bSet)	
	{	
		Helper.setCookie("co_" + p_strId,"1","0");
	}
	else
	{
		if(Helper.getCookieValueByParam("co_" + p_strId) != false)
			Helper.deleteCookie("co_" + p_strId);
	}
	return;
}
