// JavaScript Document

function MM_findObj(n, d) { //v4.01
  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 && d.getElementById) x=d.getElementById(n); return x;
}
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 validEmail(email) {
			invalidChars = " /:,;"
	
			for (i=0; i<invalidChars.length; i++) {	// does it contain any invalid characters?
				badChar = invalidChars.charAt(i)
				if (email.indexOf(badChar,0) > -1) {
					return false
				}
			}
			atPos = email.indexOf("@",1)			// there must be one "@" symbol
			if (atPos == -1) {
				return false
			}
			if (email.indexOf("@",atPos+1) != -1) {	// and only one "@" symbol
				return false
			}
			periodPos = email.indexOf(".",atPos)
			if (periodPos == -1) {					// and at least one "." after the "@"
				return false
			}
			if (periodPos+3 > email.length)	{		// must be at least 2 characters after the "."
				return false
			}
			return true
		}
function isNum(value) {

for (i=0; i<value.length; i++) {
	if (value.charAt(i) < "0") { return false; }
	if (value.charAt(i) > "9") { return false; }
}	

return true;

}

function validateContactForm(theForm)
{
	var from = theForm.from.value;
	var phone = theForm.phone.value;
	var phoneLength = theForm.phone.value.length;
	var department = theForm.department.value;
	var message = theForm.message.value;
	
	//alert ('Phone Length = ' + phoneLength + '');
	
	// Start ------->

	if (department == "#") {
		alert('Please choose a category');
		theForm.department.focus();
		return false;
	}
	if (phone == "") {
		alert('Please enter a valid phone number so we may contact you.');
		theForm.phone.focus();
		return false;
	}


	if (!from == "") {
		if (!validEmail(from)) {
			alert('' + from + ' is not a valid email address');
			theForm.from.focus();
			return false;
		}
	}
	if (!phone == "") {
		if ((!isNum(phone)) || (phoneLength != 10)) {
			alert('' + phone + ' is not a valid phone number\nPlease enter a 10-digit nubmer without spaces');
			theForm.phone.focus();
			return false;
		}
	
	}
	
	if (message == "") {
		alert('Please enter your question');
		theForm.message.focus();
		return false;
	}	
	
	return true;
}

function MM_openBrWindowFull(url) 
{
	var width = screen.width;
	var height = screen.height;
	var features = "width=" + width + ",height=" + height + ",scrollbars,resizable";

	
	newWindow = window.open(url,'win',features);
	newWindow.focus();


}


function MM_openBrWindow(theURL,winName,features) { //v2.0

	// create first array to hold values of 'features' array
	var temp = new Array(); 
	
	// split 'features' array at the ',' comma to reveal name value pairs (name = value)
	temp = features.split(','); 
	
	// create second array to hold name/value pairs
	var multi = new Array(); 

		// Loop through first array and split the name value pairs at the '=' sign
		for (i=0;i<temp.length;i++) {				
			multi[i] = temp[i].split('=');
			
				// if name = width, assign value to width variable
				if (multi[i][0] == "width") {
					var width = multi[i][1];
				}
					// if name = height, assign value to height variable
					if (multi[i][0] == "height") {
						var height = multi[i][1];
					}

		}
		
	// create left position and top position variables, append to 'features' argument
	// and return new window now positioned in middle of screen
	leftpos = (screen.width - width) / 2;
	toppos = (screen.height - height) / 2;
	newfeatures = features + ",left="+leftpos+",top="+toppos+"";
	
	NewWindow = window.open(theURL,winName,newfeatures);
	NewWindow.focus();
}


function MM_openMapWindow(theURL,winName) { //v2.0

	var features = "resizable=yes,width=685,height=550";

	// create first array to hold values of 'features' array
	var temp = new Array(); 
	
	// split 'features' array at the ',' comma to reveal name value pairs (name = value)
	temp = features.split(','); 
	
	// create second array to hold name/value pairs
	var multi = new Array(); 

		// Loop through first array and split the name value pairs at the '=' sign
		for (i=0;i<temp.length;i++) {				
			multi[i] = temp[i].split('=');
			
				// if name = width, assign value to width variable
				if (multi[i][0] == "width") {
					var width = multi[i][1];
				}
					// if name = height, assign value to height variable
					if (multi[i][0] == "height") {
						var height = multi[i][1];
					}

		}
		
	// create left position and top position variables, append to 'features' argument
	// and return new window now positioned in middle of screen
	leftpos = (screen.width - width) / 2;
	toppos = (screen.height - height) / 2;
	newfeatures = features + ",left="+leftpos+",top="+toppos+"";
	
	NewWindow = window.open(theURL,winName,newfeatures);
	NewWindow.focus();
}


//Contact Form Validation
//

function validEmail(email) {
			invalidChars = " /:,;"
	
			for (i=0; i<invalidChars.length; i++) {	// does it contain any invalid characters?
				badChar = invalidChars.charAt(i)
				if (email.indexOf(badChar,0) > -1) {
					return false
				}
			}
			atPos = email.indexOf("@",1)			// there must be one "@" symbol
			if (atPos == -1) {
				return false
			}
			if (email.indexOf("@",atPos+1) != -1) {	// and only one "@" symbol
				return false
			}
			periodPos = email.indexOf(".",atPos)
			if (periodPos == -1) {					// and at least one "." after the "@"
				return false
			}
			if (periodPos+3 > email.length)	{		// must be at least 2 characters after the "."
				return false
			}
			return true
		}
function isNum(value) {

for (i=0; i<value.length; i++) {
	if (value.charAt(i) < "0") { return false; }
	if (value.charAt(i) > "9") { return false; }
}	

return true;

}

function validateEmail(theForm) {
	
	var emailValue = theForm.from.value;
	if (!emailValue) {
		alert ('You must enter an email address');
		theForm.from.focus();
		return false;
	}
	if (!validEmail(emailValue)) {
		alert('' + emailValue + ' is not a valid email address');
		theForm.from.focus();
		return false;
	}
}

function validateForm(theForm)
{
	var from = theForm.from.value;
	var phone = theForm.phone.value;
	var phoneLength = theForm.phone.value.length;
	var department = theForm.department.value;
	var message = theForm.message.value;
	
	//alert ('Phone Length = ' + phoneLength + '');
	
	// Start ------->

	if (department == "#") {
		alert('Please choose a category');
		theForm.department.focus();
		return false;
	}
	
	if (phone == "") {
		alert('Please enter a valid phone number so we may contact you\nin case we have any questions');
		theForm.phone.focus();
		return false;
	}
	

	if (!from == "") {
		if (!validEmail(from)) {
			alert('' + from + ' is not a valid email address');
			theForm.from.focus();
			return false;
		}
	}
	if (!phone == "") {
		if ((!isNum(phone)) || (phoneLength != 10)) {
			alert('' + phone + ' is not a valid phone number\nPlease enter a 10-digit nubmer without spaces');
			theForm.phone.focus();
			return false;
		}
	
	}
	
	if (message == "") {
		alert('Please enter your question');
		theForm.message.focus();
		return false;
	}	
	
	return true;
}

// End Contact Form Validation


function register() {
	
	var activityID = document.getElementById('activityID').value;	
	var newCourseID = -1;
	
		for (i=0;i<document.getElementsByName('courseID').length;i++) {
		
			if (document.getElementsByName('courseID')[i].checked) {
			
				var newCourseID = document.getElementsByName('courseID')[i].value; 
			}
		}
	
	if (newCourseID == -1) {
			alert ("Please choose the race you would like to register for");
			return false;
		}
		
	else if(!document.getElementById('termagree').checked) {	
		alert("You need to agree with the waiver above to proceed.");
		return false;
	}	
		
	else {

	
	webaddress = 'http://online.activecommunities.com/elite/MyBasket/MyBasket.asp?Type=1&AddCourse=' + activityID + '~' + newCourseID + '~0~0~0~0~0';
	
    // alert ("Web Address = " + webaddress + "");
	
	newWindow = window.open(webaddress,'win','height=500,width=750,toolbar=yes,location=yes,status=yes,scrollbars=yes,resizable=yes');	
	newWindow.focus();

	}

}

function registerTeam() {
	
	var activityID = document.getElementById('activityID').value;	
	var newCourseID = -1;
	var newWindow;
	
		for (i=0;i<document.getElementsByName('courseID').length;i++) {
		
			if (document.getElementsByName('courseID')[i].checked) {
			
				var newCourseID = document.getElementsByName('courseID')[i].value; 
			}
		}
	
	if (newCourseID == -1) {
			alert ("Please choose the category of your team/group");
			return false;
		}	
		
	else {

	
	webaddress = 'https://online.activecommunities.com/elite/MyAccount/MyAccountCreateNewTeam.asp?activityID=' + activityID + '&courseID=' + newCourseID + '';
	
    // alert ("Web Address = " + webaddress + "");
	
	newWindow = window.open(webaddress,'win','height=500,width=750,toolbar=yes,location=yes,status=yes,scrollbars=yes,resizable=yes');	
	newWindow.focus();

	}

}

function termscond(){
	if(document.getElementById('termagree').checked) {	
		register();
		}
		else {
			alert("You need to agree with the waiver above to proceed.");
			return false;
		}
							   	
}

/***********************************************
* Show Hint script- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

/////Get Fit popup info on registration page
var sjgetfitinfo = "<p> Rally your organization to form a team and start training for the 2008 GET FIT Challenge! Corporations, schools, running clubs and other organized groups are encouraged to take part in the GET FIT fun!</p> <p align=right><a href=/Page1637.aspx>More info</a> | <a href=javascript:;>Close</a></p>";

		
var horizontal_offset="9px" //horizontal offset of hint box from anchor link

/////No further editting needed

var vertical_offset="0" //horizontal offset of hint box from anchor link. No need to change.
var ie=document.all
var ns6=document.getElementById&&!document.all

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
if (whichedge=="rightedge"){
var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-30 : window.pageXOffset+window.innerWidth-40
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth+parseInt(horizontal_offset)
}
else{
var windowedge=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight
}
return edgeoffset
}

function showhint(menucontents, obj, e, tipwidth){
if ((ie||ns6) && document.getElementById("hintbox")){
dropmenuobj=document.getElementById("hintbox")
dropmenuobj.innerHTML=menucontents
dropmenuobj.style.left=dropmenuobj.style.top=-500
if (tipwidth!=""){
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=tipwidth
}
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.offsetWidth+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px"
dropmenuobj.style.visibility="visible"
dropmenuobj.onclick=hidetip
}
}

function hidetip(e){
dropmenuobj.style.visibility="hidden"
dropmenuobj.style.left="-500px"
}

function createhintbox(){
var divblock=document.createElement("div")
divblock.setAttribute("id", "hintbox")
document.body.appendChild(divblock)
}

if (window.addEventListener)
window.addEventListener("load", createhintbox, false)
else if (window.attachEvent)
window.attachEvent("onload", createhintbox)
else if (document.getElementById)
window.onload=createhintbox


/***********************************************
* END Show Hint script- © Dynamic Drive (www.dynamicdrive.com)
***********************************************/

