// Copyright (c) 1997-1999 antares OHG - http://www.antares.de

mailvar='ansgar@asfalt-huette.de';

var wrongQuantity = "Ungültige Mengenangabe.";
var noNumber = "Mengenangabe fehlt.";
var intoBasket = " in den Warenkorb.";
var confirmDelete = "Warenkorb löschen?";
var delItem = "Position l&ouml;schen";
var delBasket = 'Alles l&ouml;schen';

var colItem = "Artikelbezeichnung";
var colQuantity = "Anzahl";
var colEach = "Einzelpreis";
var colTotal = "Gesamtreis";
var colTotalcost = "Endbetrag in Euro";
var colTotaleuro = "Endbetrag in DM";

var TheBasket = "basket.htm";
var TheAnswer = "ant-mail.htm";


function buyItem(newItem, newPrice, newQuantity) {

   if (isNaN(parseInt(newQuantity))) {
      alert (noNumber);
      return false;
   }
   if (newQuantity*1 <= 0) {
      rc = alert(wrongQuantity);
      return false;
   }
   if (confirm(newQuantity+' x '+newItem+intoBasket)) {
      index = document.cookie.indexOf("TheBasket");
      countbegin = (document.cookie.indexOf("=", index) + 1);
      countend = document.cookie.indexOf(";", index);
      if (countend == -1) {
         countend = document.cookie.length;
      }
      document.cookie="TheBasket="+document.cookie.substring(countbegin, countend)+"["+newItem+","+newPrice+"#"+newQuantity+"]";
   }
   return true;
}


function roundTwo(value) {

   if (value<=0.99) {
      newPounds = '0';
   } else {
      newPounds = parseInt(value);
   }
   newPence = parseInt((value+.0008 - newPounds)* 100);
   if (eval(newPence) <= 9) newPence='0'+newPence;
   newString = newPounds + '.' + newPence;
   return (newString);
}


function showItems() {

   index = document.cookie.indexOf("TheBasket");
   countbegin = (document.cookie.indexOf("=", index) + 1);
   countend = document.cookie.indexOf(";", index);
   if (countend == -1) {
      countend = document.cookie.length;
   }
   fulllist = document.cookie.substring(countbegin, countend);
   totprice = 0;
   europrice = 0;
   var mailvar2='<FORM method="post" action="mailto:' + mailvar + '?SUBJECT=Asfalt Huette Online-Shop Bestellung"   enctype="text/plain">';
   document.writeln(mailvar2);
   document.writeln('<table border="1" width="500" cellspacing="0" cellpadding="3">');
   document.writeln('<TR><TD VALIGN="TOP"><b>'+colItem+'</b></TD><TD VALIGN=TOP" ALIGN="CENTER"><b>'+colQuantity+'</b></TD><TD VALIGN="TOP" ALIGN="RIGHT"><b>'+colEach+'</b></TD><td VALIGN="TOP" ALIGN="RIGHT"><b>'+colTotal+'</b><TD VALIGN="TOP"><b>&nbsp;</b></TD></TR>');
   itemlist = 0;
   for (var i = 0; i <= fulllist.length; i++) {
      if (fulllist.substring(i,i+1) == '[') {
         itemstart = i+1;
      } else if (fulllist.substring(i,i+1) == ']') {
         itemend = i;
         thequantity = fulllist.substring(itemstart, itemend);
         itemtotal = 0;
         itemtotal = (eval(theprice*thequantity));
         temptotal = itemtotal * 100;
         totprice = totprice + itemtotal;
         europrice = totprice*1.9558;
         itemlist=itemlist+1;
         document.writeln('<tr><td VALIGN="TOP">'+theitem+'</td><td align=center VALIGN="TOP">'+thequantity+'</td><td align=right VALIGN="TOP">'+theprice+' Euro</td><td align=right VALIGN="TOP">'+roundTwo(itemtotal)+' Euro</td><td VALIGN="TOP"><a href="javascript:removeitem('+itemlist+')">'+delItem+'</a></td></tr>');
         document.writeln('<INPUT TYPE="hidden" NAME="Artikel'+itemlist+'" VALUE="'+theitem+'" SIZE="40">');
         document.writeln('<INPUT TYPE="hidden" NAME="Menge'+itemlist+'" VALUE="'+thequantity+'" SIZE="40">');
         document.writeln('<INPUT TYPE="hidden" NAME="Einzelpreis'+itemlist+'" VALUE="'+theprice+'" SIZE="40">');
         document.writeln('<INPUT TYPE="hidden" NAME="Gesamtpreis'+itemlist+'" VALUE="'+roundTwo(itemtotal)+'" SIZE="40">');
      } else if (fulllist.substring(i,i+1) == ',') {
         theitem = fulllist.substring(itemstart, i);
         itemstart = i+1;
      } else if (fulllist.substring(i,i+1) == '#') {
         theprice = fulllist.substring(itemstart, i);
         itemstart = i+1;
      }
   }
   document.writeln('<tr><td colspan=3><b>'+colTotalcost+'</b> zzgl. 2,50 Euro Versandkosten</td><td align=right>'+roundTwo(totprice)+' Euro</td><td><a href="javascript:clearBasket()">'+delBasket+'</a></td></tr>');

   document.writeln('<INPUT TYPE="hidden" NAME="Endbetrag (Euro)" VALUE="'+roundTwo(totprice)+'" SIZE="40">');
}

function removeitem(itemno) {
   newItemList = null;
   itemlist = 0;
   for (var i = 0; i <= fulllist.length; i++) {
      if (fulllist.substring(i,i+1) == '[') {
         itemstart = i+1;
      } else if (fulllist.substring(i,i+1) == ']') {
         itemend = i;
         theitem = fulllist.substring(itemstart, itemend);
         itemlist=itemlist+1;
         if (itemlist != itemno) {
            newItemList = newItemList+'['+fulllist.substring(itemstart, itemend)+']';
         }
      }
   }
   index = document.cookie.indexOf("TheBasket");
   document.cookie="TheBasket="+newItemList;
   document.location.href = TheBasket;
}


function clearBasket() {

   if (confirm(confirmDelete)) {
      index = document.cookie.indexOf("TheBasket");
      document.cookie="TheBasket=.";
      document.location.href = TheBasket;
   }
}

function clearOrder() {

      index = document.cookie.indexOf("TheBasket");
      document.cookie="TheBasket=.";
}