// Cookie-System fuer Online-Bestellungen
// korrigiert MAC-Bug
function FixCookieDate(date)
{
var basis=new Date(0);
var chk=basis.getTime();
if (chk > 0) date.setTime(date.getTime() - chk);
}

function loescheCookie(Name)
{
if (holeCookie(Name)) {
	document.cookie=Name+"="+"000; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}

function holeCookie(Name)
{
var nam=Name+"=";
var Laenge=nam.length;
var Cookie_Laenge=document.cookie.length;
var i=0;
while (i < Cookie_Laenge) {
	var j = i+Laenge;
	if (document.cookie.substring(i,j)== nam){
	 	return holeCookieWert(j);
	}
	i=document.cookie.indexOf(" ",i)+1;
	if (i==0) break;
}
return null;
}

function holeCookieWert(Position) 
{
var Ende=document.cookie.indexOf(";",Position);
if (Ende==-1) Ende=document.cookie.length;
return unescape(document.cookie.substring(Position,Ende));
}

function setzeCookie(Name,Wert,Datum)	
{
if (Datum!=null) {
	var expires = Datum.toGMTString();
	document.cookie=Name+"="+escape(Wert)+"; expires="+expires;
}
if (Datum==null)document.cookie=Name+"="+escape(Wert);
}

// 2 NK-Stellen //
function initzahl(wert)
{
var text=wert+"";
var punkt=text.indexOf(".");
if (punkt<0) text +=".00";
else if(punkt==0) text="0"+text;
text+="00";
punkt=text.indexOf(".");
text=text.substring(0,punkt+3);
return text;
}

function Cookie_art(art, product, unit, anz, pre)
{
ok=false;
var verfall=null;
//var verfall=new Date();
// korrigiert Mac-Bug
//FixCookieDate(verfall);
// Haltbarkeit 1 Tag
//var ein_tag=24*60*60*1000;
//verfall.setTime(verfall.getTime()+ein_tag); 
var vkorb=holeCookie("ib1");
var z1=0;
var zwic="[["+art+"~"+product+"~"+unit+"~"+anz+"~"+pre+"]]";
if (vkorb!=null) {
// max. 3 kb gehen in das Warenkorb-Cookie
//	for (i=0; (i<=vkorb.length-1); i++) {
//		var chk=vkorb.charAt(i);
//		if (chk=="[[") z1++;
//	}	
  var cookiegr=vkorb.length+zwic.length;
  if (cookiegr>3000) {
     z1=1;
  }

} else vkorb="";
if (z1==0) {
	vkorb=vkorb+"[["+art+"~"+product+"~"+unit+"~"+anz+"~"+pre+"]]";
	setzeCookie("ib1",vkorb,verfall);
	ok=true;
} else alert("The orderform is out of capacity !!\nPlease carry out an additional order when required.");
return ok;
}

// Artikeldaten werden erstellt und zur weiteren Verarbeitung uebergeben
function order(form)
{
var konf=document.forms["ORDER"];
var art=konf["N"+form].value;
var product=konf["C"+form].value;
var unit=konf["S"+form].options[konf["S"+form].options.selectedIndex].text;
var price=konf["S"+form].options[konf["S"+form].options.selectedIndex].value;
var anz=konf["A"+form].value;
if ( anz >0 && anz < 100) {
	var ok=Cookie_art(art, product, unit, anz, price);
	if (ok==true) alert("The product "+art+", "+unit+" was transferred to the orderform \n\nTo transmit  the order to us, use the PURCHASE-button on the left side.");
} else {
	alert("False input:\nPlease use only whole numbers between 1 and 99.");
}

}
// Betragsuebergabe in das Feld f. den Preis
function bsel(form)
{
 var konf=document.forms["ORDER"];
 konf["P"+form].value=konf["S"+form].options[konf["S"+form].options.selectedIndex].value;
}

// Betragsuebergabe in das Feld f. den Preis
function paend(form)
{
 var konf=document.forms["ORDER"];
 konf["S"+form].focus();
}

//Betragsberechnung nach Anzahlaenderung
function panz(form)
{
 var gesamt=0;
 var konf=document.forms["ORDER"];
 var anzahl=parseInt(konf["A"+form].value);
 var preis=konf["S"+form].options[konf["S"+form].options.selectedIndex].value;
 if ( anzahl > 0 || anzahl < 99 || konf["A"+form].value=="") {
 	if (konf["A"+form].value!="") {
		konf["A"+form].value=anzahl;
	 	gesamt=anzahl*preis;
		konf["P"+form].value=initzahl(gesamt);
	}	
 } else {
 	alert("False input:\nPlease use only whole numbers between 1 and 99.");
	konf["A"+form].value="";	
	konf["A"+form].focus();	
 }
}


function formular_pruefen(language)
{
var chk=true;
var summe=0;
if (document.BESTELLUNG.GESAMT_SUMME) summe=document.BESTELLUNG.GESAMT_SUMME.value;
// if (summe==0 || (summe-8)< 15) {
// 	alert("Leider gibt es einen Mindestbestellwert von 15 EURO.\nBitte haben Sie Verstaendnis !!");
//	chk=false;
// }
if (document.BESTELLUNG.NAME.value=="") { 
	if (language=="e") {
		alert("Please give us your name (LAST NAME/ FIRST NAME).");
	} else alert("Bitte fuellen Sie das Feld NAME, VORNAME korrekt aus.");
	chk=false;
	document.BESTELLUNG.NAME.focus();
}
if (document.BESTELLUNG.FIRMA.value=="") { 
	if (language=="e") {
		alert("Please give us your company (COMPANY).");
	} else alert("Bitte fuellen Sie das Feld FIRMA korrekt aus.");
	chk=false;
	document.BESTELLUNG.FIRMA.focus();
}
if (document.BESTELLUNG.STRASSE.value=="") { 
	if (language=="e") {
		alert("Please give us your street (STREET).");
	} else alert("Bitte fuellen Sie das Feld STRASSE korrekt aus.");
	chk=false;
	document.BESTELLUNG.STRASSE.focus();
}
if (document.BESTELLUNG.ORT.value=="") { 
	if (language=="e") {
		alert("Please give us your city (ZIP-CODE/ CITY).");
	} else alert("Bitte fuellen Sie das Feld ORT korrekt aus.");
	chk=false;
	document.BESTELLUNG.ORT.focus();
}
if (document.BESTELLUNG.EMAIL.value=="") { 
	if (language=="e") {
		alert("Please give us your E-Mail-Adress.");
	} else alert("Bitte fuellen Sie das Feld eMAIL korrekt aus.");
	chk=false;
	document.BESTELLUNG.EMAIL.focus();
}
if (chk==true) {
	loescheCookie("ib1");
}	
return chk;
}	
