// JavaScript Document

// set the help layer id
var helpLayerContainerId = 'bfc_help_box';	// container layer
var helpLayerContentId = 'bfc_help_content';	// layer to show actual help item content
var helpLayerWidth = '200';	// width (in pixels) for the container layer.
var helpLayerHeight = '100';	// height (in pixels) for the container layer.

// write the help layer object to the document
document.write('<div id="'+helpLayerContainerId+'" class="helpContainer" style="width:'+helpLayerWidth+'px; z-index:10;">' + 
					'<div id="helpBoxHead" class="helpItemHead">' + 
						'<table width="100%" border="0" cellspacing="0" cellpadding="0" class="helpItemHead"><tr>' + 
						'<td align="left"><img src="/images/HelpIcon_bluebkg_16x16.gif" alt="Bluefields Capital Help" width="16" height="16" border="0" align="absmiddle"></td>' + 
						'<td align="left">Bluefields Capital Help</td>' + 
						'<td align="right"><a href="javascript:void(0)" onClick="hideHelpItem();"><img src="images/close_window.gif" alt="Close Window" width="16" height="14" border="0" align="right"></a></td>' + 
						'</tr></table>' + 
					'</div>' +
					'<div id="'+helpLayerContentId+'" class="helpItems" style="height:'+helpLayerHeight+'px;"></div>' + 
					'' + 
			   '</div>');

// The following function creates an XMLHttpRequest object...
function createRequestObject() {
	var request_o; //declare the variable to hold the object.
	var browser = navigator.appName; //find the browser name
	if (browser == "Microsoft Internet Explorer") {
		request_o = new ActiveXObject("Microsoft.XMLHTTP"); /* Create the object using MSIE's method */
	} else {
		request_o = new XMLHttpRequest(); /* Create the object using other browser's method */
	}
	return request_o; //return the object
}

// get the global xmlreq object
var http = createRequestObject();

// sets the contents of bfc_help_box to itemId
function setHelpItemLayer(itemId) {
	if (itemId < 1) {
		return false;
	}
	http.abort();
	http.open('post', '/bfc_help.php');
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http.onreadystatechange = function () {
		if (http.readyState == 4) { //Finished loading the response
			var response = http.responseText;
			document.getElementById(helpLayerContentId).innerHTML = response;
			return true;
		}
	};
	http.send('action=getHelpItemHTML&itemId=' + itemId);
	return true;
}

function getStyleObject(objectId) {
	if(document.getElementById && document.getElementById(objectId)) {
		/* W3C DOM*/
		return document.getElementById(objectId).style;
	} else if (document.all && document.all(objectId)) {
		/* MSIE 4 DOM*/
		return document.all(objectId).style;
	} else if (document.layers && document.layers[objectId]) {
		/* NN 4 DOM.. note: this won't find nested layers*/
		return document.layers[objectId].style;
	} else {
		return false;
	}
}

function setRelLayerPos(objectId,xOffset,yOffset,e) {
    // get the mouse x & y coordinate relative to the dosument; not the screen
	// reposition the layer (objectId) to these coordinates with xOffset,yOffset
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) {
		posx = e.pageX;
		posy = e.pageY;
	} else if (e.clientX || e.clientY) {
		posx = e.clientX + document.body.scrollLeft;
		posy = e.clientY + document.body.scrollTop;
	}
	var layer = getStyleObject(objectId);
	if(layer) {
		layer.left = posx + xOffset;
		layer.top = posy + yOffset;
	} else {
		return false;
	}
}

function showHelpItem(itemId, xOffset, yOffset, e) {
	if (setHelpItemLayer(itemId)) {
		setRelLayerPos(helpLayerContainerId,xOffset,yOffset,e);
		document.getElementById(helpLayerContainerId).style.visibility = "visible";
		return true;
	} else {
		return false;
	}
}

function hideHelpItem() {
	// empty the contents
	document.getElementById(helpLayerContentId).innerHTML = '';
	// hide layer
	document.getElementById(helpLayerContainerId).style.visibility = "hidden";
	return true;
}