
//Help global variables
var helpWindow;
var helpWindowSimple;
var objCalendarFrame;
var blnLoggedIntoPortal = window.top.blnLoggedIntoPortal;

//Default starting page for help, do not remove the '#'!!!
var strProjectFramesPagePlus = "index.htm#";

function callHelp(strProjectPath, strHelpPage, strWindowName)
{
	var strTriHelpWindowOptions = ",toolbar=no,location=no,status=no,menubar=no,resizable=yes";
	strTriHelpWindowOptions += ",top=30";
	strTriHelpWindowOptions += ",left=25";
	strTriHelpWindowOptions += ",width=880";
	strTriHelpWindowOptions += ",height=625";

	if (helpWindow == null || helpWindow.closed)
	{
		if (helpWindowSimple && !helpWindowSimple.closed)
		{
			helpWindowSimple.close();
		}
		
		if(strWindowName == undefined)
			strWindowName = "Aprimo70Help";
			
		helpWindow = window.open("", strWindowName, strTriHelpWindowOptions);
		
		if(helpWindow.frames.length > 0)
		{
			//We need to set the location of the context sensitive help in the right frame in the bottom frame...
			helpWindow.frames[1].frames[1].location.href = strProjectPath + strHelpPage;
		}
		else
		{
			//Prevent Robohelp from breaking on Safari by excluding the anchor tag from the 
			//URL used to load the content frame.
			if(IsMac())
			{
				if(strHelpPage.split('#').length > 1)
				{
					strHelpPage = strHelpPage.substring(0,strHelpPage.lastIndexOf('#'));
				}
			}

			//We need to have the help render the frames and open the context sensitive help page
			helpWindow.location.href = strProjectPath + strProjectFramesPagePlus + strHelpPage;
		}
		
		helpWindow.focus();
	}
	else if (helpWindow && !helpWindow.closed)
	{
		if (helpWindowSimple && !helpWindowSimple.closed)
		{
			helpWindowSimple.close();
		}
		//We need to set the location of the context sensitive help in the right frame in the bottom frame...
		helpWindow.frames[1].frames[1].location.href = strProjectPath + strHelpPage;
		helpWindow.focus();
	}
}

function SwapImage(id, newSrc, Mode) {
	var objImg = document.getElementById(id);
	if (Mode)
	{
		if (Mode == "Off")
			objImg.src = newSrc;		
		else 
		{
			var strURL = newSrc.substring(0, newSrc.lastIndexOf(".")) + "_On" + newSrc.substring(newSrc.lastIndexOf("."));
			objImg.src = strURL;
		}
	}
	else 
		objImg.src = newSrc;	
}

function PortalButtonGlow(Name, Class, Mode, Path) 
{
	var objImg = document.getElementById(Name + "_Left");
	objImg.src = Path + "images/ButtonLeft_" + Mode + "60_s.gif";

	var objImg = document.getElementById(Name + "_Right");
	objImg.src = Path + "images/ButtonRight_" + Mode + "60_s.gif";

	var ObjText = document.getElementById(Name + "_A");
	ObjText.className = Class + "Cell";
}

function ButtonGlow(Name, Class, Mode) 
{
		var objImg = document.getElementById(Name + "Left");
		objImg.src = RelativePath + "images/ButtonLeft_" + Mode + ".gif";

		var objImg = document.getElementById(Name + "Right");
		objImg.src = RelativePath + "images/ButtonRight_" + Mode + ".gif";

		var objImg = document.getElementById(Name + "Back");
		if (objImg)
		{
			objImg.src = RelativePath + "images/Button_Back" + Mode + ".gif";
		}

		var objImg = document.getElementById(Name + "Continue");
		if (objImg)
		{
			objImg.src = RelativePath + "images/Button_Continue" + Mode + ".gif";
		}

		var ObjText = document.getElementById(Name + "A");
		ObjText.className = Class + "Cell";

		var ObjText = document.getElementById(Name + "B");
		ObjText.className = Class;

		var ObjText = document.getElementById(Name + "C");
		if (ObjText)
		{
			ObjText.className = Class + "Cell";
		}

		var ObjText = document.getElementById(Name + "D");
		if (ObjText)
		{
			ObjText.className = Class + "Cell";
		}
}

function htmlButton(name, caption, URL, mode, target, type) 
{
	if (!mode) {
		mode = "";
	}
	if (!target) {
		target = "";
	}
	if (!type) {
		width = 10;
		classon = "ButtonOn";
		classoff = "ButtonOff";
		padding = "&nbsp;&nbsp;";
		symbol = "";
	}
	else {
		if (type == "menu") {
			width = 8;
			classon = "MenuOn";
			classoff = "MenuOff";
			padding = "";
			symbol = "&#149; ";
		}
	}

	var sOut = "<table border=0 cellspacing=0 cellpadding=0>\n";
	sOut += "<tr>\n";
	sOut += "<td><img id='" + name + "Left' src='" + RelativePath + "images/" + window.StyleName + "/ButtonLeft_Off60.gif' border=0></td>\n"
	sOut += "<td id='" + name + "A' class='" + classoff + "' valign='middle' nowrap='true'>\n"
		sOut += "<a href='" + URL + "' class='none'"
		if (target != "") {
			sOut += " target=\"" + target + "\" ";
		}
		sOut += "onmouseover=\"ButtonGlow('" + name + "', 'ButtonOn', 'On');\" onmouseout=\"ButtonGlow('" + name + "', 'ButtonOff', 'Off')\">\n"   
		sOut += "<div id='" + name + "B' class='" + classoff + "'>" + padding + symbol + caption + padding + "</div></a>\n</td>\n"

	sOut += "<td><img id='" + name + "Right' src='" + RelativePath + "images/" + window.StyleName + "/ButtonRight_Off60.gif' border=0></td>\n"
	sOut += "</tr>\n";
	sOut += "</table>\n";
	return sOut;
}

//----------------------------------------------------------------
//  Author:			
//  Procedure Name:	buildButton
//  Description:	
//  Arguments:		
//  Return Value:	(none)
//  Comments:		(none)
//----------------------------------------------------------------
function buildButton(name, caption, URL, mode)
{
	buildButtonOut = htmlButton(name, caption, URL, mode);
	return buildButtonOut;
}

//----------------------------------------------------------------
//  Author:			
//  Procedure Name:	buildButtons
//  Description:	
//  Arguments:		
//  Return Value:	(none)
//  Comments:		(none)
//----------------------------------------------------------------
function buildButtons(buttonArray, type) 
{
	if (!type) 
	{
		padding = 5;
		spacing = 2;
	}
	else 
	{
		if (type == "menu") 
		{
			padding = 0;
			spacing = 0;
		}
	}

	document.write("<table border=0 cellpadding=" + padding + " cellspacing=" + spacing + ">\n");
	document.write("<tr>\n");
	for(var i = 0; i < buttonArray.length; i++) {
		document.write("<td>\n");
		document.write(buttonArray[i] + "\n");
		document.write("</td>\n");
	}
	document.write("</tr>\n");
	document.write("</table>\n");
}

//----------------------------------------------------------------
//  JavaScript Standards
//----------------------------------------------------------------
//	1. All functions must have a standard comment block (see example below)
//		- All functions should be named in mixed upper/lower case with the first 
//		  character capitalized
//		- Arguments treated as optional should be enclosed in brackets
//		- Comment block alignment should be maintained for readability
//		- Comment block items that do not apply should use the value "(none)"
//		- Notes about different topics should be listed in separate paragraphs
//
//	2. Function arguments should be separated by a comma and a space, and use
//	   mixed upper/lower case with the first character capitalized
//		- Example: function MyFunctionName(Xxx, Yyy, Zzz) 
//
//	3. All variables should be explicitly declared at the top of each function
//	   in the order that they are used and loosely follow Hungarian naming 
//	   conventions.
//		- Example: var lngCounter = 0;
//				   var dteBeginDate = new Date();
//
//	4. If/Then/Else syntax regarding spacing and alignment should be as follows:
//		if (X == Y) {
//			[statements]
//		}
//		else {
//			[statements]
//		}
//
//	5. Code should be resonably documented and statments should be logically 
//	   grouped.
//
//	6. Single-line spacing should be implemented within functions and triple-line
//	   spacing used between functions to maximize readability.
//----------------------------------------------------------------

//----------------------------------------------------------------
//  Author:			(author's full name)
//
//  Procedure Name:	(mixed-case function name)
//
//  Description:	    (brief description of what the function does)
//
//  Arguments:			(name) - (description of the value/object to be passed)
//  					(name) - (description of the value/object to be passed)
//  					[(name)] - (description of the value/object to be passed
//								   for this [OPTIONAL] parameter)
//
//  Return Value:	    (description of the return value, if any)
//
//  Comments:			(notes about special processing)
//
//						(notes about related functions)
//
//						(notes about acceptable argument values)
//----------------------------------------------------------------


//----------------------------------------------------------------
//	Global JavaScript variables
//----------------------------------------------------------------
var g_strCurrentMenu;		//Stores the name of the dynamic HTML menu currently being displayed
var g_lngCounter = 0;		//Used as a global counting variable for DHTML animations
var g_blnReverse = false;	//Identifies the current direction of an animated DHTML object

//----------------------------------------------------------------
//	Style Sheet Properties for Macintosh 
//----------------------------------------------------------------
var g_vntBackgroundColors = new Array();
	g_vntBackgroundColors[0] = "c9c38b";	//NavCellSelected
	g_vntBackgroundColors[1] = "f0e68c";	//NavCellOn, NavCellOnNotLinked, NavCellOnDisabled
	g_vntBackgroundColors[2] = "f6f6e0";	//NavCellOff, NavCellOffNotLinked, NavCellOffDisabled

var g_vntColors = new Array;
	g_vntColors[0] = "f0e68c";	//ToolBarOn, ToolBarParentOn, CaptionLinkOn
	g_vntColors[1] = "f6f6e0";	//ToolBarOff, ToolBarParentOff, CaptionLinkOff


function OpenReportWindow(URL, WinName, Width, Height, Options, x, y, bModal) {
	if(Options != "")
		Options += ","
	Options += "scrollbars=yes,width=" + Width;
	Options += ",height=" + Height;
	Options += ",left=" + x + ",top=" + y;
	Options += ",resizable=yes"
	var mywin = window.open(URL, WinName, Options);
	mywin.focus();
}

//----------------------------------------------------------------
//  Author:			Brian Tauke
//
//  Procedure Name:	OpenWindow
//
//  Description:	    Opens a secondary browser window
//
//  Arguments:			URL - 
//						[Name] - 
//						[Height] - 
//						[Width] -
//						[Options] -  
//						[Left] - 
//						[Top] - 
//						[ToolBar] - 
//						[MenuBar] - 
//						[ScrollBars] - 
//						[Resizable] - 
//						[Status] - 
//						[Location] - 
//						[Directories] - 
//
//  Return Value:	    (none)
//
//  Comments:			Embedded spaces in the "Options" parameter will cause
//						a JavaScript error.
//----------------------------------------------------------------
function openWindow(URL, WinName, Width, Height, Options, bModal) 
{
	// Make sure that the parameters were passed in, and if not, default them	
	if (!WinName || WinName == "")
		WinName = "newWin";
	if (IsMac())
	{		
		if (!Width)
			Width = 750;
		if (!Height)
			Height = 600;	
		if (!Options || Options == "")
			Options = "alwaysRaised=yes, status=1, menubar=yes";	
		
	}	
	var scrWidth = screen.availWidth;
	var scrHeight = screen.availHeight;
	var winLeft = (scrWidth-Width)/2;
	var winTop = (scrHeight-Height)/2;
	if(Options != "")
		Options += ",";
	Options += "scrollbars=yes,width=" + Width;
	Options += ",height=" + Height;
	Options += ",left=" + winLeft + ",top=" + winTop;
	Options += ",resizable=yes";
	if(bModal)
		WinName = "ModalWindow";
		
	var newWin = window.open(URL, WinName, Options);
	newWin.focus();
	if(bModal)
	{
		window.Modal = newWin;
		if(IsMac())
			window.onmouseover = WindowOnFocus;
		else
			window.onfocus = WindowOnFocus;				
	}
}
function WindowOnFocus()
{
	if(window.Modal != null)
	{				
		window.Modal.focus();
	}
}
function openPositionedWindow(URL, WinName, Width, Height, Options) 
{
	var scrWidth = screen.availWidth;
	var scrHeight = screen.availHeight;
	var winLeft = (scrWidth-Width)/2;
	var winTop = (scrHeight-Height)/2;
	if(Options != "")
		Options += ",";
	Options += "width=" + Width;
	Options += ",height=" + Height;
	Options += ",left=" + winLeft + ",top=" + winTop;
	var mywin = window.open(URL, WinName, Options);
	mywin.focus();
}

//----------------------------------------------------------------
//    Author: Mike McDole
// Purpose: This function opens a new browser window that will be size slightly 
//    smaller than the main window and will start in the upper left corner
//              of the screen.
// Argument: URL - URL of the new page
//    WinName - Window's name 
//    Options - additional options you want to set.  
// Note:  Do not include the width, height, left, or top option properties in 
//              the Options parameter.  This function will add the properties to the 
//              string automatically. 
//----------------------------------------------------------------
function openWindowsegmentation(URL, WinName, Options) 
{ 
	//First, calculate the height, width,left, and top properties.
	var scrWidth = screen.availWidth - 225;
	var scrHeight = screen.availHeight - 225;
	var winLeft = round((screen.availWidth - scrWidth)/2);
	var winTop =  round((screen.availHeight - scrHeight)/2) - 50;

	//Next, add other options
	if(Options != "") 
	{
		Options += ",";
	}
	Options += "scrollbars=no,status=yes";
	Options += ",left=" + winLeft + ",top=" + winTop; 
	Options += ",width=" + scrWidth + ",height=" + scrHeight;  

	if (bIsIE()) 
	{
		Options += ",resizable=yes";
	} 
	//now open the new window
	var mywin = window.open(URL, WinName, Options);
	mywin.focus();
}

//Opens the file output windows with a common size
function openWindowFileOutput(URL, WinName, Options) 
{ 
	//First, calculate the height, width,left, and top properties.
	var scrWidth = screen.availWidth - 225;
	var scrHeight = screen.availHeight - 225;
	var winLeft = round((screen.availWidth - scrWidth)/2);
	var winTop =  round((screen.availHeight - scrHeight)/2) - 50;

	//Next, add other options
	if(Options != "") 
	{
		Options += ",";
	}
	Options += "scrollbars=no,status=yes";
	Options += ",width=" + scrWidth + ",height=" + scrHeight;  

	if ((Options.indexOf("left") < 0) && (Options.indexOf("top") < 0))
		Options += ",left=" + winLeft + ",top=" + winTop; 

	if (bIsIE()) 
	{
		Options += ",resizable=yes";
	} 
	//now open the new window
	var mywin = window.open(URL, WinName, Options);
	mywin.focus();
}

//Opens the file output windows with a common size
function openWindowGeneric(URL, WinName, Options) 
{ 
	//First, calculate the height, width,left, and top properties.
	var scrWidth = screen.availWidth - 225;
	var scrHeight = screen.availHeight - 225;
	var winLeft = round((screen.availWidth - scrWidth)/2);
	var winTop =  round((screen.availHeight - scrHeight)/2) - 50;

	//Next, add other options
	if(Options != "") 
	{
		Options += ",";
	}
	Options += "scrollbars=no,status=yes";
	Options += ",width=" + scrWidth + ",height=" + scrHeight;  

	if ((Options.indexOf("left") < 0) && (Options.indexOf("top") < 0))
		Options += ",left=" + winLeft + ",top=" + winTop; 

	if (bIsIE()) 
	{
		Options += ",resizable=yes";
	} 
	//now open the new window
	var mywin = window.open(URL, WinName, Options);
	mywin.focus();
}

//----------------------------------------------------------------
//  Author:			Sally Xu
//  Procedure Name: openfilterwindow
//  Description:	
//  Arguments:		
//  Return Value:	(none)
//  Comments:		(none)
//----------------------------------------------------------------
function openfilterwindow(url) 
{
	win = openWindow(url, "PopupFilter", 750, 550, '', false);
}

function openDashboardWindow(url)
{
	win = window.open(url, "ExecutiveDashboard", "scrollbars=yes,menubar=yes,toolbar=no,status=no,resizable=yes,top=0,left=0,height=" + (screen.availHeight - 75) + ",width=" + (screen.availWidth - 25), false);
	win.focus();
}

//DrawGroup, DrawMRU, DrawSpacer are used in building NavCol
function DrawGroup(Name, IconName) 
{
	var strHTML = '';

	strHTML = strHTML + '<tr><td height="100%"><table border="0" cellpadding="0" cellspacing="0" height="100%"><tr><td><img src="' + RelativePath + 'images/' + StyleName + '/NavGroup_Left60.gif"></td></tr>';
	strHTML = strHTML + '<tr height="99%"><td class="NavHeadingLeft"><img src="' + RelativePath + 'images/invisible.gif" height="1" width="1"></td></tr></table></td>';
	strHTML = strHTML + '<td class="NavHeading" width="100%">';
	
	if (IconName && IconName != "") {
		strHTML = strHTML + '<img src="images/' + IconName + '" width="16" height="16" border="0" align="middle">';	
	}	
	strHTML = strHTML +  Name + '</td>';
	strHTML = strHTML + '<td height="100%"><table border="0" cellpadding="0" cellspacing="0" height="100%"><tr><td><img src="' + RelativePath + 'images/' + StyleName + '/NavGroup_Right60.gif"></td></tr>';
	strHTML = strHTML + '<tr height="99%"><td class="NavHeadingRight"><img src="' + RelativePath + 'images/invisible.gif" height="1" width="1"></td></tr></table></td>';
	strHTML = strHTML + '</tr>';

	document.write(strHTML);
}

function DrawMRU(ID, Name, PopUpMenuID, Disabled) 
{
	var strHTML = "";

	if (Disabled) {
		strHTML = strHTML + '<tr class="NavCellOffNotLinkedDisabled" OnMouseOver="el_setCssClass(this, &quot;NavCellOnNotLinkedDisabled&quot;)" OnMouseOut="ChangeClass(this, &quot;NavCellOffNotLinkedDisabled&quot;)">';
			strHTML = strHTML + '<td>&nbsp;</td>';
			strHTML = strHTML + '<td colspan="2">';
				strHTML = strHTML + '<table border="0" width="100%" cellpadding="2" cellspacing="0">';
					strHTML = strHTML + '<tr>';
						strHTML = strHTML + '<td valign="top"><img src="' + RelativePath + 'images/Invisible.gif" height="1" width="7"></td>';
						strHTML = strHTML + '<td class="NavTextDisabled" width="100%"><span id="NavItem_' + ID + '">' + Name + '</span></td>';
						strHTML = strHTML + '<td align="right" valign="top"><img src="' + RelativePath + 'images/' + StyleName + '/Menu_More.gif" border="0"></td>';
					strHTML = strHTML + '</tr>';
				strHTML = strHTML + '</table>';
			strHTML = strHTML + '</td>';
		strHTML = strHTML + '</tr>';
	}
	else {

		strHTML = strHTML + '<tr class="NavCellOffNotLinked" OnMouseOver="el_setCssClass(this, &quot;NavCellOnNotLinked&quot;)" OnMouseOut="ChangeClass(this, &quot;NavCellOffNotLinked&quot;)">';
			strHTML = strHTML + '<td>&nbsp;</td>';
			strHTML = strHTML + '<td colspan="2">';
				strHTML = strHTML + '<table border="0" width="100%" cellpadding="2" cellspacing="0" OnMouseOver="ShowMenu(&quot;' + PopUpMenuID + '&quot;, this, &quot;right&quot;)" OnMouseOut="HideMenu(&quot;' + PopUpMenuID + '&quot;)">';
					strHTML = strHTML + '<tr>'; 
						strHTML = strHTML + '<td valign="top"><img src="' + RelativePath + 'images/Invisible.gif" height="1" width="7"></td>';
						strHTML = strHTML + '<td class="NavText" width="100%"><span id="NavItem_' + ID + '">' + Name + '</span></td>';
						strHTML = strHTML + '<td align="right" valign="top"><img src="' + RelativePath + 'images/' + StyleName + '/Menu_More.gif" border="0"></td>';
					strHTML = strHTML + '</tr>';
				strHTML = strHTML + '</table>';
			strHTML = strHTML + '</td>';
		strHTML = strHTML + '</tr>';
	}
	document.write(strHTML);
}


function DrawItem(ID, Name, URL, Selected, Disabled, Format, AltText) 
{

	var strHTML = '';
	var strClassName = '';
	var i = 0;
	var intFormat = 0;
	
	if (!Selected) {
		Selected = false;
	}
	if (!Disabled) {
		Disabled = false;
	}
	if (!Format) {
		Format = 'none';
	}
	if (!AltText) {
		AltText = '';
	}

		URL = Replace(URL, '"', '&quot;');

		if (Disabled) {
			strDisabled = ' isDisabled="true"';
			strHTML = strHTML + '<tr class="NavCellOffDisabled" OnMouseOver="el_setCssClass(this, &quot;NavCellOnDisabled&quot;)" OnMouseOut="ChangeClass(this, &quot;NavCellOffDisabled&quot;)">';
			strClassName = 'NavTextDisabled';
		}
		else {
			strDisabled = ' isDisabled="false"';
			if (Selected) {
				strHTML = strHTML + '<tr class="NavCellSelected" OnClick="' + URL + '" OnMouseOver="el_setCssClass(this, &quot;NavCellOn&quot;)" OnMouseOut="ChangeClass(this, &quot;NavCellSelected&quot;)">';
				strClassName = 'NavTextSelected';
	  		}
			else {
				strHTML = strHTML + '<tr class="NavCellOff" OnClick="' + URL + '" OnMouseOver="el_setCssClass(this, &quot;NavCellOn&quot;)" OnMouseOut="ChangeClass(this, &quot;NavCellOff&quot;)">';
				strClassName = 'NavText';
			}
		}

		strHTML = strHTML + '<td>&nbsp;</td>';
		strHTML = strHTML + '<td>';
			strHTML = strHTML + '<table border="0" cellpadding="0" cellspacing="0">';
				strHTML = strHTML + '<tr>';
					if ((Format == '1') || (Format == 'CurrentObject')) {
						strHTML = strHTML + '<td class="' + strClassName + '" valign="top"><img src="' + RelativePath + 'images/dot.gif" border="0">&nbsp;</td>';
					}
					else {
						strHTML = strHTML + '<td class="' + strClassName + '" valign="top">';
						intFormat = parseInt(Format);
						for (i = 1; i < intFormat; i++) {
							strHTML = strHTML + '&nbsp;&nbsp;&nbsp;';
						}	
						strHTML = strHTML + '<img src="' + RelativePath + 'images/dot.gif" border="0">&nbsp;</td>';
					}
					if (Format == 'CurrentObject') {
						strHTML = strHTML + '<td class="NavTextSelected"><span class="NavTextSelected" id="NavItem_' + ID + '"' + strDisabled + '>' + Name + '</span></td>';
					}
					else {
						if (AltText == '') {
							strHTML = strHTML + '<td class="' + strClassName + '"><span class="' + strClassName + '" id="NavItem_' + ID + '"' + strDisabled + '>' + Name + '</span></td>';
						}
						else {
							strHTML = strHTML + '<td class="' + strClassName + '"><span class="' + strClassName + '" id="NavItem_' + ID + '"' + strDisabled + ' title="' + AltText + '">' + Name + '</span></td>';
						}
					}
				strHTML = strHTML + '</tr>';
			strHTML = strHTML + '</table>';
		strHTML = strHTML + '</td>';
		strHTML = strHTML + '<td>&nbsp;</td>';
	strHTML = strHTML + '</tr>';

	document.write(strHTML);
}

function DrawSpacer() 
{		
	var strHTML = '<tr><td colspan="3"><img src="' + RelativePath + 'images/invisible.gif" height="5" width="1"></td></tr>';	
	document.write(strHTML);
}

//----------------------------------------------------------------
//              Author: Sally Xu																		
//	   Procedure Name: popMessage														
//         Description: popup a alert box to display error message, also
//					   set the focus to the field that has the error					  
//           Arguments: sMsg - message need to displayed
//					   field - field that error occured. can be null		
//----------------------------------------------------------------
function popMessage(sMsg, field) 
{

	var sField;
	var sErrMsg;
	var bReturn = false;
	
	if(typeof(field) != "object") //it is a ID
		field = document.getElementById(field);
		
	if (sMsg.indexOf("|") > 0) 
	{
		sField = sMsg.substring(sMsg.indexOf("|") + 1);	
		sMsg = sMsg.substring(0, sMsg.indexOf("|"));
		field = document.getElementById(sField);										
	}
	if (sMsg != "") 
	{
		alert(sMsg);
		bReturn = true;
	}
	if (field != null && !field.disabled) 
	{	
		field.focus();		
		bReturn = true;
	}
	return bReturn;
}

//----------------------------------------------------------------
//  Author:		Curt Knapp	
//  Procedure Name:	openLinkFromCalendar
//  Description:	Opens a link from the View Details pop up window off of the
//			calendar.  It opens it back in the Main Window.
//  Arguments:		sURL - The URL that you want to go to.
//  Return Value:	(none)
//  Comments:		(none)
//----------------------------------------------------------------
function openLinkFromCalendar(sURL) 
{
	window.opener.parent.opener.document.location.href = sURL;
	window.opener.parent.opener.focus();
	window.close();
}

//----------------------------------------------------------------
//  Author:			Brian Tauke
//
//  Procedure Name:	buildCaptionCell
//
//  Description:		Returns an HTML string containing a table caption cell with
//						one or more right justified action buttons
//
//  Arguments:			ColSpan - the number of table columns the caption cell should span
//						CaptionText - the text string to be displayed in the caption cell
//						ButtonArray - an array of HTML strings containing action button 
//									  definitions
//
//  Return Value:		An HTML string containing a table caption cell with one or
//						more right justified action buttons
//
//  Comments:			(none)
//----------------------------------------------------------------
function buildCaptionCell(ColSpan, CaptionText, ButtonArray) 
{
	document.write('<td colspan="' + ColSpan + '" class="TDDetCap">\n');
	document.write('<table border="0" width="100%" cellpadding="0" cellspacing="0">\n');
	document.write('<tr>\n');
	document.write('<td class="TDDetCap" width="99%">' + CaptionText + '</td>\n');
	for (intButtonCount=0; intButtonCount < ButtonArray.length; intButtonCount++) 
	{
		document.write('<td class="TDDetCap">\n');
		document.write(ButtonArray[intButtonCount] + '\n');
		document.write('</td>\n');
	}
	document.write('</tr>\n');
	document.write('</table>\n');
	document.write('</td>\n');
}

function move(step) 
{
	var div = document.getElementById('Starter');	
	div.style.posLeft = div.style.posLeft + step;	
	x = div.style.posLeft;	
	var div2 = document.getElementById('StartTable');
	var maxX = div.offsetWidth - div2.offsetWidth + 10;

	if (x < maxX) 
	{
		if (g_blnReverse && x == (maxX - 15)) 
			g_blnReverse = false;
			
		if (g_blnReverse && x > (maxX - 15)) 
			setTimeout("move(-1)", 3);
		else 
			setTimeout("move(1)", 6);
	}
	else 
	{
		if (!g_blnReverse && g_lngCounter == 0) 
		{
			g_blnReverse = true;
			setTimeout("move(-1)", 50);
			g_lngCounter ++;
		}
	}			
}

//----------------------------------------------------------------
//  Author:			Curt Knapp
//
//  Procedure Name:	ToggleOverlappingElements
//
//  Description:	    Toggles the current visibility status of certain HTML 
//						elements that currently overlap with a specified HTML
//						element
//
//  Arguments:			Element - the HTML element to use in the overlap test
//						Visibility - the visibility style setting to assign any
//									 HTML elements that currently overlap with
//									 the specified HTML element
//
//  Return Value:	    (none)
//
//  Comments:			Valid values for the Visibility parameter are "hidden"
//						or "visible".
//
//						This function is necessary because IE can not render 
//						elements over top of some form elements and ActiveX 
//						controls.  Namely, SELECT boxes and the MetaDraw control.
//----------------------------------------------------------------
function ToggleOverlappingElements(Element, Visibility) 
{
	var i = 0;
	var objField;
	//Change the visibility status of any elements that overlap the specified element
	if (document.forms.length > 0 ) {
		for (i=0; i < document.forms[0].length; i++) 
		{
			objField = document.forms[0].elements[i];
			if (((objField.type == "select-one") || 
				 (objField.type == "select-mutiple"))
				&& AreOverlapping(objField, Element)) 
					objField.style.visibility = Visibility;			
		}
	}
	
	objField = document.getElementById("ViewComponent");
	if (objField != null) 
	{
		if (Visibility == "visible") 
			objField.style.visibility = Visibility; 
		else if (AreOverlapping(objField, Element)) 	
			objField.style.visibility = Visibility;
	}
   
	objField = document.getElementById("CRViewer");
	if (objField != null) 
	{
		objField = document.getElementById("TableContent");
		if (Visibility == "visible") 
			//objField.style.visibility = Visibility;
			objField.style.display = "";
		else if (AreOverlapping(objField, Element)) 			
			//objField.style.visibility = Visibility;
			objField.style.display = "none";		
	}
}
//----------------------------------------------------------------
//  Author:			Brian Tauke
//  Procedure Name:	SetCookie
//  Description:	    Assigns a value to a specified browser cookie
//
//	 Arguments:			RootName - the name of the root cookie being assigned 
//						CrumbName - the name of the cookie "crumb" being assigned
//						Value - the value to be assigned to the cookie
//						[Expires] - the amount of time before the cookie will 
//									expire
//  Return Value:	    (none)
//
//  Comments:			If the specified cookie or crumb does not currently exist,
//						it will be created and assigned the given value.
//
//						The "Expires" parameter should use one of the following
//						formats:
//							S:n - the cookie will expire in "n" seconds
//							M:n - the cookie will expire in "n" minutes
//							H:n - the cookie will expire in "n" hours
//							D:n - the cookie will expire in "n" days
//
//						If a value for the "Expires" parameter is passed and the
//						cookie being stored is a "crumb", the new expiration
//						date specified will be applied to the entire cookie.
//						Therefore, if no expiration date is specified, the 
//						previous expiration date for the entire cookie will no
//						longer apply and the cookie will not have a specific
//						expiration date.
//----------------------------------------------------------------
function SetCookie(RootName, CrumbName, Value, Expires) 
{
	var strValue = "";
	var vntExpireValues = new Array;
	var strExpireUnits = "";
	var lngExpireAmount = 0;
	var dteExpires = new Date();
	var strOptions = "";
	var vntCookies = new Array;
	var lngRootCount = 0;
	var strCurrentCookie = "";
	var blnAssigned = false;
	var strCrumbString = "";
	var vntCrumbs = new Array;
	var lngCrumbCount = 0;
	var vntCookiePair = new Array;
	var blnCrumbFound = false;
	var strRootValue = "";

	//Format the cookie value to be assigned
	strValue = Value;
	strValue = Replace(strValue, "&", "%26");
	strValue = Replace(strValue, ";", "%3B");
	strValue = Replace(strValue, " ", "%20");

	//Initialize the expiration value
	if (Expires) 
	{
		vntExpireValues = Expires.split(":");
		strExpireUnits = vntExpireValues[0];
		lngExpireAmount = vntExpireValues[1];

		switch (strExpireUnits.toUpperCase()) 
		{
			case "S":
				dteExpires.setTime (dteExpires.getTime() + (1000 * lngExpireAmount));
				break;

			case "M":
				dteExpires.setTime (dteExpires.getTime() + (1000 * 60 * lngExpireAmount));
				break;

			case "H":
				dteExpires.setTime (dteExpires.getTime() + (1000 * 60 * 60 * lngExpireAmount));
				break;

			case "D":
				dteExpires.setTime (dteExpires.getTime() + (1000 * 60 * 60 * 24 * lngExpireAmount));
				break;
		}
		strOptions = ";expires=" + dteExpires.toGMTString() + ";path=/";
	}
	else 
	{
		strOptions = ";path=/";
	}

	//Loop through all cookies and locate the requested cookie
	vntCookies = document.cookie.split(";");
	for (lngRootCount=0; lngRootCount < vntCookies.length; lngRootCount++) 
	{
		strCurrentCookie = trim(vntCookies[lngRootCount]);

		//If the current root cookie is a name and level match, assign the new value
		if ((strCurrentCookie.substring(0, strCurrentCookie.indexOf("=")) == RootName) 
		 && (CrumbName == "")) 
		{
			document.cookie = RootName + "=" + strValue + strOptions;
			blnAssigned = true;
		}
		else 
		{
			//If a "crumb" is being assigned to a root cookie, determine if the current root cookie is the correct parent
			if ((strCurrentCookie.substring(0, strCurrentCookie.indexOf("=")) == RootName) 
				&& (CrumbName != "")) 
			{

				if (strCurrentCookie.indexOf("=") != strCurrentCookie.lastIndexOf("=")) 
				{
					//The current cookie contains "crumbs", locate and assign the requested "crumb"
					strCrumbString = strCurrentCookie.substring(strCurrentCookie.indexOf("=") + 1);
					vntCrumbs = strCrumbString.split("&");

					//Loop through all "crumbs" and locate the requested cookie
					for (lngCrumbCount=0; lngCrumbCount < vntCrumbs.length; lngCrumbCount++) 
					{
						vntCookiePair = vntCrumbs[lngCrumbCount].split("=");
						if (vntCookiePair[0] == CrumbName) 
						{
							vntCrumbs[lngCrumbCount] = CrumbName + "=" + strValue;
							blnCrumbFound = true;
							break;
						}
					} 
					//If the requested "crumb" was not found, assign the specified value to a new cookie "crumb"
					if (blnCrumbFound == false) 
					{
						vntCrumbs[vntCrumbs.length] = CrumbName + "=" + strValue;
					}

					//Assign the new crumb values to the root cookie
					for (lngCrumbCount=0; lngCrumbCount < vntCrumbs.length; lngCrumbCount++) 
					{
						strRootValue = strRootValue + "&" + vntCrumbs[lngCrumbCount];
					} 
					document.cookie = RootName + "=" + strRootValue.substring(1) + strOptions;
					blnAssigned = true;

				}
				else 
				{
					//The current cookie does not contain "crumbs", any previous singular value will be overwritten
					document.cookie = RootName + "=" + CrumbName + "=" + strValue + strOptions;
					blnAssigned = true;
				}
			}
		}
		//If the cookie was located and assigned, exit the loop
		if (blnAssigned == true) 
		{
			break;
		}
	}
	//If the cookie was not found, create and assign a new cookie
	if (blnAssigned == false) 
	{
		if (CrumbName == "") 
		{
			document.cookie = RootName + "=" + strValue + strOptions;
		}
		else 
		{
			document.cookie = RootName + "=" + CrumbName + "=" + strValue + strOptions;
		}
	}
}
//----------------------------------------------------------------
//  Author:			Brian Tauke
//
//  Procedure Name:	GetCookie
//
//  Description:	    Returns the value of a specified browser cookie
//
//  Arguments:			RootName - the name of the root cookie to be returned
//						[CrumbName] - the name of the "crumb" to be returned
//
//  Return Value:	    The value of a specified browser cookie
//
//  Comments:			(none)
//----------------------------------------------------------------
function GetCookie(RootName, CrumbName) 
{
	var strCookieValue = "";
	var vntCookies = new Array;
	var lngRootCount = 0;
	var strCurrentCookie = "";
	var strCrumbString = "";
	var vntCrumbs = new Array;
	var lngCrumbCount = 0;
	var vntCookiePair = "";
	var blnFound = false;
	
	//Initialize the RootName and CrumbName parameters
	RootName = RootName.toUpperCase();
	if (!CrumbName) 
		CrumbName = "";
	CrumbName = CrumbName.toUpperCase();

	//If the current page has cookies, parse the cookie string
	if (document.cookie.length > 0) 
	{
		vntCookies = document.cookie.split(";");

		//Loop through all cookies and locate the requested cookie
		for (lngRootCount=0; lngRootCount < vntCookies.length; lngRootCount++)
		{
			strCurrentCookie = trim(vntCookies[lngRootCount]);

			//If the current root cookie is a name and level match, return the value
			if ((unescape(strCurrentCookie.substring(0, strCurrentCookie.indexOf("="))).toUpperCase() == RootName) 
			   && (CrumbName == "")) 
			{
				strCookieValue = strCurrentCookie.substring(strCurrentCookie.indexOf("=") + 1);
				blnFound = true;
			}
			else 
			{
				//If a "crumb" is being requested, determine if the current root cookie is the correct parent 
				if ((unescape(strCurrentCookie.substring(0, strCurrentCookie.indexOf("="))).toUpperCase() == RootName) 
				  && (strCurrentCookie.indexOf("=") != strCurrentCookie.lastIndexOf("="))) 
				{
					strCrumbString = strCurrentCookie.substring(strCurrentCookie.indexOf("=") + 1);
					vntCrumbs = strCrumbString.split("&");

					//Loop through all "crumbs" and locate the requested cookie
					for (lngCrumbCount=0; lngCrumbCount < vntCrumbs.length; lngCrumbCount++) 
					{
						vntCookiePair = vntCrumbs[lngCrumbCount].split("=");
						if (unescape(vntCookiePair[0]).toUpperCase() == CrumbName) 
						{
							strCookieValue = vntCookiePair[1];
							blnFound = true;
							break;
						}
					} 
				}
			}

			//If the cookie was located, format the resulting value and exit the loop
			if (blnFound == true) 
			{
				strCookieValue = Replace(strCookieValue, "%0D%0A", "\r\n");
				strCookieValue = Replace(strCookieValue, "+", " ");	
				
				// RH
				// 9-11-2006
				// Localization - decodeURIComponent instead of unescape for login error messages.
				// unescape does not fully decode certain foreign language characters.
				if(RootName == "VALIDATIONERROR")
				{
					strCookieValue = decodeURIComponent(strCookieValue);
					break;
				}
					
				strCookieValue = unescape(strCookieValue);
				break;
			}
		}
	}
	//Return the resulting value
	return strCookieValue;
}

//----------------------------------------------------------------
//  Author:			Sally Xu
//  Procedure Name:	IsIE
//  Description:	    Determines whether or not the current browser is a 
//						version of Internet Explorer.
//  Return Value:	    A boolean value indicating whether or not the current
//						browser is a version of Internet Explorer.
//----------------------------------------------------------------
function IsIE() 
{
	var strAgent = window.navigator.userAgent;
	if (IsMac()) {
		// If it's the Mac, we only support Safari (even though this method is called IsIE())
		return (strAgent.indexOf("Safari") > 0 ? true: false);
	} else {	
		return (strAgent.indexOf("MSIE ") > 0 ? true: false);
	}
}
//----------------------------------------------------------------
//  Author:			Sally Xu
//  Procedure Name:	IsValidBrowser
//  Description:	Determines whether aprimomarketing support this browser
//----------------------------------------------------------------
function IsValidBrowser() 
{
	var strAgent = window.navigator.userAgent;
	if (IsMac()) // This will actually check for Safari
		return IsIE();
	else if (IsIE())
	{	
	    var lngIEIndex = strAgent.indexOf("MSIE ") + 5;
		var strVersion = strAgent.substring(lngIEIndex, strAgent.indexOf(";", lngIEIndex));
		var vntVersion = new Array();
		//Determine if the current browser meets the IE 6.0 minimum requirement
		vntVersion = strVersion.split(".");
		if (vntVersion[0] >= 5) 
			return true;			
		else 
			return false;	
		/*
		if (vntVersion[0] > 5) 
			return true;			
		if (vntVersion[0] < 5) 
			return false;	
		return (vntVersion[1].substring(0,1) >= 5 ? true: false);
		*/
	}	
	else
	{
		return false;
	}	
}

//----------------------------------------------------------------
//  Author:				Brian Tauke
//  Procedure Name:		IsMac
//  Description:	    Determines whether or not the current operating system
//						is a version of Macintosh OS.
//  Arguments:			(none)
//  Return Value:	    A boolean value indicating whether or not the current
//						operating system is a version of Macintosh OS.
//----------------------------------------------------------------
function IsMac() 
{
	var strAgent = window.navigator.userAgent;	
	if (strAgent.indexOf("Mac") > 0 && strAgent.indexOf("Firefox") == -1)
		return true;
	else
		return false;
	//return (strAgent.indexOf("Mac") > 0 ? true: false);
}

var whitespace = "\n\r\t ";
var quotes = "\"'";

function isEmpty(str) {    
    return (str==null) || (str.length==0);

} 


//----------------------------------------------------------------
//  Author:				Fred Kenowski
//  Procedure Name:		IsSafari3
//  Description:	    Determines whether or not the current browser
//						is Safari 3
//  Arguments:			(none)
//  Return Value:	    A boolean value indicating whether or not the current
//						browser is Safari 3.
//----------------------------------------------------------------
function IsSafari3() 
{
	var strAgent = window.navigator.userAgent.toUpperCase();

    var x = strAgent.indexOf("SAFARI");
    var y = strAgent.indexOf("VERSION/3");
         
    if (x > y && y >= 0)
    {
        return true;
    }
    else
    {
        return false;
    }	
} 

//----------------------------------------------------------------
//  Author:			Sally Xu
//  Procedure Name:	trim
//  Description:	Trim off white space from string's both end
//----------------------------------------------------------------
function trim(trimString, leftTrim, rightTrim) {    
    if (isEmpty(trimString)) {
        return "";
    }

    // the general focus here is on minimal method calls - hence only one
    // substring is done to complete the trim.

    if (leftTrim == null) {
        leftTrim = true;
    }

    if (rightTrim == null) {
        rightTrim = true;
    }

    var left=0;
    var right=0;
    var i=0;
    var k=0;

    // modified to properly handle strings that are all whitespace
    if (leftTrim == true) {
        while ((i<trimString.length) && (whitespace.indexOf(trimString.charAt(i++))!=-1)) {
            left++;
        }
    }
    if (rightTrim == true) {
        k=trimString.length-1;
        while((k>=left) && (whitespace.indexOf(trimString.charAt(k--))!=-1)) {
            right++;
        }
    }
    return trimString.substring(left, trimString.length - right);
} 

//----------------------------------------------------------------
//  Author:			Sally Xu
//  Procedure Name:	Replace
//  Description:	    Returns a string in which a specified substring has 
//						been replaced with another string
//  Arguments:			Expression - the string expression containing the 
//									 substring to replace
//						Old - the substring to search for
//						New - the replacement string to use
//  Return Value:	    A copy of the Expression string with all occurences of
//						the Find substring replaced with the ReplaceWith string
//  Comments:			(none)
//----------------------------------------------------------------
function Replace(Expression, Old, New) 
{
	var x;
	//If one of the function parameters is missing or empty, return an empty string 
	if (!Expression || Expression == "") 
		return "";
	if (Old == New || (!Old || Old == ""))
		return Expression;	
	var newExp = "";
	var tempExp = Expression+"";
	x = tempExp.indexOf(Old);
	while(x >= 0) 
	{					
		newExp += tempExp.substring(0, x) + New;
		tempExp = tempExp.substring(x + Old.length);
		x = tempExp.indexOf(Old);								
	}
	if(tempExp.length> 0)
		newExp += tempExp;
	return newExp;
}

//----------------------------------------------------------------
//  Author:			Brian Tauke
//
//  Procedure Name:	ShowSection
//
//  Description:	    Makes an HTML element visible to the user
//
//  Arguments:			Element - the HTML element to show
//
//  Return Value:	    (none)
//
//  Comments:			(none)
//----------------------------------------------------------------
function ShowSection(field) {
	if(typeof(field) != "object") //it is an ID
		field = document.getElementById(field);
	
	if(field == null)
		return;
		
	field.style.display = "";
}

function ShowControl(controlID) {
	// Show the Label and Value Controls
	var tblLabel = document.getElementById("tblLabel_" + controlID);
	var tblValue = document.getElementById("tblValue_" + controlID);
	
	if (tblLabel)
		tblLabel.style.display = "";
	
	if (tblValue)
		tblValue.style.display = "";
}

function HideControl(controlID) {
	// Show the Label and Value Controls
	var tblLabel = document.getElementById("tblLabel_" + controlID);
	var tblValue = document.getElementById("tblValue_" + controlID);
	
	if (tblLabel)
		tblLabel.style.display = "none";
	
	if (tblValue)
		tblValue.style.display = "none";
}
//----------------------------------------------------------------
//  Author:			Brian Tauke
//
//  Procedure Name:	HideSection
//
//  Description:	    Makes an HTML element invisible to the user
//
//  Arguments:			Element - the HTML element to hide
//
//  Return Value:	    (none)
//
//  Comments:			(none)
//----------------------------------------------------------------
function HideSection(field) {
	if(typeof(field) != "object") //it is an ID
		field = document.getElementById(field);
	
	if(field == null)
		return;
		
	field.style.display = "none";
}

//----------------------------------------------------------------
//  Author:			Brian Tauke
//  Procedure Name:	ShowDetailSection
//
//  Description:	    Dynamically changes a page to show either the HTML 
//						contained in a single DIV tag, or all HTML contained
//						in a range of DIV tags.
//
//  Arguments:			DivID - the ID of the HTML section to be shown
//						IndexID - the ID of the index tab item that corresponds
//								  with the HTML section to be shown
//						PageTitleID - the Replacement String ID of the page title
//						ParentObjectID - the ID of the parent object for the page
//						[ChangeCookieOnly] - a boolean value indicating whether or 
//										     not only the cookie value should be changed
//
//  Return Value:	    (none)
//
//  Comments:			This function supports the BuildIndexTab() function in
//						Aprimo_Web.bas.
//
//						The DIV tag that is used to display the currently selected 
//						information on the page is named "Table_0".  DIV tags 
//						"Table_1" through "Table_12" are used to store all of 
//						the eligible HTML sections that can be displayed.
//
//						To show all HTML contained in all DIV tags, a value of 
//						"Table_0" should be passed for DivID.
//
//						The name of the cookie used to store the currently visible
//						section of a page has the following format:
//							("Aprimo")("Index_" + PageTitleID).
//
//						The value of the cookie used to store the currently visible
//						section of a page has the following format:
//							ParentObjectID * DivID : IndexID
//----------------------------------------------------------------
function ShowDetailSection(DivID, IndexID, PageTitleID, ParentObjectID, ChangeCookieOnly) 
{

	var i = 0;
	var objTable;
	var strHTML = "";
	var j = 0;
	var objTabIndex;
	var objCell;
	var strTableID = "";
	var strIndexID = "";

	//Initialize the ChangeCookieOnly parameter
	if (!ChangeCookieOnly) 
		ChangeCookieOnly = false;

	//Dynamically change the page to show the specified section
	if (ChangeCookieOnly == false) 
	{
		if (DivID == "Table_0") 
		{			
			for(var i=1; i <= 12; i++) 				
				ShowSection("Table_" + i);							
		}
		else 
		{			
			for(var i=0; i <= 12; i++) 
			{	
				var tableID = "Table_" + i;				
				if(tableID != DivID)		
					HideSection(tableID);
			}
			ShowSection(DivID);			
		}
		//Reflect the currently selected section in the index tab
		for (var j=0; j <= 12; j++) 
		{
			objTabIndex = document.getElementById("TabIndex_" + j);
			if (objTabIndex) 
			{
				if (objTabIndex.className != "TabIndexItemDisabled") 
				{
					objTabIndex.className = "TabIndexItemOff";
				}
			}
		}
		objCell = document.getElementById(IndexID);
		el_setCssClass(objCell, "TabIndexItemOn");
	}
	//Update the value of the cookie to preserve section context for this parent object
	if (PageTitleID) 
	{
		strTableID = DivID.substring(DivID.indexOf('_') + 1);
		strIndexID = IndexID.substring(IndexID.indexOf('_') + 1);
		SetCookie('AprimoViewPageData', 'Index_' + PageTitleID, ParentObjectID + '*' + strTableID + ':' + strIndexID);
	}
}


//----------------------------------------------------------------
//  Author:			Matt Kelsey
//
//  Procedure Name:	HeaderPageCommonOnLoad
//
//  Description:	    Performs standard page initialization functions for those that inherit from headerPage template
//
//  Arguments:			(none)
//
//  Return Value:	    (none)
//
//  Comments:			This function should be called upon page load of any
//						page that uses the "Main.htm" template.
//
//						Page specific processing that needs to be executed
//						automatically upon page load should be included in a
//						local function named "InitializePage()".
//----------------------------------------------------------------
function HeaderPageCommonOnLoad()
{
	if (IsMac())
		ValidatorOnLoad();
	//Call the local page initialization function, if it exists
	if (window.initializepage!= null) 
		initializepage();
	if (window.InitializePage!= null) 
		InitializePage();
}
//----------------------------------------------------------------
//  Author:			Brian Tauke
//  Procedure Name:	CommonOnLoad
//  Description:	Performs standard page initialization functions
//----------------------------------------------------------------
function CommonOnLoad() 
{	
	//This flag determines if we should reset all control default values
	var blnResetDefaults = false;
	if (window.top.WindowBar)
	{
		var w = window.top.WindowBar.GetWindow(LocalWindowName);
		if (w != null)
			w.AddTrace('In CommonOnLoad()');
	} 
	// Scroll the Selected NavItem into View
	ScrollSelectedNavItem();
	if (IsMac())
		ValidatorOnLoad();
	if (GetCookie('Aprimo', 'ResetViewPageData') == 'Yes') 
		SetCookie('AprimoViewPageData', '', '');
	ObjectManager.OnInit();	
	windowManager.OnInit();// Call OnInit for the window manager
	// Make sure the scrollable regions are synched up
	MaintainTableWidths();						
	//Call the local page initialization function, if it exists
	if(window.initializepage != null) 
	{
		initializepage();
		blnResetDefaults = true;
	}
	if(window.InitializePage != null) 
	{
		InitializePage();
		blnResetDefaults = true;
	}
	
	//If Initializepage was called, reset the page's default values 
	//In case the controls changed programmatically
	if(blnResetDefaults)
	{
		ObjectManager.ResetDefaults();
	}

	var ErrorMsg = GetCookie("ValidationError");
	SetCookie("ValidationError", "", "")
	if(ErrorMsg)
		popMessage(ErrorMsg);
	// if popUrl is given, popup another window with that url
	var popUrl = GetCookie("popUrl");
	SetCookie("popUrl", "", "")
	if(popUrl.toLowerCase().indexOf("executivedashboard") > -1)
		openDashboardWindow(popUrl);
	else if(popUrl)
		GoToURL(popUrl, "PopURL", true);
		
}

function ScrollSelectedNavItem()
{
	if (!IsMac()) {
		if (window.selectedNavItemID && window.selectedNavItemID != "") {
			var selectedTR = document.getElementById("trOuter" + window.selectedNavItemID);			
			if (selectedTR) {
				// Determine if the item is visible				
				var objContainer = document.getElementById("NavColDIV");
				if(objContainer) {				
					// Only scroll if necessary					
					if (Position(objContainer, "BOTTOM") <  Position(selectedTR, "TOP")) {				
						// Get a handle to the parentTable of this TR (two parentNodes, because of TBODY)
						var parentTable = selectedTR.parentNode.parentNode;			
						if (parentTable) {
							// Get a handle to the previous sibling, which is the header table
							var headerTable = parentTable.previousSibling;
							if (headerTable) {
								objContainer.scrollTop = headerTable.offsetTop;
							}	
						}	
					}
				}	
			}	
		}
	}	
}
function CommonOnUnload() 
{
	if(window.unloadpage)
		unloadpage();
	if(window.UnLoadPage)
		UnLoadPage();
	ObjectManager.OnUnLoad();// Call OnUnLoad() for each javascript registered object
	if( (window.opener != null) && (!window.opener.closed) && (window.opener.Modal != null))
	{
		if(window.opener.Modal.name == window.name)			
			window.opener.Modal = null;	
	}
	windowManager.OnUnLoad();//Call OnUnLoad for the window manager
}
//DO NOT REMOVE - MJK
function HeaderPageCommonOnUnload() 
{
	if(window.unloadpage)
		unloadpage();
	if(window.UnLoadPage)
		UnLoadPage();
}
//----------------------------------------------------------------
//  Author:			Brian Tauke
//  Procedure Name:	CommonOnLoadSub
//  Description:	    Performs standard page initialization functions
//  Arguments:			(none)
//  Return Value:	    (none)
//  Comments:			This function should be called upon page load of any
//						page that uses the "MainSub.htm" template.
//						Page specific processing that needs to be executed
//						automatically upon page load should be included in a
//						local function named "InitializePage()".
//----------------------------------------------------------------
function CommonOnLoadSub() 
{
	if (IsMac())
		ValidatorOnLoad();
	
	//Call the local page initialization function, if it exists
	if (window.initializepage != null) 
		initializepage();

	if (window.InitializePage != null) 
		InitializePage();
	
	LoadFocus();

	var objCalendarFrame = document.getElementById("CalendarFrame");
	if (objCalendarFrame) 
	{
		objCalendarFrame.src = RelativePath + "Common/Calendar_" + GetCookie(g_LoginCookieName, "LanguageID") + ".htm";
	}	
}

//----------------------------------------------------------------
//  Author:			Scott Dafforn
//  Procedure Name:	LoadFocus
//  Description:	    Gives page focus to the first enabled, non-hidden HTML
//						form field on the page
//  Arguments:			(none)
//  Return Value:	    (none)
//  Comments:			This function should be called upon page load for all
//						pages containing an input form.
//						If a page contains more than one input form, focus will 
//						be given to the first valid field in the first input form.
//----------------------------------------------------------------
function LoadFocus() 
{
	var i = 0;
	var objField;
	var blnNoAutoFocus = "false";
	var blnSkipFocus = false;
	
	if (window.top.WindowBar && window.LocalWindowName)
	{
		var thisWin = window.top.WindowBar.GetWindow(window.LocalWindowName);
		if (!thisWin)
			blnSkipFocus = true;
		else	
			blnSkipFocus = thisWin.IsMinimized;
	}
	if (!blnSkipFocus)
	{
		//Give page focus to the first eligible form field on the page
		if (document.forms.length > 0) 
		{
			for (i=0; i < document.forms[0].length; i++) 
			{
				objField = document.forms[0].elements[i];
				if ((objField.type != "hidden") && (objField.disabled != true) && (objField.noautofocus != "true") && 
						(!IsHidden(objField)) && !IsDisabled(objField) && objField.tagName.toLowerCase() != "object") 
				{
					try
					{
						objField.focus();
						return;
					}
					catch(e){}
				}
			}
		}
	}
}


//----------------------------------------------------------------
//  Author:			Brian Tauke
//  Procedure Name:	IsHidden
//  Description:	    Determines whether or not an HTML element is currently
//						hidden
//  Arguments:			Element - the HTML element to be tested
//  Return Value:	    A boolean value indicating whether or not the HTML
//						element is currently hidden
//
//  Comments:			This function currently evaluates only those HTML
//						elements that are of the following tag names:
//							<DIV>
//							<TABLE>
//							<SPAN>
//----------------------------------------------------------------
function IsHidden(Element) 
{
	//If the display value is set to "none" or visibility == hidden for a valid tag name, return true
	if (Element.style.display == "none" || Element.style.visibility == "hidden")
	{
		return true;
	}
	else 
	{
		//Traverse the parent heirarchy to determine the visibility status
		if (IsMac()) {
			if (!Element.parentNode)
				return false;
			else if (Element.parentNode.tagName == "HTML")
				return false;
			else	
				return IsHidden(Element.parentNode);
		}
		else
			return (Element.parentElement ? (IsHidden(Element.parentElement)) : false);
	}
}

//----------------------------------------------------------------
//  Author:			Brian Tauke
//  Procedure Name:	IsHidden
//  Description:	    Determines whether or not an HTML element is currently
//						disabled
//  Arguments:			Element - the HTML element to be tested
//  Return Value:	    A boolean value indicating whether or not the HTML
//						element is currently disabled
//
//  Comments:			This function currently evaluates only those HTML
//						elements that are of the following tag names:
//							<DIV>
//							<TABLE>
//							<SPAN>
//							<TR>
//							<TD>
//----------------------------------------------------------------
function IsDisabled(Element) 
{
	//If diabled is true for a valid tag name, return true
	if ((Element.tagName == "DIV" || Element.tagName == "TABLE" || Element.tagName == "SPAN"
		 || Element.tagName == "TR" || Element.tagName == "TD") && 
		(Element.disabled)) 
	{
		return true;
	}
	else 
	{
		//Traverse the parent heirarchy to determine the disability status
		return (Element.parentElement ? (IsDisabled(Element.parentElement)) : false);
	}
}


//----------------------------------------------------------------
//  Author:			Sally Xu
//  Procedure Name:	ChangeClass
//  Description:	    Changes the style sheet class of a given HTML element to
//						a new class
//  Arguments:			Element - the HTML element to be assigned a new class
//						NewClass - the new class to be assigned
//  Return Value:	    (none)
//  Comments:			(none)
//----------------------------------------------------------------
function ChangeClass(Element, NewClass) 
{
	if (Element) {
		if (Element.className) {
			Element.className = NewClass;
		}
	}
}

//----------------------------------------------------------------
//  Author:			Sally Xu
//  Procedure Name:	PrintPage
//  Description:	    Opens a secondary browser window to allow the user to 
//					    print the contents of the current window
//  Arguments:			(none)
//  Return Value:	    (none)
//  Comments:			The secondary browser window will load the MainPrint.htm 
//						page which contains the logic needed to format and print 
//						the contents of the current window.  The formatting will
//						prevent unnecessary items from being displayed on the
//						printout (ie: Navigation Column) by commenting out any
//						HTML that is wrapped in "<!-- BPE -->" and "<!-- EPE -->"
//						tags.  These stand for "Begin Print Exclusion" and "End
//						Print Exclusion" respectively.
//----------------------------------------------------------------
function PrintPage() 
{
	if (IsMac()) {
		var strURL = document.URL;
		// Add on the MacPrint parameter
		if (strURL.indexOf("?") >= 0)
			strURL += "&MacPrint=1";
		else
			strURL += "?MacPrint=1";
		openWindow(window.RelativePath + "MacPrint.htm", "Print", 600, 400);
	}
	else {	
		//openWindow(window.RelativePath + "Print.htm", "Print", 600, 400);
		openWindow(window.RelativePath + "Print.aspx", "Print", 600, 400);
	}
}
//----------------------------------------------------------------
//  Author:			Brian Tauke
//  Procedure Name:	Export
//  Description:	    Opens a secondary browser window to allow the user to 
//					    export the current data if there are 50,000 or less 
//						matching records
//
//  Arguments:			URL - the URL of the Export page to be opened in the 
//							  secondary browser window
//
//  Return Value:	    (none)
//
//  Comments:			This function refers to the global JavaScript variable
//						"TotalRecords", which is written to the page by the 
//						HTML_DisplayListObsInfo function in Aprimo_Web.bas.
//----------------------------------------------------------------
function Export(URL) 
{
	if (isNaN(TotalRecords)) 
		//You may not Export data from this page.
		alert(JSResourceID535);
	else 
	{
		if (TotalRecords == 0) //There are no matching records to Export.			
			alert(JSResourceID537);
		else  //Open the secondary Export window			
			openWindow(URL, "Export", 800, 500, "scroll=auto,menubar=yes");		
	}
}
//----------------------------------------------------------------
//  Author:			Sally Xu
//  Procedure Name:	AreOverlapping
//  Description:	    Determines whether or not two HTML elements are 
//						currently overlapping
//  Arguments:			Element1 - the first HTML element to be tested
//						Element2 - the second HTML element to be tested
//  Return Value:	    A boolean value indicating whether or not the two HTML
//						elements are currently overlapping
//----------------------------------------------------------------
function AreOverlapping(Element1, Element2) 
{
	//If any overlapping points can be found between the two elements, return true
	if (Position(Element1, "LEFT") >= Position(Element2, "LEFT") &&
		Position(Element1, "LEFT") <= Position(Element2, "RIGHT") &&
		Position(Element1, "TOP") >= Position(Element2, "TOP") &&
		Position(Element1, "TOP") <= Position(Element2, "BOTTOM"))
		return true;
	
	if (Position(Element1, "LEFT") >= Position(Element2, "LEFT") &&
		Position(Element1, "LEFT") <= Position(Element2, "RIGHT") &&
		Position(Element1, "BOTTOM") >= Position(Element2, "TOP") &&
		Position(Element1, "BOTTOM") <= Position(Element2, "BOTTOM")) 
		return true;
			
	if (Position(Element2, "LEFT") >= Position(Element1, "LEFT") &&
		Position(Element2, "LEFT") <= Position(Element1, "RIGHT") &&
		Position(Element2, "TOP") >= Position(Element1, "TOP") &&
		Position(Element2, "TOP") <= Position(Element1, "BOTTOM")) 
		return true;

	if (Position(Element2, "LEFT") >= Position(Element1, "LEFT") &&
		Position(Element2, "LEFT") <= Position(Element1, "RIGHT") &&
		Position(Element2, "BOTTOM") >= Position(Element1, "TOP") &&
		Position(Element2, "BOTTOM") <= Position(Element1, "BOTTOM")) 
		return true;
	//If no overlapping points have been found between the two elements, return false
	return false;
}

//----------------------------------------------------------------
//  Author:			Sally Xu
//  Procedure Name:	Position
//  Description:	    Returns an absolute position measurement for a given 
//						HTML element
//  Arguments:			Element - the HTML element to be measured
//						Measurement - the name of the absolute position 
//									  measurement to be returned
//
//  Return Value:	    An absolute postion measurement for the given HTML element
//
//  Comments:			The Measurement argument should be one of the following:
//						"LEFT", "TOP", "RIGHT", "BOTTOM"
//----------------------------------------------------------------
function Position(Element, Measurement) 
{
	//Return the appropriate absolute position measurement
	switch (Measurement.toUpperCase()) 
	{
		case "LEFT":
			var lngLeft = (Element.offsetParent ? (Position(Element.offsetParent, "LEFT") + Element.offsetLeft) : Element.offsetLeft) - Element.scrollLeft;
			if( Element.nodeName == 'BODY')
				return ( lngLeft > 0 ? lngLeft : 0);
			else
				return lngLeft;
			break;

		case "TOP":
			var lngTop = (Element.offsetParent ? (Position(Element.offsetParent, "TOP") + Element.offsetTop) : Element.offsetTop) - Element.scrollTop;
			if( Element.nodeName == 'BODY')
				return ( lngTop > 0 ? lngTop : 0);
			else
				return lngTop;
			break;

		case "RIGHT":
			var lngLeft = (Element.offsetParent ? (Position(Element.offsetParent, "LEFT") + Element.offsetLeft) : Element.offsetLeft) - Element.scrollLeft;
			return lngLeft + Element.offsetWidth;
			break;

		case "BOTTOM":
			var lngTop = (Element.offsetParent ? (Position(Element.offsetParent, "TOP") + Element.offsetTop) : Element.offsetTop) - Element.scrollTop;
			return lngTop + Element.offsetHeight;
			break;
	}
}

//------------------------------------------------------------------------------
//  Author:		Curt Knapp
//  Procedure Name:	EncodedTitle_Edit
//  Description:	Opens a pop-up window for the user so an encoded title can 
//				be added/edited
//  Arguments:		titleField - the name of the HTML form field that will contain the
//							selected date
//  Return Value:	(none)
//  Comments:		The ID of the encoded title that the user selects will
//				automatically be stored in the specified form field.  This 
//				function assumes that the form field in question has a populated 
//				RelativePath attribute that represents the relative path of the HTML
//				document that contains the form field in question.
//------------------------------------------------------------------------------
function EncodedTitle_Edit(titleField, type, EncodedTitleID)	
{	
	var args = "";
	args = "?FieldID=" + titleField.id + "&Type=" + type + "&EncodedTitleID=" + EncodedTitleID;
	// Encode the Value
	var value = Replace(Replace(Replace(Replace(titleField.value, " ", "%20"), "&", "~~@~~"), "+","@@~@@"), ",", "!!^!!");
	args += "&Value=" + value;
		
	openWindow(RelativePath + "Common/EncodedTitles/EncodedTitleAddEdit.aspx" + args, "EncodedTitle60", 600, 400, "", false);
}
/* Menu Object by Sally Xu */
function Menu(ID, SubItems, IsPopup, Style, Build)
{
	this.id = ID;			
	this.menuitems = SubItems;
	this.IsPopup = IsPopup;
	this.Style = Style;		
	if(Build)
		this.Build();		
}
Menu.Clone = function(ID, SubItems, IsPopup, Style)
{
	if(SubItems == null)
	{					
		if(document.reloadPending == null)
		{	
			SetCookie(g_SessionCookieName, "cachem",null);	
			document.reloadPending = true;
			RefreshPage();	
		}
		return null;
	}
	var m = new Menu(ID, null, IsPopup, Style);	
	m.menuitems = new Array();
	for(var i = 0; i < SubItems.length; i++)
	{ 
		var mi = SubItems[i];
		m.menuitems[i] = new MI(mi.id, mi.text, mi.url, mi.childID, mi.childAlignment, mi.status, mi.toolTip, mi.imgURL, mi.disabledToolTip);
	}
	if(!IsPopup)
		m.Build();
	return m;	
}
Menu.prototype.FindMenuItemByTitle = function(text)
{
	for(var i=0; i<this.menuitems.length; i++)
		if(this.menuitems[i].text == text)
			return this.menuitems[i];
}
/* Needed to find Toolbar Items w/out Titles */
Menu.prototype.FindMenuItemByToolTip = function(toolTip)
{
	for(var i=0; i<this.menuitems.length; i++)
		if(this.menuitems[i].toolTip == toolTip)
			return this.menuitems[i];
}
Menu.prototype.AddAt = function(mi, index)
{
	var a1 = this.menuitems.slice(0, index);	
	var a2 = this.menuitems.slice(index);
	a1.push(mi);
	this.menuitems = a1.concat(a2);
	this.Build();
}
Menu.prototype.RemoveAt = function(index)
{
	var a1 = this.menuitems.slice(0, index);	
	var a2 = this.menuitems.slice(index);
	a2.shift();
	this.menuitems = a1.concat(a2);
	this.Build();
}
Menu.prototype.AddHtmlItemAt = function(html, index,id)
{
	var mi = new MI(id);
	mi.html = html;
	this.AddAt(mi, index);
}
Menu.prototype.Build = function()
{
	var sText= ""
	if(this.Style == "NavCol" && !this.IsPopup)
		sText += "<table cellpadding=0 cellspacing=0 width=100% class='NavGroup' ";
	else
		sText += "<table cellpadding=0 cellspacing=0 id='" + this.id + "Table' class='" + this.Style + "'";		
	if(this.Style == "TopMenu" || this.Style == "ToolBar" || this.Style == "ActionMenu")	 
		sText += " width=100% height=100%";		
	sText +=">";
	if(this.Style == "TopMenu" || this.Style == "ToolBar" || this.Style == "ActionMenu")
	{
		sText +="<tr";
		if(this.Style == "TopMenu")
			sText +=" height=25";
		sText +=">";
	}
	if(this.Style == "ToolBar")
		sText +="<td><table class=ToolbarTable width=100% cellspacing=0><tr>";
	for(var i =0; i < this.menuitems.length; i++)
	{		
		var menuItem = this.menuitems[i];
		if(this.Tokens)
			menuItem.DeToken(this.Tokens);		
		menuItem.menuID = this.id;
		if(menuItem.status == "disabled" && menuItem.imgURL.indexOf("_dis.") < 0)
			menuItem.imgURL = Replace(menuItem.imgURL, ".", "_dis.")
		if(menuItem.status == "" && menuItem.imgURL.indexOf("_dis.") > 0)
			menuItem.imgURL = Replace(menuItem.imgURL, "_dis.", ".");
					
		if(this.Style == "TopMenu" || this.Style == "ToolBar"  || this.Style == "ActionMenu")	
			sText += menuItem.RenderInCell(this.Style);
		if(this.Style == "ToolBar" && i < this.menuitems.length - 1)
			sText += "<td><img src='images/vertical.gif' width=1 height=16></td>";					
		if(this.Style=="PopupMenu" || this.Style=="NavCol")				
			sText += menuItem.RenderInRow(this.Style, this.IsPopup);								
	}	
	if(this.Style == "TopMenu" || this.Style == "ActionMenu")
	{		
		sText +="<td width=99%><img src='images/invisible.gif'></td>";
		sText +="</tr>";
	}
	if(this.Style == "ToolBar")
		sText += "<td width=99%><img src='images/invisible.gif'></td></tr></table></td></tr>";		
	sText += "</table>";	
	if(!this.IsPopup)//Non popup menu
	{	
		var div = document.getElementById(this.id + "Div");	
		if(div)		
			div.innerHTML = sText;						
		return;
	}
	var doc = GetParentWindowDoc();
	var tempDiv = doc.getElementById("TempDiv");
	if(tempDiv == null)
	{
		tempDiv = doc.createElement("DIV");
		tempDiv.style.position="absolute";
		el_setSize(tempDiv, 1, 1);
		tempDiv.id = "TempDiv";	
		tempDiv.style.visibility = "hidden";
		doc.body.appendChild(tempDiv,null);	
	}					
	tempDiv.innerHTML = sText;
	
	var objTable = doc.getElementById(this.id + "Table");	
	if (this.Style == "NavCol")	
		buildFrame(this.id, sText, objTable.offsetWidth, objTable.offsetHeight, true);	
	else		
		buildFrame(this.id, sText,objTable.offsetWidth, objTable.offsetHeight, false);
	tempDiv.innerHTML = "";
	this.built = true;
	return; 			
}
/* End Menu Object by Sally Xu */
function buildFrame(ID, Content, Width, Height, AutoHide)
{
	var doc = GetParentWindowDoc();	
	var Frame = doc.getElementById(ID + "Frame");
	
	if(IsMac()) {
		Width += 30;	
	}

	if(Frame)
	{
		Frame.style.width= Width;
		Frame.style.height = Height;
		if (bIsIE()) 	
			Frame = doc.frames[ID + "Frame"];
	}
	else
		Frame = CreateFrame(ID + "Frame", doc, Width, Height, AutoHide);
	var strHeading = doc.getElementById("PageHeadInfo").innerHTML;
	strHeading = "<HEAD id='PageHeadInfo'>" + strHeading + "</HEAD>";				
	if(IsMac()) {
		var contentDoc = GetContentDocumentMac(Frame);
		contentDoc.open();	
		contentDoc.write("<html>" + strHeading + "<body class='FrameBody' id='" + ID + "body'>" + Content + "</body></html>");
		contentDoc.close();		
	}
	else
	{
		Frame.document.open();	
		Frame.document.write("<html>" + strHeading + "<body class='FrameBody' id='" + ID + "body'>" + Content + "</body></html>");				
		Frame.document.close();
	}
	return doc.getElementById(ID + "Frame");
}

function GetContentDocumentMac(IFrameObj)
{
	if (IFrameObj.contentDocument) {
		return IFrameObj.contentDocument;
	}
	else {
		return IFrameObj.contentWindow.document;  
	}
}

function GetParentWindowDoc()
{
	var doc = document;		
	while(doc.body.id !="pagebody")
		doc = parent.document;
	return doc;
}
/*MunuItem Object - SXU*/
function NavGroup(ID, Text, ImgURL)
{
	this.base = MI;
	this.base(ID, Text, null, null, null, null, null, ImgURL);
	this.base = null;
}

function MI(ID, Text, URL, ChildMenuID, ChildAlignment, Status, ToolTip, ImgURL, DisabledToolTip)
{	
	this.id = ID;	
	this.text = Text!=null?Text:"";
	this.url = URL!=null?URL:"";	
	this.status = Status;
	this.toolTip = ToolTip!=null?ToolTip:"";	
	this.imgURL = ImgURL!=null?ImgURL:"";	
	this.disabledToolTip = DisabledToolTip!=null?DisabledToolTip:"";		
	this.childID = ChildMenuID;	
	this.childAlignment = ChildAlignment;				
}
MI.prototype.DeToken = function(Tokens)
{
	if(this.text0 == null)
	{
		if(this.text==null)
			this.text0 = "";
		else
			this.text0 = this.text;
		this.url0 = this.url;
		this.status0 = this.status;
		this.toolTip0 = this.toolTip;
		this.disabledToolTip0 = this.disabledToolTip;		
	}
	else
	{
		this.text = this.text0;
		this.url = this.url0;
		this.status = this.status0;
		this.toolTip = this.toolTip0;
		this.disabledToolTip = this.disabledToolTip0;
	}
	for(var i = 0; i < Tokens.length; i++)							
	{							
		this.text = Replace(this.text, "[TK_" + i +"]", Tokens[i]);	
		this.url = Replace(this.url, "[TK_" + i +"]", Tokens[i]);
		this.status = Replace(this.status, "[TK_" + i +"]", Tokens[i]);	
		this.toolTip = Replace(this.toolTip, "[TK_" + i +"]", Tokens[i]);				
		this.disabledToolTip = Replace(this.disabledToolTip, "[TK_" + i +"]", Tokens[i]);	
	}
}
MI.prototype.RenderInRow = function(Style, IsPopup)
{
	if(this.html)
	   return this.html;
	   
	var sText = "";	
	var MenuOnStyle = Style + "On";
	var MenuOffStyle = Style + "Off";
	var MenuImg = Style + "Img";
	var MenuText = Style + "Text";	
	if(Style == "NavCol" && this.status == "selected"||this.id ==window.selectedNavItemID)
		MenuOffStyle = Style + "Selected";
		
	var toolTip = this.toolTip;
	if(this.status == "disabled" && this.disabledToolTip)
		toolTip = this.disabledToolTip;	
	if(trim(this.text) == "")// separator	
	{	
		sText += "<tr height=1>" ;
		if(Style == "NavCol")
			sText += "<td colspan=2 height=1 class=ManuBreak></td>";
		else
			sText += "<td class='" + MenuImg + "'></td><td height=1 class=ManuBreak></td>";
		sText += "</tr>" ;		
	}
	else if(this.status == "header") // navcol header	
	{	
		sText += "<tr>" ;
		sText += "<td class='NavHeaderImg'><img src='" + this.imgURL + "' style='border-width:0px;height:16px;width:16px;' align=middle /></td><td class='NavHeader' width=99%>" + this.text + "</td>";
		sText += "</tr>" ;	
	}
	else //menu item
	{										
		sText += "<tr height=16 class=" + MenuOffStyle;		
		if (this.status == "disabled")
			sText += " isDisabled='true'";			
		if(this.childID && this.status != "disabled")
		{			
			sText += " OnMouseOver='this.className =\"" + MenuOnStyle + "\"';" 
			sText += " OnMouseOut='this.className=\"" + MenuOffStyle + "\"'";			
		}
		else if(this.status != "disabled")
		{
			sText += " OnMouseOver='FixUpMenus(\"" + this.childID + "\", \"" + this.menuID + "\");this.className =\"" + MenuOnStyle + "\";'" 
			sText += " OnMouseOut='this.className=\"" + MenuOffStyle + "\";'";								
		}									
		if(this.url && trim(this.url) !="" && this.status != "disabled")
		{				
			// Put in the Replace Code to handle single and double quotes in menu URLs -- CAK			
			sText += " onClick='HideMenuTree(\"" + this.menuID + "\");"
			if(IsPopup)
				sText +="parent.";
			sText += this.url.replace("\'", "&#39;").replace("\"", "&#34;").replace("javascript:", "").replace("vbscript:", "") + "'";			
		}			
		sText += ">";	
		
		sText += "<td align=center valign=middle class='" + MenuImg + "'";
		if(Style == "PopupMenu")
			sText += " width=16>"
		else
			sText += ">"
		
		if(this.imgURL && this.imgURL !="")
		{
			if(this.imgURL.indexOf("dot_s") > 0)
				sText += "<img width=10 height=13 src='" + this.imgURL + "' alt=\"" + toolTip + "\" /></td>";	
			else
				sText += "<img width=16 height=16 src='" + this.imgURL + "' alt=\"" + toolTip + "\" /></td>";		
		}
		else
		{
			sText += "<img src='images/invisible.gif' width=10 height=10></td>";
		}
									
		sText += "<td width=99%>";
		sText += "<table border=0 cellpadding=0 cellspacing=0 width=100% height=100% ";			
		if(this.childID && this.status != "disabled")
		{			
			sText += " OnMouseOver='ShowMenu(\"" + this.childID + "\", this, \"" + this.childAlignment + "\", \"" + this.menuID + "\");'";											
			sText += " OnMouseOut='HideMenu(\"" + this.childID + "\");'";
		}	
		sText +="><tr>";
		if(Style!= "NavCol")
		{
			sText +="<td width=5>"
			if(this.status=="selected")
				sText += "&#149;"; 
			else
				sText += "&nbsp;";	
			sText += "</td>";					
		}	
		var className = MenuText;
		if(this.status == "disabled")
			className += "Disabled";
		if(IsPopup)
			sText += "<td nowrap>"		
		else
			sText += "<td>"
		var ID = this.id;
		if(Style =="NavCol" && !IsPopup)
			ID = "tr" + ID;
		sText += "<span class='" + className + "' id='" + ID + "'";
		
		if(toolTip && toolTip !="")
			sText += " title=\"" + toolTip + "\"";					
		sText += ">" + this.text + "</span></td>";
		
		if(this.childID)
			sText += "<td width=10 align=right><img src='images/arrow_right.gif' width=15 height=10></td>";					
		else
			sText += "<td width=10>&nbsp;</td>";																		
		
		sText +="</tr></table></td></tr>";	
	}
	return sText;	
}
MI.prototype.RenderInCell = function(Style)
{
	if(this.html)
	   return this.html;
	   
	var bIsMac = IsMac();
	var sText = "<td nowrap valign=middle ";
	var strDisabled ="";
	var className = "";
	var toolTip = this.toolTip;
	if(this.status == "disabled" && this.disabledToolTip)
		toolTip = this.disabledToolTip;	
	if(trim(this.text) == "" && (this.imgURL == null || this.imgURL == "images/vertical.gif"))// separator	
	{		
		sText += "><img src='images/vertical.gif'>"; //seperator					
	}
	else //menu item
	{				
		if (this.status == "disabled" || (this.childID == null && this.url == null))
		{
			strDisabled = " isDisabled='true'";		
			className = Style + "Disabled";				
		}
		else 
		{
			strDisabled = " isDisabled='false'";		
			className = Style + "Off";
		}		
		var classNameOn = Style + "On";				
		
		sText += " " + strDisabled + " class=" + className;
								
		if(this.url && trim(this.url) !="" && this.status != "disabled")							
			sText += " onClick='" + this.url.replace("\'", "&#39;").replace("\"", "&#34;") + "'";			
						
		if(this.childID && this.status != "disabled")
		{			
			sText += " OnClick='ToggleMenuState();ShowMenu(\"" + this.childID + "\", this, \"" + this.childAlignment + "\", \"" + this.menuID + "\");window.event.cancelBubble = true;' OnMouseOver='this.className =\"" + classNameOn + "\";ShowMenu(\"" + this.childID + "\", this, \"" + this.childAlignment + "\", \"" + this.menuID + "\");'";					
			sText += " OnMouseOut='this.className=\"" + className + "\";HideMenu(\"" + this.childID + "\");'";
		}
		else if(this.status != "disabled")
			sText += " OnMouseOver='this.className =\"" + classNameOn + "\";' OnMouseOut='this.className=\"" + className + "\"'";						
		sText += ">";		
		
		if(toolTip && toolTip !="")
			sText += "<span title=\"" + toolTip + "\">";
				
		if(this.imgURL && this.imgURL !="")				
			sText += "<img src='" + this.imgURL + "' id='" + this.id + "' align='absmiddle'/>";												
		
		if(this.text && this.text !="") {
			if (Style == "ActionMenu")
				sText +="&nbsp;";				
			sText += this.text;
		}			
		if(toolTip && toolTip !="")
			sText +="</span>"
																
		sText +="</td>";								
	}	
	return sText;
}
/*End MunuItem Object - SXU*/
// This function returns the name of a given function. It does this by
// converting the function to a string, then using a regular expression
// to extract the function name from the resulting code.
function funcname(f) {
    var s = f.toString().match(/function (\w*)/)[1];
    if ((s == null) || (s.length == 0)) return "anonymous";
    return s;
}
// This function returns a string that contains a "stack trace."
function stacktrace() {
    var s = "";  // This is the string we'll return.
    // Loop through the stack of functions, using the caller property of
    // one arguments object to refer to the next arguments object on the
    // stack.
    for(var a = arguments.caller; a != null; a = a.caller) {
        // Add the name of the current function to the return value.
        s += funcname(a.callee) + "\n";
        // Because of a bug in Navigator 4.0, we need this line to break.
        // a.caller will equal a rather than null when we reach the end 
        // of the stack. The following line works around this.
        if (a.caller == a) break;
    }
    return s;
}
function ToggleMenuState()
{
	var doc = GetParentWindowDoc();	
	if (doc.MenuEnabled == false)
		doc.MenuEnabled = true;
	else
		HideAllMenus();
}
function HideAllMenus()
{
	var doc = GetParentWindowDoc();	
	var ParentMenuLocation = null;		
	if (doc.MenuEnabled != false)
		doc.MenuEnabled = false;	
	if (doc.OpenWindows == null)
	{
		doc.OpenWindows = new Object();
		doc.OpenWindows.ID = "!!ROOTMENU";
		doc.OpenWindows.Child = null;
		doc.OpenWindows.Parent = null;				
	}	
	var m = doc.OpenWindows;
	while (m != null)
	{
		var frame = doc.getElementById(m.ID + "Frame");
		if (frame)
			doc.getElementById(m.ID + "Frame").style.visibility = "hidden";								
		m = m.Child;
	}
}
function FixUpMenus(MenuID, ParentMenuID)
{
	var doc = GetParentWindowDoc();	
	var ParentMenuLocation = null;	
	
	if (doc.OpenWindows == null)
	{
		doc.OpenWindows = new Object();
		doc.OpenWindows.ID = "!!ROOTMENU";
		doc.OpenWindows.Child = null;
		doc.OpenWindows.Parent = null;				
	}		
	var m = doc.OpenWindows;
	while (m != null)
	{
		if (m.ID == ParentMenuID)
			ParentMenuLocation = m;						
		m = m.Child;
	}
	if (ParentMenuLocation == null)
		ParentMenuLocation = doc.OpenWindows;
	m = ParentMenuLocation.Child
	while (m != null)
	{
		var frame = doc.getElementById(m.ID + "Frame");
		if (frame)
			doc.getElementById(m.ID + "Frame").style.visibility = "hidden";					
		m = m.Child;
	}				
	if (MenuID != "")
	{
		ParentMenuLocation.Child = new Object();
		ParentMenuLocation.Child.ID = MenuID;
		ParentMenuLocation.Child.Child = null;
		ParentMenuLocation.Child.Parent = ParentMenuLocation;	
	}
}
function ShowMenu(MenuID, ParentObj, Alignment, ParentMenuID, Tokens)
{			
	var doc = GetParentWindowDoc();
	if (doc.MenuEnabled == null)
		doc.MenuEnabled = false;			
	if (ParentMenuID == "Menu" && doc.MenuEnabled == false)
		return;	
	FixUpMenus(MenuID, ParentMenuID);				
	var w = "window.";
	if(eval(w + "build_" + MenuID))			
		eval(w + "build_" + MenuID + "()");
	var m = eval(w + MenuID);	   
	if((m == null || m.Build == null))
	{		
		w += "parent."
		if(eval(w + "build_" + MenuID))
			eval(w + "build_" + MenuID + "()");
		m = eval(w + MenuID);		
	}		
	if(ParentMenuID != null && Tokens == null)
	{			
		var parentMenu = eval(w + ParentMenuID);	
		if(parentMenu && parentMenu.Tokens != null)				
			Tokens = parentMenu.Tokens;											
	}		
	if(m && (m.built==null||Tokens != null))
	{			
		m.Tokens = Tokens;
		m.Build();					
	}						
	ShowFrame(MenuID + "Frame", ParentObj, Alignment, null, ParentMenuID + "Frame");	
}
function HideMenu(MenuID)
{			
	HideFrame(MenuID + "Frame");		
}
function CreateFrame(FrameID, doc, FrameWidth, FrameHeight, AutoHide, AdditionalFrameOptions)
{	
	if(!FrameWidth)
		FrameWidth = 1;
	if(!FrameHeight)
		FrameHeight = 1;		
	if (IsMac()) 
	{	
		var newIFrame = doc.createElement("IFRAME");					
		newIFrame.id = FrameID;						
		newIFrame.style.position = "absolute";
		newIFrame.style.visibility = "hidden";
		newIFrame.style.width = FrameWidth;
		newIFrame.style.height = FrameHeight;
		newIFrame.marginHeight = 0;
		newIFrame.marginWidth = 0;
		newIFrame.frameBorder = 0;
		newIFrame.scrolling = "no";		
		if(IsMac())
			newIFrame.src = "about:blank";				
		else
			newIFrame.src = "blank.html";				
		doc.body.insertBefore(newIFrame,null);	
		return doc.getElementById(FrameID);																
	} 
	else
	{
		if(AutoHide)			
			doc.body.insertAdjacentHTML("beforeEnd", "<IFRAME id='" + FrameID + "' src='" + RelativePath + "blank.html' style='position:absolute;visibility:hidden;width=" + FrameWidth + ";height=" + FrameHeight + ";' marginheight=0 marginwidth=0 frameborder=0 noresize scrolling=no onmouseout='HideFrame(this)' " + AdditionalFrameOptions + " ></IFRAME>");		
		else
			doc.body.insertAdjacentHTML("beforeEnd", "<IFRAME id='" + FrameID + "' src='" + RelativePath + "blank.html' style='position:absolute;visibility:hidden;width=" + FrameWidth + ";height=" + FrameHeight + ";' marginheight=0 marginwidth=0 frameborder=0 noresize scrolling=no " + AdditionalFrameOptions + " ></IFRAME>");
		return doc.frames[FrameID];			
	}
}

//Show IFrame
function ShowFrame(Frame, ParentObj, Alignment, FrameSrcURL, ParentFrameID) 
{	
	var doc = document;
	if (typeof(ParentObj) != "object") //it is a ID
		ParentObj = doc.getElementById(ParentObj);
		
	var frameOffsetX = 0;
	var frameOffsetY = 0;
	var parentFrame = null;
	while(doc.body.id !="pagebody")
	{
		doc = parent.document;
		var frameID = document.body.id;
		parentFrame = doc.getElementById(Replace(frameID, "body", "Frame"));
		if(parentFrame!=null)
		{	
			frameOffsetX += parentFrame.offsetLeft;	
			frameOffsetY += parentFrame.offsetTop;
		}
	}
	var FrameID = "";
	if(typeof(Frame) != "object") //it is a ID
	{
		FrameID = Frame;		
		Frame = doc.getElementById(Frame);	
		if(Frame !=null)
		{
			if(Frame.tagName.toLowerCase() == "iframe")		
				Frame.style.zIndex = Frame.style.zIndex + 2;
			else if(Frame.tagName.toLowerCase() == "div")
			{	
				var frameWidth = Frame.offsetWidth;
				var frameHeight = Frame.offsetHeight;	
				var html = Frame.innerHTML;														
				Frame = buildFrame(FrameID, html, frameWidth, frameHeight, false);	
				Frame.IsModal = true;					
			}
		}
	}
	if(Frame==null && FrameSrcURL==null)
		return ;
	
	if(FrameSrcURL !=null && FrameID !="")
	{
		if(Frame == null)		
			Frame = CreateFrame(FrameID, doc, 300, 300, false);					
		if(Frame.src != FrameSrcURL)
			Frame.src=FrameSrcURL;
	}
	if(Frame == null)
		return;
	
	if(parentFrame !=null)// assign parent frame
	{						
		Frame.style.zIndex = parentFrame.style.zIndex + 3;
		Frame.parentFrame = parentFrame;				
	}	
	var FrameHeight = Frame.offsetHeight;
	var FrameWidth = Frame.offsetWidth;  
	
	var ScrollTop = doc.body.scrollTop;
	var ScrollLeft = doc.body.scrollLeft;
	if(ParentObj == null || Alignment.toUpperCase() == "MOUSE")// PLACE THE MENU ACCORDING TO THE MOUSE CLICK	
	{					
		// Get the click coordinates
		var clickX = event.clientX;
		var clickY = event.clientY;
		// Set the Left Edge of the Context Menu
		if (clickX + FrameWidth > document.body.clientWidth + ScrollLeft) 						
			Frame.style.left = clickX - FrameWidth;
		else 
			Frame.style.left = clickX;		
		
		// Set the Top Edge of the Context Menu
		if (clickY + FrameHeight > document.body.clientHeight + ScrollTop && clickY > FrameHeight) 
			Frame.style.top = clickY - FrameHeight + 10;							
		else
			Frame.style.top = clickY - 10;			
	}
	else
	{	
		var ParentTop = Position(ParentObj, "top") + frameOffsetY;
		var ParentBottom = Position(ParentObj, "bottom") + frameOffsetY;
		var ParentLeft = Position(ParentObj, "left") + frameOffsetX;
		var ParentRight = Position(ParentObj, "right") + frameOffsetX;
		var ParentHeight = ParentObj.offsetHeight;
		var ParentWidth = ParentObj.offsetWidth;
	
		switch (Alignment.toUpperCase())
		{
			case "RIGHT":
				Frame.style.left = ParentRight - 2;
				if (ParentTop + FrameHeight > doc.body.clientHeight + ScrollTop) 
					Frame.style.top = ParentBottom - FrameHeight;							
				else
					Frame.style.top = ParentTop;
				break;
			case "BOTTOM":
				Frame.style.top = ParentBottom;
				if (ParentLeft + FrameWidth > doc.body.clientWidth + ScrollLeft) 						
					Frame.style.left = ParentRight - FrameWidth;
				else 
					Frame.style.left = ParentLeft;		
				break;
			case "LEFT":
				Frame.style.left = ParentLeft;
				if (ParentBottom + FrameHeight > doc.body.clientHeight + ScrollTop) 
					Frame.style.top = ParentTop - FrameHeight;							
				else
					Frame.style.top = ParentBottom;															
				break;
			case "TOP":
				Frame.style.top = ParentTop - FrameHeight;
				if (ParentLeft + FrameWidth > doc.body.clientWidth + ScrollLeft) 						
					Frame.style.left = ParentRight - FrameWidth;
				else 
					Frame.style.left = ParentLeft;		
				break;
			case "AUTO":			
				if (ParentLeft + FrameWidth > doc.body.clientWidth + ScrollLeft) 						
					Frame.style.left = ParentRight - FrameWidth;
				else 
					Frame.style.left = ParentLeft;		
				
				if (ParentBottom + FrameHeight > doc.body.clientHeight + ScrollTop) 
					Frame.style.top = ParentTop - FrameHeight;							
				else
					Frame.style.top = ParentBottom;															
				break;
			case "FRAMES":
				Frame.style.top = ParentTop;
				if (ParentLeft + FrameWidth > doc.body.clientWidth + ScrollLeft) 						
					Frame.style.left = ParentRight;
				else 
					Frame.style.left = ParentLeft;		
				break;			
		}
    }
	Frame.style.visibility = "visible";	
	if(Frame.IsModal)
	{
	    if(window.CurrentFrame != Frame)
			HideFrame(window.CurrentFrame);
		window.CurrentFrame = Frame;
	}
	if(Frame.parentFrame)
		Frame.parentFrame.childFrame = Frame;		
}
//Hide IFrame (used for popup menu)
function HideFrame(Frame, MouseX, MouseY, bForceHide) 
{		
	var doc = GetParentWindowDoc();

	if (!bForceHide)
		bForceHide = false;
	
	if(bForceHide == true)
	{		
		Frame.style.visibility = "hidden";	
		return;
	}
		
	var frameOffsetX = 0;
	var frameOffsetY = 0;
	if(typeof(Frame) != "object") //it is a ID
		Frame = doc.getElementById(Frame);
	if(!Frame)
		return;
	if(Frame.childFrame)//childFrame is still on		
		return;
	if(Frame.parentFrame)
	{
		frameOffsetX = Frame.parentFrame.offsetLeft + 2;
		frameOffsetY = Frame.parentFrame.offsetTop;
	}	
	
	// Get the correct Event object (for Safari)
	var theEvent = event;			
	var clientX = 0;
	var clientY = 0;
	
	// Hack for the Mac.  Sometimes, the event object is populated correctly with the correct coordinates
	// for the window, sometimes it is populated with the coordinates from the IFrame, and sometimes it
	// is null because the event object is populated on the IFrame itself
	if (IsMac() && theEvent == null) 
	{
		
		if (window.frames[Frame.id] != null && window.frames[Frame.id].event != null) 
			theEvent = window.frames[Frame.id].event;															
		else if (Frame.parentFrame) 
		{		
			if (window.frames[Frame.parentFrame.id] != null && window.frames[Frame.parentFrame.id].event != null) 
			{				
				theEvent = window.frames[Frame.parentFrame.id].event;	
				if (theEvent != null) //event from parent frame
				{								
					//Safari Hack.  No idea why I have to do this, but it works
					if (theEvent.x > 0 && theEvent.y > 0) 
					{									
						Frame.style.visibility = "hidden";	
						if(Frame.parentFrame)
							Frame.parentFrame.childFrame = null;						
					}							
				}									
				return;
			}							
		}	
		if(!MouseX && !MouseY && theEvent != null)
		{
			MouseX = theEvent.clientX;
			MouseY = theEvent.clientY;
		}
		if (MouseX < 0 || MouseX > Frame.offsetWidth || MouseY < 0 || MouseY > Frame.offsetHeight) 
		{			
			// Hide the Frame	
			
			Frame.style.visibility = "hidden";		
			while(Frame.parentFrame)
			{
				Frame.parentFrame.childFrame = null;		
				Frame = Frame.parentFrame;		
				Frame.style.visibility = "hidden";								
			}											
			//setTimeout("HideFrame('" + Frame.parentFrame.id + "', " + MouseX + ", " + MouseY + ")", 10);
		}				
		return;
	}	
	if(!MouseX && !MouseY && theEvent == null)
	{		
		Frame.style.visibility = "hidden";	
		return;
	}
	var XFactor = 1;
	var YFactor = 1;
	if (theEvent && !MouseX && !MouseY) 			
	{			
		clientX = theEvent.clientX;
		clientY = theEvent.clientY;
		if (clientX < 0 && IsMac()) 
			return;  // Not sure why, but this happens on Safari				
		//Identify the pop-up frame and the current mouse position							
		MouseX = document.body.scrollLeft + clientX;
		MouseY = document.body.scrollTop + clientY;				
		if(document.body.id !="pagebody")
		{
			MouseX += frameOffsetX;
			MouseY += frameOffsetY;
			XFactor = 0;
		}					
	}	
	if(MouseX < 0 || MouseY < 0)
		return;
	
	if (MouseX > Frame.offsetLeft + XFactor && 
		MouseX < Frame.offsetLeft + Frame.offsetWidth &&
		MouseY > Frame.offsetTop + YFactor && 
		MouseY < Frame.offsetTop + Frame.offsetHeight)
	{	
		return;		
	}		
	Frame.style.visibility = "hidden";	
	if(Frame.parentFrame)
	{				
		Frame.parentFrame.childFrame = null;	
		setTimeout("HideFrame('" + Frame.parentFrame.id + "', " + MouseX + ", " + MouseY + ")", 10);
	}				
}

function HideMenuTree(MenuID) 
{
	var doc = GetParentWindowDoc();
	var Frame = doc.getElementById(MenuID + "Frame");
	while(Frame) {
		HideFrame(Frame, -1, -1, true);
		Frame = Frame.parentFrame;				
	}
}

//Leave this, needed for creative reviews (Curt)
function updateMainWindow(url) 
{		
	//We are doing this replace to account for the special case where the url is going to the Attachment view page
	//which requires an encoded string. If we didn't replace "%" with "~@@~" prior to calling this function we 
	//would wind up with a decoded string which would fail.  All other cases should not require this check.
	var re = /~@@~/;
	while(url.indexOf("~@@~") != -1)	
	{
		url = url.replace(re, "%");
	}
	document.URL = url;
}

function MergeTableAttributes(NewTable, TableToMerge, blnCopyID)
{
	if (!IsMac())
		NewTable.mergeAttributes(TableToMerge, blnCopyID);	
	else {
		NewTable.width = TableToMerge.width;
		NewTable.className = TableToMerge.className;		
		NewTable.height = TableToMerge.height;
		NewTable.cellspacing = TableToMerge.cellspacing;
		NewTable.cellpadding = TableToMerge.cellpadding;
		NewTable.border = TableToMerge.border;
		NewTable.rules = TableToMerge.rules;
		NewTable.style.width = TableToMerge.style.width;
		NewTable.style.borderCollapse = TableToMerge.style.borderCollapse;
		
		if (blnCopyID)
			NewTable.id = TableToMerge.id;	
	}		
}

function MergeTableRowAttributes(NewTableRow, TableRowToMerge, blnCopyID)
{
	if (!IsMac())
		NewTableRow.mergeAttributes(TableRowToMerge, blnCopyID);
	else {	
		if (blnCopyID)
			NewTableRow.id = TableRowToMerge.id;	
	}		
}

function MergeTableCellAttributes(NewTableCell, TableCellToMerge, blnCopyID)
{
	if (!IsMac())
		NewTableCell.mergeAttributes(TableCellToMerge, blnCopyID);
	else {
		NewTableCell.width = TableCellToMerge.width;
		NewTableCell.height = TableCellToMerge.height;
		NewTableCell.className = TableCellToMerge.className;		
		NewTableCell.noWrap = TableCellToMerge.noWrap;
		NewTableCell.vAlign = TableCellToMerge.vAlign;
		NewTableCell.align = TableCellToMerge.align;
		NewTableCell.style.width = TableCellToMerge.style.width;
		
		if (blnCopyID)
			NewTableCell.id = TableCellToMerge.id;
	}		
}			
// TODO:  Move this to a new CommonObjects.js include after the project is checked in
function jsDictionary()
{
	this.NumEntries = 0;
	this.Keys = new Array();
	this.StatusMessage = "";
			
	this.Add = function(key, value) {
		this.StatusMessage = "";
		if (key == "") {
			this.StatusMessage = "Invalid key!";
		} else {
			var realKey = key.toLowerCase();
			var oldVal = this[realKey];
			if (oldVal != null) {
				if (oldVal == value) {
					this.StatusMessage = "Entry already exists for " + value + " for key " + key;
				} else {
					this[realKey] = value;
					this.StatusMessage = "Replaced entry for " + oldVal + " with " + value + " for key " + key;
				}
			} else {
				this[realKey] = value;
				this.Keys[this.Keys.length] = realKey;
				this.NumEntries++;
				this.StatusMessage = "Successfully added " + value + " for key " + key;
			}	
		}
		//return result;
	}
	
	this.LookupValue = function(key) {
		this.StatusMessage = "";
		var realKey = key.toLowerCase();
		return this[realKey];
	}
	
	this.Delete = function(key) {
		this.StatusMessage = "";
		if (key == "") {
			this.StatusMessage = "Invalid key!";
		} else {
			var realKey = key.toLowerCase();
			if (this[realKey]) {
				this.StatusMessage = "Successfully Deleted " + key;
				this[realKey] = null;
				
				// NULL OUT THE ENTRY IN THE KEY ARRAYLIST
				// This is OK because in practice, we probably won't be deleting keys
				for (var i = 0; i < this.Keys.length; i++) {
					if (this.Keys[i] == realKey) {
						this.Keys[i] = null;
						break;
					}
				}
				this.NumEntries--;
			} else {
				this.StatusMessage = "Could not find an entry to delete for " + key;
			}	
		}
		return result;
	}	
	
	this.GetCount = function() {
		this.StatusMessage = "";
		return this.NumEntries;
	}
	
	this.GetEntries = function() {
		// Returns a 2-D Array of Key/Value Pairs
		this.StatusMessage = "";
		
		var entries = new Array(this.NumEntries);
		var counter = 0;
		for (var i = 0; i < this.Keys.length; i++) {
			if (this.Keys[i] != null) {
				entries[counter] = new Array(2);
				entries[counter][0] = this.Keys[i];
				entries[counter++][1] = this[this.Keys[i]];
			}
		}
		return entries;
	}
}

function RedirectF5()
{			
	if (window.event && window.event.keyCode == 116) 
	{			
		window.event.keyCode = 17;
	    window.event.cancelBubble = true;
	    window.event.returnValue = false;
	    
	    window.location.reload();	    
	
	    return false;
	}		
}

function SetFocusToWindow()
{			
	var activeWin = window.top.WindowBar.GetActiveWindow();
	var thisWin = window.top.WindowBar.GetWindow(LocalWindowName);
	var bSetFocus = false;
	if (activeWin != thisWin)
		bSetFocus = true;
	
	thisWin.Activate(bSetFocus);		
}

function HideCommonIFrames() 
{
	if (window.HideAssigneesFrame)
	    HideAssigneesFrame();
	if (window.HideCalendar)
		HideCalendar();		
	if (window.HideSelectBox)
		HideSelectBox();	
	if (window.HideDropDowns)
		HideDropDowns();
	if (!blnLoggedIntoPortal && window.HideContextMenu)
		HideContextMenu();
	if (!blnLoggedIntoPortal && window.HideAllMenus)
		HideAllMenus();
	if (!blnLoggedIntoPortal && window.top.WindowBar)
		window.top.WindowBar.HideWindowMenus();
}

function CommonOnResize() 
{	
	HideCommonIFrames();	
	WriteWinCoord();	
	InitializeScrollRegionForNavCol();		
	ObjectManager.OnResize();	
}

function ShowMultiEdit(ID)
{
	// Get the JS Object and if it exists, call Show()
	var MultiEdit = ObjectManager.GetObject(ID);
	if (MultiEdit)
		MultiEdit.Show();		
	// Don't bubble the event up to the body, which closes the iframe
	if(event)
		event.cancelBubble = true;				
}

function MultiEdit(namingContainer, objName)
{
	this.namingContainer = namingContainer;
	this.objName = objName;
	this.divTagName = objName + "MultiEditIframe";

	if (namingContainer != "")
		this.controlPrefix = namingContainer + "_";
	else
		this.controlPrefix = "";

	this.Show = function()
	{
		var divToDisplay = document.getElementById(this.divTagName);
		this.tableName = this.controlPrefix + objName + "EditLink";
		if (divToDisplay)
		{
			// Figure out the Menu Width and Height
			var strHTML = divToDisplay.innerHTML;
			var objContainer = CreateSizingContainer(strHTML, true);
			var displayTable = document.getElementById(this.tableName);
			var menuHeightME = eval('window.' + objName + '_MultiHeight');
			var menuWidthME = eval('window.' + objName + '_MultiWidth');
			
			objContainer.innerHTML = "";

			// Get a handle to the IFrame
			var theIFrame = this.GetMultiEditIFrame(menuWidthME, menuHeightME);

			if (theIFrame)
			{	
				// Hide or Show It						
				if (IsIFrameHidden(theIFrame))
				{
					// Show the IFrame in the right position
					this.PositionMultiEdit(theIFrame, displayTable, menuHeightME, menuWidthME);
					
					//Iterate through the controls
					//Display the controls each option List
					for (var i=0; i < ObjectManager.RegisteredObjects.Keys.length; i++ )
					{
						var obj = ObjectManager.RegisteredObjects.LookupValue(ObjectManager.RegisteredObjects.Keys[i]);
						if (obj.ID != undefined)
							if (obj.ID.indexOf('_MultiEdit') > 0)
								obj.Render;
						
						this.hidden=false;
						ShowIFrame(theIFrame);		
					}
				}
				else
				{
					// Hide it
					this.hidden = true;
					HideIFrame(theIFrame);
				}				
			}
		}
	}

	this.GetMultiEditIFrame = function(menuWidth, menuHeight) 
	{
		var tempIFrame = document.getElementById(this.divTagName);
		
		tempIFrame.removeNode(true);
		theIFrame = document.body.insertBefore(tempIFrame);															
		theIFrame.onselectstart = function () { return false; };
		return theIFrame;
	}

	this.PositionMultiEdit = function(Frame, ParentObj, FrameHeight, FrameWidth) 
	{
		var ParentTop = Position(ParentObj, "TOP");
		var ParentBottom = Position(ParentObj, "BOTTOM");
		var ParentLeft = Position(ParentObj, "LEFT");
		var ParentRight = Position(ParentObj, "RIGHT");			
		var ParentHeight = ParentObj.offsetHeight;
		var ParentWidth = ParentObj.offsetWidth;
		var ScrollTop = document.body.scrollTop;
		var ScrollLeft = document.body.scrollLeft;
		
		// Set the Height/Width of the frame
		Frame.style.height = FrameHeight;
		Frame.style.width = FrameWidth;    
		
		// Set the Left Edge of the IFrame
		if (ParentLeft + FrameWidth >  document.body.clientWidth + ScrollLeft)
			Frame.style.left = ParentLeft - FrameWidth;
		else 
			Frame.style.left = ParentLeft;
		
		// Set the Top Edge of the IFrame
		if (ParentTop + FrameHeight > document.body.clientHeight + ScrollTop)
			Frame.style.top = ParentTop; // - FrameHeight;
		else
			Frame.style.top = ParentTop;
			
		Frame.style.zIndex=900;  //make it less than the standard select box
			
	}
}

function SaveMultiEdit(ID)
{
	var multiEdit = ObjectManager.GetObject(ID);
	
	if(multiEdit)
	{
		if (window.PageLevelMultiEditSave != null)
			PageLevelMultiEditSave(ID, multiEdit);
	}
	
	//hides the windiw
	var divToHide = document.getElementById(multiEdit.divTagName);	
	if(divToHide.style.display != "none")
	{
		divToHide.style.display = "none";
	}
}

function HideMultiEdit(ID,cancel)
{
	
	var multiEdit = ObjectManager.GetObject(ID);
	
	var divToHide = document.getElementById(multiEdit.divTagName);
	
	if(divToHide.style.display != "none")
	{
		divToHide.style.display = "none";
	}
}					
//----------------------------------------------------------------
//  Author:			Curt Knapp
//
//  Procedure Name:	HideSubSection
//
//  Description:	Makes an entire sub section invisible to the user
//
//  Arguments:		sectionID - the id of the subsection to show
//
//  Return Value:	(none)
//
//  Comments:		(none)
//----------------------------------------------------------------
function HideSubSection(sectionID) {
	ShowHideSubSection(sectionID, "none");
}

//----------------------------------------------------------------
//  Author:			Curt Knapp
//
//  Procedure Name:	ShowSubSection
//
//  Description:	Makes an entire subsection visible to the user
//
//  Arguments:		sectionID - the id of the subsection to show
//
//  Return Value:	(none)
//
//  Comments:		(none)
//----------------------------------------------------------------
function ShowSubSection(sectionID) {
	ShowHideSubSection(sectionID, "");
}

function ShowHideSubSection(sectionID, displayString) {
	if(typeof(sectionID) == "object") //it is not an ID
		sectionID = sectionID.id;
	// Get the First and Last Row IDs
	var firstID = eval("window." + sectionID + "_FirstRowID");
	var lastID = eval("window." + sectionID + "_LastRowID");
	var field = null;
	for (var i = firstID; i <= lastID; i++) 
	{
		field = document.getElementById(sectionID + i);
		if (field)
			field.style.display = displayString;		
	}	
}
function RunSpellCheckFromMenu(buttonClick)
{
	multiSpellChecker_RunSpellCheck(buttonClick);
	HideMenu("Menu_0");
}
// Menu Stuff

//  Get Replacemenet String
var RepStringReq;
var RepStringValue;
function GetRepStringProcessRequest()
{
	if (RepStringReq.readyState == 4) 
	{
        if (RepStringReq.status == 200) 
        {   
	        var xmlDoc = RepStringReq.responseXML;	   	      
	      	if(IsMac())
	      	{		      	
		      	var result = xmlDoc.getElementsByTagName('string');
				RepStringValue = result[0].firstChild.data;
		    }
	      	else
		     	RepStringValue = xmlDoc.selectNodes("/string")(0).text;	            	                         	        	 
        } 
        else 
            alert("There was a problem retrieving the XML data:\n" + RepStringReq.statusText + " " + RepStringReq.status);            
    }
}

function GetReplacementString(StringID)
{		
	if(window.XMLHttpRequest)
		RepStringReq = new XMLHttpRequest();
	else
		RepStringReq = new ActiveXObject("Microsoft.XMLHTTP");
	url = "submit.asmx/GetReplacementString"; 
	var data = "";
	data += "DSN=" + GetCookie(g_LoginCookieName, "DSN");
	data += "&UserID=" + GetCookie(g_SessionCookieName, "UserID");
	data += "&LanguageID=" + GetCookie(g_LoginCookieName, "LanguageID");
	data += "&DomainID=" + GetCookie(g_LoginCookieName, "DomainID");
	data += "&SecurityToken=" + GetCookie(g_SessionCookieName, "SecurityToken");
	data += "&ReplacementStringID=" + StringID;	
    if (RepStringReq) 
    {
		RepStringReq.onreadystatechange = GetRepStringProcessRequest;            
        RepStringReq.open("POST", url, false);                  
        RepStringReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');            
        RepStringReq.send(data);        
    }
    return RepStringValue;
}
//HTMLElement common functions -SXU
function mkElement(tag, id, x, y, w, h)
{
	var el;		
	if(id) el = document.getElementById(id);		
	if(!el || el.tagName != tag)
	{	
		el = document.createElement(tag);
		if(id) el.id = id;		
	}
	else
		el.exist = true;
	el_setPosition(el, x, y);
	el_setSize(el, w, h);				
	return el;
}

function el_setCursor(el, val){if(val)el.style.cursor = val;}
function el_setColor(el, val, cornerStyle)
{
	if(!val) return;
	if(cornerStyle)
	{		
		var bs = el.getElementsByTagName("B");
		for(var i=0; i< bs.length; i++)
		{										
			if(bs[i].className !="rb1")			
				bs[i].style.backgroundColor = val;													
		}			
	}	
	else
		el.style.backgroundColor = val;	
}
function el_setBorderColor(el, val, cornerStyle)
{		
	if(!val) return;	
	if(cornerStyle)
	{		
		var bs = el.getElementsByTagName("B");
		for(var i=0; i< bs.length; i++)
		{						
			if(bs[i].className=="rb1")
				bs[i].style.backgroundColor = val;											
			else
				bs[i].style.borderColor = val;
		}			
	}
	else
		el.style.borderColor = val;	
}

function el_setPosition(el, x,y)
{
	if(x!=null){el.style.left = x;}
	if(y!=null){el.style.top = y;}
}
function el_setSize(el, w, h)
{		
	if(w){el.style.width = w;}
	if(h){el.style.height = h;}
}
function el_setCssClass(el, className){el.className = className;}
function el_show(el){el.style.display = "";}
function el_hide(el){el.style.display = "none";}
function el_setZIndex(el,zIndex){el.style.zIndex = zIndex;}	
//make any div or span object roundcorner	
function el_roundCorner(el, color, borderColor, roundStyle)
{		
	if(typeof(el) != "object")
		el = document.getElementById(el);
	if(el == null)
		return;
	el.style.borderWidth=0;	
	el.style.backgroundColor = "";
	var b = document.createElement("b");
	b.className ="rbbody";
				
	b.style.backgroundColor = color;
	b.style.borderColor = borderColor;	
	b.style.display = "block";	
	b.style.overflow = "hidden";
	b.style.borderRightWidth = "1px";
	b.style.borderLeftWidth = "1px";
	b.style.borderLeftStyle = "solid";
	b.style.borderRightStyle = "solid";	
	b.innerHTML = el.innerHTML;
	el.innerHTML = "";
	el.appendChild(b);	
	var j1 = 1; j2=2;
	if(roundStyle == "roundupper") j2 = 1;
	if(roundStyle == "roundlower") j1 = 2;
	for(var k = j1; k <= j2; k++)
	{											
		for(var i = 4; i > 0; i--)
		{
			b = document.createElement("b");
			b.style.display = "block";	
	        b.style.overflow = "hidden";
			b.style.backgroundColor = color;
			b.style.height = "1px";	
			b.className ="rb" + i;									
			if(i == 1)
			{				
				b.style.marginLeft = "5px";
				b.style.marginRight = "5px";
				b.style.backgroundColor = borderColor;
				b.border = true;
			}
			else
			{
				b.style.borderLeftWidth = "1px";
				b.style.borderRightWidth = "1px";				
				b.style.borderLeftStyle = "solid";
				b.style.borderRightStyle = "solid";								
				b.style.borderColor = borderColor;	
			}
			if(i==2)
			{
				b.style.borderLeftWidth = "2px";
				b.style.borderRightWidth = "2px";				
				b.style.marginRight = "3px";
				b.style.marginLeft = "3px";
			}
			if(i == 3)
			{
				b.style.marginLeft = "2px";
				b.style.marginRight = "2px";				
			}
			if(i == 4)
			{
				b.style.marginLeft = "1px";
				b.style.marginRight = "1px";				
				b.style.height = "2px";																		
			}
			if(k == 1)				
				el.insertBefore(b, el.firstChild);
			else
				el.appendChild(b, el.lastChild);
		}					
	}					
}
function el_setGroupboxTitle(el, startX, bkColor)
{			
	var titleDiv = document.getElementById(el.id + "_Title");
	if(!titleDiv)
		return;
	var d = mkDiv(startX, 0, 0, 1);//1 pixel height			
	d.style.paddingLeft = "5px";
	d.style.paddingRight = "5px";			
	d.style.zIndex = el.style.zIndex + 1;
	if(!bkColor)				
		d.style.backgroundColor = "#ffffff";
	else
		d.style.backgroundColor = bkColor;				
	d.innerHTML = titleDiv.innerHTML;
	el.appendChild(d);	
	d = titleDiv; 
	d.style.paddingLeft = "5px";
	d.style.paddingRight = "5px";
	d.style.zIndex = el.style.zIndex + 2;
	d.innerHTML = titleDiv.innerHTML;
	d.style.overflow = "";
	d.style.visibility = "visible";
	var h = d.offsetHeight;
	el_setPosition(d, startX, (-1)* parseInt(h/2));
}
function mkDiv(x, y, w, h, id)
{
	var el= mkElement("DIV", id, x, y, w, h);	
	if(!el.exist)
	{		
		el.style.position="absolute";
		el.style.overflow = "hidden";
		el.style.cursor = "default";	
		if(!el.style.zIndex)
			el.style.zIndex = 1;			
	}
	return el;
}
function clearSelection()
{	
	if(window.getSelection)		
	{
		var s = window.getSelection();		
		if(s.removeAllRanges)//Firefox
			s.removeAllRanges();
		if(s.empty)	//Safari
			s.empty();	
	}
	if (document.selection)	//IE	
		document.selection.empty()
}
function eventTarget(evt)
{
	var t;
	if(!evt && event.srcElement) 
		t = event.srcElement;
	else if(evt.target) 
		t= evt.target;				
	if(t && t.nodeType && t.nodeType== 3)
		t = t.parentNode;
	return t;
}

// 11-09-2005 Caleb Packard
// Case: 13391 Defect: 30621
// Allow reports to link to the app efficiently
// NEW CODE
function OpenLinkFromReport(url)
{
	var newWin;
	newWin = window.top.WindowBar.CreateWindow(url,'LinkFromReport'); 
	newWin.Maximize(); 
	newWin.Activate();
}
// END NEW CODE

