﻿//Author: Paul Berry - PBerry@CirrusSoftware.com   

//Date: July 2002

//Licence: Its Freeware!... Just leave my name against the code and send me a mail if you like.

//Purpose: Provides simple dropdown functionality that could be used on multiple cascading dropdown lists.

//Compatability: This process will work on both IE and Netscape (tested on Ns 4.5 and IE 5.5)



var iArrayMax = new Number(0)

var aDropdown = new Array()

var LevelCount = new Number()



function sElement(sLevel,sParentId,sValue,sDescription)

{	

	// elements that will be loaded into the array structure and persisted

	// think of it as an object.

	this.ParentId = sParentId

	this.Id = sValue

	this.Level = sLevel

	this.Description = sDescription

	iArrayMax++

	if (LevelCount<sLevel) LevelCount = sLevel

}



function bCascadeDrop(sLevel,oDDsource,oDDdest)

{

	//function to enable cascading dropdowns

	//called as the parent dropdown changes.

	var iX

	var sText

	var iY= 0

	var sOptionId

	var sOptionDesc

	var iStartPos

	//find the value of the item currently selected		

	sText = oDDsource.options[oDDsource.selectedIndex].value

	if (sText != '0')

	{

		//clear down the destination list box

		oDDdest.options.length = 0                

		

		//loop through the elements that are in the array

		// if they match the parent if then they should be displayed.

		if (sText=="disabled")

			{

				oDDdest.options[iY] = new Option ("---pasirinkite miestą---", "disabled");

				oDDdest.options[iY].disabled

			}

			else

			{	

				oDDdest.options[iY] = new Option ("visos tematikos", "disabled");

				oDDdest.options[iY].disabled

				

				iY++

				if (sText=="none") sLevel = sLevel - 1

				for (iX=0; iX<=(iArrayMax - 1); iX++) 

				{	

					if((sText == Array[iX].ParentId) && (sLevel == Array[iX].Level))

					{

						//grab the values out of the element (Netscape is not happy doing too many things in a function call!)

						sOptionId = Array[iX].Id

						sOptionDesc= Array[iX].Description

						//alert(sOptionDesc)

			

						//write the element into the dripdown box.		

						oDDdest.options[iY] = new Option (sOptionDesc,sOptionId)

						iY++

					}

				}

				if (iY == 1) 

				{

					iY2 = iY-1

					oDDdest.options.length = 0

					oDDdest.options[iY2] = new Option ("---nėra---","none");

					oDDdest.options[iY2].disabled

					oDDdest.disabled

				}

			}

	}	

}