// Style Switcher
function switchStyle(s) {
  if (!document.getElementsByTagName) return;
  var el = document.getElementsByTagName("link");
  for (var i = 0; i < el.length; i++ ) {
    if (el[i].getAttribute("rel").indexOf("style") != -1 && el[i].getAttribute("title")) {
      el[i].disabled = true;
      if (el[i].getAttribute("title") == s) el[i].disabled = false;
    }
  }
}

function setStyle(s) 
{
  	if (s != "Standard") 
  	{
	    switchStyle(s);
	    Stil = s;
  	}
}

// Liefert zu einem String das dazugehörige Datum, sofern das Format OK ist
function ConvertToDate(dat)
{
	var MonatsLetzter = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

	// regulaerer Ausdruck, der sicherstellt, dass grundsätzlich
	// ein ordentliches Datumsfromat der Form d[d].m[m].yyyy gewählt wurde.
	var regEx = "[0-9]{1,2}[.][0-9]{1,2}[.][0-9]{4}";	
	
	var res = dat.match(regEx);

	if (res != dat)
		return null;

	var pos_1 = dat.indexOf(".");
	var pos_2 = dat.lastIndexOf(".");
	
	// ParseInt zur Basis 10. Standard ist Basis 8. 
	var dd = parseInt(dat.substr(0, pos_1), 10);
	var mm = parseInt(dat.substr(pos_1 + 1, pos_2 - pos_1 - 1), 10);
	var yy = parseInt(dat.substr(pos_2 + 1), 10);

	// Jetzt auf plausibles Datum hin ueberpruefen
	if (yy % 4 == 0)  // Schaltjahr
		Monat[1] = 29;

	if (mm < 1 || mm > 12)
	{
		return null;
	}
	
	if (dd < 1 || dd > MonatsLetzter[mm-1]) 
	{
		return null;
	}

	// Achtung Monat zaehlt immer ab 0
	return new Date(yy, mm-1, dd);
}


function GetDateFormatted (theDate)
{
	var Monat = new Array("Januar", "Februar", "M&auml;rz", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember");
	
	// Monat ermitteln
	var dd = theDate.getDate();
	var mm = theDate.getMonth();
	var yy = 1900 + theDate.getYear(); 
	
	var fmt = dd + "." +  Monat[mm]+ "." + yy;

	return fmt;
}

function SetCheckBox (chkBoxId, wert)
{
	chkBox = document.getElementById(chkBoxId);

	chkBox.checked = wert;
}

function LoadURL (url)
{
	location.href = url;	
}


function cookiesEnabled() 
{
 	var result=3;  // undefined, if the browser does not know the property
 	
 	if (navigator.cookieEnabled!=null) 
 	{
  		if (navigator.cookieEnabled) 
  			result=1;
  		else 
  			result=2;
 	}
 	return result;
}

function setCookie (a_name, a_value, a_lifetime) 
{  
	// a_lifetime in Tagen
 	var now = new Date();
 	
 	// Festlegen, wann das Cookie ablaeuft
 	var expiry = new Date(now.getTime() + a_lifetime*24*60*60*1000);
 	
 	if ((a_value != null) && (a_value != ""))
 	{
  		document.cookie=a_name + "=" + escape(a_value) + "; expires=" + expiry.toGMTString();
  	}
 	
 	return getCookie(a_name) != null; // Test, ob es geklappt hat
}

function getCookie(a_name) 
{
 	var a_start, an_end;
 	
 	if (document.cookie) 
 	{
  		a_start = document.cookie.indexOf(a_name+"=");
	  	
	  	if (a_start < 0) return null;
	  	
	  	a_start = document.cookie.indexOf("=", a_start) + 1;
	  	an_end = document.cookie.indexOf(";", a_start);
	  	
	  	if (an_end < 0) an_end = document.cookie.length;
	  	
	  	return unescape(document.cookie.substring(a_start, an_end));
 	}
 	else 
 		return null;
}

function deleteCookie(a_name) 
{
	var now = new Date();
	var expired = new Date(now.getTime() - 10*24*60*60*1000);  // 10 Tage zurueck
 	document.cookie=a_name + "=null; expires=" + expired.toGMTString();
}

/* Laedt Bilder in den Cache, so dass diese ohne weitere Serverzugriffe genutzt werden können */
function FP_preloadImgs() 
{
 	var d=document,a=arguments; 
 	
 	if(!d.FP_imgs) 
 		d.FP_imgs=new Array();
 		
 	for(var i=0; i<a.length; i++) 
 	{ 
 		d.FP_imgs[i] = new Image; 
 		d.FP_imgs[i].src=a[i]; 
 	}
}

/* Wechselt das Bild in einem IMG-Tag */
function FP_swapImg(id, nr) 
{
	/* Ermittele den IMG-Tag */
	elm=FP_getObjectByID(id); 

	/* Falls Element gefunden wurde Bild wechseln */
	if(elm) 
		elm.src = document.FP_imgs[nr].src; 
}

function FP_getObjectByID(id,o) 
{
 	var c,el,els,f,m,n; if(!o)o=document; if(o.getElementById) el=o.getElementById(id);
 	else if(o.layers) c=o.layers; else if(o.all) el=o.all[id]; if(el) return el;
 	if(o.id==id || o.name==id) return o; if(o.childNodes) c=o.childNodes; if(c)
 	for(n=0; n<c.length; n++) { el=FP_getObjectByID(id,c[n]); if(el) return el; }
 	f=o.forms; if(f) for(n=0; n<f.length; n++) { els=f[n].elements;
 	for(m=0; m<els.length; m++){ el=FP_getObjectByID(id,els[n]); if(el) return el; } }
 	return null;
}


function show_key ( the_key )
{
	alert ("versuch");
    if ( ! the_key )
    {
        the_key = event.keyCode;
    }

    document.my_form.key_display.value = String.fromCharCode ( the_key );
}

function lg_SetClass (id, myclassname)
{
	var node = document.getElementById(id);
	
	if(node == null)
		return;
	
	node.className = myclassname;
}

// Schlimm Schlimm, dass man sich eine solche Routine erst noch schreiben muß unter JS
function lg_Pause(millis)
{
	date = new Date();
	var curDate = null;

	do { var curDate = new Date(); }
		while(curDate-date < millis);
} 

function lg_MixedArray ( myArray ) 
{
  var i = myArray.length;
  
  if ( i == 0 ) 
  	return false;
  
  while ( --i ) 
  {
     var j = Math.floor( Math.random() * ( i + 1 ) );
     var tempi = myArray[i];
     var tempj = myArray[j];
     myArray[i] = tempj;
     myArray[j] = tempi;
   }
}

function lg_DeleteChildNodes(startNode) 
{
	while (startNode.hasChildNodes()) 
	{
		startNode.removeChild(startNode.lastChild);
	}
}

function lg_SetText(id, text)
{
	var node = document.getElementById(id);
	
	if (node == null)
		return;
	
	lg_DeleteChildNodes(node);
	
	var inhalt    = document.createTextNode(text);
	node.appendChild(inhalt);
}
