
// Alternative to m.offsetLeft as some browsers take their offsets from the body while others take it from the parent element
function FindPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x) { curleft += obj.x; }
	return curleft;
}

// Alternative to m.offsetTop as some browsers take their offsets from the body while others take it from the parent element
function FindPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y) { curtop += obj.y; }
	return curtop;
}

// get the height of the window
function GetWindowHeight() {
	if (window.innerHeight) 
		var window_height = window.innerHeight;
	else {
		if (document.documentElement.clientHeight)
			var window_height = document.documentElement.clientHeight;
		else
			var window_height = document.body.clientHeight;
	}
	return window_height;
}

// get the position of the scroll bar
function GetScrollTop() {
	if (window.pageYOffset)
		var window_top = window.pageYOffset;
	else {
		if (document.documentElement.scrollTop)
			var window_top = document.documentElement.scrollTop;
		else
			var window_top = document.body.scrollTop;
	}
	return window_top;
}

/*function insertAtCursor(el, myValue) 
{
  //IE support
  if (document.selection) {
    el.focus();
    sel = document.selection.createRange();
    sel.text = myValue;
  }else if (el.selectionStart || el.selectionStart == '0') {//MOZILLA/NETSCAPE support
    var startPos = el.selectionStart;
    var endPos = el.selectionEnd;
    el.value = el.value.substring(0, startPos)
    + myValue
    + el.value.substring(endPos, el.value.length);
  } else {
    el.value += myValue;
  }
}*/

function SetCursorPosition(el, pos) 
{
	if (document.selection)
	{
		el.focus();
		sel = document.selection.createRange();

		sel.move('character', pos);
		sel.select();

	}
	else if (el.selectionStart || el.selectionStart == '0')
	{
		el.selectionStart = pos;
		el.selectionEnd = pos;
	}
}
