function _setZIndex(id, zindex)
{
    document.getElementById(id).style.zIndex = zindex;
}

function _setOpacity(id, opacity)
{
	if(opacity == 0) _hideelement(id); else _showelement(id);
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 

function _changeCSS(theClass, element, value) {
	var cssRules;
	if(document.all) { cssRules = 'rules'; } else if(document.getElementById) { cssRules = 'cssRules'; }
	for(var S = 0; S < document.styleSheets.length; S++) {
		for(var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
			if(document.styleSheets[S][cssRules][R].selectorText == theClass) {
				if(document.styleSheets[S][cssRules][R].style[element]) {
					document.styleSheets[S][cssRules][R].style[element] = value;
					break;
				}
			}
		}
	}
}

function _toggleelement(id, newdisplaytype)
{
	var obj = document.layers ? document.layers[id] : document.getElementById ? document.getElementById(id).style : document.all[id].style;
	if(newdisplaytype == null || newdisplaytype == "") { newdisplaytype = "block"; }
	if(obj.display != "none") {
		obj.display = "none";
		return false;
	} else {
		obj.display = newdisplaytype;
		return true;
	}
}

function _showelement(id, newdisplaytype)
{
	var obj = document.layers ? document.layers[id] : document.getElementById ? document.getElementById(id).style : document.all[id].style;
	if(newdisplaytype == null || newdisplaytype == "") { newdisplaytype = "block"; }
	obj.display = newdisplaytype;
}

function _hideelement(id)
{
	var obj = document.layers ? document.layers[id] : document.getElementById ? document.getElementById(id).style : document.all[id].style;
	obj.display = "none";
}

function _positionelement(id, xp, yp)
{
	var obj = document.layers ? document.layers[id] : document.getElementById ? document.getElementById(id).style : document.all[id].style;
	if(yp != null) obj.top = yp + "px";
	if(xp != null) obj.left = xp + "px";
}

function _setwidthelement(id, width)
{
	var obj = document.layers ? document.layers[id] : document.getElementById ? document.getElementById(id).style : document.all[id].style;
	obj.width = width + "px";
}

function _getwidthelement(id)
{
	var obj = document.layers ? document.layers[id] : document.getElementById ? document.getElementById(id).style : document.all[id].style;
	return obj.offsetWidth;
}

function _getheightelement(id)
{
	return document.getElementById(id).offsetHeight;
}
function _setrightelement(id, right)
{
	var obj = document.layers ? document.layers[id] : document.getElementById ? document.getElementById(id).style : document.all[id].style;
	obj.right = right + "px";
}

function _setbottomelement(id, bottom)
{
	var obj = document.layers ? document.layers[id] : document.getElementById ? document.getElementById(id).style : document.all[id].style;
	obj.bottom = bottom + "px";
}

function _setheightelement(id, height)
{
	var obj = document.layers ? document.layers[id] : document.getElementById ? document.getElementById(id).style : document.all[id].style;
	obj.height = height + "px";
}

function _getwidth(id)
{
	var obj = document.getElementById(id);
	if (typeof obj.clip !== "undefined") {
		return obj.clip.width;
	} else {
		if (obj.style.pixelWidth) {
			return obj.style.pixelWidth;
		} else {
			return obj.offsetWidth;
		}
	}
}
function _getheight(id)
{
	var obj = document.getElementById(id);
	if (typeof obj.clip !== "undefined") {
		return obj.clip.height;
	} else {
		if (obj.style.pixelHeight) {
			return obj.style.pixelHeight;
		} else {
			return obj.offsetHeight;
		}
	}
}
function _getleft(id)
{
	var xPos = document.getElementById(id).offsetLeft;
	var obj = document.getElementById(id).offsetParent;
	while(obj != null) { xPos += obj.offsetLeft; obj = obj.offsetParent; }
	return xPos;
}

function _gettop(id)
{
	var yPos = document.getElementById(id).offsetTop;
	var obj = document.getElementById(id).offsetParent;
	while(obj != null) { yPos += obj.offsetTop; obj = obj.offsetParent; }
	return yPos;
}

function _getcenter(id)
{
	var coords = new Object();
	var obj = document.getElementById ? document.getElementById(id) : document.all[id];
	coords.cx = ((obj.offsetHeight / 2) + _gettop(id));
	coords.cy = ((obj.offsetWidth / 2) + _getleft(id));
	return coords;
}

function _getwindowsize()
{
	var coords = new Object();
	coords.w = 800;
	coords.h = 600;
	if(window.innerWidth)
	{
		coords.w = window.innerWidth;
		coords.h = window.innerHeight;
	} else if(document.body.offsetWidth) {
		coords.w = document.body.offsetWidth;
		coords.h = document.body.offsetHeight;
	}
	return coords;
}

function _getwindowcenter()
{
	var coords = new Object();
	coords.cx = 300;
	coords.cy = 200;
	if(typeof(window.innerWidth)=='number')
	{
		// non IE browsers
		coords.cx = Math.round(window.innerWidth / 2);
		coords.cy = Math.round(window.innerHeight / 2);
	} else if(document.documentElement && document.documentElement.clientWidth) {
		// ie 6+ browsers
		coords.cx = Math.round(document.documentElement.clientWidth / 2);
		coords.cy = Math.round(document.documentElement.clientHeight / 2);
	} else if(document.body.clientWidth) {
		// ie 4 compat browsers
		coords.cx = Math.round(document.body.clientWidth / 2);
		coords.cy = Math.round(document.body.clientHeight / 2);
	}
	return coords;
}

function _setBackground(obj, col)
{
	if(obj.style) { var obj = obj.style; }
	obj.backgroundColor = col;
}



// simulate the IE functions for Moz - God, these are woderful prototypes - DONT WORK IN SAFARI!!!
if(typeof HTMLElement!="undefined" && !HTMLElement.prototype.insertAdjacentElement)
{
	HTMLElement.prototype.insertAdjacentElement = function(where, parsedNode)
	{
		switch(where)
		{
			case 'beforeBegin':
				this.parentNode.insertBefore(parsedNode, this);
				break;
			case 'afterBegin':
				this.insertBefore(parsedNode, this.firstChild);
				break;
			case 'beforeEnd':
				this.appendChild(parsedNode);
				break;
			case 'afterEnd':
				if(this.nextSibling)
					this.parentNode.insertBefore(parsedNode, this.nextSibling);
				else
					this.parentNode.appendChild(parsedNode);
				break;
		}
	}

	HTMLElement.prototype.insertAdjacentHTML = function(where, htmlStr)
	{
		var r = this.ownerDocument.createRange();
		r.setStartBefore(this);
		var parsedHTML = r.createContextualFragment(htmlStr);
		this.insertAdjacentElement(where,parsedHTML);
	}

	HTMLElement.prototype.insertAdjacentText = function(where, txtStr)
	{
		var parsedText = document.createTextNode(txtStr);

		this.insertAdjacentElement(where,parsedText);
	}
}
