Want more features on Pastebin? Sign Up, it's FREE!
Guest

Localitatea de sosire

By: a guest on Mar 28th, 2013  |  syntax: None  |  size: 8.15 KB  |  views: 23  |  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 arrivalRequest;
  2. var arrivalResult = null;
  3. var dstArrivalObj = null;
  4. var arrivalIndex = -1;
  5. var arrivalSelectedValue = null;
  6. var arrivalOk = false;
  7. var arrivalInput = null;
  8. var arrivalSrollVisible = false;
  9.  
  10. var finalDeparture = null;
  11. var finalArrival = null;
  12.  
  13. var finalRequest;
  14.  
  15. function arrivalIn() {
  16.     dstArrivalObj = document.getElementById('plecari');
  17.     clearTimeout(thread);
  18.     hideDepartures();
  19.  
  20.     // daca e scris ceva in inputul de sosiri in momentul in care ia focusul lansam thread-ul
  21.     arrivalInput = document.getElementById('la');
  22.     if (arrivalInput.value != '') {
  23.         if (thread != null)
  24.           clearTimeout(thread);
  25.         thread = setTimeout('doArrivalRequest()', 300);
  26.     }
  27.  
  28. }
  29. function arrivalOut() {
  30.     clearTimeout(thread);
  31.     hideArrivals();
  32. }
  33.  
  34. function arivalKeyUp(key) {
  35.     hideDepartures();
  36.     arrivalInput = document.getElementById('la');
  37.     if (arrivalInput.value == '') {// daca e vid anulam call-ul si ascundem meniul
  38.         clearTimeout(thread);
  39.         hideArrivals();
  40.         return;
  41.     }
  42.  
  43.     if ((key == 9) || (key == 13) || (key == 38) || (key == 40) || (key == 16))
  44.     // tab, enter, sageata sus, sageata jos, shift
  45.       return true;
  46.     if (thread != null)
  47.       clearTimeout(thread);
  48.     thread = setTimeout('doArrivalRequest()', 300);
  49. }
  50.  
  51. function arrivalKeyDown(key) {
  52.     hideDepartures();
  53.     arrivalInput = document.getElementById('la');
  54.     dstArrivalObj = document.getElementById('sosiri');
  55.  
  56.     if (arrivalInput.value == '') {// daca e vid anulam call-ul si ascundem meniul
  57.         clearTimeout(thread);
  58.         hideArrivals();
  59.     }
  60.    
  61.     if ((key == 9) && (arrivalSelectedValue != null) && (arrivalOk)) {
  62.             arrivalInput.value = arrivalSelectedValue;
  63.             hideArrivals();
  64.             finish();
  65.     }
  66.  
  67.     if ((key == 13) && (arrivalSelectedValue != null) && (arrivalOk)) {
  68.             arrivalInput.value = arrivalSelectedValue;
  69.             hideArrivals();
  70.             finish();
  71.     }
  72.  
  73.     // daca meniul nu este vizibil nu tinem cont de sageata sus si sageata jos
  74.     if (! arrivalSrollVisible)
  75.         return true;
  76.  
  77.  
  78.     if (key == 38) {
  79.         if (arrivalIndex > 0) {
  80.             arrivalIndex--;
  81.             showArrivals();
  82.             buildArrivalTable();
  83.         }
  84.         return true;
  85.     }
  86.  
  87.     if (key == 40) {
  88.         if (arrivalIndex < arrivalResult.arrivals.length - 1) {
  89.             arrivalIndex++;
  90.             showArrivals();
  91.             buildArrivalTable();
  92.         }
  93.         return true;
  94.     }
  95. }
  96.  
  97. function doArrivalRequest() {
  98.  
  99.   if (arrivalInput.value == '') // daca e vid nu face call-ul
  100.     return;
  101.  
  102.   departureInput = document.getElementById('dela');
  103.  
  104.   try {
  105.     if (window.XMLHttpRequest)
  106.         arrivalRequest = new XMLHttpRequest();
  107.     else
  108.         if (window.ActiveXObject)
  109.           arrivalRequest = new ActiveXObject("Microsoft.XMLHTTP");
  110.   } catch (e) {
  111.       return false;
  112.   }
  113.  
  114.  
  115.   arrivalRequest.onreadystatechange = waitArrivalResponse;
  116.   arrivalRequest.open('GET', 'getsosiri.php?' + departureInput.name + '=' + replaceDiacritics(townMatch(departureInput.value)) + '&' + arrivalInput.name + '=' + replaceDiacritics(townMatch(arrivalInput.value)), true);
  117.   arrivalRequest.send('');
  118.   return true;
  119. }
  120.  
  121. function waitArrivalResponse() {
  122.   if (arrivalRequest.readyState == 4) {
  123.     if (arrivalRequest.status == 200) {
  124.         arrivalResult = eval('(' + arrivalRequest.responseText + ')');
  125.  
  126.         if (arrivalResult.arrivals.length == 0) {
  127.             arrivalResult.arrivals[0] = 'Nici o cursă găsită!'
  128.             arrivalOk = false;
  129.         }
  130.         else {
  131.             arrivalOk = true;
  132.         }
  133.         arrivalIndex = 0;
  134.         if (!((arrivalInput.value == '') || ((replaceDiacritics(townMatch(arrivalInput.value.toLowerCase())) == replaceDiacritics(arrivalResult.arrivals[0].toLowerCase())) && (arrivalResult.arrivals.length == 1)))) {
  135.             showArrivals();
  136.             buildArrivalTable();
  137.         }
  138.         // un singur raspuns, match perfect pe user input
  139.         if ((replaceDiacritics(townMatch(arrivalInput.value.toLowerCase())) == replaceDiacritics(arrivalResult.arrivals[0].toLowerCase())) && (arrivalResult.arrivals.length == 1)) {
  140.             hideArrivals();
  141.             finish();
  142.         }
  143.  
  144.     }
  145.   }
  146. }
  147.  
  148. function showArrivals() {
  149.     if (dstArrivalObj == null)
  150.         return;
  151.     dstArrivalObj.style.top = '81px';
  152.     dstArrivalObj.style.left = $('#la').offset().left + 'px';
  153.     dstArrivalObj.style.visibility = 'visible';
  154.     dstArrivalObj.style.display = 'inline';
  155.     arrivalSrollVisible = true;
  156. }
  157.  
  158. function hideArrivals() {
  159.     if (dstArrivalObj == null)
  160.         return;
  161.     while (dstArrivalObj.rows.length > 0)
  162.         dstArrivalObj.deleteRow(0);    
  163.     dstArrivalObj.style.visibility = 'hidden';
  164.     dstArrivalObj.style.display = 'none';
  165.     arrivalSrollVisible = false;
  166.     arrivalSelectedValue = null;
  167. }
  168.  
  169. function selectArrivalTableItem() {
  170.     var color;
  171.     if (arrivalOk)
  172.       color = '#14a143';
  173.     else
  174.       color = 'red';
  175.     for (var i = 0; i < dstArrivalObj.rows.length; i++) {
  176.         var row = dstArrivalObj.rows[i];
  177.         var cell = row.cells[0];
  178.         if (i == arrivalIndex) {
  179.             cell.style.color = 'white';
  180.             cell.style.backgroundColor = color;
  181.             arrivalSelectedValue = arrivalResult.arrivals[i];
  182.         }
  183.         else {
  184.             cell.style.color = '#666666';
  185.             cell.style.backgroundColor = 'white';
  186.         }
  187.     }
  188. }
  189.  
  190. function getArrivalTableItemIndex(cell) {
  191.     for (var i = 0; i < dstArrivalObj.rows.length; i++) {
  192.         var row = dstArrivalObj.rows[i];
  193.         if (row.cells[0] == cell)
  194.             return i;
  195.     }
  196. }
  197.  
  198. function buildArrivalTable() {
  199.     while (dstArrivalObj.rows.length > 0)
  200.         dstArrivalObj.deleteRow(0);
  201.  
  202.     if (arrivalResult == null)
  203.       return;
  204.  
  205.     for (var i = 0; i < arrivalResult.arrivals.length; i++) {
  206.         var row = dstArrivalObj.insertRow(i);
  207.         var cell = row.insertCell(0);
  208.         cell.innerHTML = arrivalResult.arrivals[i];
  209.         cell.onmousemove = function() {
  210.             arrivalIndex = getArrivalTableItemIndex(this);
  211.             selectArrivalTableItem();
  212.         }
  213.         cell.onmousedown = function() {
  214.             arrivalIndex = getArrivalTableItemIndex(this);
  215.             selectArrivalTableItem();
  216.             if (arrivalOk) {
  217.                  arrivalInput.value = arrivalSelectedValue;
  218.                  finish();
  219.             }
  220.             hideArrivals();
  221.         }
  222.     }
  223.     selectArrivalTableItem();    
  224. }
  225.  
  226. function finish() {
  227.     try {
  228.         if (window.XMLHttpRequest)
  229.             finalRequest = new XMLHttpRequest();
  230.         else
  231.             if (window.ActiveXObject)
  232.                 finalRequest = new ActiveXObject("Microsoft.XMLHTTP");
  233.     } catch (e) {
  234.       return false;
  235.     }
  236.  
  237.     finalDeparture = townNameFormat(townMatch(replaceDiacritics(departureInput.value)));
  238.     finalArrival = townNameFormat(townMatch(replaceDiacritics(arrivalInput.value)));
  239.     finalRequest.onreadystatechange = doFinalRequest;    
  240.     finalRequest.open('GET', 'autocare.php?nmp=1&dela=' + finalDeparture  + '&la=' +  finalArrival, true);
  241.     finalRequest.send('');
  242.    
  243.     return true;
  244. }
  245.  
  246. function doFinalRequest() {
  247.     if (finalRequest.readyState == 4) {
  248.       if (finalRequest.status == 200) {
  249.         var content = document.getElementById('content');
  250.         content.innerHTML = finalRequest.responseText;
  251.         document.title = 'Orarul curselor FANY de la ' + finalDeparture +  ' la ' + finalArrival;
  252.          
  253.         var urlDeparture = finalDeparture.replace(/-/g, ' ');
  254.         var urlArrival = finalArrival.replace(/-/g, ' ');
  255.         var ajax_url = '/autocare-' + urlDeparture + '-' + urlArrival;
  256.         var pageTracker = _gat._getTracker('UA-9627298-1');
  257.         pageTracker._trackPageview(ajax_url);
  258.  
  259.         // +1 code
  260.         var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
  261.         po.src = 'https://apis.google.com/js/plusone.js';
  262.         var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
  263.       }
  264.     }
  265. }
clone this paste RAW Paste Data