// JavaScript Document
<!--
var produktArrayAnz = new Array( 0,0,0,0,0,0,0,0);
var produktPreis = 18.99;
//var zahlung = 0;
var versand = 0;
var bonus = 0;


produktArrayAnz[0] = parseInt(getCookie("Artikel_0"));
produktArrayAnz[1] = parseInt(getCookie("Artikel_1"));
produktArrayAnz[2] = parseInt(getCookie("Artikel_2"));
produktArrayAnz[3] = parseInt(getCookie("Artikel_3"));
produktArrayAnz[4] = parseInt(getCookie("Artikel_4"));
produktArrayAnz[5] = parseInt(getCookie("Artikel_5"));
produktArrayAnz[6] = parseInt(getCookie("Artikel_6"));
produktArrayAnz[7] = parseInt(getCookie("Artikel_7"));
function istZahl(n){
  s = ""+n;
  var ziffern = "0123456789";
  for (var i=0; i<s.length; i++)
    if (ziffern.indexOf(s.charAt(i))<0) return false;
  return true;
}
function setCookie(name, wert, domain, expires, path, secure){
   var cook = name+"="+unescape(wert);
   cook += (domain) ? "; domain="+ domain : "";
   cook += (expires) ? "; expires="+expires : "";
   cook += (path) ? "; path="+path : "";
   cook += (secure) ? "; secure": "";
   document.cookie = cook;
}
function getCookie(name){
   var i=0 ; //Suchposition im Cookie
   var suche = name+"=";
   while (i<document.cookie.length){
      if (document.cookie.substring(i, i+suche.length)==suche){
         var ende = document.cookie.indexOf(";", i+suche.length);
         ende = (ende>-1) ? ende : document.cookie.length;
         var cook = document.cookie.substring(i+suche.length, ende);
         return unescape(cook);
      }
      i++;
   }
   return 0;
}
function checkCookie(){
   setCookie("CookieTest", "OK");
   if (!getCookie("CookieTest"))
      return false;
   else{
      eraseCookie("CookieTest");
      return true;
   }
}
function destroy(){
    for(i=0; i< produktArrayAnz.length; i++){
		produktArrayAnz[i] = 0;
		setCookie("Artikel_"+i, produktArrayAnz[i] );
	}
}
function start(){	
    for(i=0; i< produktArrayAnz.length; i++){
		produktArrayAnz[i] = 0;
		produktArrayAnz[i] = parseInt(getCookie("Artikel_"+i));
		setCookie("Artikel_"+i, produktArrayAnz[i] );
	}
	werteNeu();
	for(i=0; i< produktArrayAnz.length; i++){
		 if( $('Var_Anz_'+i) ) $('Var_Anz_'+i).value=produktArrayAnz[i];
    };
}
function anzArtikel(){
	anzA =0;
	for(i=0; i<produktArrayAnz.length; i++){ anzA += produktArrayAnz[i]; }
	document.write(anzA);
}
function getAnzGesamt(){
	var anzA =0;
	for(i=0; i<produktArrayAnz.length; i++){ anzA += produktArrayAnz[i]; }
	return anzA;
}
function getMwSt(){
	anzA =0;
	mwst = 0.00;
	for(i=0; i<produktArrayAnz.length; i++){ anzA += produktArrayAnz[i]; }
	if(anzA > 0) {
		  mwst = (produktPreis * anzA) + versand;
		  mwst = ( mwst * 19.00) / 119.00;
	}
	mwst = mwst.toFixed(2);
	komma = mwst.replace(/\./,",") ;
	document.write( komma );
}
function getAnz(num){
	produktArrayAnz[num] = parseInt(getCookie("Artikel_"+num));
	return produktArrayAnz[num]; 
}

function getVersand(){
	anzA = 0;
	for(i=0; i<produktArrayAnz.length; i++){ anzA += produktArrayAnz[i] ; }
	if(anzA < 3) { return versand;}
	else return 0;
}
function getVersandDoc(){
	philf =getVersand();
	philf = philf.toFixed(2);
	komma = philf.replace(/\./,",");
	if ( $('versandkosten') ) $('versandkosten').innerHTML= komma;
}
function preisGesamt(){
	anzA = getVersand();
	for(i=0; i<produktArrayAnz.length; i++){ anzA += (produktArrayAnz[i] * produktPreis); }
	anzA = anzA.toFixed(2)
	komma = anzA.replace(/\./,",") ;
	document.write( komma );
}
function addArtikel( num ){
	//$('add').disabled=true;
	anz = $F($('Anzahl'));		
	anz = (istZahl(anz) ? anz : "0");
	produktArrayAnz[num] += parseInt(anz);	
	setCookie("Artikel_"+num, produktArrayAnz[num] );

	werteNeu();
}
function wertNeu(num, wert){
	anz = 0;		
	anz = ( istZahl(wert) ? wert : "0");
	produktArrayAnz[num] = parseInt(anz);

	hilf = parseInt( produktArrayAnz[parseInt(num)]  ) * produktPreis;
	text = " "+hilf.toFixed(2)+" EUR";
	$("gPreis_"+num).innerHTML=text ;
	setCookie("Artikel_"+num, produktArrayAnz[num] );
	werteNeu();
}
function werteNeu(){
	hilf = 0;
	mwst = 0.00;
	for(i=0; i<produktArrayAnz.length; i++){
	   if( !istZahl(produktArrayAnz[i]) ) { produktArrayAnz[i]=0; }
/*	   $('Anz_'+i).innerHTML = produktArrayAnz[i] +'x';
	   ges = (produktArrayAnz[i] * produktPreis).toFixed(2);
	   ges = ges.replace(/\./,",");
	   $('GES_'+i).innerHTML = ges;*/
	   hilf += produktArrayAnz[i]; 
	 }
	
	philf =getVersand();
	philf += (hilf * produktPreis); 
	philf = philf.toFixed(2);
	komma = philf.replace(/\./,",");
	if ( $('wahrenPreis') ) $('wahrenPreis').innerHTML= komma;
	if ( $('wahrenAnz') ) $('wahrenAnz').innerHTML= hilf;
	mwst = (philf * 19.00) / 119.00;
	mwst = mwst.toFixed(2);
	mwst = mwst.replace(/\./,",");
	if ( $('MwSt') ) $('MwSt').innerHTML= mwst;
	philf =getVersand();
	philf = philf.toFixed(2);
	komma = philf.replace(/\./,",");
	if ( $('versandkosten') ) $('versandkosten').innerHTML= komma;
}

function WK_an(i){
	   $('Var_'+i).show(); 
	   $('Anz_'+i).hide(); 
	   $('Var_Anz_'+i).value=produktArrayAnz[i];
}
function WK_aus(i){
	   $('Var_Anz_'+i).value=produktArrayAnz[i];
	   $('Anz_'+i).show(); 
	   $('Var_'+i).hide();  
}
function WK_ok(i){
	   var v = $('Var_Anz_'+i).value;
	   if( (v!='') && istZahl(v) ){
			produktArrayAnz[i] = parseInt( $('Var_Anz_'+i).value );
			$('Var_Anz_'+i).value=produktArrayAnz[i] ;
			setCookie("Artikel_"+i, produktArrayAnz[i] );
			werteNeu();
	   }else{
	   	 	$('Var_Anz_'+i).value=0;
			produktArrayAnz[i] = parseInt( $('Var_Anz_'+i).value );
			setCookie("Artikel_"+i, produktArrayAnz[i] );
			werteNeu();			
	   }
}
function WK_nok(i){
        produktArrayAnz[i] = 0;
		setCookie("Artikel_"+i, produktArrayAnz[i] );
		$('WK_'+i).hide();
		werteNeu();
}
function validEmail(email) {
  var strReg = "^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$";
  var regex = new RegExp(strReg);
  return(regex.test(email));
}
function chek_bestellung(){
	var status = 1;	
	v = $('name').value;
	if (v.length < 1) {status=0; }
	v = $('strasse').value;
	if (v.length < 1) {status=0; }
	v = $('ort').value;
	if (v.length < 1) {status=0; }
	v = $('email').value;
	if (!validEmail(v)) {status=0; }

	if( getAnzGesamt() <= 0) {status = 0;}
	if(status == 1) { $('kauf').disabled = false; $('kauf').style.color ="#990000"; 
	} else { $('kauf').disabled = true; $('kauf').style.color ="#999999"; }
}
function chek_empfehlung(){
	var status = 1;	
	v = $('absender').value;
	if (!validEmail(v)) {status=0; }
	v = $('empfang').value;
	if (!validEmail(v)) {status=0; }
	if(status == 1) { $('abschicken').disabled = false; $('abschicken').style.color ="#000000"; 
	} else { $('abschicken').disabled = true; $('abschicken').style.color ="#999999"; }
}
	
function trim (zeichenkette) {
  // Erst führende, dann Abschließende Whitespaces entfernen
  // und das Ergebnis dieser Operationen zurückliefern
  return zeichenkette.replace (/^\s+/, '').replace (/\s+$/, '');
}

function chek_code(){
	bonus=-1;
	text = "";
	$('code').value = trim($('code').value);
	if ( $('code').value=='' ) bonus= 0;
	else if ( $('code').value=='UH-12-IK' ) bonus= 1;
	else if ( $('code').value=='CD-95-PL' ) bonus= 2;
	else if ( $('code').value=='JK-73-PZ' ) bonus= 3;
	else if ( $('code').value=='LL-82-TZ' ) bonus= 4;
	else if ( $('code').value=='OK-51-GH' ) bonus= 5;
	else if ( $('code').value=='HU-11-FR') bonus= 2;
	else if ( $('code').value=='IU-12-FG') bonus= 2;
	else if ( $('code').value=='OI-13-GT') bonus= 2;
	else if ( $('code').value=='TR-14-HJ') bonus= 2;
	else if ( $('code').value=='RF-15-JK') bonus= 2;
	else if ( $('code').value=='ZH-16-IK') bonus= 2;
	else if ( $('code').value=='BG-17-IK') bonus= 2;
	else if ( $('code').value=='MJ-18-KL') bonus= 2;
	else if ( $('code').value=='DC-19-QT') bonus= 2;
	else if ( $('code').value=='DE-20-EU') bonus= 2;
	else if ( $('code').value=='DR-21-EO') bonus= 2;
	else if ( $('code').value=='WS-22-UJ') bonus= 2;
	else if ( $('code').value=='CF-23-TG') bonus= 2;
	else if ( $('code').value=='IH-24-EC') bonus= 2;
	else if ( $('code').value=='PW-25-UM') bonus= 2;
	else if ( $('code').value=='UQ-26-TB') bonus= 2;
	else if ( $('code').value=='OR-27-OM') bonus= 2;
	else if ( $('code').value=='NY-28-QA') bonus= 2;
	else if ( $('code').value=='MC-29-CE') bonus= 2;
	else if ( $('code').value=='TV-30-BT') bonus= 10;
	else {
		text="&nbsp;&nbsp;Fehlerhafter Kunden-Code";
		$('bonus').innerHTML = text;
		$('bonus').style.color = '#ff0000';
		bonus =0;
		$('bonus').innerHTML = text;
		hilf = (betrag *(100 -bonus) / 100) + versand;
	    $('gesamt').innerHTML = hilf.toFixed(2);
		$('gesamtBetrag').style.color ='#000';
		return -1;
	}
	
	if((bonus > 0) && (bonus < 90)){
		text="&nbsp;&nbsp;Sie bekommen " + bonus+"% Rabatt";	
		$('bonus').style.color ='#66CC00';
		$('gesamtBetrag').style.color ='#66CC00';
	} else {
		text="&nbsp;";
		$('gesamtBetrag').style.color ='#000';
	}
	$('bonus').innerHTML = text;
	hilf = (betrag *(100 -bonus) / 100) + versand;
	$('gesamt').innerHTML = hilf.toFixed(2);
	return bonus;
}

function chek_kaufen(){
	var status = 1;	
	//if(zahlung == 0) status = 0;
	
	if ( $('AGB').checked==false ){
		 status = 0;
	}
	if ( chek_code() < 0 ){
		 status = 0;
	}
	
	if(status == 1) { $('kaufen').disabled = false; $('kaufen').style.color ="#990000"; 
	} else { $('kaufen').disabled = true; $('kaufen').style.color ="#999999"; }
}


