function isEmpty(inputVal) {
	if (inputVal == null || inputVal == "") {
		return true
		}
	return false
}

function isInteger(inputVal) {
	if (isEmpty(inputVal)) {
		return false
		}
	inputStr = inputVal.toString()
	for (var i = 0; i < inputStr.length; i++) {
		var oneChar = inputStr.charAt(i)
		if (i == 0 && oneChar == "-") {
			continue
		}
		if (oneChar < "0" || oneChar > "9") {
			return false
		}
	}
	return true
}

function isPosInteger(inputVal) {
	if (isEmpty(inputVal)) {
		return false
		}
	inputStr = inputVal.toString()
	for (var i = 0; i < inputStr.length; i++) {
		var oneChar = inputStr.charAt(i)
		if (oneChar < "0" || oneChar > "9") {
			return false
		}
	}
	return true
}

function inRange(inputStr,i,j) {
	if (!isInteger(inputStr)) {
		return false
		}
	num = parseInt(inputStr)
	if (num < i || num > j) {
		return false
	}
	return true
}

function isYear(s) {
	if (isEmpty(s)) 
	   if (isYear.arguments.length == 1) return false;
	   else return (isYear.arguments[1] == true);
	if (!isPosInteger(s)) return false;
	return ((s.length == 2) || (s.length == 4));
}

function isMonth(s) {
	if (isEmpty(s)) 
	   if (isMonth.arguments.length == 1) return false;
	   else return (isMonth.arguments[1] == true);
	return inRange (s, 1, 12);
}

function isDay(s) {
	if (isEmpty(s)) 
	   if (isDay.arguments.length == 1) return false;
	   else return (isDay.arguments[1] == true);   
	return inRange (s, 1, 31);
}

function makeArray(n) {
   for (var i = 1; i <= n; i++) {
	  this[i] = 0
   } 
   return this
}

var daysInMonth = makeArray(12);
	daysInMonth[1] = 31;
	daysInMonth[2] = 29;   // must programmatically check this
	daysInMonth[3] = 31;
	daysInMonth[4] = 30;
	daysInMonth[5] = 31;
	daysInMonth[6] = 30;
	daysInMonth[7] = 31;
	daysInMonth[8] = 31;
	daysInMonth[9] = 30;
	daysInMonth[10] = 31;
	daysInMonth[11] = 30;
	daysInMonth[12] = 31;

function daysInFebruary (year) {
	return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
}

function isDate (year, month, day) {
	if (! (isYear(year) && isMonth(month) && isDay(day))) return false;

	var intYear = parseInt(year);
	var intMonth = parseInt(month);
	var intDay = parseInt(day);

	if (intDay > daysInMonth[intMonth]) return false; 

	if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false;

	return true;
}

function validate(form) {
	if (!isDate(form.year.options[form.year.selectedIndex].value,form.month.options[form.month.selectedIndex].value,form.day.options[form.day.selectedIndex].value)) {
		alert("That date is invalid.")
		form.month.focus()
		return false
	}
}
	
function popUp(doc,w,h,align,valign,scroll,menubar) {
	if (popUp.arguments.length < 7) {
		var menubar = 'no'
	}
	if (popUp.arguments.length < 6) {
		var scroll = 'yes'
	}
	if (popUp.arguments.length < 4) {
		var align = 'c'
		var valign = 'm'
	}
	topPos=0
	leftPos=0
	if (screen) {
		if (align == 'c') {
			leftPos = screen.width/2 - w/2
		} else {
			if (align == 'r') {
				leftPos = screen.width - w - 12
			}
		}
		if (valign == 'm') {
			topPos = screen.height/2 - h/2
		} else {
			if (valign == 'b') {
				topPos = screen.height - h - 45
			}
		}
	}
	custWin = window.open (doc,'custWin','toolbar=no,menubar='+menubar+',location=no,scrollbars='+scroll+',resizable=yes,width='+w+',height='+h+',left='+leftPos+',top='+topPos+'')
	custWin.document.close()
	custWin.focus()	
}

function isNumeric(strString) {
   var strValidChars = "0123456789.";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return true;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++) {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1) {
         blnResult = false;
       }
    }
   return blnResult;
}


function toggleDiv(id) {
	var divs = Array('overview','biography','experience');
	for(var i=0;i<divs.length;i++){
		if (!document.getElementById(divs[i]+'_link')) continue; // if no link is defined, skip it
		document.getElementById(divs[i]).style.display = 'none'; // make other divs hide
		document.getElementById(divs[i]+'_link').className = 'lo'; // make other anchors lo
	}
	document.getElementById(id).style.display = 'block'; // make this div selected
	document.getElementById(id+'_link').className = 'hi';
}
