function searchbox(item_id, event){ s_val = document.getElementById('search').value; if(!event) event = window.event; k = event.keyCode; s = 0; if(k == 13){ if(document.getElementById("current_path")) location = document.getElementById("current_path").value; s = 1; } if(s_val != "" && s == 0){ function afterDone(data){ //пишем таблицу if(data) document.getElementById(item_id).innerHTML = data; //делаем бродилку var results_amount = document.getElementById("results_amount").value; var current_item = document.getElementById("current_item").value; //стрелка вверх if(k == 38){ if(document.getElementById("current_item").value == 0){ document.getElementById("item_"+results_amount).style.backgroundColor = "#daeecb"; document.getElementById("current_item").value = results_amount; document.getElementById("current_path").value = document.getElementById("path_"+results_amount).value; document.getElementById("search").value = document.getElementById("name_"+results_amount).innerHTML; cleanSeparations(); } else if(document.getElementById("current_item").value == 1){ document.getElementById("item_"+results_amount).style.backgroundColor = "#daeecb"; document.getElementById("current_item").value = results_amount; document.getElementById("current_path").value = document.getElementById("path_"+current_item).value; document.getElementById("search").value = document.getElementById("name_"+current_item).innerHTML; cleanSeparations(); } else { current_item = document.getElementById("current_item").value - 1; document.getElementById("item_"+current_item).style.backgroundColor = "#daeecb"; document.getElementById("current_item").value--; document.getElementById("current_path").value = document.getElementById("path_"+current_item).value; document.getElementById("search").value = document.getElementById("name_"+current_item).innerHTML; cleanSeparations(); } } //стрелка вниз if(k == 40){ if(document.getElementById("current_item").value == 0){ document.getElementById("item_1").style.backgroundColor = "#daeecb"; document.getElementById("current_item").value = 1; document.getElementById("current_path").value = document.getElementById("path_1").value; document.getElementById("search").value = document.getElementById("name_1").innerHTML; } else if(document.getElementById("current_item").value == results_amount){ document.getElementById("item_1").style.backgroundColor = "#daeecb"; document.getElementById("current_item").value = 1; document.getElementById("current_path").value = document.getElementById("path_1").value; document.getElementById("search").value = document.getElementById("name_1").innerHTML; cleanSeparations(); } else { current_item = document.getElementById("current_item").value * 1 + 1; document.getElementById("item_"+current_item).style.backgroundColor = "#daeecb"; document.getElementById("current_item").value++; document.getElementById("current_path").value = document.getElementById("path_"+current_item).value; document.getElementById("search").value = document.getElementById("name_"+current_item).innerHTML; cleanSeparations(); } } function cleanSeparations(){ counter = 0; for(i = 0; i != results_amount; i++){ counter++; if(document.getElementById("current_item").value != counter){ document.getElementById("item_"+counter).style.backgroundColor = "#fff"; } } } } if(!document.getElementById("current_item")){ citem = 0; } else citem = document.getElementById("current_item").value; if(!document.getElementById("current_path")){ cpath = ""; } else cpath = document.getElementById("current_path").value; if(k != 38 && k != 40){ $.post( '/',{ searchbox_val : s_val, current_item : citem, current_path : cpath }, afterDone ); } else afterDone(0); } else document.getElementById(item_id).innerHTML = ""; }