Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

Localitatea de plecare

By: a guest on Mar 28th, 2013  |  syntax: None  |  size: 4.39 KB  |  hits: 28  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. var departureRequest;var departureResult=null;var dstDepartureObj=null;var departureSelectedValue=null;var departureIndex=-1;var departureOk=false;var departureInput=null;var departureSrollVisible=false;var thread=null;function departureIn(){document.getElementById('la').value='';departureInput=document.getElementById('dela');if(departureInput.value!=''){if(thread!=null)
  2. clearTimeout(thread);thread=setTimeout('doDepartureRequest()',300);}}
  3. function departureOut(){clearTimeout(thread);hideDepartures();}
  4. function departureKeyUp(key){departureInput=document.getElementById('dela');if(departureInput.value==''){clearTimeout(thread);hideDepartures();return;}
  5. if((key==9)||(key==13)||(key==38)||(key==40)||(key==16))
  6. return true;if(thread!=null)
  7. clearTimeout(thread);thread=setTimeout('doDepartureRequest()',300);}
  8. function departureKeyDown(key){departureInput=document.getElementById('dela');dstDepartureObj=document.getElementById('plecari')
  9. if(departureInput.value==''){clearTimeout(thread);hideDepartures();}
  10. if((key==9)&&(departureSelectedValue!=null)&&(departureOk)){departureInput.value=departureSelectedValue;hideDepartures();}
  11. if((key==13)&&(departureSelectedValue!=null)&&(departureOk)){departureInput.value=departureSelectedValue;hideDepartures();}
  12. if(!departureSrollVisible)
  13. return true;if(key==38){if(departureIndex>0){departureIndex--;showDepartures();buildDepartureTable();}
  14. return true;}
  15. if(key==40){if(departureIndex<departureResult.departures.length-1){departureIndex++;showDepartures();buildDepartureTable();}
  16. return true;}}
  17. function doDepartureRequest(){if(departureInput.value=='')
  18. return;try{if(window.XMLHttpRequest)
  19. departureRequest=new XMLHttpRequest();else
  20. if(window.ActiveXObject)
  21. departureRequest=new ActiveXObject("Microsoft.XMLHTTP");}catch(e){return false;}
  22. departureRequest.onreadystatechange=waitDepartureResponse;departureRequest.open('GET','getplecari.php?'+departureInput.name+'='+replaceDiacritics(townMatch(departureInput.value)),true);departureRequest.send('');return true;}
  23. function waitDepartureResponse(){if(departureRequest.readyState==4){if(departureRequest.status==200){departureResult=eval('('+departureRequest.responseText+')');if(departureResult.departures.length==0){departureResult.departures[0]='Localitate invalidă!'
  24. departureOk=false;}
  25. else{departureOk=true;}
  26. departureIndex=0;if(!((departureInput.value=='')||((replaceDiacritics(townMatch(departureInput.value.toLowerCase()))==replaceDiacritics(departureResult.departures[0].toLowerCase()))&&(departureResult.departures.length==1)))){showDepartures();buildDepartureTable();}
  27. if((replaceDiacritics(townMatch(departureInput.value.toLowerCase()))==replaceDiacritics(departureResult.departures[0].toLowerCase()))&&(departureResult.departures.length==1))
  28. hideDepartures();}}}
  29. function showDepartures(){if(dstDepartureObj==null)
  30. return;dstDepartureObj.style.top='57px';dstDepartureObj.style.left=$('#dela').offset().left+'px';dstDepartureObj.style.visibility='visible';dstDepartureObj.style.display='inline';departureSrollVisible=true;}
  31. function hideDepartures(){if(dstDepartureObj==null)
  32. return;while(dstDepartureObj.rows.length>0)
  33. dstDepartureObj.deleteRow(0);dstDepartureObj.style.visibility='hidden';dstDepartureObj.style.display='none';departureSrollVisible=false;departureSelectedValue=null;}
  34. function selectDepartureTableItem(){var color;if(departureOk)
  35. color='#14a143';else
  36. color='red';for(var i=0;i<dstDepartureObj.rows.length;i++){var row=dstDepartureObj.rows[i];var cell=row.cells[0];if(i==departureIndex){cell.style.color='white';cell.style.backgroundColor=color;departureSelectedValue=departureResult.departures[i];}
  37. else{cell.style.color='#666666';cell.style.backgroundColor='white';}}}
  38. function getDepartureTableItemIndex(cell){for(var i=0;i<dstDepartureObj.rows.length;i++){var row=dstDepartureObj.rows[i];if(row.cells[0]==cell)
  39. return i;}}
  40. function buildDepartureTable(){while(dstDepartureObj.rows.length>0)
  41. dstDepartureObj.deleteRow(0);for(var i=0;i<departureResult.departures.length;i++){var row=dstDepartureObj.insertRow(i);var cell=row.insertCell(0);cell.innerHTML=departureResult.departures[i];cell.onmousemove=function(){departureIndex=getDepartureTableItemIndex(this);selectDepartureTableItem();}
  42. cell.onmousedown=function(){departureIndex=getDepartureTableItemIndex(this);selectDepartureTableItem();if(departureOk)
  43. departureInput.value=departureSelectedValue;hideDepartures();}}
  44. selectDepartureTableItem();}// JavaScript Document