function DHTMLHelper() {  }

/**
 * adds a CSS class to a DOM element
 */
DHTMLHelper.elementAddClass = function(ctrl, className)
{
	var regex = new RegExp("\s?"+className+"\s?");
	
	if(regex.test(ctrl.className))
		return;
	
	ctrl.className += " "+className;
}

/**
 * removes a CSS class to a DOM element
 */
DHTMLHelper.elementRemoveClass = function(ctrl, className)
{
	var regex = new RegExp("\s?"+className+"\s?");
	ctrl.className = ctrl.className.replace(regex, " ");
}

/**
 * checks if a given DOM element is using a certain CSS class
 */
DHTMLHelper.elementContainsClass = function(ctrl, className)
{
	var regex = new RegExp("\s?"+className+"\s?");
	return (ctrl.className.search(regex) != -1)
}



/**
 * adds an event listener callback function to an element
 * cross-browser compatible
 * 'eventName' can be any event name without the leading "on"; e.g. "mouseup", "keydown"
 */
DHTMLHelper.elementAddEventListener = function(element, eventName, callback)
{
	if(element.addEventListener)
		element.addEventListener(eventName, callback, false);
	else if(element.attachEvent)
		element.attachEvent("on"+eventName, callback);
}

/**
 * gets the actual Event object instance for any DOM event 'e' received by an event handler callback
 * cross-browser compatible
 */
DHTMLHelper.getRealEvent = function(e)
{
	if(!e.target)  // IE SUCKS
	{
		e = window.event;
		e.relatedTarget = e.toElement;
	}
	
	return e;
}




/**
 * Makes the currently selected <option> in this <select> element be the <option> with its value equal to 'selectVal'
 */
DHTMLHelper.selectOption = function(controlID, selectVal)
{
    var control = document.getElementById(controlID);
    for(var i = 0 ; i < control.options.length ; i++)
    {
        if(control.options[i].value == selectVal)
        {
            control.selectedIndex = i;
            break;
        }
    }
}

/**
 * Makes the currently selected radio button with name 'controlName' be the radio button with its value equal to 'selectVal'
 */
DHTMLHelper.selectRadio = function(controlName, selectVal)
{
	var control = document.getElementsByName(controlName);
	for(var i = 0 ;  i < control.length ; i++)
		control[i].checked = (control[i].value == selectVal);
}
