function ClearOptions(OptionList) {

   // Always clear an option list from the last entry to the first
   for (x = OptionList.length; x >= 0; x = x - 1) {
      OptionList[x] = null;
   }
	return true;
}

function AddToOptionList(OptionList, OptionValue, OptionText) {
   // Add option to the bottom of the list
   OptionList[OptionList.length] = new Option(OptionText, OptionValue);
}

function PopulateAge(StatusList) {
	//alert(StatusList.options[StatusList.selectedIndex].text);
	var AgeList = document.frmMain[StatusList.name.replace(/status/,"age")];
	//alert(AgeList);
	if(StatusList.options[StatusList.selectedIndex].text == "Mas") {
		ClearOptions(AgeList);
		AgeList.disabled = false;
		AddToOptionList(AgeList, "A", "A");
		AddToOptionList(AgeList, "B", "B");
 	   	AddToOptionList(AgeList, "C", "C");
 	   	AddToOptionList(AgeList, "D", "D");
 	   	AddToOptionList(AgeList, "E", "E");
 	   	AddToOptionList(AgeList, "F", "F");
 	   	AddToOptionList(AgeList, "G", "G");
 	   	AddToOptionList(AgeList, "H", "H");
 	   	AddToOptionList(AgeList, "I", "I");
 	} else if (StatusList.options[StatusList.selectedIndex].text == "Junior") {
 	   	ClearOptions(AgeList);
 	   	AgeList.disabled = false;
 	   	AddToOptionList(AgeList, "J10", "J10");
 	   	AddToOptionList(AgeList, "J11", "J11");
 	   	AddToOptionList(AgeList, "J12", "J12");
 	   	AddToOptionList(AgeList, "J13", "J13");
 	   	AddToOptionList(AgeList, "J14", "J14");
 	   	AddToOptionList(AgeList, "J15", "J15");
 	   	AddToOptionList(AgeList, "J16", "J16");
 	   	AddToOptionList(AgeList, "J17", "J17");
 	   	AddToOptionList(AgeList, "J18", "J18");
 	} else {
 	   	ClearOptions(AgeList);
 	   	AgeList.disabled = true;
 	}
}

function AffiliationChange(AffList) {
	var StatusList = document.frmMain[AffList.name.replace(/cra/,"status")];
	var BoatList = document.frmMain[AffList.name.replace(/cra/,"boat")];
	var AgeList = document.frmMain[AffList.name.replace(/cra/,"age")];
	
	//ClearOptions(StatusList);
	//BoatList.disabled = false;
	if(AffList.options[AffList.selectedIndex].text == "Student") {
		ClearOptions(StatusList);
		ClearOptions(AgeList);
		AgeList.disabled = true;
		AddToOptionList(StatusList, "Mays/Eights Div 1", "Mays/Eights Div 1");
		AddToOptionList(StatusList, "Mays/Eights Div 2", "Mays/Eights Div 2");
		AddToOptionList(StatusList, "Mays/Eights Div 3", "Mays/Eights Div 3");
		AddToOptionList(StatusList, "Mays/Eights Lower", "Mays/Eights Lower");
		ClearOptions(BoatList);
		AddToOptionList(BoatList, "8+", "8+");
		AddToOptionList(BoatList, "4+", "4+");
		AddToOptionList(BoatList, "4x", "4x");
		AddToOptionList(BoatList, "2-", "2-");
		AddToOptionList(BoatList, "2x", "2x");
		AddToOptionList(BoatList, "1x", "1x");
	} else if((AffList.options[AffList.selectedIndex].text == "CRA") || (AffList.options[AffList.selectedIndex].text == "ARA")){
		ClearOptions(StatusList);
		AddToOptionList(StatusList, "Elite","Elite");
		AddToOptionList(StatusList, "Senior","Senior");
		AddToOptionList(StatusList, "Intermediate 1","Intermediate 1");
		AddToOptionList(StatusList, "Intermediate 2","Intermediate 2");
		AddToOptionList(StatusList, "Intermediate 3","Intermediate 3");
		AddToOptionList(StatusList, "Novice","Novice");
		AddToOptionList(StatusList, "Junior","Junior");
		AddToOptionList(StatusList, "Mas","Mas");
		ClearOptions(BoatList);
		AddToOptionList(BoatList, "8+", "8+");
		AddToOptionList(BoatList, "4+", "4+");
		AddToOptionList(BoatList, "4x", "4x");
		AddToOptionList(BoatList, "2-", "2-");
		AddToOptionList(BoatList, "2x", "2x");
		AddToOptionList(BoatList, "1x", "1x");
		ClearOptions(AgeList);
		AgeList.disabled = true;
	} else {
		ClearOptions(AgeList);
		ClearOptions(BoatList);
		ClearOptions(StatusList);
	}
}


function ClearOptionList() {
	for (i = 1; i < 11; i=i+1) {
		var AgeList = document.frmMain['age['+i+']'];
		var AgeListText = AgeList.options[AgeList.selectedIndex].text;
		//alert(AgeList.options[AgeList.selectedIndex].text);
		if( AgeListText == ""){
	    ClearOptions(AgeList);
		AgeList.disabled = true;
		}
	}
	return true;
}

function ResetForm() {
	for (i = 1; i < 11; i=i+1) {
		var AgeList = document.frmMain['age['+i+']'];
		var StatusList = document.frmMain['status['+i+']'];
		var BoatList = document.frmMain['boat['+i+']'];
		ClearOptions(AgeList);
		ClearOptions(BoatList);
		ClearOptions(StatusList);
	}
	return true;
}

