All pastes #368869 Raw Edit

Someone

public text v1 · immutable
#368869 ·published 2007-02-23 11:57 UTC
rendered paste body
/************************************************* Global  *************************************************/

var STATUS_ACTIVE = 1;
var STATUS_INACTIVE = 2;
var STATUS_SETTLED = 3;
var STATUS_VOIDED = 4;
var STATUS_SUSPENDED = 6;
var STATUS_PENDING = 7;
var STATUS_CLOSED = 8;
var STATUS_SCRATCHED = 9;
var STATUS_INRUNNING = 10;

var MAX_LEVELS = 4;
var m_bLoadFlag = false;
var m_iTreeLevel = 0;
var m_iTreeParentId = 0;

var m_iCurrentRequestId;
var m_aAlarms = new Array();
var m_aTransactions = new Array();
var m_bViewAlarms = false;
// default calander settings
var m_iYear = 2007;
var m_iMonth = 1;
var m_iDay = 1;
var m_sDate = "";

/************************************************* Main Application  *************************************************/

function initialiseApplication()
{
	/*
	 * function: initialiseApplication()
	 * purpose: Does initialisation.
	 * params: none
	 * returns: none
	 */
	
	// initialise the markets
	initialiseMarkets();
	// start timers.
	doRealTime();
}

function cleanApplication()
{
	/*
	 * function: cleanApplication()
	 * purpose: Cleans up before exiting.
	 * params: none
	 * returns: none
	 */
	
	// get the document root element.
	var oRoot = document.documentElement;
	// clean all its children.
	cleanAllChildren(oRoot);
}

/************************************************* Market Tree *************************************************/

function populateTreeLevel(iTreeLevel, iTreeParentId, sMarketTab) 
{
	var sParams = "";
	if((isNumeric(iTreeLevel) === true) && ((iTreeLevel > 0) && (iTreeLevel <= MAX_LEVELS)) && (sMarketTab !== ""))
	{
		
		m_iTreeLevel = iTreeLevel;
		sParams = "treeLevel=" + iTreeLevel;
		if(iTreeLevel > 1)
			{
				if((isNumeric(iTreeParentId) === true) && (iTreeParentId > 0))
				{
					m_iTreeParentId = iTreeParentId;
					sParams += "&treeParentId=" + iTreeParentId;
				}	
			}
		// validate this input!
		sParams += "&marketDateFilter=" + getMarketDateFilterCode(sMarketTab);
		sParams += "&sMarketTab=" + sMarketTab;

		if(sMarketTab === "bodyMarketManagementNavigationQueryMarket")
		{
			sParams += "&date=" + m_sDate;
		}
		
		m_iCurrentRequestId = 1;
		
		ajaxRequest("php/getTreeLevel.php", sParams, processMarketLevelString);								   
	}
	else
	{
		alert("Error populating level");
	}
}

function contractTodaysMarket()
{	
	var oParent = $("bodyMarketManagementNavigationToday");
	// get the top level unordered list.
	var oUnorderedList = oParent.childNodes[1];
	
	for(var i = 0; i < oUnorderedList.childNodes.length; i++)
	{
		var oChild = oUnorderedList.childNodes[i];
		if(oChild.tagName === "LI")
		{
			if(oChild.childNodes.length > 1)
			{
				var oChild2 = oChild.childNodes[1];
				if(oChild2.tagName === "UL")
				{
					cleanAllChildren(oChild2);
					oChild2.parentNode.removeChild(oChild2);
				}
			}
		}
	}
	
	showTodaysMarket();
}

function unpopulateTreeLevel(iTreeLevel, sMarketTab)
{
	// is this code needed ???
	if((iTreeLevel > 1) && (iTreeLevel < MAX_LEVELS))
	{
		//alert("ok");
	}
}

function processMarketLevelString(oResponse)
{
    /*
	 * function: processMarketLevelList
	 * purpose: Processes market tree response
	 * params: oResponse
	 * returns: none
	 */
	 
	var sMarketLevelString = oResponse.responseText;
	
	var aTable;
	var oMarketDetail;
	
	// unpack the delimited string into an array of arrays (table)
	aTable = unpackIt(sMarketLevelString);
	
	//alert(sMarketLevelString + ", " + aTable.length);
	var sGeneric = aTable.shift();
	var sGeneric2 = aTable.shift();
	var aMarketLevelInfo = sGeneric.split("[");
	
	var iTreeLevel = parseInt(aMarketLevelInfo[0]);
	var iTreeParentId = parseInt(aMarketLevelInfo[1]);
	var sMarketTab = aMarketLevelInfo[2];
	
	// all levels except the last are loaded into the navigation
	if(iTreeLevel < MAX_LEVELS)
	{
		// build a DOM tree from the table.
		oMarketLevelList = generateMarketLevelList(iTreeLevel, iTreeParentId, sMarketTab, aTable);
		// render the DOM tree to the screen
		renderMarketLevelList(iTreeLevel, iTreeParentId, sMarketTab, oMarketLevelList);
	}
	else
	{
		// load the last level into the right hand side.
		
		if(hasDetailBeenShown(iTreeParentId) === false)
		{
			// this is the parent info we are adding back in.
			aTable.unshift(sGeneric2);
			oMarketDetail = generateMarketDetail(iTreeLevel, iTreeParentId, aTable);
			
			renderMarketDetail(oMarketDetail);
			
			if(m_bViewAlarms === true)
			{
				showAlarmLines(iTreeParentId);
				m_bViewAlarms = false;
			}
		}
		else
		{
			var bConfirm  = confirm("You already have that detail open. Do you wish to view?");
			
			if(bConfirm === true)
			{
				scrollToDetail(m_iTreeParentId);
			}
		}
	}
}

function generateMarketLevelList(iTreeLevel, iTreeParentId, sMarketTab, aTable)
{
    /*
	 * function: generateMarketLevelList
	 * purpose: Turns part of the market tree into a DOM tree structure
	 * params: aTable - Array(Array)
	 * returns: none
	 */
	
	var aRow;
	var oMarketLevelList = document.createElement("MarketLevelList");
	var oUl = document.createElement("ul");
	if((isArray(aTable) === true) && (aTable.length > 0))
	{
		for(var rowCounter = 0; rowCounter < aTable.length; rowCounter++)
		{
			// create the various nodes that we need
			var oLi = document.createElement("li");
			var oA = document.createElement("a");
			var oAText;
			var sClassName;
			
			// get the next row
			aRow = aTable[rowCounter];
			
			// set the attributes for the A node.
			oA.href = "#";
			oA.nextTreeLevel = (iTreeLevel+1); // this link will populate the next level
			oA.nextTreeParentId = aRow[0];
			oA.marketTab = sMarketTab;
			
			oA.onclick = function()
							{
								populateTreeLevel(this.nextTreeLevel, this.nextTreeParentId, this.marketTab);
							}
							
			
			var sText;
			
			switch(iTreeLevel)
			{
				case 2: 
					sText = aRow[2];
					break;
				default:
					sText = aRow[1];
					break;
			}
			
			oAText = document.createTextNode(sText);
			
			// add the text node to the A
			oA.appendChild(oAText);
			
			if(iTreeLevel === 3)
			{
				// depending on the status (aRow[4])
				// we want to set the class differently
				oA.className =  getStatusColour(parseInt(aRow[4])) + "Light";
				oLi.status = parseInt(aRow[4]);
			}
			
			// add the A to the LI 
			oLi.appendChild(oA);
			oLi.treeLevel = iTreeLevel;
			oLi.treeParentId = aRow[0];
			oLi.marketTab = sMarketTab;
			
			if(rowCounter === (aTable.length-1))
			{
				oLi.className = "last-child";
			}
			
			// add the LI to the UL
			oUl.appendChild(oLi);
		}
			
		// we want to set the id of the root LI of the full structure so
		// we can style it to remove top border.
		if(iTreeLevel === 1)
		{
			oUl.className = "root";
		}
		oMarketLevelList.appendChild(oUl);
	}
	return oMarketLevelList;
}

function renderMarketLevelList(iTreeLevel, iTreeParentId, sMarketTab, oMarketLevelList)
{
	/*
	 * function: renderMarketLevelList
	 * purpose: Renders the DOM tree to the browser
	 * params: oMarketLevelList - DOM tree
	 * returns: none
	 */
	
	if(m_iTreeLevel === 1)
	{	
		oInsertElement = $(sMarketTab);
	}
	else
	{
	    var oNodeList = document.getElementsByTagName("li");
		var bFoundChild = false;
		var iChildNodeCount = oNodeList.length;
		var iCount = 0;
		
		while((bFoundChild === false) && (iCount < iChildNodeCount))
		{
			oChild = oNodeList[iCount];
			if((oChild.marketTab === sMarketTab) && (parseInt(oChild.treeLevel) === (iTreeLevel-1)) && (parseInt(oChild.treeParentId) === iTreeParentId))
			{
				oInsertElement = oChild;
			}
			iCount++;
		}
	}
	

	if(iTreeLevel === 1)
	{
		///////////////////////////////////////////////////////!!!
		//////////              fix this               ////////!!!
		///////////////////////////////////////////////////////!!!
		///////////////////////////////////////////////////////!!!
		if(oInsertElement.id === "bodyMarketManagementNavigationQueryMarket")
		{
			for(var i = 0; i < oInsertElement.childNodes.length; i++)
			{
				//alert(oInsertElement.childNodes.length)
				oChild = oInsertElement.childNodes[i];
				if(oChild.tagName === "UL")
				{
					//cleanAllChildren(oChild);
					//oDiv.removeChild(oChild);
				}
			}
			// need to free up memory so we want to clean the 
			// node we are going to remove and all its children
			//cleanAllChildren(oDiv.childNodes[1]);
			//oDiv.removeChild(oDiv.childNodes[2]);
		}
	}
	else
	{
		for(var i = 0; i < oInsertElement.parentNode.childNodes.length; i++)
		{
			var oChild = oInsertElement.parentNode.childNodes[i];
			if(oChild.tagName === "LI")
			{
				if(oChild.childNodes.length > 1)
				{
					// need to free up memory so we want to clean the 
					// node we are going to remove and all its children
					cleanAllChildren(oChild.childNodes[1]);
					oChild.removeChild(oChild.childNodes[1]);
				}
			}
		}
	}
	
	while(oMarketLevelList.firstChild)
	{
		// the parent element is a dummy UL element. We want to take its children
		// and add it as the children of the UL element identified by oUlElement
		oInsertElement.appendChild(oMarketLevelList.firstChild);
	}
}

function generateMarketDetail(iTreeLevel, iTreeParentId, aTable)
{	
    /*
	 * function: generateMarketDetail
	 * purpose: Turns the lowest level of the market tree (detail) into a DOM tree
	 * params: aTable - Array(Array)
	 * returns: none
	 */
	
	// the first element in the array is parent information
	
	var sLineOwnerDetails = aTable.shift();
	
	var aLineOwnerDetails = sLineOwnerDetails.split("{");
	var sLineNavName = aLineOwnerDetails[0];
	var sLineOwnerName = aLineOwnerDetails[1];
	var iStatusRef = parseInt(aLineOwnerDetails[2]);
	var iSportsRef = parseInt(aLineOwnerDetails[3]);
	var iLineOwnerRef = parseInt(aLineOwnerDetails[4]);
	
	// want to change this so that there is no table being passed then a simple error box is displayed
	// header box, content box (with error)

	var aRow;
	// this is just a dummy element which we are using to hold our stuff

	var oTop = document.createElement("nodes");

	var oDivContentFrame = document.createElement("div");
	
	oDivContentFrame.lineOwnerRef = iTreeParentId;
	
	var MAX_COLUMNS = 4;
	
	// create our nodes ;)
	//container nodes
	
	// header nodes
	var oDivContentFrameHeader = document.createElement("div");
	var oSpanSpanLeft = document.createElement("span");
	var oPP1 = document.createElement("p");
	var oPP1Text;
	var oAClose = document.createElement("a");
	var oACloseText;
	
	var oAPinUnpin = document.createElement("a");
	var oAPinUnpinText;
	
	var oSpanSpanRight = document.createElement("span");
	
	// content frame nodes
	var oDivContentFrameMain = document.createElement("div");
	var oTableContentFrame = document.createElement("table");
	var oTableContentFrameBody = document.createElement("tbody");
	var oTrHeaderRow = document.createElement("tr");
	
	var aTableContentFrameHeaders = new Array(MAX_COLUMNS);
	var aTableContentFrameCellWidths = new Array(MAX_COLUMNS);
	
	aTableContentFrameHeaders[0] = "#";
	aTableContentFrameHeaders[1] = "Name";
	aTableContentFrameHeaders[2] = "Current Status";
	
	if(iSportsRef === 2)
	{
		aTableContentFrameHeaders[3] = "Actions";
	}
	else
	{
		aTableContentFrameHeaders[3] = " ";
	}
	
	aTableContentFrameHeaders[4] = "";
	
	aTableContentFrameCellWidths[0] = "35px";
	aTableContentFrameCellWidths[1] = "150px";
	aTableContentFrameCellWidths[2] = "100px";
	aTableContentFrameCellWidths[3] = "100px";
	aTableContentFrameCellWidths[4] = "100px";
	
	oPP1.className = "p1";
	
	// bringing this from db now.
	oPP1Text = document.createTextNode(sLineNavName + " - " + sLineOwnerName);
	
	oPP1.appendChild(oPP1Text);
	
	oSpanSpanLeft.appendChild(oPP1);
	oSpanSpanLeft.className = "spanLeft";	

	oDivContentFrameHeader.className = "contentFrameHeader " + getStatusColour(iStatusRef) + "Top";
	oDivContentFrameHeader.appendChild(oSpanSpanLeft);
	
	oAPinUnpinText = document.createTextNode("[ Pin ]");
	oAPinUnpin.appendChild(oAPinUnpinText);
	oAPinUnpin.href = "#";
	
	oAPinUnpin.treeParentId = iTreeParentId;
	oAPinUnpin.style.marginRight = "10px";
	
	oAPinUnpin.onclick = function()
							{
								pin(this.treeParentId);
							}
							
	oAPinUnpin.pinned = false;
	
	oSpanSpanRight.appendChild(oAPinUnpin);
	
	oACloseText = document.createTextNode("[ Close ]");
	
	oAClose.appendChild(oACloseText);
	oAClose.href = "#";
	oAClose.treeLevel =  iTreeLevel;
	oAClose.treeParentId = iTreeParentId;
	
	oAClose.onclick  = function()
						{
							closeMarketDetail(this.treeParentId);
						}
						
	oSpanSpanRight.appendChild(oAClose);
	
	
	oSpanSpanRight.className = "spanRight";
	
	oDivContentFrameHeader.appendChild(oSpanSpanRight);
	
	oDivContentFrame.id = iTreeParentId;
	oDivContentFrame.className = "contentFrame";
	oDivContentFrame.appendChild(oDivContentFrameHeader);
	
	var oTrHeaderRow = document.createElement("tr");
		
	for(var colCounter = 0; colCounter < MAX_COLUMNS; colCounter++)
	{
		var oTdContentFrameCell = document.createElement("td");
	
		oTdContentFrameCell.className = "headerFrameCell";
		oTdContentFrameCell.style.width = aTableContentFrameCellWidths[colCounter];
		var oTextNode = document.createTextNode(aTableContentFrameHeaders[colCounter]);
		oTdContentFrameCell.appendChild(oTextNode);
				
		oTrHeaderRow.appendChild(oTdContentFrameCell);
	}
	
	oTableContentFrameBody.appendChild(oTrHeaderRow);
	
	if((isArray(aTable) === true) && (aTable.length > 0))
	{
		for(var rowCounter = 0; rowCounter < aTable.length; rowCounter++)
		{
			aRow = aTable[rowCounter];
			var oTrDetailRow = document.createElement("tr");
			
			var oTdContentFrameCell1 = document.createElement("td");
			var oTdContentFrameCell2 = document.createElement("td");
			var oTdContentFrameCell3 = document.createElement("td");
			var oTdContentFrameCell4 = document.createElement("td");
	
			if(iSportsRef === 2)
			{
				
				oTdContentFrameCell1.className = "contentFrameCell lineNo" + (rowCounter+1);
			}
			else
			{
				oTdContentFrameCell1.className = "contentFrameCell";
			}

			oTdContentFrameCell2.className = "contentFrameCell";
			oTdContentFrameCell3.className = "contentFrameCell";
			oTdContentFrameCell4.className = "contentFrameCell";

			var oTextNode1 = document.createTextNode(rowCounter+1); // line
			var oTextNode2 = document.createTextNode(aRow[1]); // name
			var iStatus = parseInt(aRow[3]);
			var oTextNode3 = document.createTextNode(getStatus(iStatus)); // status
			
			var oSelect = populateSelectOptions(iStatus);
			
			// so we can always tell what the current status
			oSelect.lineOwnerRef = iLineOwnerRef;
			oSelect.lineRef = aRow[0];
			
			
			oTdContentFrameCell1.appendChild(oTextNode1);
			oTdContentFrameCell2.appendChild(oTextNode2);
			oTdContentFrameCell3.appendChild(oTextNode3);
			oTdContentFrameCell4.appendChild(oSelect);

			oTrDetailRow.appendChild(oTdContentFrameCell1);
			oTrDetailRow.appendChild(oTdContentFrameCell2);
			oTrDetailRow.appendChild(oTdContentFrameCell3);
			oTrDetailRow.appendChild(oTdContentFrameCell4);

			// we can identify a row by lineRef in a table.
			oTrDetailRow.lineRef = aRow[0];

			oTableContentFrameBody.appendChild(oTrDetailRow);
		}
	}

	oTableContentFrame.className = "contentFrameTable";
	oTableContentFrame.appendChild(oTableContentFrameBody);
	
	var oSpan = document.createElement("span");
	oSpan.className = "buttonSpanRight";
	var oButton = document.createElement("button");
	
	oButton.value = "Commit";
	
	oButton.lineOwnerRef = iLineOwnerRef;
	
	oButton.onclick = function ()
					{
						var bWantConfirmations = false;
						var bConfirm = false;
						
						if(bWantConfirmations === true)
						{
							 bConfirm = confirm("You are about to change these lines. Are you sure?");
						}
						if(bConfirm === true || bWantConfirmations === false)
						{
							this.disabled = true;
							updateLines(this.lineOwnerRef);
						}
					}
				
				
	oSpan.appendChild(oButton);
	
	oDivContentFrameMain.className = "contentFrameMain";
	oDivContentFrameMain.appendChild(oTableContentFrame);
	oDivContentFrameMain.appendChild(oSpan);
	
	// set some attributes
	oDivContentFrame.pinned = false;
	oDivContentFrame.treeLevel = iTreeLevel;
	oDivContentFrame.treeParentId = iTreeParentId;
	
	var oForm = document.createElement("form");
	
	oForm.lineOwnerRef = iLineOwnerRef;
	
	oForm.appendChild(oDivContentFrameMain);
	
	oDivContentFrame.appendChild(oForm);
	
	oTop.appendChild(oDivContentFrame);

	return(oTop);
}

function populateSelectOptions(iStatus)
{	
	var oSelect = document.createElement("select");
	
	var oDefaultOption = document.createElement("option");
	var oDefaultOptionText = document.createTextNode("Choose an Action...")
	oDefaultOption.appendChild(oDefaultOptionText);
	oSelect.appendChild(oDefaultOption);
	
	oSelect.currentStatus = iStatus;
	
	oSelect.onchange = function()
						{
							var sSelectedStatus = this.options[this.selectedIndex].status;
							if(sSelectedStatus === STATUS_SCRATCHED)	
							{
								do
								{
									sReductionOdds = prompt("Please enter reduction odds","10.0");
								}
								while(sReductionOdds === "");
								
								if(sReductionOdds !== null)
								{
									this.reductionOdds = sReductionOdds;
								}
								else
								{
									this.selectedIndex = 0;
								}
							}
						}
	
	switch(iStatus)
	{
		case STATUS_ACTIVE:
		{
			oSelect.appendChild(getSelectOption(STATUS_INACTIVE));
			oSelect.appendChild(getSelectOption(STATUS_VOIDED));
			oSelect.appendChild(getSelectOption(STATUS_SUSPENDED));
			oSelect.appendChild(getSelectOption(STATUS_PENDING));
			oSelect.appendChild(getSelectOption(STATUS_CLOSED));
			oSelect.appendChild(getSelectOption(STATUS_SCRATCHED));
			oSelect.appendChild(getSelectOption(STATUS_INRUNNING));
			break;
		}
		case STATUS_INACTIVE:
		{
			oSelect.appendChild(getSelectOption(STATUS_ACTIVE));
			oSelect.appendChild(getSelectOption(STATUS_VOIDED));
			oSelect.appendChild(getSelectOption(STATUS_SUSPENDED));
			oSelect.appendChild(getSelectOption(STATUS_PENDING));
			oSelect.appendChild(getSelectOption(STATUS_CLOSED));
			oSelect.appendChild(getSelectOption(STATUS_SCRATCHED));
			oSelect.appendChild(getSelectOption(STATUS_INRUNNING));
			break;
		}
		case STATUS_SETTLED:
		{
			oSelect.appendChild(getSelectOption(STATUS_CLOSED));
			oSelect.appendChild(getSelectOption(STATUS_VOIDED));
			break;
		}
		case STATUS_VOIDED:
		{
			oSelect.appendChild(getSelectOption(STATUS_ACTIVE));
			oSelect.appendChild(getSelectOption(STATUS_SUSPENDED));
			oSelect.appendChild(getSelectOption(STATUS_PENDING));
			oSelect.appendChild(getSelectOption(STATUS_CLOSED));
			oSelect.appendChild(getSelectOption(STATUS_SCRATCHED));
			oSelect.appendChild(getSelectOption(STATUS_INRUNNING));
			break;
		}
		case STATUS_SUSPENDED:
		{
			oSelect.appendChild(getSelectOption(STATUS_ACTIVE));
			oSelect.appendChild(getSelectOption(STATUS_VOIDED));
			oSelect.appendChild(getSelectOption(STATUS_CLOSED));
			oSelect.appendChild(getSelectOption(STATUS_SCRATCHED));
			oSelect.appendChild(getSelectOption(STATUS_INRUNNING));
			break;
		}
		case STATUS_PENDING:
		{
			oSelect.appendChild(getSelectOption(STATUS_ACTIVE));
			oSelect.appendChild(getSelectOption(STATUS_VOIDED));
			oSelect.appendChild(getSelectOption(STATUS_SCRATCHED));
			break;
		}
		case STATUS_CLOSED:
		{
			oSelect.appendChild(getSelectOption(STATUS_ACTIVE));
			oSelect.appendChild(getSelectOption(STATUS_SUSPENDED));
			oSelect.appendChild(getSelectOption(STATUS_SCRATCHED));
			oSelect.appendChild(getSelectOption(STATUS_SETTLED));
			break;
		}
		case STATUS_SCRATCHED:
		{
			oSelect.appendChild(getSelectOption(STATUS_ACTIVE));
			oSelect.appendChild(getSelectOption(STATUS_SUSPENDED));
			oSelect.appendChild(getSelectOption(STATUS_CLOSED));
			oSelect.appendChild(getSelectOption(STATUS_PENDING));
			break;
		}
		case STATUS_INRUNNING:
		{
			oSelect.appendChild(getSelectOption(STATUS_VOIDED));
			break;
		}
	}
	return oSelect;
}

function getSelectOption(iStatus)
{
	var oOption = document.createElement("option");
	var oOptionText;
	
	oOption.status = iStatus;
	
	switch(iStatus)
	{
		case STATUS_ACTIVE:
		{
			oOptionText = document.createTextNode("Activate");
			oOption.appendChild(oOptionText);
			break;
		}
		case STATUS_INACTIVE:
		{
			oOptionText = document.createTextNode("Inactivate");
			oOption.appendChild(oOptionText);
			break;
		}
		case STATUS_SETTLED:
		{
			oOptionText = document.createTextNode("Settle");
			oOption.appendChild(oOptionText);
			break;
		}
		case STATUS_VOIDED:
		{
			oOptionText = document.createTextNode("Void");
			oOption.appendChild(oOptionText);
			break;
		}
		case STATUS_SUSPENDED:
		{	
			oOptionText = document.createTextNode("Suspend");
			oOption.appendChild(oOptionText);
			break;
		}
		case STATUS_PENDING:
		{	
			oOptionText = document.createTextNode("Pending");
			oOption.appendChild(oOptionText);
			break;
		}
		case STATUS_CLOSED:
		{
			oOptionText = document.createTextNode("Close");
			oOption.appendChild(oOptionText);
			break;
		}
		case STATUS_SCRATCHED:
		{
			oOptionText = document.createTextNode("Scratch");
			oOption.appendChild(oOptionText);
			break;
		}
		case STATUS_INRUNNING:
		{
			oOptionText = document.createTextNode("InRunning");
			oOption.appendChild(oOptionText);
			break;
		}
	}
	return oOption;
}

function renderMarketDetail(oMarketDetail)
{
	/*
	 * function: renderMarketDetail
	 * purpose: Renders the detail level to the browser
	 * params: oMarketDetail - market detail DOM tree
	 * returns: none
	 */

	oParentNode = $("bodyMarketManagementDetail"); 
	
	while(oMarketDetail.firstChild)
	{
		oParentNode.appendChild(oMarketDetail.firstChild);
	}
	
}

function pin(iTreeParentId) 
{
	var oDivMain;
	var iDivMainCount;
	var iChildCount;
	var oChild;
	var bFoundCorrectChild = false;
	// this is where all content frames are held
	oDivMain = $("bodyMarketManagementDetail");
	
	// how many content frames are there?
	iDivMainCount = oDivMain.childNodes.length;
	
	// loop through all the content frames
	iChildCount = 0;

	while((bFoundCorrectChild === false) && (iChildCount < iDivMainCount))
	{
		// get the content frame
		oChild = oDivMain.childNodes[iChildCount];
		// is the content frame the one we want?
		
		if(parseInt(oChild.treeParentId) === iTreeParentId)
		{				
			bFoundCorrectChild = true;
			
			// get the text of the A node so we change it.
			//   DIV    DIV           SPAN(right)   A             text
			oAText = oChild.childNodes[0].childNodes[1].childNodes[0].childNodes[0];
			
			// pin or unpin the content frame.
			if(oChild.pinned === "false")
			{
				oChild.pinned = "true";
				oAText.nodeValue = "[ Unpin ]";
			}
			else
			{
				oChild.pinned = "false";
				oAText.nodeValue = "[ Pin ]";
			}
		}

		iChildCount++;
	}
}

function closeMarketDetail(iLineOwnerRef)
{
	var bFoundCorrectChild = false;
	var oDivMain;
	var iDivMainCount;
	var iChildCount;
	var oChild;
	
	// this is where all content frames are held
	oDivMain = $("bodyMarketManagementDetail");
	
	// how many content frames are there?
	iDivMainCount = oDivMain.childNodes.length;
	iChildCount = 0;
	while((bFoundCorrectChild === false) && (iChildCount < iDivMainCount))
	{
		// get the content frame
		oChild = oDivMain.childNodes[iChildCount];
		// is the content frame the one we want?
		
		if(parseInt(oChild.treeParentId) === iLineOwnerRef)
		{
			// if pinned. get confirmation
			var bConfirm = true;
			
			if(oChild.pinned === "true")
			{
				bConfirm = confirm("Item is pinned. Are you sure?");
			}

			if(bConfirm === true)
			{
				cleanAllChildren(oChild);
				oChild.parentNode.removeChild(oChild);	
			}
			bFoundCorrectChild = true;
		}
		iChildCount++;
	}
}

function initialiseMarkets()
{
	populateTreeLevel(1, 0, "bodyMarketManagementNavigationToday");
	populateTreeLevel(1, 0, "bodyMarketManagementNavigationFuture");
	
	
	// move somewhere else.. this will do for now
	populateCalander();
	showQueryMarket();
}

function showTodaysMarket()
{
	$("tabToday").className = "active";
	$("tabFuture").className = "inactive";
	$("tabQuery").className = "inactive";
	$("bodyMarketManagementNavigationToday").style.visibility = "visible";
	$("bodyMarketManagementNavigationFuture").style.visibility = "hidden";
	$("bodyMarketManagementNavigationQuery").style.visibility = "hidden";
}

function showFutureMarket()
{
	$("tabToday").className = "inactive";
	$("tabFuture").className = "active";
	$("tabQuery").className = "inactive";
	$("bodyMarketManagementNavigationToday").style.visibility = "hidden";
	$("bodyMarketManagementNavigationFuture").style.visibility = "visible";
	$("bodyMarketManagementNavigationQuery").style.visibility = "hidden";
}

function showQueryMarket()
{
	$("tabToday").className = "inactive";
	$("tabFuture").className = "inactive";
	$("tabQuery").className = "active";
	$("bodyMarketManagementNavigationToday").style.visibility = "hidden";
	$("bodyMarketManagementNavigationFuture").style.visibility = "hidden";
	$("bodyMarketManagementNavigationQuery").style.visibility = "visible";
}

function getStatusColour(iStatus)
{
	var sStatusColour = ""
	switch(iStatus)
	{
		case 1: // active/open
			sStatusColour = "green";
			break;
		case 2: // inactive
			sStatusColour = "";
			break;
		case 3: // settled/graded
			sStatusColour = "red";
			break;
		case 4: // voided
			sStatusColour = "black";
			break;
		case 6: // suspended
			sStatusColour = "amber";
			break;
		case 8: // closed
			sStatusColour = "blue";
			break;
	}
	return sStatusColour;
}

function getStatus(iStatus)
{
	var sStatus = ""
	switch(iStatus)
	{
		case STATUS_ACTIVE: // active/open
			sStatus = "Active";
			break;
		case STATUS_INACTIVE: // inactive
			sStatus = "Inactive";
			break;
		case STATUS_SETTLED: // settled/graded
			sStatus = "Settled";
			break;
		case STATUS_VOIDED: // voided
			sStatus = "Void";
			break;
		case STATUS_SUSPENDED: // suspended
			sStatus = "Suspended";
			break;
		case STATUS_PENDING: // pending
			sStatus = "Pending";
			break;
		case STATUS_CLOSED: // closed
			sStatus = "Closed";
			break;
		case STATUS_SCRATCHED: // scratched
			sStatus = "Scratched";
			break;
	}
	return sStatus;
}


function getMarketDateFilterCode(sMarketTab)
{
	var iMarketDateFilterCode = 0;
	switch(sMarketTab)
	{
		case "bodyMarketManagementNavigationToday":
		{
			iMarketDateFilterCode = 0;
			break;
		}
		case "bodyMarketManagementNavigationFuture":
		{
			iMarketDateFilterCode = 1;
			break;
		}
		case "bodyMarketManagementNavigationQueryMarket":
		{
			iMarketDateFilterCode = 2;
			break;
		}
	}
	//
	//iMarketDateFilterCode = 2;
	//
	return iMarketDateFilterCode;
}

function hasDetailBeenShown(iTreeParentId)
{
    /*
	 * function: hasDetailBeenShown
	 * purpose: Checks to see if a detail level is already in display or not
	 * params: iParentId
	 * returns: boolean
	 */
	 
	var bShown = false;
	
	var oParentNode = $("bodyMarketManagementDetail") 
	var iChildNodeCount = oParentNode.childNodes.length;
	var iCount = 0;
	
	while((bShown === false) && (iCount < iChildNodeCount))
	{
		oChild = oParentNode.childNodes[iCount];
		iCount++;
		if(parseInt(oChild.treeParentId) === iTreeParentId)
		{				
			bShown = true;
		}
	}
	return bShown;
}

function scrollToDetail(iTreeParentId)
{
    /*
	 * function: scrollToDetail
	 * purpose: Finds a detail frame, and moves the browser to it
	 * params: iTreeParentId
	 * returns: none
	 */
	
	var bFoundChild = false;
	var oParentNode = $("bodyMarketManagementDetail"); 
	var iChildNodeCount = oParentNode.childNodes.length;
	var iCount = 0;
	
	while((bFoundChild === false) && (iCount < iChildNodeCount))
	{
		oChild = oParentNode.childNodes[iCount];
		iCount++;
		if(parseInt(oChild.treeParentId) === iTreeParentId)
		{		
			bFoundChild = true;
			document.location.href = "#" + oChild.id;
		}
	}
}
/************************************************* Query Tab Stuff *************************************************/

function populateCalander()
{
	var oTable = generateCalander()
	renderCalander(oTable);
}

function generateCalander()
{
	var aDays = new Array("S","M","T","W","T","F","S");
	var aMonths = new Array("January","Febuary","March","April","May","June","July","August","September","October","November","December");
	
	var MAX_COLUMNS = 7;
	var MAX_ROWS = 8;
	var oTable = document.createElement("table")
	oTable.className = "calanderTable";
	
	var oThead = document.createElement("thead");
	var oTbody = document.createElement("tbody");
	
	// time stuff
	var oDate = new Date();
	oDate.setFullYear(m_iYear, m_iMonth, m_iDay);
	var bStartedDays  = false;
	var iDayCount = 0;
	
	//var daysInMonth = (32 - new Date(2007, 0, 32).getDate());

	var dDate = new Date(m_iYear, m_iMonth+1, 0);
	var daysInMonth = dDate.getDate();

	for(var i = 0; i < MAX_ROWS; i++)
	{
		var oTr = document.createElement("tr");

		switch(i)
		{
			case 0:
			{		
			
				var oThLeft = document.createElement("th");
				var oButtonLeft = document.createElement("button");
				var oButtonLeftText = document.createTextNode("<");
				oButtonLeft.appendChild(oButtonLeftText);
				oButtonLeft.onclick =  function ()
										{
											changeMonth(-1);
										}
				oThLeft.appendChild(oButtonLeft);
				oTr.appendChild(oThLeft);
				
				var oThCentre = document.createElement("th");
				oThCentre.colSpan = MAX_COLUMNS-2;
				var oThTextCentre = document.createTextNode(aMonths[oDate.getMonth()] + ", " + oDate.getFullYear());
				oThCentre.appendChild(oThTextCentre);
				oTr.appendChild(oThCentre);
				
				var oThRight = document.createElement("th");
				var oButtonRight = document.createElement("button");
				var oButtonRightText = document.createTextNode(">");
				oButtonRight.appendChild(oButtonRightText);
				oButtonRight.onclick =  function ()
										{
											changeMonth(1);
										}
				oThRight.appendChild(oButtonRight);
				oTr.appendChild(oThRight);
				
				oThead.appendChild(oTr);
				break;
			}
			case 1:
			{
				for(var j = 0; j < MAX_COLUMNS; j++)
				{
					var oTh = document.createElement("th");
					var oThText = document.createTextNode(aDays[j]);
					oTh.appendChild(oThText);
					oTr.appendChild(oTh);
					oTr.className = "days";
				}
				oThead.appendChild(oTr);
				break;
			}
			default:
			{
				for(var j = 0; j < MAX_COLUMNS; j++)
				{
					var oTd = document.createElement("td");
					if(bStartedDays === false)
					{
						var oTdText = document.createTextNode("");
						if(parseInt(oDate.getDay()) === j)
						{
							bStartedDays = true;
							var oTdText = document.createTextNode(iDayCount+1);
							oTd.onmouseover = function ()
												{
													this.className = "hover";
												}
												
							oTd.onmouseout = function ()
												{
													if(this.active!== "true")
													{
														
														this.className = null;
													}
												}
							oTd.onclick = function ()
												{
													//this.className = "active";
													var sMonth = new String(m_iMonth + 1);
													var sDay = new String(this.childNodes[0].nodeValue);
													
													if(sMonth.length === 1)
													{
														sMonth = "0" + sMonth;
													}
													
													if(sDay.length === 1)
													{
														sDay = "0" + sDay;
													}
													
													m_sDate = m_iYear + "-" + sMonth + "-" + sDay;
													populateTreeLevel(1, 0, "bodyMarketManagementNavigationQueryMarket");
												}
							iDayCount++;
						}
					}
					else
					{
						if((iDayCount) < daysInMonth)
						{
							var oTdText = document.createTextNode(iDayCount+1);
							
							oTd.onmouseover = function ()
												{
													this.className = "hover";
												}
												
							oTd.onmouseout = function ()
												{
													this.className = null;
												}
							oTd.onclick = function ()
												{
													/*var oParent = this.parentNode;
													for(var k = 0; k < oParent.childNodes.length; k++)
													{
														var oChild = oParent.childNodes[k];
														
														if((oChild.tagName === "TD") && (oChild.active === "true"))
														{
															alert("ok");
															oChild.active = false;
															this.className = null;
														}
													}
													
													this.active = true;
													this.className = "active";*/
													
													var sMonth = new String(m_iMonth + 1);
													var sDay = new String(this.childNodes[0].nodeValue);
													
													if(sMonth.length === 1)
													{
														sMonth = "0" + sMonth;
													}
													
													if(sDay.length === 1)
													{
														sDay = "0" + sDay;
													}
													
													m_sDate = m_iYear + "-" + sMonth + "-" + sDay;
													
													populateTreeLevel(1, 0, "bodyMarketManagementNavigationQueryMarket");
												}
						}
						else
						{
							var oTdText = document.createTextNode("");
						}
						iDayCount++;
					}
					
					oTd.appendChild(oTdText);
					oTr.appendChild(oTd);
				}
				oTbody.appendChild(oTr);
				break;
			}
			
		} // end switch
	} // end for i
	
	oTable.appendChild(oThead);
	oTable.appendChild(oTbody);
	return oTable;
}

function changeMonth(iChangeAmount)
{
	if(iChangeAmount === -1)
	{
		if(m_iMonth > 0)
		{
			m_iMonth--;
		}
		else
		{
			if(m_iMonth === 0)
			{
				m_iMonth = 11;
				m_iYear--;
			}
		}
	}
	else
	{
		if(iChangeAmount = 1)
		{
			if(m_iMonth < 11)
			{
				m_iMonth++;
			}
			else
			{
				if(m_iMonth === 11)
				{
					m_iMonth = 0;
					m_iYear++;
				}
			}
		}
	}
	
	populateCalander();
}

function renderCalander(oTable)
{
	var oCalanderDiv = $("bodyMarketManagementNavigationQueryCalander");
	// just for testing
	// change this to a proper clean and remove.
	oCalanderDiv.innerHTML = "";
	oCalanderDiv.appendChild(oTable);
}

/************************************************* Real Time / Alarms *************************************************/

function doRealTime()
{
	/*
	 * function: doRealTime()
	 * purpose: Does real time monitoring on next 15 mins of events.
	 * params: none
	 * returns: none
	 */
	
	
	doRequestRealTime();
	doRequestAlarms();
	doRequestEvents();
}

function doRequestRealTime()
{
	requestRealTime(); // rename the realTime functions to eliminate confusion.
	setTimeout("doRequestRealTime();", 60000);
}

function doRequestAlarms()
{
	requestAlarms();
	setTimeout("doRequestAlarms();", 2000);
}

function doRequestEvents()
{
	requestEvents();
	setTimeout("doRequestEvents();", 60000);
}


function requestRealTime()
{
	/*
	 * function: requestRealTime()
	 * purpose: Requests real time event information through Ajax.
	 * params: none
	 * returns: none
	 */
	
	// how many events do we want - this case 4 columns of 4 LI elements = 16
	var sParams = "eventCount=16";
	// AJAX request is for events.
	m_iCurrentRequestId = 3;
	ajaxRequest("php/getRealTime.php", sParams, processRealTime);
}

function requestAlarms()
{
	/*
	 * function: requestAlarms()
	 * purpose: Requests alarms through Ajax.
	 * params: none
	 * returns: none
	 */
	
	// list of the lineNavs we are in charge of.
	var sParams = "1011, 1012, 1012";
	// AJAX request is for alarms.
	m_iCurrentRequestId = 2;
	ajaxRequest("php/getAlarms.php", sParams, processAlarms);
}

function requestEvents()
{
    /*
	 * function: requestEvents()
	 * purpose: Requests next event information through Ajax.
	 * params: none
	 * returns: none
	 */
	
	// how many events to return.
	var sParams = "eventCount=20";
	// AJAX request is for events.
	m_iCurrentRequestId = 4;
	ajaxRequest("php/getEvents.php", sParams, processEvents);
}

function processAlarms(oResponse)
{
	/*
	 * function: processAlarms()
	 * purpose: Processes alarms and then requests again.
	 * params: sAlarms - the delimited string containing alarm information.
	 * returns: none
	 */
	
	var sAlarms = oResponse.responseText
	
	var bFound = false;
	//we know that there is a change in one of the
	//last 12 events... update its class
	
	var aAlarms = unpackIt(sAlarms);
	
	// remove the message info - not using here just now
	var sGeneric = aAlarms.shift();
	
	var sGeneric2 = aAlarms.shift();
	
	// shift off any alarms which are over 15 mins old
	updateAlarms();
	
	// store any new alarms
	storeAlarms(aAlarms);
	
	// show any current alarms to the user/browser
	showAlarmLineOwners();
}

function updateAlarms()
{
	// this will filter alarms that are 15 minutes old
}

function storeAlarms(aAlarms)
{	
	// for each alarm recieved
	for(var i = 0; i < aAlarms.length; i++)
	{
		// create an alarm object and set its properties
		var oAlarm = new Object();
		oAlarm.lineName = aAlarms[i][0];
		oAlarm.lineRef = aAlarms[i][1];
		oAlarm.lineOwnerRef = aAlarms[i][2];
		oAlarm.lineOwnerName = aAlarms[i][3];
		oAlarm.lineNavTop = aAlarms[i][4];
		oAlarm.lineNavName = aAlarms[i][5];
		oAlarm.lastUpdate = aAlarms[i][6];
		oAlarm.alarmRecieved = aAlarms[i][7];
		oAlarm.active = true;
		
		// if we have alarms then
		if(m_aAlarms.length > 0)
		{
			var bFoundAlarm = false;
			// for each alarm we have stored
			for(var j = 0; j < m_aAlarms.length; j++)
			{
				// retrieve alarm
				oStoredAlarm = m_aAlarms[j];
				// if this stored alarm is the same as the one we are checking
				if((parseInt(oStoredAlarm.lineRef) === oAlarm.lineRef) && (oStoredAlarm.lastUpdate === oAlarm.lastUpdate))
				{
					// set the flag to say we have already dealt with this alarm
					bFoundAlarm = true;
					break;
				}
			}
			// if we never found this alarm stored
			if(bFoundAlarm === false)
			{
				//debug("adding another alarm");
				// store it
				m_aAlarms.push(oAlarm);
			}
		}
		// if we have no alarms.. just add it. no checking required
		else
		{
			m_aAlarms.push(oAlarm);
		}
	}	
}

function showAlarmLineOwners()
{	
	// go through each of our alarms
	for(var i = 0; i < m_aAlarms.length; i++)
	{
		// set to false for each alarm
		var bFound = false;
		oStoredAlarm = m_aAlarms[i];
		// go through each real time column
		for(var j = 0; j < 4; j++)
		{
			// get the current column
			var oDiv = $("containerHeaderRealTimeContentColumn" + (j+1));
			// check the first child is an unordered list.
			if(oDiv.firstChild.tagName === "UL")
			{
				// get the unordered list
				var oUnorderedList = oDiv.firstChild;

				// go through each child in the unordered list
				for(var k = 0; k < oUnorderedList.childNodes.length; k++)
				{
					// if the child is a list item
					if(oUnorderedList.childNodes[k].tagName === "LI")
					{
						// get the list item
						var oListItem = oUnorderedList.childNodes[k];
						// if the list item's lineOwnerRef matches the alarm's
						if(oListItem.lineOwnerRef === oStoredAlarm.lineOwnerRef)
						{
							// then we need to alarm it.
							var oAnchor = oListItem.firstChild;
							oAnchor.className = "alarmed";
							// set the flag to say we have found
							bFound = true;
						}				
					} // end if === LI
					
					// we dont need to look through any more elements
					// so we can break this loop
					if(bFound === true)
					{
						break;
					}
						
				} // end for k (each li)
			} // end if === UL
			
			// we dont need to look through any more columns
			// so we can break this loop
			if(bFound === true)
			{
				break;
			}
		} // end for j (each column)
	} // end for i (each alarm)
}

function showAlarmLines(iLineOwnerRef)
{
	for(var i = 0; i < m_aAlarms.length; i++)
	{
		
		// set to false for each alarm
		oStoredAlarm = m_aAlarms[i];
		if(parseInt(oStoredAlarm.lineOwnerRef) === iLineOwnerRef)
		{
			var aDiv = document.getElementsByTagName("div")
			// for each div on the page
			var iLength = aDiv.length;
			for(var j = 0; j < iLength; j++)
			{
				// if the div has a lineOwnerRef, and it matches
				// ours, then this is the one we want.
				if(parseInt(aDiv[j].lineOwnerRef) === iLineOwnerRef)
				{
					// traverse the tree
					
					var oDiv2 = aDiv[j].childNodes[1];
					var oForm = oDiv2.childNodes[0];
					
					var oTable = oForm.childNodes[0];	
					var oTbody = oTable.childNodes[0];
					
					// for each row in the table body
					for(var k = 0; k < oTbody.childNodes.length; k++)
					{
						// get the row
						oTableRow = oTbody.childNodes[k];
						// if the row's lineRef matches the alarms
						if(oTableRow.lineRef === oStoredAlarm.lineRef)
						{
							// modify the style so to indicate that its alarmed.
							oTableRow.className = "alarmed";
						}
					}
				}
			}
		}
	}
}

function processRealTime(oResponse)
{
	/*
	 * function: processRealTime()
	 * purpose: Processes realtime on events.
	 * params: sRealTime - the delimited string containing real time information.
	 * returns: none
	 */
	
	var sRealTime = oResponse.responseText;
	
	var aRealTime = unpackIt(sRealTime);
	
	// remove the message info - not using here just now
	var sGeneric = aRealTime.shift();
	
	var sGeneric2 = aRealTime.shift();
	
	if(aRealTime.length > 0)
	{
		var aRealTimeDOM = generateRealTimeDOM(aRealTime);
		renderRealTime(aRealTimeDOM);
	}
	else
	{
		//alert("Problem processing RealTime request");
	}
}

function processEvents(oResponse)
{
	/*
	 * function: processEvents()
	 * purpose: Processes next events.
	 * params: sEvents - the delimited string containing event information.
	 * returns: none
	 */
	
	var sEvents = oResponse.responseText;
	
	var aEvents = unpackIt(sEvents);
	
	// remove the message info - not using here just now
	var sGeneric = aEvents.shift();
	
	var sGeneric2 = aEvents.shift();
	
	if(aEvents.length > 0)
	{
		var oEventsDOM = generateEventsDOM(aEvents);
		renderEventsDOM(oEventsDOM);
	}
	else
	{
		//alert("Problem processing events request");
	}
}

function generateRealTimeDOM(aRealTime)
{
	/*
	 * function: generateRealTimeDOM()
	 * purpose: Generates 4x4 array containing 4 rows of 4 DOM trees,
	 *			one for each column in the real time space.
	 * params: aRealTime - array of columns and rows
	 * returns: aDOMArray
	 */
	 
	// this needs to be fixed!!!!!
	
	var MAX_COL = Math.ceil(aRealTime.length  / 4);
	var aRealTimeDOM = new Array(MAX_COL);
	for(var i = 0; i < MAX_COL; i++)
	{
		aRealTimeDOM[i] = document.createElement("ul");
	}
	
	for(var i = 0; i < aRealTime.length; i++)
	{
		var iCol = Math.ceil((i + 1) / 4);
		var oAnchor;
		var oListItem;
		var oAnchorText;
		
		oAnchor = document.createElement("a");
		
		oAnchorText = document.createTextNode(aRealTime[i][1] + " - " + aRealTime[i][0]);
		oAnchor.appendChild(oAnchorText);
		oAnchor.href = "#";
		oAnchor.onclick = function ()
							{
								contractTodaysMarket();
								populateTreeLevel(2, this.parentNode.lineNavSportRef,"bodyMarketManagementNavigationToday");
								populateTreeLevel(3, this.parentNode.lineNavRef,"bodyMarketManagementNavigationToday");
								populateTreeLevel(4, this.parentNode.lineOwnerRef,"bodyMarketManagementNavigationToday");
								m_bViewAlarms = true;
							}

		oListItem = document.createElement("li");
		oListItem.appendChild(oAnchor);
		oListItem.lineOwnerRef = aRealTime[i][2];
		oListItem.lineNavRef = aRealTime[i][3];
		oListItem.lineNavSportRef = aRealTime[i][4];
		
		aRealTimeDOM[iCol-1].appendChild(oListItem);
	}
	return aRealTimeDOM;
}

function renderRealTime(aRealTimeDOM)
{
	for(var i = 0; i < 4; i++)
	{
		var oParent = $("containerHeaderRealTimeContentColumn" + (i+1));

		if(oParent.firstChild)
		{
			cleanAllChildren(oParent.firstChild);
			oParent.removeChild(oParent.firstChild);
		}
		
		oParent.appendChild(aRealTimeDOM[i]);
	}
}

function generateEventsDOM(aEvents)
{
	/*
	 * function: generateEventsDOM()
	 * purpose: Generates an array containing a DOM tree for the times
	 			and a DOM tree for the events. Both will be unordered lists
	 * params: aEvents - array of columns and rows
	 * returns: aEventsDOM - 2 element array or DOM trees
	 */
	 
	 // we only want to elements in the array.
	 var aEventsDOM = new Array(2);
	 
	 // this is the list of times
	 var oUnorderedListTimes = document.createElement("ul");
	 var oListItemTime;
	 var oListItemTimeText;
	 
	 // this is the list of events
	 var oUnorderedListEvents = document.createElement("ul");
	 var oListItemEvent;
	 
	 /// this is the list of columns for each event
	 var oUnorderedListEventColumns;
	 var oListItemEventColumn;
	 var oListItemEventColumnText;
	 
	 for(var i = 0; i < aEvents.length; i++)
	 {	 	
	 	oListItemTime = document.createElement("li")
	 	oListItemTimeText = document.createTextNode(aEvents[i][0]);
	 	oListItemTime.appendChild(oListItemTimeText);
	 	oUnorderedListTimes.appendChild(oListItemTime);
	 	
	 	oListItemEvent = document.createElement("li")
	 	oListItemEvent.className = "event";
	 	//oListItemEventText = document.createTextNode();
	 	
		oUnorderedListEventColumns = document.createElement("ul");
		
	 	oListItemEventColumnText = document.createTextNode(aEvents[i][1]); // + " - " + aEvents[i][2]);
	 	oListItemEventColumn = document.createElement("li");
	 	oListItemEventColumn.className = "eventColumn";
	 	oListItemEventColumn.appendChild(oListItemEventColumnText);
	 	oUnorderedListEventColumns.appendChild(oListItemEventColumn);
	 	
	 	oListItemEventColumnText = document.createTextNode(aEvents[i][3]);
	 	oListItemEventColumn = document.createElement("li");
	 	oListItemEventColumn.className = "eventColumn";
	 	oListItemEventColumn.appendChild(oListItemEventColumnText);
	 	oUnorderedListEventColumns.appendChild(oListItemEventColumn);
	 	
	 	oListItemEventColumnText = document.createTextNode(aEvents[i][4]);
	 	oListItemEventColumn = document.createElement("li");
	 	oListItemEventColumn.className = "eventColumn";
	 	oListItemEventColumn.appendChild(oListItemEventColumnText);
	 	oUnorderedListEventColumns.appendChild(oListItemEventColumn);
	 	
	 	oUnorderedListEventColumns.className = "eventColumn";
	 	oListItemEvent.appendChild(oUnorderedListEventColumns);
	 	oUnorderedListEvents.appendChild(oListItemEvent);
	 	oUnorderedListEvents.className = "event";
	 }
	 
	 aEventsDOM[0] = oUnorderedListTimes;
	 aEventsDOM[1] = oUnorderedListEvents;

	 return(aEventsDOM);
}

function renderEventsDOM(aEventsDOM)
{
	/*
	 * function: renderEventsDOM()
	 * purpose: Renders the events DOM
	 * params: aEventsDOM - array containing time DOM and event DOM
	 * returns: none
	 */
	 
	var oTimesParent = $("bodyEventManagementContentTimes");
	var oEventsParent = $("bodyEventManagementContentEvents");
		
	// change to explicit check
	if(oTimesParent.firstChild)
	{
		cleanAllChildren(oTimesParent.firstChild);
		oTimesParent.removeChild(oTimesParent.firstChild);
	}
	
	oTimesParent.appendChild(aEventsDOM[0]);
	
	
	if(oEventsParent.firstChild)
	{
		cleanAllChildren(oEventsParent.firstChild);
		oEventsParent.removeChild(oEventsParent.firstChild);
	}
	
	oEventsParent.appendChild(aEventsDOM[1]);
}
/************************************************* Transaction logging/monitoring functions *************************************************/

function addTransaction(iLineOwnerRef, iLineRef)
{
	var oAlarm = new Object();
}


/************************************************* Update functions *************************************************/

function sendUpdateLines(iLineOwnerRef, sUpdateString)
{
	/*
	 * function: sendUpdateLines()
	 * purpose: 
	 * params:
	 * returns: none
	 */
	
	// how many events to return.
	var sParams = "sUpdateString=" + sUpdateString;
	sParams += "&iLineOwnerRef=" + iLineOwnerRef;
	
	// AJAX request is for a line update.
	m_iCurrentRequestId = 5;
	ajaxRequest("php/updateLines.php", sParams, processLineUpdateResponse);
	//debug(sParams);
}

function processLineUpdateResponse(oResponse)
{
	var sResponse = oResponse.responseText;
	
	// we want to send better information back.
	// list of successfull and failed lines {1001|true}|{1002|false}

	var aResponse = sResponse.split("|");
	//var sMessage = aResponse[0];
	var sStatus = aResponse.shift();
		// get any generic information about the rest of the information.
	var sMessage = aResponse.shift();
		
	var iLineOwnerRef = parseInt(aResponse.shift());
	
	var iChecksum = parseInt(aResponse.pop());
	
	// write a new function to update on the fly... as removing and adding sticks it to the
	// bottom of the current list of market details.	
	closeMarketDetail(iLineOwnerRef);
	populateTreeLevel(4, iLineOwnerRef,"bodyMarketManagementNavigationToday");
}

function updateLines(iLineOwnerRef)
{

	/*
	 * function: 
	 * purpose: 
	 * params: iLineOwnerRef - Integer
	 * returns: none
	 */
	
	// update string protocol >> line=lineRef{statusRef{param1{param2, 
	
	var sUpdateString = "";
 
	var oForms = document.forms;
	
	for(var i = 0; i < oForms.length; i++)
	{
		var oForm = oForms[i];
		
		if(parseInt(oForm.lineOwnerRef) === iLineOwnerRef)
		{
			
			// sending as unique param now
			//sUpdateString += iLineOwnerRef + "|";
			
			var oElements = oForm.elements;
			for(var j = 0; j < oElements.length; j++)
			{
				var oElement = oElements[j];
				var sType = oElement.type;
				if(sType === "select-one")
				{
					if(oElement.selectedIndex !== 0)
					{
						var iStatus = oElement.options[oElement.selectedIndex].status;
						if(iStatus === STATUS_SCRATCHED)
						{
							// no line ref set - fix this.
							sUpdateString += oElement.lineRef + "{" + iStatus + "{" + oElement.reductionOdds + "|";
						}
						else
						{
							sUpdateString += oElement.lineRef + "{" + iStatus + "|";
						}
					}
				}
			}
		}
	}
	
	if(sUpdateString !== "")
	{
		sUpdateString = sUpdateString.substring(0, sUpdateString.length - 1)
	}
	
	sendUpdateLines(iLineOwnerRef, sUpdateString);
}