// JavaScript Document
// beim Laden initialiesieren
window.onload = init;
timerHauptmenu = null;

// initialisieren:
function init() {
	// Mouseoverfunktionen dem Hauptmenü hinzufügen
	lis = document.getElementById("menu").getElementsByTagName("LI");
	if(lis.length > 0) {
		for(j=0;j<lis.length;j++) {
			if(lis[j].className.indexOf("ebene1") == "0") {
			addEvent(lis[j].getElementsByTagName("IMG")[0], "mouseover", highliteHauptmenu);
			} else {
				if(lis[j].className != "noJS") {
					addEvent(lis[j], "mouseover", highliteButton);
					addEvent(lis[j], "mouseout", downliteButton);
				}
			}
			if(lis[j].className != "noJS") addEvent(lis[j], "mouseout", setTimerFolgemenue);
			//addEvent(lis[j], "click", goToChildHref);
			if(lis[j].className == "aktiv") {
				lis[j].parentNode.className = lis[j].parentNode.className.replace("normal", "on");
				ebene1 = lis[j].parentNode.parentNode.getElementsByTagName("IMG")[0];
			} 
		}
	}
// Dateiendung + -Größe
	as = document.getElementsByTagName("A");
	for(j=0;j<as.length;j++) {
		with(as[j]) {
			// fix links with javascript in href
			if (strpos(as[j].href,'<!--navNavlinkExt-->')>0) {
				as[j].href = substr(as[j].href,0,-20);
			}
			if(className=="linkIconLinkSize") {
				loadMe(as[j]);
			}
			if(className=="auszeichnungsLink") {
				addEvent(as[j].firstChild, "mouseover", showAuszeichnung);
				addEvent(as[j].firstChild, "mouseout", hideAuszeichnung);
			}
		}
	}
// Höhenanpassung bei Produktseiten 	
	divs=document.getElementsByTagName("DIV");
	var produkte = new Array();
	var max = 0;
	var min = 284;
	for(i in divs) {
		if(divs[i].className == "produktInformationen") {
			children = divs[i].getElementsByTagName("DIV");
			for(j in children) {
				if((children[j].className == "produktDetails")||(children[j].className == "produktDetails2")) {
					produkte = produkte.concat(children[j]);
				}
			}
		}
	}
	for(j in produkte) {
  if(produkte[j].offsetHeight > max) {
			max = produkte[j].offsetHeight;
		}
	}
	for(j in produkte) {
		if((produkte[j].className == "produktDetails")||(produkte[j].className == "produktDetails2")) {
		  if (max < min)max=min;
			produkte[j].style.height = max + "px";
		}
	}
	document.getElementById("content").style.height=document.getElementById("content").offsetHeight + "px";
	

/* Produktbilder auf Breite pruefen und Produktdiv dann anpassen, da bei zu breiten Bildern das Design verschoben wird. 25.06.07 Nicole Kussler */
	lisImg = document.getElementById("content").getElementsByTagName("IMG");
	if(lisImg.length > 0) {
		for(j=0;j<lisImg.length;j++) {
			if((lisImg[j].className.indexOf("produktBild") == "0")&&(lisImg[j].parentNode.parentNode.className.indexOf("produktPromotion") != "0")&&(lisImg[j].parentNode.className.indexOf("produktDetails2") == "0")) {
				breite = lisImg[j].width;
				if (breite < 200) breite= 200;
				lisImg[j].parentNode.style.width= breite + "px";
			}
			else if((lisImg[j].className.indexOf("produktBild") == "0")&&(lisImg[j].parentNode.parentNode.className.indexOf("produktPromotion") != "0")) {
				breite = lisImg[j].width;
				if (breite < 150) breite= 150;
				lisImg[j].parentNode.style.width= breite + "px";
			}
			else if((lisImg[j].className.indexOf("produktBild") == "0")&&(lisImg[j].parentNode.parentNode.className.indexOf("produktPromotion") == "0")) {
				breite = lisImg[j].width;
				if (breite < 160) breite= 160;
				lisImg[j].parentNode.style.width= breite + "px";
			}
		}
	}
}
function substr (str, start, len) {
	// Returns part of a string  
	// 
	// version: 909.322
	// discuss at: http://phpjs.org/functions/substr
	// +     original by: Martijn Wieringa
	// +     bugfixed by: T.Wild
	// +      tweaked by: Onno Marsman
	// +      revised by: Theriault
	// *       example 1: substr('abcdef', 0, -1);
	// *       returns 1: 'abcde'
	// *       example 2: substr(2, 0, -6);
	// *       returns 2: false
	
	// Add: (?) Use unicode.semantics and/or unicode.runtime_encoding (e.g., with string wrapped in "binary" or "Binary" class) to
	// allow access of binary (see file_get_contents()) by: charCodeAt(x) & 0xFF (see https://developer.mozilla.org/En/Using_XMLHttpRequest )
	// Fix: Handle 4-byte characters
	
	str += '';
	var end = str.length;
	if (start < 0) {
	start += end;
	}
	end = typeof len === 'undefined' ? end : (len < 0 ? len + end : len + start);
	// PHP returns false if start does not fall within the string.
	// PHP returns false if the calculated end comes before the calculated start.
	// PHP returns an empty string if start and end are the same.
	// Otherwise, PHP returns the portion of the string from start to end.
	return start >= str.length || start < 0 || start > end ? !1 : str.slice(start, end);
}
function strpos (haystack, needle, offset) {
	var i = (haystack+'').indexOf(needle, (offset || 0));
	return i === -1 ? false : i;
}

function loadMe(obj) {
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	  xmlhttp = new XMLHttpRequest();
	} else {
		var xmlhttp=false;
		 try {
		  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		 } catch (e) {
		  try {
		   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		  } catch (e) {
		   xmlhttp = false;
		  }
		 }
	}
	langRe = /.*?\/dauphin\/(..)\/.*/;
 	langReArray = langRe.exec(document.URL);

	if (xmlhttp) {
	  xmlhttp.open("GET", "/lib/linkExtension.js.php?file="+obj.href+"&lang="+RegExp.$1, true);
		xmlhttp.onreadystatechange = function () {
			if  (xmlhttp.readyState == 4) {
				if (xmlhttp.status == 200) {
					obj.innerHTML += xmlhttp.responseText;
				}
			}
		}
		
		
		try{
			xmlhttp.send();
		} catch (sdf) {
			xmlhttp.send(true);
		}
		
	}

}

function showAuszeichnung(evt) {
	obj = getGetTarget(evt);
	text = obj.parentNode.parentNode.parentNode.getElementsByTagName("DIV")[0];
	if(text.className == "auszeichnungsText") {
		text.style.display = "block";
		text.style.marginTop = text.offsetHeight/-2 +"px";
		text.style.marginLeft = text.offsetWidth/2 +"px";
	}
}
function hideAuszeichnung(evt) {
	obj = getGetTarget(evt);
	text = obj.parentNode.parentNode.parentNode.getElementsByTagName("DIV")[0];
	if(text.className == "auszeichnungsText") {
		text.style.display="none";
	}
}

// Event-Hilfsfunktionen Funktionen
function addEvent(obj, evType, fn){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, false);
    return true;
  } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
  } else {
    return false;
	}
}

function getGetTarget(evt) {
	if(evt.srcElement) return evt.srcElement;
	else return evt.target;
}

// Timer-Funktionen
function setTimerFolgemenue() {
	clearTimeout(timerHauptmenu);
	timerHauptmenu = setTimeout("downliteHauptmenu()", 150);
}

/* Mouseover-Funktionen */

// Ändert die Klasse des feuernden Elements 
// Klappmenü anzeigen
function highliteHauptmenu(evt) {
	clearTimeout(timerHauptmenu);
	obj = getGetTarget(evt);
	if (obj.nodeName == "IMG") {
		ul = obj.parentNode.parentNode.getElementsByTagName("UL");
		downliteHauptmenuBut(ul[0]);
		if (ul[0]) {
			ul[0].className = ul[0].className.replace("normal", "over");
			if(ul[0].className.indexOf("on") != -1) ul[0].style.display = "block";
		}
	}
	document.getElementById("showornot").style.display = "none";
}

// Diese funktion setzt alle Hauptmenupunkte zurück
function downliteHauptmenu() {
	uls = document.getElementById("menu").getElementsByTagName("ul");
	for(j=0;j<uls.length;j++) {
		if(uls[j].nodeName == "UL") {
			uls[j].className = uls[j].className.replace("over", "normal");
			if(uls[j].className.indexOf("on")!= -1) uls[j].style.display = "block";
		}
	}
	document.getElementById("showornot").style.display = "block";
}
// alle anderen Klappmenüs ausblenden
function downliteHauptmenuBut(current) {
	uls = document.getElementById("menu").getElementsByTagName("ul");
	for(j=0;j<uls.length;j++) {
		if(uls[j].nodeName == "UL" && uls[j] != current) {
			uls[j].className = uls[j].className.replace("over", "normal");
			if(uls[j].className.indexOf("on")!= -1) uls[j].style.display = "none";
		}
	}
}


// Hover-Effekt: 
function highliteButton(evt) {
	clearTimeout(timerHauptmenu);
	obj = getGetTarget(evt);
	ul = obj.parentNode.parentNode.parentNode.getElementsByTagName("IMG");
	for(i in ul) {downliteButton(ul[i]);}
}
function downliteButton(evt) {
	obj = getGetTarget(evt);
}
function downliteButton(img) {
}


// Damit man nicht genau die Links treffen muss:
function goToChildHref(evt) {
		//Get the firing Element
	li = getGetTarget(evt);
	if(li) location.href = li.parentNode.href;
}


// Popus, externe Links
function openWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}
// Dauphin Weltweit Mouseover
function highliteMap(nav, map, zusatz) {
	if(map) {
		map=document.getElementById(map);
		map.src = map.src.replace("i_", "a_");
	}
	if(zusatz) {
		zusatz=document.getElementById(zusatz);
		zusatz.src = zusatz.src.replace("i_europa", "a_asien_eu");
	}
}
function downliteMap(nav, map, zusatz) {
	if(map) {
		map=document.getElementById(map);
		map.src = map.src.replace("a_", "i_");
	}
	if(zusatz) {
		zusatz=document.getElementById(zusatz);
		zusatz.src = zusatz.src.replace("a_asien_eu", "i_europa");
	}

}
function openPopup(pic) {
	window.open('/dauphin/bild.php?pic=' + pic,'Bildansicht','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=200,height=200');
}
function openPopup2(pic, width, height) {
	window.open('/dauphin/bild2.php?pic=' +pic+'&width='+width+'&height='+height,'Bildansicht','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width='+width+',height='+height);
}
function maskEmail(name, domain) {
	document.writeln('<a  class="mailto" href="mailto:'+name+'@'+domain+'">'+name+'@'+domain+'</a>');
}
function maskEmailAndTrack(name, domain,trackingID) {
	document.writeln('<a  class="mailto" href="mailto:'+name+'@'+domain+'" onclick="clickTracking(\''+trackingID+'\')";>'+name+'@'+domain+'</a>');
}
// Chairfinder Popup
function popup_cf(destination)
{
  WelcomePopWin=window.open
  (destination,'_blank',
   'width=650,height=515,left=20,top=20,resizable=no,scrollbars=yes,toolbar=no,status=no,directories=no,menubar=no,location=tabelle');
 //'width=550,height=510,left=20,top=20,resizable=no,scrollbars=yes,toolbar=no,status=no,directories=no,menubar=yes,location=tabelle');
 // WelcomePopWin.focus();
}


//Volltextsuche


function Trim(STRING){
	STRING = LTrim(STRING);
	return RTrim(STRING);
}

function RTrim(STRING){
	while(STRING.charAt((STRING.length -1))==" "){
	STRING = STRING.substring(0,STRING.length-1);
	}
	return STRING;
}

function LTrim(STRING){
	while(STRING.charAt(0)==" "){
	STRING = STRING.replace(STRING.charAt(0),"");
	}
	return STRING;
}


function operator_chance(num){
	if (num==1){
		if(document.frmSearch.operator[0].checked == true){
			document.frmSearch.operator2[0].checked = true;
		}
		if(document.frmSearch.operator[1].checked == true){
			document.frmSearch.operator2[1].checked = true;
		}
	}else{
		if(document.frmSearch.operator2[0].checked == true){
			document.frmSearch.operator[0].checked = true;
		}
		if(document.frmSearch.operator2[1].checked == true){
			document.frmSearch.operator[1].checked = true;
		}
	}
}

function showAdresse (name) {
	var p;
	p = document.getElementById("content").getElementsByTagName("P");
	if(p.length > 0) {
		for(j=0;j<p.length;j++) {
			if(p[j].className.indexOf(name) > "0") {
				p[j].style.display= "block";
			}
		}
	}
}
function hideAdresse (name) {
	var p;
	p = document.getElementById("content").getElementsByTagName("P");
	if(p.length > 0) {
		for(j=0;j<p.length;j++) {
			if(p[j].className.indexOf(name) > "0") {
				p[j].style.display= "none";
			}
		}
	}
}
// Popup Bionic
function popUp1(wintype) {
  var nwl = (screen.width-1000)/2;
  var nwh = (screen.height-790)/2;
  popUp=window.open(wintype, 'PopUp','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=1000,height=790,left='+nwl+',top='+nwh+''); 
  popUp.window.focus(); 
}

// Popup Chairfinder
function popUp2(wintype) {
  var nwl = (screen.width-1050)/2;
  var nwh = (screen.height-800)/2;
  popUp=window.open(wintype, 'PopUp2','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=1050,height=800,left='+nwl+',top='+nwh+''); 
  popUp.window.focus(); 
}

