
/*
 * Form Utils Package
 *
 * Type:  Package
 * Name:  -
 * Purpose:  Nützliche Routinen für die Verwaltung von Formularen
 *
 */

function formElementsLoop(aForm, formFieldsRegEx, disable) {
  if (document.forms[aForm] != null) {
    with(document.forms[aForm]) {
      for (var i = 0; i < elements.length; i++) {
        if (elements[i].name.match(formFieldsRegEx)) {
          elements[i].disabled = disable;
        }
      }
    }
  }
}

/*
 * Form Disable Function
 *
 * Type:  Function
 * Name:  -
 * Purpose:  Disable bestimmte Felder, deren Namen die RegEx matched
 *
 * @param:  formName, Regex
 * @return:  -
 *
 */

function disableAll(aForm, formFieldsRegEx) {
  formElementsLoop(aForm, formFieldsRegEx, true);
}

/*
 * Form Enable Function
 *
 * Type:  Function
 * Name:  -
 * Purpose:  Enable bestimmte Felder, deren Namen die RegEx matched
 *
 * @param:  formName, Regex
 * @return:  -
 *
 */

function enableAll(aForm, formFieldsRegEx) {
  formElementsLoop(aForm, formFieldsRegEx, false);
}


/* 
	Methods to select/deselect elements of a form matching a regex. 
*/

function selectAll(aForm, formFieldsRegEx) {
	selectElementsLoop(aForm, formFieldsRegEx, true);
}

function deselectAll(aForm, formFieldsRegEx) {
	selectElementsLoop(aForm, formFieldsRegEx, false);
}


function selectElementsLoop(aForm, formFieldsRegEx, state) {
	if (document.forms[aForm] != null) {
		with(document.forms[aForm]) {
      		for (var i = 0; i < elements.length; i++) {
				if (elements[i].name) {
        			if (elements[i].name.match(formFieldsRegEx) && !elements[i].disabled) {
						elements[i].checked = state;
        			}
				}
      		}
    	}
  	}
}