/* ---------------------------- */
/* XMLHTTPRequest Enable 		*/
/* ---------------------------- */
function createObject() {
	var request_type;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer"){
	request_type = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		request_type = new XMLHttpRequest();
	}
		return request_type;
}

var http = createObject();

/* -------------------------- */
/* SEARCH					 */
/* -------------------------- */
function autosuggest() {
q = document.getElementById('searchphrase').value;
// Set te random number to add to URL request
nocache = Math.random();
http.open('get', 'http://whadu.com/ajaxsearch/search.php?q='+q+'&nocache = '+nocache);
http.onreadystatechange = autosuggestReply;
http.send(null);
}
function autosuggestReply() {
if(http.readyState == 4){
	var response = http.responseText;
	e = document.getElementById('results');
	if(response!=""){
		e.innerHTML=response;
		e.style.display="block";
	} else {
		e.style.display="none";
	}
}
}

function goup() {

var x=document.getElementsByTagName("li");

if(x.length>0 && x[0].style.backgroundColor == "lightblue"){
x[0].style.backgroundColor = "";
x[x.length-1].style.backgroundColor = "lightblue";
document.getElementById("searchphrase").value = x[x.length-1].firstChild.innerHTML;

return;
}
else if(x.length>1 && x[1].style.backgroundColor == "lightblue"){
x[1].style.backgroundColor = "";
x[0].style.backgroundColor = "lightblue";
document.getElementById("searchphrase").value = x[0].firstChild.innerHTML;

return;
}
else if(x.length>2 && x[2].style.backgroundColor == "lightblue"){
x[2].style.backgroundColor = "";
x[1].style.backgroundColor = "lightblue";
document.getElementById("searchphrase").value = x[1].firstChild.innerHTML;

return;
}
else if(x.length>3 && x[3].style.backgroundColor == "lightblue"){
x[3].style.backgroundColor = "";
x[2].style.backgroundColor = "lightblue";
document.getElementById("searchphrase").value = x[2].firstChild.innerHTML;

return;
}
else if(x.length>4 && x[4].style.backgroundColor == "lightblue"){
x[4].style.backgroundColor = "";
x[3].style.backgroundColor = "lightblue";
document.getElementById("searchphrase").value = x[3].firstChild.innerHTML;

return;
}
else if(x.length>5 && x[5].style.backgroundColor == "lightblue"){
x[5].style.backgroundColor = "";
x[4].style.backgroundColor = "lightblue";
document.getElementById("searchphrase").value = x[4].firstChild.innerHTML;

return;
}
else if(x.length>6 && x[6].style.backgroundColor == "lightblue"){
x[6].style.backgroundColor = "";
x[5].style.backgroundColor = "lightblue";
document.getElementById("searchphrase").value = x[5].firstChild.innerHTML;

return;
}
else if(x.length>7 && x[7].style.backgroundColor == "lightblue"){
x[7].style.backgroundColor = "";
x[6].style.backgroundColor = "lightblue";
document.getElementById("searchphrase").value = x[6].firstChild.innerHTML;

return;
}
else if(x.length>8 && x[8].style.backgroundColor == "lightblue"){
x[8].style.backgroundColor = "";
x[7].style.backgroundColor = "lightblue";
document.getElementById("searchphrase").value = x[7].firstChild.innerHTML;

return;
}
else if(x.length>9 && x[9].style.backgroundColor == "lightblue"){
x[9].style.backgroundColor = "";
x[8].style.backgroundColor = "lightblue";
document.getElementById("searchphrase").value = x[8].firstChild.innerHTML;

return;
}
else{

x[0].style.backgroundColor = "";
x[x.length-1].style.backgroundColor = "lightblue";
document.getElementById("searchphrase").value = x[x.length-1].firstChild.innerHTML;

return;
}
}


function godown() {

var x=document.getElementsByTagName("li");


if(x.length>1 && x[0].style.backgroundColor == "lightblue"){
x[0].style.backgroundColor = "";
x[1].style.backgroundColor = "lightblue";
document.getElementById("searchphrase").value = x[1].firstChild.innerHTML;
return;
}
else if(x.length>2 && x[1].style.backgroundColor == "lightblue"){
x[1].style.backgroundColor = "";
x[2].style.backgroundColor = "lightblue";
document.getElementById("searchphrase").value = x[2].firstChild.innerHTML;

return;
}
else if(x.length>3 && x[2].style.backgroundColor == "lightblue"){
x[2].style.backgroundColor = "";
x[3].style.backgroundColor = "lightblue";
document.getElementById("searchphrase").value = x[3].firstChild.innerHTML;

return;
}
else if(x.length>4 && x[3].style.backgroundColor == "lightblue"){
x[3].style.backgroundColor = "";
x[4].style.backgroundColor = "lightblue";
document.getElementById("searchphrase").value = x[4].firstChild.innerHTML;

return;
}
else if(x.length>5 && x[4].style.backgroundColor == "lightblue"){
x[4].style.backgroundColor = "";
x[5].style.backgroundColor = "lightblue";
document.getElementById("searchphrase").value = x[5].firstChild.innerHTML;

return;
}
else if(x.length>6 && x[5].style.backgroundColor == "lightblue"){
x[5].style.backgroundColor = "";
x[6].style.backgroundColor = "lightblue";
document.getElementById("searchphrase").value = x[6].firstChild.innerHTML;

return;
}
else if(x.length>7 && x[6].style.backgroundColor == "lightblue"){
x[6].style.backgroundColor = "";
x[7].style.backgroundColor = "lightblue";
document.getElementById("searchphrase").value = x[7].firstChild.innerHTML;

return;
}
else if(x.length>8 && x[7].style.backgroundColor == "lightblue"){
x[7].style.backgroundColor = "";
x[8].style.backgroundColor = "lightblue";
document.getElementById("searchphrase").value = x[8].firstChild.innerHTML;

return;
}
else if(x.length>9 && x[8].style.backgroundColor == "lightblue"){
x[8].style.backgroundColor = "";
x[9].style.backgroundColor = "lightblue";
document.getElementById("searchphrase").value = x[9].firstChild.innerHTML;

return;
}
else if(x.length>9 && x[9].style.backgroundColor == "lightblue"){
x[9].style.backgroundColor = "";
x[0].style.backgroundColor = "lightblue";
document.getElementById("searchphrase").value = x[0].firstChild.innerHTML;

return;
}
else{
x[x.length-1].style.backgroundColor = "";
x[0].style.backgroundColor = "lightblue";
document.getElementById("searchphrase").value = x[0].firstChild.innerHTML;

return;
}
}