
// ++ outils de gestion des pages de classification ++

var y_status = {base: "hmt_cla.htm", cla:"", aut:"", aut_sel:-1};

function parseLocation() {
    if (location.href.indexOf("?") == -1) {
      y_status.base = location.href;
      return 0;
    }

    locQuery = location.href.split("?");

    y_status.base = locQuery[0];
    locElements = locQuery[1].split(",");

    if (locElements[0] != null) {
      y_status.cla = locElements[0];
      }
    if (locElements[1] != null) {
      y_status.aut     = unescape( locElements[1] );
      y_status.aut_sel = parseInt( locElements[2] );
      }

    return 1;
}

function go_subdiv(subdiv)
{
  var aut_status = get_aut_value();
  var newURL = y_status.base + "?" + subdiv + "," + escape(aut_status.init) + "," + aut_status.sel;
  location.href = newURL; // -- to go to selected page --
  return null;
}


function create_title()
{
  // ++ not used ++
  var d = ""; // to store new document 
  var w_cla = d_cla[y_status.cla];

  if (w_cla) {
    if(w_cla.c.length > 0) {
      d += "<p class=\"hkb-tit\"><span class=\"hkb-tit\">" + w_cla.c + ": " + w_cla.lbl + "</span></p>";
      }
    }
  else {
    d += "<p class=\"hkb-err-s\">?? Problem #41 with: " + y_status.cla + " ??<p>";
    }

  self.document.write(d);
}


function edit_classif(cla_descr) {
  var cla_edit = ""; // to store doc. element 

  if( cla_descr.c == "") {
    cla_edit = cla_descr.lbl;
    }
  else {
    cla_edit = cla_descr.c + ": " + cla_descr.lbl;
    }

  return cla_edit;
}


function edit_class_link(cla_id, cla_txt) {
  var s_link = ""; // to store output 

  s_link += "<a href=\"javascript: go_subdiv('" + cla_id +"');\">" + cla_txt + "</a>";
  return s_link;
}


function edit_input(cla_code, checked) {
  var tag_input = ""; // to store output 

  tag_input += "<input type=\"checkbox\" name=\"qacla\" value=\"" + cla_code + "\"";
  
  if (checked) {
    tag_input += " checked";
    }

  tag_input += ">";
  
  return tag_input;
}


function edit_start_lvl_block(lvl) {
  var d = ""; // to store output 

  var lvl_class = "hkb-lvl-" + lvl
  
  d += "<p class=\"" + lvl_class + "\">" + "<span class=\"" + lvl_class + "\">";

  return d;
}


function edit_end_lvl_block() {
  var d = "</span></p>\n"; // to store output 
  return d;
}


function edit_waut_link() {
  var d = "<img alt=\"+AUT\" src=\"i_waut.png\">"
  return d;
}


function create_see_link(cla_descr) {
  var d = ""; // to store doc. element 
  var xx = 0; // to make it local 
  var lbl_see = "siehe "; 
  
  if (language == 'e') lbl_see = "see "; 
  if (language == 'f') lbl_see = "voir "; 
  if (language == 'g') lbl_see = "siehe "; 

  if (cla_descr.see && cla_descr.see.length > 0) {
    for( xx=0; xx < cla_descr.see.length; xx++) {
      a_see = cla_descr.see[xx].split(':');
      img_see = "<img alt=\"->\" src=\"i_see.gif\">";
      see_lbl = a_see[2] + ": " + img_see + edit_class_link(a_see[0], lbl_see + a_see[1]);
      d += "<p class=\"hkb-see\">";
      d += "<span class=\"hkb-see\">" + see_lbl + "</span></p>\n";
      }
    }

  return d
}


function create_parent_elem(c_cla, first) {
  var d = ""; // to store doc. element 
  var cla_descr = d_cla[c_cla];

  if (! cla_descr) {
    d += "<p class=\"hkb-err-s\">Problem #31 with: " + c_cla + " () !</p>\n";
    }
  else {
    if (cla_descr.up != "/") {
      d += create_parent_elem(cla_descr.up, 0);
      }
    var z_space = "<img alt=\"&nbsp;\" src=\"i_space.gif\">";
    if (first) {
      d += edit_start_lvl_block(cla_descr.lvl) + z_space;
      if (! cla_descr.ch) { 
        d += edit_input(cla_descr.c, 1);
        }
      d += edit_classif(cla_descr);

      d += edit_end_lvl_block()

      }
    else {
      d += edit_start_lvl_block(cla_descr.lvl) + z_space + edit_class_link(c_cla, edit_classif(cla_descr)) + edit_end_lvl_block();
      }
    }

  return d
}


function create_subdiv()
{
  var d = ""; // to store new document 
  var xx = 0; // to make it local 

  var w_cla = d_cla[y_status.cla];

  if (! w_cla) {
    d += "<p class=\"hkb-err-s\">?? Problem #19 with: " + y_status.cla + " ??</p>\n";
    }
  else {
    d += create_parent_elem(y_status.cla, 1)
    var l_choice = w_cla.ch;
    if (l_choice && l_choice.length > 0) {
      for( xx=0; xx < l_choice.length; xx++) {
        var k_cla = l_choice[xx];
        var ch_cla = d_cla[k_cla];
	if (! ch_cla) {
	  d += "<p class=\"hkb-err-s\">?? Problem #21 with choice " + k_cla + " (undefined?) ??</p>\n";
	  }
	else {
	  li_entry = edit_start_lvl_block(ch_cla.lvl);
	  // -- select for selectable or not; either a hardcoded rule, either a new field in hmt_cla --
	  if (k_cla.length == 6 || k_cla.length == 2) {
	    li_entry += edit_input(ch_cla.c)
	    }
          else {
	    // -- li_entry += "<span call=\"hkb-pseudo-radio\">\xA0\xA0\xA0</span>";
	    li_entry += "<img alt=\"&nbsp;\" src=\"i_check_dummy.gif\">";
	    }
	  // -- complete choice with link (if choices exists) --
	  if (ch_cla.ulk) {
	    d += li_entry + edit_class_link(k_cla, edit_classif(ch_cla));
	    }
	  else {
	    d += li_entry + edit_classif(ch_cla);
	    }

	  // -- if (ch_cla.waut) {
	  // --   d += edit_waut_link();
	  d += edit_end_lvl_block();

	  d += create_see_link(ch_cla);
	  }
        }
      }
    }

  self.document.write(d);
}


function cla_sel_all(form, mode) {
  var c_nm = 0, ii = 0 ;
  for(ii=0; ii<form.elements.length; ii++) 
  {
    form.elements[ii].checked = mode;
  }
}

