var tab_categs_id = new Array();
var tab_categs_names = new Array();
var news_pdf_path = "<?php echo MAIN_PATH.NEWS_PATH_PDF; ?>";
var timestamp = "<?php echo $timestamp; ?>";
var id_object = "<?php echo $id_object; ?>";
var news_admin_path = "<?php echo MAIN_PATH; ?><?php echo NEWS_ADMIN_PATH; ?>";
var main_div_name = "<?php echo MAIN_DIV_NAME; ?>";
var page_to = "<?php echo $page_to; ?>";

function addEvent(elem, type, func)
{
  if (elem.addEventListener)
     elem.addEventListener(type, func, true);
  else if (elem.attachEvent)
  {
    callback = function()
    {
      func.apply(elem, new Array());
    }
    elem.attachEvent('on'+type, callback);
  }
}

function aff_list_categories(selected)
{
  var page_to_call = document.getElementById('page_to_call').innerHTML;
  page_to_call = decodeURIComponent(page_to_call);
  var nb_max = document.getElementById('categs_nb_max').value;
  nb_max = (nb_max * 1) + 1;
  document.getElementById('categs_nb_max').value = nb_max;


  var obj_tr = document.createElement("tr");
  var obj_td = document.createElement("td");
  obj_td.style.verticalAlign = "top";


  var obj_td_two = document.createElement("td");
  obj_td_two.style.verticalAlign = "top";
  obj_td_two.setAttribute("id", "td"+nb_max);


  var new_obj = document.createElement("select");
  new_obj.setAttribute("name", "categs_"+nb_max);
  new_obj.setAttribute("id", nb_max);
  new_obj.setAttribute("style", "font-size:12px; font-family:Arial;");
  addEvent(new_obj, "change", update_list_categories);

   var element = document.createElement("option");
   var text = document.createTextNode(tab_title);
   element.appendChild(text);
   element.value = "";
   new_obj.appendChild(element);
  for (var i = 0; i < tab_categs_id.length; i++)
  {
     element = document.createElement("option");
     text = document.createTextNode(tab_categs_names[i]);
     element.appendChild(text);
     if (selected != null && (tab_categs_id[i] == selected))
        element.selected = true;
     element.value = tab_categs_id[i];
     new_obj.appendChild(element);
  }

  obj_td.appendChild(new_obj);
  obj_tr.appendChild(obj_td);
  obj_tr.appendChild(obj_td_two);
  document.getElementById('categs_container').appendChild(obj_tr);
  if (selected != null)
     ajaxGET(page_to_call+"&id="+selected, "td"+nb_max);
}

function update_list_categories(evt)
{
  var page_to_call = document.getElementById('page_to_call').innerHTML;
  page_to_call = decodeURIComponent(page_to_call);
  cur_categ = (this.id * 1);
  var nb_max = document.getElementById('categs_nb_max').value;
  if (nb_max == cur_categ && tab_categs_id.length > (nb_max * 1))
  {
    aff_list_categories(0);
  }
  ajaxGET(page_to_call+"&id="+this.value, "td"+cur_categ);
}
