/******************************************************************************
 *
 *                   INDIGEN SOLUTIONS CODE PROPERTY
 *       The present javascript code is property of Indigen Solutions. This 
 *     code can only be used inside Internet/Intranet web sites located on 
 *  *web servers*, as the outcome of a licensed Indigen Solutions application 
 *  only. Any unauthorized use, reverse-engineering, alteration, transmission, 
 * transformation, facsimile, or copying of any means (electronic or not) is 
 *     strictly prohibited and will be prosecuted. Removal of the present 
 *              copyright notice is strictly prohibited
 *         Copyright (c) 2004 Indigen Solutions. All Rights Reserved.
 *
 * RCS Id                       $Id: extras.js,v 1.4 2006/09/06 07:29:20 indigen Exp $
 * 
 ******************************************************************************/

/* IDateField */

function IDateField(formals) {
  this.defaultData = 0;
  this.base = IType;
  this.base(formals);
  this.selects;
  this.edit = IDateField.prototype.edit;
  this.updateData = IDateField.prototype.updateData;
  this.canDirectData = IDateField.prototype.canDirectData;
}

IDateField.prototype = new IType;

IDateField.prototype.edit = function(parentNode) {
  // Create Editor HTML structure.
  this.doc = parentNode.ownerDocument; 
  var doc = this.doc;
  var table = doc.getElementById("istruct_idatefield_editor");
  if ( !table ) {
    table = window.parent.document.getElementById("istruct_idatefield_editor");
    var html = table.outerHTML;
    div = doc.createElement("div");
    div.innerHTML = html;
    doc.appendChild(div);
    table = doc.getElementById("istruct_idatefield_editor");
  }
  table = table.cloneNode(true);
  table.style.display = "";
  parentNode.appendChild(table);
  // Get select references.
  this.format = ( ( this.formal && (this.formal.format == "date") ) ? "date" : "datetime" );
  this.selects = {};
  this.selects.day = getElementById(table, "day");
  this.selects.month = getElementById(table, "month");
  this.selects.year = getElementById(table, "year");
  if ( this.format == "date" ) {
    var td = getElementById(table, "hourtd1");
    if ( td )
      td.parentNode.removeChild(td);
    td = getElementById(table, "hourtd2");
    if ( td )
      td.parentNode.removeChild(td);
    td = getElementById(table, "hourtd3");
    if ( td )
      td.parentNode.removeChild(td);
  } else {    
    this.selects.hour = getElementById(table, "hour");
    this.selects.minute = getElementById(table, "minute");
  }
  // Init selects.
  var time = this.baseData[this.dataField];
  IDateField._setDate(this.selects, ( ( time > 0 ) ? new Date(time * 1000) : new Date() ), this.format);
};

IDateField.prototype.updateData = function() {
  this.baseData[this.dataField] = IDateField._getDate(this.selects, this.format).getTime() / 1000;
};

IDateField.prototype.canDirectData = function() {
};

IDateField._getDate = function(selects, format) {
  if ( !format )
    format = "datetime";
  var date = new Date(0);
  date.setDate(selects.day.value);
  date.setMonth(selects.month.value);
  date.setFullYear(selects.year.value);
  if ( format == "date" ) {
    date.setHours(0);
    date.setMinutes(0);
  } else {
    date.setHours(selects.hour.value);
    date.setMinutes(selects.minute.value);
  }
  return date;					
};

IDateField._setDate = function(selects, date, format) {
  if ( !format )
    format = "datetime";
  selects.day.value = date.getDate();
  selects.month.value = date.getMonth();
  selects.year.value = date.getFullYear();
  if ( format == "datetime" ) {
    selects.hour.value = date.getHours();
    selects.minute.value = date.getMinutes();
  }
};

/* IFileField. */

function IFileField(formals) {
  this.defaultData = ""; /** @todo */
  this.base = IType;
  this.base(formals);

  this.fileChooserPanel;
  this.fileInput;
  this.selectButton;
  this.fileChooser;
  this.fileid;
  this.newFileid;

  this.canDirectData = IFileField.prototype.canDirectData;
  this.edit = IFileField.prototype.edit;
  this.updateData = IFileField.prototype.updateData;
  this.selectFile = IFileField.selectFile;
}

IFileField.prototype = new IType;

IFileField.prototype.canDirectData = function() {
  return false;
};

IFileField.prototype.edit = function(parentNode) {
  // Create editor layout.
  this.doc = parentNode.ownerDocument;
  var doc = this.doc;
  var model = document.getElementById("filePanelModel");
  if ( !model ) {
    alert("Impossible to find file panel model for IFileField");
    return;
  }
  this.fileChooserPanel = doc.createElement("div");
  parentNode.appendChild(this.fileChooserPanel);
  var table = doc.createElement("table");
  parentNode.appendChild(table);
  var tbody = doc.createElement("tbody");
  table.appendChild(tbody);
  var tr = doc.createElement("tr");
  tbody.appendChild(tr);
  var td = doc.createElement("td");
  tr.appendChild(td);
  this.fileInput = doc.createElement("input");
  this.fileInput.setAttribute("type", "text");
  this.fileInput.disabled = true;
  td.appendChild(this.fileInput);
  td = doc.createElement("td");
  tr.appendChild(td);
  this.selectButton = doc.createElement("input");
  this.selectButton.setAttribute("type", "button");
  this.selectButton.setAttribute("value", "...");
  td.appendChild(this.selectButton);
  // Create file chooser.
  this.id = IStruct.registerElement(this);
  var handler = new Function("IStruct.getRegisteredElement('" + this.id + "').selectFile();");
  this.selectButton.onclick = handler;
  if ( this.baseData[this.dataField] ) {
    this.fileInput.value = this.baseData[this.dataField].basename;
    this.fileid = this.baseData[this.dataField].fileid;
  } else
    this.fileid = 0;
  this.newFileid = 0;
  this.fileChooser = new FileChooser(this.fileChooserPanel, model, table);
};

IFileField.selectFile = function() {
  var thisRef = this;
  var handler = function(inputs) {
    thisRef.fileInput.value = FileChooser.getBasename(inputs.filename);
    return true;
  };
  this.newFileid = this.fileChooser.choose(handler, null, null, this.newFileid);
};

IFileField.prototype.updateData = function() {
  this.baseData[this.dataField] = {
    basename  : this.fileInput.value,
    fileid    : this.fileid,
    newFileid : this.newFileid,
    _isfile   : true
  };
};

/* IFileUploadField. */

function IFileUploadField(formals) {
  this.defaultData = "";
  this.base = IType;
  this.base(formals);

  this.fileid;
  this.basename;
  this.inputid;
  this.currentFilePanel;
  this.currentFileInput;
  this.currentFileDeleteButton;
  this.uploadFileInput;

  this.canDirectData = IFileUploadField.prototype.canDirectData;
  this.edit = IFileUploadField.prototype.edit;
  this.getValue = IFileUploadField.prototype.getValue;
  this.updateData = IFileUploadField.prototype.updateData;
  this.deleteCurrentFile = IFileUploadField.deleteCurrentFile;
}

IFileUploadField.prototype = new IType;

IFileUploadField.prototype.canDirectData = function() {
  return false;
};

IFileUploadField.prototype.edit = function(parentNode) {
  // Create editor layout.
  this.doc = parentNode.ownerDocument;
  var doc = this.doc;
  var table = doc.getElementById("istruct_ifileuploadfield_editor");
  table = table.cloneNode(true);
  table.id = "";
  parentNode.appendChild(table);
  table.style.display = "";
  this.currentFilePanel = getElementById(table, "currentFilePanel");
  if ( this.baseData[this.dataField] ) {
    this.basename = this.baseData[this.dataField].basename;
    this.fileid = this.baseData[this.dataField].fileid;
  } else {
    this.basename = "";
    this.fileid = 0;
  }
  if ( !this.basename || !this.fileid ) {
    this.basename = "";
    this.fileid = 0;
  }
  if ( this.fileid  && this.currentFilePanel ) {
    var input = getElementById(this.currentFilePanel, "currentFileInput");
    input.value = this.basename;
    var button = getElementById(this.currentFilePanel, "currentFileDeleteButton");
    this.id = IStruct.registerElement(this);
    var handler = new Function("IStruct.getRegisteredElement('" + this.id + "').deleteCurrentFile();");
    button.onclick = handler;
  } else {
    if ( this.currentFilePanel && this.currentFilePanel.parentNode )
      this.currentFilePanel.parentNode.removeChild(this.currentFilePanel);
    this.currentFilePanel = null;
  }
  this.inputid = IFileUploadField.freeid++;
  this.uploadFileInput = getElementById(table, "uploadFileInput");
  this.uploadFileInput.name = "file_upload_" + this.inputid;
};

IFileUploadField.prototype.getValue = function() {
  return {
    basename      : this.basename,
    fileid        : this.fileid,
    inputname     : this.uploadFileInput.name,
    _isfileupload : true
  };
}

IFileUploadField.prototype.updateData = function() {
  this.baseData[this.dataField] = this.getValue();
};

IFileUploadField.deleteCurrentFile = function() {
  if ( this.currentFilePanel )
    this.currentFilePanel.parentNode.removeChild(this.currentFilePanel);
  this.currentFilePanel = null;
  this.basename = "";
  this.fileid = 0;
};

IFileUploadField.freeid = 1;

/* IDynamicSelectField */

function IDynamicSelectField(formals) {
  this.defaultData = "[]";
  this.base = IType;
  this.base(formals);
  this.edit = IDynamicSelectField.prototype.edit;
  this.updateData = IDynamicSelectField.prototype.updateData;

  this.removeItem = IDynamicSelectField.prototype.removeItem;
  this.appendItem = IDynamicSelectField.prototype.appendItem;

  this.addLine = IDynamicSelectField.prototype.addLine;
  this.buildCommands = IDynamicSelectField.prototype.buildCommands;
  this.validate = IDynamicSelectField.prototype.validate;
}

IDynamicSelectField.prototype = new IType;


/**
 * Handle a REMOVE command on an array item
 * @param {int} index the item index to be removed
 */
IDynamicSelectField.prototype.removeItem = function(index) {
  try {
    var entry = this.entries[index];
    this.entries.splice(index,1);
    var tr = document.getElementById(entry.trId);
    this.directData.splice(index,1);
    for(var i=index;i<this.entries.length;i++) {
      var itype = this.entries[i].itype;
      if(itype.dataField == i+1)
	itype.dataField = i;
    }
    tr.parentNode.removeChild(tr);
    this.buildCommands();
  } catch(e) {
    alert("Error removing entry: "+e);
  }
}

/**
 * Add a new item at the end of the array
 */
IDynamicSelectField.prototype.appendItem = function() {
  var typeIndex = 0;
  var typeSelector = this.doc.getElementById(this.typeSelectId);
  if(typeSelector!=null) {
    typeIndex = typeSelector.value;
  }
  this.addLine(this.directData.length,typeIndex);
  this.buildCommands();
}

/**
 * Add a new editor line. This method is called for each item when creating the 
 * initial editor, and then once every created item.
 * @param {int} i the index of the line
 * @param {int} typeIndex the index of the line editor type, or if <code>null</code>
 * the editor type is guessed from the actual data
 */
IDynamicSelectField.prototype.addLine = function(i, typeIndex) {
  var doc = this.doc;
  var ent0 = {};
  this.entries.push(ent0);
  var data = this.directData[i];
  var tr = doc.createElement("tr");
  var selector = doc.getElementById(this.selectorTrId);
  var tbody = selector.parentNode;
  tbody.insertBefore(tr,tbody.lastChild);
  ent0.trId = "iarray-"+IStruct.getId();
  tr.setAttribute("id",ent0.trId);
  var td1 = doc.createElement("td");
  tr.appendChild(td1);
  ent0.tdUpId = "iarray-"+IStruct.getId();
  td1.setAttribute("id",ent0.tdUpId);
  var div1 = doc.createElement("div");
  div1.innerHTML = "&nbsp;";
  this.setClass(div1, "buttonClass", "iarray-div-cmd");
  td1.appendChild(div1);
  var td2 = doc.createElement("td");
  tr.appendChild(td2);
  ent0.tdDownId = "iarray-"+IStruct.getId();
  td2.setAttribute("id",ent0.tdDownId);
  var div2 = doc.createElement("div");
  div2.innerHTML = "&nbsp;";
  this.setClass(div2, "buttonClass", "iarray-div-cmd");
  td2.appendChild(div2);
  var td3 = doc.createElement("td");
  ent0.tdRemoveId = "iarray-"+IStruct.getId();
  td3.setAttribute("id",ent0.tdRemoveId);
  tr.appendChild(td3);
  var div3 = doc.createElement("div");
  div3.innerHTML = "&nbsp;";
  this.setClass(div3, "buttonClass", "iarray-div-cmd");
  td3.appendChild(div3);
  var tdValue = doc.createElement("td");
  this.setClass(tdValue,"valueClass","iarray-td-value");
  tr.appendChild(tdValue);
  if(this.formal==null) {
    alert("IDynamicSelectField missing formal");
    return;
  }
  if(this.formal.entries==null) {
    alert("IDynamicSelectField missing formal entries");
    return;
  }
  if(!this.formal.entries instanceof Array) {
    alert("IDynamicSelectField formal entries is not a array");
    return;
  }
  var entry=null;
  if(typeIndex!=null) {
    entry = this.formal.entries[typeIndex];
  } else {
    for(var j=0;j<this.formal.entries.length;j++) {
      var ent = this.formal.entries[j];
      if(ent.type==null) {
	alert("IDynamicSelectField formal entry has no type");
	return;
      }				
      if(ent.typeTest==null) {
	entry=ent;
	break;
      }
      var check = eval(ent.typeTest);
      if(check==true) {
	entry = ent;
	break;
      }
    }
  }
  if(entry==null) {
    alert("Could not map IDynamicSelectField data to formal entry");
    return;
  }
  var itype;
  try {
    // FIXME : deep copy for formal (to correct bug to many hselect field in an array).
    var tmp = util_serialize(entry.formal);
    itype = eval("new "+entry.type+"(" + tmp + ")");
  } catch(e) {
    alert("Error instantiating "+entry.type+": "+e);
    return;
  }
  if(i==this.directData.length)
    this.directData.push(itype.getDefaultData());
  if(itype.canDirectData()) {
    itype.setData(this.directData[i]);
  } else {
    itype.setDataField(this.directData, i);
  }

  itype.draw(tdValue);
  ent0.itype = itype;
}

/**
 * Update the comand cells depending of the item index. For instance, the first
 * item must not have a triggerable UP command
 */
IDynamicSelectField.prototype.buildCommands = function() {
  for(var i=0;i<this.entries.length;i++) {
    var ent = this.entries[i];
    var td1 = document.getElementById(ent.tdUpId);
    var td2 = document.getElementById(ent.tdDownId);
    var td3 = document.getElementById(ent.tdRemoveId);
    if(i>0) {
      td1.onclick = new Function("IStruct.getRegisteredElement('"+this.id+"').upItem("+i+");");
      this.setClass(td1,"cmdClass","iarray-cmd","upClass","iarray-up");
    }	else {
      td1.onclick = new Function("");
      this.setClass(td1,"nocmdClass","iarray-nocmd");
    }
    if(i<this.entries.length-1) {
      td2.onclick = new Function("IStruct.getRegisteredElement('"+this.id+"').downItem("+i+");");
      this.setClass(td2,"cmdClass","iarray-cmd","downClass","iarray-down");
    } else {
      td2.onclick = new Function("");
      this.setClass(td2,"nocmdClass","iarray-nocmd");
    }
    this.setClass(td3,"cmdClass","iarray-cmd","removeClass","iarray-remove");
    td3.onclick = new Function("IStruct.getRegisteredElement('"+this.id+"').removeItem("+i+");");
  }
}

/**
 * Display the array editor
 * @param {node} parentNode the HTML node to attach the editor to
 */
IDynamicSelectField.prototype.edit = function(parentNode) {
  this.doc = parentNode.ownerDocument;
  var doc = this.doc;
  /**
  if(!this.directData instanceof Array) {
    alert("IDynamicSelectField data is not an array");
    return;
  }
  **/
  table = doc.createElement("table");
  table.setAttribute("cellSpacing","0");
  table.setAttribute("cellPadding","0");
  parentNode.appendChild(table);
  this.setClass(table,"tableClass","iarray-table");
  this.entries = [];
  this.id=IStruct.registerElement(this);
  var tr = doc.createElement("tr");
  var tbody = doc.createElement("tbody");
  table.appendChild(tbody);
  tbody.appendChild(tr);
  this.selectorTrId = "iarray-"+IStruct.getId();
  tr.setAttribute("id",this.selectorTrId);
  var td = doc.createElement("td");
  tr.appendChild(td);
  this.setClass(td,"cmdClass","iarray-cmd","addClass","iarray-add");
  td.onclick = new Function("IStruct.getRegisteredElement('"+this.id+"').appendItem();");
  var div = doc.createElement("div");
  this.setClass(div, "buttonClass", "iarray-div-cmd");
  td.appendChild(div);
  td = doc.createElement("td");
  tr.appendChild(doc.createElement("td"));	
  tr.appendChild(doc.createElement("td"));
  tr.appendChild(td);
  this.setClass(td,"addCellClass","iarray-td-sel");
  if(this.formal.entries.length>1) {
    var select = document.createElement("select");
    this.setClass(select,"addSelClass","iarray-sel");
    this.typeSelectId = "iarray-"+IStruct.getId();
    select.setAttribute("id",this.typeSelectId);
    td.appendChild(select);
    for(var i=0;i<this.formal.entries.length;i++) {
      var entry = this.formal.entries[i];
      var option = doc.createElement("option");
      select.appendChild(option);
      option.setAttribute("value",i);
      var label=entry.label;
      if(label==null)
	label = entry.type;
      option.appendChild(doc.createTextNode(label));
    }
  } else {
    td.innerHTML = "&nbsp;";
  }
  for(var i=0;i<this.directData.length;i++) {
    this.addLine(i,null);
  }
	
  this.buildCommands();
}

/**
 * Update the actual data with the content of the editor. This is performed
 * by calling the sub-editors <code>updateData</code> method for each item
 */
IDynamicSelectField.prototype.updateData = function() {
  for(var i=0;i<this.entries.length;i++) {
    var entry = this.entries[i];
    entry.itype.updateData();
  }
}

/**
 * Check the availability of the edited data by checking each of its fields
 */
IDynamicSelectField.prototype.validate = function() {
  for(var i=0;i<this.entries.length;i++) {
    var entry = this.entries[i];
    var v = entry.itype.validate();
    if(v == false)
      return false;
  }
  return true;
}

/* ISitemapField */

function ISitemapField(formal) {
  this.defaultData = "''";
  this.base = IType;
  this.base(formal);
  this.pageid;
  this.edit = ISitemapField.prototype.edit;
  this.updateData = ISitemapField.prototype.updateData;
  this.validate = ISitemapField.prototype.validate;
  this.canDirectData = ISitemapField.prototype.canDirectData;
}

ISitemapField.prototype = new IType;

/**
 * Returns <code>false</code> to indicate that this object does not handle
 * direct data
 */
ISitemapField.prototype.canDirectData = function() {
  return false;
}

/**
 * Display the sitemap editor
 * @param {node} parentNode the HTML node to attach the editor to
 */
ISitemapField.prototype.edit = function(parentNode) {
  this.doc = parentNode.ownerDocument; 
  var doc = this.doc;
  var input = doc.createElement("input");
  input.setAttribute("type", "button");
  this.inputId = "isitemapfield-" + IStruct.getId();
  input.setAttribute("id", this.inputId);
  input.setAttribute("value", this.formal.buttonLabel);
  this.id = IStruct.registerElement(this);
  parentNode.appendChild(input);
  var fnt = "IStruct.getRegisteredElement(\"" + this.id + "\").openSitemap()";
  input.onclick = new Function(fnt);
}

/**
 * Update the actual data with the content of the editor
 */
ISitemapField.prototype.updateData = function() {
  if (this.sitemapEditor)
    this.baseData[this.dataField] = this.sitemapEditor.getData(); 
}

/**
* Check the validity of the data
*/
ISitemapField.prototype.validate = function() {
  return true;
}

/**
* Specific function. Open sitemap.
*/
ISitemapField.prototype.openSitemap = function() {
  if (this.sitemapPanel == null) {
    this.sitemapPanel = document.createElement('div');
    this.sitemapPanel.style.height="500px";
    if (this.formal && this.formal.istructPanelId)
      this.istructPanel = document.getElementById(this.formal.istructPanelId);
    this.istructPanel.parentNode.appendChild(this.sitemapPanel);
  }
  var anchors = {};
  anchors.panel = this.sitemapPanel;
  anchors.istructField = this;
  if(this.baseData[this.dataField] != null)
    anchors.pageids = this.baseData[this.dataField];
  if (this.formal && this.formal.defaultNavigationId)
    anchors.defaultNavigationId = this.formal.defaultNavigationId;
  if (this.formal && this.formal.navigations)
    anchors.navigations = this.formal.navigations;
  if (this.formal && this.formal.wholeNavigations)
    anchors.wholeNavigations = this.formal.wholeNavigations;
  this.sitemapEditor = new ISitemapFieldEditor(anchors);
  this.istructPanel.style.display = 'none';
  this.sitemapEditor.show();  
}

ISitemapField.prototype.closeSitemap = function() {
  this.istructPanel.style.display = 'inline';
}

function ISitemapFieldEditor(anchors) {
  
  /* Attributes. */

  this.currentNavigationId;

  if (anchors) {
    if (anchors.istructField)
      this.istructField = anchors.istructField;
    else 
      alert('Parent panel is not defined');
    if (anchors.pageids)
      this.data = anchors.pageids;
    if (anchors.panel)
      this.panel = anchors.panel;
    else 
      alert('Parent panel is not defined');
    if (anchors.navigations)
      this.navigations = anchors.navigations;
    else
      alert('Whole Navigations are not set');
    if (anchors.wholeNavigations)
      this.wholeNavigations = anchors.wholeNavigations;
    else
      alert('Whole Navigations are not set');
    if (anchors.defaultNavigationId)
      this.defaultNavigationId = anchors.defaultNavigationId;
    else
      alert('Default Navigation is not set');
  };

  this.sitemap = new SitemapEditor();
    if (this.data && this.data.length != 0)
      this.currentNavigationId = this.data[0];    
    else
      this.currentNavigationId = this.defaultNavigationId;
  
  /* Methods. */
  
  this.show = function() {
    eval('var func = ' + this.wholeNavigations[this.currentNavigationId] + ';');
    var navigation = func();
    this.panel.innerHTML = this._getHTML(navigation);
    this.panel.style.display = 'inline';
    this.sitemap.redraw();
    var pathids = [];
    if (this.data)
      for (var i = 1; i < this.data.length; i++)
	pathids.push(this.data[i]);
    this.sitemap.selectPath(pathids);      
  };

  this.hide = function() {
    this.panel.style.display = 'none';
    this.istructField.closeSitemap();
  };

  this.insert = function() {
    this.data = [];
    this.data.push(this.currentNavigationId);
    for (var i in this.sitemap.getObjectids())
      this.data.push(this.sitemap.getObjectids()[i]);
    this.istructField.updateData();
    this.hide();
  };

  this.cancel = function() {
    this.hide();
  }; 

  this.remove = function() {
    this.data = [];
    this.istructField.updateData();
    this.hide();   
  }; 

  this.changeNavigation = function(id) {
    this.currentNavigationId = id;
    this.show();
  };

  this.getData = function() {
    return this.data;
  };

  /* Internal methods. */

  this._getHTML = function(nav) {
    var str = "";
    str += "<table style=\"height:100%; width:100%;\" border=1>";
    str += "<tr>";
    str += "<td class=\"internalLinkHTMLElement_titleTable\" colspan=\"2\">";
    str += "<table>";
    str += "<tr>";
    str += "<td>";
    str += "<select onchange=\"" + this.getStrRef() + ".changeNavigation(this.value)\" >";
    for (var i in this.navigations) {
      str += "<option " + (this.currentNavigationId == this.navigations[i]["id"] ? "selected" : "") +" ";
      str += "value=\"" + this.navigations[i]["id"] + "\">" + this.navigations[i]["title"] + "</option>";
    }
    str += "</select>";
    str += "</td>";       
    str += "<td>";
    str += "<input class=\"internalLinkHTMLElement_button\" type=\"button\" ";
    str += "value=\""+locale_get("ilhe_insert_button")+"\" onclick=\"" + this.getStrRef() + ".insert()\">";
    str += "</td>";
    str += "<td>";
    str += "<input class=\"internalLinkHTMLElement_button\" type=\"button\" ";
    str += "value=\""+locale_get("ilhe_cancel_button")+"\" onclick=\"" + this.getStrRef() + ".cancel()\">";
    str += "</td>";
    str += "<td>";
    str += "<input class=\"internalLinkHTMLElement_button\" type=\"button\" ";
    str += "value=\""+locale_get("Remove")+"\" onclick=\"" + this.getStrRef() + ".remove()\">";
    str += "</td>";
    str += "</tr>";
    str += "</table>";
    str += "</td>";
    str += "</tr>";
    str += "<tr>";
    str += "<td colspan=\"2\" width=\"100%;\" height=\"100%;\">";
    if (nav != null)
      str += this.sitemap.initForLink(nav, 'sitemap_' + this.istructField.id);
    str += "</td>";
    str += "</tr>";
    str += "</table>";
    return str;
  };

  this.getStrRef = function() {
    return "IStruct.getRegisteredElement('" + this.istructField.id + "').sitemapEditor";
  };
}

