// "Internal URLs" should be based on the PAGE you want to go to.  It is the job
// of the routines here to translate that into an API number.
//
// Note that if the window parameter passed into the InternalURL functions is null,
// then instead of attempting to set the window's href to the appropriate URL, the
// functions will RETURN the appropriate URL.

function escapeStr( str )
{
	if ( str == null )
		return ''
	else
	{
		var ret = escape( str )
		var pos = ret.indexOf( '+' )
		while (pos != -1)
			{
			ret = ret.substring( 0, pos ) + "%2B" + ret.substring( pos+1 )
			pos = ret.indexOf( '+' )
			}
		return ret
	}
}

function WSSInternalURLs()
{
}
WSSInternalURLs.URLPARAM_API      = 'psapi'
WSSInternalURLs.URLPARAM_TEMPLATE = 'page'
WSSInternalURLs.URLPARAM_DEENCODE = 'deenc'

WSSInternalURLs.ESIG              = 'esig'
WSSInternalURLs.ESIG_CCNO         = 'esigccno'
WSSInternalURLs.ESIG_REASON       = 'esigreason'
WSSInternalURLs.ESIG_USER_ID      = 'esiguserid'
WSSInternalURLs.ESIG_PWD          = 'esigpwd'

function BuildInternalURL( nAPI, sParams, sTemplateName )
{
	var params = '';
	if ( !isEmptyString(sParams) )
		params = '&' + sParams;

	var tpl = '';
	if ( !isEmptyString(sTemplateName) )
		tpl = '&' + WSSInternalURLs.URLPARAM_TEMPLATE + '=' + sTemplateName;

	// Get the current link id
	var linkid = getLinkID()

	// Build the URL
	var sURL = 
		phnxapp
	     + 'linkid=' + linkid
		 + '&' + WSSInternalURLs.URLPARAM_API + '=' + nAPI
		 + params
		 + tpl;
//	alert(sURL);
	return sURL;
}

function InternalURL( w, ePageID, sParams, sTemplateName )
{
	var templateName = '';
	if ( isEmptyString(sTemplateName) )
	{
		if ( g_WSSPageTemplateMap != null )
			templateName = g_WSSPageTemplateMap[ePageID]
	}
	else
		templateName = sTemplateName

	var nAPI = 0;
	if ( g_WSSPageAPIMap != null )
		nAPI = g_WSSPageAPIMap[ ePageID ];

	// Debugging check...
	if ( nAPI == null )
		alert( 'Error in call to InternalURL:\n' +
		       'nAPI is undefined.\n' +
		       'ePageID = ' + ePageID + '\n' +
			   'sTemplateName = ' + sTemplateName );

	var sURL = BuildInternalURL(nAPI, sParams, templateName )
	if ( w == null )
		return sURL

	w.location.href=sURL
}

// Carried over from OLS and modified to make the request through
// the extension DLL instead of direct template request.
function LoadTemplate( w, sTemplateName, sParams )
{
	var sURL = BuildInternalURL(WSSAPIs.NONE, sParams, sTemplateName )
	if ( w == null )
		return sURL

	w.location.href=sURL
}

function InternalURL_Bulletins( w, sTemplateName )
{
	return InternalURL(w, WSSPageIDs.BULLETINS, null, sTemplateName)
}

function InternalURL_CatCurriculumList( w, sTemplateName )
{
	// Mask is for curriculum information only (0)
	// Request type is for "available" (1) curriculums
	return InternalURL(w, WSSPageIDs.CATCURRICULUMLIST, 'requesttype=1&mask=0', sTemplateName)
}

function InternalURL_ChatroomList( w, sTemplateName )
{
	return InternalURL(w, WSSPageIDs.CHATROOMLIST, null, sTemplateName)
}

function InternalURL_ChangePwd( w, sTemplateName )
{
	return InternalURL(w, WSSPageIDs.CHANGEPASSWORD, null, sTemplateName)
}

function InternalURL_ClassMenu( w, sTemplateName )
{
	return InternalURL(w, WSSPageIDs.CLASSSEARCH, null, sTemplateName)
}

function InternalURL_CourseMenu( w, sTemplateName )
{
	return InternalURL(w, WSSPageIDs.COURSESEARCH, null, sTemplateName)
}

function InternalURL_CurriculumList( w, sTemplateName )
{
	// Mask only needs courses (1), regInfo (2), and content (4)
	// Request type is "assigned" curriculums (0)
	return InternalURL(w, WSSPageIDs.CURRICULUMLIST, 'requesttype=0&mask=7', sTemplateName)
}

function InternalURL_Evaluate( w, sTemplateName )
{
	return InternalURL(w, WSSPageIDs.EVALUATECLASSES, null, sTemplateName)
}

function InternalURL_Finalize( w, sTemplateName )
{
	return InternalURL(w, WSSPageIDs.FINALIZECLASSES, null, sTemplateName)
}

function InternalURL_FinalizeClass( w, sTemplateName, sLocator, sHOKey )
{
	var sParams = 'loc=' + escapeStr(sLocator);
	if ( !isEmptyString(sHOKey) )
		sParams += '&hokey=' + escapeStr(sHOKey)

	return InternalURL(w, WSSPageIDs.FINALIZECLASS, sParams, sTemplateName)
}

function InternalURL_GetFinalizeContent( w, sTemplateName, sLocator, sCOKey )
{
	var sParams = ''

	sParams += 'loc=' + escapeStr(sLocator)
	sParams += '&cokey=' + escapeStr(sCOKey)
	
	return InternalURL(w, WSSPageIDs.GETFINALIZECONTENT, sParams, sTemplateName)
}

function InternalURL_DoFinalizeContent( w, sTemplateName, sLocator, sCOKey, yuk, status, score )
{
	var sParams = ''

	sParams += 'ffLocator=' + escapeStr(sLocator)
	sParams += '&ffReadOnly=0'

	sParams += '&ffNumCOKeys=1'
	sParams += '&ffCOKey1=' + escapeStr(sCOKey)
	
	sParams += '&ffNumUKeys=1'
	sParams += '&ffUKey1=' + escapeStr(yuk)
	sParams += '&ffStatus1=' + escapeStr(status)
	sParams += '&ffScore1=' + escapeStr(score)
	
	if ( isEmptyString(sTemplateName) )
		sTemplateName = 'FinalizeContentOptions.htm'

	var sURL = BuildInternalURL(WSSAPIs.DOFINALIZECONTENT, sParams, sTemplateName )
	if ( w == null )
		return sURL

	w.location.href=sURL
}
	
function InternalURL_Help( w, sTemplateName, eHelpID )
{
	// Call pop-up window routine
	doHelp(eHelpID)
}

function InternalURL_MainMenu( w, sTemplateName )
{
	return InternalURL(w, WSSPageIDs.MAINMENU, null, sTemplateName)
}

function InternalURL_MyCal( w, sTemplateName )
{
	return InternalURL(w, WSSPageIDs.MYCALENDAR, null, sTemplateName)
}

function InternalURL_News( w, sTemplateName )
{
	// Call pop-up window routine
	doNews()
}

function InternalURL_Online( w, sTemplateName )
{
	return InternalURL(w, WSSPageIDs.ONLINE, null, sTemplateName)
}

function InternalURL_PersonData( w, sTemplateName )
{
	return InternalURL(w, WSSPageIDs.PERSONDETAIL, null, sTemplateName)
}

function InternalURL_Plan( w, sTemplateName )
{
	return InternalURL(w, WSSPageIDs.PLAN, null, sTemplateName)
}

function InternalURL_PlanNote( w, sTemplateName )
{
	return InternalURL(w, WSSPageIDs.PLANNOTE, null, sTemplateName)
}

function InternalURL_RecordPlanNote( w, sTemplateName )
{
	return InternalURL(w, WSSPageIDs.PLANNOTERESULT, null, sTemplateName)
}

function InternalURL_DeletePlanNote( w, sTemplateName )
{
	return InternalURL(w, WSSPageIDs.DELETEPLANNOTE, 'delete=1', sTemplateName)
}

function InternalURL_DeletePlanNoteConfirm( w, sTemplateName )
{
	return InternalURL(w, WSSPageIDs.DELETEPLANNOTECONFIRM, null, sTemplateName)
}

function InternalURL_PlanInput( w, sTemplateName )
{
	return InternalURL(w, WSSPageIDs.PLANINPUT, null, sTemplateName);
}

function InternalURL_PlanDeleteConfirm( w, sTemplateName )
{
	return InternalURL(w, WSSPageIDs.PLANDELETE, null,  sTemplateName)
}

function InternalURL_PlanDelete( w, nOrdinal, sTemplateName )
{
	return InternalURL(w, WSSPageIDs.PLANDELETERESULT, 'ordinal=-' + nOrdinal, sTemplateName)
}

function InternalURL_RecordPlanInput( w, sTemplateName )
{
	return InternalURL(w, WSSPageIDs.PLANINPUTRESULT, null, sTemplateName)
}

function InternalURL_DoCourseTurnaround( w, sTemplateName, code, loc, xnumber, fSchedule )
{
	var sParams = 'code=' + escapeStr(code)
	if ( !isEmptyString(loc) )
		sParams += '&loc=' + escapeStr(loc)
	if ( !isEmptyString(xnumber) )
		sParams += '&xnumber=' + escapeStr(xnumber)

	var sURL = null;
	if ( isEmptyString(loc) && isEmptyString( xnumber ) )
		{
		// Go to CourseTurnaround.htm to determine if the course exists or not.
		// If it does not, then it will redirect to Schedule of Classes.
		if ( isEmptyString(sTemplateName) )
			sTemplateName = 'CourseTurnaround.htm'

		if ( fSchedule )
			sParams += '&sched=1';

		sURL = BuildInternalURL(WSSAPIs.COURSEDETAIL, sParams, sTemplateName )
		}
	else // we have a locator or xnumber for a class, ClassDetail.htm will redirect if it is an Online Class.
		sURL = BuildInternalURL(WSSAPIs.CLASSDETAIL, sParams, sTemplateName )

	if ( w == null )
		return sURL

	w.location.href=sURL
}

function InternalURL_PrereqCourseTurnaround( w, sTemplateName, sCode, sLocator )
{
	InternalURL_DoCourseTurnaround( w, sTemplateName, sCode, sLocator, null )
}

function InternalURL_TranscriptUpdate(w, sTemplateName)
	{
	if ( isEmptyString(sTemplateName) )
		sTemplateName = 'TranscriptUpdate.htm'

	return InternalURL_Transcript(w, sTemplateName)
	}

function InternalURL_PlanRegUpdate(w, sTemplateName)
{
	if ( isEmptyString(sTemplateName) )
		sTemplateName = 'PlanRegUpdate.htm'

	return InternalURL_Plan(w, sTemplateName)
}

function InternalURL_CurrRegUpdate(w, sTemplateName)
{
	if ( isEmptyString(sTemplateName) )
		sTemplateName = 'CurrRegUpdate.htm'

	// Mask only needs courses (1) & regInfo (2)
	// Request type is "assigned" curriculums (0)
	return InternalURL(w, WSSPageIDs.CURRICULUMLIST, 'requesttype=0&mask=3', sTemplateName)
}

function InternalURL_RecordCompletedTraining( w, sTemplateName )
{
	return InternalURL(w, WSSPageIDs.RCTCLASSES, null, sTemplateName)
}

function InternalURL_RCTStudent( w, sTemplateName, sLocator )
{
	return InternalURL(w, WSSPageIDs.RCTSTUDENT, 'loc=' + sLocator + '&viewdata=0', sTemplateName)
}

function InternalURL_Requests( w, sTemplateName )
{
	return InternalURL(w, WSSPageIDs.REQUESTS, null, sTemplateName)
}

function InternalURL_DoARequest( w, nRequestID, sRequestString, sTemplateName)
{
	return InternalURL(w, WSSPageIDs.DOAREQUEST, "req=REQUEST" + nRequestID + ".txt&reqstr=" + escapeStr(sRequestString), sTemplateName)
}

function InternalURL_Roster( w, sTemplateName )
{
	return InternalURL(w, WSSPageIDs.ROSTERTRANSCRIPT, null, sTemplateName)
}

function InternalURL_SignOn( w, sTemplateName )
{
	return InternalURL(w, WSSPageIDs.SIGNON, null, sTemplateName)
}

function InternalURL_Transcript( w, sTemplateName )
{
	return InternalURL(w, WSSPageIDs.TRANSCRIPT, null, sTemplateName)
}

function InternalURL_TranscriptCourseTurnaround( w, sTemplateName, code, loc, xnumber )
{
	return InternalURL_DoCourseTurnaround( w, sTemplateName, code, loc, xnumber )
}

function InternalURL_Virtual( w, sTemplateName )
{
	return InternalURL(w, WSSPageIDs.VIRTUALSINPROGRESS, null, sTemplateName)
}

function InternalURL_DoVirtualCancel( w, sTemplateName, sLocator )
{
	if ( isEmptyString(sTemplateName) )
		sTemplateName = "VirtualCancelConfirm.htm"

	var sURL = BuildInternalURL(WSSAPIs.VIRTUALCANCEL, 'loc=' + escapeStr(sLocator), sTemplateName )
	if ( w == null )
		return sURL

	w.location.href=sURL
}

function InternalURL_VirtualCancelConfirm( w, sTemplateName, sName, sLocator )
{
	if ( isEmptyString(sTemplateName) )
		sTemplateName = "VirtualCancel.htm"

	return LoadTemplate(w, sTemplateName, 'name=' + escapeStr(sName) + '&loc=' + escapeStr(sLocator) )
}

function InternalURL_DoVirtualFinish( w, sTemplateName, sLocator, sCode )
{
	if ( isEmptyString(sTemplateName) )
		sTemplateName = "VirtualFinishConfirm.htm"

	var sURL = BuildInternalURL(WSSAPIs.VIRTUALFINISH, 'loc=' + escapeStr(sLocator) + '&code=' + escapeStr(sCode), sTemplateName )
	if ( w == null )
		return sURL

	w.location.href=sURL
}

function InternalURL_VirtualFinishConfirm( w, sTemplateName, sName, sLocator, sCode )
{
	if ( isEmptyString(sTemplateName) )
		sTemplateName = "VirtualFinish.htm"

	return LoadTemplate(w, sTemplateName, 'name=' + escapeStr(sName) + '&loc=' + escapeStr(sLocator) + '&code=' + escapeStr(sCode) )
}

function InternalURL_ClassAttend( w, sTemplateName, sLocator, sSessKey )
{
	return InternalURL(w, WSSPageIDs.CLASSATTEND, 'loc=' + escapeStr(sLocator) +
	                                              '&sesskey=' + escapeStr(sSessKey) +
	                                              '&attype=A', sTemplateName)
}

function InternalURL_ClassPlayback( w, sTemplateName, sLocator, sSessKey )
{
	return InternalURL(w, WSSPageIDs.CLASSATTEND, 'loc=' + escapeStr(sLocator) +
	                                              '&sesskey=' + escapeStr(sSessKey) +
 	                                              '&attype=P', sTemplateName)
}

function InternalURL_Message( w, sTemplateName )
{
	// The Message URL is simplay a mailto: link
	var sURL = 'mailto:' + objCore.scMessage.sMailto
	if ( w == null )
		return sURL

	// Load the mailto in the top frameset to avoid warning message when using SSL.
	// If using SSL, the any mailto executed in a frames source will cause the "secure
	// and nonsecure" warning to pop up.  Executing it in the top frameset prevents this
	// warning from being displayed.
	objCore.location.href = sURL
}

function InternalURL_ClassDetail( w, sTemplateName, loc, xnumber )
{
	var sParams = ''

	// Always pass the "loc" parameter, even if the "loc" value is empty.
	// This is because some LMS_APIs expect this parameter being present.
	sParams += 'loc=' + escapeStr(loc)

	// Always pass the "xnumber" parameter for the same reason.
	// Better to pass a blank value than none at all.
	sParams += '&xnumber=' + escapeStr(xnumber)

	return InternalURL(w, WSSPageIDs.CLASSDETAIL, sParams, sTemplateName)
}

function InternalURL_ClassDetailDisplay( w, sTemplateName, sLocator, bForceSignOn, eShowTab )
{
	var sParams = ''

	// Always pass the "loc" parameter, even if we are just loading the template.
	// This is because some LMS_APIs expect this parameter being present.
	sParams += 'loc=' + escapeStr(sLocator)

	if ( eShowTab != null )
		sParams += '&showtab=' + escapeStr(eShowTab)

	if ( !bForceSignOn && !objCore.isLoggedIn() )
		return LoadTemplate( w, g_WSSPageTemplateMap[WSSPageIDs.CLASSDETAILDISPLAY], sParams )

	sParams += '&authreq=' + ( bForceSignOn ? "1" : "0" )

	return InternalURL(w, WSSPageIDs.CLASSDETAILDISPLAY, sParams, sTemplateName);
}

function InternalURL_ClassRegConfirm( w, sTemplateName, sAction, fApproval, fPretest, fPrereqs )
{
	var sParams = ''
	sParams += 'action=' + escapeStr(sAction)
	sParams += '&approval=' + (fApproval ? '1' : '0')
	sParams += '&pretest=' + (fPretest ? '1' : '0')
	sParams += '&prereqs=' + (fPrereqs ? '1' : '0')
	
	return InternalURL(w, WSSPageIDs.CLASSREGCONFIRM, sParams, sTemplateName)
}

function InternalURL_ClassRegWrite( w, sTemplateName, sLocator, sStatusGroup )
{
	return InternalURL(w, WSSPageIDs.CLASSREGWRITE, 'loc=' + escapeStr(sLocator) + '&statusgroup=' + escapeStr(sStatusGroup), sTemplateName)
}

function InternalURL_ClassRegInput( w, sTemplateName, sLocator, sAction)
{
	var sParams = ''
	sParams += 'loc=' + escapeStr(sLocator)
	sParams += '&action=' + escapeStr(sAction)

	return InternalURL(w, WSSPageIDs.CLASSREGINPUT, sParams, sTemplateName)
}

function InternalURL_Registration( w, sTemplateName, sLocator, fileID)
{
	return InternalURL(w, WSSPageIDs.REGISTRATION, 'loc=' + escapeStr(sLocator) + '&fileid=' + escapeStr(fileID), sTemplateName)
}

function InternalURL_ClassRoster( w, sTemplateName, sLocator )
{
	return InternalURL(w, WSSPageIDs.CLASSROSTER, 'loc=' + escapeStr(sLocator), sTemplateName)
}

function InternalURL_CoursePrerequisites( w, sTemplateName, sCode )
{
	return InternalURL(w, WSSPageIDs.PREREQUISITES, 'code=' + escapeStr(sCode), sTemplateName)
}

function InternalURL_CourseEquivalents( w, sTemplateName, sCode )
{
	return InternalURL(w, WSSPageIDs.EQUIVALENTSFS, 'code=' + escapeStr(sCode) + '&viewdata=1', sTemplateName)
}

function InternalURL_DoSignOn( w, sTemplateName, uk, pwd, lname, direct )
{
	if ( isEmptyString(sTemplateName) )
		sTemplateName = 'SignOnDisplay.htm'

	var sURL = BuildInternalURL(WSSAPIs.DOSIGNON, 'uniquekey=' + escapeStr(uk) + '&password=' + escapeStr(pwd) + '&lastname=' + escapeStr(lname) + '&direct=' + escapeStr(direct), sTemplateName )
	if ( w == null )
		return sURL

	w.location.href=sURL
}

function InternalURL_DoSignOff( w, sTemplateName )
{
	if ( isEmptyString(sTemplateName) )
		sTemplateName = 'DoSignOff.htm'

	var sURL = BuildInternalURL(WSSAPIs.DOSIGNOFF, null, sTemplateName )
	if ( w == null )
		return sURL

	w.location.href=sURL
}

function InternalURL_PersonAdd( w, sTemplateName )
{
	return InternalURL(w, WSSPageIDs.PERSONADD, null, sTemplateName)
}

function InternalURL_PersonAddDisplay( w, sTemplateName )
{
	if ( isEmptyString(sTemplateName) )
		sTemplateName = "PersonAddDisplay.htm"

	return LoadTemplate(w, sTemplateName)
}

function InternalURL_ClassList( w, sTemplateName )
{
	return InternalURL( w, WSSPageIDs.CLASSLIST, null, sTemplateName );
}

function InternalURL_ClassSchedule( w, sTemplateName, sCode )
{
	return InternalURL( w, WSSPageIDs.CLASSSCHEDULE, 'code=' + escapeStr(sCode), sTemplateName )
}

function InternalURL_CourseList( w, sTemplateName )
{
	return InternalURL( w, WSSPageIDs.COURSELIST, null, sTemplateName );
}

function InternalURL_CourseDetail( w, sTemplateName, sCode, eShowTab )
{
	var sParams = 'code=' + escapeStr(sCode)
	if ( eShowTab != null )
		sParams += '&showtab=' + escapeStr(eShowTab)

	return InternalURL( w, WSSPageIDs.COURSEDETAIL, sParams, sTemplateName );
}

function InternalURL_CourseDetailDisplay( w, sTemplateName, sCode, fGetRegInfo, fSilent, eShowTab )
{
	var sParams = 'code=' + escapeStr(sCode)
	if ( eShowTab != null )
		sParams += '&showtab=' + escapeStr(eShowTab)

	if ( !fGetRegInfo )
		return LoadTemplate( w, g_WSSPageTemplateMap[WSSPageIDs.COURSEDETAILDISPLAY], sParams )

	if ( fSilent )
		sParams += '&silent=1'

	return InternalURL(w, WSSPageIDs.COURSEDETAILDISPLAY, sParams, sTemplateName);
}

function InternalURL_RCTStudentDisplay( w, sTemplateName )
{
	if ( isEmptyString(sTemplateName) )
		sTemplateName = "RCTStudentDisplay.htm"

	return LoadTemplate(w, sTemplateName)
}

function InternalURL_CurriculumListDisplay( w, sTemplateName )
{
	if ( isEmptyString(sTemplateName) )
		sTemplateName = "CurrListDisplay.htm"

	return LoadTemplate(w, sTemplateName)
}

function InternalURL_CatCurriculumListDisplay( w, sTemplateName )
{
	if ( isEmptyString(sTemplateName) )
		sTemplateName = "CatCurrListDisplay.htm"

	return LoadTemplate(w, sTemplateName)
}

function InternalURL_CurriculumDetailDisplay( w, sTemplateName )
{
	if ( isEmptyString(sTemplateName) )
		sTemplateName = "CurrDetailDisplay.htm"

	return LoadTemplate(w, sTemplateName)
}

function InternalURL_CatCurriculumDetailDisplay( w, sTemplateName, key, fGetCourses )
{
	if ( isEmptyString(sTemplateName) )
		sTemplateName = "CurrDetailDisplay.htm"

	if ( fGetCourses )
	{
		var sURL = BuildInternalURL(WSSAPIs.CURRICULUMCOURSES, 'currkey=' + key + '&mask=4', sTemplateName )
		if ( w == null )
			return sURL

		w.location.href=sURL
	}
	else
		return LoadTemplate(w, sTemplateName)
}

function InternalURL_CurriculumEnrollConfirm( w, sTemplateName )
{
	return InternalURL(w, WSSPageIDs.CURRENROLLCONFIRM, null, sTemplateName)
}

function InternalURL_DoCurriculumEnroll( w, sTemplateName, sCurrKey )
{
	return InternalURL(w, WSSPageIDs.CURRENROLLRESULT, 'currkey=' + escapeStr(sCurrKey), sTemplateName)
}

function InternalURL_ClassContent( w, sTemplateName, sLocator )
{
	return InternalURL(w, WSSPageIDs.COURSECONTENT, 'fileid=2&loc=' + escapeStr(sLocator), sTemplateName)
}

function InternalURL_CourseContent( w, sTemplateName, sCode, sLocator )
{
	return InternalURL(w, WSSPageIDs.COURSECONTENT, 'fileid=1&code=' + escapeStr(sCode) + '&loc=' + escapeStr(sLocator), sTemplateName)
}

function InternalURL_eCourseDetail( w, sTemplateName, sCode )
{
	return InternalURL(w, WSSPageIDs.COURSECONTENT, 'code=' + escapeStr(sCode), sTemplateName)
}

function InternalURL_GoToSE( w, sTemplateName, sCode, sURL )
{
	return InternalURL( w, WSSPageIDs.GOTOSE, 'code=' + escapeStr(sCode), sTemplateName);
}

function InternalURL_eCourseDetailDisplay( w, sTemplateName )
{
	if ( isEmptyString(sTemplateName) )
		sTemplateName = "eCourseDetailDisplay.htm";

	return LoadTemplate(w, sTemplateName)
}

function InternalURL_ClassSearchDisplay( w, sTemplateName )
{
	if ( isEmptyString(sTemplateName) )
		sTemplateName = "ClassSearchDisplay.htm";

	return LoadTemplate(w, sTemplateName)
}

function InternalURL_CourseSearchDisplay( w, sTemplateName )
{
	if ( isEmptyString(sTemplateName) )
		sTemplateName = "CourseSearchDisplay.htm";

	return LoadTemplate(w, sTemplateName)
}

function InternalURL_GetInfoSection( w, sTemplateName, sLoc, sCode, sCategory, sSection, sDisplayName )
{
	return InternalURL(w, WSSPageIDs.INFOSECTION, 'loc=' + escapeStr(sLoc) + '&code=' + escapeStr(sCode) + '&category=' + escapeStr(sCategory) + '&section=' + escapeStr(sSection) + '&displayname=' + escapeStr(sDisplayName), sTemplateName)
}	

function InternalURL_AddSelfToGroup( w, sTemplateName )
{
	return InternalURL(w, WSSPageIDs.ADDSELFTOGROUP, null, sTemplateName)
}

function InternalURL_GetPopApprover( w, sTemplateName, loc )
{
	var sParams = ''

	// Always pass the "loc" parameter, even if the "loc" value is empty.
	// This is because some LMS_APIs expect this parameter being present.
	sParams += 'loc=' + escapeStr(loc)

	return InternalURL(w, WSSPageIDs.POPAPPROVER, sParams, sTemplateName)
}

function InternalURL_RegistrationApprovals( w, sTemplateName)
{
	return InternalURL(w, WSSPageIDs.REGAPPROVALS, null, sTemplateName)
}

function InternalURL_ApproveReg( w, sTemplateName, loc, yuk, option, sESig )
{
	if ( isEmptyString(sTemplateName) )
		sTemplateName = 'RegApprovalsOptions.htm'

	var sURL = BuildInternalURL(WSSAPIs.WRITEAPPROVEREG, 'loc=' + escapeStr(loc) + '&uk=' + escapeStr(yuk) +'&option=' + option + sESig, sTemplateName )
	if ( w == null )
		return sURL

	w.location.href=sURL
}

function InternalURL_FinalizeReg( w, sTemplateName, loc, yuk, status, grade, sESig )
{
	if ( isEmptyString(sTemplateName) )
		sTemplateName = 'FinalizeClassOptions.htm'

	var sURL = BuildInternalURL(WSSAPIs.DOFINALIZECLASS,
	                           'loc=' + escapeStr(loc) + '&yuk=' + escapeStr(yuk) +
	                           '&status=' + escapeStr(status) + '&grade=' + escapeStr(grade) + sESig, sTemplateName )
	if ( w == null )
		return sURL

	w.location.href=sURL
}

function InternalURL_ESigTurnaround( w, api, params )
{
	var sURL = BuildInternalURL(api, params )
	if ( w == null )
		return sURL

	w.location.href=sURL
}

function InternalURL_Managers( w, sTemplateName )
	{
	return InternalURL(w, WSSPageIDs.MANAGERSFS, null, sTemplateName)
	}

function InternalURL_SetEffectiveUser( w, sTemplateName, yuk, url )
	{
	if ( isEmptyString(sTemplateName) )
		{
		if ( isEmptyString( url  ) )
			sTemplateName = 'ManagersDisplay.htm'
		else
			sTemplateName = 'ManagersHandler.htm'
		}

	var sURL = BuildInternalURL(WSSAPIs.SETEFFECTIVEUSER, 'yuk=' + escapeStr(yuk) + '&url=' + escapeStr(url), sTemplateName )
	if ( w == null )
		return sURL

	w.location.href=sURL
	}

function InternalURL_APPLink( w, sTemplateName, sTheURL, sTarget, coursecode, loc, scrn )
{
	if ( isEmptyString(sTemplateName) )
		sTemplateName = 'Turnaround.htm'

	var params = 'url=' + escapeStr(sTheURL)
	if ( sTarget != null )
		params += '&target=' + escapeStr(sTarget)
	if ( coursecode != null )
		params += '&coursecode=' + escapeStr(coursecode)
	if ( loc != null )
		params += '&loc=' + escapeStr(loc)
	if ( scrn != null )
		params += '&scrn=' + escapeStr(scrn)

	var sURL = BuildInternalURL(WSSAPIs.APPLINK, params, sTemplateName )
	if ( w == null )
		return sURL

	var fWindowIsHidden = ( w.name.toLowerCase().search( /hidden$/i ) >= 0 );
	if ( fWindowIsHidden ) // Special handling for when the applink targets a hidden frame.
		w.location.replace( sURL );
	else
		w.location.href=sURL
}

function psRetrieveSCOTrace( w, userid )
{
	w.location.href=BuildInternalURL( WSSAPIs.REQSCOTRACE, 'userid=' + escapeStr(userid), 'SCOTraceBody.htm' )
}

// OLS 4 "internal URLs"

function psPingServer( w, page, contentping )
{
	// Search for contentping=[contentping] in the current href.
	// If it is there, then we have already begun the ping, so just reload.
	// If it isn't, build the ping URL and replace
	if ( w.location.href.indexOf( "contentping=" + contentping ) > -1 )
		{
		// Do a reload because it does not fill the browser history list with pings, and
		// it does not reload the current active frame in screen readers.
		w.location.reload( true );
		}
	else
		{
		// Do a replace so that we don't fill the browser history list with pings!
		var params = 'contentping=' + (contentping != null ? contentping : 0);
		//alert( BuildInternalURL( WSSAPIs.PING, params, page ) )
		w.location.replace( BuildInternalURL( WSSAPIs.PING, params, page ) )
		}
}

function psRequestConnectData( w, connecttype, page )
{
	w.location.href=BuildInternalURL( WSSAPIs.REQ_CONNECT_DATA, 'ct=' + escapeStr(connecttype), page )
}

function psRequestConnectDataSmall( w, page )
{
	var sURL = BuildInternalURL( WSSAPIs.REQ_CONNECT_DATA_SM, null, page )
	if ( w == null )
		return sURL

	w.location.href = sURL
}

function psStopRunningContent( w, sTemplateName )
{
	if ( isEmptyString(sTemplateName) )
		sTemplateName = "StopRunningContent.htm";

	return LoadTemplate( w, sTemplateName )
}

function InternalURL_StartContent( w, startmode, launchcontext, coursecode, locator, sesskey, launchkey, launchpwd, inherit, newregok, stoppage, page )
	{
	var sParams = '';
	sParams = 'startmode='      + escapeStr(startmode)
	        + '&launchcontext=' + escapeStr(launchcontext)
	        + '&coursecode='    + escapeStr(coursecode)
	        + '&loc='           + escapeStr(locator)
	        + '&sesskey='       + escapeStr(sesskey)
	        + '&launchkey='     + escapeStr(launchkey)
	        + '&launchpwd='     + escapeStr(launchpwd)
	        + '&inherit='       + escapeStr(inherit)
	        + '&newregok='      + escapeStr(newregok)
	        + '&stoppage='      + escapeStr(stoppage);

	var sURL = BuildInternalURL( WSSAPIs.START_COURSE, sParams, page )
	if ( w == null )
		return sURL

	w.location.href = sURL
	}

function psStartCourse( w, currkey, coursecode, contentkey, topickey, stoppage, page )
	{
	alert('psStartCourse called - should be calling InternalURL_StartContent')
//	var sURL = BuildInternalURL( WSSAPIs.START_COURSE, 'currkey=' + escapeStr(currkey) + '&coursecode=' + escapeStr(coursecode) + '&coursekey=' + escapeStr(contentkey) + '&topickey=' + escapeStr(topickey) + '&stoppage=' + escapeStr(stoppage), page )
//	if ( w == null )
//		return sURL
//
//	w.location.href= sURL
	}

function psContinueCourse( w, currkey, coursecode, contentkey, topickey, stoppage )
{
	w.location.href=BuildInternalURL( WSSAPIs.CONTINUE_COURSE, 'currkey=' + escapeStr(currkey) + '&coursecode=' + escapeStr(coursecode) + '&coursekey=' + escapeStr(contentkey) + '&topickey=' + escapeStr(topickey) + '&stoppage=' + escapeStr(stoppage) )
}

function psBrowseCourse( w, currkey, coursecode, contentkey, topickey, stoppage )
{
	w.location.href=BuildInternalURL( WSSAPIs.BROWSE_COURSE, 'currkey=' + escapeStr(currkey) + '&coursecode=' + escapeStr(coursecode) + '&coursekey=' + escapeStr(contentkey) + '&topickey=' + escapeStr(topickey) + '&stoppage=' + escapeStr(stoppage) )
}

function psShowContentInfoPage( w, key )
{
	w.location.href=BuildInternalURL( WSSAPIs.CONTENT_INFO, 'coursekey=' + escapeStr(key) )
}

function InternalURL_StopContent( w, coursecode, status, startnext, lastpage, stoppage )
	{
	var sParams = '';
	sParams = 'coursecode=' + escapeStr(coursecode)
	        + '&status='    + escapeStr(status)
	        + '&startnext='	+ escapeStr(startnext)
	        + '&lastpage='  + escapeStr(lastpage)
	        + '&stoppage='  + escapeStr(stoppage);

	var page = "ContentStop.htm";
	
	//var sURL = BuildInternalURL( WSSAPIs.NONE, sParams, page )
	var sURL = BuildInternalURL( WSSAPIs.STOP_COURSE, sParams, page )
	if ( w == null )
		return sURL

	w.location.href = sURL
	}

function psStopCourse( w, key, lastpage, targetpage, status )
{
	alert('psStopCourse called - should be calling InternalURL_StopContent')
	//w.location.href=BuildInternalURL( WSSAPIs.STOP_COURSE, 'coursekey=' + escapeStr(key) + '&lastpage=' + escapeStr(lastpage) + '&stoppage=' + escapeStr(targetpage) + '&status=' + escapeStr(status) )
}

function psScore( w, contentkey, category, itemid, points, nextpage )
{
	w.location.href=BuildInternalURL( WSSAPIs.SCORE, 'coursekey=' + escapeStr(contentkey) + '&category=' + escapeStr(category) + '&scoreid=' + escapeStr(itemid) + '&score=' + escapeStr(points) + '&nextpage=' + escapeStr(nextpage) )
}

function psSetVariable( w, contentkey, category, variableid, value )
{
	w.location.href=BuildInternalURL( WSSAPIs.SET_VARIABLE, 'coursekey=' + escapeStr(contentkey) + '&category=' + escapeStr(category) + '&variableid=' + escapeStr(variableid) + '&value=' + escapeStr(value) )
}

function psExitChatRoom( w, roomid, msg )
{
	w.location.href=BuildInternalURL( WSSAPIs.CHATROOMEXIT, 'roomid=' + escapeStr(roomid) + '&msg=' + escapeStr(msg), "ChatRoomExit.htm" )
}

function psRefreshChatRoom( w, roomid )
{
	w.location.href=BuildInternalURL( WSSAPIs.CHATROOMREFRESH, 'roomid=' + escapeStr(roomid), 'ChatRoomBody.htm' )
}

function psAiccReceivedExitAU( w, key, count, page )
{
	w.location.href=BuildInternalURL( WSSAPIs.AICC_EXITAU_RECEIVED, 'coursekey=' + escapeStr(key) + '&count=' + escapeStr(count) + '&page=' + escapeStr(page) )
}

function psGotoQuestion( w, contentkey, questionkey, time )
{
	w.location.href=BuildInternalURL( WSSAPIs.GOTO_QUESTION, 'coursekey=' + escapeStr(contentkey) + '&questionkey=' + escapeStr(questionkey) + '&time=' + escapeStr(time) )
}

// End OLS 4 "Internal URLs"

// Begin LMS 5.5 Skills "Internal URLs"

function InternalURL_SkillsTranscript( w, sTemplateName )
{
	return InternalURL(w, WSSPageIDs.SKILLSTRANSCRIPT, null, sTemplateName)
}

function InternalURL_SkillsPlan( w, sTemplateName )
{
	return InternalURL(w, WSSPageIDs.SKILLSPLAN, null, sTemplateName)
}

function InternalURL_SkillsPlanUpdate( w, sTemplateName )
{
	if ( isEmptyString(sTemplateName) )
		sTemplateName = 'SkillsPlanUpdate.htm'

	return InternalURL(w, WSSPageIDs.SKILLSPLAN, null, sTemplateName)
}

function InternalURL_360Assessments( w, sTemplateName )
{
	return InternalURL(w, WSSPageIDs.SKILLS360SUMMARYFS, null, sTemplateName)
}

function InternalURL_360SummaryUpdate( w, sTemplateName )
{
	if ( isEmptyString(sTemplateName) )
		sTemplateName = 'Skills360SummaryUpdate.htm'

	return InternalURL(w, WSSPageIDs.SKILLS360SUMMARYFS, null, sTemplateName)
}

function InternalURL_ProfileCompare( w, sTemplateName )
{
	return InternalURL(w, WSSPageIDs.PROFILESEARCHFS, null, sTemplateName)
}

function InternalURL_DoProfileCompare( w, sTemplateName, profcode )
{
	return InternalURL(w, WSSPageIDs.PROFILECOMPAREFS, 'profcode=' + escapeStr(profcode), sTemplateName)
}

function InternalURL_GetPopScale( w, sTemplateName, scalecode )
{
	return InternalURL(w, WSSPageIDs.POPSCALE, 'scalecode=' + escapeStr(scalecode), sTemplateName)
}

function InternalURL_GetPopSkill( w, sTemplateName, skillcode )
{
	return InternalURL(w, WSSPageIDs.POPSKILL, 'skillcode=' + escapeStr(skillcode), sTemplateName)
}

function InternalURL_SkillsPlanInput( w, sTemplateName, scalecode, scalekey )
{
return InternalURL(w, WSSPageIDs.SKILLSPLANINPUT, 'scalecode=' + (scalecode != null ? escapeStr(scalecode) : '') + '&scalekey=' + (scalekey != null ? scalekey : ''), sTemplateName);
}

function InternalURL_SkillsPlanDelete( w, sTemplateName )
{
	return InternalURL(w, WSSPageIDs.SKILLSPLANDELETE, null, sTemplateName);
}

function InternalURL_SelfAssess( w, sTemplateName, scalecode )
{
	return InternalURL(w, WSSPageIDs.SELFASSESS, 'scalecode=' + escapeStr(scalecode), sTemplateName);
}

function InternalURL_SkillsSearch( w, sTemplateName )
{
	return InternalURL(w, WSSPageIDs.SKILLSSEARCH, null, sTemplateName);
}

function InternalURL_SkillsDrilldown( w, sTemplateName )
{
	return InternalURL(w, WSSPageIDs.SKILLSDRILLDOWN, null, sTemplateName);
}

function InternalURL_SkillsList( w, sTemplateName )
{
	return InternalURL(w, WSSPageIDs.SKILLSLISTFS, null, sTemplateName);
}

function InternalURL_SkillsResources( w, sTemplateName, skillcode, scalecode, currprof, minprof )
{
	return InternalURL(w, WSSPageIDs.SKILLSRESOURCESFS,
	                   'skillcode=' + escapeStr(skillcode) + '&scalecode=' + escapeStr(scalecode) +
					   '&currprof=' + escapeStr(currprof) + '&minprof=' + escapeStr(minprof),
					   sTemplateName);
}

function InternalURL_Skills360New( w, sTemplateName )
{
	if ( isEmptyString(sTemplateName) )
		sTemplateName = 'Skills360DataFS.htm'

	return LoadTemplate( w, sTemplateName, 'edit=1' )
}

function InternalURL_Skills360Edit( w, sTemplateName, assess_ky )
{
	var params = 'edit=1'
	if ( assess_ky != null )
		params += '&assess_ky=' + escapeStr(assess_ky)

	return InternalURL(w, WSSPageIDs.SKILLS360DATAFS, params, sTemplateName);
}

function InternalURL_Skills360View( w, sTemplateName, assess_ky )
{
	var params = 'edit=0'
	if ( assess_ky != null )
		params += '&assess_ky=' + escapeStr(assess_ky)

	return InternalURL(w, WSSPageIDs.SKILLS360DATAFS, params, sTemplateName);
}

function InternalURL_360DataUpdate( w, sTemplateName, assess_ky )
{
	if ( isEmptyString(sTemplateName) )
		sTemplateName = 'Skills360DataUpdate.htm'

	var params = 'edit=0'
	if ( assess_ky != null )
		params += '&assess_ky=' + escapeStr(assess_ky)

	return InternalURL(w, WSSPageIDs.SKILLS360DATAFS, params, sTemplateName)
}

function InternalURL_DoStart360( w, sTemplateName, assess_ky )
{
	if ( isEmptyString(sTemplateName) )
		sTemplateName = 'Skills360Start.htm'

	var sURL = BuildInternalURL(WSSAPIs.WRITE360ASSESSMENT, 'assess_ky=' + escapeStr(assess_ky) + '&start=1', sTemplateName )
	if ( w == null )
		return sURL

	w.location.href=sURL
}

function InternalURL_DoEmail360( w, sTemplateName, assess_ky )
{
	if ( isEmptyString(sTemplateName) )
		sTemplateName = 'Skills360Email.htm'

	var sURL = BuildInternalURL(WSSAPIs.WRITE360ASSESSMENT, 'assess_ky=' + escapeStr(assess_ky) + '&resend=1', sTemplateName )
	if ( w == null )
		return sURL

	w.location.href=sURL
}// End LMS 5.5 Skills "Internal URLs"

// Internal URL Utility functions

function isURLAPI( sQS, nAPI )
{
	// We scan the query string portion of the URL to see if the
	// psapi that was originally requested was the specified API.
	// Return true only if we find the specified psapi.
	var bFound = false;
	var sTarget = 'psapi=' + nAPI;
	var arPairs = sQS.split('&');
	for ( var i = 0; i < arPairs.length; i++ )
	{
		if ( arPairs[i].toLowerCase() == sTarget )
			bFound = true;
	}

	return bFound;
}

function isURLDirect( sQS, sDirect, sClient )
{
	// We scan the query string portion of the URL to see if the
	// psapi that was originally requested was the specified API.
	// Return true only if we find the specified psapi.
	var bFound = false;
	var sTarget = (sDirect + '=' + sClient).toLowerCase();
	var arPairs = sQS.split('&');
	for ( var i = 0; i < arPairs.length; i++ )
	{
		if ( arPairs[i].toLowerCase() == sTarget )
			bFound = true;
	}

	return bFound;
}
