/** Get the x coordinate of an dom element
*
*	@param element HtmlObject
*	@return integer, the top position in pixels
*/
function getElementLeft(element)
{
	if(element.offsetLeft>0) return element.offsetLeft;
	else if (element.currentStyle) return parseInt(element.currentStyle['left']);
	else if (window.getComputedStyle)
		return parseInt(document.defaultView.getComputedStyle(element,null).getPropertyValue('left'));
	return null;
}
/** Get the y coordinate of an dom element
*
*	@param element HtmlObject
*	@return integer, the left position in pixels
*/
function getElementTop(element)
{
	if(element.offsetTop>0) return element.offsetTop;
	else if (element.currentStyle) return parseInt(element.currentStyle['top']);
	else if (window.getComputedStyle)
		return parseInt(document.defaultView.getComputedStyle(element,null).getPropertyValue('top'));
	return null;
}
/** Get the height of an dom element
*
*	@param element HtmlObject
*	@return integer, the height in pixels
*/
function getElementHeight(element)
{
	if(element.offsetHeight>0) return element.offsetHeight;
	else if (element.currentStyle) return parseInt(element.currentStyle['height']);
	else if (window.getComputedStyle)
		return parseInt(document.defaultView.getComputedStyle(element,null).getPropertyValue('height'));
	return null;
}
/** Get the width of an dom element
*
*	@param element HtmlObject
*	@return integer, the width in pixels
*/
function getElementWidth(element)
{
	if(element.offsetWidth>0) return element.offsetWidth;
	else if (element.currentStyle) return parseInt(element.currentStyle['width']);
	else if (window.getComputedStyle)
		return parseInt(document.defaultView.getComputedStyle(element,null).getPropertyValue('width'));
	return null;
}
/**	Set a cookie.
*
*	@param name string, the cookie name.
*	@param value string, the cookie value.
*	@param days integer, the numbar of days until the cookie expires.
*	@return void.
*/
function setCookie(name, value, days)
{
	if(days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
/**	Get a cookie.
*
*	@param name string, the cookie name.
*	@return string, the cookie value.
*/
function getCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
/**	Remove a cookie.
*
*	@param name string, the cookie name.
*	@return void.
*/
function removeCookie(name)
{
	createCookie(name,"",-1);
}
/**	Get the window width.
*
*	@return integer, the window width in pixels.
*/
function getWindowWidth()
{
	var width = 0;
  	if( typeof( window.innerWidth ) == 'number' )
	{
		//Non-IE
   		width = window.innerWidth;
  	}
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
	{
    	//IE 6+ in 'standards compliant mode'
    	width = document.documentElement.clientWidth;
  	}
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
	{
    	//IE 4 compatible
    	width = document.body.clientWidth;
  	}
	return width;
}
/**	Get the window height.
*
*	@return integer, the window height in pixels.
*/
function getWindowHeight()
{
	var height = 0;
  	if( typeof( window.innerWidth ) == 'number' )
	{
    	//Non-IE
   		height = window.innerHeight;
	}
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
	{
	    //IE 6+ in 'standards compliant mode'
    	height = document.documentElement.clientHeight;
  	}
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
	{
    	//IE 4 compatible
    	height = document.body.clientHeight;
  	}
	return height;
}
/**	Get elements by class name.
*
*	@param tag string, tag name, it will search for these tags and there children only.
*	@param className, the class name to search for.
*	@return array, the elements it found.
*/
function getElementsByClass(tag, className)
{
	var elements = new Array();
	var tags = document.getElementsByTagName(tag);
	for(var i=0; i<tags.length; i++)
	{
		if(tags[i].className.match(new RegExp("(^|\\s)" + className + "(\\s|$)"))) elements.push(tags[i]);
	}
	return elements;
}
/*	Launch the admin panel. */
var misc_oldKeyHandler = null;
function goAdmin(e)
{
	if(!e && window.event) var e = window.event;
	if(misc_oldKeyHandler) misc_oldKeyHandler(e);
	if(e)
	{
		if(e.ctrlKey && e.shiftKey)
		{
			if(e.which) var c = e.which;
			else if(e.keyCode) var c = e.keyCode;
			else return false;
			if(String.fromCharCode(c) == 'A')
			{
				window.open(LINK_BASE+"admin");
			}
		}
	}
}
if(document.onkeypress) misc_oldKeyHandler = document.onkeypress;
document.onkeypress = goAdmin;

