function activateFields(masterFieldId){
  var myElements = document.myForm.elements;
  for (var countAct=0;countAct< myElements.length;countAct++){
    index1 = myElements[countAct].id.indexOf(masterFieldId + '#');
    if ( index1 != -1){
          //alert(myElements[countAct].id);
          myElements[countAct].disabled=false;
          myElements[countAct].style.background='#FFFFFF';
    }
  }
  return true;
}

function deactivateFields(masterFieldId){
  var myElements = document.myForm.elements;
  var level = 1;
  var index = masterFieldId.indexOf('#');
  if (index != -1){
    level ++;
  }
  for (var countDeAct=0;countDeAct< myElements.length;countDeAct++){
    index1 = myElements[countDeAct].id.indexOf(masterFieldId + '#');
    if ( index1 != -1){
      if (level > 1){
          myElements[countDeAct].disabled=true;
          myElements[countDeAct].style.background='#E2E2E2';
      } else {
        index2 = myElements[countDeAct].id.indexOf('#',masterFieldId.length+1);
        if (index2 != -1){
          myElements[countDeAct].disabled=true;
          myElements[countDeAct].style.background='#E2E2E2';
        }
      }
    }
  }
  return true;
}

function checkCheckbox(masterFieldId){
  theCheckbox  = document.getElementById(masterFieldId);
  if (theCheckbox.checked == true){
    activateFields(masterFieldId);
  }else{
    deactivateFields(masterFieldId);
  }
  return true;
}

/*function checkRadio(masterFieldId){
  masterMasterFieldId = masterFieldId.substring(0,masterFieldId.indexOf('#'));
  deactivateFields(masterMasterFieldId);
  activateFields(masterFieldId);
  return true;
}*/

function checkRadio(masterFieldId){
  masterMasterFieldId = masterFieldId.substring(0,masterFieldId.indexOf('#'));
  theRadioButton = document.getElementById(masterFieldId);
  deactivateFields(masterMasterFieldId);
  if(theRadioButton.checked == true) {
  	activateFields(masterFieldId);
  }
  return true;
}


function checkSelect(masterFieldId){
  deactivateFields(masterFieldId);
  mySelectBox = eval('document.myForm.' + masterFieldId);
  if (mySelectBox.options!=null){
    theSelectedIndex = mySelectBox.selectedIndex;
    if (theSelectedIndex != null){
      activateFields(mySelectBox.options[theSelectedIndex].id);
    }
  }
  return true;
}


function initializeForm2(){
	var myElements = document.myForm.elements;
	for (var countInit=0;countInit< myElements.length;countInit++){
  	theElement = myElements[countInit];
    var index1 = theElement.id.indexOf('#');
    var index2 = theElement.id.substring(index1+1,theElement.id.length).indexOf('#');
    if(index1 != -1 && index2 == -1) {
        if (theElement.type == 'radio'){
        	checkRadio(theElement.id);
        } else if (theElement.type == 'checkbox'){
        	checkCheckbox(theElement.id);
        }
    }
    if(theElement.type == 'select-one' && index1 == -1) {
    	checkSelect(theElement.name);
    }

  }
}


