// JavaScript Document
// Set the Form Name that contanis Dynamic Select

//var formName = 'form1';
var ParentList = new Array();

function Parent(code, name){
   this.Code = code; 
   		// Value of Parent Select Option
   this.Name = name;   
   		// Text of Parent Select Object
   this.Children = new Array();
      	// Array of Dependants
} // End Function Parent


function setDynamicList(controling_select, dependent_select){

   var parentForm = controling_select.form;

   var oList1 = controling_select;
   		// Parent Option List
   var oList2 = parentForm.elements[dependent_select] 
		// Dependent Select
   clearDynamicList(oList2);
 
   if (oList1.selectedIndex == -1){
       oList1.selectedIndex = 0;
   }

   populateDynamicList(oList2, oList1[oList1.selectedIndex].value );
   return true;
}


function populateDynamicList(oList, parentCode){

    oList.options[0] = new Option("-- SELECT --","");
	 
//    for(child in ParentList[parentCode].Children.sort())
    //for(child in ParentList[parentCode].Children.sort())//added sort function 7/23/08 markg
    for(child in ParentList[parentCode].Children)
    {
	    if (ParentList[parentCode].Children[child] != null){
          oList.options[oList.options.length] = new Option( ParentList[parentCode].Children[child], child);
       }
	 }
		
    if (oList.options.length == 1){
       oList.options[oList.options.length] = new Option("[none available]","");
    }
    
    oList.selectedIndex = 0;
} // End function


function clearDynamicList(oList){

   for (var i = oList.options.length; i >= 0; i--){
       oList.options[i] = null;
   }
 
   oList.selectedIndex = -1;
} 