// globale Instanz von XMLHttpRequest
var xmlHttp = false;

// XMLHttpRequest-Instanz erstellen
// ... für Internet Explorer
try {
    xmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
    try {
        xmlHttp  = new ActiveXObject("Microsoft.XMLHTTP");
    } catch(e) {
        xmlHttp  = false;
    }
}
// ... für Mozilla, Opera und Safari
if (!xmlHttp  && typeof XMLHttpRequest != 'undefined') {
    xmlHttp = new XMLHttpRequest();
}

// search
var interval = "";
var lastsearch = "";

function searchit()
{	
	var keyword = escape(document.getElementById('search').value);
	if (keyword == lastsearch) return false;
	
	xmlHttp.open("GET", 'http://dailydpad.de/index.php?search=' + keyword + '&ajax=true', true);
	xmlHttp.onreadystatechange = function() 
	{
		if (xmlHttp.readyState == 4)
		{
			document.getElementById('ajax_listStart').innerHTML = xmlHttp.responseText;
			lastsearch = keyword;
		}
	}
	xmlHttp.send(null);
	return false;
}

function toggle_menu(id)
{	
	xmlHttp.open("GET", 'http://dailydpad.de/index.php?sect=user&act=toggle_menu&id=' + id, true);
	xmlHttp.send(null);
	return false;
}


function toggle_search(box)
{
	if (box.checked == true)
		interval = setInterval("searchit()",500);
	else
		clearInterval(interval);
}


// article autosaving
function autosave(id)
{	
	var text = document.getElementById('text').value;

	// Request öffnen
	xmlHttp.open('post', 'index.php?sect=article&act=autosave&id=' + id, true);
	// Requestheader senden
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	// Request senden
	xmlHttp.send('text=' + text);
	// Request auswerten
	/* silenced..
	xmlHttp.onreadystatechange = function() 
	{
		if (xmlHttp.readyState == 4)
		{
			alert(xmlHttp.responseText);
		}
	} 
	*/
}