$(document).ready(function(){
	
	cookieResize('#access a', 'medium');
	
	$('#quicksearch h4').addClass('jspointer');
	$('#quicksearch .lft .bordered').before('<div class="toggler floatwrap"></div>');
	$('#quicksearch .bordered h4').each(function(){
		$(this).appendTo('#quicksearch .toggler')
	});
	
	$('#quicksearch .hidTab').hide();
	$('#quicksearch .tkurse').show();
	$('#quicksearch #tkurse').addClass('act')
	
	$('#quicksearch .toggle').each(function(){	
		$(this).bind('click',function(){
			id = $(this).attr('id');
			$('#quicksearch .toggle').each(function(){
				$(this).removeClass('act');
			});
			$(this).addClass('act')
			$('#quicksearch .hidTab').hide();
			$('#quicksearch .'+id).show();
			
			return false;
		})
	});
	
	$('#access a').each(function(){
		$(this).bind('click',function(){
			
			$('#access a').each(function(){
				$(this).removeClass('cur');
			});
			
			$(this).addClass('cur');
			$('body').attr('class','');
			$('body').addClass($(this).attr('class'));
			
			$(this).blur();
			
			return false;
		});
	});
	

	
	
	$("a.jQueryBookmark").click(function(e){
		var bookmarkUrl = this.href;
		var bookmarkTitle = this.title;
		if (window.sidebar) { // For Mozilla Firefox Bookmark
			e.preventDefault(); // this will prevent the anchor tag from going the user off to the link
			window.sidebar.addPanel(bookmarkTitle, bookmarkUrl,"");
		} else if( window.external || document.all) { // For IE Favorite
			e.preventDefault(); // this will prevent the anchor tag from going the user off to the link
			window.external.AddFavorite( bookmarkUrl, bookmarkTitle);
		/* } else if(window.opera) { // For Opera Browsers
			$("a.jQueryBookmark").attr("href",bookmarkUrl);
			$("a.jQueryBookmark").attr("title",bookmarkTitle);
			$("a.jQueryBookmark").attr("rel","sidebar");
			*/
		} 
	});
	
	$('dfn').tooltip({ 
	    delay: 0
	});
		
	
	
});

function UnCryptMailto( s )
  {
        var n = 0;
        var r = "";
        for( var i = 0; i < s.length; i++)
        {
            n = s.charCodeAt( i );
            if( n >= 8364 )
            {
                n = 128;
            }
            r += String.fromCharCode( n - 1 );
        }
        return r;
    }

function linkTo_UnCryptMailto( s )
{ location.href=UnCryptMailto( s );}	
	
function addToList(urlString){
 window.location.href = urlString + "&offY=" + getScrollY();
}


function getScrollY() {
  var scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
  } else if( document.body && document.body.scrollTop ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
  } else if( document.documentElement &&  document.documentElement.scrollTop ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
  }
  return scrOfY;
}

function NewWindow(theUrl,winName,features)
{
 window.open(theUrl,winName,features);
}

function SetzeFocus(){
 document.kurssuche["allg.stichwort"].focus();
}
	
function csspopup() {
	// PopUp verstecken
	document.getElementById("popup").style.display = "none";
	// Cookie setzen
	var expirationdate = new Date();
	expirationdate = new Date(expirationdate.getTime() + 60*60*24*45);
	document.cookie = "PopUp=nomore;expires=" + expirationdate.toGMTString() + ";";
}
function cookiecheck() {
	// Prüfen ob Cookie vorhanden
	if (document.cookie.search("PopUp=nomore") == -1){
	// Nicht vorhanden, also PopUp anzeigen
		document.getElementById("popup").style.display = "block";
	}
}	

function CallNews(dest) {
	var myRand = Math.round(Math.random()*100);
	window.open(dest, "News"+myRand, "resizable=1,status=1,scrollbars=1,width=950,height=550");
}

function CallDetails(dest) {
	var myRand = Math.round(Math.random()*100);
	window.open(dest, "Details"+myRand, "resizable=1,status=1,scrollbars=1,width=950,height=550");
}
	
	
function setAllgKategorie1(me){
	var getVal = document.forms["xtsearch"].elements[me];
	document.forms["xtsearch"].elements["allg.kategorie"].value = getVal.options[getVal.selectedIndex].value;
	document.getElementsByName('allg.kategorie2')[0].checked = true;
	document.getElementsByName('allg.kategorie2')[1].checked = false;
}	
function setAllgKategorie2(me){
	var getVal = document.forms["xtsearch"].elements[me];
	if (getVal[1].checked) {
		document.forms["xtsearch"].elements["allg.kategorie"].value = getVal[1].value;
		document.forms["xtsearch"].elements["allg.kategorie1"].selectedIndex = 0;	
	} else {
		document.forms["xtsearch"].elements["allg.kategorie"].value = getVal[0].value;	
	}
}	
function setProfiKategorie1(me){
	var getVal = document.forms["xtsearch"].elements[me];
	document.forms["xtsearch"].elements["profi.kategorie"].value = getVal.options[getVal.selectedIndex].value;
	document.getElementsByName('profi.kategorie2')[0].checked = true;
	document.getElementsByName('profi.kategorie2')[1].checked = false;
}	
function setProfiKategorie2(me){
	var getVal = document.forms["xtsearch"].elements[me];
	if (getVal[1].checked) {
		document.forms["xtsearch"].elements["profi.kategorie"].value = getVal[1].value;
		document.forms["xtsearch"].elements["profi.kategorie1"].selectedIndex = 0;	
	} else {
		document.forms["xtsearch"].elements["profi.kategorie"].value = getVal[0].value;	
	}
}	
	
function checkdate()	{
	var fehler=0;
	var emptyEnd=0;
	
	
	a=document.forms[0].elements["profi.beginn"].value
	h=document.forms[0].elements["profi.ende"].value

	// wenn beide Datumfelder leer sind, dann keine weiteren Prüfungen:
	if (h.length == 0 && a.length == 0) {
	  	emptyEnd=1 
	}
	// wenn eins oder beide Datumfelder nicht leer, hier schon mal eine Feldlängenprüfung: 
	else {
		if (h.length != 10) fehler=6
		if (a.length != 10) fehler=5
	}

	// Beginndatum prüfen
	if (a.length != 0) {
		// Fehleranzeige, wenn bereits Beginndatum-Fehler vorliegt:
		if (fehler==5) {
			alert('Beginndatum bitte im Format dd.mm.yyyy angeben!')
			return false;
		}
		
		// ansonsten Datumprüfung, beginnend mit BeginnDatum:
		else {
			d = a.substring(0, 2)// day
			c = a.substring(2, 3)// '.'
			b = a.substring(3, 5)// month
			e = a.substring(5, 6)// '.'
			f = a.substring(6, 10)// year
			
			//basic fehler checking BeginnDatum
			if (b<1 || b>12) fehler = 2			// Die Angaben fuer den Beginn-Monat sind nicht korrekt
			if (c != '.') fehler = 1			// Falsches Datenformat bei Beginndatum
			if (d<1 || d>31) fehler = 3			// Falsche Tagesangabe bei Beginndatum
			if (e != '.') fehler = 1
			if (f<1990 || f>2099) fehler = 4	// Bitte nur Jahresangaben zwischen 1990 und 2099 !
			
			//advanced fehler checking BeginnDatum
		
			// months with 30 days
			if (b==4 || b==6 || b==9 || b==11) {
				if (d==31) fehler=3
			}
	
			//february, leap year
			if (b==2)  {
				// feb
			    var g=parseInt(f/4)
				if (isNaN(g)) fehler=3
		
				if (d>29) fehler=3
				if (d==29 && ((f/4)!=parseInt(f/4))) fehler=3
			}
			   
			// Fehlerausgabe, falls bei BeginnDatum Fehler festgestellt:
			if (fehler==1){
				alert('Beginndatum bitte im Format dd.mm.jjjj eingeben!')
				return false;
			}
			if (fehler==2) {
				alert('Ungültiges Beginndatum!')
				return false;
			}
			if (fehler==3) {
				alert('Ungültiges Beginndatum!')
				return false;
			}
			if (fehler==4) {
				alert('Bitte nur Jahresangaben zwischen 1990 und 2099 !')
				return false;
			}
		} 
	}	// Ende Prüfung BeginnDatum
	
	// Endedatum prüfen
	if (h.length != 0) {
		// Fehleranzeige, wenn bereits Endedatum-Fehler vorliegt:
		if (h.length != 10) {
			alert('Endedatum bitte im Format dd.mm.yyyy angeben oder Feld leer lassen!')
			return false;
		}
		
		// ansonsten Datumprüfung, beginnend mit BeginnDatum:
		else {
				i = h.substring(0, 2)// day
				j = h.substring(2, 3)// '.'
				k = h.substring(3, 5)// month
				l = h.substring(5, 6)// '.'
				m = h.substring(6, 10)// year
		
			//basic fehler checking
				if (k<1 || k>12) fehler = 2
				if (j != '.') fehler = 1
				if (i<1 || i>31) fehler = 3
				if (l != '.') fehler = 1
				if (m<1990 || m>2099) fehler = 4
		
			//advanced fehler checking
	
			   // months with 30 days
			   if (k==4 || k==6 || k==9 || k==11) {
					if (i==31) fehler=3
			   }
	
			   //february, leap year
			   if (k==2) {
					// feb
					var g=parseInt(m/4)
					if (isNaN(g))  {
						fehler=3
					}
					if (i>29) fehler=3
					if (i==29 && ((m/4)!=parseInt(m/4))) fehler=3
			   }
			   
			   // wenn bis hier noch kein Fehler bei EndeDatum, dann zusätzliche Prüfungen nach Ende vor Anfang
			   if (fehler==0) {
			   		if (a.length != 0) {
						 if (m>f || m==f) {  // Normalfall: Endejahr >= Beginnjahr
						   
							if(m==f) {
							  
								if(k>b || k==b) {
								  
									if(k==b) {
									  
										if(i<d) {
											alert('Der Endetag darf nicht vor dem Anfangstag liegen!')
											return false;
										}
									}
								 }
								 else {
									alert('Der Endemonat darf nicht vor dem Anfangsmonat liegen!')
									return false;
								 }
							 }
						 }
						 else {
							alert('Das Endejahr darf nicht vor dem Anfangsjahr liegen!')
							return false;
						 }
					}						 
			   }
				 
				 
			   // wenn bereits vorher Fehler aus Endedatumprüfung registriert:
			   else	 {
					if (fehler==1){
						alert('Endedatum bitte im Format dd.mm.jjjj eingeben!')
						return false;
					}
					if (fehler==2) {
						alert('Ungültiges Endedatum!')
						return false;
					}
					if (fehler==3) {
						alert('Ungültiges Endedatum!')
						return false;
					}
					if (fehler==4) {
						alert('Bitte nur Jahresangaben zwischen 1990 und 2099 !')
						return false;
					}
		      } 
		 } 
	}	// Ende Prüfung EndeDatum
	


	
}	// Ende Funktion

