/*
Copyright © 2003
Author: Avery Perich
Date: 7-11-2003
Updated: 7-30-2004
Description: Code for the job details page
TODO: Add cross-browser support (currently only truly supports IE)
*/

var sSuffix = "_exp";
var sTargetClass;

// Returns true on success
function Expand(oDiv)
{
	// This code requires "document.all" support
	if (!document.all) return false;


	if (!oDiv) oDiv = event.srcElement;
	var oImg; // Plus or minus image
	var SpanIndex = oDiv.sourceIndex;

	if (oDiv.nodeName == "IMG")
	{
		oImg = oDiv;
	}
	else
	{
		var oTemp;
		var i = Math.max(SpanIndex - 2, 0);
		for(i; i < document.all.length; i++)
		{
			oTemp = document.all.item(i);
			if ((oTemp.nodeName == "IMG") && ((oTemp.src.indexOf("plus.gif") >= 0) || (oTemp.src.indexOf("minus.gif") >= 0)))
			{
				oImg = oTemp;
				break; // Exit the loop
			}
		}

		if (!oImg)
		{
			alert("Incorrect web page format!");
			return false;
		}
	}

	if (oDiv.nodeName != "DIV")
	{
		// Loop down until we find the first div
		var oTemp;
		var i;
		for(i = SpanIndex; i < document.all.length; i++)
		{
			oTemp = document.all.item(i);
			if (oTemp.nodeName == "DIV")
			{
				oDiv = oTemp;
				break; // Exit the loop
			}
		}

		if (!oTemp) 
		{
			alert("No DIVs where found!");
			return false;
		}
	}

	var sClass = oDiv.className;
	var index = sClass.indexOf(sSuffix);
	var isExpanded = (index >= 0);

	if (isExpanded)
	{
		oDiv.className = sClass.substring(0, index);
		oImg.src = "images/plus.gif";
	}
	else
	{
		oDiv.className = sClass + sSuffix;
		oImg.src = "images/minus.gif";
	}

	return true;
}

function hideAll(sClass)
{
	// This code requires "document.all" support
	if (!document.all) return false;


	if (!sClass) return;
	sTargetClass = sClass;

	var i;
	var oTemp;
	for(i = 0; i < document.all.length; i++)
	{
		oTemp = document.all.item(i);
		if (oTemp.className == sClass)
		{
			if (!Expand(oTemp)) return;
		}
	}
}

function ExpandCheck()
{
	// This code requires "document.all" support
	if (!document.all) return false;


	var obj = window.event.srcElement;
	if (obj && sTargetClass)
	{
		var oTemp = obj;
		while (oTemp)
		{
			if (oTemp.className == sTargetClass) Expand(obj);
			oTemp = oTemp.parentElement;
		}
	}
	window.event.returnValue = true;
	return true;
}

