var clientHas = { 
	'Event' : window.Event ? true : false,
	'addEventListener' : window.addEventListener ? true : false
}

function makePopup(url, name, width) {
    if(isUndefinedOrNull(width)) width = '600';
    if(isUndefinedOrNull(name)) name = 'helpwindow';
    var win = window.open(url, name, 'resizable=yes,menubar=no,statusbar=yes,scrollbars=yes,width='+width+',height=480');
	win.focus();
	return false;
}

function getTarget() {	
	if(clientHas['Event']) return getTarget.caller.arguments[0].target;
	else return event.srcElement;
}

function getEvent() {
	if(!clientHas['Event']) return window.event;
	else return getEvent.caller.arguments[0];
}

function setEvent(target, event, handler, capture) {
	target = $(target);
	if(clientHas['addEventListener']) {
		capture = (capture != 'undefined' && capture) ? true : false;
		target.addEventListener(event, handler, capture);
	} else {
		target.attachEvent('on' + event, handler);
	}
}	


function getSelected(target) {
	target = $(target);
	return target.options[target.selectedIndex];
}


function startModal(elm) {
    var screen = DIV({'id':'modalscreen'});
	document.body.appendChild(screen);
	showElement(elm);
	return function() {
	    document.body.removeChild(screen);
		hideElement(elm);
    }
}



function loadButtonAltImage(elm) {
    var oimg = computedStyle(elm, 'backgroundImage', 'background-image');    
    img = oimg.substring(oimg.search('buttons'), oimg.search('.gif')) + '_t.gif';

    var hiddenDiv = $('hiddenDiv');
    if(isUndefinedOrNull(hiddenDiv)) {
	hiddenDiv = DIV({'id':'hiddenDiv'}, '');
	appendChildNodes(document.body, hiddenDiv);
	hiddenDiv.style.position = 'absolute';
	hiddenDiv.style.top = '0px';
	hiddenDiv.style.left = '-1000px';
    }

    var loadImage = DIV({'style':'background-image:url('+img+')'}, 'a');
    appendChildNodes(hiddenDiv, loadImage);

    //loadImage.style.display = 'none';
    //appendChildNodes(elm.parentNode, loadImage);
}

function hookButtonImages() {
    forEach(getElementsByTagAndClassName('*', 'button'), loadButtonAltImage);
}

//addLoadEvent(hookButtonImages);

