Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for birdname.hta

(view source code of birdname.hta as plain text)

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2. <html>
  3. <head>
  4. <title>BirdName</title>
  5.  
  6. <HTA:APPLICATION
  7.   APPLICATIONNAME="BirdName"
  8.   ID="BirdName"
  9.   VERSION="2.13"
  10.   SCROLL="auto"
  11.   SINGLEINSTANCE="yes"/>
  12.  
  13. <style type="text/css">
  1. .Center
  2. {
  3. 	text-align: center;
  4. 	margin-left: auto;
  5. 	margin-right: auto;
  6. }
  7.  
  8. .Group
  9. {
  10. 	border: 1px solid gray;
  11. 	padding: 12px 25px 12px 25px;
  12. }
  13.  
  14. .Hidden
  15. {
  16. 	visibility: hidden;
  17. }
  18.  
  19. a
  20. {
  21. 	color: yellow;
  22. }
  23.  
  24. body
  25. {
  26. 	font: 12pt arial,sans-serif;
  27. 	color:white;
  28. 	background-color: #606060;
  29. 	filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr='#000000', EndColorStr='#606060');
  30. 	height: 100%;
  31. 	padding: 15px;
  32. 	margin: 0;
  33. }
  34.  
  35. input.Button, span.Button
  36. {
  37. 	width: 12em;
  38. 	height: 2em;
  39. }
  40.  
  41. table
  42. {
  43. 	border: 0 none;
  44. 	width: 90%;
  45. }
  46.  
  47. td.Content
  48. {
  49. 	width: 35%;
  50. }
  51.  
  52. td.Control
  53. {
  54. 	width: 20%;
  55. 	text-align: right;
  56. }
  57.  
  58. td.Spacer
  59. {
  60. 	width: 5%;
  61. }
  1. </style>
  2.  
  3. </head>
  4.  
  5.  
  6. <script language="VBScript">
  1. Option Explicit
  2.  
  3. On Error Goto 0
  4.  
  5. Const ForAppending = 8
  6. Const ForReading   = 1
  7. Const ForWriting   = 2
  8.  
  9. Const TristateFalse      =  0
  10. Const TristateMixed      = -2
  11. Const TristateTrue       = -1
  12. Const TristateUseDefault = -2
  13.  
  14. Dim arrLang( )
  15. Dim blnUseLocalLanguageNames
  16. Dim objCaptions, objFSO, objIE, objSettings, wshShell
  17. Dim strAlternativeScientificName
  18.  
  19. Set objCaptions = CreateObject( "Scripting.Dictionary" )
  20. Set objSettings = CreateObject( "Scripting.Dictionary" )
  21. Set objIE       = CreateObject( "InternetExplorer.Application" )
  22. Set wshShell    = CreateObject( "WScript.Shell" )
  23. Set objFSO      = CreateObject( "Scripting.FileSystemObject" )
  24.  
  25.  
  26. Function Backup( myFile )
  27. 	' Backup this HTA; the COPY command is used because it handles open files much better than the FileSystemObject does
  28. 	Dim strBackup, strNow, wshShell
  29. 	strNow = Year( Now ) & Right( "0" & Month( Now ), 2 ) & Right( "0" & Day( Now ), 2 ) & "." & Right( "0" & Hour( Now ), 2 ) & Right( "0" & Minute( Now ), 2 ) & Right( "0" & Second( Now ), 2 )
  30. 	strBackup = myFile & "." & BirdName.Version & ".backup." & strNow
  31. 	Set wshShell = CreateObject( "WScript.Shell" )
  32. 	wshShell.Run "CMD.EXE /C COPY /Y """ & myFile & """ """ & strBackup & """", 7, True
  33. 	Set wshShell = Nothing
  34. 	Backup = strBackup
  35. End Function
  36.  
  37.  
  38. ' Capitalize
  39. Function Cap( myString )
  40. 	Dim strString
  41. 	strString = Replace( myString, "  ", " " )
  42. 	strString = LCase( Trim( strString ) )
  43. 	Cap = UCase( Left( strString, 1 ) ) & Mid( strString, 2 )
  44. End Function
  45.  
  46.  
  47. Sub CheckUpdate( )
  48. 	Dim intAnswer, intButtons, lenLatestVer
  49. 	Dim strCurDir, strCurrentVer, strLatestver, strPrompt, strTitle, strZIPFile
  50.  
  51. 	'On Error Resume Next
  52.  
  53. 	' Change mouse pointer to hourglass while checking for update
  54. 	Document.Body.Style.Cursor = "wait"
  55.  
  56. 	strCurrentVer = BirdName.Version
  57. 	' Read the latest version info from the web
  58. 	strLatestVer  = WGet( "http://www.robvanderwoude.com/updates/birdname.txt" )
  59.  
  60. 	' Retry once, after clearing the IE cache, if the versions don't match
  61. 	If strCurrentVer <> strLatestver Then
  62. 		' Clear the IE cache
  63. 		wshShell.Run "RUNDll32.EXE InetCpl.cpl,ClearMyTracksByProcess 8", 7, True
  64. 		' Try again, read the latest version info from the web
  65. 		strLatestver = WGet( "http://www.robvanderwoude.com/updates/birdname.txt" )
  66. 	End If
  67.  
  68. 	lenLatestVer  = Len( strLatestVer )
  69. 	If lenLatestVer = 4 Then
  70. 		If objSettings.Item( "AutoUpdate" ) = 1 Then
  71. 			Update
  72. 		Else
  73. 			intButtons = vbYesNoCancel + vbApplicationModal + vbInformation
  74. 			If strLatestVer < strCurrentVer Then
  75. 				strTitle  = "Unofficial version"
  76. 				strPrompt = "You seem to be using a pre-release version (" & strCurrentVer & ") of BirdName.hta." _
  77. 				          & vbCrLf & vbCrLf _
  78. 				          & "The latest official release is " & strLatestver _
  79. 				          & vbCrLf & vbCrLf _
  80. 				          & "Do you want to download the latest official version?"
  81. 				intAnswer = MsgBox( strPrompt, intButtons + vbDefaultButton2, strTitle )
  82. 			End If
  83. 			If strLatestVer > strCurrentVer Then
  84. 				strTitle  = "Old version"
  85. 				strPrompt = "You are using version " & strCurrentVer & " of BirdName.hta." _
  86. 				          & vbCrLf & vbCrLf _
  87. 				          & "The latest official release is " & strLatestver _
  88. 				          & vbCrLf & vbCrLf _
  89. 				          & "Do you want to download the latest official version?"
  90. 				intAnswer = MsgBox( strPrompt, intButtons, strTitle )
  91. 			End If
  92. 			If intAnswer = vbYes Then
  93. 				strCurDir  = objFSO.GetParentFolderName( Self.location.pathname )
  94. 				strZIPFile = objFSO.BuildPath( strCurDir, "birdname_hta.zip" )
  95. 				' Delete existing ZIP file
  96. 				If objFSO.FileExists( strZIPFile ) Then objFSO.DeleteFile strZIPFile, True
  97. 				' Backup current HTA
  98. 				strTitle  = "Backup saved"
  99. 				strPrompt = "The current HTA has been copied to" & vbCrLf _
  100. 				          & """" & Backup( Self.location.pathname ) & """" & vbCrLf & vbCrLf _
  101. 				          & "Click OK to continue"
  102. 				intAnswer = MsgBox( strPrompt, vbOKCancel + vbApplicationModal + vbInformation, strTitle )
  103. 				If intAnswer = vbOK Then
  104. 					If Download( "http://www.robvanderwoude.com/files/birdname_hta.zip", strZIPFile ) > 12000 Then
  105. 						' Overwrite current HTA with extracted new version and restart HTA
  106. 						Extract strZIPFile, strCurDir
  107. 						setTimeout "Self.location.reload", 3000, "VBScript"
  108. 					Else
  109. 						' Delete corrupted ZIP file
  110. 						If objFSO.FileExists( strZIPFile ) Then objFSO.DeleteFile strZIPFile, True
  111. 						intButtons = vbOKOnly + vbExclamation + vbApplicationModal
  112. 						strPrompt  = "An error occurred while trying to download ""birdname_hta.zip""." _
  113. 						           & vbCrLf & vbCrLf _
  114. 						           & "Try again later, or contact the author if the problem persists."
  115. 						strTitle   = "Download Error"
  116. 						MsgBox strPrompt, intButtons, strTitle
  117. 					End If
  118. 				Else
  119. 					wshShell.Run "http://www.robvanderwoude.com/birdname.php", 3, False
  120. 				End If
  121. 			End If
  122. 		End If
  123. 	End If
  124.  
  125. 	' Change mouse pointer back to default
  126. 	Document.Body.Style.Cursor = "default"
  127.  
  128. 	On Error Goto 0
  129. End Sub
  130.  
  131.  
  132. Sub ClearTranslations( )
  133. 	Translation1.value = ""
  134. 	Translation2.value = ""
  135. 	Translation3.value = ""
  136. 	Translation4.value = ""
  137. 	Button_SearchTranslation1.disabled   = True
  138. 	Button_SearchTranslation2.disabled   = True
  139. 	Button_SearchTranslation3.disabled   = True
  140. 	Button_SearchTranslation4.disabled   = True
  141. End Sub
  142.  
  143.  
  144. Function Download( myURL, myFile )
  145. 	Dim i, intLen, objFile, objFSO, objHTTP
  146. 	intLen = 0
  147. 	Set objFSO  = CreateObject( "Scripting.FileSystemObject" )
  148. 	Set objFile = objFSO.OpenTextFile( myFile, ForWriting, True )
  149. 	Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" )
  150. 	objHTTP.Open "GET", myURL, False
  151. 	objHTTP.Send
  152. 	' Write the downloaded byte stream to the target file
  153. 	intLen = LenB( objHTTP.ResponseBody )
  154. 	For i = 1 To intLen
  155. 		objFile.Write Chr( AscB( MidB( objHTTP.ResponseBody, i, 1 ) ) )
  156. 	Next
  157. 	objFile.Close( )
  158. 	Set objHTTP = Nothing
  159. 	Set objFile = Nothing
  160. 	Set objFSO  = Nothing
  161. 	Download = intLen
  162. End Function
  163.  
  164.  
  165. Sub Extract( myZIPFile, myTargetDir )
  166. 	Dim intOptions, objShell, objSource, objTarget
  167. 	Set objShell  = CreateObject( "Shell.Application" )
  168. 	Set objSource = objShell.NameSpace( myZIPFile ).Items( )
  169. 	Set objTarget = objShell.NameSpace( myTargetDir )
  170. 	' These are the available CopyHere options, according to MSDN
  171. 	' (http://msdn2.microsoft.com/en-us/library/ms723207.aspx).
  172. 	' On my test systems, however, the options were completely ignored.
  173. 	'      4: Do not display a progress dialog box.
  174. 	'      8: Give the file a new name in a move, copy, or rename operation if a file with the target name already exists.
  175. 	'     16: Click "Yes to All" in any dialog box that is displayed.
  176. 	'     64: Preserve undo information, if possible.
  177. 	'    128: Perform the operation on files only if a wildcard file name (*.*) is specified.
  178. 	'    256: Display a progress dialog box but do not show the file names.
  179. 	'    512: Do not confirm the creation of a new directory if the operation requires one to be created.
  180. 	'   1024: Do not display a user interface if an error occurs.
  181. 	'   4096: Only operate in the local directory. Don't operate recursively into subdirectories.
  182. 	'   8192: Do not copy connected files as a group. Only copy the specified files.
  183. 	intOptions = 16 + 256
  184. 	objTarget.CopyHere objSource, intOptions
  185. 	Set objSource = Nothing
  186. 	Set objTarget = Nothing
  187. 	Set objShell  = Nothing
  188. End Sub
  189.  
  190.  
  191. Function GetLanguageList( )
  192. 	Dim i
  193. 	Dim objHTTP, objMatch, objMatches, objNewOption, objRE
  194. 	Dim strHTML, strMsg, strResp, strURL
  195.  
  196. 	GetLanguageList = False
  197.  
  198. 	' Read and save the entire URL including HTML tags in a variable named strHTML
  199. 	Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" )
  200. 	strURL = "http://meta.wikimedia.org/wiki/List_of_Wikipedias"
  201. 	objHTTP.Open "GET", strURL
  202. 	objHTTP.Send
  203. 	If objHTTP.Status = 200 Then
  204. 		strHTML = objHTTP.ResponseText
  205. 		GetLanguageList = True
  206. 	Else
  207. 		MsgBox "Unable to contact Wikipedia for a list of available languages." _
  208. 		     & vbCrLf & vbCrLf _
  209. 		     & "Error code: " & objHTTP.Status _
  210. 		     & vbCrLf & vbCrLf _
  211. 		     & "Correct the problem and try again.", vbOKOnly, "Connection Error"
  212. 	End If
  213. 	Set objHTTP = Nothing
  214.  
  215. 	' Parse the languages tables and save the results in a 2-dimensional array named arrLang;
  216. 	' arrLang(0) is the language code
  217. 	' arrLang(1) is the local language name
  218. 	' arrLang(2) is the English language name
  219. 	Set objRE = New RegExp
  220. 	objRE.Global = True
  221. 	objRE.IgnoreCase = True
  222. 	objRE.Pattern = "<tr>[^<]*<td>[0-9,]+</td>[^<]*<td><a [^>]+>([^<]+)</a></td>[^<]*<td[^>]*><a [^>]+>([^<]+)</a></td>[^<]*<td><a [^>]+>([^<]+)</a></td>"
  223. 	Set objMatches = objRE.Execute( strHTML )
  224. 	For Each objMatch In objMatches
  225. 		If objMatch.Submatches.Count > 2 Then
  226. 			ReDim Preserve arrLang( 2, i )
  227. 			arrLang( 0, i ) = objMatch.Submatches.Item(2)
  228. 			arrLang( 1, i ) = objMatch.Submatches.Item(1)
  229. 			arrLang( 2, i ) = objMatch.Submatches.Item(0)
  230. 			i = i + 1
  231. 		End If
  232. 	Next
  233. 	Set objRE = Nothing
  234. End Function
  235.  
  236.  
  237. ' Read scientific name from WikiPedia page
  238. Sub GetScientificName( )
  239. 	Dim objMatches, objOption, objRE
  240. 	Dim strSpeciesName, strHTML, strLangCode, strURL
  241. 	Dim strDEBUG
  242.  
  243. 	ScientificName.value = ""
  244. 	strAlternativeScientificName = ""
  245. 	strSpeciesName = Cap( SpeciesInput.value )
  246. 	SpeciesInput.value = strSpeciesName
  247. 	For Each objOption In SelectSourceLanguage.Options
  248. 		If objOption.Selected Then
  249. 			strLangCode = objOption.value
  250. 		End If
  251. 	Next
  252. 	strURL = "http://" & strLangCode & ".wikipedia.org/wiki/" & Und( strSpeciesName )
  253. 	strHTML = WGet( strURL )
  254. 	If Left( LCase( strHTML ), 2 ) = "--" Then
  255. 		ScientificName.value = strHTML
  256. 		ScientificName.style.color = "red"
  257. 		Exit Sub
  258. 	Else
  259. 		ScientificName.style.color = "black"
  260. 	End If
  261. 	Set objRE = New RegExp
  262. 	objRE.Global = True
  263. 	objRE.IgnoreCase = True
  264. 	' First, test if the URL is for the selected animal class
  265. 	objRE.Pattern = Replace( SelectClass.value, "ph", "(ph|f)" )
  266. 	If objRE.Test( strHTML ) Or SelectClass.value = "All" Then
  267. 		' Next, find the bird name, followed by 1 or 2 scientific names in parenthesis
  268. 		objRE.Pattern = "<b>" & strSpeciesName & "</b> (<[bi]>)*\((<[bi]>)*([^<\n\r]+)(</[bi]>)*(<sup[^>]*>.*?</sup>)?([^<\)]*(<[bi]>)*([^<\)]+)(</[bi]>)*(<sup[^>]*>.*?</sup>)?)?\)(</[bi]>)*"
  269. 		Set objMatches = objRE.Execute( strHTML )
  270. 		If objMatches.Count > 0 Then
  271. 			If objMatches.Item(0).Submatches.Count > 10 Then
  272. 				' The displayed scientific name is the first match
  273. 				ScientificName.value = Cap( objMatches.Item(0).Submatches(2) )
  274. 				ScientificName.style.color = "black"
  275. 				' The optional second match is kept as a "spare" in case a translation will not be found
  276. 				strAlternativeScientificName = Cap( objMatches.Item(0).Submatches(9) )
  277. 			End If
  278. 		End If
  279. 	Else
  280. 		ScientificName.value = "--" & objcaptions.Item( "Not" & SelectClass.value ) & " " & objcaptions.Item( "OrAmbiguous" ) & "?--"
  281. 		ScientificName.style.color = "red"
  282. 		Button_SearchScientificName.disabled = False
  283. 		strAlternativeScientificName = ""
  284. 		ClearTranslations
  285. 	End If
  286. 	strDEBUG = strAlternativeScientificName
  287. 	Set objMatches = Nothing
  288. 	Set objRE = Nothing
  289. End Sub
  290.  
  291.  
  292. Sub HelpMsg( )
  293. 	Dim strHTML
  294. 	strHTML = "<h1>BirdName,  Version " & BirdName.Version & "</h1>\n\n" _
  295. 	        & "<p>This HTA uses <a href=""http://www.wikipedia.org/"">Wikipedia</a> to translate animal (chordata) species names from and to (m)any language(s).</p>\n\n" _
  296. 	        & "<p>You can use this program to translate a species name from one of the supported ""local"" languages to any of the other supported languages.<br>\n" _
  297. 	        & "Start by selecting a class in the dropdown list """ & objCaptions.Item( "Class" ) & ": <select size=""1"" style=""width: 10em;"">\n\t<option>" & objCaptions.Item( "All" ) & "</option>\n\t<option>" & objCaptions.Item( "ClassActinopterygii" ) & "</option>\n\t<option>" & objCaptions.Item( "ClassAmphibia" ) & "</option>\n\t<option selected=""selected"">" & objCaptions.Item( "ClassAves" ) & "</option>\n\t<option>" & objCaptions.Item( "ClassChondrichthyes" ) & "</option>\n\t<option>" & objCaptions.Item( "ClassMammalia" ) & "</option>\n\t<option>" & objCaptions.Item( "ClassReptilia" ) & "</option>\n</select>"".<br>\n" _
  298. 	        & "Next, type the species name in the <em>empty</em> field just below the class selection.<br>\n" _
  299. 	        & "The program will first search the scientific name on Wikipedia and then translate that scientific name to the language of choice.<br>\n" _
  300. 	        & "Alternatively, you can enter the scientific name yourself, and the program will translate it to the language(s) of choice.<br>\n" _
  301. 	        & "With the <input type=""button"" style=""width: 10em; height: 2em; vertical-align: middle"" value=""" & objCaptions.Item( "Search" ) & """> buttons you can search Wikipedia interactively for the requested translations.</p>\n\n" _
  302. 	        & "<h2>Settings</h2>\n\n" _
  303. 	        & "<p>If <input type=""checkbox""> <code>" & objCaptions.Item( "UseLocalLanguageNames" ) & "</code> is checked, the list of available languages shows the local language names (e.g. ""Fran&ccedil;ais"", ""Cymraeg""), if not checked the English language names are listed instead (e.g. ""French"", ""Welsh"").</p>\n\n" _
  304. 	        & "<p><select size=""1"" style=""width: 3em;"">\n\t<option>1</option>\n\t<option selected>2</option>\n\t<option>3</option>\n\t<option>4</option>\n</select> <code>" & objCaptions.Item( "SimultaneousTranslations" ) & "</code> controls the number of translations shown; it ranges from 1 to 4.</p>\n\n" _
  305. 	        & "<p>To change settings permanently, click the <input type=""button"" class=""Button"" value=""" & objCaptions.Item( "Configure" ) & """ style=""width: 10em; height: 2em; vertical-align: middle""> button, next to the """ & objCaptions.Item( "Settings" ) & """ header, to open the configuration files in Notepad (see the chapter ""Customization"" for more details).</p>\n\n" _
  306. 	        & "<p>Click <input type=""button"" style=""width: 10em; height: 2em; vertical-align: middle"" value=""" & objCaptions.Item( "HideSettings" ) & """> to move the """ & objCaptions.Item( "Settings" ) & """ block out of sight (it will reappear next time the program is started).</p>\n\n" _
  307. 	        & "<h2>Program Updates</h2>\n\n" _
  308. 	        & "<p>This program automatically checks for updates.<br>\n" _
  309. 	        & "If an update is available, a notification will pop up, asking you if you want to download the latest official release.<br>\n" _
  310. 	        & "If you click ""Yes"" the BirdName download page will be opened in your default browser.<br>\n" _
  311. 	        & "Unless you update the program, the notification will reappear next time the program is started.</p>\n\n" _
  312. 	        & "<p>If AutoUpdate is enabled, the program is updated ""on-the-fly"" without notification (see the chapter <a href=""#Customization"">Customization</a> for more details).</p>\n\n" _
  313. 	        & "<h2>Restrictions</h2>\n\n" _
  314. 	        & "<p>This program uses Wikipedia to find the requested translations.<br>\n" _
  315. 	        & "Thus it depends on:<br>\n\n" _
  316. 	        & "<ol>\n\t<li>the full name being entered, exactly as used on Wikipedia (e.g. ""Great Bittern"" instead of ""Bittern"")</li>\n\t<li>a page dedicated to the bird of choice in each language of choice</li>\n\t<li>redirection of the scientific name to the local name</li>\n\t<li>Wikipedia's page layout remaining more or less unchanged</li>\n</ol>\n\n" _
  317. 	        & "<p>It may be clear that these conditions may not always be met.<br>\n" _
  318. 	        & "If no translation was found because there is no dedicated page, use the <input type=""button"" style=""width: 10em; height: 2em; vertical-align: middle"" value=""" & objCaptions.Item( "Search" ) & """> button next to the """ & objCaptions.Item( "Translation" ) & """ field to search for the name yourself.</p>\n\n" _
  319. 	        & "<p>Ambiguity, multiple ""local"" names, or the use of an incomplete name or group name instead of the species' full name, may prevent the program to find the scientific name.<br>\n" _
  320. 	        & "That is where the <input type=""button"" style=""width: 10em; height: 2em; vertical-align: middle"" value=""" & objCaptions.Item( "Search" ) & """> button next to the """ & objCaptions.Item( "ScientificName" ) & """ field comes to the rescue.<br>\n" _
  321. 	        & "Click it to find the scientific name yourself, or look it up in a printed bird guide.<br>\n" _
  322. 	        & "Once found, clear the """ & objCaptions.Item( "BirdName" ) & """ field and use the """ & objCaptions.Item( "ScientificName" ) & """ field to find the requested translations.<br>\n" _
  323. 	        & "If you still can't find the translation that way, this program cannot assist you any further.</p>\n\n" _
  324. 	        & "<h2 id=""Customization"">Customization</h2>\n\n" _
  325. 	        & "<p>You may use a configuration file named BirdName.cfg, to customize the window size, default input and output languages and number of simultaneous translations.<br>\n" _
  326. 	        & "BirdName.cfg is an ANSI encoded (or ""ASCII"") plain text file, located in BirdName.hta's parent folder.<br>\n" _
  327. 	        & "Examine the default settings shown below to find out what you can customize and how:</p>\n\n" _
  328. 	        & "<pre>Version=" & BirdName.Version & "\n" _
  329. 	        & "AutoUpdate=0\n" _
  330. 	        & "ConfigLanguage=en\n" _
  331. 	        & "DefaultLanguage=en\n" _
  332. 	        & "LocalLanguageNames=1\n" _
  333. 	        & "NumTrans=4\n" _
  334. 	        & "TransLang1=nl\n" _
  335. 	        & "TransLang2=de\n" _
  336. 	        & "TransLang3=es\n" _
  337. 	        & "TransLang4=da\n" _
  338. 	        & "WindowHeight=768\n" _
  339. 	        & "WindowWidth=1024</pre>\n\n" _
  340. 	        & "<table>\n<tr>\n\t<th style=""vertical-align: top;"">Note 1:</th>\n\t<td style=""vertical-align: top;"">Each of these settings can also be specified on the command line, e.g.<br>\n" _
  341. 	        & "\t\t<code>BirdName.hta /ConfigLanguage=en /DefaultLanguage=fr</code></td>\n</tr>\n" _
  342. 	        & "<tr>\n\t<th style=""vertical-align: top;"">Note 2:</th>\n\t<td style=""vertical-align: top;""><code>AutoUpdate=1</code> will update the HTA to the latest version without any user interaction.</td>\n</tr>\n</table>\n\n" _
  343. 	        & "<p>Besides the program settings, you can also customize (translate) the captions and button labels.<br>\n" _
  344. 	        & "This requires an ANSI encoded (or ""ASCII"") plain text file named BirdName.<em>lang</em>, located in BirdName.hta's parent folder, where <em>lang</em> is the language code specified by <code>ConfigLanguage</code> in BirdName.cfg (e.g. <code>en</code>).<br>\n" _
  345. 	        & "Unicode or extended ASCII characters in all text except button labels must be escaped (e.g. <code>&amp;Uuml;</code> for <code>&Uuml;</code>).<br>\n" _
  346. 	        & "You may have to experiment with code page settings when using extended ASCII characters in translated <em>button</em> labels.<br>\n" _
  347. 	        & "Examine BirdName.en, shown below, to figure out what you can customize and how:</p>\n\n" _
  348. 	        & "<pre>Version=" & BirdName.Version & "\n" _
  349. 	        & "All=All\n" _
  350. 	        & "Class=Class\n" _
  351. 	        & "ClassAll=All\n" _
  352. 	        & "ClassActinopterygii=Ray-finned fishes\n" _
  353. 	        & "ClassAmphibia=Amphibians\n" _
  354. 	        & "ClassAves=Birds\n" _
  355. 	        & "ClassChondrichthyes=Cartilaginous fishes\n" _
  356. 	        & "ClassMammalia=Mammmals\n" _
  357. 	        & "ClassReptilia=Reptiles\n" _
  358. 	        & "Configure=Configure\n" _
  359. 	        & "Help=Help\n" _
  360. 	        & "HideSettings=Hide Settings\n" _
  361. 	        & "NotActinopterygii=Not a ray-finned fish\n" _
  362. 	        & "NotAmphibia=Not an amphibian\n" _
  363. 	        & "NotAves=Not a bird\n" _
  364. 	        & "NotChondrichthyes=Not a cartilaginous fish\n" _
  365. 	        & "NotMammalia=Not a mammmal\n" _
  366. 	        & "NotReptilia=Not a reptile\n" _
  367. 	        & "OrAmbiguous=or ambiguous name\n" _
  368. 	        & "ScientificName=Scientific Name\n" _
  369. 	        & "Search=Search Wikipedia\n" _
  370. 	        & "Settings=Settings\n" _
  371. 	        & "SimultaneousTranslations=simultaneous translations\n" _
  372. 	        & "Translate=Translate\n" _
  373. 	        & "Translation=Translation\n" _
  374. 	        & "UseLocalLanguageNames=Use local language names</pre>\n\n" _
  375. 	        & "<p>Open the configuration files by clicking the <input type=""button"" class=""Button"" value=""" & objCaptions.Item( "Configure" ) & """ style=""width: 10em; height: 2em; vertical-align: middle""> button, next to the """ & objCaptions.Item( "Settings" ) & """ header.</p>\n\n" _
  376. 	        & "Change one setting at a time and examine the effect.<br>\n" _
  377. 	        & "If the result is a complete mess, just delete BirdName.cfg (and optionally BirdName.<em>lang</em>) to restore the default settings.</p>\n\n" _
  378. 	        & "&copy; 2014 Rob van der Woude<br>\n" _
  379. 	        & "<a href=""http://www.robvanderwoude.com/birdname.php"">http://www.robvanderwoude.com/birdname.php</a></p>\n"
  380. 	strHTML = Replace( strHTML, "\n", vbCrLf )
  381. 	strHTML = Replace( strHTML, "\t", vbTab  )
  382.  
  383. 	On Error Resume Next
  384. 	objIE.Navigate "about:blank"
  385. 	If Err Then
  386. 		Set objIE = CreateObject( "InternetExplorer.Application" )
  387. 		objIE.Navigate "about:blank"
  388. 	End If
  389. 	On Error Goto 0
  390. 	objIE.Width  = objSettings.Item( "WindowWidth" )
  391. 	objIE.Height = objSettings.Item( "WindowHeight" )
  392. 	objIE.Left   = Int( ( window.screen.width  - objIE.Width  ) / 2 ) + 30
  393. 	objIE.Top    = Int( ( window.screen.height - objIE.Height ) / 2 ) + 30
  394. 	objIE.StatusBar  = False
  395. 	objIE.AddressBar = False
  396. 	objIE.MenuBar    = False
  397. 	objIE.ToolBar    = False
  398. 	objIE.Document.title = "Help for BirdName " & BirdName.Version & ", © Rob van der Woude 2014"
  399. 	objIE.Document.body.style.fontFamily = "arial,sans-serif"
  400. 	objIE.Document.body.style.fontSize = "80%"
  401. 	objIE.Document.body.InnerHTML = strHTML
  402. 	objIE.Visible = 1
  403. End Sub
  404.  
  405.  
  406. Sub InitialConfig( )
  407. 	objCaptions.RemoveAll
  408. 	objCaptions.Add "Version", "0.00"
  409. 	objCaptions.Add "All", "All"
  410. 	objCaptions.Add "Class", "Class"
  411. 	objCaptions.Add "ClassAll", "All"
  412. 	objCaptions.Add "ClassActinopterygii", "Ray-finned fishes"
  413. 	objCaptions.Add "ClassAmphibia", "Amphibians"
  414. 	objCaptions.Add "ClassAves", "Birds"
  415. 	objCaptions.Add "ClassChondrichthyes", "Cartilaginous fishes"
  416. 	objCaptions.Add "ClassMammalia", "Mammmals"
  417. 	objCaptions.Add "ClassReptilia", "Reptiles"
  418. 	objCaptions.Add "Configure", "Configure"
  419. 	objCaptions.Add "Help", "Help"
  420. 	objCaptions.Add "HideSettings", "Hide Settings"
  421. 	objCaptions.Add "NotActinopterygii", "Not a ray-finned fish"
  422. 	objCaptions.Add "NotAmphibia", "Not an amphibian"
  423. 	objCaptions.Add "NotAves", "Not a bird"
  424. 	objCaptions.Add "NotChondrichthyes", "Not a cartilaginous fish"
  425. 	objCaptions.Add "NotMammalia", "Not a mammmal"
  426. 	objCaptions.Add "NotReptilia", "Not a reptile"
  427. 	objCaptions.Add "OrAmbiguous", "or ambiguous name"
  428. 	objCaptions.Add "ScientificName", "Scientific Name"
  429. 	objCaptions.Add "Search", "Search Wikipedia"
  430. 	objCaptions.Add "Settings", "Settings"
  431. 	objCaptions.Add "SimultaneousTranslations", "simultaneous translations"
  432. 	objCaptions.Add "Translate", "Translate"
  433. 	objCaptions.Add "Translation", "Translation"
  434. 	objCaptions.Add "UseLocalLanguageNames", "Use local language names"
  435.  
  436. 	objSettings.RemoveAll
  437. 	objSettings.Add "Version", "0.00"
  438. 	objSettings.Add "AutoUpdate", 0
  439. 	objSettings.Add "ConfigLanguage", ""
  440. 	objSettings.Add "DefaultLanguage", "en"
  441. 	objSettings.Add "LocalLanguageNames", True
  442. 	objSettings.Add "NumTrans", 2
  443. 	objSettings.Add "TransLang1", "nl"
  444. 	objSettings.Add "TransLang2", "de"
  445. 	objSettings.Add "TransLang3", "fr"
  446. 	objSettings.Add "TransLang4", "it"
  447. 	objSettings.Add "WindowHeight", 768
  448. 	objSettings.Add "WindowWidth", 1024
  449. End Sub
  450.  
  451.  
  452. Sub LoadConfig( )
  453. 	Dim blnError
  454. 	Dim i, intButtons
  455. 	Dim objCaptionsFile, objFSO, objMatches, objNewOption, objRE, objSettingsFile
  456. 	Dim strBaseName, strCaptionsFile, strCommandLine, strKey, strLine, strPrompt, strSettingsFile, strTitle, strValue
  457.  
  458. 	blnError       = False
  459. 	strCommandLine = BirdName.CommandLine
  460.  
  461. 	' Regular expression object to check command line arguments
  462. 	Set objRE = New RegExp
  463. 	objRE.Global = True
  464. 	objRE.IgnoreCase = True
  465.  
  466. 	' Find the full path of this HTA
  467. 	strBaseName = Left( Self.location.pathname, Len( Self.location.pathname ) - 4 )
  468.  
  469. 	' Check if it is accompanied by a config file
  470. 	strSettingsFile = strBaseName & ".cfg"
  471. 	Set objFSO = CreateObject( "Scripting.FileSystemObject" )
  472. 	With objFSO
  473. 		If .FileExists( strSettingsFile ) Then
  474. 			Set objSettingsFile = .OpenTextFile( strSettingsFile, ForReading, TristateFalse )
  475. 			While Not objSettingsFile.AtEndOfStream
  476. 				strLine = objSettingsFile.ReadLine( )
  477. 				strKey   = Trim( Left( strLine, InStr( strLine, "=" ) - 1 ) )
  478. 				strValue = Trim( Mid( strLine, InStr( strLine, "=" ) + 1 ) )
  479. 				Select Case strKey
  480. 					Case "AutoUpdate", "LocalLanguageNames"
  481. 						objSettings.Item( strKey ) = CBool( strValue )
  482. 						If InStr( UCase( strCommandLine ), "/" & UCase( strKey ) ) Then
  483. 							objRE.Pattern = " /" & strKey & "[\=\:](0|1)([^\d]|$)"
  484. 							Set objMatches = objRE.Execute( strCommandLine )
  485. 							If objMatches.Count > 0 Then
  486. 								objSettings.Item( strKey ) = CBool( objMatches.Item(0).Submatches(0) )
  487. 							End If
  488. 							Set objMatches = Nothing
  489. 						End if
  490. 					Case "ConfigLanguage", "DefaultClass", "DefaultLanguage", "TransLang1", "TransLang2", "TransLang3", "TransLang4", "Version"
  491. 						objSettings.Item( strKey ) = CStr( strValue )
  492. 						If InStr( UCase( strCommandLine ), "/" & UCase( strKey ) ) Then
  493. 							objRE.Pattern = " /" & strKey & "[\=\:]([a-z]+)"
  494. 							Set objMatches = objRE.Execute( strCommandLine )
  495. 							If objMatches.Count > 0 Then
  496. 								objSettings.Item( strKey ) = Trim( objMatches.Item(0).Submatches(0) )
  497. 							End If
  498. 							Set objMatches = Nothing
  499. 						End If
  500. 					Case "NumTrans", "WindowHeight", "WindowWidth"
  501. 						objSettings.Item( strKey ) = CInt( strValue )
  502. 						If InStr( UCase( strCommandLine ), "/" & UCase( strKey ) ) Then
  503. 							objRE.Pattern = " /" & strKey & "[\=\:](\d+)"
  504. 							Set objMatches = objRE.Execute( strCommandLine )
  505. 							If objMatches.Count > 0 Then
  506. 								objSettings.Item( strKey ) = CInt( objMatches.Item(0).Submatches(0) )
  507. 							End If
  508. 							Set objMatches = Nothing
  509. 						End if
  510. 					Case Else
  511. 						If Left( strKey, 1 ) <> ";" Then blnError = True
  512. 				End Select
  513. 			Wend
  514. 			objSettingsFile.Close
  515. 			Set objSettingsFile = Nothing
  516.  
  517. 			If objSettings.Item( "Version" ) <> BirdName.Version And objSettings.Item( "Version" ) <> "0.00" Then
  518. 				intButtons = vbOKOnly + vbApplicationModal + vbExclamation
  519. 				strTitle   = "Old configuration file"
  520. 				strPrompt  = "The configuration file BirdName.cfg is not compatible with this version of BirdName.hta." _
  521. 				           & vbCrLf & vbCrLf _
  522. 				           & "The default configuration values will be used instead."
  523. 				MsgBox strPrompt, intButtons, strTitle
  524. 				InitialConfig
  525. 			End If
  526.  
  527. 			If Not blnError Then
  528. 				If objSettings.Item( "ConfigLanguage" ) <> "" Then
  529. 					strCaptionsFile = strBaseName & "." & objSettings.Item( "ConfigLanguage" )
  530. 					If .FileExists( strCaptionsFile ) Then
  531. 						Set objCaptionsFile = .OpenTextFile( strCaptionsFile, ForReading, TristateFalse )
  532. 						While Not objCaptionsFile.AtEndOfStream
  533. 							strLine = objCaptionsFile.ReadLine( )
  534. 							strKey = Trim( Left( strLine, InStr( strLine, "=" ) - 1 ) )
  535. 							strValue = Trim( Mid( strLine, InStr( strLine, "=" ) + 1 ) )
  536. 							Select Case strKey
  537. 								Case "Configure", "Help", "HideSettings", "Invertebrate", "Name", "ScientificName", "Search", "Settings", "SimultaneousTranslations", "Translate", "Translation", "UseLocalLanguageNames", "Version"
  538. 									objCaptions.Item( strKey ) = strValue
  539. 								Case "Class", "ClassAll", "ClassActinopterygii", "ClassAmphibia", "ClassAves", "ClassChondrichthyes", "ClassMammalia", "ClassReptilia"
  540. 									objCaptions.Item( strKey ) = strValue
  541. 								Case "All", "Actinopterygii", "Amphibia", "Aves", "Chondrichthyes", "Mammalia", "Reptilia"
  542. 									objCaptions.Item( strKey ) = strValue
  543. 								Case "Amphibian", "Bird", "CartilaginousFish", "Mammal", "RayFinnedFish", "Reptile"
  544. 									objCaptions.Item( strKey ) = strValue
  545. 								Case "NotActinopterygii", "NotAmphibia", "NotAves", "NotChondrichthyes", "NotMammalia", "NotReptilia", "OrAmbiguous"
  546. 									objCaptions.Item( strKey ) = strValue
  547. 								Case Else
  548. 									If Left( strKey, 1 ) <> ";" Then blnError = True
  549. 							End Select
  550. 						Wend
  551. 						objCaptionsFile.Close
  552. 						Set objCaptionsFile = Nothing
  553. 					End If
  554. 				End If
  555. 			End If
  556.  
  557. 			If objCaptions.Item( "Version" ) <> BirdName.Version And objCaptions.Item( "Version" ) <> "0.00" Then
  558. 				intButtons = vbOKOnly + vbApplicationModal + vbExclamation
  559. 				strTitle   = "Old configuration file"
  560. 				strPrompt  = "The language file BirdName." & objSettings.Item( "ConfigLanguage" ) & " is not compatible with this version of BirdName.hta." _
  561. 				           & vbCrLf & vbCrLf _
  562. 				           & "The default language, English, will be used instead."
  563. 				MsgBox strPrompt, intButtons, strTitle
  564. 				InitialConfig
  565. 			End If
  566.  
  567. 			SelectNumTrans.innerHTML  = ""
  568. 			For i = 1 To 4
  569. 				Set objNewOption  = document.createElement( "OPTION" )
  570. 				objNewOption.text = i
  571. 				objNewOption.value = i
  572. 				If Int( objSettings.Item( "NumTrans" ) ) = i Then
  573. 					objNewOption.selected = True
  574. 				End If
  575. 				SelectNumTrans.options.Add( objNewOption )
  576. 			Next
  577.  
  578. 			SelectClass.innerHTML  = ""
  579. 			Set objNewOption  = document.createElement( "OPTION" )
  580. 			objNewOption.text = objCaptions.Item( "All" )
  581. 			objNewOption.value = "All"
  582. 			If objSettings.Item( "DefaultClass" ) = objNewOption.value Then objNewOption.selected = True
  583. 			SelectClass.options.Add( objNewOption )
  584. 			Set objNewOption  = document.createElement( "OPTION" )
  585. 			objNewOption.text = objCaptions.Item( "ClassActinopterygii" )
  586. 			objNewOption.value = "Actinopterygii"
  587. 			If objSettings.Item( "DefaultClass" ) = objNewOption.value Then objNewOption.selected = True
  588. 			SelectClass.options.Add( objNewOption )
  589. 			Set objNewOption  = document.createElement( "OPTION" )
  590. 			objNewOption.text = objCaptions.Item( "ClassAmphibia" )
  591. 			objNewOption.value = "Amphibia"
  592. 			If objSettings.Item( "DefaultClass" ) = objNewOption.value Then objNewOption.selected = True
  593. 			SelectClass.options.Add( objNewOption )
  594. 			Set objNewOption  = document.createElement( "OPTION" )
  595. 			objNewOption.text = objCaptions.Item( "ClassAves" )
  596. 			objNewOption.value = "Aves"
  597. 			If objSettings.Item( "DefaultClass" ) = objNewOption.value Then objNewOption.selected = True
  598. 			SelectClass.options.Add( objNewOption )
  599. 			Set objNewOption  = document.createElement( "OPTION" )
  600. 			objNewOption.text = objCaptions.Item( "ClassChondrichthyes" )
  601. 			objNewOption.value = "Chondrichthyes"
  602. 			If objSettings.Item( "DefaultClass" ) = objNewOption.value Then objNewOption.selected = True
  603. 			SelectClass.options.Add( objNewOption )
  604. 			Set objNewOption  = document.createElement( "OPTION" )
  605. 			objNewOption.text = objCaptions.Item( "ClassMammalia" )
  606. 			objNewOption.value = "Mammalia"
  607. 			If objSettings.Item( "DefaultClass" ) = objNewOption.value Then objNewOption.selected = True
  608. 			SelectClass.options.Add( objNewOption )
  609. 			Set objNewOption  = document.createElement( "OPTION" )
  610. 			objNewOption.text = objCaptions.Item( "ClassReptilia" )
  611. 			objNewOption.value = "Reptilia"
  612. 			SelectClass.options.Add( objNewOption )
  613.  
  614. 			Label_Class.innerHTML                    = objCaptions.Item( "Class" )
  615. 			Button_Configure.value                   = objCaptions.Item( "Configure" )
  616. 			Button_Help.value                        = objCaptions.Item( "Help" )
  617. 			Button_HideSettings.value                = objCaptions.Item( "HideSettings" )
  618. 			Label_ScientificName.innerHTML           = objCaptions.Item( "ScientificName" )
  619. 			Button_SearchScientificName.value        = objCaptions.Item( "Search" )
  620. 			Button_SearchTranslation1.value          = objCaptions.Item( "Search" )
  621. 			Button_SearchTranslation2.value          = objCaptions.Item( "Search" )
  622. 			Button_SearchTranslation3.value          = objCaptions.Item( "Search" )
  623. 			Button_SearchTranslation4.value          = objCaptions.Item( "Search" )
  624. 			Label_Settings.innerHTML                 = objCaptions.Item( "Settings" )
  625. 			Label_SimultaneousTranslations.innerHTML = objCaptions.Item( "SimultaneousTranslations" )
  626. 			Button_Translate.value                   = objCaptions.Item( "Translate" )
  627. 			Label_Translation1.innerHTML             = objCaptions.Item( "Translation" )
  628. 			Label_Translation2.innerHTML             = objCaptions.Item( "Translation" )
  629. 			Label_Translation3.innerHTML             = objCaptions.Item( "Translation" )
  630. 			Label_Translation4.innerHTML             = objCaptions.Item( "Translation" )
  631. 			Label_UseLocalLanguageNames.innerHTML    = objCaptions.Item( "UseLocalLanguageNames" )
  632. 			UseLocalLanguageNames.Checked            = objSettings.Item( "LocalLanguageNames" )
  633. 		Else
  634. 			InitialConfig
  635. 		End If
  636. 	End With
  637. 	Set objFSO = Nothing
  638. 	Set objRE  = Nothing
  639.  
  640. 	' Resize and position window
  641. 	objSettings.Item( "WindowWidth" )  = Min( objSettings.Item( "WindowWidth" ), window.screen.width )
  642. 	objSettings.Item( "WindowHeight" ) = Min( objSettings.Item( "WindowHeight" ), window.screen.height )
  643. 	Self.resizeTo objSettings.Item( "WindowWidth" ), objSettings.Item( "WindowHeight" )
  644. 	Self.moveTo Int( ( window.screen.width  - objSettings.Item( "WindowWidth" ) ) / 2 ), Int( ( window.screen.height - objSettings.Item( "WindowHeight" ) ) / 2 )
  645. End Sub
  646.  
  647.  
  648. Function Max( num1, num2 )
  649. 	If CDbl( num1 ) > CDbl( num2 ) Then
  650. 		Max = CDbl( num1 )
  651. 	Else
  652. 		Max = CDbl( num2 )
  653. 	End If
  654. End Function
  655.  
  656.  
  657. Function Min( num1, num2 )
  658. 	If CDbl( num1 ) < CDbl( num2 ) Then
  659. 		Min = CDbl( num1 )
  660. 	Else
  661. 		Min = CDbl( num2 )
  662. 	End If
  663. End Function
  664.  
  665.  
  666. Function OSVersion( )
  667. 	Dim arrOSVer
  668. 	OSVersion = 0
  669. 	On Error Resume Next
  670. 	Set objWMIService = GetObject( "winmgmts://./root/cimv2" )
  671. 	Set colInstances  = objWMIService.ExecQuery( "SELECT * FROM Win32_OperatingSystem" )
  672. 	For Each objInstance In colInstances
  673. 		arrOSVer = Split( objInstance.Version, "." )
  674. 		If UBound( arrOSVer ) > 0 Then OSVersion = 100 * arrOSVer(0) + arrOSVer(1)
  675. 	Next
  676. 	Set colInstances  = Nothing
  677. 	Set objWMIService = Nothing
  678. 	On Error Goto 0
  679. End Function
  680.  
  681.  
  682. Sub Sleep( seconds )
  683. 	Dim strCmd
  684. 	On Error Resume Next
  685. 	strCmd = "%COMSPEC% /C (PING -n " & seconds & " 127.0.0.1 >NUL 2>&1 || PING -n " & seconds & " ::1 >NUL 2>&1)"
  686. 	wshShell.Run strCmd, 0, 1
  687. 	On Error Goto 0
  688. End Sub
  689.  
  690.  
  691. Sub Sort2Dim1( ByRef myArray, myIndex )
  692. ' Sort a 2-dimensional array by its specified index in the 1st dimension
  693.     Dim i, j, arrHolder( 2 )
  694.     For i = ( UBound( myArray, 2 ) - 1 ) to 0 Step -1
  695.         For j= 0 to i
  696.             If UCase( myArray( myIndex, j ) ) > UCase( myArray( myIndex, j + 1 ) ) Then
  697.                 arrHolder( 0 )      = myArray( 0, j + 1 )
  698.                 arrHolder( 1 )      = myArray( 1, j + 1 )
  699.                 arrHolder( 2 )      = myArray( 2, j + 1 )
  700.                 myArray( 0, j + 1 ) = myArray( 0, j )
  701.                 myArray( 1, j + 1 ) = myArray( 1, j )
  702.                 myArray( 2, j + 1 ) = myArray( 2, j )
  703.                 myArray( 0, j )     = arrHolder( 0 )
  704.                 myArray( 1, j )     = arrHolder( 1 )
  705.                 myArray( 2, j )     = arrHolder( 2 )
  706.             End If
  707.         Next
  708.     Next 
  709. End Sub
  710.  
  711.  
  712. ' Translate scientific name to specified language using WikiPedia
  713. Function Translate( myLanguageCode )
  714. 	Dim objMatches, objRE
  715. 	Dim strHTML, strName, strURL
  716.  
  717. 	If Trim( ScientificName.value ) = "" Then
  718. 		Translate = ""
  719. 		Exit Function
  720. 	End If
  721.  
  722. 	' First, try the URL generated with the first scientific name
  723. 	strURL = "http://" & myLanguageCode & ".wikipedia.org/wiki/" & Und( ScientificName.value )
  724. 	strHTML = WGet( strURL )
  725. 	' If the page or translation wasn't found, try the second scientific name, if available
  726. 	If Left( strHTML, 2 ) = "--" Then
  727. 		If strAlternativeScientificName = "" Then
  728. 			Translate = strHTML
  729. 			Exit Function
  730. 		Else
  731. 			strURL = "http://" & myLanguageCode & ".wikipedia.org/wiki/" & Und( strAlternativeScientificName )
  732. 			strHTML = WGet( strURL )
  733. 			If Left( strHTML, 2 ) = "--" Then
  734. 				Translate = strHTML
  735. 				Exit Function
  736. 			End If
  737. 		End If
  738. 	End If
  739. 	Set objRE = New RegExp
  740. 	objRE.Global = False
  741. 	objRE.IgnoreCase = True
  742. 	' First, let's assume the page title is the translated name
  743. 	objRE.Pattern = "<h1 (?:[^>]*?)?(?:id|class)=""firstHeading"" (?:class|id)=""firstHeading""(?:[^>]*?)?>(?:[\n\r\s]*)(?:<span[^>]*>)?(.*?)(?:</span>)(?:[\n\r\s]*)?</h1>"
  744. 	Set objMatches = objRE.Execute( strHTML )
  745. 	If objMatches.Count > 0 Then
  746. 		If objMatches.Item(0).Submatches.Count > 0 Then
  747. 			strName = objMatches.Item(0).Submatches(0)
  748. 			If InStr( strName, "<i>" ) Then
  749. 				strName = Replace( strName, "<i>", "" )
  750. 				strName = Replace( strName, "</i>", "" )
  751. 			End If
  752. 		End If
  753. 	End If
  754. 	' In case the page title is the scientific name, try an alternative search pattern
  755. 	If LCase( ScientificName.value ) = LCase( strName ) Then
  756. 		objre.Pattern = "<b>([^<]+)</b> \(<i>(<b>)?" & ScientificName.value & "(</b>)?</i>(,|\)) [^\n\r]{20,}[\n\r]"
  757. 		Set objMatches = objRE.Execute( strHTML )
  758. 		If objMatches.Count > 0 Then
  759. 			If objMatches.Item(0).Submatches.Count > 0 Then
  760. 				strName = objMatches.Item(0).Submatches(0)
  761. 			End If
  762. 		End If
  763. 	End If
  764. 	' For english translations only: in case the page title still equals the scientific name, try an alternative search pattern
  765. 	If myLanguageCode = "en" And LCase( ScientificName.value ) = LCase( strName ) Then
  766. 		objre.Pattern = "<a href=""/wiki/Common_name"" title=""Common name"">common name</a> is (?:the )?<b>([^<]{3,45})</b>"
  767. 		Set objMatches = objRE.Execute( strHTML )
  768. 		If objMatches.Count > 0 Then
  769. 			If objMatches.Item(0).Submatches.Count > 0 Then
  770. 				strName = objMatches.Item(0).Submatches(0)
  771. 			End If
  772. 		End If
  773. 		' In case the page title still equals the scientific name, try yet another alternative search pattern
  774. 		If LCase( ScientificName.value ) = LCase( strName ) Then
  775. 			objre.Pattern = "is known as (?:the )?<b>([^<]{3,45})</b>"
  776. 			Set objMatches = objRE.Execute( strHTML )
  777. 			If objMatches.Count > 0 Then
  778. 				If objMatches.Item(0).Submatches.Count > 0 Then
  779. 					strName = objMatches.Item(0).Submatches(0)
  780. 				End If
  781. 			End If
  782. 		End If
  783. 	End If
  784.  
  785. 	Set objMatches = Nothing
  786. 	Set objRE = Nothing
  787. 	Translate = strName
  788. End Function
  789.  
  790.  
  791. Function TextFromHTML( myURL )
  792.     Dim objHTTP
  793.     TextFromHTML = ""
  794.     Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" )
  795.     objHTTP.Open "GET", myURL
  796.     objHTTP.Send
  797.     ' Check if the result was valid, and if so return the result
  798.     If objHTTP.Status = 200 Then
  799.     	TextFromHTML = objHTTP.ResponseText
  800.     End If
  801.     Set objHTTP = Nothing
  802. End Function
  803.  
  804.  
  805. ' Replace spaces by underscores to create URL
  806. Function Und( myString )
  807. 	Und = Replace( myString, " ", "_" )
  808. End Function
  809.  
  810.  
  811. Sub Update( )
  812. 	Dim blnAccess, blnCreate, blnOverwrite
  813. 	Dim objFSO, objHTAFile, objShell
  814. 	Dim strHTAFile
  815.  
  816. 	blnCreate = True
  817. 	blnOverwrite = True
  818. 	strHTAFile = Self.location.pathname
  819. 	Set objFSO   = CreateObject( "Scripting.FileSystemObject" )
  820. 	'On Error Resume Next
  821. 	With objFSO
  822. 		Set objHTAFile = .GetFile( strHTAFile )
  823. 		objHTAFile.Copy Left( strHTAFile, Len( strHTAFile ) - 4 ) & ".bak." & CStr( 10000 * Hour( Now ) + 100 * Minute( Now ) + Second( Now ) ), blnOverwrite
  824. 		If Err Then
  825. 			blnAccess = False
  826. 		Else
  827. 			blnAccess = True
  828. 		End If
  829. 		Set objHTAFile = Nothing
  830. 		WGetSource
  831. 		Self.location.reload( True )
  832. 	End With
  833. 	On Error Goto 0
  834. 	Set objFSO   = Nothing
  835. 	' If we could not access the HTA to update it, we will retry with elevated privileges
  836. 	If Not blnAccess Then
  837. 		If InStr( BirdName.CommandLine, " /Update" ) Then
  838. 			MsgBox "The automatic update failed: no access.", vbOKOnly + vbApplicationModal + vbExclamation, "Automatic update failed"
  839. 		Else
  840. 			If OSVersion > 599 Then
  841. 				Set objShell = CreateObject( "Shell.Application" )
  842. 				objShell.ShellExecute BirdName.CommandLine & " /Update", "", "runas", 1
  843. 				Set objShell = Nothing
  844. 			Else
  845. 				MsgBox "Update failed, no access."
  846. 			End If
  847. 		End If
  848. 	End If
  849. End Sub
  850.  
  851.  
  852. ' Read the entire web page
  853. Function WGet( myURL )
  854. 	Dim objHTTP
  855. 	WGet = "--Not Found: " & myURL & "--"
  856. 	Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" )
  857. 	objHTTP.Open "GET", myURL
  858. 	objHTTP.Send
  859. 	If objHTTP.Status = 200 Then
  860. 		WGet = objHTTP.ResponseText
  861. 	Else
  862. 		WGet = "--Not found (" & objHTTP.Status & ") " & myURL & "--"
  863. 	End If
  864. 	Set objHTTP = Nothing
  865. End Function
  866.  
  867.  
  868. ' Read the HTA source code from the web page and overwrite this HTA itself
  869. Sub WGetSource(  )
  870. 	Dim intAnswer, intButtons
  871. 	Dim objADODB, objHTTP, objRE
  872. 	Dim strHTA, strPrompt, strText, strTitle, strURL
  873.  
  874. 	Const adTypeBinary          = 1
  875. 	Const adTypeText            = 2
  876. 	Const adSaveCreateNotExist  = 1
  877. 	Const adSaveCreateOverWrite = 2
  878.  
  879. 	strURL  = "http://www.robvanderwoude.com/files/birdname_hta.txt"
  880. 	strHTA  = Self.location.pathname
  881. 	strText = ""
  882.  
  883. 	Set objADODB = CreateObject( "ADODB.Stream" )
  884. 	Set objRE    = New RegExp
  885.  
  886. 	Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" )
  887. 	objHTTP.Open "GET", strURL
  888. 	objHTTP.Send
  889. 	If objHTTP.Status = 200 Then
  890. 		strText = objHTTP.ResponseText
  891. 	End If
  892. 	Set objHTTP = Nothing
  893.  
  894. 	If InStr( strText, "APPLICATIONNAME=""BirdName""" ) Then
  895. 		' Use ADODB stream to convert to and save as ASCII
  896. 		With objADODB
  897. 			.Open
  898. 			.Type = adTypeText
  899. 			.CharSet = "us-ascii"
  900. 			.WriteText strText
  901. 			.SaveToFile strHTA, adSaveCreateOverWrite
  902. 			.Close
  903. 		End With
  904. 	Else
  905. 		intButtons = vbYesNoCancel + vbApplicationModal + vbInformation
  906. 		strTitle   = "Automatic update failed"
  907. 		strPrompt  = "The automatic update of BirdName.hta failed." & vbCrLf & vbCrLf & "Do you want to download the latest official release now?" 
  908. 		intAnswer  = MsgBox( strPrompt, intButtons, strTitle )
  909. 		If intAnswer = vbYes Then
  910. 			wshShell.Run "http://www.robvanderwoude.com/birdname.php", 3, False
  911. 		End If
  912. 	End If
  913.  
  914. 	Set objADODB = Nothing
  915. 	Set objHTTP  = Nothing
  916. 	Set objRE    = Nothing
  917. End Sub
  918.  
  919.  
  920. ' Event triggered subroutines
  921.  
  922.  
  923. Sub Window_OnLoad( )
  924. 	window.document.title = "BirdName " & BirdName.Version & ", © Rob van der Woude 2014"
  925. 	LoadConfig
  926. 	If GetLanguageList( ) Then
  927. 		OnClick_UseLocalLanguageNames
  928. 		OnChange_SelectNumTrans
  929. 		setTimeout "CheckUpdate", 500, "VBScript"
  930. 		If InStr( BirdName.CommandLine, "/?" ) Then HelpMsg
  931. 	Else
  932. 		Self.close
  933. 	End If
  934. End Sub
  935.  
  936.  
  937. Sub Window_OnUnload( )
  938. 	On Error Resume Next
  939. 	objIE.Quit
  940. 	Set objIE       = Nothing
  941. 	Set objFSO      = Nothing
  942. 	Set objCaptions = Nothing
  943. 	Set objSettings = Nothing
  944. 	Set wshShell    = Nothing
  945. 	On Error Goto 0
  946. End Sub
  947.  
  948.  
  949. Sub OnChange_ScientificName( )
  950. 	ClearTranslations
  951. 	If Not Button_SearchScientificName.disabled Then
  952. 		If Trim( ScientificName.value ) <> "" And Left( LCase( Trim( ScientificName.value ) ), 11 ) <> "--not found" Then
  953. 			SpeciesInput.value = ""
  954. 			Button_SearchScientificName.disabled = False
  955. 		End If
  956. 	End If
  957. 	If Trim( SpeciesInput.value & ScientificName.value ) = "" Then
  958. 		Button_Clear.disabled     = True
  959. 		Button_Translate.disabled = True
  960. 	Else
  961. 		Button_Clear.disabled     = False
  962. 		Button_Translate.disabled = False
  963. 	End If
  964. 	If Trim( ScientificName.value ) = "" Then
  965. 		Button_SearchScientificName.disabled = True
  966. 	Else
  967. 		Button_SearchScientificName.disabled = False
  968. 		' Start translating when Enter key is pressed
  969. 		If window.event.Keycode = 13 Then OnClick_ButtonTranslate
  970. 	End If
  971. End Sub
  972.  
  973.  
  974. Sub OnChange_SelectSourceLanguage( )
  975. 	objSettings.Item( "DefaultLanguage" ) = SelectSourceLanguage.value
  976. End Sub
  977.  
  978.  
  979. Sub OnChange_SelectTargetLanguage1( )
  980. 	Translation1.value = ""
  981. 	objSettings.Item( "TransLang1" ) = SelectTargetLanguage1.value
  982. End Sub
  983.  
  984.  
  985. Sub OnChange_SelectTargetLanguage2( )
  986. 	Translation2.value = ""
  987. 	objSettings.Item( "TransLang2" ) = SelectTargetLanguage2.value
  988. End Sub
  989.  
  990.  
  991. Sub OnChange_SelectTargetLanguage3( )
  992. 	Translation3.value = ""
  993. 	objSettings.Item( "TransLang3" ) = SelectTargetLanguage3.value
  994. End Sub
  995.  
  996.  
  997. Sub OnChange_SelectTargetLanguage4( )
  998. 	Translation4.value = ""
  999. 	objSettings.Item( "TransLang4" ) = SelectTargetLanguage4.value
  1000. End Sub
  1001.  
  1002.  
  1003. Sub OnChange_SelectClass( )
  1004. 	ScientificName.value = ""
  1005. 	Button_SearchScientificName.disabled = True
  1006. 	ClearTranslations
  1007. 	SpeciesInput.Focus
  1008. End Sub
  1009.  
  1010.  
  1011. Sub OnChange_SelectNumTrans( )
  1012. 	Dim i, intNumTrans, objNewOption
  1013. 	If SelectNumTrans.value = "" Then
  1014. 		SelectNumTrans.innerHTML  = ""
  1015. 		For i = 1 To 4
  1016. 			Set objNewOption  = document.createElement( "OPTION" )
  1017. 			objNewOption.text = i
  1018. 			objNewOption.value = i
  1019. 			If Int( objSettings.Item( "NumTrans" ) ) = i Then
  1020. 				objNewOption.selected = True
  1021. 			End If
  1022. 			SelectNumTrans.options.Add( objNewOption )
  1023. 		Next
  1024. 	End If
  1025. 	intNumTrans = SelectNumTrans.value
  1026. 	TranslationBlock2.style.display = "none"
  1027. 	TranslationBlock3.style.display = "none"
  1028. 	TranslationBlock4.style.display = "none"
  1029. 	If intNumTrans = 1 Then
  1030. 		Label_Trans1.style.display = "none"
  1031. 	Else
  1032. 		Label_Trans1.style.display = "inline"
  1033. 	End If
  1034. 	If intNumTrans > 1 Then TranslationBlock2.style.display = "block"
  1035. 	If intNumTrans > 2 Then TranslationBlock3.style.display = "block"
  1036. 	If intNumTrans > 3 Then TranslationBlock4.style.display = "block"
  1037. End Sub
  1038.  
  1039.  
  1040. Sub OnChange_SpeciesInput( )
  1041. 	ClearTranslations
  1042. 	If Trim( SpeciesInput.value ) <> "" Then
  1043. 		ScientificName.value = ""
  1044. 	End If
  1045. 	If Trim( SpeciesInput.value & ScientificName.value ) = "" Then
  1046. 		Button_Clear.disabled     = True
  1047. 		Button_Translate.disabled = True
  1048. 	Else
  1049. 		Button_Clear.disabled     = False
  1050. 		Button_Translate.disabled = False
  1051. 	End If
  1052. 	If Trim( SpeciesInput.value ) = "" Then
  1053. 		Button_Translate.disabled = True
  1054. 	Else
  1055. 		Button_Translate.disabled = False
  1056. 		' Start translating when Enter key is pressed
  1057. 		If window.event.Keycode = 13 Then OnClick_ButtonTranslate
  1058. 	End If
  1059. 	If Trim( ScientificName.value ) = "" Then
  1060. 		Button_SearchScientificName.disabled = True
  1061. 	Else
  1062. 		Button_SearchScientificName.disabled = False
  1063. 	End If
  1064. End Sub
  1065.  
  1066.  
  1067. Sub OnClick_ButtonClear( )
  1068. 	ScientificName.value = ""
  1069. 	SpeciesInput.value  = ""
  1070. 	OnChange_SpeciesInput
  1071. 	SpeciesInput.Focus
  1072. End Sub
  1073.  
  1074.  
  1075. Sub OnClick_ButtonConfigure( )
  1076. 	Dim strBaseName
  1077. 	strBaseName = Left( Self.location.pathname, Len( Self.location.pathname ) - 4 )
  1078. 	wshShell.Run "notepad.exe " & strBaseName & ".cfg", 5, True
  1079. 	LoadConfig
  1080. 	wshShell.Run "notepad.exe " & strBaseName & "." & objSettings.Item( "ConfigLanguage" ), 5, True
  1081. 	Self.location.reload True
  1082. End Sub
  1083.  
  1084.  
  1085. Sub OnClick_ButtonDownload( )
  1086. 	wshShell.Run "http://www.robvanderwoude.com/birdname.php"
  1087. End Sub
  1088.  
  1089.  
  1090. Sub OnClick_ButtonHideSettings( )
  1091. 	SettingsBlock.style.display = "none"
  1092. End Sub
  1093.  
  1094.  
  1095. Sub OnClick_ButtonSearchScientificName( )
  1096. 	wshshell.Run "http://" & SelectSourceLanguage.value & ".wikipedia.org/wiki/" & Cap( Und( SpeciesInput.value ) )
  1097. End Sub
  1098.  
  1099.  
  1100. Sub OnClick_ButtonSearchTranslation1( )
  1101. 	If Translation1.value = "" Or Left( LCase( Trim( Translation1.value ) ), 2 ) = "--" Then
  1102. 		wshshell.Run "http://" & SelectTargetLanguage1.value & ".wikipedia.org/wiki/" & Und( ScientificName.value )
  1103. 	Else
  1104. 		wshshell.Run "http://" & SelectTargetLanguage1.value & ".wikipedia.org/wiki/" & Und( Translation1.value )
  1105. 	End If
  1106. End Sub
  1107.  
  1108.  
  1109. Sub OnClick_ButtonSearchTranslation2( )
  1110. 	If Translation2.value = "" Or Left( LCase( Trim( Translation2.value ) ), 2 ) = "--" Then
  1111. 		wshshell.Run "http://" & SelectTargetLanguage2.value & ".wikipedia.org/wiki/" & Und( ScientificName.value )
  1112. 	Else
  1113. 		wshshell.Run "http://" & SelectTargetLanguage2.value & ".wikipedia.org/wiki/" & Und( Translation2.value )
  1114. 	End If
  1115. End Sub
  1116.  
  1117.  
  1118. Sub OnClick_ButtonSearchTranslation3( )
  1119. 	If Translation3.value = "" Or Left( LCase( Trim( Translation3.value ) ), 2 ) = "--" Then
  1120. 		wshshell.Run "http://" & SelectTargetLanguage3.value & ".wikipedia.org/wiki/" & Und( ScientificName.value )
  1121. 	Else
  1122. 		wshshell.Run "http://" & SelectTargetLanguage3.value & ".wikipedia.org/wiki/" & Und( Translation3.value )
  1123. 	End If
  1124. End Sub
  1125.  
  1126.  
  1127. Sub OnClick_ButtonSearchTranslation4( )
  1128. 	If Translation4.value = "" Or Left( LCase( Trim( Translation4.value ) ), 2 ) = "--" Then
  1129. 		wshshell.Run "http://" & SelectTargetLanguage4.value & ".wikipedia.org/wiki/" & Und( ScientificName.value )
  1130. 	Else
  1131. 		wshshell.Run "http://" & SelectTargetLanguage4.value & ".wikipedia.org/wiki/" & Und( Translation4.value )
  1132. 	End If
  1133. End Sub
  1134.  
  1135.  
  1136. Sub OnClick_ButtonTranslate( )
  1137. 	ClearTranslations
  1138. 	Button_SearchScientificName.disabled = True
  1139. 	If Trim( SpeciesInput.value ) = "" Then
  1140. 		ScientificName.value = Cap( ScientificName.value )
  1141. 		SpeciesInput.value = Translate( objSettings.Item( "DefaultLanguage" ) )
  1142. 	Else
  1143. 		ScientificName.value = ""
  1144. 		GetScientificName
  1145. 	End If
  1146. 	Button_SearchScientificName.disabled = False
  1147. 	If ScientificName.value <> "" And Left( LCase( Trim( ScientificName.value ) ), 2 ) <> "--" Then
  1148. 		Translation1.value = Translate( objSettings.Item( "TransLang1" ) )
  1149. 		Button_SearchTranslation1.disabled = False
  1150. 		If Left( LCase( Trim( Translation1.value ) ), 2 ) = "--" Then
  1151. 			Translation1.style.color = "red"
  1152. 		Else
  1153. 			Translation1.style.color = "black"
  1154. 		End If
  1155. 		If SelectNumTrans.value > 1 Then
  1156. 			Translation2.value = Translate( objSettings.Item( "TransLang2" ) )
  1157. 			Button_SearchTranslation2.disabled = False
  1158. 			If Left( LCase( Trim( Translation2.value ) ), 2 ) = "--" Then
  1159. 				Translation2.style.color = "red"
  1160. 			Else
  1161. 				Translation2.style.color = "black"
  1162. 			End If
  1163. 		End If
  1164. 		If SelectNumTrans.value > 2 Then
  1165. 			Translation3.value = Translate( objSettings.Item( "TransLang3" ) )
  1166. 			Button_SearchTranslation3.disabled = False
  1167. 			If Left( LCase( Trim( Translation3.value ) ), 2 ) = "--" Then
  1168. 				Translation3.style.color = "red"
  1169. 			Else
  1170. 				Translation3.style.color = "black"
  1171. 			End If
  1172. 		End If
  1173. 		If SelectNumTrans.value > 3 Then
  1174. 			Translation4.value = Translate( objSettings.Item( "TransLang4" ) )
  1175. 			Button_SearchTranslation4.disabled = False
  1176. 			If Left( LCase( Trim( Translation4.value ) ), 2 ) = "--" Then
  1177. 				Translation4.style.color = "red"
  1178. 			Else
  1179. 				Translation4.style.color = "black"
  1180. 			End If
  1181. 		End If
  1182. 	End If
  1183. 	If Left( LCase( Trim( SpeciesInput.value ) ), 2 ) = "--" Then
  1184. 		SpeciesInput.style.color = "red"
  1185. 	Else
  1186. 		SpeciesInput.style.color = "black"
  1187. 	End If
  1188. 	If Left( LCase( Trim( ScientificName.value ) ), 2 ) = "--" Then
  1189. 		ScientificName.style.color = "red"
  1190. 	Else
  1191. 		ScientificName.style.color = "black"
  1192. 	End If
  1193. End Sub
  1194.  
  1195.  
  1196. Sub OnClick_ButtonUpdate( )
  1197. 	Dim strMsg, strQuote, strTitle
  1198.  
  1199. 	Const vbCancel = 2
  1200. 	Const vbYes    = 6
  1201. 	Const vbNo     = 7
  1202.  
  1203. 	If Left( BirdName.Version, 1 ) = "0" Then strQuote = Chr(34)
  1204. 	strMsg   = "You are about to update the running BirdName program to its latest " & strQuote & "stable" & strQuote & " release." & vbCrLf _
  1205. 	         & "A copy of the program will be saved, allowing a roll-back if necessary." & vbCrLf & vbCrLf
  1206. 	If Left( BirdName.Version, 4 ) < "0.30" Then
  1207. 		strMsg = strMsg & "The update to version " & BirdName.Version & " will render previous configuration files useless." & vbCrLf & vbCrLf
  1208. 	End If
  1209. 	strMsg   = strMsg & "Do you want to update now?"
  1210. 	strTitle = "Confirm Update"
  1211. 	If MsgBox( strMsg, vbYesNoCancel, strTitle ) = vbYes Then Update
  1212. End Sub
  1213.  
  1214.  
  1215. Sub OnClick_UseLocalLanguageNames( )
  1216. 	Dim i, intIndex, objNewOption
  1217. 	blnUseLocalLanguageNames = UseLocalLanguageNames.Checked
  1218. 	If blnUseLocalLanguageNames Then
  1219. 		intIndex = 1
  1220. 	Else
  1221. 		intIndex = 2
  1222. 	End If
  1223. 	Sort2Dim1 arrLang, intIndex
  1224.  
  1225. 	SelectSourceLanguage.innerHTML  = ""
  1226. 	For i = 0 To UBound( arrLang, 2 )
  1227. 		Set objNewOption  = document.createElement( "OPTION" )
  1228. 		objNewOption.text = arrLang( intIndex, i )
  1229. 		objNewOption.value = arrLang( 0, i )
  1230. 		objNewOption.title = arrLang( 3 - intIndex, i )
  1231. 		If UCase( objSettings.Item( "DefaultLanguage" ) ) = UCase( arrLang( 0, i ) ) Then
  1232. 			objNewOption.selected = True
  1233. 		End If
  1234. 		SelectSourceLanguage.options.Add( objNewOption )
  1235. 	Next
  1236.  
  1237. 	SelectTargetLanguage1.innerHTML = ""
  1238. 	For i = 0 To UBound( arrLang, 2 )
  1239. 		Set objNewOption  = document.createElement( "OPTION" )
  1240. 		objNewOption.text = arrLang( intIndex, i )
  1241. 		objNewOption.value = arrLang( 0, i )
  1242. 		objNewOption.title = arrLang( 3 - intIndex, i )
  1243. 		If UCase( objSettings.Item( "TransLang1" ) ) = UCase( arrLang( 0, i ) ) Then
  1244. 			objNewOption.selected = True
  1245. 		End If
  1246. 		SelectTargetLanguage1.options.Add( objNewOption )
  1247. 	Next
  1248.  
  1249. 	SelectTargetLanguage2.innerHTML = ""
  1250. 	For i = 0 To UBound( arrLang, 2 )
  1251. 		Set objNewOption  = document.createElement( "OPTION" )
  1252. 		objNewOption.text = arrLang( intIndex, i )
  1253. 		objNewOption.value = arrLang( 0, i )
  1254. 		objNewOption.title = arrLang( 3 - intIndex, i )
  1255. 		If UCase( objSettings.Item( "TransLang2" ) ) = UCase( arrLang( 0, i ) ) Then
  1256. 			objNewOption.selected = True
  1257. 		End If
  1258. 		SelectTargetLanguage2.options.Add( objNewOption )
  1259. 	Next
  1260.  
  1261. 	SelectTargetLanguage3.innerHTML = ""
  1262. 	For i = 0 To UBound( arrLang, 2 )
  1263. 		Set objNewOption  = document.createElement( "OPTION" )
  1264. 		objNewOption.text = arrLang( intIndex, i )
  1265. 		objNewOption.value = arrLang( 0, i )
  1266. 		objNewOption.title = arrLang( 3 - intIndex, i )
  1267. 		If UCase( objSettings.Item( "TransLang3" ) ) = UCase( arrLang( 0, i ) ) Then
  1268. 			objNewOption.selected = True
  1269. 		End If
  1270. 		SelectTargetLanguage3.options.Add( objNewOption )
  1271. 	Next
  1272.  
  1273. 	SelectTargetLanguage4.innerHTML = ""
  1274. 	For i = 0 To UBound( arrLang, 2 )
  1275. 		Set objNewOption  = document.createElement( "OPTION" )
  1276. 		objNewOption.text = arrLang( intIndex, i )
  1277. 		objNewOption.value = arrLang( 0, i )
  1278. 		objNewOption.title = arrLang( 3 - intIndex, i )
  1279. 		If UCase( objSettings.Item( "TransLang4" ) ) = UCase( arrLang( 0, i ) ) Then
  1280. 			objNewOption.selected = True
  1281. 		End If
  1282. 		SelectTargetLanguage4.options.Add( objNewOption )
  1283. 	Next
  1284. End Sub
  1. </script>
  2.  
  3. <body onhelp="HelpMsg()">
  4.  
  5. <div id="SettingsBlock">
  6.  
  7. <h3>
  8. <span name="Label_Settings" id="Label_Settings" onclick="OnClick_ButtonConfigure">Settings</span>
  9. <input class="Button Hidden">
  10. <input name="Button_Configure" id="Button_Configure" type="button" class="Button" value="Configure" onclick="OnClick_ButtonConfigure" style="vertical-align: middle;">
  11. </h3>
  12.  
  13. <div class="Group">
  14.  
  15. <table>
  16. <tr>
  17. 	<td class="Content">
  18. 		<input type="checkbox" name="UseLocalLanguageNames" id="UseLocalLanguageNames" onclick="OnClick_UseLocalLanguageNames"><label for="UseLocalLanguageNames" id="Label_UseLocalLanguageNames" title="Deselect to use English language names">Use local language names</label></td>
  19. 	<td class="Spacer">&nbsp;</td>
  20. 	<td class="Content">
  21. 		<select name="SelectNumTrans" id="SelectNumTrans" size="1" onchange="OnChange_SelectNumTrans" style="width: 3em;"></select> <span id="Label_SimultaneousTranslations">simultaneous translations</span></td>
  22. 	<td class="Spacer">&nbsp;</td>
  23. 	<td class="Control"><input type="button" class="Button" name="Button_HideSettings" id="Button_HideSettings" value="Hide Settings" onclick="OnClick_ButtonHideSettings"></td>
  24. </tr>
  25. </table>
  26.  
  27. </div>
  28.  
  29. </div>
  30.  
  31.  
  32.  
  33. <h3><span id="Label_Class">Class</span>:
  34. <select name="SelectClass" id="SelectClass" size="1" onchange="OnChange_SelectClass" style="width: 10em;">
  35. 	<option value="All">All</option>
  36. 	<option value="Actinopterygii">Ray-finned fishes</option>
  37. 	<option value="Amphibia">Amphibians</option>
  38. 	<option value="Aves">Birds</option>
  39. 	<option value="Chondrichthyes">Cartilaginous fishes</option>
  40. 	<option value="Mammalia">Mammals</option>
  41. 	<option value="Reptilia">Reptiles</option>
  42. </select></h3>
  43.  
  44. <div class="Group">
  45.  
  46. <table>
  47. <tr>
  48. 	<td class="Content"><select name="SelectSourceLanguage" id="SelectSourceLanguage" size="1" onchange="OnChange_SelectSourceLanguage" style="width: 20em;"></select></td>
  49. 	<td class="Spacer">&nbsp;</td>
  50. 	<td class="Content"><input type="text" name="SpeciesInput" id="SpeciesInput" style="width: 25em;" onchange="OnChange_SpeciesInput" onclick="OnChange_SpeciesInput" onkeyup="OnChange_SpeciesInput"></td>
  51. 	<td class="Spacer">&nbsp;</td>
  52. 	<td class="Control"><input type="button" class="Button" name="Button_Translate" id="Button_Translate" value="Translate" onclick="OnClick_ButtonTranslate" disabled></td>
  53. </tr>
  54. </table>
  55.  
  56. </div>
  57.  
  58.  
  59.  
  60. <h3 id="Label_ScientificName">Scientific Name</h3>
  61.  
  62. <div class="Group">
  63.  
  64. <table>
  65. <tr>
  66. 	<td class="Content"><select name="Spacer" id="Spacer" style="width: 20em; visibility: hidden;"></select></td>
  67. 	<td class="Spacer">&nbsp;</td>
  68. 	<td class="Content"><input type="text" name="ScientificName" id="ScientificName" onchange="OnChange_ScientificName" onkeyup="OnChange_ScientificName" style="width: 25em;"></td>
  69. 	<td class="Spacer">&nbsp;</td>
  70. 	<td class="Control"><input type="button" class="Button" name="Button_SearchScientificName" id="Button_SearchScientificName" value="Search Wikipedia" onclick="OnClick_ButtonSearchScientificName" disabled></td>
  71. </tr>
  72. </table>
  73.  
  74. </div>
  75.  
  76.  
  77.  
  78. <h3><span id="Label_Translation1">Translation</span><span id="Label_Trans1"> 1</span></h3>
  79.  
  80. <div class="Group">
  81.  
  82. <table>
  83. <tr>
  84. 	<td class="Content"><select name="SelectTargetLanguage1" id="SelectTargetLanguage1" size="1" onchange="OnChange_SelectTargetLanguage1" style="width: 20em;"></select></td>
  85. 	<td class="Spacer">&nbsp;</td>
  86. 	<td class="Content"><input type="text" name="Translation1" id="Translation1" style="width: 25em;" readonly></td>
  87. 	<td class="Spacer">&nbsp;</td>
  88. 	<td class="Control"><input type="button" class="Button" name="Button_SearchTranslation1" id="Button_SearchTranslation1" value="Search Wikipedia" onclick="OnClick_ButtonSearchTranslation1" disabled></td>
  89. </tr>
  90. </table>
  91.  
  92. </div>
  93.  
  94.  
  95.  
  96. <div id="TranslationBlock2" style="display: block;">
  97.  
  98. <h3><span id="Label_Translation2">Translation</span> 2</h3>
  99.  
  100. <div class="Group">
  101.  
  102. <table>
  103. <tr>
  104. 	<td class="Content"><select name="SelectTargetLanguage2" id="SelectTargetLanguage2" size="1" onchange="OnChange_SelectTargetLanguage2" style="width: 20em;"></select></td>
  105. 	<td class="Spacer">&nbsp;</td>
  106. 	<td class="Content"><input type="text" name="Translation2" id="Translation2" style="width: 25em;" readonly></td>
  107. 	<td class="Spacer">&nbsp;</td>
  108. 	<td class="Control"><input type="button" class="Button" name="Button_SearchTranslation2" id="Button_SearchTranslation2" value="Search Wikipedia" onclick="OnClick_ButtonSearchTranslation2" disabled></td>
  109. </tr>
  110. </table>
  111.  
  112. </div>
  113.  
  114. </div>
  115.  
  116.  
  117.  
  118. <div id="TranslationBlock3" style="display: none;">
  119.  
  120. <h3><span id="Label_Translation3">Translation</span> 3</h3>
  121.  
  122. <div class="Group">
  123.  
  124. <table>
  125. <tr>
  126. 	<td class="Content"><select name="SelectTargetLanguage3" id="SelectTargetLanguage3" size="1" onchange="OnChange_SelectTargetLanguage3" style="width: 20em;"></select></td>
  127. 	<td class="Spacer">&nbsp;</td>
  128. 	<td class="Content"><input type="text" name="Translation3" id="Translation3" style="width: 25em;" readonly></td>
  129. 	<td class="Spacer">&nbsp;</td>
  130. 	<td class="Control"><input type="button" class="Button" name="Button_SearchTranslation3" id="Button_SearchTranslation3" value="Search Wikipedia" onclick="OnClick_ButtonSearchTranslation3" disabled></td>
  131. </tr>
  132. </table>
  133.  
  134. </div>
  135.  
  136. </div>
  137.  
  138.  
  139.  
  140. <div id="TranslationBlock4" style="display: none;">
  141.  
  142. <h3><span id="Label_Translation4">Translation</span> 4</h3>
  143.  
  144. <div class="Group">
  145.  
  146. <table>
  147. <tr>
  148. 	<td class="Content"><select name="SelectTargetLanguage4" id="SelectTargetLanguage4" size="1" onchange="OnChange_SelectTargetLanguage4" style="width: 20em;"></select></td>
  149. 	<td class="Spacer">&nbsp;</td>
  150. 	<td class="Content"><input type="text" name="Translation4" id="Translation4" style="width: 25em;" readonly></td>
  151. 	<td class="Spacer">&nbsp;</td>
  152. 	<td class="Control"><input type="button" class="Button" name="Button_SearchTranslation4" id="Button_SearchTranslation4" value="Search Wikipedia" onclick="OnClick_ButtonSearchTranslation4" disabled></td>
  153. </tr>
  154. </table>
  155.  
  156. </div>
  157.  
  158. </div>
  159.  
  160. <p>&nbsp;</p>
  161.  
  162. <p class="Center"><input type="button" class="Button" name="Button_Clear" id="Button_Clear" value="Clear" onclick="OnClick_ButtonClear" disabled>
  163. <!-- IE 10 messes up spans, so we use an invisible button for spacer -->
  164. <input class="Button Hidden">
  165. <input type="button" class="Button" name="Button_Help" id="Button_Help" value="Help" onclick="HelpMsg"></p>
  166.  
  167.  
  168.  
  169. <!--{{InsertControlsHere}}-Do not remove this line-->
  170. </body>
  171. </html>

page last modified: 2024-02-26; loaded in 0.1407 seconds