var http = getHTTPObject();
 
function getHTTPObject(){
    var xmlHttp = false;

    // mozi,opera,ie7
    if(typeof XMLHttpRequest != 'undefined') {
        xmlHttp = new XMLHttpRequest();
    }

    if(!xmlHttp) {
        //ie6andolder
        try {
            xmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");
        } catch(e) {
            try {
                xmlHttp  = new ActiveXObject("Microsoft.XMLHTTP");
            } catch(e) {
                xmlHttp  = false;
            }
        }
    }

    return xmlHttp;
}

function doText(theURL,theID){
	var url = "../ajax_" + theURL;
	var ID = theID;
 
  http.open("GET", url, true);
  http.onreadystatechange = function () { handleHttpResponse(ID); }
  http.send(null);
}

function wText(theURL,theID){
  var derText = document.getElementById('text').value;
  derText = derText.replace(/\n/g,"<br/>");
  var url = "ajax_" + theURL;
  url += "&text=" + derText;
  var ID = theID;
 
  http.open("GET", url, true);
  http.onreadystatechange = function () { handleHttpResponse(ID); }
 
  http.send(null);
}

function wCaptcha(theURL,theID){
  var derText = document.getElementById('text').value;
  var derCap = document.getElementById('cap').value;
  derText = derText.replace(/\n/g,"<br/>");
  var url = "ajax_" + theURL;
  url += "&text=" + derText;
  url += "&cap=" + derCap;
  var ID = theID;
 
  http.open("GET", url, true);
  http.onreadystatechange = function () { handleHttpResponse(ID); }
 
  http.send(null);
}

function handleHttpResponse(theID){
	var ID = theID;

  if(http.readyState == 4){
    document.getElementById(ID).innerHTML = http.responseText;
  }
}
function leeren(theID){
	var ID = theID;

  if(http.readyState == 4){
    document.getElementById(ID).innerHTML = "";
  }
}


function loading(theID){
	var ID = theID;
	document.getElementById(ID).innerHTML = "<br><img src=http://nofuckingbullshit.de/images/load.gif border=0>";
	window.setTimeout(function() { wechsel(ID); },1500);
	
}


function wechsel(theID)
{
	var ID = theID;
	window.setTimeout(function() { loading(ID); },15000);
	window.setTimeout(function() { doText(ID,ID); },500);

}

function changeBG(theID)
{
	var ID = theID;
	for (var i = 1; i <= 4; i++) {
		if(ID==i) { document.getElementById('r'+i).style.backgroundColor = '#FFFFFF'; } else { document.getElementById('r'+i).style.backgroundColor = '#BACCD3'; }
	}
}