//-----------------------------
function stopEnterKey(evt) {
  var evt = (evt) ? evt : ((event) ? event : null);
  var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
  if ((evt.keyCode == 13) && (node.type=="text"))  {return false;}
}
document.onkeypress = stopEnterKey;
//-----------------------------
function equalizeHeight(){
	var firstCol = document.getElementById("columnLeft");
	var secondCol = document.getElementById("columnRight");
	if(firstCol.clientHeight < secondCol.clientHeight){
		firstCol.style.height = secondCol.clientHeight + "px";
	}
	else{
		secondCol.style.height = firstCol.clientHeight + "px";
	}
}
//-----------------------------
function turnOnButtonCurrentPage(){
	var fileName = location.href.substring(location.href.lastIndexOf('/') + 1);
	var anchorList = document.getElementById('navmenu').getElementsByTagName('a');
	for(var i=0; i<anchorList .length; ++i) {
		var anchorHref = anchorList[i].href;
		anchorHref = anchorHref.substring(anchorHref.lastIndexOf('/') + 1);
		if(anchorHref == fileName) {
			anchorList[i].className = 'buttonSelected';// change the class of this anchor
			//break;
		}
		else{
			anchorList[i].className = '';// change the class of this anchor
		}
	} 
}
//-----------------------------
function clearInputBoxDefaultsOnClick(){
	/* this adds code to all text boxes to make them clear default values on click */
	var textBoxes = new Array();
	var allInputs = new Array();
	var x = 0;
	allInputs = document.getElementsByTagName( 'input' )
	for ( i = 0; i < allInputs.length; i++ ){
		if ( allInputs[i].type == 'text' ){
            textBoxes.push( allInputs[i] );
         }
     }
	for ( i = 0; i < textBoxes.length; i++ ){ 
		if(textBoxes[i].value != ""){
			textBoxes[i].setAttribute('onblur', 'if (this.value == "") { this.value="' + textBoxes[i].value + '"; }');
			textBoxes[i].setAttribute('onfocus', 'if (this.value == "' +  textBoxes[i].value + '") { this.value=""; }');  
		}
	}  
}
//-----------------------------
function getQuerystring(key, default_){
    if (default_==null){
        default_="";
    }
    var search = unescape(location.search);
    if (search == ""){
        return default_;
    }
    search = search.substr(1);
    var params = search.split("&");
    for (var i = 0; i < params.length; i++){
        var pairs = params[i].split("=");
        if(pairs[0] == key){
            return pairs[1];
        }
    }
    return default_;
}
//-----------------------------
function swapImage(id, src) {
	document.getElementById(id).style.backgroundImage = "url('" + src + "')";
}
//-----------------------------
function setCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
//-----------------------------
function getCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
//-----------------------------
function eraseCookie(name) {
	createCookie(name,"",-1);
}
//-----------------------------
function showDiv(boxid){
	if(!document.getElementById(boxid)) return;
	document.getElementById(boxid).style.visibility="visible";
	document.getElementById(boxid).style.display="block";
}
//-----------------------------
function hideDiv(boxid){
	if(!document.getElementById(boxid)) return;
	document.getElementById(boxid).style.visibility="hidden";
	document.getElementById(boxid).style.display="none";
}
//-----------------------------
function toggleHideDiv(boxid){
	// if clicked, show if hidden, hide if visible
	if(!document.getElementById(boxid)) return;
	var boxStyle = document.getElementById(boxid).style; 
	if(boxStyle.visibility == "hidden" || boxStyle.display == "none"){
		boxStyle.visibility ="visible";
		boxStyle.display = "block";
	}
	else{
		boxStyle.visibility ="hidden";
		boxStyle.display = "none";
	}
}
//-----------------------------
function checkBox(checkBoxId){
	document.getElementById(checkBoxId).checked = true;
}
//-----------------------------
function clientSideInclude(id, url) {
	var req = false;
	if (window.XMLHttpRequest) {
		try {
			req = new XMLHttpRequest();
		}
		catch (e) {
			req = false;
		}
	}
	else if (window.ActiveXObject) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				req = false;
			}
		}
	}
	var element = document.getElementById(id);
	if (!element) {
		alert("Bad id " + id + "passed to clientSideInclude." +	"You need a div or span element " + "with this id in your page.");
		return;
	}
	if (req) {
		req.open('GET', url, false);
		req.send(null);
		element.innerHTML = req.responseText;
	}
	else {
		element.innerHTML =
			"Sorry, your browser does not support XMLHTTPRequest objects. This page requires " +
			"Internet Explorer 5 or better for Windows, or Firefox for any system, or Safari. Other " +
			"compatible browsers may also exist.";
	}
}
//-----------------------------
var imgObj = new Array;
function splashImagesToDOM(){
	var splashID = "splashImage";
	// first create the images in divs, appended to existing image
	var parentDiv = document.getElementById(splashID);
	if(parentDiv){
		for(var i=0; i<imageArray.length; i++) { 
			var newDiv = document.createElement("DIV");
			parentDiv.appendChild(newDiv);
			newDiv.setAttribute('id',splashID + i);
			newDiv.style.width = "100%";
			newDiv.style.height = "100%";
			newDiv.style.position = "absolute";
			newDiv.style.top = "0";
			newDiv.style.left = "0";
			newDiv.style.background = "url(" + imageArray[i] + ")";
			newDiv.style.backgroundRepeat = "no-repeat";
			newDiv.style.backgroundPosition = "0px 0px";			
			newDiv.style.overflow = "hidden";
			newDiv.style.display = "none";
			newDiv.style.zIndex = "auto";
			imgObj.push(document.getElementById(splashID + i));
			imgObj[i].xOpacity = 0;
		}
		// now begin crossfading the images:
		imgObj[0].xOpacity = .99;
		crossFadeSplashImages(0);
	}
}
//-----------------------------
var current=0;
function crossFadeSplashImages(){
	var currentOpacity = imgObj[current].xOpacity;
	var nextIndex = imgObj[current+1]?current+1:0;
	var nextOpacity = imgObj[nextIndex].xOpacity;
	currentOpacity-=.05; 
	nextOpacity+=.05;
	imgObj[nextIndex].style.display = "block";
	imgObj[current].xOpacity = currentOpacity;
	imgObj[nextIndex].xOpacity = nextOpacity;

	setOpacity(imgObj[current]); 
	setOpacity(imgObj[nextIndex]);

	if(currentOpacity<=0) {
		imgObj[current].style.display = "none";
		current = nextIndex;
		setTimeout(crossFadeSplashImages,8000);
	} else {
		setTimeout(crossFadeSplashImages,40);
	}
	function setOpacity(obj) {
		if(obj.xOpacity>.99) {
			obj.xOpacity = .99;
			return;
		}
		obj.style.opacity = obj.xOpacity;
		obj.style.MozOpacity = obj.xOpacity;
		obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
	}
}
//-----------------------------
function zebraStripe(id) {
		var even = false; //flag
	  	// arguments can be used, otherwise defaults are:
		var evenColor = arguments[1] ? arguments[1] : "";
		var oddColor = arguments[2] ? arguments[2] : "#eee";
		var table = document.getElementById(id); // reference to desired table
		if (! table) { return; } // abort?
		var tbodies = table.getElementsByTagName("tbody");
		for (var h = 0; h < tbodies.length; h++) { 	// and iterate through tbodies
			// find all the <tr> elements... 
			var trs = tbodies[h].getElementsByTagName("tr");
			for (var i = 0; i < trs.length; i++) { // iterate
				// avoid rows that have a class attribute
				// or backgroundColor style
				if (!trs[i].style.backgroundColor) {
					// get all the cells in this row...
					var tds = trs[i].getElementsByTagName("td");
					// and iterate through them...
					for (var j = 0; j < tds.length; j++) {
						var mytd = tds[j];
						// avoid cells that have a class attribute
						// or backgroundColor style
						if (!hasClass(mytd) && !mytd.style.backgroundColor) {
							mytd.style.backgroundColor = even ? evenColor : oddColor;
						}
					}
				}
				even =  ! even; // flip from odd to even, or vice-versa
			}
		}
	}
	function hasClass(obj) { // part of zebraStripe
		var result = false;
		if (obj.getAttributeNode("class") != null) {
			result = obj.getAttributeNode("class").value;
		}
	return result;
}
//-----------------------------

