


// deutsch() - Punkt nach Komma wandeln
function deutsch (wert) {
	var pos = wert.indexOf('.');
	var laenge = wert.length;
	var links = wert.substring(0,pos);
	var rechts = wert.substring(pos+1,laenge);
	var ergebnis = links+','+rechts;
	return ergebnis;
}

// versand() - Versandkostenzuschlag
// F&#252;gen Sie hier f&#252;r jede Preisstufung eine IF-Zeile ein
// Beachten Sie, da&#223; die Stufungen absteigend angegeben werden!
function versand (preis) {
	if (preis > 100.00) return 0.00;	// Zuschlag bei Bestellsumme &#252;ber 50 EUR
	if (preis == 0.00) return 0.00;	// Keine Artikel im Warenkorb
	return 4.00;	// Grundlegender Zuschlag
}

// alterError() - behebt einen Rundungsfehler in Netscape 2
function alterError(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);
}

// buyItem() - legt einen Artikel in den Warenkorb
function buyItem(newItem, newPrice, newQuantity) {
	if (newQuantity <= 0) {
		rc = alert('Die Menge wurde falsch eingegeben');
		// return false;
	}
	if (confirm(newItem+' in den Warenkorb legen?')) {
		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;
}

// removeItem() - entfernt einen Artikel aus dem Warenkorb
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;
	parent.unten.location = "shopkorb.htm";
}

// clearBasket() - leert den gesamten Warenkorb
function clearBasket() {
	if (confirm('Wollen Sie den Warenkorb wirklich leeren?')) {
		index = document.cookie.indexOf("TheBasket");
		document.cookie="TheBasket=.";
		parent.unten.location = "shopkorb.htm";
	}
}

// resetBasket() - l&#246;scht den Warenkorb
function resetBasket() {
	index = document.cookie.indexOf("TheBasket");
	document.cookie="TheBasket=.";
}

// showItems() - zeigt den Warenkorb in einer Tabelle an
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;
	parent.unten.document.writeln('<table border=0 cellpadding="7">');
	parent.unten.document.writeln('<tr><td><b>Artikel</b></td><td><b>Preis</b></td><td><b>Aktion</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;
			itemlist=itemlist+1;
			parent.unten.document.writeln('<tr><td class="bold">'+theitem+'</td><td align=right class="bold">'+deutsch(alterError(itemtotal))+'</td><td class="bestellen"><a onFocus="if(this.blur)this.blur()" href="javascript:parent.unten.removeItem('+itemlist+')"><font color="#A62336">Entfernen</a></td></tr>');
		} 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;
		}
	}
	parent.unten.document.writeln('<tr><td class="bold"><b>Bestellsumme</b></td><td align=right class="bold"><b>'+deutsch(alterError(totprice))+'</b></td><td>&nbsp;</td></tr>');
	var vers = versand(totprice);
	var endp = totprice+vers;
	parent.unten.document.writeln('<tr><td class="bold">Versandkostenzuschlag</td><td align=right class="bold">'+deutsch(alterError(vers))+'</td><td>&nbsp;</td></tr>');
	parent.unten.document.writeln('<tr><td class="bold"><b>Endsumme</b></td><td align=right class="bold"><b>'+deutsch(alterError(endp))+'</b></td><td>&nbsp;</td></tr>');
	parent.unten.document.writeln('</table>');
}

// buildForm() - generiert Bestellformular
function buildForm() {
	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;
	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;
			itemlist=itemlist+1;
			parent.unten.document.writeln('<input type="hidden" name="Artikel'+itemlist+'" value="'+theitem+' ('+deutsch(theprice)+' EUR)">');
		} 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;
		}
	}
	parent.unten.document.writeln('<input type="hidden" name="s1_Bestellsumme" value="'+deutsch(alterError(totprice))+'">');
	var vers = versand(totprice);
	var endp = totprice+vers;
	parent.unten.document.writeln('<input type="hidden" name="s2_Versand" value="'+deutsch(alterError(vers))+' EUR">');
	parent.unten.document.writeln('<input type="hidden" name="s3_Gesamtsumme" value="'+deutsch(alterError(endp))+' EUR">');
	parent.unten.document.writeln('</td></tr>');
}
