//ie6?
ie6 = false;
if (navigator.appVersion.indexOf("MSIE 6.0") != -1) {
	var ie6 = true;
}

//intitialisation function - called onload.
function init() {
	prepareFaq();
	initLightbox(); 
	initDropdowns();
	
	
	if (ie6) {
		//link rollover for ie6
		initLinks();
	}
}

function initWindow() {
	prepareFaq();
	initDropdowns();
	
	
	if (ie6) {
		//link rollover for ie6
		initLinks();
	}
}

function initLogin() {
	if (ie6) {
		//link rollover for ie6
		initLinks();
	}
}

function initFeedback(w,h) {
	if (ie6) {
		//link rollover for ie6
		initLinks();
	}
	
	top.objModalWindow.style.width = w;
	top.objModalWindow.style.height = h;
	top.objModalWindowIframe.style.width = w;
	top.objModalWindowIframe.style.height = h;
	top.objModalWindow.style.marginLeft = -(Math.round(parseInt(w)/2))+'px';
}

function initLinks(){
	var objBody = document.getElementsByTagName('body').item(0);
		
	for (i=0; i<objBody.getElementsByTagName('a').length; i++) {
		if(objBody.getElementsByTagName('a')[i].getElementsByTagName('span').length > 0) {
			objBody.getElementsByTagName('a')[i].attachEvent('onmouseover', function() {  event.srcElement.style.backgroundColor = "#FBEDED"; } );
			objBody.getElementsByTagName('a')[i].attachEvent('onmouseout', function() {  event.srcElement.style.backgroundColor = ""; } );
		}
	}
}

//function show first level subnavigation
function naviActionOver(currentTopic) {
	currentTopic.parentNode.parentNode.style.position = 'relative';
	
	var previousNavItem = currentTopic.parentNode.previousSibling;
	
	while (previousNavItem.nodeType == 3)
    	previousNavItem = previousNavItem.previousSibling;
	
	if (previousNavItem.getElementsByTagName('a')[0].className == 'naviLink')
		previousNavItem.getElementsByTagName('a')[0].className = 'naviLinkWoSep';
	else 
		previousNavItem.getElementsByTagName('a')[0].className = 'naviLinkWithSubItemsWoSep';
	
	if (currentTopic.className.indexOf('WithSubItems') != -1 || currentTopic.className.indexOf('naviLayerHi') != -1) {   
		currentTopic.parentNode.className = 'hasSubItemsHi';
		currentTopic.parentNode.getElementsByTagName('div')[0].style.display = 'block';
		currentTopic.parentNode.getElementsByTagName('iframe')[0].style.display = 'block';
		currentTopic.parentNode.getElementsByTagName('iframe')[0].style.height = (currentTopic.parentNode.getElementsByTagName('div')[0].offsetHeight-23)+'px';
	}
}

//function hide first level subnavigation
function naviActionOut(currentTopic) {
	currentTopic.parentNode.parentNode.style.position = '';
	
	var previousNavItem = currentTopic.parentNode.previousSibling;
	
	while (previousNavItem.nodeType == 3)
    	previousNavItem = previousNavItem.previousSibling;
	
	if (previousNavItem.getElementsByTagName('a')[0].className == 'naviLinkWoSep')
		previousNavItem.getElementsByTagName('a')[0].className = 'naviLink';
	else 
		previousNavItem.getElementsByTagName('a')[0].className = 'naviLinkWithSubItems';
	
	if (currentTopic.className.indexOf('WithSubItems') != -1 || currentTopic.className.indexOf('naviLayerHi') != -1) {
		currentTopic.parentNode.className = 'hasSubItems';
		currentTopic.parentNode.getElementsByTagName('div')[0].style.display = 'none';
		currentTopic.parentNode.getElementsByTagName('iframe')[0].style.display = 'none';
	}
}

//function toggle faq answers
function toggleFaq(obj) {
	
	if (obj) {
	
		var image = obj.getElementsByTagName('img')[0];
		var answer = obj.nextSibling;
		
		if (answer) {
			while (answer.nodeType == 3)
				answer = answer.nextSibling;
			
			if (answer.style.display != 'block') {
				answer.style.display = 'block';
				image.src = 'images/faq_active_icon.gif';
			}
			else {
				answer.style.display = 'none';
				image.src = 'images/link_icon.gif';
			}
		}
	}
}

//function write social bookmarks
function writeSocialBookmarks() {
	document.write("<a href=\"http://www.facebook.com/\" onclick=\" window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(location.href)+'&t='+encodeURIComponent(document.title));return false;\"><img src=\"images/facebook.gif\" alt=\"Facebook\" name=\"Facebook\"></a><!-- next --><a href=\"http://www.twitter.com/\" onclick=\" window.open('http://twitter.com/home?status='+encodeURIComponent(document.title)+'%20'+encodeURIComponent(location.href)); return false;\"><img src=\"images/twitter.gif\" alt=\"Twitter\" name=\"Twitter\"></a><!-- next --><a href=\"http://www.mister-wong.de\" onclick=\"window.open('http://www.mister-wong.de/index.php?action=addurl&bm_url='+encodeURIComponent(location.href)+'&bm_notice=&bm_description='+encodeURIComponent(document.title)+'&bm_tags=');return false;\"><img src=\"images/misterwong.gif\" alt=\"wong\" title=\"wong\" class=\"bookmarkicon\" /></a><!-- next --><a href=\"http://del.icio.us\" onclick=\"window.open('http://del.icio.us/post?v=2&url='+encodeURIComponent(location.href)+'&notes=&tags=&title='+encodeURIComponent(document.title));return false;\"><img src=\"images/delicious.gif\" alt=\"del.icio.us\" title=\"del.icio.us\" class=\"bookmarkicon\" /></a><!-- next --><a href=\"http://www.google.com/\" onclick=\"window.open('http://www.google.com/bookmarks/mark?op=add&hl=de&bkmk='+encodeURIComponent(location.href)+'&annotation=&labels=&title='+encodeURIComponent(document.title));return false;\"><img src=\"images/google.gif\" alt=\"Google\" title=\"Google\" class=\"bookmarkicon\" /></a><!-- next --><a href=\"http://www.yahoo.com/\" onclick=\"window.open('http://myweb2.search.yahoo.com/myresults/bookmarklet?t='+encodeURIComponent(document.title)+'&d=&tag=&u='+encodeURIComponent(location.href));return false;\"><img src=\"images/yahoo.gif\" alt=\"Yahoo\" title=\"Yahoo\" class=\"bookmarkicon\" /></a><!-- next --><a href=\"http://yigg.de/\" onclick=\"window.open('http://yigg.de/neu?exturl='+encodeURIComponent(location.href));return false;\"><img src=\"images/yigg.gif\" alt=\"Yigg\" title=\"Yigg\" class=\"bookmarkicon\" /></a><!-- next --><a href=\"http://digg.com/\" onclick=\" window.open('http://digg.com/submit?phase=2&url='+encodeURIComponent(location.href)+'&bodytext=&tags=&title='+encodeURIComponent(document.title));return false;\"><img src=\"images/digg.gif\" alt=\"Digg\" name=\"Digg\" class=\"bookmarkicon\" /></a>");
}

//function write js version of faqs
function prepareFaq() {

	var faqBlockArray = document.getElementsByClassName('faqContainer');
	
	if (faqBlockArray) {
	
		var faqQuestion = null;
		var faqAnswer = null;
		var linkImage = null;
		var linkText = null;
	
		for (i=0; i<faqBlockArray.length; i++) {
		
			faqQuestion = faqBlockArray[i].getElementsByTagName('a')[0];
			faqAnswer = faqBlockArray[i].getElementsByTagName('p')[0];
			linkText = faqBlockArray[i].getElementsByTagName('span')[0];
			linkImage = document.createElement('img');
			linkImage.src = 'images/link_icon.gif';
			linkImage.width = '9';
			linkImage.height = '8';
			linkImage.alt = '';
			
			if (faqBlockArray[i].className.indexOf('noJs') != -1)
				faqBlockArray[i].className = faqBlockArray[i].className.replace(' noJs', '');
			
			faqQuestion.style.marginLeft = '5px'
			faqQuestion.insertBefore(linkImage, linkText);
			
			faqAnswer.style.display = 'none';
			faqAnswer.className = 'indent';
		}
	}
}

//function toggle faq answers
function toggleFaq(obj) {
	
	if (obj) {
	
		var image = obj.getElementsByTagName('img')[0];
		var answer = obj.nextSibling;
		
		if (answer) {
			while (answer.nodeType == 3)
				answer = answer.nextSibling;
			
			if (answer.style.display != 'block') {
				answer.style.display = 'block';
				image.src = 'images/faq_active_icon.gif';
			}
			else {
				answer.style.display = 'none';
				image.src = 'images/link_icon.gif';
			}
		}
	}
}

//sprungmarken funktion
function jumpToMarker(fieldId) {    
	window.location.hash = document.getElementById(fieldId).value;  
}

//print bug pngfix fix :)
if (window.attachEvent  && /MSIE (5\.5|6)/.test(navigator.userAgent))
{
function printPNGFix(disable)
 {
  for (var  i = 0; i < document.all.length; i++)
  {
   var  e = document.all[i];
   if (e.filters['DXImageTransform.Microsoft.AlphaImageLoader'] || e._png_print)
{
    if (disable)
    {
e._png_print = e.style.filter;
     e.style.filter = '';
}
    else
    {
     e.style.filter  = e._png_print;
     e._png_print = '';
    }
}
  }
 };
 window.attachEvent('onbeforeprint',  function() { printPNGFix(1) });
 window.attachEvent('onafterprint', function()  { printPNGFix(0) });
}

//modale fenster
objModalWindow = null;
objModalWindowIframe = null; 

function createModalWindow(iFrameSrc,objId,w,h) {
	var objBody = document.getElementsByTagName("body").item(0);
	
	objModalWindow = document.createElement("div");
	objModalWindow.setAttribute('id',objId);
	objModalWindow.className = 'modalWindow';
	objModalWindow.style.width = w;
	objModalWindow.style.height = h;
	objModalWindow.style.marginLeft = -(Math.round(parseInt(w)/2))+'px';
	
	objBody.appendChild(objModalWindow);
	
	objModalWindowIframe = document.createElement("iframe");
	objModalWindowIframe.marginWidth = '0';
	objModalWindowIframe.marginHeight = '0';
	objModalWindowIframe.frameBorder = '0';
	objModalWindowIframe.scroll = 'auto';
	objModalWindowIframe.src = iFrameSrc;
	objModalWindowIframe.style.width = w;
	objModalWindowIframe.style.height = h;
	
	objModalWindow.appendChild(objModalWindowIframe);
	
	
}

function showWindow(windowId, url) {
	switch (windowId) {
		case 'modalWindowContact': createModalWindow(url,'modalWindowContact','577px','670px'); if(ie6) objModalWindowIframe.src = url;
		break;
		case 'modalWindowRecommend': createModalWindow(url,'modalWindowRecommend','577px','540px'); if(ie6) objModalWindowIframe.src = url;
		break;
	}
	
	var scrOfY = 0;
	
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
	}
	else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
	}
	
	overlayEffect.custom(0,0.6);
	document.getElementById(windowId).style.top = 30 + parseInt(scrOfY)+'px';
	
	document.getElementById(windowId).style.display = 'block';
}

function hideWindow() {
	top.overlayEffect.custom(0.6,0); 
	top.objModalWindow.parentNode.removeChild(top.objModalWindow);
}

//seite empfehlen add recipient
function addrecipient(elmt) {
	var counter = document.getElementById('recipients').getElementsByTagName('fieldset').length;
	
	if( counter == 2 ) { // auf 3 Empfänger beschränken
		elmt.parentNode.style.display = 'none';
	}//if
	
	var objDiv = document.getElementById('recipients');

	var objFieldset = document.createElement('fieldset');
		objDiv.appendChild(objFieldset);
		
	var objInputBg = document.createElement('div');
		objInputBg.className = 'inputBg';
		objFieldset.appendChild(objInputBg);
		
	var objLabel = document.createElement('label');
		objLabel.setAttribute('for','email_'+counter);
		objLabel.innerHTML = 'E-Mail:';
		objInputBg.appendChild(objLabel);
		
	var objInputText = document.createElement('input');
//		objInputText.setAttribute('type','text');
		objInputText.setAttribute('value','');
		objInputText.setAttribute('name','f_toMail_'+counter);
		objInputText.setAttribute('id','email_'+counter);
		objInputBg.appendChild(objInputText);
		
	var objInputBg = document.createElement('div');
		objInputBg.className = 'inputBg';
		objFieldset.appendChild(objInputBg);
		
	var objLabel = document.createElement('label');
		objLabel.setAttribute('for','name_'+counter);
		objLabel.innerHTML = 'Name:';
		objInputBg.appendChild(objLabel);
		
	var objInputText = document.createElement('input');
//		objInputText.setAttribute('type','text');
		objInputText.setAttribute('value','');
		objInputText.setAttribute('name','f_recipientName_'+counter);
		objInputText.setAttribute('id','name_'+counter);
		objInputBg.appendChild(objInputText);
	
	var clearFix = document.createElement('br');
		clearFix.className = 'clear';
		objFieldset.appendChild(clearFix);
}

//login script
function toggleLogin(elmt) {
	if (top.document.getElementById('loginButton').className == 'firstActive') {
		top.document.getElementById('loginButton').className = '';
		
		if(ie6) {
			top.document.getElementById('loginButton').style.filter = 'none';
			top.document.getElementById('loginButton').style.background = 'url(images/bg_quicklinks.gif) right 11px no-repeat';
		}
		
		top.document.getElementById('loginContainer').style.display = 'none';
	}
	else {
		if(ie6) {
			top.document.getElementById('loginButton').style.background = 'url(images/dnd_login_reiter.png) 0 0 no-repeat';
		}
		top.document.getElementById('loginButton').className = 'firstActive';
		top.document.getElementById('loginContainer').style.display = 'block';
	}
}

//login error
function error() {
	top.document.getElementById('loginContainer').getElementsByTagName('iframe')[0].style.height = '248px';
}

