
function onLoad() {
	setLocationOnLoad();
	setCategoryOnLoad();
	setMonthOnLoad();
}

function setMonthOnLoad() {
	document.getElementById("Jan").className = "month-table-cell";
	document.getElementById("Feb").className = "month-table-cell";
	document.getElementById("Mar").className = "month-table-cell";
	document.getElementById("Apr").className = "month-table-cell";
	document.getElementById("May").className = "month-table-cell";
	document.getElementById("Jun").className = "month-table-cell";
	document.getElementById("Jul").className = "month-table-cell";
	document.getElementById("Aug").className = "month-table-cell";
	document.getElementById("Sep").className = "month-table-cell";
	document.getElementById("Oct").className = "month-table-cell";
	document.getElementById("Nov").className = "month-table-cell";
	document.getElementById("Dec").className = "month-table-cell";
	document.getElementById("Search-By-Item").className = "month-table-cell";

	var selectedMonth = document.getElementById("selected-search-type");
	var value = (selectedMonth.value == "Search By Item" ? "Search-By-Item" : selectedMonth.value);
	var monthCell = document.getElementById(value);
	monthCell.className = "month-table-cell-selected";
}

function setMonth(newMonthCell) {
	var selectedMonth = document.getElementById("selected-search-type");
	var oldMonthCell = document.getElementById(selectedMonth.value);
	if (oldMonthCell.id == newMonthCell.id) {
		return;
	}
	oldMonthCell.className = "month-table-cell";
	selectedMonth.value = newMonthCell.id;
	newMonthCell.className = "month-table-cell-selected";
}

function setLocationOnLoad() {
	setLocation(document.getElementById("location-select"));
}

function setLocation(locationSelector) {
	var selectedIndex = locationSelector.selectedIndex;
	var selectedValue = locationSelector.options[selectedIndex].value;
	setLocationImage(selectedValue);
	setLocationCookie(selectedValue);
}

function setLocationImage(location) {
	var imageElement = document.getElementById("location-image");
	var imageSrc = "images/map/" + location + ".png";
	if (imageSrc != imageElement.src) {
		imageElement.src = imageSrc;
	}
}

function setLocationCookie(location) {
	var date = new Date();
	date.setTime(date.getTime() + (365*24*60*60*1000));
	document.cookie = "location-cookie=" + location + "; expires=" + date.toGMTString() + "; path=/";
}

function setCategoryOnLoad() {
	var selectedCategory = document.getElementById("selected-category");
	setCategoryUI(selectedCategory.value);
}

function setCategory(categoryElement) {
	var selectedCategory = document.getElementById("selected-category");
	if (categoryElement.id == selectedCategory.value) {
		return;
	}
	selectedCategory.value = categoryElement.id;
	setCategoryUI(categoryElement.id);
}

function setCategoryUI(category) {
	var fruitElement = document.getElementById("Fruit");
	var vegElement = document.getElementById("Vegetables");
	if (category == "Vegetables") {
		fruitElement.className = "category-table-unselected";
		vegElement.className = "category-table";
	} else {
		fruitElement.className = "category-table";
		vegElement.className = "category-table-unselected";
	}

	var fruitSuffix = "";
	var vegSuffix = "-gray";
	if (category == "Vegetables") {
		fruitSuffix = "-gray";
		vegSuffix = "";
	}
	var fruitImage= document.getElementById("Fruit-image");
	var vegImage= document.getElementById("Vegetables-image");
	fruitImage.src = "images/misc/fruit-combo3" + fruitSuffix + ".jpg";
	vegImage.src = "images/misc/vegie-combo3" + vegSuffix + ".jpg";
}

