// Disable and Enable Fields f40_Part1 (15-09-2005)
// by Vic Phillips http://www.vicsjavascripts.org.uk/

// Disable and Enable Form Elements from a CheckBox
// TextBoxes, Checkboxs, Radio Buttons, Select Lists & TextAreas
// Options to 'Disable' when 'checked' or  'Enable' when 'checked'
// As many and nested application as required on a page.

// Application Notes

// The elements to be controlled must be nested in an element

// For localised application
// the controlling checkbox may be nested in the same element
// In which case the controlling check box must include the onclick event call
// onclick="f40_Disable(null,this,true);"
// Only the last parameter of the call requires customising to 'true' or 'false'
// true  = if the checkbox is checked the elements will be 'disabled';
// false = if the checkbox is checked the elements will be 'enabled';
// Example HTML Code
// <span >
// <input type="checkbox" name=""  >
// <input type="text" name=""  >
// <select ><option>Select</option></select>
// <input type="checkbox" name="" onclick="f40_Disable(null,this,true);" > Disable/Enable
// </span>

// For more global applications
// the controlling checkbox may be positioned anywhere
// In which case the controlling check box must include the onclick event call
// onclick="f40_Disable(null,this,true);"
// e.g. onclick="f40_Disable('*ID*',this,true);"
// where
// *ID* = the unique ID of the top level parent element
// The last parameter of the call requires customising to 'true' or 'false'
// true  = if the checkbox is checked the elements will be 'disabled';
// false = if the checkbox is checked the elements will be 'enabled';
// Example HTML Code
// <form id="MyForm">
// <span >
// <input type="checkbox" name="" disabled="disabled" >
// <input type="text" name="" disabled="disabled" >
// <select disabled="disabled" ><option>Select</option></select>
// <input type="checkbox" name="" onclick="f40_Disable(null,this,false);" > Enabled (Local)
// </span>
// <br>
// <span >
// <input type="checkbox" name=""  >
// <input type="text" name=""  >
// <select ><option>Select</option></select>
// <input type="checkbox" name="" onclick="f40_Disable(null,this,true);" > Disable (Local)
// </span>
// <br>
// <input type="checkbox" name="" onclick="f40_Disable('MyForm',this,true);" > Disable (Global)
// </form>


// The functional code f40_Part1 (about 1.0K) is best as an external JavaScript

// All variable, function etc. names are prefixed with 'f40_' to minimise conflicts with other javascripts


// Functional Code -  NO NEED to Change

function f40_Disable(f40_par,f40_obj,f40_state){
 if (f40_par){f40_clds=f40_AllElements(document.getElementById(f40_par)); }
 else { f40_clds=f40_AllElements(f40_obj.parentNode); }
 if (!f40_obj.ary){
  f40_obj.ary=new Array();
  for (f40_0=0;f40_0<f40_clds.length;f40_0++){
   if (f40_clds[f40_0].tagName=='INPUT'||f40_clds[f40_0].tagName=='SELECT'||f40_clds[f40_0].tagName=='TEXTAREA'){
    f40_obj.ary[f40_obj.ary.length]=f40_clds[f40_0];
   }
  }
 }
 for (f40_1=0;f40_1<f40_obj.ary.length;f40_1++){
  f40_obj.ary[f40_1].removeAttribute('disabled');
 }
 if (f40_obj.checked==f40_state){
  for (f40_2=0;f40_2<f40_obj.ary.length;f40_2++){
    f40_obj.ary[f40_2].setAttribute('disabled','disabled');
  }
 }
 f40_obj.removeAttribute('disabled');
}

function f40_AllElements(f40_){
  if (f40_.all){ return f40_.all; }
  return f40_.getElementsByTagName('*');
}

//-->
