<!--#include file="DateFunctions.asp"-->
<%

Function Get_State_Full (State)
	Set State=Conn.Execute("Get_State_Full @State_Abbr='" & State & "'")
	Get_State_Full = State("State_Name")
End Function

Function FormatSpecText(Text)


Replace Text, "'", "''"
Replace Text, "%23", "#"
Replace Text, "%38", "&"
Replace Text, "%27", "''"

FormatSpecText = Text

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

Function GetLodgingVars(Entity_ID, Page)
Dim SQL2, i, HTML
i = 0
HTML = ""
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_Page='" & Page & "', @Display=1"
	'Response.Write SQL2
	RS2.Open SQL2, Conn

Do Until RS2.EOF
Variable = Cstr(Trim(RS2("Variable")))
If Not Variable = "" And Not Int(RS2("Att_Group_ID")) = 7 Then
	If i > 0 Then 
		If Variable = "True" Then 
			HTML = HTML & ", " & RS2("Att_Desc") 
			i = i + 1
		Else
			HTML = HTML &  ", " & RS2("Att_Desc") & ": " & Variable
			i = i + 1
		End If
	Else
		If Variable = "True" Then 
			HTML = HTML &  RS2("Att_Desc") 
			i = i + 1
		Else
			HTML = HTML &  RS2("Att_Desc") & ": " & Variable
			i = i + 1
		End If
	End If
End If

RS2.MoveNext()
Loop

GetLodgingVars = HTML

RS2.Close()
Set RS2 = Nothing

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 FCurrency(Amount, CurType)

' l33t comments
'
'  Curtype 1 returns   xxxxx.xx format
'  Curtype 2 returns  xxxxx.xx format
'  Curtype 3 returns  xx,xxx.xx format
'  Curtype 4 returns xx,xxx.xx format
'

   If CurType = 1 Then
	Amount = Replace(Replace(FormatCurrency(Amount, 2, -1, 0, -1), "", ""), ",", "")
	FCurrency = Amount

   ElseIf CurType = 2 Then
	Amount = Replace(FormatCurrency(Amount, 2, -1, 0, -1), ",", "")
	FCurrency = Amount

   ElseIf CurType = 3 Then
	Amount = Replace(FormatCurrency(Amount, 2, -1, 0, -1), "", "")
	FCurrency = Amount

   ElseIf CurType = 4 Then
	Amount = FormatCurrency(Amount, 2, -1, 0, -1)
	FCurrency = Amount

   End If

End Function


Function Get_Att_Desc_By_Group(Group_ID, Att_ID)

	Dim SQLAtt, RSAtt
	SQLAtt = "Get_Attribute_Values @GroupID='" & Group_ID & "', @att_ID='" & Att_ID & "'"
	Set RSAtt = Conn.Execute(SQLAtt)

	If Not RSAtt.EOF Then
		Get_Att_Desc_By_Group = RSAtt("Att_Desc")
	Else
		Get_Att_Desc_By_Group = ""
	End If

End Function


Function Get_Att_Var_By_Group(Group_ID, Att_ID)

	Dim SQLAtt, RSAtt
	SQLAtt = "Get_Attribute_Values @GroupID='" & Group_ID & "', @att_ID='" & Att_ID & "'"
	Set RSAtt = Conn.Execute(SQLAtt)

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

End Function


Function RemoveHTML( strText )
    Const TAGLIST = ";!--;!DOCTYPE;A;ACRONYM;ADDRESS;APPLET;AREA;B;BASE;BASEFONT;BGSOUND;BIG;BLOCKQUOTE;BODY;BR;BUTTON;CAPTION;CENTER;CITE;CODE;COL;COLGROUP;COMMENT;DD;DEL;DFN;DIR;DIV;DL;DT;EM;EMBED;FIELDSET;FONT;FORM;FRAME;FRAMESET;HEAD;H1;H2;H3;H4;H5;H6;HR;HTML;I;IFRAME;IMG;INPUT;INS;ISINDEX;KBD;LABEL;LAYER;LAGEND;LI;LINK;LISTING;MAP;MARQUEE;MENU;META;NOBR;NOFRAMES;NOSCRIPT;OBJECT;OL;OPTION;P;PARAM;PLAINTEXT;PRE;Q;S;SAMP;SCRIPT;SELECT;SMALL;SPAN;STRIKE;STRONG;STYLE;SUB;SUP;TABLE;TBODY;TD;TEXTAREA;TFOOT;TH;THEAD;TITLE;TR;TT;U;UL;VAR;WBR;XMP;"
    Const BLOCKTAGLIST = ";APPLET;EMBED;FRAMESET;HEAD;NOFRAMES;NOSCRIPT;OBJECT;SCRIPT;STYLE;"
    
    Dim nPos1
    Dim nPos2
    Dim nPos3
    Dim strResult
    Dim strTagName
    Dim bRemove
    Dim bSearchForBlock
    
    nPos1 = InStr(strText, "<")
    Do While nPos1 > 0
        nPos2 = InStr(nPos1 + 1, strText, ">")
        If nPos2 > 0 Then
            strTagName = Mid(strText, nPos1 + 1, nPos2 - nPos1 - 1)
	    strTagName = Replace(Replace(strTagName, vbCr, " "), vbLf, " ")

            nPos3 = InStr(strTagName, " ")
            If nPos3 > 0 Then
                strTagName = Left(strTagName, nPos3 - 1)
            End If
            
            If Left(strTagName, 1) = "/" Then
                strTagName = Mid(strTagName, 2)
                bSearchForBlock = False
            Else
                bSearchForBlock = True
            End If
            
            If InStr(1, TAGLIST, ";" & strTagName & ";", vbTextCompare) > 0 Then
                bRemove = True
                If bSearchForBlock Then
                    If InStr(1, BLOCKTAGLIST, ";" & strTagName & ";", vbTextCompare) > 0 Then
                        nPos2 = Len(strText)
                        nPos3 = InStr(nPos1 + 1, strText, "</" & strTagName, vbTextCompare)
                        If nPos3 > 0 Then
                            nPos3 = InStr(nPos3 + 1, strText, ">")
                        End If
                        
                        If nPos3 > 0 Then
                            nPos2 = nPos3
                        End If
                    End If
                End If
            Else
                bRemove = False
            End If
            
            If bRemove Then
                strResult = strResult & Left(strText, nPos1 - 1)
                strText = Mid(strText, nPos2 + 1)
            Else
                strResult = strResult & Left(strText, nPos1)
                strText = Mid(strText, nPos1 + 1)
            End If
        Else
            strResult = strResult & strText
            strText = ""
        End If
        
        nPos1 = InStr(strText, "<")
    Loop
    strResult = strResult & strText
    
    RemoveHTML = strResult
End Function


Function TextLimit(strText, nChars, lbreaks)
' Usage:   strText = TextLimit(strText, 300, False)
	Dim nPos

    If lbreaks = True Then
		strText = Replace(strText, Chr(13) & Chr(10), " ")
	End If

	' Check if it's longer than limit
    	If Len(strText) > nChars And nChars > 4 Then
        	' Find the end of last whole word that we can use
        	nPos = InStrRev(Left(strText, nChars - 3), " ")

        	If nPos > 0 Then
			' Take whole words only 
            		TextLimit = Left(strText, nPos) & "..."
        	Else
			' No spaces were found - take what we can
            		TextLimit = Left(strText, nChars - 4) & " ..."
	        End If
    	Else
		' Take nChars from the text
        	TextLimit = Left(strText, nChars)
    	End If
End Function

  
Function RemoveAllSpaces(InputString)
	RemoveAllSpaces = Replace(InputString, " ", "")
End Function


'Get_Permissions @Realm_ID=19, @Group_ID=6071, @Key_ID=15   /* Finds Users for Group Given & Realm Given with key of receive resi confirmations by fax */
'Get_Permissions @Realm_ID=19, @Group_ID=6071, @Key_ID=14   /* Finds Users for Group Given & Realm Given with key of receive resi confirmations by e-mail */

'Get_Realms_By_Group @Group_ID=6071, @Realm_Type_ID=6
'Get_Merchant @Group_ID=
%>