mChaloBEST/index.min.js

1 line
7.3 KiB
JavaScript
Raw Normal View History

2011-08-13 12:42:40 +00:00
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].a