
/* *********************************************************************** */
/* This functions properly spaces content below the second iframe */
/* *********************************************************************** */
function afteriframe() {
	if (navigator.product == 'Gecko') {
		document.write("<br />\n");
	}
	else {
		document.write("<br /><br />\n");
	}
}


/* *********************************************************************** */
/* Today's Date */
/* *********************************************************************** */
function gettodaysdate() {
	// Array of day names
	var dayNames = new Array("Sunday","Monday","Tuesday","Wednesday",
					"Thursday","Friday","Saturday");
	
	// Array of month Names
	var monthNames = new Array(
	"Jan","Feb","Mar","Apr","May","Jun","Jul",
	"Aug","Sep","Oct","Nov","Dec");
	
	var now = new Date();
	document.write(dayNames[now.getDay()] + ", " + 	monthNames[now.getMonth()] + " " + 
		now.getDate() + ", " + now.getFullYear());
}

/* *********************************************************************** */
/* Home page functions */
/* *********************************************************************** */
function getInternetExplorerVersion() {
	// Returns the version of Internet Explorer or a -1
	// (indicating the use of another browser).

	var rv = -1; // Return value assumes failure
	if (navigator.appName == 'Microsoft Internet Explorer') {
		var ua = navigator.userAgent;
		var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
		if (re.exec(ua) != null)
			rv = parseFloat( RegExp.$1 );
	}
	return rv;
}
				
/* *********************************************************************** */
function winalign() {
	if (getInternetExplorerVersion() > 0 && getInternetExplorerVersion() < 7) {
		window.resizeBy( -10, -10 );
		//window.resizeBy( 10, 10 );
	}
}

/* *********************************************************************** */
function check_ie6() {

	var bName = navigator.appName;
	var bVer = getInternetExplorerVersion();
	
	if (bName == "Microsoft Internet Explorer" && bVer < 7.0) {
		window.document.write("<p>Your browser is out-of-date.  littlerun.com recommends upgrading to " +
			"<a href=\"http://www.microsoft.com/windows/downloads/ie/getitnow.mspx\">" +
			"Internet Explorer 7</a> " +
			"or better yet <a href=\"http://www.getfirefox.com\">Firefox 2</a>.</p>");
	}
}

/* *********************************************************************** */
function check_ie() {

	var bName = navigator.appName;

	if (bName == "Microsoft Internet Explorer") {
		window.document.write("\t\t\t\t<br />\n");
	}
}

/* *********************************************************************** */
function getfirefox() {

	if (navigator.appName == "Microsoft Internet Explorer") {
		window.document.write("<a href=\"http://getfirefox.com/\" " +
			"title=\"Get Firefox - The Browser, Reloaded.\">" +
			"<img src=\"http://www.mozilla.org/products/firefox/buttons/getfirefox_88x31.png\" " + 
			"width=\"88\" height=\"31\" border=\"0\" style=\"vertical-align: middle;\" " +
			"alt=\"Get Firefox\" /></a>"); 
	}
}

/* *********************************************************************** 
		Pace Calculator Functions
 *********************************************************************** */
function calculate_pace() {

	var t = document.getElementById("time").value;
	var d = document.getElementById("distance").value;
	
	if (timeToSeconds(t) == "Bad Time Format.  Try HH:MM:SS") {
		alert(timeToSeconds(t));
	}
	else {
		window.document.getElementById("span_pace").innerHTML = 
			secondsToTime(timeToSeconds(t) / d) + " minutes per mile.";
	}
}

/* *********************************************************************** */
function timeToSeconds(t) {

	var hr;
	var min;
	var sec;
	
	if(t.length == 5) {
		min = t.substr(0,2);
		sec = t.substr(3,2);

		return 1*min*60 + 1*sec;		
	}
	else if(t.length == 7 && t.substr(5,1) == '.') {
		min = t.substr(0,2);
		sec = t.substr(3,4);

		return 1*min*60 + 1*sec;		
	}
	else if(t.length == 7 && t.substr(1,1) == ':' && t.substr(4,1) == ':') {
		hr = t.substr(0,1);
		min = t.substr(2,2);
		sec = t.substr(5,2);

		return 1*hr*3600 + 1*min*60 + 1*sec;		
	}
	else if(t.length == 8 && t.substr(2,1) == ':' && t.substr(5,1) == ':') {
		hr = t.substr(0,2);
		min = t.substr(3,2);
		sec = t.substr(6,2);

		return 1*hr*3600 + 1*min*60 + 1*sec;		
	}
	else {
		return ("Bad Time Format.  Try HH:MM:SS");
	}
}

/* *********************************************************************** */
function secondsToTime(s) {
	
	var hr = Math.floor(s/3600);
	var min = Math.floor( (s - hr*3600) / 60);
	var sec = Math.floor((s - hr*3600 - min*60)*10)/10;

	if (hr > 0) {
		var strHr = hr + ":";
	}
	else {
		var strHr = "";
	}
	
	if (min < 10 && hr > 0) {
		var strMin = "0" + min + ":";
	}
	else {
		var strMin = min + ":";
	}
	
	if (sec < 10) {
		var strSec = "0" + sec;
	}
	else {
		var strSec = "" + sec;
	}
	
	return strHr + strMin + strSec;
}

