var s1, s4, s7;
var s2, s5, s8;

function change(control, controlToPopulate, ItemArray, GroupArray, IDArray)
{
	var myVal ;
	var myEle ;
	var x ;
	
	for (var q=controlToPopulate.options.length;q>=0;q--) controlToPopulate.options[q]=null;
	myVal = validate(control);
	if (control.name == "step1" || control.name == "step4" || control.name == "step7")
	{
		if (myVal == true)
		{
			//only for the first step...to ensure people know they must select a step 1.2,2.2,or 3.2.
			myEle = document.createElement("option") ;
			myEle.value = -1 ;
			myEle.text = "[Select]";
			controlToPopulate.add(myEle) ;
		}
	}
	
	if (myVal == true)
	{
		if (control.name == "step1") {s1 = control.value; s2 = '';}
		else if (control.name == "step2") {s2 = control.value}
		else if (control.name == "step4") {s4 = control.value; s5 = '';}
		else if (control.name == "step5") {s5 = control.value}
		else if (control.name == "step7") {s7 = control.value; s8 = '';}
		else if (control.name == "step8") {s8 = control.value}
		for ( x = 0 ; x < ItemArray.length  ; x++ )
		{
			if ( GroupArray[x] == control.value)
			{
				myEle = document.createElement("option") ;
				if (control.name == "step1" || control.name == "step4" || control.name == "step7")
				{
					myEle.value = x ;
				}
				else if (control.name == "step2" || control.name == "step5" || control.name == "step8")
				{
					myEle.value =  arrID2[x] ;
				}
				myEle.text = ItemArray[x] ;
				controlToPopulate.add(myEle) ;
			}
		}
		return true;
	}
	else
	{
		//myEle = document.createElement("option") ;
		//myEle.value = -1 ;
		//myEle.text = "[Step 2]";
		//controlToPopulate.add(myEle) ;
		alert("You selected this sort in a prior step. Please choose another sort.")
		return false;
	}
}

function validate(item)
{
	//if the second step matches
	if ((s1 == s4 && (eval(s2) == eval(item.value) && item.name != 'step2')) || (s1 == s7 && (eval(s2) == eval(item.value) && item.name != 'step2')) || (s4 == s7 && (eval(s5) == eval(item.value) && item.name != 'step2')))
	{
		return false;
	}
	else
	{
		return true;
	}
}


function validateForm()
{
	var validatedYear = 0;
	
	for (counter = 0; counter < document.sort.years.length; counter++)
	{
		if (document.sort.years[counter].checked)
			{ validatedYear = 1; }
	}

	if (!validatedYear)
	{
		alert("Please select a year.");
		return false;
	}
	else
	{
		return true;
	}
}

function clearForm() {
		formElements = document.getElementById('sort').elements;
		for(i=0;i<formElements.length;i++) {
			formElements[i].checked=false;
		}
	}
