<%
	'-- String Constants
	Const PROG_BAR_PERCENT = 90	' The percent of the Window width of the Progress bar

	' ---- [Private] retrieve 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

	dim iProgMan		' The progress manager
	dim iProgItem		' The progress item

	dim nPercent		' The current item percent completed
	dim nSubPercent		' The current sub item percent completed
	dim strDescription	' The current item description
	dim strSubDescription	' The current sub item description

	dim bCompleted		' Has the task completed?
	dim bCanceled		' Did the user request the operation to be canceled?
	dim strGUID		' The GUID of the item to investigate
	dim bIsCanceled     	' Is the canceled flag set to true?

	' Get the guid of the item to grab.
	strGUID = request.queryString( "GUID" )

	' See if the user requested the action to be canceled.
	dim strCanceled
	strCanceled = request.queryString( "Cancel" )
	if strCanceled = "True" then
		bCanceled = true
	else
		bCanceled = false
	end if


	' Get the progress manager
	set iProgMan = Server.CreateObject( "NRProgMeter.NRProgressManager" )

	'Get the progress item that we are interested in
	set iProgItem = iProgMan.GetItem(strGUID)

	' Does the requested item exist?
	if iProgItem is nothing then
		' Nope, so let the user know.
		Response.Write ("Can't find the requested item.")
		' Set the status text to "NCError" which will inform the progress dialog that an error has occurred
		Response.Write("<SCRIPT Language=""JavaScript"">window.setTimeout(""ReallySetStatus();"", 500); function ReallySetStatus() {window.status = ""NCError""; window.setTimeout(""ReallySetStatus();"", 500); }</SCRIPT>")
	else
		'Get the values
		nPercent = iProgItem.PercentComplete
		nSubPercent = iProgItem.SubItemPercentComplete
		strDescription = iProgItem.Description
		strSubDescription = iProgItem.SubItemDescription
		bCompleted = iProgItem.Completed
		bIsCanceled = iProgItem.Canceled

		'Should we refresh?
		if bCompleted = false then
			' Set the refresh info
			response.AddHeader "Refresh", "2"
		else
			iProgMan.ReleaseItem( strGUID )
		end if

		' If the user selected cancel, pass the request to the progress item.
		if bCanceled = true then
			iProgItem.CancelOperation
			' Set the status text to "NCCancel" which will inform the progress dialog that the user cancelled the operation
			Response.Write("<SCRIPT Language=""JavaScript"">window.setTimeout(""ReallySetStatus();"", 500); function ReallySetStatus() {window.status = ""NCCancel""; window.setTimeout(""ReallySetStatus();"", 500); }</SCRIPT>")
		end if


		'
		' This is where the actual HTML is generated
		'
		' Response.Write "<html><head></head><body bgcolor=""#C0C0C0"">" + VbCrLf
		Response.Write "<html><head>" + VbCrLf
                Response.Write "<style type=""text/css"">" + VbCrLf
                Response.Write "<!--" + VbCrLf
		Response.Write "BODY {  font-family: Arial, Helvetica, sans-serif; }" + VbCrLf
		Response.Write ".small { font-family: Arial, Helvetica, sans-serif; font-size: 9pt; }" + VbCrLf
                Response.Write "-->" + VbCrLf
                Response.Write "</style>" + VbCrLf
		Response.Write "</head><body bgcolor=""silver""><div align=""center"">" + VbCrLf

		' Draw the secondary progress bar, if necessary
		' Should we draw the lower progress bar?
		if nSubPercent > 0 or strSubDescription <> "" then
			' Draw the secondary progress bar
			' Use a table as the basis for the progress bar
	                Response.Write "<table border=""0"" width=""" + CStr(PROG_BAR_PERCENT) + "%"" cellspacing=""0"" cellpadding=""0"">" + vbCrLf

			' first row -- sub description
			Response.Write "<tr><td class=""small"" align=""left"">" + strSubDescription + "&nbsp;</td></tr>" + vbCrLf

			' second row -- percentage bar
			' first create the row and a single cell for this table,
			Response.Write "<tr><td>" + vbCrLf

			' create a 'border' subtable
			' (table with one row and a black border)
			Response.Write "<table border=""1"" width=""100%"" cellspacing=""0"" cellpadding=""0""><tr><td>" + vbCrLf

			' create a 'bar' subtable
			' (table with one row and two cells for the bar)
			Response.Write "<table border=""0"" width=""100%"" cellspacing=""0"" cellpadding=""0""><tr>" + vbCrLf

			' create the bar
			if nSubPercent = 0 then
				' All Empty
				Response.Write "<td bgcolor=""silver"" width=""100%"">&nbsp;</td>" + vbCrLf
			elseif nSubPercent = 100 then
				' All Filled
				Response.Write "<td bgcolor=""navy"" width=""100%"">&nbsp;</td>" + vbCrLf
			else
				' Filled portion
				Response.Write "<td bgcolor=""navy"" width=""" + CStr(nSubPercent) + "%"">&nbsp;</td>" + vbCrLf

				' Empty portion
				Response.Write "<td bgcolor=""silver"" width=""" + CStr(100 - nSubPercent) + "%"">&nbsp;</td>" + vbCrLf
			end if

			' end 'bar' subtable
			Response.Write "</tr></table>" + vbCrLf

			' end 'border' subtable
			Response.Write "</td></tr></table>" + vbCrLf

			' end second row
			Response.Write "</td></tr>" + vbCrLf

			' third row -- percent complete
			Response.Write "<tr><td class=""small"" align=""center"">" + CStr(nSubPercent) + "%</td></tr>" + vbCrLf

			' end progress bar table
			Response.Write "</table>" + vbCrLf

			' Put in an empty paragraph for spacing
			' response.write "<p>&nbsp;</p>" + vbCrLf
		end if

		' Draw the main progress bar
		' Use a table as the basis for the progress bar
                Response.Write "<table border=""0"" width=""" + CStr(PROG_BAR_PERCENT) + "%"" cellspacing=""0"" cellpadding=""0"">" + vbCrLf

		' first row -- main description
		Response.Write "<tr><td class=""small"" align=""left"">" + strDescription + "&nbsp;</td></tr>" + vbCrLf

		' second row -- percentage bar
		' first create the row and a single cell for this table,
		Response.Write "<tr><td>" + vbCrLf

		' create a 'border' subtable
		' (table with one row and a black border)
		Response.Write "<table border=""1"" width=""100%"" cellspacing=""0"" cellpadding=""0""><tr><td>" + vbCrLf

		' create a 'bar' subtable
		' (table with one row and two cells for the bar)
		Response.Write "<table border=""0"" width=""100%"" cellspacing=""0"" cellpadding=""0""><tr>" + vbCrLf

		' create the bar
		if nPercent = 0 then
			' All Empty
			Response.Write "<td bgcolor=""silver"" width=""100%"">&nbsp;</td>" + vbCrLf
		elseif nPercent = 100 then
			' All Filled
			Response.Write "<td bgcolor=""navy"" width=""100%"">&nbsp;</td>" + vbCrLf
		else
			' Filled portion
			Response.Write "<td bgcolor=""navy"" width=""" + CStr(nPercent) + "%"">&nbsp;</td>" + vbCrLf

			' Empty portion
			Response.Write "<td bgcolor=""silver"" width=""" + CStr(100 - nPercent) + "%"">&nbsp;</td>" + vbCrLf
		end if

		' end 'bar' subtable
		Response.Write "</tr></table>" + vbCrLf

		' end 'border' subtable
		Response.Write "</td></tr></table>" + vbCrLf

		' end second row
		Response.Write "</td></tr>" + vbCrLf

		' third row -- percent complete
		Response.Write "<tr><td class=""small"" align=""center"">" + CStr(nPercent) + "%</td></tr>" + vbCrLf

		' end progress bar table
		Response.Write "</table>" + vbCrLf


		if bCompleted <> true then
			' Give the user the chance to cancel the operation.
			Dim strNextUrl

			' Check to see if they want to hide tha cancel button
			if (Request.QueryString("HideCancelBtn") <> "TRUE") then
				' They want the cancel button so create the INPUT tag
				if bCanceled <> true then
					strNextUrl = Request.ServerVariables("SCRIPT_NAME") + "?" + URLEncodedQueryString() + "&Cancel=True"
				else
					strNextUrl = Request.ServerVariables("SCRIPT_NAME") + "?" + URLEncodedQueryString()
				end if

				Response.Write "<p><form><input class=""small"" type=""button"" onclick=""javascript:window.location='" + strNextUrl + "';"" value=""Cancel""></form></p>" + vbCrLf
			end if
		else
			Response.Write "<p><b>Finished.</b></p>" + vbCrLf

			' Set the status text to "NCDone" which will inform the progress dialog that everything finished OK
			Response.Write("<SCRIPT Language=""JavaScript"">window.setTimeout(""ReallySetStatus();"", 500); function ReallySetStatus() {window.status = ""NCDone""; window.setTimeout(""ReallySetStatus();"", 500); }</SCRIPT>")
		end if

		Response.Write "</div></body></html>"
	end if

%>
