function replaceEntities(eingabe) 
{
  rohtext = eingabe.replace(/\r\n/g,"\n");
  var ausgabe = "";
  for(var n=0; n < eingabe.length; n++)
  {
    var c=eingabe.charCodeAt(n);
    if (c == 8222 || c == 8220) //Anf?hrungszeichen oben/unten werden ersetzt
    {
      ausgabe += '"';
    }
    else if (c == 8218 || c == 8217)
    {
      ausgabe += "'";
    }
    else if (c < 256) //Ansonsten nur ANSI erlaubt, alle sonstigen Entities werden gel?scht
    {
      ausgabe += String.fromCharCode(c);
    }
  }
  return ausgabe;
}    

function replaceInput(inputName)
{
  var myText = document.getElementById(inputName).value;              
  //Variante 1
  myText = replaceEntities(myText);

  //Variante 2
  /*
  myText = myText.replace(/("|")/g, '"');
  myText = myText.replace(/(,|')/g, "'");
  */
              
  document.getElementById(inputName).value = myText; 
}
	
function submitWithEntities(formName, inputNames)
{
  try
  {
    var arrayInputNames = inputNames.split(",");
    for(var i = 0; i < arrayInputNames.length; i++)
    {
      replaceInput(arrayInputNames[i]);
    }
  }catch(e){}
  document.getElementById(formName).submit();
}

function submitWithEntities(formName, inputNames, anker)
{
  try
  {
    var arrayInputNames = inputNames.split(",");
    for(var i = 0; i < arrayInputNames.length; i++)
    {
      replaceInput(arrayInputNames[i]);
    }
  }catch(e){}
  document.getElementById(formName).action = '#' + anker;
  document.getElementById(formName).submit();
}

function decode_utf8(utftext) 
{
  try
  {
    var plaintext = ""; var i=0; var c=c1=c2=0;
    // while-Schleife, weil einige Zeichen uebersprungen werden
    while(i<utftext.length)
    {
      c = utftext.charCodeAt(i);
      if (c<128) 
      {
        plaintext += String.fromCharCode(c);
        i++;
      }
      else if((c>191) && (c<224)) 
      {
        c2 = utftext.charCodeAt(i+1);
        plaintext += String.fromCharCode(((c&31)<<6) | (c2&63));
        i+=2;
      }
      else 
      {
        c2 = utftext.charCodeAt(i+1); c3 = utftext.charCodeAt(i+2);
        plaintext += String.fromCharCode(((c&15)<<12) | ((c2&63)<<6) | (c3&63));
        i+=3;
      }
    }
    return plaintext;
  }
  catch(e)
  {
    return utftext;
  }
}

