paul@0 | 1 | // initial values for either Nosy, Superseder, Keyword and Waiting On, |
paul@0 | 2 | // depending on which has called |
paul@0 | 3 | original_field = form[field].value; |
paul@0 | 4 | |
paul@0 | 5 | // Some browsers (ok, IE) don't define the "undefined" variable. |
paul@0 | 6 | undefined = document.geez_IE_is_really_friggin_annoying; |
paul@0 | 7 | |
paul@0 | 8 | function trim(value) { |
paul@0 | 9 | var temp = value; |
paul@0 | 10 | var obj = /^(\s*)([\W\w]*)(\b\s*$)/; |
paul@0 | 11 | if (obj.test(temp)) { temp = temp.replace(obj, '$2'); } |
paul@0 | 12 | var obj = / /g; |
paul@0 | 13 | while (temp.match(obj)) { temp = temp.replace(obj, " "); } |
paul@0 | 14 | return temp; |
paul@0 | 15 | } |
paul@0 | 16 | |
paul@0 | 17 | function determineList() { |
paul@0 | 18 | // generate a comma-separated list of the checked items |
paul@0 | 19 | var list = new String(''); |
paul@0 | 20 | |
paul@0 | 21 | // either a checkbox object or an array of checkboxes |
paul@0 | 22 | var check = document.frm_help.check; |
paul@0 | 23 | |
paul@0 | 24 | if ((check.length == undefined) && (check.checked != undefined)) { |
paul@0 | 25 | // only one checkbox on page |
paul@0 | 26 | if (check.checked) { |
paul@0 | 27 | list = check.value; |
paul@0 | 28 | } |
paul@0 | 29 | } else { |
paul@0 | 30 | // array of checkboxes |
paul@0 | 31 | for (box=0; box < check.length; box++) { |
paul@0 | 32 | if (check[box].checked) { |
paul@0 | 33 | if (list.length == 0) { |
paul@0 | 34 | separator = ''; |
paul@0 | 35 | } |
paul@0 | 36 | else { |
paul@0 | 37 | separator = ','; |
paul@0 | 38 | } |
paul@0 | 39 | // we used to use an Array and push / join, but IE5.0 sux |
paul@0 | 40 | list = list + separator + check[box].value; |
paul@0 | 41 | } |
paul@0 | 42 | } |
paul@0 | 43 | } |
paul@0 | 44 | return list; |
paul@0 | 45 | } |
paul@0 | 46 | |
paul@0 | 47 | /** |
paul@0 | 48 | * update the field in the opening window; |
paul@0 | 49 | * the text_field variable must be set in the calling page |
paul@0 | 50 | */ |
paul@0 | 51 | function updateOpener() { |
paul@0 | 52 | // write back to opener window |
paul@0 | 53 | if (document.frm_help.check==undefined) { return; } |
paul@0 | 54 | form[field].value = text_field.value; |
paul@0 | 55 | } |
paul@0 | 56 | |
paul@0 | 57 | function updateList() { |
paul@0 | 58 | // write back to opener window |
paul@0 | 59 | if (document.frm_help.check==undefined) { return; } |
paul@0 | 60 | form[field].value = determineList(); |
paul@0 | 61 | } |
paul@0 | 62 | |
paul@0 | 63 | function updatePreview() { |
paul@0 | 64 | // update the preview box |
paul@0 | 65 | if (document.frm_help.check==undefined) { return; } |
paul@0 | 66 | writePreview(determineList()); |
paul@0 | 67 | } |
paul@0 | 68 | |
paul@0 | 69 | function clearList() { |
paul@0 | 70 | // uncheck all checkboxes |
paul@0 | 71 | if (document.frm_help.check==undefined) { return; } |
paul@0 | 72 | for (box=0; box < document.frm_help.check.length; box++) { |
paul@0 | 73 | document.frm_help.check[box].checked = false; |
paul@0 | 74 | } |
paul@0 | 75 | } |
paul@0 | 76 | |
paul@0 | 77 | function reviseList_framed(form, textfield) { |
paul@0 | 78 | // update the checkboxes based on the preview field |
paul@0 | 79 | // alert('reviseList_framed') |
paul@0 | 80 | // alert(form) |
paul@0 | 81 | if (form.check==undefined) |
paul@0 | 82 | return; |
paul@0 | 83 | // alert(textfield) |
paul@0 | 84 | var to_check; |
paul@0 | 85 | var list = textfield.value.split(","); |
paul@0 | 86 | if (form.check.length==undefined) { |
paul@0 | 87 | check = form.check; |
paul@0 | 88 | to_check = false; |
paul@0 | 89 | for (val in list) { |
paul@0 | 90 | if (check.value==trim(list[val])) { |
paul@0 | 91 | to_check = true; |
paul@0 | 92 | break; |
paul@0 | 93 | } |
paul@0 | 94 | } |
paul@0 | 95 | check.checked = to_check; |
paul@0 | 96 | } else { |
paul@0 | 97 | for (box=0; box < form.check.length; box++) { |
paul@0 | 98 | check = form.check[box]; |
paul@0 | 99 | to_check = false; |
paul@0 | 100 | for (val in list) { |
paul@0 | 101 | if (check.value==trim(list[val])) { |
paul@0 | 102 | to_check = true; |
paul@0 | 103 | break; |
paul@0 | 104 | } |
paul@0 | 105 | } |
paul@0 | 106 | check.checked = to_check; |
paul@0 | 107 | } |
paul@0 | 108 | } |
paul@0 | 109 | } |
paul@0 | 110 | |
paul@0 | 111 | function reviseList(vals) { |
paul@0 | 112 | // update the checkboxes based on the preview field |
paul@0 | 113 | if (document.frm_help.check==undefined) { return; } |
paul@0 | 114 | var to_check; |
paul@0 | 115 | var list = vals.split(","); |
paul@0 | 116 | if (document.frm_help.check.length==undefined) { |
paul@0 | 117 | check = document.frm_help.check; |
paul@0 | 118 | to_check = false; |
paul@0 | 119 | for (val in list) { |
paul@0 | 120 | if (check.value==trim(list[val])) { |
paul@0 | 121 | to_check = true; |
paul@0 | 122 | break; |
paul@0 | 123 | } |
paul@0 | 124 | } |
paul@0 | 125 | check.checked = to_check; |
paul@0 | 126 | } else { |
paul@0 | 127 | for (box=0; box < document.frm_help.check.length; box++) { |
paul@0 | 128 | check = document.frm_help.check[box]; |
paul@0 | 129 | to_check = false; |
paul@0 | 130 | for (val in list) { |
paul@0 | 131 | if (check.value==trim(list[val])) { |
paul@0 | 132 | to_check = true; |
paul@0 | 133 | break; |
paul@0 | 134 | } |
paul@0 | 135 | } |
paul@0 | 136 | check.checked = to_check; |
paul@0 | 137 | } |
paul@0 | 138 | } |
paul@0 | 139 | } |
paul@0 | 140 | |
paul@0 | 141 | function resetList() { |
paul@0 | 142 | // reset preview and check boxes to initial values |
paul@0 | 143 | if (document.frm_help.check==undefined) { return; } |
paul@0 | 144 | writePreview(original_field); |
paul@0 | 145 | reviseList(original_field); |
paul@0 | 146 | } |
paul@0 | 147 | |
paul@0 | 148 | function writePreview(val) { |
paul@0 | 149 | // writes a value to the text_preview |
paul@0 | 150 | document.frm_help.text_preview.value = val; |
paul@0 | 151 | } |
paul@0 | 152 | |
paul@0 | 153 | function focusField(name) { |
paul@0 | 154 | for(i=0; i < document.forms.length; ++i) { |
paul@0 | 155 | var obj = document.forms[i].elements[name]; |
paul@0 | 156 | if (obj && obj.focus) {obj.focus();} |
paul@0 | 157 | } |
paul@0 | 158 | } |
paul@0 | 159 | |
paul@0 | 160 | function selectField(name) { |
paul@0 | 161 | for(i=0; i < document.forms.length; ++i) { |
paul@0 | 162 | var obj = document.forms[i].elements[name]; |
paul@0 | 163 | if (obj && obj.focus){obj.focus();} |
paul@0 | 164 | if (obj && obj.select){obj.select();} |
paul@0 | 165 | } |
paul@0 | 166 | } |
paul@0 | 167 | |
paul@0 | 168 | function checkRequiredFields(fields) |
paul@0 | 169 | { |
paul@0 | 170 | var bonk=''; |
paul@0 | 171 | var res=''; |
paul@0 | 172 | var argv = checkRequiredFields.arguments; |
paul@0 | 173 | var argc = argv.length; |
paul@0 | 174 | var input = ''; |
paul@0 | 175 | var val=''; |
paul@0 | 176 | |
paul@0 | 177 | for (var i=0; i < argc; i++) { |
paul@0 | 178 | fi = argv[i]; |
paul@0 | 179 | input = document.getElementById(fi); |
paul@0 | 180 | if (input) { |
paul@0 | 181 | val = input.value |
paul@0 | 182 | if (val == '' || val == '-1' || val == -1) { |
paul@0 | 183 | if (res == '') { |
paul@0 | 184 | res = fi; |
paul@0 | 185 | bonk = input; |
paul@0 | 186 | } else { |
paul@0 | 187 | res += ', '+fi; |
paul@0 | 188 | } |
paul@0 | 189 | } |
paul@0 | 190 | } else { |
paul@0 | 191 | alert('Field with id='+fi+' not found!') |
paul@0 | 192 | } |
paul@0 | 193 | } |
paul@0 | 194 | if (res == '') { |
paul@0 | 195 | return submit_once(); |
paul@0 | 196 | } else { |
paul@0 | 197 | alert('Missing value here ('+res+')!'); |
paul@0 | 198 | if (window.event && window.event.returnvalue) { |
paul@0 | 199 | event.returnValue = 0; // work-around for IE |
paul@0 | 200 | } |
paul@0 | 201 | bonk.focus(); |
paul@0 | 202 | return false; |
paul@0 | 203 | } |
paul@0 | 204 | } |
paul@0 | 205 | |
paul@0 | 206 | /** |
paul@0 | 207 | * seeks the given value (2nd argument) |
paul@0 | 208 | * in the value of the given input element (1st argument), |
paul@0 | 209 | * which is considered a list of values, separated by commas |
paul@0 | 210 | */ |
paul@0 | 211 | function has_value(input, val) |
paul@0 | 212 | { |
paul@0 | 213 | var actval = input.value |
paul@0 | 214 | var arr = feld.value.split(','); |
paul@0 | 215 | var max = arr.length; |
paul@0 | 216 | for (i=0;i<max;i++) { |
paul@0 | 217 | if (trim(arr[i]) == val) { |
paul@0 | 218 | return true |
paul@0 | 219 | } |
paul@0 | 220 | } |
paul@0 | 221 | return false |
paul@0 | 222 | } |
paul@0 | 223 | |
paul@0 | 224 | /** |
paul@0 | 225 | * Switch Value: |
paul@0 | 226 | * change the value of the given input field (might be of type text or hidden), |
paul@0 | 227 | * adding or removing the value of the given checkbox field (might be a radio |
paul@0 | 228 | * button as well) |
paul@0 | 229 | * |
paul@0 | 230 | * This function doesn't care whether or not the checkboxes of all values of |
paul@0 | 231 | * interest are present; but of course it doesn't have total control of the |
paul@0 | 232 | * text field. |
paul@0 | 233 | */ |
paul@0 | 234 | function switch_val(text, check) |
paul@0 | 235 | { |
paul@0 | 236 | var switched_val = check.value |
paul@0 | 237 | var arr = text.value.split(',') |
paul@0 | 238 | var max = arr.length |
paul@0 | 239 | if (check.checked) { |
paul@0 | 240 | for (i=0; i<max; i++) { |
paul@0 | 241 | if (trim(arr[i]) == switched_val) { |
paul@0 | 242 | return |
paul@0 | 243 | } |
paul@0 | 244 | } |
paul@0 | 245 | if (text.value) |
paul@0 | 246 | text.value = text.value+','+switched_val |
paul@0 | 247 | else |
paul@0 | 248 | text.value = switched_val |
paul@0 | 249 | } else { |
paul@0 | 250 | var neu = '' |
paul@0 | 251 | var changed = false |
paul@0 | 252 | for (i=0; i<max; i++) { |
paul@0 | 253 | if (trim(arr[i]) == switched_val) { |
paul@0 | 254 | changed=true |
paul@0 | 255 | } else { |
paul@0 | 256 | neu = neu+','+trim(arr[i]) |
paul@0 | 257 | } |
paul@0 | 258 | } |
paul@0 | 259 | if (changed) { |
paul@0 | 260 | text.value = neu.substr(1) |
paul@0 | 261 | } |
paul@0 | 262 | } |
paul@0 | 263 | } |
paul@0 | 264 | |
paul@0 | 265 | /** |
paul@0 | 266 | * append the given value (2nd argument) to an input field |
paul@0 | 267 | * (1st argument) which contains comma-separated values; |
paul@0 | 268 | * see --> remove_val() |
paul@0 | 269 | * |
paul@0 | 270 | * This will work nicely even for batched lists |
paul@0 | 271 | */ |
paul@0 | 272 | function append_val(name, val) |
paul@0 | 273 | { |
paul@0 | 274 | var feld = document.itemSynopsis[name]; |
paul@0 | 275 | var actval = feld.value; |
paul@0 | 276 | if (actval == '') { |
paul@0 | 277 | feld.value = val |
paul@0 | 278 | } else { |
paul@0 | 279 | var arr = feld.value.split(','); |
paul@0 | 280 | var max = arr.length; |
paul@0 | 281 | for (i=0;i<max;i++) { |
paul@0 | 282 | if (trim(arr[i]) == val) { |
paul@0 | 283 | return |
paul@0 | 284 | } |
paul@0 | 285 | } |
paul@0 | 286 | feld.value = actval+','+val |
paul@0 | 287 | } |
paul@0 | 288 | } |
paul@0 | 289 | |
paul@0 | 290 | /** |
paul@0 | 291 | * remove the given value (2nd argument) from the comma-separated values |
paul@0 | 292 | * of the given input element (1st argument); see --> append_val() |
paul@0 | 293 | */ |
paul@0 | 294 | function remove_val(name, val) |
paul@0 | 295 | { |
paul@0 | 296 | var feld = document.itemSynopsis[name]; |
paul@0 | 297 | var actval = feld.value; |
paul@0 | 298 | var changed=false; |
paul@0 | 299 | if (actval == '') { |
paul@0 | 300 | return |
paul@0 | 301 | } else { |
paul@0 | 302 | var arr = feld.value.split(','); |
paul@0 | 303 | var max = arr.length; |
paul@0 | 304 | var neu = '' |
paul@0 | 305 | for (i=0;i<max;i++) { |
paul@0 | 306 | if (trim(arr[i]) == val) { |
paul@0 | 307 | changed=true |
paul@0 | 308 | } else { |
paul@0 | 309 | neu = neu+','+trim(arr[i]) |
paul@0 | 310 | } |
paul@0 | 311 | } |
paul@0 | 312 | if (changed) { |
paul@0 | 313 | feld.value = neu.substr(1) |
paul@0 | 314 | } |
paul@0 | 315 | } |
paul@0 | 316 | } |
paul@0 | 317 | |
paul@0 | 318 | /** |
paul@0 | 319 | * give the focus to the element given by id |
paul@0 | 320 | */ |
paul@0 | 321 | function focus2id(name) |
paul@0 | 322 | { |
paul@0 | 323 | document.getElementById(name).focus(); |
paul@0 | 324 | } |