var IS_MSIE		= navigator.userAgent.indexOf("MSIE") >= 0;
var IS_MSIE6	= IS_MSIE && navigator.userAgent.indexOf("MSIE 6") >= 0;
var IS_MSIE7	= IS_MSIE && navigator.userAgent.indexOf("MSIE 7") >= 0;
var IS_OPERA	= navigator.userAgent.indexOf("Opera") >= 0;
var IS_FIREFOX	= navigator.userAgent.indexOf("Firefox") >= 0;
var IS_SAFARI	= navigator.userAgent.indexOf("Safari") >= 0;

var IN_IFRAME	= window.parent != null && window.parent.document != null;

function getRealDocument() {
	if (IN_IFRAME) {
		return window.parent.document;
	}
	
	return document;
}

function getRealWindow() {
	if (IN_IFRAME) {
		return window.parent.window;
	}
	
	return window;
}

function getElementById(id) {
	var obj = document.getElementById(id);
	if (obj == null) {
		if (IN_IFRAME) {
			obj = getRealDocument().getElementById(id);
		}
	}

	return obj
}

function getStageWidth(){
	if(IS_MSIE || IS_OPERA){
		return getRealDocument().body.parentElement.clientWidth;	
	}else{
		return getRealDocument().body.offsetWidth;
	}
}

function getStageHeight(){
	if(IS_MSIE){
		var height = getRealDocument().body.parentElement.clientHeight;
		if(getRealDocument().body.parentElement.clientHeight == 0){
			height = getRealDocument().body.clientHeight;
		}
		return height;
	}else{
		return height = getRealWindow().innerHeight;
	}
}

function getScrollHeight() {
	if(IS_MSIE) {
		return getRealDocument().documentElement.scrollTop;
	} else {
		return getRealWindow().pageYOffset
	}
}

function getWindowHieght() {
	if(IS_MSIE || IS_OPERA) {
		return getRealDocument().body.offsetHeight;
	} else {
		return getRealDocument().height;
	}
}

function getObjectOffsetTop(obj) {
	var x = obj.offsetTop;
	
	while (obj = obj.offsetParent) {
		x += obj.offsetTop;
	}
	
	return x;
}

function processMaxLength(text, length) {
	if (text != null && text.length > length) {
		return text.substring(0, length - 3) + "...";
	} else {
		return text;
	}
}

