var selectsShown = true;
var popupsShown = false;

function helpPop(evt, name, width, position){
	
	//first hides all popups
	//var allDivTags = new Array();
	hideAllPops(true);
	//sets variable to true
	popupsShown = true;
	//hides selects using other function
	showHideSelects();
	//sets object variable
	popObj = document.getElementById(name)
	//gets the position of the mouse when clicked using other function
	xyArray = getPos(evt);
	posx= xyArray[0];
	posy= xyArray[1];
	//checks which side the popup should display at
	if (position == "left")	posx = posx - width;
	//sets position of popup
	popObj.style.position = "absolute";
	popObj.style.left = posx + "px";
	popObj.style.top = posy + "px";
	popObj.style.width = width + "px";
	popObj.style.display = "";
	
	var detect = navigator.userAgent.toLowerCase();
	if (document.all && !(detect.indexOf("mac") > 0)){
		//this hack is required because IE is not showing the border when the pop up is first displayed
		//hidden from the mac
		setTimeout("popObj.style.display = 'none';", 1);
		setTimeout("popObj.style.display = '';", 1);
	}
}
function hideAllPops(calledByHelpPop){
	/*this checks if the close button has been used.
	It works in reverse by checking if the helpPop() function has called it.
	If true, no popups will be displayed and therefore showHideSelects should work */
	if(!calledByHelpPop)popupsShown = false; 
	var allDocDivs = getElementsByStyleClass("helpPop", "div");
	for (i=0; i<allDocDivs.length; i++){
		allDocDivs[i].style.left = "0px";//required because of bug in ie mac
		allDocDivs[i].style.display = "none";

	}
	showHideSelects();
}

function showHideSelects(){

	if (!popupsShown && document.all){
		var allSelects = document.getElementsByTagName('select');
		if (allSelects.length>0){
			if (selectsShown == true){
				for (i=0; i<allSelects.length; i++){
					allSelects[i].style.visibility = "hidden";
				}
				selectsShown = false;
			}else{
				for (i=0; i<allSelects.length; i++){
					allSelects[i].style.visibility = "";
				}
				selectsShown = true;
			}
		}
	}
}
function getElementsByStyleClass(className, tagName) {
	var allDivTags = document.all ? document.all : document.getElementsByTagName(tagName);
	var elements = new Array();
  for (var e = 0; e < allDivTags.length; e++)
    if (allDivTags[e].className == className)
      elements[elements.length] = allDivTags[e];
  return elements;
}


function getPos(e)
{
	var posx = 0;
	var posy = 0;
	//for ie
	if (!e) var e = window.event;
	if (e.pageX || e.pageY)
	{
		//should return this value for mozilla browsers.
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY)
	{ 
		if (document.documentElement && document.documentElement.scrollTop){
			/*ie 6*/
			theTop = document.documentElement.scrollTop;
			theLeft = document.documentElement.scrollLeft;
		}else if (document.body){
			/*ie 5.x*/
			theTop = document.body.scrollTop;
			theLeft = document.body.scrollLeft;
		}
		posx = e.clientX + theLeft;
		posy = e.clientY + theTop;
	}
	return [posx, posy]
}