/********************
File:  		general.js
Created:  	March 30, 2011
Purpose:    general javascript functions.

Modified:	
	1.	Dec 2011 (EDS) - copied over from OFP (but not implemented)
	2.	26 Jan 2011 (RPM) - renamed and made ready for TP use


This file is broken up into two sections:
	Section 1.  General functions common to both the Mobile and Full Website modes.  This section should be exactly the same
				as what is in the equivalent general_m.js file for the mobile mode.  Any edits to this section should also be
				made in general_m.js
	Section 2.  Functions that are specific to the Full Website mode			


Function list:

Section 1
	1.  sortTable
		1.a  getTextValue
		1.b  noramlizeString
		1.c  Sort
	2. 	toggleShowHide
	3.  showHide
	4.  showHideColumn
	5.  TextAreaLength
	6.  demoOnly
	7.  loadXMLDoc
	8.  isNumeric
	9.  matchup
	10. isDate
	11. getNumeric
	12. switchTab
	13. showhideswitchlinks
	14. flagKeywords
	15. trim, ltrim, rtrim
	16. myload (used as the body onload event)
	17.	formModified / canLeavePage  (used on setupWizard)
	18. togglenote

Section 2  (Full Website Only)
	1.  openMenu (for "hover" menus)
	2.	closeMenu
*/


/****************************************************************************************	
/* SECTION 1:  COMMON FUNCTIONS (Applicable to both MOBILE and FULL WEBSITE modes)  */	
/****************************************************************************************/
/*-----------------------------------------------------------------------------
	1.
	sortTable(id, col, rev, ranks, sortTypeFlag)

	id  - ID of the TABLE, TBODY, THEAD or TFOOT element to be sorted.
	col - Index of the column to sort, 0 = first column, 1 = second column,
        etc.
  rev - If true, the column is sorted in reverse (descending) order
        initially.
  ranks - If true, the "rank" is calculated and displayed in the first column.
  
  sortTypeFlag - (optional) Generally not used, this can be used to specify the 
  sort type. Currently there are only seven sort types defined: text, numeric, getFloat, 
  count, checkbox, input, and date. The getFloat type parses the table contents and returns
  the first floating point number it encounters, which can, of course, be an integer.
  The checkbox, input, and date types have limited use.  The date type assumes that the 
  date is in the format month day year (i.e., the  month followed by the day followed 
  by the year separated by a space) as on the roster.
  

 Note: the team name column (index 1) is used as a secondary sort column and
 always sorted in ascending order.
-----------------------------------------------------------------------------*/

function sortTable(id, col, rev, ranks, sortTypeFlag)
	{
		try 
			{
				// Create the table reference
				var tbl = document.getElementById(id)
				
				// Determine how many rows are in the table
				var noRows = tbl.rows.length
						
				// Create an array to track the sort direction for each column 
				if (typeof(sortDir) == 'undefined') {sortDir = new Array()}	
				
				// If this column has not been sorted before, set the initial sort direction to the direction specified.		
				if (sortDir[col] == null) {sortDir[col] = rev}
				
				// If this column was the last one sorted, reverse its sort direction
				if (typeof(lastCol) != 'undefined' && col == lastCol) {sortDir[col] = !sortDir[col]}
				
				// Record the last column sorted
				lastCol = col	
				
				// Declare a multi-dimensional array to hold the table data. Note that it would probably be more
				// efficient to declare and populate this table array only once. This could lead to problems in cases
				// when more than one table is present on a page.
				tableArray = new Array() 
				
				// Declare the table rows
				for (var i = 0; i < noRows; i ++) {tableArray[i] = new Array(2)}

				// Populate the table array with the contents of the HTML table using the gettext function
				for (i = 0; i < noRows; i++)
					{
						if (sortTypeFlag == "checkbox") {tableArray[i][0] = getCheckboxValue(tbl.rows[i].cells[col]);}
						else if (sortTypeFlag == "input") {tableArray[i][0] = getInputValue(tbl.rows[i].cells[col]);}
						else if (sortTypeFlag == "date") {tableArray[i][0] = getDateValue(getTextValue(tbl.rows[i].cells[col]));}
						else {tableArray[i][0] = getTextValue(tbl.rows[i].cells[col]);}
						tableArray[i][1] = i; // keep track of "where each row went"
					} // end for i
						
				// If a specific sortType is not provided, sort the array based on the current in-place table sort
				// implemenation. Since this technique requires data processing, we will perform this processing to the specified
				// search column in the table array before sorting the array.
				
				if (!sortTypeFlag) 
                    {
                   	// No sort type was provided; determine the sort type from the column date type
                    var sortTypeFlag = "numeric"
				    for (var i = 0; i < noRows; i ++) {if (isNaN(parseFloat(tableArray[i][0]))) {sortTypeFlag = "text"; break}} // at least one element was non-numeric}
                    } 
						
				// Update the data in the tableArray
				if (sortTypeFlag == "text") 
                    {for (var i = 0; i < noRows; i ++) {tableArray[i][0] = tableArray[i][0].toUpperCase()}}                    
				else if (sortTypeFlag == "count" || sortTypeFlag == "checkbox") 
                    {for (var i = 0; i < noRows; i ++) 
                        {
					tableArray[i][0] = parseInt(tableArray[i][0],10);    
                        	if (isNaN(tableArray[i][0])) {tableArray[i][0] = -1} // sort text last
                        }
                    } 
				else if (sortTypeFlag == "getFloat")
                    {for (var i = 0; i < noRows; i ++) 
                        {
					tableArray[i][0] = parseFloat(getNumeric(tableArray[i][0],false,"float"));    
                        	if (isNaN(tableArray[i][0])) 
						{
						if (rev) {tableArray[i][0] = -Infinity;} else {tableArray[i][0] = Infinity;} // sort text last						
						} 
                        }
                    } 				
				else {for (var i = 0; i < noRows; i ++) {tableArray[i][0] = parseFloat(tableArray[i][0])}}
									
				// Sort the tableArray		
				Sort(sortDir[col]) // tableArray is global	
					
				// Adjust the ranks if requested
				if (ranks) 					
					{	
						// Declare a temporary array to store the ranks
						var rankArray = new Array(noRows)
						
						if (sortDir[col] == rev)
							{
								rankArray[0] = 1
								for (i = 1; i < noRows; i++)
									{
										if (tableArray[i][0] != tableArray[i-1][0]) {rankArray[i] = i+1}
										else {rankArray[i] = rankArray[i-1]}
									} // end i-loop 								
							} // end if
						else
							{
								rankArray[noRows-1] = 1
								for (i = noRows-2; i >= 0; i--)
									{
										if (tableArray[i][0] != tableArray[i+1][0]) {rankArray[i] = noRows-i}
										else {rankArray[i] = rankArray[i+1]}
									} // end i-loop 
							} // end else
					} // end if ranks == "true"				

				// Repopulate original HTML based on the position change of rows in the tableArray
				for (i = 0; i < noRows; i++)
					{removeRowID = tableArray[i][1]
						for (j = i; j < noRows; j++) {if (removeRowID > tableArray[j][1]){tableArray[j][1]++}}
						if (i != removeRowID) 
							{	
								tmpRow = tbl.removeChild(tbl.rows[removeRowID]); // this is the row we wish to delete and place below
								tbl.insertBefore(tmpRow,tbl.rows[i])
							}			
					} // end i-loop
					
				// Add ranks
				if (ranks)
					{
						for (i = 0; i < noRows; i++)
							{
								while (tbl.rows[i].cells[0].lastChild != null) {tbl.rows[i].cells[0].removeChild(tbl.rows[i].cells[0].lastChild)}
								tbl.rows[i].cells[0].appendChild(document.createTextNode(rankArray[i]));									
							} // end i-loop
					}							
			} // end try
		catch (er)
			{
			} // end catch
			
	return false
	} // end function sortTable

function getTextValue(el) {

  var i;
  var s;

	// This code is necessary for browsers that don't reflect the DOM constants
	// (like IE).
	if (document.ELEMENT_NODE == null) 
		{
  		document.ELEMENT_NODE = 1;
  		document.TEXT_NODE = 3;
		}

  // Find and concatenate the values of all text nodes contained within the
  // element.
  s = "";
  for (i = 0; i < el.childNodes.length; i++)
    if (el.childNodes[i].nodeType == document.TEXT_NODE)
      s += el.childNodes[i].nodeValue;
    else if (el.childNodes[i].nodeType == document.ELEMENT_NODE &&
             el.childNodes[i].tagName == "BR")
      s += " ";
    else
      // Use recursion to get text within sub-elements.
      s += getTextValue(el.childNodes[i]);

  return normalizeString(s);
}

function getCheckboxValue(el) {
	var checked = 0;
	if (el.childNodes.length == 1) {
		if (el.childNodes[0]) {
		//checked = el.childNodes[0].getAttribute("value")	
		if (el.childNodes[0].checked) {checked = 1}
		}
	}
	return checked;	
}

function getInputValue(el) {
	var value = 0;
	if (el.childNodes.length == 1) {
		if (el.childNodes[0]) {
		value = el.childNodes[0].getAttribute("value")	
		}
	}
	return value;	
}

function getDateValue(str) {
	str = str.replace("AM"," AM");
	str = str.replace("PM"," PM");	
	
	// Try to create a valid date
	var dateObj = new Date(str);
	if (isDate(dateObj)) {return dateObj.getTime();}
	else return 0;
}

// Regular expressions for normalizing white space.
var whtSpEnds = new RegExp("^\\s*|\\s*$", "g");
var whtSpMult = new RegExp("\\s\\s+", "g");

function normalizeString(s) 
	{
		// Regular expressions for normalizing white space.
		var whtSpEnds = new RegExp("^\\s*|\\s*$", "g");
		var whtSpMult = new RegExp("\\s\\s+", "g");
  	s = s.replace(whtSpMult, " ");  // Collapse any multiple whites space.
  	s = s.replace(whtSpEnds, "");   // Remove leading or trailing white space.
	  return s;
	}

function Sort(dir) 
	{
			// Sort the array
			if (!dir) {tableArray = merge_sort(tableArray,SortA)}
			else {tableArray = merge_sort(tableArray,SortD)}
				
			function merge(left,right,comparison)
				{
					var result = new Array();
					while((left.length > 0) && (right.length > 0))
						{
							if(comparison(left[0],right[0]) <= 0)
								{result.push(left.shift())}
							else
								{result.push(right.shift())}
						} // end while		
					while(left.length > 0) {result.push(left.shift())}
					while(right.length > 0) {result.push(right.shift())}
					return result;
				} // end function merge


			function merge_sort(array,comparison)
				{
					if(array.length < 2) {return array}
					var middle = Math.ceil(array.length/2);
					return merge(merge_sort(array.slice(0,middle),comparison), merge_sort(array.slice(middle),comparison), comparison);
				}	// end function merge_sort

			function SortA(x1,x2) {if (x1[0] == x2[0]) return 0; if (x1[0] > x2[0]) return 1; return -1}
			function SortD(x1,x2) {if (x1[0] == x2[0]) return 0; if (x1[0] < x2[0]) return 1; return -1}

	} // end function Sort


/*------------------
	2.
	toggleShowHide
--------------------*/	
function toggleShowHide(myid,showMsg,hideMsg) {
	// Used to "show" or "hide" a div.  Used
	// in conjunction with the "shFilter" and "shInstr" id's
	//
	
	if (myid == "filter") {
		var id = "shFilter";
		var toggleId = "shTogFilter";
		}
	else if (myid == "ColSettings") {
		var id = "shColSets";
		var toggleId = "shTogColSets";
		}		
	else if (myid == "lcGamesToday") {
		var id = "lcGamesToday";
		var toggleId = "shTogGamesToday";
		}		
	else if (myid == "realNames") {
		var id = "shRealNames";
		var toggleId = "shTogRealNames";
		}		
	else {  // default to myid = 'instructions'
		var id = "shInstr";
		var toggleId = "shTogInstr";
		}
	
	var divEl = document.getElementById(id);
	var aEl = document.getElementById(toggleId);
	
	if (divEl.className == "hidden") {
		divEl.className = "";
		aEl.innerHTML = hideMsg;
		}
	else {
		divEl.className = "hidden";
		aEl.innerHTML = showMsg;
		}

	//	return false;
}

function showHide(myid) {
	// Used to "show" or "hide" a div based on checking a box. 
		
	var divEl = document.getElementById(myid);
	
	if (divEl.className == "hidden") {
		divEl.className = "";
		}
	else {
		divEl.className = "hidden";
		}

	//	return false;
}
function showHideColumn(tableid,toggleid,colClass,showMsg,hideMsg) {
	// Used to "show" or "hide" a column in a table
	//
	// tableid:  id of the table
	// toggleid:  id of the anchor that acts as the toggle switch
	// colClass:  the class of the column (th and td's) that are to be hidden
	// showMsg:  the "show" link text for the toggle (e.g. "Show Real Names")
	// hideMsg:  the "hide" link text for the toggle (e.g. "Hide Real Names")
	
	
	var myToggle = document.getElementById(toggleid);

	var myTable = document.getElementById(tableid);
	var myHeaders = myTable.getElementsByTagName('TH');
	var myCells = myTable.getElementsByTagName('TD');
		
	for (i=1; i<myHeaders.length; i++)
	if (myHeaders[i].className == colClass + " hidden") {
		myHeaders[i].className = colClass;
		}
	else if (myHeaders[i].className == colClass){
		myHeaders[i].className = colClass + " hidden";
		
		}

	for (i=1; i<myCells.length; i++)
	if (myCells[i].className == colClass + " hidden") {
		myCells[i].className = colClass;
		}
	else if (myCells[i].className == colClass) {
		myCells[i].className = colClass + " hidden";
		}
	
	if (myToggle.innerHTML == hideMsg)
		myToggle.innerHTML = showMsg;
	else 
		myToggle.innerHTML = hideMsg;
		
	var standingsHeader = document.getElementById('standingsHeader');
	
	if (standingsHeader) {
		if (myToggle.innerHTML == hideMsg)
			standingsHeader.colSpan = standingsHeader.colSpan + 1;
		else 
			standingsHeader.colSpan = standingsHeader.colSpan - 1;
		}
	//	return false;
}

function textAreaLength(textbox,maxlength,countID) {
		var mylen = textbox.value.length;
		if (mylen > maxlength) {
			textbox.value = textbox.value.substring(0,maxlength);
			mylen = mbox.value.length;
		 }
		if (mylen > 0.9 * maxlength) {
		document.getElementById(countID).className = 'alert';
		document.getElementById(countID).innerHTML = mylen;
		} else {
		document.getElementById(countID).className = '';
		document.getElementById(countID).innerHTML = mylen;
		}
	}

function demoOnly(s) {
	if (!s || s == '') {
		alert('This page is for demonstration only.');
		}
	else
		{
		alert (s + '. This page is for demonstration only.');
		} 	
	}

/******************************************************
	7.  loadXMLDoc
******************************************************/
function loadXMLDoc(url)
{
	xmlhttp=null;
	if (window.XMLHttpRequest)
		{// code for IE7, Firefox, Mozilla, etc.
		xmlhttp=new XMLHttpRequest();
		}
	else if (window.ActiveXObject)
		{// code for IE5, IE6
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		  
	 if (xmlhttp!=null) 
	 	{

		  	xmlhttp.onreadystatechange=function() {onResponse(url)};
			xmlhttp.open("GET",url,true);	
			//xmlhttp.open("GET","sbProxy.cfm",true);		
			xmlhttp.setRequestHeader('Pragma', 'Cache-Control: no-cache, must-revalidate');
			xmlhttp.send(null);
	  	}
	 else
	 	{
		document.write("Your browser does not support XMLHTTP."); // changed to document.write to overwrite page
		}

}
	
/******************************************************
	7.  loadXMLDoc - "Post" version
******************************************************/
function loadXMLDocPost(url)
{
	xmlhttp=null;
	if (window.XMLHttpRequest)
		{// code for IE7, Firefox, Mozilla, etc.
		xmlhttp=new XMLHttpRequest();
		}
	else if (window.ActiveXObject)
		{// code for IE5, IE6
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		  
	 if (xmlhttp!=null) 
	 	{

		  	xmlhttp.onreadystatechange=function() {onResponse(url)};
			xmlhttp.open("POST",url,true);	
			//xmlhttp.open("GET","sbProxy.cfm",true);		
			xmlhttp.setRequestHeader('Pragma', 'Cache-Control: no-cache, must-revalidate');
			xmlhttp.send(null);
	  	}
	 else
	 	{
		document.write("Your browser does not support XMLHTTP."); // changed to document.write to overwrite page
		}

}
		


/**********************************************************
isNumeric
**********************************************************/

function isNumeric(n) {
  return !isNaN(parseFloat(n)) && isFinite(n);
}


/**********************************************************
matchup
**********************************************************/

function matchup(gameid) 
{
	//var r_window = window.open('research_window.cfm?g='+gameid,'Research','height=500,width=700,resizable,scrollbars,location');

	if (typeof(r_window) != "undefined")
		{if (r_window.closed == false) r_window.close();}
	
	r_window = window.open('research_window.cfm?g='+gameid,'Research','height=600,width=840,toolbar=0,menubar=0,resizable=1,scrollbars=1,location=0,directories=0,status=0');
}


/**********************************************************
isDate
**********************************************************/

function isDate(input)
{
  return (null != input) && !isNaN(input) && ("undefined" !== typeof input.getDate); 
}

/**********************************************************
getNumeric
**********************************************************/

function getNumeric(str,returnAll,type)
{
	if (returnAll) {var pattern = /[0-9.]+/g;}
	else {var pattern = /[0-9.-]+/;}
	var matches = str.match(pattern);
	// Return an empty string if no matches were found
	if (!matches) {return ""}
	// Else parse the string for 
	var retArray = new Array;
	if (type == "float") {for (i=0; i < matches.length; i++) {if (!isNaN(parseFloat(matches[i]))) {retArray.push(matches[i]);}}}
	else if (type = "integer") {for (i=0; i < matches.length; i++) {if (!isNaN(parseInt(matches[i],10))) {retArray.push(matches[i]);}}}
	return retArray;
}

/**********************************************************
switchTab
	Purpose:  works in conjuntion with the generic "tab" control
		(see pooladmin_filter for an example)
**********************************************************/

function switchTab(iTab) {

if (!window.myTabs) {
	// set the selected tab (hide the others)
	
	myTabPane = document.getElementById('tabPane');
	var myLinks=document.getElementsByTagName("A");
	j=0;
	myTabs = new Array;
	myTabPanes = new Array;
	for (i=0; i<myLinks.length; i++) {
	 	if (myLinks[i].name == "tab") {
			myTabs[j] = document.getElementById('tab_'+j);
			myTabPanes[j] = document.getElementById('tabPane_'+j);
			j++;
		}	
	}
	
}

for (i=0; i<myTabs.length; i++) { 
	if (i==iTab) {
		if(myTabs[i].className == 'tab selected') {
			myTabs[i].className = "tab";
			myTabPanes[i].className = "hidden";
			myTabPane.className = "tabpane hidden"
			}
		else { 
			myTabs[i].className = "tab selected";
			myTabPanes[i].className = "";
			myTabPane.className = "tabpane"
			}
	}
	else {
		myTabs[i].className = "tab";
		myTabPanes[i].className = "hidden";
	}
}

return false;
}


// show/hide toggle switch for the "my pools" and "my aliases" lists.
function showhideswitchlinks(id) { 
	theTable = document.getElementById(id);
	theRows = theTable.getElementsByTagName('tr');
	//alert ('here: ' + theRows.length + ' ' + theRows[1].className);
	
	if(theRows[1].className == 'hidden') { 
		for (i=1; i<=theRows.length - 1; i++) {theRows[i].className = '';}
		theRows[0].className = 'down';
		}
	else { 
		for (i=1; i<=theRows.length - 1; i++) theRows[i].className = 'hidden';
		theRows[0].className = 'right';
		}
	}

/*-----------------------------------------------------------------------------
	flagKeywords(id,textidentifier)

	id  - ID of the text field or text area to search
	textidentifier - The reference to the text field or text area; 
	                 e.g. Manager Note, message, etc.
-----------------------------------------------------------------------------*/


function flagKeywords(id,textidentifier) {
	var reg; 
	var idx; 
	var prohibitedWords = "";
	var retStr = "";
	
	var keywords = ['entry fee','payout','prize'];
	
	var str = document.getElementById(id).value;
	for (var i = 0; i < keywords.length; i++) {
		reg = new RegExp(keywords[i],"i");
		idx = str.search(reg);
		if (idx != -1) {
			if (prohibitedWords == "") {prohibitedWords = prohibitedWords + keywords[i];}
			else {prohibitedWords = prohibitedWords + ", " + keywords[i];}		
		}
	}
	if (str.search("\\\$") != -1) {
		if (prohibitedWords == "") {prohibitedWords = prohibitedWords + "$";}
		else {prohibitedWords = prohibitedWords + ", $";}
	}
	
	if (prohibitedWords.length > 0) {
		retStr = "Your " + textidentifier + " contains the following prohibited words or symbols: " + prohibitedWords + ".\n" 
	}
	return retStr;	
}

/*-----------------------------------------------------------------------------
	trim(string), ltrim(string), rtrim(string)

	string  - The string to be trimmed
-----------------------------------------------------------------------------*/
function trim(string) { // trim both left and right
	return string.replace(/^\s+|\s+$/g,"");
}

function ltrim(string) { // trim left only
	return string.replace(/^\s+/,"");
}

function rtrim(string) { // trim right only
	return string.replace(/\s+$/,"");
}
	
function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}	

/*-----------------------------------------------------------------------------
16.	myload function for the body onload event
-----------------------------------------------------------------------------*/

<!-- Original:  John Cranston  -->
<!-- Key Script:  Tim Khoury (twaks@yahoo.com) -->

function myload(a,b,c) {

if (a == 1) {placeFocus();}
if (b == 1) {replaceText();}
if (c == 1) {prefill();}

}  // end my load

	<!-- Original:  Tom Khoury  -->
	<!-- Begin 
	
function placeFocus() {
	// n is the field that you want blinking
	// basic login form, put the cursor in the first empty field
	if (document.forms.length > 0) {
		var myform = document.getElementById('loginform');
		var myReg = document.getElementById('regForm');
		if (myform != null && myReg == null) {
			var field = myform;
			for (i = 0; i < field.length; i++) {
				if ((field.elements[i].name == "username" || field.elements[i].name == "screen_name" || field.elements[i].name == 'poolid') && field.elements[i].value == '') {
					field.elements[i].focus();
					break; 
					}  
				else if ((field.elements[i].name == "password" || field.elements[i].name == "poolpassword") && field.elements[i].value == '') {
					field.elements[i].focus();
					//field.elements[i].style.background='cccc00';
					break;	
				}// end if 2
			   } // end for
			   } // end if
		} // end if 1
	} // end function
	//  End -->
	
function timeout() {
	setTimeout("sessionSaver();",600000); //
	}
		
function sessionSaver() 	{
	window.open('sessionSaver.cfm','OFP','height=100,width=350,resizable');
	return;
	}
	
function initialize() {
	return true;
	}	
	

/*-----------------------------------------------------------------------------
17.	formModified / canLeavePage
-----------------------------------------------------------------------------*/

  /**
   * Check if a form has changed
   */    
  function formModified(aForm)
  {                
      for (var i=0; i < aForm.elements.length; i++) {
          // get the form current element
          var curElement = aForm.elements[i];
          // get the current element type            
          var myType = curElement.type;
          // assume that the form is modified
          var valueChanged = true;
          
          if (myType == 'checkbox' || myType == 'radio') {
              // if both the checked state and the DefaultCheck state are equal
              if (curElement.checked == curElement.defaultChecked) {
                  valueChanged = false
              }                     
          } else if (myType == 'hidden' || myType == 'password' || myType == 'text' || myType == 'textarea') {
              // if the current text is the same as the default text i.e. the original in the
              // HTML Document
              if (curElement.value == curElement.defaultValue) {
                  valueChanged = false
              }
          } else if (myType == 'select-one' || myType == 'select-multiple') {
              for (var j=0;  j < curElement.options.length; j++) {
                  if (curElement.options[j].selected && curElement.options[j].defaultSelected) {
                      valueChanged = false
                  }
              }
          } else
              // unhandled type assume no change
              valueChanged = false;
                  
          // the previously checked element has changed
          if (valueChanged)
              return true;
      }

      // all elements have their default value
      return false;
  }

  function canLeavePage()
  {
    // Create a reference to the form
      var aForm = document.forms[0];
    
    // Verify that the form exists; if it does, check to see if changes were made
    if (typeof(aForm) != "undefined")
    {
      if (formModified(aForm) == false) {return true} // No changes were made to the form; return
      
      // Changes were made to the form; confirm with user
      return confirm('Are you sure you want to leave this page ?  Your changes have not been saved. \n\n' +
			   ' Click "Okay" to discard your changes and go to the next page or\n\n' +
			   ' Click "Cancel" to remain on this page, making sure to click the submit button\n' +
			   ' associated with the form below when you have finished.') ;
    }   
  }   

/*-----------------------------------------------------------------------------
18.	togglenote - show/hide function for the horizontal trash talk.
-----------------------------------------------------------------------------*/

function togglenote(note,action) {
	if (note == 'trash') {
		if (action == 'expand') {
			document.getElementById('trash_1').className = 'hidden';
			document.getElementById('trash_2').className = '';
			}
		else {
			document.getElementById('trash_1').className = '';
			document.getElementById('trash_2').className = 'hidden';
			}	
		}
	else {
		if (action == 'expand') {
			document.getElementById('mgr_1').className = 'hidden';
			document.getElementById('mgr_2').className = '';
			}
		else {
			document.getElementById('mgr_1').className = '';
			document.getElementById('mgr_2').className = 'hidden';
			}	
		}	
}
  
/****************************************************************************************	
/* SECTION 2:  FULL WEBSITE mode only                                                   */	
/****************************************************************************************/

	//open menu with given ID 
		function openMenu(menuID,linkObj)
		{
			//if the menu code is ready
			if(um.ready)
			{
				//find co-ordinates of link object
				var coords = {
					'x' : um.getRealPosition(linkObj,'x'),
					'y' : um.getRealPosition(linkObj,'y')
					};
					
				//increase y-position to place it below the link
				//coords.y += (linkObj.offsetHeight + 2);
				if (menuID == 'aliaslist' || menuID == 'poollist') {
					coords.x += (linkObj.offsetWidth + 2);
					coords.y += 10;
					}
				else {	coords.y += (linkObj.offsetHeight + 2);}

				//activate menu at returned co-ordinates
				um.activateMenu(menuID, coords.x + 'px', coords.y + 'px');
			}
		}
		
		//close menu with given ID
		function closeMenu(menuID)
		{
			//if the menu code is ready
			if(um.ready)
			{
				//deactive menu
				um.deactivateMenu(menuID);
			}
		}


