
function getcookie(cookiename) {
 var cookiestring=""+document.cookie;
 var index1=cookiestring.indexOf(cookiename);
 if (index1==-1 || cookiename=="") return ""; 
 var index2=cookiestring.indexOf(';',index1);
 if (index2==-1) index2=cookiestring.length; 
 return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}

function setWaehrung() {
	// nur, wenn keine Waehrung ausgewaehlt
	waehrung = '';
	if(getElemId('wkBoxForm')) {
		if(!getElemId('wkBoxForm').waehrung[0].checked && !getElemId('wkBoxForm').waehrung[1].checked ) {
			if (document.cookie) {
				waehrung = getcookie("waehrung");
				if(waehrung=="CHF") getElemId('wkBoxForm').waehrung[1].checked=true;
				else				getElemId('wkBoxForm').waehrung[0].checked=true;
			}
		}
		if(getElemId('wkBoxForm').waehrung[0].checked) waehrung = 'EUR';
		if(getElemId('wkBoxForm').waehrung[1].checked) waehrung = 'CHF';
	}
/*
	if(waehrung!='') {
		var t=document.getElementsByTagName('div');
		if(t) {
			for (i=0;i<t.length;i++) {
				divIdName = t[i].id;
				divIdNameArr = divIdName.split('_');
				if(divIdNameArr[0] && divIdNameArr[0]=='div' && divIdNameArr[2]) {
					if(divIdNameArr[2].indexOf('CHF')!=-1 && waehrung=='CHF') void(t[i].style.visibility='visible');
					if(divIdNameArr[2].indexOf('EUR')!=-1 && waehrung=='EUR') void(t[i].style.visibility='visible');
				}
			} 
		} 
	}
*/
}
window.setTimeout("setWaehrung()", 300);

function gotoUrl(pageURL) {
	window.location.href = pageURL;
}
function gotoSelectedUrl(listObj) {
	pageURL = getSelectedOption(listObj);
	gotoUrl(pageURL);
}


function getSelectedOption(listObj) {
	// listObj = eval("document.thisForm.elements[\'" + listObj + "\']");
	 selIndex = listObj.selectedIndex;
	 selValue = listObj.options[selIndex].value;
	 return selValue;
}


function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_showHideLayers() { //v3.0
	var i,p,v,obj,args=MM_showHideLayers.arguments;
	if (document.getElementById){
		for (i=0; i<(args.length-2); i+=3) {
			v=args[i+2];
			v=(v=="show")?"visible":(v="hide")?"hidden":v; 
			if (document.getElementById(args[i])){
				document.getElementById(args[i]).style.visibility = v;
				if(v=="hidden") document.getElementById(args[i]).style.display = "none";
				else			document.getElementById(args[i]).style.display = "block";
			}
		}
	}
	else {
		for (i=0; i<(args.length-2); i+=3) {
			if ((obj=MM_findObj(args[i]))!=null) { 
				v=args[i+2];
    			if (obj.style) { 
					obj=obj.style; 
					v=(v=="show")?"visible":(v="hide")?"hidden":v; 
				}
    			obj.visibility=v; 
				if(v=="hidden") document.getElementById(args[i]).style.display = "none";
				else			document.getElementById(args[i]).style.display = "block";
			}
		}
	}
}

function getElemId(elementid) {
	return document.getElementById(elementid);
}

function suchtextClicked(obj, standardtext) {
	if(obj) {
		if(obj.value==standardtext) obj.value='';
	}
}


// Warenkorb / Bestellung

function showHideLieferadresse(radioButton) {
//	if(!radioButton&&document&&document.thisForm&&document.thisForm.orderFrm_lieferadresseEingabe) radioButton = eval("document.thisForm.orderFrm_lieferadresseEingabe[0]");
//	if(!radioButton&&document&&document.thisForm&&document.thisForm.lieferadresseEingabe) radioButton = eval("document.thisForm.lieferadresseEingabe[0]");

// NEU: PACKSTATION
	radioButtonVal = -1;
	if(!radioButton) {
		if(document&&document.thisForm&&document.thisForm.lieferadresseEingabe) radioButton = eval("document.thisForm.lieferadresseEingabe");
		if(document&&document.thisForm&&document.thisForm.orderFrm_lieferadresseEingabe) radioButton = eval("document.thisForm.orderFrm_lieferadresseEingabe");
		if(radioButton)  {
			for(radioButtonX=0; radioButtonX<radioButton.length; radioButtonX++) {
				if(radioButton[radioButtonX].checked) radioButtonVal = radioButton[radioButtonX].value;
			}
		}
	}
	else {
		radioButtonVal = radioButton.value;
	}
	if(radioButtonVal!=-1) {
		MM_showHideLayers('lieferadresseAbschnitt','','hide');
		MM_showHideLayers('packstationAbschnitt','','hide');
		if(radioButtonVal=='0')		;
		else if(radioButtonVal=='1')	MM_showHideLayers('lieferadresseAbschnitt','','show');
		else if(radioButtonVal=='2')	MM_showHideLayers('packstationAbschnitt','','show');
	}
	 
}

function landAuwahl(obj) {
	if(document.thisForm.Lland) {
		document.thisForm.Lland.enabled = true;
		document.thisForm.Lland.value = getSelectedOption(obj);
		document.thisForm.Lland.disabled = true;
	}
}

function checkWaehrung(obj) {
	changeWaehrung = false;
	if(getElemId('wkBoxForm')) {
		if(getElemId('wkBoxForm').waehrung) {
//			if(getElemId('wkBoxForm').waehrung.value) {
				if(obj.value=="DE" && !getElemId('wkBoxForm').waehrung[0].checked) changeWaehrung = true;
				if(obj.value=="AT" && !getElemId('wkBoxForm').waehrung[0].checked) changeWaehrung = true;
				if(obj.value=="CH" && !getElemId('wkBoxForm').waehrung[1].checked) changeWaehrung = true;
				if(obj.value=="LI" && !getElemId('wkBoxForm').waehrung[1].checked) changeWaehrung = true;
//			}
		}
	}
	if(changeWaehrung) {
		document.thisForm.submit();
	}
}

function setLoginEmail(sourceObj, targetFieldName) {
	targetObj = eval("document.thisForm.elements[\'" + targetFieldName + "\']");
	if(sourceObj && targetObj) {
		targetObj.enabled = false;
		targetObj.disabled = false;
		targetObj.value = sourceObj.value;
	}
}

function checkKundennummer(kundennummerObj) {
	if(kundennummerObj) {
		kdnr = kundennummerObj.value;
		if(kdnr=="") return false;
		
		kdnrNichtZiffern = kdnr.search(/\D+/);
		kdnrSlash = kdnr.indexOf("/");
		if(kdnrNichtZiffern!=-1 || kdnrSlash!=-1) {
			if(kdnrSlash!=-1) {
				kdnr = kdnr.substr(0,kdnrSlash);
			}
			if(kdnrNichtZiffern!=-1) {
				kdnr = kdnr.replace(/\D+/g, "");
			}
			alert("Die Delinat Kundennummer besteht nur aus Ziffern (0-9).\nDie Trennzeichen werden nun automatisch entfernt.");
			kundennummerObj.value = kdnr;
		}
		
	}
}

function checkDSEintraege(checkboxObj) {
	dsTypArr = new Array('DSREinzel', 'DSRDoppel', 'DSWEinzel', 'DSWDoppel', 'DSEEinzel', 'DSEDoppel', 'DSXEinzel', 'DSXDoppel', 'DSSEinzel', 'DSSDoppel', 'DSUEinzel', 'DSUDoppel');
	dsChecked = false;
	for(i=0; i<dsTypArr.length; i++) {
		tempObj = eval("document.thisForm.elements['" + dsTypArr[i] + "']");
		if(tempObj.checked) dsChecked=true;
	}
	if(!dsChecked) {
		alert("Sie haben keine DegustierService Sorten ausgewählt.\nFalls Sie ganz aus dem DegustierService austeigen wollen, schicken Sie uns einfach eine kurze E-Mail oder rufen sie uns an. ");
		checkboxObj.checked = true;
		return false;
	}
	return true;
}


function getAlter(bDate) {
	nDate = new Date();
	nMonth = nDate.getMonth()+1;
	nDay = nDate.getDate();
	nYear = nDate.getFullYear();

	// parse String2Date
	if(typeof(bDate)=="string") {

		bTextArr = bDate.split(".");
		if(bTextArr[2]) tYear = bTextArr[2];	else return false; // tYear = String(nDate.getYear());
		if(bTextArr[1]) tMonth = bTextArr[1];	else return false; // tMonth = String(nDate.getMonth()+1);
		if(bTextArr[0]) tDay = bTextArr[0]; 	else return false; // tDay = String(nDate.getDate());
		bDate = new Date(tYear, (tMonth-1), tDay);
	}
	

	bMonth = bDate.getMonth()+1;
	bDay = bDate.getDate();
	bYear = bDate.getFullYear();

	if(bMonth>nMonth)						return (nYear - bYear - 1);
	else if(bMonth==nMonth && bDay>nDay)	return (nYear - bYear - 1);
	else									return (nYear - bYear);
}



// Web-Autor
// TODOWebautor_AutomWeiterleitungBeiFalscherSchreibweise	
function gotoPage(listObj, newWin) {
	newPage = listObj.options[listObj.selectedIndex].value;
	if(!newWin) document.autorForm.action = newPage;
	else		document.autorForm.action = "/index.html";
	document.autorForm.submit();
}
function gotoNextPage(newWin) {
	document.autorForm.template.selectedIndex++;
	gotoPage(document.autorForm.template, newWin);
}		
var autorWindow;	
var autorWindowOpened = false;	
function autorWin(templateName) {
	if(!autorWindowOpened || autorWindow.closed) {
		autorWindow = window.open("/intranet/index.php?mode=webAutor&template="+templateName , "WebAutor", "width=640,height=545,screenX=0,screenY=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,copyhistory=0"); 
		autorWindowOpened = true;
	}
	autorWindow.focus();
}
