// JavaScript Document

function validateAndSubmitSearch(form) {
	if(form.search.value == "Search UHFS" || form.search.value == "") {
		// no search submitted on "Search UHFS" or empty searches
		form.search.focus() // places cursor back in the search field
		return false //stops the form from being submitted
	} else {
		form.search.value = form.search.value + " site:www.csuchico.edu/housing/" //search only UHFS site
		return true
	}
}

function selectHomeImage() {
	var randNum = Math.round(Math.random()*9)+1
	document.write("<img src='http://www.csuchico.edu/hfa/images/home/" + randNum + ".jpg' alt='College of Humanities and Fine Arts banner' name='banner_photo' width='604' height='280' border='0' id='banner_photo' />")
	//alert(randNum)
}

function selectInteriorImage() {
	var randNum = Math.round(Math.random()*19)+1
	document.write("<img src='http://www.csuchico.edu/hfa/images/interior/" + randNum + ".jpg' alt='College of Humanities and Fine Arts photo' name='interior_photo' width='170' height='361' border='0' id='interior_photo' />")
	//alert(randNum)
}

function selectDonorImage() {
	var randNum = Math.round(Math.random()*2)+1
	document.write("<img src='http://www.csuchico.edu/hfa/images/donor/" + randNum + ".jpg' alt='College of Humanities and Fine Arts donor' name='donor_photo' id='donor_photo' width='385' height='166' border='0' />")
	//alert(randNum)
}

startList = function() {
	//alert('function called');
	if (document.all && document.getElementById) {
		//alert('if statement called');
		var collegeNav = document.getElementById("college-nav"); /* to make the subnavs under the college pop out */
		var academicsNav = document.getElementById("leftnav"); /* to make the academics subnav pop out */
		
		for (i = 0; i < collegeNav.childNodes.length; i++) {
			node = collegeNav.childNodes[i];
			if (node.nodeName == "LI") {
				node.onmouseover=function() {
					this.className += " over";
				}
				node.onmouseout = function() {
					this.className = this.className.replace(" over", "");
				}
			}
		}
		node = leftnav.childNodes[1];
		if (node.nodeName == "LI") {
			node.onmouseover=function() {
				this.className += " over";
			}
			node.onmouseout = function() {
				this.className = this.className.replace(" over", "");
			}
		}
	}
}

window.onload=startList;