<!--#include virtual="/includes/dbfunctions.asp" -->

<%
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 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

'Virtual Images Directory
If Image_Dir = "" Then
	Image_Dir = "/dimages/"
End If


Function Get_Image_Height_Width_By_Lodging_Item(Item_ID, Image_Type_ID)

	Dim Image_File, Image_Alt

	Dim SQLImage, RSImage
	SQLImage = "Get_Image_By_Lodging_Item @Item_ID='" & Item_ID & "', @Image_Type_ID='" & Image_Type_ID & "'"
	Set RSImage = Conn.Execute(SQLImage)

	If Not RSImage.EOF Then
		Session("Image_Height") = RSImage("Image_Height") 
		Session("Image_Width") = RSImage("Image_Width") 
	Else
		Session("Image_Width") = "300"
		Session("Image_Height") = "200"
	End If

	Get_Image_Height_Width_By_Lodging_Item = ""

End Function


Function Get_Image_By_Lodging_Item(Item_ID, Image_Type_ID, No_Str)

	Dim Image_File, Image_Alt

	Dim SQLImage, RSImage
	SQLImage = "Get_Image_By_Lodging_Item @Item_ID='" & Item_ID & "', @Image_Type_ID='" & Image_Type_ID & "'"
	Set RSImage = Conn.Execute(SQLImage)

	If Not RSImage.EOF Then
		Image_File = RSImage("Image_ID") & "." & RSImage("Image_Ext")
		Image_Alt = RSImage("Image_Alt")
	Else
		Image_File = "blank.gif"
		Image_Alt = ""
	End If

	If No_Str = True Then
		Get_Image_By_Lodging_Item = ""
	Else
		Get_Image_By_Lodging_Item = "<img src=""" & Image_Dir & Image_File & """ alt=""" & Image_Alt & """>"
	End If

End Function


Function Get_Image_By_Group(Group_ID, Image_Type_ID, No_Str)

	Dim Image_File, Image_Alt


	Dim SQLImage, RSImage
	SQLImage = "Get_Image_By_Group @Group_ID='" & Group_ID & "', @Image_Type_ID='" & Image_Type_ID & "'"
	Set RSImage = Conn.Execute(SQLImage)

	If Not RSImage.EOF Then
		Image_File = RSImage("Image_ID") & "." & RSImage("Image_Ext")
		Image_Alt = RSImage("Image_Alt")
		Get_Image_By_Group = "<img src=""" & Image_Dir & Image_File & """ alt=""" & Image_Alt & """>"
	Else
		If No_Str = True Then
			Get_Image_By_Group = ""
		Else
			Image_File = "blank.gif"
			Image_Alt = ""
			Get_Image_By_Group = "<img src=""" & Image_Dir & Image_File & """ alt=""" & Image_Alt & """>"
		End If
	End If

End Function


Function Get_Image_By_Entity(Entity_ID, Image_Type_ID, No_Str)

	Dim Image_File, Image_Alt


	Dim SQLImage, RSImage
	SQLImage = "Get_Image_By_Entity @Entity_ID='" & Entity_ID & "', @Image_Type_ID='" & Image_Type_ID & "'"
	Set RSImage = Conn.Execute(SQLImage)

	If Not RSImage.EOF Then
		Image_File = RSImage("Image_ID") & "." & RSImage("Image_Ext")
		Image_Alt = RSImage("Image_Alt")
		Get_Image_By_Entity = "<img src=""" & Image_Dir & Image_File & """ alt=""" & Image_Alt & """>"
	Else
		If No_Str = True Then
			Get_Image_By_Entity = ""
		Else
			Image_File = "blank.gif"
			Image_Alt = ""
			Get_Image_By_Entity = "<img src=""" & Image_Dir & Image_File & """ alt=""" & Image_Alt & """>"
		End If			
	End If

End Function


Function Get_Image_By_Entity_Or_Brand (Entity_ID, Image_Type_ID, No_Str)

	Dim Image_File, Image_Alt


	Dim SQLImage, RSImage
	SQLImage = "Get_Image_By_Entity @Entity_ID='" & Entity_ID & "', @Image_Type_ID='" & Image_Type_ID & "'"
	Set RSImage = Conn.Execute(SQLImage)

	If Not RSImage.EOF Then
		Image_File = RSImage("Image_ID") & "." & RSImage("Image_Ext")
		Image_Alt = RSImage("Image_Alt")
		Get_Image_By_Entity_Or_Brand = "<img src=""" & Image_Dir & Image_File &	""" alt=""" & Image_Alt & """ align=""center"">"
	Else
		SQLImage = "Get_Image_Brand_By_Entity @Entity_ID='" & Entity_ID & "', @Image_Type_ID='" & Image_Type_ID & "'"
		Set RSImage = Conn.Execute(SQLImage)
	
		If Not RSImage.EOF Then
			Image_File = RSImage("Image_ID") & "." & RSImage("Image_Ext")
			Image_Alt = RSImage("Image_Alt")
		Else
			Image_File = "blank.gif"
			Image_Alt = ""
		End If
	
		If No_Str = True Then
			Get_Image_By_Entity_Or_Brand = ""
		Else
			Get_Image_By_Entity_Or_Brand = "<img src=""" & Image_Dir & Image_File &	""" alt=""" & Image_Alt & """>"
		End If
	End If

End Function


Function Get_Image_By_Group_Or_Brand (Group_ID, Image_Type_ID, No_Str)

	Dim Image_File, Image_Alt


	Dim SQLImage, RSImage
	SQLImage = "Get_Image_By_Group @Group_ID='" & Group_ID & "', @Image_Type_ID='" & Image_Type_ID & "'"
	Set RSImage = Conn.Execute(SQLImage)

	If Not RSImage.EOF Then
		Image_File = RSImage("Image_ID") & "." & RSImage("Image_Ext")
		Image_Alt = RSImage("Image_Alt")
		Get_Image_By_Group_Or_Brand = "<img src=""" & Image_Dir & Image_File &	""" alt=""" & Image_Alt & """>"
	Else
		SQLImage = "Get_Image_Brand_By_Group @Group_ID='" & Group_ID & "', @Image_Type_ID='" & Image_Type_ID & "'"
		Set RSImage = Conn.Execute(SQLImage)
	
		If Not RSImage.EOF Then
			Image_File = RSImage("Image_ID") & "." & RSImage("Image_Ext")
			Image_Alt = RSImage("Image_Alt")
		Else
			Image_File = "blank.gif"
			Image_Alt = ""
		End If
	
		If No_Str = True Then
			Get_Image_By_Group_Or_Brand = ""
		Else
			Get_Image_By_Group_Or_Brand = "<img src=""" & Image_Dir & Image_File &	""" alt=""" & Image_Alt & """>"
		End If
		
	End If


End Function



Function Get_Image_Brand_By_Group(Group_ID, Image_Type_ID, No_Str)

	Dim Image_File, Image_Alt


	Dim SQLImage, RSImage
	SQLImage = "Get_Image_Brand_By_Group @Group_ID='" & Group_ID & "', @Image_Type_ID='" & Image_Type_ID & "'"
	Set RSImage = Conn.Execute(SQLImage)

	If Not RSImage.EOF Then
		Image_File = RSImage("Image_ID") & "." & RSImage("Image_Ext")
		Image_Alt = RSImage("Image_Alt")
		Get_Image_Brand_By_Group = "<img src=""" & Image_Dir & Image_File &	""" alt=""" & Image_Alt & """>"
	Else
		SQLImage = "Get_Image_By_Group @Group_ID='" & Group_ID & "', @Image_Type_ID='" & Image_Type_ID & "'"
		Set RSImage = Conn.Execute(SQLImage)
	
		If Not RSImage.EOF Then
			Image_File = RSImage("Image_ID") & "." & RSImage("Image_Ext")
			Image_Alt = RSImage("Image_Alt")

			If No_Str = True Then
				Get_Image_Brand_By_Group = Image_Dir & Image_File
			Else
				Get_Image_Brand_By_Group = "<img src=""" & Image_Dir & Image_File &	""" alt=""" & Image_Alt & """>"
			End If

		Else
			Image_File = "blank.gif"
			Image_Alt = ""
			
			If No_Str = True Then
				Get_Image_Brand_By_Group = ""
			Else
				Get_Image_Brand_By_Group = "<img src=""" & Image_Dir & Image_File &	""" alt=""" & Image_Alt & """>"
			End If
		End If

	End If

End Function


Function Get_Image_Brand_By_Entity(Entity_ID, Image_Type_ID, No_Str)

	Dim Image_File, Image_Alt


	Dim SQLImage, RSImage
	SQLImage = "Get_Image_Brand_By_Entity @Entity_ID='" & Entity_ID & "', @Image_Type_ID='" & Image_Type_ID & "'"
	Set RSImage = Conn.Execute(SQLImage)

	If Not RSImage.EOF Then
		Image_File = RSImage("Image_ID") & "." & RSImage("Image_Ext")
		Image_Alt = RSImage("Image_Alt")
		Get_Image_Brand_By_Entity = "<img src=""" & Image_Dir & Image_File &	""" alt=""" & Image_Alt & """>"
	Else
		SQLImage = "Get_Image_By_Entity @Entity_ID='" & Entity_ID & "', @Image_Type_ID='" & Image_Type_ID & "'"
		Set RSImage = Conn.Execute(SQLImage)
	
		If Not RSImage.EOF Then
			Image_File = RSImage("Image_ID") & "." & RSImage("Image_Ext")
			Image_Alt = RSImage("Image_Alt")

			If No_Str = True Then
				Get_Image_Brand_By_Entity = Image_Dir & Image_File
			Else
				Get_Image_Brand_By_Entity = "<img src=""" & Image_Dir & Image_File &	""" alt=""" & Image_Alt & """>"
			End If

		Else
			Image_File = "blank.gif"
			Image_Alt = ""
			
			If No_Str = True Then
				Get_Image_Brand_By_Entity = ""
			Else
				Get_Image_Brand_By_Entity = "<img src=""" & Image_Dir & Image_File &	""" alt=""" & Image_Alt & """>"
			End If
		End If
		
	End If

End Function


Function Get_Image_By_Event(Event_ID, Image_Type_ID, No_Str)

	Dim Image_File, Image_Alt


	Dim SQLImage, RSImage
	SQLImage = "Get_Image_By_Event @Event_ID='" & Event_ID & "', @Image_Type_ID='" & Image_Type_ID & "'"
	Set RSImage = Conn.Execute(SQLImage)

	If Not RSImage.EOF Then
		Image_File = RSImage("Image_ID") & "." & RSImage("Image_Ext")
		Image_Alt = RSImage("Image_Alt")
	Else
		Image_File = "blank.gif"
		Image_Alt = ""
	End If

	If No_Str = True Then
		Get_Image_By_Event = ""
	Else
		Get_Image_By_Event = "<img src=""" & Image_Dir & Image_File &	""" alt=""" & Image_Alt & """>"
	End If

End Function


Function Get_Image_Sponsor_By_Event(Event_ID, Image_Type_ID, No_Str)

	Dim Image_File, Image_Alt


	Dim SQLImage, RSImage
	SQLImage = "Get_Image_Sponsor_By_Event @Event_ID='" & Event_ID & "', @Image_Type_ID='" & Image_Type_ID & "'"
	Set RSImage = Conn.Execute(SQLImage)

	If Not RSImage.EOF Then
		Image_File = RSImage("Image_ID") & "." & RSImage("Image_Ext")
		Image_Alt = RSImage("Image_Alt")
	Else
		Image_File = "blank.gif"
		Image_Alt = ""
	End If

	If No_Str = True Then
		Get_Image_Sponsor_By_Event = ""
	Else
		Get_Image_Sponsor_By_Event = "<img src=""" & Image_Dir & Image_File &	""" alt=""" & Image_Alt & """>"
	End If

End Function


Function Get_Destination_Image(Dest_ID, Image_Type_ID, No_Str)

	Dim Image_File, Image_Alt

	Dim SQLImage, RSImage
	SQLImage = "Get_Destination_Image @Dest_ID='" & Dest_ID & "', @Image_Type_ID='" & Image_Type_ID & "'"
	Set RSImage = Conn.Execute(SQLImage)

	If Not RSImage.EOF Then
		Image_File = RSImage("Image_ID") & "." & RSImage("Image_Ext")
		Image_Alt = RSImage("Image_Alt")
		If No_Str = True Then
			Get_Destination_Image = Image_Dir & Image_File
		Else
			Get_Destination_Image = "<img src=""" & Image_Dir & Image_File & """ alt=""" & Image_Alt & """>"
		End If
	Else
		If No_Str = True Then
			Get_Destination_Image = ""
		Else
			Image_File = "blank.gif"
			Image_Alt = ""
			Get_Destination_Image = "<img src=""" & Image_Dir & Image_File & """ alt=""" & Image_Alt & """>"
		End If
	End If
End Function

Function PCase(strInput)
    Dim iPosition 
    Dim iSpace 
    Dim strOutput 

    iPosition = 1

    Do While InStr(iPosition, strInput, " ", 1) <> 0
            iSpace = InStr(iPosition, strInput, " ", 1)
            strOutput = strOutput & UCase(Mid(strInput, iPosition, 1))
            strOutput = strOutput & LCase(Mid(strInput, iPosition + 1, iSpace - iPosition))
            iPosition = iSpace + 1
    Loop

    strOutput = strOutput & UCase(Mid(strInput, iPosition, 1))
    strOutput = strOutput & LCase(Mid(strInput, iPosition + 1))

    PCase = strOutput
End Function

Function GetCostByTrans(Itinerary_ID, Trans_ID)
Dim Total, sqlTrans
Total = 0

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

sqlTrans = "Select Sum(Unit_Price * Quantity) as Cost From Itinerary_Detail Where Itinerary_ID = '" & Itinerary_ID & "' "
sqlTrans = sqlTrans & "And Web_Trans_ID = '" & Trans_ID & "'"

rsTrans.Open sqlTrans, Conn

If Not rsTRans.EOF Then
GetCostByTrans = rsTrans("Cost")
Else
GetCostByTrans = 0
End If

rsTrans.Close()
Set rsTrans = Nothing

End Function

Function GetCost(Itinerary_ID)
Dim Total, sqlTrans
Total = 0

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

sqlTrans = "Select Sum(Unit_Price * Quantity) as Cost From Itinerary_Detail Where Itinerary_ID = '" & Itinerary_ID & "'"

rsTrans.Open sqlTrans, Conn

If Not rsTRans.EOF Then
GetCost = rsTrans("Cost")
Else
GetCost = 0
End If

rsTrans.Close()
Set rsTrans = Nothing

End Function

Function GetTransCount(Itinerary_ID)
Dim sqlTrans
Set rsTrans = server.CreateObject("ADODB.Recordset")

sqlTrans = "Select Max(Web_Trans_ID) as TransCount From Itinerary_Detail Where Itinerary_ID = '" & Itinerary_ID & "'"

rsTrans.Open sqlTrans, Conn

If Not rsTrans.EOF Then
GetTransCount = rsTrans("TransCount")
Else
GetTransCount = 0
End If

rsTrans.Close()
Set rsTrans = Nothing

End Function

Function RoomType(Itinerary_ID, Trans_ID, Entity_ID)
Dim SQLRoom, SQLTrans

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

sqlTrans = "Select Top 1 * From Itinerary_Detail Where Itinerary_ID = '" & Itinerary_ID & "' And Web_Trans_ID = '" & Trans_ID & "'"
rsTrans.Open sqlTrans ,conn



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 "
SQLRoom = SQLRoom & "ILL.Inventory_List_ID = '" & rsTrans("Product_ID") & "' "
SQLRoom = SQLRoom & "Order By ATT.Att_Desc_Detail"
RSRoom.Open SQLRoom, Conn

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

rsTrans.Close()
Set rsTrans = Nothing

RSRoom.Close()
Set RSRoom = Nothing

End Function

Function LodgingTax(Itinerary_ID) 'Get total tax for Lodging Items
	Dim SQLTax, TotalTax, sqlItem
	Set RSTax = Server.CreateObject("ADODB.Recordset")
	TotalTax = 0
	Set rsItem = Server.CreateObject("ADODB.Recordset")
	sqlItem = "Select * From Itinerary_Detail Where Itinerary_ID = '" & Itinerary_ID & "'"
	rsItem.Open sqlItem, Conn

	Do While Not rsItem.EOF
		'If rsItem("Product_Type") = "1" Then
			SQLTax = "Get_Tax_Costs_Lodging '" & Int(rsItem("Product_ID")) & "', '" & CCur(rsItem("Unit_Price") * rsItem("Quantity")) & "'"
			'SQLTax = "Get_Tax_Costs_Lodging '52524', '158'"
			RSTax.Open SQLTax, Conn
			If Not rsTax.EOF Then
			TotalTax = TotalTax + RSTax("Total_Tax")
			End If
			RSTax.Close()
		'End If
		rsItem.MoveNext()
	Loop

	Set RSTax = Nothing
	
If TotalTax = 0 Then
	LodgingTax = 0
Else
	LodgingTax = FormatNumber(TotalTax, 2)
End If

End Function

Function CartTotalwTax(Itinerary_ID) 'Get Total Cost for Itinerary

CartTotalwTax = GetCost(Itinerary_ID) + LodgingTax(Itinerary_ID)

End Function

Function GetCardType(cc)
Dim CardType

If Not Trim(cc) = "" Then
	If Len(cc) = 16 Or Len(cc) = 13 Then
		If Left(cc, 1) = 4 Then CardType = 1
	End If

	If (Len(cc) = 15 And Int(Left(cc, 1)) = 5 And (Int(Mid(cc, 2, 1)) >= 1 Or Int(Mid(cc, 2, 1)) <= 5)) Then
		CardType = 2
	End If

	If (Len(cc) = 15 And Int(Left(cc, 1)) = 3 And (Int(Mid(cc, 2, 1)) = 4 Or Int(Mid(cc, 2, 1)) = 7)) Then
		CardType = 3
	End If

	If Len(cc) = 16 And Int(Left(cc, 4)) = 6011 Then
		CardType = 4
	End If
End If

GetCardType = CardType

End Function

Function Get_Attribute_Variable (Entity_ID, Att_ID)

	Set RS2 = Server.CreateObject("ADODB.Recordset")
	'SQL2 = "Select * from Entity E inner join (Group_Entity_Map GEM inner join (Att_Group_Map AGM Inner Join Attribute_Type A "
	'SQL2 = SQL2 & "on AGM.ATT_ID = A.ATT_ID) on GEM.Group_ID = AGM.Group_ID)	on E.Entity_ID = GEM.Entity_ID "
	'SQL2 = SQL2 & "Where E.Entity_ID = '" & Request.QueryString("Entity_ID") & "' And Att_Page = '" & Page & "' "
	SQL2 = "Get_Attribute_Values @Entity_ID = '" & Entity_ID & "', @Att_ID='" & Att_ID & "', @Display=1"
	'Response.Write SQL2
	RS2.Open SQL2, Conn

	If Not RS2.EOF Then
		Variable = Cstr(Trim(RS2("Variable")))
	Else
		Variable = ""
	End If

	Get_Attribute_Variable = Variable

End Function

%>
