function getLeftOffset(obj){
	var myleft = 0;
	while(obj.offsetParent != null){
		myleft += obj.offsetLeft;
		obj = obj.offsetParent;
	}
	return myleft;
}
function getTopOffset(obj){
	var mytop = 0;
	while(obj.offsetParent != null){
		mytop += obj.offsetTop;
		obj = obj.offsetParent;
	}
	return mytop;
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function trim_right_char(str,length){
	len = ((length == undefined) ? 0:length)
	return str.substr(0,str.length - len);
}

// event worker object constructor
function EventWorker(){
 this.addHandler = EventWorker.addHandler;
}

// event worker static method
EventWorker.addHandler =
 function (eventRef, func) {
  var eventHandlers = eval(eventRef);
  if (typeof eventHandlers == 'function') { // not first handler
   eval(eventRef + " = function(event) {eventHandlers(event); func(event);}");  
  } else { // first handler
   eval(eventRef + " = func;");
  }
 }
 
function str_count(_needle,_haystack) {
 var _c = 0;
 for (var i=0; i < _haystack.length; i++) {
   if ( _needle == _haystack.substr(i, _needle.length) )
   	_c++;
 }
 return _c;
}
function isObject(a){
 return (typeof a == 'object' && !!a) || (typeof a == 'function');
}