// INSTANT SEARCH var req = null; var currscroll = 0; var lastquery = ""; var AjaxSearchCsomag = { areThePositionsInitialized: false, init: function() { defcity = ""; defcityID = ""; var q2 = $("csomag_cityname"); q2.originalValue = q2.value; // eltároljuk az eredeti szöveget q2.onfocus = function() { AjaxSearchCsomag.onFocus(q2); } // ha belelép q2.onblur = function() { AjaxSearchCsomag.onBlur(q2); } // ha kilép q2.onkeyup = function() { AjaxSearchCsomag.sendQuery(q2); } if (q2.value != 'Bármely') q2.value = defcity; $("csomag_cityID").value = defcityID; }, scrollSelect : function() { if (currscroll > 0) { $("csomag_cityname").value = $("element_name_"+currscroll).value; $("csomag_cityID").value = $("element_id_"+currscroll).value; setTimeout('$("instantsearchblockcsomag").setStyle("display", "none")', 200); } }, scrollDown : function() { var totalscroll = $("elementnum").value; if (currscroll > 0) { $("element_"+currscroll).className = "nonscrolled"; } currscroll++; if (currscroll > totalscroll) currscroll = 1; $("element_"+currscroll).className = "scrolled"; }, scrollUp : function() { if (currscroll > 0) { $("element_"+currscroll).className = "nonscrolled"; } currscroll--; if (currscroll <= 0) currscroll = $("elementnum").value; $("element_"+currscroll).className = "scrolled"; }, init2: function() { this.areThePositionsInitialized = true; }, onFocus: function(input) { if (this.areThePositionsInitialized == false) this.init2(); // ha az eredeti szöveg van az inputban, akkor töröljük //if (input.value == defcity) input.value = ''; if (input.value == 'Bármely') input.value = ''; }, onBlur: function(input) { if (currscroll > 0) { $("csomag_cityname").value = $("element_name_"+currscroll).value; $("csomag_cityID").value = $("element_id_"+currscroll).value; } else { var totalscroll = $("elementnum").value; if (totalscroll > 0) { $("csomag_cityname").value = $("element_name_1").value; $("csomag_cityID").value = $("element_id_1").value; } else { input.value = defcity; $("csomag_cityID").value = defcityID; } } setTimeout('$("instantsearchblockcsomag").setStyle("display", "none")', 200); }, // lekérdezés sendQuery: function(input) { $("instantsearchblockcsomag").setStyle("display", "block"); var v = input.value; if (v == "") { return; } if (lastquery == v) { return; } lastquery = v; currscroll = 0; req = new Request.HTML({ url:'/ajax.php?action=AjaxSearchCsomag&q='+ escape(v), onSuccess: function(html) { $("instantsearchblockcsomag").innerHTML = ""; $('instantsearchblockcsomag').adopt(html); if (($("instantsearchblockcsomag").innerHTML != "") && ($('searchresultdefid')) && ($('searchresultdefname'))) { defcity = $('searchresultdefname').value; defcityID = $('searchresultdefid').value; } }, onFailure: function() { alert('The request failed!'); return false; } }); req.send(); }, // a gyorskeresésben kiválasztott elemet hozzáadja a listához addElement: function(id, nev) { $("csomag_cityname").value = nev; $("csomag_cityID").value = id; defcity = nev; defcityID = id; $("instantsearchblockcsomag").setStyle("display", "none"); } } //******************************************* //INICIALIZÁLÁS var defcity = ""; var defcityID = ""; window.addEvent('domready', function() { AjaxSearchCsomag.init(); });