/*
-----------------------------------------------
lasola.li Basic Javascripts
Author:   Robert Hilbe
Version:  30 August 2005
----------------------------------------------- */

/* googleSearchHighlight: Highlights Searched Words from Google and Yahoo, define .searchword in CSS (from http://www.kryogenix.org/code/browser/searchhi/)
----------------------------------------------- */

function highlightWord(node,word) {
	if (node.hasChildNodes) {
		var hi_cn;
		for (hi_cn=0;hi_cn<node.childNodes.length;hi_cn++) {
			highlightWord(node.childNodes[hi_cn],word);
		}
	}

	if (node.nodeType == 3) {
		tempNodeVal = node.nodeValue.toLowerCase();
		tempWordVal = word.toLowerCase();
		if (tempNodeVal.indexOf(tempWordVal) != -1) {
			pn = node.parentNode;
			if (pn.className != "searchword") {
				nv = node.nodeValue;
				ni = tempNodeVal.indexOf(tempWordVal);
				before = document.createTextNode(nv.substr(0,ni));
				docWordVal = nv.substr(ni,word.length);
				after = document.createTextNode(nv.substr(ni+word.length));
				hiwordtext = document.createTextNode(docWordVal);
				hiword = document.createElement("span");
				hiword.className = "searchword";
				hiword.appendChild(hiwordtext);
				pn.insertBefore(before,node);
				pn.insertBefore(hiword,node);
				pn.insertBefore(after,node);
				pn.removeChild(node);
			}
		}
	}
}

function googleSearchHighlight() {
	if (!document.createElement) return;
	ref = document.referrer;
	if (ref.indexOf('?') == -1) return;
	qs = ref.substr(ref.indexOf('?')+1);
	qsa = qs.split('&');
	for (i=0;i<qsa.length;i++) {
		qsip = qsa[i].split('=');
	        if (qsip.length == 1) continue;
        	if (qsip[0] == 'q' || qsip[0] == 'p') {
			words = unescape(qsip[1].replace(/\+/g,' ')).split(/\s+/);
	                for (w=0;w<words.length;w++) {
				highlightWord(document.getElementsByTagName("body")[0],words[w]);
                	}
	        }
	}
}

/* prepareSearchbox: Hide text in searchbox onfocus
----------------------------------------------- */

function prepareSearchbox() {
	if (document.getElementById('searchbox')) {
		target = document.getElementById('searchbox');
		target.value = 'Suche nach ...';

		target.onfocus = function() {
			if(target.value=='Suche nach ...') target.value='';
		}

		target.onblur = function() {
			if(target.value=='') target.value='Suche nach ...';
		}
	}
}

/* Fadomatic: Fads Elements in or out (siehe http://chimpen.com/fadomatic/)

	INTERVAL_MILLIS: Fade interval in milliseconds (Make this larger if you experience performance issues
	function Fadomatic creates a fader: element to falde, speed (0-100), minimum opacity (0-100), maximum opacity (0-100)
	function fadeIn: starts fading in
	function fadeOut: starts fading out:
	function makeVisible: sets opacity to maximum
	function makeTransparent: sets opacity to minimum
----------------------------------------------- */

Fadomatic.INTERVAL_MILLIS = 50;

function Fadomatic (element, rate, initialOpacity, minOpacity, maxOpacity) {
	this._element = element;
	this._intervalId = null;
	this._rate = rate;
	this._isFadeOut = true;
	this._minOpacity = 0;
	this._maxOpacity = 99;
	this._opacity = 99;

	if (typeof minOpacity != 'undefined') {
		if (minOpacity < 0) {
			this._minOpacity = 0;
		} else if (minOpacity > 99) {
			this._minOpacity = 99;
		} else {
			this._minOpacity = minOpacity;
		}
	}

	if (typeof maxOpacity != 'undefined') {
		if (maxOpacity < 0) {
			this._maxOpacity = 0;
		} else if (maxOpacity > 99) {
			this._maxOpacity = 99;
		} else {
			this._maxOpacity = maxOpacity;
		}

		if (this._maxOpacity < this._minOpacity) {
			this._maxOpacity = this._minOpacity;
		}
	}

	if (typeof initialOpacity != 'undefined') {
		if (initialOpacity > this._maxOpacity) {
			this._opacity = this._maxOpacity;
		} else if (initialOpacity < this._minOpacity) {
			this._opacity = this._minOpacity;
		} else {
			this._opacity = initialOpacity;
		}
	}

	if(typeof element.style.opacity != 'undefined') {
		this._updateOpacity = this._updateOpacityW3c;
	} else if(typeof element.style.filter != 'undefined') {
		var existingFilters="";
		if (element.style.filter) {
			existingFilters = element.style.filter+" ";
		}
		element.style.filter = existingFilters+"alpha(opacity="+this._opacity+")";
		this._updateOpacity = this._updateOpacityMSIE;
	} else {
		this._updateOpacity = this._updateVisibility;
	}
	this._updateOpacity();
}

Fadomatic.prototype.fadeOut = function () {
	this._isFadeOut = true;
	this._beginFade();
}

Fadomatic.prototype.fadeIn = function () {
	this._isFadeOut = false;
	this._beginFade();
}

Fadomatic.prototype.makeVisible = function () {
	this.haltFade();
	this._opacity = this._maxOpacity;
	this._updateOpacity();
}

Fadomatic.prototype.makeTransparent = function () {
	this.haltFade();
	this._opacity = 0;
	this._updateOpacity();
}

Fadomatic.prototype.haltFade = function () {
	clearInterval(this._intervalId);
}

Fadomatic.prototype.resumeFade = function () {
	this._beginFade();
}

Fadomatic.prototype._beginFade = function () {
	this.haltFade();
	var objref = this;
	this._intervalId = setInterval(function() { objref._tickFade(); },Fadomatic.INTERVAL_MILLIS);
}

Fadomatic.prototype._tickFade = function () {
	if (this._isFadeOut) {
		this._opacity -= this._rate;
		if (this._opacity < this._minOpacity) {
			this._opacity = this._minOpacity;
			this.haltFade();
		}
	} else {
		this._opacity += this._rate;
		if (this._opacity > this._maxOpacity ) {
			this._opacity = this._maxOpacity;
			this.haltFade();
		}
	}
	this._updateOpacity();
}

Fadomatic.prototype._updateVisibility = function () {
	if (this._opacity > 0) {
		this._element.style.visibility = 'visible';
	} else {
		this._element.style.visibility = 'hidden';
	}
}

Fadomatic.prototype._updateOpacityW3c = function () {
	this._element.style.opacity = this._opacity/100;
	this._updateVisibility();
}

Fadomatic.prototype._updateOpacityMSIE = function () {
	this._element.filters.alpha.opacity = this._opacity;
	this._updateVisibility();
}

Fadomatic.prototype._updateOpacity = null;

/* Onload Behaviour
-----------------------------------------------*/

window.onload=function() {

	// prepare Searchbox
	prepareSearchbox();

	// Highlight Searched Words
	googleSearchHighlight();

	// Fade in Header
	var navigation = document.getElementById('header');
	fader = new Fadomatic(navigation, 5, 0);
	fader.fadeIn();
}
/* Formularhandling */
function eingaben_ueberpruefen(){

 var mail = document.Formular.email.value;

 if (document.Formular.vorname.value.length < 3){

  alert("Bitte trage noch deinen Vornamen ein")

  document.Formular.vorname.focus();

  return false;

 }



 else if (document.Formular.nachname.value.length < 3){

  alert("Bitte trage noch deinen Nachnamen ein");

  document.Formular.nachname.focus();

  return false;

 }



 else if (document.Formular.strasse.value.length < 3){

  alert("Bitte trage noch deine Stra&szlig;e ein");

  document.Formular.strasse.focus();

  return false;

 }



 else if (document.Formular.plz.value.length < 3){

  alert("Bitte trage deine PLZ ein");

  document.Formular.plz.focus();

  return false;

 }



 else if (document.Formular.ort.value.length < 3){

  alert("Bitte trage deinen Ort ein");

  document.Formular.nachname.focus();

  return false;

 }


 else if (mail.length < 10 || mail.indexOf ('@',0) == -1 || mail.indexOf ('.',0) == -1){

  alert("Bitte gib deine E-Mail-Adresse ein")

  document.Formular.email.select();

  return false;

 }



 else if (document.Formular.betreff.value.length < 10){

  alert("Bitte gib einen Betreff ein")

  document.Formular.betreff.focus();

  return false;

 }




 else

 return true;

}

/*
-----------------------------------------------*/

function tagvisibility( id, vis ) {
if(document.getElementById) {
//shorttag = document.getElementById( id ).style.visibility;
if (vis != null) {
document.getElementById( id ).style.visibility = vis;
} else {
if (
document.getElementById( id ).style.visibility ==
"hidden" ||
document.getElementById( id ).style.visibility == ""
) {
document.getElementById( id ).style.visibility = "visible";
} else document.getElementById( id ).style.visibility =
"hidden";
}
}
}
