var IE = document.all?true:false;

var mouse_xpos = 0;
var mouse_ypos = 0;
var mouse_pos_init = false;
var mouse_help_delay = 300 ;

var max_x = 0;

var max_y = 0;

var help_active = 0;

var mousehelp = null;

var top_scroll = 0;

var left_scroll = 0;

var stringer_width = 0;
var default_width = 300;
stringer_width = default_width;


var stringer_height = 0;

var vector_x = 20;
var vector_y = 20;

var mhint_min_width = 0;



//if (!IE) document.captureEvents(Event.MOUSEMOVE);

function get_mouse_xy ( e ) {
	if ( ( help_active == 1 ) || ( mouse_pos_init == false ) ) {
		get_scrolls();
		if (IE) {
			mouse_xpos = event.clientX + left_scroll;
			mouse_ypos = event.clientY + top_scroll;
		} else {
			mouse_xpos = e.pageX;
			mouse_ypos = e.pageY;
		}
		// x left position
		if ( mouse_xpos < 0 ) mouse_xpos = 0;
		else if ( mouse_xpos > max_x - stringer_width - 2 * vector_x )
			mouse_xpos = mouse_xpos - stringer_width - vector_x;
		else mouse_xpos = mouse_xpos + vector_x ;
		// y top position
		if ( mouse_ypos < 0 ) mouse_ypos = 0;
		else if ( mouse_ypos < top_scroll + stringer_height + vector_y ) mouse_ypos = mouse_ypos + vector_y;
		else mouse_ypos = mouse_ypos - stringer_height - vector_y ;
		// set positions
		if ( help_active == 1 ) mousehelp_pos();
		mouse_pos_init = true;
	}
}
document.onmousemove = get_mouse_xy;



function get_top_scroll () {
	var retval;
	if (document.documentElement && document.documentElement.scrollTop) {
		top_scroll = document.documentElement.scrollTop;
	} else {
		top_scroll = document.body.scrollTop;
	}
	retval = top_scroll;
	return retval;
}


function get_left_scroll () {
	var retval;
	if (document.documentElement && document.documentElement.scrollLeft)
		left_scroll = document.documentElement.scrollLeft;
	else {
		left_scroll = document.body.scrollLeft;
	}
	retval = left_scroll;
	return retval;
}


function get_scrolls () {
	get_top_scroll();
	get_left_scroll();
}



function getWindowSize ( what ) {
	var browser_width = 0;
	var browser_height = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
			browser_width = window.innerWidth;
			browser_height = window.innerHeight;
	} else if (
		document.documentElement
		&& ( document.documentElement.clientWidth || document.documentElement.clientHeight )
	) {
			//IE 6+ in 'standards compliant mode'
			browser_width = document.documentElement.clientWidth;
			browser_height = document.documentElement.clientHeight;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			//IE 4 compatible
			browser_width = document.body.clientWidth;
			browser_height = document.body.clientHeight;
	}
	switch ( what ) {
		case 'width' : return browser_width; break;
		case 'height' : return browser_height; break;
	}
}


function mousehelp_size () {
	if ( help_active == 1 ) {
		stringer_width = default_width;
		var test_width = document.getElementById('mousehelp_text').offsetWidth;
		if ( test_width < stringer_width ) stringer_width = test_width;
		if ( ( test_width > stringer_width ) && ( test_width < default_width ) ) stringer_width = test_width;
		stringer_height = document.getElementById('mousehelp_text').offsetHeight;
		if ((mhint_min_width > 0) && (stringer_width < mhint_min_width))
		{
			stringer_width = mhint_min_width;
		}
		mousehelp.style.width = stringer_width + 'px';
		mousehelp.style.height = stringer_height + 'px';
	}
}


function mousehelp_on ( show_text ) {
	try {
		if ( mouse_pos_init == false ) return;
		mousehelp_off();
		get_scrolls();
		max_x = getWindowSize('width') + left_scroll;
		max_y = getWindowSize('height') + top_scroll;
		if ( !mousehelp )
		{
			mousehelp = document.getElementById('mousehelp');
			mousehelp.style.position = 'absolute' ;
		}
		var stringer = "";
		switch ( show_text ) {
			case 'null': stringer= ''; break;
			default: stringer = show_text; break;
		}
		mousehelp.innerHTML = '<table cellspacing="0" cellpadding="0" border="0"><td id="mousehelp_text">' + stringer + '</td></table>';
		help_active = 1;
		try {
			get_mouse_xy(event);
		} catch (e) { }
		mousehelp_size();
		mousehelp_pos();
		window.setTimeout("if ( help_active == 1 ) mousehelp.style.visibility = 'visible';",mouse_help_delay);
		//window.setTimeout("mousehelp_pos()",mouse_help_delay/2);
	}
	catch ( e )
	{ }
}

function mhon( show_text ) {
	mousehelp_on ( show_text ) ;
}

function mhoff ( ) {
	mousehelp_off () ;
}


function mousehelp_pos ( ) {
	mousehelp.style.left = mouse_xpos + 'px';
	mousehelp.style.top = mouse_ypos + 'px';
}


function mousehelp_off ( ) {
	var mousehelp_for_off = document.getElementById('mousehelp');
	mousehelp_for_off.style.visibility = 'hidden';
	mousehelp_for_off.innerHTML = '';
	mousehelp_for_off.style.width = '0px';
	mousehelp_for_off.style.height = '0px';
	mousehelp_for_off.style.left = '0px';
	mousehelp_for_off.style.top = '0px';
	help_active = 0;
}

MH_Hint = function ( HintingObject , HintString )
{
	HintingObject.style.cursor = "help";
	mousehelp_on(HintString);
	HintingObject.onmouseout = mousehelp_off;
}

MH_HintNoCursor = function ( HintingObject , HintString )
{
	mousehelp_on(HintString);
	HintingObject.onmouseout = mousehelp_off;
}
