/* --------------------------------------------------------------------
 *	Interdependent Selectboxes Script 
 *  Version 1.0 (w) 20.06.01 by Christian Heilmann 
 *  Location: http://www.onlinetools.org/easyselect/                                    
 */
 
datasets=new Array();
datasets[0]="Option1,subOption1_1,subOption1_2,subOption1_3,subOption1_4".split(",");
datasets[1]="Option2,subOption2_1,subOption2_2,subOption2_3".split(",");
datasets[2]="Option3,subOption3_1, subOption3_2, subOption3_3,subOption3_4,subOption3_5".split(",");
datasets[3]="Option4,subOption4_1,subOption4_2,subOption4_3,subOption4_4".split(",");
datasets[4]="Option5,subOption5_1,subOption5_2,subOption5_3,subOption5_4,subOption5_5,subOption5_6".split(",");
datasets[5]="Option6,subOption6_1,subOption6_2,subOption6_3,subOption6_4".split(",");
datasets[6]="Option7,subOption7_1,subOption7_2,subOption7_3,subOption7_4".split(",");

/* --------------------------------------------------------------------
 	populateselect()
 * --------------------------------------------------------------------
 * This function is to be called onload and populates the form according 
 * to the datasets.
 */

function populateselect(){
	/* Define Form elements (lesser typing)
	 * myForm is the form name, select1 and select 2 the selectboxes.
	 * Change this to your names in the HTML document
	 */
	theform=document.myForm;
	sel1 = theform.states;
	sel2 = theform.localgovernments;

	sel1.options.length = 0;
	sel1.options.length = datasets.length;
	for (i=0;i<datasets.length;i++){
		sel1.options[i].text = datasets[i][0];
		sel1.options[i].value = datasets[i][0];
		}
	sel1.selectedIndex=0;
	changeselect(0);
	}

/* --------------------------------------------------------------------
 	changeselect()
 * --------------------------------------------------------------------
 * This function changes the content of the second selectbox according 
 * to the data of the datasets and the selected option of the first.
 */

function changeselect(){
	theform=document.myForm;
	sel1 = theform.states;
	sel2 = theform.localgovernments;

	dataset=sel1.selectedIndex;
	sel2.options.length = 0;
	sel2.options.length = datasets[dataset].length-1;
	for (i=1;i<((datasets[dataset].length));i++){
		sel2.options[i-1].text = datasets[dataset][i];
		sel2.options[i-1].value = datasets[dataset][i];
		}
	sel2.selectedIndex=0;
}
