// 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();
}
function showDiv( ID ) {
	if( Div = get( ID ) ) {
		Div.style.display	=	"block";	
	}
}
function hideDiv( ID ) {
	if( Div = get( ID ) ) {
		Div.style.display	=	"none";	
	}
}
function get( ID ) {
	return	document.getElementById( ID );	
}
function checkContactForm() {
	Required	=	Array( "Vorname", "Name", "Strasse", "PLZ", "Ort", "Email", "Sicherheitscode", "Nachricht" );	
	Error		=	false;
	MailError	=	false;
	First		=	-1;
	for( i=0; i<Required.length; i++ ) {
		if( TF = get( Required[ i ] ) ) {
			if( TF.value == "" ) {
				TF.focus();
				if( !Error ) {
					First	=	i;
				}
				Error	=	true;
			}
			if( Required[ i ] == "Email" ) {
				if( !checkMail( TF.value ) ) {
					TF.focus();
					if( !Error ) {
						First	=	i;
					}
					MailError	=	true;
					Error		=	true;
				}
			}
		}
	}
	if( Error ) {
		if( TF = get( Required[ First ] ) ) {
			TF.focus();	
		}
		if( MailError ) {
			alert( "Bitte füllen Sie alle notwendigen Felder aus. Geben Sie eine korrekte E-Mail Adresse an." );
		}
		else {
			alert( "Bitte füllen Sie alle notwendigen Felder aus." );
		}
		return	false;
	}
}
function checkApplicationForm() {
	Required	=	Array( "Vorname", "Name", "Strasse", "PLZ", "Ort", "Familienstand", "Staatsangehoerigkeit", "Berufsbezeichnung", "Sicherheitscode" );	
	Error		=	false;
	MailError	=	false;
	NumberError	=	false;
	First		=	-1;
	for( i=0; i<Required.length; i++ ) {
		if( TF = get( Required[ i ] ) ) {
			if( TF.value == "" ) {
				TF.focus();
				if( !Error ) {
					First	=	i;
				}
				Error	=	true;
			}
			if( Required[ i ] == "Email" ) {
				if( !checkMail( TF.value ) ) {
					TF.focus();
					if( !Error ) {
						First	=	i;
					}
					MailError	=	true;
					Error		=	true;
				}
			}
			if( Required[ i ] == "EinsatzOrtPLZ" ) {
				Val	=	TF.value;
				if( isNaN( Val ) || Val.length != 2 ) {
					if( !Error ) {
						First	=	i;
					}
					TF.value	=	"";
					TF.focus();
					NumberError	=	true;
					Error		=	true;
				}
			}
		}
	}
	if( Error ) {
		if( TF = get( Required[ First ] ) ) {
			TF.focus();	
		}
		Text	=	"Bitte füllen Sie alle notwendigen Felder aus.";
		if( MailError ) {
			Text	+=	"\nBitte geben Sie eine korrekte E-Mail Adresse ein.";	
		}
		if( NumberError ) {
			Text	+=	"\nBitte geben Sie als Einsatzort die ersten zwei Stellen\nIhres Postleitzahlengebietes ein. (z.B. 89)";	
		}
		alert( Text );
		return	false;
	}
}
LastReiter	=	0;
function changeReiter( ID ) {
	hideReiter( LastReiter );
	showReiter( ID );
	LastReiter	=	ID;
}
function showReiter( ID ) {
	if( Div = get( "reiterclick" + ID ) ) {
		Div.className	=	"clickdivsel";
	}
	if( Div = get( "reiterdiv" + ID ) ) {
		Div.style.display	=	"block";	
	}
}
function hideReiter( ID ) {
	if( Div = get( "reiterclick" + ID ) ) {
		Div.className	=	"clickdiv";
	}
	if( Div = get( "reiterdiv" + ID ) ) {
		Div.style.display	=	"none";	
	}
}
function changePerSite( SF ) {
	location.href	+=	"&persite=" + SF.options[ SF.selectedIndex ].value;
}
function over( TR ) {
	TR.className	=	"rowover";	
}
function out( TR ) {
	TR.className	=	"";	
}
LastFormreiter	=	0;
function showFormreiter( ID ) {
	if( LastFormreiter != ID ) {
		if( Table = get( "Formreiter" + LastFormreiter ) ) {
			Table.style.display	=	"none";	
		}
		if( Href = get( "formreiterlink" + LastFormreiter ) ) {
			Href.className	=	"";	
		}
		LastFormreiter	=	ID;
		if( Table = get( "Formreiter" + LastFormreiter ) ) {
			Table.style.display	=	"block";	
		}
		if( Href = get( "formreiterlink" + LastFormreiter ) ) {
			Href.className	=	"sel";	
		}
	}
}
function multiselectclick( SF ) {
	SelIDs	=	Array();
	for( j=0; j<SF.options.length; j++ ) {
		if( SF.options[ j ].selected ) {
			SelIDs.push( SF.options[ j ].value );	
		}
	}
	switch( SelIDs.length ) {
		case 0:	// keine ausgewaehlt - evtl. nur gescrollt
			break;
		case 1: // ein direkter klick
			for( j=0; j<SF.options.length; j++ ) {
				NewID	=	SF.options[ j ].value;
				T_Index	=	getIndexOf( MultiselectIDs, NewID );
				if( SF.options[ j ].selected ) {
					if( T_Index > -1 ) {
						MultiselectIDs	=	remEle( MultiselectIDs, T_Index );
						SF.options[ j ].selected	=	false;
					}
					else {
						MultiselectIDs.push( NewID );
					}
				}
				else {
					if( T_Index > -1 ) {
						SF.options[ j ].selected	=	true;	
					}
				}			
			}
			break;
		default: // mehrfachausmal per dragndrop
			MultiselectIDs	=	SelIDs;
			break;
	}
}
MultiselectIDs	=	Array();
function getIndexOf( Arr, Inhalt ) {
	for( i=0; i<Arr.length; i++ ) {
		if( Arr[ i ] == Inhalt ) {
			return	i;
		}
	}
	return	-1;
}
function remEle( Arr, Index ) {
	Erg	=	Array();
	for( i=0; i<Arr.length; i++ ) {
		if( i != Index ) {
			Erg.push( Arr[ i ] );
		}
	}
	return	Erg;
}
FormChange	=	false;
function formchanged( FormularID ) {
	FormChange	=	true;
	showHinweisliste( FormularID );
}
Formcheck	=	true;
LastFormID	=	"";
function showHinweisliste( FormularID, Markierung ) {
	if( Markierung == null ) {
		Markierung	=	false;	
	}
	Divtext	=	"";
	Divtext	+=	"<h3>Checkliste</h3>";
	Formcheck	=	true;
	CheckText	=	Array();
	ReqArrays	=	Array();
	LastFormID	=	FormularID;
	switch( FormularID ) {
		case "berufsbezeichnung":
			Required	=	Array( "Name" );
			ReqArrays.push( Required );
			CheckText.push( "Pflichtfelder" );
			break;
		case "bewerber":
			Required	=	Array( "Vorname", "Name", "Strasse", "PLZ", "Ort" );
			ReqArrays.push( Required );
			CheckText.push( "Adressdaten" );
			Required	=	Array( "Ueberschrift", "Beschreibung", "Branche" );
			ReqArrays.push( Required );
			CheckText.push( "Einsatzbereich" );
			break;
		case "branche":
			Required	=	Array( "Name" );
			ReqArrays.push( Required );
			CheckText.push( "Pflichtfelder" );
			break;
		case "firma":
			Required	=	Array( "Name", "Strasse", "PLZ", "Ort", "Ansprechpartner", "Branche" );
			ReqArrays.push( Required );
			CheckText.push( "Adressdaten" );
			break;
		case "job":
			Required	=	Array( "Name", "Strasse", "PLZ", "Ort", "Ansprechpartner", "Branche" );
			ReqArrays.push( Required );
			CheckText.push( "Adressdaten" );
			Required	=	Array( "JobTitel", "JobBeschreibung", "Anzahl" );
			ReqArrays.push( Required );
			CheckText.push( "Jobdetails" );
			break;
		default:
			break;
	}
	for( i=0; i<ReqArrays.length; i++ ) {
		Required	=	ReqArrays[ i ];
		Check	=	false;
		Some	=	false;
		for( j=0; j<Required.length; j++ ) {
			if( TF = get( Required[ j ] ) ) {
				Some	=	true;
				if( TF.value == "" ) {
					if( !Check ) {
						Divtext	+=	"<span>" + CheckText[ i ] + "<img src=\"/img/buttons_new/x.gif\" /><br />";
						Formcheck	=	false;
						Check	=	true;
					}
					else {
						Divtext	+=	"<br />";
					}
					Divtext	+=	"<i>- " + Required[ j ] + " erforderlich.</i>";
					if( Markierung ) {
						TF.style.backgroundColor	=	"#FCC";	
					}
				}
				else {
					TF.style.backgroundColor		=	"";	
				}
			}
		}
		if( Some ) {
			if( !Check ) {
				Divtext	+=	"<span>" + CheckText[ i ] + "<img src=\"/img/buttons_new/hacken.gif\" />";	
			}
			Divtext	+=	"</span><br />\n";
		}
	}
	if( Div = get( "HINWEISLISTE" ) ) {
		Reiter	=	get( "Formreiter" + LastFormreiter );
		Div.style.height	=	Reiter.offsetHeight + "px";
		if( Div2 = get( "MODULES" ) ) {
			if( Div.offsetHeight + 120 > Div2.offsetHeight ) {
				Div2.style.height	=	( Div.offsetHeight + 120 ) + "px";	
			}
		}
		if( Reiter.offsetHeight != Div.offsetHeight ) {
//			Reiter.style.height	=	Div.offsetHeight + "px";
		}
		Div.innerHTML	=	Divtext;
	}
}
function isformchanged() {
	if( FormChange ) {
		if( !confirm( "Sie haben Daten im Formular geändert und noch nicht gespeichert.\nMöchten Sie ohne die Speicherung der Daten fortfahren?" ) ) {
			return	false;			
		}
		else {
			FormChange	=	false;
		}
	}
	return	true;
}
function checkForm() {
	showHinweisliste( LastFormID, true );
	if( !Formcheck ) {
		alert( "Bitte füllen Sie alle notwendigen Felder aus." );
		return	false;
	}
}
function checkIntKey( E ) {
	if( !E ) {
    	E	=	window.event;
		alert( "check" );
	}
	KC	=	E.keyCode;
	if( KC > 47 && KC < 58 || KC == 13 || KC == 8 || KC == 37|| KC == 38 || KC == 39 || KC == 40 || KC == 9 || KC == 46 || ( KC > 95 && KC < 106 ) ) {
		return	true;
	}
	else {
		alert( "Es sind nur Zahlen als Eingabeformat erlaubt." );	
	}
	return	false;	
}
function resetSearchForm() {
	Leeren	=	Array( "Von", "Bis", "keyword" );
	for( i=0; i<Leeren.length; i++ ) {
		if( TF = get( Leeren[ i ] ) ) {
			TF.value	=	"";
		}
	}
	document.forms[ 0 ].submit();	
}
function checkEmptyTitle( SF, ID ) {
	if( TF = get( ID) ) {
		if( TF.value == "" ) {
			TF.value	=	SF.options[ SF.selectedIndex ].text;	
		}
	}
}
