/*
The_Nephilim's ActionSearch
----------------------------------------

This is my very own way to an Apple inspired way of searching.
This means that the search is performed while you are
typing, without having to press any "Go" or "Search" button.

*/

var t = null;

function crearHttpObj() {
	var obj;
	if(window.XMLHttpRequest)  {//Cualquiera menos IE
		obj = new XMLHttpRequest();
	} else { //Es IE 6 o - o no tiene el objeto XMLHttpRequest
		try {
			obj = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e) {
			alert ("Tu navegador no soporta Ajax!");
		}
	}
	return obj;
}
var aSearch = crearHttpObj();
aSearch.abort();

function InitActionSearch() {
	document.getElementById("actionsearch").setAttribute("autocomplete","off");
	loaderDisplayMode(false);
}

function loaderDisplayMode(mode) {
	document.getElementById("loader").style.display = mode ? "inline" : "none";
}

function actionSearch() {	
	if(t) {
		window.clearTimeout(t);
	}
	var theInput = document.getElementById("actionsearch");
	if(theInput.value == "" || theInput.value == " ") { //mejorar esto!!!!!!!!!!
		aSearch.abort();
		document.getElementById("result").innerHTML = "";
	}
	else
	{
		aSearch.abort();
		t = window.setTimeout("actionSearchString()",500);
	}
}

function showResults() {
	if(aSearch.readyState == 3) {
		loaderDisplayMode(true);
	}
	if(aSearch.readyState == 4) {
		document.getElementById("result").innerHTML = aSearch.responseText;
		loaderDisplayMode(false);
	}
}

function actionSearchString() {
	var theString = document.getElementById("actionsearch").value;
	var params =  '?s='+theString;
	
	aSearch.open('POST', 'index.php'+params);
	aSearch.onreadystatechange = showResults;
	aSearch.send('');
}

function getfocus(input) {
	input.value="";
}

function getblur(input) {
	input.value = "Buscar en el blog...";
}





