var picid = "", helpbutton = null, helpbuttontimeout = 0, bigpic = null;

function getRealPos(e, which) {
	var pos = 0;
	while( e != null ) {
		var ofs = e["offset" + which];
		pos += ofs;
		e = e.offsetParent;
	}
	return pos;
}

function showHelpButton(e, n) {
	keepHelpButtonOpen();
	hideHelpButton();

	var left = getRealPos(e, "Left"), top = getRealPos(e, "Top"), width = e.width, height = e.height;
	if( e.nodeName.toLowerCase() == "div" ) {
		width = parseInt(e.style.width);
		height = parseInt(e.style.height);
	}

	picid = e.id;

	left -= 2;
	top -= 2;
	/*@cc_on @if(@_jscript_version <= 5.5) width += 4; height += 4; @end @*/
	if( width < 0 ) width = 0;
	if( height < 0 ) height = 0;

	e = document.getElementById(n + "button");
	if( e == null ) return;
	e.style.display = "block";
	e.style.left = left + "px";
	e.style.top = top + "px";
	e.style.width = width + "px";
	e.style.height = height + "px";

	helpbutton = e;
}

function keepHelpButtonOpen() {
	if( helpbuttontimeout != 0 ) {
		window.clearTimeout(helpbuttontimeout);
		helpbuttontimeout = 0;
	}
}

function hideHelpButton() {
	if( helpbutton != null ) {
		helpbutton.style.display = "";
		helpbutton = null;
		picid = "";
	}
}

function delayHideHelpButton() {
	helpbuttontimeout = setTimeout("hideHelpButton()", 50);
}

function enlargePic() {
	var n = picid;
	hideHelpButton();
	if( n == "" ) return;

	shrinkPic();

	var s = document.getElementById(n), b = document.getElementById(n + "Big"), left = getRealPos(s, "Left"), top = getRealPos(s, "Top");
	b.style.display = "block";
	var width = b.width, height = b.height;
	if( b.nodeName.toLowerCase() == "div" ) {
		width = parseInt(b.style.width);
		height = parseInt(b.style.height);
	}
	var clientWidth = document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth;
	var max = clientWidth - width - 4;
	if( max < 0 ) max = 0;
	if( left > max ) left = max;
	max = document.body.scrollHeight - height - 4;
	if( max < 0 ) max = 0;
	if( top > max ) top = max;

	b.style.left = left + "px";
	b.style.top = top + "px";

	bigpic = b;

	s = document.getElementById("bigpicshadow");
	s.style.display = "block";
	s.style.left = (left + 4) + "px";
	s.style.top = (top + 4) + "px";
	s.style.width = width + "px";
	s.style.height = height + "px";
}

function shrinkPic() {
	if( bigpic != null ) {
		hideHelpButton();

		bigpic.style.display = "";
		bigpic = null;

		document.getElementById("bigpicshadow").style.display = "";
	}
}
