function checkEmail(emailFieldName) {
    // this function checks for a well-formed e-mail address
    // in the format:
    // user@domain.com

    // this requires prototype library loaded
    emailAddr = $F(emailFieldName);
    var i;

    // check for @
    i = emailAddr.indexOf("@");
    if (i == -1) {
        return false;
    }

    // separate the user name and domain
    var username = emailAddr.substring(0, i);
    var domain = emailAddr.substring(i + 1, emailAddr.length)

    // look for spaces at the beginning of the username
    i = 0;
    while ((username.substring(i, i + 1) == " ") && (i < username.length)) {
        i++;
    }
    // remove any found
    if (i > 0) {
        username = username.substring(i, username.length);
    }

    // look for spaces at the end of the domain
    i = domain.length - 1;
    while ((domain.substring(i, i + 1) == " ") && (i >= 0)) {
        i--;
    }
    // remove any found
    if (i < (domain.length - 1)) {
        domain = domain.substring(0, i + 1);
    }

    // make sure neither the username nor domain is blank
    if ((username == "") || (domain == "")) {
        return false;
    }

    // check for bad characters in the username
    var ch;
    for (i = 0; i < username.length; i++) {
        ch = (username.substring(i, i + 1)).toLowerCase();
        if (!(((ch >= "a") && (ch <= "z")) ||
            ((ch >= "0") && (ch <= "9")) ||
            (ch == "_") || (ch == "-") || (ch == "."))) {
                return false;
        }
    }

    // check for bad characters in the domain
    for (i = 0; i < domain.length; i++) {
        ch = (domain.substring(i, i + 1)).toLowerCase();
        if (!(((ch >= "a") && (ch <= "z")) ||
            ((ch >= "0") && (ch <= "9")) ||
            (ch == "_") || (ch == "-") || (ch == "."))) {
                return false;
        }
    }

    // check for . in domain (AVS)
    p = domain.indexOf(".");
    if (p == -1) {
        return false;
    }

    return true;
}

function klar(obj, defText)
{
    if(obj.value == defText)
    {
        obj.value = '';
    }
    return true;
}

function kopie(emailFieldName, zielName)
{
    ziel = $(zielName);

    if ( checkEmail(emailFieldName) )
    {
        ziel.checked = true;
        ziel.disabled = false;
    } else
    {
        ziel.checked = false;
        ziel.disabled = true;
    }
}

function disableOnStart(zielName)
{
    $(ziel).disabled = true;
}

function noError(obj)
{
  $(obj).removeClassName('error');
}

function hasError(obj)
{
  $(obj).addClassName('error');
}

function checkValue(obj)
{
  if ( $(obj).value == '' )
  {
    hasError('label_' + obj);
  } else
  {
    noError('label_' + obj);
  }
  
  if ( obj == 'EMail' )
  {
    if ( ! checkEmail('EMail') )
    {
      alert('Die eingegebene E-Mail-Adresse scheint nicht korrekt zu sein. Möglicherweise haben Sie sich vertippt. Bitte überprüfen Sie die Eingabe.');
      hasError('label_EMail');
      $('EMail').activate();
    }
    
  }
}

function enableRekla()
{
  eff = Effect.BlindDown($('reklamation'), {duration:0.3});
  $('label_Nachricht').update('Grund Ihrer Reklamation:');
}

function checkReceip()
{
  var empfaenger = $('Empfaenger').options;
  var isRekla = false;  
  
  for ( i = 0; i < empfaenger.length; i++ )
  {
    if ( empfaenger[i].selected == true && empfaenger[i].value == 'qurek' )
    {
      //alert(empfaenger[i].value);
      enableRekla();
      isRekla = true;
      break;
    }
  }
  
  if ( ! isRekla )
  {
    eff = Effect.BlindUp($('reklamation'), {duration:0.3});
    $('label_Nachricht').update('Ihre Nachricht:');
  }
}
















