// JavaScript Document

function selectImage() {
	var randNum = Math.round(Math.random()*7)+1
	document.write("<img src='/tlpvirtual/dss/images/fp" + randNum + ".jpg' alt='' name='photo' width='413' height='273' />")
	//alert(randNum)
}

function selectInteriorImage() {
	var randNum = Math.round(Math.random()*6)+1
	document.write("<img src='/tlpvirtual/dss/images/rt" + randNum + ".jpg' alt='' name='photo' width='180' height='238' align='top' />")
	//alert(randNum)
}

function validateAndSubmitSearch(form) {
	if(form.search.value == "DSS" || form.search.value == "") {
		// no search submitted on "Search Chico State" 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/dss/" //search only dss site
		return true
	}
}
function validateEmailAddress(email) { // validate email addresses
	if (email.indexOf("@") == -1) { // not valid email address
		return false
	}
	var emailLength = email.length
	if (email.lastIndexOf(".") != emailLength-4) { // not valid
		return false
	}
	return true
}
function validatePhoneNum(phoneNum) {
	var validChars = "0123456789"
	if (phoneNum.length == 0) {
			alert("Please enter a phone number.")
			return false 
	}
	else if (phoneNum.length != 4) { 
		alert("You entered an invalid phone number!")
		return false 
	}
	//check that all characters in number are OK
	for (var i = 0; i < (phoneNum.length); i++) { 
		testChar = phoneNum.charAt(i)
		if (validChars.indexOf(testChar) == -1) { //testChar is not valid
			alert("You entered an invalid phone number!")
			return false
		}
	}	
	return true
}