<!-- #include virtual="/NR/System/WBC/Internals/Integration/CFeatureManager.inc" -->
<!-- #include virtual="/NR/System/WBC/Internals/Integration/URLUtilities.inc" -->
<!-- #include virtual="/NR/System/WBC/Internals/Shared/CommonServer.inc" -->
<!-- #include virtual="/NR/System/WBC/Internals/LinksSupport/CommonURL.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."
' ********************************************************************

' ---- [Public] Embed HTML/script necessary for WBC in the <head> section of ASP pages
Sub EmbedWBCHeadSection
	If Not IsStagedOrCrawled Then
%>
		<link rel="stylesheet"
				href="<%= AutoSession.ResolveURL( IDS_FRAMEWORK_VIRTUAL_PATH & "/Customizable/WBC.css" ) %>">
		<script language="JavaScript"
				src="<%= AutoSession.ResolveURL(IDS_FRAMEWORK_VIRTUAL_PATH & "/Customizable/WBCFuncPagesConfig/UIStringConstants/JavaScriptUIStrings.js" ) %>"
				type="text/javascript"></script>
		<script language="JavaScript"
				src="<%= AutoSession.ResolveURL(IDS_FRAMEWORK_VIRTUAL_PATH & "/Customizable/OptionsClient.js" ) %>"
				type="text/javascript"></script>
		<script language="JavaScript"
				src="<%= AutoSession.ResolveURL(IDS_FRAMEWORK_VIRTUAL_PATH & "/Internals/Shared/Dates.js" ) %>"
				type="text/javascript"></script>
		<script language="JavaScript"
				src="<%= AutoSession.ResolveURL(IDS_FRAMEWORK_VIRTUAL_PATH & "/Internals/Shared/Windows.js" ) %>"
				type="text/javascript"></script>
		<script language="JavaScript"
				src="<%= AutoSession.ResolveURL(IDS_FRAMEWORK_VIRTUAL_PATH & "/Internals/Shared/CommonClient.js" ) %>"
				type="text/javascript"></script>
<%
		' reference LinksSupport.js when wbc_purpose is present
		If (Request.QueryString(IDS_QPARAM_WBCPURPOSE) <> "") Then
%>
			<script language="JavaScript"
					src="<%= AutoSession.ResolveURL(IDS_FRAMEWORK_VIRTUAL_PATH & "/Internals/LinksSupport/LinksSupport.js" ) %>"
					type="text/javascript"></script>
<%
		End If
	End If
End Sub

' ---- [Private] Generate response for the case that the reading of the form elements failed
Sub RespondFormReadFailed( )
%>
	<h4>Sorry, an error has occurred when attempting to read the data required to update the posting.</h4>
	&nbsp;&nbsp;&nbsp;&nbsp;Error description: <em><%= Err.Description %></em><br>
	<br>
	<hr>
	<br>
	&nbsp;&nbsp;<a href='javascript:history.back()'>Please go back and try the operation again</a>,
	or contact your system administrator.
<%
	Response.Flush
End Sub

' ---- [Private] Lazy initialized global pointer to the form reader for this session.
Dim g_pLazyInitFormReader
Set g_pLazyInitFormReader = Nothing

' ---- [Public] Initialize the NCASPExtensions.ASPFormReader object for form reading and display any errors
Function GetInitializedFormReaderSafe( bUpoadValidate )
	On Error Resume Next

	' If the form reader has already been initialized, then return the existing reader.
	If Not g_pLazyInitFormReader Is Nothing Then
		Set GetInitializedFormReaderSafe = g_pLazyInitFormReader
		Exit Function
	End If

	' Create the ASPFormReader object
	Set g_pLazyInitFormReader = Server.CreateObject("NCASPExtensions.ASPFormReader")

	' set global CodePage value to the one from AutoSession.This
	g_pLazyInitFormReader.CodePage = AutoSession.This.CodePage

	' Turn on/off validation according to passed in parameter
	g_pLazyInitFormReader.UploadValidation = bUpoadValidate

	'If there was any errors here, respond to the user and bail out.
	If (Err.Number <> 0) Then

		RespondFormReadFailed

		' Read all the content and throw it away so we can do a clean exit
		Dim varContent
		while true
			Dim nCount
			nCount = 100000
			varContent = Request.BinaryRead(nCount)
			if nCount = 0 then
				Response.End
			end if
		wend

	End If

	Set GetInitializedFormReaderSafe = g_pLazyInitFormReader
End Function

%>