// FUNCTION ::: PORUKA KORISNICIMA DA SE REZULTATI UCITAVAJU
function showLoadingMsg (divID) {	
	var theObj = document.getElementById(divID);
	theObj.innerHTML = "<center><b>Rezultati se učitavaju...</b><br /><br /><img src=\"images/extra/indicator.gif\" width=\"16\" height=\"16\" border=\"0\" alt=\"indicator\" /><br /><br /><img src=\"images/extra/progressbar_green.gif\" width=\"214\" height=\"15\" border=\"0\" alt=\"indicator\" /></center>";
	return true;
} // end function


// ::::: LIVE SEARCH ::::: //

var xmlhttpSearchReq = false;
var t = null;
var liveSearchLast = "";


function liveSearchStart() {
	if (t) {
		window.clearTimeout(t);
	}
	if (liveSearchLast != document.forms.searchForm.pojam.value) {
		temp = showLoadingMsg('pageMainContainer');
	}
	t = window.setTimeout("liveSearchDoSearch()",200);
}

function liveSearchDoSearch() {
	
	var theDIV = document.getElementById('pageMainContainer');
	
	if (liveSearchLast != document.forms.searchForm.pojam.value) {
		if (xmlhttpSearchReq && xmlhttpSearchReq.readyState < 4) {
			xmlhttpSearchReq.abort();
		}
		
		xmlhttpSearchReq = getxmlhttp();
		
		serverPage = "php/ajax.search.php?pojam=" + document.forms.searchForm.pojam.value + "&stranica=1";
		noChache = "&chid=" + Math.random();
		xmlhttpSearchReq.open("GET", serverPage + noChache);
		
		xmlhttpSearchReq.onreadystatechange = function() {
			if (xmlhttpSearchReq.readyState == 4 && xmlhttpSearchReq.status == 200) {
				theDIV.innerHTML = xmlhttpSearchReq.responseText;
			}
		} // end onreadystatechange function
		
		
		liveSearchLast = document.forms.searchForm.pojam.value;
		xmlhttpSearchReq.send(null);
	}
}
