addLoadEvent(function () {
	buttonHover();
});

function renderFlash(flashMovie, flashWidth, flashHeight) {
	var html = 
	'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="' + flashWidth + '" height="' + flashHeight + '" id="flash">' +
	'<param name="allowScriptAccess" value="sameDomain" />' +
	'<param name="movie" value="' + flashMovie + '.swf" />' +
	'<param name="quality" value="high" />' +
	'<param name="bgcolor" value="#ffffff" />' +
	'<param name="wmode" value="transparent" />' +
	'<embed src="' + flashMovie + '.swf" quality="high" wmode="transparent" bgcolor="#ffffff" width="' + flashWidth + '" height="' + flashHeight + '" name="flash" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />' +
	'</object>';

	document.writeln(html);
}


//-------------------------------------------------------------------------
// Apache Functions:
//-------------------------------------------------------------------------

function $(id) {
	return document.getElementById(id);
}

function addClass(el, className) {
	if (!hasClass(el, className)) el.className += ' ' + className;
}

function addLoadEvent(func) {
	var oldOnload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			if (oldOnload) {
				oldOnload();
			}
			func();
		};
	}
}

function buttonHover() {
	var inputs = document.getElementsByTagName('input');

	for (var i = 0; i < inputs.length; i++) {
		if (hasClass(inputs[i], 'button') && !hasClass(inputs[i], 'buttonDisabled')) {

			inputs[i].onmouseover = function () {
				addClass(this, 'buttonHover');
			};

			inputs[i].onmouseout = function () {
				removeClass(this, 'buttonHover');
			};
		}
	}
}

function hasClass(el, className) {
	var regex = new RegExp('(^|\\s)' + className + '(\\s|$)');
	return regex.test(el.className);
}

function removeClass(el, className) {
	var regex = new RegExp('(^|\\s)' + className + '(\\s|$)');
	el.className = el.className.replace(regex, ' ');
}

function trim(obj) {
	if (typeof obj === 'object') {
		obj.value = obj.value.replace(/^\s{1,}/, '').replace(/\s{1,}$/, '');
		return obj;
	}
	return obj.replace(/^\s{1,}/, '').replace(/\s{1,}$/, '');
}

function truncateStrByNumOfWords(str, maxWords) {

	// Replace line breaks and tabs with spaces
	var str = str.replace(/[\r\n\t]+/g, ' ');

	// Remove leading and trailing spaces
	str = str.replace(/(^\s+)|(\s+$)/, '');

	// Remove duplicate spaces
	str = str.replace(/ {2,}/g, ' ');

	// If the current number of words is greater than the maximum number of words
	if (str.split(' ').length > maxWords) {

		str = str.split(' ');								// Convert the string into an array of words
		str = str.slice(0, (maxWords - 1)); // Remove words subsequent to word limit
		str = str.join(' ');								// Convert array back into a string
		str+= '&hellip;'										// Append ellipsis to indicate truncation
	}
	return str;
}