// JavaScript Document

function OpenShoutBoxText()
{
	var value = "<table><tr><td align='left'>" +
			"<strong>Name</strong>:</td></tr><tr><td align='left'><input type='text' name='shoutbox-name' id='shoutbox-name' value=''/></td></tr> " +
			"<tr><td align='left'><strong>Text:</strong></td></tr><tr><td align='left'><textarea rows='5' id='shoutbox-value' cols='18' name='shoutbox-value' width='50px'></textarea></td></tr>" +
			"<tr><td><input type='button' onClick='SaveShoutBoxSubmit();' name='shoutbox-add' value='Speichern' /></td></tr></table>";
	
	document.getElementById("shoutbox-textarea").innerHTML = value;
	document.getElementsByName("shoutbox-stat").value = "1";
}

function SaveShoutBoxSubmit()
{
	var value = document.getElementById("shoutbox-value").value;
	var name = document.getElementById("shoutbox-name").value;

	if(name.length >= 30)
	{
		alert("Der Name darf nicht mehr als 30 Zeichen haben");
		return;
	}
	else if(value.length >= 255)
	{
		alert("Der eingegebene Text darf nicht mehr als 255 Zeichen haben");
		return;
	}
	else if(name == "")
	{
		alert("Geben Sie bitte einen Namen ein");
		return;
	}
	else if(value == "")
	{
		alert("Geben Sie bitte einen Text ein");
		return;
	}

	
	var count = document.getElementById("shoutbox-count").value;
	var div = document.createElement("div");
	
	div.setAttribute("id", "shoutbox-submit"+count);
	
	document.getElementById("shoutbox-submit").appendChild(div);
	
	Load("shoutbox.php?value="+value+"&name="+name, "shoutbox-submit"+count);
	document.getElementsByName("shoutbox-stat").value = "0";
	count = count + 1;
	document.getElementById("shoutbox-count").value = count;
	document.getElementById("shoutbox-textarea").innerHTML = '<a href="javascript:void(0)" onClick="OpenShoutBoxText();">Text schreiben</a>';
}

function ShoutboxMove(pos)
{
	var currentPos = parseInt(document.getElementById("shoutbox-position").value);
	currentPos = pos + currentPos;
	
	if(document.getElementsByName("shoutbox-stat").value == "0")
	{
		Load("shoutbox.php?fastLoad=true&pos="+currentPos, "shoutbox");
		document.getElementById("shoutbox-position").value = currentPos;
	}
}

function ShoutboxOnMouseOver()
{
	var time = parseInt(document.getElementById("shoutbox-refresh").value);
	var pos = parseInt(document.getElementById("shoutbox-position").value);
	var time2 = time + 1;
	var varDate = new Date();
	
	if(time == "0")
	{
		document.getElementById("shoutbox-refresh").value = varDate.getMinutes();
		time = parseInt(document.getElementById("shoutbox-refresh").value);
		time2 = time + 5;
	}
	
	if(varDate.getMinutes() >= time2)
	{
		if(document.getElementsByName("shoutbox-stat").value == "0")
		{
			document.getElementById("shoutbox-refresh").value = varDate.getMinutes();
			Load("shoutbox.php?fastLoad=true&pos="+pos, "shoutbox");
		}
	}
	
	//document.getElementById("debug").innerHTML = "Minutes Record: "+time+" - Now: " + varDate.getMinutes() + " test: "+time2;
}

//JavaScript Document
function sql_error()
{
	setTimeout("self.location.href='index.php?site=error&errorType=query&query='+query+'&sql_error='+sqlerror+''",0);
}
function fetch_error()
{
	setTimeout("self.location.href='index.php?site=error&errorType=fetch&sql_error='+sqlerror+''",0);
}
function redirect()
{
	setTimeout("self.location.href=''+site+''",1500);	
}
function noTimeRedirect()
{
	setTimeout("self.location.href=''+site+''",0);	
}
function MM_confirm(msg, url) { //v1.0
  if(confirm(msg)) location.replace(url);
}
