
<!--

function fnToggleEventsCalendar(nYear, nMonth)
{
	//alert("Year = " + nYear + " :: Month = " + nMonth);
	
	fnGetElementById("divEventsCalendar").innerHTML = "<img src='" + HOST_ROOT + "images/" + SKIN_ID + "/icons/loading_32x32.gif' alt='Loading...' />";
	
	//Initialise variables.
	var objAjax;
	var strURL;
	var strReturn = new String();

	//Create a new AJAX object.
	objAjax = fnGetNewAjax();
	
	if (objAjax)
	{
		objAjax.onreadystatechange =
			
		function()
		{
			if (objAjax.readyState == 4)
			{
				//Initialise variables.
				strReturn = Trim(objAjax.responseText);
				
				fnGetElementById("divEventsCalendar").innerHTML = strReturn;
			}
		}
		
		//Initialise variables.
		strURL = HOST_ROOT + "tools/getEventsCalendar.php?nMonth=" + nMonth + "&nYear=" + nYear;
		
		objAjax.open("GET", strURL, true);
		
		objAjax.send(null);
	}
}

function fnGetElementById(id)
{
	var object = null;
	
	if (document.layers)
	{
		object = document.layers[id];
	}
	else if (document.all)
	{
		object = document.all[id];
	}
	else if (document.getElementById)
	{
		object = document.getElementById(id);
	}
	
	return object;
}
  
function fnGetNewAjax()
{
	var objAjax;
	
	try
	{    
		//Firefox, Opera 8.0+, Safari    
		objAjax = new XMLHttpRequest();
	}
	catch (e)
	{   
		//Internet Explorer    
		try
		{    
			objAjax = new ActiveXObject("Msxml2.XMLHTTP"); 
		}
		catch (e)
		{   
			try
			{    
				objAjax = new ActiveXObject("Microsoft.XMLHTTP");   
			}
			catch (e)
			{     
				objAjax = false;
			}  
		} 
	}
	
	return(objAjax);
}

function fnToggleVenuesMenu(strSelectedTab)
{ 
	var objAjax = fnGetNewAjax();
	var strURL = HOST_ROOT + "venues_tab.php?strSelectedTab=" + strSelectedTab;
	
	if (objAjax)
	{
		/*
		objAjax.onreadystatechange =
			
			function()
			{
				if (objAjax.readyState == 4)
				{
					document.frmToggleVenuesMenu.time.value = objAjax.responseText;
				}
			}
		*/
			
		objAjax.open("GET", strURL, true);
		
		objAjax.send(null);
	}
}

//This function opens a new window, centered in the middle of the user's screen.
function fnOpenWindow(strURL, strID, nWidth, nHeight, bScrollbars, bToolbar, bResizable, bLocation, bDirectories, bMenubar, bStatus)
{
	//Initialise variables.
	var strFeatures = "";
	var strScrollbars = bScrollbars ? "yes" : "no";
	var strToolbar = bToolbar ? "yes" : "no";
	var strResizable = bResizable ? "yes" : "no";
	var strLocation = bLocation ? "yes" : "no";
	var strDirectories = bDirectories ? "yes" : "no";
	var strMenubar = bMenubar ? "yes" : "no";
	var strStatus = bStatus ? "yes" : "no";
	var nScreenWidth; var nScreenHeight; var nPosX; var nPosY;
	
	strFeatures += "scrollbars=" + strScrollbars + ", ";
	strFeatures += "toolbar=" + strToolbar + ", ";
	strFeatures += "resizable=" + strResizable + ", ";
	strFeatures += "location=" + strLocation + ", ";
	strFeatures += "directories=" + strDirectories + ", ";
	strFeatures += "menubar=" + strMenubar + ", ";
	strFeatures += "status=" + strStatus + ", ";
	strFeatures += "width=" + nWidth + ",innerWidth=" + nWidth;
	strFeatures += ",height=" + nHeight + ",innerHeight=" + nHeight;
	
	if (window.screen)
	{
		nScreenWidth = screen.availWidth;
		nScreenHeight = screen.availHeight;
		nPosX = parseInt((nScreenWidth - nWidth) / 2);
		nPosY = parseInt((nScreenHeight - nHeight) / 2);
		strFeatures += ",left=" + nPosX + ",screenX=" + nPosX;
		strFeatures += ",top=" + nPosY + ",screenY=" + nPosY;
	}
	
	//Open window.
	window.open(strURL, strID, strFeatures);
}

/*########################################################################################################
START Sort/Paging functions.
########################################################################################################*/
function fnSort(nUniqueID, strSortColumn, strSortOrder, nRowsPerPage, nPage, bToggleSortOrder, bSetRowsPerPagePreference)
{
	//alert("nUniqueID = " + nUniqueID + "\nstrSortColumn = " + strSortColumn + "\nstrSortOrder = " + strSortOrder + "\nnRowsPerPage = " + nRowsPerPage + "\nnPage = " + nPage + "\nbToggleSortOrder = " + bToggleSortOrder + "\nbSetRowsPerPagePreference = " + bSetRowsPerPagePreference);
	
	document.getElementById("hidSortColumn" + nUniqueID).value = strSortColumn;
	
	if (bToggleSortOrder == 1)
	{
    	document.getElementById("hidSortOrder" + nUniqueID).value = (strSortOrder == "ASC") ? "DESC" : "ASC";
	}
	else
	{
		document.getElementById("hidSortOrder" + nUniqueID).value = strSortOrder;
	}
	
	document.getElementById("hidRowsPerPage" + nUniqueID).value = nRowsPerPage;
	document.getElementById("hidPage" + nUniqueID).value = nPage;
	document.getElementById("hidSetRowsPerPagePreference" + nUniqueID).value = bSetRowsPerPagePreference;
	
	//alert("nUniqueID = " + nUniqueID + "\nstrSortColumn = " + strSortColumn + "\nstrSortOrder = " + strSortOrder + "\nnRowsPerPage = " + nRowsPerPage + "\nnPage = " + nPage + "\nbToggleSortOrder = " + bToggleSortOrder + "\nbSetRowsPerPagePreference = " + bSetRowsPerPagePreference);
	
	document.getElementById("frmSort" + nUniqueID).submit();
}
/*########################################################################################################
END Sort/Paging functions.
########################################################################################################*/


function fnURLEncode(strText)
{
	//Declare variables.
    var regString;
	
    if (typeof(strText) == "string")
	{
        if (strText != null)
		{
            regString = /(^\s+)|(\s+$)/g;
            strText = strText.replace(regString, "");
            for (nIndex = 32; nIndex < 256; nIndex++)
			{               
            	strText = strText.replace(String.fromCharCode(nIndex), escape(String.fromCharCode(nIndex)));                                                             
            }
        }
    }          
    return strText;
}

function fnDoOnKeyDown()
{
	if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13))
	{
		document.getElementById("frmLeftMenuSignIn").submit();
		return false;
	} 
    else
	{
		return true;
	}
}

function fnOpenWindow_sizeToImage(strImageURL, strWindowID, nWidth, nHeight)
{
	//Declare variables.
	var strHTML;
	var strFeatures;
	
	//Setup the "features" parameter of the window.open() method.
	strFeatures = "scrollbars=no, resizable=no, width=" + nWidth + ", innerWidth=" + nWidth;
	strFeatures+= ", height=" + nHeight + ", innerHeight=" + nHeight;
	
	//Center the window, if possible.
	if (window.screen)
	{
		var nScreenWidth = screen.availWidth;
		var nScreenHeight = screen.availHeight;
		var nPosX = parseInt((nScreenWidth - nWidth) / 2);
		var nPosY = parseInt((nScreenHeight - nHeight) / 2);
		strFeatures += ", left=" + nPosX + ", screenX=" + nPosX;
		strFeatures += ", top=" + nPosY + ", screenY=" + nPosY;
	}
	
	//Create the window object.
	objWindow = window.open("", "win" + strWindowID, strFeatures);

	//Setup the HTML string for the new window.
	strHTML = "";
	strHTML+= "<html>";
	strHTML+= "<head>";
	strHTML+= "<title>TIFM 2004 - Points & Position Graph</title>";
	strHTML+= "<scri" + "pt>";
	strHTML+= "if (!window.sizeToContent) {";
	strHTML+= "function sizeToContent(img) {\n"; 
	strHTML+= "x=img.width; y=img.height;\n";
	strHTML+= "window.resizeTo(x, y);}}";
	strHTML+= "</scr"+"ipt>";
	strHTML+= "</head>";
	strHTML+= "<body style='margin: 0px 0px 0px 0px;'>";
	strHTML+= "<img src=\"" + strImageURL + "\" border=\"0\" onload=\"sizeToContent(this);\" alt=\"\" />";
	strHTML+= "</body>";
	strHTML+= "</html>";
	
	//Output the HTML for the new window.
	objWindow.document.write(strHTML);
	
	//Close the document.
	objWindow.document.close();
}

function fnResizeToContents(strFrameName, bResizeWidth, bResizeHeight)
{
	if (bResizeWidth == 1)
	{
		var nWidth = document.getElementById(strFrameName).contentWindow.document.body.scrollWidth;
		document.getElementById(strFrameName).style.width = nWidth;
	}
	if (bResizeHeight == 1)
	{
		var nHeight = document.getElementById(strFrameName).contentWindow.document.body.scrollHeight;
		document.getElementById(strFrameName).style.height = nHeight;
	}
}

//This function is used to make sure certain browsers (namely, IE) always display very small images.
function fnRefreshImages()
{
	//Declare variables.
	var nIndex;
	var astrImages = new Array();
	
	//Setup array.
	astrImages = document.images;
	
	//Loop through the array of images, "refreshing" them one-by-one.
	for (nIndex = 0; nIndex < astrImages.length; nIndex++)
	{
		document.images[nIndex].src = document.images[nIndex].src;
	}
}

function FormatNumber(num,decimalNum,bolLeadingZero,bolParens,bolCommas)
/**********************************************************************
	IN:
		NUM - the number to format
		decimalNum - the number of decimal places to format the number to
		bolLeadingZero - true / false - display a leading zero for
										numbers between -1 and 1
		bolParens - true / false - use parenthesis around negative numbers
		bolCommas - put commas as number separators.
 
	RETVAL:
		The formatted number!
 **********************************************************************/
{ 
        if (isNaN(parseInt(num))) return "NaN";

	var tmpNum = num;
	var iSign = num < 0 ? -1 : 1;		// Get sign of number
	
	// Adjust number so only the specified number of numbers after
	// the decimal point are shown.
	tmpNum *= Math.pow(10,decimalNum);
	tmpNum = Math.round(Math.abs(tmpNum))
	tmpNum /= Math.pow(10,decimalNum);
	tmpNum *= iSign;					// Readjust for sign
	
	
	// Create a string object to do our formatting on
	var tmpNumStr = new String(tmpNum);

	// See if we need to strip out the leading zero or not.
	if (!bolLeadingZero && num < 1 && num > -1 && num != 0)
		if (num > 0)
			tmpNumStr = tmpNumStr.substring(1,tmpNumStr.length);
		else
			tmpNumStr = "-" + tmpNumStr.substring(2,tmpNumStr.length);
		
	// See if we need to put in the commas
	if (bolCommas && (num >= 1000 || num <= -1000)) {
		var iStart = tmpNumStr.indexOf(".");
		if (iStart < 0)
			iStart = tmpNumStr.length;

		iStart -= 3;
		while (iStart >= 1) {
			tmpNumStr = tmpNumStr.substring(0,iStart) + "," + tmpNumStr.substring(iStart,tmpNumStr.length)
			iStart -= 3;
		}		
	}

	// See if we need to use parenthesis
	if (bolParens && num < 0)
		tmpNumStr = "(" + tmpNumStr.substring(1,tmpNumStr.length) + ")";

	return tmpNumStr;		// Return our formatted string!
}

function FormatPercent(num,decimalNum,bolLeadingZero,bolParens,bolCommas)
/**********************************************************************
	IN:
		NUM - the number to format
		decimalNum - the number of decimal places to format the number to
		bolLeadingZero - true / false - display a leading zero for
										numbers between -1 and 1
		bolParens - true / false - use parenthesis around negative numbers
		bolCommas - put commas as number separators.										
 
	RETVAL:
		The formatted number!		
 **********************************************************************/
{
	var tmpStr = new String(FormatNumber(num*100,decimalNum,bolLeadingZero,bolParens,bolCommas));

	if (tmpStr.indexOf(")") != -1) {
		// We know we have a negative number, so place '%' inside of ')'
		tmpStr = tmpStr.substring(0,tmpStr.length - 1) + "%)";
		return tmpStr;
	}
	else
		return tmpStr + "%";			// Return formatted string!
}

function FormatCurrency(num,decimalNum,bolLeadingZero,bolParens,bolCommas)
/**********************************************************************
	IN:
		NUM - the number to format
		decimalNum - the number of decimal places to format the number to
		bolLeadingZero - true / false - display a leading zero for
										numbers between -1 and 1
		bolParens - true / false - use parenthesis around negative numbers
		bolCommas - put commas as number separators.										
 
	RETVAL:
		The formatted number!		
 **********************************************************************/
{
	var tmpStr = new String(FormatNumber(num,decimalNum,bolLeadingZero,bolParens,bolCommas));

	if (tmpStr.indexOf("(") != -1 || tmpStr.indexOf("-") != -1) {
		// We know we have a negative number, so place '$' inside of '(' / after '-'
		if (tmpStr.charAt(0) == "(")
			tmpStr = "($"  + tmpStr.substring(1,tmpStr.length);
		else if (tmpStr.charAt(0) == "-")
			tmpStr = "-$" + tmpStr.substring(1,tmpStr.length);
			
		return tmpStr;
	}
	else
		return "$" + tmpStr;		// Return formatted string!
}

function FormatDateTime(datetime, FormatType)
/*
	 FomatType takes the following values
		1 - General Date = Friday, October 30, 1998
		2 - Typical Date = 10/30/98
		3 - Standard Time = 6:31 PM
		4 - Military Time = 18:31
*/
{
	var strDate = new String(datetime);

	if (strDate.toUpperCase() == "NOW") {
		var myDate = new Date();
		strDate = String(myDate);
	} else {
		var myDate = new Date(datetime);
		strDate = String(myDate);
	}


	// Get the date variable parts
	var Day = new String(strDate.substring(0,3));
	if (Day == "Sun") Day = "Sunday";
	if (Day == "Mon") Day = "Monday";
	if (Day == "Tue") Day = "Tuesday";
	if (Day == "Wed") Day = "Wednesday";
	if (Day == "Thu") Day = "Thursday";
	if (Day == "Fri") Day = "Friday";
	if (Day == "Sat") Day = "Saturday";	
	
	var Month = new String(strDate.substring(4,7)), MonthNumber = 0;
	if (Month == "Jan") { Month = "January"; MonthNumber = 1; }
	if (Month == "Feb") { Month = "February"; MonthNumber = 2; }
	if (Month == "Mar") { Month = "March"; MonthNumber = 3; }
	if (Month == "Apr") { Month = "April"; MonthNumber = 4; }
	if (Month == "May") { Month = "May"; MonthNumber = 5; }
	if (Month == "Jun") { Month = "June"; MonthNumber = 6; }
	if (Month == "Jul") { Month = "July"; MonthNumber = 7; }
	if (Month == "Aug") { Month = "August"; MonthNumber = 8; }
	if (Month == "Sep") { Month = "September"; MonthNumber = 9; }
	if (Month == "Oct") { Month = "October"; MonthNumber = 10; }
	if (Month == "Nov") { Month = "November"; MonthNumber = 11; }
	if (Month == "Dec") { Month = "December"; MonthNumber = 12; }
	
	var curPos = 11;
	var MonthDay = new String(strDate.substring(8,10));
	if (MonthDay.charAt(1) == " ") {
		MonthDay = "0" + MonthDay.charAt(0);
		curPos--;
	}	
	
	var MilitaryTime = new String(strDate.substring(curPos,curPos + 5));
	
	var Year = new String(strDate.substring(strDate.length - 4, strDate.length));	
	
	document.write(strDate + "");	

	// Format Type decision time!
	if (FormatType == 1)
		strDate = Day + ", " + Month + " " + MonthDay + ", " + Year;
	else if (FormatType == 2)
		strDate = MonthNumber + "/" + MonthDay + "/" + Year.substring(2,4);
	else if (FormatType == 3) {
		var AMPM = MilitaryTime.substring(0,2) >= 12 && MilitaryTime.substring(0,2) != "24" ? " PM" : " AM";
		if (MilitaryTime.substring(0,2) > 12)
			strDate = (MilitaryTime.substring(0,2) - 12) + ":" + MilitaryTime.substring(3,MilitaryTime.length) + AMPM;
		else {
			if (MilitaryTime.substring(0,2) < 10)
				strDate = MilitaryTime.substring(1,MilitaryTime.length) + AMPM;
			else
				strDate = MilitaryTime + AMPM;
		}
	}	
	else if (FormatType == 4)
		strDate = MilitaryTime;


	return strDate;
}

function LTrim(str)
        /***
                PURPOSE: Remove leading blanks from our string.
                IN: str - the string we want to LTrim

                RETVAL: An LTrimmed string!
        ***/
        {
                var whitespace = new String(" \t\n\r");

                var s = new String(str);

                if (whitespace.indexOf(s.charAt(0)) != -1) {
                    // We have a string with leading blank(s)...

                    var j=0, i = s.length;

                    // Iterate from the far left of string until we
                    // don't have any more whitespace...
                    while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
                        j++;


                    // Get the substring from the first non-whitespace
                    // character to the end of the string...
                    s = s.substring(j, i);
                }

                return s;
        }

function RTrim(str)
        /***
                PURPOSE: Remove trailing blanks from our string.
                IN: str - the string we want to RTrim

                RETVAL: An RTrimmed string!
        ***/
        {
                // We don't want to trip JUST spaces, but also tabs,
                // line feeds, etc.  Add anything else you want to
                // "trim" here in Whitespace
                var whitespace = new String(" \t\n\r");

                var s = new String(str);

                if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
                    // We have a string with trailing blank(s)...

                    var i = s.length - 1;       // Get length of string

                    // Iterate from the far right of string until we
                    // don't have any more whitespace...
                    while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
                        i--;


                    // Get the substring from the front of the string to
                    // where the last non-whitespace character is...
                    s = s.substring(0, i+1);
                }

                return s;
        }

        function Trim(str)
        /***
                PURPOSE: Remove trailing and leading blanks from our string.
                IN: str - the string we want to Trim

                RETVAL: A Trimmed string!
        ***/
        {
                return RTrim(LTrim(str));
        }

        function Len(str)
        /***
                IN: str - the string whose length we are interested in

                RETVAL: The number of characters in the string
        ***/
        {  return String(str).length;  }

        function Left(str, n)
        /***
                IN: str - the string we are LEFTing
                    n - the number of characters we want to return

                RETVAL: n characters from the left side of the string
        ***/
        {
                if (n <= 0)     // Invalid bound, return blank string
                        return "";
                else if (n > String(str).length)   // Invalid bound, return
                        return str;                // entire string
                else // Valid bound, return appropriate substring
                        return String(str).substring(0,n);
        }

        function Right(str, n)
        /***
                IN: str - the string we are RIGHTing
                    n - the number of characters we want to return

                RETVAL: n characters from the right side of the string
        ***/
        {
                if (n <= 0)     // Invalid bound, return blank string
                   return "";
                else if (n > String(str).length)   // Invalid bound, return
                   return str;                     // entire string
                else { // Valid bound, return appropriate substring
                   var iLen = String(str).length;
                   return String(str).substring(iLen, iLen - n);
                }
        }

        function Mid(str, start, len)
        /***
                IN: str - the string we are LEFTing
                    start - our string's starting position (0 based!!)
                    len - how many characters from start we want to get

                RETVAL: The substring from start to start+len
        ***/
        {
                // Make sure start and len are within proper bounds
                if (start < 0 || len < 0) return "";

                var iEnd, iLen = String(str).length;
                if (start + len > iLen)
                        iEnd = iLen;
                else
                        iEnd = start + len;

                return String(str).substring(start,iEnd);
        }

//This function returns the first location of "charSearchFor" found in "strSearch". If "charSearchFor" is not found, -1 is returned.)
function fnInStr(strNeedle, strHaystack)
{
	var bInStr = (strHaystack.indexOf(strNeedle) >= 0) ? true : false;
	
	return(bInStr);
}

function fnInsertSmiley(strFormFieldID, strCode)
{
	var strMessage = window.opener.document.getElementById(strFormFieldID).value;
	
	strMessage = strMessage + strCode + " ";
	
	window.opener.document.getElementById(strFormFieldID).value = strMessage;
}

//-->
