/** * forms.js * * Copyright 2005 by ProStores Inc., All Rights Reserved. * * Revision history: * Date Ini Description * --------- --- ----------- * 15-Mar-02 ACB Initial version created. * 17-Apr-02 JLW Commented out show/hide of help buttons - can remove later * 17-Aug-05 JBJ Added checkAll function for checking all checkboxes on a named form. * 01-Sep-06 MGG Add method to check a string for all digits. (#15453) * 21-Feb-07 TDR Check to make sure window.events exists before accessing it (16614). */ /** * This script contains the code necessary to expand and collapse * FORM sections. */ // Initialize global form variables. var aFormSection = new Array(); var strFieldFocus = null; // Initialize form expand/collapse images. var IMAGE_COLLAPSED_FORMS = "/storeadmin/images/plus.gif"; var IMAGE_EXPANDED_FORMS = "/storeadmin/images/minus.gif"; // Cache images if (isAdmin) { expandformon = new Image(14,14); expandformon.src = imagePath + 'navdownform-on.gif'; expandformoff = new Image(14,14); expandformoff.src = imagePath + 'navdownform.gif'; collapseformon = new Image(14,14); collapseformon.src = imagePath +'navupform-on.gif'; collapseformoff = new Image(14,14); collapseformoff.src = imagePath + 'navupform.gif'; } /** * This function is the object constructor for each form section. * It is called from within the body of the form pages. */ function oDiv(strSection, strVisibility){ this.getId = strSection; this.getVisibility = strVisibility; return this; } /** * This function is the object constructor for each form field * that will be edited. * It is called from within the body of the form pages. */ function oField(strFieldLabel, strField, strSection){ this.getFieldLabel = strFieldLabel; this.getField = strField; this.getSection = strSection; return this; } /** * This function expands/collapses all sections within a form. */ function toggleForm(strAction) { var strVisibility = strAction; if (aFormSection != null && aFormSection.length > 0) { var strDisplay = ""; for (i = 1; i < aFormSection.length; i++) { var strSection = aFormSection[i].getId; if (strAction == null) strVisibility = aFormSection[i].getVisibility; else strVisibility = strAction; var strDivId = "div" + strSection; var strImgId = "img" + strSection; /**var strHelpId = "help" + strSection;*/ if (strVisibility == "collapse") { strDisplay = "none"; strImage = IMAGE_COLLAPSED_FORMS; } else { strDisplay = ""; strImage = IMAGE_EXPANDED_FORMS; } // Determine browser based upon defined objects. if(document.getElementById && document.getElementById(strDivId)) { // Browser is IE5+ or Netscape6+ document.getElementById(strDivId).style.display = strDisplay; /** document.getElementById(strHelpId).style.display = strDisplay;*/ if (document.getElementById(strImgId)) document.getElementById(strImgId).src = strImage; } else if (document.all && document.all(strDivId)) { // Browser is IE 4+: document.all(strDivId).style.display = strDisplay; /** document.all(strHelpId).style.display = strDisplay;*/ if (docuemnt.all(strImgId)) document.all(strImgId).src = strImage; } } } } /** * This function expands/collapses a specific section within a form. */ function toggleFormSection(strSection) { var strDivId = "div" + strSection; var strImageId = "img" + strSection; /**var strHelpId = "help" + strSection;*/ var strEndId = "end" + strSection // Toggle the 'display' property and the expand/collapse image. // Determine browser based upon defined objects. if(document.getElementById && document.getElementById(strDivId)) { // Browser is IE5+ or Netscape6+ if (document.getElementById(strDivId).style.display == "none") { // Section is not displayed. Make it visible. document.getElementById(strDivId).style.display = ""; /**document.getElementById(strHelpId).style.display = "";*/ document.getElementById(strImageId).src = IMAGE_EXPANDED_FORMS; // Set focus to end of section document.getElementById(strEndId).focus; } else { // Section is showing. Hide it. document.getElementById(strDivId).style.display = "none"; /**document.getElementById(strHelpId).style.display = "none";*/ document.getElementById(strImageId).src = IMAGE_COLLAPSED_FORMS; } } else if (document.all && document.all(strDivId)) { // Browser is IE 4+: if (document.all(strDivId).style.display == "none") { // Section is not display. Make it visible. document.all(strDivId).style.display = "inline"; /**document.all(strHelpId).style.display = "inline";*/ document.all(strImageId).src = IMAGE_EXPANDED_FORMS; } else { // Section is showing. Hide it. document.all(strDivId).style.display = "none"; /**document.all(strHelpId).style.display = "none";*/ document.all(strImageId).src = IMAGE_COLLAPSED_FORMS; } } } /** * This function expands a specific section within a form. */ function expandFormSection(strSection) { var strDivId = "div" + strSection; var strImageId = "img" + strSection; /**var strHelpId = "help" + strSection;*/ var strEndId = "end" + strSection // Toggle the 'display' property and the expand/collapse image. // Determine browser based upon defined objects. if(document.getElementById && document.getElementById(strDivId)) { // Browser is IE5+ or Netscape6+ if (document.getElementById(strDivId).style.display == "none") { // Section is not displayed. Make it visible. document.getElementById(strDivId).style.display = ""; /**document.getElementById(strHelpId).style.display = "";*/ document.getElementById(strImageId).src = IMAGE_EXPANDED_FORMS; // Set focus to end of section document.getElementById(strEndId).focus; } } else if (document.all && document.all(strDivId)) { // Browser is IE 4+: if (document.all(strDivId).style.display == "none") { // Section is not display. Make it visible. document.all(strDivId).style.display = "inline"; /**document.all(strHelpId).style.display = "inline";*/ document.all(strImageId).src = IMAGE_EXPANDED_FORMS; } } } /** * This function edits all required fields. */ function isValidRequiredFields(form, aRequiredField) { var REQUIRED_MESSAGE = " is a required field." var bValid = true; if (aRequiredField != null && aRequiredField.length > 0) { for (var i = 1; i < aRequiredField.length; i++) { for (var j = 0; j < form.elements.length; j++) { if (form.elements[j].name != null && (form.elements[j].name == aRequiredField[i].getField || form.elements[j].name.indexOf(aRequiredField[i].getField.toString()) != -1)) { strFieldValue = form.elements[j].value; if (isBlank(strFieldValue)) { fieldAlert(REQUIRED_MESSAGE, aRequiredField[i], form, j); bValid = false; // Present one error at a time. Jump out of required fields loop. i = aRequiredField.length; } // Found form field. Jump out of form elements loop. j = form.elements.length; } } } } return bValid; } /** * This function determines if a string contains all digits. */ function isAllDigits(strValue) { var bAlldigits = false; var nLength = strValue.length; if (nLength > 0) { bAlldigits = true; while ((bAlldigits == true) && (nLength > 0)) { nLength = nLength - 1; if(!isDigit(strValue.charAt(nLength))) bAlldigits = false; } } return bAlldigits; } /** * This function determines if a character is a digit */ function isDigit(c) { return (c >= '0' && c <= '9'); } /** * This function determines if the field passed in is blank. */ function isBlank(strValue) { var bBlank = false; if ((strValue == null) || (strValue == "")) bBlank = true; return bBlank; } /** * This function presents the user with an alert and sets focus * on the field that contains the error. The section that the * field is contained in is made visible. * . */ function fieldAlert(strErrorMsg, aField, form, j) { // Provide the user with an error message. alert(aField.getFieldLabel + strErrorMsg); // Make sure section is expanded before setting focus. expandFormSection(aField.getSection); // Set focus to field in error. form.elements[j].focus(); } /** * This function sets the form focus to the field that is specified. */ function setFieldFocus(form, strFieldFocus) { for (var j = 0; j < form.elements.length; j++) { if (form.elements[j].name == strFieldFocus) { form.elements[j].focus(); j = form.elements.length; } } } /** * This function stops the onClick event from bubbling so that the FORM * section does not expand/collapse when the help icon is clicked. */ function onHelpClick() { if (window.event) window.event.cancelBubble = true; } function ImageOn(imgDocID) { if (document.images) document[imgDocID].src = eval(imgDocID + 'on.src'); } function ImageOff(imgDocID) { if (document.images) document[imgDocID].src = eval(imgDocID + 'off.src'); } /** * This function selects or deselects all checkboxes on the form, * acording to the state of the special checkbox with id= checkSwitch * */ function checkAll(form) { checkAll(form, null); } /** * This function selects or deselects all checkboxes on the form, matching the parameter strName * acording to the state of the special checkbox with id= checkSwitch * form the form to scan * strName the matching checkbox name. Only checkboxes exactly matching this name will be modified. Null implies all checkboxes. */ function checkAll(form, strName) { if (form.checkSwitch.checked == true) { form.checkSwitch.title = "Uncheck All"; for (var i = 0; i < form.elements.length; i++) { if (form.elements[i].type == "checkbox" && (strName == null || form.elements[i].name == strName)) form.elements[i].checked = true; } } else { form.checkSwitch.title = "Check All"; for (var i = 0; i < form.elements.length; i++) { if (form.elements[i].type == "checkbox" && (strName == null || form.elements[i].name == strName)) form.elements[i].checked = false; } } } function disableButton(btnDisable) { var form = document.forms[0]; // Prevent user from clicking the specified button multiple times. // Only disable if button can actually be located. if (document.getElementById(btnDisable) != null) { document.getElementById(btnDisable).disabled = true; // Let the user know that something is happening. if (document.getElementById("divInProgressMessage") != null) document.getElementById("divInProgressMessage").style.display = "inline"; } }