function toggleDiv(element)
{ 
	if(document.getElementById(element).style.display == 'none')   
		document.getElementById(element).style.display = 'block';
	else       
		document.getElementById(element).style.display = 'none'; 
} 

function checkCookie()
{
	index = document.cookie.indexOf("TheBasket");
	document.cookie="TheBasket=.";

	if (document.cookie) 
	{
        } 
	else 
	{
	self.location="bestellung_ers.html";        
	return false;
	}
}

function writeOrder(bNurPreisBerechnen)
{
	var summe = 0;
	var pospreis = 0;
	var version = document.Bestellung.cboupdate.options[document.Bestellung.cboupdate.options.selectedIndex].value;
	var summereferendare = 0;

	index = document.cookie.indexOf("TheBasket");
	document.cookie="TheBasket=.";
	
	document.Bestellung.preisref.value='0';
	document.Bestellung.preisref.style.color = '#3c3c3c';

	if (document.Bestellung.Lizenzart[0].checked || document.Bestellung.Lizenzart[2].checked) 
		{
		if (document.Bestellung.Lizenzart[0].checked)
		{
		pospreis=parseFloat(document.Bestellung.blindel.value);
		summe+=pospreis;
		buyItem("SF8EL","Einzellizenz",pospreis);
		}
		else
		{
		buyItem("SF8ELMD","Modul-Nachbestellung für Einzellizenz","0.00");
		if (version != "") {buyItem(version,"vorhandene Lizenz: " + document.Bestellung.cboupdate.options[document.Bestellung.cboupdate.options.selectedIndex].text,"0.00");}
		}
		
		if (document.Bestellung.Modul_Schueler.checked) {
			pospreis=parseFloat(document.Bestellung.blindelse.value);
			summe+=pospreis;
			buyItem("SF8ELSE","Schüler-Erweiterungen",pospreis);}
		if (document.Bestellung.Modul_Planung.checked) 	{
			pospreis=parseFloat(document.Bestellung.blindelpl.value);
			summe+=pospreis;
			buyItem("SF8ELPL","Planung",pospreis);}
		if (document.Bestellung.Modul_Mehrplatz.checked) {
			pospreis=parseFloat(document.Bestellung.blindelmp.value);
			summe+=pospreis;
			buyItem("SF8ELMP","Mehrplatz",pospreis);}
		if (document.Bestellung.Modul_PocketPC.checked) {
			pospreis=parseFloat(document.Bestellung.blindelppc.value);
			summe+=pospreis;
			buyItem("SF8ELPPC","MOBIL Pocket-PC/Palm",pospreis);
			var Einsatz = "MOBIL-Einsatz auf: " + document.Bestellung.MobilArt.options[document.Bestellung.MobilArt.options.selectedIndex].value;
			buyItem("SF8PPC"+ document.Bestellung.MobilArt.options.selectedIndex, Einsatz, "0.00");}
		if (document.Bestellung.Referendar.checked) {
			pospreis=summe*20/100*-1;
			summe+=pospreis;
			document.Bestellung.preisref.style.color = 'red';
			document.Bestellung.preisref.value = pospreis*-1;
			buyItem("REF","- 20% Referendar-Nachlass auf die Lizenzpreise",pospreis);}
		if (document.Bestellung.Software_auf_CD.checked) {
			pospreis=parseFloat(document.Bestellung.blindcd.value);
			summe+=pospreis;
			buyItem("SF8CD","unlizenzierte Software auf CD",pospreis);}
		}
	
	else if (document.Bestellung.Lizenzart[1].checked || document.Bestellung.Lizenzart[3].checked)
		{
		if (document.Bestellung.Lizenzart[1].checked)
		{
		pospreis=parseFloat(document.Bestellung.blindsl.value);
		summe+=pospreis;
		buyItem("SF8SL","Schullizenz",pospreis);
		}
		else
		{
		buyItem("SF8SLMD","Modul-Nachbestellung für Schullizenz","0.00");
		if (version != "") {buyItem(version,"vorhandene Lizenz: " + document.Bestellung.cboupdate.options[document.Bestellung.cboupdate.options.selectedIndex].text,"0.00");}
		}
		
		if (document.Bestellung.Modul_Schueler.checked) {
			pospreis=parseFloat(document.Bestellung.blindslse.value);
			summe+=pospreis;
			buyItem("SF8SLSE","Schüler-Erweiterungen",pospreis);}
		if (document.Bestellung.Modul_Planung.checked) {
			pospreis=parseFloat(document.Bestellung.blindslpl.value);
			summe+=pospreis;
			buyItem("SF8SLPL","Planung",pospreis);}
		if (document.Bestellung.Modul_Mehrplatz.checked) {
			pospreis=parseFloat(document.Bestellung.blindslmp.value);
			summe+=pospreis;
			buyItem("SF8SLMP","Mehrplatz",pospreis);}
		if (document.Bestellung.Modul_PocketPC.checked) {
			pospreis=parseFloat(document.Bestellung.blindslppc.value);
			summe+=pospreis;
			buyItem("SF8SLPPC","MOBIL Pocket-PC/Palm",pospreis);
			var Einsatz = "MOBIL-Einsatz auf: " + document.Bestellung.MobilArt.options[document.Bestellung.MobilArt.options.selectedIndex].value;
			buyItem("SF8PPC" + document.Bestellung.MobilArt.options.selectedIndex, Einsatz, "0.00");}

	
		if (summe!=0) {buyItem("SF8CD","unlizenzierte Software auf CD","0.00");}
		}

	else if (document.Bestellung.Software_auf_CD.checked) 
		{
		if (document.Bestellung.Modul_Schueler.checked || document.Bestellung.Modul_Planung.checked || document.Bestellung.Modul_Mehrplatz.checked || document.Bestellung.Modul_PocketPC.checked) 
			{	
			alert('Bitte wählen Sie eine Option im Bereich Grundversion,\noder deaktivieren Sie die Zusatzmodule!');
			return false;
			}
		else
			pospreis=parseFloat(document.Bestellung.blindcd.value);
			summe+=pospreis;
			buyItem("SF8CD","unlizenzierte Software auf CD",document.Bestellung.blindcd.value);
		}
	else
		{
		if ((bNurPreisBerechnen == 0) || (bNurPreisBerechnen == 2))
			{
			alert('Bitte wählen Sie eine Option im Bereich Grundversion!');
			return false;
			}
	}
	
	

	if (bNurPreisBerechnen == 1)
	{
		document.Bestellung.Bestellwert.value = alterError(summe);
	}
	else
	{

		if (version == "UPDLTUP" && document.Bestellung.Modul_Schueler.checked && document.Bestellung.Modul_Planung.checked == false)
		// LT + UP + SE nur in Verbindung mit PL!
		{
			alert('Die Kombination "LT + Unterrichtsplanung + Modul Schüler-Erweiterung"\nkann nur in Verbindung mit Modul "Planung" bestellt werden!');
			return false;
		}
		
		if (bNurPreisBerechnen == 0)
		{
			self.location="bestellung2.html";
		}
		else if (bNurPreisBerechnen == 2)
		{
			return chkFormular();
		}
	}
	
	return true;
}

function updatepreis() 
{
	var version = document.Bestellung.cboupdate.options[document.Bestellung.cboupdate.options.selectedIndex].value;
	
	document.Bestellung.blindelse.value = document.Bestellung.fixelse.value + ".00";
	document.Bestellung.preiselse.value = document.Bestellung.fixelse.value;
	document.Bestellung.preiselse.style.color = '#3c3c3c';
	document.Bestellung.blindelpl.value = document.Bestellung.fixelpl.value + ".00";
	document.Bestellung.preiselpl.value = document.Bestellung.fixelpl.value;
	document.Bestellung.preiselpl.style.color = '#3c3c3c';
	document.Bestellung.blindelmp.value = document.Bestellung.fixelmp.value + ".00";
	document.Bestellung.preiselmp.value = document.Bestellung.fixelmp.value;
	document.Bestellung.preiselmp.style.color = '#3c3c3c';
	document.Bestellung.blindelppc.value = document.Bestellung.fixelppc.value + ".00";
	document.Bestellung.preiselppc.value = document.Bestellung.fixelppc.value;
	document.Bestellung.preiselppc.style.color = '#3c3c3c';

	document.Bestellung.blindslse.value = document.Bestellung.fixslse.value + ".00";
	document.Bestellung.preisslse.value = document.Bestellung.fixslse.value;
	document.Bestellung.preisslse.style.color = '#3c3c3c';
	document.Bestellung.blindslpl.value = document.Bestellung.fixslpl.value + ".00";
	document.Bestellung.preisslpl.value = document.Bestellung.fixslpl.value;
	document.Bestellung.preisslpl.style.color = '#3c3c3c';
	document.Bestellung.blindslmp.value = document.Bestellung.fixslmp.value + ".00";
	document.Bestellung.preisslmp.value = document.Bestellung.fixslmp.value;
	document.Bestellung.preisslmp.style.color = '#3c3c3c';
	document.Bestellung.blindslppc.value = document.Bestellung.fixslppc.value + ".00";
	document.Bestellung.preisslppc.value = document.Bestellung.fixslppc.value;
	document.Bestellung.preisslppc.style.color = '#3c3c3c';
	
	if ((document.Bestellung.Lizenzart[2].checked || document.Bestellung.Lizenzart[3].checked) && (version != ""))
	{
		if (version == "UPDLTUP")
			{
			document.Bestellung.blindelpl.value = "5.00";
			document.Bestellung.preiselpl.value = "5";
			document.Bestellung.preiselpl.style.color = 'red';
			
			document.Bestellung.blindslpl.value = "35.00";
			document.Bestellung.preisslpl.value = "35";
			document.Bestellung.preisslpl.style.color = 'red';
			}
		else if ((version == "UPDST") || (version =="UPDSTPPC"))
			{
			document.Bestellung.blindelse.value = "10.00";
			document.Bestellung.preiselse.value = "10";
			document.Bestellung.preiselse.style.color = 'red'; 
			document.Bestellung.blindelpl.value = "10.00";
			document.Bestellung.preiselpl.value = "10";
			document.Bestellung.preiselpl.style.color = 'red';

			document.Bestellung.blindslse.value = "70.00";
			document.Bestellung.preisslse.value = "70";
			document.Bestellung.preisslse.style.color = 'red'; 
			document.Bestellung.blindslpl.value = "70.00";
			document.Bestellung.preisslpl.value = "70";
			document.Bestellung.preisslpl.style.color = 'red';
			if (version == "UPDSTPPC")
			{
			document.Bestellung.blindelppc.value = "0.00";
			document.Bestellung.preiselppc.value = "0";
			document.Bestellung.preiselppc.style.color = 'red';
			document.Bestellung.blindslppc.value = "0.00";
			document.Bestellung.preisslppc.value = "0";
			document.Bestellung.preisslppc.style.color = 'red';
			}
			
			}
		else if ((version == "UPDSTUP") || (version == "UPDSTUPPPC"))
			{
			document.Bestellung.blindelse.value = "10.00";
			document.Bestellung.preiselse.value = "10";
			document.Bestellung.preiselse.style.color = 'red';
			document.Bestellung.blindelpl.value = "0.00";
			document.Bestellung.preiselpl.value = "0";
			document.Bestellung.preiselpl.style.color = 'red';
			
			document.Bestellung.blindslse.value = "70.00";
			document.Bestellung.preisslse.value = "70";
			document.Bestellung.preisslse.style.color = 'red';
			document.Bestellung.blindslpl.value = "0.00";
			document.Bestellung.preisslpl.value = "0";
			document.Bestellung.preisslpl.style.color = 'red';
			if (version == "UPDSTUPPPC")
			{
			document.Bestellung.blindelppc.value = "0.00";
			document.Bestellung.preiselppc.value = "0";
			document.Bestellung.preiselppc.style.color = 'red';
			document.Bestellung.blindslppc.value = "0.00";
			document.Bestellung.preisslppc.value = "0";
			document.Bestellung.preisslppc.style.color = 'red';
			}

			}
		
		else if (version == "UPDSTUPBEN")
			{
			document.Bestellung.blindelse.value = "10.00";
			document.Bestellung.preiselse.value = "10";
			document.Bestellung.preiselse.style.color = 'red';
			document.Bestellung.blindelpl.value = "0.00";
			document.Bestellung.preiselpl.value = "0";
			document.Bestellung.preiselpl.style.color = 'red';
			document.Bestellung.blindelmp.value = "10.00";
			document.Bestellung.preiselmp.value = "10";
			document.Bestellung.preiselmp.style.color = 'red';

			document.Bestellung.blindslse.value = "70.00";
			document.Bestellung.preisslse.value = "70";
			document.Bestellung.preisslse.style.color = 'red';
			document.Bestellung.blindslpl.value = "0.00";
			document.Bestellung.preisslpl.value = "0";
			document.Bestellung.preisslpl.style.color = 'red';
			document.Bestellung.blindslmp.value = "70.00";
			document.Bestellung.preisslmp.value = "70";
			document.Bestellung.preisslmp.style.color = 'red';
			}
		else if ((version == "UPDXL") || (version == "UPDXLPPC"))
			{
			document.Bestellung.blindelse.value = "0.00";
			document.Bestellung.preiselse.value = "0";
			document.Bestellung.preiselse.style.color = 'red'; 
			document.Bestellung.blindelpl.value = "10.00";
			document.Bestellung.preiselpl.value = "10";
			document.Bestellung.preiselpl.style.color = 'red';

			document.Bestellung.blindslse.value = "0.00";
			document.Bestellung.preisslse.value = "0";
			document.Bestellung.preisslse.style.color = 'red'; 
			document.Bestellung.blindslpl.value = "70.00";
			document.Bestellung.preisslpl.value = "70";
			document.Bestellung.preisslpl.style.color = 'red';
			if (version == "UPDXLPPC")
			{
			document.Bestellung.blindelppc.value = "0.00";
			document.Bestellung.preiselppc.value = "0";
			document.Bestellung.preiselppc.style.color = 'red';
			document.Bestellung.blindslppc.value = "0.00";
			document.Bestellung.preisslppc.value = "0";
			document.Bestellung.preisslppc.style.color = 'red';
			}
			}
		else if (version == "UPDXLUP")
			{
			document.Bestellung.blindelse.value = "0.00";
			document.Bestellung.preiselse.value = "0";
			document.Bestellung.preiselse.style.color = 'red';
			document.Bestellung.blindelpl.value = "0.00";
			document.Bestellung.preiselpl.value = "0";
			document.Bestellung.preiselpl.style.color = 'red';

			document.Bestellung.blindslse.value = "0.00";
			document.Bestellung.preisslse.value = "0";
			document.Bestellung.preisslse.style.color = 'red';
			document.Bestellung.blindslpl.value = "0.00";
			document.Bestellung.preisslpl.value = "0";
			document.Bestellung.preisslpl.style.color = 'red';
			}
		else if (version == "UPDXLBEN")
			{
			document.Bestellung.blindelse.value = "0.00";
			document.Bestellung.preiselse.value = "0";
			document.Bestellung.preiselse.style.color = 'red';
			document.Bestellung.blindelpl.value = "10.00";
			document.Bestellung.preiselpl.value = "10";
			document.Bestellung.preiselpl.style.color = 'red';
			document.Bestellung.blindelmp.value = "10.00";
			document.Bestellung.preiselmp.value = "10";
			document.Bestellung.preiselmp.style.color = 'red';

			document.Bestellung.blindslse.value = "0.00";
			document.Bestellung.preisslse.value = "0";
			document.Bestellung.preisslse.style.color = 'red';
			document.Bestellung.blindslpl.value = "70.00";
			document.Bestellung.preisslpl.value = "70";
			document.Bestellung.preisslpl.style.color = 'red';
			document.Bestellung.blindslmp.value = "70.00";
			document.Bestellung.preisslmp.value = "70";
			document.Bestellung.preisslmp.style.color = 'red';
			}
		else if ((version == "UPDXLUPBEN") || (version == "UPDXLUPBENPPC"))
			{
			document.Bestellung.blindelse.value = "0.00";
			document.Bestellung.preiselse.value = "0";
			document.Bestellung.preiselse.style.color = 'red';
			document.Bestellung.blindelpl.value = "0.00";
			document.Bestellung.preiselpl.value = "0";
			document.Bestellung.preiselpl.style.color = 'red';
			document.Bestellung.blindelmp.value = "10.00";
			document.Bestellung.preiselmp.value = "10";
			document.Bestellung.preiselmp.style.color = 'red';

			document.Bestellung.blindslse.value = "0.00";
			document.Bestellung.preisslse.value = "0";
			document.Bestellung.preisslse.style.color = 'red';
			document.Bestellung.blindslpl.value = "0.00";
			document.Bestellung.preisslpl.value = "0";
			document.Bestellung.preisslpl.style.color = 'red';
			document.Bestellung.blindslmp.value = "70.00";
			document.Bestellung.preisslmp.value = "70";
			document.Bestellung.preisslmp.style.color = 'red';
			if (version == "UPDXLUPBENPPC")
			{
			document.Bestellung.blindelppc.value = "0.00";
			document.Bestellung.preiselppc.value = "0";
			document.Bestellung.preiselppc.style.color = 'red';
			document.Bestellung.blindslppc.value = "0.00";
			document.Bestellung.preisslppc.value = "0";
			document.Bestellung.preisslppc.style.color = 'red';
			}
			}

	}

	writeOrder(1);
}
	

function buyItem(Artikel, Bezeichnung, Preis)
{
	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)+"["+Artikel+"|"+Preis+"|"+Bezeichnung+"]";
}

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;
	
	document.writeln('<table border="0" cellpadding="2" cellspacing="0">');
	document.writeln('<tr bgcolor="#316598"><td class="weiss">Artikel</td><td>&nbsp;</td><td class="weiss">Bezeichnung</td><td align="right" class="weiss">Preis</td></tr>');
                
	itemlist = 0;
	for (var i = 0; i <= fulllist.length; i++) {
                
	if (fulllist.substring(i,i+1) == '[')
		{thisitem = 1;
		itemstart = i+1;
		
	} else if (fulllist.substring(i,i+1) == ']') {
		itemend = i;
		thequantity = 1
		Bezeichnung=fulllist.substring(itemstart, itemend);
		itemtotal = 0;
		itemtotal = (eval(theprice*thequantity));
		totprice = totprice + itemtotal;
		itemlist=itemlist+1;

		document.writeln('<tr><td>'+theitem+'</td><td>&nbsp;</td>');
		document.writeln('<td>'+Bezeichnung+'</td><td align=right>'+alterError(itemtotal)+'</td></tr>');
		document.writeln('<INPUT TYPE="hidden" NAME="Artikel'+itemlist+'" VALUE="'+theitem+'" SIZE="40">');
		

	} else if (fulllist.substring(i,i+1) == '|') {
		if (thisitem==1) theitem = fulllist.substring(itemstart, i);
		if (thisitem==2) theprice = fulllist.substring(itemstart, i);
		thisitem++;
		itemstart=i+1;
		}
	}

        	document.writeln('<tr bgcolor="#316598"><td colspan="3" class="weiss"><b>Gesamt</b></td><td align="right" class="weiss"><b>EUR '+alterError(totprice)+'</b></td></tr>');
document.writeln('<tr><td colspan="3">Betrag enthält je nach Empfangsland ggf. 19% MWSt.</td><td align="right">EUR '+Mehrwertsteuer(totprice)+'</td></tr>');
	document.writeln('</table>');
	document.writeln('<INPUT TYPE="hidden" NAME="Bestellwert" VALUE="'+totprice+'" SIZE="6">');
	}

function alterError(value)
{

var pos=0;
var ende=0;
var anf=0;

value=new String(value)

pos = value.indexOf(".");
if (pos==-1)
{
value = value+".00";
}
else
	{
	ende=pos+3;
	if ((pos+3)>value.length);
	{
	value=value+"000";
	}
	if (pos>0)
	{
	value=value.substring(anf,pos)+"."+value.substring(pos+1,ende);
	}
}
return (value)
}

function Mehrwertsteuer(value)
{

var brutto
var netto

	brutto=alterError(value);
	netto=kaufm(brutto-(brutto/1.19));
	return netto;
}

function kaufm(x) {
  var k = (Math.round(x * 100) / 100).toString();
  k += (k.indexOf('.') == -1)? '.00' : '00';
  return k.substring(0, k.indexOf('.') + 3);
}


function chkFormular()
{
	if(document.Bestellung.Name.value == "")  {
	alert("Bitte geben Sie Ihren Namen (bzw. Schulnamen bei Schullizenz) ein!");
   	document.Bestellung.Name.focus();
	return false;
  	}
	if(document.Bestellung.Strasse.value == "") {
	alert("Bitte machen Sie eine Eingabe im Feld 'Strasse'");
   	document.Bestellung.Strasse.focus();
	return false;
  	}
	if(document.Bestellung.PLZ.value == "") {
	alert("Bitte machen Sie eine Eingabe im Feld 'PLZ'");
   	document.Bestellung.PLZ.focus();
	return false;
	}
	if(document.Bestellung.Ort.value == "") {
	alert("Bitte machen Sie eine Eingabe im Feld 'Ort'");
   	document.Bestellung.Ort.focus();
	return false;
	}
	if(document.Bestellung.Versandart.checked) {
		if(document.Bestellung.email.value == "") {
		alert("Bitte machen Sie eine gültige Eingabe im Feld 'E-Mail' oder deaktivieren Sie den Versand per E-Mail");
   		document.Bestellung.email.focus();
		return false;
		}
	}
}

function  zurueck()
{
        self.location="bestellung.html";
}

