arrFormDropdowns = null;

 function LSOInit(){
	 LSOLoad(strLSOFormName);
 }
 
 function LSOUpdate(intMyLevel,intUpdateLevel){
	updateDropdownIndex = intUpdateLevel - 1
	IsChildSubSeries = 1;
	
	selectedDropDown = arrFormDropdowns[intMyLevel - 1];
	selectedIndex = selectedDropDown.options.selectedIndex;
	selectedID = selectedDropDown.options[selectedDropDown.selectedIndex].value;
	// reset certain select option in the beginning depending on which select tag you chosen
	
	if (intMyLevel==1)
	{
		cleanUp(4);
		cleanUp(3);
		cleanUp(2);
	}
	
	if (intMyLevel==2)
	{
		cleanUp(4);
		cleanUp(3);
	}
	if (intMyLevel==3)
	{
		cleanUp(4);
	}
	// if selected index value is not blank
	if(selectedID!=""){
		if (intUpdateLevel == 2){ arrChild = arrLSO_2;} // query which update level has been chosen
	
		if (intUpdateLevel == 3){ 
			arrChild = arrLSO_3;
			
			// 1) Get the Top level selected value
			// 2) Loop through the SubFondsSeriesChildLookup array
			// 3) Check if the combination of the Top Level ID and the selectedID exist.
			// 4) This means that isSubSeries the child is false.
			
			selectedTopLevelIndex = arrFormDropdowns[0].options.selectedIndex;
			ToplevelID = arrFormDropdowns[0].options[selectedTopLevelIndex].value;
			for(i=0;i<arrSubFondsSeriesChildLookup.length;i++)
		    {
				if(parseInt(arrSubFondsSeriesChildLookup[i][0]) == ToplevelID && parseInt(arrSubFondsSeriesChildLookup[i][1])==selectedID)
				{	
					IsChildSubSeries = 0;
				}
			}
			
			hiddenIsChildSubSeries.value=IsChildSubSeries;
			
			//strHTML = "<select name=\"LSO_3\" onChange=\"LSOUpdate(3,4)\" class=\"dropmenuLong3\">";
			//strHTML = strHTML + "<option value=\"\">Please select</option></select>";
			if(IsChildSubSeries == 1)
			{
				 //eval("document.all.divt"+ 2 +".style.visibility='visible';");
				// eval("document.all.divt"+ 2 +".innerHTML=strHTML+'';");
			}
			else{
				
				updateDropdownIndex = 3;
				 document.all.divt2.style.visibility='hidden';
				 document.all.divt3.style.visibility='visible';
				//eval("document.all.divt"+ 2 +".innerHTML='<i>Not applicable</i>';");
				arrChild = arrLSO_4;
				
			}
			
	} 
	
	// and then populate the arrChild array with the
	if (intUpdateLevel == 4){
		 	arrChild = arrLSO_4;
	} // array generated by the SQL query
		var counter = 1;
		
		//alert("setting child drop downs");
		if(IsChildSubSeries == 1)
		{
			
			if(updateDropdownIndex == 2){
				strHTML = "<select name=\"LSO_3\" onChange=\"LSOUpdate(3,4)\" class=\"dropmenuLong3\">";
				strHTML = strHTML + "<option value=\"\">Please select</option>";
				for(i=0;i<arrChild.length;i++)
				{
					if(parseInt(arrChild[i][1])==selectedID)
					{
						
						arrFormDropdowns[updateDropdownIndex].options[counter] = new Option(arrChild[i][2],arrChild[i][0]);
						//strHTML = strHTML + '<option value=\"'+arrChild[i][0]+'\">'+ arrChild[i][2].replace("'","\'") + '</option>';
						counter++;
					}
				}
			strHTML = strHTML + "</select>";
			//eval("document.all.divt"+ 2 +".style.visibility='visible';");
			// eval("document.all.divt"+ 2 +".innerHTML=strHTML+'';");
			}
			else{
				
				if(updateDropdownIndex == 3){
					for(i=0;i<arrChild.length;i++)
					{
						if(parseInt(arrChild[i][1])==selectedID && parseInt(arrChild[i][3]) == 1)
						{
							arrFormDropdowns[updateDropdownIndex].options[counter] = new Option(arrChild[i][2],arrChild[i][0]);
							counter++;
						}
					}
				}
				else{
					for(i=0;i<arrChild.length;i++)
					{
						if(parseInt(arrChild[i][1])==selectedID)
						{
							arrFormDropdowns[updateDropdownIndex].options[counter] = new Option(arrChild[i][2],arrChild[i][0]);
							counter++;
						}
					}
				}
				
			}
		}
		
		else
		{
			counter = 1;
			for(i=0;i<arrChild.length;i++)
			{
				//if(parseInt(arrChild[i][1])==selectedID && parseInt(arrChild[i][3]) == 0 ){alert(parseInt(arrChild[i][4]));}
				if(parseInt(arrChild[i][1])==selectedID && parseInt(arrChild[i][3]) == 0)
				{
					//used for testing purpose arrFormDropdowns[intUpdateLevel - 1].options[counter] = new Option(arrChild[i][2] + " " + selectedLSOID + ">" + arrChild.length ,arrChild[i][0]);
					arrFormDropdowns[updateDropdownIndex].options[counter] = new Option(arrChild[i][2],arrChild[i][0]);
					counter++;
				}
			}
		}	
	}   
	
	else
	{				
		cleanUp(intUpdateLevel);
	}
 }
 
 function removeAllOptions(from)
 {
 	for(var i=(from.options.length-1);i>=0;i--)
	{
		from.options[i] = null;
	}
	from.selectedIndex = -1;
}


 function cleanUp(intUpdateLevel)
 {
 	
 	removeAllOptions(arrFormDropdowns[intUpdateLevel - 1]);
	arrFormDropdowns[intUpdateLevel - 1].options[0] = new Option("Please Select","");
	
	if(intUpdateLevel==3){
		document.all.divt2.style.visibility='visible';

	}
 }

function LSOLoad(strLSOFormName){
	 hiddenIsChildSubSeries = document.forms[strLSOFormName]['IsChildSubSeries'];
	 arrFormDropdowns = new Array()
	 arrFormDropdowns[0] = document.forms[strLSOFormName]['LSO_1'];
	 arrFormDropdowns[1] = document.forms[strLSOFormName]['LSO_2']; 
	 arrFormDropdowns[2] = document.forms[strLSOFormName]['LSO_3'];
	 arrFormDropdowns[3] = document.forms[strLSOFormName]['LSO_4']; 
	 
	 if(document.layers)	   //NN4+
	{
			//document.layers[szDivID].visibility = iState ? "show" : "hide";
			//alert("NN4+");
	}
	else if(document.getElementById)	  //gecko(NN6) + IE 5+
	{
		//alert("IE6+");
	    /**
		 var obj = document.getElementById('demodiv1');
		 obj.style.visibility = iState ? "visible" : "hidden";
		 **/
	}
 }
