function setupPageCommonElements( dataPage, pageDescriptor )
{
	// Set up the page header
	pageDescriptor.objPageHeader = setupPageHeader( pageDescriptor, pageDescriptor.sTargetFrame);

	// Get the person's name
	pageDescriptor.sUserDisplayName = getSessionPersonName();
	if ( IsInEffectiveUserMode() )
		{
		pageDescriptor.sEffectiveUserDisplayName = getEffectiveUserPersonName();
		pageDescriptor.fEditMode                 = CanDoWriteOnEffectiveUser();
		pageDescriptor.sWorkingOn                = pageDescriptor.fEditMode ? scCommon.sWorkingOn : scCommon.sWorkingOnReadOnly;
		}

	// Set up the page footer
	pageDescriptor.objPageFooter = setupPageFooter(pageDescriptor.objPageFooter, pageDescriptor.sTargetFrame);


	// NOTE: (re: WSS 7.0)
	//   The Copyright is really static except for the date stamp.
	pageDescriptor.sProductName   = scCommon.sPRODUCT_NAME;
	pageDescriptor.sModuleName    = scCommon.sWEB_SELF_SERVICE_NAME;
	pageDescriptor.sModuleVersion = scCommon.sWEB_SELF_SERVICE_VERSION;
	pageDescriptor.sCopyright     = scCommon.sPRODUCT_COPYRIGHT;
	pageDescriptor.sGeneratedGMT  = new Date().toGMTString();
}

function setupPageHeader( pageDescriptor, sPageTarget )
{
	// Create the header object if it didn't get passed in
	if ( pageDescriptor.objHeader == null )
		pageDescriptor.objHeader = new objCore.PageHeader();
	var objHeader = pageDescriptor.objHeader;

	// If the Logo is enabled, then set its text, URL.
	if ( !isEmptyString(scCommonImages.sLogo) )
	{
		objHeader.objLogo.sImg= makeMediaPath(scCommonImages.sLogo );
		objHeader.objLogo.sImgAltText = objCore.scAccessibility.sLogoAltText;
		objHeader.objLogo.sHREF = scCommon.sLogoLink;
	}

	// Add the User-defined links first...
	// Note: it has been noticed that doing an objCore.location.href= causes IE 5.5
	// to display the URL in the body of the page before going to the new URL.
	// We are not sure why. Doing a location.replace() avoids the problem, but then
	// you lose the ability to go "back" to Student Center with the browser's Back
	// button.  It was deemed a lesser issue to have the URL temporarily displayed.
	objHeader.addHeaderLink( 'javascript:objCore.location.href=\'' + objCore.JSEncode(scCommon.sWebUserLink1) + '\'', scCommon.sWebUserLinkDesc1, null, null );
	objHeader.addHeaderLink( 'javascript:objCore.location.href=\'' + objCore.JSEncode(scCommon.sWebUserLink2) + '\'', scCommon.sWebUserLinkDesc2, null, null );
	objHeader.addHeaderLink( 'javascript:objCore.location.href=\'' + objCore.JSEncode(scCommon.sWebUserLink3) + '\'', scCommon.sWebUserLinkDesc3, null, null );

	// Add the main-menu link [as long as the header links are not displayed with the Page Trail.]
	if ( scCommon.bNoPageTrail )
		objHeader.addHeaderLink( 'javascript:objCore.InternalURL_MainMenu(self)', scCommon.sWebMainMenuLink, sPageTarget, null );

	// Add the "working on" link for manager center
	addWorkingOnHeaderLink( objHeader );

	// Add the "sign-on" link
	if (objCore.g_IsEnabled.SignOn() && (!objCore.scSignOn.bDisableSignOnLink))
	{
		objHeader.addHeaderLink( 'javascript:objCore.InternalURL_SignOn(self)',
		                         scCommon.sWebSignOnLink,
		                         sPageTarget, null );
	}

	// Add the "sign-off" link
	if (!isEmptyString(scCommon.sWebSignOffLink))
	{
		objHeader.addHeaderLink( 'javascript:objCore.InternalURL_DoSignOff(self)',
		                         scCommon.sWebSignOffLink,
		                         sPageTarget, null );
	}

	// Add the "help" link
	if (!isEmptyString(scCommon.sWebHelpLink))
	{
		objHeader.addHeaderLink( 'javascript:objCore.onClickPageHelp(self)',
		                         scCommon.sWebHelpLink,
		                         null, null );
	}

	// Return the header object
	return objHeader;
}

function addWorkingOnHeaderLink( objHeader )
{
	if ( objCore.getSessionUserIsManager() )
	{
		objHeader.addHeaderLink( 'javascript:objCore.onClickManagerList( self )',
		                         scCommon.sWebWorkOnUserLink,
		                         null, 'WORKINGON' );
	}
}

var wManagerList = null;
function onClickManagerList( w )
{
	// Pick a default size.
	var nWidth = 600;
	var nHeight = 400;

	var src = objCore.InternalURL_Managers(null);

	if ( useModal() )
	{

		var loc = objCore.getPopWindowLocStr( true );
		var dialogArgs = new Array();
		dialogArgs[0] = new Object();
		dialogArgs.opener = self;

		var returnVal =  w.showModalDialog(src, dialogArgs, 
		                              "dialogHeight:"+nHeight+"px;dialogWidth:"+nWidth+"px;" + loc + ";center:No;help:No;resizable:Yes;status:No;");
		if ( returnVal )
			PopUpManagerListCallback( w );
	}
	else
	{
		var loc = objCore.getPopWindowLocStr( true );
		wManagerList = w.open('','PopManagerList','dependent=1,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,copyhistory=0,width=' + nWidth + ',height=' + nHeight + loc);
		wManagerList.callbackWindow = w;
		wManagerList.location.href = src;
	}
}

// Replaces a query string fields value.
// If the field does not exist it is added.
// bAddQuestionMark defaults to yes.  If it isn't supplied, then we add the question mark
function ReplaceQSField( sQS, sField, sValue, bAddQuestionMark )
{
	bAddQuestionMark = ( (bAddQuestionMark == null) ? true : bAddQuestionMark );
	var urldc = new clURLDecoder();
	urldc.Decode( sQS );

	field = urldc.GetFieldIC(sField)
	if ( field == null )
		urldc.AddField(sField, sValue);
	else
		field.sValue = sValue;

	sQS = (bAddQuestionMark ? '?' : '') + urldc.GetQueryString();
	return sQS;
}

function updateLinkIDInURL( loc )
{
	var sQS = loc.search;
	sQS = ReplaceQSField( sQS, 'linkid', objCore.getLinkID() )
	return loc.pathname + sQS;
}

function LooseEqualStr( s1, s2 )
	{
	if ( s1 == s2 )
		return true;

	if ( isEmptyString( s1 ) && isEmptyString( s2 ) )
		return true;

	return false;
	}

function doStaleCheck( w )
{
	var fDidRefresh = false;

	var sEffYUK       = (objCore.oEffectiveUser == null) ? null : objCore.oEffectiveUser.yuk;

	// Note: if the PD is undefined or the PD.effYUK is undefined (different than null)
	// then assume that the page/API is not dependent on the YUK.  Without this check
	// we can get into an endless cycle of refetching.
	if ( (w.parent.PD != null) && (typeof(w.parent.PD.effyuk) != "undefined")
	  && !LooseEqualStr(w.parent.PD.effyuk, sEffYUK) )
	{
		if ( w.parent.doSelfRefresh )
			w.parent.doSelfRefresh();
		else
			w.parent.location.replace( updateLinkIDInURL(w.parent.location) );

		fDidRefresh = true;
	}
	else if ( (w.PD != null) && (typeof(w.PD.effyuk) != "undefined")
	       && !LooseEqualStr(w.PD.effyuk, sEffYUK) )
	{
		// If we just performed a "set effective user", don't auto-refresh that page
		// (because we'll do it over and over and over).
		if ( (w.PD.xapi != WSSAPIs.SETEFFECTIVEUSER)
			&& (w.PD.xapi != WSSAPIs.DOSIGNON) ) 
		{
			if ( w.doSelfRefresh )
				w.doSelfRefresh();
			else
				w.location.replace( updateLinkIDInURL(w.location) );

			fDidRefresh = true;
		}
	}

	return fDidRefresh;
}

function PopUpManagerListCallback( w )
	{
	// Do "staleness" check.  Since we know that we just changed effective user,
	// if the staleness check does nothing, then we at least need to reload the
	// main visible frame (to update the header).
	if ( !doStaleCheck(w) )
		w.location.replace( updateLinkIDInURL(w.location) );
	}

// This should (probably) go in WSSMisc.js
function setPDYUKs( PD )
	{
	PD.yuk    = (objCore.userProperties == null) ? '' : objCore.userProperties.userid;
	PD.effyuk = (objCore.oEffectiveUser == null) ? '' : objCore.oEffectiveUser.yuk;
	}

function onClickPageHelp( w )
{
	var eHelpID = w.pageDescriptor.ePageID;
	if ( w.getHelpID )
		eHelpID = w.getHelpID();

	objCore.InternalURL_Help(w, null, eHelpID )
}

function setupPageFooter( objFooter, sPageTarget )
{
	if ( objFooter == null )
		objFooter = new objCore.PageFooter();

	var objLink = null;

	// Main Menu Link
	objLink = new objCore.PageFooterLink();
	objLink.sText   = scCommon.sWebMainMenuLink;
	objLink.sTitle  = scCommon.sWebMainMenuLink;
	objLink.sHREF   = 'javascript:objCore.InternalURL_MainMenu(self)';
	objLink.sTarget = sPageTarget;
	objLink.sImg    = makeMediaPath(scCommonImages.sHome);
	objLink.nPos    = objCore.g_PageFooterLocations.NONE;
	objFooter.arLinks.addLink(objLink);

	// Add either the Course Catalog link (if enabled) or the Class Schedule link
	if ( !isEmptyString( objCore.scMainMenu.sMainMenuCourse ) )
	{
		objLink = new objCore.PageFooterLink();
		objLink.sText   = objCore.scMainMenu.sMainMenuCourse;
		objLink.sTitle  = objCore.scMainMenu.sMainMenuCourse;
		objLink.sHREF   = 'javascript:objCore.InternalURL_CourseMenu(self)';
		objLink.sTarget = sPageTarget;
		objLink.sImg    = makeMediaPath(scCommonImages.sSearch);
		objLink.nPos    = objCore.g_PageFooterLocations.NONE;
		objFooter.arLinks.addLink(objLink);
	}
	else if ( !isEmptyString( objCore.scMainMenu.sMainMenuClass ) )
	{
		objLink = new objCore.PageFooterLink();
		objLink.sText   = objCore.scMainMenu.sMainMenuClass;
		objLink.sTitle  = objCore.scMainMenu.sMainMenuClass;
		objLink.sHREF   = 'javascript:objCore.InternalURL_ClassMenu(self)';
		objLink.sTarget = sPageTarget;
		objLink.sImg    = makeMediaPath(scCommonImages.sSearch);
		objLink.nPos    = objCore.g_PageFooterLocations.NONE;
		objFooter.arLinks.addLink(objLink);
	}

	// Add the "top of page" link
	objLink = new objCore.PageFooterLink();
	objLink.sText = scCommon.sWebTopOfPage;
	objLink.sTitle = scCommon.sWebTopOfPage;
	objLink.sHREF = '#TOP';
	objLink.sImg  = makeMediaPath(scCommonImages.sUp);
	objLink.nPos  = objCore.g_PageFooterLocations.NONE;
	objFooter.arLinks.addLink(objLink);

	// Add the "message" link
	if ( !isEmptyString( objCore.scMainMenu.sMainMenuMessage ) )
	{
		objLink = new objCore.PageFooterLink();
		objLink.sText = objCore.scMainMenu.sMainMenuMessage;
		objLink.sTitle = objCore.scMainMenu.sMainMenuMessage;
		objLink.sHREF = 'javascript:objCore.InternalURL_Message(self)';
		objLink.sImg  = makeMediaPath(scCommonImages.sMail);
		objLink.nPos  = objCore.g_PageFooterLocations.NONE;
		objFooter.arLinks.addLink(objLink);
	}

	// Add the "help" link
	if ( !isEmptyString( scCommon.sFooterHelpLink ) 
	  && !isEmptyString( scCommonImages.sHelp ) )
	{
		objLink = new objCore.PageFooterLink();
		objLink.sText = scCommon.sFooterHelpLink;
		objLink.sTitle = scCommon.sFooterHelpLink;
		objLink.sHREF = 'javascript:objCore.onClickPageHelp(self)';
		objLink.sImg  = makeMediaPath(scCommonImages.sHelp);
		objLink.nPos  = objCore.g_PageFooterLocations.NONE;
		objFooter.arLinks.addLink(objLink);
	}

	// Add the "about" link
	objLink = new objCore.PageFooterLink();
	objLink.sText = objCore.scLocalize.sMenuHelpAbout;
	objLink.sTitle = objCore.scLocalize.sMenuHelpAbout;
	objLink.sHREF = 'javascript:objCore.doAbout()';
	objLink.sImg  = makeMediaPath(scCommonImages.sAbout);
	objLink.nPos  = objCore.g_PageFooterLocations.NONE;
	objFooter.arLinks.addLink(objLink);

	// Return the footer object
	return objFooter;
}
