function setDynaList(arrDL,strFrom)
{
	var oList1 = document.forms[arrDL[2]].elements[arrDL[1]];
	var oList2 = document.forms[arrDL[4]].elements[arrDL[3]];
	var oList3 = document.MyFORM.cboTop;
	var oList4 = document.MyFORM.cboUser;
	var arrList = arrDL[5];
	clearDynaList(oList2);
	 
	if (oList1.selectedIndex == -1)
	{
		oList1.selectedIndex = 0;
	}

	if (strFrom == 'Assign Users')
	{
		var oList5 = document.forms[arrDL[7]].elements[arrDL[6]];
		populateDynaList1(oList2, oList1[oList1.selectedIndex].value, oList5[oList5.selectedIndex].value, arrList,strFrom);
	}
	else
	{
		populateDynaList(oList2, oList1[oList1.selectedIndex].value, arrList,strFrom);
	}
	if (strFrom == "All Categories")
	{
		if (oList3.selectedIndex >= 0)
		{
			clearDynaList(oList3);
		}
		oList3.options[oList3.options.length] = new Option("All Topic",0);
	}
	return true;
}
 
function clearDynaList(oList)
{
	for (var i = oList.options.length; i >= 0; i--)
	{
		oList.options[i] = null;
	}
 
	oList.selectedIndex = -1;
}
 
function populateDynaList(oList, nIndex, aArray,strFrom)
{
	if (strFrom == 'All Status')
	{
		oList.options[oList.options.length] = new Option(TxtAllUserGroup,"ALL");
	}
	for (var i = 0; i < aArray.length; i= i + 3)
	{
		if (aArray[i] == nIndex)
		{
			oList.options[oList.options.length] = new Option(aArray[i + 1], aArray[i + 2]);
		}
	}
	oList.selectedIndex = 0;
}

function populateDynaList1(oList, nIndex, nStatus,aArray,strFrom)
{
	if (nIndex == "ALL")
	{
		for (var i = 0; i < aArray.length; i= i + 4)
		{
			if (nStatus == aArray[i+1])
			{
				oList.options[oList.options.length] = new Option(aArray[i + 2], aArray[i + 3]);
			}
		}
		oList.selectedIndex = 0;
	
	}
	else
	{
		for (var i = 0; i < aArray.length; i= i + 4)
		{
			if (aArray[i] == nIndex && nStatus == aArray[i+1])
			{
				oList.options[oList.options.length] = new Option(aArray[i + 2], aArray[i + 3]);
			}
		}
		oList.selectedIndex = 0;
	}
}

function populateStatus(oList, aArray1,aArray2,strFrom,strValue)
{
	//oList.options[oList.options.length] = new Option(strFrom,strValue);
	for (var i = 0; i < aArray1.length; i= i + 1)
	{
		oList.options[oList.options.length] = new Option(aArray2[i],aArray1[i]);
	}
	oList.selectedIndex = 0;
}

function PopulateNonPubLishedMain(objListBox,intCurrentValue)
{
	var intPosition	= 0;	
	clearStatus(objListBox);
	var StrValue	= "";
	for (var i = 0; i < aPrivilge.length; i++)
	{
		if (aPrivilge[i])
		{
			StrValue	= aPrivilge[i];
			aPublishedArray	= StrValue.split("|");
			if ((intCurrentValue != "") && (intCurrentValue == aPublishedArray[0]))
				intPosition	= objListBox.options.length;
			objListBox.options[objListBox.options.length] = new Option(aPublishedArray[1],aPublishedArray[0]);
		}
	}
	objListBox.selectedIndex = intPosition;
}

function PopulateUserGroup(StrFirstValue,StrCurrentValue)
{
	var objListBox	= document.forms[0].elements["cboRole"];
	clearStatus(objListBox);
	var StrPrivilValue	= document.MyFORM.cboStatus.options[document.MyFORM.cboStatus.selectedIndex].value;
	var StrValue	= "";
	var intSelectedIndex	= 0;
	objListBox.options[objListBox.options.length] = new Option(StrFirstValue,"ALL");
	objListBox.options[objListBox.options.length] = new Option("Administrator","0");
	var j	= 1;
	for (var i = 0; i < aRoleWorkingKnowledge.length; i++)
	{
		StrValue	= aRoleWorkingKnowledge[i];
		aPublishedArray	= StrValue.split("|");
		if (StrPrivilValue == parseInt(aPublishedArray[0]))
		{
			objListBox.options[objListBox.options.length] = new Option(aPublishedArray[2],aPublishedArray[1]);
			if (StrCurrentValue == aPublishedArray[1])
				intSelectedIndex	= j+1;
			j++;
		}
	}
	if (StrCurrentValue == 0)
		intSelectedIndex	= 1;

	objListBox.selectedIndex = intSelectedIndex;
}

function PopulateUsers(StrCurrentValue)
{
	var objListBox		= document.forms[0].elements["cboUser"];
	clearStatus(objListBox);
	var StrStatusValue		= document.MyFORM.cboStatus.options[document.MyFORM.cboStatus.selectedIndex].value;
	var StrUserGroupValue	= document.MyFORM.cboRole.options[document.MyFORM.cboRole.selectedIndex].value;
	var StrValue	= "";
	var intSelectedIndex	= 0;
	var j	= 1;
	intPrivilageID	= 1001;
	for (var i = 0; i < aPrivilgeSub.length; i++)
	{
		if (aPrivilgeSub[i])
		{
			StrValue			= aPrivilgeSub[i];
			aPrivilgeSubArray	= StrValue.split("|");
			if (aPrivilgeSubArray[0] == StrStatusValue)
			{
				intPrivilageID	= aPrivilgeSubArray[2];
				i = aPrivilgeSub.length + 1;
			}
		}
	}

	var StrMainLoopValue	= "";
	var StrLoopValue		= "";
	if ((StrUserGroupValue == "ALL") || (StrUserGroupValue == 0))
	{
		for (var j = 0; j < aUserUserGroup.length; j++)
		{
			StrUserValue		= aUserUserGroup[j];
			aUserUserGroupArray	= StrUserValue.split("|");
			if (aUserUserGroupArray[2] == 0)
			{
				StrLoopValue	= aUserUserGroupArray[1] + "~" + aUserUserGroupArray[0];
			}
			if (StrLoopValue != "")
			{
				if (StrMainLoopValue	!= "")
					StrMainLoopValue	= StrMainLoopValue + "|" + StrLoopValue;
				else
					StrMainLoopValue	= StrLoopValue;
			}
			StrLoopValue	= "";
		}
	}

	for (var i = 0; i < aUserWorkingKnowledge.length; i++)
	{
		StrValue		= aUserWorkingKnowledge[i];
		aPriVilArray	= StrValue.split("|");
		if (aPriVilArray[1] == intPrivilageID)
		{
			StrLoopValue		= "";			
			if ((aUserUserGroupLocal) && (aPriVilArray[0] <= aUserUserGroupLocal.length))
			{
				StrUserValue		= aUserUserGroupLocal[aPriVilArray[0]];
				aUserUserGroupArray	= StrUserValue.split("|");
				if ((StrUserGroupValue == "ALL") || (aUserUserGroupArray[2] == StrUserGroupValue))
				{
					StrLoopValue	= aUserUserGroupArray[1] + "~" + aUserUserGroupArray[0];
				}
				
				if (StrLoopValue != "")
				{
					if (StrMainLoopValue	!= "")
						StrMainLoopValue	= StrMainLoopValue + "|" + StrLoopValue;
					else
						StrMainLoopValue	= StrLoopValue;
				}
			}
		}
	}

	aMainLoopValue	= StrMainLoopValue.split("|");
	StrMainUcaseValue	= StrMainLoopValue.toUpperCase();
	aMainUCASEValue		= StrMainUcaseValue.split("|");
	aMainUCASEValue.sort();

	var nCount = 0;
	for (var j = 0; j < aMainUCASEValue.length; j++)
	{
		for (var i = 0; i < aMainLoopValue.length; i++)
		{
			StrValue	= aMainLoopValue[i];
			if (aMainUCASEValue[j] == StrValue.toUpperCase())
			{
				aMainUCASEValue[j]	= aMainLoopValue[i];

				StrMainLoopValue	= aMainLoopValue[i];
				aStrMainLoopValue	= StrMainLoopValue.split("~");
				objListBox.options[objListBox.options.length] = new Option(aStrMainLoopValue[0],aStrMainLoopValue[1]);
				if (StrCurrentValue == aStrMainLoopValue[1])
				{
					intSelectedIndex	= nCount;
				}
				nCount++;
			}
		}
	}
	objListBox.selectedIndex = intSelectedIndex;
}

