<%
	
Function NewItinerary() 'Create New Itinerary

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

If Trim(Session("UserID")) = "" Then
	SQLNew = "New_Itinerary Null, '1', '" & Session.SessionID & "'"
	RSNew.open SQLNew, Conn
	Session("Itinerary_ID") = RSNew("Itinerary_ID")
Else
	SQLNew = "New_Itinerary '" & Session("UserID") & "', '1', Null"
	RSNew.open SQLNew, Conn
	Session("Itinerary_ID") = RSNew("Itinerary_ID")
End If
	
End Function	

Function SaveItinerary() 'Save Array into Itinerary

Dim SQLAddCart, RSAddCart, Itinerary_ID, Item_ID, Quantity, URL, Item, Value, i
Dim tmpArray
tmpArray = Session("Itinerary_Items")

	If Trim(Session("Itinerary_ID")) = "" Then
		Call NewItinerary()
	End If
	
	For i = LBound(tmpArray, 2) to UBound(tmpArray, 2)
			SQLAddCart = "[Avante].[dbo].[ItineraryAddItem] '" & Session("Itinerary_ID") & "', '" & tmpArray(1, i) & "', '" & tmpArray(2, i) & "', '" & tmpArray(3, i) & "', '" & tmpArray(4, i) & "'"
			Conn.Execute(SQLAddCart)
		Next
End Function

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

Extra_Adult = CheckAdultCount(Item_ID, Quantity)

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

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

If exists = False Then
	ArrayLength = UBound(tmpArray, 2) + 1
	Redim Preserve tmpArray(10, ArrayLength)
	tmpArray(1, ArrayLength) = Item_ID
	tmpArray(2, ArrayLength) = Quantity
	tmpArray(3, ArrayLength) = Cost
	tmpArray(4, ArrayLength) = Product_Type
	tmpArray(5, ArrayLength) = Rollaway
	tmpArray(6, ArrayLength) = Extra_Adult
	tmpArray(10, ArrayLength) = Trans_ID
	Session("Itinerary_Items") = tmpArray
End If
End If

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 tmpArray(), SQLItinerary, RSLength, i
Set RSItinerary = Server.CreateObject("ADODB.Recordset")
SQLItinerary = "Select * from Itinerary I inner join Itinerary_Detail ID on I.Itinerary_ID = ID.Itinerary_ID Where Itinerary_ID = '" & Itinerary_ID & "' "
SQLItinerary = SQLItinerary & "And Contact_ID = '" & User_ID & "' Order by Product_ID"
RSItinerary.Open SQLItinerary, Conn
RSLength = RSItinerary.RecordCount
Redim tmpArray (10, RSLength - 1)

For i = 0 to RSItinerary.RecordCount - 1
tmpArray(1, i) = RSItinerary("Product_ID")
tmpArray(2, i) = RSItinerary("Quantity")
tmpArray(3, i) = RSItinerary("Unit_Price")
tmpArray(4, i) = RSItinerary("Product_Type")
RSItinerary.MoveNext()
Next

RSItinerary.Close()
Set RSItinerary = Nothing

OpenSavedItinerary = tmpArray

End Function

Function LodgingTotal() 'Get Total Cost for Lodging
Dim i, h, tmpArray, Total, AdultCost
Total = 0
TotalRoll = 0
tmpArray = Session("Itinerary_Items")
AdultCost = 0

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


LodgingTotal = Total

End Function

Function MerchandiseTotal() 'Get Total Cost for Merchandise
Dim i, tmpArray, Total
Total = 0
tmpArray = Session("Itinerary_Items")

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

MerchandiseTotal = Total

End Function

Function CartTotal() 'Get Total Cost for Itinerary
Dim i, tmpArray, Total
Total = 0
tmpArray = Session("Itinerary_Items")

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

CartTotal = Total

End Function

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

For i = LBound(tmpArray, 2) to UBound(tmpArray, 2)
	If tmpArray(4, i) = "2" Then
	SQLTax = "Get_Tax_Costs_Merchandise '" & tmpArray(1, i) & "', '" & CCur(tmpArray(3, i) * tmpArray(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() 'Get Total Tax for Lodging Items
Dim SQLTax, TotalLodging, TotalTax, tmpArray
Set RSTax = Server.CreateObject("ADODB.Recordset")
tmpArray = Session("Itinerary_Items")
TotalTax = 0

for j = tmpArray(10, LBound(tmpArray, 2)) to tmpArray(10, UBound(tmpArray, 2))

SQLTax = "Select * From Tax_Rate where Entity_ID = '" & GetEntityFromID(j) & "'"
RSTax.Open SQLTax, Conn

If Not RSTax.EOF Then
RSTax.MoveFirst()

TotalLodging = GetCostByTranswRoll(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 LodgingTotalwTax() 'Get Total Cost for Lodging
Dim LodgingwRoll
LodgingwRoll = 0
For m = tmpArray(10, LBound(tmpArray, 2)) to tmpArray(10, UBound(tmpArray, 2))
LodgingwRoll = LodgingwRoll + GetCostByTranswRoll(m)
Next

LodgingTotalwTax = LodgingwRoll + LodgingTax()

End Function

Function MerchandiseTotalwTax() 'Get Total Cost for Merchandise
Dim i, tmpArray, Total
Total = 0
tmpArray = Session("Itinerary_Items")

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

MerchandiseTotalwTax = Total + MerchandiseTax()

End Function

Function CartTotalwTax() 'Get Total Cost for Itinerary

CartTotalwTax = MerchandiseTotalwTax() + LodgingTotalwTax()

End Function

Function GetRooms(Trans_ID)
Dim tmpArray, j
tmpArray = Session("Itinerary_Items")
j = 0
Dim transArray()
Redim transArray(10, 0)
For i = LBound(tmpArray, 2) to UBound(tmpArray, 2)
	If tmpArray(4, i) = "1" And tmpArray(10, i) = Trans_ID Then
		If j > 0 Then 
		Redim Preserve transArray(10, j)
		End If
		transArray(1, j) = tmpArray(1, i)
		transArray(2, j) = tmpArray(2, i)
		transArray(3, j) = tmpArray(3, i)
		transArray(4, j) = tmpArray(4, i)
		transArray(5, j) = tmpArray(5, i)
		transArray(6, j) = tmpArray(6, i)
		transArray(10, j) = Trans_ID
		j = j + 1
	End If
Next

GetRooms = transArray


End Function

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

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

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


GetCostByTranswRoll = Total + TotalRoll + TotalAdults

End Function

Function GetCostByTrans(Trans_ID)
Dim Total
Total = 0

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

GetCostByTrans = Total

End Function


Function GetFirstDateByID(Trans_ID)
Dim tmpArray, jFunc
tmpArray = Session("Itinerary_Items")
jFunc = 0
Dim transArray()
Redim transArray(10, 0)
For iFunc = LBound(tmpArray, 2) to UBound(tmpArray, 2)
	If tmpArray(4, iFunc) = "1" And tmpArray(10, iFunc) = Int(Trans_ID) Then
		If jFunc > 0 Then 
		Redim Preserve transArray(10, jFunc)
		End If
		transArray(1, jFunc) = tmpArray(1, iFunc)
		transArray(2, jFunc) = tmpArray(2, iFunc)
		transArray(3, jFunc) = tmpArray(3, iFunc)
		transArray(4, jFunc) = tmpArray(4, iFunc)
		transArray(5, jFunc) = tmpArray(5, iFunc)
		transArray(6, jFunc) = tmpArray(6, 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(Trans_ID)
Dim tmpArray, j
tmpArray = Session("Itinerary_Items")
j = 0
Dim transArray()
Redim transArray(10, 0)
For i = LBound(tmpArray, 2) to UBound(tmpArray, 2)
	If tmpArray(4, i) = "1" And tmpArray(10, i) = Int(Trans_ID) Then
		If j > 0 Then 
		Redim Preserve transArray(10, j)
		End If
		transArray(1, j) = tmpArray(1, i)
		transArray(2, j) = tmpArray(2, i)
		transArray(3, j) = tmpArray(3, i)
		transArray(4, j) = tmpArray(4, i)
		transArray(5, j) = tmpArray(5, i)
		transArray(6, j) = tmpArray(6, 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 AddRollaway(Trans_ID, Qty)
Dim tmpArray
tmpArray = Session("Itinerary_Items")

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

Session("Itinerary_Items") = tmpArray

End Function

Function GetEntityFromID(Trans_ID)
Dim tmpArray, transArray(), p, SQLEntity
Redim transArray(10, 0)
p = 0
tmpArray = Session("Itinerary_Items")
Set RSEntity = Server.CreateObject("ADODB.Recordset")
For n = LBound(tmpArray, 2) to UBound(tmpArray, 2)
	If tmpArray(4, n) = "1" And tmpArray(10, n) = Trans_ID Then
		If p > 0 Then 
		Redim Preserve transArray(10, p)
		End If
		transArray(1, p) = tmpArray(1, n)
		transArray(2, p) = tmpArray(2, n)
		transArray(3, p) = tmpArray(3, n)
		transArray(4, p) = tmpArray(4, n)
		transArray(5, p) = tmpArray(5, n)
		transArray(6, p) = tmpArray(6, 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(Trans_ID)
Dim tmpArray, transArray(), p, SQLEntity
Redim transArray(10, 0)
p = 0
tmpArray = Session("Itinerary_Items")
Set RSEntity = Server.CreateObject("ADODB.Recordset")
For n = LBound(tmpArray, 2) to UBound(tmpArray, 2)
	If tmpArray(4, n) = "1" And tmpArray(10, n) = Trans_ID Then
		If p > 0 Then 
		Redim Preserve transArray(10, p)
		End If
		transArray(1, p) = tmpArray(1, n)
		transArray(2, p) = tmpArray(2, n)
		transArray(3, p) = tmpArray(3, n)
		transArray(4, p) = tmpArray(4, n)
		transArray(5, p) = tmpArray(5, n)
		transArray(6, p) = tmpArray(6, 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") & " " & RSEntity("City") & " " & RSEntity("State") & " " & RSEntity("Zip")

End Function

Function GetEntityNameOnlyFromID(Trans_ID)
Dim tmpArray, transArray(), p, SQLEntity
Redim transArray(10, 0)
p = 0
tmpArray = Session("Itinerary_Items")
Set RSEntity = Server.CreateObject("ADODB.Recordset")
For n = LBound(tmpArray, 2) to UBound(tmpArray, 2)
	If tmpArray(4, n) = "1" And tmpArray(10, n) = Trans_ID Then
		If p > 0 Then 
		Redim Preserve transArray(10, p)
		End If
		transArray(1, p) = tmpArray(1, n)
		transArray(2, p) = tmpArray(2, n)
		transArray(3, p) = tmpArray(3, n)
		transArray(4, p) = tmpArray(4, n)
		transArray(5, p) = tmpArray(5, n)
		transArray(6, p) = tmpArray(6, 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 RoomType(Trans_ID)
Dim tmpArray, transArray(), p, SQLRoom
Redim transArray(10, 0)
p = 0
tmpArray = Session("Itinerary_Items")
Set RSRoom = Server.CreateObject("ADODB.Recordset")
For n = LBound(tmpArray, 2) to UBound(tmpArray, 2)
	If tmpArray(4, n) = "1" And tmpArray(10, n) = Trans_ID Then
		If p > 0 Then 
		Redim Preserve transArray(10, p)
		End If
		transArray(1, p) = tmpArray(1, n)
		transArray(2, p) = tmpArray(2, n)
		transArray(3, p) = tmpArray(3, n)
		transArray(4, p) = tmpArray(4, n)
		transArray(5, p) = tmpArray(5, n)
		transArray(6, p) = tmpArray(6, 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 (Inventory_Item II "
SQLRoom = SQLRoom & "Inner Join Amenity_Package AP "
SQLRoom = SQLRoom & "On II.Amenity_ID = AP.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(Trans_ID)) & "' "
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(Trans_ID, Attr)
Dim tmpArray, transArray(), p, SQLRoom
Redim transArray(10, 0)
p = 0
tmpArray = Session("Itinerary_Items")
Set RSRoom = Server.CreateObject("ADODB.Recordset")
For n = LBound(tmpArray, 2) to UBound(tmpArray, 2)
	If tmpArray(4, n) = "1" And tmpArray(10, n) = Trans_ID Then
		If p > 0 Then 
		Redim Preserve transArray(10, p)
		End If
		transArray(1, p) = tmpArray(1, n)
		transArray(2, p) = tmpArray(2, n)
		transArray(3, p) = tmpArray(3, n)
		transArray(4, p) = tmpArray(4, n)
		transArray(5, p) = tmpArray(5, n)
		transArray(6, p) = tmpArray(6, 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(Item_ID, Attr)
Dim tmpArray, transArray(), p, SQLRoom
Redim transArray(10, 0)
p = 0
tmpArray = Session("Itinerary_Items")
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(Trans_ID)
Dim tmpArray, transArray(), p, SQLRoom
Redim transArray(10, 0)
p = 0
tmpArray = Session("Itinerary_Items")
Set RSRoom = Server.CreateObject("ADODB.Recordset")
For n = LBound(tmpArray, 2) to UBound(tmpArray, 2)
	If tmpArray(4, n) = "1" And tmpArray(10, n) = Trans_ID Then
		If p > 0 Then 
		Redim Preserve transArray(10, p)
		End If
		transArray(1, p) = tmpArray(1, n)
		transArray(2, p) = tmpArray(2, n)
		transArray(3, p) = tmpArray(3, n)
		transArray(4, p) = tmpArray(4, n)
		transArray(5, p) = tmpArray(5, n)
		transArray(6, p) = tmpArray(6, n)
		transArray(10, p) = Trans_ID
		p = p + 1
	End If
Next

NightCount = UBound(transArray, 2) + 1

End Function

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

Redim dateArray(0)
Set RSItem = Server.CreateObject("ADODB.Recordset")
tmpArray = Session("Itinerary_Items")
For j = LBound(tmpArray, 2) to UBound(tmpArray, 2)
If tmpArray(4, j) = "1" Then
If j > 0 Then Redim Preserve dateArray(j)
SQLItem = "Get_Inventory_by_ID '" & Int(tmpArray(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(Trans_ID)

Dim tmpArray
tmpArray = Session("Itinerary_Items")

For m = LBound(tmpArray, 2) to UBound(tmpArray, 2)
	If Int(tmpArray(4, m)) = 1 And Int(tmpArray(10, m)) = Int(Trans_ID) Then
	If Not tmpArray(2, m) = tmpArray(8, m) Then
		tmpArray(8, m) = tmpArray(8, m) + 1
		End If		
	End If
Next

Session("Itinerary_Items") = tmpArray

End Function

Function AddSpecial(Trans_ID)

Dim tmpArray
tmpArray = Session("Itinerary_Items")

For m = LBound(tmpArray, 2) to UBound(tmpArray, 2)
	If Int(tmpArray(4, m)) = 1 And Int(tmpArray(10, m)) = Int(Trans_ID) Then
	If Not tmpArray(2, m) = tmpArray(7, m) Then
		tmpArray(7, m) = tmpArray(7, m) + 1
		End If		
	End If
Next

Session("Itinerary_Items") = tmpArray

End Function

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

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

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

CheckAdultCount = AdultCount

End Function

Function GetAdultCost(Trans_ID)
Dim Cost, tmpArray, SQLCost
tmpArray = GetRooms(Trans_ID)
Set RSCost = Server.CreateObject("ADODB.Recordset")
SQLCost = "[Avante].[dbo].[Get_Extra_Adult] @Entity_ID = '" & GetEntityFromID(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(Trans_ID)
Dim tmpArray, newArray, Count, l
Count = 0
tmpArray = Session("Itinerary_Items")
For n = LBound(tmpArray, 2) to UBound(tmpArray, 2)
	If tmpArray(10, n) = Int(Trans_ID) Then Count = Count + 1
Next
If (UBound(tmpArray, 2) - Count) = -1 Then
	Redim newArray(10, 0)
Else
	Redim newArray(10, (UBound(tmpArray, 2) - Count))
	l = 0
For n = LBound(tmpArray, 2) to UBound(tmpArray, 2)
	If Not tmpArray(10, n) = Int(Trans_ID) Then
		newArray(1, l) = tmpArray(1, n)
		newArray(2, l) = tmpArray(2, n)
		newArray(3, l) = tmpArray(3, n)
		newArray(4, l) = tmpArray(4, n)
		newArray(5, l) = tmpArray(5, n)
		newArray(6, l) = tmpArray(6, n)
		newArray(7, l) = tmpArray(7, n)
		newArray(8, l) = tmpArray(8, n)
		newArray(10, l) = tmpArray(10, n)
		l = l + 1
	End If
Next
End If

Session("Itinerary_Items") = newArray

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("Adults") / Session("RoomCount") & "'"	
	RSAtt.Open SQLAtt, Conn
If Not RSAtt.EOF Then Count = Count + 1
	RSAtt.Close()
	RSAmen.MoveNext()
Loop

CheckAvailRooms = Count	
	
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
%>