1// Regions.js 2// ~~~~~~~~~~ 3// JavaScript functions for 'Regions' SQL database. 4// Called by the "All Country" and "All Topic" systems' index.asp. 5// Works in conjunction with data in "RegionsData.js", setup by Regions.asp. 6// Warren Blatt & Michael Tobias, Apr 2005, Mar 2015, Jun 2015 7 8 9// setRegions() 10// Populates the "Regions" <SELECT> pulldown for the given database. 11 12function setRegions(database) 13{ 14 // Special case for the JOWBR database: 15 if (database == "JOWBR") { database = "DEFAULT"; } 16 17 // Get the Regions <SELECT> pulldown: 18 var regionChooser = document.getElementById("GeoRegion"); 19 if ( ! regionChooser ) 20 { 21 // Error: This should never happen 22 return; 23 } 24 25 // Save any previously-selected item: 26 var save_selectedIndex = regionChooser.selectedIndex; 27 28 // Clear all previous settings of the Regions pulldown: 29 // *** Why? We really should be able to cache this data, 30 // and prevent unnecessary work. *** 31 regionChooser.options.length = 0; 32 33if(database!="CEMETERY"){ 34 var label = "All Regions"; 35 var value = "ALL"; 36 if(document.getElementById("CemCountryListDiv"))document.getElementById("CemCountryListDiv").style.display = "none"; 37 if(document.getElementById("CemRegionListDiv"))document.getElementById("CemRegionListDiv").style.display = "none"; 38 39 // Populate options in the Regions pulldown: 40 var index = 0; 41 for (var i = 0; i < reg_data.length; i++) 42 { 43 if ( database == reg_data[i].sys ) 44 { 45 // Get the region's label (the displayed name): 46 label = reg_data[i].lab; 47 48 // Save the top-level value: 49 if ( reg_data[i].ind == "1" ) 50 { value = reg_data[i].val; } 51 52 // For sub-regions, indent the label appropriately: 53 switch ( reg_data[i].ind ) 54 { 55 case "2": 56 label = " - - - " + label; 57 break; 58 case "3": 59 label = " - - - - - - " + label; 60 break; 61 case "4": 62 label = " - - - - - - - - - " + label; 63 break; 64 case "5": 65 label = " - - - - - - - - - - - - " + label; 66 break; 67 } 68 69 // Create an <OPTION> in the <SELECT> pulldown: 70 var y = document.createElement('span'); 71 y.innerHTML = label; 72 73 regionChooser.options[index++] = new Option (y.innerHTML, reg_data[i].val); 74 } 75 } 76 // *** Should we issue a warning if "database" not found in reg_data? (index==0) *** 77 // Provide a default option if this system has no regions: 78 if ( ! index ) 79 { regionChooser.options[0] = new Option (label, value, true, false); } 80 // Restore any previously-selected option: 81 // *** Doesn't work... value not saved. 82 // regionChooser.selectedIndex = save_selectedIndex; 83 84 // Set the sensitivity of the Regions pulldown: 85 regionChooser.disabled = ( ! index ); 86 87} else { 88 if(document.getElementById("CemRegionListDiv"))document.getElementById("CemCountryListDiv").style.display = "block"; 89 var xhr = new XMLHttpRequest(); 90 xhr.onreadystatechange = function() { 91 if (xhr.readyState === 4){ 92 const data = JSON.parse(xhr.responseText); 93 var option; 94 var dropdown = document.getElementById("CemCountryList"); 95 for (i = dropdown.options.length-1; i >= 0; i--) { 96 dropdown.options[i] = null; 97 } 98 for (var i = 0; i < data.country.length; i++) { 99 option = document.createElement('option'); 100 option.text = data.country[i]; 101 option.value = data.country[i];; 102 dropdown.add(option); 103 } 104 setCemRegion(dropdown.value) 105 106 } 107 }; 108 xhr.open('GET', '/wp_php/cemlist.php'); 109 xhr.send(); 110} 111 112} 113 114 115 116function setButtonText(ButtonID, Text) 117{ 118 var button = document.getElementById(ButtonID); 119 if ( ! button ) 120 { ; } 121 else 122 { button.value = Text; } 123} 124 125 126function setSpanText(SpanID, Text) 127{ 128 var span = document.getElementById(SpanID); 129 if ( ! span ) 130 { ; } 131 else 132 { span.innerHTML = Text; } 133} 134 135function setCemRegion(country) 136{ 137 var xhr = new XMLHttpRequest(); 138 xhr.onreadystatechange = function() { 139 if (xhr.readyState === 4){ 140 const data = JSON.parse(xhr.responseText); 141 var option; 142 var dropdown = document.getElementById("CemRegionList"); 143 for (i = dropdown.options.length-1; i >= 0; i--) { 144 dropdown.options[i] = null; 145 } 146 for (var i = 0; i < data.region.length; i++) { 147 option = document.createElement('option'); 148 option.text = data.region[i]; 149 option.value = data.region[i];; 150 dropdown.add(option); 151 } 152 setCemCity(dropdown.value); 153 if(dropdown.options.length>1) 154 if(document.getElementById("CemRegionListDiv"))document.getElementById("CemRegionListDiv").style.display = "block"; 155 else
156 if(document.getElementById("CemRegionListDiv"))document.getElementById("CemRegionListDiv").style.display = "none"; 157 } 158 }; 159 xhr.open('GET', '/wp_php/cemlist.php?country='+country); 160 xhr.send(); 161} 162function setCemCity(region) 163{ 164 165 document.getElementById("SubRegionsDiv").style.display = "block"; 166 var xhr = new XMLHttpRequest(); 167 xhr.onreadystatechange = function() { 168 if (xhr.readyState === 4){ 169 const data = JSON.parse(xhr.responseText); 170 var option; 171 var dropdown = document.getElementById("GeoRegion"); 172 for (i = dropdown.options.length-1; i >= 0; i--) { 173 dropdown.options[i] = null; 174 } 175 for (var i = 0; i < data.cem_list.length; i++) { 176 option = document.createElement('option'); 177 option.text = data.cem_list[i].city+' / '+data.cem_list[i].cem_name; 178 option.value = '01jowbr_99'+data.cem_list[i].cemeteryid; 179 dropdown.add(option); 180 } 181 document.getElementById("GeoRegion").disabled = false;; 182 } 183 }; 184 xhr.open('GET', '/wp_php/cemlist.php?country='+document.getElementById("CemCountryList").value+'®ion='+region); 185 xhr.send(); 186}
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.