















// check for browser families
var _platformSupported = false;
var _userAgent = navigator.userAgent;
var _isOP = _userAgent.indexOf("Opera") != -1;
var _isIE = !_isOP && navigator.appName.indexOf("Microsoft") != -1;
var _isNN = false;
var _isMZ = false;
var _isSF = false;
if(!(_isOP||_isIE)) {
  if(_userAgent.match(/^Mozilla\//)) {
    if(_userAgent.match(/rv:\d+(\.\d+)?/)) {
      if(_userAgent.match(/Netscape\//)) {
        _isNN = true;
      }
      else {
        _isMZ = true;
      }
    }
    else if(_userAgent.match(/Safari\//)) {
      _isSF = true;
    }
    else {
      _isNN = true;
    }
  }
}

//
// localizable strings
//
var STR_INSTALL_PLATFORM        = "Platform";
var STR_INSTALL_PLATFORM_INFO   = "Web Conferencing requires Microsoft Windows 98, Windows Me, Windows NT 4.0 Service Pack 4, Windows 2000, Windows XP, or higher.";
var STR_INSTALL_UNKNOWN_SYSTEM  = "Unknown system";

var STR_INSTALL_RESOLUTION      = "Resolution";
var STR_INSTALL_RESOLUTION_VALUE = "WIDTH x HEIGHT";
var STR_INSTALL_RESOLUTION_INFO = "Web Conferencing requires system resolution to be set at 1024x768 pixels or higher.";

var STR_INSTALL_BROWSER         = "Browser";
var STR_INSTALL_BROWSER_INFO    = "Web Conferencing requires Internet Explorer 5.5 or higher.";
var STR_INSTALL_UNKNOWN_BROWSER = "Unknown browser";

var STR_INSTALL_JAVA            = "Java";
var STR_INSTALL_JAVA_INFO       = "Document Presentation is not available when JAVA is not enabled or when JAVA is not properly configured in the browser.";
var STR_INSTALL_ENABLED         = "Enabled";
var STR_INSTALL_DISABLED        = "Disabled";

var STR_INSTALL_FAILED          = "Failed";
var STR_INSTALL_SUCCESSFUL      = "Successful";
var STR_INSTALL_UNAVAILABLE     = "Unavailable";
var STR_INSTALL_INSTALLED       = "Installed";
var STR_INSTALL_NOT_INSTALLED   = "Not installed";
var STR_INSTALL_SUFFICIENT      = "Sufficient";
var STR_INSTALL_INSUFFICIENT    = "Insufficient";
var STR_INSTALL_UNAVAIL_INFO    = "Need to download console to determine status";

var STR_INSTALL_DISK_SPACE      = "Disk Space";
var STR_INSTALL_IMT_CLIENT      = "Oracle Web Conferencing Client";
var STR_INSTALL_IMT_CONNECT     = "Oracle Web Conferencing Connectivity";
var STR_INSTALL_NET_CONNECT     = "Network Connectivity";
var STR_INSTALL_AUDIO           = "Audio";

var STR_INSTALL_EXCELLENT       = "Excellent";
var STR_INSTALL_GOOD            = "Good";
var STR_INSTALL_POOR            = "Poor";

var STR_INSTALL_IMT_CONNECT_INFO = "Your system failed to connect to the Web Conferencing server. Please contact an Web Conferencing admin for help.";
var STR_INSTALL_NET_CONNECT_INFO = "Your network connectivity is poor. You may experience dropped connections.";

var STR_RTCC003_INFO            = "Oracle Web Conferencing is supported on Windows NT 4.0 Service Pack 6, Windows 2000, Windows XP, and Windows 98.";
var STR_RTCC004_INFO            = "Oracle Web Conferencing requires Internet Explorer 5.5 or higher to support all features. Document Presentation may not work on Netscape 4.75 or higher, Mozilla 1.6 or higher, and Internet Explorer 5.0. If Internet Explorer 5.5 or higher is properly configured on this machine, all features will be supported regardless of the browser used to join the conference.";

// internal variables
var _out = new Array();
var _outUpdated = 0;
var _id;
var _done;
var _oncomplete;
var _params;


//
// creates a compatibility item
// 
function CompatItem(name, status, details, info)
{
  this.name = name;
  this.status = status;
  this.details = details;
  this.info = info;
}

//
// Set, Get methods for params
//
function setParams(params)
{
  _params = params;
}
function getParams()
{
  return _params;
}

//
// accept method for recieving _out array from iframe:
//
function acceptResult(res)
{
//alert("acceptResult()");
  if(typeof(res["platform"]) != "undefined")
    _out["platform"] = res["platform"];
  if(typeof(res["resolution"]) != "undefined")
    _out["resolution"] = res["resolution"];
  if(typeof(res["browser"]) != "undefined")
    _out["browser"] = res["browser"];
  if(typeof(res["java"]) != "undefined")
    _out["java"] = res["java"];
  if(typeof(res["disk"]) != "undefined")
    _out["disk"] = res["disk"];
  if(typeof(res["client"]) != "undefined")
    _out["client"] = res["client"];
  if(typeof(res["connect"]) != "undefined")
    _out["connect"] = res["connect"];
  if(typeof(res["network"]) != "undefined")
    _out["network"] = res["network"];
  if(typeof(res["audio"]) != "undefined")
    _out["audio"] = res["audio"];
  if(typeof(res["misc"]) != "undefined")
    _out["misc"] = res["misc"];
  _outUpdated = 1;
//showOutValues(_out);
}

//
// checks windows version
//
function getOSVersion()
{
  var stat = 0;
  var details = "";
  var info = "";

  var ua = navigator.userAgent.toUpperCase();
  var i;

  if (_isIE)
  {
    i = ua.indexOf("WINDOWS NT");
    if (i != -1)
    {
      var sys = ua.substr(i + 11, 3);
      
      if (sys == "5.0")
        details = "Windows 2000";
      else if (sys == "5.1")
        details = "Windows XP";
      else if (sys == "5.2")
        details = "Windows Server 2003";
      else
        details = "Windows NT 4.0" + sys;

      stat = 1;
    }
    else
    {
      i = ua.indexOf("WINDOWS 95");
      if (i != -1)
      {
        stat = 0;
        details = "Windows 95";
      }
      else
      {
        i = ua.indexOf("WINDOWS 98");
        if (i != -1)
        {
          stat = 1;
          i = ua.indexOf("WIN 9X 4.90", i + 11);
          if (i != -1)
            details = "Windows Me";
          else
            details = "Windows 98";
        }
      }
    }
  }

  if (_isNN || _isMZ)
  {
    if (ua.indexOf("WIN95") != -1)
    {
      stat = 0;
      details = "Windows 95";
    }
    else if (ua.indexOf("WIN98") != -1)
    {
      stat = 1;
      details = "Windows 98";
    }
    else if (ua.indexOf("WIN 9X 4.90") != -1)
    {
      stat = 1;
      details = "Windows Me";
    }
    else if (ua.indexOf("WINNT4.0") != -1)
    {
      stat = 1;
      details = "Windows NT 4.0";
    }
    else if ((i = ua.indexOf("WINDOWS NT")) != -1)
    {
      var sys = ua.substr(i + 11, 3);

      stat = (parseFloat(sys) >= 4.0) ? 1 : 0;

      if (sys == "5.0")
        details = "Windows 2000";
      else if (sys == "5.1")
        details = "Windows XP";
      else if (sys == "5.2")
        details = "Windows Server 2003";
      else
        details = "Windows NT " + sys;
    }
  }

  if (_isOP)
  {
    if (ua.indexOf("WINDOWS 95") != -1)
    {
      stat = 0;
      details = "Windows 95";
    }
    else if (ua.indexOf("WINDOWS 98") != -1)
    {
      stat = 1;
      details = "Windows 98";
    }
    else if (ua.indexOf("WINDOWS ME") != -1)
    {
      stat = 1;
      details = "Windows Me";
    }
    else if (ua.indexOf("WINDOWS NT 4.0") != -1)
    {
      stat = 1;
      details = "Windows NT 4.0";
    }
    else if (ua.indexOf("WINDOWS 2000") != -1)
    {
      stat = 1;
      details = "Windows 2000";
    }
    else if (ua.indexOf("WINDOWS XP") != -1)
    {
      stat = 1;
      details = "Windows XP";
    }
  }

  if (details == "")
  {
    if (ua.indexOf("LINUX") != -1)
      details = "Linux";
    else if (ua.indexOf("FREEBSD") != -1)
      details = "FreeBSD";
    else if (ua.indexOf("SOLARIS") != -1)
      details = "Solaris";
    else if (ua.indexOf("OPENBSD") != -1)
      details = "OpenBSD";
    else if (ua.indexOf("MACINTOSH") != -1)
      details = "Macintosh";
    else if (ua.indexOf("MAC") != -1)
      details = "Macintosh";
    else
      details = STR_INSTALL_UNKNOWN_SYSTEM;
  }

  if (stat == 0)
    info = STR_INSTALL_PLATFORM_INFO;

  return new CompatItem(STR_INSTALL_PLATFORM, stat, details, info);
}

//
// checks screen resolution
//
function getScreenResolution()
{
  var stat = ((screen.width >= 1024) && (screen.height >= 768)) ? 1 : 0;
  //var details = screen.width + " x " + screen.height;
  var details = STR_INSTALL_RESOLUTION_VALUE;
  details = details.replace("WIDTH", screen.width);
  details = details.replace("HEIGHT", screen.height);
  var info = stat == 1 ? "" : STR_INSTALL_RESOLUTION_INFO;

  return new CompatItem(STR_INSTALL_RESOLUTION, stat, details, info);
}


//
// checks browser version
//
function getBrowserVersion()
{
  var stat = 0;
  var details = "";
  var info = "";

  var ua = navigator.userAgent.toUpperCase();

  var ver;

  if (_isIE)
  {
    ver = parseFloat(ua.substr(ua.indexOf("MSIE") + 5, 4));

    stat = (ver >= 5.5) ? 1 : (ver > 4) ? 2 : 0;
    details = "Internet Explorer " + ver;
  }

  if (_isNN)
  {
    ver = parseFloat(navigator.appVersion);

    if (ver >= 5.0)
      ver = parseFloat(ua.substr(ua.indexOf("NETSCAPE/") + 9, 3));

    details = "Netscape " + ver;
    stat = 2;
  }

  if(_isMZ)
  {
    ver = parseFloat(ua.substr(ua.indexOf("RV:") + 3, 3));
    details = "Mozilla " + ver;
    stat = 2;
  }

  if (_isOP)
  {
    ver = parseFloat(ua.substr(ua.indexOf("OPERA") + 6, 4));
    stat = 2;
    details = "Opera " + ver;
  }

  if(_isSF)
  {
    var matchResult = ua.match(/SAFARI\/(\d)(\d)/);
    var ver = "";
    if(matchResult[1] != null && matchResult[2] != null)
    {
      ver = matchResult[1] + "." + matchResult[2];
    }
    details = "Safari " + ver;
    stat = 2;
  }

  if (details == "")
    details = STR_INSTALL_UNKNOWN_BROWSER;
  if (stat == 0)
    info = STR_RTCC003_INFO;
  if (stat == 2)
    info = STR_RTCC004_INFO;

  return new CompatItem(STR_INSTALL_BROWSER, stat, details, info);
}

//
// determines whether Java is enabled
//
function getJavaEnabled()
{
  var stat = navigator.javaEnabled() ? 1 : 0;
  var details = stat == 1 ? STR_INSTALL_ENABLED : STR_INSTALL_DISABLED;
  var info = stat == 1 ? "" : STR_INSTALL_JAVA_INFO;
  
  return new CompatItem(STR_INSTALL_JAVA, stat, details, info);
}

//
// returns undetermined item
//
function getUndetermined(name)
{
  return new CompatItem(name, 3, STR_INSTALL_UNAVAILABLE, 
                        STR_INSTALL_UNAVAIL_INFO);
}

//
// encodes function parameters into a string
//
function encodeParameters(param)
{
  var names = [ "mxhost", "mxport", "httphost", "httpport",
                "httpshost", "httpsport", "servernode", "ctoken",
                "mtoken", "ttoken", "weburl", "popup", "privacy", "ssl",
                "sslname", "_oncomplete" ];
  var str = "";

  for (var i = 0; i < names.length; i++)
    str += "&" + names[i] + "=" + escape(param[names[i]]);

  return str;
}

//
// Try to load url into iframe, otherwise load in a new window:
//
function tryLoadIFrame(url)
{
  // And load cns_start_window into iframe:
  if(typeof(window.frames.status_frame) != "undefined") {
    // Netscape and Mozilla paint IFRAME black color while it's loading,
    // so we hide a DIV containing IFRAME. (Loaded doc will unhide IFRAME)
    if(typeof(document.getElementById("status_frame_div")) != "undefined") {
      document.getElementById("status_frame_div").style.visibility = "hidden";
    }
    window.frames.status_frame.location.replace(url);
  }
  // If iframe is not available (old version of Netscape)
  // open cns_start_window as a pop-up and redirect opener:
  else {
    var cx = 440;
    var cy = 340;
    window.open(url + "&popupmode=1", "_blank", "width=" + cx + ",height=" + cy
              + ",screenX=" + ((screen.width - cx) / 2)
              + ",screenY=" + (2 * (screen.height - cx) / 5));
    if(typeof(redirectUrl) != "undefined") {
      window.location.replace(redirectUrl);
    }
  }
}

//
// starts console or performs new user test
// 
function doStartFlow(param, action)
{
  if (typeof(param["popup"]) == "undefined")
    param["popup"] = "";
  if (typeof(param["ctoken"]) == "undefined")
    param["ctoken"] = "";
  if (typeof(param["mtoken"]) == "undefined")
    param["mtoken"] = "";
  if (typeof(param["ttoken"]) == "undefined")
    param["ttoken"] = "";
  if (typeof(param["privacy"]) == "undefined")
    param["privacy"] = 0;
  if (typeof(param["ssl"]) == "undefined")
    param["ssl"] = 0;
  if (typeof(param["sslname"]) == "undefined")
    param["sslname"] = "";
  if (param["privacy"] == "")
    param["privacy"] = 0;
  if (param["ssl"] == "")
    param["ssl"] = 0;
  if (typeof(param["_oncomplete"]) == "undefined")
    param["_oncomplete"] = "";

    // Just copying param array into global array:
    setParams(param);

  // set initial values for all output parameters
  _out["platform"]   = getOSVersion();
  _out["resolution"] = getScreenResolution();
  _out["browser"]    = getBrowserVersion();
  _out["java"]       = getJavaEnabled();
  _out["disk"]       = getUndetermined(STR_INSTALL_DISK_SPACE);
  _out["client"]     = getUndetermined(STR_INSTALL_IMT_CLIENT);
  _out["connect"]    = getUndetermined(STR_INSTALL_IMT_CONNECT);
  _out["network"]    = getUndetermined(STR_INSTALL_NET_CONNECT);
  _out["audio"]      = getUndetermined(STR_INSTALL_AUDIO);
  _out["misc"]       = new Array();
  //showOutValues(_out);

  if (_isIE && _platformSupported)
  {
    var url = "../console/cns_start_dialog.jsp?lang=en"
            + "&ver=3,0,3,674&action=" + action;
    // Load start dialog into iframe:
    window.frames.status_frame.location.replace(url);
  } 
  // if not IE, try to run limited Native or Java client:
  else
  {
    if ((action == "test")&&((!_platformSupported)|(_out["java"].status != 1)))
    {
      if (param["_oncomplete"] != "")
        setTimeout(param["_oncomplete"] + "(_out)", 1);
      return _out;
    }

    // Form url request:
    var url = "../console/cns_start_window.jsp?lang=en" +
      "&ver=3,0,3,674&action=" + action + 
      encodeParameters(param);
    // And load it 1 second later:
    setTimeout("tryLoadIFrame('" + url + "')", 1000);
  }

  if (param["_oncomplete"] != "")
  {
    _oncomplete = param["_oncomplete"];
    _id = setInterval("checkDone()", 500);
  }
  return _out;
}

// just for debug:
function showOutValues(out)
{
var str = "out['platform'] = " + out["platform"].name + ", " + out["platform"].status + ", " + out["platform"].details + ", " + out["platform"].info + "\n" +
          "out['resolution'] = " + out["resolution"].name + ", " + out["resolution"].status + ", " + out["resolution"].details + ", " + out["resolution"].info + "\n" + 
          "out['browser'] = " + out["browser"].name + ", " + out["browser"].status + ", " + out["browser"].details + ", " + out["browser"].info + "\n" + 
          "out['java'] = " + out["java"].name + ", " + out["java"].status + ", " + out["java"].details + ", " + out["java"].info + "\n" +
          "out['disk'] = " + out["disk"].name + ", " + out["disk"].status + ", " + out["disk"].details + ", " + out["disk"].info + "\n" +
          "out['client'] = " + out["client"].name + ", " + out["client"].status + ", " + out["client"].details + ", " + out["client"].info + "\n" +
          "out['connect'] = " + out["connect"].name + ", " + out["connect"].status + ", " + out["connect"].details + ", " + out["connect"].info + "\n" +
          "out['network'] = " + out["network"].name + ", " + out["network"].status + ", " + out["network"].details + ", " + out["network"].info + "\n" +
          "out['audio'] = " + out["audio"].name + ", " + out["audio"].status + ", " + out["audio"].details + ", " + out["audio"].info + "\n" +
          "out['misc] = " + out["misc"].name + ", " + out["misc"].status + ", " + out["misc"].details + ", " + out["misc"].info;
alert(str);
}

//
// starts console
// 
function startConsole(param)
{
  param["privacy"] = 1;
  return doStartFlow(param, "start");
}

//
// performs new user test
//
function newUserTest(param, oncomplete)
{
  param["_oncomplete"] = oncomplete;
  return doStartFlow(param, "test");
}

//
// checks if user clicked in Audio confirmation window
// and _out array has been updated, then runs a function
// specified by a _oncomplete variable.
//
function checkDone()
{
  if (_done && _outUpdated)
  {
    clearInterval(_id);
    setTimeout(_oncomplete + "(_out)", 1);
  }
}

//
// Escapes a string into escaped sequence of entities:
//
function decEscape(str)
{
  var encStr = "";
  if(str != "null" && str != "undefined")
  {
    
      try {
    
    for(var i=0; i<str.length; i++)
    {
      var chrCode = str.charCodeAt(i);
      encStr = encStr + "&#" + chrCode + ";";
    }
    
      } catch(ex) { encStr = str; }
    
  }
  return escape(encStr);
}

// Parse and return cookie value
function getCookie(name)
{
  var cookiestr = "" + document.cookie;
  var index1 = cookiestr.indexOf(name);
  if(index1 == -1) return "";
  var index2 = cookiestr.indexOf(';', index1);
  if(index2 == -1) index2 = cookiestr.length;
  return unescape(cookiestr.substring(index1 + name.length + 1, index2));
}
                                                                                                       
// Set a new cookie expiring in # secs
function setCookie(name, value, secs)
{
  var date = new Date();
  date.setTime(date.getTime() + secs*1000);
  var cookiestr = name + "=" + escape(value) + ";expires=" + date.toGMTString();
  document.cookie = cookiestr;
}


