// general javascript functions

function signOf(num) {
	var r;
	if (num>0) r = 1; else if (num<0) r = -1; else r = 0;
	return r;
}

// crossbrowser realisation of getElementById
function $(aID) {
	return (document.getElementById) ? document.getElementById(aID) : document.all[aID];
}

// 

function getGeometry(eID) {
	var elm = $(eID);
	var w = elm.offsetWidth;
	var h = elm.offsetHeight;
	var x = 0;
	var y = 0;
	do {
		x = x + elm.offsetLeft;
		y = y + elm.offsetTop;
	} while	( elm = elm.offsetParent ) ;
	return {"x":x, "y":y, "w": w, "h":h};
}

function getMousePosition(e)
{
  var x = 0, y = 0;

  if (!e) e = window.event;

  if (e.pageX || e.pageY)
  {
    x = e.pageX;
    y = e.pageY;
  }
  else if (e.clientX || e.clientY)
  {
    x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
    y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
  }

  return {"x":x, "y":y};
}

var mousePosition = { 'x':0, 'y':0 };

function traceMousePosition(e) {
	mousePosition = getMousePosition(e);
}

function gotoUrlPost(url,params,target) {
	var form = document.createElement('form');
	form.action = url;
	form.method="post";
	if ( target ) form.target = target;
	form.style.display = "none";
	var element = null;
	for (var propName in params) {
		element = document.createElement('input');
		element.type = "text";
		element.name = propName;
		element.value = params[propName];
		form.appendChild(element);
	}
	document.body.appendChild(form);
	form.submit();
}

// this function is taken from here:
// http://www.howtocreate.co.uk/tutorials/javascript/browserwindow
function innerSize() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
	//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	return { "w":myWidth, "h":myHeight };
}

// this code is based on this one:
// http://www.howtocreate.co.uk/tutorials/javascript/browserwindow
function scrollPosition() {
	var x = 0, y = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
	//Netscape compliant
		y = window.pageYOffset;
		x = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
	//DOM compliant
		y = document.body.scrollTop;
		x = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
	//IE6 standards compliant mode
		y = document.documentElement.scrollTop;
		x = document.documentElement.scrollLeft;
	}
	return { "x":x, "y":y };
}

// this code is based on this one:
// http://www.thescripts.com/forum/thread91876.html
function documentSize() {
	if (typeof(document.height) != 'undefined') return { "w":document.width, "h":document.height };
	else if (document.compatMode && document.compatMode != 'BackCompat') 
		return { "w":document.documentElement.scrollWidth, "h":document.documentElement.scrollHeight };
	else if (document.body && typeof(document.body.scrollHeight) != 'undefined')
		return { "w":document.body.scrollWidth, "h":document.body.scrollHeight };
}
