function stap(stap) {
  if (stap == 'enq') {
    var a = document.getElementById('inzenden');
    if (a && a.className == 'disabled') {
      alert("Enquête nog niet compleet");
      return;
    }
  }
  document.forms[0].stap.value = stap;
  new_answers();
  document.forms[0].submit();
}

function new_answers() {
  var vragen = document.getElementById("vragen");
  
  var beroep1 = beroep();

  for (var i=0; i<vragen.childNodes.length; i++) {
    var c = vragen.childNodes[i];
    if (c.nodeType == 1 && c.tagName == 'DIV') {
      var name = c.getAttribute('id');
      var div = c.getElementsByTagName('DIV');
      for (var j=0; j<div.length; j++) {
        if (hasclass(div[j], "antw") && hasclass(div[j], "on"))
          document.forms[0][name].value = div[j].getAttribute('title');
      }
    }
  }
  var beroep2 = beroep();
  if (beroep1 != beroep2) {
    // verwijder ingevulde waarden
    var input = document.getElementsByTagName('INPUT');
    for (var i=0; i<input.length; i++) {
      var name = input[i].getAttribute('name');
      if (name.substr(3, 1) > 2) {
        input[i].setAttribute('value', '');
      }
    }
  }
}

function beroep() {
  var beroepsgroep = document.forms[0]["tab1vraag1"].value;
  if (document.forms[0]['tab2vraag1'].value == 1) {
    beroepsgroep = document.forms[0]["tab2vraag3"].value;
  }
  return beroepsgroep;
}

function popup(name, event) {
  if (event && !document.all) event.stopPropagation();
  var p = document.getElementById(name);
  if (p.style.display == "block") {
    p.style.display = "none";
  } else {
    p.style.display = "block";
  }
}

function radio_click(e) {
  if (!e) var e = window.event;
  var a = getTarget(e);
  if (a) {
    for (var i = 0; i < a.parentNode.childNodes.length; i++) {
      delclass(a.parentNode.childNodes[i], 'on');
    }
  }
  flipclass(a, 'on');
  cond_showhide(a);
  refresh_tabs(a);
}

function cond_showhide(a) {
  var value = a.getAttribute('title');
  var vraag = a.parentNode.parentNode.getAttribute('id');

  var vragen = document.getElementById("vragen");
  for (var i=0; i<vragen.childNodes.length; i++) {
    var c = vragen.childNodes[i];
    if (c.nodeType == 1 && c.tagName == 'DIV') {
      var cond = c.getAttribute('cond');
      if (cond != "") {
        if (cond == vraag + "|" + value)
          delclass(c, 'hide');
        else if(cond.split("|")[0] == vraag)
          addclass(c, 'hide');
      }
    }
  }
}

function refresh_tabs(a) {
  var vraag = a.parentNode.parentNode.getAttribute('id');
  var tabcond = document.getElementById('tabcond');
  for (var i=0; i<tabcond.childNodes.length; i++) {
    var c = tabcond.childNodes[i];
    if (c.firstChild.data == vraag) {
      new_answers();
      document.forms[0].submit();
    }
  }
}

function radio_over(e) {
  if (!e) var e = window.event;
  var a = getTarget(e);
//  a.style.color = "#f4b5a2"; 
  a.style.color = "#ffcc00"; 
}

function radio_out(e) {
  if (!e) var e = window.event;
  var a = getTarget(e);
  a.style.color = "#fff"; 
  var nested = a.getElementsByTagName('A');
  for (var i=0; i < nested.length; i++) {
    nested[i].style.color = "#ffcc00";
  }
}

function init() {
  var v = document.getElementById('vragen');
  if (v) {
    var a = v.getElementsByTagName('div');
    for (var i=0; i<a.length; i++) {
      if (hasclass(a[i], "antw") && !hasclass(a[i], "disabled")) {
        a[i].onclick = radio_click;
        a[i].onmouseover = radio_over;
        a[i].onmouseout  = radio_out;
      }
    }
  }
}

onload = init;

function popup_opmerkingen(url) {
  var w = window.open(url, "Opmerkingen", "status=0, scrollbars=0, resizable=1, left=100, top=100, width=500, height=450");
  w.focus();
}

function popup_enquete(url) {
  var w = window.open(url, "Enquete", "status=0, scrollbars=0, resizable=1, left=100, top=100, width=980, height=730");
  w.focus();
}


/*****************************************************
 * general functions
 *****************************************************/
function getTarget(e) {
	var targ;
	if (e.currentTarget) targ = e.currentTarget;
	else if (e.srcElement) targ = e.srcElement;
  return targ;
}
 
function addclass(e, c) {
  if (e.className.indexOf(c) == -1) {
    if (e.className.length > 0)
      e.className += " " + c;
    else
      e.className = c;
  }
}

function delclass(e, c) {
  if (e.className) {
  var p = e.className.indexOf(c);
  if (p >= 0)
    e.className = e.className.substr(0, p) + e.className.substr(p + c.length);
  }
}


function flipclass(e, c) {
  if (e.className.indexOf(c) == -1)
    addclass(e, c);
  else
    delclass(e, c);
}


function hasclass(e, c) {
  var p = e.className.indexOf(c);
  return (p >= 0)
}



