function deleteCookieTest() {
  var myCookieName = 'JSESSIONID';
  if (!getCookieValue(myCookieName))
    alert ('Cookie does not exist')
  else  {
    deleteCookie(myCookieName);
  }
}

function getCookieValue(cookieName) {
  var exp = new RegExp (escape(cookieName) + "=([^;]+)");
  if (exp.test (document.cookie + ";")) {
    exp.exec (document.cookie + ";");
    return unescape(RegExp.$1);
  }
  else return false;
}

function deleteCookie (cookieName) {
  if (getCookieValue (cookieName)) writePersistentCookie (cookieName,"Pending delete","years", -1);  
  return true;     
}

function writePersistentCookie (CookieName, CookieValue, periodType, offset) {
	  var expireDate = new Date ();
	  offset = offset / 1;
	  
	  var myPeriodType = periodType;
	  switch (myPeriodType.toLowerCase()) {
	    case "years": 
	     var year = expireDate.getYear();     
	     if (year < 1000) year = year + 1900;     
	     expireDate.setYear(year + offset);
	     break;
	    case "months":
	      expireDate.setMonth(expireDate.getMonth() + offset);
	      break;
	    case "days":
	      expireDate.setDate(expireDate.getDate() + offset);
	      break;
	    case "hours":
	      expireDate.setHours(expireDate.getHours() + offset);
	      break;
	    case "minutes":
	      expireDate.setMinutes(expireDate.getMinutes() + offset);
	      break;
	    default:
	      //alert ("Invalid periodType parameter for writePersistentCookie()");
	      break;
	  } 
	  
	  document.cookie = escape(CookieName ) + "=" + escape(CookieValue) + "; expires=" + expireDate.toGMTString() + "; path=/";
	} 

function PopupFenster_small(url) {
	var isSafari3 = false; 
	
	if( window.devicePixelRatio &&  window.getMatchedCSSRules && !window.Opera){
	    isSafari3  =  !!window.getMatchedCSSRules(document.documentElement,'');
		msgWindow=window.open(url,"popup","toolbar=no,width=645,height=445,status=no,scrollbars=no,resizable=no,menubar=no,dependent=no");
	}else{
		msgWindow=window.open(url,"popup","toolbar=no,width=630,height=445,status=no,scrollbars=no,resizable=no,menubar=no,dependent=no");
	}
}

function mailto(url){
        var myUrl = escape(url);
        parent.location.href="mailto:Ihre%20Kontaktadresse?subject=Link-Tip&body=Hallo,%0C%20Ich%20sende%20Ihnen%20einen%20Link%20zu%20einer%20Webseite,%20von%20der%20ich%20denke,%20dass%20sie%20interessant%20ist:%20" + myUrl+"%20";
}

//Globale Variable welche f�r "printpage" ben�tigt wird
var activeTab;

//Funktion welche tab active inactive setzt udn inhalt anzeigt by juwimm
function showtab(id) 
{   
	activeTab = id;	
	
	classNameActive = document.getElementById("tab" + activeTab).className;
	classNameArrayActive = classNameActive.split('_');
	
	
    //tab aktiv setzen und andere Tabs inaktiv setzen, tabcontainer anzeigen
    for (i = 1; i <= tabLables.length; i++) {
    	
    	if (!document.getElementById("tab"+i) || !document.getElementById("tabcontent"+i)) {
    		continue;
    	}
    
	    className = document.getElementById("tab"+i).className;
		classNameArray = className.split('_');
		
		
	
        if (i == id)//tab activ setzen 
        {
        	document.getElementById("tab"+i).className =  "tabactive_" + classNameArray[1];
            document.getElementById("tabcontent"+i).style.display = "block";
	                    
	        document.getElementById("wrapper").className = (classNameArray[1] == "blue" ? "mainBlue" : "mainOrange");
        }
        else //Tab inactiv setzen 
        {
            document.getElementById("tab"+i).className = "tabinactive_" + classNameArray[1];
            document.getElementById("tabcontent"+i).style.display = "none";
        }
    }
    
   	document.getElementById("bigTab").className = "bigTab_" + classNameArrayActive[1];
    
}

function openWindow(url,width,height,scroll,name,anchor)
{
	//default scrollbars=no;
	if(scroll=='')
	{
		scroll = 'no';
	}
	if(activeTab == null)
	{
		activeTab=1;
	}
	url = url+"&actTab="+activeTab+""+anchor;
	popWindow = window.open(url,name,"toolbar=no,width="+width+",height="+height+",status=yes,scrollbars="+scroll+",resizable=no,menubar=no,dependent=no");
	popWindow.blur;
}


// will be called by flash layer
function closeFlashBannerDiv() 
{
	document.getElementById("flashLayer").style.display = "none";
}


var activeSubcontactDiv = undefined;
var activeSubcontactSelect = undefined;

function updateSubcontactField(div, select) {

    var subcontactDiv 		= document.getElementById(div);
    var subcontactSelect 	= document.getElementById(select);
    
    if (activeSubcontactSelect != null) {
    	activeSubcontactSelect.selectedIndex = 0;
    	activeSubcontactDiv.style.display = 'none';
    	
    }
    
    if (subcontactDiv != null &&  subcontactDiv != undefined) {
         subcontactDiv.style.display = 'block';
         activeSubcontactDiv = subcontactDiv;
         activeSubcontactSelect = subcontactSelect;
    }
}



function createXMLHttpRequest() {

	var ua;

	if(window.XMLHttpRequest) {
    	try {
      		ua = new XMLHttpRequest();
    	} catch(e) {
      		ua = false;
    	}
  	} else if(window.ActiveXObject) {
    	try {
      		ua = new ActiveXObject("Microsoft.XMLHTTP");
    	} catch(e) {
      		ua = false;
    	}
  	}
  return ua;
}

function sendRequest(url) {
  var req = createXMLHttpRequest();
  id = document.getElementById("dropdown").value;
  req.open("POST",url,true);
  req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
  req.onreadystatechange = tryit;
  req.send(id); 
} 

function tryit(){
    document.frm.i_gruppe.value = req.responseText;
}

function changeIndicationImg(pos,state,iconId,file)
{
	elementId = 'indicationImg'+pos;
	if(state=='on')
	{
		document.getElementById(elementId).src = '/mepaerb/img_2009/icon_indication'+iconId+'_50.gif';
	}
	else
	{
		document.getElementById(elementId).src = '/mepaerb/img_2009/icon_indication'+iconId+'_'+file+'.gif';
	}
}

(function($) {
	// initialize faq lists
	$.fn.faqList = function(options) {
		
		var settings = $.extend({
			questionTags: "dt", // any jQuery selector possible, you can also use span.question, div.title, etc.
			answerTags: "dd",
			expandedId: false,
			animationSpeed: 400
		}, options);
	
	
		this.each(function(i, v) {
			var l = $(this);
			if (settings.expandedId == true) {
				var answers = l.find(settings.answerTags).not(":eq(" + settings.expandedId + ")").hide();
			} else {
				var answers = l.find(settings.answerTags).hide();
			}
			l.find(settings.questionTags).each(function(i, v) {
				$(this).wrapInner("<a href='#'></a>").find("a").click(function() {
					l.find(settings.answerTags + ":visible").slideUp(settings.animationSpeed);
					if (!answers.eq(i).is(":visible")) {
						answers.eq(i).slideDown(settings.animationSpeed);
					}
					return false;
				});
			});
		});
	};
})(jQuery);

// snippet found at: http://jdsharp.us/jQuery/minute/calculate-scrollbar-width.php
function getScrollbarWidth() {
    var div = $('<div style="width:50px;height:50px;overflow:hidden;position:absolute;top:-200px;left:-200px;"><div style="height:100px;"></div>');
    // Append our div, do our calculation and then remove it
    $('body').append(div);
    var w1 = $('div', div).innerWidth();
    div.css('overflow-y', 'scroll');
    var w2 = $('div', div).innerWidth();
    $(div).remove();
    return (w1 - w2);
}


$(document).ready(function() {
	
	// init search box
	var initialSearchValue = $("#initialSearchValue").text();
	$("#searchTerm").focus(function() {
		if ($(this).val() == initialSearchValue) {
			$(this).val("");
		}
	}).blur(function() {
		if ($(this).val() == "") {
			$(this).val(initialSearchValue);
		}
	});
	
	// if there area any faqlists on the page, initialize 'em
	if ($(".faqList").length > 0) {
		initFaqLists();
	}
	
	// init print popup
	$("a.print-link").click(function() {
		msgWindow = window.open($(this).attr("href"),"popup","toolbar=no,width=" + (554 + getScrollbarWidth()) + ",height=630,status=no,scrollbars=no,resizable=no,menubar=no,dependent=no");		
		return false;
	});
	
	// init faq lists
	//$(".faq-list dl").faqList();
});
