<!--
//------------------------------------
//Common functions used on the site.
//last modified:  11/24/2010 by CDW
//------------------------------------

//Global variables, used on forms.
var place = getQueryVariable('place');
var url = getQueryVariable('url');
var sval = "Search";

//Run common functions on page load.
function init() {	
	if (document.getElementById('page').className.match('form')) { //setting some options on page if a form.
		formUtils();
	}
}

function formUtils() {
	//default fallback function if page specific formUtils() does not exist. DO NO DELETE.
}

//Get location on forms to return user to previous location
function formsLocation(goURL,ifsearch) {
	var place = escape(document.title);
	var fromURL = window.location.toString();
	if (ifsearch == null ) {
		window.location = goURL+"?place="+place+"&url="+escape(fromURL);
	} else if (ifsearch == "yes") {
		window.location = goURL;
	}
}
//Write link on 'thanks' pages of forms.
function writeReturnLink(place,url) {
	if (place != null && url != null) {
		document.write("Return to: <a href='"+unescape(url)+"'>"+unescape(place)+"</a>.");
	}
}

//Form - select box go script
function getOption(form) {
	if (form.options[form.selectedIndex].value != "#") {
		location = form.options[form.selectedIndex].value;
	}	
}
//Check email for basic struture like an @ sign on newsletter signup
function chkEmail(form) {
	if (!form.EmailAddress.value.match('@')) {
		alert("Please provide a properly formatted e-mail address.");
		form.EmailAddress.focus();
		return false;
	} else {
		return true;
	}
}

//check validatity of email address on login forms
function isValidEmail(email) {
     var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/; 
     return emailPattern.test(email);
}

//Form Validation - basic check to see of field empty or not checked.
function formValidation(form,formErrors) {	
	var fields = form.elements;
	var formErrors2 = "";
	var details = "<ul>";
	
	if (formErrors == null) { // chk if any form specific errors have been passed in
		formErrors2 = "";
	} else if (formErrors != "") {
		formErrors2 = formErrors;
	}	//alert("details = " + details + "<br>formErrors = " + formErrors2);
	var boxli, radli = 0;
	for (var i = 0; i < fields.length; i++ ){
		if (fields[i].className.match("required")) {
			//chk text and textarea fields
			if ((fields[i].type == 'text' || fields[i].type == 'textarea' || fields[i].type == 'password') && !fields[i].value.length > 0) {
				details += "<li>"+fields[i].title+" is blank.</li>";
			//chk radio buttons
			} else if (fields[i].type == 'radio' ) {
				//do something
				var rname = fields[i].name;
				var radio = document.getElementsByName(rname);
				for (cnt = x = 0; x < radio.length; x++ ) {
					if (radio[x].checked) cnt++; 
				}
				if (cnt == 0 && (!details.match(fields[i].title))) { //check to see if li already in 'details'
					radli++;
					details += "<li>"+fields[i].title+" does not have a selection.</li>";
				}
			} 
			//check checkboxes (single or groups)
			else if (fields[i].type == 'checkbox') { 
				var boxName = fields[i].name;
				var boxes = document.getElementsByName(boxName);
				for (cnt = x = 0; x < boxes.length; x++ ) {
					if (boxes[x].checked) cnt++; 
				}
				if (cnt == 0 && (!details.match(fields[i].title))) { //check to see if li already in 'details'
					boxli++;
					details += "<li>"+fields[i].title+"</li>";
				}				
			} 
			//email format check - primarily for login/create account/forgot password form
			else if (fields[i].className.match("form-email")) {
				var email = fields[i].value;
				if (isValidEmail(email) == false) {
					details += "<li>The provided email address is not properly formatted; please enter a valid email address (ex. name@gmail.com).";	
				}
			}			
			//select drop downs
			else if (fields[i].tagName == 'SELECT' && (fields[i].value == '#' || fields[i].value == '')) { 
				details += "<li>"+fields[i].title+" does not have a selection.</li>";
			} else if ( fields[i].type == 'hidden' ) {
				//skip
			}
		}
	}
	if (details != "<ul>" || formErrors2 != "") {
		details += formErrors2;
		details += '</ul>';
		document.getElementById('validDetails').innerHTML = details;	
		document.getElementById('validSummary').style.display = 'block';
		document.location = "#validSummary";
		return false; 
	} else  {
		//blur_buttons(form); //disabled as seems to cause hickups on ASP pages.
		return true;
	}
}


//blur all buttons on the form
function blur_buttons(form) {
  for (var i=0; i<form.elements.length; i++) {
    if (form.elements[i].type=='button' || form.elements[i].type=='submit' ||
        form.elements[i].type=='reset') {
      form.elements[i].disabled = true;
    }
  }
}

//Get query string from URL.
function getQueryVariable(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
			return pair[1];
		}
  	} 
}

//Highlight side nav category. Show/hide 2nd level nav.
function sidenav(topic,subtopic) {
	if ( topic != '' ) {
		document.getElementById(topic).className = 'topicon';
	}	
	if ( subtopic != '' ) {
  		document.getElementById(subtopic).className = 'subtopicson';
  	}
}

//Page Tool - Add page to favorites.
function pageToolsBookmark() {
	bkmkurl= document.URL;
	bkmktitle= document.title;
	//if (window.external) {
	if (document.all) {
		window.external.AddFavorite(bkmkurl,bkmktitle);
	} else {
		alert("Please use Control + D to set a bookmark for this page");
	}
}


//Page Tool - Email page to coworkers
function pageToolsEmail() {
	var title = document.title;
	var bar = title.indexOf("|");
	title = title.substring(0,bar-1);
	var subj = "You might be interested in this -- "+escape(title);
	var pageurl = document.URL;
	var bodyTxt = "Hi,\n\nI thought you might like to see this Allen Eagles Ice Hockey Page - " + title + ", found at: " + pageurl + ".";
	bodyTxt = escape(bodyTxt);
	document.writeln("<a onmouseover=\"window.status='Recommend this Web page.'; return true\" onmouseout=\"window.status=' ';return true\" onfocus=\"window.status='Recommend this Web page';return true;\" onblur=\"window.status=' ';return true;\" href='mailto:\?subject=" + subj + "\&body\=" + bodyTxt + "' title=\"Recommend this Web page.\" id=\"emailthis\">e-mail</a>");
}

// Ultraseek Search functions
function searchsubmit(form) {
	if (form.qt.value=='') {
		alert("Please type in a keyword");
		form.qt.focus();
		return false;
	}
}
function advancedsearchsubmit() {
	var form = document.advancedsearchform;
	if (form.tx0.value=='' && form.tx1.value=='' && form.tx2.value=='' && form.tx3.value=='' ) {
		alert("Please type in a keyword");
		form.tx0.focus();
		return false;
	}
}
function clearSearch(el) {
	if(el.value==sval) {
		el.value='';		
	}
}
function restoreSearch(el){
	if(el.value=='') el.value=sval;
}

//Author: C. Watkins - 08/2003, Updated: 12/2005
function writeIndicator(expires,what) {
	var today = new Date();
	if (today < expires ) {
		document.write("<strong class='accenttext'>"+what+"!</strong>");
	}  else {
		//document.write("in the else");
	}
}

//Read XML file and display whats new content
function verify() { 
	if(xmlDoc.readyState != 4) {
		false; 
	}
}

//XML feed reader and display script.
function displayXmlFeed(display,xmlfeed,postcount,pagetype,startcount) {
	var xmlDoc = null;
	var file = "";
	if (xmlfeed == "announcements") { //determine file 1st
		file = "/com/xml/announcements.xml";
	} else if (xmlfeed == "schedule") {
		file = "/com/xml/schedule.xml";
	} else {
		//no feed to display
	}
	//Try to get file for browsers
	try { //IE 
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async=false;
		xmlDoc.load(file);
	} catch(e) {
		try { //Firefox, Mozilla, Opera, etc.
			xmlDoc=document.implementation.createDocument("","",null);
			xmlDoc.async=false;
			xmlDoc.load(file);
		} catch(e) {
			try { //Chrome, Safari
				var xmlhttp = new window.XMLHttpRequest();
				xmlhttp.open("GET",file,false);
				xmlhttp.send(null);
				xmlDoc = xmlhttp.responseXML.documentElement;
			}
			catch(e) {
				error=e.message;
			}
		}
	}
	if (xmlDoc != null) {
		xmlDoc.async = false;
		//xmlDoc.onreadystatechange=verify;
		var xml = xmlDoc.getElementsByTagName("item");
		
		if (display == "ul") {
			document.write("<ul>")
			for (var i=0;i<postcount;i++) {
				document.write("<li><a href='");
				document.write(xml[i].getElementsByTagName("link")[0].childNodes[0].nodeValue);
				document.write("'>");
				document.write(xml[i].getElementsByTagName("title")[0].childNodes[0].nodeValue);
				if (xmlfeed == "announcements") {
					document.write(" &raquo; </a></li>");
				} else {
					document.write("</a></li>");
				}
			}
			document.write("</ul>")
		} else if (display == "dl") {
			document.write("<dl class='rssreader'>")
			var i = 0;
			if (startcount != null) { i = startcount; }
			if (postcount == 'all') { postcount = xml.length; }
			for (i;i < postcount;i++) { //<x.length
				var pubDate = xml[i].getElementsByTagName("pubDate")[0].childNodes[0].nodeValue
				pubDate = pubDate.substring(0,11);
				var description = xml[i].getElementsByTagName("description")[0].childNodes[0].nodeValue;
				description = description.replace("[...]","&#8230;");
				
				if (xmlfeed == "announcements") {
					document.write("<dt><span class=\"pubDate\">"+ pubDate + "</span>" + " ");
				} else {
					document.write("<dt>");
				}
				document.write(xml[i].getElementsByTagName("title")[0].childNodes[0].nodeValue);
				document.write("</dt>");	
				document.write("<dd>");
				document.write(description);
				document.write("</dd>");
			}
			document.write("</dl>")
		} else {
			//no other format	
		}
	}
}

-->
