//--------- Common
var ie5=(document.all != null && document.getElementById != null);
var ns6=(document.getElementById != null && document.all == null);
if (ie5||ns6)
	var menuobj=document.getElementById("contextmenu");

function set_obj_position(obj, left, top){
	obj.style.left = left + "px";
	obj.style.top = top + "px";
}
//------
function get_screen_width(){
	return (window.innerWidth) ? window.innerWidth : document.documentElement.clientWidth;
//	return (window.innerWidth) ? window.innerWidth - 25 : document.body.clientWidth;
}
function get_screen_height(){
	return (window.innerHeight) ? window.innerHeight : document.documentElement.clientHeight;
//	return (window.innerHeight) ? window.innerHeight - 25 : document.body.clientHeight;
}
function get_scroll_top(){
	return ie5 ? document.documentElement.scrollTop : window.pageYOffset;
}
function get_scroll_left(){
	return ie5 ? document.documentElement.scrollLeft : window.pageXOffset;
}
function get_offset_left(elm) {
	var ofs_left = elm.offsetLeft;
	var ofs_parent = elm.offsetParent;
	while(ofs_parent){
		ofs_left += ofs_parent.offsetLeft;
		ofs_parent = ofs_parent.offsetParent;
	}
	return ofs_left;
}
function get_offset_top(elm){
	var ofs_top = elm.offsetTop;
	var ofs_parent = elm.offsetParent;
	while(ofs_parent){
		ofs_top += ofs_parent.offsetTop;
		ofs_parent = ofs_parent.offsetParent;
	}
	return ofs_top;
}

function show_context_box(pivot_obj, obj, show){
   	obj.style.display = (show) ? "" : "none";

	if(show){
		//Get location of mouseover object, move object to the left if will display off-screen
		var w = obj.offsetWidth;
		var x = get_offset_left(pivot_obj);
		var right = get_screen_width() + get_scroll_left() - 24;
		if(x + w > right)
			x = right - w;

		//Get location of mouseover object, move object on top if will display off-screen
		var h = obj.offsetHeight;
		var y = get_offset_top(pivot_obj) + pivot_obj.offsetHeight;
		var bottom = get_screen_height() + get_scroll_top() - 24;
		if(y + h > bottom)
			y = get_offset_top(pivot_obj) - h;

        set_obj_position(obj, x, y);
    }
}

//-------------------------
//--------- Context Help

function showHelp(obj, field, show){
	var helpObj;
	//Get help object
	if(document.all)
		helpObj = document.all[field];
	else
		if(document.getElementById)
			helpObj = document.getElementById(field);

	if(helpObj)
	{
		show_context_box(obj, helpObj, show);
		helpObj.style.zIndex = 1000;
	}
}
