function breadcrumbs(base,delStr,defp,cStyle,tStyle,dStyle,nl) { 
var wholeLoc=window.location.toString().split("?");loc=wholeLoc[0];
subs=loc.substr(loc.indexOf(base)+base.length+1).split("/");
 document.write('<a href="'+getLoc(subs.length-1)+defp+'" class="'+cStyle+'">Home</a>  '+'<span class="'+dStyle+'">'+delStr+'</span> ');
 a=(loc.indexOf(defp)==-1)?1:2;
 for (i=0;i<(subs.length-a);i++) { subs[i]=makeCaps(unescape(subs[i]));
 document.write('<a href="'+getLoc(subs.length-i-2)+defp+'" class="'+cStyle+'">'+subs[i]+'</a>  '+'<span class="'+dStyle+'">'+delStr+'</span> ');}
 if (nl==1) document.write("<br>");document.write('<span class="'+tStyle+'">'+document.title+'</span>');
}
function makeCaps(a) {
  g=a.split(' ');for (l=0;l<g.length;l++) g[l]=g[l].toUpperCase().slice(0,1)+g[l].slice(1);
  return g.join(" ");
}
function getLoc(c) {
  var d="";if (c>0) for (k=0;k<c;k++) d=d+"../"; return d;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
		newWindow = window.open(theURL,winName,features);
		newWindow.focus()
}

/* Included Functions */
// checkDaysInMonth
// validateDate
// validateEmail
// validatePhone
// validateTimes

function checkDaysInMonth(dateArray) { // determines that the day number associated with a month is valid; used by validateDate() function
	monthLengthArray = [31,28,31,30,31,30,31,31,30,31,30,31]
	if (eval(dateArray[2]) % 4 == 0) {
		monthLengthArray[1] = 29
	}
	monthDays = monthLengthArray[dateArray[0]-1]
	if (dateArray[1] > monthDays) {
		return false
	}
	return true
}

function validateCampusPhone(form) {
	var validChars = "0123456789"
	var phoneNum = form.Phone.value
	if (phoneNum.length == 0) {
			alert("Please enter a phone number.")
			return false 
	}
	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
}

function validateDate(date) { // validates that date is valid
	var dateArray = date.split("/")
	//dateArray[0] = month
	//dateArray[1] = day
	//dateArray[2] = year
	if (isNaN(dateArray[0]) || isNaN(dateArray[1]) || isNaN(dateArray[2])) {
		alert("Invalid date!")
		return false
	}
	if (dateArray[0] == null || dateArray[1] == null || dateArray[2] == null) {
		alert("Invalid date!")
		return false
	}
	if (dateArray[0] == "" || dateArray[1] == "" || dateArray[2] == "") {
		alert("Invalid date!")
		return false
	}
	//check month is between 1 and 12
	if (eval(dateArray[0]) < 1 || eval(dateArray[0]) > 12) { 
		alert("You entered an invalid month!")
		return false
	}
	//check if days in month correct
	if (!(checkDaysInMonth(dateArray))) {
		alert ("The month you selected only has " + monthDays + " days in it.")
		return false
	}
	//check year is between 2001 and 2009
	if (eval(dateArray[2]) > 2000) {
		dateArray[2] = (dateArray[2]-2000)
	}
	if (eval(dateArray[2]) < 6) { // change this per year to equal the current year
		alert("You must enter 2006 or greater for the year.  This year is in the past.")
		return false
	} 
	return true
}

/*function validateEmail(form) { // validate email addresses
	var emailad = form.Email.value
	if (emailad.indexOf("@") == -1) { // not valid email address
		return false
	}
	var emailLength = emailad.length
	if (emailad.lastIndexOf(".") != emailLength-4) { // not valid
		return false
	}
	return true
}*/

function validatePhone(phoneNum) { // validates the proper number formatting for phone numbers
	var validChars = "0123456789"
	if (phoneNum.length == 0) {
			return false 
	}
	switch (phoneNum.length) {
		case 8 : 
			 // 7 digit: 898-6550
			if(phoneNum.charAt(3) != "-")  { return false }
			//check that all characters in number are OK
			for (var i = 0; i < (phoneNum.length); i++) { 
				if(i == 3) {continue } // "-" 
				testChar = phoneNum.charAt(i)
				if (validChars.indexOf(testChar) == "-1") { //testChar is not valid
					return false
				}
			}	
			return true
		case 12 : // 10 digit: 530-898-6550
			if(phoneNum.charAt(3) != "-" &&  phoneNum.charAt(7) != "-") { return false }
			//check that all characters in number are OK
			for (var i = 0; i < (phoneNum.length); i++) { 
				if(i == 3 || i == 7) { continue } // "-" 
				testChar = phoneNum.charAt(i)
				if (validChars.indexOf(testChar) == -1) { //testChar is not valid
					return false
				}
			}	
			return true

		case 13 : // 10 digit: (530)898-6550
			if(phoneNum.charAt(0) != "(" && phoneNum.charAt(4) != ")" &&  phoneNum.charAt(8) != "-") { return false }
			//check that all characters in number are OK
			for (var i = 0; i < (phoneNum.length); i++) { 
				if(i == 0 || i == 4 || i == 8) { continue } // "-" 
				testChar = phoneNum.charAt(i)
				if (validChars.indexOf(testChar) == "-1") { //testChar is not valid
					return false
				}
			}
				return true
		default :
				return false
	}
	return true
}

function validateTimes(begin, end) { // validates that begin time is before the end time
	if (begin >= end) {
		alert("Please choose a beginning time that occurs before the ending time!")
		return false
	}
	return true
}
