liveInput = this;


liveInput.liElementHandle = {}


liveInput.liFileHandle = function () { this.liRequest = {}; }


liveInput.liFileHandle.prototype.makeRequest = function (liUrl, liMethod, liComp, liErr) {


				if (liMethod != "POST") { liMethod = "GET"; }


				this.liComplete = liComp;


				this.liError = liErr;


				var pointer = this;


				if (window.XMLHttpRequest) {


					this.liRequest = new XMLHttpRequest();


					this.liRequest.onreadystatechange = function () { pointer.processReqChange() };


					this.liRequest.open(liMethod, liUrl, true); //


					this.liRequest.send(null);


				} else if (window.ActiveXObject) {


					this.liRequest = new ActiveXObject("Microsoft.XMLHTTP");


					if (this.liRequest) {


						this.liRequest.onreadystatechange = function () { pointer.processReqChange() };


						this.liRequest.open(liMethod, liUrl, true);


						this.liRequest.send();


					}


				}


			}


liveInput.liFileHandle.prototype.processReqChange = function() {


				if (this.liRequest.readyState == 4) {


					if (this.liRequest.status == 200)	{


						this.liComplete(this.liRequest);


					} else {


						this.liError(this.liRequest.status);


					}


				}


			}








liveInput.liElementHandle.createElement = function (liType, liAttributes, liContent, liHypLang)	{


				var ne = document.createElement(liType);


				if (!ne) return false;


				for (var a in liAttributes) ne[a] = liAttributes[a];


				if (typeof(liContent) == "string" && !liHypLang) {


					ne.appendChild(document.createTextNode(liContent));


				} else if (typeof(liContent) == "string" && liHypLang) {


					ne.innerHTML = liContent;


				} else if (typeof(liContent) == "object") {


					ne.appendChild(liContent);


				}


				return ne;


			}


liveInput.liElementHandle.clearElement = function (liIdent)	{


				var liElement = this.getElement(liIdent);


				if (!liElement) return false;


				while (liElement.childNodes.length) liElement.removeChild(liElement.childNodes[0]);


				return true;


			}


liveInput.liElementHandle.removeElement = function (liElement) {


				var e = this.getElement(liElement);


				if (!e) {


					return false;


				} else if (e.parentNode.removeChild(e)) {


					return true;


				} else {


					return false;


				}


			}


liveInput.liElementHandle.replaceContent = function (liIdent, liContent, liHypLang) {


				var liElement = this.getElement(liIdent);


				if (!liElement) return false;


				this.clearElement(liElement);


				if (typeof(liContent) == "string" && !liHypLang) {


					liElement.appendChild(document.createTextNode(liContent));


				} else if (typeof(liContent) == "string" && liHypLang) {


					liElement.innerHTML = liContent;


				} else if (typeof(liContent) == "object") {


					liElement.appendChild(liContent);


				}


			}


liveInput.liElementHandle.getElement = function (liElement) {


				if (typeof(liElement) == "undefined") {


					return false;


				} else if (typeof(liElement) == "string")	{


					var re = document.getElementById(liElement);


					if (!re) {


						return false;


					} else if (typeof(re.appendChild) != "undefined") {


						return re;


					} else {


						return false;


					}


				} else if (typeof(liElement.appendChild) != "undefined") {


					return liElement;


				} else {


					return false;


				}


			}


liveInput.liElementHandle.appendChildren = function (liIdent, liArray) {


				var liElement = this.getElement(liIdent);


				if (!liElement) return false;


				if (typeof(liArray) != "object") return false;


				for (var i=0;i<liArray.length;i++) {


					var liContent = liArray[i];


					if (typeof(liContent) == "string") {


						liElement.appendChild(document.createTextNode(liContent));


					} else if (typeof(liContent) == "object") {


						liElement.appendChild(liContent);


					}


				}


			}


liveInput.liElementHandle.createSelect = function (liAttributes, liOptions, liSelections)	{


				var select = this.createElement('select', liAttributes);


				for (var a in liOptions) {


					var o = {id:a};


					if (a == liSelections) o.selected = "selected";


					select.appendChild(this.createElement('option', o, liOptions[a]));


				}


				return select;


			}


liveInput.liElementHandle.getPos = function (liElement) {


				var liElement = this.getElement(liElement);


				var obj = liElement;


				var curleft = 0;


				if (obj.offsetParent) {


					while (obj.offsetParent) {


						curleft += obj.offsetLeft;


						obj = obj.offsetParent;


					}


				} else if (obj.x) {


					curleft += obj.x;


				}


				var obj = liElement;


				var curtop = 0;


				if (obj.offsetParent) {


					while (obj.offsetParent) {


						curtop += obj.offsetTop


						obj = obj.offsetParent;


					}


				} else if (obj.y) {


					curtop += obj.y;


				}


				return {x:curleft, y:curtop}


			}








liveInput.LiveInput = function (liSearchField, liFillField, param) {


				if (!document.getElementById) return false;


				this.fld = liveInput.liElementHandle.getElement(liSearchField);


				this.fldNumber = liveInput.liElementHandle.getElement(liFillField);


				if (!this.fld) return false;


				this.nInputChars = 0;


				this.aSuggestions = [];


				this.nSuggestions = [];


				var neElements;


				this.iHighlighted = 0;


				this.liParam = (param) ? param : {};


				if (!this.liParam.liChars)		this.liParam.liChars = 1;


				if (!this.liParam.liMethod)		this.liParam.liMethod = "get";


				if (!this.liParam.liSearchQte)	this.liParam.liSearchQte = "search";


				if (!this.liParam.liClass)		this.liParam.liClass = "liveinput";


				if (!this.liParam.liBoxTime)	this.liParam.liBoxTime = 10000;


				if (!this.liParam.liBoxDelay)	this.liParam.liBoxDelay = 300;


				if (!this.liParam.liBoxMaxH && 	this.liParam.liBoxMaxH !== 0) this.liParam.liBoxMaxH = 126;


				if (!this.liParam.liCache)		this.liParam.liCache = true;


				var pointer = this;


				this.fld.onkeyup = function () { pointer.getSuggestions(this.value) };


				this.fld.setAttribute("autocomplete","off");


			}








liveInput.LiveInput.prototype.getSuggestions = function (liValue) {


				if (liValue.length == this.nInputChars) return false;


				if (liValue.length < this.liParam.liChars) {


					this.nInputChars = liValue.length;


					this.aSuggestions = [];	


					this.clearSuggestions();


					return false;


				}


				if (liValue.length > this.nInputChars && this.aSuggestions.length && this.liParam.liCache) {


					var liArray = [];


					for (var i = 0; i < this.aSuggestions.length; i++) {


						if (this.aSuggestions[i].substr(0,liValue.length).toLowerCase() == liValue.toLowerCase()) {


							liArray.push(this.aSuggestions[i]);


						}


					}


					this.nInputChars = liValue.length;


					this.aSuggestions = liArray;


					this.createList(this.aSuggestions);


					return false;


				}


				this.nInputChars = liValue.length;


				var pointer = this;


				clearTimeout(this.ajID);


				this.ajID = setTimeout(function() { pointer.liFileHandleRequest() }, this.liParam.liBoxDelay);


				return false;


			}


liveInput.LiveInput.prototype.liFileHandleRequest = function () {


				var pointer = this;


				var liUrl = "../Scripts/"+this.liParam.lookfor+".php?li=1i&"+this.liParam.liSearchQte+"="+this.fld.value;


				var liMethod = this.liParam.liMethod;


				var liSuccessFunc = function (liRequest) { pointer.setSuggestions(liRequest) };


				var liErrorFunc = function (status) { if (status == "404") alert("LiveInput error: Requested file not available!"); else var dudut; };


				var thisFileHandle = new liveInput.liFileHandle;


				thisFileHandle.makeRequest(liUrl, liMethod, liSuccessFunc, liErrorFunc);


			}


liveInput.LiveInput.prototype.setSuggestions = function (liRequest) {


				var xml = liRequest.responseXML;


				this.aSuggestions = [];


				var results = xml.getElementsByTagName('results')[0].childNodes;


				for (var i = 0; i < results.length; i++) {


					if (results[i].hasChildNodes()) {


						var fullSuggestion = results[i].childNodes[0].nodeValue;


						this.aSuggestions.push(fullSuggestion);


					}


				}


				this.idAs = "as_"+this.fld.id;


				this.createList(this.aSuggestions);


			}


liveInput.LiveInput.prototype.createList = function(liArray) {


				this.clearSuggestions();


				var ul = liveInput.liElementHandle.createElement("ul", {id:this.idAs, className:this.liParam.liClass});


				var pointer = this;


				for (var i = 0; i < liArray.length; i++) {


					var onclickValueName = liArray[i];


					if (this.fldNumber) {


						var fullSuggestion = onclickValueName;


						var nameSuggestion = fullSuggestion.substring(0, fullSuggestion.indexOf('|'));


						var numberSuggestion = fullSuggestion.substring(fullSuggestion.indexOf('|')+1, fullSuggestion.length);


						var aRowValue = nameSuggestion+"<small style=\"visibility:hidden\">"+numberSuggestion+"</small>";


						var a = liveInput.liElementHandle.createElement("a", {href:"#"}, aRowValue, true);


						a.onclick = function () { pointer.setValue(this.childNodes[0].nodeValue); pointer.setValueNumber(this.childNodes[1].firstChild.nodeValue); };


					} else {


						var aRowValue = onclickValueName;


						var a = liveInput.liElementHandle.createElement("a", {href:"#"}, aRowValue, true);


						a.onclick = function () { pointer.setValue(this.childNodes[0].nodeValue); };


					}


					var li = liveInput.liElementHandle.createElement("li", {}, a);


					ul.appendChild(li);


				}


				var pos = liveInput.liElementHandle.getPos(this.fld);


				ul.style.left = pos.x + "px";


				ul.style.top = (pos.y + this.fld.offsetHeight) + "px";


				ul.style.width = this.fld.offsetWidth + "px";


				ul.onmouseover = function(){ pointer.killTimeout() }


				ul.onmouseout = function(){ pointer.resetTimeout() }


				document.getElementsByTagName("body")[0].appendChild(ul);


				if (ul.offsetHeight > this.liParam.liBoxMaxH && this.liParam.liBoxMaxH != 0) {


					ul.style['height'] = this.liParam.liBoxMaxH + "px";


				}


				var TAB = 9;


				var ESC = 27;


				var KEYUP = 38;


				var KEYDN = 40;


				var RETURN = 13;


				this.fld.onkeydown = function(liEvent) {


					var key = (window.event) ? window.event.keyCode : liEvent.keyCode;


					switch(key) {


						case RETURN:


							pointer.setHighlightedValue();


							break;


						case TAB:


							pointer.setHighlightedValue();


							break;


						case ESC:


							pointer.clearSuggestions();


							break;


						case KEYUP:


							pointer.changeHighlight(key);


							return false;


							break;


						case KEYDN:


							pointer.changeHighlight(key);


							return false;


							break;


					}


				};


	


				this.iHighlighted = 0;


				clearTimeout(this.toID);


				var pointer = this;


				this.toID = setTimeout(function () { pointer.clearSuggestions() }, this.liParam.liBoxTime);


			}


liveInput.LiveInput.prototype.changeHighlight = function(key) {


				var list = liveInput.liElementHandle.getElement(this.idAs);


				if (!list) return false;


				if (this.iHighlighted > 0) list.childNodes[this.iHighlighted-1].className = "";


				if (key == 40) {


					this.iHighlighted ++;


				} else if (key = 38) {


					this.iHighlighted --;


				}


				if (this.iHighlighted > list.childNodes.length) this.iHighlighted = list.childNodes.length;


				if (this.iHighlighted < 1) this.iHighlighted = 1;


				list.childNodes[this.iHighlighted-1].className = "highlight";


				this.killTimeout();


			}


liveInput.LiveInput.prototype.killTimeout = function() {


				clearTimeout(this.toID);


			}


liveInput.LiveInput.prototype.resetTimeout = function() {


				clearTimeout(this.toID);


				var pointer = this;


				this.toID = setTimeout(function () { pointer.clearSuggestions() }, 150);


			}


liveInput.LiveInput.prototype.clearSuggestions = function () {


				if (document.getElementById(this.idAs)) liveInput.liElementHandle.removeElement(this.idAs);


				this.fld.onkeydown = null;


			}


liveInput.LiveInput.prototype.setHighlightedValue = function () {


				if (this.iHighlighted) {


					var fillNameFromSuggestionRaw = document.getElementById(this.idAs).childNodes[this.iHighlighted-1].firstChild.firstChild.nodeValue;


					var fillNameFromSuggestion = fillNameFromSuggestionRaw.substring(0, fillNameFromSuggestionRaw.indexOf('|') - 0);

					this.fld.value = fillNameFromSuggestionRaw;

					if (this.fldNumber) {


						var fillNumberFromSuggestion = document.getElementById(this.idAs).childNodes[this.iHighlighted-1].firstChild.childNodes[1].firstChild.nodeValue;


						this.fldNumber.value = fillNumberFromSuggestion;


					}


					this.killTimeout();


					this.clearSuggestions();


				}


			}


liveInput.LiveInput.prototype.setValue = function (liValue) {


				var fillNameFromSuggestion = liValue.substring(0, liValue.indexOf('(') - 1);


				this.fld.value = fillNameFromSuggestion;


				this.resetTimeout();


			}


liveInput.LiveInput.prototype.setValueNumber = function (liValueNumber) {


				this.fldNumber.value = liValueNumber;


			}





// End liveInput //



