///////////////////////////////////////////////////////
//############## MAIN NAVIGATION MENU FUNCTIONS
///////////////////////////////////////////////////////
var closetimer	= 0;
var menuItem	= 0;
var miliSecs	= 450;

// Show hidden Div Elements
function showMenu(id)
{	
	// Abort Menu Closure
	abortTimeout();

	// close old layer
	if(menuItem) menuItem.style.visibility = 'hidden';

	// get new layer and show it
	menuItem = document.getElementById(id);
	menuItem.style.visibility = 'visible';

}
// Hide Corresponding DIV Elements
function hideMenu()
{
	if(menuItem) menuItem.style.visibility = 'hidden';
}

// Self Destructing Sequence initialized
function closeMenuTimeout()
{
	closetimer = window.setTimeout(hideMenu, miliSecs);
}

// Abort Self Destruct Sequence .. authorization Picard Omega Nine Alpha
function abortTimeout()
{
	if(closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

// Hide Menu when clicking a link
document.onclick = hideMenu; 







///////////////////////////////////////////////////////
//##############   JS FOR DB INTERACTION
///////////////////////////////////////////////////////



function addPost(form) {
	
	var postTitle = encodeURIComponent(form.postTitleInput.value);
	var postText = encodeURIComponent(form.postTextInput.value);
	var ajaxRequest;
	var parameters = "postTitle=" + postTitle + "&postText=" + postText;
	
		ajaxRequest = new XMLHttpRequest();
	
		ajaxRequest.open("POST", "scripts/addPost.php", true);
		ajaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		
		ajaxRequest.send(parameters);
	
		ajaxRequest.onreadystatechange = function(){
	
		// Wenn Server mit Code 4 antwortet die echo Daten des PHP Scripts in output ausgeben
		if(ajaxRequest.readyState == 4)
		{
			
			document.getElementById('madeBy').innerHTML = (ajaxRequest.responseText);

			
		
		} // End of if

	} // End of function()	
	
} // END OF function sendForm
	



























