// Dette bibliotekt skal indeholde funktioner til at finde felter, aflæse feltværdier og validere felter // function getFrameAnonymous(field) { switch (field.type) { case 'text' : return getFrameValue(field); break; case 'textarea' : return getFrameValue(field); break; case 'checkbox' : return getFrameCheckbox(field); break; case 'radio' : return getFrameRadio(field); break; case 'select-one' : return getFrameSelect(field); break; case 'select-multiple' : return getFrameSelect(field); break; default : return ''; } }; function getAnonymous(fieldname) { var field = getField(fieldname) switch (field.type) { case 'text' : return getValue(fieldname); break; case 'textarea' : return getValue(fieldname); break; case 'checkbox' : return getCheckbox(fieldname); break; case 'radio' : return getRadio(fieldname); break; case 'select-one' : return getSelect(fieldname); break; case 'select-multiple' : return getSelect(fieldname); break; default : return ''; } }; function getFrameRadio(radio) { var field; if (radio == undefined) return ''; if (radio.length == undefined) { // only one option return getField(fieldname).value; } else { for (var i = 0 ; i < radio.length ; i++) { field = getField(fieldname + '[' + i + ']'); if (field.checked) return field.value; } } return ''; }; function getRadio(fieldname) { var field, radio = getField(fieldname); if (radio == undefined) return ''; if (radio.length == undefined) { // only one option return getField(fieldname).value; } else { for (var i = 0 ; i < radio.length ; i++) { field = getField(fieldname + '[' + i + ']'); if (field.checked) return field.value; } } return ''; }; function getFrameCheckbox(checkbox) { result = new Array(); var count, field; if (checkbox == undefined) return ''; if (checkbox.length == undefined || checkbox.length == 1) { if (checkbox.checked) return checkbox.value; } else { count = 0; for (var i = 0 ; i < checkbox.length ; i++) { field = getField(fieldname + '[' + i + ']'); if (field.checked) { result[count] = field.value; count++; } } } return result; }; function getCheckbox(fieldname) { result = new Array(); var count, checkbox = getField(fieldname), field; if (checkbox == undefined) return ''; if (checkbox.length == undefined || checkbox.length == 1) { if (checkbox.checked) return checkbox.value; } else { count = 0; for (var i = 0 ; i < checkbox.length ; i++) { field = getField(fieldname + '[' + i + ']'); if (field.checked) { result[count] = field.value; count++; } } } return result; }; function getFrameSelect(field) { result = new Array(); var index, count, index; if (field == undefined) return ''; if (field.type == 'select-one') { index = field.selectedIndex; if (field.options[index].value != '') return field.options[index].value; else return field.options[index].text; } else if (field.type == 'select-multiple') { count = 0; for (var i = 0 ; i < field.length ; i++) { if (field.options[i].selected) { if (field.options[i].value != '') result[count] = field.options[i].value; else result[count] = field.options[i].text; count++; } } return result; } else return ''; }; function getSelect(fieldname) { result = new Array(); var index, count, field = getField(fieldname), index; if (field == undefined) return ''; if (field.type == 'select-one') { index = field.selectedIndex; if (field.options[index].value != '') return field.options[index].value; else return field.options[index].text; } else if (field.type == 'select-multiple') { count = 0; for (var i = 0 ; i < field.length ; i++) { if (field.options[i].selected) { if (field.options[i].value != '') result[count] = field.options[i].value; else result[count] = field.options[i].text; count++; } } return result; } else return ''; }; function getFrameValue(field) { if (field != undefined) return field.value; return ''; }; function getValue(fieldname) { var field = getField(fieldname); if (field != undefined) return field.value; return ''; }; function setValue(fieldname, fieldvalue) { var field = getField(fieldname); if (field != undefined) field.value = fieldvalue; }; function toArray(values, separator) { if (values == '') return new Array(); return values.split(separator); }; function getField(fieldname) { var field; for (var i = 0 ; i < document.forms.length ; i++) { field = eval('document.forms[' + i + '].' + fieldname); if (field != undefined) return field; } try { for (var i = 0 ; i < window.opener.document.forms.length ; i++) { field = eval('window.opener.document.forms[' + i + '].' + fieldname); if (field != undefined) return field; } } catch (e) { return undefined; } }; function getElement(id) { var element = document.getElementById(id); if (element == null) return undefined; return element; }; function getSelectByID(id) { result = new Array(); var index, count, field = getElement(id), index; if (field == undefined) return ''; if (field.type == 'select-one') { index = field.selectedIndex; if (field.options[index].value != '') return field.options[index].value; else return field.options[index].text; } else if (field.type == 'select-multiple') { count = 0; for (var i = 0 ; i < field.length ; i++) { if (field.options[i].selected) { if (field.options[i].value != '') result[count] = field.options[i].value; else result[count] = field.options[i].text; count++; } } return result; } else return ''; }; function getCheckboxByID(id) { result = new Array(); var count, checkbox = getField(id), field; if (checkbox == undefined) return ''; if (checkbox.length == undefined || checkbox.length == 1) { if (checkbox.checked) return checkbox.value; } else { count = 0; for (var i = 0 ; i < checkbox.length ; i++) { field = getField(fieldname + '[' + i + ']'); if (field.checked) { result[count] = field.value; count++; } } } return result; }; function getRadioByID(id) { var field, radio = getField(id); if (radio == undefined) return ''; if (radio.length == undefined) { // only one option return getField(fieldname).value; } else { for (var i = 0 ; i < radio.length ; i++) { field = getField(fieldname + '[' + i + ']'); if (field.checked) return field.value; } } return ''; };