﻿// AJAX enabled expanding table
// May 2007 : Javascript
// Tim Surtell @ Clario

var Details, AlwaysReload, PersistView, FullWidthPointer

function SetupExpandingTable(DetailsURLSetting, AlwaysReloadSetting, PersistViewSetting, FullWidthPointerSetting)
	{
	DetailsURL = DetailsURLSetting; // The relative URL that will be loaded when expanding
	AlwaysReload = AlwaysReloadSetting; // True to force reload on every expand
	PersistView = PersistViewSetting // True to store a cookie for each item viewed and show viewed icon
	FullWidthPointer = FullWidthPointerSetting // True to show the pointer over the full width of the row
	}
//************************************************************************************************************
function HeadingMouseOver(HeadingRowID)
	{
	// Add color heading and hand cursor if row is not expanded
	if (document.getElementById(HeadingRowID).className == "ExpandingTableHeadingRow")
		{
		document.getElementById(HeadingRowID).className = "ExpandingTableHeadingRowOver";
		}
	if (FullWidthPointer == true)
		{
		document.getElementById(HeadingRowID).style.cursor = "pointer";
		}
	}
//************************************************************************************************************
function HeadingMouseOut(HeadingRowID)
	{
	// Remove color heading and hand cursor if row is not expanded
	if (document.getElementById(HeadingRowID).className == "ExpandingTableHeadingRowOver")
		{
		document.getElementById(HeadingRowID).className = "ExpandingTableHeadingRow";
		document.getElementById(HeadingRowID).style.cursor = "";
		}
	}
//************************************************************************************************************
function ExpandCollapse(HeadingRowID, DetailsRowID, DetailsCellID, StatusIconID, DetailsID)
	{	
	// Expand or collapse row
	if (document.getElementById(HeadingRowID).className != "ExpandingTableHeadingRowSelected")
		{
		// Don't reload the same data unless AlwaysReload setting is true
		if (document.getElementById(DetailsCellID).innerHTML.length < 20 || AlwaysReload == true)
			{
			// Use AJAX to get details
			GetDetails(HeadingRowID, DetailsRowID, DetailsCellID, StatusIconID, DetailsID);
			}
		else
			{
			// Expand row
			document.getElementById(DetailsRowID).style.display = "";
			document.getElementById(HeadingRowID).className = "ExpandingTableHeadingRowSelected";
			}
		}
	else
		{
		// Collapse row
		document.getElementById(DetailsRowID).style.display = "none";
		document.getElementById(HeadingRowID).className = "ExpandingTableHeadingRow";
		}
	}
//************************************************************************************************************
function GetDetails(HeadingRowID, DetailsRowID, DetailsCellID, StatusIconID, DetailsID)
	{
	var xmlHttp;
		
	// Instantiate a XMLHttpRequest object
	try
		{
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
		}
	catch (e)
		{
		// Internet Explorer
		try
			{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
			}
		catch (e)
			{
			try
				{
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
				}
			catch (e)
				{
				alert("Your browser does not support AJAX!");
				}
			}
		}
		
		// Create a function to respond to XMLHttpRequest state changes
		xmlHttp.onreadystatechange = function()
			{
			if(xmlHttp.readyState == 4)
				{
				// Populate details, expand row, show status icon, and set cookie
				document.getElementById(DetailsCellID).innerHTML = xmlHttp.responseText;
				document.getElementById(DetailsRowID).style.display = "";
				document.getElementById(HeadingRowID).className = "ExpandingTableHeadingRowSelected";
				if (PersistView == true)
					{
					document.getElementById(StatusIconID).src = "Images/Icons/icon_status_viewed.gif";
					document.getElementById(StatusIconID).alt = "You have viewed this item";
					document.getElementById(StatusIconID).title = "You have viewed this item";
					CreateCookie("candidate_job_views", DetailsID, "V");
					}
				else
					{
					document.getElementById(StatusIconID).src = "Images/trans_pixel.gif";
					}
				}
			}
		
		// Show waiting status icon
		document.getElementById(StatusIconID).src = "Images/Icons/icon_status_waiting.gif";
		document.getElementById(StatusIconID).alt = "Please wait...";
		document.getElementById(StatusIconID).title = "Please wait...";

		// Send request using XMLHttpRequest
		xmlHttp.open("GET", ajaxPath + DetailsURL + DetailsID, true);
		xmlHttp.send(null);
	}
//************************************************************************************************************
function GotoJob(DetailsID, SectorName, Title)
	{	
	// Set cookie
	CreateCookie("candidate_job_views", DetailsID, "V");
	
	// Navigate to Job
	location.href = ajaxPath + SectorName + "-jobs/" + DetailsID + "/" + Title + ".html";
	}
//************************************************************************************************************
function GotoMicrositeJob(DetailsID, Microsite)
	{	
	// Set cookie
	CreateCookie("candidate_job_views", DetailsID, "V");
	
	// Navigate to Job
	location.href = ajaxPath + "Microsites/" + Microsite + "/job_details.aspx?JobID=" + DetailsID;
	}