/*
#########################################################################
# Scripts for Selfmadeshop 5.0
# func.js v1.2 / 21.07.2005
#
# (c) 2001-2005 CATMEDIA e-busines solutions http://www.catmedia.de/
#
# Lizenzbedingungen
#
# ACHTUNG! Diese Scripte sind kein Open Source, keine Freeware, keine
#          Public Domain. Sie unterliegen zu 100% dem Urheberrecht 
#          und unseren Lizenbedingungen.
#
# Diese Scripte duerfen nur zusammen mit einer legalen Version
# von Selfmadeshop verwendet werden. Jede andere Form der 
# Verwendung bedarf der ausdruecklichen Zustimmung von CATMEDIA.
# Unberechtigte Nutzung, Vervielfaeltigung, Verbreitung sowie
# Veraenderung oder Entfernung der Urheberrechtshinweise sind 
# bei Strafe verboten!
#
# Funktionelle Veraenderungen oder der Einbau spezieller Funktionen 
# sind CATMEDIA durch Ueberlassung einer Kopie der angepassten
# Version zu belegen.
#
# Alle Aenderungen gehen in das Eigenntum von CATMEDIA ueber und 
# duerfen von CATMEDIA kuenftig ohne Einschraenkung verwendet werden.
#
#########################################################################
*/



function checkMenge(menge,art){
// Die Funktion checkMenge überprüft eine Eingabe 
// wenn keine Zahl eingegeben wurde, wird 0 zurückgegeben
	var new_menge;
		menge=menge.replace(',','.');

	if (art.dezimalOK) {
		menge=menge.replace(',','.');
		new_menge=parseFloat(menge)
	}	
	else new_menge=parseInt(menge);
	if(isNaN(new_menge)) {
		new_menge=0;
		alert(menge+' ist keine Zahl');
	}
	if (art.flags['e']==true && menge!=1){
		new_menge=false;
		alert(parent.I18N["ALT_EINZELSTUECK"]);
	}
	if (new_menge<eval(art.minmenge)){
		new_menge=false;
		alert(parent.I18N["ART_MBMTXT"]+art.minmenge);
	}
	if (eval(art.gebinde) && (new_menge%eval(art.gebinde))!=0){
		new_menge=false;
		alert(parent.I18N["ART_GEBINDETXT"]+art.gebinde);
	}
	return new_menge;
	
}

function printPreis(p){
// die Funktion printPreis stellt den Preis bzw. Sonderpreis des Artikels in Währungsformat dar.
// verknüpfungen bestehen zur Klasse Zahlen, sowie curr + currFactor
	if (p!=""){
		var z = new Zahlen();
		z.currFactor = parent.vars.currFactor;
		z.curr = parent.vars.curr;
	
		var x=z.PreisWOC(p);
		return ('<nobr>'+(x) +' ' + parent.vars.curr+'</nobr>');
	} else {
		return p;
	}		
}

function checkClientRegion(){
//  vor dem Betreten des Warenkorbs wird geprüft, ob in welcher Region sich 
//  der Nutzer befindet
	if (parent.vars.trade=="") {
		parent.vars.trade=1;
//		window.location.href="clientregion.html";
//		return false;
		return true;
	} else return true;
}

function checkWaKo(){
//	wenn keine Artiel im Warenkorb enthalten sind, wird auf der Seite nowako eine Meldung gebracht.
	if (parent.vars.gWK.ArtAnz()==0) {
		window.location.href="nowako.html";
	}

}

function checkMinBestwert(){
	for (i=0;i<gZOMindestBest.length;i++){
		if (gZOMindestBest[i][0]==parent.vars.clientRegion && gZOMindestBest[i][2]!=false){
			return gZOMindestBest[i][1];
		} 
	}

}

function checkCouponwert(){
	if (parent.vars.ges_coupon!=0) {
		if (parent.vars.gCP[0][2]>parent.vars.ges_warenwert) {
			return parent.I18N["WK_GUTSCHEINNOK"]+printPreis(parent.vars.gCP[0][2]);
		} else return false;
	} else return false;
}

function check_email(addr) {
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,4})\.(\d{1,4})\.(\d{1,4})\.(\d{1,4})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray = addr.match(emailPat);
	
	if (matchArray == null) return false;
	var user = matchArray[1];
	var domain = matchArray[2];

	if (user.match(userPat) == null) return false;
	var IPArray = domain.match(ipDomainPat);
	if (IPArray != null) {
		for (var i=1;i<=5;i++) if ((IPArray[i] > 255) || (IPArray[i] < 0)) return false;
		return true;
	}

	var domainArray = domain.match(domainPat);
	if (domainArray == null) return false;
	var atomPat = new RegExp(atom,"g");
	var domArr = domain.match(atomPat);
	var len = domArr.length;

	if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>4) return false;
	if (len<2) return false;
	return true;
}

function bond(a,b,c){
	var ret="";
  if (a!="") ret = (a + c + b + '');
  else ret = b + '';
  return ret;
}

function bond0(a,b,c){
	var ret="";
  if (a!="" && b!="") ret = (a + c + b + '');
  else ret = '';
  return ret;
}

function in_array(s,a){
	var in_array_ergebnis=false;
	for (var i=0;i<a.length;i++){
		if (typeof(a[i])=='object') {
				if(!in_array_ergebnis) in_array_ergebnis=in_array(s,a[i]);
		}	else {
			if (a[i]==s) {
				in_array_ergebnis=true;
			}
		}

	}
	return in_array_ergebnis;
}

function element_delete(s,a){
	
	var return_array=new Array();
	for (var i=0;i<a.length;i++){
		if (a[i]!=s) return_array[return_array.length]=a[i];
	}
	return return_array;
}

function getZOKosten(gzo_i){
	var x;
	
	if (!parent.vars.ges_warenwert) parent.vars.ges_warenwert=eval(parent.vars.gWK.Sum("ArtGP"));
	
	if (gzo_i<gZO.length){
		x = gZO[gzo_i][3]/100*parent.vars.ges_warenwert; ////Warenwert
		if (gZO[gzo_i][2]>x && eval(gZO[gzo_i][2])!=0) x=gZO[gzo_i][2];
	} else {
		x = gZM[gzo_i-gZO.length][3]/100*parent.vars.ges_warenwert; ////Warenwert
		if (gZM[gzo_i-gZO.length][2]>x && eval(gZM[gzo_i-gZO.length][2])!=0) x=gZM[gzo_i-gZO.length][2];
		
	}
	return x;
}

function getZOMwST(gzo_i){
	var x;

	if (gzo_i<gZO.length){
		x = gZO[gzo_i][4];
	} else x = 0;
		return x;
	
}

function changePaySystem(){
	parent.vars.PaySystem=gZM[document.forms['order_finish'].elements['PaySystem'].value];
}

function changeConfirmPayData(){
	parent.vars.gZMPayData[0]=document.forms['order_finish'].elements['vorname'].value;
	parent.vars.gZMPayData[1]=document.forms['order_finish'].elements['nachname'].value;
	parent.vars.gZMPayData[2]=document.forms['order_finish'].elements['email'].value;
	changePaySystem();
}

function stringreplace(str,findText,replaceText){
	var pos=0;
	var pos2=str.indexOf(findText);
	while (pos2!=-1){
		pos2=str.indexOf(findText);
		str=str.substr(0,pos2)+replaceText+str.substr(pos2+findText.length,str.length);
		pos=pos2+1;
	}
	return str;
}

function checkPlz(plz){
	 if (plz!=parseInt(plz) && parseInt(plz)!=parseInt('0'+plz)) {
	 	alert ('Die PLZ ' + plz + ' ist ungültig');
		return "";
	} else if (plz.length < 4 || plz.length > 6) {
		alert ('Die PLZ ' + plz + ' ist ungültig');
		return "";
	} else {
		return plz;
	}
}

function checkInteger(zahl){
	var compare=stringreplace(zahl,' ','');
	if (compare!=parseInt(compare)) {
	 	alert ('Die eingegebene Zahl ist ungültig');
		return "";
	} else {
		return zahl;
	}
}

function checkEmail(str){
	if (check_email(str)==false) {
		alert('Die E-Mail Adresse ' + str + ' ist ungültig')
		return "";
	} else {
		return str;
	}
}

function setValue(fo,el,check){
	if (check=='plz') {
		parent.vars[el] = checkPlz(document.forms[fo].elements[el].value);
		document.forms[fo].elements[el].value=parent.vars[el];
	}	else if (check=='email') {
		parent.vars[el] = checkEmail(document.forms[fo].elements[el].value);
		document.forms[fo].elements[el].value=parent.vars[el];
	}	else if (check=='integer') {
		parent.vars[el] = checkInteger(document.forms[fo].elements[el].value);
		document.forms[fo].elements[el].value=parent.vars[el];
	}	else {
		parent.vars[el] = document.forms[fo].elements[el].value;
		document.forms[fo].elements[el].value=parent.vars[el];
	}
}


function cleardata() {
	if (document.forms['order_finish'].sKNummer) {
		document.forms['order_finish'].sKNummer.value = '';
		parent.vars.sKNummer='';
	}
	if (document.forms['order_finish'].sKFirma) {
		document.forms['order_finish'].sKFirma.value = '';
		parent.vars.sKFirma='';
	}
	if (document.forms['order_finish'].sKName) { 
		document.forms['order_finish'].sKName.value = '';
		parent.vars.sKName='';
	}
	if (document.forms['order_finish'].sKStrasse)  {
		document.forms['order_finish'].sKStrasse.value = '';
		parent.vars.sKStrasse='';
	}
	if (document.forms['order_finish'].sKPlz) { 
		document.forms['order_finish'].sKPlz.value = '';
		parent.vars.sKPlz='';
	}
	if (document.forms['order_finish'].sKOrt) { 
		document.forms['order_finish'].sKOrt.value = '';
		parent.vars.sKOrt='';
	}
	if (document.forms['order_finish'].sKTelefon) { 
		document.forms['order_finish'].sKTelefon.value = '';
		parent.vars.sKTelefon='';
	}
	if (document.forms['order_finish'].sKTelefax) { 
		document.forms['order_finish'].sKTelefax.value = '';
		parent.vars.sKTelefax='';
	}
	if (document.forms['order_finish'].sKMail) { 
		document.forms['order_finish'].sKMail.value = '';
		parent.vars.sKMail='';
	}
	if (document.forms['order_finish'].sKLand) { 
		document.forms['order_finish'].sKLand.value = '';
		parent.vars.sKLand='';
	}
	if (document.forms['order_finish'].sKUStID) { 
		document.forms['order_finish'].sKUStID.value = '';
			parent.vars.sKUStID='';
	}
	if (document.forms['order_finish'].sLKFirma) { 
		document.forms['order_finish'].sLKFirma.value = '';
		parent.vars.sLKFirma='';
	}
	if (document.forms['order_finish'].sLKName) { 
		document.forms['order_finish'].sLKName.value = '';
		parent.vars.sLKName='';
	}
	if (document.forms['order_finish'].sLKStrasse) { 
		document.forms['order_finish'].sLKStrasse.value = '';
		parent.vars.sLKStrasse='';
	}
	if (document.forms['order_finish'].sLKPlz) { 
		document.forms['order_finish'].sLKPlz.value = '';
		parent.vars.sLKPlz='';
	}
	if (document.forms['order_finish'].sLKOrt) { 
		document.forms['order_finish'].sLKOrt.value = '';
		parent.vars.sLKOrt='';
	}
	if (document.forms['order_finish'].sLKTelefon) { 
		document.forms['order_finish'].sLKTelefon.value = '';
		parent.vars.sLKTelefon='';
	}
	if (document.forms['order_finish'].sLKTelefax) { 
		document.forms['order_finish'].sLKTelefax.value = '';
		parent.vars.sLKTelefax='';
	}
	if (document.forms['order_finish'].sLKMail) { 
		document.forms['order_finish'].sLKMail.value = '';
		parent.vars.sLKMail='';
	}
	if (document.forms['order_finish'].sLKLand) { 
		document.forms['order_finish'].sLKLand.value = '';
		parent.vars.sLKLand='';
	}
	if (document.forms['order_finish'].sKKin) { 	
		document.forms['order_finish'].sKKin.value = '';
		parent.vars.sKKin='';
	}
	if (document.forms['order_finish'].sKKnu) { 
		document.forms['order_finish'].sKKnu.value = '';
		parent.vars.sKKnu='';
	}
	if (document.forms['order_finish'].sKKad) { 
		document.forms['order_finish'].sKKad.value = '';
		parent.vars.sKKad='';
	}
	if (document.forms['order_finish'].sKKch) { 
		document.forms['order_finish'].sKKch.value = '';
		parent.vars.sKKch='';
	}
	if (document.forms['order_finish'].sKBank) { 
		document.forms['order_finish'].sKBank.value = '';
		parent.vars.sKBank='';
	}
	if (document.forms['order_finish'].sKKonto) { 
		document.forms['order_finish'].sKKonto.value = '';
		parent.vars.sKKonto='';
	}
	if (document.forms['order_finish'].sKInhaber) { 
		document.forms['order_finish'].sKInhaber.value = '';
		parent.vars.sKInhaber='';
	}
	if (document.forms['order_finish'].sKBlz) { 
		document.forms['order_finish'].sKBlz.value = '';
		parent.vars.sKBlz='';
	}
	if (document.forms['order_finish'].sKBic) { 
		document.forms['order_finish'].sKBic.value = '';
		parent.vars.sKBic='';
	}
	if (document.forms['order_finish'].sKIban) { 
		document.forms['order_finish'].sKIban.value = '';
		parent.vars.sKIban='';
	}
	if (document.forms['order_finish'].sMitteilung) {
		document.forms['order_finish'].sMitteilung.value = '';
		parent.vars.sMitteilung='';
	}
	return true;
}

function check_target(){
	var meldung="";
	
	if (document.forms['order_finish'].cStammkunde.checked) {
		if (!parent.vars.sKNummer) {
			if (document.forms['order_finish'] && document.forms['order_finish'].sKNummer.value!="") parent.vars.sKNummer=document.forms['order_finish'].sKNummer.value
			else meldung=bond(meldung," Ihre Kundennummer",",");
		}
		if (!parent.vars.sKMail) {
			if (document.forms['order_finish'] && document.forms['order_finish'].sKMail.value!="") parent.vars.sKMail=document.forms['order_finish'].sKMail.value
			else meldung=bond(meldung," Ihre Emailadresse",",");
		}
	}
	else {
		if (!parent.vars.sKName) {
			if (document.forms['order_finish'] && document.forms['order_finish'].sKName.value!="") parent.vars.sKName=document.forms['order_finish'].sKName.value
			else meldung=bond(meldung," Ihren Namen",",");
		}
		if (!parent.vars.sKStrasse) {
			if (document.forms['order_finish'] && document.forms['order_finish'].sKStrasse.value!="") parent.vars.sKStrasse=document.forms['order_finish'].sKStrasse.value
			else meldung=bond(meldung," Ihre Straße",",");
		}
		if (!parent.vars.sKPlz) {
			if (document.forms['order_finish'] && document.forms['order_finish'].sKPlz.value!="") parent.vars.sKPlz=document.forms['order_finish'].sKPlz.value
			else meldung=bond(meldung," Ihre PLZ",",");
		}
		if (!parent.vars.sKOrt) {
			if (document.forms['order_finish'] && document.forms['order_finish'].sKOrt.value!="") parent.vars.sKOrt=document.forms['order_finish'].sKOrt.value
			else meldung=bond(meldung," Ihren Ort",",");
		}
		if (!parent.vars.sKMail) {
			if (document.forms['order_finish'] && document.forms['order_finish'].sKMail.value!="") parent.vars.sKMail=document.forms['order_finish'].sKMail.value
			else meldung=bond(meldung," Ihre Emailadresse",",");
		}
	}
	
	if (parent.vars.clientZahloptionString=="Lastschrift"){
		if (!parent.vars.sKBank) {
			if (document.forms['order_finish'] && document.forms['order_finish'].sKBank.value!="") parent.vars.sKBank=document.forms['order_finish'].sKBank.value
			else meldung=bond(meldung," Ihr Kreditinstitut",",");
		}
		if (!parent.vars.sKInhaber) {
			if (document.forms['order_finish'] && document.forms['order_finish'].sKInhaber.value!="") parent.vars.sKInhaber=document.forms['order_finish'].sKInhaber.value
			else meldung=bond(meldung," den Kontoinhaber",",");
		}
		if (!parent.vars.sKBlz) {
			if (document.forms['order_finish'] && document.forms['order_finish'].sKBlz.value!="") parent.vars.sKBlz=document.forms['order_finish'].sKBlz.value
			else meldung=bond(meldung," die Bankleitzahl",",");
		}
		if (!parent.vars.sKKonto) {
			if (document.forms['order_finish'] && document.forms['order_finish'].sKKonto.value!="") parent.vars.sKKonto=document.forms['order_finish'].sKKonto.value
			else meldung=bond(meldung," die Kontonummer",",");
		}
	}

	if (parent.vars.clientZahloptionString=="Kreditkarte" || parent.vars.clientZahloptionString=="Kreditkarte (ungesichert)"){
		if (!parent.vars.sKBank) {
			if (document.forms['order_finish'] && document.forms['order_finish'].sKBank.value!="") parent.vars.sKBank=document.forms['order_finish'].sKBank.value
			else meldung=bond(meldung," Ihr Kreditinstitut",",");
		}
		if (!parent.vars.sKInhaber) {
			if (document.forms['order_finish'] && document.forms['order_finish'].sKInhaber.value!="") parent.vars.sKInhaber=document.forms['order_finish'].sKInhaber.value
			else meldung=bond(meldung," den Kontoinhaber",",");
		}
		if (!parent.vars.sKKredMonat || !parent.vars.sKKredJahr) {
			if (document.forms['order_finish'] && document.forms['order_finish'].sKKredMonat.value!="" && document.forms['order_finish'].sKKredJahr.value!="") {
				parent.vars.sKKredMonat=document.forms['order_finish'].sKKredMonat.value;
				parent.vars.sKKredJahr=document.forms['order_finish'].sKKredJahr.value;
				parent.vars.sKBlz=document.forms['order_finish'].sKKredMonat.value+'/'+document.forms['order_finish'].sKKredJahr.value;
			}
			else meldung=bond(meldung," die Gültigkeit",",");
		} else {
				parent.vars.sKBlz=document.forms['order_finish'].sKKredMonat.value+'/'+document.forms['order_finish'].sKKredJahr.value;
		}
		if (!parent.vars.sKBic) {
			if (document.forms['order_finish'] && document.forms['order_finish'].sKBic.value!="") parent.vars.sKBic=document.forms['order_finish'].sKBic.value
			else meldung=bond(meldung," die Prüfziffer",",");
		}

		if (!parent.vars.sKKonto) {
			if (document.forms['order_finish'] && document.forms['order_finish'].sKKonto.value!="") parent.vars.sKKonto=document.forms['order_finish'].sKKonto.value
			else meldung=bond(meldung," die Kreditkartennummer",",");
		}
	}
 
 	if (meldung=="")	window.location.href="view.html";
	else alert("Bitte geben Sie"+ meldung + " ein")	
//	window.location.href="view.html";
}

function check() {
	var errstr = "", os = "";
		
	if (parent.orderopt != 11) {
		if (document.forms['order_finish'].KName.value == "") { errstr = errstr + "Pflichtangabe Name fehlt.\n"; }
		if (document.forms['order_finish'].KStrasse.value == "") { errstr = errstr + "Pflichtangabe Strasse fehlt.\n"; }
		if (document.forms['order_finish'].KPlz.value == "") { errstr = errstr + "Pflichtangabe PLZ fehlt.\n"; }
		if (document.forms['order_finish'].KOrt.value == "") { errstr = errstr + "Pflichtangabe Ort fehlt.\n"; }
		if (document.forms['order_finish'].KTelefon.value == "") { errstr = errstr + "Pflichtangabe Telefon fehlt.\n"; }
		if (document.forms['order_finish'].KMail.value == "") { errstr = errstr + "Pflichtangabe E-Mail fehlt.\n"; }
		if (!check_email(document.forms['order_finish'].KMail.value)) { errstr = errstr + "E-Mail Adresse ist ungültig.\n"; }
		if ((parent.country == SH_FOREIGN) && (document.forms['order_finish'].KLand.value == "")) { errstr = errstr + "Pflichtangabe Land fehlt.\n"; }
		if (errstr != "") document.forms['order_finish'].KName.focus();
		
		if (document.forms['order_finish'].kkin) {
				os = errstr;
			if (document.forms['order_finish'].kkin.value == "") { errstr = errstr + "Pflichtangabe Karteninstitut fehlt.\n"; }
			if (document.forms['order_finish'].kknu.value == "") { errstr = errstr + "Pflichtangabe Kartennummer fehlt.\n"; }
			if (document.forms['order_finish'].kkad.value == "") { errstr = errstr + "Pflichtangabe Ablaufdatum fehlt.\n"; }
			if (document.forms['order_finish'].kkch.value == "") { errstr = errstr + "Pflichtangabe Prüfnummer fehlt.\n"; }
			if (errstr != os) document.forms['order_finish'].kkin.focus();
		}
		
		if (document.forms['order_finish'].bank) {
			os = errstr;
			if (document.forms['order_finish'].bank.value == "") { errstr = errstr + "Pflichtangabe Bank fehlt.\n"; }
			if (document.forms['order_finish'].kontoh.value == "") { errstr = errstr + "Pflichtangabe Kontoinhaber fehlt.\n"; }
			if (document.forms['order_finish'].konto.value == "") { errstr = errstr + "Pflichtangabe Kontonummer fehlt.\n"; }
//			if (document.forms['order_finish'].blz.value == "") { errstr = errstr + "Pflichtangabe Bankleitzahl fehlt.\n"; }
			if (errstr != os) document.forms['order_finish'].bank.focus();
		}
	}
		
	if (errstr != "") { alert(errstr); return false; } else return true;
}

function changeClientRegion(){
	parent.vars.clientRegion=document.order.Region.value;
	
	parent.vars.gZahlPreis=0
	parent.vars.ZahlOpt=""
	parent.vars.VersArt=""
	parent.vars.gVersandPreis=0
	parent.vars.gVersicherungPreis=0;
	if (document.order && document.order.VersCheck && document.order.VersCheck.checked) parent.vars.Versicherung=document.order.VersCheck.value 
	else parent.vars.Versicherung=false;
	
	parent.main.location.reload();
}

//Versandart
function changeVersArt(){
	parent.vars.VersArt=document.order.VersArt.value;
	if (parent.vars.gGesamtPreis < parent.vars.gVKfrei) {
		for (var i_ge=0;i_ge<gVA.length;i_ge++)
			if (document.order.VersArt.value==gVA[i_ge][0]) parent.vars.gVersandPreis=gVA[i_ge][4];
	} else parent.vars.gVersandPreis=0;
		parent.main.location.reload();
}

function changeVersicherung(val,mwst){
	
	if (document.order.VersCheck.checked) {
		parent.vars.Versicherung=document.order.VersCheck.value 
		parent.vars.gVersicherungPreis=val+'';
		parent.vars.gVersicherung_mwst=mwst+'';
	} else {
		parent.vars.Versicherung=false;
		parent.vars.gVersicherungPreis=0;
		parent.vars.gVersicherung_mwst=0;
	}
	parent.main.location.reload();
}

function changeZahlOpt(){
	parent.vars.ZahlOpt=document.order.ZahlOpt.value;
	parent.vars.gZahlPreis=getZOKosten(document.order.ZahlOpt.value);
	parent.vars.gZahl_mwst=getZOMwST(document.order.ZahlOpt.value);

	if (parent.vars.ZahlOpt && gZO[parent.vars.ZahlOpt]){
		if (gZO[parent.vars.ZahlOpt][1]=='Überweisung' || gZO[parent.vars.ZahlOpt][1]=='Vorauskasse') parent.vars.BankData=parent.vars.ShopData2
		else parent.vars.BankData="";
		parent.vars.ShopData=parent.vars.ShopData1;
	}
	
	parent.main.location.reload();
}

function checkCoupon(ref,val){
	var aTmp=new Array();
	var ref_check=parent.I18N["COU_ERROR"];

	for (var i=0;i<gCoupon.length;i++){
		aTmp=gCoupon[i][6];
		if (typeof(aTmp)=="object"){
			for (var j=0;j<aTmp.length;j++){
				if (aTmp[j]==ref) {
					if (parseFloat(gCoupon[i][2])==parseFloat(strreplace(val,',','.'))) {
						ref_check=getCoupon(i,ref);
					}
				} 
			}
		}
	}
	if (ref_check==1) parent.main.location.reload();
	else alert(ref_check);
}

function getCoupon(i,ref){
	var ret=1;
	var cpPreis=(0-gCoupon[i][2]);
	var minWert=gCoupon[i][5];
	for (j=0;j<parent.vars.gCP.length;j++){
		if (parent.vars.gCP[j][1]==ref) ret=parent.I18N["COU_DOUBLE"];
	}

	if (gCoupon[i][5]>parent.vars.gGesamtPreis) ret=parent.I18N["WK_GUTSCHEINNOK"]+' '+printPreis(gCoupon[i][5]);
	if (timestamp(gCoupon[i][3])>timestamp(parent.vars.gToday) || timestamp(gCoupon[i][4])<timestamp(parent.vars.gToday)) ret=I18N["COU_FALSE"];
	if (ret==1){

		parent.vars.gCP.push(new Array(cpPreis,ref,minWert));
		parent.vars.ges_coupon=parent.vars.ges_coupon+cpPreis
		parent.vars.Gutschein=ref;
		parent.vars.GutscheinWert=cpPreis;
	} 
	return ret;
}		

function timestamp(xs){
	var na=xs.split('.');
	var return_c = Date.UTC(na[2],na[1],na[0])	
	return return_c
}
function printdate(d){
	var return_d="";
	if (d){
		var dat=d.split('/');
		return_d=dat[2]+'.'+dat[1]+'.'+dat[0];
	}
	return return_d;
}


function set_vars2(){
// windowname wird gesetzt um an ssl übergeben zu werden
	
	var windowname="";
	windowname=windowname+'|='+parent.vars.gStandardCurr; //EUR
	windowname=windowname+'|='+parent.vars.currFactor;
	windowname=windowname+'|='+parent.vars.curr;

	windowname=windowname+'|='+parent.vars.gVersandPreis; //Zusatzkosten für Versand
	windowname=windowname+'|='+parent.vars.ges_versand; //Summe der Versandkosten für Artikel
	windowname=windowname+'|='+parent.vars.gZahlPreis; //Zusatzkosten für Paysysteme 
	windowname=windowname+'|='+array2submit(parent.vars.gMwSt,'mwst'); //Array über Mehrwertsteuersätze und Beträge
	windowname=windowname+'|='+parent.vars.gGesamtPreis; //Zahlbetrag (Brutto)

	windowname=windowname+'|='+parent.vars.ges_warenwert; //reiner Warenwert
	windowname=windowname+'|='+parent.vars.ges_mwst1; //reine summe der Mwst
	windowname=windowname+'|='+parent.vars.ges_mwst; //reine summe der Mwst
	windowname=windowname+'|='+parent.vars.ges_coupon; //reiner Gutscheinwert
	

	windowname=windowname+'|='+parent.vars.gShopkind; //brutto oder nettoshop
	windowname=windowname+'|='+parent.vars.auslbruttoNetto //verfahren mit Auslandspreisen

	windowname=windowname+'|='+parent.vars.VersArt; //id der Versandart

	var isinwindow=false;
	for (i_ge=0;i_ge<gVA.length;i_ge++){
		if (parent.vars.VersArt==gVA[i_ge][0]){
			windowname=windowname+'|='+(parent.vars.VersArt?gVA[i_ge][1]+' '+gVA[i_ge][2]:''); //Bezeichnung der Versandart
			isinwindow=true
		}
	}
	if (isinwindow==false) windowname=windowname+'|=';	

	windowname=windowname+'|='+parent.vars.ZahlOpt; // id der Zahloption
	windowname=windowname+'|='+parent.vars.clientZahloptionString; //Zahloption

	windowname=windowname+'|='+parent.vars.clientRegion; //Herkunft des Kunden
	windowname=windowname+'|='+parent.vars.trade;

	windowname=windowname+'|='+parent.vars.gDelimDec;
	windowname=windowname+'|='+parent.vars.gDelimTh;
	windowname=windowname+'|='+parent.vars.rooturl;
	
	windowname=windowname+'|='+parent.vars.sslurl;

	windowname=windowname+'|='+parent.vars.showAGB;
	windowname=windowname+'|='+parent.vars.showFAG1;
	windowname=windowname+'|='+parent.vars.showFAG2;

	windowname=windowname+'|='+parent.vars.gWK.submitstring();

	windowname=windowname+'|='+parent.vars.to_email;
	windowname=windowname+'|='+parent.vars.from_email_name;
	windowname=windowname+'|='+parent.vars.from_email_address;

	windowname=windowname+'|='+parent.vars.Gutschein;
	windowname=windowname+'|='+parent.vars.GutscheinWert;

	windowname=windowname+'|='+parent.vars.ShopID;
	windowname=windowname+'|='+parent.vars.ShopID2;
	windowname=windowname+'|='+parent.vars.ShopID3;
	windowname=windowname+'|='+parent.vars.ShopID4;
	windowname=windowname+'|='+parent.vars.ShopID5;
	windowname=windowname+'|='+parent.vars.ShopID6;

	windowname=windowname+'|='+parent.vars.payscript;

//pers. daten

	windowname=windowname+'|='+parent.vars.sKNummer;
	windowname=windowname+'|='+parent.vars.sKFirma;
	windowname=windowname+'|='+parent.vars.sKName;
	windowname=windowname+'|='+parent.vars.sKStrasse;
	windowname=windowname+'|='+parent.vars.sKPlz;
	windowname=windowname+'|='+parent.vars.sKOrt;
	windowname=windowname+'|='+parent.vars.sKTelefon;
	windowname=windowname+'|='+parent.vars.sKTelefax;
	windowname=windowname+'|='+parent.vars.sKMail;
	windowname=windowname+'|='+parent.vars.sKLand;
	windowname=windowname+'|='+parent.vars.sKUStID;

	windowname=windowname+'|='+parent.vars.sKBank;
	windowname=windowname+'|='+parent.vars.sKInhaber;
	windowname=windowname+'|='+parent.vars.sKBlz;
	windowname=windowname+'|='+parent.vars.sKKonto;
	windowname=windowname+'|='+parent.vars.sKBic;
	windowname=windowname+'|='+parent.vars.sKIban;

	windowname=windowname+'|='+parent.vars.sLKFirma;
	windowname=windowname+'|='+parent.vars.sLKName;
	windowname=windowname+'|='+parent.vars.sLKStrasse;
	windowname=windowname+'|='+parent.vars.sLKPlz;
	windowname=windowname+'|='+parent.vars.sLKOrt;
	windowname=windowname+'|='+parent.vars.sLKTelefon;
	windowname=windowname+'|='+parent.vars.sLKTelefax;
	windowname=windowname+'|='+parent.vars.sLKMail;
	windowname=windowname+'|='+parent.vars.sLKLand;

	windowname=windowname+'|='+parent.vars.sMitteilung;

	windowname=windowname+'|='+parent.vars.Versicherung;
	windowname=windowname+'|='+parent.vars.gVersicherungPreis;
	windowname=windowname+'|='+parent.vars.gVersicherung_mwst;

	windowname=windowname+'|='+parent.vars.TextOrderAGB;
	windowname=windowname+'|='+parent.vars.TextOrderWiderruf;
	windowname=windowname+'|='+parent.vars.TextOrderFreiw;

	windowname=windowname+'|='+parent.vars.design_bgcolor;
	windowname=windowname+'|='+parent.vars.design_table_spacing;
	windowname=windowname+'|='+parent.vars.design_table_even_lines;
	windowname=windowname+'|='+parent.vars.design_table_odd_line;
	windowname=windowname+'|='+parent.vars.design_table_odd_lines;
	windowname=windowname+'|='+parent.vars.design_table_odd_lines_width;
	windowname=windowname+'|='+parent.vars.design_font;
	windowname=windowname+'|='+parent.vars.ShopData;
	windowname=windowname+'|='+parent.vars.BankData;
	windowname=windowname+'|='+parent.vars.ShopURL;
	windowname=windowname+'|='+parent.vars.CgiMimetype;

	windowname=windowname+'|='+parent.vars.MwStKind;
	windowname=windowname+'|='+parent.vars.gStandardCurrFactor;

	parent.vars.windowname=windowname;
	top.name=windowname;
}

function take_vars2(windowname){
	// stellt parent.vars-Variablen wieder her aus dem window.name (wird in der target.html) aufgerufen
	var x=windowname.split('|=');
	var i=1;
	parent.vars.gStandardCurr=x[i++]; //EUR
	parent.vars.currFactor=x[i++];
	parent.vars.curr=x[i++];
	parent.vars.gVersandPreis=x[i++]; //Zusatzkosten für Versand
	parent.vars.ges_versand=x[i++];//Summe der Versandkosten für Artikel
	parent.vars.gZahlPreis=x[i++];//Zusatzkosten für Paysysteme 
//	parent.vars.gVKfrei=x[i++]; //Versandkostenbefreiung
	parent.vars.gMwSt=submit2array(x[i++],'mwst');//Array über Mehrwertsteuersätze und Beträge
	parent.vars.gGesamtPreis=x[i++];//Zahlbetrag (Brutto)

	parent.vars.ges_warenwert=x[i++]; //reiner Warenwert
	parent.vars.ges_mwst1=x[i++]; //reine summe der Mwst
	parent.vars.ges_mwst=x[i++]; //reine summe der Mwst
	parent.vars.ges_coupon=x[i++];//reiner Gutscheinwert
	
	parent.vars.gShopkind=x[i++];//brutto oder nettoshop
	parent.vars.auslbruttoNetto=x[i++];//verfahren mit Auslandspreisen

//	parent.vars.gVA=x[i++];//Array über alle Versandarten (Brief, Päckchen)
	parent.vars.VersArt=x[i++]; //id der Versandart
	parent.vars.VersArtString=x[i++]; //id der Versandart
	
//	parent.vars.gZO=x[i++]; // Array der Zahloptionen Nachname Kreditkarte, etc
//	parent.vars.gZM=x[i++]; // Array der Paysysteme
	
	parent.vars.ZahlOpt=x[i++];	// id der Zahloption
	parent.vars.clientZahloptionString=x[i++]; //Zahloption
	
//	parent.vars.PaySystem=x[i++];
//	parent.vars.gTradeArray=x[i++];//1.Privatkunde 2. Geschäftkunde

	parent.vars.clientRegion=x[i++];//Herkunft des Kunden
	parent.vars.trade=x[i++];

	parent.vars.gDelimDec=x[i++];
	parent.vars.gDelimTh=x[i++];
	parent.vars.rooturl=x[i++];
	parent.vars.sslurl=x[i++];

	parent.vars.showAGB=x[i++];
	parent.vars.showFAG1=x[i++];
	parent.vars.showFAG2=x[i++];

	setTimeout('insertsubmitstring("'+escape(x[i++])+'")',1000); 		
//	insertsubmitstring(x[i++]);
	
	parent.vars.to_email=x[i++];
	parent.vars.from_email_name=x[i++];
	parent.vars.from_email_address=x[i++];

	parent.vars.Gutschein=x[i++];
	parent.vars.GutscheinWert=x[i++];
	
	parent.vars.ShopID=x[i++];
	parent.vars.ShopID2=x[i++];
	parent.vars.ShopID3=x[i++];
	parent.vars.ShopID4=x[i++];
	parent.vars.ShopID5=x[i++];
	parent.vars.ShopID6=x[i++];

	parent.vars.payscript=x[i++];
	
	//pers. daten
	
	parent.vars.sKNummer=x[i++];
	parent.vars.sKFirma=x[i++];
	parent.vars.sKName=x[i++];
	parent.vars.sKStrasse=x[i++];
	parent.vars.sKPlz=x[i++];
	parent.vars.sKOrt=x[i++];
	parent.vars.sKTelefon=x[i++];
	parent.vars.sKTelefax=x[i++];
	parent.vars.sKMail=x[i++];
	parent.vars.sKLand=x[i++];
	parent.vars.sKUStID=x[i++];

	parent.vars.sKBank=x[i++];
	parent.vars.sKInhaber=x[i++];
	parent.vars.sKBlz=x[i++];
	parent.vars.sKKonto=x[i++];
	parent.vars.sKBic=x[i++];
	parent.vars.sKIban=x[i++];

	parent.vars.sLKFirma=x[i++];
	parent.vars.sLKName=x[i++];
	parent.vars.sLKStrasse=x[i++];
	parent.vars.sLKPlz=x[i++];
	parent.vars.sLKOrt=x[i++];
	parent.vars.sLKTelefon=x[i++];
	parent.vars.sLKTelefax=x[i++];
	parent.vars.sLKMail=x[i++];
	parent.vars.sLKLand=x[i++];

	parent.vars.sMitteilung=x[i++];

	parent.vars.Versicherung=x[i++];
	parent.vars.gVersicherungPreis=x[i++];
	parent.vars.gVersicherung_mwst=x[i++];

	parent.vars.TextOrderAGB=x[i++];
	parent.vars.TextOrderWiderruf=x[i++];
	parent.vars.TextOrderFreiw=x[i++];
	
	parent.vars.design_bgcolor=x[i++];
	parent.vars.design_table_spacing=x[i++];
	parent.vars.design_table_even_lines=x[i++];
	parent.vars.design_table_odd_line=x[i++];
	parent.vars.design_table_odd_lines=x[i++];
	parent.vars.design_table_odd_lines_width=x[i++];
	parent.vars.design_font=x[i++];
	parent.vars.ShopData=x[i++];
	parent.vars.BankData=x[i++];
	parent.vars.ShopURL=x[i++];
	parent.vars.CgiMimetype=x[i++];

	parent.vars.MwStKind=x[i++];
	parent.vars.gStandardCurrFactor=x[i++];
}
function array2submit(arr,typ){
	var ret="";
	if (typ=='mwst') {
		for (var i=0;i<arr.length;i++){
			ret='|%='+arr[i][0]+'|%='+arr[i][1]+'|%!';
		}
	}
	return ret;
}
function submit2array(str,typ){
	var ret=new Array();
	if (typ=='mwst'){
		var x=str.split('|%!');
		if (typeof(x)=="object"){
			for (var i=0;i<x.length-1;i++){
				y=x[i].split('|%=');
				ret.push(new Array (y[1],y[2]));
			}		
		}
	}
return ret;
}

function insertsubmitstring(submitstring){
	submitstring=unescape(submitstring);
	
	var x=submitstring.split('|%!')
	var val="";
	//parent.vars.gWK.Clear();
	parent.vars.gWK=new parent.cWK();	
	for (var i_wk=0;i_wk<x.length-1;i_wk++){
		val_i=1;
		val=x[i_wk].split('|%=');

		parent.vars.gWK.db.fAddRow(new Array(val[val_i++],val[val_i++],val[val_i++],val[val_i++],val[val_i++],val[val_i++],val[val_i++],val[val_i++],val[val_i++],val[val_i++],val[val_i++],val[val_i++],val[val_i++],val[val_i++],val[val_i++],val[val_i++],val[val_i++],val[val_i++],val[val_i++],val[val_i++],val[val_i++],val[val_i++],val[val_i++],val[val_i++],val[val_i++],val[val_i++],val[val_i++]));
	}
}

	function check_agb(go_ssl){
		var es="";

		if(!parent.vars.showAGB)  es = es + 'Bitte bestätigen Sie, dass Sie die AGB gelesen haben.\n';
		if(!parent.vars.showFAG1) es = es + 'Bitte bestätigen Sie, dass Sie die Widerrufsbelehrung gelesen haben.\n';

		if (es == "") {

			if (parent.vars.ZahlOpt>=gZO.length) {

				parent.vars.ShopID=gZM[parent.vars.ZahlOpt-gZO.length][4]
				parent.vars.ShopID2=gZM[parent.vars.ZahlOpt-gZO.length][5]
				parent.vars.ShopID3=gZM[parent.vars.ZahlOpt-gZO.length][6]
				parent.vars.ShopID4=gZM[parent.vars.ZahlOpt-gZO.length][7]
				parent.vars.ShopID5=gZM[parent.vars.ZahlOpt-gZO.length][8]
				parent.vars.ShopID6=gZM[parent.vars.ZahlOpt-gZO.length][9]
			}


			if (parent.vars.sslurl!="" && go_ssl=="1") {
				set_vars2();
				var ssl=window.open(parent.vars.sslurl+'ssl.html','ssl_new','status=yes,scrollbars=auto,resizable=yes');
				ssl.name='ssl'+parent.vars.windowname;

			} else  {
				set_vars2();
				top.name='index'+parent.vars.windowname;
				window.location.href='target.html';
			}
		} else  alert(es);
	}

function waren2y_mwst(){
	for(var k=0; k < parent.vars.gWK.Anz(); k++){
		y=eval(parent.vars.gWK.db.fGetValByRowCol(k,'ArtMwSt'));
		if (in_array(y,y_mwst)){
			//netto-shop
			if (parent.vars.gShopkind=="n") p_mwst[y]=p_mwst[y]+eval(parent.vars.gWK.db.fGetValByRowCol(k,'ArtGP')*(y/100));
			//brutto-shop
			else p_mwst[y]=p_mwst[y]+eval(parent.vars.gWK.db.fGetValByRowCol(k,'ArtGP')*(1-1/(1+y/100)));
		} else {
			//netto-shop
			if (parent.vars.gShopkind=="n") p_mwst[y]=eval(parent.vars.gWK.db.fGetValByRowCol(k,'ArtGP')*(y/100));
			//brutto-shop
			else p_mwst[y]=eval(parent.vars.gWK.db.fGetValByRowCol(k,'ArtGP')*(1-1/(1+y/100)));
			y_mwst.push(y);
		}
	}
}

function warenversand2y_mwst(){
	for(var k=0; k < parent.vars.gWK.Anz(); k++){
		y=eval(parent.vars.gWK.db.fGetValByRowCol(k,'ArtMwSt'));
		if (in_array(y,y_mwst)){
			//netto-shop
			if (parent.vars.gShopkind=="n") p_mwst[y]=p_mwst[y]+eval(parent.vars.gWK.db.fGetValByRowCol(k,'VersPreis')*(y/100));
			//brutto-shop
			else p_mwst[y]=p_mwst[y]+eval(parent.vars.gWK.db.fGetValByRowCol(k,'VersPreis')*(1-1/(1+y/100)));
		} else {
			//netto-shop
			if (parent.vars.gShopkind=="n") p_mwst[y]=eval(parent.vars.gWK.db.fGetValByRowCol(k,'VersPreis')*(y/100));
			//brutto-shop
			else p_mwst[y]=eval(parent.vars.gWK.db.fGetValByRowCol(k,'VersPreis')*(1-1/(1+y/100)));
			y_mwst.push(y);
		}
	}
}

function versand2y_mwst(){
	var y=eval(parent.vars.gVersand_mwst);

	if (in_array(y,y_mwst)){
		//netto-shop
		if (parent.vars.gShopkind=="n") p_mwst[y]=p_mwst[y]+eval(parent.vars.gVersandPreis*(y/100));
		//brutto-shop
		else p_mwst[y]=p_mwst[y]+eval(parent.vars.gVersandPreis*(1-1/(1+y/100)));
	} else {
		//netto-shop
		if (parent.vars.gShopkind=="n") p_mwst[y]=eval(parent.vars.gVersandPreis*(y/100));
		//brutto-shop
		else p_mwst[y]=eval(parent.vars.gVersandPreis*(1-1/(1+y/100)));
		y_mwst.push(y);
	}
}

function zahl2y_mwst(){
	var y=eval(parent.vars.gZahl_mwst);
	if (in_array(y,y_mwst)){
		if (parent.vars.gShopkind=="n") p_mwst[y]=p_mwst[y]+eval(parent.vars.gZahlPreis*(y/100));
		//brutto-shop
		else p_mwst[y]=p_mwst[y]+eval(parent.vars.gZahlPreis*(1-1/(1+y/100)));
	} else {
		//netto-shop
		if (parent.vars.gShopkind=="n") p_mwst[y]=eval(parent.vars.gZahlPreis*(y/100));
		//brutto-shop
		else p_mwst[y]=eval(parent.vars.gZahlPreis*(1-1/(1+y/100)));
		y_mwst.push(y);
		
	}
}

function coupon2y_mwst(){
	y=0;
	for (var i=0;i<y_mwst.length;i++){
		if (y_mwst[i]>y) y =y_mwst[i];
	}

	if (in_array(y,y_mwst)){
		//netto-shop
		if (parent.vars.gShopkind=="n") p_mwst[y]=p_mwst[y]+eval(parent.vars.ges_coupon*(y/100));
		//brutto-shop
		else p_mwst[y]=p_mwst[y]+eval(parent.vars.ges_coupon*(1-1/(1+y/100)));
	} else {
		//netto-shop
		if (parent.vars.gShopkind=="n") p_mwst[y]=eval(parent.vars.ges_coupon*(y/100));
		//brutto-shop
		else p_mwst[y]=eval(parent.vars.ges_coupon*(1-1/(1+y/100)));
		y_mwst.push(y);
	}
}

function versicherung2y_mwst(){
	
	if (parent.vars.Versicherung=="true"){
		var y=eval(parent.vars.gVersicherung_mwst);
		if (in_array(y,y_mwst)){
			if (parent.vars.gShopkind=="n") p_mwst[y]=p_mwst[y]+eval(parent.vars.gVersicherungPreis*(y/100));
			//brutto-shop
			else p_mwst[y]=p_mwst[y]+eval(parent.vars.gVersicherungPreis*(1-1/(1+y/100)));
		} else {
			//netto-shop
			if (parent.vars.gShopkind=="n") p_mwst[y]=eval(parent.vars.gVersicherungPreis*(y/100));
			//brutto-shop
			else p_mwst[y]=eval(parent.vars.gVersicherungPreis*(1-1/(1+y/100)));
			y_mwst.push(y);
		}
	}
}

function calcMwst(){
	
	parent.vars.y_mwst=y_mwst;
	parent.vars.p_mwst=p_mwst;
	parent.vars.y_mwst1=y_mwst;
	parent.vars.p_mwst1=p_mwst;

	parent.vars.gMwSt=new Array();
	parent.vars.ges_mwst=0;

	//MwST
	for (var k=0; k < y_mwst.length; k++){
		if (p_mwst[y_mwst[k]]) {
			parent.vars.gMwSt.push(new Array(y_mwst[k],p_mwst[y_mwst[k]]));
			parent.vars.ges_mwst=parent.vars.ges_mwst+p_mwst[y_mwst[k]];
		}
	}
}

function calcWarenMwstSum(){
	var summe=0;
	for(var k=0; k < parent.vars.gWK.Anz(); k++){
		if (parent.vars.gWK.db.fGetValByRowCol(k,'ArtNrBez')){
			y=eval(parent.vars.gWK.db.fGetValByRowCol(k,'ArtMwSt'));
			if (!y) y=0;
			
			//netto-shop
			if (parent.vars.gShopkind=="n") summe=summe+eval(parent.vars.gWK.db.fGetValByRowCol(k,'ArtGP')*(y/100));
			else summe=summe+eval(parent.vars.gWK.db.fGetValByRowCol(k,'ArtGP')*(1-1/(1+y/100)));
		}
	}
	return summe;
}

function checkMwStKind(){
	// Definition der MwStAnzeige und Berechnung
	if (parent.vars.clientRegion=="AU") MwStKind="no";
	else if (parent.vars.clientRegion=="EU" && parent.vars.sKUStID!="") MwStKind="bin";
	else if (parent.vars.gShopkind == "n") MwStKind="det";
	else MwStKind="sum";

	parent.vars.MwStKind=MwStKind;

}

function strreplace(checkMe,toberep,repwith){
	temp = checkMe;
	a = 0;
	
	for(i = 0; i < checkMe.length; i++){
		a = temp.indexOf(toberep);
		if (a>=0)temp = temp.substring(0 , a) + repwith + temp.substring((a + toberep.length));
		
		if (a == -1){
			break;
		}
	}
	return temp;
}

function getBankZahl(){
	return parent.vars.gBank.length;
}

