
function FilterChild(e, cboTarget, aOptions)
{
	iSelected = e.options[e.selectedIndex].value;
	PopulateTarget(iSelected,cboTarget,aOptions);
}

function PopulateTarget(iParent,sTarget,aOptions)
{
	// get all dates (from aOptions) for the given course (iParent)
	var aList = GetArrayWithOptions(iParent,aOptions);
	if (aList == null)
	{
		var oTargetID = GetObjectName(sTarget);
		var cboTarget = eval('document.forms[0].'+ oTargetID);
		cboTarget.options.length = 0;
	}
	FillCombo(aList,sTarget)		
}

function FillCombo(aList, sTarget)
{
	var sText;
	var sValue;
	var oTargetID = GetObjectName(sTarget);
	if (oTargetID.length <1)
	{
//		oTargetID.options.length = 0;	
//		return
	}
	var cboTarget = eval('document.forms[0].'+ oTargetID);
	
	// Clear the list first
	cboTarget.options.length = 0;
	
	cboTarget.options[cboTarget.options.length] = new Option("-Please Select-",0);	
	// Make sure there is an array to work with.
	
	if (aList != null)
	{
		for(var i=0; i<aList.length;i++)
		{
			sText = aList[i][1];
			sValue = aList[i][0];
			cboTarget.options[cboTarget.options.length] = new Option(sText,sValue);
		}
	}
}

function GetObjectName(id)
{		
	for (var i=0, n=document.forms[0].elements.length; i<n; i++)
	{
		var myString = new String(document.forms[0].elements[i].id);
		if (myString.indexOf(id) != -1)
		{
			//we have found the full name of the control
			return myString.toString();
		}
	}
	return "";
}

function GetArrayWithOptions(iParent, aOptions)
{
	var a = new Array();
	var aSize = 0;
	if (aOptions.length != 0)
	{
		for (var i = 0;i<aOptions.length;i++)
		{
			// Add items to the arrary that have the same parent ID
			// Make sure that the index exists first..			
			try
			{
				if (aOptions[i][2] == iParent)
				{
					a[aSize] = new Array(aOptions[i][0],aOptions[i][1]);
					aSize++;
				}
			}
			catch(e)
			{}			
		}
	}
	if(a.length >=1)
		return a;
	else
		return null;
}
