You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

1 lines
7.3 KiB

var firstLoad=true;var arStopNames,arBusMaster,arBusList,arStopBus;var gStartStop,gDestStop;var gaoNearStops=null;var goNearestStop=null;var MAXRECENTSTOPS=7;var selectedInput=1;var goCurStop={id:""};$(document).ready(function(){arStopNames=getStopNames();arBusMaster=getbusmaster();arBusList=getbuslist();arStopBus=getStopBusList();scrollTo(0,0);getLocation();PopulateAllBusList();PopulateOtherBusLists();activateList("ALL");initStops();showRecentStops();document.getElementById("busNoCombo").checked=true;$("#startStop").autocomplete({source:function(f,b){var e=$.ui.autocomplete.escapeRegex(f.term);e=e.toLowerCase();stopid=e.replace(/[^a-zA-Z0-9]+/g,"");var a=stopid.length;var d=0;matchArr=[];for(var c=0;c<stopNames.length;c++){if(stopid==stopNames[c][0].toLowerCase().substring(0,a)){matchArr[d]=createOStop(stopNames[c]);d=d+1}}if(!matchArr.length){for(var c=0;c<stopNames.length;c++){if(stopNames[c][3].indexOf(stopid)>=0){matchArr[d]=createOStop(stopNames[c]);d=d+1}}}b(matchArr)},minLength:2,select:function(a,b){$("#startStop").val(b.item.value);setStart(b.item);$("#destStop").focus()}});$("#startStop").focus(function(){selectedInput=1});$("#destStop").autocomplete({source:function(f,b){var e=$.ui.autocomplete.escapeRegex(f.term);e=e.toLowerCase();stopid=e.replace(/[^a-zA-Z0-9]+/g,"");var a=stopid.length;var d=0;matchArr=[];for(var c=0;c<stopNames.length;c++){if(stopid==stopNames[c][0].toLowerCase().substring(0,a)){matchArr[d]=createOStop(stopNames[c]);d=d+1}}if(!matchArr.length){for(var c=0;c<stopNames.length;c++){if(stopNames[c][3].indexOf(stopid)>=0){matchArr[d]=createOStop(stopNames[c]);d=d+1}}}b(matchArr)},minLength:2,select:function(a,b){$("#destStopId").val(b.item.id);setCookie("cDestStop",b.item.value,1);setCookie("cDestStopNameId",b.item.id,1);setDest(b.item);$("#fndBusBtn").focus()}});$("#destStop").focus(function(){selectedInput=2})});function setGeoPos(a){geoPos=a}function showLocation(g){if(typeof(document.getElementById("myLoc"))==="undefined"){return}var b=[];var d,c,a,f,e;b=findNearStops(g);c='<table id="myLoc" class="tbl_color">';if(b!==null){for(a=0;a<b.length;a+=1){f=b[a];if(a===0){goNearestStop=f;document.getElementById("stopsnearyou").innerHTML="Nearby Stops ("+f.area+")";setStart(f)}e="<tr><td><a href=\"javascript:popStop({'di':"+a+",'id':'"+f.id+"', 'area': '"+f.area+"', 'stopname': '"+f.stopname+"', 'landmark': '"+f.landmark+"', 'stopnameext': '"+f.stopnameext+"'}, 1)\">"+f.stopname+"</td><td>"+f.di+"&nbsp;m</a></td></tr>";c=c+e;if(a>=2){break}}}else{c=c+"<tr><td>No stops near you found</td></tr>"}if(firstLoad){if(goNearestStop!==null){$("#startStop").val(goNearestStop.stopname);showRoutesAtStop(goNearestStop,"Buses at "+goNearestStop.stopname+" ");$("#destStop").focus();firstLoad=false}}c=c+"</tbody></table>";document.getElementById("myLoc").innerHTML=c;setCookie("cMyLat",g.coords.latitude,1);setCookie("cMyLon",g.coords.longitude,1)}function setStart(a){gStartStop=a;localStorage.startStop=JSON.stringify(gStartStop);setCookie("cStartStop",a.stopname,1);setCookie("cStartStopNameId",a.id,1);addRecentStop(a);showRoutesAtStop(a,"Buses at "+a.stopname+" ")}function addRecentStop(f){if(f.id===goCurStop.id){return}oCurStop=f;var b=localStorage.recentStops;var a;if(b!=null){a=JSON.parse(b)}e=null;var e=new Array;e[0]=f;var g=false;if(a!==null&&a!=undefined){for(var d=0;d<a.length;d++){if(a[d]===undefined||a[d]===null){continue}g=false;for(var c=0;c<e.length;c++){if(e[c].stopname===a[d].stopname){g=true;break}}if(!g){e[e.length]=a[d]}}}if(!g){localStorage.recentStops=JSON.stringify(e);showRecentStops()}}function showRecentStops(){if(localStorage.recentStops===undefined||localStorage.recentStops===null){return}var b=JSON.parse(localStorage.recentStops);recentStopsStr='<table id="recentStops" class="tbl_color">';if(b===null){return}if(b.length){for(var a=0;a<b.length&&a<MAXRECENTSTOPS;a++){if(b[a]!==null&&b[a]!==undefined&&typeof(b[a])==="object"){lmark=typeof(b[a].landmark)=="undefined"||b[a].landmark=="undefined"?"":b[a].landmark;elm="<tr><td><a href=\"javascript:popStop({'id':'"+b[a].id+"', 'area': '"+b[a].area+"', 'stopname': '"+b[a].stopname+"', 'landmark': '"+b[a].landmark+"', 'stopnameext': '"+b[a].stopnameext+"'}, selectedInput)\">"+b[a].stopname+"</td><td>"+b[a].area+"</td><td>"+lmark+"</a></td></tr>";recentStopsStr=recentStopsStr+elm}}recentStopsStr=recentStopsStr+"</table>";document.getElementById("recentStops").innerHTML=recentStopsStr}}function activateList(a){document.getElementById("busNoCombo").style.display="none";document.getElementById("oBus").style.display="none";document.getElementById("lBus").style.display="none";document.getElementById("aBus").style.display="none";document.getElementById("asBus").style.display="none";document.getElementById("cBus").style.display="none";if(a==="ALL"){document.getElementById("busNoCombo").style.display="block"}else{if(a==="O"){document.getElementById("oBus").style.display="block"}else{if(a==="L"){document.getElementById("lBus").style.display="block"}else{if(a==="A"){document.getElementById("aBus").style.display="block"}else{if(a==="AS"){document.getElementById("asBus").style.display="block"}else{if(a==="C"){document.getElementById("cBus").style.display="block"}}}}}}}function createOStop(a){return{id:a[3],label:a[0]+": "+a[1]+" "+a[2],area:a[0],value:a[1],stopname:a[1],landmark:a[2]}}function popStop(b,a){if(a===1){$("#startStop").val(b.stopname);setCookie("cStartStop",b.stopname,1);setStart(b);$("#destStop").focus()}else{if(a===2){$("#destStop").val(b.stopname);setCookie("cDestStop",b.stopname,1);setDest(b);$("#findBus").focus()}}}function setDest(a){gDestStop=a;localStorage.destStop=JSON.stringify(gDestStop);setCookie("cDestStop",a.stopname,1);setCookie("cDestStopNameId",a.id,1);addRecentStop(a)}function initStops(){if(typeof(localStorage.destStop)!=="undefined"){if(localStorage.startStop!==null&&localStorage.startStop!=="undefined"){gStartStop=JSON.parse(localStorage.startStop);$("#startStop").val(gStartStop.stopname)}}if(typeof(localStorage.destStop)!=="undefined"){if(localStorage.destStop!==null&&localStorage.destStop!=="undefined"){gDestStop=JSON.parse(localStorage.destStop);$("#destStop").val(gDestStop.stopname)}}}function validateFindBusForm(){var e,g,d,b,a,f,i,c,h;e="";g="";d="";if(gStartStop.id===""&&gDestStop.id===""){alert("Enter a start stop or a start and destination stop");return false}if(gStartStop.id===""&&gDestStop.id!==""){alert("To check buses near a stop enter only start stop");return false}if(gStartStop.id!==""&&gDestStop.id===""){if(gStartStop!==undefined&&gStartStop.id!==""){g=gStartStop.id;d="";e="busesfound.html?s="+gStartStop.id}}if(gStartStop!==null&&gDestStop.id!==null){g=gStartStop.id;d=gDestStop.id;e="busesfound.html?s="+gStartStop.id+"&d="+gDestStop.id}if(e!==""){goLinkBusesFound(gStartStop.id,gDestStop.id);return false}return}function clearInput(){if(selectedInput===1){document.getElementById("startStop").value="";setCookie("cStartStop","",1);setCookie("cStartStopNameId",0,1);setCookie("cStartStopInfo",0,1);$("#startStop").focus();gStartStop=null}else{document.getElementById("destStop").value="";setCookie("cDestStop","",1);setCookie("cDestStopNameId",0,1);setCookie("cDestStopInfo",0,1);$("#destStop").focus();gDestStop=null}}function goLinkBusesFound(b,a){var c;setCookie("cStartStopNameId",b,1);setCookie("cDestStopNameId",a,1);if(b!==""){c=a!==""?"&d="+a:"";window.location="busesfound.html"}return false}function showStatus(){window.location="status.html?s="+gStartStop.id};