// by Johnson Cheung (http://www.wahon.net/~johnson/)
// Last update : December 1, 2008
// checked on
//	IE		: 6.0
//	Mozilla	: 1.7
//	Netscape	: 4.78
//	Opera	: 7.53, 9.20
//	Avant	: 9.02
//	Firefox	: 2.0.0.1
//	Safari	: 2.0.4

// based on 'dream.js', 'browser.js', 'number.js'

// getDIVWidth(String LayerName)
// getDIVHeight(String LayerName)
// getDIVX(String LayerName)
// getDIVY(String LayerName)
// setDIVXY(String LayerName, Integer x, Integer y)	-1 means unchange	// Not work on Safari 2.0.4
// setDIVWH(String LayerName, Integer w, Integer h)	-1 means unchange	// Not work on Safari 2.0.4
// setDIVbgColor(String LayerName, r, g, b)
// setDIVbgColorHex(String LayerName, String ColorCode)
// setDIVbgImage(String LayerName, String ImageURL)
// setDIVVisibility(String LayerName, boolean show)
// isDIVVisible(String LayerName)
// getDIVZ(String LayerName)
// setDIVZ(String LayerName, Integer zIndex)
// setDIVClip(String LayerName, Integer left, Integer right, Integer top, Integer bottom)
// setDIVDisplay(String LayerName, String Value)						// Not work on Netscape 4.78
// setDIVInnerHTML(String IDName, String Value)
// setDIVInnerHTMLWTarget(String IDName, String Value, String sTarget)
// setOpacity(String LayerName, Integer Value)						// Not work on Netscape 4.78, Opera 7.53, Safari 2.0.4

// getInnerWidth()
// getInnerHeight()
// doInnerResize(w, h)	// Opera, Avant Browser will not work if the tab is maximized
// getScrollX()
// getScrollY()
// setScroll(x, y)
// getScrollWidth()
// getScrollHeight()
// getWindowX()
// getWindowY()
// setWindoxXY(x, y)	// Opera will not work if the tab is maximized, the changes are within opera control, Avant Browser 9.02
// setWindowBgColor(r,g,b)
// setWindowBgColorHex(hexvalue)

// getScreenWidth()
// getScreenHeight()
// getScreenAvailWidth()
// getScreenAvailHeight()


// **********************************************
// DIV function

// get the layer size
function getDIVWidth(sName) {
	var oObj = MM_findObj(sName);
	if ((bisNS) && (fVersion < 5.0)) {
		return oObj.clip.width;
	} else {
		return oObj.offsetWidth;
	}
}
function getDIVHeight(sName) {
	var oObj = MM_findObj(sName);
	if ((bisNS) && (fVersion < 5.0)) {
		return oObj.clip.height;
	} else {
		return oObj.offsetHeight;
	}
}

// get the position, the value need to be set before
function getDIVX(sName) {
	var oObj = MM_findObj(sName);
	if ((bisNS) && (fVersion < 5.0)) {
		return oObj.left;
	} else {
		return oObj.offsetLeft;
	}
}
function getDIVY(sName) {
	var oObj = MM_findObj(sName);
	if ((bisNS) && (fVersion < 5.0)) {
		return oObj.top;
	} else {
		return oObj.offsetTop;
	}
}

// set the position, -1 is unchanged
function setDIVXY(sName, x, y) {
	var oObj = MM_findObj(sName);
	if ((bisIE) || (bisOP)) {
		if (x != -1) oObj.style.pixelLeft = x;
		if (y != -1) oObj.style.pixelTop = y;
	}
	if (bisNS) {
		if (fVersion < 5.0) {
			if (x != -1) oObj.left = x;
			if (y != -1) oObj.top = y;
		} else {
			if (x != -1) oObj.style.left = x;
			if (y != -1) oObj.style.top = y;
		}
	}
}
// set the size, -1 is unchanged
function setDIVWH(sName, w, h) {
	var oObj = MM_findObj(sName);
	if ((bisIE) || (bisOP)) {
		if (w != -1) oObj.style.pixelWidth = w;
		if (h != -1) oObj.style.pixelHeight = h;
	}
	if (bisNS) {
		if (fVersion < 5.0) {
			if (w != -1) oObj.clip.width = w;
			if (h != -1) oObj.clip.height = h;
		} else {
			if (w != -1) oObj.style.width = w;
			if (h != -1) oObj.style.height = h;
		}
	}
}

// Color and Background
function setDIVbgColor(sName, r, g, b) {
	var sColorCode= "#" + dec2hex(r) + dec2hex(g) + dec2hex(b);
	setDIVbgColorHex(sName, sColorCode);
}
function setDIVbgColorHex(sName, sColorCode) {
	var oObj = MM_findObj(sName);
	if ((bisNS) && (fVersion < 5.0)) {
		oObj.bgColor = sColorCode;
	} else {
		oObj.style.backgroundColor = sColorCode;
	}
}
function setDIVbgImage(sName, sURL) {
	var oObj = MM_findObj(sName);
	if ((bisNS) && (fVersion < 5.0)) {
		oObj.background.src = sURL;
	} else {
		oObj.style.backgroundImage = "url(" + sURL + ")";
	}
}

// Visibility
function setDIVVisibility(sName, bShow) {
	var oObj = MM_findObj(sName);
	if (bShow) {
		if ((bisNS) && (fVersion < 5.0)) {
			oObj.visibility = "show";
		} else {
			oObj.style.visibility = "visible";
		}
	} else {
		if ((bisNS) && (fVersion < 5.0)) {
			oObj.visibility = "hide";
		} else {
			oObj.style.visibility = "hidden";
		}
	}
}
function isDIVVisible(sName) {
	var oObj = MM_findObj(sName);
	if ((bisNS) && (fVersion < 5.0)) {
		return (oObj.visibility == "show");
	} else {
		return (oObj.style.visibility == "visible");
	}
}

function setDIVDisplay(sName, sValue) {
	var oObj = MM_findObj(sName);
	if ((bisNS) && (fVersion < 5.0)) {
		oObj.display = sValue;
	} else {
		if (bisIE) {
			oObj.style.display = sValue;
		} else {
			// Fix the problem on mozilla when show/hide tr
			if ((sName.indexOf("tr_") == 0) && ((sValue == "inline") || (sValue == "block"))) {
				oObj.style.display = "table-row";
			} else {
				oObj.style.display = sValue;
			}
		}
	}
}

function setDIVInnerHTML(sName, sValue) {
	if ((bisNS) && (fVersion < 5.0)) {
		var oObj = document.layers[sName].document;
		oObj.open();
		oObj.write(sValue);
		oObj.close();
	} else {
		var oObj = MM_findObj(sName);
		oObj.innerHTML = sValue;
	}
}

function setDIVInnerHTMLWTarget(sName, sValue, sTarget) {
	if ((bisNS) && (fVersion < 5.0)) {
		var oObj = eval(sTarget + ".document").layers[sName].document;
		oObj.open();
		oObj.write(sValue);
		oObj.close();
	} else {
		var oObj = eval(sTarget + ".document").getElementById(sName);
		oObj.innerHTML = sValue;
	}
}

// tackle the z value
function getDIVZ(sName) {
	var oObj = MM_findObj(sName);
	if ((bisNS) && (fVersion < 5.0)) {
		return oObj.zIndex;
	} else {
		return oObj.style.zIndex;
	}
}
function setDIVZ(sName, iZValue) {
	var oObj = MM_findObj(sName);
	if ((bisNS) && (fVersion < 5.0)) {
		oObj.zIndex = iZValue;
	} else {
		oObj.style.zIndex = iZValue;
	}
}


// Clip the layer
function setDIVClip(sName, l, r, t, b) {
	var oObj = MM_findObj(sName);
	if ((bisNS) && (fVersion < 5.0)) {
		oObj.clip.left = l; oObj.clip.right = r; oObj.clip.top = t; oObj.clip.bottom = b;
	} else {
		oObj.style.clip = "rect(" + t + "," + r + "," + b + "," + l + ")";
	}
}

// Set Opacity
function setOpacity(sName, iValue) {
	var oObj = MM_findObj(sName);
	if (bisNS) {
		if (!oObj) return;
		oObj.style.MozOpacity = (iValue / 100.0);
	} else {
		if (bisOP) {
			oObj.style.opacity = (iValue / 100.0);
		} else {
			if (!oObj.filters) return;
			oObj.filters.item("alpha").opacity = iValue;
		}
	}
}

// **********************************************
// Window function

// get the inner size
function getInnerWidth() {
	if ((bisNS) && (fVersion < 5.0)) {
		return window.innerWidth;
	} else {
		return document.body.clientWidth;
	}
}
function getInnerHeight() {
	if ((bisNS) && (fVersion < 5.0)) {
		return window.innerHeight;
	} else {
		return document.body.clientHeight;
	}
}

// get the total scroll size, i.e. the content size
function getScrollWidth() {
	if ((bisNS) && (fVersion < 5.0)) {
		return document.width;
	} else {
		return document.body.scrollWidth;
	}
}
function getScrollHeight() {
	if ((bisNS) && (fVersion < 5.0)) {
		return document.height;
	} else {
		return document.body.scrollHeight;
	}
}

function doInnerResize(w, h) {
	self.resizeTo(w, h);
}

// get the scroll bar position
function getScrollX() {
	if ((bisNS) && (fVersion < 5.0)) {
		return window.pageXOffset;
	} else {
		return document.body.scrollLeft;
	}
}
function getScrollY() {
	if ((bisNS) && (fVersion < 5.0)) {
		return window.pageYOffset;
	} else {
		return document.body.scrollTop;
	}
}
function setScroll(x, y) {
	self.scrollTo(x, y);
}

// get the browser position
function getWindowX() {
	if (bisIE) {
		// IE value starts on Content area
		// this is used to find out the left border and top button size
		var iCurLeft = self.screenLeft;
		var iCurTop = self.screenTop;
		self.moveTo(0,0);
		var iAddLeft = self.screenLeft;
		var iAddTop = self.screenTop;
		self.moveTo(iCurLeft - iAddLeft, iCurTop - iAddTop);
		return iCurLeft - iAddLeft;
	}
	if (bisNS) return self.screenX;
	if (bisOP) return self.screenLeft;
}
function getWindowY() {
	if (bisIE) {
		// IE value starts on Content area
		// this is used to find out the left border and top button size
		var iCurLeft = self.screenLeft;
		var iCurTop = self.screenTop;
		self.moveTo(0,0);
		var iAddLeft = self.screenLeft;
		var iAddTop = self.screenTop;
		self.moveTo(iCurLeft - iAddLeft, iCurTop - iAddTop);
		return iCurTop - iAddTop;
	}
	if (bisNS) return self.screenY;
	if (bisOP) return self.screenTop;
}
function setWindoxXY(x, y) {
	window.moveTo(x, y);
}

// change the background color
function setWindowBgColor(r, g, b) {
	setWindowBgColorHex("#" + dec2hex(r) + dec2hex(g) + dec2hex(b));
}
function setWindowBgColorHex(sColorCode) {
	document.bgColor = sColorCode;
}

// **********************************************
// Screen function

// get the total screen size
function getScreenWidth() {
   return self.screen.width;
}
function getScreenHeight() {
   return self.screen.height;
}

// get the available size, excluding all the taskbars, startbars
function getScreenAvailWidth() {
   return self.screen.availWidth;
}
function getScreenAvailHeight() {
   return self.screen.availHeight;
}