// Write out object and embed tag to avoid the user having to activate control.
// Expects an even number of parameters in name,value pairs.
// Attributes beginning with obj# are object tag specific.
// Attributes beggining with emb# are embed tag specific.
// If id is passed, this will be the name attribute of the embed tag.
// If src is passed, this will be the url param of the object tag.
// 'divid' id the id of the div to place the object in.
function tiswriteobject() {
  var divid = '';
  var debug = 0;
  var data = new Array();
  var objattrs = new Array();
  var objparams = new Array();
  var embattrs = new Array();
  var noobj = '';
  var isattr = new Array();
      isattr["id"] = 1;
      isattr["classid"] = 1;
      isattr["width"] = 1;
      isattr["height"] = 1;
      isattr["style"] = 1;
      isattr["type"] = 1;

  if((arguments.length % 2) != 0) {
    alert('An even number of parameter is required.');
    return;
  }
  var i;
  var name;
  var value;
  for(i = 0;i < arguments.length;i+=2) {
    data[arguments[i]] = arguments[i+1];
  }

  if(data['divid']) {
    divid = data['divid'];
    delete data['divid'];
  }
  if(data['debug']) {
    debug = data['debug'];
    delete data['debug'];
  }
  if(data['src']) {
    // Change src values to be tag specific.
    data['obj#url'] = data['src'];
    data['emb#src'] = data['src'];
    delete data['src'];
  }
  if(data['id']) {
    data['obj#id'] = data['id'];
    data['emb#name'] = data['id'];
    delete data['id'];
  }
  if(data['noobj']) {
    noobj = data['noobj'];
    delete data['noobj'];
  }

  for(name in data) {
    value = data[name];
    if(name.indexOf("obj#") == 0) {
      // For object tag only.
      name = name.substring(4);
      if(isattr[name]) {
        objattrs[name] = value;
      } else {
        objparams[name] = value;
      }
    } else if(name.indexOf("emb#") == 0) {
      // For embed tag only.
      name = name.substring(4);
      embattrs[name] = value;
    } else {
      // For object and embed tag.
      if(isattr[name]) {
        objattrs[name] = value;
      } else {
        objparams[name] = value;
      }
      embattrs[name] = value;
    }
  }

  // Build tag.
  var html = '<object ';
  for(name in objattrs) {
    html += name + '="' + objattrs[name] + '" ';
  }
  html += '>\n';
  for(name in objparams) {
    html += '<param name="' + name + '" value="' + objparams[name] + '" />\n';
  }
  html += noobj;
  html += '<embed ';
  for(name in embattrs) {
    html += name + '="' + embattrs[name] + '" ';
  }
  html += '></embed>\n';
  html += '</object>';

  if(debug) {
    alert(html);
  }
  var d = document.getElementById(divid);
  try {
	  d.innerHTML = html;
  }catch(e){}
}