var srchType=1; var variantsDiv = ""; var num=0; var curID=0; var oldID=0; function doLoad() { var req = new JsHttpRequest(); req.onreadystatechange = function() { if (req.readyState == 4) { if (req.responseJS['res']!='') { curID=0; num=req.responseJS['res_num']; document.getElementById('container').innerHTML = req.responseJS['res']; document.getElementById('container').style.display = 'block'; } else { num=0; document.getElementById('container').innerHTML = ''; document.getElementById('container').style.display = 'none'; } } } req.open(null, '../searchRCV2.php', true); req.send( { q: document.getElementById('inpId').value, t: srchType } ); } //tip: catalog, objavleniya, vezde function setType(type){ srchType = type; } function set_oldID(id){ oldID=id; } function set_curID(id){ curID=id; } function TRLostFocus (id) { document.getElementById(id).style.cursor='default'; document.getElementById(id).style.backgroundColor='white'; document.getElementById(id).style.color='black'; } //oldID_non_exist == 1, kogda s oldID net, naprimer ujesto4enie poiska function TRFocus (id, oldID_non_exist) { set_curID(id); if (oldID!=0 && oldID_non_exist==0) TRLostFocus(oldID); document.getElementById(id).style.cursor='pointer'; document.getElementById(id).style.backgroundColor='#DC302D'; document.getElementById(id).style.color='white'; set_oldID(id); } //prya4em suggest, zapolnyaem input function TRValue (id, value) { document.getElementById('inpId').value = value; document.getElementById('container').style.display = 'none'; } function keyHandler(e) { var keycode; if (window.event) { //ie keycode = window.event.keyCode; target = window.event.srcElement; } else if (e) { //fox keycode = e.which; target = e.target; } //alert(keycode); if (target.name=='q') { //input s name==q keynum = keycode; switch (keynum) { case 38: if (document.getElementById('container').style.display == 'block'){ if (curID == 0) { //peremesheniy ne bilo, vibiraem perviy set_curID('trn^1'); TRFocus(curID); set_oldID(curID); }else { tmp=curID.split("^"); tmp[1] = parseInt(tmp[1]); if (tmp[1] != 1) { TRLostFocus(oldID); tmp[1] = tmp[1] - 1; set_curID('trn^' + tmp[1]); TRFocus(curID); set_oldID(curID); } } } break case 40: if (document.getElementById('container').style.display == 'block'){ if (curID==0) { set_curID('trn^1'); TRFocus(curID, '1'); set_oldID(curID); }else { tmp=curID.split("^"); tmp[1] = parseInt(tmp[1]); if (tmp[1]>=num){ TRLostFocus(oldID); set_curID('trn^' + num); TRFocus(curID, '1'); }else { if (tmp[1] != num) { TRLostFocus(oldID); tmp[1] = tmp[1] + 1; set_curID('trn^' + tmp[1]); TRFocus(curID, '0'); set_oldID(curID); } } } } break case 13: TRValue (curID, document.getElementById(curID).firstChild.firstChild.nodeValue); document.getElementById('inpId').submit(); return true; break case 8: if (document.getElementById('inpId').value.length-1 > 1){ doLoad(); }else { document.getElementById('container').style.display = 'none'; } break default : doLoad(); break } } }