
var XMLHTTP = null;

if (window.XMLHttpRequest) {
  XMLHTTP = new XMLHttpRequest();
} else if (window.ActiveXObject) {
  try {
    XMLHTTP = 
      new ActiveXObject("Msxml2.XMLHTTP");
  } catch (ex) {
    try {
      XMLHTTP = 
       new ActiveXObject("Microsoft.XMLHTTP");
    } catch (ex) {
    }
  }
}

function answerforum() {
  if (XMLHTTP.readyState == 4) {
    document.getElementById("ajaxforumwait").style.display='none';
    var d = document.getElementById("ajaxforumanswer");
    d.innerHTML = XMLHTTP.responseText;
    document.getElementById("ajaxforumanswer").style.display='inline';
    if(window.location.hash == "") {
      window.location.href = "#ajaxlastpost";
    }
  }
}

function answerlog() {
  if (XMLHTTP.readyState == 4) {
    document.getElementById("ajaxlogwait").style.display='none';
    var d = document.getElementById("ajaxloginanswer");
    d.innerHTML = XMLHTTP.responseText;
    document.getElementById("ajaxloginanswer").style.display='inline';
    location.reload();
  }
}

function sendforumanswer() {
document.getElementById("ajaxforumwait").style.display='inline';
document.getElementById("ajaxforumrequest").style.display='none';
  XMLHTTP.open("POST", "ajax.php");
  XMLHTTP.onreadystatechange = answerforum;
  XMLHTTP.setRequestHeader("Content-Type", 
    "application/x-www-form-urlencoded");
	var f_title = encodeURIComponent(document.getElementById('f_title').value);
	var f_inhalt = encodeURIComponent(document.getElementById('f_inhalt').value);
	var threadid = document.getElementById('threadid').value;
	var forumid = document.getElementById('forumid').value;
  XMLHTTP.send("action=forumanswer&threadid=" + threadid + "&forumid=" + forumid + "&f_title=" + f_title + "&f_inhalt=" + f_inhalt);
}

function sendlogin() {
document.getElementById("ajaxlogwait").style.display='inline';
document.getElementById("ajaxloginrequest").style.display='none';
  XMLHTTP.open("POST", "ajax.php");
  XMLHTTP.onreadystatechange = answerlog;
  XMLHTTP.setRequestHeader("Content-Type", 
    "application/x-www-form-urlencoded");
	var username = encodeURIComponent(document.getElementById('username').value);
	var pass = encodeURIComponent(document.getElementById('pass').value);
  XMLHTTP.send("action=login&username=" + username + "&pass=" + pass);
}

function sendlogout() {
document.getElementById("ajaxlogwait").style.display='inline';
document.getElementById("ajaxloginanswer").style.display='none';
  XMLHTTP.open("POST", "ajax.php");
  XMLHTTP.onreadystatechange = answerlog;
  XMLHTTP.setRequestHeader("Content-Type", 
    "application/x-www-form-urlencoded");
  XMLHTTP.send("action=logout");
}