function checkEingabe()  {
//alert(document.cookie);
	var validemail = 0;
	var cmail = document.updateform.email.value;
	if (cmail.length > 6 && cmail.indexOf('@') > 0 && cmail.indexOf('@') < cmail.length - 4 && cmail.indexOf('.') > 0 && cmail.indexOf('.') < cmail.length - 2 && cmail.indexOf(' ') == -1) validemail = 1;
	if (document.updateform.name.value.length < 2)  {
		alert ("Bitte geben Sie Ihren Namen ein!");
		document.updateform.name.focus();
	}
	else if (document.updateform.vorname.value.length < 2)  {
		alert ("Bitte geben Sie Ihren Vornamen ein!");
		document.updateform.vorname.focus();
		}
		else if (document.updateform.strasse.value.length < 2)  {
			alert ("Bitte geben Sie die Strasse ein!");
			document.updateform.strasse.focus();
			}
			else if (document.updateform.plz.value.length < 4)  {
				alert ("Bitte geben Sie die PLZ ein!");
				document.updateform.plz.focus();
				}
				else if (document.updateform.ort.value.length < 2)  {
					alert ("Bitte geben Sie den Ort ein!");
					document.updateform.ort.focus();
					}
					else if (validemail == 0)  {
						alert ("Bitte geben Sie Ihre eMail-Adresse ein!");
						document.updateform.email.focus();
						}
						else if (document.updateform.konto && document.updateform.konto.value.length < 3) {
							alert ("Bitte geben Sie Ihre Kontonummer ein!");
							document.updateform.konto.focus();
							}
							else if (document.updateform.blz && document.updateform.blz.value.length < 8) {
								alert ("Bitte geben Sie Ihre Bankleitzahl ein!");
								document.updateform.blz.focus();
								}
								else if (document.updateform.blz && document.updateform.bank.value.length < 3) {
									alert ("Bitte geben Sie den Namen Ihrer Bank ein!");
									document.updateform.bank.focus();
									}
//									else alert("OK");
									else if (document.updateform.agb[0].checked != true) {
										alert ("Sie haben den AGB nicht zugestimmt!");
										document.updateform.agb[0].focus();
										}
										else {
											index = document.cookie.indexOf("TheBasket");
											document.cookie="TheBasket=.";
											document.updateform.submit();
										}
}

function buyItem(bestelltext) {
//	bestelltext = newItem;newPrice;newWeight;newQuantity
	newItem = bestelltext.substr(0,bestelltext.indexOf(";"));
	bestelltext = bestelltext.substr(newItem.length+1,bestelltext.length);
	newPrice = bestelltext.substr(0,bestelltext.indexOf(";"));
	bestelltext = bestelltext.substr(newPrice.length+1,bestelltext.length);
	newQuantity = bestelltext.substr(0,bestelltext.indexOf(";"));
	newWeight = bestelltext.substr(newQuantity.length+1,bestelltext.length);
//	if (newQuantity <= 0) nix = alert('Die eingegebene Menge ist inkorrekt');
	if (newQuantity <= 0) ;
	else {
//		if (confirm(newQuantity+' x '+newItem+' in den Einkaufskorb 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+"|"+newWeight+"]"
			if (!document.cookie) document.location.href = "main.php?info=nocookie";
//		}
	}
}

function alterError(value) {
	value = parseInt(value*100+0.5);
	if (isNaN(value) == true) value = eval('0');
	newPounds = String(value).substr(0,String(value).length-2);
	if (newPounds == '') newPounds = '0';
	if (isNaN(newPounds) == true) newPounds = eval('0');
	newPence = String(value).substr(String(value).length-2,2);
	if (isNaN(newPence) == true) newPence = eval('0');
	if (eval(newPence) <= 9) newPence='0'+eval(newPence);
	if (eval(newPence) == 0) newPence='00';
	return(newPounds+'.'+newPence);
}

function showItems() {
	var tablerowcolor = '#F0F0F0';
	index = document.cookie.indexOf("TheBasket");
	kauf = document.location.href.indexOf("kaufen.php");
	countbegin = (document.cookie.indexOf("=", index) + 1);
	countend = document.cookie.indexOf(";", index);
	if (countend == -1) 	countend = document.cookie.length;
	fulllist = document.cookie.substring(countbegin, countend);
//alert(fulllist);
	totprice = 0;
	totmwst = 0;
	totweight = 0;
	if (kauf == -1) 	document.writeln('<form name="updateform"><div align="left">');
	else {
		document.writeln('<form name="updateform" action="http://www.ortofon-elite.de/cgi-bin/formularmail.pl" method="post"><div align="left">');
		document.write('<input type="hidden" name="recipient" value="best"><input type="hidden" name="subject" value="Bestellung an Ortofon-Elite">');
		document.write('<input type="hidden" name="redirect" value="http://www.ortofon-elite.de/main.php?info=bestdanke">');
	}
	document.writeln('<table width="600" border="0">');
	document.writeln('<tr bgcolor="#dcdcdc"><td style="width: 280px"><span class="bold">Artikel</span></td><td style="text-align: right; width: 54px"><span class="bold">Menge</span></td><td style="text-align: right; width: 125px"><span class="bold">Einzelpreis</span></td><td style="text-align: right; width: 125px"><span class="bold">Gesamtpreis</span></td><td style="text-align: center; width: 16px;">&nbsp;</td></tr>');
//document.writeln('<tr bgcolor=blue><td colspan="5"><hr></td></tr>');
	itemlist = 0;
	for (var i = 0; i <= fulllist.length; i++) {
		if (fulllist.substring(i,i+1) == '[') {
			itemstart = i+1;
			thisitem = 1;
		}
		else if (fulllist.substring(i,i+1) == ']') {
			itemend = i;
			thequantity = fulllist.substring(itemstart, itemend);
			weighttotal = 0;
			weighttotal = (eval(theweight*thequantity));
			totweight = totweight + weighttotal;
			itemtotal = 0;
			itemtotal = (eval(theprice*thequantity));
			temptotal = itemtotal * 100;
			totprice = totprice + itemtotal;
			itemlist=itemlist+1;
			document.write('<tr valign="top" bgcolor="'+tablerowcolor+'"><td>'+theitem+'</td>');
			document.write('<td valign="top" style="text-align: right">'+thequantity+'</td><td valign="top" style="text-align: right">'+theprice+'</td><td valign="top" style="text-align: right">'+alterError(itemtotal)+'</td>');
			document.write('<td><a href="javascript:removeItem('+itemlist+')"><img src="bilder/del02.gif" width="16" height="16" border="0" alt="entfernen"></a></td></tr>');
			if (kauf != -1) {
				document.writeln('<input type="hidden" name="artikel'+itemlist+'" value="'+theitem+'" size="40">');
				document.writeln('<input type="hidden" name="anzahl'+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="'+alterError(itemtotal)+'" size="40">');
			}
			if (tablerowcolor == '#F0F0F0') tablerowcolor = "#F8F8F8";
			else tablerowcolor = "#F0F0F0";
		}
		else if (fulllist.substring(i,i+1) == '|') {
			if (thisitem==1) theitem = fulllist.substring(itemstart, i);
			if (thisitem==2) theprice = fulllist.substring(itemstart, i);
			if (thisitem==3) theweight = fulllist.substring(itemstart, i);
			thisitem++;
			itemstart=i+1;
		}
	}
	if (totweight == 0) document.write('<tr valign="top" bgcolor="'+tablerowcolor+'"><td colspan="5" valign="top">Ihr Warenkorb ist leer.</td>');
//	if (fulllist == 'null') document.write('<tr valign="top" bgcolor="'+tablerowcolor+'"><td colspan="5" valign="top">Ihr Warenkorb ist leer.</td>');
//	document.writeln('<tr bgcolor="#FCFCFC"><td colspan="5"><hr></td></tr>');
	versandArt();
	totmwst = totprice - totprice / 119e-2;
	document.writeln('<tr bgcolor="#FCFCFC"><td colspan="3" style="text-align: right">enthaltene MwSt. 19%</td><td style="text-align: right">'+alterError(totmwst)+'</td><td>&nbsp;</td></tr>');
	document.writeln('<tr bgcolor="#dcdcdc"><td><span class="bold">Total</span></td><td colspan="2" style="text-align: right">Versandgewicht: '+alterError(totweight)+'kg</td><td style="text-align: right"><span class="bold">EUR '+alterError(totprice)+'</span></td><td>&nbsp;</td></tr>');
	document.writeln('<tr bgcolor="#FCFCFC"><td colspan="5">* f&uuml;r den Versand innerhalb Deutschlands. Die Versandkosten ausserhalb Deutschlands teilen wir Ihnen per email mit.</td></tr>');
	if (document.updateform.versand.options[2].selected) {
		document.writeln('<tr bgcolor="#F8F8F8"><td colspan="5"><span class="red"><b>Bei Neukunden</b> werden Lastschriften <b><u>vor</u></b> dem Versand belastet (Vorkasse). Der Versand erfolgt nur,<br>'+
																		'sofern die Lastschrift nicht rückbelastet wird. Wir bitten um Verständnis für diese Vorgehensweise,<br>'+
																		'sind jedoch durch das Verhalten einiger Kunden dazu gezwungen worden.</span></td></tr>');
	}
	if (kauf != -1) document.writeln('<input type="hidden" name="summe" value="'+alterError(totprice)+'" size="40">');
	if (kauf != -1) document.writeln('<input type="hidden" name="gewicht" value="'+alterError(totweight)+'" size="40">');
	document.writeln('</table><br>');
	if (kauf != -1) anschrift();
	document.writeln('</div>');
	document.writeln('</form>');
}

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;
	if (kauf == -1) self.location = "korb.php";
	else self.location.reload();
}

function clearBasket() {
	if (confirm('Möchten Sie wirklich alle Artikel aus dem Einkaufswagen entfernen?')) {
		index = document.cookie.indexOf("TheBasket");
		document.cookie="TheBasket=.";
		self.location = "korb.php";
	}
}

function versandArt() {
	var versandkosten = 6.9;
	if (totweight < 1) versandkosten = 3.9;
	if (totweight > 4) versandkosten = ((totweight - 4) / 1.0) + versandkosten;
	va = new Array("Nachnahme","Vorkasse","Lastschrift");
	if (document.cookie.indexOf("Ship") == -1) document.cookie = "Ship=0,"+ (alterError(versandkosten + 6)) +";" + document.cookie;
	var ind = document.cookie.indexOf("Ship");
//	versandkosten = document.cookie.substring(ind+7,document.cookie.length);
	ind = document.cookie.substring(ind+5,ind+6);
	if (ind == 0) versandkosten = (alterError(versandkosten + 6));
	else versandkosten = (alterError(versandkosten));
	document.write('<tr bgcolor="#FCFCFC"><td colspan="2">Zahlung erfolgt per <select name="versand" size="1" onChange="versandAend('+versandkosten+')"><option value="5" ' );
	if (ind == 0) document.write('selected');
	document.write('>Nachnahme</option><option value="0" ');
	if (ind == 1) document.write('selected');
	document.write('>Vorkasse</option><option value="0" ');
	if (ind == 2) document.write('selected');
	document.write('>Lastschrift</option></select></td>');
	document.write('<td style="text-align: right">Versandkosten *</td><td style="text-align: right">'+versandkosten+'</td><td>&nbsp;</td></tr>');
	document.writeln('<input type="hidden" name="bezahlung" value="'+va[ind]+'" size="15">');
	document.writeln('<input type="hidden" name="versandkosten" value="'+versandkosten+'" size="15">');
	document.cookie = "Ship=" + ind + "," + versandkosten + ";" + document.cookie;
	totprice = eval(totprice) + eval(versandkosten);
}

function versandAend(wert) {
	for (var i = 0; i < document.updateform.versand.options.length; ++i) {
		if (document.updateform.versand.options[i].selected == true) {
			versandkosten = alterError(wert + eval(document.updateform.versand.options[i].value));
			document.cookie = "Ship=" + i + "," + versandkosten + ";" + document.cookie;
			if (kauf == -1) self.location = "korb.php";
//			else self.location.reload();
			else self.location = "kaufen.php";
		}
	}
}

function anschrift() {
	document.write('<table width="600" border="0" cellpadding="0">');
	document.write('<tr><td align="left" width="110"><span class="bold">Name:</span></td><td align="left"><input name="name" type="text" size="58" maxlength="100"></td></tr>');
	document.updateform.name.focus();
	document.write('<tr><td align="left"><span class="bold">Vorame:</span></td><td align="left"><input name="vorname" type="text" size="58" maxlength="100"></td></tr>');
	document.write('<tr><td align="left"><span class="bold">Stra&szlig;e:</span></td><td align="left"><input name="strasse" type="text" size="58" maxlength="300"></td></tr>');
	document.write('<tr><td align="left"><span class="bold">PLZ:</span></td><td align="left"><input name="plz" type="text" size="5" maxlength="10"><span class="bold">&nbsp;&nbsp;&nbsp;Ort (Land):&nbsp;</span><input name="ort" type="text" size="33" maxlength="300"></td></tr>');
	document.write('<tr><td align="left"><span class="bold">eMail:</span></td><td align="left"><input name="email" type="text" size="58" maxlength="58"></td></tr>');
	if (document.updateform.versand.options[2].selected) {
		document.write('<tr><td align="left"><span class="bold">Kontonummer:</span></td><td align="left"><input name="konto" type="text" size="20" maxlength="50"><span class="bold">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BLZ:&nbsp;</span><input name="blz" type="text" size="22" maxlength="8"></td></tr>');
		document.write('<tr><td align="left"><span class="bold">Bank:</span></td><td align="left"><input name="bank" type="text" size="58" maxlength="58"></td></tr>');
	}
	document.write('<tr><td align="left"><span class="bold">Bemerkung:</span></td><td align="left"><input name="bemerkung" type="text" size="58" value="keine"></td></tr>');
	document.write('<tr><td colspan="2" align="left">Die Lieferung sollte bevorzugt erfolgen durch <input class="radiobutton" name="lieferwunsch" type="radio" value="ups" checked>UPS  <input class="radiobutton" name="lieferwunsch" type="radio" value="post">Deutsche Post / DHL.</td></tr>');
	document.write('<tr><td colspan="2" align="left" class="xsml"><span class="bold">Die <a href="main.php?info=agb"><span class="undl">AGB</span></a> habe ich gelesen und akzeptiere diese: <input class="radiobutton" name="agb" type="radio" value="ja">ja <input class="radiobutton" name="agb" type="radio" value="nein" checked>nein</span></td></tr>');
	document.write('</table><br>');
}