function LivePov() { this.construct();}
LivePov.prototype = {
url:'/search_pov.php',
prevQ:'',
prevT:null,
timeout:null,
construct: function() {
this.prevT = new Date();
var th = this;
addEvent(document.getElementById('searchpov'), 'onkeydown', function(e) {
th.prevT = new Date();
if (e.keyCode == 13) th.onchangeControl(this.value, 10);
return true;
});
addEvent(document.getElementById('searchpov'), 'onkeyup', function(e) { 
if (e.keyCode == 13) return true;
th.onchangeControl(this.value, e.keyCode==32? 10 : null);
return true;
});
addEvent(document.getElementById('searchpov'), 'onfocus', function() {
// stupid Mozilla sometimes loses focus on DIV repainting :-(
return true;
});
addEvent(document.getElementById('searchpov'), 'onblur', function() {
th.onchangeControl(document.getElementById('searchpov').value, 0);
return true;
});
},
onchangeControl: function(text, dt) {
var t = new Date();
var wait = 0;
if (dt == null) dt = 100;
if (t.getTime() - this.prevT.getTime() < dt) {
this.prevT = t;
wait = dt;
}
var th = this;
if (this.timeout) { clearTimeout(this.timeout); this.timeout=null; }
this.timeout = setTimeout(function() { th.prevT = t; th.timeout=null; th.onchange(text) }, wait);
},
onchange: function(text, force) {
var q = text;
if (q != this.prevQ && q != "") {
this.prevQ = q;
var th = this;
var req = new JsHttpRequest();
req.onreadystatechange = function() {
if (req.readyState != 4) return;
if (!req.responseJS) {
document.getElementById('divsearchpov').style.display = "none";
return;
}
document.getElementById('divsearchpov').innerHTML = req.responseJS['tags'];
document.getElementById('divsearchpov').style.display = "block";
document.getElementById('searchpov').focus();
}
req.caching = false;
req.open('GET', th.url, true);
req.send({ 'q': q });
}
},
clean: function(text) {
var spl = text.split(/[\s~!@#&$%^*()\[\]{}:\"<>?`=;\',\.\/\\|\-]+/i);
var words = [];
for (var i=0; i<spl.length; i++) if (!spl[i].match(/^[a-zą-’_0-9]{0,2}$/)) 
words[words.length] = spl[i].toLowerCase();
return words.join(" ");
}
};
