//CT.2004.05.04 re-used from UN Human rights so name and title are not used
function Document(i, tp, nm, t)
{  
  this.id = new String(i); //the id of the document url*stylesheet
  this.type = new String(tp); //the type of the document
  this.url = new String(nm); //
  this.stylesheet = new String(t); //not used
}

function DocumentHistoryRemove(index)
{
  for (var i = index; i < this.docids.length-1; ++i)
    this.docids[i] = this.docids[i+1];
  this.docids.length = this.docids.length-1;  
}

function DocumentHistoryIndex(id)
{
  for (var i = 0; i < this.docids.length; i++)
    if (this.docids[i].id == id)
      return i;
  return -1; 
}

function DocumentHistoryAdd(tp, url, stylesheet)
{
  var id = url + "*" + stylesheet; //document_id  
  var index = this.index(id);
  if (index > -1)
    this.remove(index);
  var doc = new Document(id, tp, url, stylesheet);  
  this.docids[this.docids.length] = doc;  
}

function DocumentHistoryGoBack()
{
  var sLocation = "";
  if (this.docids.length > 1)
  {
    var oDocument = this.docids[this.docids.length - 2];    
    if (oDocument.type = "doc")
    {
      var sDocumentInfo  = "sUrl=" + encodeURIComponent(oDocument.url);
      sDocumentInfo     += "&sDtbId=" + encodeURIComponent(cstop.csconfig.currentDtbId);  
    
      sLocation  = "../pgdocument/document.asp";
      sLocation += "?sDocumentInfo=" + encodeURIComponent(sDocumentInfo);
      sLocation += "&sFromPage=menu";
      sLocation += "&docXSL=" + encodeURIComponent(oDocument.stylesheet);
      sLocation += "&skipHistory=";
    }
    
    this.docids.length = this.docids.length-1; //remove item from history
  }    
  return sLocation;
}

function DocumentHistoryAlert()
{
  alert(this.docids.length);  
}

function DocumentHistoryAlertAll()
{
  var msg = new String();
  for (var i = 0; i < this.docids.length; ++i)
  {
    msg += this.docids[i].id + "\n";
  }
  alert(msg);
}

function DocumentHistory()
{
  this.add = DocumentHistoryAdd;
  this.remove = DocumentHistoryRemove;
  this.index = DocumentHistoryIndex;
  this.goBack = DocumentHistoryGoBack;
  this.alert = DocumentHistoryAlert;
  this.alertAll = DocumentHistoryAlertAll;

  this.docids = new Array();
}

var docHistory = new DocumentHistory();
