// JavaScript Document
//-----------------------------------------------------------------------------------------------
var defaultEmptyOK = false


function isInteger (s)
{

var i;

if (isEmpty(s))
    if (isInteger.arguments.length == 1) return defaultEmptyOK;
   else return (isInteger.arguments[1] == true);
   for (i = 0; i < s.length; i++)
    {
         // Check that current character is number.
         var c = s.charAt(i);
         if (!isDigit(c)) return false;
    }
// All characters are numbers.
return true;
}

//------------------------------------------------------------------------------------------------

// Returns true if character c is a digit
// (0 .. 9).

function isDigit (c)
{
    return ((c >= "0") && (c <= "9"));
}

//------------------------------------------------------------------------------------------------

function isEmpty(s)
{

var whitespace = new String(" ");

//   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 == null) || (s.length == 0))
}
//------------------------------------------------------------------------------------------------

function isFloat (s)

{
    var i;
    var decimalPointDelimiter = "."
	var decimalPointDelimiter2 = ","
    var seenDecimalPoint = false;

   if (isEmpty(s)) 
       if (isFloat.arguments.length == 1) return false;
      else return (isFloat.arguments[1] == true);

  if ((s == decimalPointDelimiter)||(s == decimalPointDelimiter2)) return false;
//   if (s == decimalPointDelimiter) return false;

   // Search through string's characters one by one
   // until we find a non-numeric character.
   // When we do, return false; if we don't, return true.

   for (i = 0; i < s.length; i++)
   {   
        // Check that current character is number.
       var c = s.charAt(i);

  //     if ( (c == decimalPointDelimiter) && !seenDecimalPoint) seenDecimalPoint = true;
    if ( ((c == decimalPointDelimiter) || (c == decimalPointDelimiter2)) && !seenDecimalPoint) seenDecimalPoint = true;
       else if (!isDigit(c)) return false;
   }

   // All characters are numbers.
   return true;
}

//------------------------------------------------------------------------------------------------

// isNegativeInteger (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if string s is an integer < 0.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isNegativeInteger (s)
{   var secondArg = defaultEmptyOK;

   if (isNegativeInteger.arguments.length > 1)
       secondArg = isNegativeInteger.arguments[1];

   // The next line is a bit byzantine.  What it means is:
   // a) s must be a signed integer, AND
   // b) one of the following must be true:
   //    i)  s is empty and we are supposed to return true for
   //        empty strings
   //    ii) this is a negative, not positive, number

   return (isSignedInteger(s, secondArg)
        && ( (isEmpty(s) && secondArg)  || (parseInt (s) < 0) ) );

}

//------------------------------------------------------------------------------------------------

// isIntegerInRange (STRING s, INTEGER a, INTEGER b [, BOOLEAN emptyOK])
// 
// isIntegerInRange returns true if string s is an integer 
// within the range of integer arguments a and b, inclusive.
// 
// For explanation of optional argument emptyOK,
// see comments of function isInteger.


function isIntegerInRange (s, a, b)
{   if (isEmpty(s)) 
       if (isIntegerInRange.arguments.length == 1) return defaultEmptyOK;
      else return (isIntegerInRange.arguments[1] == true);

   // Catch non-integer strings to avoid creating a NaN below,
   // which isn't available on JavaScript 1.0 for Windows.
   if (!isInteger(s, false)) return false;

   // Now, explicitly change the type to integer via parseInt
   // so that the comparison code below will work both on 
    // JavaScript 1.2 (which typechecks in equality comparisons)
   // and JavaScript 1.1 and before (which doesn't).
   var num = parseInt (s);
   return ((num >= a) && (num <= b));
}

//------------------------------------------------------------------------------------------------

// isSignedFloat (STRING s [, BOOLEAN emptyOK])
// 
// True if string s is a signed or unsigned floating point 
// (real) number. First character is allowed to be + or -.
//
// Also returns true for unsigned integers. If you wish
// to distinguish between integers and floating point numbers,
// first call isSignedInteger, then call isSignedFloat.
//

// Does not accept exponential notation.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isSignedFloat (s)

{   if (isEmpty(s)) 
       if (isSignedFloat.arguments.length == 1) return defaultEmptyOK;
      else return (isSignedFloat.arguments[1] == true);

   else {
       var startPos = 0;
       var secondArg = defaultEmptyOK;

       if (isSignedFloat.arguments.length > 1)
           secondArg = isSignedFloat.arguments[1];

       // skip leading + or -
       if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
          startPos = 1;    
       return (isFloat(s.substring(startPos, s.length), secondArg))
   }
}
//------------------------------------------------------------------------------------------------

// removes all spaces from a string

function trim (s)
{
    var iLen = s.length;
    var sOut = "";
    var chr = "";

    for (var i=0; i<iLen; i++)
    {
         chr = s.charAt (i); 
          if (chr!=" ")
         {
              sOut = sOut + chr; 
          }
    }
    return sOut;
}



//------------------------------------------------------------------------------------------------

function isAlphaNumeric(s)
{
  var validChars = "abcdefghijklmnopqrstuvwxyz0123456789";
  s = s.toLowerCase();
  
   for (var i = 0; i < s.length; i++) 
   {
     if (validChars.indexOf(s.charAt(i)) == -1)
     return false;
  }
  return true; 
  }
  
//---------------------------------------------------------------------------------------------------

function VerifeMail(adresse)
	{
	//adresse = document.form1.zugemail.value;
	var place = adresse.indexOf("@",1);
	var point = adresse.indexOf(".",place+1);
	if ((place > -1)&&(adresse.length >2)&&(point > 1))
		{
		return true;
		}
	else
		{
		return false;
		}
	}

function trim(str)
{ 
	while (str.substring(str.length-1,str.length)==' ')
	str = str.substring(0, str.length-1);

	while (str.substring(1,0)==' ')
	str = str.substring(1,str.length);

	return str;
}
function nachoben()
{
	//window.scrollTo(0,0); // nach oben - nur für IE
	document.body.scrollTop = 0; // nach oben - funktioniert überall außer NN4.x
	//document.body.scrollTop = document.body.scrollHeight - document.body.clientHeight; // nach unten - funktioniert überall außer NN4.x
}

function VerifeSuchFeld(event)
{
	if (event.keyCode==13)
	{
		SucheChk();
		return false;
	}
	
}

function SucheChk()
{
	var feld, sstr
	
		feld=document.suchform.suchen;
		sstr=feld.value;
		sstr=trim(sstr);

		if ((isEmpty(sstr)==true) || (sstr.length<3))
		{
    		alert("Sie sollen mindestens drei Buchstaben eingeben.");
    		feld.focus();
			return false;
		}
		else 
		{
			document.suchform.submit();
		}
}

function nWin(trg,param)
 { //v3.0
  var newWindow, trg, param
  newWindow = window.open(trg,"subWind", param);
  newWindow.focus();
}



/******************************************************************************************************************/
// setzen eines Cookies

function Set_Cookie( name, value, expires, path, domain, secure ) 
{
	// Zeit setzen, in millisekunden
	var today = new Date();
	today.setTime( today.getTime() );
	
	if ( expires )																									// Prüfen, ob die Gültigkeit des Cookies geändert werden soll
	{
		expires = expires * 1000 * 60 * 60 * 24;																	// expires: Zeit in Tagen
		//expires = expires * 1000 * 60 * 60;																		// expires: Zeit in Stunden
		//expires = expires * 1000 * 60;																			// expires: Zeit in Minuten
	}
	
	// GüligkeitsDatum wird in Variable geschrieben
	var expires_date = new Date( today.getTime() + (expires) );
	
	// Cookie wird mit den angegebenen Parametern gesetzt
	document.cookie = name + "=" +escape( value ) +																	// Name des Cookies
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 												// Gültigkeit wird gesetzt, wenn angegeben
	( ( path ) ? ";path=" + path : "" ) + 																			// Pfad wird gesetzt, wenn angegeben
	( ( domain ) ? ";domain=" + domain : "" ) +																		// domain wird gesetzt, wenn angegeben
	( ( secure ) ? ";secure" : "" );																				// secure wird gesetzt, wenn angegeben
}
/******************************************************************************************************************/
	
/******************************************************************************************************************/
// lesen eines Cookies
function Get_Cookie( name )
{
	var start = document.cookie.indexOf( name + "=" );																// Inhalt des Cookie in Variable Start schreiben
	var len = start + name.length + 1;																				// Ermitteln der String - Länge
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) )									// Prüfen, ob Cookie mit den angegebenen Werten existiert
	{
		return null;																								// Rückgabewert NULL
	}
	if ( start == -1 )																								// Prüfen, ob start -1 ist: kein Cookie mit gesuchtem Namen gefunden
	{
		return null;																								// Rückgabewert NULL
	}
	var end = document.cookie.indexOf( ";", len );																	// Wert des Cookies in variabele end speichern
	if ( end == -1 )																								// Prüfen, ob end -1 ist: das ;-Zeichen wurde nicht gefunden -> im Cookie stehen keine weiteren Angaben
	{
		end = document.cookie.length;																				// Gesamtlänge des Strings speichern
	}
	return unescape( document.cookie.substring( len, end ) );														// Rückgabewert ist Inhalt des Cookies (Wert zwischen [CookieName]= und ; bzw. wenn keine weiteren Werte angegeben wurden alles ab [CookieName]=
}
/******************************************************************************************************************/
	
/******************************************************************************************************************/
// löschen eines Cookies
function Delete_Cookie( name, path, domain )
{
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +														// Prüfen, ob das Cookie exitiert
	( ( path ) ? ";path=" + path : "") +
	( ( domain ) ? ";domain=" + domain : "" ) +
	";expires=Thu, 01-Jan-1970 00:00:01 GMT";																		// Gültigkeitsdatum wird neu auf ein Datum in der Vergangenheit gesetzt
}
/******************************************************************************************************************/
function checkContactForm() {
	Err	=	false;
	for( i=0; i<checkContactForm.arguments.length; i++ ) {
		TFArray	=	document.getElementsByName( checkContactForm.arguments[ i ] );
		if( TFArray.length > 0 ) {
			if( TFArray[ 0 ].value == "" ) {
				TFArray[ 0 ].style.backgroundColor	=	"#FAA";
				Err	=	true;
			}
			else {
				TFArray[ 0 ].style.backgroundColor	=	"";
			}
		}
	}
	if( Err ) {
		if( Kontaktfehler ) {
			alert( Kontaktfehler );	
		}
		else {
			alert( "Bitte füllen Sie alle markierten Felder aus." );
		}
	}
	return	!Err;
}
function submitCallback() {
	if( checkCallBack() ) {
		document.callback.submit();	
	}
}
function checkCallBack() {
	Required	=	Array( "callback_name", "callback_phone", "callback_notes" );
	Error		=	false;
	for( i=0; i<Required.length; i++ ) {
		if( Ele = get( Required[ i ] ) ) {
			if( Ele.value == "" || Ele.value == Ele.title  ) {	
				Error	=	true;
				Ele.style.backgroundColor	=	"#FF8888";
			}
			else {
				Ele.style.backgroundColor	=	"";
			}
		}
		else {
			Error	=	true;	
		}
	}
	return	!Error;	
}
function focusField( Ele ) {
	if( Ele.value == Ele.title ) {
		Ele.value	=	"";	
	}
}
function blurField( Ele ) {
	if( Ele.value == "" ) {
		Ele.value	=	Ele.title;	
	}
}
