var fotoweltShopWin;
var bestellung = new Array();
var shop_main = "bodyframe";
var picpath = "<PERL $SP_PIC_HREF LREP>";


function ShopItemToString() {
   return "key  : " + this.key + "\n" +
          "anz  : " + this.anz + "\n" +
          "title: " + this.title;
}
function ShopItem (key,title,price,anz) {
   this.key = key;
   this.anz = anz;
   this.price = price;
   this.title = title;
   this.toString = ShopItemToString;
}

function find_ShopItem(key) {
   // key : string-value eindeutige Nummer des Artikels
   var r = 0;
   for (i = 0; (i < bestellung.length) && (r == 0); i++) {
      if (bestellung[i])
         r = (bestellung[i].key == key) ? bestellung[i] : 0;
   }
   return r;
}

function add_ShopItem(akey, atitle, aprice, anz) {
var aShopItem;
   if ((anz != "") && (anz != null)) {
      aShopItem = find_ShopItem(akey);
      if ( aShopItem == 0) {
         bestellung[bestellung.length] = new ShopItem (akey, atitle, aprice, anz);
      }
      else {
         aShopItem.anz = parseInt(aShopItem.anz) + parseInt(anz);
      }
      alert(aShopItem.anz + "//" + aShopItem.key);
   }
   else {
   }
//   updatekorb();
}
function remove_ShopItem(akey) {
var r = 0;
   for (i = 0; (i < bestellung.length) && (r == 0); i++) {
      if (bestellung[i]!=0) {
         r = (bestellung[i].key == akey) ? bestellung[i] : 0;
      }
   }
   i--;
   bestellung[i] = 0;
}

function updatekorb(adoc) {

// adoc = parent.body.liste.document;
   adoc.open();
   adoc.writeln("<TR><TD>&nbsp;<B>Anzahl</TD>");
   adoc.writeln("<TD>&nbsp;<B>ArtikelNr</TD>");
   adoc.writeln("<TD>&nbsp;<B>Artikelbezeichnung</TD>");
   adoc.writeln("<TD>&nbsp;<B>Listpreis &Ouml;S</TD>");
   for (i=0; i<bestellung.length; i++) {
      if (bestellung[i]) {
         adoc.write("<TR>");
         adoc.write("<TD>&nbsp;" + bestellung[i].anz + "</TD>");
         adoc.write("<TD>&nbsp;" + bestellung[i].key + "</TD>");
         adoc.write("<TD>&nbsp;" + unescape(bestellung[i].title) + "</TD>");
         adoc.write("<TD ALIGN=RIGHT>&nbsp;" + bestellung[i].price + "</TD>");
//         adoc.write("<TD CLASS=small><INPUT TYPE=TEXT NAME='" + bestellung[i].title + "' VALUE=" + bestellung[i].anz +" SIZE=2></TD>");

//         adoc.write("<TD>" + bestellung[i].price * bestellung[i].anz + "</TD>");
 
        
      }
   }
   adoc.close();
}


function updatekorb2(adoc) {

// adoc = parent.body.liste.document;
   adoc.open();
   adoc.writeln("<TR><TD></TD>");
   adoc.writeln("<TD>&nbsp;<B>Anzahl</TD>");
   adoc.writeln("<TD>&nbsp;<B>ArtikelNr</TD>");
   adoc.writeln("<TD>&nbsp;<B>Artikelbezeichnung</TD>");
   adoc.writeln("<TD><B>&nbsp;Listpreis &Ouml;S</TD>");
   for (i=0; i<bestellung.length; i++) {
      if (bestellung[i]) {
         adoc.writeln("<TR>");
         adoc.writeln("<TD>");
         adoc.writeln("<INPUT TYPE=HIDDEN NAME='BEZ_" + bestellung[i].key + "' VALUE='" + bestellung[i].title + "'>");
         adoc.writeln("<INPUT TYPE=HIDDEN NAME='PR_" + bestellung[i].key + "' VALUE='" + bestellung[i].price + "'></TD>");
         adoc.writeln("<TD><INPUT TYPE=TEXT NAME='ARTNR_" + bestellung[i].key + "' VALUE=" + bestellung[i].anz + " SIZE=4></TD>");
         
         adoc.writeln("<TD>&nbsp;" + bestellung[i].key + "</TD>");
         adoc.writeln("<TD>&nbsp;" + unescape(bestellung[i].title) + "</TD>");
         adoc.writeln("<TD ALIGN=RIGHT>&nbsp;" + bestellung[i].price + "</TD>");

//         adoc.write("<TD>" + bestellung[i].price * bestellung[i].anz + "</TD>");


      }
   }
   adoc.close();
}


function clearKorb() {
   for (var i=bestellung.length; i>=0; i--) {
      delete bestellung[i];
   }
}


function submitform()
{
   fotoweltShopWin.document.forms[0].submit();
}


clearKorb();
