
//==================================================================================
//==================================================================================
// 
// TEMPLATES-MODUL
// AUTOR: DF
// ERSTELLT: 04.05.2005
//
//==================================================================================
//==================================================================================

// ============================================================
// Globale Deklarationen
// ============================================================

// den undefinierten Wert deklarieren
var undefined;


// ============================================================
// Klasse ShopTemplates
// ============================================================

// ------------------------------------------------------------
// Konstruktor
// ------------------------------------------------------------

// ---------------------------------------
// ShopTemplates()
// ---------------------------------------
//
// Beispiel:
// ---------
// new ShopTemplates()
//
function ShopTemplates() {
}

// ------------------------------------------------------------
// Zugriffsfunktionen
// ------------------------------------------------------------

// ------------------------------------------------------------
// Öffentliche Instanzmethoden
// ------------------------------------------------------------

// ------------------------------------------------------------
// Private Instanzmethoden
// ------------------------------------------------------------

// ------------------------------------------------------------
// Öffentliche Klasseneigenschaften
// ------------------------------------------------------------

// ------------------------------------------------------------
// Private Klasseneigenschaften
// ------------------------------------------------------------

// ------------------------------------------------------------
// Öffentliche Klassenmethoden
// ------------------------------------------------------------

// -------------------------------------------
// ShopTemplates.getHTMLCompactShoppingCart()
// -------------------------------------------
//
// Beschreibung:
// -------------
//   ...
//
// Beispiel:
// ---------
// ShopTemplates.getHTMLCompactShoppingCart();
//

ShopTemplates.getHTMLCompactShoppingCart = function(obj) { 
  var html = '';
  if (arguments.length) {
    if (! obj instanceof Order) {
      focus();
      throw new Error("ArgumentError:noObjectFromClassOrder!");
    }
    html += '<div class="warenkorb-willi">\n';
    html += '<img src="/kiosk/grafik/willi_warenkorb.gif" style="width: 71px; height: 93px;" alt="" title="" /><br />\n';
    html += '</div>\n';
    html += '<div class="warenkorb-eintraege">\n';
    html += '<div class="warenkorb-eintraege-artikel" id="shop-artikelanzahl">\n';
    html += '<span class="warenkorb-eintraege-artikel-artikelanzahl">'+ obj.getTotalQuantity() +'</span> Artikel\n';
    html += '</div>\n';
    html += '<div class="warenkorb-eintraege-summe" id="shop-summe">\n';
    html += 'Summe:<br />\n';
    html += '<span class="warenkorb-eintraege-summe-wert">'+ obj.getTotalPrice() +' EUR</span>\n';
    html += '</div>\n';
    html += '<div class="warenkorb-eintraege-link">\n';
    html += '<a href="javascript:showShoppingCart();" class="warenkorb-link">Zum Warenkorb</a>\n';
    html += '</div>\n';
    html += '</div>\n';
    html += '<div class="float-aufheben"><br />\n';
  }
  return html;
}

// -------------------------------------------
// ShopTemplates.getHTMLShoppingCart()
// -------------------------------------------
//
// Beschreibung:
// -------------
//   ...
//
// Beispiel:
// ---------
// ShopTemplates.getHTMLShoppingCart();
//

ShopTemplates.getHTMLShoppingCart = function(obj) { 
  var html = '';
  if (arguments.length) {
    if (! obj instanceof Order) {
      focus();
      throw new Error("ArgumentError:noObjectFromClassOrder!");
    }
    html += '<div class="zwischenueberschrift">\n';
    html += '<div class="zwischenueberschrift-titel">\n';
    html += '<h2>Artikelübersicht</h2>\n';
    html += '</div>\n';
    html += '</div>\n';
    html += '<form name="warenkorb" onsubmit="return false;">\n';
    html += '<div class="tabelle">\n';
    html += '<div class="tabelle-inhalt">\n';
    html += '<table cellspacing="0" cellpadding="0" class="tabelle-warenkorb">\n';
    html += '<tr>\n';
    html += '<th class="tabelle-warenkorb-th-left" id="tabelle-warenkorb-th-id-1">\n';
    html += 'Artikel<br />\n';
    html += '</th>\n';
    html += '<th class="tabelle-warenkorb-th-right" id="tabelle-warenkorb-th-id-2">\n';
    html += 'Preis<br />\n';
    html += '</th>\n';
    html += '<th class="tabelle-warenkorb-th-center" id="tabelle-warenkorb-th-id-3">\n';
    html += 'Anzahl<br />\n';
    html += '</th>\n';
    html += '<th class="tabelle-warenkorb-th-right" id="tabelle-warenkorb-th-id-4">\n';
    html += 'Gesamt<br />\n';
    html += '</th>\n';
    html += '</tr>\n';
    for (var i=0; i<obj.orderedItemList().length; i++){
      html += '<tr>\n';
      html += '<td class="tabelle-warenkorb-td-left">\n';
      html += '<span class="hervorheben">'+ obj.orderedItemList()[i].item().title() +'</span><br />\n';
      if (obj.orderedItemList()[i].item().propertyMap()['untertitel']){
        html += obj.orderedItemList()[i].item().propertyMap()['untertitel']._value + '<br/>\n'; 
      }
      if (obj.orderedItemList()[i].item().propertyMap()['typ']){
        html += '(Typ: ' + obj.orderedItemList()[i].item().propertyMap()['typ']._value + ')<br/>\n'; 
      }
      html += '</td>\n';
      html += '<td class="tabelle-warenkorb-td-right" nowrap="nowrap">\n';
      html += obj.orderedItemList()[i].item().getFormatedPrice() + ' EUR<br />\n';
      html += '</td>\n';
      html += '<td class="tabelle-warenkorb-td-center" nowrap="nowrap">\n';
      html += '<input type="text" name="Anzahl-feld-1" id="form-id-artikeleintrag-feld-1" value="'+ obj.orderedItemList()[i].quantity() +'" class="formular-inhalt-einzeilig_" onfocus="this.select();" onchange="updateShoppingCart(\''+ obj.orderedItemList()[i].item().id() +'\', this.value);" /><br />\n';
      html += '</td>\n';
      html += '<td class="tabelle-warenkorb-td-right" nowrap="nowrap">\n';
      html += obj.orderedItemList()[i].getTotalPrice() + ' EUR<br />\n';
      html += '</td>\n';
      html += '</tr>\n';
    }
   html += '<tr>\n';
   html += '<td class="tabelle-warenkorb-td-summe-left" colspan="3">\n';
   html += 'enthaltene MwSt. 19%<br />\n';
   html += '</td>\n';
   html += '<td class="tabelle-warenkorb-td-summe-right" nowrap="nowrap">\n';
   html += obj.getTaxFromTotalPriceTaxInclusive() +' EUR<br />\n';
   html += '</td>\n';
   html += '</tr>\n';
   html += '<tr>\n';
   html += '<td class="tabelle-warenkorb-td-summe-left" colspan="3">\n';
   html += 'Summe<br />\n';
   html += '</td>\n';
   html += '<td class="tabelle-warenkorb-td-summe-right" nowrap="nowrap">\n';
   html += obj.getTotalPrice() +' EUR<br />\n';
   html += '</td>\n';
   html += '</tr>\n';
   html += '</table>\n';
   html += '</div>\n';
   html += '</div>\n';
   html += '</form>\n';
  }
  return html;
}

// -------------------------------------------
// ShopTemplates.getHTMLCustomerDataForm()
// -------------------------------------------
//
// Beschreibung:
// -------------
//   ...
//
// Beispiel:
// ---------
// ShopTemplates.getHTMLCustomerDataForm();
//

ShopTemplates.getHTMLCustomerDataForm = function(obj) { 
  var html = '';
  if (arguments.length) {
    if (! obj instanceof Order) {
      focus();
      throw new Error("ArgumentError:noObjectFromClassOrder!");
    }
    
    html += '<div class="zwischenueberschrift">\n';
    html += '<div class="zwischenueberschrift-titel">\n';
    html += '<h2>Adressdaten</h2>\n';
    html += '</div>\n';
    html += '</div>\n';

    html += '<div class="artikeleintrag">\n';

    html += '<div class="artikeleintrag-inhalt">\n';

    html += '<div class="artikeleintrag-inhalt-formular">\n';

    html += '<div class="artikeleintrag-inhalt-formular-eintrag">\n';
    html += '<div class="artikeleintrag-inhalt-formular-wert">\n';
    html += '<label for="Name">Name:</label><br />\n';
    html += '</div>\n';
    html += '<div class="artikeleintrag-inhalt-formular-feld">\n';
    var name = '';
    if (obj.customer().name() != undefined){
      name = obj.customer().name();
    }
    html += '<input type="text" name="Name" id="Name" value="'+ name +'" class="formular-inhalt-einzeilig" onfocus="this.select();" onchange="parent.top.Order.GetInstance().customer().setName(this.value);" /><br />\n';
    html += '</div>\n';
    html += '<div class="float-aufheben"><br /></div>\n';
    html += '</div>\n';

    html += '<div class="artikeleintrag-inhalt-formular-eintrag">\n';
    html += '<div class="artikeleintrag-inhalt-formular-wert">\n';
    html += '<label for="Vorname">Vorname:</label><br />\n';
    html += '</div>\n';
    html += '<div class="artikeleintrag-inhalt-formular-feld">\n';
    var vorname = '';
    if (obj.customer().firstName() != undefined){
      vorname = obj.customer().firstName();
    }
    html += '<input type="text" name="Vorname" id="Vorname" value="'+ vorname +'" class="formular-inhalt-einzeilig" onfocus="this.select();" onchange="parent.top.Order.GetInstance().customer().setFirstName(this.value);" /><br />\n';
    html += '</div>\n';
    html += '<div class="float-aufheben"><br /></div>\n';
    html += '</div>\n';

    html += '<div class="artikeleintrag-inhalt-formular-eintrag">\n';
    html += '<div class="artikeleintrag-inhalt-formular-wert">\n';
    html += '<label for="Strasse_Nr">Straße/Nr.:</label><br />\n';
    html += '</div>\n';
    html += '<div class="artikeleintrag-inhalt-formular-feld">\n';
    var strasse = '';
    if (obj.customer().street() != undefined){
      strasse = obj.customer().street();
    }
    html += '<input type="text" name="Strasse_Nr" id="Strasse_Nr" value="'+ strasse +'" class="formular-inhalt-einzeilig" onfocus="this.select();" onchange="parent.top.Order.GetInstance().customer().setStreet(this.value);" /><br />\n';
    html += '</div>\n';
    html += '<div class="float-aufheben"><br /></div>\n';
    html += '</div>\n';

    html += '<div class="artikeleintrag-inhalt-formular-eintrag">\n';
    html += '<div class="artikeleintrag-inhalt-formular-wert">\n';
    html += '<label for="PLZ">PLZ:</label><br />\n';
    html += '</div>\n';

    html += '<div class="artikeleintrag-inhalt-formular-feld">\n';
    var plz = '';
    if (obj.customer().postCode() != undefined){
      plz = obj.customer().postCode();
    }
    html += '<input type="text" name="PLZ" id="PLZ" value="'+ plz +'" class="formular-inhalt-einzeilig" onfocus="this.select();" onchange="parent.top.Order.GetInstance().customer().setPostCode(this.value);" /><br />\n';
    html += '</div>\n';
    html += '<div class="float-aufheben"><br /></div>\n';
    html += '</div>\n';

    html += '<div class="artikeleintrag-inhalt-formular-eintrag">\n';
    html += '<div class="artikeleintrag-inhalt-formular-wert">\n';
    html += '<label for="Ort">Ort:</label><br />\n';
    html += '</div>\n';
    html += '<div class="artikeleintrag-inhalt-formular-feld">\n';
    var ort = '';
    if (obj.customer().city() != undefined){
      ort = obj.customer().city();
    }
    html += '<input type="text" name="Ort" id="Ort" value="'+ ort +'" class="formular-inhalt-einzeilig" onfocus="this.select();" onchange="parent.top.Order.GetInstance().customer().setCity(this.value);" /><br />\n';

    html += '</div>\n';
    html += '<div class="float-aufheben"><br /></div>\n';
    html += '</div>\n';

    html += '<div class="artikeleintrag-inhalt-formular-eintrag">\n';
    html += '<div class="artikeleintrag-inhalt-formular-wert">\n';
    html += '<label for="Telefon">Telefon:</label><br />\n';
    html += '</div>\n';
    html += '<div class="artikeleintrag-inhalt-formular-feld">\n';

    var tel = '';
    if (obj.customer().telephone() != undefined){
      tel = obj.customer().telephone();
    }
    html += '<input type="text" name="Telefon" id="Telefon" value="'+ tel +'" class="formular-inhalt-einzeilig" onfocus="this.select();" onchange="parent.top.Order.GetInstance().customer().setTelephone(this.value);" /><br />\n';
    html += '</div>\n';
    html += '<div class="float-aufheben"><br /></div>\n';
    html += '</div>\n';

    html += '<div class="artikeleintrag-inhalt-formular-eintrag">\n';
    html += '<div class="artikeleintrag-inhalt-formular-wert">\n';
    html += '<label for="Email">E-Mail-Adresse:</label><br />\n';
    html += '</div>\n';

    html += '<div class="artikeleintrag-inhalt-formular-feld">\n';

    var mail = '';
    if (obj.customer().email() != undefined){
      mail = obj.customer().email();
    }
    html += '<input type="text" name="Email" id="Email" value="'+ mail +'" class="formular-inhalt-einzeilig" onfocus="this.select();" onchange="parent.top.Order.GetInstance().customer().setEmail(this.value);" /><br />\n';
    html += '</div>\n';
    html += '<div class="float-aufheben"><br /></div>\n';
    html += '</div>\n';

    html += '<div class="artikeleintrag-inhalt-formular-eintrag">\n';
    html += '<div class="artikeleintrag-inhalt-formular-wert">\n';
    html += '<br />\n';
    html += '</div>\n';

    html += '<div class="artikeleintrag-inhalt-formular-feld">\n';
    
    html += '<input type="checkbox" name="AGB" id="AGB" value="Ich akzeptiere die AGB." onfocus="this.select();" checked="checked"/> Ich akzeptiere die <a href="http://www.brueder.info/cgi-bin/cms?_SID=fake&_bereich=artikel&_aktion=detail&idartikel=100467&idrubrik=1002&_sprache=shop">AGB</a>.<br />\n';
    html += '</div>\n';
    html += '<div class="float-aufheben"><br /></div>\n';
    html += '</div>\n';

    html += '</div>\n';

    html += '<div class="float-aufheben"><br /></div>\n';

    html += '</div>\n';

    html += '</div>\n';

    html += '<input type="submit" value="bestellen" class="formular-inhalt-button" /><br />\n';

    html += '</div>\n';
  }
  return html;
}

// -------------------------------------------
// ShopTemplates.getTextOrderItems()
// -------------------------------------------
//
// Beschreibung:
// -------------
//   ...
//
// Beispiel:
// ---------
// ShopTemplates.getTextOrderItems();
//

ShopTemplates.getTextOrderItems = function(obj) { 
  var str = '';
  if (arguments.length) {
    if (! obj instanceof Order) {
      focus();
      throw new Error("ArgumentError:noObjectFromClassOrder!");
    }
    for (var i=0; i<obj.orderedItemList().length; i++){
      if (i==0){
        str += '\n';
        str += '\n';
      }
      str += 'Artikel ' + parseFloat(i+1) + ':\n';
      str += 'Titel: ' + obj.orderedItemList()[i].item().title() + '\n';
      if (obj.orderedItemList()[i].item().propertyMap()['artikel-id']){
        str += 'Artikel-Nr.: ' + obj.orderedItemList()[i].item().propertyMap()['artikel-id']._value + '\n'; 
      }
      if (obj.orderedItemList()[i].item().propertyMap()['typ']){
        str += 'Typ: ' + obj.orderedItemList()[i].item().propertyMap()['typ']._value + '\n'; 
      }
      str += 'Preis: ' + obj.orderedItemList()[i].item().getFormatedPrice() + ' EUR\n';
      str += 'Anzahl: ' + obj.orderedItemList()[i].quantity() + '\n';
      str += 'Summe: ' + obj.orderedItemList()[i].getTotalPrice() + ' EUR\n';
      str += '-----------\n';
    }
    str += '\n';
    str += 'entahltene MwSt 19%: ' + obj.getTaxFromTotalPriceTaxInclusive() + ' EUR\n';
    str += 'Gesamtsumme: ' + obj.getTotalPrice() + ' EUR\n';
  }
  return str;
}

// -------------------------------------------
// ShopTemplates.getTextCustomerData()
// -------------------------------------------
//
// Beschreibung:
// -------------
//   ...
//
// Beispiel:
// ---------
// ShopTemplates.getTextCustomerData();
//

ShopTemplates.getTextCustomerData = function(obj) { 
  var str = '';
  if (arguments.length) {
    if (! obj instanceof Order) {
      focus();
      throw new Error("ArgumentError:noObjectFromClassOrder!");
    }
    if (obj.customer().name() != undefined){
      str += 'Name: ' + obj.customer().name() + '\n';
    }
    if (obj.customer().firstName() != undefined){
      str += 'Vorname: ' + obj.customer().firstName() + '\n';
    }
    if (obj.customer().street() != undefined){
      str += 'Straße/Nr.: ' + obj.customer().street() + '\n';
    }
    if (obj.customer().postCode() != undefined){
      str += 'PLZ: ' + obj.customer().postCode() + '\n';
    }
    if (obj.customer().city() != undefined){
      str += 'Ort: ' + obj.customer().city() + '\n';
    }
    if (obj.customer().telephone() != undefined){
      str += 'Tel.: ' + obj.customer().telephone() + '\n';
    }
    if (obj.customer().email() != undefined){
      str += 'E-Mail: ' + obj.customer().email() + '\n';
    }
  }
  return str;
}

// ------------------------------------------------------------
// Private Klassenmethoden
// ------------------------------------------------------------

// ------------------------------------------------------------
// toString()
// ------------------------------------------------------------

ShopTemplates.prototype.toString = function() {
  // zunaechst an Methode der Basisklasse weiterleiten
  return Object.prototype.toString.apply(this);
}
