// 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);
}

function aw(name, artikel, option, id)
{
ok=false;
var verfall=null;
var a1="false";
var b1="false"; 
var c1="false";
var a="";
var b=""; 
var c="";
var vkorb=holeCookie("art");
if (option=="a1") a1="true";
if (option=="b1") b1="true";
if (option=="c1") c1="true";
var z1=0;
if (vkorb!=null) {
     	vorhanden=vkorb.indexOf("ID="+id+"]",0);
		if (vorhanden > -1) {
		   vor_start=vkorb.lastIndexOf("[",vorhanden);
		   vor_ende=vkorb.indexOf("]",vor_start);
		   		   var part1="";
		   var part2="";
		   if (vor_start > 0) {
		   		part1=vkorb.substring(0,vor_start);
		   } else part1="";
		   if (vor_ende < vkorb.length) {
				part2=vkorb.substring(vor_ende+1,vkorb.length);
		   } else part2="";	
		   var vsatz=vkorb.substring(vor_start+1,vor_ende);
		   var ez=0;
		   var sz=0;
		   sz=vsatz.indexOf("|");
		   var nr=vsatz.substring(0,sz);
		   ez=sz+1;
		   sz=vsatz.indexOf("|",ez);
   		   var text=vsatz.substring(ez,sz);
		   ez=sz+1;
		   sz=vsatz.indexOf("|",ez);
		   a=vsatz.substring(ez,sz);
		   ez=sz+1;
		   sz=vsatz.indexOf("|",ez);
		   b=vsatz.substring(ez,sz);
   		   ez=sz+1;
		   sz=vsatz.indexOf("|",ez);
		   c=vsatz.substring(ez,sz);
		   ez=sz+1;
		   sz=vsatz.indexOf("|",ez);
	 	   var opt=vsatz.substring(sz+1,vsatz.length);
		   a1=a;
		   b1=b;
		   c1=c;
		   if (a=="true" && option=="a1") a1="false";
   		   if (a=="false" && option=="a1") a1="true";
   		   if (b=="true" && option=="b1") b1="false";
   		   if (b=="false" && option=="b1") b1="true";
   		   if (c=="true" && option=="c1") c1="false";
   		   if (c=="false" && option=="c1") c1="true";
	       vkorb=part1+part2;
		}
// max. 55 Artikel pro Bestellung
	for (i=0; (i<=vkorb.length-1); i++) {
		var chk=vkorb.charAt(i);
		if (chk=="[") z1++;
	}	
} else vkorb="";
if (z1<30) {
	if (a1=="true" || b1=="true" || c1=="true") {
		vkorb=vkorb+"["+name+"|"+artikel+"|"+a1+"|"+b1+"|"+c1+"|ID="+id+"]";
	}	
	setzeCookie("art",vkorb,verfall);
	ok=true;
} else alert("Es können max. 30 Substanzen gleichzeitig bestellt werden.");
return ok;
}


function formfuell(lang)
{
var quali="Qualit&auml;t";
var meng="Menge";
if (lang=="e") {
	quali="Quality";
	meng="Quantity";
}
var form=document.BESTELLUNG;
var vkorb=holeCookie("art");
var spos=0;
var epos=0;
var sposalt=-1;
var bgcol="#F4F4F4";
if (vkorb!=null) {
	document.write("<TABLE BORDER=0 cellpadding=3 cellspacing=0>");
 	for (var i=1; (i<=55); i++) {
    	spos=vkorb.indexOf("[",sposalt+1);
		if (spos!=-1 && sposalt!=spos) {
		   	epos=vkorb.indexOf("]",spos);
			if (epos!=-1){
			   var vsatz=vkorb.substring(spos+1,epos);
			   var sz=0;
			   sz=vsatz.indexOf("|");
			   var nr=vsatz.substring(0,sz);
   			   ez=sz+1;
			   sz=vsatz.indexOf("|",ez);
			   var text=vsatz.substring(ez,sz);
			   ez=sz+1;
			   sz=vsatz.indexOf("|",ez);
			   var a1=vsatz.substring(ez,sz);
   			   ez=sz+1;
			   sz=vsatz.indexOf("|",ez);
			   var b1=vsatz.substring(ez,sz);
   			   ez=sz+1;
			   sz=vsatz.indexOf("|",ez);
			   var c1=vsatz.substring(ez,sz);
			   var id=vsatz.substring(sz+4,vsatz.length);
			   var oncl_a1="onClick=\""+"aw('"+nr+"','"+text+"','a1','"+id+"');\"";
			   var oncl_b1="onClick=\""+"aw('"+nr+"','"+text+"','b1','"+id+"');\"";
			   var oncl_c1="onClick=\""+"aw('"+nr+"','"+text+"','c1','"+id+"');\"";
			   document.write("<TR><TD bgcolor='"+bgcol+"'>");
			   document.write("<input type='hidden' name='NAME"+i+"' value='"+nr+"'>");
			   document.write("<b class='bluelb'>"+nr+"</B><BR><img src='images/shim.gif' width='1' height='3' hspace='0' vspace='0' border='0' alt=''><BR>");
   			   document.write("<input type='hidden' name='TEXT"+i+"' value='"+text+"'>");
			   document.write("<b class='blackl'>"+text+"</B><BR><img src='images/shim.gif' width='1' height='3' hspace='0' vspace='0' border='0' alt=''><BR>");
			   document.write("<B>"+quali+"&nbsp;</B>");
			   document.write("<input type='text' name='QUALITAET"+i+"' value='' size='20' maxlength='25' style='height:18px;width:130px;background-color:#FFFFFF;font-size:8pt;font-family:verdana,arial;font-weight:normal;color:#000000;BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid;'>&nbsp;");
			   document.write("&nbsp;<B>&nbsp;"+meng+"&nbsp;</B>");
			   document.write("<input type='text' name='MENGE"+i+"' value='' size='10' maxlength='15' style='height:18px;width:70px;background-color:#FFFFFF;font-size:8pt;font-family:verdana,arial;font-weight:normal;color:#000000;BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid;'>&nbsp;");
			   var chk="";
			   if (a1=="true") chk="checked=\"true\"";
			   document.write("&nbsp;<B>&nbsp;Infos&nbsp;</B><input type=\"checkbox\" name=\"INFOS"+i+"\" "+chk+" "+oncl_a1+">");
			   document.write("</TD></TR>");
   			   document.write("<TR><TD bgcolor='#FFFFFF'><img src='images/shim.gif' width='1' height='1' hspace='0' vspace='0' border='0' alt=''></TD></TR>");
			   if (bgcol=="#F4F4F4") {
			   		bgcol="#FFF5E0";
			   } else {
			   		bgcol="#F4F4F4";
			   }
			
			   chk="";
//			   if (b1=="true") chk="checked=\"true\"";
//			   document.write("&nbsp;&nbsp;<input type=\"checkbox\" name=\"ANALYSE"+i+"\" "+chk+" "+oncl_b1+"><FONT COLOR='black' size='-1'>Analyse</FONT>");
//   			   chk="";
//			   if (c1=="true") chk="checked=\"true\"";
//	   		   document.writeln("&nbsp;&nbsp;<input type=\"checkbox\" name=\"ANGEBOT"+i+"\" "+chk+" "+oncl_c1+"><FONT COLOR='black' size='-1'>Angebot</FONT><BR><bR>");
          }
    	}	
	if (spos!=-1) sposalt=spos;
//	if (spos==0) spos++;
  }
  document.write("</TABLE>");
 }
}

function feldchk(bereich)
{
var form=document.BESTAND;
var vkorb=holeCookie("art");
var spos=0;
var epos=0;
var sposalt=-1;
if (vkorb!=null) {
 	for (var i=1; (i<=55); i++) {
    	spos=vkorb.indexOf("[",sposalt+1);
		if (spos!=-1 && sposalt!=spos) {
		   	epos=vkorb.indexOf("]",spos);
			if (epos!=-1){
			   var vsatz=vkorb.substring(spos+1,epos);
			   var sz=0;
			   sz=vsatz.indexOf("|");
			   var nr=vsatz.substring(0,sz);
   			   ez=sz+1;
			   sz=vsatz.indexOf("|",ez);
			   var text=vsatz.substring(ez,sz);
			   ez=sz+1;
			   sz=vsatz.indexOf("|",ez);
			   var a1=vsatz.substring(ez,sz);
   			   ez=sz+1;
			   sz=vsatz.indexOf("|",ez);
			   var b1=vsatz.substring(ez,sz);
   			   ez=sz+1;
			   sz=vsatz.indexOf("|",ez);
			   var c1=vsatz.substring(ez,sz);
			   var id=vsatz.substring(sz+4,vsatz.length);
			   var nummer=id.substring(1,id.length);
			   var bereich_dummy=id.substring(0,1);
			   if (bereich_dummy==bereich) {
	   		   		if (a1=="true") form["a"+nummer].checked=true;
    		   		if (b1=="true") form["b"+nummer].checked=true;
    		   		if (c1=="true") form["c"+nummer].checked=true;
			   }	
          }
    	}	
	if (spos!=-1) sposalt=spos;
//	if (spos==0) spos++;
  }
 }
}

function formular_pruefen(lang)
{
var chk=true;
if (document.BESTELLUNG.FIRMA.value=="") { 
	if (lang=="e") {
		alert("Please give us a accurate COMPANY");	
	} else {
		alert("Bitte fuellen Sie das Feld FIRMA korrekt aus.");
	}	
	chk=false;
	document.BESTELLUNG.FIRMA.focus();
}		
if (document.BESTELLUNG.VORNAME.value=="") { 
	if (lang=="e") {
		alert("Please give us a accurate FIRST NAME");
	} else {
		alert("Bitte fuellen Sie das Feld VORNAME korrekt aus.");	
	}	
	chk=false;
	document.BESTELLUNG.VORNAME.focus();
}
if (document.BESTELLUNG.NACHNAME.value=="") { 
	if (lang=="e") {
		alert("Please give us a LAST NAME");
	} else {
		alert("Bitte fuellen Sie das Feld NACHNAME korrekt aus.");	
	}	
	chk=false;
	document.BESTELLUNG.NACHNAME.focus();
}
if (document.BESTELLUNG.STRASSE.value=="") { 
	if (lang=="e") {
		alert("Please give us a accurate STREET");
	} else {
		alert("Bitte fuellen Sie das Feld STRASSE korrekt aus.");
	}	
	chk=false;
	document.BESTELLUNG.STRASSE.focus();
}
if (document.BESTELLUNG.ORT.value=="") { 
	if (lang=="e") {
		alert("Please give us a accurate ZIP-CODE/ CITY");
	} else {
		alert("Bitte fuellen Sie das Feld PLZ/ ORT korrekt aus.");
	}	
	chk=false;
	document.BESTELLUNG.ORT.focus();
}
if (document.BESTELLUNG.TELEFON.value=="") { 
	if (lang=="e") {
		alert("Please give us a accurate PHONE");
	} else {
		alert("Bitte fuellen Sie das Feld TELEFON korrekt aus.");
	}
	chk=false;
	document.BESTELLUNG.TELEFON.focus();
}


var email=document.BESTELLUNG.MAIL.value;
if (email !="")	{
   var atpos=email.indexOf("@");
	if (atpos<0) {
		if (lang=="e") {
			alert("Please give us a accurate MAIL");
		} else {
			alert("Bitte fuellen Sie das Feld MAIL korrekt aus");
		}	
    	chk=false;
	} else {
		if (email.lastIndexOf("@") != atpos) {
			if (lang=="e") {
				alert("Please give us a accurate MAIL");			
			} else {
				alert("Bitte geben Sie Ihre E-Mail-Adresse korrekt ein: Mehrfaches @");			
			}	
			chk=false;
		}	
	}
}
l=document.BESTELLUNG.ANMERKUNG.value;
if (l.length > 255) { 
	if (lang=="e") {
		alert("Als Anmerkung duerfen maximal 255 Zeichen eingegeben werden.");			
	} else {
		alert("Bitte geben Sie Ihre E-Mail-Adresse korrekt ein: Mehrfaches @");			
	}	
	alert("Please use for your COMMENT max. 255 character.");
	chk=false;
	document.BESTELLUNG.ANMERKUNG.focus();
}
return chk;
}	 

