
//==================================================================================
//==================================================================================
// 
// 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 += '<table cellspacing="0" cellpadding="0">\n';
    html += '<tr>\n';
    html += '<th>Artikel<br /></th>\n';
    html += '<td>'+ obj.getTotalQuantity() +'</td>\n';
    html += '</tr>\n';
    html += '<tr>\n';
    html += '<th>Summe:<br /></th>\n';
    html += '<td>'+ obj.getTotalPrice() +' EUR</td>\n';
    html += '</tr>\n';
    html += '</table>\n';
  }
  return html;
}

// -------------------------------------------
// ShopTemplates.getHTMLShoppingCart()
// -------------------------------------------
//
// Beschreibung:
// -------------
//   ...
//
// Beispiel:
// ---------
// ShopTemplates.getHTMLShoppingCart();
//

ShopTemplates.getHTMLShoppingCart = function(obj) { 
  var articleLink = false;
  if (ShopTemplates.CMSURL!=undefined){
    articleLink = ShopTemplates.CMSURL + '&_sprache=de&_bereich=artikel&_aktion=detail&idartikel=';
  }
  var html = '';
  if (arguments.length) {
    if (! obj instanceof Order) {
      focus();
      throw new Error("ArgumentError:noObjectFromClassOrder!");
    }
      html += '<form id="warenkorb" onsubmit="return false;">\n';
      html += '<div class="warenkorbdetail-inhalt">\n';
      html += '<table cellspacing="0" cellpadding="0" class="table-warenkorbdetail-inhalt">\n';
      html += '<tr>\n';
      html += '<th class="table-warenkorbdetail-inhalt-titel-artikel">\n';
      html += '<img src="/kiosk/grafik/warenkorbdetail_titel_artikel.gif" style="width: px; height: px;" alt="Artikel." title="Artikel." /><br />\n';
      html += '</th>\n';
      html += '<th class="table-warenkorbdetail-inhalt-titel-preis">\n';
      html += '<img src="/kiosk/grafik/warenkorbdetail_titel_preis.gif" style="width: px; height: px;" alt="Preis." title="Preis." /><br />\n';
      html += '</th>\n';
      html += '<th class="table-warenkorbdetail-inhalt-titel-anzahl">\n';
      html += '<img src="/kiosk/grafik/warenkorbdetail_titel_anzahl.gif" style="width: px; height: px;" alt="Anzahl." title="Anzahl." /><br />\n';
      html += '</th>\n';
      html += '<th class="table-warenkorbdetail-inhalt-titel-gesamt">\n';
      html += '<img src="/kiosk/grafik/warenkorbdetail_titel_gesamt.gif" style="width: px; height: px;" alt="Gesamt." title="Gesamt." /><br />\n';
      html += '</th>\n';
      html += '</tr>\n';
              
    for (var i=0; i<obj.orderedItemList().length; i++){
      html += '<tr>\n';
      html += '<td class="table-warenkorbdetail-inhalt-artikel">\n';
      html += '<div class="warenkorbdetail-inhalt-artikel">\n';
      if (obj.orderedItemList()[i].item().propertyMap()['bezeichnung']){
      html += '<div class="warenkorbdetail-inhalt-artikel-name">\n';
      html += '<p>\n';
      html += obj.orderedItemList()[i].item().propertyMap()['bezeichnung']._value;
      html += '</p>\n';
      html += '</div>\n';
      }
      html += '<div class="warenkorbdetail-inhalt-artikel-titel">\n';
      if (articleLink){
        var _id = obj.orderedItemList()[i].item().id().toString().split(/\[/)[0];
        html += '<h4><a href="'+ articleLink +'' + _id + '">' + obj.orderedItemList()[i].item().title() + '</a></h4>\n';
      } else {
        html += '<h4>' + obj.orderedItemList()[i].item().title() + '</h4>\n';
      }
      html += '</div>\n';
      if (obj.orderedItemList()[i].item().propertyMap()['verbund']){
      html += '<div class="warenkorbdetail-inhalt-artikel-text">\n';
      html += '<p>\n';
      html += obj.orderedItemList()[i].item().propertyMap()['verbund']._value;
      html += '</p>\n';
      html += '</div>\n';
      html += '</div>\n';
      }
      html += '</td>\n';
      html += '<td class="table-warenkorbdetail-inhalt-preis">\n';
      html += '<div class="warenkorbdetail-inhalt-preis">\n';
      html += '<p>\n';
      html += obj.orderedItemList()[i].item().getFormatedPrice() +' EUR\n';
      html += '</p>\n';
      html += '</div>\n';
      html += '</td>\n';
      html += '<td class="table-warenkorbdetail-inhalt-anzahl">\n';
      html += '<div class="warenkorbdetail-inhalt-menge">\n';
      html += '<a href="javascript:void(0);" onclick="updateShoppingCart(\''+ obj.orderedItemList()[i].item().id() +'\', \'0\');" style="display: inline;"><img src="/kiosk/grafik/button_shop_delete.gif" alt="Artikel aus dem Warenkorb entfernen" title="Artikel aus dem Warenkorb entfernen" style="float: right; padding: 1px 5px 0 0;"/></a><input type="text" id="feld-'+ i +'" name="Anzahl-Flaschen-'+ i +'" class="warenkorbdetail-anzahl" value="'+ obj.orderedItemList()[i].quantity() +'" onchange="updateShoppingCart(\''+ obj.orderedItemList()[i].item().id() +'\', this.value);"/>\n';
      html += '</div>\n';
      html += '</td>\n';
      html += '<td class="table-warenkorbdetail-inhalt-gesamt">\n';
      html += '<div class="warenkorbdetail-inhalt-preis">\n';
      html += '<p>\n';
      html += obj.orderedItemList()[i].getTotalPrice() + ' EUR\n';
      html += '</p>\n';
      html += '</div>\n';
      html += '</td>\n';
      html += '</tr>\n';
    }
    
    html += '<tr>\n';
    html += '<td colspan="3" class="table-warenkorbdetail-fuss-titel" style="background-color: #90A6CE;">\n';
    html += 'enthaltene MwSt. '+ Order.TaxRate +'%<br />\n';
    html += '</td>\n';
    html += '<td class="table-warenkorbdetail-fuss-gesamtpreis" style="background-color: #90A6CE;">\n';
    html += '<div class="warenkorbdetail-inhalt-preis">\n';
    html += '<p>\n';
    html += obj.getTaxFromTotalPriceTaxInclusive() +' EUR\n';
    html += '</p>\n';
    html += '</div>\n';
    html += '</td>\n';
    html += '</tr>\n';
    
    html += '<tr>\n';
    html += '<td colspan="3" class="table-warenkorbdetail-fuss-titel" style="background-color: #90A6CE;">\n';
    html += 'Lieferung<br />\n';
    html += '</td>\n';
    html += '<td class="table-warenkorbdetail-fuss-gesamtpreis" style="background-color: #90A6CE;">\n';
    html += '<div class="warenkorbdetail-inhalt-preis">\n';
    html += '<p>\n';
    html += ShopTemplates.getSendingPrice(obj) +' EUR\n';
    html += '</p>\n';
    html += '</div>\n';
    html += '</td>\n';
    html += '</tr>\n';
    
    html += '<tr>\n';
    html += '<td colspan="3" class="table-warenkorbdetail-fuss-titel">\n';
    html += 'Summe<br />\n';
    html += '</td>\n';
    html += '<td class="table-warenkorbdetail-fuss-gesamtpreis">\n';
    html += '<div class="warenkorbdetail-inhalt-preis">\n';
    html += '<p>\n';
    html += ShopTemplates.getTotalPrice(obj) +' EUR\n';
    html += '</p>\n';
    html += '</div>\n';
    html += '</td>\n';
    html += '</tr>\n';

    html += '<tr>';
    html += '<td colspan="3" class="table-warenkorbdetail-anhang-text">';
    html += '<span style="color:#657DAB;">Mindestbestellung 6 Flaschen, bzw. 40 EUR. Alle Preise inkl. Sekt- und Mehrwertsteuer<br />';
    html += 'Versand und Verpackung innerhalb Deutschlands.</span><br />';
    html += '</td>';
    html += '<td class="table-warenkorbdetail-anhang-link">';
    html += '<a href="javascript:void(0);" onclick="showCustomerDataForm();">Zur Kasse</a>';
    html += '</td>';
    html += '</tr>';
    html += '</table>\n';
    html += '</div>\n';
    html += '</form>\n';
  }
  return html;
}

// -------------------------------------------
// ShopTemplates.getTotalPrice()
// -------------------------------------------
//
// Beschreibung:
// -------------
//   ...
//
// Beispiel:
// ---------
// ShopTemplates.getTotalPrice(obj);
//


ShopTemplates.getTotalPrice = function(obj){
  var _totalItems = obj.getTotalPrice().toString().replace(/\,/,'.');
  var _sendingPrice = ShopTemplates.getSendingPrice(obj).toString().replace(/\,/,'.');
  var _totalPrice = parseFloat(parseFloat(_totalItems) + parseFloat(_sendingPrice));
  var _totalPriceFull = _totalPrice.toString().split(/\./)[0];
  var _totalPriceCent = parseFloat(_totalPrice.toString().split(/\./)[1]); 
  if (!_totalPriceCent){
    _totalPriceCent = '00';
  }
  _totalPriceCent = _totalPriceCent.toString();
  if (_totalPriceCent && _totalPriceCent.length < 2){
    _totalPriceCent = _totalPriceCent +'' + '0';
  }
  return _totalPriceFull + ',' + _totalPriceCent;
}

// -------------------------------------------
// ShopTemplates.getSendingPrice()
// -------------------------------------------
//
// Beschreibung:
// -------------
//   ...
//
// Beispiel:
// ---------
// ShopTemplates.getSendingPrice(obj);
//


ShopTemplates.getSendingPrice = function(obj){
  var _flaschen = 0;
  var _price = '7,50';
  for (var i=0; i<obj.orderedItemList().length; i++){
    if (obj.orderedItemList()[i].item().propertyMap()['kategorie1'] && obj.orderedItemList()[i].item().propertyMap()['kategorie1']._value != '10041'){
      _flaschen += parseFloat(obj.orderedItemList()[i].quantity());
    } 
  }
  if(_flaschen >= 30){
    _price = '11,50';
  }
  if(_flaschen >= 60 || !obj.getTotalQuantity()){
    _price = '0,00';
  }
  return _price;
}

// -------------------------------------------
// 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!");
    }
    var _path = undefined;
    if (parent.top){
      _path = 'parent.top';
    } else if (opener && opener.top){
      _path = 'opener.top';
    }
    if (!_path){
      return '';
    }
    html += '<div class="formular-titel">\n';
    html += '<h3><img src="/kiosk/grafik/formular_titel_adressdaten.gif" style="width: 149px; height: 13px;" alt="Ihre Adressdaten." title="Ihre Adressdaten." /></h3>\n';
    html += '</div>\n';

    html += '<div class="formular-inhalt">\n';

    html += '<div class="formular-inhalt-eintrag">\n';
    html += '<div class="formular-inhalt-eintrag-titel">\n';
    html += '<label for="feld-2">Vorname:</label><br />\n';
    html += '</div>\n';
    html += '<div class="formular-inhalt-eintrag-feld">\n';
    var vorname = '';
    if (obj.customer().firstName() != undefined){
      vorname = obj.customer().firstName();
    }
    html += '<input type="text" id="feld-2" onchange="' + _path + '.Order.GetInstance().customer().setFirstName(this.value);" name="Vorname" class="einzeilig-lang" value="'+ vorname +'" /><br />\n';
    html += '<div class="float-aufheben"><br /></div>\n';
    html += '</div>\n';
    html += '<div class="float-aufheben"><br /></div>\n';
    html += '</div>\n';

    html += '<div class="formular-inhalt-eintrag">\n';
    html += '<div class="formular-inhalt-eintrag-titel">\n';
    html += '<label for="feld-3">Name:</label><br />\n';
    html += '</div>\n';
    html += '<div class="formular-inhalt-eintrag-feld">\n';
    var name = '';
    if (obj.customer().name() != undefined){
      name = obj.customer().name();
    }
    html += '<input type="text" id="feld-3" onchange="' + _path + '.Order.GetInstance().customer().setName(this.value);" name="Name" class="einzeilig-lang" value="'+ name +'" /><br />\n';
    html += '<div class="float-aufheben"><br /></div>\n';
    html += '</div>\n';
    html += '<div class="float-aufheben"><br /></div>\n';
    html += '</div>\n';

    html += '<div class="formular-inhalt-eintrag">\n';
    html += '<div class="formular-inhalt-eintrag-titel">\n';
    html += '<label for="feld-4">Straße/Nr.:</label><br />\n';
    html += '</div>\n';
    html += '<div class="formular-inhalt-eintrag-feld">\n';
    var strasse = '';
    if (obj.customer().street() != undefined){
      strasse = obj.customer().street();
    }
    html += '<input type="text" id="feld-4" onchange="' + _path + '.Order.GetInstance().customer().setStreet(this.value);" name="Straße/Nr." class="einzeilig-lang" value="'+ strasse +'" /><br />\n';
    html += '<div class="float-aufheben"><br /></div>\n';
    html += '</div>\n';
    html += '<div class="float-aufheben"><br /></div>\n';
    html += '</div>\n';

    html += '<div class="formular-inhalt-eintrag">\n';
    html += '<div class="formular-inhalt-eintrag-titel">\n';
    html += '<label for="feld-6">PLZ</label> / <label for="feld-7">Ort:</label><br />\n';
    html += '</div>\n';
    html += '<div class="formular-inhalt-eintrag-feld">\n';
    var plz = '';
    if (obj.customer().postCode() != undefined){
      plz = obj.customer().postCode();
    }
    var ort = '';
    if (obj.customer().city() != undefined){
      ort = obj.customer().city();
    }
    html += '<input type="text" id="feld-6" onchange="' + _path + '.Order.GetInstance().customer().setPostCode(this.value);" name="PLZ" class="einzeilig-kurz erstes-feld" value="'+ plz +'" /><input type="text" id="feld-7" onchange="' + _path + '.Order.GetInstance().customer().setCity(this.value);" name="Ort" class="einzeilig-mittel" value="'+ ort +'" /><br />\n';
    html += '<div class="float-aufheben"><br /></div>\n';
    html += '</div>\n';
    html += '<div class="float-aufheben"><br /></div>\n';
    html += '</div>\n';

    html += '<div class="formular-inhalt-eintrag">\n';
    html += '<div class="formular-inhalt-eintrag-titel">\n';
    html += '<label for="feld-8">Telefon:</label><br />\n';
    html += '</div>\n';
    html += '<div class="formular-inhalt-eintrag-feld">\n';
    var tel = '';
    if (obj.customer().telephone() != undefined){
      tel = obj.customer().telephone();
    }
    html += '<input type="text" id="feld-8" onchange="' + _path + '.Order.GetInstance().customer().setTelephone(this.value);" name="Telefon" class="einzeilig-lang" value="'+ tel +'" /><br />\n';
    html += '<div class="float-aufheben"><br /></div>\n';
    html += '</div>\n';
    html += '<div class="float-aufheben"><br /></div>\n';
    html += '</div>\n';

    html += '<div class="formular-inhalt-eintrag">\n';
    html += '<div class="formular-inhalt-eintrag-titel">\n';
    html += '<label for="feld-9">E-Mail:</label><br />\n';
    html += '</div>\n';
    html += '<div class="formular-inhalt-eintrag-feld">\n';
    var mail = '';
    if (obj.customer().email() != undefined){
      mail = obj.customer().email();
    }
    html += '<input type="text" id="feld-9" onchange="' + _path + '.Order.GetInstance().customer().setEmail(this.value);" name="E-Mail" class="einzeilig-lang" value="'+ mail +'" /><br />\n';
    html += '<div class="float-aufheben"><br /></div>\n';
    html += '</div>\n';
    html += '<div class="float-aufheben"><br /></div>\n';
    html += '</div>\n';
    

    html += '<div class="formular-inhalt-eintrag">\n';
    html += '<div class="formular-inhalt-eintrag-titel">\n';
    html += '<label for="feld-11">Bemerkung:</label><br />\n';
    html += '</div>\n';
    html += '<div class="formular-inhalt-eintrag-feld">\n';
    html += '<textarea id="feld-11" name="Bemerkung" class="mehrzeilig-lang-mittel"></textarea>\n';
    html += '<div class="float-aufheben"><br /></div>\n';
    html += '</div>\n';
    html += '<div class="float-aufheben"><br /></div>\n';
    html += '</div>\n';

    html += '<div class="formular-inhalt-eintrag">\n';
    html += '<div class="formular-inhalt-eintrag-titel">\n';
    html += '<br />\n';
    html += '</div>\n';
    html += '<div class="formular-inhalt-eintrag-feld">\n';
    html += '<input type="checkbox" id="feld-10" name="AGB" class="checkbox" value="akzeptiert" checked="checked"/><label for="feld-10">Ich akzeptiere die <a href="'+ ShopTemplates.CMSURL +'&_sprache=sekt-shop&_bereich=artikel&_aktion=detail&idartikel=100051">Allgemeinen Geschäftsbedingungen</a></label>\n';
    html += '<div class="float-aufheben"><br /></div>\n';
    html += '</div>\n';
    html += '<div class="float-aufheben"><br /></div>\n';
    html += '</div>\n';

    html += '<div class="formular-inhalt-eintrag">\n';
    html += '<div class="formular-inhalt-eintrag-titel">\n';
    html += '<br />\n';
    html += '</div>\n';
    html += '<div class="formular-inhalt-eintrag-feld">\n';
    html += '<input type="checkbox" id="feld-12" name="Einverständniserklärung über Speicherung der persönl. Daten" class="checkbox" value="akzeptiert" checked="checked"/><label for="feld-12">Ich bin damit einverstanden, dass meine Daten zur<br/>Auftragsabwicklung und weiteren Information gespeichert werden.<br/>Eine Weitergabe der Daten an Dritte erfolgt nicht.</label>\n';
    html += '<div class="float-aufheben"><br /></div>\n';
    html += '</div>\n';
    html += '<div class="float-aufheben"><br /></div>\n';
    html += '</div>\n';

    html += '</div>\n';

    html += '<div class="formular-abschluss">\n';
    html += '<div class="formular-abschluss-absenden">\n';
    html += '<input type="submit" id="absenden" name="Bestellen" class="button-absenden" value="BESTELLEN" /><br />\n';
    html += '</div>\n';
    html += '<div class="formular-abschluss-loeschen">\n';
    html += '<input type="reset" id="loeschen" name="Löschen" class="button-loeschen" value="LÖSCHEN" /><br />\n';
    html += '</div>\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 += 'EAN: ' + obj.orderedItemList()[i].item().propertyMap()['artikel-id']._value + '\n'; 
      }
      if (obj.orderedItemList()[i].item().propertyMap()['bezeichnung']){
        str += 'Bezeichnung: ' + obj.orderedItemList()[i].item().propertyMap()['bezeichnung']._value + '\n'; 
      }
      if (obj.orderedItemList()[i].item().propertyMap()['typ']){
        str += 'Typ: ' + obj.orderedItemList()[i].item().propertyMap()['typ']._value + '\n'; 
      }
      if (obj.orderedItemList()[i].item().propertyMap()['verbund']){
        str += 'Verbund: ' + obj.orderedItemList()[i].item().propertyMap()['verbund']._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 16%: ' + obj.getTaxFromTotalPriceTaxInclusive() + ' EUR\n';
    str += 'Lieferung: ' + ShopTemplates.getSendingPrice(obj) + ' EUR\n';
    str += 'Gesamtsumme: ' + ShopTemplates.getTotalPrice(obj) + ' 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);
}
