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


function getDimensions(obj) {
	var style
	if (obj.currentStyle) {
		style = obj.currentStyle;
	}
	else {
		style = getComputedStyle(obj,'');
	}
	padding = [parseInt(style.paddingTop), parseInt(style.paddingRight), parseInt(style.paddingBottom), parseInt(style.paddingLeft)]
	border = [parseInt(style.borderTopWidth), parseInt(style.borderRightWidth), parseInt(style.borderBottomWidth), parseInt(style.borderLeftWidth)]
	for (var i in padding)  if ( isNaN( padding[i] ) ) padding[i] = 0
	for (var i in border)  if ( isNaN( border[i] ) ) border[i] = 0

	var result = new Object();
	result.innerHeight = obj.clientHeight - padding[0] - padding[2];
	result.innerWidth = obj.clientWidth - padding[1] - padding[3];
	result.padding = padding;
	result.borders = border;

	result.outerHeight = obj.clientHeight + border[0] + border[2];
	result.outerWidth = obj.clientHeight + border[1] + border[3];

	return result;
}

function findPos(obj, with_scroll) {
	if (!with_scroll) var with_scroll = false;
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft - (with_scroll ? obj.scrollLeft : 0)
		curtop = obj.offsetTop - (with_scroll ? obj.scrollTop : 0)
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft - (with_scroll ? obj.scrollLeft : 0)
			curtop += obj.offsetTop - (with_scroll ? obj.scrollTop : 0)
		}
	}
	return [curleft,curtop];
}

function isset(variable) {
	if (variable==null) {
		return false;
	}
	return (typeof(variable)=='undefined')?false:true;
}

function in_array(needle, haystack) {
	return array_search(needle, haystack) != -1;
}

function array_search(needle, haystack) {
	for (var i=0; i<haystack.length; i++) {
		if (haystack[i] == needle) return i;
	}
	return -1;
}

function getRealLeft(el)
{
	if (typeof(el) == 'string') {
		el = document.getElementById(el);
	}
	xPos = el.offsetLeft;
	tempEl = el.offsetParent;
	while (tempEl != null)
	{
		xPos += tempEl.offsetLeft;
		tempEl = tempEl.offsetParent;
	}
	//	if (obj.x) return obj.x;
	return xPos;
}

function getRealTop(el)
{
	if (typeof(el) == 'string') {
		el = document.getElementById(el);
	}
	yPos = el.offsetTop;
	tempEl = el.offsetParent;
	while (tempEl != null)
	{
		yPos += tempEl.offsetTop;
		tempEl = tempEl.offsetParent;
	}

//	if (obj.y) return obj.y;
	return yPos;
}

function preg_print_pre(obj, reg)
{
	if (!reg) reg = /.*/;
	var p = ''
	for (var prop in obj) {
		if (prop.match(reg) ) {
			p += prop + ': '+obj[prop] + '\n'
		}
	}
	alert(p)
}

