function ToggleCheckBoxes(FieldName) {
  var checks    = document.getElementsByName(FieldName);
  var boxLength = checks.length;

  if ( checks[0].checked == true )
    for ( i=0; i < boxLength; i++ ) checks[i].checked = false;
  else
    for ( i=0; i < boxLength; i++ ) checks[i].checked = true;
}

function chk_max_codes() {
 var chks = document.Formular2.elements['NeueCodes[]'];
 var count = 0;
 var maxvalue = document.Formular2.max_key_codes.value;

 for (var i=0;i<chks.length;i++)
    if (chks[i].checked) count +=1;
 if (count > maxvalue) {
    alert("Sorry, selection is limited to " + maxvalue + " items only");
    return false;
 }
 return true;
}

function chkformular()
{

if(document.Formular1.language.value == "l2") {
 iOrganisation       = "Organisation name missing!";
 iStreet     = "Street missing!";
 iZip         = "Postal Code missing!";
 iCity         = "City missing!";
 iRegion      = "Region/Country missing";
 iTelefon     = "Phone missing!";
 iMail        = "E-Mail address missing or wrong!";
 iFoundet       = "Year of foundation missing";
 iMitarbeiter = "Number of employees missing";
 iBusinessTyp = "Organisation Type missing";
 iGender      = "Gender (Mr/Ms) missing";
 iFirstname     = "First Name missing!";
 iLastname    = "Last Name missing!";
 iLanguage     = "Which language do you speak?";
 iBranche     = "Thematic areas (branch) missing!";
 iPasswort    = "Passwort missing or to short (min. 4 characters)!";
 iOnline      = "Should your Expert status be accessible via Internet?";
 iAntispam    = "Anti-Spam Code missing or wrong!";
}
else if (document.Formular1.language.value == "l1") {
 iOrganisation       = "Bitte einen Firmennamen eingeben!";
 iStreet      = "Bitte eine Straße eingeben!";
 iZip         = "Bitte eine Postleitzahl eingeben!";
 iCity        = "Bitte einen Ort eingeben!";
 iRegion      = "Bitte eine Region auswählen";
 iTelefon     = "Bitte eine Telefonnummer eingeben!";
 iMail        = "E-Mail addresse fehlt oder fehlerhaft!";
 iFoundet     = "Bitte Gründungsjahr angeben";
 iMitarbeiter = "Bitte Zahl der Mitarbeiter angeben";
 iBusinessTyp = "Bitte den Unternehmenstyp angeben";
 iGender      = "Bitte Gender Herr/Frau angeben";
 iFirstname   = "Bitte einen Vornamen angeben!";
 iLastname    = "Bitte einen Nachnamen angeben!";
 iLanguage    = "Welche Sprachen sprechen Sie?";
 iBranche     = "Bitte eine Branche auswählen";
 iPasswort    = "Bitte ein Passwort angeben (min. 4 Zeichen)!";
 iOnline      = "Soll Ihr Expertenprofil über Internet öffentlich zugänglich sein?";
 iAntispam    = "Anti-Spam Code fehlt bzw. falsch!";
}
else {
 iOrganisation = "Nom de l’organisation à spécifier!"; 
 iStreet      = "Rue à spécifier!"; 
 iZip         = "Code postal à spécifier!";
 iCity        = "Nom de la ville à spécifier!";
 iRegion      = "Région/pays à spécifier!";
 iTelefon     = "Téléphone à spécifier!";
 iMail        = "Adresse email manquante ou incorrecte!";
 iFoundet     = "Année de fondation à spécifier!";
 iMitarbeiter = "Nombre d’employés à spécifier!";
 iBusinessTyp = "Type d’organisation à spécifier!";
 iGender      = "Salutations (Mr/Mme) à spécifier!";
 iFirstname   = "Prénom à spécifier!";
 iLastname    = "Nom à spécifier!";
 iLanguage    = "Veuillez spécifier la langue souhaitée.";
 iBranche     = "Secteurs à spécifier!";
 iPasswort    = "Mot de passe manquant ou trop court (min 4 caractères)!";
 iOnline      = "Voulez-vous publier votre statut d’expert sur Internet?";
 iAntispam    = "Code anti-spam manquant ou incorrect!";
}

if(document.Formular1.organisation.value == "")
 { alert(iOrganisation);
   document.Formular1.organisation.focus();
   return false; }

if(document.Formular1.street.value == "")
 { alert(iStreet);
   document.Formular1.street.focus();
   return false; }

if(document.Formular1.zip.value == "")
 { alert(iZip);
   document.Formular1.zip.focus();
   return false; }

if(document.Formular1.city.value == "")
 { alert(iCity);
   document.Formular1.city.focus();
   return false; }

/* Unterschiedliche Abfrage bei select / radio */

if (document.Formular1.region.selectedIndex < 2)
{ alert(iRegion);
  document.Formular1.region.focus();
  return false; }


if(document.Formular1.telefon.value == "")
 { alert(iTelefon);
   document.Formular1.telefon.focus();
   return false; }

if(chk_mail(document.Formular1.clientmail.value) == false)
 { alert(iMail);
   document.Formular1.clientmail.focus();
   return false; }


if(document.Formular1.founded)
{
 if(document.Formular1.founded.value == "")
  { alert(iFoundet);
    document.Formular1.founded.focus();
    return false; }
}

if(document.Formular1.business)
{
 var business_ok = false;
 for (var i=0; i<document.Formular1.business.length; i++)
    if (document.Formular1.business[i].checked) business_ok = true;
 if (!business_ok) { alert(iBusinessTyp);
                   document.Formular1.business[0].focus();
                   return false; }
}

if(document.Formular1.employees)
{
 var employees_ok = false;
 for (var i=0; i<document.Formular1.employees.length; i++)
    if (document.Formular1.employees[i].checked) employees_ok = true;
 if (!employees_ok) { alert(iMitarbeiter);
                   document.Formular1.employees[0].focus();
                   return false; }
}

if(document.Formular1.gender[0].checked == false &&
   document.Formular1.gender[1].checked == false )
 { alert(iGender);
   document.Formular1.gender[0].focus();
   return false; }

if(document.Formular1.firstname.value == "")
 { alert(iFirstname);
   document.Formular1.firstname.focus();
   return false; }

if(document.Formular1.lastname.value == "")
 { alert(iLastname);
   document.Formular1.lastname.focus();
   return false; }

/*
var chks = document.Formular1.elements['branche[]'];
var count = 0;
for (var i=0;i<chks.length;i++)
   if (chks[i].checked) count +=1;
if (count == 0) { alert(iBranche);
                  chks[0].focus();
                  return false;
                }
*/

if(document.Formular1.passkunde.value.length < 4)
 { alert(iPasswort);
   document.Formular1.passkunde.focus();
   return false; }

if(document.Formular1.antispam && document.Formular1.antispam.value != document.Formular1.antispam2.value)
 { alert(iAntispam);
   document.Formular1.antispam.focus();
   return false; }


} // ###############  Ende Check Formular  #############################


 function chkEOIForm()
  {
   if(document.Formular.language.value == "l2") {
     Message     = "Please answer the following fields (min. 50 characters)!! Read also 'Why do we ask this questions'";
     iName       = "Please enter name!";
     iCompany    = "Please enter organisation name!";
     iCity       = "Please insert City!";
     iPhone      = "Please insert phone number!";
     iEmail      = "Please insert an Email address!";
     iEmailError = "No valid Email address!";
     iAntispam   = "Anti-Spam Code missing or wrong!";
     iEENOffice  = "Please choose an office.";
  }
   else if (document.Formular.language.value == "l1") {
     Message     = "Bitte diese Felder ausfüllen (min. 50 Zeichen)!! Siehe auch 'Warum stellen wir diese Fragen'";
     iName       = "Bitte Ihren Namen eingeben!";
     iCompany    = "Bitte Firma eingeben!";
     iCity       = "Bitte Ort eingeben!";
     iPhone      = "Bitte Telefonnummer eingeben!";
     iEmail      = "Bitte Ihre E-Mail-Adresse eingeben!";
     iEmailError = "Keine gültige E-Mail Adresse!";
     iAntispam   = "Anti-Spam Code fehlt bzw. falsch!";
     iEENOffice  = "Bitte wählen Sie das für Sie zuständige Landesbüro aus.";
  }
  else {
     Message     = "Veuillez compléter les champs suivants (min. 50 caractères)!! Veuillez aussi lire 'Pourquoi posons-nous ces questions'";  
     iName       = "Veuillez spécifier le nom de famille!";
     iCompany    = "Veuillez spécifier le nom de l'organisation!";
     iCity       = "Veuillez spécifier le nom de la ville!";
     iPhone      = "Veuillez spécifier le numéro de téléphone!";
     iEmail      = "Veuillez spécifier l'adresse e-mail!";
     iEmailError = "Adresse e-mail incorrecte!";
     iAntispam   = "Code anti-spam manquant ou incorrect!";
     iEENOffice  = "Choisissez le partenaire que vous souhaitez contacter.";
  }

   if(document.Formular.Frage1.value.length < 50)
    { alert(Message);
      document.Formular.Frage1.focus();
      return false; }

   if(document.Formular.Frage3.value.length < 50)
    { alert(Message);
      document.Formular.Frage3.focus();
      return false; }

   if(document.Formular.Frage4.value.length < 50)
    { alert(Message);
      document.Formular.Frage4.focus();
      return false; }

   if(document.Formular.name.value == "")
    { alert(iName);
      document.Formular.name.focus();
      return false; }

   if(document.Formular.organisation.value == "")
    { alert(iCompany);
      document.Formular.organisation.focus();
      return false; }

   if(document.Formular.city.value == "")
    { alert(iCity);
      document.Formular.city.focus();
      return false; }

   if(document.Formular.telefon.value == "")
    { alert(iPhone);
      document.Formular.telefon.focus();
      return false;  }

   if(document.Formular.clientmail.value == "")
    { alert(iEmail);
      document.Formular.clientmail.focus();
      return false; }

   if(document.Formular.clientmail.value.indexOf('@') == -1)
    { alert(iEmailError);
      document.Formular.clientmail.focus();
      return false;  }

   if(document.Formular.antispam.value == "")
    { alert(iAntispam);
      document.Formular.antispam.focus();
      return false;  }

   if(document.Formular.eenbuero)
    { var eenbuero_ok = false;
      for (var i=0; i<document.Formular.eenbuero.length; i++)
        if (document.Formular.eenbuero[i].checked) eenbuero_ok = true;
      if (!eenbuero_ok) { alert(iEENOffice);
                          document.Formular.eenbuero[0].focus();
                          return false;
                        }
    }
}


function isInt(wert) {
  if (wert == "") return false;
  for (i=0; i<4;i++) {
    if (wert.charAt(i) < "0") { return false; }
    if (wert.charAt(i) > "9") { return false; }
  }
}

function chk_mail(s)
{
 var a = false;
 var res = false;
 if(typeof(RegExp) == 'function')
 {
  var b = new RegExp('abc');
  if(b.test('abc') == true){a = true;}
  }

 if(a == true)
 {
  reg = new RegExp('^([a-zA-Z0-9\\-\\.\\_]+)'+
                   '(\\@)([a-zA-Z0-9\\-\\.]+)'+
                   '(\\.)([a-zA-Z]{2,4})$');
  res = (reg.test(s));
 }
 else
 {
  res = (s.search('@') >= 1 &&
         s.lastIndexOf('.') > s.search('@') &&
         s.lastIndexOf('.') >= s.length-5)
 }
 return(res);
}
