<!--
function setListToValue(oList, nValue)
{
	for (var i = 0; i < oList.options.length; i++)
	{
	//alert(oList.options[i].value + '=' + nValue);
		if (oList.options[i].value == nValue)
		{
			oList.selectedIndex = i;
			return;
		}
	}
}

function initListFromHidden(oList, oHidden)
{
	//alert(oHidden.value);
	setListToValue(oList, oHidden.value);
	if (oList.onChange)	// if onChange event exists, call it
		oList.onChange();
}

function clearcombo(oList)
{
	var i;
	for (i = oList.options.length; i >= 0; i--) oList.options[i] = null;
	oList.selectedIndex = -1;
}

function populateSubList(oList, strArray, index, sText)
{
	clearcombo(oList);
	
// Check if the main array has an existing element at the position specified by the parameter index.
// If so, load up the dependent list box with all subordinate array elements that match the index.
	var newloc = oList.options.length;
	var incr = 2;
	if (oList.name.toLowerCase() == 'selsubcategory')
		incr = 3;

	if (typeof(index) != 'object')
	{
		//alert('populate ' + oList.name + ': array length=' + strArray.length + ', index=' + index );
		if (strArray.length >= index)
		{
		// If the index is a particular number, get all the dependent values from that "row"
			if (strArray[index])
			{
				// zero entry will display the caller's text (e.g. "-- Select --")
				//oList.options[newloc] = new Option('-- ' + sText + ' --', 0);
				oList.options[newloc] = new Option(sText, 0);
				oList.selectedIndex = newloc;
					
				for (var i = 0; i < strArray[index].length; i = i + incr)
				{
					newloc = oList.options.length;
					
					//if (strArray[index][i] != 0)
					if (strArray[index][i] != -1)
					{
						oList.options[newloc] = new Option(strArray[index][i + 1], strArray[index][i]);
					}
				}
			}
			else
			{
			//alert(2);					
			// If the index is zero, get all the dependent values from all the "rows"
				if (index == 0)
				{
					// zero entry will display the caller's text (e.g. "-- Select --")
					//oList.options[newloc] = new Option('-- ' + sText + ' --', 0);
					oList.options[newloc] = new Option(sText, 0);
					oList.selectedIndex = newloc;
						
					for (var i = 0; i < strArray.length; i = i + 1)
					{
						if (strArray[i])
						{
							//alert('Loading strArray[' + i + '] len=' + strArray[i].length);
							for (var j = 0; j < strArray[i].length; j = j + 2)
							{
								newloc = oList.options.length;
						
								if (strArray[i][j] > -1)
									oList.options[newloc] = new Option(strArray[i][j + 1], strArray[i][j]);
								else
								{
									// write a divider line
									oList.options[newloc] = new Option('-- ' + strArray[i][j + 1] + ' --', strArray[i][j]);
									if (oList.options[newloc].style)
										oList.options[newloc].style.backgroundColor = '#dadada';
								}
							}
						}
					}
				}
				else
					oList.options[newloc] = new Option("[none available]", -1);
					
				oList.selectedIndex = 0;
			}
		}
		else
		{
			oList.options[newloc] = new Option("[none available]", -1);
			oList.selectedIndex = 0;
		}
	}
	else
	// selected items are in an array
	{
		// zero entry will display the caller's text (e.g. "-- Select --")
		//oList.options[newloc] = new Option('-- ' + sText + ' --', 0);
		oList.options[newloc] = new Option(sText, 0);
		oList.selectedIndex = newloc;
			
		for (var idx = 0; idx < index.length; idx = idx + 1)
		{
			if (strArray[index[idx]])
			{
				//alert('Loading strArray[' + index[idx] + '] len=' + strArray[index[idx]].length);
				for (var j = 0; j < strArray[index[idx]].length; j = j + 2)
				{
					newloc = oList.options.length;
			
					if (strArray[index[idx]][j] > -1)
						oList.options[newloc] = new Option(strArray[index[idx]][j + 1], strArray[index[idx]][j]);
					else
					{
						// write a divider line
						//oList.options[newloc] = new Option(strArray[index[idx]][j + 1].toUpperCase(), strArray[index[idx]][j]);
						oList.options[newloc] = new Option('-- ' + strArray[index[idx]][j + 1] + ' --', strArray[index[idx]][j]);
						if (oList.options[newloc].style)
							oList.options[newloc].style.backgroundColor = '#dadada';
					}
				}
			}
		}
	}
}

function initDependentList(oMainList, oSubList, oArray, oHidden, sText)
{
	if (oMainList.options)
	{
		var sel = oMainList.selectedIndex;

	// Populate the subordinate list using value of the selected item in the main list
		//alert(oSubList.name + ', ' + oArray.length + ', ' + oMainList.name + ', ' + sel);
		populateSubList(oSubList, oArray, oMainList.options[sel].value, sText);
	}
	else
	// Populate the subordinate list using an array of values
		populateSubList(oSubList, oArray, oMainList, sText);

	if (oHidden.value)
		initListFromHidden(oSubList, oHidden);
}

function populateTypeList(oList)
{
	if (oList)
	{
		// Get the containing form (this function could be called from pages with different form names)
		var curform = oList.form;
		
		initListFromHidden(oList, curform.SaveType);
	}
}

function populateSingleCategoryList(oList)
{
	if (oList)
	{
		// Get the containing form (this function could be called from pages with different form names)
		var curform = oList.form;
		
		//initDependentList(curform.selProductType, oList, catMenu, curform.SaveCategory, 'All Categories');
		//populateSubList(oList, catMenu, 0, 'Select Category');
		// Altered 7/24/2007, Samuel Phelps: Reverted to say 'All Categories',
		// rather than 'Select Category'
		populateSubList(oList, catMenu, 0, 'All Categories');
		
		if (curform.SaveCategory)
			if (curform.SaveCategory.value.length > 0)
				initListFromHidden(oList, curform.SaveCategory);
			else
				oList.selectedIndex = 0;
	}
}		

function populateCategoryList(oList)
{
	if (oList)
	{
		// Get the containing form (this function could be called from pages with different form names)
		var curform = oList.form;
		
		if (curform.selProductType)
		{
		// Look for 'seg=' in the index.  Then all the categories in that product segment must be selected.
			var sel = curform.selProductType.selectedIndex;
			var segment = curform.selProductType.options[sel].value;

			if (segment.indexOf('seg=') > -1)
			{
				var segnum = parseInt(segment.substr(4))
				var arrCats = new Array();
			// Pull out the subset of categories that we need and keep them in an array
				if(segMenu[segnum] && segMenu[segnum].length) {
					for (var i = 0, idx = 0; i < segMenu[segnum].length; i = i + 2, idx = idx + 1)
						arrCats[idx] = segMenu[segnum][i];
					initDependentList(arrCats, oList, catMenu, curform.SaveCategory, 'All Categories');
				}
			}
			else
			{
				initDependentList(curform.selProductType, oList, catMenu, curform.SaveCategory, 'All Categories');
			}				
		}
		else
		{
			var sel;
			var segnum;
			var arrCats = new Array();
			
			if (curform.selProductSeg)
			{
				sel = curform.selProductSeg.selectedIndex;
				segnum = curform.selProductSeg.options[sel].value;
			}
			else
				if (segMenu[0])
					segnum = 0;
				else
					segnum = 1;
				
			// Pull out the subset of categories that we need and keep them in an array
			for (var i = 0, idx = 0; i < segMenu[segnum].length; i = i + 2, idx = idx + 1)
				arrCats[idx] = segMenu[segnum][i];
			initDependentList(arrCats, oList, catMenu, curform.SaveCategory, 'All Categories');
		}
	}
}		

function populateSubCatList(oList)
{
	if (oList)
	{
		// get the containing form
		var curform = oList.form;
		initDependentList(curform.selProductCategory, oList, subMenu, curform.SaveSubCat, 'All Subcategories');
	}
}		

// Print Music Instruction Levels
function populateLevelList(oList)
{
	var levelGroup;
	var newloc;
	
	levelGroup = -1;
	
	if (oList)
	{
		// Get the containing form (this function could be called from pages with different form names)
		var curform = oList.form;
		
		// Get the category, which provides the index into the subcategory array
		var selCat = curform.selProductCategory.selectedIndex;
		var idxCat = curform.selProductCategory.options[selCat].value;
		var selSubCat = curform.selSubCategory.selectedIndex;
		var idxSubCat = curform.selSubCategory.options[selSubCat].value;
		var selLevel = curform.SaveLevel.value;
		//alert('idxCat=' + idxCat + ',idxSubCat=' + idxSubCat);
		
		if (subMenu[idxCat])
		{
			// Now find the subcategory in the list. This will give us the Level Group code (if any.)
			for (var i = 0; i < subMenu[idxCat].length; i = i + 3)
			{
				//alert(subMenu[idxCat][i]);
				if (subMenu[idxCat][i] == idxSubCat)
				{
					//alert('found at ' + i);
					levelGroup = subMenu[idxCat][i+2]
					break;
				}
			}
		}

		clearcombo(curform.selSubLevel);

		// Now we can populate the Level list
		if (levelGroup != -1)
		{
			newloc = curform.selSubLevel.options.length;
			oList.options[newloc] = new Option('All Print Music Levels', 0);

			for (i = 0;  i < LevelMenu[levelGroup].length; i = i + 2)
			{
				//alert(LevelMenu[levelGroup][i]);
				newloc = oList.options.length
				oList.options[newloc] = new Option(LevelMenu[levelGroup][i+1], LevelMenu[levelGroup][i]);
				if (LevelMenu[levelGroup][i] == selLevel)
				{
					//alert('Setting level to ' + selLevel);
					oList.selectedIndex = newloc;
				}
			}
		}
		else
		{
			newloc = curform.selSubLevel.options.length;
			oList.options[newloc] = new Option('[None available]', 0);
			//oList.options[newloc] = new Option('All Print Music Levels', 0);
		}
	}
}

// -->
