//=====================
// Copyright (c) 2004-2005
// Fastpath
// http://www.jivesoftware.com
//=====================

// Array of all open windows
var windows = new Array();

// Checks to see if a window exists
function windowExists(name) {

  for (var i = 0; i < windows.length; i++) {

    // IE needs a try/catch here for to avoid an access violation on windows[i].name
    // in some cases.
    try {
      if (windows[i].name == name) {
        return true;
      }
    }
    catch (exception) {
    }
  }

  return false;
}

// Returns the window object - returns nothing if not found.
function getWindow(name) {

  for (var i = 0; i < windows.length; i++) {
    try {
      if (windows[i].name == name) {
        return windows[i];
      }
    }
    catch (exception) {
    }
  }
}

// Open a window given its unique name, url, width and height.
function launchWin(name, url, width, height) {

  var defaultOptions = "location=no,status=no,toolbar=no,personalbar=no,menubar=no,directories=no,";
  var winleft = (screen.width - width) / 2;
  var winUp = (screen.height - height) / 2;

  defaultOptions += "scrollbars=no,resizable=yes,top=" + winUp + ",left=" + winleft + ",";
  defaultOptions += "width=" + width + ",height=" + height;
  launchWinWithOptions(name, url, defaultOptions);
}

// Open a window with given name, url, and options list
function launchWinWithOptions(name, url, options) {

  if (! windowExists(name)) {
    var winVar = window.open(url, name, options);
    windows[windows.length] = winVar;
    return winVar;
  }
  else{
    var theWin = getWindow(name);
    theWin.focus();
  }
}

document.write(
   "<a href=\"#\" onclick=\"launchWin(\'framemain\', '//jabber.iv.lt/webchat/start.jsp?workgroup=support@workgroup.jabber.iv.lt&location=" + (typeof(jabberLocation) == "undefined" ? window.location.href : jabberLocation) + "', 500, 400); return false;\"><img border=\"0\" src=\"//jabber.iv.lt/webchat/live?action=isAvailable&workgroup=support@workgroup.jabber.iv.lt"  + (typeof(jabberOnline) == "undefined" ? "" : "&online=" + jabberOnline) + (typeof(jabberOffline) == "undefined" ? "" : "&offline=" + jabberOffline) + "\"></a>"
);
