/**
* Alles was mit den Menus zu tun hat, ist hier zu finden
*/


/*
* Prüft ob das Kommentar-Formular richtig ausgefüllt wurde.
*/
function checknewcommentform(){
  if (document.getElementById("newcommentname").value == "") {
    alert('Gib deinen Namen an'); 
    return false;
  }
  else if (document.getElementById("newcommentcomment").value == ""){
    alert('Du hast keinen Kommentar geschrieben');
    return false;
  }
  else if (document.getElementById("newcommentcaptcha").value == ""){
    alert('Du hast den Code vom Captcha nicht eingegeben');
    return false;
  }
  else if (document.getElementById("newcommentsid").value == ""){
    alert('Systemfehler: Es wurde keine Seiten ID uebertragen');
    return false;
  }
  else return true;
}

/*
* erstellt einen neuen Commentar
*/
var commentanfrage=null;


function newcomment(){
  if (checknewcommentform()){
    commentanfrage = erzeugeAnfrage();
    commentanfrage.onreadystatechange = newcommentupdatesite;
    commentanfrage.open('POST', 'scripts/comment_ajax.php', true);
    commentanfrage.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    commentanfrage.send(
	  "name="      +document.getElementById("newcommentname").value
      +"&comment=" +document.getElementById("newcommentcomment").value
      +"&homepage="+document.getElementById("newcommenthomepage").value
      +"&email="   +document.getElementById("newcommentemail").value
      +"&sid="     +document.getElementById("newcommentsid").value
	  +"&captcha=" +document.getElementById("newcommentcaptcha").value  
    );
  }
}



/*
* wenn eine Antwort vom Server kommt, verarbeite sie
*/
function newcommentupdatesite(){
  if (commentanfrage.readyState == 4){ //der Server ist mit der Anfrage fertig
    if (commentanfrage.status == 200) { //Die Antwort ist in Ordnung
	  var antwort = commentanfrage.responseText; //Text aus der Antwort holen
      alert(antwort); //Gib die Antwort zum Benutzer per alert-Meldung
      
	  if (antwort == "Dein Kommentar wurde gespeichert."){
        location.reload();
	  }
	  else {
	    document.getElementById("newcommentcaptcha").value = "";
	    new_freecap();
	  }
    }
  }
}
