







function buttonClick(buttonElement, newName) {
	buttonElement.name = newName;
}

function forward(page) {

	document.location.href = document.getElementsByTagName('base')[0].href + page;

}





var floatActivityDivTop = 0;
function floatActivityDiv() {


	if (document.documentElement && document.documentElement.scrollTop) {
		scrollTop = document.documentElement.scrollTop;
	} else {
		scrollTop = document.body.scrollTop;
	}
	
	floatActivityDivTop += (scrollTop + 20 - floatActivityDivTop) / 6;

	$('showActivity').style.top = floatActivityDivTop + 'px';
	$('showActivity').style.right = 20 + 'px';

}



function ajaxTransportText(transport) {
	
	var toReturn = new Array();

	if(transport.statusText != "OK") {
		toReturn['error'] = true;
		toReturn['text'] = (transport.statusText != "Internal Server Error") ? 'Error with server' : transport.responseText;
	} else {
		toReturn['error'] = false;
		toReturn['text'] = transport.responseText;
	}
	
	return toReturn;

}



//if request takes longer than 1.5 seconds, it shows 'activity'
Ajax.Responders.register({
	onCreate: function() {
		if($('showActivity') && Ajax.activeRequestCount> 0) {
			setTimeout("if(Ajax.activeRequestCount> 0) { showActivity() }", 1500);
		}
	},
	onComplete: function() {
		if($('showActivity') && Ajax.activeRequestCount == 0) {
			Effect.Fade('showActivity',{duration: 0.5, queue: {position:'end', scope:'showActivity', limit: 50}});
		}
	}
});
function showActivity() {
	if($('showActivity')) {
		Effect.Appear('showActivity',{duration: 0.5, queue: {position:'front', scope:'showActivity', limit: 50}});
	}
}

function goBack() {

	history.go(-1);

	return false;

}

var docSubmitted = false;

function formSubmit(formElement) {

	if(docSubmitted == true) {

		alert('A form is currently submitting. Please be patient!');
		return false;

	} else {

		docSubmitted = true;

		setTimeout("showActivity()", 2000);

		return true;

	}

}


// Cross-browser implementation of element.addEventListener()
function addListener(element, type, expression, bubbling) {
	bubbling = bubbling || false;
	if(window.addEventListener) { // Standard
		element.addEventListener(type, expression, bubbling);
		return true;
	} else if(window.attachEvent) { // IE
		element.attachEvent('on' + type, expression);
		return true;
	} else return false;
}




// http://24ways.org/2005/splintered-striper

/*
 * Summary:      Core experiment function that applies any number of classes to all child elements
 *               contained in all occurences of a parent element (either with or without a specific class)
 * Parameters:   parentElementTag - parent tag name
 *               parentElementClass - class assigned to the parent; if null, all parentElementTag elements will be affected
 *               childElementTag -  tag name of the child elements to apply the styles to
 *               styleClasses - comma separated list of any number of style classes (using 2 classes gives the classic "zebra" effect)
 * Return:       none
 */
 
function zebra(parentElementTag, parentElementClass, childElementTag, styleClasses)
{
	var i=0,currentParent,currentChild;
	// capability and sanity check
	if ((document.getElementsByTagName)&&(parentElementTag)&&(childElementTag)&&(styleClasses)) {
		// turn the comma separate list of classes into an array
		var styles = styleClasses.split(',');
		// get an array of all parent tags
		var parentItems = document.getElementsByTagName(parentElementTag);
		// loop through all parent elements
		while (currentParent = parentItems[i++]) {
			// if parentElementClass was null, or if the current parent's class matches the specified class
			if ((parentElementClass == null)||(currentParent.className.indexOf(parentElementClass) > -1)) {
				var j=0,k=0;
				// get all child elements in the current parent element
				var childItems = currentParent.getElementsByTagName(childElementTag);
				// loop through all child elements
				while (currentChild = childItems[j++]) {
					// based on the current element and the number of styles in the array, work out which class to apply
					k = (j+(styles.length-1)) % styles.length;
					// add the class to the child element - if any other classes were already present, they're kept intact
					currentChild.className = currentChild.className+" "+styles[k];
				}
			}
		}
	}
}





//this will be called after DOM is loaded
function init() {

	zebra('table', 'zebra', 'tr', 'odd, even');

	if($('showActivity')) {
		setInterval("floatActivityDiv()", 30);
	}

}






// for Internet Explorer (using conditional comments)
/*@cc_on @*/
/*@if (@_win32)
document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
var script = document.getElementById("__ie_onload");
script.onreadystatechange = function() {
	if (this.readyState == "complete") {
		init(); // call the onload handler
	}
};
/*@end @*/

//for safari
if (/WebKit/i.test(navigator.userAgent)) { // sniff
	var _timer = setInterval(function() {
		if (/loaded|complete/.test(document.readyState)) {
			clearInterval(_timer);
			init(); // call the onload handler
		}
	}, 10);
}

//for firefox
if (document.addEventListener) {
	document.addEventListener("DOMContentLoaded", init, false);
}
