function addEvent(object,eventName,do_function) { if(typeof(object) == "string") object = document.getElementById(object); if(!object) { alert('No object in function addEvent!'); return; } if(object.addEventListener) { object.addEventListener(eventName, do_function, false); } else { object.attachEvent('on'+eventName, do_function); } } function setSelectionRange(obj) { if(obj && typeof(obj) == "object" && (obj.type == "text" || obj.type == "textarea")) { if(obj.createTextRange) { var range = obj.createTextRange(); range.moveStart("character", 0); range.moveEnd("character", obj.value.lengh-1); range.select(); } else { if(obj.setSelectionRange) { obj.setSelectionRange(0,obj.value.length); } } obj.focus(); } if(obj && typeof(obj) == "object" && obj.options) { obj.focus(); } } var AjaxSearchItems; function AjaxSearch(div,displayNone) { //fields this.parentDIV = div; //pole w ktorym zawiera sie pole wyszukiwania this.div; //pole glowne wyszukiwania this.inputSearch; //input wyszukiwania this.timeout; //wskaznik zwracany przez setTimeout przy wcisnieciu klawisza this.searchDelay = 800; //opoznienie wyszukiwania this.divList; //pole w ktorym wyswietlana bedzie lista znalezionnych elementow this.ajaxSearchItem; //unikalny identyfikator; this.module = 'EcmProducts'; this.inputCode; this.positionSelected; //functions this.setInputCode = function(input) { this.inputCode = input; this.inputCode.previousCode = this.inputCode.value; } this.inputSearchOnKeyDown = function(e,other) { var keynum; if(typeof(e) == "number") keynum = e; else { if(window.event) //IE keynum = e.keyCode; else keynum = e.which; } if(keynum == 38) { this.selectPreviousPosition(); return false; } if(keynum == 40) { this.selectNextPosition(); return false; } if(keynum == 13 || keynum == 9) { this.inputSearchEnterPressed(other); return false; } if(keynum == 27) { this.div.style.display = 'none'; } if(this.timeout) { clearTimeout(this.timeout); this.timeout = null; } this.timeout = setTimeout("document.getElementById('"+this.div.id+"').AjaxSearch.search();", 500); } this.inputSearchEnterPressed = function(other) { if(this.positionSelected) { var row; if(N.selectedRow) { N.selectedRow.setData(this.positionSelected.positionData); row = N.selectedRow; } else { row = N.addRow().setData(this.positionSelected.positionData); } row.calculateTotal(); if((other && other == "clear") || OPT['quick_product_item_adding']==0) { this.clearList(); this.div.style.display = 'none'; if(OPT['quick_product_item_adding'] == 0) if(N.selectedCell && N.selectedCell.index == 1) N.selectedCell.selectNext(); } else { row.noHideASP = true; if(N.selectedRow) row = row.myTable.addRow(row.index+1); row.select(); row.cells.item(0).select(); setSelectionRange(this.inputSearch); } } else if(N.selectedRow) { if(this.inputSearch.value != this.inputCode.previousCode || this.inputCode.previousCode == '') { var data = new Object(); N.selectedRow.setData(data); N.selectedRow.cells.item(1).select(); } } //N.addRow(); } this.selectNextPosition = function() { if(this.positionSelected) { if(this.positionSelected.nextSibling) { this.positionSelect(this.positionSelected.nextSibling); return; } } this.positionSelect(this.divList.lastChild); } this.selectPreviousPosition = function() { if(this.positionSelected) { if(this.positionSelected.previousSibling) { this.positionSelect(this.positionSelected.previousSibling); return; } } this.positionSelect(this.divList.firstChild); } this.search = function() { if(this.inputSearch.value == '') { this.clearList(); return; } var _ajax_search_process_search_ = this; this.Display = function(result) { _ajax_search_process_search_.processSearch(result.responseText); } this.Fail = function(result) { alert(result.responseText); } YAHOO.util.Connect.asyncRequest('POST','index.php',{success:this.Display,failure:this.Fail},'module='+this.module+'&action=AjaxSearchQuery&to_pdf=1&as_inputSearch='+this.inputSearch.value); //+'&ecmlanguage='+document.forms.EditView.ecmlanguage.value); } this.processSearch = function(result) { this.clearList(); var list = eval(result); if(typeof(list) != "object") return; this.fillList(list); } this.clearList = function() { this.divList.innerHTML = ''; this.divList.style.height = ''; this.positionDeselect(); } this.fillList = function(list) { for(x in list) { this.addPosition(list[x]); } this.positionSelect(); this.setScrolls(); } this.setScrolls = function() { var clientH = -1; if(window.innerHeight && window.innerHeight > 0) clientH = window.innerHeight; else if(document.documentElement && document.documentElement.clientHeight > 0) clientH = document.documentElement.clientHeight; else if(document.body && document.body.clientHeight > 0) clientH = document.body.clientHeight; var XY = YAHOO.util.Dom.getXY(this.div); var divTop = (XY[1]+this.div.offsetHeight); if((divTop - (clientH+document.body.scrollTop)) > 0) { var newPos = divTop-clientH; document.body.scrollTop = newPos; } } this.positionSelect = function(div,noScroll) { if(!div) { if(!this.positionSelected) { if(this.divList.firstChild) this.positionSelect(this.divList.firstChild); } return; } this.positionDeselect(); div.className = 'AjaxSearchPositionDivSelected'; this.positionSelected = div; if(!noScroll) this.divList.scrollTop = div.offsetTop; } this.positionDeselect = function() { if(this.positionSelected) { this.positionSelected.className = ''; this.positionSelected = null; } } this.addPosition = function(list) { if(typeof(list.code) == "undefined") return; var position = document.createElement('div'); position.positionData = list; position.onclick = function() { this.parentNode.AjaxSearch.inputSearchEnterPressed(this); } position.onmouseover = function() { this.parentNode.AjaxSearch.positionSelect(this,true); }; position.innerHTML = '
| '+this.markElement(list['code'])+' | '+list['purchase_price']+' '+list['currency_symbol']+' - '+list['selling_price']+' '+list['currency_symbol']+' |
| '+this.markElement(list['name'])+' | |
';
img += '