
var ole_object = "cFosSpeed.Config";
var cFos_object = null;
try {
   if (window.location.href.replace(/\?.*$/, "").match(/\.cfhta$/i)) cFos_object = new ActiveXObject(ole_object);
}
catch(x) {
   alert(ole_object + "\n\n" + x.message + "\n\n" + ml_object.ole_error);
   window.close();
}

if (cFos_object) {   // we are in HTA mode
   try { window.resizeTo(820, 580); } catch (x) { }
}

if (navigator.userAgent.indexOf("Trident/") == -1 && cFos_object)
   alert("Please install Internet Explorer 8.0 or above for this dialog.");

jQuery.fn.center = function() {   // thanks to Tony L. @ stackoverflow
   this.css("position","absolute");
   this.css("top", Math.max(0, ($(window).height() - this.outerHeight()) / 2 + $(window).scrollTop()) + "px");
   this.css("left", Math.max(0, ($(window).width() - this.outerWidth()) / 2 + $(window).scrollLeft()) + "px");
   return this;
}

jQuery.fn.scrollIntoView = function() {
   for (var i=0; i < this.length; ++i) this[i].scrollIntoView();
   return this;
}

function os_version() {
   var m = navigator.userAgent.match(/Windows NT (\d+)\.(\d+)/);
   if (m == null) return 0;
   return Number(m[1])*100 + Number(m[2]);
}

var prio_names = ["", ml_object.prio_lowest, ml_object.prio_low, ml_object.prio_normal, ml_object.prio_high, ml_object.prio_higher];
var clicked_el = null;

function show_prio(page_x) {
   var el = $(clicked_el);
   var pos = el.offset();
   var w = el.width();
   var prio = (5*(page_x - pos.left)/w).toFixed(0);
   ++prio;
   if (prio < 1) prio = 1;
   else if (prio > 5) prio = 5;
   clicked_el.src = 'images/prio_' + prio + '_a.png';
   clicked_el.alt = prio_names[prio];
   $(clicked_el).next().text(prio_names[prio]);
   return prio;
}

var mouse_evt_obj = {  // return false to stop further event processing
   dragstart: function(e) {
      if (e.target.tagName.toLowerCase() != "img") return true;
      return false;
   },
   mouseup: function(e) {
      if (!clicked_el) return false;
      if ($(clicked_el).is("img.set_prio")) clicked_el.src = clicked_el.src.replace("_a.", ".");
      var ret = e.data.mouse_up_handler(e);
      clicked_el = null;
      return ret;
   },
   mousedown: function(e) {
      if (e.target.tagName.toLowerCase() != "img") return true;
      clicked_el = e.target;
   },
   mousemove: function(e) {
      if (!clicked_el) return false;
      if (clicked_el.tagName.toLowerCase() != "img" || clicked_el.src.indexOf("prio_") == -1) return true;
      e.data.mouse_up_handler(e);
      return false;
   }
};

function open_url(u) {
   var s = new ActiveXObject("Shell.Application");
   s.ShellExecute("explorer.exe", u, "", "open", 1);
}
