// beinhaltet alle Funktionen von linkFade.js, imgSwap.js, window.js, check.js

// START -- imgSwap.js --
function swapByName(imgName,imgObj) {
	document.getElementsByName(imgName)[0].src = imgObj;
}

// START -- window.js --
function openDefWin(myURL, myWidth, myHeight, myToolbar, myLocation, myMenubar, myDirectories, myStatus, myResizeable, myScrollbars, myWinName, myPosX, myPosY) {
	var floater=null;
	if (floater && !floater.closed && floater.name==myWinName) {
		floater.focus();
		floater.location.href=myURL;
	} else {
		floater = window.open(myURL, myWinName, 'WIDTH=' + myWidth + ',HEIGHT=' + myHeight + ',TOOLBAR=' + myToolbar + ',LOCATION=' + myLocation + ',MENUBAR=' + myMenubar + ',DIRECTORIES=' + myDirectories + ',STATUS=' + myStatus + ',RESIZABLE=' + myResizeable + ',SCROLLBARS=' + myScrollbars);
		floater.moveTo(myPosX, myPosY);
		floater.focus();
	}
}

// START -- linkFade.js --
fadeColor = "#8C9197";  // color to fade to
stepIn = 20; // delay when fading in
stepOut = 30; // delay when fading out
autoFade = true;
sloppyClass = true;
macCompat = false;

hexa = new makearray(16);
for(var i = 0; i < 10; i++)
    hexa[i] = i;
hexa[10]="a"; hexa[11]="b"; hexa[12]="c";
hexa[13]="d"; hexa[14]="e"; hexa[15]="f";

document.onmouseover = domouseover;
document.onmouseout = domouseout;

fadeColor = dehexize(fadeColor.toLowerCase());

var fadeId = new Array();

function dehexize(Color){
	var colorArr = new makearray(3);
	for (i=1; i<7; i++){
		for (j=0; j<16; j++){
			if (Color.charAt(i) == hexa[j]){
				if (i%2 !=0)
					colorArr[Math.floor((i-1)/2)]=eval(j)*16;
				else
					colorArr[Math.floor((i-1)/2)]+=eval(j);
			}
		}
	}
	return colorArr;
}

function domouseover() {
	if(document.all){
		var srcElement = event.srcElement;
		if ((srcElement.tagName == "A" && autoFade && srcElement.className != "nofade") || srcElement.className == "fade" || (sloppyClass && srcElement.className.indexOf("fade") != -1)) {
				if (!srcElement.startColor) {
					srcElement.startColor = (srcElement.style.color)? srcElement.style.color: srcElement.currentStyle.color;
					srcElement.startColor = dehexize(srcElement.startColor.toLowerCase());
				}
				var link = (macCompat? srcElement.name: srcElement.uniqueID);
				if (link) fade(srcElement.startColor,fadeColor,link,stepIn);				
				else if (macCompat) alert("Error: Mac Compatility mode enabled, but link has no name.");
		}
	}
}

function domouseout() {
	if (document.all){
		var srcElement = event.srcElement;
		if ((srcElement.tagName == "A" && autoFade && srcElement.className != "nofade") || srcElement.className == "fade" || (sloppyClass && srcElement.className.indexOf("fade") != -1)) {
			var link = (macCompat? srcElement.name: srcElement.uniqueID);
			if (link) fade(fadeColor,srcElement.startColor,link,stepOut);
		}
	}
}

function makearray(n) {
    this.length = n;
    for(var i = 1; i <= n; i++)
        this[i] = 0;
    return this;
}

function hex(i) {
    if (i < 0)
        return "00";
    else if (i > 255)
        return "ff";
    else
       return "" + hexa[Math.floor(i/16)] + hexa[i%16];
}

function setColor(r, g, b, element) {
      var hr = hex(r); var hg = hex(g); var hb = hex(b);
      element.style.color = "#"+hr+hg+hb;
}

function fade(s,e,element,step) {
	var sr = s[0]; var sg = s[1]; var sb = s[2];
	var er = e[0]; var eg = e[1]; var eb = e[2];
	
	if (fadeId[0] != null && fade[0] != element && eval(fadeId[0])) {
		var orig = eval(fadeId[0]);
		setColor(orig.startColor[0],orig.startColor[1],orig.startColor[2],orig);
		var i = 1;
		while(i < fadeId.length) {
			clearTimeout(fadeId[i]);
			i++;
		}
	}
		
	for(var i = 0; i <= step; i++) {
		fadeId[i+1] = setTimeout("setColor(Math.floor(" +sr+ " *(( " +step+ " - " +i+ " )/ " +step+ " ) + " +er+ " * (" +i+ "/" +
			step+ ")),Math.floor(" +sg+ " * (( " +step+ " - " +i+ " )/ " +step+ " ) + " +eg+ " * (" +i+ "/" +step+
			")),Math.floor(" +sb+ " * ((" +step+ "-" +i+ ")/" +step+ ") + " +eb+ " * (" +i+ "/" +step+ ")),"+element+");",i*step);
	}
	fadeId[0] = element;
}


// START -- check.js --
function CheckLen_news_txt(Target,txtTarget)
{
	StrLen = Target.value.length
	if (StrLen == 1 && Target.value.substring(0,1) == " ")
	{
		Target.value = ""
		StrLen = 0
	}
	if (StrLen >2000 )
	{
		Target.value = Target.value.substring(0,2000)
		CharsLeft = 0
	}
	else
	{
		CharsLeft = 2000 - StrLen
	}
	txtTarget.value = CharsLeft 
}


// für Gästebuch
function checkEntry(action)
{
	var_name=document.entry.name.value;
	var_msg=document.entry.msg.value;
	var_email = document.entry.email.value;
	document.entry.add.value=action;
	
	if (var_email!="")
	{
		if (!isValidEmail(var_email))
		{
			alert ("Du hast keine gültige E-Mailadresse eingegeben.");
			document.entry.email.focus();
			return false;
		}
	}
		
	if (var_msg=="" && var_name=="")
	{
		alert("Du hast keine Namen und keine Nachricht eingegeben.");
		return false;
	}
	else
	{
		if (var_msg=="")
		{
			alert("Du hast nichts eingegeben . . ");
			document.entry.msg.focus();
			return false;
		}
		else
		{		
			if (var_name=="")
			{
				alert("Du hast keinen Namen eingegeben.");
				document.entry.name.focus();
				return false;
			}
			else
				document.entry.submit();
		}
	}
}

// Führende Leerzeichen entfernen
function LTrim(str)
 {
	var whitespace = new String(" \t\n\r");

	var s = new String(str);

	if (whitespace.indexOf(s.charAt(0)) != -1)
	 {
		 // We have a string with leading blank(s)...

		 var j=0, i = s.length;

		 // Iterate from the far left of string until we
		 // don't have any more whitespace...
		 while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
			  j++;

		 // Get the substring from the first non-whitespace
		 // character to the end of the string...
		 s = s.substring(j, i);
	 }

	return s;
 }


// Nachfolgende Leerzeichen entfernen
function RTrim(str)
 {
	// We don't want to trip JUST spaces, but also tabs,
	// line feeds, etc.  Add anything else you want to
	// "trim" here in Whitespace
	var whitespace = new String(" \t\n\r");

	var s = new String(str);

	if (whitespace.indexOf(s.charAt(s.length-1)) != -1)
	 {
		 // We have a string with trailing blank(s)...

		 var i = s.length - 1;       // Get length of string

		 // Iterate from the far right of string until we
		 // don't have any more whitespace...
		 while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
			  i--;

		 // Get the substring from the front of the string to
		 // where the last non-whitespace character is...
		 s = s.substring(0, i+1);
	 }

	return s;
 }

	
// Führende und nachfolgende Leerzeichen entfernen
function Trim(str)
 {
	return RTrim(LTrim(str));
 }
	

// substring von [start] bis [start+len]
function Mid(str, start, len)
 {
	// Make sure start and len are within proper bounds
	if (start < 0 || len < 0) return "";
	
	var iEnd, iLen = String(str).length;

	if (start + len > iLen) iEnd = iLen;
	else iEnd = start + len;
	
	return String(str).substring(start,iEnd);
 }
	

// String mit [anz] Leerzeichen zurückgeben
function setSpace(anz)
 {
	var space_str = "";
for (var i=1; i<=anz; i++)
 {
	space_str += " ";
 }
return space_str; 
 }

// eMail-Adresse gültig ?
function isValidEmail(email)
 { 
	var validFlag = false;
	if ( (email != "") && (email.indexOf("@") != -1) && (email.indexOf(".") != -1) )
	 {
		var atCount = 0;
		var specialFlag = false;
		
		for (var atLoop=0; atLoop<email.length; atLoop++)
		 {
			atChr = email.charAt(atLoop);
			atChrCode = atChr.charCodeAt(0);
			
			if (atChr == "@") atCount++;
			if ( (atChrCode >= 32) && (atChrCode <= 44) ) specialFlag = true;
			if ( (atChrCode == 47) || (atChrCode == 96) || (atChrCode >= 123) ) specialFlag = true;
			if ( (atChrCode >= 58) && (atChrCode <= 63) ) specialFlag = true;
			if ( (atChrCode >= 91) && (atChrCode <= 94) ) specialFlag = true;
		 }
		
		if ( (atCount == 1) && (!specialFlag) )
		 {
			var badFlag = false;
			
			var tAry1 = new Array();
			tAry1 = email.split("@");
			var UserName = tAry1[0];
			var DomainName = tAry1[1];
			
			if ( (UserName == "") || (DomainName == "") ) badFlag = true;
			if (DomainName.charAt(0) == ".") badFlag = true;
			if (Mid(DomainName, DomainName.length-1, 1) == ".") badFlag = true;
			
			validFlag = true;
		 }
	 }
	if (badFlag) validFlag = false;
	
	return validFlag;
}
	
function adressCheck()
{
	var check_vorname="",check_nachname="",check_ort="",check_plz="",check_strasse="",check_email="";
	var str_check;
	var counter=0;
	
	vorname=document.frm_adresse.vorname.value;
	nachname=document.frm_adresse.nachname.value;
	ort=document.frm_adresse.ort.value;
	plz=document.frm_adresse.plz.value;
	email=document.frm_adresse.email.value;
	strasse=document.frm_adresse.strasse.value;
		
	if (vorname == "" ) {
		check_vorname="Vorname\n";
		counter++; }
		
	if (nachname == "" ) {
		check_nachname="Nachname\n";
		counter++; }
		
	if (ort == "" ) {
		check_ort="Wohnort\n";
		counter++; }
		
	if (plz == "" || isNaN(plz) || document.frm_adresse.plz.value.length!=5) {
		check_plz="PLZ\n";
		counter++; }
		
	if (email == "" ) {
		check_email="e-mail Adresse\n";
		counter++; }
		
	if (strasse == "" ) {
		check_strasse="Strasse & Hausnummer\n";
		counter++; }

	str_check = check_vorname + check_nachname + check_strasse + check_plz + check_ort + check_email;
	if (str_check != "")
	{
		if (counter<2) {
			alert("Folgendes Feld muß korrekt ausgefüllt werden, damit die Bestellung abgeschickt wird:\n"+str_check);
			return false;
		} else  {
			alert("Folgende Felder müssen korrekt ausgefüllt werden, damit die Bestellung abgeschickt wird:\n"+str_check);
			return false;
		}
	}
	else
	{
		if (!isValidEmail(email)) {
			alert("Du hast keine gültige eMail - Adresse eingegeben.");
			return false;
		} else {
			return true;
		}
	}
}

function calc(preis,anzahl,ergebnis,summe)
{
	ges_preis = preis * anzahl.value;
	ergebnis.value=ges_preis+".- €";
	sum(summe);
return true;
}

function sum(summe)
{
	summe.value = parseInt(document.form1[8].value) +  parseInt(document.form1[10].value) +  parseInt(document.form1[12].value) + ".- €";
return true;
}

function checkNumber(myValue)
{
	if (isNaN(myValue.value))
		myValue.value="0";
	
	return true;
}

function isTelNr(telnr) {
	var validExp = /[^0-9 \/_.-]/i;
	var validTest = validExp.test(telnr);
	if(validTest == false)
		return true;
	else
		return false;
}

