function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

function getElementsByAttribute(oElm, strTagName, strAttributeName, strAttributeValue) {
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	var oAttributeValue = (typeof strAttributeValue != "undefined")? new RegExp("(^|\s)" + strAttributeValue + "(\s|$)") : null;
	var oCurrent;
	var oAttribute;
	for(var i=0; i<arrElements.length; i++) {
		oCurrent = arrElements[i];
		oAttribute = oCurrent.getAttribute && oCurrent.getAttribute(strAttributeName);
		if(typeof oAttribute == "string" && oAttribute.length > 0) {
			if(typeof strAttributeValue == "undefined" || (oAttributeValue && oAttributeValue.test(oAttribute))) {
				arrReturnElements.push(oCurrent);
			}
		}
	}
	return arrReturnElements;
}


function addEvent(that,eventName,eventAction) {
	if (that.attachEvent) {
		// ie
		that.attachEvent('on'+eventName,eventAction);
	} else if (that.addEventListener) {
		// w3 compilant
		that.addEventListener(eventName,eventAction,false);
	} else {
		// fail silently
		// alert('event could not be attached: '+eventName+', '+eventAction);
	}
}

function removeEvent(that,eventName,eventAction) {
	if (that.detachEvent) {
		// ie
		that.detachEvent('on'+eventName,eventAction);
	} else if (that.removeEventListener) {
		// w3 compilant
		that.removeEventListener(eventName,eventAction);
	} else {
		// fail silently
		// alert('event could not be detached: '+eventName+', '+eventAction);
	}
}

function evenElementHeights() {
	var maxHeight = 0;
	// find out the tallest element
	for (var i=0;i<arguments.length;i++) {
		if (arguments[i].offsetHeight > maxHeight) {
			maxHeight = arguments[i].offsetHeight;
		}
		maxHeight = (arguments[i].offsetHeight > maxHeight) ? arguments[i].offsetHeight : maxHeight;
	}
	// go through and adjust the height of the others.
	for (var i=0;i<arguments.length;i++) {
		// skip the one that is already the correct height
		if (arguments[i].clientHeight < maxHeight) {
			arguments[i].style.height = maxHeight + 'px';
			// make adjustments
			var comp = arguments[i].offsetHeight - maxHeight;
			if (comp) {
				arguments[i].style.height = (maxHeight - comp) + 'px';
			}
		}
	}
}

function fieldFlash(field,color1,color0,remaining) {
	var thisFunc = arguments.callee;
	if (color1 == undefined) {
		color1 = '#FFF90D';
	}
	if (color0 == undefined) {
		color0 = field.style.backgroundColor;
	}
	if (remaining == undefined) {
		remaining = 6;
	}
	if (remaining > 0) {
		field.style.backgroundColor = (remaining%2) ? color0 : color1;
		setTimeout(function() { thisFunc(field,color1,color0,remaining-1); },100);
	}
}

function flash(element,styleProperty,color0,color1,remaining) {
	var thisFunc = arguments.callee;
	if (color0 == undefined) {
		color0 = '#FFF90D';
	}
	if (color1 == undefined) {
		color1 = element.style[styleProperty];
	}
	if (remaining == undefined) {
		remaining = 6;
	}
	if (remaining > 0) {
		element.style[styleProperty] = (remaining%2) ? color1 : color0;
		setTimeout(function() { thisFunc(element,styleProperty,color0,color1,remaining-1); },100);
	}
}

function formGetQueryString(form) {
	var qs = '';
	for (var i=0;i<form.elements.length;i++) {
		element = form.elements[i];
		switch (element.type.toLowerCase()) {
		
			case 'checkbox':
				if (element.checked) {
					qs += encodeURIComponent(element.name) + '=on&';
				}
			break;
			
			case 'button': case 'submit':
				//ignore
			break;
			
			default:
				qs += encodeURIComponent(element.name) + '=' + encodeURIComponent(element.value) + '&';
			break;		}
	}
	return qs;
}


