Function Em(cString)
	Em = Len(Trim(cString)) = 0
End Function

Function Min(nOne, nTwo)
	If nOne < nTwo Then
		Min = nOne
	Else
		Min = nTwo
	End If
End Function

Function Max(nOne, nTwo)
	If nOne > nTwo Then
		Max = nOne
	Else
		Max = nTwo
	End If
End Function

Function QuestionBox(cTitle, cMessage, cChoice1, cChoice2, cChoice3)
	cURL = "/dialog/questionBox.asp?Title=" & cTitle & _
	                 "&Message=" & cMessage & _
					 "&Choice1=" & cChoice1 & _
					 "&Choice2=" & cChoice2 & _
					 "&Choice3=" & cChoice3
	nResult = window.showModalDialog(cURL,,"dialogHeight=200px;dialogWidth=400px;center=yes;help=no;resizable=no;status=no")
	QuestionBox = nResult
End Function

Sub SetSelect(oSelect, cValue)
	For nI = 0 To (oSelect.length - 1)
		cOption = oSelect.item(nI).value
		If InStr(cOption, "|") > 0 Then 
			cOption = Left(cOption, InStr(cOption, "|") - 1)
		End If
		If cOption = cValue Then
			oSelect.selectedIndex = nI
		End If
	Next
End Sub

Function FormatMinToDur(nMin)
	nHours = Int(nMin / 60)
	cHours = Right("00" & nHours,2)
	nMinutes = nMin Mod 60
	cMinutes = Right("00" & nMinutes,2)
	FormatMinToDur = cHours & ":" & cMinutes
End Function

Function FormatDate(dDate)
	If Em(dDate) Or IsNull(dDate) Then
		FormatDate = ""
	ElseIf Year(dDate) <= 1900 Then
		FormatDate = ""
	Else
		FormatDate = DatePart("m", dDate) & "/" & _
		             DatePart("d", dDate) & "/" & _
		             DatePart("yyyy", dDate)
	End If
End Function

Function FormatTime(dTime)
    If Em(dTime) Or IsNull(dTime) Then
        FormatTime = ""
    ElseIf Hour(dTime) = 0 And Minute(dTime) = 0 Then
    	FormatTime = ""
    Else
		nHour = Hour(dTime)
		If nHour > 12 Then nHour = nHour - 12
		cHour = CStr(nHour)
		If nHour = 0 Then cHour = "12"
		cHours = Right("00" & cHour,2)
		nMinutes = Minute(dTime)
		cMinutes = Right("00" & nMinutes,2)
		FormatTime = cHours & ":" & cMinutes
    End If
End Function

Function FormatAmPm(dTime)
    If Em(dTime) Or IsNull(dTime) Then
        FormatAmPm = "AM"
    Else
		nHour = Hour(dTime)
		If nHour > 11 Then
		  FormatAmPm = "PM"
		Else
		  FormatAmPm = "AM"
		End If
    End If
End Function

Function Coalesce(cString1, cString2)
	If Not Em(cString1) Then
		Coalesce = cString1
	Else
		Coalesce = cString2
	End If
End Function

Function URLEncode(cString)
	cCodeChars = "%#_&=+ "
	cRet = ""
	For nI = 1 To Len(cString)
		cChar = Mid(cString, nI, 1)
		If InStr(1, cCodeChars, cChar) > 0 Then
			cChar = "%" & Hex(Asc(cChar))
		End If
		cRet = cRet & cChar
	Next
	URLEncode = cRet
End Function

Function PCase(cString)
	nPosition = 1
	
	Do While InStr(nPosition, cString, " ", 1) <> 0
		nSpace = InStr(nPosition, cString, " ", 1)
		strOutput = strOutput & UCase(Mid(cString, nPosition, 1))
		strOutput = strOutput & LCase(Mid(cString, nPosition + 1, nSpace - nPosition))
		nPosition = nSpace + 1
	Loop

	strOutput = strOutput & UCase(Mid(cString, nPosition, 1))
	strOutput = strOutput & LCase(Mid(cString, nPosition + 1))

	PCase = strOutput
End Function

Function DurationToMinutes(cDuration)
    If InStr(1, cDuration, ":") = 0 Then
        DurationToMinutes = 0
    Else
        aDuration = Split(cDuration, ":")
        nHours = CDbl("0" & aDuration(0))
        nMinutes = CDbl("0" & aDuration(1))
        DurationToMinutes = (nHours * 60) + nMinutes
    End If
End Function