/**
 * Copyright(C) 2006 Ken Millennium Corporation. All rights reserved.
 * IE One click support.
 * T.Ohno
 */

/**
 * Applet タグを生成します。
 * name が不要な場合には、null を指定します。
 * name: name
 * code: class
 * codebase: code base
 * width: content width
 * height: content height
 * archive: jar
 * alt: alt
 */
function AppletTag(name, code, codebase, width, height, archive, alt) {
  this.name = name;
  this.code = code;
  this.codebase = codebase;
  this.width = width;
  this.height = height;
	this.archive = archive;
	this.alt = alt;
  this.paramNames = null;
  this.paramValues = null;
  this.archive = null;
  this.alt = null;

	if(archive != null /*|| archive == undefined*/) {
		this.archive = archive;
	}
	if(alt != null /*|| alt == undefined*/) {
		this.alt = alt;
	}

}

/**
 * パラメータを設定します。
 * name: param タグの name
 * value: param タグの value
 */
AppletTag.prototype.addParam = function(name, value) {
  if(this.paramNames == null) {
    this.paramNames = new Array();
    this.paramValues = new Array();
  }

  this.paramNames[this.paramNames.length] = name;
  this.paramValues[this.paramValues.length] = value;
}

/**
 * Applet タグ取得
 */
AppletTag.prototype.toString = function() {
  // object タグ、embed タグ には、あえて非対応
  var appletTag = new String();

  // applet タグ
  appletTag += '<applet ';

	if(this.name != null) {
		appletTag += 'name="' + this.name + '" ';
	}

  appletTag += 'code="' + this.code + '" ';
  appletTag += 'codebase="' + this.codebase + '" ';

	if(this.archive != null) {
		appletTag += 'archive="' + this.archive + '" ';
	}

  appletTag += 'width="' + this.width + '" ';
  appletTag += 'height="' + this.height + '" ';

	if(this.alt != null) {
		appletTag += 'alt="' + this.alt + '" ';
	}

  //2009/06/18 Add
  appletTag += 'id="applet_id" ';

  appletTag += 'MAYSCRIPT>';


  // <param> タグ作成
  if(this.paramNames != null) {
    for(i = 0; i < this.paramNames.length; i++) {
      appletTag += '<param name="' + this.paramNames[i] + '" ';
      appletTag += 'value="' + this.paramValues[i] + '">';
    }
  }

  // applet 閉じタグ
  appletTag += '</applet>';

  return appletTag;
}

/**
 * 書き出し
 * id が null の場合には、document に直接書き出します。
 * id: 書き出す オブジェクトID
 */
AppletTag.prototype.write = function(id) {
  if(id == null) {
    document.write(this.toString());
  }
  else {
    var target = document.getElementById(id);
    target.innerHTML = this.toString();
  }
}

