//date updated: 12.06.2005

//<xmp>
/* msgr_detect.js
 * a javascript library to figure out things about a locally installed messenger client
 */

function Messenger() {
  this.startDetect();
  return null;
}
Messenger.prototype.installed = 0;
Messenger.prototype.cobrand = '';
Messenger.prototype.intl = 'us';
Messenger.prototype.version = "4";
Messenger.prototype.platform = "w32";
Messenger.prototype.post = [];
Messenger.prototype.detect = function() {
  // loop through post process
  for (var i=0;i<this.post.length;i++) {
    this[this.post[i]]();
  }
  this.post=[];
  return this;
}
Messenger.prototype.startDetect = function () {
  var ok = this.detectCookie();
  if (!ok) ok = this.detectBing();
  if (!ok) ok = this.detectRafi();
  if (!ok) ok = this.detectCapabilities();
  if (!ok) ok = this.detectControl();
  if (!ok) ok = this.detectMime();
  /* if you don't know by now, you'll never ever know. */
}
Messenger.prototype.detectControl = function() {
  if (this.detectBrowser() == 'ie')
  {
    document.writeln("<object classid='clasid:41695A8E-6414-11D4-8FB3-00D0B7730277' hidden='true' id='Ymsgr01' width='0' height='0' codebase='tkzwtyzwzi:qwerty'><span id='Ymsgr00'></span></object>");
    this.post[this.post.length] = "postDetectControl";
  }
}
Messenger.prototype.detectBrowser = function()
{
  var ua = navigator.userAgent.toLowerCase();

  if (ua.indexOf('opera')!=-1)
  {
    return 'opera';
  }
  else if (ua.indexOf('msie')!=-1)
  {
    return 'ie';
  }
  else if (ua.indexOf('safari')!=-1)
  {
    return 'safari';
  }
  else if (ua.indexOf('flock')!= -1)
  {
    return 'flock';
  }
  else if (ua.indexOf('firefox')!= -1)
  {
    return 'firefox';
  }
  else if (ua.indexOf('gecko')!= -1)
  {
    return 'gecko';
  }
  else
  {
    return false;
  }
}
Messenger.prototype.postDetectControl = function() {
  var w,v;
  if (document.all) {
    v = document.all.Ymsgr00;
  } else {
    v = document.getElementById("Ymsgr00");
  }
  if (v) {
    // mutant gecko+active X case
    w = document.getElementById("Ymsgr01");
    if (w&&w.offsetHeight) {
      this.installed = 1;
      this.version = "5.02";
      this.platform = "w32";
    } else {
      return false;
    }
  } else {
    this.installed = 1;
    this.version = "5.03";
    this.platform = "w32";
  }
  return true;
}
Messenger.prototype.detectMime = function() {
  if (navigator.mimeTypes && navigator.mimeTypes.length) {
    for (var i=0; i<navigator.mimeTypes.length; i++) {
      if (navigator.mimeTypes[i].suffixes.indexOf("yps") > -1) {
         this.installed = 1;
         this.version = "5.04";
         this.platform = "w32";
         return true;
      }
    }
  }
  return false;
}
Messenger.prototype.detectCapabilities = function() {
  if (document.body && document.body.style && typeof document.body.style.behavior == "string") {
    document.body.style.behavior = "url(#default#clientCaps)";
    var ver = document.body.getComponentVersion("{E5D12C4E-7B4F-11D3-B5C9-0050045C3C96}","ComponentID");
    if (ver) {
      this.installed = 1;
      this.version = ver;
      this.platform = "w32";
      return true;
    }
  }
  return false;
}
Messenger.prototype.detectBing = function() {
  if (this.detectBrowser() == 'ie')
  {
    document.writeln('<object id="Ymsgr02" classid="CLSID:DA4F543C-C8A9-4E88-9A79-548CBB46F18F" hidden="true" width="0" height="0" codebase="tkzwtyzwzi:qwerty"></object>');
    this.post[this.post.length] = "postDetectBing";
  }
}
Messenger.prototype.postDetectBing = function() {
  var v;
  if (document.all) {
    v = document.all.Ymsgr02;
  } else { 
    // gecko w/ activeX patch
    v = document.getElementById("Ymsgr02");
  }
  if (!v) return false;
  if (typeof v.installed == "undefined") return false;
  if (typeof v.version == "undefined") return false;
  this.installed = v.installed();
  var versionstring = v.version(1);
  if (!versionstring || typeof versionstring == "undefined") return false;
  this.version = versionstring.split(".").join(",");
  this.cobrand = v.cobrand();
  this.intl = v.intl();
  return true;
}
Messenger.prototype.detectRafi = function() {
  if (!document.getElementById) return false;
  if (!navigator.plugins["Yahoo Application State Plugin"]) return false;
  document.writeln("<object id='Ymsgr03' type='application/x-vnd.yahoo.applicationState' hidden='true'></object>");
  this.post[this.post.length] = "postDetectRafi";
  return false;
}
Messenger.prototype.postDetectRafi = function() {
  var v = document.getElementById("Ymsgr03");
  if (!v) return false;
  if (typeof v.applicationInfo != "function") return false;
  var m = v.applicationInfo("msgr");
  if (!m) return false;
  this.installed = m.installed();
  var ver = m.version();
  this.version = ver.major+","+ver.minor+","+ver.hiBuild+","+ver.loBuild;
  this.cobrand = m.cobrand();
  this.intl = m.internationalCode();
  return true;
}
Messenger.prototype.detectCookie = function() {
  // check C cookie. XXX
  return false;
}

