

/*--------------------------------------
	User configured variables
--------------------------------------*/
var inputId = 'livesearch'; 
					// This is the id on the input/textarea that you want to use as the query.
									
var outputId = 'LSShadow';
//var outputId = 'agencyresults';
 					// use this to have the results populate your own ID'd tag.
					// leave it blank and a div tag will automatically be added
					// with an id="liveSearchResults"
									
var processURI    = '../include_search/lsxml.php';
					// this is the file that you request data from.
					
var processURI2    = '../include_search/getjobinfo.php';
					// this is the file that you request data from.
									
var emptyString   = '';
					// What to display in the results field when there's nothing
					// Leaving this null will cause the results field to be set to display: none

/*--------------------------------------
	Script Stuff
--------------------------------------*/
var liveReq = false;
var t = null;
var liveReqLast = "";
var isIE = false;

var inputElement;
var outputElement;

function liveReqInit() {
	//alert('test'); 
	inputElement  = document.getElementById(inputId);
	outputElement = document.getElementById(outputId);
	
	if( inputElement == null || outputElement == null )
	
		return;
	
	
	if (navigator.userAgent.indexOf("Safari") > 0) {
		inputElement.addEventListener("keydown",liveSearchKeyPress,false);
//		document.getElementById('livesearch').addEventListener("blur",liveSearchHide,false);
	} else if (navigator.product == "Gecko") {
		
		inputElement.addEventListener("keypress",liveSearchKeyPress,false);
		//inputElement.addEventListener("blur",liveSearchHideDelayed,false);
		
	} else {
		inputElement.attachEvent('onkeydown',liveSearchKeyPress);
//		document.getElementById('livesearch').attachEvent("onblur",liveSearchHide,false);
		isIE = true;
	}
	
	if(emptyString == '') {
		// set the result field to hidden, or to default string
		outputElement.style.display = "none";
	} else {
		outputElement.innerHTML = emptyString;
	}
}

//addLoadEvent(liveReqInit);

function liveSearchKeyPress(event) {
	if (inputElement.value=='') return;
	if (event.keyCode == 40 )
	//KEY DOWN
	{
		highlight = document.getElementById("LSHighlight");
		if (!highlight) {
			highlight = document.getElementById("LSShadow").firstChild.firstChild;
		} else {
			highlight.removeAttribute("id");
			highlight = highlight.nextSibling;
		}
		if (highlight) {
			highlight.setAttribute("id","LSHighlight");
		} 
		if (!isIE) { event.preventDefault(); }
	} 
	//KEY UP
	else if (event.keyCode == 38 ) {
		highlight = document.getElementById("LSHighlight");
		if (!highlight) {
			highlight = document.getElementById("LSResult").firstChild.firstChild.lastChild;
		} 
		else {
			highlight.removeAttribute("id");
			highlight = highlight.previousSibling;
		}
		if (highlight) {
				highlight.setAttribute("id","LSHighlight");
		}
		if (!isIE) { event.preventDefault(); }
	} 
	//ESC
	else if (event.keyCode == 27) {
		highlight = document.getElementById("LSHighlight");
		if (highlight) {
			highlight.removeAttribute("id");
		}
		inputElement.value='';
		if(emptyString == '') {
			outputElement.innerHTML = '';
			outputElement.style.display = "none";
		} else {
			outputElement.innerHTML = emptyString;
		}
		
	} 
	//Enter
	else if (event.keyCode==13) {
		highlight = document.getElementById("LSHighlight");
		if (highlight) var x=highlight.firstChild.getAttribute("name");
		processlr(x);
	}
	else liveReqStart();
	//liveReqDoReq();
}



function liveReqStart() {
	if (t) {
		window.clearTimeout(t);
	}
	t = window.setTimeout("liveReqDoReq()",400);
}


function liveReqDoReq() {
	if (liveReqLast != inputElement.value && inputElement.value != "") {
		
	var	liveReqLast=inputElement.value;
	var mysearch='mysearch='+encodeURI(inputElement.value)
    new ajax (processURI, {postBody: mysearch,  onComplete: liveReqProcessReqChange});

	}else if(inputElement.value == "") {
		if(emptyString == '') {
			outputElement.innerHTML = '';
			outputElement.style.display = "none";
		} else {
			outputElement.innerHTML = emptyString;
		}
	}
}


function liveReqProcessReqChange(response) {
		outputElement.innerHTML = response.responseText;
		if(emptyString == '') {
			outputElement.style.display = "block";
		}
}


function init() {
	liveReqInit();
}

function init_search() {
	processURI = $('processURI').value;// this is the file that you request data from.
	processURI2 = $('processURI2').value;// // this is the results.
	mysearch = $('mysearch').value;// this is the index in the XML file.
	liveReqInit();
}

// TO SELECT THE ITEM
function processsearch(oid) {
	
	outputElement = document.getElementById('LSShadow');
	outputElement.innerHTML = '';
	mysearch=mysearch+oid;
	var processURI    = processURI2;
	new ajax (processURI, {postBody: mysearch,  onComplete: updatesearch});
	mysearch= $('mysearch').value;
}


// TO UPDATE HTML
function updatesearch(response) {
	itemsElement=document.getElementById('searchresults');
	itemsElement.innerHTML = '';
	itemsElement.innerHTML = response.responseText;
}

