<!--#include file="datefunctions.asp"-->
<%
	
Function NewItinerary() 'Create New Itinerary

Dim SQLNew
Set RSNew = Server.CreateObject("ADODB.Recordset")

	SQLNew = "New_Itinerary '" & Session("UserID") & "', '1', '" & Session.SessionID & "'"
	RSNew.open SQLNew, Conn
	Session("Itinerary_ID") = RSNew("Itinerary_ID")

	
End Function	


Function CheckItinerary(Itinerary_ID) 'Create New Itinerary

Dim SQLCheck
Set RSNew = Server.CreateObject("ADODB.Recordset")

	SQLCheck = "Check_Itinerary '" & Session("UserID") & "', '" & Itinerary_ID & "'"
	Conn.Execute(SQLCheck)
	
End Function	


Function SaveItinerary(funcArray, Itinerary_ID, itemArray) 'Save Array into Itinerary

Dim SQLAddCart, RSAddCart, Item_ID, Quantity, URL, Item, Value, i, SQLPackage, PType
Set RSPackage = Server.CreateObject("ADODB.Recordset")
	If Trim(Session("Itinerary_ID")) = "" Then
		Call NewItinerary()
	End If
	
	For i = LBound(funcArray, 2) to UBound(funcArray, 2)
			'SQLAddCart = "[Avante].[dbo].[ItineraryAddItem] '" & Itinerary_ID & "', '" & funcArray(1, i) & "', '" & funcArray(2, i) & "', '" & funcArray(3, i) & "', '" & funcArray(4, i) & "', '" & "', '" & funcArray(5, i) & "', '" & "', '" & funcArray(6, i) & "', '" & "', '" & funcArray(7, i) & "', '" & "', '" & funcArray(8, i) & "', '" & funcArray(10, i) & "'"
			SQLAddCart = "[Avante].[dbo].[ItineraryAddItem] '" & Itinerary_ID & "', '" & Int(funcArray(1, i)) & "', '" & Int(funcArray(2, i)) & "', '" & funcArray(3, i) & "', '" & Int(funcArray(4, i)) & "', '" & Int(funcArray(5, i)) & "', '" & Int(funcArray(6, i)) & "', '" & funcArray(7, i) & "', '" & Int(funcArray(8, i)) & "', '" & Int(funcArray(9, i)) & "', '" & Int(funcArray(10, i)) & "'"
			'Response.Write SQLAddCart
			Conn.Execute(SQLAddCart)		
		Next

	For j = LBound(itemArray, 2) to UBound(itemArray, 2)
		'Response.Write i
		'SQLAddCart = "[Avante].[dbo].[ItineraryAddDetail] '" & Itinerary_ID & "', '" & Int(funcArray(1, i)) & "', '" & Int(funcArray(2, i)) & "', '" & funcArray(3, i) & "', '" & Int(funcArray(4, i)) & "', '" & Int(funcArray(5, i)) & "', '" & Int(funcArray(6, i)) & "', '" & funcArray(7, i) & "', '" & Int(funcArray(8, i)) & "', '" & Int(funcArray(9, i)) & "'"
		SQLAddCart = "[Avante].[dbo].[ItineraryAddDetail] '" & Itinerary_ID & "', '" & itemArray(1, j) & "', '" & itemArray(2, j) & "', '" & itemArray(3, j) & "', '" & itemArray(4, j) & "', '" & itemArray(5, j) & "', '" & itemArray(6, j) & "', '" & itemArray(7, j) & "', '" & itemArray(8, j) & "', '" & itemArray(9, j) & "'"
		'Response.Write SQLAddCart
		Conn.Execute(SQLAddCart)
	Next
		
End Function

Function DeleteItin(Itinerary_ID)
Dim SQLDelete
SQLDelete = "[Avante].[dbo].[ItineraryDelete] @Itinerary_ID = '" & Itinerary_ID & "'"
Conn.Execute(SQLDelete)
End Function

Function AddToArray(funcArray, Item_ID, Quantity, Cost, Product_Type, Trans_ID, Rollaway, Special_Request, Smoking, Package_Date) 'Add Item to Itinerary Array
Dim ArrayLength, exists, Extra_Adult
exists = False

Extra_Adult = CheckAdultCount(funcArray, Item_ID, Quantity)


If (Ubound(funcArray, 2) = "0" And Trim(funcArray(1, 0)) = "") Then
	funcArray(1, 0) = Item_ID
	funcArray(2, 0) = Quantity
	funcArray(3, 0) = Cost
	funcArray(4, 0) = Product_Type
	funcArray(5, 0) = Rollaway
	funcArray(6, 0) = Extra_Adult
	funcArray(7, 0) = Special_Request
	funcArray(8, 0) = Smoking
	funcArray(9, 0) = Package_Date
	funcArray(10, 0) = Trans_ID

Else

For l = LBound(funcArray, 2) to UBound(funcArray, 2)
	'Response.Write "Item: " & tmpArray(1, i) & "<br>"
	If Int(funcArray(1, l)) = Int(Item_ID) And Int(funcArray(2, l)) = Int(Quantity) Then		
		exists = True
		'Response.Write "Found: " & Item_ID & "<br>"
	ElseIf Int(funcArray(1, l)) = Int(Item_ID) And Not (Int(funcArray(2, l)) = Int(Quantity)) Then
		funcArray(2, l) = Quantity		
		exists = True

	End If
Next

If exists = False Then
	ArrayLength = UBound(funcArray, 2) + 1
	Redim Preserve funcArray(10, ArrayLength)
	funcArray(1, ArrayLength) = Item_ID
	funcArray(2, ArrayLength) = Quantity
	funcArray(3, ArrayLength) = Cost
	funcArray(4, ArrayLength) = Product_Type
	funcArray(5, ArrayLength) = Rollaway
	funcArray(6, ArrayLength) = Extra_Adult
	funcArray(7, ArrayLength) = Special_Request
	funcArray(8, ArrayLength) = Smoking
	funcArray(9, ArrayLength) = Package_Date
	funcArray(10, ArrayLength) = Trans_ID

End If
End If

AddToArray = funcArray

End Function

Function AddToItemArray(funcArray, Trans_ID, ArrivalDate, Stay, AdultCount, GuestCount, Extra_Adult, Rollaway, Special_Request, Smoking, Package_ID) 'Add Transaction to Itinerary Array
Dim ArrayLength, exists
exists = False

If (Ubound(funcArray, 2) = "0" And Trim(funcArray(1, 0)) = "") Then
	funcArray(1, 0) = Trans_ID
	funcArray(2, 0) = ArrivalDate
	funcArray(3, 0) = Stay
	funcArray(4, 0) = AdultCount
	funcArray(5, 0) = GuestCount
	funcArray(6, 0) = Extra_Adult
	funcArray(7, 0) = Rollaway
	funcArray(8, 0) = Special_Request
	funcArray(9, 0) = Smoking
	funcArray(10, 0) = Package_ID

Else

For l = LBound(funcArray, 2) to UBound(funcArray, 2)
	'Response.Write "Item: " & tmpArray(1, i) & "<br>"
	If Int(funcArray(1, l)) = Int(Trans_ID) Then		
		exists = True
	End If
Next

If exists = False Then
	ArrayLength = UBound(funcArray, 2) + 1
	Redim Preserve funcArray(10, ArrayLength)
	funcArray(1, ArrayLength) = Trans_ID
	funcArray(2, ArrayLength) = ArrivalDate
	funcArray(3, ArrayLength) = Stay
	funcArray(4, ArrayLength) = AdultCount
	funcArray(5, ArrayLength) = GuestCount
	funcArray(6, ArrayLength) = Extra_Adult
	funcArray(7, ArrayLength) = Rollaway
	funcArray(8, ArrayLength) = Special_Request
	funcArray(9, ArrayLength) = Smoking
	funcArray(10, ArrayLength) = Package_ID

End If
End If

AddToItemArray = funcArray

End Function

Function ClearArray()
Dim tmpArray
Redim tmpArray(10, 0)
Session("Itinerary_Items") = tmpArray

End Function

Function OpenSavedItinerary(Itinerary_ID, User_ID) 'Open and Retrieve a Saved Itinerary
Dim funcArray, SQLItinerary, RSLength, j
j = 0
Set RSItinerary = Server.CreateObject("ADODB.Recordset")
SQLItinerary = "Select * from Itinerary I inner join Itinerary_Detail ID on I.Itinerary_ID = ID.Itinerary_ID Where I.Itinerary_ID = '" & Itinerary_ID & "' "
SQLItinerary = SQLItinerary & "And Contact_ID = '" & User_ID & "' Order by ID.Web_Trans_ID"
RSItinerary.Open SQLItinerary, Conn
If Not RSItinerary.EOF Then
RSItinerary.MoveFirst()
Redim funcArray(10, 0)

Do While Not RSItinerary.EOF
		If j > 0 Then 
		Redim Preserve funcArray(10, j)
		End If
		On Error Resume Next
		funcArray(1, j) = RSItinerary("Product_ID")
		funcArray(2, j) = RSItinerary("Quantity")
		funcArray(3, j) = RSItinerary("Unit_Price")
		funcArray(4, j) = RSItinerary("Product_Type")
		funcArray(5, j) = RSItinerary("Rollaway")
		funcArray(6, j) = RSItinerary("ExtraAdults")
		funcArray(7, j) = RSItinerary("Special_Request")
		funcArray(8, j) = RSItinerary("Smoking")
		funcArray(9, j) = RSItinerary("Package_Date")
		funcArray(10, j) = RSItinerary("Web_Trans_ID")
		On Error Goto 0
	RSItinerary.MoveNext()
	j = j + 1
Loop

RSItinerary.Close()
Set RSItinerary = Nothing

OpenSavedItinerary = funcArray

Else
'funcArray(1, 0) = "None"
OpenSavedItinerary = funcArray

End If

End Function

Function OpenItemArray(Itinerary_ID)
Dim itemArray, SQLItinerary, RSLength, j
j=0
Set RSItinerary = Server.CreateObject("ADODB.Recordset")
SQLItinerary = "Select * from Itinerary_Detail_Vars Where Itinerary_ID = '" & Itinerary_ID & "' "
RSItinerary.Open SQLItinerary, Conn
If Not RSItinerary.EOF Then
RSItinerary.MoveFirst()
Redim itemArray(10, 0)

Do While Not RSItinerary.EOF
		If j > 0 Then 
		Redim Preserve itemArray(10, j)
		End If
		On Error Resume Next
		itemArray(1, j) = RSItinerary("Trans_ID")
		itemArray(2, j) = RSItinerary("Arrival_Date")
		itemArray(3, j) = RSItinerary("Stay")
		itemArray(4, j) = RSItinerary("AdultCount")
		itemArray(5, j) = RSItinerary("Guest_Count")
		itemArray(6, j) = RSItinerary("Extra_Adult")
		itemArray(7, j) = RSItinerary("Rollaway")
		itemArray(8, j) = RSItinerary("Special_Request")
		itemArray(9, j) = RSItinerary("Smoking")
		On Error Goto 0
	RSItinerary.MoveNext()
	j = j + 1
Loop

RSItinerary.Close()
Set RSItinerary = Nothing

OpenItemArray = itemArray

Else
'funcArray(1, 0) = "None"
OpenItemArray = itemArray


End If

End Function

Function OpenSavedItineraryItemArray(Itinerary_ID) 'Open and Retrieve a Saved Itinerary
Dim itemArray, SQLItinerary, RSLength, j
j = 0
Set RSItinerary = Server.CreateObject("ADODB.Recordset")
SQLItinerary = "Select * from Itinerary_Detail_Vars IDV Where IDV.Itinerary_ID = '" & Itinerary_ID & "' "
SQLItinerary = SQLItinerary & "Order by IDV.Trans_ID"
RSItinerary.Open SQLItinerary, Conn
If Not RSItinerary.EOF Then
RSItinerary.MoveFirst()
Redim itemArray(10, 0)

Do While Not RSItinerary.EOF
		If j > 0 Then 
		Redim Preserve itemArray(10, j)
		End If
		On Error Resume Next
		itemArray(1, j) = RSItinerary("Trans_ID")
		itemArray(2, j) = RSItinerary("Arrival_Date")
		itemArray(3, j) = RSItinerary("Stay")
		itemArray(4, j) = RSItinerary("AdultCount")
		itemArray(5, j) = RSItinerary("Guest_Count")
		itemArray(6, j) = RSItinerary("Extra_Adult")
		itemArray(7, j) = RSItinerary("Rollaway")
		itemArray(8, j) = RSItinerary("Special_Request")
		itemArray(9, j) = RSItinerary("Smoking")
		On Error Goto 0
	RSItinerary.MoveNext()
	j = j + 1
Loop

RSItinerary.Close()
Set RSItinerary = Nothing

OpenSavedItineraryItemArray = itemArray

Else
funcArray(1, 0) = "None"
OpenSavedItineraryItemArray = funcArray

End If

End Function

Function LodgingTotal(funcArray) 'Get Total Cost for Lodging
Dim i, h, Total, AdultCost
Total = 0
TotalRoll = 0

AdultCost = 0

For m = funcArray(10, LBound(funcArray, 2)) to funcArray(10, UBound(funcArray, 2))
Total = Total + GetCostByTranswRoll(funcArray, m)
Next


LodgingTotal = Total

End Function

Function MerchandiseTotal(funcArray) 'Get Total Cost for Merchandise
Dim i, Total
Total = 0

For i = LBound(funcArray, 2) to UBound(funcArray, 2)
	If funcArray(4, i) = "2" Then
		Total = Total + (funcArray(3, i) * funcArray(2, i))
	End If
Next

MerchandiseTotal = Total

End Function

Function PackageTotal(funcarray)
Dim i, Total
Total = 0

For i = LBound(funcArray, 2) to UBound(funcArray, 2)
	If funcArray(4, i) = "3" Then
		Total = Total + (funcArray(3, i) * funcArray(2, i))
	End If
Next

PackageTotal = Total

End Function

Function CartTotal(funcArray) 'Get Total Cost for Itinerary
Dim i, Total
Total = 0

For i = LBound(funcArray, 2) to UBound(funcArray, 2)
	Total = Total + (funcArray(3, i) * funcArray(2, i))
Next

CartTotal = Total

End Function

Function MerchandiseTax(funcArray) 'Get Total Tax for Merchandise Items
	Dim SQLTax, TotalTax
	Set RSTax = Server.CreateObject("ADODB.Recordset")
	TotalTax = 0

	For i = LBound(funcArray, 2) to UBound(funcArray, 2)
		If funcArray(4, i) = "2" Then
			SQLTax = "Get_Tax_Costs_Merchandise '" & funcArray(1, i) & "', '" & CCur(funcArray(3, i) * funcArray(2, i)) & "'"
			RSTax.Open SQLTax, Conn
			TotalTax = TotalTax + RSTax("Total_Tax")
			RSTax.Close()
		End If
	Next

	Set RSTax = Nothing

	MerchandiseTax = FormatNumber(TotalTax, 2)
End Function


Function LodgingTax(funcArray) 'Get total tax for Lodging Items
	Dim SQLTax, TotalTax
	Set RSTax = Server.CreateObject("ADODB.Recordset")
	TotalTax = 0

	For i = LBound(funcArray, 2) to UBound(funcArray, 2)
		If funcArray(4, i) = "1" Then
			SQLTax = "Get_Tax_Costs_Lodging '" & funcArray(1, i) & "', '" & CCur(funcArray(3, i) * funcArray(2, i)) & "'"
			RSTax.Open SQLTax, Conn
			TotalTax = TotalTax + RSTax("Total_Tax")
			RSTax.Close()
		End If
	Next

	Set RSTax = Nothing

	LodgingTax = FormatNumber(TotalTax, 2)
End Function


' expired functionality, new tax methods in place
'
'Function LodgingTax(funcArray) 'Get Total Tax for Lodging Items
'Dim SQLTax, TotalLodging, TotalTax
'Set RSTax = Server.CreateObject("ADODB.Recordset")
'
'TotalTax = 0
'
'for j = funcArray(10, LBound(funcArray, 2)) to funcArray(10, UBound(funcArray, 2))
'
'SQLTax = "Select * From Tax_Rate where Entity_ID = '" & GetEntityFromID(funcArray, j) & "'"
'RSTax.Open SQLTax, Conn
'
'If Not RSTax.EOF Then
'RSTax.MoveFirst()
'
'TotalLodging = GetCostByTranswRoll(funcArray, j)
'
'Do While Not RSTax.EOF
'TotalTax = TotalTax + (TotalLodging * (RSTax("Tax_Rate") / 100))
'RSTax.MoveNext()
'loop
'End If
'RSTax.Close()
'
'Next
'Set RSTax = Nothing
'LodgingTax = FormatNumber(TotalTax, 2)
'
'End Function




Function PackageTax(funcArray, itemArray)
Dim Tax, SQLPackage, TotalLodging, SQLTax, itemArray2
itemArray2 = Session("itemArray")
Tax = 0
Set RSTax = Server.CreateObject("ADODB.Recordset")
	For i = LBound(funcArray, 2) to UBound(funcArray, 2)
		If funcArray(4, i) = "3" Then
			SQLPackage = "[Avante].[dbo].[Get_Package_Items_No_Tax] @Package_ID = '" & Int(funcArray(1, i)) & "', @Date = '" & CDate(itemArray2(2, funcArray(10, i))) & "'"
			Set RSPackage = Conn.Execute(SQLPackage)
			Do While Not RSPackage.EOF

				If RSPackage("Inventory_Type_ID") = "3" Then
					TotalLodging = RSPackage("Markedup_Cost")
					SQLTax = "Get_Tax_Costs_Lodging @Inventory_List_ID='" & RSPackage("Inventory_List_ID") & "', @Cost='" & TotalLodging & "'"
					Set RSTax = Conn.Execute(SQLTax)
					If Not RSTax.EOF Then 
							Tax = Tax + RSTax("Total_Tax")
							RSTax.MoveNext()
					End If
					Set RSTax = Nothing
				End If
			
				If RSPackage("Inventory_Type_ID") = "3" Then
					SQLTax = "Get_Tax_Costs_Merchandise '" & funcArray(1, i) & "', '" & CCur(funcArray(3, i) * funcArray(2, i)) & "'"
					Set RSTax = Conn.Execute(SQLTax)
					Tax = Tax + RSTax("Total_Tax")
					Set RSTax = Nothing
				End If
			
				RSPackage.MoveNext()
			Loop
		End If		
	Next

On Error Resume Next
RSPackage.Close()
On Error goto 0
PackageTax = Tax

End Function


Function LodgingTotalwTax(funcArray) 'Get Total Cost for Lodging
Dim LodgingwRoll
LodgingwRoll = 0
For m = funcArray(10, LBound(funcArray, 2)) to funcArray(10, UBound(funcArray, 2))
LodgingwRoll = LodgingwRoll + GetCostByTranswRoll(funcArray, m)
Next

LodgingTotalwTax = LodgingwRoll + LodgingTax(funcArray)

End Function

Function MerchandiseTotalwTax(funcArray) 'Get Total Cost for Merchandise
Dim i, Total
Total = 0

For i = LBound(funcArray, 2) to UBound(funcArray, 2)
	If funcArray(4, i) = "2" Then
		Total = Total + (funcArray(3, i) * funcArray(2, i))
	End If
Next

MerchandiseTotalwTax = Total + MerchandiseTax(funcArray)

End Function

Function PackageTotalwTax(funcArray, itemArray) 'Get Total Cost for Merchandise
Dim Total
Total = 0

Total = PackageTotal(funcArray) + PackageTax(funcArray, itemArray)

PackageTotalwTax = Total

End Function

Function CartTotalwTax(funcArray, itemArray) 'Get Total Cost for Itinerary

CartTotalwTax = MerchandiseTotalwTax(funcArray) + LodgingTotalwTax(funcArray) + PackageTotalwTax(funcArray, itemArray)

End Function

Function GetRooms(funcArray, Trans_ID)
Dim j

j = 0
Dim transArray()
Redim transArray(10, 0)
For i = LBound(funcArray, 2) to UBound(funcArray, 2)
	If funcArray(4, i) = "1" And funcArray(10, i) = Trans_ID Then
		If j > 0 Then 
		Redim Preserve transArray(10, j)
		End If
		transArray(1, j) = funcArray(1, i)
		transArray(2, j) = funcArray(2, i)
		transArray(3, j) = funcArray(3, i)
		transArray(4, j) = funcArray(4, i)
		transArray(5, j) = funcArray(5, i)
		transArray(6, j) = funcArray(6, i)
		transArray(7, j) = funcArray(7, i)
		transArray(8, j) = funcArray(8, i)
		transArray(9, j) = funcArray(9, i)
		transArray(10, j) = Trans_ID
		j = j + 1
	End If
Next

GetRooms = transArray


End Function

Function GetCostByTranswRoll(funcArray, Trans_ID)
Dim Total, TotalRoll, transArray, TotalAdults
Total = 0
TotalRoll = 0

For i = LBound(funcArray, 2) to UBound(funcArray, 2)
	If funcArray(4, i) = "1" And funcArray(10, i) = Trans_ID Then
		Total = Total + funcArray(3, i) * funcArray(2, i)
	End If
Next

transArray = GetRooms(funcArray, Trans_ID)
TotalRoll = (GetRollaway(transArray(1, LBound(transArray, 2))) * transArray(5, LBound(transArray, 2)) * NightCount(funcArray, Trans_ID))
TotalAdults = (GetAdultCost(funcArray, Trans_ID) * transArray(6, LBound(transArray, 2)))


GetCostByTranswRoll = Total + TotalRoll + TotalAdults

End Function

Function GetCostByTrans(funcArray, Trans_ID)
Dim Total
Total = 0

For i = LBound(funcArray, 2) to UBound(funcArray, 2)
	If funcArray(4, i) = "1" And funcArray(10, i) = Trans_ID Then
		Total = Total + funcArray(3, i)
	End If
Next

GetCostByTrans = Total

End Function


Function GetFirstDateByID(funcArray, Trans_ID)
Dim jFunc

jFunc = 0
Dim transArray()
Redim transArray(10, 0)
For iFunc = LBound(funcArray, 2) to UBound(funcArray, 2)
	If funcArray(4, iFunc) = "1" And funcArray(10, iFunc) = Int(Trans_ID) Then
		If jFunc > 0 Then 
		Redim Preserve transArray(10, jFunc)
		End If
		transArray(1, jFunc) = funcArray(1, iFunc)
		transArray(2, jFunc) = funcArray(2, iFunc)
		transArray(3, jFunc) = funcArray(3, iFunc)
		transArray(4, jFunc) = funcArray(4, iFunc)
		transArray(5, jFunc) = funcArray(5, iFunc)
		transArray(6, jFunc) = funcArray(6, iFunc)
		transArray(7, jFunc) = funcArray(7, iFunc)
		transArray(8, jFunc) = funcArray(8, iFunc)
		transArray(9, jFunc) = funcArray(9, iFunc)
		transArray(10, jFunc) = Int(Trans_ID)
		jFunc = jFunc + 1
	End If
Next
Set RSItem = Server.CreateObject("ADODB.Recordset")
SQLItem = "Get_Inventory_by_ID '" & Int(transArray(1, 0)) & "'"
RSItem.Open SQLItem, Conn
If Not RSItem.EOF Then
GetFirstDateByID = RSItem("Date")
Else
GetFirstDateByID = "Merc"
End If
RSItem.Close()
Set RSItem = Nothing

End Function

Function GetLastDateByID(funcArray, Trans_ID)
Dim j

j = 0
Dim transArray()
Redim transArray(10, 0)
For i = LBound(funcArray, 2) to UBound(funcArray, 2)
	If funcArray(4, i) = "1" And funcArray(10, i) = Int(Trans_ID) Then
		If j > 0 Then 
		Redim Preserve transArray(10, j)
		End If
		transArray(1, j) = funcArray(1, i)
		transArray(2, j) = funcArray(2, i)
		transArray(3, j) = funcArray(3, i)
		transArray(4, j) = funcArray(4, i)
		transArray(5, j) = funcArray(5, i)
		transArray(6, j) = funcArray(6, i)
		transArray(7, j) = funcArray(7, i)
		transArray(8, j) = funcArray(8, i)
		transArray(9, j) = funcArray(9, i)
		transArray(10, j) = Int(Trans_ID)
		j = j + 1
	End If
Next
Set RSItem = Server.CreateObject("ADODB.Recordset")
SQLItem = "Get_Inventory_by_ID '" & Int(transArray(1, UBound(transArray, 2))) & "'"
RSItem.Open SQLItem, Conn
If Not RSItem.EOF Then
GetLastDateByID = RSItem("Date")
End If
RSItem.Close()

End Function

Function GetRollaway(Item_ID)

Dim SQLRoll
Set RSRoll = Server.CreateObject("ADODB.Recordset")
SQLRoll = "Get_Rollaway_ILL '" & Item_ID & "'"
RSRoll.Open SQLRoll, Conn

If Not RSRoll.EOF Then
GetRollaway = RSRoll("Display_Price")
End If

End Function

Function AddRollawayItemArray(itemArray, Trans_ID, Qty)

			For n = LBound(itemArray, 2) to UBound(itemArray, 2)
			If Int(itemArray(1, n)) = Int(Trans_ID) Then
				itemArray(7, n) = Qty
			End If
			Next
AddRollawayItemArray = itemArray

End Function

Function AddRollaway(funcArray, Trans_ID, Qty)

For m = LBound(funcArray, 2) to UBound(funcArray, 2)
	If Int(funcArray(4, m)) = 1 And Int(funcArray(10, m)) = Int(Trans_ID) Then
			funcArray(5, m) = Qty
	End If
Next

AddRollaway = funcArray

End Function

Function GetEntityFromID(funcArray, Trans_ID)
Dim transArray(), p, SQLEntity
Redim transArray(10, 0)
p = 0

Set RSEntity = Server.CreateObject("ADODB.Recordset")
For n = LBound(funcArray, 2) to UBound(funcArray, 2)
	If funcArray(4, n) = "1" And funcArray(10, n) = Trans_ID Then
		If p > 0 Then 
		Redim Preserve transArray(10, p)
		End If
		transArray(1, p) = funcArray(1, n)
		transArray(2, p) = funcArray(2, n)
		transArray(3, p) = funcArray(3, n)
		transArray(4, p) = funcArray(4, n)
		transArray(5, p) = funcArray(5, n)
		transArray(6, p) = funcArray(6, n)
		transArray(7, p) = funcArray(7, n)
		transArray(8, p) = funcArray(8, n)
		transArray(9, p) = funcArray(9, n)
		transArray(10, p) = Trans_ID
		p = p + 1
	End If
Next

SQLEntity = "Select GEM.Entity_ID From Inventory_List_Lodging ILL Inner Join Group_Entity_Map GEM on ILL.Group_ID = GEM.Group_ID Where ILL.Inventory_List_ID = '" & transArray(1, 0) & "'"
RSEntity.Open SQLEntity, Conn

If Not RSEntity.EOF Then
GetEntityFromID = RSEntity("Entity_ID")
End If

End Function

Function GetEntityNameFromID(funcArray, Trans_ID)
Dim transArray(), p, SQLEntity
Redim transArray(10, 0)
p = 0

Set RSEntity = Server.CreateObject("ADODB.Recordset")
For n = LBound(funcArray, 2) to UBound(funcArray, 2)
	If funcArray(4, n) = "1" And funcArray(10, n) = Trans_ID Then
		If p > 0 Then 
		Redim Preserve transArray(10, p)
		End If
		transArray(1, p) = funcArray(1, n)
		transArray(2, p) = funcArray(2, n)
		transArray(3, p) = funcArray(3, n)
		transArray(4, p) = funcArray(4, n)
		transArray(5, p) = funcArray(5, n)
		transArray(6, p) = funcArray(6, n)
		transArray(7, p) = funcArray(7, n)
		transArray(8, p) = funcArray(8, n)
		transArray(9, p) = funcArray(9, n)
		transArray(10, p) = Trans_ID
		p = p + 1
	End If
Next

SQLEntity = "Select E.Name, ED.Address_1, ED.City, ED.State, ED.Zip From Inventory_List_Lodging ILL Inner Join ( Group_Entity_Map GEM Inner Join (Entity E Inner Join Entity_Detail ED on E.Entity_ID = ED.Entity_ID) on GEM.Entity_ID = E.Entity_ID) "
SQLEntity = SQLEntity & "on Ill.Group_ID = GEM.Group_ID Where ILL.Inventory_List_ID = '" & transArray(1, 0) & "'"
RSEntity.Open SQLEntity, Conn

GetEntityNameFromID = RSEntity("Name") & "<br>" & RSEntity("Address_1") & "<br>" & RSEntity("City") & " " & RSEntity("State") & " " & RSEntity("Zip")

End Function

Function GetEntityNameOnlyFromID(funcArray, Trans_ID)
Dim transArray(), p, SQLEntity
Redim transArray(10, 0)
p = 0

Set RSEntity = Server.CreateObject("ADODB.Recordset")
For n = LBound(funcArray, 2) to UBound(funcArray, 2)
	If funcArray(4, n) = "1" And funcArray(10, n) = Trans_ID Then
		If p > 0 Then 
		Redim Preserve transArray(10, p)
		End If
		transArray(1, p) = funcArray(1, n)
		transArray(2, p) = funcArray(2, n)
		transArray(3, p) = funcArray(3, n)
		transArray(4, p) = funcArray(4, n)
		transArray(5, p) = funcArray(5, n)
		transArray(6, p) = funcArray(6, n)
		transArray(7, p) = funcArray(7, n)
		transArray(8, p) = funcArray(8, n)
		transArray(9, p) = funcArray(9, n)
		transArray(10, p) = Trans_ID
		p = p + 1
	End If
Next

SQLEntity = "Select E.Name From Inventory_List_Lodging ILL Inner Join ( Group_Entity_Map GEM Inner Join (Entity E Inner Join Entity_Detail ED on E.Entity_ID = ED.Entity_ID) on GEM.Entity_ID = E.Entity_ID) "
SQLEntity = SQLEntity & "on Ill.Group_ID = GEM.Group_ID Where ILL.Inventory_List_ID = '" & transArray(1, 0) & "'"
RSEntity.Open SQLEntity, Conn
If Not RSEntity.EOF Then
GetEntityNameOnlyFromID = RSEntity("Name")
End If
RSEntity.Close()
Set RSEntity = Nothing

End Function

Function GetEntityLocationFromID(funcArray, Trans_ID)
Dim transArray(), p, SQLEntity
Redim transArray(10, 0)
p = 0

Set RSEntity = Server.CreateObject("ADODB.Recordset")
For n = LBound(funcArray, 2) to UBound(funcArray, 2)
	If funcArray(4, n) = "1" And funcArray(10, n) = Trans_ID Then
		If p > 0 Then 
		Redim Preserve transArray(10, p)
		End If
		transArray(1, p) = funcArray(1, n)
		transArray(2, p) = funcArray(2, n)
		transArray(3, p) = funcArray(3, n)
		transArray(4, p) = funcArray(4, n)
		transArray(5, p) = funcArray(5, n)
		transArray(6, p) = funcArray(6, n)
		transArray(7, p) = funcArray(7, n)
		transArray(8, p) = funcArray(8, n)
		transArray(9, p) = funcArray(9, n)
		transArray(10, p) = Trans_ID
		p = p + 1
	End If
Next

SQLEntity = "Select ED.City From Inventory_List_Lodging ILL Inner Join ( Group_Entity_Map GEM Inner Join (Entity E Inner Join Entity_Detail ED on E.Entity_ID = ED.Entity_ID) on GEM.Entity_ID = E.Entity_ID) "
SQLEntity = SQLEntity & "on Ill.Group_ID = GEM.Group_ID Where ILL.Inventory_List_ID = '" & transArray(1, 0) & "'"
RSEntity.Open SQLEntity, Conn
If Not RSEntity.EOF Then
GetEntityLocationFromID = RSEntity("City")
End If
RSEntity.Close()
Set RSEntity = Nothing

End Function

Function RoomType(funcArray, Trans_ID)
Dim transArray(), p, SQLRoom
Redim transArray(10, 0)
p = 0

Set RSRoom = Server.CreateObject("ADODB.Recordset")
For n = LBound(funcArray, 2) to UBound(funcArray, 2)
	If funcArray(4, n) = "1" And funcArray(10, n) = Trans_ID Then
		If p > 0 Then 
		Redim Preserve transArray(10, p)
		End If
		transArray(1, p) = funcArray(1, n)
		transArray(2, p) = funcArray(2, n)
		transArray(3, p) = funcArray(3, n)
		transArray(4, p) = funcArray(4, n)
		transArray(5, p) = funcArray(5, n)
		transArray(6, p) = funcArray(6, n)
		transArray(7, p) = funcArray(7, n)
		transArray(8, p) = funcArray(8, n)
		transArray(9, p) = funcArray(9, n)
		transArray(10, p) = Trans_ID
		p = p + 1
	End If
Next



SQLRoom = "Select AP.[Amenity_ID], AP.[Group_ID], II.[Item_ID], AP.[Name], AP.[Description], ATT.[Att_Desc] "
SQLRoom = SQLRoom & "from Entity E "
SQLRoom = SQLRoom & "Inner Join (Group_Entity_Map GEM "
SQLRoom = SQLRoom & "Inner Join ([Group] G "
SQLRoom = SQLRoom & "Inner Join (Attribute_Type ATT "
SQLRoom = SQLRoom & "Inner Join (Amenity_Package AP "
SQLRoom = SQLRoom & "Inner Join (Inventory_Item II "
SQLRoom = SQLRoom & "Inner Join Inventory_List_Lodging ILL "
SQLRoom = SQLRoom & "On II.Item_ID = ILL.Item_ID) "
SQLRoom = SQLRoom & "On AP.Amenity_ID = II.Amenity_ID) "
SQLRoom = SQLRoom & "On ATT.Att_ID = II.Att_ID) "
SQLRoom = SQLRoom & "On AP.Group_ID = G.Group_ID) " 
SQLRoom = SQLRoom & "On GEM.Group_ID = G.Group_ID) " 
SQLRoom = SQLRoom & "On E.Entity_ID = GEM.Entity_ID "
SQLRoom = SQLRoom & "Where E.Entity_ID='" & Int(GetEntityFromID(funcArray, Trans_ID)) & "' And "
SQLRoom = SQLRoom & "ILL.Inventory_List_ID = '" & Int(transArray(1, 0)) & "' "
SQLRoom = SQLRoom & "Order By ATT.Att_Desc_Detail"
RSRoom.Open SQLRoom, Conn

RoomType = RSRoom("Att_Desc") & " - " & RSRoom("Name")

RSRoom.Close()
Set RSRoom = Nothing

End Function

Function GetRoomAttribute(funcArray, Trans_ID, Attr)
Dim transArray(), p, SQLRoom
Redim transArray(10, 0)
p = 0

Set RSRoom = Server.CreateObject("ADODB.Recordset")
For n = LBound(funcArray, 2) to UBound(funcArray, 2)
	If funcArray(4, n) = "1" And funcArray(10, n) = Trans_ID Then
		If p > 0 Then 
		Redim Preserve transArray(10, p)
		End If
		transArray(1, p) = funcArray(1, n)
		transArray(2, p) = funcArray(2, n)
		transArray(3, p) = funcArray(3, n)
		transArray(4, p) = funcArray(4, n)
		transArray(5, p) = funcArray(5, n)
		transArray(6, p) = funcArray(6, n)
		transArray(7, p) = funcArray(7, n)
		transArray(8, p) = funcArray(8, n)
		transArray(9, p) = funcArray(9, n)
		transArray(10, p) = Trans_ID
		p = p + 1
	End If
Next



SQLRoom = "Select AMT.Name, APM.Variable, APM.Amenity_Type_ID from Inventory_List_Lodging ILL Inner Join (Inventory_Item II Inner Join (Amenity_Package AP "
SQLRoom = SQLRoom &	"inner join (Amenity_Package_Map APM inner join Amenity_Type AMT on APM.Amenity_Type_ID = AMT.Amenity_Type_ID) "
SQLRoom = SQLRoom &	"on AP.Amenity_ID = APM.Amenity_ID) on AP.Amenity_ID = II.Amenity_ID) on ILL.Item_ID = II.Item_ID where ILL.Inventory_List_ID = '" & transArray(1, 0) & "' And "
SQLRoom = SQLRoom &	"APM.Amenity_Type_ID = '" & Attr & "'"
RSRoom.Open SQLRoom, Conn

If Not RSRoom.EOF Then
GetRoomAttribute = RSRoom("Variable")
End If

RSRoom.Close()
Set RSRoom = Nothing

End Function

Function GetRoomAttributeByItemID(funcArray, Item_ID, Attr)
Dim transArray(), p, SQLRoom
Redim transArray(10, 0)
p = 0

Set RSRoom = Server.CreateObject("ADODB.Recordset")

SQLRoom = "Select AMT.Name, APM.Variable, APM.Amenity_Type_ID from Inventory_List_Lodging ILL Inner Join (Inventory_Item II Inner Join (Amenity_Package AP "
SQLRoom = SQLRoom &	"inner join (Amenity_Package_Map APM inner join Amenity_Type AMT on APM.Amenity_Type_ID = AMT.Amenity_Type_ID) "
SQLRoom = SQLRoom &	"on AP.Amenity_ID = APM.Amenity_ID) on AP.Amenity_ID = II.Amenity_ID) on ILL.Item_ID = II.Item_ID where ILL.Inventory_List_ID = '" & Item_ID & "' And "
SQLRoom = SQLRoom &	"APM.Amenity_Type_ID = '" & Attr & "'"
RSRoom.Open SQLRoom, Conn

If Not RSRoom.EOF Then
GetRoomAttributeByItemID = RSRoom("Variable")
End If

RSRoom.Close()
Set RSRoom = Nothing

End Function

Function NightCount(funcArray, Trans_ID)
Dim transArray(), p, SQLRoom
Redim transArray(10, 0)
p = 0

Set RSRoom = Server.CreateObject("ADODB.Recordset")
For n = LBound(funcArray, 2) to UBound(funcArray, 2)
	If funcArray(4, n) = "1" And funcArray(10, n) = Trans_ID Then
		If p > 0 Then 
		Redim Preserve transArray(10, p)
		End If
		transArray(1, p) = funcArray(1, n)
		transArray(2, p) = funcArray(2, n)
		transArray(3, p) = funcArray(3, n)
		transArray(4, p) = funcArray(4, n)
		transArray(5, p) = funcArray(5, n)
		transArray(6, p) = funcArray(6, n)
		transArray(7, p) = funcArray(7, n)
		transArray(8, p) = funcArray(8, n)
		transArray(9, p) = funcArray(9, n)
		transArray(10, p) = Trans_ID
		p = p + 1
	End If
Next

NightCount = UBound(transArray, 2) + 1

End Function

Function TotalDate(funcArray)
Dim dateArray(), temp, finalArray()
Redim finalArray(1)

Redim dateArray(0)
Set RSItem = Server.CreateObject("ADODB.Recordset")

For j = LBound(funcArray, 2) to UBound(funcArray, 2)
If funcArray(4, j) = "1" Then
If j > 0 Then Redim Preserve dateArray(j)
SQLItem = "Get_Inventory_by_ID '" & Int(funcArray(1, j)) & "'"
RSItem.Open SQLItem, Conn
dateArray(j) = RSItem("Date")
RSItem.Close()
End If
Next

for k = 0 to ubound(dateArray) - 1
    for l= 0 to k
        if dateArray(l)>dateArray(l+1) then
            temp=dateArray(l+1)
            dateArray(l+1)=dateArray(l)
            dateArray(l)=temp
        end if
    next
next

finalArray(0) = dateArray(LBound(dateArray))
finalArray(1) = dateArray(UBound(dateArray))

TotalDate = finalArray

End Function

Function RoomQtyCheck(Entity_ID, ArrivalDate, DepartDate, Amenity_ID)
Dim SQLCheck
Set RSCheck = Server.CreateObject("ADODB.Recordset")
SQLCheck = "Check_Inventory '" & Entity_ID & "', '" & ArrivalDate & "', '" & DepartDate & "', '" & Amenity_ID & "'"
RSCheck.Open SQLCheck, Conn

If Not RSCheck.EOF Then
	RoomQtyCheck = RSCheck("Available")
Else
	RoomQtyCheck = "0"
End If

End Function

Function AddSmoking(itemArray, Trans_ID)

For m = LBound(itemArray, 2) to UBound(itemArray, 2)
	If Int(itemArray(1, m)) = Int(Trans_ID) Then
		itemArray(9, m) = 1
	End If
Next

AddSmoking = itemArray

End Function

Function AddSpecial(itemArray, Trans_ID, Spec)

For m = LBound(itemArray, 2) to UBound(itemArray, 2)
	If Int(itemArray(1, m)) = Int(Trans_ID) Then
		itemArray(8, m) = Spec	
	End If
Next

AddSpecial = itemArray

End Function

Function CheckAdultCount(funcArray, Item_ID, Qty)
Dim Adults, Max, AdultCount

Adults = GetRoomAttributeByItemID(funcArray, Item_ID, 67) 
Max = GetRoomAttributeByItemID(funcArray, Item_ID, 68)

If Int(Session("AdultCount")) <= (Int(Adults) * Int(Qty)) Then
	AdultCount = 0
ElseIf (Int(Session("AdultCount")) > (Int(Adults) * Int(Qty))) And (Int(Session("AdultCount")) <= (Int(Max) * Int(Qty))) Then
	AdultCount = (Int(Session("AdultCount")) - (Int(Adults) * Int(Qty)))
End If

CheckAdultCount = AdultCount

End Function

Function GetAdultCost(funcArray, Trans_ID)
Dim Cost, SQLCost

Set RSCost = Server.CreateObject("ADODB.Recordset")
SQLCost = "[Avante].[dbo].[Get_Extra_Adult] @Entity_ID = '" & GetEntityFromID(funcArray, Trans_ID) & "', @Desc = 'Web'"
RSCost.Open SQLCost, Conn

If Not RSCost.EOF Then
Cost = RSCost("Display_Price")
End If

GetAdultCost = Cost

End Function

Function ClearTrans(funcArray, Trans_ID)
Dim newArray, Count, l, newitemArray
Count = 0

For n = LBound(funcArray, 2) to UBound(funcArray, 2)
	If funcArray(10, n) = Int(Trans_ID) Then Count = Count + 1
Next
If (UBound(funcArray, 2) - Count) = -1 Then
	Redim newArray(10, 0)
Else
	Redim newArray(10, (UBound(funcArray, 2) - Count))
	l = 0
For n = LBound(funcArray, 2) to UBound(funcArray, 2)
	If Not funcArray(10, n) = Int(Trans_ID) Then
		newArray(1, l) = funcArray(1, n)
		newArray(2, l) = funcArray(2, n)
		newArray(3, l) = funcArray(3, n)
		newArray(4, l) = funcArray(4, n)
		newArray(5, l) = funcArray(5, n)
		newArray(6, l) = funcArray(6, n)
		newArray(7, l) = funcArray(7, n)
		newArray(8, l) = funcArray(8, n)
		newArray(9, l) = funcArray(9, n)
		newArray(10, l) = funcArray(10, n)
		l = l + 1
	End If
Next
End If

ClearTrans = newArray

End Function

Function ClearItemTrans(itemArray, Trans_ID)
Dim Count, l, newitemArray, n
Count = 0

For n = LBound(itemArray, 2) to UBound(itemArray, 2)
	If itemArray(1, n) = Int(Trans_ID) Then Count = Count + 1
Next
If (UBound(itemArray, 2) - Count) = -1 Then
	Redim newitemArray(10, 0)
Else
	Redim newitemArray(10, (UBound(itemArray, 2) - Count))
	l = 0
For n = LBound(itemArray, 2) to UBound(itemArray, 2)
	If Not itemArray(1, n) = Int(Trans_ID) Then
		newitemArray(1, l) = itemArray(1, n)
		newitemArray(2, l) = itemArray(2, n)
		newitemArray(3, l) = itemArray(3, n)
		newitemArray(4, l) = itemArray(4, n)
		newitemArray(5, l) = itemArray(5, n)
		newitemArray(6, l) = itemArray(6, n)
		newitemArray(7, l) = itemArray(7, n)
		newitemArray(8, l) = itemArray(8, n)
		newitemArray(9, l) = itemArray(9, n)
		newitemArray(10, l) = itemArray(10, n)
		l = l + 1
	End If
Next
End If

ClearItemTrans = newitemArray

End Function

Function CheckAvailRooms(Entity_ID)
	Dim SQLAmen, SQLAtt, Count
	Count = 0

	Set RSAmen = Server.CreateObject("ADODB.Recordset")
	Set RSAtt = Server.CreateObject("ADODB.Recordset")

	SQLAmen = "Select AP.[Amenity_ID], AP.[Group_ID], II.[Item_ID], AP.[Name], AP.[Description], ATT.[Att_Desc] "
	SQLAmen = SQLAmen & "from Entity E "
	SQLAmen = SQLAmen & "Inner Join (Group_Entity_Map GEM "
	SQLAmen = SQLAmen & "Inner Join ([Group] G "
	SQLAmen = SQLAmen & "Inner Join (Attribute_Type ATT "
	SQLAmen = SQLAmen & "Inner Join (Inventory_Item II "
	SQLAmen = SQLAmen & "Inner Join Amenity_Package AP "
	SQLAmen = SQLAmen & "On II.Amenity_ID = AP.Amenity_ID) "
	SQLAmen = SQLAmen & "On ATT.Att_ID = II.Att_ID) "
	SQLAmen = SQLAmen & "On AP.Group_ID = G.Group_ID) " 
	SQLAmen = SQLAmen & "On GEM.Group_ID = G.Group_ID) " 
	SQLAmen = SQLAmen & "On E.Entity_ID = GEM.Entity_ID "
	SQLAmen = SQLAmen & "Where E.Entity_ID='" & Entity_ID & "' "
	SQLAmen = SQLAmen & "Order By ATT.Att_Desc_Detail"
	
	RSAmen.Open SQLAmen, Conn


	Do While Not RSAmen.EOF
		SQLAtt = "Select AMT.Name, APM.Variable, APM.Amenity_Type_ID from Amenity_Package AP inner join (Amenity_Package_Map APM inner join Amenity_Type AMT on APM.Amenity_Type_ID = AMT.Amenity_Type_ID) "
		SQLAtt = SQLAtt & "on AP.Amenity_ID = APM.Amenity_ID where AP.Amenity_ID = '" & RSAmenity("Amenity_ID") & "' And "
		SQLAtt = SQLAtt & "APM.Amenity_Type_ID = '68' And APM.Variable >= '" & Session("AdultCount") / Session("RoomCount") & "'"	
		RSAtt.Open SQLAtt, Conn
		If Not RSAmen.EOF Then Count = Count + 1
		RSAtt.Close()
		RSAmen.MoveNext()
	Loop

	CheckAvailRooms = Count	
		
End Function

Function CheckAvailRoomsDate(Entity_ID, ArrivalDate, DepartDate)

	Dim SQLAmen, SQLAtt, Count
	Count = 0

	Set RSAmen = Server.CreateObject("ADODB.Recordset")
	Set RSAtt = Server.CreateObject("ADODB.Recordset")

	SQLAmen = "Select AP.[Amenity_ID], AP.[Group_ID], II.[Item_ID], AP.[Name], AP.[Description], ATT.[Att_Desc] "
	SQLAmen = SQLAmen & "from Entity E "
	SQLAmen = SQLAmen & "Inner Join (Group_Entity_Map GEM "
	SQLAmen = SQLAmen & "Inner Join ([Group] G "
	SQLAmen = SQLAmen & "Inner Join (Attribute_Type ATT "
	SQLAmen = SQLAmen & "Inner Join (Inventory_Item II "
	SQLAmen = SQLAmen & "Inner Join Amenity_Package AP "
	SQLAmen = SQLAmen & "On II.Amenity_ID = AP.Amenity_ID) "
	SQLAmen = SQLAmen & "On ATT.Att_ID = II.Att_ID) "
	SQLAmen = SQLAmen & "On AP.Group_ID = G.Group_ID) " 
	SQLAmen = SQLAmen & "On GEM.Group_ID = G.Group_ID) " 
	SQLAmen = SQLAmen & "On E.Entity_ID = GEM.Entity_ID "
	SQLAmen = SQLAmen & "Where E.Entity_ID='" & Entity_ID & "' "
	SQLAmen = SQLAmen & "And Exists(Select * From Inventory_List_Lodging ILL Where ILL.Item_ID = II.Item_ID And Date between '" & ArrivalDate & "' and '" & DepartDate & "')"
	SQLAmen = SQLAmen & "Order By ATT.Att_Desc_Detail"
	
	RSAmen.Open SQLAmen, Conn


	Do While Not RSAmen.EOF
		SQLAtt = "Select AMT.Name, APM.Variable, APM.Amenity_Type_ID from Amenity_Package AP inner join (Amenity_Package_Map APM inner join Amenity_Type AMT on APM.Amenity_Type_ID = AMT.Amenity_Type_ID) "
		SQLAtt = SQLAtt & "on AP.Amenity_ID = APM.Amenity_ID where AP.Amenity_ID = '" & RSAmenity("Amenity_ID") & "' And "
		SQLAtt = SQLAtt & "APM.Amenity_Type_ID = '68' And APM.Variable >= '" & Session("AdultCount") / Session("RoomCount") & "'"	
		RSAtt.Open SQLAtt, Conn
		If Not RSAmen.EOF Then Count = Count + 1
		RSAtt.Close()
		RSAmen.MoveNext()
	Loop

	CheckAvailRoomsDate = Count	
	
End Function

Function RoomAvailabilityByILID(List_ID)
' Returns Boolean, checks availability on a room for a given adate period
	Dim SQLItem, RSItem
	SQLItem = "Select * From Inventory_List_Lodging ILL Where ILL.Inventory_List_ID = '" & List_ID & "' And ILL.Available > 0"
	Set RSItem = Conn.Execute(SQLItem)
	If Not RSItem.EOF Then 
		RoomAvailabilityByILID = True
	Else
		RoomAvailabilityByILID = False
	End If
	RSItem.Close
End Function

Function RoomAvailability(Item_ID, ArrivalDate, DepartDate)
' Returns Boolean, checks availability on a room for a given adate period
	Dim SQLItem, RSItem
	SQLItem = "Select * From Inventory_List_Lodging ILL Where ILL.Item_ID = " & Item_ID & " And ILL.Date between '" & ArrivalDate & "' and '" & DepartDate & "' And ILL.Available > 0"
	Set RSItem = Conn.Execute(SQLItem)
	If Not RSItem.EOF Then 
		RoomAvailability = True
	Else
		RoomAvailability = False
	End If
	RSItem.Close
End Function


Function GetMaxAdultsByRoom(Amenity_ID)
Dim SQLAtt
Set RSAtt = Server.CreateObject("ADODB.Recordset")

	SQLAtt = "Select AMT.Name, APM.Variable, APM.Amenity_Type_ID from Inventory_Item II Inner Join (Amenity_Package AP inner join (Amenity_Package_Map APM inner join Amenity_Type AMT on APM.Amenity_Type_ID = AMT.Amenity_Type_ID) "
	SQLAtt = SQLAtt & "on AP.Amenity_ID = APM.Amenity_ID) on II.Amenity_ID = AP.Amenity_ID where II.Item_ID = '" & Amenity_ID & "' And "
	SQLAtt = SQLAtt & "APM.Amenity_Type_ID = '68'"	
	RSAtt.Open SQLAtt, Conn

If Not RSAtt.EOF Then
GetMaxAdultsByRoom = RSAtt("Variable")
Else
GetMaxAdultsByRoom = 0
End If

RSAtt.Close()
Set RSAtt = Nothing

End Function

Function LodgingExists(funcArray)
Dim Exists
Exists = False
For a = LBound(funcArray, 2) to UBound(funcArray, 2)
	If Int(funcArray(4, a)) = 1 Then Exists = True
Next

LodgingExists = Exists

End Function

Function MercExists(funcArray)
Dim Exists
Exists = False
For a = LBound(funcArray, 2) to UBound(funcArray, 2)
	If Int(funcArray(4, a)) = 2 Then Exists = True
Next

MercExists = Exists


End Function

Function PackageExists(funcArray)
Dim Exists
Exists = False
For a = LBound(funcArray, 2) to UBound(funcArray, 2)
	If Int(funcArray(4, a)) = 3 Then Exists = True
Next

PackageExists = Exists


End Function

Function Need_Delivery(funcArray)
Dim sqlDelivery, Delivery
Delivery = True

Set rsGroup = server.CreateObject("ADODB.Recordset")

Set rsDelivery = Server.CreateObject("ADODB.Recordset")
sqlDelivery = "Get_Locations_Delivery @Realm_ID='1'"
rsDelivery.Open sqlDelivery, Conn
For n = LBound(funcArray, 2) to UBound(funcArray, 2)
If funcArray(4, n) = "1" Then
sqlGroup = "Get_Inventory_by_ID '" & funcArray(1, n) & "'"
rsGroup.Open sqlGroup, Conn


rsDelivery.MoveFirst()

Do While Not rsDelivery.EOF
If rsGroup("Group_ID") = rsDelivery("Group_ID") Then
Delivery = False
End If
rsDelivery.MoveNext()
Loop
rsGroup.Close()
End If
Next


Set rsGroup = Nothing
rsDelivery.Close()
Set rsDelivery = Nothing

Need_Delivery = Delivery

End Function
%>