function fetch(url, id)
{
	var http; 
	try
	{
		http = new XMLHttpRequest();
	}                 
	catch(e) 
	{    
		http = new ActiveXObject(Microsoft.XMLHTTP);
	} 
	http.onreadystatechange = function()
	{ 
		if(http.readyState == 4)
		{
			if(http.status == 200) 
			{
				document.getElementById(id).innerHTML = http.responseText;
			}
			else
			{
				document.getElementById(id).innerHTML = 'Error';
			}
		}
	};
	http.open('GET', url, true);
	http.send(null);
}

function show_comment(id)
{
	document.getElementById('comment_' + id).style.display = 'block';
}

function suggest()
{
	var curleft = curtop = 0;
	var obj = document.getElementById('thesearchbox');
	if (obj.offsetParent)
	{
		do
		{
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
		while (obj = obj.offsetParent);
		curtop = curtop + document.getElementById('thesearchbox').offsetHeight;
		document.getElementById('suggestbox').style.top = curtop + 'px';
		document.getElementById('suggestbox').style.left = curleft + 'px';	
	}
	var str = escape(document.getElementById('thesearchbox').value);
	fetch('/suggest.php?q=' + str, 'suggestbox');
}

function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "e")
     anchor.target = "_blank";
 }
}
window.onload = externalLinks;

