
//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 = "Aprimo80Help";
			
		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;	
}

//----------------------------------------------------------------
//  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.
//----------------------------------------------------------------

//----------------------------------------------------------------
//	Global JavaScript variables
//----------------------------------------------------------------
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

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();
}

//----------------------------------------------------------------
//              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();
}

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:			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);
	}
}
function IsIE6()
{
	var strAgent = window.navigator.userAgent;
	if (IsMac()) {
		// If it's the Mac, we only support Safari (even though this method is called IsIE6())
		return (strAgent.indexOf("Safari") > 0 ? true: false);
	} else {	
		return (strAgent.indexOf("MSIE 6.0") > 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;			
	}	
	else if(strAgent.indexOf("Firefox")>-1)
	    return true;
	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:			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:			Ted Elliott
//  Procedure Name:	ToInt
//  Description:	Converts a value to an integer, similar to
//                        APUtility.ToInt.  Empty Strings, null, etc
//                        get translated to 0.
//----------------------------------------------------------------
function ToInt(value) {
	value = parseInt(value);
	if (isNaN(value) || value == null)
		value = 0;
	return value;
}

//----------------------------------------------------------------
//  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 = "";
}
//----------------------------------------------------------------
//  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";
}

function ShowControl(controlID) {
	// Show the Label and Value Controls
	var tblLabel = document.getElementById("L_" + controlID);
	var tblValue = document.getElementById("V_" + controlID);
	
	if (tblLabel)
		tblLabel.style.display = "";
	
	if (tblValue)
		tblValue.style.display = "";
}

function HideControl(controlID) {
	// Show the Label and Value Controls
	var tblLabel = document.getElementById("L_" + controlID);
	var tblValue = document.getElementById("V_" + controlID);
	
	if (tblLabel)
		tblLabel.style.display = "none";
	
	if (tblValue)
		tblValue.style.display = "none";
}

//----------------------------------------------------------------
//  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() 
{		
	if (window.Aprimo && window.Aprimo.jsVersionID && window.jsDynVersionID)
	{
		if (window.Aprimo.jsVersionID != window.jsDynVersionID)
			alert(ResourceID12830);
	}
	
	if (window.top.WindowBar)
	{
		var w = window.top.WindowBar.GetWindow(LocalWindowName);
		if (w != null)
			w.AddTrace('Begin CommonOnLoad()');
	} 

	//This flag determines if we should reset all control default values
	var blnResetDefaults = false;	
	if(window.menus)
	{
	    for(var i = 0; i < window.menus.length; i++)
	        Menu.build(menus[i]);
	}
	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(window.Aprimo && window.Aprimo.processControls)
	{
		Aprimo.processControls();
		Aprimo.trigger("Page.Load");
		Aprimo.triggerDelayed("Window.Resize");
	}
	//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);
		
	if (window.top.WindowBar)
	{
		var w = window.top.WindowBar.GetWindow(LocalWindowName);
		if (w != null)
			w.AddTrace('After CommonOnLoad()');
	} 
	
	setTimeout("LoadFocus()", 1);
	
}

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

	if(window.menus)
	{
		for(var i = 0; i < window.menus.length; i++)
		{
	       PurgeEvents(document.getElementById(menus[i]));
		}
	}	
	
	Aprimo.unload();
}
//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:			Sally Xu
//  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:	IsDisabled
//  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(Aprimo.Events.hasSubscribers("Page.Print"))
	{
		Aprimo.trigger("Page.Print",null);
	}
	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:	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);
}
    

/* End Menu Object by Sally Xu */
function buildFrame(ID, Content, Width, Height, AutoHide)
{
	var doc = GetParentWindowDoc();	
	var Frame = doc.getElementById(ID + "Frame");	

	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 f;
	if (Frame.contentWindow)//SAFARI 3 fix
		f = Frame.contentWindow;
	else
		f = Frame;
	var strHeading = doc.getElementById("PageHeadInfo").innerHTML;
	strHeading = "<HEAD id='PageHeadInfo'>" + strHeading + "</HEAD>";				
	f.document.open();			
	f.document.write("<html>" + strHeading + "<body class='FrameBody' id='" + ID + "body'>" + Content + "</body></html>");				
	//f.document.close();		
	setTimeout("CloseFrame(" + f.ID + ")",1)
	return doc.getElementById(ID + "Frame");
}

function CloseFrame(frameID)
{
    var f = document.getElementById(frameID)
    if(f != null)
        f.document.close();
}








function GetParentWindowDoc()
{
	var doc = document;		
	while(doc.body.id !="pagebody")
		doc = parent.document;
	return doc;
}

// 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 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 popup div
function ShowPopupDiv(div, anchor, po, nohide)
{
    //hide any other popups
    if(!nohide)
        HidePopupDivs();
	if(typeof(div)!="object")
        div=document.getElementById(div);
    if(anchor && typeof(anchor)!="object")
        anchor=document.getElementById(anchor); 
        
    if(div && div.parentElement.tagName != "BODY")
    {
        div.parentElement.removeChild(div);
        document.body.appendChild(div);
        div.style.display = "block";                       
    }
    if(!po)
        po="right";           
    var pl, pt, pr, pb;   
    if(anchor == null) return;      
    if(anchor.clientX)//anchor is the mouseclick event
    {    
        pl = pr = anchor.clientX;
	    pt = pb = anchor.clientY;
	}
	else
	{
        pl = Position(anchor, "left");
        pt = Position(anchor, "top");
        pr = Position(anchor, "right");
        pb = Position(anchor, "bottom");
    }
    if(po=="bottom")
    {                         
        div.style.top = pb;   
        if(pl + div.offsetWidth > document.body.offsetWidth)
            div.style.left = pr - div.offsetWidth;
        else                                        
            div.style.left = pl;   
    }                                   
    if(po=="right")
    {                  
        if(pr + div.offsetWidth > document.body.offsetWidth)
            div.style.left = pl - div.offsetWidth;
        else                                        
            div.style.left = pr -1;                                                                                                                      
        if(pt + div.offsetHeight > document.body.offsetHeight)
            div.style.top = pb - div.offsetHeight; 
        else                                                                          
            div.style.top = pt;                                                                                                                                                                                                                                                
    }            
    if(po=="left")             
    {
        div.style.left = pr - div.offsetWidth; 
        if(pb + div.offsetHeight > document.body.offsetHeight)
            div.style.top = pt - div.offsetHeight; 
        else                                                                           
            div.style.top = pb;  
    }
    if(po=="top")
    {
        div.style.top = pt - div.offsetHeight;                         
        if(pl + div.offsetWidth > document.body.offsetWidth)                                                           
            div.style.left = pr - div.offsetWidth; 
        else
            div.style.left = pl;   
    }
    div.style.zIndex = 10;
    if(!nohide)//mark as visible popup          
        window.VisiblePopUp = div;    
    el_popup(div, true);      
}
//used to remove any existing popups so that there is not overlapping of popups
function HidePopupDivs()
{
    var popUpDiv = window.VisiblePopUp;
    if(popUpDiv)
    {
        el_popup(popUpDiv, false);     
    }    
}

//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;
			if (key.toLowerCase != null)
				realKey = key.toLowerCase();
			else
				realKey = key;
			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) {
		var result;
		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 (window.HideTreeDropDowns)
	{
	    HideTreeDropDowns()
	}
	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;
	        var result = xmlDoc.getElementsByTagName('string');	        
	        RepStringValue = result[0].firstChild.nodeValue;  		            	      		            	                         	        	 
        } 
        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 += "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 walkTheDom(node, func) 
{        
    func(node);
    node = node.firstChild;
    while(node)
    {            
        walkTheDom(node, func);
        node = node.nextSibling;
    }
}
    
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 =="1")
				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";}

/*popup a div or any container element*/
function el_popup(e, on)
{   
   if(on == undefined)
        on = true;
   if(typeof(e) != "object") //id   
        e = document.getElementById(e); 
   if(e == null)
      return;  
   var shadow = mkElement("DIV", e.id + 'shadow');
   if(!shadow.exist)
   {
		if(IsMac())
		{		
			document.body.appendChild(shadow);
		}
		else
		{
			if(e.parentElement)
				e.parentElement.appendChild(shadow);  
			else
				document.body.appendChild(shadow);
		}
	}	
		
   var shimfr;
   var modifier = 5;
	if(e.taskBarShim)//we need to look for the shim in the AprimoApp.aspx, so we need to use window.top
	{
		shimfr = window.top.document.getElementById('shimTB');
		modifier =0;
	}
	else
	{
		shimfr = document.getElementById('shim');
	}
	
   if(shimfr)//if it's IE6
   {
		var myshim;
		if(e.taskBarShim)//we need to look for the shim in the AprimoApp.aspx, so we need to use window.top
		{
			if(e.taskBarPopUpShim)
				myshim = window.top.document.getElementById('shimTB');//reuse the shim for popups
			else
				myshim = window.top.document.getElementById(e.id + 'shimTB');//this will be the main taskbar shim, we will always have
		}
		else
		{
			myshim = document.getElementById(e.id + 'shim');
		}
             
        if(!myshim)
        {     
			myshim = shimfr.cloneNode();//for each popup element, we need one shim because there might be more than one popup at the time (menu)                
			if(e.taskBarShim)
			{
				window.top.document.body.appendChild(myshim, shimfr);
				myshim.id = e.id + 'shimTB';       
			}
			else
			{
				if(e.parentElement)
					e.parentElement.appendChild(myshim, shimfr);  
				else
					document.body.appendChild(myshim, shimfr);
					
				myshim.id = e.id + 'shim';       
			}
			                                                         
        }                                               
   }      
   if(on)
   {                                      
        e.style.visibility = "visible";   
        shadow.className = "shadow";
        shadow.style.top = Position(e, "top") + 5;                 
        shadow.style.left = Position(e, "left") + 5;                
        shadow.style.width = e.offsetWidth;               
        shadow.style.height = e.offsetHeight + 1;   
        shadow.style.zIndex = e.style.zIndex-1;         
        shadow.style.visibility = "visible";                                                                                                                        
        if(myshim)//ie6
        {                
            myshim.style.visibility = "visible";                                                                                           
            myshim.style.top = Position(e, "top") + modifier;             
            myshim.style.left = Position(e, "left") + modifier;
			myshim.style.width = e.offsetWidth;               
            myshim.style.height = e.offsetHeight + 1;   
            myshim.style.zIndex = e.style.zIndex - 2;
        }          
   }
   else
   {            
        e.style.visibility = "hidden";  
        shadow.style.visibility = "hidden";    
		if(myshim)//ie6
            myshim.style.visibility = "hidden";
   }
}
function el_setZIndex(el,zIndex){el.style.zIndex = zIndex;}	

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(w)
{	
    if(w == null)
        w = window;
	if(w.getSelection)		
	{
		var s = w.getSelection();		
		if(s.removeAllRanges)//Firefox
			s.removeAllRanges();
		if(s.empty)	//Safari
			s.empty();	
	}
	if (w.document.selection)	//IE	
		w.document.selection.empty()
}
function eventTarget(e)
{
	var t;
	e = e || event;
	if(e.srcElement) 
		t = e.srcElement;
	else if(e.target) 
		t= e.target;				
	if(t && t.nodeType && t.nodeType== 3)
		t = t.parentNode;
	return t;
}
function cancelBubble(e)
{
    if(!e)e=event; 
    if(e)
    { 
        e.cancelBubble=true;
        if(e.stopPropagation)
            e.stopPropagation();
    }
}

function hexEncoding(s)
{
  var h = '';
  for(var i=0; i<s.length; i++)
  {
    c = s.charCodeAt(i);
    h += ((c<16) ? "0" : "") + c.toString(16);
  }
  return h;
}

// 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
// Retrieves the dualselect listboxes from a window with a datagrid and applies those options
// to a other listboxes (for a dualselect)
function ApplyDataGridColumns(targetAvailableList, targetSelectedList, dataGridName)
{
	var dgSelectedList = ObjectManager.GetObject(dataGridName + 'SC_S');
	var dgAvailableList = ObjectManager.GetObject(dataGridName + 'SC_A');
	if ((dgSelectedList) && (dgAvailableList))
	{
		targetSelectedList.CreateOptionsFrom2DArray(dgSelectedList.CopyOptions());
		targetAvailableList.CreateOptionsFrom2DArray(dgAvailableList.CopyOptions());
	}
	else
	{
		var d = Aprimo.getControl(dataGridName);
		if(d) 
		    d.populateArrays(targetAvailableList, targetSelectedList);
	}
}

function BlockBubble()
{
	if (event)
	{
		event.cancelBubble = true;
	}
}

function swapStyles(id,newStyle)
{
	var obj;
	if(typeof(id) != "object") //id   
         obj = document.getElementById(id); 
	else
		 obj = id;
	if(obj)
		obj.className = newStyle;
}




//----------------------------------------------------------------
//  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");
}

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; ";
		}
	}

	//.ButtonOff {
	//BACKGROUND-COLOR: #185A9C; COLOR: #F7F7EF; FONT-SIZE: 9pt; FONT-FAMILY: verdana; TEXT-ALIGN: center
  //}
	
	var sOut = "<table border=0 cellspacing=0 cellpadding=0>\n";
	sOut += "<tr>\n";
	sOut += "<td><img id='" + name + "Left' src='" + RelativePath + "images/ButtonLeft_Off60b.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/ButtonRight_Off60b.gif' border=0></td>\n";
	sOut += "</tr>\n";
	sOut += "</table>\n";
	return sOut;
}

function ButtonGlow(Name, Class, Mode) 
{
		var objImg = document.getElementById(Name + "Left");
		if(Mode == 'Off')
			objImg.src = RelativePath + "images/ButtonLeft_" + Mode + "60b.gif";
		else
			objImg.src = RelativePath + "images/ButtonLeft_" + Mode + ".gif";

		var objImg = document.getElementById(Name + "Right");
		if(Mode == 'Off')
			objImg.src = RelativePath + "images/ButtonRight_" + Mode + "60b.gif";
		else
			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 PurgeEvents(elm)
{
	if(elm)
	{
		var a = elm.attributes, i, l, n;
	    if (a) {
	        l = a.length;
	        for (i = 0; i < l; i += 1) {
	            n = a[i].name;
	            if (typeof elm[n] == 'function') {
	                elm[n] = null;
	            }
	        }
	    }
	    a = elm.childNodes;
	    if (a) {
	        l = a.length;
	        for (i = 0; i < l; i += 1) {
	            PurgeEvents(elm.childNodes[i]);
	        }
	    }
	}
}
