//***************************************************************************************************
//***************************************************************************************************
//**
//** Notepad
//** Autor: DF
//** Erstellung: 19.12.2006
//** © rdts AG
//**
//***************************************************************************************************
//***************************************************************************************************

var undefined;

//***************************************************************************************************
// Notepad
//***************************************************************************************************

// Konstruktor:
// ------------
//   + Notepad()
//   + Notepad.createInstance()
//
// Eigenschaften:
// --------------
//   + _id: str
//   + _language: str
//   + _viewElement: str
//   + _systemURLPrefix: str
//   + noteData: obj (Hash)
//   + noteDataLenght: arr

function Notepad(idx) {
  this._id = undefined;
  this._language = Notepad._defaultLanugage;
  this._systemURLPrefix = '';
  this._viewElement = undefined;
  this.noteData = {};
  this.noteDataLenght = [];
  
  this.id(idx);
}

/////////////////////////////////////////////////
// Zugriffsmethoden
/////////////////////////////////////////////////

// -------------
// id()
// -------------
Notepad.prototype.id = function(str) {
  if (arguments.length > 1) {
    focus();
    throw new Error("Notepad->id: Falsche Anzahl von Argumenten!");
  }
  if (arguments.length) {
    if (typeof str != "string") {
      focus();
      throw new Error("Notepad->id: Argument ist nicht vom Typ String!");
    }
    this._id = str;
  }
  return this._id;
}


/////////////////////////////////////////////////
// private Instanzmethoden
/////////////////////////////////////////////////

/////////////////////////////////////////////////
// öffentliche Instanzmethoden
/////////////////////////////////////////////////

// -------------
// setLanguage()
// -------------
Notepad.prototype.setLanguage = function(str) {
  if (arguments.length != 1) {
    focus();
    throw new Error("Notepad->setLanguage: Falsche Anzahl von Argumenten!");
  }
  this._language = str;
}

// -------------
// setViewElement()
// -------------
Notepad.prototype.setViewElement = function(obj) {
  if (arguments.length != 1) {
    focus();
    throw new Error("Notepad->setViewElement: Falsche Anzahl von Argumenten!");
  }
  this._viewElement = obj;
  //alert(this._viewElement);
}

// -------------
// setSystemURLPrefix()
// -------------
Notepad.prototype.setSystemURLPrefix = function(str) {
  if (arguments.length != 1) {
    focus();
    throw new Error("Notepad->setLanguage: Falsche Anzahl von Argumenten!");
  }
  this._systemURLPrefix = str;
}

// -------------
// setLanguage()
// -------------
Notepad.prototype.setLanguage = function(str) {
  if (arguments.length != 1) {
    focus();
    throw new Error("Notepad->setLanguage: Falsche Anzahl von Argumenten!");
  }
  this._language = str;
}


// -------------
// addData()
// -------------
Notepad.prototype.addData = function(idx) {
  if (arguments.length != 1) {
    focus();
    throw new Error("Notepad->addData: Falsche Anzahl von Argumenten!");
  }
  if (! this.noteData[idx]){
    this.noteData[idx] = Notedata.getInstance(idx);
    this.noteDataLenght.push(idx);
  }
  if (Notepad._alertAddData[this._language]){
    alert(Notepad._alertAddData[this._language]);
  } else {
    alert(Notepad._alertAddData[Notepad._defaultLanugage]);
  }
  this.drawNotepad();
}

// -------------
// deleteData()
// -------------
Notepad.prototype.deleteData = function(idx) {
  if (arguments.length != 1) {
    focus();
    throw new Error("Notepad->deleteData: Falsche Anzahl von Argumenten!");
  }
  if (this.noteData[idx]){
    delete this.noteData[idx];
    var arr = [];
    for (var i=0; i<this.noteDataLenght.length; i++){
      if (this.noteDataLenght[i] == idx){
        continue;
      }
      arr.push(this.noteDataLenght[i]);
    }
    this.noteDataLenght = arr;
  }
  this.drawNotepad();
  this.drawNotepadDetail();
}

// -------------
// dataLength()
// -------------
Notepad.prototype.dataLength = function(typ) {
  if (arguments.length > 0){
    var _count = 0;
    for (var i in this.noteData){
      if (this.noteData[i].typ == typ){
        _count++;
      }
    }
    return _count;
  }
  return this.noteDataLenght.length;
}

// -------------
// drawNotepad()
// -------------
Notepad.prototype.drawNotepad = function() {
  var xhtml = '';  
  xhtml += '<div class="merkzettel-inhalt">\n';
  xhtml += '<div class="merkzettel-kopf">\n';
  xhtml += '<h3 class="h3-merkzettel"><a href="'+ this._systemURLPrefix +'&amp;_bereich=artikel&amp;_aktion=detail&amp;idartikel=100030&amp;_sprache=merkzettel" class="h3-merkzettel">Merkzettel</a></h3>\n';
  xhtml += '</div>\n';
  xhtml += '<div class="merkzettel-text">\n';
  xhtml += '<div class="merkzettel-inhalt-eintrag"><span class="merkzettel-anzahl">' +  this.dataLength('Firmen') + '</span> <a href="'+ this._systemURLPrefix +'&amp;_bereich=artikel&amp;_aktion=detail&amp;idartikel=100030&amp;_sprache=merkzettel&amp;_template_variant=firmen" class="merkzettel">Firmen</a></div>\n';
  xhtml += '<div class="merkzettel-inhalt-eintrag"><span class="merkzettel-anzahl">' +  this.dataLength('Tagungsstätten / Lieux de congrès') + '</span> <a href="'+ this._systemURLPrefix +'&amp;_bereich=artikel&amp;_aktion=detail&amp;idartikel=100030&amp;_sprache=merkzettel&amp;_template_variant=tagung" class="merkzettel">Tagungsstätten</a></div>\n';
  xhtml += '</div>\n';
  xhtml += '</div>\n';
  if (window['hauptframe']){
    var elem = window['hauptframe'].document.getElementById('merkzettel');
    if (elem){
      elem.innerHTML = xhtml;
      if (this.dataLength() > 0){
        elem.style.display = 'block';
      } else {
        elem.style.display = 'none';
      }
    }
  }
}


// -------------
// drawNotepadDetail()
// -------------
Notepad.prototype.drawNotepadDetail = function(_type) {
  var xhtml = ''
  if (this.dataLength() > 0){
    if (this.dataLength('Firmen') > 0 && (!_type || _type == 'firmen')){
      var typ = 'Firmen';
      xhtml += '<div class="navigation-">\n';
      xhtml += '<table cellspacing="0" cellpadding="0" class="tabelle-navigation">\n';
      xhtml += '<tr>\n';
      xhtml += '<td class="tabelle-navigation-anzeige">\n';
      xhtml += 'Firmen: '+ this.dataLength(typ) +'<br />\n';
      xhtml += '</td>\n';
      xhtml += '</tr>\n';
      xhtml += '</table>\n';
      xhtml += '</div>\n';

      xhtml += '<table cellspacing="3" cellpadding="0" class="tabelle-uebersichtstabelle-2">\n';
      xhtml += '<tr>\n';
      xhtml += '<th class="th-uebersichtstabelle-2-1">\n';
      xhtml += '<br />\n';
      xhtml += '</th>\n';
      xhtml += '<th class="th-uebersichtstabelle-2-2" colspan="2">\n';
      xhtml += 'Name<br />\n';
      xhtml += '</th>\n';
      xhtml += '<th class="th-uebersichtstabelle-2-3">\n';
      xhtml += 'Ort<br />\n';
      xhtml += '</th>\n';
      xhtml += '<th class="th-uebersichtstabelle-2-4a">\n';
      xhtml += 'Region<br />\n';
      xhtml += '</th>\n';
      xhtml += '<th class="th-uebersichtstabelle-2-4">\n';
      xhtml += '<br />\n';
      xhtml += '</th>\n';
      for (var i in this.noteData){
        if (this.noteData[i].typ == typ){
          xhtml += '</tr>\n';
          xhtml += '<tr>\n';
          xhtml += '<td class="td-uebersichtstabelle-2-1">\n';
          xhtml += '<br />\n';
          xhtml += '</td>\n';
          xhtml += '<td class="td-uebersichtstabelle-2-3" colspan="2">\n';
          xhtml += '<a href="'+ this.noteData[i].detailURL +'" class="titel-link">'+ this.noteData[i].title +'</a><br />\n';
          xhtml += '</td>\n';
          xhtml += '<td class="td-uebersichtstabelle-2-4a">\n';
          if (this.noteData[i].ort){
            xhtml += this.noteData[i].ort;
          }
          xhtml += '<br />\n';
          xhtml += '</td>\n';
          xhtml += '<td class="td-uebersichtstabelle-2-4">\n';
          if (this.noteData[i].region){
            xhtml += this.noteData[i].region;
          }
          xhtml += '<br />\n';
          xhtml += '</td>\n';
          xhtml += '<td class="td-uebersichtstabelle-2-5">\n';
          xhtml += '<a href="javascript:void(0);" onclick="deleteData(\''+ this.noteData[i].id() +'\');" class="uebersichtstabelle-4-link">Von dem Merkzettel löschen</a><br />\n';
          xhtml += '</td>\n';
          xhtml += '</tr>\n';
        }
      }
      xhtml += '</table>\n';
    }

    if (this.dataLength('Tagungsstätten / Lieux de congrès') > 0 && (!_type || _type == 'tagung')){
      var typ = 'Tagungsstätten / Lieux de congrès';
      xhtml += '<div class="navigation-">\n';
      xhtml += '<table cellspacing="0" cellpadding="0" class="tabelle-navigation">\n';
      xhtml += '<tr>\n';
      xhtml += '<td class="tabelle-navigation-anzeige">\n';
      xhtml += 'Tagungsstätten / Lieux de congrès: '+ this.dataLength(typ) +'<br />\n';
      xhtml += '</td>\n';
      xhtml += '</tr>\n';
      xhtml += '</table>\n';
      xhtml += '</div>\n';

      xhtml += '<table cellspacing="3" cellpadding="0" class="tabelle-uebersichtstabelle-2">\n';
      xhtml += '<tr>\n';
      xhtml += '<th class="th-uebersichtstabelle-2-1">\n';
      xhtml += '<br />\n';
      xhtml += '</th>\n';
      xhtml += '<th class="th-uebersichtstabelle-2-2" colspan="2">\n';
      xhtml += 'Name<br />\n';
      xhtml += '</th>\n';
      xhtml += '<th class="th-uebersichtstabelle-2-3">\n';
      xhtml += 'Ort<br />\n';
      xhtml += '</th>\n';
      xhtml += '<th class="th-uebersichtstabelle-2-4a">\n';
      xhtml += 'Region<br />\n';
      xhtml += '</th>\n';
      xhtml += '<th class="th-uebersichtstabelle-2-4">\n';
      xhtml += '<br />\n';
      xhtml += '</th>\n';
      for (var i in this.noteData){
        if (this.noteData[i].typ == typ){
          xhtml += '</tr>\n';
          xhtml += '<tr>\n';
          xhtml += '<td class="td-uebersichtstabelle-2-1">\n';
          xhtml += '<br />\n';
          xhtml += '</td>\n';
          xhtml += '<td class="td-uebersichtstabelle-2-3" colspan="2">\n';
          xhtml += '<a href="'+ this.noteData[i].detailURL +'" class="titel-link">'+ this.noteData[i].title +'</a><br />\n';
          xhtml += '</td>\n';
          xhtml += '<td class="td-uebersichtstabelle-2-4a">\n';
          if (this.noteData[i].ort){
            xhtml += this.noteData[i].ort;
          }
          xhtml += '<br />\n';
          xhtml += '</td>\n';
          xhtml += '<td class="td-uebersichtstabelle-2-4">\n';
          if (this.noteData[i].region){
            xhtml += this.noteData[i].region;
          }
          xhtml += '<br />\n';
          xhtml += '</td>\n';
          xhtml += '<td class="td-uebersichtstabelle-2-5">\n';
          xhtml += '<a href="javascript:void(0);" onclick="deleteData(\''+ this.noteData[i].id() +'\');" class="uebersichtstabelle-4-link">Von dem Merkzettel löschen</a><br />\n';
          xhtml += '</td>\n';
          xhtml += '</tr>\n';
        }
      }
      xhtml += '</table>\n';
    }
  } else {
    xhtml += '<div class="kategorie-eintrag">\n';
    xhtml += '<div class="kategorie-eintrag-inhalt">\n';
    xhtml += '<table cellpadding="0" cellspacing="0" border="0" class="tabelle-kategorie">\n';
    xhtml += '<tr>\n';
    xhtml += '<td  class="td-daten-kategorie">\n';
    xhtml += '<div class="kategorie-eintrag-inhalt-daten-titel">\n';
    xhtml += '<h4 class="h4-kategorie-eintrag-titel">\n';
    if (Notepad._alertAddData[this._language]){
      xhtml += Notepad._alertNoData[this._language] + '\n';
    } else {
      xhtml += Notepad._alertNoData[Notepad._defaultLanugage] + '\n';
    }
    xhtml += '</h4>\n';
    xhtml += '</div>\n';
    xhtml += '</td>\n';
    xhtml += '</tr>\n';
    xhtml += '</table>\n';
    xhtml += '</div>\n';
    xhtml += '<div class="float-aufheben"><br /></div>\n';
    xhtml += '</div>\n';
  }  

  if (window['hauptframe']){
    var elem = window['hauptframe'].document.getElementById('merkzettel-detail');
    if (elem){
      elem.innerHTML = xhtml;
    }
  }
}  

/////////////////////////////////////////////////
// private Klasseneigenschaften
/////////////////////////////////////////////////

Notepad._defaultID = [];

Notepad._registerInstance = {};

Notepad._alertAddData = {};
Notepad._alertAddData['de'] = 'Der Datensatz wurde auf den Merkzettel gesetzt.';
Notepad._alertAddData['uk'] = 'The data has been added to the Notepad';

Notepad._alertNoData = {};
Notepad._alertNoData['de'] = 'Es liegen keine Einträge auf dem Merkzettel vor.';
Notepad._alertNoData['uk'] = 'The is no data on the Notepad';


Notepad._defaultLanugage = 'de';

/////////////////////////////////////////////////
// private Klassenmethoden
/////////////////////////////////////////////////

/////////////////////////////////////////////////
// öffentliche Klasseneigenschaften
/////////////////////////////////////////////////

/////////////////////////////////////////////////
// öffentliche Klassenmethoden
/////////////////////////////////////////////////

// ----------------
// getInstance
// ----------------
Notepad.getInstance = function (idx) {
  if (arguments.length!=1) {
    throw new Error("Notepad.getInstance: Falsche Anzahl von Argumenten!");
  }
  if (! (Notepad._registerInstance[idx])){
    focus();
    throw new Error("Notepad.getInstance: Es ist keine Notepad.Instance mit id=" + idx + " registriert!");
  } 
  return Notepad._registerInstance[idx];
}

// ----------------
// createInstance
// ----------------
Notepad.createInstance = function (idx) {
  if (!arguments.length) {
    idx = Notepad._defaultID.length;
    Notepad._defaultID.push('1');
  }
  idx = idx.toString();
  if (! (Notepad._registerInstance[idx])){
    Notepad._registerInstance[idx] = new Notepad(idx);
  } 
  return Notepad.getInstance(idx);
}  

//***************************************************************************************************
// Notedata
//***************************************************************************************************

// Konstruktor:
// ------------
//   + Notedata()
//   + Notedata.createInstance()
//
// Eigenschaften:
// --------------
//   + _id: str
//   + typ: str
//   + title: str
//   + subtitle: str
//   + text: str
//   + autor: str
//   + imageURL: str
//   + detailURL: str
//   + ort: str
//   + region: str
//   + noteData: obj (Hash)

function Notedata(idx) {
  this._id = undefined;
  
  this.typ = undefined;
  this.title = undefined;
  this.subtitle = undefined;
  this.text = undefined;
  this.autor = undefined;
  this.imageURL = undefined;
  this.detailURL = undefined;
  this.ort = undefined;
  this.region = undefined;
  
  this.id(idx);
  //this._createNotedata();
}

/////////////////////////////////////////////////
// Zugriffsmethoden
/////////////////////////////////////////////////

// -------------
// id()
// -------------
Notedata.prototype.id = function(str) {
  if (arguments.length > 1) {
    focus();
    throw new Error("Notedata->id: Falsche Anzahl von Argumenten!");
  }
  if (arguments.length) {
    if (typeof str != "string") {
      focus();
      throw new Error("Notedata->id: Argument ist nicht vom Typ String!");
    }
    this._id = str;
  }
  return this._id;
}


/////////////////////////////////////////////////
// private Instanzmethoden
/////////////////////////////////////////////////

/////////////////////////////////////////////////
// öffentliche Instanzmethoden
/////////////////////////////////////////////////

// -------------
// setTyp()
// -------------
Notedata.prototype.setTyp = function(str) {
  if (arguments.length != 1) {
    focus();
    throw new Error("Notedata->setTyp: Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Notedata->setTyp: Argument ist nicht vom Typ String!");
  }
  this.typ = str;
}

// -------------
// setTitle()
// -------------
Notedata.prototype.setTitle = function(str) {
  if (arguments.length != 1) {
    focus();
    throw new Error("Notedata->setTitle: Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Notedata->setTitle: Argument ist nicht vom Typ String!");
  }
  this.title = str;
}

// -------------
// setSubTitle()
// -------------
Notedata.prototype.setSubTitle = function(str) {
  if (arguments.length != 1) {
    focus();
    throw new Error("Notedata->setSubTitle: Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Notedata->setSubTitle: Argument ist nicht vom Typ String!");
  }
  this.subtitle = str;
}

// -------------
// setText()
// -------------
Notedata.prototype.setText = function(str) {
  if (arguments.length != 1) {
    focus();
    throw new Error("Notedata->setText: Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Notedata->setText: Argument ist nicht vom Typ String!");
  }
  this.text = str;
}

// -------------
// setAutor()
// -------------
Notedata.prototype.setAutor = function(str) {
  if (arguments.length != 1) {
    focus();
    throw new Error("Notedata->setAutor: Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Notedata->setAutor: Argument ist nicht vom Typ String!");
  }
  this.autor = str;
}

// -------------
// setImageURL()
// -------------
Notedata.prototype.setImageURL = function(str) {
  if (arguments.length != 1) {
    focus();
    throw new Error("Notedata->setImageURL: Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Notedata->setImageURL: Argument ist nicht vom Typ String!");
  }
  this.imageURL = str;
}

// -------------
// setDetailURL()
// -------------
Notedata.prototype.setDetailURL = function(str) {
  if (arguments.length != 1) {
    focus();
    throw new Error("Notedata->setDetailURL: Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Notedata->setDetailURL: Argument ist nicht vom Typ String!");
  }
  this.detailURL = str;
}

// -------------
// setOrt()
// -------------
Notedata.prototype.setOrt = function(str) {
  if (arguments.length != 1) {
    focus();
    throw new Error("Notedata->setOrt: Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Notedata->setOrt: Argument ist nicht vom Typ String!");
  }
  this.ort = str;
}

// -------------
// setRegion()
// -------------
Notedata.prototype.setRegion = function(str) {
  if (arguments.length != 1) {
    focus();
    throw new Error("Notedata->setRegion: Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Notedata->setRegion: Argument ist nicht vom Typ String!");
  }
  this.region = str;
}

/////////////////////////////////////////////////
// private Klasseneigenschaften
/////////////////////////////////////////////////

Notedata._defaultID = [];

Notedata._registerInstance = {};

/////////////////////////////////////////////////
// private Klassenmethoden
/////////////////////////////////////////////////

/////////////////////////////////////////////////
// öffentliche Klasseneigenschaften
/////////////////////////////////////////////////

/////////////////////////////////////////////////
// öffentliche Klassenmethoden
/////////////////////////////////////////////////

// ----------------
// getInstance
// ----------------
Notedata.getInstance = function (idx) {
  if (arguments.length!=1) {
    throw new Error("Notedata.getInstance: Falsche Anzahl von Argumenten!");
  }
  if (! (Notedata._registerInstance[idx])){
    focus();
    throw new Error("Notedata.getInstance: Es ist keine Notedata.Instance mit id=" + idx + " registriert!");
  } 
  return Notedata._registerInstance[idx];
}

// ----------------
// createInstance
// ----------------
Notedata.createInstance = function (idx) {
  if (!arguments.length) {
    idx = Notedata._defaultID.length;
    Notedata._defaultID.push('1');
  }
  idx = idx.toString();
  if (! (Notedata._registerInstance[idx])){
    Notedata._registerInstance[idx] = new Notedata(idx);
  } 
  return Notedata.getInstance(idx);
}  



