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 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 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 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]) < 1 || eval(dateArray[2]) > 10) {
		alert("Invalid year!")
		return false
	} 
	return true
}

function validateTimes(form) { // validates that check in time is after the check out time
	var dayOut = form.ResDateOut.value 
	var timeOutString = form.TimeOut.value
	var timeOut = timeOutString.substring(0,timeOutString.indexOf(":"))
	if (timeOutString.indexOf("P") != -1 && timeOut != 12) { timeOut = parseInt(timeOut)+12 }
	var dayIn = form.DateIn.value
	var timeInString = form.TimeIn.value
	var timeIn = timeInString.substring(0,timeInString.indexOf(":"))
	if (timeInString.indexOf("P") != -1 && timeIn != 12) { timeIn = parseInt(timeIn)+12 }
	//alert("'" + timeOut + "'" + timeIn + "'")
	if (Date.parse(dayIn) == Date.parse(dayOut) && parseInt(timeIn) <= parseInt(timeOut)) { 
		alert("The check in time must be after the check out time.")
		return false 
	}	
	return true
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
		newWindow = window.open(theURL,winName,features);
		newWindow.focus()
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function isInteger(theNum) {
	var validChars = "0123456789"
	//check that all characters in number are OK
	for (var i = 0; i < (theNum.length); i++) { 
		testChar = theNum.charAt(i)
		if (validChars.indexOf(testChar) == "-1") { //testChar is not valid
			return false
		}
	}	
	return true
}

function isPNFloat(theNum) { // verifies that theNum is a positive or negative float value and does not contain text
	var validChars = "0123456789."
	var decimalCount = 0
	//check that all characters in number are OK
	for (var i = 0; i < (theNum.length); i++) { 
		testChar = theNum.charAt(i)
		if(i == 0 && testChar == "-") {
		} else {
			if (validChars.indexOf(testChar) == "-1") { //testChar is not valid
			return false
		}
		if(testChar == ".") { decimalCount++ }
		//alert(theNum.charAt(i))
		if (decimalCount > 1) { return false }
		}
	}
	return true	
}

function isFloat(theNum) { // verifies that theNum is a positive float value and does not contain text
	var validChars = "0123456789."
	var decimalCount = 0
	//check that all characters in number are OK
	for (var i = 0; i < (theNum.length); i++) { 
		testChar = theNum.charAt(i)
		if(theNum.charAt(i) == ".") { decimalCount++ }
		//alert(theNum.charAt(i))
		if (decimalCount > 1) { return false }
		if (validChars.indexOf(testChar) == "-1") { //testChar is not valid
			return false
		}
	}
	return true	
}

function optionalIntegers(theValue) { // validates optional integer value fields
	if(theValue == "" ) {
		return true
	}
	else {
		if(!isInteger(theValue)) {
			return false
		}
		else {
			return true
		}
	}
}

function optionalPhoneNum(theValue) { // validates optional phone number fields
	if(theValue == "" ) {
		return true
	}
	else {
		if(!validatePhone(theValue)) {
			return false
		}
	}
	return true
}

function fixDecimals(theValue) { // returns the value with two decimal places by adding zeros where needed
	theValue = theValue * 100
	theValue = Math.round(theValue)
	theValue = String(theValue/100)
	if(theValue.indexOf(".") == -1) { // no decimals at all; add two zeroes
		return theValue + ".00" }
	else if(theValue.lastIndexOf(".") == (theValue.length -2))  { // only one decimal; add one zero
		return theValue + "0" }
	else {
		return theValue
	}	
}
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="../~/_scripts/'+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="../~/_scripts/'+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>');
}
