// Global variables
var fertig = false
var nn4 = false;	// Netscape Navigator or Communicator
var ie4 = false;
var ie5 = false;
var ie6 = false;
var ie = false;		//IE 5 und IE6
var ns6 = false;    // Netscape 6
var ns7 = false;   	// Netscape 7
var moz = false;	// Mozilla Engine
var dom1 = false;	// fully supports DOM1
var dom2 = false;	// fully supports (important bits of) DOM2
var op = false;  	//all opera
var op7 = false;  	//opera 7
var mac = false;	//mac
var safari = false;	//mac Safari
var old = false;	// very old browser

var browserWarn = false;
var strAgent = window.navigator.userAgent;

function browser_detect()
{
	op = (strAgent.indexOf("Opera") > -1);
	op7 = (strAgent.indexOf("Opera/7") > -1) || (strAgent.indexOf("Opera 7") > -1);	

    // do it the official W3C way
    if ( window.document.implementation != null)
    {
         dom1 = window.document.implementation.hasFeature("HTML","1.0");
         dom2 = window.document.implementation.hasFeature("HTML","2.0") &&
         	window.document.implementation.hasFeature("Events","2.0") &&
         	window.document.implementation.hasFeature("Core","2.0") &&
         	window.document.implementation.hasFeature("CSS2","2.0");
    }
    // Mozilla based browsers contain the Gecko rendering engine
    moz = (window.navigator != null )
		? (strAgent.indexOf("ecko") != -1 )
		: false;
    nn4 = (window.document.layers != null && !moz);
	ns6 = (moz && !dom2);
	ns7 = (moz && (strAgent.indexOf("Netscape/7") > 0));
	
    // IE has incremental support for the Document Object Model
    ie6 = (window.document.all && dom1);
    ie5 = (window.document.all && (strAgent.indexOf('MSIE 5')>0));		//&& window.document.getElementsByTagName()
	ie  = (ie5 || ie6 && !op);
    ie4 = (window.document.all && !ie6 && !ie5); 
	mac = (strAgent.indexOf('Mac')>0);
	safari = (strAgent.indexOf('Safari')>0)
    // something horrible and old
    old = (!ie && !dom1 && !moz);
	
	// set flag browserWarn true if IE<5 or Netscape < 6
	if (ie == true || moz== true){
		browserWarn = false;
	} 
	else {
		browserWarn = true;
	}
	//alert (browserWarn);
}

var jquery = {
	init: function() {
        $('.expander dt:not(.open)+dd').hide()
        $('.expander dt').click(function() {
            var dt = $(this)
            dt.next('dd').slideToggle('fast', function() {
                dt.toggleClass('open')          
            })
        })
		$('a.withTooltipp').cluetip({
			leftOffset: -100,
			topOffset: -440,
			sticky: true, 
			activation: 'click',
			closeText: unescape('schliessen'),
			local:true, 
			hoverIntent: {sensitivity: 1,interval: 750,timeout: 750}, 
			width: 382, 
			closePosition: 'title'
		});
    }
}
// do onready
$(jquery.init);



function checkAndResize() {
	browser_detect();
	var oCont = document.getElementById('contentarea');
	if(document.getElementById('SendErgebnisse'))
		oCont = document.getElementById('SendErgebnisse');
	var oBody = document.getElementById('pageBody');
	var criticalWidth = 1014;
	var nNet7Dif = 0;
	if(ns7) nNet7Dif = 14;
	if(moz) {
		if(window.innerHeight>600)
			oCont.style.height = (window.innerHeight - (308 + nNet7Dif)) + "px";
		else
			oCont.style.height = (290 - nNet7Dif) + "px";
			
		if(window.innerWidth>=criticalWidth) {
			oBody.style.overflow = 'hidden';
		}else{
			oBody.style.overflow = 'visible';
			oCont.style.height = "auto";
		}			
	}
	if(document.body.offsetWidth > 1024) 
	{
		document.getElementById('Schatten').style.display = 'inline';
		if(document.getElementById('SchattenBottom')!=null)
			document.getElementById('SchattenBottom').style.display = 'inline';
	} 
	if(!ns7 && document.body.offsetWidth < criticalWidth) {
		oBody.style.overflow = 'auto';
		oCont.style.height = "auto";
	}	
}

function toggleTeaserVisibility(block,submenueblock,FFevnt,sNoMoz) {
	if(sNoMoz=='noMoz' && moz==true)
		return;

	if(block!=null){
		var e = document.getElementById("klappBlock"+block);
		var oImg = document.getElementById("klappPfeil"+block);
		var oTable = document.getElementById("klappBlockTable"+block);
	} else {
		var e = document.getElementById("submenueLink"+submenueblock);
		var oImg = document.getElementById("productPic"+submenueblock);
		if(FFevnt && moz){
			e.style.left = FFevnt.target.x+"px";
			e.style.top = FFevnt.target.y+"px";
		}else if(FFevnt && op){
			e.style.left = FFevnt.x-240 + "px";
			e.style.top = FFevnt.y-70 + "px";
		}
	}
	if (e.style.display == '') //test in ie, if not set -> set it!
		e.style.display = "none";
	if (e.style.display == "none") {
		if(oImg) {
			if(submenueblock) 
				oImg.className = "alpha";
			else
				oImg.style.backgroundImage = "url(/images/pfeilklein_down.gif)";
		}
		e.style.display = "block";
		if(oTable) oTable.style.display = "inline";
	} else { 
		if(oImg) {
			if(submenueblock) 
				oImg.className = "";
			else 
				oImg.style.backgroundImage = "url(/images/pfeilklein.gif)";}
		e.style.display = "none";
		if(oTable) oTable.style.display = "none";
		}
	return false;
}


//===================/=NAVIGATION=========================


startList = function() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("sitemapNav");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			//nextNode = node.childNodes[0];
			//alert(node.innerText);
			if (node.nodeName=="A" && nextNode.length>0 && nextNode[0].nodeName=="P") {
			
				//alert(nextNode.nodeName.className);
			
				node.onmouseover=function() {nextNode.className += " visible";}
				node.onmouseout=function() {nextNode.className = nextNode.className.replace(" visible", "");}
			}
		}
	}
}

//===================/=NAVIGATION=========================

//Popup mit Url,Fensternamen,Breite,Groesse - ohne Toolbar,ohne Scrollbars (wenn > 1000px/700px)
//zentriert popup auf Mitte
function popup2(url,name,width,height,top,left,scrollable,resizeable)	{

	var stage_width = width;
	var stage_height = height;
	var scroll = scrollable;
	var resize= resizeable;

	//calculates centered position on the screen
	var aw = screen.availWidth - 10;
	var ah = screen.availHeight - 30;
	var endWidth = 	aw - stage_width;
	var endHeight = ah - stage_height;
		//if(endWidth > 0 && endHeight > 0)
		//{
			var stage_left = endWidth / 2;
			var stage_top = endHeight / 2;
		/*}else{
			var stage_left = 1;
			var stage_top = 1;
		}*/
		if ((aw<650)||(ah<480))
		{
			scroll = 1;
			resize = 1;
			width = aw;
			height = ah;
		}

	var para_str = "";
	para_str += ",width=" + width;
	para_str += ",height="+ height;
	para_str += ",top=" + stage_top; ;//+ stage_top
	para_str += ",left="+ stage_left;// + stage_left;
	para_str += ",scrollbars="+ scroll;
	para_str += ",resizable="+ resize;
	para_str += ",status=0"; //+ stat;
	para_str += ",menubar=0"; // + menu
	para_str += ",toolbar=0"; //+ tool;
	//para_str += ",location=" + loc;
	//para_str += ",directories=" + dir;

	win = window.open(url, name, para_str);
	if (win && win.open && !win.closed) win.focus();
}


function pruefenSuche(form,aReqFields) {
	leeresFeld = false;
	Pflichtfelder = new Array();
	var oField1,oField2;

	oField1 = eval('form.'+aReqFields[0]);
	oField2 = eval('form.'+aReqFields[1]);
	if (leeresFeld == false && FeldLeer(oField1) == true && FeldLeer(oField2) == true){ 
		Pflichtfelder[Pflichtfelder.length] = "- Bitte f&uuml;llen Sie mindestens eins der Felder aus.";}
	if (leeresFeld == false && FeldLeer(oField1) == false && oField1.name == "PLZ"){
		if (nurZahlen(oField1)==false || oField1.value.length<5){ 
			Pflichtfelder[Pflichtfelder.length] = "- Bitte eine f&uuml;nfstellige PLZ eingeben.";
		}
	}
	if (Pflichtfelder.length > 0){
		var sFehlerQuery = Pflichtfelder.join("<br>");
		eval ("popup2('/_static/error.html?" + sFehlerQuery + "','fehlerhinweis',340,220);");
		leeresFeld = true;
	}
	if (leeresFeld == false) {
		form.submit();
	}
}


function takeCookieText(cookieinhalt){
        if (document.cookie.indexOf(cookieinhalt) != -1){
		var aInCookie = document.cookie.split(";");
		for (y=0;y<aInCookie.length;y++){
			if(aInCookie[y].indexOf(cookieinhalt)!=-1){
				if(aInCookie[y].indexOf("=")!=-1){
					aCookie = aInCookie[y].split("=");
					return unescape(aCookie[1]);}
				else	{
					return null;
				}}	
		}
	}else{return '';}
}

function setQPCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

function pruefen(form,aReqFields,newAction) {
	leeresFeld = false;
	Pflichtfelder = new Array();
	var oField;
	for (a=0; a<aReqFields.length; a++){
		oField = eval('form.'+aReqFields[a]);
		// Abfrage der Check- und Radioboxen
		var oType = oField.type;
		if (oField.type == undefined)
			oType = oField[0].type;
		var oName = oField.name;
		if (oField.name == undefined)
			oName = oField[0].name;
		if (oType =='checkbox' || oType =='radio'){
			var bChecked = false;
			var xy = 0;
			if(!oField.length) {
				xy++;
				if (oField.checked) 
					bChecked = true;
			}else{
				for (i=0; i<oField.length; i++){
					xy++;
					if (oField[i].checked) {
						bChecked = true;
						break;}}}
			if (xy == 1 && bChecked == false) {Pflichtfelder[Pflichtfelder.length] = "- das Feld \"" + oName + "\" muss aktiviert sein";}
			if (xy > 1 && bChecked == false) {Pflichtfelder[Pflichtfelder.length] = "- Ihre Bestellung bzw. Anmeldung";}
		}
		else if ((oType == 'select-one' || oType == 'select') && oField.selectedIndex==0){
			Pflichtfelder[Pflichtfelder.length] = "- "+aReqFields[a];}
		else if (aReqFields[a].indexOf("captchaImageTXT")!=-1){
			if (leeresFeld == false && FeldLeer(oField) == true)
				Pflichtfelder[Pflichtfelder.length] = "- Zahlen der Sicherheitsabfrage";
			else if (FeldLeer(oField) == false && oField.value != sGUId)
				Pflichtfelder[Pflichtfelder.length] = "- die Zahlen der Sicherheitsabfrage stimmen nicht &uuml;berein";
		}
		else if (leeresFeld == false && FeldLeer(oField) == true){
			Pflichtfelder[Pflichtfelder.length] = "- "+aReqFields[a];}
		if (aReqFields[a].toLowerCase().indexOf("email")>-1){
			if (leeresFeld == false && FeldLeer(oField) == false && (checkEmail(oField.value) == false))  {Pflichtfelder[Pflichtfelder.length] = "- g" + String.fromCharCode(252) + "ltige Email-Adresse";}
		}
	}
	if (Pflichtfelder.length > 0){
		var sFehlerQuery = Pflichtfelder.join("<br>");
		eval ("popup2('/_static/error.html?" + sFehlerQuery + "','fehlerhinweis',340,220);");
		leeresFeld = true;
	}
		
	if (leeresFeld == false) {
		if(form.submitTarget && form.submitTarget.value!='') 
			form.target = form.submitTarget.value;
		if(newAction!=null) form.action = newAction;
		if(form.pageState) form.pageState.value = "send";
		if(aReqFields[0]=='Suchbegriffe'){
			form.submit();
		} else if (takeCookieText("allreadySend")!="true") {
			var sExp = new Date();
			var sExpMin = sExp.getTime() + (30 * 1000);
			sExp.setTime(sExpMin);
			setQPCookie("allreadySend", "true", sExp, "/");
			form.submit();
		}
	}
}
function valButton(btn) {
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
       if (btn[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1) return btn[cnt].value;
    else return null;
}
                  
function checkLengthAndAlarm(CountSigns,oThisField)
{
	if(oThisField.value.length > CountSigns)
	{
		alert("Ihr Text ist zu lang, er besteht aus " + oThisField.value.length + " Zeichen. Bitte k"+ String.fromCharCode(252) +"rzen Sie den Text auf max. " +CountSigns+ " Zeichen.");
		oThisField.focus();
	}
}

function FeldLeer(feld){
	if (feld && feld.value == "") return true; else return false;}

function checkEmail(email)
{
	var filter=/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/i;
	if (!(filter.test(email)))
	return false;
}
function nurZahlen(feld) {
	if (isNaN(feld.value))
		return false;
	else 
		return true;
/*
	var zahlen = "0123456789"; 
	for (var i=0; i < feld.length; i++) {
		if (zahlen.indexOf(feld.charAt(i)) == -1)
			return false;
	}
	return true;
*/

}

function resetForm(){
        var bCheck = confirm("Sollen alle Inhalte des Formulars gel" + String.fromCharCode(246) + "scht werden?");
        if(bCheck == true) 
		document.frmForm.reset();
	}


function picHighlight(oElemNr,sStatus,oThisElem,sExistClass){
	var oImg = document.getElementById("productPic"+oElemNr);
	if(oImg) {
		if(sStatus=='on'){
			if(sExistClass!=null)
				oImg.className = sExistClass + " alpha";
			else
				oImg.className = "alpha";
			if(moz)
				oThisElem.style.cursor = "pointer";
			else
				oThisElem.style.cursor = "hand";
					
		}else {
			if(sExistClass!=null)
				oImg.className = sExistClass;
			else
				oImg.className = "";
			oThisElem.style.cursor = "";}
	}
}

startList4sitemap = function() {
if (document.all&&document.getElementById) {
	navRoot = document.getElementById("newsitemap1");
	for (i=0; i<navRoot.childNodes.length; i++) {
		node = navRoot.childNodes[i];
		if (node.nodeName=="LI") {
			node.onmouseover=function() {
				this.className+=" over";
			}
			node.onmouseout=function() {
				this.className=this.className.replace(" over", "");
			}
		}
	}
	navRoot = document.getElementById("newsitemap2");
	for (i=0; i<navRoot.childNodes.length; i++) {
		node = navRoot.childNodes[i];
		if (node.nodeName=="LI") {
			node.onmouseover=function() {
				this.className+=" over";
			}
			node.onmouseout=function() {
				this.className=this.className.replace(" over", "");
			}
		}
	}
 }
}



/*
function changeVisibility(oElemToChange,nBlockCounter,sBlockName,oClassToChange,oActionLink) {
	for(var i=1;i<=nBlockCounter;i++){
		var oBlockToDelete = eval(document.getElementById(sBlockName+i));
		oBlockToDelete.style.display = "none";
	}
	if(oClassToChange){
		document.getElementById(oClassToChange).className='aktiv';
	}
	var oBlockToChange = eval(document.getElementById(oElemToChange));
	oBlockToChange.style.display = "block";

	if(oActionLink){
		var oActionThisLink = eval(document.getElementById(oActionLink));
		var sActionID = String(oActionThisLink.id);
		sActionID = sActionID.substring(0, sActionID.length-1);
		for(var i=0;i<nBlockCounter;i++){
			var oActionLinkToChange = eval(document.getElementById(sActionID+i));
			oActionLinkToChange.className = "";
		}
		oActionThisLink.className = "noLink";
	}
}
*/
