// help script
// pop div with help information


//print out the help box
window.document.write("<div id=\"helpbox\" class=\"helpbounds helpcontents\">");
	window.document.write("<div id=\"helptitle\" style=\"float:left;\"></div>");
	window.document.write("<div align=\"right\" style=\"text-align:right;margin-bottom:5px;\">");
		window.document.write("<a href=\"javascript:void(0)\">");
			window.document.write("<img src=\"../images/buttons/btn_x.gif\" border=\"0\" onclick=\"closehelp();\"/>");
		window.document.write("</a>");
	window.document.write("</div>");
	window.document.write("<div id=\"helpinfo\" class=\"helpinfocontents\">");
	window.document.write("</div>");
window.document.write("</div>");

function browser() {
	this.IE    = false;
	this.NS    = false
	agent = navigator.userAgent;
	if ((i = agent.indexOf("MSIE")) >= 0) {
		this.IE = true;
		return;
	}
	if ((i = agent.indexOf("Gecko")) >= 0) {
		this.NS = true;
		return;
	}
	if ((i = agent.indexOf("Netscape6/")) >= 0) {
		this.NS = true;
		return;
	}
}
browser = new browser();

function helpme(event){
	//hdoc the help document to get
	var tbody = (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
	var docwidth=document.all? tbody.scrollLeft+tbody.clientWidth : pageXOffset+window.innerWidth;
	var docheight=document.all? Math.min(tbody.scrollHeight, tbody.clientHeight) : Math.min(window.innerHeight);
		
	
	//get the help title
	if(browser.IE){
		src_obj = window.event.srcElement;	
	}
	if(browser.NS){
		src_obj = event.target;
	}
	hdoc = src_obj.getAttribute("help");
	type = src_obj.getAttribute("type");
	
	if(hdoc == "decline"){
		did = src_obj.getAttribute("did");	
	}else{
		did = "";	
	}
	if(type == "long"){
		height =  400;
	}else if(type == "short"){
		height = 100;
	}else{
		height = 100;
	}
	width = 400;
	var helpboxinfo = window.document.getElementById("helpinfo");
	helpboxinfo.style.width = width+"px";
	helpboxinfo.style.height = height+"px";
	
	xpos = tbody.scrollLeft+event.clientX
	ypos = tbody.scrollTop + event.clientY - (height + 55);
	if((event.clientX -(width/2)) > docwidth){
		//make the box appear on the left
		xpos = (event.clientX - width) - 10;
	}else{
		xpos = (event.clientX -(width/2));
	}
	if(ypos > docheight){
		ypos = tbody.scrollTop + event.clientY + 15;
	}
	
	var helpbox = window.document.getElementById("helpbox");
	helpbox.style.left = (xpos)+"px";
	helpbox.style.top = (ypos)+"px";
	
	loadcontents(hdoc,did);
}

function closehelp(){
	window.document.getElementById("helptitle").innerHTML = "";
	window.document.getElementById("helpinfo").innerHTML = "";
	var helpbox = window.document.getElementById("helpbox");
	
	helpbox.style.left = "-500px";
	helpbox.style.top = "-500px";	
}

function loadcontents(hdoc,did){
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		window.document.alert ("Browser does not support HTTP Request")
		return
	} 
	if(hdoc == "decline"){
		var url="../include/loadhelp.php?doc="+hdoc+"&did="+did;	
	}else{
		var url="../include/loadhelp.php?doc="+hdoc;
	}
	xmlHttp.onreadystatechange=function(){
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
			response = xmlHttp.responseText;
			response = response.split("~");
			success = response[0];
			if(success == "go"){
				window.document.getElementById("helptitle").innerHTML = response[1];
				window.document.getElementById("helpinfo").innerHTML = response[2];
			}else{
				window.document.getElementById("helptitle").innerHTML = "ERROR";
				window.document.getElementById("helpinfo").innerHTML = "Sorry, The Help Document Requested Could Not Be Found";
			}
   		}
	}

xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}


function GetXmlHttpObject(){ 
	var objXMLHttp=null;
	
	if (window.XMLHttpRequest){
	  objXMLHttp=new XMLHttpRequest()
	}else if(window.ActiveXObject){
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
}