function shout(id)
{
	dp = document.getElementById(id);
	var display = dp.style.display ? '' : 'none';
	dp.style.display = display;
}
function resetshout()
{
	var message = document.getElementById("shout");
	var name = document.getElementById("name");

	document.getElementById("submit").disabled=false;
	message.value="message";
	name.value="naam"
	document.getElementById("sbCharCount").innerHTML="0/300";
}


function focus_txt(id,str)
{
	(id.value==str)?id.value="":void (0);
}


function blur_txt(id,str)
{
	(id.value=="")?id.value=str:void (0);
}

function checklength(str)
{
	if(str>300)
	{
		document.getElementById("submit").disabled=true;
		document.getElementById("sbCharCount").innerHTML="<span style='color: #F00;'>"+str+"/300</span>";
	}
	else
	{
		document.getElementById("submit").disabled=false;
		document.getElementById("sbCharCount").innerHTML=str+"/300";
	}
}

function ShoutGetXmlHttpObject()
{
  var xmlHttp=null;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
  return xmlHttp;
}

function readshout(page)
{
	xmlHttp=ShoutGetXmlHttpObject()
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 

	xmlHttp.onreadystatechange=function(){
		if (xmlHttp.readyState==1)
		{ 
			document.getElementById("messages").innerHTML="<img src='ext/loading.gif' /> ontvangen ";
		}
		if (xmlHttp.readyState==4)
		{ 
			document.getElementById("messages").innerHTML=xmlHttp.responseText;
		}

	}
	xmlHttp.open("GET","sb.php?read&page="+page,true);
	xmlHttp.send(null);
}

function addShout()
{
	var message = document.getElementById("shout");
	var name = document.getElementById("name");
	var error = false;
	
	if(message.value.length<2 || message.value=="message")
	{
		message.style.color="#F00";
		error = true;
	}
	else
	{
		message.style.color="#000";
	}
	
	if(name.value=="naam" || name.value.length<2 || name.value.length>=30 )
	{
		name.style.color="#F00";
		var error = true;
	}
	else
	{
		name.style.color="#000";
	}
	
	if(error)
	{
		document.getElementById("outputShout").innerHTML="<span style='color: #F00;'>U heeft niet alle velden correct ingevuld</span>";
	}
	else
	{	
		document.getElementById("submit").disabled="true";
		xmlHttp=ShoutGetXmlHttpObject()
		if (xmlHttp==null)
		  {
		  alert ("Your browser does not support AJAX!");
		  return;
		  } 
		
		xmlHttp.onreadystatechange=function()
		{
			if (xmlHttp.readyState==1)
			{ 
				document.getElementById("outputShout").innerHTML="<img src='ext/loading.gif' /> verzenden ";
			}
			if (xmlHttp.readyState==4)
			{ 
				var str=xmlHttp.responseText;
				var pos=str.indexOf("error");
				if (pos>=0)
				{
					document.getElementById("outputShout").innerHTML="<span style='color: #F00;'>"+xmlHttp.responseText+"</span>";
					document.getElementById("submit").disabled=false;
				}
				else
				{
					document.getElementById("outputShout").innerHTML=xmlHttp.responseText;
					readshout("1");
					resetshout();
					shout('inputShout');
				}
			}
		}
		xmlHttp.open("GET","sb.php?add&message="+message.value+"&name="+name.value,true);
		xmlHttp.send(null);
	}
}
