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.frage.value.length < 10) {
							alert ("Bitte geben Sie Ihre Frage ein!");
							document.updateform.frage.focus();
							}
//									else alert("OK");
										else {
											index = document.cookie.indexOf("TheBasket");
//											document.cookie="TheBasket=.";
											document.updateform.submit();
										}
}

function buyItem(bestelltext) {
//	bestelltext = newItem;newPrice;newWeight;newQuantity;newKonfig
	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);
	newWeight = bestelltext.substr(0,bestelltext.indexOf(";"));
	bestelltext = bestelltext.substr(newWeight.length+1,bestelltext.length);
	newQuantity = bestelltext.substr(0,bestelltext.indexOf(";"));
	newKonfig = bestelltext.substr(newQuantity.length+1,bestelltext.length);
//	if (newQuantity <= 0) nix = alert('Die eingegebene Menge ist inkorrekt');
	if (newQuantity <= 0) 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+"|"+newWeight+"|"+newKonfig+"|"+newQuantity+"]"
			if (!document.cookie) document.location.href = "nocookie.html";
//		}
	}
}

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");
	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;
	totmwst = 0;
	totweight = 0;
	document.writeln('<form name="updateform" action="cgi-bin/formularmail.pl" method="post"><div align="left">');
	document.write('<input type="hidden" name="recipient" value="beratung"><input type="hidden" name="subject" value="Beratung durch sound-at-home">');
	document.write('<input type="hidden" name="redirect" value="../beratdanke.html">');
	document.writeln('<table class="acht" width="600" border="0" cellpadding="2">');
	document.writeln('<tr bgcolor="#F8F8F8"><td colspan="5"><span class="bold">Beratungsanfrage zur Konfiguration:</span></td></tr>');	
	document.writeln('<tr bgcolor="#dcdcdc"><td><span class="bold">Artikel</span></td><td align="right"><span class="bold">Menge</span></td><td align="right"><span class="bold">Einzelpreis</span></td><td align="right"><span class="bold">Gesamtpreis</span></td><td>&nbsp;</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" align="right">'+thequantity+'</td><td valign="top" align="right">'+theprice+'</td><td valign="top" align="right">'+alterError(itemtotal)+'</td>');
			document.write('<td align="center"><a href="javascript:removeItem('+itemlist+')"><img src="bilder/del02.gif" width="16" height="16" border="0" alt="entfernen"></a></td></tr>');
			document.writeln('<input type="hidden" name="artikel'+itemlist+'" value="'+theitem1+'" 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);
				//entfernt die links aus der email;
				theitem1 = theitem;
				while (theitem1.indexOf(">") > 0) {
					linkA = theitem1.indexOf("<");
					linkE = theitem1.indexOf(">");
					ersetzen = theitem1.substring(linkA,linkE+1);
					theitem1 = theitem1.replace(ersetzen,"");
				}
			}
			if (thisitem==2) theprice = fulllist.substring(itemstart, i);
			if (thisitem==3) theweight = fulllist.substring(itemstart, i);
			thisitem++;
			itemstart=i+1;
		}
	}
	if (document.cookie.length < 29) document.write('<tr valign="top" bgcolor="'+tablerowcolor+'"><td colspan="5" valign="top" align="left">Sie haben kein Produkt gew&auml;hlt.</td>');
	if (document.cookie.length > 28) {
		totmwst = totprice - totprice / 119e-2;
		document.writeln('<tr bgcolor="#F8F8F8"><td colspan=3 align=right>enthaltene MwSt. 19%</td><td align=right>'+alterError(totmwst)+'</td><td>&nbsp;</td></tr>');
		document.writeln('<tr bgcolor="#dcdcdc"><td><span class="bold">Total</span></td><td colspan=2 align=right>Versandgewicht: '+alterError(totweight)+'kg</td><td align=right><span class="bold">Euro '+alterError(totprice)+'</span></td><td>&nbsp;</td></tr>');
	}
	document.writeln('<input type="hidden" name="summe" value="'+alterError(totprice)+'" size="40">');
	document.writeln('<input type="hidden" name="gewicht" value="'+alterError(totweight)+'" size="40">');
	document.writeln('</table><br>');
	if (document.cookie.length > 28) 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;
	self.location.reload();
}

function anschrift() {
	document.write('<table class="acht" 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">Vorname:</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>');
	document.write('<tr><td align="left" valign="top"><span class="bold">Ihre Frage:</span></td><td align="left"><textarea name="frage" rows="4" cols="60"></textarea></td></tr>');
	document.write('<tr><td colspan="2" align="right"><br><br><span class="achtb"><a href="javascript:checkEingabe();">Anfrage abschicken</a></span><a href="javascript:checkEingabe();"><img src="bilder/mail.gif" width="22" height="16" border="0" alt="Anfrage abschicken" hspace="8"></a>');
	document.write('</table><br>');
}