andrewhthomas
9/25/2012 - 4:35 PM

BASArchive - Bible Functions

BASArchive - Bible Functions

function OpenBibleRef(sBibleRef) {

	BibleRef = window.open(sBibleRef, '', 'width=600,height=400,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no');
	
	BibleRef.focus();
	
	/*setTimeout("BibleRef.scroll(0, "+scroll+")",1000);*/
	
		if (BibleRef.opener == null) BibleRef.opener = window; 
	BibleRef.opener.name = "opener";

}
<%@ Language=VBScript %>
<% Option Explicit %>
<!--#include virtual="bswb.inc.vb"-->
<%
Dim Browser
Dim Version
Dim MyBrow
If Application("bBrowserDifferentiation") = "True" Then
	Set MyBrow = Server.CreateObject("MSWC.BrowserType")
	Browser = MyBrow.browser
	Version = MyBrow.version
	If Browser <> "IE" And Browser <> "Netscape" Then Response.Redirect Application("ArchivePath") & Application("BrowserPage")
	Set MyBrow = Nothing
Else 
	Browser = "IE"
	Version = 6
End If

%>
<html>
<head>
<%
Dim VerseIDMin
Dim VerseIDMax

If Session("Login") = False or Session("Login") = True Then

If Request.QueryString("VerseIDMin") = "" and Request.QueryString("VerseIDMax") <> "" Then
	VerseIDMin = clng(Request.QueryString("VerseIDMax"))
Else
	VerseIDMin = clng(Request.QueryString("VerseIDMin"))
End If
If Request.QueryString("VerseIDMax") = "" and Request.QueryString("VerseIDMin") <> "" Then
	VerseIDMax = clng(Request.QueryString("VerseIDMin"))
Else
	VerseIDMax = clng(Request.QueryString("VerseIDMax"))
End If
%>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<title><% Response.Write(VerseNameReHyphenation(VerseName(VerseIDMin), VerseName(VerseIDMax))) %></title>
<meta name="generator" content="text pad">
<meta name="description" content="The Biblical Archaeology Society publishes Biblical Archaeology Review, Bible Review, and Archaeology Odyssey, and educates the public about archaeology and the Bible through books, videos, and tours.">
<meta name="keywords" content="archaeology,archeology,archaeologist,archeologist,archaeology magazine,magazine,archeological,news,excavation,excavations,dig,archaeological,digs,archaeological dig,anthropology,anthro,antiquity,artifacts,discovery,discoveries,archaeology books,books on archaeology,past cultures,prehistory,history,science,ancient,past,digging,finds,travel,dead sea scrolls,bible,bible study">
<link rel=stylesheet href="bswbstyles<% If Browser = "Netscape" and Version < 6 Then Response.Write "ns" %>.css" type="text/css">
<SCRIPT LANGUAGE="JavaScript" SRC="bswbJavaScriptFunctions.js"></SCRIPT>
</head>
<body bgcolor="#FFFFFF" link="#993300" vlink="#800080" alink="#993300" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table>
<tr><td>

<%
Response.Write("<div id=" & Chr(34) & "bibleverse" & Chr(34) & ">")

GetBiblePopup VerseIDMin, VerseIDMax

Response.Write("</div>")

Else 
	Response.Redirect Application("ArchivePath")
End If

%>
</td></tr>
</table>
<!--#include file = "ClickTracks.js"-->
</body>
</html>
function xbrSub(sInput)
  'DESCRIPTION: Translates and parses LGM xbr's in HTML document to references to Bible Content.
  'INPUTS:
      'sInput: The inputed text being operated upon.
  'OUTPUT: Modified HTML.
  'CALLED BY:
    'abbrevSub
    'imagePageSub
    'authInfoSub
    'textSub
    'PrintSub
    'frSub
    'noteSub
  'Variable Definition
  Dim objReggie
  Dim objMatches
  Dim objMatch
  Dim objConn
  Dim objCmd
  Dim objParams
  Dim sReplace
  'Object Definition Connection and Command Created.
  Set objConn = Server.CreateObject("ADODB.Connection")
  objConn.Open Application("ConnectionString")
  Set objCmd = Server.CreateObject("ADODB.Command")
  Set objCmd.ActiveConnection = objConn
  'Regular Expression Object initialized.
  Set objReggie = New RegExp
  objReggie.Pattern = "</xbr>"
  objReggie.Global = True
  objReggie.Multiline = True
  'Replace all </xbr> tags with </a> tags.
  sInput = objReggie.Replace(sInput, "</a>")
  'Hyphen splitting procedures.  Most of the procedures for dealing with hyphenation will not be needed.  Although they
  'will function within the canonical bible.
  'Break hyphenation on xbr's of the pattern Book Chapter:Verse-Book Chapter.
  objReggie.Pattern = "<xbr t=" & Chr(34) & Application("BooksRegEx") & " ([1-9][^>:]*):([1-9][^>\-]*)-([1-9A-Z][^1-9 ]*|[1-9A-Za-z]{1,3} [^1-9 ]+) ([1-9][^>:" & Chr(34) & "]*)" & Chr(34) & ">"
  sInput = objReggie.Replace(sInput, "<xbr t=" & Chr(34) & "$1 $2:$3" & Chr(34) & ">§<xbr t=" & Chr(34) & "$4 $5:1" & Chr(34) & ">¥")
  'Break hyphenation of xbr's of the pattern Book Chapter.
  objReggie.Pattern = "<xbr t=" & Chr(34) & Application("BooksRegEx") & " ([1-9][^>:\-" & Chr(34) & "]*)" & Chr(34) & ">"
  sInput = objReggie.Replace(sInput, "<xbr t=" & Chr(34) & "$1 $2:1" & Chr(34) & ">§<xbr t=" & Chr(34) & "$1 $2:1" & Chr(34) & ">¥")
  'Break hyphenation of xbr's of the pattern Book Chapter-Book Chapter
  objReggie.Pattern = "<xbr t=" & Chr(34) & Application("BooksRegEx") & " ([1-9][^>:\-]*)-([1-9A-Z][^1-9 ]*|[1-9A-Za-z]{1,3} [^1-9 ]+) ([1-9][^>:" & Chr(34) & "]*)" & Chr(34) & ">"
  sInput = objReggie.Replace(sInput, "<xbr t=" & Chr(34) & "$1 $2:1" & Chr(34) & ">§<xbr t=" & Chr(34) & "$3 $4:1" & Chr(34) & ">¥")
  'Break hyphenation on xbr's of the pattern Book Chapter-Book Chapter:Verse.
  objReggie.Pattern = "<xbr t=" & Chr(34) & Application("BooksRegEx") & " ([1-9][^>:\-]*)-([1-9A-Z][^1-9 ]*|[1-9A-Za-z]{1,3} [^1-9 ]+) ([1-9][^>:]*):([1-9][^>" & Chr(34) & "]*)" & Chr(34) & ">"
  sInput = objReggie.Replace(sInput, "<xbr t=" & Chr(34) & "$1 $2:1" & Chr(34) & ">§<xbr t=" & Chr(34) & "$3 $4:$5" & Chr(34) & ">")
  'Break hyphenation of xbr's of the pattern Book Chapter-Chapter
  objReggie.Pattern = "<xbr t=" & Chr(34) & Application("BooksRegEx") & " ([1-9][^>:\-]*)-([1-9][^>A-Za-z:" & Chr(34) & "]*)" & Chr(34) & ">"
  sInput = objReggie.Replace(sInput, "<xbr t=" & Chr(34) & "$1 $2:1" & Chr(34) & ">§<xbr t=" & Chr(34) & "$1 $3:1" & Chr(34) & ">¥")
  'Break hyphenation of xbr's of the pattern Book Chapter:Verse-Book Chapter:Verse
  objReggie.Pattern = "<xbr t=" & Chr(34) & Application("BooksRegEx") & " ([1-9][^>:]*):([1-9][^>\-]*)-([1-9A-Z][^1-9 ]*|[1-9A-Za-z]{1,3} [^1-9 ]+) ([1-9][^>:]*):([1-9][^>" & Chr(34) & "]*)" & Chr(34) & ">"
  sInput = objReggie.Replace(sInput, "<xbr t=" & Chr(34) & "$1 $2:$3" & Chr(34) & ">§<xbr t=" & Chr(34) & "$4 $5:$6" & Chr(34) & ">")
  'Break hyphenation of xbr's of the pattern Book Chapter:Verse-Chapter:Verse
  objReggie.Pattern = "<xbr t=" & Chr(34) & Application("BooksRegEx") & " ([1-9][^>:]*):([1-9][^>\-]*)-([1-9][^>A-Za-z:]*):([1-9][^>" & Chr(34) & "]*)" & Chr(34) & ">"
  sInput = objReggie.Replace(sInput, "<xbr t=" & Chr(34) & "$1 $2:$3" & Chr(34) & ">§<xbr t=" & Chr(34) & "$1 $4:$5" & Chr(34) & ">")
  'Break hyphenation of xbr's of the pattern Book Chapter:Verse-Verse
  objReggie.Pattern = "<xbr t=" & Chr(34) & Application("BooksRegEx") & " ([1-9][^>:]*):([1-9][^>\-]*)-([1-9][^> " & Chr(34) & ":]*)" & Chr(34) & ">"
  sInput = objReggie.Replace(sInput, "<xbr t=" & Chr(34) & "$1 $2:$3" & Chr(34) & ">§<xbr t=" & Chr(34) & "$1 $2:$4" & Chr(34) & ">")
  'Break hyphenation of xbr tags of the pattern Book Chapter-Chapter:Verse
  objReggie.Pattern = "<xbr t=" & Chr(34) & Application("BooksRegEx") & " ([1-9][^>:\-]*)-([1-9][^>A-Za-z:]*):([1-9][^>" & Chr(34) & "]*)" & Chr(34) & ">"
  sInput = objReggie.Replace(sInput, "<xbr t=" & Chr(34) & "$1 $2:1" & Chr(34) & ">§<xbr t=" & Chr(34) & "$1 $3:$4" & Chr(34) & ">")
  'Set regular expression pattern to find all xbr tags.
  objReggie.Pattern = "<xbr[^>]*>"
  'Set command to the Stored Procedure bswbXBRtoVerseID, which, unsurprisingly, converts XBR's to VerseID's
  objCmd.CommandText = "bswb.dbo.bswbXBRtoVerseID"
  objCmd.CommandType = adCmdStoredProc
  Set objParams = objCmd.Parameters
  objParams.Append objCmd.CreateParameter ("@BookName", adVarChar, adParamInput, 50)
  objParams.Append objCmd.CreateParameter ("@Chapter", adInteger, adParamInput)
  objParams.Append objCmd.CreateParameter ("@Verse", adInteger, adParamInput)
  objParams.Append objCmd.CreateParameter ("@output", adInteger, adParamOutput)
  'Fill the object objMatches with the Match collection holding all xbr tags in sInput.
  Set objMatches = objReggie.Execute(sInput)
  for each objMatch in objMatches
    'Cycling through the list of matches, extract the BookName, Chapter, and Verse from each xbr using the
    'functions of the same name.  It uses these values as the pass through inputs for the above referenced
    'Stored Procedure and places its output, a numeric ID, in xbr tag in place of the LGM t attribute string.
    objCmd("@BookName") = trim(BookName(objMatch.Value))
    objCmd("@Chapter") = Chapter(objMatch.Value)
    objCmd("@Verse") = Verse(objMatch.Value)
    objCmd.Execute
    sReplace = "<xbr" & objCmd("@output") & ">"
    sInput = Replace(sInput, objMatch.Value, sReplace)
  next
  'Reset command to GetChapterMax and set Regular Expression pattern to find all implicit
  'Chapter endings.  (Xbrs that did not give an end verse and default to the last verse in the chapter,
  'which were marked with ¥ in the above hyphen splitting procedures.)
  Set objParams = Nothing
  Set objCmd = Nothing
  objReggie.Pattern = "§<xbr[^>]*>¥"
  Set objCmd = Server.CreateObject("ADODB.Command")
  Set objCmd.ActiveConnection = objConn
  objCmd.CommandText = "bswb.dbo.bswbGetChapterMax"
  objCmd.CommandType = adCmdStoredProc
  Set objParams = objCmd.Parameters
  objParams.Append objCmd.CreateParameter ("@input", adInteger, adParamInput)
  objParams.Append objCmd.CreateParameter ("@output", adInteger, adParamOutput)
  Set objMatches = objReggie.Execute(sInput)
  for each objMatch in objMatches
    'Cycling through all implicit chapter endings and sets them.
    objCmd("@input") = clng(Right(Left(objMatch.Value, objMatch.Length - 2), objMatch.Length - 7))
    objCmd.Execute
    sReplace = "§" & "<xbr" & objCmd("@output") & ">"
    sInput = Replace(sInput, objMatch.Value, sReplace)
  next
  'Deallocate all unneeded objects.
  Set objParams = Nothing
  Set objCmd = Nothing
  objConn.Close
  Set objConn = Nothing
  Set objMatch = Nothing
  Set objMatches = Nothing
  'Replace all formerly hyphenated xbr tags with a a link opening the Bible reference popup page.
  objReggie.Pattern = "<xbr([^>]*)>§<xbr([^>]*)>"
  sInput = objReggie.Replace(sInput, "<a class=" & chr(34) &  "bibleref" & chr(34) &  " href=javascript:OpenBibleRef(" & chr(34) &  Application("ArchivePath") & Application("XBRPage") & "?VerseIDMin=$1" & chr(38) & "VerseIDMax=$2" & chr(38) & chr(34) &  ")>")
  'Replace all remaining single verse xbr's with link as above, only setting the VerseIDMax and VerseIDMin parameters
  'to the single verse.
  objReggie.Pattern = "<xbr([^>]*)>"
  sInput = objReggie.Replace(sInput, "<a class=" & chr(34) &  "bibleref" & chr(34) &  " href=javascript:OpenBibleRef(" & chr(34) &  Application("ArchivePath") & Application("XBRPage") & "?VerseIDMin=$1" & chr(38) & "VerseIDMax=$1" & chr(38) & chr(34) &  ")>")
  'Clean up
  Set objReggie = Nothing
  'Return finished HTML text.
  xbrSub = sInput
End Function

function GetChapterEnd(iXBRIn)
  'DESCRIPTION: Takes a VerseID as its input and returns the VerseID that ends the input VerseID's Chapter
  'INPUTS: DB VerseID
  'OUTPUT: DBVerseID (Integer)
  'CALLED BY:
    'Nothing?
  Dim objConn
  Dim objCmd
  Dim objParams
  Set objConn = Server.CreateObject("ADODB.Connection")
  objConn.Open Application("ConnectionString")
  Set objCmd = Server.CreateObject("ADODB.Command")
  Set objCmd.ActiveConnection = objConn
  objCmd.CommandText = "bswb.dbo.bswbGetChapterMax"
  objCmd.CommandType = adCmdStoredProc
  Set objParams = objCmd.Parameters
  objParams.Append objCmd.CreateParameter ("@input", adInteger, adParamInput)
  objParams.Append objCmd.CreateParameter ("@output", adInteger, adParamOutput)
  objCmd("@input") = iXBRIn
  objCmd.Execute
  GetChapterEnd =  objCmd("@output")
  Set objParams = objCmd.Parameters
  Set objParams = Nothing
  Set objCmd = Nothing
  objConn.Close
  Set objConn = Nothing

end function

sub GetBiblePopup (iXBRMin, iXBRMax)
  'DESCRIPTION: Writes the content of the Application("XBRPage").
  'INPUTS:
    'iXBRMin: The DB VerseID of the first verse.
    'iXBRMax: The DB VerseID of the last verse.
  'OUTPUT: Writes the HTML text to the Response object.
  'CALLED BY:
    'Application("XBRPage")
  Dim objConn
  Dim objRS
  Dim objCmd
  Dim objParams
  Dim sChapter
  Dim sVerse
  Dim sPointer
  Set objConn = Server.CreateObject("ADODB.Connection")
  objConn.Open Application("ConnectionString")
  Set objCmd = Server.CreateObject("ADODB.Command")
  Set objCmd.ActiveConnection = objConn
  objCmd.CommandText = "bswb.dbo.bswbVerseRange"
  objCmd.CommandType = adCmdStoredProc
  Set objParams = objCmd.Parameters
  objParams.Append objCmd.CreateParameter ("@VerseIDMin", adInteger, adParamInput)
  objParams.Append objCmd.CreateParameter ("@VerseIDMax", adInteger, adParamInput)
  objCmd("@VerseIDMin") = iXBRMin
  objCmd("@VerseIDMax") = iXBRMax
  Set objRS = objCmd.Execute
  'First we print the Reference so that the person knows what their looking at.
  Response.Write("<div class=" & chr(34) &  "VerseContext" & chr(34) &  ">" & VerseNameReHyphenation(VerseName(iXBRMin), VerseName(iXBRMax))  & "</div>" & vbNewLine)
  If objRS.EOF = False Then
    'Writes the book name.
    'Response.Write("<div class=" & chr(34) &  "bookheader" & chr(34) &  ">" & objRS("Book")  & "</div>" & vbNewLine)
    do while not objRS.EOF
      sChapter = objRS("Chapter")
      'Writes the Chapter Header.
      Response.Write ("<div class=" & chr(34) &  "chapterheader" & chr(34) &  ">" & sChapter & "</div>" & vbNewLine)
      do while ((objRS("Chapter") = sChapter))
          'Fills in the Verse text.
          If objRS("Pointer") = 1 Then
            sPointer = "<font size=4 color=" & chr(34) &  "#a52a2a" & chr(34) &  "><b>&#187;</b></font> "
          Else
            sPointer = ""
          End If
          Response.Write ("<div class=" & chr(34) &  "versetext" & chr(34) &  ">" & sPointer & "(" & objRS("Verse") & ") " & objRS("VerseText") & "</div>" & vbNewLine)
          objRS.MoveNext
          If objRS.EOF = True Then Exit do
      loop
    loop
  End If
  objRS.Close
  Set objRS = Nothing
  Set objParams = Nothing
  Set objCmd = Nothing
  objConn.Close
  Set objConn = Nothing
End Sub

Function BookName(sInput)
  'DESCRIPTION: Pulls the Book Abbreviation from an XBR tag.
  'INPUTS:
    'sInput: The inputed text being operated upon. (In this case an XBR tag.)
  'OUTPUT: A string containing only the Book name Abbreviations.
  'CALLED BY:
    'xbrSub
  'First remove the first 8 characters, <xbr t="

  Dim objReggie

  Set objReggie = New RegExp
  objReggie.Pattern = "<xbr t=" & chr(34) & Application("BooksRegEx") &  " ([1-9][^>:]*):([1-9][^>\-]*)" & chr(34) & ">"
  objReggie.Global = False
  objReggie.Multiline = False
  objReggie.IgnoreCase = True
  BookName = objReggie.Replace(sInput, "$1")

End Function

Function Chapter(sInput)
  'DESCRIPTION: Pulls the Chapter Number from an XBR.
  'INPUTS:
    'sInput: The inputed text being operated upon. (In this case an XBR tag.)
  'OUTPUT: An integer containing the Chapter number.
  'CALLED BY:
    'xbrSub
  'First remove the first 8 characters, <xbr t="

  Dim objReggie

  Set objReggie = New RegExp
  objReggie.Pattern = "<xbr t=" & chr(34) & Application("BooksRegEx") &  " ([1-9][^>:]*):([1-9][^>\-]*)" & chr(34) & ">"
  objReggie.Global = False
  objReggie.Multiline = False
  objReggie.IgnoreCase = True
  Chapter = cint(objReggie.Replace(sInput, "$2"))

End Function

Function Verse(sInput)
  'DESCRIPTION: Pulls the Verse Number from an XBR.
  'INPUTS:
    'sInput: The inputed text being operated upon. (In this case an XBR tag.)
  'OUTPUT: An integer containing the Verse Number.
  'CALLED BY:
    'xbrSub
  'Kill everything to the Left of the colon.

  Dim objReggie

  Set objReggie = New RegExp
  objReggie.Pattern = "<xbr t=" & chr(34) & Application("BooksRegEx") &  " ([1-9][^>:]*):([1-9][^>\-]*)" & chr(34) & ">"
  objReggie.Global = False
  objReggie.Multiline = False
  objReggie.IgnoreCase = True
  Verse = cint(objReggie.Replace(sInput, "$3"))

End Function