function getWindowInnerSize() {
	var windowInnerHeight, windowInnerWidth;
	if (navigator.userAgent.indexOf('MSIE') != -1 && !window.opera) {
		if (document.compatMode && document.compatMode != "BackCompat") {
			windowInnerHeight = document.documentElement.clientHeight;
			windowInnerWidth = document.documentElement.clientWidth;
		} else {
			windowInnerHeight = document.body.clientHeight;
			windowInnerWidth = document.body.clientWidth;
		}	
	} else if (window.opera) {
		windowInnerHeight = window.innerHeight;
		windowInnerWidth = window.innerWidth;
		
	} else if (navigator.userAgent.indexOf('Netscape') != -1 || navigator.userAgent.indexOf('Firefox')) {
		windowInnerHeight = innerHeight;
		windowInnerWidth = innerWidth;
	} else {
		windowInnerHeight = 550;
		windowInnerWidth = 990;
	}
	var windowInnerSize=new Array(windowInnerWidth, windowInnerHeight);
	return windowInnerSize;
}
function getPageSizeWithScroll(){
	if (window.innerHeight != undefined && window.scrollMaxY  != undefined) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	}else if(window.innerHeight  && document.body.scrollHeight > document.body.offsetHeight){
		yWithScroll = (window.innerHeight >document.body.scrollHeight)?window.innerHeight:document.body.scrollHeight;
		xWithScroll = (window.innerWidth >document.body.scrollWidth)?window.innerWidth:document.body.scrollWidth;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	}
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
	return arrayPageSizeWithScroll;
}
function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function calculateCenterPos(elementW,elementH) {
	var elementMinX = 0;
	var elementMinY = 10;
	var windowInnerSize=getWindowInnerSize();
	var scrXY=getScrollXY();
	windowInnerWidth = windowInnerSize[0];
	windowInnerHeight = windowInnerSize[1];	
	if (windowInnerWidth<elementW+elementMinX) {
		elX = elementMinX;
	} else {
		elX = scrXY[0] - 25 + (windowInnerWidth-elementW)/2;
	}
	if (windowInnerHeight<elementH+elementMinY) {
		elY = elementMinY;
	} else {
		elY = scrXY[1]+(windowInnerHeight-elementH)/2;		
	}
	var elementPos = new Array(elX,elY);
	return elementPos;
}
function centerElement(elementID,elementW,elementH,onlyH) {
	var elementPos=calculateCenterPos(elementW,elementH);
	if (onlyH != 1) {
		findElement(elementID).style.left = elementPos[0]+"px";	
	}
	findElement(elementID).style.top = elementPos[1]+"px";	
}

function getW(obj) {var ret = 0; if (document.getElementById || document.all) {ret = obj.offsetWidth;} else if (document.layers){ret = obj.style.clip.bottom;} return ret;}
function getH(obj) {var ret = 0; if (document.getElementById || document.all) {ret = obj.offsetWidth;} else if (document.layers){ret = obj.style.clip.bottom;} return ret;}

function getPageOffsetLeft (el) {
	var ol=el.offsetLeft;
	while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
	return ol;
	}
function getPageOffsetTop (el) {
	var ot=el.offsetTop;
	while((el=el.offsetParent) != null) { ot += el.offsetTop; }
	return ot;
	}

function getPos(obj) {
	var coordinates=new Object();
	var x=0,y=0;
	if (document.getElementById) {
		x=obj.offsetLeft; y=obj.offsetTop;
	}
	else if (document.layers) {
		x=obj.x;
		y=obj.y;
	}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
}


function getStylePropNumVal(obj,propName) { // get style property numeric value
	var styleVal = obj.style[propName];
	var styleNumVal = Number(styleVal.replace(/([a-z]+)$/i,''));
	return styleNumVal!='NaN'?styleNumVal:0;
}
