﻿var ie = (document.styleSheets && document.all)?true:false;

// Navigation Portal
var picNav0on=new Image();  picNav0on.src="/images/navi/top/D4A479C3-435B-4F85-9CE1-3F38F575F106R.gif";
var picNav0off=new Image(); picNav0off.src="/images/navi/top/D4A479C3-435B-4F85-9CE1-3F38F575F106.gif";
var picNav1on=new Image();  picNav1on.src="/images/navi/top/288F8601-4655-42EB-A0EA-ABEC0BFF1928R.gif";
var picNav1off=new Image(); picNav1off.src="/images/navi/top/288F8601-4655-42EB-A0EA-ABEC0BFF1928.gif";
var picNav2on=new Image();  picNav2on.src="/images/navi/top/152B46EE-0EC0-4071-82CA-7452D3B911D9R.gif";
var picNav2off=new Image(); picNav2off.src="/images/navi/top/152B46EE-0EC0-4071-82CA-7452D3B911D9.gif";
var picNav3on=new Image();  picNav3on.src="/images/navi/top/A4CBE51C-6DE2-489E-B2A5-18D203B9B2D3R.gif";
var picNav3off=new Image(); picNav3off.src="/images/navi/top/A4CBE51C-6DE2-489E-B2A5-18D203B9B2D3.gif";
var picNav4on=new Image();  picNav4on.src="/images/navi/top/B07594D9-547C-4EAB-A587-461B42E7F0D2R.gif";
var picNav4off=new Image(); picNav4off.src="/images/navi/top/B07594D9-547C-4EAB-A587-461B42E7F0D2.gif";
var picNav5on=new Image();  picNav5on.src="/images/navi/top/ForumR.gif";
var picNav5off=new Image(); picNav5off.src="/images/navi/top/Forum.gif";

// Navigation Forum
//var picNavForumon=new Image();  picNavForumon.src="/images/navi/top/HomeR.gif";
//var picNavForumoff=new Image(); picNavForumoff.src="/images/navi/top/Home.gif";

function img_act_link(imgName, obj) {
	if (obj.firstChild.src){
		obj.firstChild.src=eval(imgName+".src");
	}
}

function checkSimpleSearch( obj, currStat ){
	var defaultVal = "Suchwort eingeben"
	if (currStat==1 && obj.value==defaultVal) {
		obj.value = "";
	}
	if (currStat==0 && !obj.value) {
		obj.value = defaultVal;
	}
}


try {
	var txCookie = document.cookie.split(";");
	var txCookieEntry;
	var isCookie = false;
	for (var i=0;i<txCookie.length;i++){
		txCookieEntry = txCookie[i].split("=");

		if (txCookieEntry[0].replace(" ","")=="FontSize") {
			document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"/css/" + txCookieEntry[1].replace(" ","") + ".css\" id=\"knorrCSS\">");
			isCookie = true;
		}
	}
	if (isCookie == false) {
		document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"/css/middle.css\" id=\"knorrCSS\">");
	}
} catch (ex) {
		// ignore
}



function setFontSize(descr){
	var i, lnk, boxFS, boxFSLink;
	boxFS = document.getElementById("boxFontSize");
	boxFSLink = boxFS.getElementsByTagName("a");
	document.getElementById("knorrCSS").href = "/css/" + descr + ".css";
	for (i=0;i<3;i++){
		boxFSLink[i].className = "fsLink"
	}
	if (descr == "small") {
		boxFSLink[0].className = "fsLinkActive";
	} else if (descr == "middle") {
		boxFSLink[1].className = "fsLinkActive";
	} else if (descr == "big") {
		boxFSLink[2].className = "fsLinkActive";
	}
	
	document.cookie = "FontSize="+descr;
}

function addEvent( obj, type, fn ){ 
	if (obj.addEventListener){ 
		obj.addEventListener( type, fn, false );
	} else if (obj.attachEvent){ 
		obj["e"+type+fn] = fn; 
		obj[type+fn] = function(){ obj["e"+type+fn]( window.event ); } 
		obj.attachEvent( "on"+type, obj[type+fn] ); 
	}
}

function markFontSize(){
	var boxFS, boxFSLink, descr;
	boxFS = document.getElementById("boxFontSize");
	boxFSLink = boxFS.getElementsByTagName("a");
	descr = document.getElementById("knorrCSS").href;

	if (descr.indexOf("small") != -1) {
		boxFSLink[0].className = "fsLinkActive";
	} else if (descr.indexOf("middle") != -1) {
		boxFSLink[1].className = "fsLinkActive";
	} else if (descr.indexOf("big") != -1) {
		boxFSLink[2].className = "fsLinkActive";
	}
}

/*
	function setProdSubCategory() 
	product search - category dropdowns
	maybe not needed
*/
function setProdSubCategory (cat, subcat, subsubcat, currentField){
	if (cat == currentField){
		if (document.getElementById(cat).options[document.getElementById(cat).selectedIndex].value != "#"){
			document.getElementById(subcat).disabled = false;
			try {document.getElementById(subcat).style.filter = "alpha(opacity=100)";} catch (ex) { };
			try {document.getElementById(subcat).style.opacity = 1;} catch (ex) { };
		} else {
			document.getElementById(subcat).selectedIndex = 0;
			document.getElementById(subsubcat).selectedIndex = 0;
			document.getElementById(subcat).disabled = true;
			document.getElementById(subsubcat).disabled = true;
			try {document.getElementById(subcat).style.filter = "alpha(opacity=50)";} catch (ex) { };
			try {document.getElementById(subsubcat).style.filter = "alpha(opacity=50)";} catch (ex) { };
			try {document.getElementById(subcat).style.opacity = 0.5;} catch (ex) { };
			try {document.getElementById(subsubcat).style.opacity = 0.5;} catch (ex) { };
		}
	}
	else if (subcat == currentField){
		if (document.getElementById(subcat).options[document.getElementById(subcat).selectedIndex].value != "#"){
			document.getElementById(subsubcat).disabled = false;
			try {document.getElementById(subsubcat).style.filter = "alpha(opacity=100)";} catch (ex) { };
			try {document.getElementById(subsubcat).style.opacity = 1;} catch (ex) { };
		} else {
			document.getElementById(subsubcat).selectedIndex = 0;
			document.getElementById(subsubcat).disabled = true;
			try {document.getElementById(subsubcat).style.filter = "alpha(opacity=50)";} catch (ex) { };
			try {document.getElementById(subsubcat).style.opacity = 0.5;} catch (ex) { };
		}
	} 
}

/*
	function setProdSubCategory() END
*/

function openTeilnahmebedingungen(obj){
	var theUrl = obj.href;
	try {
		var newPrint = window.open(theUrl, "TN", "width=610,height=500,scrollbars");
		newPrint.focus();
	} catch (ex) {
		alert("Dieser Link öffnet ein neues Fenster. Bitte lassen Sie Popups zu!");
	}
}

function openPrint(obj) {
// used to open print popup
	var theUrl = obj.href;
	try {
		var newTN = window.open(theUrl, "PrintPage", "width=610,height=500,scrollbars");
		newTN.focus();
	} catch (ex) {
		alert("Dieser Link öffnet ein neues Fenster. Bitte lassen Sie Popups zu!");
	}
}

function printIt(){
// used to print page without popup
	if (window.print) {
		window.print();
	} else {
		var WebBrowser = "<OBJECT ID=\"WebBrowser1\" WIDTH=\"0\" HEIGHT=\"0\" CLASSID=\"CLSID:8856F961-340A-11D0-A96B-00C04FD705A2\"><\/OBJECT>";
		document.body.insertAdjacentHTML("beforeEnd", WebBrowser);
		WebBrowser1.ExecWB(6, 2);	//Use a 1 vs. a 2 for a prompting dialog box WebBrowser1.outerHTML = "";
	}
}

function printStandardPage(){
// rendering the print-button
// print-button has no function without javascript
// therefore it is rendered by javascript ...
	document.writeln("<div id=\"dvHeaderFeatures\">");
	document.writeln("<table cellpadding=\"0\" cellspacing=\"0\" align=\"right\">");
	document.writeln("<tr><td style=\"text-align:right;\"><a href=\"#\" onclick=\"printIt(this);return false;\">Seite drucken</a></td>");
	document.writeln("<td><a href=\"#\" onclick=\"printIt(this);return false;\"><img src=\"/images/content/icons/iconPrint.gif\" width=\"30\" height=\"18\" alt=\"Seite drucken\"></a></td></tr>");
	document.writeln("</table></div>");
}

function send2friend(theUrl){
// opens popup send2friend
	try {
		var newS2F = window.open("Send2Friend.wa?theUrl="+encodeURIComponent(theUrl), "S2F", "width=610,height=500,scrollbars");
		newS2F.focus();
	} catch (ex) {
		alert("Dieser Link öffnet ein neues Fenster. Bitte lassen Sie Popups zu!");
	}
	
}

function showCommentForm(){
// recipe detail
	document.getElementById("dvCommentLink").style.display = "none";
	document.getElementById("dvCommentForm").style.display = "block";
}

function checkEvent(evt){
  evt = (evt) ? evt : ((event) ? event : null);
	if (evt)
	{
	  var charCode = evt.keyCode;
		if (charCode == 13)
		{
			if (evt.returnValue)
			{
				evt.returnValue = false;
			} 
			else if (evt.preventDefault)
			{
		  	document.getElementById("ContentForm").setAttribute("onsubmit","return false",false);
			} 
			else 
			{
				var frmRetAtt=document.createAttribute("onsubmit");
				frmRetAtt.nodeValue="return false";
				document.getElementById("ContentForm").setAttributeNode(frmRetAtt);
				return false;
			}
		}
		else
		{
			document.getElementById("ContentForm").removeAttribute("onsubmit");
		}
	}
}

function loginEventCatcher(){
	if(ie && document.getElementById("layoutcontent_empty_custom_KnorrLogin_UserName"))
	{
	  document.getElementById("layoutcontent_empty_custom_KnorrLogin_UserName").onkeydown=checkEvent;
		document.getElementById("layoutcontent_empty_custom_KnorrLogin_Password").onkeydown=checkEvent;
		document.getElementById("layoutcontent_empty_custom_KnorrLogin_LoginButton").onmousedown=checkEvent;
		document.getElementById("layoutcontent_empty_custom_KnorrLogin_LoginButton").onmouseup=checkEvent;
	}
	else if(document.getElementById("layoutcontent_empty_custom_KnorrLogin_UserName"))
	{
		document.getElementById("layoutcontent_empty_custom_KnorrLogin_UserName").addEventListener("keydown", checkEvent, true);
		document.getElementById("layoutcontent_empty_custom_KnorrLogin_Password").addEventListener("keydown", checkEvent, true);
		document.getElementById("layoutcontent_empty_custom_KnorrLogin_LoginButton").addEventListener("mousedown", checkEvent, true);
		document.getElementById("layoutcontent_empty_custom_KnorrLogin_LoginButton").addEventListener("mouseup", checkEvent, true);
	}
}

function findPosX(obj){
	var curleft = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj){
	var curtop = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function displayProdCat(idObj) {
	var dropdown = document.getElementById("Dropdown."+idObj);
	if (dropdown.style.display == "none") {
		var xPos = findPosX ( document.getElementById("Text."+idObj) );
		var yPos = findPosY ( document.getElementById("Text."+idObj) );
		dropdown.style.left = (xPos - 210) + "px";
		if (ie){
			dropdown.style.top  = (yPos - 78) + "px";
		} else {
			dropdown.style.top  = (yPos - 73) + "px";
		}
		dropdown.style.display = "block";
	} else {
		dropdown.style.display = "none";
	}
}

function setProdCat(pcTarget, pcText, pcID) {
	document.getElementById(pcTarget).value = pcID;
	document.getElementById("Text."+pcTarget).value = pcText;
	document.getElementById("Text."+pcTarget).title = pcText;
	document.getElementById("Dropdown."+pcTarget).style.display = "none";
}

var colorTrEven = "#ddf3a9";	// background color of even row in data table
var colorTrOdd = "#ebf8cb";			// background color of odd row in data table
var colorTrHigh = "#FFE84D";	// background color of highlighted row in data table

function highlightRow(obj, bg){
	if (bg == 2)
		obj.style.backgroundColor=colorTrHigh
	else if (bg == 1)
		obj.style.backgroundColor=colorTrOdd
	else
		obj.style.backgroundColor=colorTrEven
}


		function farbenfroh(url){
		 var fenster;
		 fenster = window.open(url, "_blank", "width=800,height=600,resizable=no");
		 fenster.creator = self;
		 fenster.focus();
		}