<%

Function GetYearDD(ArrivalDate, CurrentDate, Selected)

	If CurrentDate = "" Then 
		CurrentYear = Year(Date())
	Else
		CurrentYear = Year(CurrentDate)
	End If

	If ArrivalDate = "" Then
		ArrivalYear = ""
	Else
		ArrivalYear = Year(ArrivalDate)
	End If
	
	HTML = ""

	If ArrivalYear <> "" then
		HTML = HTML & "<option value=""" & ArrivalYear & """ selected>" & ArrivalYear & "</option>" & Chr(13)
		HTML = HTML & "<option value="""">-</option>" & Chr(13)
	Else
		Get_Date = True
	End If 

	If Num_Years = "" Then Num_Years = 3

	For i = 0 to Num_Years
		If Year(Date()) + i = CurrentYear And Get_Date = True Then
			HTML = HTML & "<option value=" & CurrentYear & " selected>" & CurrentYear & "</option>" & Chr(13)
		Else			
			HTML = HTML & "<option value=" & Year(Date()) + i & ">" & Year(Date()) + i & "</option>" & Chr(13)
		End If
	Next

GetYearDD = HTML

End Function


Function GetMonthDD(ArrivalDate, CurrentDate, Selected, Num, Abbr)
	
	If CurrentDate = "" Then 
		CurrentMonth = Month(Date())
	Else
		CurrentMonth = Month(CurrentDate)
	End If

	If ArrivalDate = "" Then
		ArrivalMonth = ""
	Else
		ArrivalMonth = Month(ArrivalDate)
	End If
	
	HTML = ""

	If ArrivalMonth <> "" then
		If Num = True Then
			HTML = HTML &  "<option value=""" & ArrivalMonth & """ selected>" & ArrivalMonth & "</option>" & Chr(13)
			HTML = HTML & "<option value="""">-</option>" & Chr(13)
		Else
			HTML = HTML &  "<option value=""" & ArrivalMonth & """ selected>" & ConvertMonth(ArrivalMonth, 2) & "</option>" & Chr(13)
			HTML = HTML & "<option value="""">-</option>" & Chr(13)
		End If
	Else
		Get_Date = True
	End If 

	For i = 1 to 12
		If Num = True Then
			If i = CurrentMonth And Get_Date = True Then
				HTML = HTML & "<option value=" & CurrentMonth & " selected>" & CurrentMonth & "</option>" & Chr(13)
			Else			
				HTML = HTML & "<option value=" & i & ">" & i & "</option>" & Chr(13)
			End If
		Else
			If Abbr = True Then
				If i = CurrentMonth And Get_Date = True Then
					HTML = HTML & "<option value=" & CurrentMonth & " selected>" & ConvertMonth(CurrentMonth, 2) & "</option>" & Chr(13)
				Else			
					HTML = HTML & "<option value=" & i & ">" & ConvertMonth(i, 2) & "</option>" & Chr(13)
				End If
			Else
				If i = CurrentMonth And Get_Date = True Then
					HTML = HTML & "<option value=" & CurrentMonth & " selected>" & ConvertMonth(CurrentMonth, 2) & "</option>" & Chr(13)
				Else			
					HTML = HTML & "<option value=" & i & ">" & ConvertMonth(i, 2) & "</option>" & Chr(13)
				End If
			End If
		End If
	Next

	GetMonthDD = HTML

End Function


Function GetDayDD(ArrivalDate, CurrentDate, Selected)

	If CurrentDate = "" Then 
		CurrentDay = Day(Date())
	Else
		CurrentDay = Day(CurrentDate)
	End If

	If ArrivalDate = "" Then
		ArrivalDay = ""
	Else
		ArrivalDay = Day(ArrivalDate)
	End If

	HTML = ""
	
	If ArrivalDay <> "" then
		HTML = HTML & "<option value=""" & ArrivalDay & """ selected>" & ArrivalDay & "</option>" & Chr(13)
		HTML = HTML & "<option value="""">-</option>" & Chr(13)
	Else
		Get_Date = True
	End If 

	For i = 1 to 31
		If i = CurrentDay And Get_Date = True Then
			HTML = HTML & "<option value=" & CurrentDay & " selected>" & CurrentDay & "</option>" & Chr(13)
		Else			
			HTML = HTML & "<option value=" & i & ">" & i & "</option>" & Chr(13)
		End If
	Next

	GetDayDD = HTML

End Function






' =================================================================
' Wrote this function because the VBscript date formatting left me missing one format.
' That is "Month Day, Year" and "Month Year"
' "sDate" is a valid date, "bDay" is TRUE/FALSE to return DAY, and "bYear" is 
' TRUE/FALSE to return YEAR
' =================================================================
function DateFormat(sDate, bDay, bYear)
    dim theMonths, iMonth, iDay, iYear
    theMonths =  Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")    
    
    iMonth = month(sDate)
    iDay = day(sDate)
    iYear = year(sDate)
    
    ' Remember to substract one from iMonth due to array index of 0
    DateFormat = theMonths(iMonth-1) 
    
    if bDay and bYear then
        DateFormat = DateFormat & " " & iDay & ", " & iYear
    elseif bDay and not bYear then
        DateFormat = DateFormat & " " & iDay
    elseif not bDay and bYear then
        DateFormat = DateFormat & " " & iYear
    end if
    
end function


function ConvertMonth(Month, Format)
    dim Months, AbbrMonths
	
    Months =  Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")    
    AbbrMonths =  Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")    

	If Format = "1" Then
		ConvertMonth = Months(Int(Month) -1)
	Else
		ConvertMonth = AbbrMonths(Int(Month) -1)
	End If
	
end function


' =================================================================


' =================================================================
' This will return total number of years and months
' "iMonths" is the total number of months
' =================================================================
function MonthToYears(iMonths)
    on error resume next
    iTotalYears = iMonths\12
    iTmpMonths = iTotalYears * 12
    iTotalMonths = iMonths - iTmpMonths
    
    if iTotalYears > 1 then
        sYears = " Years"
    else
        sYears = " Year"
    end if
    
    if iTotalMonths > 1 then
        sMonths = " Months"
    else
        sMonths = " Month"
    end if
    
    if iTotalYears > 0 and iTotalMonths > 0 then
        MonthToYears = iTotalYears & sYears & " " & iTotalMonths & sMonths
    elseif iTotalYears > 0 and iTotalMonths = 0 then
        MonthToYears = iTotalYears & sYears
    elseif iTotalYears = 0 and iTotalMonths > 0 then
        MonthToYears = iTotalMonths & sMonths
    else
        MonthToYears = "ERROR"
    end if

end function
' =================================================================


' =================================================================
' Determine if passed date "vDate" falls on a holiday
' =================================================================
function IsHoliday(vDate)
  Dim Y, iNumHol, Dy, N, M 
  
  Y = Year(vDate)
  M = Month(vDate)
  
  IsHoliday = False
  Select Case M
  Case 1
    '---- NewYears day
    If Day(vDate) = 1 Or (Day(vDate) = 2 And WeekDay(vDate) = vbMonday) Then
      IsHoliday = True
    Else
      '---- Martin Luther King day
      If vDate = FirstMonday(Y, 1) + (2 * 7) Then
        IsHoliday = True
      End If
    End If

  case 3,4
    '---- Good Friday
    if isGoodFriday(vDate) then 
        IsHoliday = True
        sHolidayName = "GOOD FRIDAY"
    else
        sHolidayName = ""
    end if
  
  Case 2
    '---- Presidents day
    If vDate = FirstMonday(Y, 2) + (2 * 7) Then IsHoliday = True
    
  Case 5
    '---- Memorial day (last week of month)
    Dy = FirstMonday(Y, 5) + (4 * 7)
    If Month(Dy) <> 5 Then Dy = Dy - 7
    If vDate = Dy Then IsHoliday = True
      
  Case 7
    '---- Independance day
    If Day(vDate) = 4 Or (Day(vDate) = 3 And WeekDay(vDate) = vbFriday) Or (Day(vDate) = 5 And WeekDay(vDate) = vbMonday) Then IsHoliday = True
  
  Case 9
    '---- Labor day
    If vDate = FirstMonday(Y, 9) Then IsHoliday = True
  
  Case 10
    '---- Columbus day
    If vDate = FirstMonday(Y, 10) + 7 Then IsHoliday = True
  
  Case 11
    '---- Veterans day
    If Day(vDate) = 11 Or (Day(vDate) = 10 And WeekDay(vDate) = vbFriday) Or (Day(vDate) = 12 And WeekDay(vDate) = vbMonday) Then
      IsHoliday = True
    Else
      '---- Thanksgiving day (last week of month)
      Dy = FirstMonday(Y, 11) + 3 + (3 * 7)
      If Month(Dy) <> 11 Then Dy = Dy - 7
      If vDate = Dy Then IsHoliday = True
    End If
    
  Case 12
    '---- Christmas day
    If Day(vDate) = 25 Or (Day(vDate) = 24 And WeekDay(vDate) = vbFriday) Or (Day(vDate) = 26 And WeekDay(vDate) = vbMonday) Or (Day(vDate) = 31 And WeekDay(vDate) = vbFriday) Then IsHoliday = True
  End Select
End function

' Used by isHoliday sub
Function FirstMonday(Y, M)
  Dim lDay, N
  lDay = DateSerial(Y, M, 1)
  
  For N = lDay To lDay + 6
    If N Mod 7 = vbMonday Then Exit For
  Next
  FirstMonday = N
End Function


' Used by isHoliday sub
' Determine if date is Good Friday
function isGoodFriday(vDate)
    ' Calculation adapted from algorithm at http://www.smart.net/~mmontes/carter.html
    dim iCentury, iYear2, iG, iK, iI, iJ, iL, iEasterMonth, iEasterDay, dtGoodFriday

    ' Find date of Easter
    iYear2 = year(vDate)
    iCentury = iYear2\100
    iG = iYear2 mod 19
    iK = (iCentury - 17)\25
    iI = (iCentury - iCentury\4 - (iCentury - iK)\3 + 19*iG + 15) mod 30
    iI = iI - (iI\28)*(1 - (iI\28)*(29\(iI + 1))*((21 - iG)\11))
    iJ = (iYear2 + iYear2\4 + iI + 2 - iCentury + iCentury\4) mod 7
    iL = iI - iJ
    iEasterMonth = 3 + (iL + 40)\44
    iEasterDay = iL + 28 - 31*(iEasterMonth\4)

    ' Good Friday is 2 days before Easter
    dtGoodFriday = datevalue((iEasterMonth & "/" & iEasterDay & "/" & iYear2)) - 2

    if vDate = dtGoodFriday then
        isGoodFriday = True
    else
        isGoodFriday = False
    end if
end function
' =================================================================
%>

