function formatTime(f) {
	//get the current value in the form field
	var theTime = f.value
	
	//stop the script if no time was entered
	if(!theTime) return
	/*******************************************************************************
	 * remove any periods and colons from theTime using a regular expression
	 * the regular expression is
	 *
	 *    /:|\./gi
	 *
	 * The regular expression is delimited by the two forward slashes(//)
	 * We wish to remove any colons (:) or periods (.), so we put both characters
	 * into the regular expression seperated by the OR (|) operator. The backslash (\)
	 * in front of the period is there because the period has a special meaning in
	 * regular expressions, so it must be escapted.  The two letters after the final
	 * forward slash (gi) indicate a global search, meaning to search for the characters
	 * more then once, and a case insensitive search
	 *
	 * We're removing these "valid" characters because we'll reinsert them later.
	 * Since entered times may only have numbers, a colon and a period, these are
	 * removed to determine if the remaining characters are numbers.
	 *******************************************************************************/
	theTime = theTime.replace(/:|\./gi,"")

	//create a regular expression that will test for non numeric characters
	var regEx = new RegExp("\\D")
	
	//if the number has any non numeric characters in it
	//or if the number is longer then 6 characters, then an invalid time was entered
	if(regEx.test(theTime) || theTime.length > 6) {
		//display an alert that the time is invalid
		alert("Invalid Time")
		
		//set focus to the form field
		f.focus()
		
		//return false
		return false
	}
	else {
		//otherwise, format the time
		
		//get the hundredths portion of the time by getting
		//the last two numbers
		var hundredthsPart = theTime.slice(-2)
		
		//get the seconds part by getting the characters
		//between the fourth position and the second to last
		var secondsPart = theTime.slice(-4,theTime.length-2)
		
		//get the minutes time by getting the remaining characters
		//excluding the last 4.  If the times is 4 characters or less
		//then minutesPart will be empty
		var minutesPart = theTime.slice(0,theTime.length-4)

		//if minutesPart is not empty, then format it to include
		//the colon after the minute
		if(minutesPart) minutesPart = minutesPart + ":"
		
		//add the minutesPart, the secondsPart a period and the hundredthsPart
		theTime = minutesPart + secondsPart + "." + hundredthsPart
		
		//set the form field value to theTime 
		f.value = theTime
		
		return true
		
	}
}


function openWindow(location,query) {
	var randomNumber= Math.random()
	randomNumber = Math.floor(randomNumber * 1000000) + 1
	var windowName = "OregonSwimming" + randomNumber
	
	var location=location + "?" + query
	
	var parameters = 'directories=no,height=600,width=400,resizable=no,status=no,toolbar=no,scrollbars=yes,titlebar=yes'
	window.open(location,windowName,parameters)
}

function checkDate(f) {
	//this function will check if the date is valid
	var theDate = f.value
	
	var passed = true
	if(theDate.length == 0) return
	
	//first split the supplied date by the forward slashes
	var temp = theDate.split("/")
	var theMonth = parseInt(temp[0])
	var theDay = parseInt(temp[1])
	var theYear = temp[2]
	
	var numDays = getMonthLen(theYear,theMonth)
	
	if(!theYear || !theDay || !theMonth) {
		alert("Please enter a valid date")
		passed = false
	}
	//check if the date is valid
	else if(theYear.length < 4) {
		alert("The Year needs to be four digits")
		passed = false
	}
	//check if the month is valid
	else if(theMonth < 1 || theMonth > 12) {
		alert("The month needs to be a value between 1 and 12")
		passed = false
	}
	//check if the entered day is valide	
	else if(theDay < 1 || theDay > numDays) {
		alert("The number of days can not be less then one and more then " + numDays + ".")
		passed = false
	}
	
	if(passed == false) {
		f.value = ''
		f.focus()
	}
}

// number of days in the month
function getMonthLen(theYear, theMonth) {
	if(!theYear || ! theMonth) return
	theMonth = theMonth-1
	var oneHour = 1000 * 60 * 60
	var oneDay = oneHour * 24
	var thisMonth = new Date(theYear, theMonth, 1)
	var nextMonth = new Date(theYear, theMonth + 1, 1)
	var len = Math.ceil((nextMonth.getTime() - thisMonth.getTime() - oneHour)/oneDay)
	return len
}

 function moveCursor(num,evt,numCols) {
  var nextNum;
  
  evt = (evt) ? evt : event;
  var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
  
  switch(charCode) {
   case 40:   //arrow down
    nextNum = num+numCols;
    break;
   case 37:   //arrow left
    nextNum = num-1;
    break;
   case 39:   //arrow right
    nextNum = num+1;
    break;
   case 38:   //arrow up
    nextNum = num-numCols;
    break;
   default:
    return true;
    break;
  }
  var nextItem = "element" + nextNum;
 
  var nextElement = document.getElementById(nextItem);
  if(nextElement) {
	  //nextElement.focus();
	  nextElement.select();
  }
  else return true;
 
 }
 
function deleteNews(idNum) {
	if(idNum) {
		if(confirm("Are you sure you want to delete this news story?")) {
			window.location="editNews.php?delete=" + idNum
		}
	}
}
function deletePerson(idNum) {
	if(confirm("Are you sure you want to delete this person?")) {
		window.location="editPeople.php?delete=" + idNum
	}
}
function deleteRecord(idNum) {
	if(confirm("Are you sure you want to delete this record?")) {
		window.location="editRecords.php?delete=" + idNum
	}
}
	
function deleteMeet(idNum) {
	if(idNum) {
		if(confirm("Are you sure you want to delete this meet?")) {
			window.location="editCalendar.php?delete=" + idNum
		}
	}
}

function validateJobsForm(f) {
	if (trim(f.rname.value) == "") {
		alert("Please enter your name.");
		return false;
	}
	else if(trim(f.remail.value) == "") {
		alert("Please enter your email address.");
		return false;
	}
	else if(trim(f.title.value) == "") {
		alert("Please enter a job title.");
		return false;
	}
	else if(trim(f.club.value) == "") {
		alert("Please enter the club or organization.");
		return false;
	}
	else if(trim(f.text.value) == "") {
		alert("Please enter the text of your advertisement.");
		return false;
	}
	else {
		return true;
	}
}

function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

var backgrounds = new Array();
var myTimer = new Array();
var myElems = new Array();
var counts = new Array();
function unsetBackground(elem) {
	elem.style.background = "none";
}

function setBackground(elem) {
	
	elem.style.background= "#dcdcdc";
}
function increment(uniqueid) {
	//alert(backgrounds[uniqueid]);
	if(backgrounds[uniqueid] >= 220) {
		var colorString = d2h(backgrounds[uniqueid]);
		myElems[uniqueid].style.backgroundColor = "#" + colorString + colorString + colorString;
		backgrounds[uniqueid] = backgrounds[uniqueid] - 1;
	}
	else {
		clearInterval(myTimer[uniqueid]);
		myElems[uniqueid] = null;
		backgrounds[uniqueid] = null;
	}
}
function decrement(uniqueid) {
	//alert(backgrounds[uniqueid]);
	if(backgrounds[uniqueid] <= 255) {
		var colorString = d2h(backgrounds[uniqueid]);
		myElems[uniqueid].style.backgroundColor = "#" + colorString + colorString + colorString;
		backgrounds[uniqueid] = backgrounds[uniqueid] + 1;
	}
	else {
		clearInterval(myTimer[uniqueid]);
		myElems[uniqueid] = null;
		backgrounds[uniqueid] = null;
	}
}
function d2h(d) {return d.toString(16);}

function doHide(div) {
	fDiv = document.getElementById(div);
	fader = new faderObj();
	fader.div = fDiv;
	fader.startHide();
}	

function findPosY(obj)
	{
		var curtop = 0;
		if (obj.offsetParent)
		{
			while (obj.offsetParent)
			{
				curtop += obj.offsetTop
				obj = obj.offsetParent;
			}
		}
		else if (obj.y)
			curtop += obj.y;
				return curtop;
	}
	function findPosX(obj)
	{
		var curleft = 0;
		if (obj.offsetParent)
		{
			while (obj.offsetParent)
			{
				curleft += obj.offsetLeft
				obj = obj.offsetParent;
			}
		}
		else if (obj.x)
			curleft += obj.x;
		return curleft;
		
		
	}
	
	function time2Integer(theTime)
	{
		var times = new array();
		var returnTime = "";
		
		//echo "$theTime - " . substr_count($theTime, ":");
		if(theTime.match(/:/)) {
		
			times = theTime.split(":");
			//echo " times[0] = $times[0] && times[1] = $times[1] ";
			returnTime = times[0]*60 + times[1];
			returnTime = returnTime * 100;
			//echo " returnTime = $returnTime<br>\n";
		}		
		else { returnTime = theTime * 100; }
		return returnTime;
	}
	
	function integer2Time(theTime)
	{
		theTime = theTime / 100.0;
		
		if(theTime < 60)
		{
			//format the time so that there are two decimal places
			returnTime = number_format(theTime,2,'.',',');
		}
		else
		{
			//get the minutes
			var t = theTime / 60.0;
			var temp = t + "";
			var temp1 = new Array();
			temp1 = temp.split(/\./);
			theMinutes = temp1[0];
			theSeconds = theTime - (theMinutes*60);
			theSeconds = number_format(theSeconds,2,'.',',');
			if(theSeconds.length == 4) theSeconds = "0"  + theSeconds;
			returnTime = theMinutes + ":" + theSeconds;
		}
		
		return returnTime;
	}
	
	function number_format(a, b, c, d) {
	// number_format(number, decimals, comma, formatSeparator)
	a = Math.round(a * Math.pow(10, b)) / Math.pow(10, b);
	e = a + '';
	f = e.split('.');
	if(!f[0]) f[0] = '0';
	if(!f[1]) f[1] = '';
	if(f[1].length < b){
		g = f[1];
		for(i = f[1].length + 1; i <= b; i++) {
			g += '0';
		}
		f[1] = g;
	}
	if(d != '' && f[0].length > 3) {
		h = f[0];
		f[0] = '';
		for(j = 3; j < h.length; j += 3) {
			i = h.slice(h.length - j, h.length - j + 3);
			f[0] = d + i +  f[0] + '';
		}
		j = h.substr(0, (h.length % 3 == 0) ? 3 : (h.length % 3));
		f[0] = j + f[0];
	}
	c = (b <= 0) ? '': c;
	return f[0] + c + f[1];
}

function getCheckedValue(radioObj) {
	if(!radioObj) return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		if(radioObj.checked) {
			return radioObj.value;
		}
		else {
			return "";
		}
	}
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

