
/**
 * Show a tooltip
 *
 * @param Event evt The event passed in from gecko browsers, will be undefined under ie
 */
function showTooltip(evt)
{
	if (evt == undefined)
	{
		evt = event;
	}
	if (evt.stopPropagation)
	{
		evt.stopPropagation();
	}
	else
	{
		evt.cancelBubble = true;
	}
	var source = evt.srcElement || evt.target;
	var id = source.id.replace("Launcher", "");
	var tooltip = document.getElementById(id + "Tooltip");
	if (tooltip.className != "tooltip hiddenTooltip")
	{
		// hide it
		tooltip.className = "tooltip hiddenTooltip";
	}
	else
	{
		tooltip.className = "tooltip " + id + "Tooltip";
	}
}

/**
 * Hides a tooltip
 *
 * @param Event evt The event passed in from gecko browsers, will be undefined under ie
 */
function hideTooltip(evt)
{
	if (evt == undefined)
	{
		evt = event;
	}
	if (evt.stopPropagation)
	{
		evt.stopPropagation();
	}
	else
	{
		evt.cancelBubble = true;
	}
	var source = evt.srcElement || evt.target;
	// backtrack up to the parent with class equals help-tip
	var tooltip = getParentWithClassName(source, "tooltip");
	tooltip.className = "tooltip hiddenTooltip";
}

/**
 * Finds a parent node with the given class name
 
 */
function getParentWithClassName(node, className)
{
	var regex = new RegExp(className, "i");
	//regex.compile(node.className);
	// if the current node is the one were looking for then return it
	if (regex.exec(node.className))
	{
		theNode = node;
	}
	// check the node if and only if its not the body tag
	else if (node.nodeName.toLowerCase() != "body")
	{
		theNode = getParentWithClassName(node.parentNode, className);
	}
	// exit recursion
	else
	{
		theNode = false;
	}
	return theNode;
}

/**
 * Adds an event listener to a node
 *
 * @param DomNode node The node to add the event listener to
 * @param string event The name of the event, e.g. click, change, mouseover
 * @param Function handler A reference to the handler function
 * @param bool capture Flag to indicate that the event should register to capture events of this type
 */
function addEventListener(node, event, handler, capture)
{
	// internet explorer
	if (node.attachEvent)
	{
		node.attachEvent("on" + event, handler);
	}
	// gecko
	else if (node.addEventListener)
	{
		node.addEventListener(event, handler, capture);
	}
	// old
	else
	{
		node.onclick = handler;
	}
}

/**
 * Adds show and hide methods to the relevant tooltip items
 *
 */
function addTooltipMethods()
{
	// find all divs with classname equals help-tip and add the showTooltip method to their click events
	var ids = new Array();
	ids[ids.length] = "keywordsLauncher";
	ids[ids.length] = "locationLauncher";
	ids[ids.length] = "subCategoriesLauncher";
	ids[ids.length] = "categoryLauncher";
	for (var i = 0; i < ids.length; i++)
	{
		var node = document.getElementById(ids[i]);
		addEventListener(node, "click", showTooltip, false);
	}
	// find all buttons with class equals close and add the hideTooltip method to their click events
	nodes = document.getElementsByTagName("button");
	for (var i = 0; i < nodes.length; i++)
	{
		var node = nodes.item(i);
		if (node.className.toLowerCase() == "close")
		{
			addEventListener(node, "click", hideTooltip, false);
		}
	}
}


function setBooleanSearching(status)
{
	var searchMode = document.getElementById("searchMode");
	if (status.toLowerCase() == "yes")
	{
		searchMode.value = "BOOLEAN";
	}
	else if (searchMode.value.toUpperCase() == "BOOLEAN")
	{
		searchMode.value = "ANY";
	}
}