function dynamicShowSections(sections, fields, labels) { try { for (var i=0;i<fields.length;i++) { addMandatory(fields[i],labels[i]); } } catch(err) { //alert("addMandatory error: " + err); //This won't apply for View Bug } if (!sections) { log("Sections undefined???"); return; } for (var i=0;i<sections.length;i++) { var sectionHead = document.getElementById(sections[i]); var sectionBody = document.getElementById(sections[i] + "_INNER"); sectionHead.style.display = "block"; sectionBody.style.display = "block"; } } function dynamicHideSections(sections, fields) { log("dynamicHideSections: starting..."); try { for (var i=0;i<fields.length;i++) { removeMandatory(fields[i]); } } catch(err) { //alert("removeMandatory error: " + err); //This won't apply for View Bug } log("dynamicHideSections: hiding sections..."); for (var i=0;i<sections.length;i++) { var sectionHead = document.getElementById(sections[i]); if (sectionHead!=null) { // might be hidden by workflow on some pages var sectionBody = document.getElementById(sections[i] + "_INNER"); sectionHead.style.display = "none"; sectionBody.style.display = "none"; } } log("dynamicHideSections: returning..."); } function showSectionsOnChange(fieldName, value, showSections, sectionMandFields, sectionMandLabels, mandFieldParents) { var fields = document.getElementsByName(fieldName); if (fields.length > 1) { //checkbox list field for (var i=0; i<fields.length;i++) { if (fields[i].value == value) { showSectionsOnChangeField(fieldName, fields[i], "##CHECKED##", showSections, sectionMandFields, sectionMandLabels, mandFieldParents); break; } } } else if (fields.length == 1) { var fieldElement = fields[0]; if (fieldElement.tagName == "DIV") { fieldElement = null; } showSectionsOnChangeField(fieldName, fieldElement, value, showSections, sectionMandFields, sectionMandLabels, mandFieldParents); } } function showSectionsOnChangeField(fieldName, fieldElement, value, showSections, sectionMandFields, sectionMandLabels, mandFieldParents) { var checkfield = fieldElement; log("showSectionsOnChange CALLED: Checking field: " + fieldName + " against val:" + value); if (!checkfield) { checkfield = getDivByName(fieldName); log("showSectionsOnChange: Checking field (by Div): " + fieldName + " against val:" + value); if (!checkfield) { return false; } } var origOnchange = checkfield.onchange; if (checkfield.hierarchy) { //in this case we've already done this at least once //so we just want to call origOnchange()... checkfield.onchange = function() { log("showSectionsOnChange FIRED, cp "+checkfield.chainPosition+": Checking field: " + fieldName + "..."); if (origOnchange) { if (!checkfield.chainPosition) { log("showSectionsOnChange FIRED, cp "+checkfield.chainPosition+": setting chainPosition"); checkfield.chainPosition = 0; checkfield.showSections = 0; checkfield.sectionMandFields = 0; checkfield.sectionMandLabels = 0; } checkfield.chainPosition++; log("showSectionsOnChange FIRED, cp "+checkfield.chainPosition+": incrementing chainPosition: " + checkfield.chainPosition); log("showSectionsOnChange FIRED, cp "+checkfield.chainPosition+": Checking field: " + fieldName + ", running origOnchange..."); var ret = origOnchange(); checkfield.chainPosition--; log("showSectionsOnChange FIRED, cp "+checkfield.chainPosition+": decrementing chainPosition: " + checkfield.chainPosition); if (ret) { //log("showSectionsOnChange: Checking field: " + fieldName + ", origOnchange returned TRUE"); if (checkfield.chainPosition == 0) { log("showSectionsOnChange A, cp "+checkfield.chainPosition+": Checking field: " + fieldName + ", chainPosition OK!"); if (mandFieldParents) { try { for (i=0;i<mandFieldParents.length;i++) { log("showSectionsOnChange FIRED, cp "+checkfield.chainPosition+": Checking field: " + fieldName + ", changeField parent: " + mandFieldParents[i]); changeField(eval("document.entry_form."+mandFieldParents[i])); } } catch (err) { log("could not update mandFieldParents... field does not exist?"); } } try { changeField(this); } catch (err) {} //return true; } //return true; } } var field = fieldElement; var viewPage = 0; var fieldVal; if (!field) { //field = document.getElementsByName(fieldName)[0]; field = getDivByName(fieldName); if (!field) { return false; } viewPage =1; //fieldVal = field.innerHTML.substring(0,field.innerHTML.length-4); fieldVal = field.innerHTML; var re=new RegExp("^<table(?:.|\n)*<td(?:.|\n)*>(.*)(?:.|\n)*$","i"); fieldVal=fieldVal.replace(re,"$1"); } else { fieldVal = field.value; //this allow showSectionsOnChange to be called for checkboxes if (value == "##CHECKED##" && field.checked) { fieldVal = "##CHECKED##"; } } log("showSectionsOnChange FIRED: Checking field: " + fieldName + ", Checking value: " + fieldVal + " - Against: " + value); if (fieldVal == value || viewPage && fieldVal.indexOf(value) >= 0) { //dynamicHideSections(sectionList,allMandFields); //log("showSectionsOnChange FIRED: Checking field: " + fieldName + ", matched value: " + value + ", showing sections"); //dynamicShowSections(showSections,sectionMandFields,sectionMandLabels); //log("showSectionsOnChange FIRED: Checking field: " + fieldName + ", matched value: " + value + ", showed sections, returning TRUE"); if (field.chainPosition == 0) { log("showSectionsOnChange FIRED, cp "+field.chainPosition+": Checking field: " + fieldName + ", matched value: " + value + ", showing sections B"); dynamicShowSections(showSections,sectionMandFields,sectionMandLabels); log("showSectionsOnChange FIRED, cp "+field.chainPosition+": Checking field: " + fieldName + ", matched value: " + value + ", showed sections, returning TRUE"); log("showSectionsOnChange B: Checking field: " + fieldName + ", chainPosition OK!"); try { changeField(field); } catch (err) {} //return true; } //we've found our value, we'll need to show these sections after the //sections for the other values have hidden themselves log("showSectionsOnChange FIRED, cp "+field.chainPosition+": Checking field: " + fieldName + ", matched value: " + value + ", remembering sections"); checkfield.showSections = showSections; checkfield.sectionMandFields = sectionMandFields; checkfield.sectionMandLabels = sectionMandLabels; //return true; } else { //why should we hide all the sections? why not show the sections //if the value is right, otherwise hide ONLY those sections //if we hide all sections it will interfere with other dynamic fields //we should let each field take care of itself //dynamicHideSections(sectionList,allMandFields); log("showSectionsOnChange FIRED, cp "+field.chainPosition+": Checking field: " + fieldName + ", did NOT match value: " + value + ", hiding sections"); dynamicHideSections(showSections,sectionMandFields); } log("showSectionsOnChange FIRED, cp "+field.chainPosition+": Checking field: " + fieldName + ", need to update parents: [" + mandFieldParents + "]"); if (field.chainPosition == 0) { if (checkfield.chainPosition == 0) { //we're back at the bottom of the chain, show the sections for the matched value log("showSectionsOnChange FIRED, cp "+field.chainPosition+": Checking field: " + fieldName + ", matched value: " + value + ", showing sections A"); if (checkfield.showSections) { dynamicShowSections(checkfield.showSections,checkfield.sectionMandFields,checkfield.sectionMandLabels); } } log("showSectionsOnChange C, cp "+field.chainPosition+": Checking field: " + fieldName + ", chainPosition OK!"); if (mandFieldParents) { try { for (i=0;i<mandFieldParents.length;i++) { log("showSectionsOnChange FIRED, cp "+field.chainPosition+": Checking field: " + fieldName + ", changeField parent: " + mandFieldParents[i]); changeField(eval("document.entry_form."+mandFieldParents[i])); } } catch (err) { log("could not update mandFieldParents... field does not exist?"); } } try { changeField(field); } catch (err) {} } } log("showSectionsOnChange: Checking field: " + fieldName + ", added onchange, running now..."); checkfield.onchange(); } else { //... but in this case we need to explicitly call changeField //because origOnchange(field) can't seem to pass the field to changeField //(I get an [object Window] instead...) if (!checkfield.chainPosition) { log("showSectionsOnChange (first) FIRED, cp "+checkfield.chainPosition+": setting chainPosition"); checkfield.chainPosition = 0; checkfield.showSections = 0; checkfield.sectionMandFields = 0; checkfield.sectionMandLabels = 0; } checkfield.hierarchy = "OK"; checkfield.onchange = function() { log("showSectionsOnChange (first) FIRED, cp "+checkfield.chainPosition+": Checking field: " + fieldName + "..."); if (origOnchange) { log("showSectionsOnChange (first) FIRED, cp "+checkfield.chainPosition+": Checking field: " + fieldName + ", running changeField..."); //changeField(checkfield); } var field = fieldElement; var viewPage = 0; var fieldVal; if (!field) { field = getDivByName(fieldName); if (!field) { return false; } viewPage =1; //fieldVal = field.innerHTML.substring(0,field.innerHTML.length-4); fieldVal = field.innerHTML; var re=new RegExp("^<table(?:.|\n)*<td(?:.|\n)*>(.*)(?:.|\n)*$","i"); fieldVal=fieldVal.replace(re,"$1"); } else { fieldVal = field.value; //this allow showSectionsOnChange to be called for checkboxes if (value == "##CHECKED##" && field.checked) { fieldVal = "##CHECKED##"; } } log("showSectionsOnChange (first) FIRED: Checking field: " + fieldName + ", Checking value: " + fieldVal + " - Against: " + value); if (fieldVal == value || viewPage && fieldVal.indexOf(value) >= 0) { //log("showSectionsOnChange (first) FIRED: Checking field: " + fieldName + ", matched value: " + value + ", showing sections"); //dynamicShowSections(showSections,sectionMandFields,sectionMandLabels); //we've found our value, we'll need to show these sections after the //sections for the other values have hidden themselves log("showSectionsOnChange FIRED, cp "+field.chainPosition+": Checking field: " + fieldName + ", matched value: " + value + ", remembering sections B"); field.showSections = showSections; field.sectionMandFields = sectionMandFields; field.sectionMandLabels = sectionMandLabels; if (checkfield.chainPosition == 0) { log("showSectionsOnChange D, cp "+field.chainPosition+": Checking field: " + fieldName + ", chainPosition OK!"); log("showSectionsOnChange (first) FIRED, cp "+field.chainPosition+": Checking field: " + fieldName + ", matched value: " + value + ", showing sections C"); dynamicShowSections(showSections,sectionMandFields,sectionMandLabels); try { changeField(field); } catch (err) {} } //log("showSectionsOnChange (first) FIRED: Checking field: " + fieldName + ", matched value: " + value + ", showed sections, returning TRUE"); return true; } else { //dynamicHideSections(sectionList,allMandFields); log("showSectionsOnChange (first) FIRED, cp "+field.chainPosition+": Checking field: " + fieldName + ", did NOT match value: " + value + ", hiding sections"); dynamicHideSections(showSections,sectionMandFields); } log("showSectionsOnChange FIRED, cp "+field.chainPosition+": Checking field: " + fieldName + ", need to update parents: [" + mandFieldParents + "]"); if (field.chainPosition == 0) { log("showSectionsOnChange E, cp "+field.chainPosition+": Checking field: " + fieldName + ", chainPosition OK!"); if (mandFieldParents) { try { for (i=0;i