//***************************************************************************************************
//***************************************************************************************************
//**
//** Notepad
//** Autor: DF
//** Erstellung: 19.12.2006
//** © rdts AG
//**
//***************************************************************************************************
//***************************************************************************************************

var undefined;

//***************************************************************************************************
// Notepad
//***************************************************************************************************

// Konstruktor:
// ------------
//   + Notepad()
//   + Notepad.createInstance()
//
// Eigenschaften:
// --------------
//   + _id: str
//   + _language: str
//   + _viewElementName: str
//   + _viewElementWindowName: str
//   + _systemURLPrefix: str
//   + _systemHTMLROOTPrefix: str
//   + noteData: obj (Hash)
//   + noteDataLenght: arr

function Notepad(idx) {
  this._id = undefined;
  this._language = Notepad._defaultLanugage;
  this._systemURLPrefix = '';
  this._systemHTMLROOTPrefix = '';
  this._viewElementName = undefined;
  this._viewElementWindowName = undefined;
  this._viewListElementName = undefined;
  this._viewListElementWindowName = 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;
}

// -------------
// setViewElementName()
// -------------
Notepad.prototype.setViewElementName = function(str) {
  if (arguments.length != 1) {
    focus();
    throw new Error("Notepad->setViewElementName: Falsche Anzahl von Argumenten!");
  }
  this._viewElementName = str;
}

// -------------
// setViewElementWindowName()
// -------------
Notepad.prototype.setViewElementWindowName = function(str) {
  if (arguments.length != 1) {
    focus();
    throw new Error("Notepad->setViewElementWindowName: Falsche Anzahl von Argumenten!");
  }
  this._viewElementWindowName = str;
}

// -------------
// setViewListElementName()
// -------------
Notepad.prototype.setViewListElementName = function(str) {
  if (arguments.length != 1) {
    focus();
    throw new Error("Notepad->setViewListElementName: Falsche Anzahl von Argumenten!");
  }
  this._viewListElementName = str;
}

// -------------
// setViewListElementWindowName()
// -------------
Notepad.prototype.setViewListElementWindowName = function(str) {
  if (arguments.length != 1) {
    focus();
    throw new Error("Notepad->setViewListElementWindowName: Falsche Anzahl von Argumenten!");
  }
  this._viewListElementWindowName = str;
}

// -------------
// setSystemURLPrefix()
// -------------
Notepad.prototype.setSystemURLPrefix = function(str) {
  if (arguments.length != 1) {
    focus();
    throw new Error("Notepad->setSystemURLPrefix: Falsche Anzahl von Argumenten!");
  }
  this._systemURLPrefix = str;
}

// -------------
// setHTMLROOTPrefix()
// -------------
Notepad.prototype.setHTMLROOTPrefix = function(str) {
  if (arguments.length != 1) {
    focus();
    throw new Error("Notepad->setHTMLROOTPrefix: Falsche Anzahl von Argumenten!");
  }
  this._systemHTMLROOTPrefix = 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 += '<a href="'+ this._systemURLPrefix +'&amp;_bereich=artikel&amp;_aktion=detail&amp;idartikel=100021&amp;_sprache=memo">';
  if (this.dataLength() < 1){
    xhtml += '<img src="'+ this._systemHTMLROOTPrefix +'/grafik/zmenue_2.gif" style="width: 248px; height: 15px;" alt="Grafik: Menüpunkt Einkaufszettel." title="EINKAUFSZETTEL" />';
  } else {
    xhtml += '<img src="'+ this._systemHTMLROOTPrefix +'/grafik/zmenue_2_ani.gif" style="width: 248px; height: 15px;" alt="Grafik: Menüpunkt Einkaufszettel." title="EINKAUFSZETTEL" />';
  }
  xhtml += '</a><br />\n';
  xhtml += '<div class="hauptmenue-punkt-einkaufszettel" style="display: block;">\n';
  if (this.dataLength() == 1){
    xhtml += this.dataLength() + ' Eintrag<br />\n';
  } else {
    xhtml += this.dataLength() + ' Einträge<br />\n';
  }
  xhtml += '</div>\n';
  if (window[this._viewElementWindowName]){
    var elem = window[this._viewElementWindowName].document.getElementById(this._viewElementName);
    if (elem){
      elem.innerHTML = xhtml;
      /*
      if (this.dataLength() > 0){
        elem.style.display = 'block';
      } else {
        elem.style.display = 'none';
      }*/
    }
  }
}


// -------------
// drawNotepadDetail()
// -------------
Notepad.prototype.drawNotepadDetail = function() {
  var xhtml = ''
  if (this.dataLength() > 0){
    for (var i in this.noteData){
      var data = this.noteData[i];
      xhtml += '<div class="artikel-eintrag-notepad">\n';
      
      xhtml += '<div class="artikel-eintrag-datum-notepad">\n';
      xhtml += data.title + '<br />\n';
      xhtml += '</div>\n';

      xhtml += '<div class="artikel-eintrag-inhalt-notepad">\n';
      xhtml += '<div class="artikel-eintrag-inhalt-untertitel-notepad">\n';
      if (data.imageURL){
        xhtml += '<img src="'+ data.imageURL +'" border="0" style="float: right;"/>\n';
      }
      if (data.branche1){
        xhtml += 'Branche/n: ' + data.branche1;
        if (data.branche2){
          xhtml += data.branche2;
        }
        xhtml += '<br />\n';
        xhtml += '<br />\n';
      }
      if (data.adresse){
        xhtml += data.adresse + '<br />\n';
        xhtml += '<br />\n';
      }
      if (data.telefon){
        xhtml += 'Telefon: ' + data.telefon + '<br />\n';
      }
      if (data.telefax){
        xhtml += 'Telefax: ' + data.telefax + '<br />\n';
      }
      xhtml += '<br />\n';
      if (data.ansprechpartner){
        xhtml += 'Ansprechpartner/in: ' + data.ansprechpartner + '<br />\n';
      }
      xhtml += '</div>\n';
      xhtml += '</div>\n';
      xhtml += '<div class="artikel-eintrag-bild-delete">\n';
      xhtml += '<br /><a href="javascript:void(0);" class="artikel-eintrag-bild-delete" onclick="deleteNotepadData(\''+ data.id() +'\');"><img src="/kiosk/grafik/merkzettel_loeschen.gif" alt="Grafik: Vom Einkaufszettel löschen." title="Vom Einkaufszettel löschen."/></a><br />\n';
      xhtml += '</div>\n';

      xhtml += '</div>\n';
      xhtml += '<hr class="artikel-eintrag-notepad" />\n';
      xhtml += '<div class="float-aufheben"><br /></div>\n';
    }
  } else {
    xhtml += '<div class="artikel-eintrag-notepad">\n';

    xhtml += '<div class="artikel-eintrag-inhalt-notepad">\n';
    xhtml += '<div class="artikel-eintrag-inhalt-untertitel-notepad">\n';
    
    if (Notepad._alertAddData[this._language]){
      xhtml += Notepad._alertNoData[this._language] + '\n';
    } else {
      xhtml += Notepad._alertNoData[Notepad._defaultLanugage] + '\n';
    }
    
    xhtml += '</div>\n';
    xhtml += '</div>\n';    

    xhtml += '</div>\n';
    xhtml += '<div class="float-aufheben"><br /></div>\n';
  }  

  if (window[this._viewListElementWindowName]){
    var elem = window[this._viewListElementWindowName].document.getElementById(this._viewListElementName);
    if (elem){
      elem.innerHTML = xhtml;
    }
  }
}  

/////////////////////////////////////////////////
// private Klasseneigenschaften
/////////////////////////////////////////////////

Notepad._defaultID = [];

Notepad._registerInstance = {};

Notepad._alertAddData = {};
Notepad._alertAddData['de'] = 'Die Firma wurde auf den Einkaufszettel gesetzt.';
Notepad._alertAddData['uk'] = 'The company has been added to the Notepad';

Notepad._alertNoData = {};
Notepad._alertNoData['de'] = 'Es liegen keine Einträge auf dem Einkaufszettel 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
//   + adresse: str
//   + telefon: str
//   + telefax: str
//   + ansprechpartner: str
//   + branche1: str
//   + branche2: 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.adresse = undefined;
  this.telefon = undefined;
  this.telefax = undefined;
  this.ansprechpartner = undefined;
  this.branche1 = undefined;
  this.branche2 = 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;
}

// -------------
// setAdresse()
// -------------
Notedata.prototype.setAdresse = function(str) {
  if (arguments.length != 1) {
    focus();
    throw new Error("Notedata->setAdresse: Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Notedata->setAdresse: Argument ist nicht vom Typ String!");
  }
  this.adresse = str;
}

// -------------
// setTelefon()
// -------------
Notedata.prototype.setTelefon = function(str) {
  if (arguments.length != 1) {
    focus();
    throw new Error("Notedata->setTelefon: Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Notedata->setTelefon: Argument ist nicht vom Typ String!");
  }
  this.telefon = str;
}

// -------------
// setTelefax()
// -------------
Notedata.prototype.setTelefax = function(str) {
  if (arguments.length != 1) {
    focus();
    throw new Error("Notedata->setTelefax: Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Notedata->setTelefax: Argument ist nicht vom Typ String!");
  }
  this.telefax = str;
}

// -------------
// setAnsprechpartner()
// -------------
Notedata.prototype.setAnsprechpartner = function(str) {
  if (arguments.length != 1) {
    focus();
    throw new Error("Notedata->setAnsprechpartner: Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Notedata->setAnsprechpartner: Argument ist nicht vom Typ String!");
  }
  this.ansprechpartner = str;
}

// -------------
// setBranche1()
// -------------
Notedata.prototype.setBranche1 = function(str) {
  if (arguments.length != 1) {
    focus();
    throw new Error("Notedata->setBranche1: Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Notedata->setBranche1: Argument ist nicht vom Typ String!");
  }
  this.branche1 = str;
}

// -------------
// setBranche2()
// -------------
Notedata.prototype.setBranche2 = function(str) {
  if (arguments.length != 1) {
    focus();
    throw new Error("Notedata->setBranche2: Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Notedata->setBranche2: Argument ist nicht vom Typ String!");
  }
  this.branche2 = 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);
}  



