
  addLoadEvent(pre_load_imgs);

  function pre_load_imgs()
  { (new Image()).src = "/simtic-share/cms/admin/images/disconnect_over.gif";
  }

  function confirm_dialog(message, url) { if(confirm(message)) window.location = url; }

  function js_choose_dialog(message, js_yes, js_cancel)
  { if(confirm(message)) eval(js_yes);
    else eval(js_cancel);
  }

  function check_keycount(obj, item, max)
  { size_ok = obj.value.length <= max;
    if(!size_ok)
	{ obj.value = obj.value.substr(0, max);
	  alert("maximum " + max + " caractères.");
	}
    document.getElementById(item + "_counter").innerHTML = obj.value.length;
    return size_ok;
  }
  
  function save_jxhtmledit_content()
  { try { document.edit_form.contenu.value=document.jxhtmleditA.getCode(); }
	catch(er) { document.edit_form.contenu.value=document.jxhtmleditB.getCode(); }
  }

  function type_selected(type)
  { SHOW = type == "choix";
	try
    { if(SHOW)
	  { th_choix = document.createElement("th");
        td_choix = document.createElement("td");
        document.getElementById("tr_choix").appendChild(th_choix);
        document.getElementById("tr_choix").appendChild(td_choix);
        th_choix.id = "th_choix";
        td_choix.id = "td_choix";
        th_choix.appendChild(document.createTextNode('choix parmis'));
        a_new_choix = document.createElement("a");
        td_choix.appendChild(a_new_choix);
        a_new_choix.appendChild(document.createTextNode("ajouter un choix"));
        a_new_choix.href = "javascript:new_choix();";
        for(i = 0; i < possibles.length; i++) new_choix(possibles[i]);
      }
	  else
	  { if(document.getElementById("tr_choix"))
	    { document.getElementById("tr_choix").removeChild(document.getElementById("th_choix"));
	      document.getElementById("tr_choix").removeChild(document.getElementById("td_choix"));
        }
	  }
    }
	catch(e) {}
  }

  var current_choix_id = 0;
  var possibles = Array();

  function new_choix(possible)
  { mah_td = document.getElementById("td_choix");
	br = document.createElement("br");
    br.id = "br_possible_" + current_choix_id;
    input = document.createElement("input");
    input.type = "text";
	input.name = "possible[]";
    mah_td.appendChild(br);
    mah_td.appendChild(input);
    input.id = "possible_" + current_choix_id;
    if(possible != undefined) input.value = possible;
    a_del_choix = document.createElement("a");
    mah_td.appendChild(a_del_choix);
    a_del_choix.appendChild(document.createTextNode("supprimer"));
    a_del_choix.id = "a_possible_" + current_choix_id;
    a_del_choix.href = "javascript:del_choix('" + current_choix_id + "');";
	current_choix_id += 1;
	input.focus();
  }
  
  function del_choix(id)
  { mah_td = document.getElementById("td_choix");
    mah_td.removeChild(document.getElementById("br_possible_" + id));
    mah_td.removeChild(document.getElementById("possible_" + id));
    mah_td.removeChild(document.getElementById("a_possible_" + id));
  }

  function addLoadEvent(func)
  { var oldonload = window.onload;
    if(typeof window.onload != 'function') window.onload = func;
    else
    { window.onload = function()
      { if(oldonload) oldonload();
        func();
      }
    }
  }