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

function Messenger() {
  if(this.constructor!=Messenger) return new Messenger;
  this.startDetect();
}
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() {
  document.writeln("<object classid='clasid:41695A8E-6414-11D4-8FB3-00D0B7730277' hidden='true' id='Ymsgr01' width='1' height='1'><span id='Ymsgr00'></span></object>");
  this.post[this.post.length] = "postDetectControl";
}
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 (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;
    }
  }
  try{
      var __ym_obj = new ActiveXObject("Ypager.Messenger");
      this.installed = 1;
      this.version = null;
      this.platform = "w32";
      return true;
  }catch(e){
  }
  return false;
}
Messenger.prototype.detectBing = function() {
  document.writeln('<object id="Ymsgr02" classid="CLSID:DA4F543C-C8A9-4E88-9A79-548CBB46F18F" hidden="true"></object>');
  this.post[this.post.length] = "postDetectBing";
}
Messenger.prototype.postDetectBing = function() {
  try{
    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;
    this.installed = v.installed();
    this.version = v.version(1).split(".").join(",");
    this.cobrand = v.cobrand();
    this.intl = v.intl();
    return true;
  }catch(e){
    return false;
  }
}
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";
}
Messenger.prototype.postDetectRafi = function() {
  try{
    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;
  }catch(e){
    return false;
  }
}
Messenger.prototype.detectCookie = function() {
  // check C cookie. XXX
  return false;
}
function genYmFlash(__yid,__o,__evt){
  var __id="ymsgr"+(ymFlashCount++);
  var f="<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" width=\""+ymFlashWidth+"\" height=\""+ymFlashHeight+"\" id=\""+__id+"\" align=\"middle\">"+
  "<param name=\"allowScriptAccess\" value=\"sameDomain\" />"+
  "<param name=\"movie\" value=\""+ymFlashUrl+"?evt="+__evt+"&ym="+ymInstall+"&o="+__o+"&yid="+__yid+"\" />"+
  "<param name=\"quality\" value=\"high\" />"+
  "<param name=\"bgcolor\" value=\"#ffffff\" />"+
  "<embed src=\""+ymFlashUrl+"?evt="+evt+"&ym="+ymInstall+"&o="+o+"&yid="+yid+"\" quality=\"high\" bgcolor=\"#ffffff\" width=\""+ymFlashWidth+"\" height=\""+ymFlashHeight+"\" name=\""+__id+"\" align=\"middle\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />"+
  "</object>";
  
  document.write(f);

}

var messenger = new Messenger();
/*
var ymFlashCount=0;
var ymFlashUrl = "http://tw.yimg.com/i/tw/messenger/opi_auction/opi_auction.swf";
var ymFlashWidth = "125";
var ymFlashHeight = "30";
var ymInstall="0";
var ymObj;
try{
  ymObj=messenger.detect();
  if(ymObj.installed){
    ymInstall="1";
  }else{
    ymInstall="0";
  }
}catch(e){}
*/