var active = 0;
var entryBoxActive = false;
var guestbookReplyOpen = false;
var container;
var contWidth = 300;	//in pixel
var contHeight = 150;	//in pixel
var steps = 15;			//die anzahl der Schritte zum �ffnen und schlie�en des Antworten containers

function makeGbEntry() {	
	if (!guestbookReplyOpen) {
		container = document.createElement("div");
		
		//Container positionieren
		container.setAttribute("id","guestbookReplyContainer");
		container.style.position = "absolute";
		container.style.width = "1px";
		container.style.height = "1px";

		container.style.left = ((((window.innerWidth == undefined) ? document.body.clientWidth : window.innerWidth) - contWidth) / 2) + "px";
		container.style.top = ((((window.innerHeight == undefined) ? document.body.clientHeight : window.innerHeight) - contHeight) / 2) + "px";		
		//Container positioniert - formatieren
		
		//X einf�gen
		closeX = document.createElement("div");
		closeX.setAttribute("class","closeX");
		closeX.className = "closeX";
		closeX.onclick = rmGbContainer;
		container.appendChild(closeX);
		//X eingef�gt		
		
		//Formular einf�gen
		innerContainer = document.createElement("div");
		
		html = "<table id='innerContainer' style='margin: 20px auto;'><tr>";
		html += "<td><label for='name'>Name:</label></td> <td><input id='gbEntryName' type='text' name='name' /></td>";
		html += "</tr><tr>";
		html += "<td><label for='message'>Nachricht:</label></td>";
		html += "<td><textarea name='message' id='gbEntryMsg'></textarea></td>";
		html += "</tr><tr>";
		html += "<td colspan='2' style='text-align: center;' id='addGbEntryCont'>";
		html += 	"<input id='addGbEntryBut' style='margin-top: 5px;' type='button' value='eintragen' onclick='addGbEntry()'>";
		html += "</td>";
		html += "</tr></table>";
		
		innerContainer.innerHTML = html;
		
		container.appendChild(innerContainer);		
		//Formular eingef�gt
			
		document.body.appendChild(container);
		guestbookReplyOpen = true;
	} 
	
	if (guestbookReplyOpen) {
		_contWidth = parseInt(container.style.width);
		_contHeight = parseInt(container.style.height);			
		if (_contHeight < contHeight && _contWidth < contWidth) {			

			if ((_contWidth + (contWidth / steps)) > contWidth) {
				container.style.width = contWidth + "px";
			} else {
				container.style.width = (_contWidth + (contWidth / steps)) + "px";				
			}
			
			if ((_contHeight + (contHeight / steps)) > contHeight) {
				container.style.height = contHeight + "px";
			} else {
				container.style.height = (_contHeight + (contHeight / steps)) + "px";
			}
			setTimeout("makeGbEntry()",5);
		}
	}
}

function addGbEntry() {
	author = document.getElementById('gbEntryName').value;
	msg = document.getElementById('gbEntryMsg').value;
	
	if (author.length >= 3 && msg.length >= 5) {
		makeRequest('./addGbEntry.php', ADD_GB_ENTRY);
	} else {
		alert("Bitte eingaben überprüfen (mind 5 Buchstaben pro Feld)");
	}
}

function formatMessage(msg) {
	msg = msg.replace(/\n/g,"<br />");
	return msg;
}

function rmGbContainer() {
	if (guestbookReplyOpen) {
		_contWidth = parseInt(container.style.width);
		_contHeight = parseInt(container.style.height);		
		if (_contWidth >= (contWidth / steps) && _contHeight >= (contHeight / steps)){
			
			if ((_contWidth - (contWidth / steps)) >= 1) {
				container.style.width = (_contWidth - (contWidth / steps)) + "px";
			} else {
				container.style.width = "1px";
			}
			
			if ((_contHeight - (contHeight / steps)) >= 1) {
				container.style.height = (_contHeight - (contHeight / steps)) + "px";
			} else {
				container.style.width = "1px";
			}
			setTimeout("rmGbContainer()",5);
		} else {
			document.body.removeChild(container);
			guestbookReplyOpen = false;	
		}
	}
}
