// NG-Gamer Live Search

var searchBoxHeight = 40;
var searchBoxHeightTarget = 40;
var results_name, results_url;

var XMLHttpRequestObject = false;

if(window.XMLHttpRequest) {
	XMLHttpRequestObject = new XMLHttpRequest();
} else if(window.ActiveXObject) {
	XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
}

doMove();

function getResults2(keyEvent)
{
	
	keyEvent = (keyEvent) ? keyEvent: window.event;
	input = (keyEvent.target) ? keyEvent.target : keyEvent.srcElement;
	
	if(keyEvent.type == "keyup") {
		
		if(input.value) {
			var url = "/scripts/livesearch_results.php?q=" + input.value;
			getData2(url);
			
		} else {
			document.getElementById('liveSearchResults2').innerHTML = '&nbsp;&nbsp;&nbsp;<a href="/search.php">Meer Zoekopties</a>';
			searchBoxHeightTarget = 40;
		}		
	}
	

}

function getData2(dataSource) 
{
	
	if(XMLHttpRequestObject != false) {
		XMLHttpRequestObject.open("GET", dataSource, true);
		
		XMLHttpRequestObject.onreadystatechange = function()
		{
			if(XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) {
				var xmlDocument = XMLHttpRequestObject.responseXML;
				results_name = xmlDocument.getElementsByTagName("name");
				results_url = xmlDocument.getElementsByTagName("url");
				listResults2();
			}
		}
		
		XMLHttpRequestObject.send(null);
		
	}
	
}

function listResults2()
{
	var loopIndex = 0;
	var boxContent = "";
	searchBoxHeightTarget = 40 + (13 * results_name.length);
	
	while(loopIndex < results_name.length) {
		
		if(loopIndex == 6) {
			boxContent = boxContent + '&nbsp;&nbsp;&nbsp;<a href="' + results_url[loopIndex].firstChild.data + '">' + results_name[loopIndex].firstChild.data + '</a><br>';
		} else {
			if(results_url[loopIndex].firstChild.data != "disable") {
				boxContent = boxContent + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&raquo;&nbsp;<a href="' + results_url[loopIndex].firstChild.data + '">' + results_name[loopIndex].firstChild.data + '</a><br>';
			} else {
				boxContent = boxContent + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&raquo;&nbsp;' + results_name[loopIndex].firstChild.data + '<br>';
			}
		}
		loopIndex = loopIndex + 1;
	}
	boxContent = boxContent + '&nbsp;&nbsp;&nbsp;<a href="search.php">Meer Zoekopties</a>';
	
	document.getElementById('liveSearchResults2').innerHTML = boxContent;
	
}


function getResults(keyEvent)
{
	
	keyEvent = (keyEvent) ? keyEvent: window.event;
	input = (keyEvent.target) ? keyEvent.target : keyEvent.srcElement;
	
	if(keyEvent.type == "keyup") {
		
		if(input.value) {
			var url = "/scripts/livesearch_results.php?q=" + input.value;
			getData(url);
			
		} else {
			document.getElementById('liveSearchResults').innerHTML = '&nbsp;&nbsp;&nbsp;<a href="/search.php">Meer Zoekopties</a>';
			searchBoxHeightTarget = 40;
		}		
	}
	

}

function getData(dataSource) 
{
	
	if(XMLHttpRequestObject != false) {
		XMLHttpRequestObject.open("GET", dataSource, true);
		
		XMLHttpRequestObject.onreadystatechange = function()
		{
			if(XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) {
				var xmlDocument = XMLHttpRequestObject.responseXML;
				results_name = xmlDocument.getElementsByTagName("name");
				results_url = xmlDocument.getElementsByTagName("url");
				listResults();
			}
		}
		
		XMLHttpRequestObject.send(null);
		
	}
	
}

function listResults()
{
	var loopIndex = 0;
	var boxContent = "";
	searchBoxHeightTarget = 40 + (13 * results_name.length);
	
	while(loopIndex < results_name.length) {
		
		if(loopIndex == 6) {
			boxContent = boxContent + '&nbsp;&nbsp;&nbsp;<a href="' + results_url[loopIndex].firstChild.data + '">' + results_name[loopIndex].firstChild.data + '</a><br>';
		} else {
			if(results_url[loopIndex].firstChild.data != "disable") {
				boxContent = boxContent + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&raquo;&nbsp;<a href="' + results_url[loopIndex].firstChild.data + '">' + results_name[loopIndex].firstChild.data + '</a><br>';
			} else {
				boxContent = boxContent + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&raquo;&nbsp;' + results_name[loopIndex].firstChild.data + '<br>';
			}
		}
		loopIndex = loopIndex + 1;
	}
	boxContent = boxContent + '&nbsp;&nbsp;&nbsp;<a href="search.php">Meer Zoekopties</a>';
	
	document.getElementById('liveSearchResults').innerHTML = boxContent;
	
}

function doMove()
{
	if(searchBoxHeight < searchBoxHeightTarget) {
		
		searchBoxHeight = searchBoxHeight + 30;
		if(searchBoxHeight >= searchBoxHeightTarget) {
			searchBoxHeight = searchBoxHeightTarget;
		}
		document.getElementById('searchBox').style.height = searchBoxHeight;
	}
	if(searchBoxHeight > searchBoxHeightTarget) {
		searchBoxHeight = searchBoxHeight - 30;
		if(searchBoxHeight <= searchBoxHeightTarget) {
			searchBoxHeight = searchBoxHeightTarget;
		}
		document.getElementById('searchBox').style.height = searchBoxHeight;
	}
	setTimeout(doMove,.0005);

}
function printLink(anchor, link)
{
	document.write('<a href="' + link + '" title="' + anchor + '" rel="nofollow" target="_blank">' + anchor + '</a>');
}

function printLinkImage(anchor, link, src)
{
	document.write('<a href="' + link + '" title="' + anchor + '" rel="nofollow" target="_blank"><img src="' + src + '" border="0" alt=""/></a>');
}

function printLinkImageSmall(anchor, link, src)
{
	document.write('<a href="' + link + '" title="' + anchor + '" rel="nofollow" target="_blank"><img src="' + src + '" border="0" height="50" alt=""/></a>');
}