// This script dynamically populates the "Sub Category" select options based on "Category" select option selection.

function SetOptions() {
	
	var ReferralList = document.getElementById('type');
	
	// Clear out the list of teams
	ClearOptions(document.getElementById('source'));
   
	if (ReferralList[ReferralList.selectedIndex].value == "Search Engine") {
		AddToOptionList(document.getElementById('source'), "None Selected", "Select Source");
		AddToOptionList(document.getElementById('source'), "Google", "Google");
		AddToOptionList(document.getElementById('source'), "Yahoo", "Yahoo");
		AddToOptionList(document.getElementById('source'), "MSN", "MSN");
		AddToOptionList(document.getElementById('source'), "Bing", "Bing");
	}
	
	if (ReferralList[ReferralList.selectedIndex].value == "Magazine") {
		AddToOptionList(document.getElementById('source'), "None Selected", "Select Source");
		AddToOptionList(document.getElementById('source'), "Veterinarian Economics", "Veterinarian Economics");
	}
	
	if (ReferralList[ReferralList.selectedIndex].value == "Referral") {
		AddToOptionList(document.getElementById('source'), "None Selected", "Select Source");
		AddToOptionList(document.getElementById('source'), "VetMatrix Portfolio Website", "VetMatrix Portfolio Website");
		AddToOptionList(document.getElementById('source'), "Another VetMatrix Client", "Another VetMatrix Client");
	}

}
	
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;
	}
}


function AddToOptionList(OptionList, OptionValue, OptionText) {
	// Add option to the bottom of the list
	OptionList[OptionList.length] = new Option(OptionText, OptionValue);
}