
var ini_file = cFos_object.ini_file;
var show_prio_id = true;
var filter_key = "program_filter";
var prio_table_id = "programs";

var prio1_section = prog_prio1_section;
var prio2_section = prog_prio2_section;
var prio3_section = prog_prio3_section;
var prio4_section = prog_prio4_section;
var prio5_section = prog_prio5_section;

var suggest = true;

var np_prio = 3;

function send_prio_to_cfos(exe, desc) {
   try {
      var h = new ActiveXObject("WinHttp.WinHttpRequest.5.1");
      h.Option(0) = "add_prio_dialog"; // user agent
      var url = "http://www.cfos.de/cgi-bin/priopost.pl"
         + "?program=" + encodeURIComponent(exe)
         + "&program_name=" + encodeURIComponent(desc)
         + "&genre=" + encodeURIComponent(current_filter)
         + "&email=" + encodeURIComponent("dialog@cfos.de");
      h.Open("GET", url, false);
      h.Send();
   }
   catch (x) { }
}

function set_np_prio(p, pname) {
   np_prio = p;
   get_element("npname").innerHTML = pname;
}

function add_np() {
   var key = get_element("exefile").value;
   var idx = key.lastIndexOf('\\');
   if (idx != -1) key = key.substr(idx+1);
   if (key.charAt(1) == ':') key = key.substr(2);
   key = key.replace(/[\x00-\x1f:<>\|\?\*]/g, "");
   key = btrim(key);
   if (key == "") return;
   var exits = key in prio_items;
   if (exits) {
      var s = ml.overwrite.replace(/#p/, key);
      if (!confirm(s)) return;
      delete prio_items[key];
   }
   var desc = btrim(get_element("desc").value);
   prio_items[key] = new prio_obj(current_filter, desc, np_prio, ini_name);
   if (suggest && !exits) {
      send_prio_to_cfos(key, desc);
   }
   set_limit(key,'prog','np','tx');
   modified = true;
   load_table();
}

function browse_for_file() {
   var f = cFos_object.open_file_dialog("*.exe\0*.exe\0*.*\0*.*\0", 0);
   if (f != "") get_element("exefile").value = f.replace(/^.*\\/, "");
}

function toggle_suggest() {
   suggest = !suggest;
   get_element("suggest_prog").src = suggest ? "images/checkbox_on.png" : "images/checkbox_off.png";
}

function dialog() {
   do_resize();
   if (navigator.appVersion.indexOf("MSIE 5.") != -1)
      alert("Please install Internet Explorer 6.0 or above for this dialog.");

   read_all_prog_sections();

   var limit_class_list = cFos_object.spd_command("@limit class").split("\n");

   for (var l in limit_class_list) {
      var limit_class = limit_class_list[l];
      if (limit_class.indexOf("limit class c_prog_") != -1) {
         var class_name = limit_class.substr(19, limit_class.indexOf("-speed")-20);
         if (prio_items[class_name]) prio_items[class_name].tx_limit = limit_class.substr(limit_class.indexOf("-speed")+7);
      }
   }

   var f = new Array();
   for (var x in filters) {
      var o = new Object();
      o.trans_filter = translate_filter(x);
      o.filter = x;
      f[f.length] = o;
   }
   make_submenu(f);

   current_filter = cFos_object.param(filter_key);
   if (!filters[current_filter]) {
      for (var x in filters) {
         current_filter = x;
         break;
      }
   }
   set_filter(current_filter);
   init_radio_button("np", np_prio, true);
   load_table();
}
