document.getElementsByClassName = function(cl) {
	var retnode = [];
	var myclass = new RegExp('\\b'+cl+'\\b');
	var elem = this.getElementsByTagName('*');
	for (var i = 0; i < elem.length; i++) {
	var classes = elem[i].className;
	if (myclass.test(classes)) retnode.push(elem[i]);
	}
	return retnode;
};

function changeClassName (element, old_class, new_class){
	var str = element.className;
	var reg = new RegExp(old_class);
	element.className = str.replace(reg, new_class);	
}

function activateFormfieldSelect(elem_name, imparr){
	var opt = document.getElementsByName(elem_name)[0];
  var active_value = opt.options[opt.options.selectedIndex].value;
  var active_index = -1;
	for (i = 0; i < opt.options.length; i++){
		if (opt.options[i].value == active_value){
		  active_index = i;
		}
		else{
			//alert ("val:" + opt.options[i].value + " elem:" + imparr[0][opt.options[i].value] + ' subelemlength:' + imparr[0][opt.options[i].value].length);
			if (imparr[0][opt.options[i].value]){
        for (j = 0; j < imparr[0][opt.options[i].value].length; j++) {
          hideElement(imparr[0][opt.options[i].value][j]);
        }
      }
		}
	}
	if (imparr[0][opt.options[active_index].value]){
    for (j = 0; j < imparr[0][opt.options[active_index].value].length; j++) {
      showElement(imparr[0][opt.options[active_index].value][j]);
    }
  }
}

function activateFormfieldCheckbox(elem_name, imparr){
  var opt = document.getElementsByName(elem_name)[0];
  if (opt.checked == true){
    for (i = 0; i < imparr[0]['v1'].length; i++) {
      showElement(imparr[0]['v1'][i]);
    }
  }
  else{
    for (i = 0; i < imparr[0]['v1'].length; i++) {
      hideElement(imparr[0]['v1'][i]);
    }
  }
}

function activateFormfieldRadio(elem_name, imparr){
  var opt = document.getElementsByName(elem_name)[0];
  var active_index = -1;
  for (i = 0; i < opt.length; i++){
    if (opt[i].checked == true){
      active_index = i;
    }
    else{
      if (imparr[0][opt[i].value]){
        for (j = 0; j < imparr[0][opt[i].value].length; j++) {
          hideElement(imparr[0][opt[i].value][j]);
        }
      }
    }
  }
  if (imparr[0][opt[active_index].value] != 'undefined'){
    for (j = 0; j < imparr[0][opt[active_index].value].length; j++) {
      showElement(imparr[0][opt[active_index].value][j]);
    }
  }
}

function showElement(element){
	document.getElementById(element).style.display = "block";
}

function hideElement(element){
  document.getElementById(element).style.display = "none";
}

function getSelected(select_name){
	var opt = document.getElementsByName(select_name)[0];
	return opt.options[opt.options.selectedIndex].value;
}

function changeStep(stepsize){
  document.getElementById(imptool_questions[imptool_active_question][0]).style.display = "none";
	changeClassName(document.getElementById(imptool_questions[imptool_active_question][2]),'hl_active', 'hl_inactive');
	imptool_active_question += stepsize;
	if (imptool_active_question < imptool_questions.length){
		document.getElementById(imptool_questions[imptool_active_question][0]).style.display = "block";
		changeClassName(document.getElementById(imptool_questions[imptool_active_question][2]),'hl_inactive', 'hl_active');
	}
}
