// help script
// pop div with help information

//print out the alert box
window.document.write("<div id=\"alertbox\" class=\"alertbounds\">");
	window.document.write("<div id=\"alerttitle\" 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/x_btn.jpg\" border=\"0\" onclick=\"closeAlert();\"/>");
		window.document.write("</a>");
	window.document.write("</div>");
	window.document.write("<div id=\"alertinfo\" class=\"alertinfocontents\">");
	window.document.write("</div>");
	window.document.write("<div id=\"alertBtn\" align=\"center\"></div>");
window.document.write("</div>");


function alertMe(event){ // alert called from a button or link
	//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);
		
	browser = new CheckBrowser();
	//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(type == "long"){
		height =  400;
	}else if(type == "short"){
		height = 100;
	}else{
		height = 100;
	}
	width = 400;
	var alertboxinfo = window.document.getElementById("helpinfo");
	alertboxinfo.style.width = width+"px";
	alertboxinfo.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 alertbox = window.document.getElementById("alertbox");
	alertbox.style.left = (xpos)+"px";
	alertbox.style.top = (ypos)+"px";
}
function alertCustom(title,contents,mode){ //trigured from javascript
	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);
		
	
	
	width = 300;
	
	var alertboxinfo = window.document.getElementById("alertinfo");
	
	xpos = (docwidth/2) - (width/2);
	ypos = (docheight/2)+ tbody.scrollTop - 100;
	
	var alertbox = $("alertbox");
	alertbox.style.left = (xpos)+"px";
	alertbox.style.top = (ypos)+"px";
	alertbox.style.width = width+"px";
	
	$("alerttitle").innerHTML = title;
	$("alertinfo").innerHTML = contents;
	//decide the button
	switch(mode){
		case "OK":
			$("alertBtn").innerHTML = "<img src=\"../images/buttons/ok_btn.jpg\" onclick=\"closeAlert();\" border=\"0\"/>";
		break;
	}
}

function closeAlert(){
	$("alerttitle").innerHTML = "";
	$("alertinfo").innerHTML = "";
	$("alertBtn").innerHTML = "";
	var alertbox = window.document.getElementById("alertbox");
	
	alertbox.style.left = "-500px";
	alertbox.style.top = "-500px";	
}
