PageSourceSearch

https://jewishgen.org/databases/Regions/SearchForm_solr.js

js jewishgen.org collected 2026-09-24 09:03:02 UTC 4,332 bytes, 138 lines download raw bytes

1// SearchForm_solr.js
2// ~~~~~~~~~~~~~~~~~~
3// JavaScript functions for the "All Country" and "All Topic" Database search form.
4// Warren Blatt, May 2005.
5// Updated July 2007, May 2010, Oct 2011, Jul 2013, Jun 2015
6
7// Globals:
8var num_opts   = 0;      // Number of <OPTION>s in the "Search Type" <SELECT>
9var OptsInited = false;
10
11function InitOpts(select_obj)
12{
13  num_opts = select_obj.length;
14  OptsInited = true;
15}
16
17
18// OnChange event handler for "Data Type" <SELECT> drop-down.
19//   Also called by InitSearchForm().
20function SelProc(choice, target1, target2, initialize)
21{
22  var target_opt = document.getElementById(target1);  // "Search Type" SELECT pulldown
23  var target_txt = document.getElementById(target2);  // Search text field
24
25  // First time: Find out the number of "Search Type" options, save it.
26  if ( ! OptsInited )
27    { InitOpts(target_opt); }
28
29
30  // Get the selected value of the "Data Type" <SELECT> drop-down.
31  var datatype;
32  if ( choice == null )
33    { datatype = "S"; }
34  else
35    { datatype = choice.value; }
36
37  if (datatype == "X")
38    {
39      // If DataType is "Any Field", then "Search Type" MUST be "contains".
40      target_opt.disabled = 1;   // Don't allow user to change the "Search Type"
41      // Add a new "contains" <OPTION> at the bottom:
42      target_opt.options[num_opts] = new Option ("contains", "", false, true);
43      target_txt.disabled = 0;   // Enable text field
44    }
45  else if (datatype == "")
46    {
47      // If DataType is Unselected, then disable both "Search Type" and text field.
48      target_opt.disabled = 1;
49      target_opt.selectedIndex = 0;
50      target_txt.disabled = 1;
51    }
52  else
53    {
54      // For DataTypes "Surname", "GivenName" and "Town":
55      // If initializing (and on Page Back), leave "Search Type" pulldown alone.
56      // If interactive, then set the "Search Type" pulldown to
57      //    a good default for that DataType.
58      if ( initialize == 0 )
59        {
60          if (datatype == "S")                 // Surname -
61            { target_opt.selectedIndex = 1; }  //   "Phonetically Like" (BMPM)
62          else if (datatype == "G")            // Given Name -
63            { target_opt.selectedIndex = 2; }  //   "Sounds Like" (D-M Soundex)
64          else if (datatype == "T")            // Town -
65            { target_opt.selectedIndex = 1; }  //   "Phonetically Like" (BMPM)
66		}
67
68      // Enable both the "Search Type" and search text field:
69      target_opt.disabled = 0;
70      // If a "contains" <OPTION> was added, remove it:
71      if ( target_opt.options.length == num_opts+1 )
72         { target_opt.options.length = num_opts; }
73      target_txt.disabled = 0;
74    }
75  return true;
76}
77
78
79
80function SensitizeDateOpts(val)
81{
82  document.f.Months.disabled = val;
83  document.f.Years.disabled  = val;
84}
85
86
87
88// Used as a BODY OnLoad() event handler:
89function InitSearchForm()
90{
91  //document.f.dates[0].checked = 1;  // Select "All Entries"
92  //SensitizeDateOpts(1);             // Disable Month & Year pulldowns
93  var sel1 = document.getElementById('SEL1'); SelProc(sel1, 'OPT1', 'SRCH1', 1);
94  var sel2 = document.getElementById('SEL2'); SelProc(sel2, 'OPT2', 'SRCH2', 1);
95  var sel3 = document.getElementById('SEL3'); SelProc(sel3, 'OPT3', 'SRCH3', 1);
96  var sel4 = document.getElementById('SEL4'); SelProc(sel4, 'OPT4', 'SRCH4', 1);
97  document.f.srch1.focus();
98}
99
100
101
102// Sets the value of a SELECT pulldown:
103function setOption(SelectID, Text)
104{
105  if ( ! Text ) return;
106
107  var select = document.getElementById(SelectID);
108  for (i=0; i < select.length; i++)
109    {
110      iVal = select.options[i].text.indexOf(Text);
111      if (iVal != -1)
112        {
113          // alert('Matched Text: ' + select.options[i].text);
114          select.selectedIndex = i;
115          return;
116        }
117    }
118}
119
120
121
122// Gets the value of a URL Query variable:
123function getQueryVariable(variable)
124{
125  var query = window.location.search.substring(1);
126  if ( ! query ) return;
127
128  var vars = query.split("&");
129  for (var i = 0; i < vars.length; i++)
130    {
131      var pair = vars[i].split("=");
132      if (pair[0] == variable)
133        {
134          // alert('Query Variable ' + variable + ' is ' + pair[1]);
135          return unescape(pair[1]);
136        }
137    }
138}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.