/**
 * common javascript functions
 **/



/**
 * simple browser detection. the "!(!" typcasts undefined values back to booleans.
 * - Mozilla/Netscape browsers have the DOM addEventListener() method,
 * - Safari/KHTML browsers have MSIE's .screenTop property, but no ActiveXObject.
 * - MSIE has a window.ActiveXObject() method even when ActiveX is disabled.
 **/
var isIE = !(!window.ActiveXObject);
var isSafari = !(!window.screenTop) && !isIE;
var isMozilla = !(!window.addEventListener) && !isSafari;



function gel(obj, a) {
	return obj.getElementById?obj.getElementById(a):null;
}



function gelstn(obj, a) {
	return obj.getElementsByTagName?obj.getElementsByTagName(a):new Array()
}



/**
 * addEventHandler()        attaches an event handler to an object
 *
 * @param object  object    the object to which you wish to attach
 * @param event   string    the event (without the 'on' prefix)
 * @param handler function  the function (can be anonymous) to perform
 *
 **/
function addEventHandler(object, event, handler) {
	if(isIE) {
		object.attachEvent('on' + event, function() { handler(object); } );
	} else {
		object.addEventListener(event, function() { handler(object); }, false);
	}

}



/**
 * stopDefaultAction()   prevents the default event action from occuring
 *
 * @param oEvent object  the target Event object
 *
 **/
function stopDefaultAction(oEvent) {
	if(isIE) {
		oEvent = window.event;
		oEvent.returnValue = false;
	} else {
		oEvent.preventDefault();
	}
}


/**
 * domcss()			manipulates an objects className attribute
 *
 * @param	action 	string	either swap, add, remove, check
 * @param	obj		object	the target object
 * @param	class1	string	classname 1
 * @param	class2	string	classname 2
 *
 **/
function domcss(action, obj, class1, class2)
{
	if (obj) {
		switch (action){
			case 'swap':
			obj.className = !domcss('check', obj, class1) ? obj.className.replace(class2, class1) : obj.className.replace(class1, class2);
			break;

			case 'add':
			if(!domcss('check', obj, class1)) {
				obj.className += obj.className ? ' ' + class1 : class1;
			}
			break;

			case 'remove':
			var rep = obj.className.match(' '+class1) ? ' ' + class1 : class1;
			obj.className = obj.className.replace(rep, '');
			break;

			case 'check':
			return new RegExp('\\b'+class1+'\\b').test(obj.className);
			break;
		}
	}
}


