function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function attachEventListener(target, eventType, functionRef, capture){
	if(typeof target.addEventListener != 'undefined'){
		target.addEventListener(eventType, functionRef, capture);
	}else if(typeof target.attachEvent != 'undefined'){
		var functionString = eventType + functionRef;
		target['e' + functionString] = functionRef;
		
		target[functionString] = function(event){
			if(typeof event == 'undefined'){
				event = window.event;
			}
			target['e' + functionString](event);
		};
		target.attachEvent('on' + eventType, target[functionString]);
	}else{
		eventType = 'on' + eventType;
		
		if(typeof target[eventType] == 'function'){
			var oldListener = target[eventType];
			target[eventType] = function(){
				oldListener();
				return functionRef();
			};
		}else{
			target[eventType] = functionRef;
		}
	}
}

function detachEventListener(target, eventType, functionRef, capture){
	if(typeof target.removeEventListener != 'undefined'){
		target.removeEventListener(eventType, functionRef, capture);
	}else if(typeof target.detachEvent != 'undefined'){
		var functionString = eventType + functionRef;
		target.detachEvent('on' + eventType, target[functionString]);
		target['e' + functionString] = null;
		target[functionString] = null;
	}else{
		target['on' + eventType] = null;
	}
}