function DisplayRelatedQuestions(q, r, a) {
  if (a.type == 'checkbox') {
    $A($('fq' + q).getElementsByTagName('tr')).each(function(row) {
      if (row.id.endsWith('_r' + q + '_' + r)) {
        if (a.checked) {
          $(row.id).show();
          $A($(row.id).getElementsByTagName('input')).each(function(input) {
              input.disabled = false;
          });
        } else {
          $(row.id).hide();
          $A($(row.id).getElementsByTagName('input')).each(function(input) {
              input.disabled = true;
          });
        }
      }
    });
  } else if (a.type == 'radio') {
    $A($('fq' + q).getElementsByTagName('tr')).each(function(row) {
      if (row.id.indexOf('_r' + q + '_') >= 0) {
        $(row.id).hide();
      }
      if (row.id.endsWith('_r' + q + '_' + r)) {
        if (a.checked) {
          $(row.id).show();
        } else {
          $(row.id).hide();
        }
      }
    });
  } else if (a.type == 'select-one') {
    url  = '/ajax_related_question_id.php';
    pars = {question_id:q, answer:a.value};
    new Ajax.Request(
      url,
      {
        method:'post',
        parameters:pars,
        onComplete:function(transport) {
          $A($('fq' + q).getElementsByTagName('tr')).each(function(row) {
            if (row.id.endsWith('_r' + q + '_' + transport.responseText)) {
              $(row.id).show();
            } else if (row.id.indexOf('_r' + q + '_') >= 0) {
              $(row.id).hide();
            }
          });
        }
      }
    );
  } else if (a.type == 'select-multiple') {
    $A($('fq' + q).getElementsByTagName('tr')).each(function(row) {
      if (row.id.indexOf('_r' + q + '_') >= 0) {
        $(row.id).hide();
      }
    });
    $A($(a).getElementsByTagName('option')).each(function(option) {
      url  = '/ajax_related_question_id.php';
      pars = {question_id:q, answer:option.value};
      new Ajax.Request(
        url,
        {
          method:'post',
          parameters:pars,
          onComplete:function(transport) {
            $A($('fq' + q).getElementsByTagName('tr')).each(function(row) {
              if (row.id.endsWith('_r' + q + '_' + transport.responseText)) {
                $(row.id).show();
              }
            });
          }
        }
      );
    });
  }
}
