<!-- #include virtual="/NR/System/WBC/Customizable/OptionsServer.inc" -->
<!-- #include virtual="/NR/Shared/WhatBrowser.inc" -->

<%
' ********************************************************************
' Copyright (C) 2001 Microsoft Corporation. All rights reserved.
'
'	IMPORTANT.  Please read the legal.txt file, located in the
'	"<CMS Install Directory>\Server\httpexec\WBC\Internals"
'	directory, governing the use of this internal file."
' ********************************************************************

' Define global constants
Const IDS_FRAMEWORK_VIRTUAL_PATH = "/NR/System/WBC"	' Path to WBC files. Also defined in CommonClient.js
Const IDS_FRAMEWORK_VIRTUAL_PATH_ASPX = "/MCMS"    ' Path to WBC Aspx files for Creating connected page
Const IDS_PAGECREATIONWIZARD_PATH_ASPX = "/CMS/WebAuthor/Dialogs/PageCreationWizard" ' Path to WBC Aspx files for Creating connected page


' Define querystring parameters
Const IDS_QPARAM_ATTACHICON = "wbc_attachicon"	' Also defined in CommonClient.js
Const IDS_QPARAM_DESC = "wbc_desc"
Const IDS_QPARAM_DESKRES = "wbc_deskres"	' Also defined in CommonClient.js
Const IDS_QPARAM_DISPLAY = "wbc_display"
Const IDS_QPARAM_GALLERY = "wbc_gallery"	' Also defined in CommonClient.js
Const IDS_QPARAM_IMG = "wbc_img"	' Also defined in CommonClient.js
Const IDS_QPARAM_IMGNAME = "wbc_imgname"	' Also defined in CommonClient.js
Const IDS_QPARAM_LASTMOD = "wbc_lastmod"
Const IDS_QPARAM_NREMIT = "nr_emit"	' Also defined in CommonClient.js

Const IDS_QPARAM_PHNAME = "wbc_phname"	' Also defined in CommonClient.js
Const IDS_QPARAM_PHTYPE = "wbc_phtype"	' Also define in CommonClient.js

Const IDS_QPARAM_RESOURCE = "wbc_resource"
Const IDS_QPARAM_RESTYPE = "wbc_restype"
Const IDS_QPARAM_SORT = "wbc_sort"
Const IDS_QPARAM_STARTINDEX = "wbc_startindex"
Const IDS_QPARAM_SUBMITFORM = "wbc_submitform"
Const IDS_QPARAM_URL = "wbc_url"	' Also defined in CommonClient.js
Const IDS_QPARAM_VIDEO = "wbc_video"	' Also defined in CommonClient.js
Const IDS_QPARAM_VIEWTYPE = "wbc_viewtype"
Const IDS_QPARAM_WBCPURPOSE = "wbc_purpose"	' Also defined in CommonClient.js
Const IDS_QPARAM_WBCACCEPT = "wbc_acceptcontent"	' Also defined in CommonClient.js
Const IDS_QPARAM_WBCACTION = "wbc_action"	' Also defined in CommonClient.js
Const IDS_QPARAM_NRMODE = "NRMODE"
Const IDS_QPARAM_GOTOMODE = "wbc_gotomode"



' Define querystring values
Const IDS_ACCEPTCONTENT_PHS = "Phs"
Const IDS_ACTION_APPROVE = "Approve"	' Also defined in CommonClient.js
Const IDS_ACTION_DECLINE = "Decline"	' Also defined in CommonClient.js
Const IDS_ACTION_DELETE = "Delete"
Const IDS_ACTION_SAVE = "Save"	' Also defined in CommonClient.js
Const IDS_ACTION_SAVEANDEXIT = "SaveAndExit" ' Also defined in CommonClient.js
Const IDS_ACTION_SUBMIT = "Submit"	' Also defined in CommonClient.js
Const IDS_EMIT_THINEDIT = "ThinEdit"
Const IDS_EMIT_VIEW = "View"
Const IDS_EMIT_WIN32EDIT = "Win32Edit"
Const IDS_PHTYPE_MULTIPURPOSE = "MultiPurpose"
Const IDS_PHTYPE_SINGLEATTACHMENT = "SingleAttachment"	' Also defined in CommonClient.js
Const IDS_PHTYPE_SINGLEIMAGE = "SingleImage"	' Also defined in CommonClient.js
Const IDS_PHTYPE_SINGLELINETEXT = "SingleLineText"	' Also defined in CommonClient.js
Const IDS_PHTYPE_MULTILINETEXT = "MultiLineText"	' Also defined in CommonClient.js
Const IDS_PHTYPE_THINEDITIE = "ThinEditIE"		' Also defined in CommonClient.js
Const IDS_RESTYPE_ATTACHMENT = "Attachment"	' Also defined in CommonClient.js
Const IDS_RESTYPE_IMAGE = "Image"	' Also defined in CommonClient.js
Const IDS_RESTYPE_VIDEO = "Video"	' Also defined in CommonClient.js


Const IDS_WBCPURPOSE_PREVIEWAUTHORING = "PreviewAuthoring"
Const IDS_WBCPURPOSE_BASIC = "Basic"
Const IDS_WBCPURPOSE_AUTHORING = "Authoring"
Const IDS_NRMODE_UNPUBLISHED = "Unpublished"
Const IDS_NRMODE_UPDATE = "Update"
Const IDS_GOTOMODE_EDIT = "EDIT"
Const IDS_GOTOMODE_AUTHORING = "AUTHORING"


' Define messages
Const IDS_INCORRECT_PARM = "Incorrect parameters."

Const IDS_NO_ATTACHMENT = "No Attachment"
Const IDS_NO_ATTACHMENT_VIDEO = "No Attachment or Video"
Const IDS_NO_IMAGE = "No Image"
Const IDS_NO_VIDEO = "No Video"

Const IDS_PLACEHOLDER_NO_UPLOAD = "Placeholder does not allow upload of desktop images or attachments."
Const IDS_UNAVAILABLE_FOR_BROWSER = "Unavailable for this browser"

' ---- "Never" is represented by "Jan 1, 3000"
Dim DATE_NEVER
DATE_NEVER = DateSerial(3000,1,1)

Dim IDCOL_MONTH
IDCOL_MONTH = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")

Dim IDS_TRANSPARENT_GIF
IDS_TRANSPARENT_GIF = IDS_FRAMEWORK_VIRTUAL_PATH & "/Internals/Shared/Transparent.gif"


' -----------------------------------------------------------------------------
'
'	[Public] Determine whether we are looking at a Posting or Channel
'
' -----------------------------------------------------------------------------
Function GetCurrentObject()
	' We cannot use AutoSession.This because it always returns Channel
	' if we are in a Framed Navigation script

	' We have to check for ThisPosting first because AutoSession.ThisChannel
	' is always true, so checking it first would not tell us much info
	If (Not AutoSession.ThisPosting Is Nothing) Then
		Set GetCurrentObject = AutoSession.ThisPosting
	ElseIf (Not AutoSession.ThisChannel Is Nothing) Then
		Set GetCurrentObject = AutoSession.ThisChannel
	End If
End Function

' -----------------------------------------------------------------------------
'
'	[Public] Determines whether page is before staged (site-stager) or crawled (web-crawler)
'
' -----------------------------------------------------------------------------
Function IsStagedOrCrawled()
	IsStagedOrCrawled = (IsUserAgentRobot Or AutoSession.IsModeStaging)
End Function

' -----------------------------------------------------------------------------
'
'	[Public] Determines if the WBC UI in the Unpublished mode is visible
'
' -----------------------------------------------------------------------------
Function IsWBCVisible()
	IsWBCVisible = ( AutoSession.IsModeUnpublished And _
					(Request.QueryString(IDS_QPARAM_WBCPURPOSE) <> "") And _
					(Not IsStagedOrCrawled) )
End Function

' -----------------------------------------------------------------------------
'
'	[Public] Returns if the Posting exists on the server or not
'
' -----------------------------------------------------------------------------
Function IsExistingPosting( pPosting )
	IsExistingPosting = Not ((pPosting.State = "New") And (pPosting.StateApprovedVersion = "None"))
End Function

' -----------------------------------------------------------------------------
'
'	[Public] Format date to "DD MMM YYYY HH:MM:SS". This is the standard IETF
'			format as mentioned on the Date.parse() documentation in
'			"JavaScrip, The Definitive Guide" (
'
'	@param dateVal [in] - the Date object to be formatted as IETF date string
'
' -----------------------------------------------------------------------------
Function FormatDate( dateVal )
	FormatDate = Day(dateVal) & " " & IDCOL_MONTH(Month(dateVal)-1) & " " & Year(dateVal) & " " & _
					AddLeadingZero(Hour(dateVal)) & ":" & AddLeadingZero(Minute(dateVal)) & ":" & AddLeadingZero(Second(dateVal))
End Function

' -----------------------------------------------------------------------------
'
'	[Private] Add a leading zero to an integer if it is less than 10
'
' -----------------------------------------------------------------------------
Function AddLeadingZero(mynum)
	If mynum < 10 Then
		AddLeadingZero = "0" & mynum
	Else
		AddLeadingZero = mynum
	End If
End Function

' -----------------------------------------------------------------------------
'
'	[Public] Immediate If - something that exists in VB but not VBS
'
' -----------------------------------------------------------------------------
Function IIf(b, t, f)
	If b Then
		IIf = t
	Else
		IIf = f
	End If
End Function

' -----------------------------------------------------------------------------
'
'	[Public] Return the minimum of 2 values
'
' -----------------------------------------------------------------------------
Function Min(x, y)
	Min = IIf(x < y, x, y)
End Function

' -----------------------------------------------------------------------------
'
'	[Public] Return the maximum of 2 values
'
' -----------------------------------------------------------------------------
Function Max(x, y)
	Max = IIf(x > y, x, y)
End Function

' -----------------------------------------------------------------------------
'
'	[Public] This function appends querystring to a url
'
' -----------------------------------------------------------------------------
Function AppendQueryString(strBaseUrl, strQueryString)
	If InStr(strBaseUrl,"?") = 0 Then
		AppendQueryString = strBaseUrl & "?" & strQueryString
	Else
		AppendQueryString = strBaseUrl & "&" & strQueryString
	End If
End Function

' -----------------------------------------------------------------------------
'
'	[Public] This function retrieves the current Request.QueryString in an 
'				XSS safe manner.
'
' -----------------------------------------------------------------------------
Function URLEncodedQueryString()
	Dim pQParam, pSubQParam, bOweAmpersand

	bOweAmpersand = False
	URLEncodedQueryString = ""
	For Each pQParam In Request.QueryString
		For Each pSubQParam In Request.QueryString(pQParam)
			If (bOweAmpersand = True) Then
				URLEncodedQueryString = URLEncodedQueryString & "&"
			End If
			URLEncodedQueryString = URLEncodedQueryString & _
							Server.URLEncode(CStr(pQParam)) & "=" & Server.URLEncode(CStr(pSubQParam))
			bOweAmpersand = True
		Next
	Next
End Function

	
' -----------------------------------------------------------------------------
'
'	[Public] For backward compatibility with version 3.x
'
' -----------------------------------------------------------------------------
Sub ResetPropagateParam()
	Call SetROMPropagationPolicyForWBCMode()
End Sub

' -----------------------------------------------------------------------------
'
'	[Public] Set the ROM PropagateParam policy for WBC mode
'
' -----------------------------------------------------------------------------
Sub SetROMPropagationPolicyForWBCMode()
	' Propagate WBC mode QParams but prevent link generations to lead to WBC Authoring mode
	Dim strQParamWBCPurpose

	strQParamWBCPurpose = Request.QueryString(IDS_QPARAM_WBCPURPOSE)
	If (strQParamWBCPurpose <> "") Then
		If (strQParamWBCPurpose = IDS_WBCPURPOSE_AUTHORING) Then
			Call AutoSession.PropagateParameter( IDS_QPARAM_WBCPURPOSE, IDS_WBCPURPOSE_BASIC )
		Else
			Call AutoSession.PropagateParameter( IDS_QPARAM_WBCPURPOSE, Server.URLEncode(strQParamWBCPurpose) )
		End If
	End If
End Sub

' -----------------------------------------------------------------------------
'
'	[Public] Disable propagation of WBC mode QParams
'
' -----------------------------------------------------------------------------
Sub DisableROMPropagationPolicyForWBCMode()
	Call AutoSession.PropagateParameter( IDS_QPARAM_WBCPURPOSE, "" )
End Sub


' -----------------------------------------------------------------------------
'
'	[Public] Generate HTML hidden form elements to retain user authored content
'
' -----------------------------------------------------------------------------
Public Sub GenerateRoundTripFormElements()

	' NOTE: Relys on WBCCommonShared.inc being included prior to this file.
	' We call GetInitializedFormReaderSafe() with a False parameter to indicate that
	' we don't need to enforce upload validation since this is not a resource upload page.
	' If there is any error getting and initializing this form reader an error is printed
	'	and the response is ended
	Dim pFormReader
	Set pFormReader = GetInitializedFormReaderSafe( False )

	Dim pASPUtils
	Set pASPUtils = GetInitializedASPUtils()

	Dim lCount
	Dim lIndex
	Dim lCodePage

	lCodePage = AutoSession.This.CodePage
	lCount = pFormReader.Form.Count
	For lIndex = 1 to lCount
	%>
	<input type="hidden"
		name="<%=pFormReader.Form.Key(lIndex)%>"
		value="<% Call pASPUtils.MBCSWrite( pASPUtils.HTMLEncode(pFormReader.Form(lIndex)), lCodePage) %>"><br>
	<%
		Next
End Sub


' -----------------------------------------------------------------------------
'
'	[PUBLIC] This helper function dumps out a <nobr> start and end tag
'	around the HTML that is passed in if the browser is Internet Explorer,
'	otherwise it dumps out the text as passed. For the grid control in
'	particular, Netscape doesn't handle <nobr> tags properly and produces
' 	a display with overlapping table columns.
'
'	@param strHTML [in] - the HTML to potentially enclose in non-breaking
'		tags.
'
' -------------------------------------------------------------------------
Sub WriteAsNonbreakingBlock( strHTML )

	If isIE Then
		Response.Write( "<nobr>" & strHTML & "</nobr>" )

	Else
		Response.Write( strHTML )

	End If  'if Internet Explorer

End Sub  'WriteAsNonbreakingBlock


' -----------------------------------------------------------------------------
'
'	[Public] Checks if we are in authoring mode or not
'
' -----------------------------------------------------------------------------
Function IsAuthoringMode()
	Dim strEmit
	strEmit = Request.QueryString(IDS_QPARAM_NREMIT)

	' (As of Comox) In a navigation frame, AutoSession.This is always a Channel object,
	' therefore, checking against AutoSession.This.IsPosting will make sure the
	' authoring form will not be embedded in a navigation frame.
	IsAuthoringMode = (AutoSession.This.IsPosting) And _
						(strEmit = IDS_EMIT_THINEDIT Or strEmit = IDS_EMIT_WIN32EDIT)
End Function


' -----------------------------------------------------------------------------
'
'[Public]: 	Convert ASP boolean to Javascript boolean
'			The ASP boolean may not be "true" and "false" in some OS.
'			E.g. In German OS "wahr"="true" and "falscht"="false". This function
'			is to make sure the ASP boolean returning "true" and "false"
'			in order to	use when calling the Javascript function.
'
'Input:		bAspBoolean - an ASP boolean based on the OS
'
'Output:  	return "true" if the ASP boolean is meaning "true"; otherwise, returns "false"
'
' -----------------------------------------------------------------------------
Function Bool2LCaseStr(bASPBoolean)
	If bASPBoolean Then
		Bool2LCaseStr = "true"
	Else
		Bool2LCaseStr = "false"
	End If
End Function

Dim strEmit
strEmit = Request.QueryString(IDS_QPARAM_NREMIT)
if ( (AutoSession.IsModeUnpublished = true) Or _
     (AutoSession.IsModeStaging = true) Or _
     (AutoSession.IsModeUpdate = true) ) Or _
     ( (strEmit <> "") And (strEmit <> IDS_EMIT_VIEW) ) Or _
     (StrComp(Left(Request.ServerVariables("SCRIPT_NAME"), Len(IDS_FRAMEWORK_VIRTUAL_PATH)), IDS_FRAMEWORK_VIRTUAL_PATH, 1)=0) then
	if (AutoSession.UserCanModifySite = false) AND _
	   (AutoSession.Server.IsInRole(7) = false) then
                Response.Status = "404"
                %>
                <html>
                <head>
                <META NAME="ROBOTS" CONTENT="NOINDEX">
                <title>The page cannot be found</title>
                </head>
                <body bgcolor="FFFFFF">
                <table width="410" cellpadding="3" cellspacing="5">
                    <tr>    
                        <td align="left" valign="middle" width="360">
                            <h1 style="COLOR:000000; FONT: 13pt/15pt verdana"><!--Problem-->The page cannot be found</h1>
                        </td>
                    </tr>
                    <TR>
                        <TD><h2 style="font:8pt/11pt verdana; color:000000">HTTP 404 - File not found<br></h2>
                    </tr>
                </table>
                </body>
                </html>
                <%
		Response.End
	end if
end if
' -----------------------------------------------------------------------------
'
'[Public]: 	Returns the Guid for a channel from the QueryString. This function 
'			queries the AutoSession object to get the GUID.		
'
'Input:		
'
'Output:  	returns the Guid.
'
' -----------------------------------------------------------------------------

Function GetChannelGuidFromQueryString()
	
	Dim strChannelGuid
	Dim ChannelNode
	GetChannelGuidFromQueryString = ""
	strChannelGuid = Request.QueryString(IDS_QSTR_PAGECREATIONWIZARD_DESTINATIONCHANNEL)
	If	strChannelGuid <> "" Then
		Set ChannelNode = AutoSession.Searches.GetByGUID(strChannelGuid)
		If Not (ChannelNode is Nothing) Then
			GetChannelGuidFromQueryString = ChannelNode.Guid
		End If
	End If
End Function

' -----------------------------------------------------------------------------
'
'[Public]: 	Returns the Guid for a cpnnected page from the QueryString. This function 
'			queries the AutoSession object to get the GUID.		
'
'Input:		
'
'Output:  	returns the Guid.error is True if the QUeryString does not contain a 
'			valid GUID
'
' -----------------------------------------------------------------------------

Function GetConnectedPageGuidFromQueryString(ByRef error)
	
	Dim strConnectedPageGuid
	Dim PageNode
	error = False
	GetConnectedPageGuidFromQueryString = ""
	strConnectedPageGuid = Request.QueryString(IDS_QSTR_PAGECREATIONWIZARD_CONNECTEDPAGE)
	If	strConnectedPageGuid <> "" Then
		Set PageNode = AutoSession.Searches.GetByGUID(strConnectedPageGuid)
		If Not (PageNode is Nothing) Then
			GetConnectedPageGuidFromQueryString = PageNode.Guid
			error = True	
		End If
	End If
	
End Function

' -----------------------------------------------------------------------------
'
'[Public]: 	Returns the Guid for an AutoSession object via GetByGuid() call using
'			the passed in name to look up the GUID value in the QueryString.
'
'Input:		param name to the Querystring parameter containing the GUID.
'
'Output:  	returns the Guid. If error, return empty string.
'
' -----------------------------------------------------------------------------

Function GetGuidFromQueryString(strGuidParamName)
	On Error Resume Next
	
	Dim strTempGuid
	Dim pNode

	' init to error value first
	GetGuidFromQueryString = ""
	
	strTempGuid = Request.QueryString(strGuidParamName)
	If (strTempGuid <> "") Then
		Set pNode = AutoSession.Searches.GetByGUID(strTempGuid)
		If Not (pNode is Nothing) Then
			GetGuidFromQueryString = pNode.Guid
		End If
	End If
	
End Function

AutoSession.SuppressExceptions = False
Call AutoSession.ClearLastError()
%>