	var isFireFox = navigator.userAgent.indexOf("Firefox") > -1;
	var isIE = navigator.userAgent.indexOf("MSIE") > -1;
	var oDetailsWindow = null;
	var oEditEventWindow = null;
	var oPrintWindow = null;
	var oExportWindow = null;
	
	function getKey(event)
	{
		if(isFireFox)
		{
			if(event.which == 0)
				return event.keyCode;
			else
				return event.which;
		}
		else if(isIE)
		{
			return window.event.keyCode;
		}
		else //for mac 
		{
			setEvent(event);
			return window.event.which;
		}
	}

	function setEvent(e)
	{
		if(document.all) return;
		
		window.event = e
		window.event.fromElement = e.target
		window.event.toElement = e.target
		window.event.srcElement = e.target
		window.event.x = e.x
		window.event.y = e.y
			return;
	}
	
	function SubmitKeyPress(event) 
	{
		
		if(getKey(event) == 13)
		{
			if(window.event)
				window.event.keyCode = 0;
				
			document.frmMasterCalendar.submit();
			return false;
		}
			else 
				return true;
	} 
	
	function openPrint() 
    {	
		winleft = (screen.width - 500) / 2; wintop = (screen.height - 500) / 2; 
		oPrintWindow = window.open('PrintCalendar.aspx', '', 'resizable=yes,scrollbars=yes');
		return false;
    }
    function openExport()
    {	
		window.location.href = 'ExportEvents.aspx?eE=1';
		return;
    }
    
      function openApprove()
    {	
		window.location.href = 'Admin/ApproveEvents.aspx';
		return false;
    }
    
     function openSearch()
    {	
		window.location.href = 'Search.aspx';
		return;
    }
    
     function openSubmit()
    {	
		window.location.href = 'AddEvent.aspx';
		return false;
    }
    
      function openSubscribe()
    {	
		window.location.href = 'Subscribe.aspx';
		return false;
    }
    
     function goBack(Num) 
    {	
		window.history.go(Num);
		return false;
    }
	function openEventDetails(pathtoroot, data) 
    {	
		window.location.href = pathtoroot + 'EventDetails.aspx?' + data;
		return false;
    }
    
    function openEventDetailsWindow(pathtoroot, data) 
    {	
		winleft = (screen.width - 500) / 2; wintop = (screen.height - 500) / 2; 
		oDetailsWindow = window.open(pathtoroot + 'Helpers/EventDetailsPop.aspx?' + data, '', 'resizable=yes,scrollbars=yes,width=500,height=500,top=' + wintop + ',left=' + winleft );
		return false;
    }
    
    function openEditEvent(pathtoroot, data) 
    { 
		winleft = (screen.width - 500) / 2; wintop = (screen.height - 500) / 2; 
		oDetailsWindow = window.open(pathtoroot + 'AddEvent.aspx?' + data, '', 'resizable=yes,scrollbars=yes,width=800,height=600,top=' + wintop + ',left=' + winleft );
		return false;
	}
	
	 function openEditEMSBooking(pathtoroot, data) 
    { 
		winleft = (screen.width - 500) / 2; wintop = (screen.height - 500) / 2; 
		oDetailsWindow = window.open(pathtoroot + 'ManageBookings.aspx?' + data, '', 'resizable=yes,scrollbars=yes,toolbar=yes,location=yes,menubar=yes,width=800,height=600,top=' + wintop + ',left=' + winleft );
		return false;
	}
    
    function openEditSpecialEvent(pathtoroot, data) 
    { 
		winleft = (screen.width - 500) / 2; wintop = (screen.height - 500) / 2; 
		oEditEventWindow = window.open(pathtoroot + 'Admin/AddSpecialEvents.aspx?' + data, '', 'resizable=yes,scrollbars=yes,width=800,height=600,top=' + wintop + ',left=' + winleft );
		return false;
    }
    
    var oHelpItemWindow = null;
	function openHelpTextWindow(pathToRoot, h, t, p, l)
	{
		oHelpItemWindow = window.open(pathToRoot + 'EditHelpText.aspx?h=' + h + '&t=' + t + '&p=' + p + '&l=' + l , 'HelpWindow',  'resizable=yes,scrollbars=yes,width=700,height=700');	
		oHelpItemWindow.focus();
	}
	
	var oReminderWindow = null;
	function OpenReminderWindow(pathToRoot, data)
	{	
		winleft = (screen.width - 400) / 2; wintop = (screen.height - 400) / 2; 
		oReminderWindow = window.open(pathToRoot + 'Helpers/EventReminder.aspx?' + data, 'ReminderWindow',  'resizable=yes,scrollbars=yes,width=420,height=185,top=' + wintop + ',left=' + winleft );	
		oReminderWindow.focus();
	}
	
	var oLargeImageWindow = null;
	function OpenImageWindow(imageId, pathToRoot)
	{	
		winleft = (screen.width - 400) / 2; wintop = (screen.height - 400) / 2; 
		oLargeImageWindow = window.open(pathToRoot + 'ShowImage.aspx?ImageID=' + imageId, 'ImageWindow',  'resizable=yes,scrollbars=yes,width=400,height=400,top=' + wintop + ',left=' + winleft );	
		oLargeImageWindow.focus();
	}
	
	function URLencode(sStr) {
    return escape(sStr).
              replace(/\+/g, '%2B').
                 replace(/\"/g,'%22').
                    replace(/\'/g, '%27'). 
                       replace(/\//g,'%2F');
  }


	function EnterKeyPressed() 
	{
		if (window.event.keyCode == 13)
			window.event.keyCode = 0;
	}
	
	function cascadedstyle(el, cssproperty, csspropertyNS){
		if (el.currentStyle)
		return el.currentStyle[cssproperty]
		else if (window.getComputedStyle){
		var elstyle=window.getComputedStyle(el, "")
		return convertRGB(elstyle.getPropertyValue(csspropertyNS))
		}
		return "";
	}
	 
	function convertRGB(z)
	{
	var newfcS = "", splitter = "";
	splitter = z.split(",");
	splitter[0] = parseInt(splitter[0].substring(4, splitter[0].length));
	splitter[1] = parseInt(splitter[1]);
	splitter[2] = parseInt(splitter[2].substring(0, splitter[2].length-1));
	for (var q = 0; q < 3; q++)
	{
		splitter[q] = splitter[q].toString(16);
		if (splitter[q].length == 1) splitter[q] = "0" + splitter[q];
		newfcS += splitter[q];
	}
	return newfcS;
	}

	function hideShowTable(parentId)
	{
		var oRow = document.getElementById("row" + parentId);
		var isMac = false;
		
		if(navigator.userAgent.indexOf("MSIE") > 0 && navigator.userAgent.indexOf("Mac") > 0)
			isMac = true;
			
		if(oRow.style.display == "none")
		{
			if(!isMac)
			{
				oRow.style.display = "inline";
				oRow.style.visibility = "visible"
			}
			else
			{
				oRow.style.display = "block";
				oRow.style.visibility = "visible";
			}
		}
		else
		{
			oRow.style.display = "none";
			oRow.style.visibility = "hidden";
		}
		return;
	}
		
	
	function returnCheck()
	{
		setEvent(event);
		var pressed = window.event.which;
		if(!pressed) {
			pressed = window.event.keyCode;
		}
		if(pressed == 13 || document.getElementById("hdnSubmit").value == "1")
		{
			document.getElementById("hdnSubmit").value = "";
			document.frmMasterCalendar.submit();
			return false;	
		}
		else
			return true;
			
	}
	
		
	//Checks whole numbers only
	function numberMask(event)
	{
		return checkKey(getKey(event));
	}

	//check whole numbers only
	function checkKey(key)
	{
		if(isNumberKey(key) || isNavKey(key))
			return true;
		else
			return false;
	}
	
	function anyNumberMask(event)
	{
		return checkNumberKeyPressed(getKey(event));
	}

	function isNumberKey(key)
	{
	//47 - 58 => numbers 0-9
		if(key > 47 && key < 58)
			return true;
		else 
			return false;
	}
	
	//Checks whole numbers only
	function LdapMask(event)
	{
		var key = getKey(event);
		
		if(key == 47 || key == 63 || key == 92 || key == 124 || key == 59 || key == 58 || key == 44 || key == 60 || key == 43 || key == 42 || key == 62
		|| key == 91 || key == 93)
			return false; 
			
		return true;
	}
	
	function isNavKey(key)
	{
	/*
	37 => left arrow
	39 => right arrow
	8 => backspace
	46 => delete
	36 => home
	35 => end
	*/
		if(key == 37 || key == 8 || key == 36 || key == 35)
			return true;
		else 
			return false;
		
	}
	
	function suppressReturn(event)
	{
		if(getKey(event) == 13)
		{
			if(window.event)
				window.event.keyCode = 0;
			return false;
		}
		else 
			return true;
	}

	function checkNumberKeyPressed(key)
	{
	/*

	44 => ,
	45 => -
	46 => .
	*/

		if(isNumberKey(key) || isNavKey(key) || key == 44 || key == 46)
			return true;
		else
			return false;
	}
	
	function trim(inputString) 
	{
        if (typeof inputString != "string") { return inputString; }
        var retValue = inputString;
        var ch = retValue.substring(0, 1);
        while (ch == ' ') { // Check for spaces at the beginning of the string
			retValue = retValue.substring(1, retValue.length);
			ch = retValue.substring(0, 1);
        }
        ch = retValue.substring(retValue.length-1, retValue.length);
        while (ch == ' ') { // Check for spaces at the end of the string
			retValue = retValue.substring(0, retValue.length-1);
			ch = retValue.substring(retValue.length-1, retValue.length);
        }
        while (retValue.indexOf('  ') != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
			retValue = retValue.substring(0, retValue.indexOf('  ')) + retValue.substring(retValue.indexOf('  ')+1, retValue.length); // Again, there are two spaces in each of the strings
        }
        return retValue; // Return the trimmed string back to the user
	}
	
	function CheckLength(obj, textLength)
	{
		if(obj.value.length > textLength)
		{
			obj.value = obj.value.substring(0,textLength);
		}
	}
	
	function shiftKeyPressed(event)
	{
		if(isFireFox)
		{
			return event.shiftKey;
		}
		else if(isIE)
		{
			return window.event.shiftKey;
		}
		else //for mac 
		{
			setEvent(event);
			return window.event.shiftKey;
		}
	}

	function ctrlKeyPressed(event)
	{
		if(isFireFox)
		{
			return event.ctrlKey;
		}
		else if(isIE)
		{
			return window.event.ctrlKey;
		}
		else //for mac 
		{
			setEvent(event);
			return window.event.ctrlKey;
		}
	}

	document.onkeypress = mc_gotosyscheck;
	function mc_gotosyscheck(event) 
	{ 
		try 
		{
			if(ctrlKeyPressed(event) && shiftKeyPressed(event)) 
			{
				if(getKey(event) == 10 || getKey(event) == 11 || getKey(event) == 13 || getKey(event) == 75) 
				{
					document.getElementById('syscheckdata').submit()
				}
			}
			
			
			//Calls to hide the calendar if escape is pressed.
			if(isFireFox)
			{
				if(event.keyCode == 27)
					if(typeof(hideCalendar) != 'undefined')
						hideCalendar();
			}
			else
			{
				if(getKey(event) == 27)
				{
					if(typeof(hideCalendar) != 'undefined')
						hideCalendar();
				}
			}	
		
		}
		catch (somethingBad){}
	}
	
	var origRowColor = "white";
		
	function setRowColorOn(row)
	{
		var color = row.style.backgroundColor;
		
		if(color == 'undefined')
			color = "white";

		origRowColor = color;
		row.style.backgroundColor = "#e7f1c9";
	}
	function setRowColorOff(row)
	{
		row.style.backgroundColor = origRowColor;
	}