function show_gaestebuch(id) {
	overlay('display');
	document.getElementById('gaestebuch').style.display='block';
	var query="X="+id;
	var xmlhttp = new ajaxRequest(
		"http://www.die-erde.com/request/fetch_gaestebuch.php",
		function() {
			var r = xmlhttp.req;
			if (r.readyState==4) {
				if(r.status == 200) {
					document.getElementById('gaestebuch').innerHTML='<div class="gbhead"><div onclick="close_div(\'gaestebuch\')" class="close" /></div></div><div class="gbinhalt">'+r.responseText+'</div><div class="gbfoot"></div>';
				}
			}
		},
		"POST",
		query,
		["Content-Type","application/x-www-form-urlencoded"]
	);
	xmlhttp.doRequest();
}

function close_div(div) {
	document.getElementById(div).style.display='none';
	overlay('close');
}

function add_smilie(smilie,id) {
	document.getElementById(id).innerHTML+=' '+smilie+' ';
}

function save_gaestebuch() {
	var query="nickname="+document.getElementById('nickname').value;
	query+="&email="+document.getElementById('email').value;
	query+="&homep="+document.getElementById('homep').value;
	query+="&action="+document.getElementById('action').value;
	query+="&identifikation="+document.getElementById('identifikation').value;
	query+="&message="+document.getElementById('message').value;
	var xmlhttp = new ajaxRequest(
		"http://www.die-erde.com/request/save_gaestebuch.php",
		function() {
			var r = xmlhttp.req;
			if (r.readyState==4) {
				if(r.status == 200) {
					if(r.responseText==0) {
						show_gaestebuch('0');
						alert('Vielen Dank für den Eintrag. Bevor der Eintrag erscheinen kann, muss dieser freigeschaltet werden.')
					} else {
						alert(r.responseText);
					}
				}
			}
		},
		"POST",
		query,
		["Content-Type","application/x-www-form-urlencoded"]
	);
	xmlhttp.doRequest();
}

function overlay(mode) {

   if(mode == 'display') {
       if(document.getElementById("overlay") === null) {
           div = document.createElement("div");
           div.setAttribute('id', 'overlay');
           div.setAttribute('className', 'overlayBG');
           div.setAttribute('class', 'overlayBG');

           document.getElementsByTagName("body")[0].appendChild(div);

       }
   } else {
       document.getElementsByTagName("body")[0].removeChild(document.getElementById("overlay"));

   }
}

/* AJAX Request f�r POST */

ajaxRequest = function(u,f,m,b,h,s)
{
    this.url      = u;
    this.wState   = f || function() { };
    this.method   = m || "GET";
    this.body     = b || null;
    this.headers  = h || false;
    this.sync     = s || true;
    this.abortReq = false;

    this.req = (window.XMLHttpRequest)
           ?
           new XMLHttpRequest()
           :
           ((window.ActiveXObject)
           ?
           new ActiveXObject("Microsoft.XMLHTTP")
           :
           false
           );

    this.doRequest = function()
    {
        this.req.open(this.method,this.url,this.sync);
        if (this.headers)
        {
            for (var i=0; i<this.headers.length; i+=2)
            {
                this.req.setRequestHeader(
                    this.headers[i],this.headers[i+1]
                );
            }
        }
        this.req.onreadystatechange = this.wState;
        (!this.abortReq) ? this.req.send(this.body) : this.req.abort();
    }
}

