﻿      var map = null;
      var altitude = null;
      var address = null;
      var allStores = new Array();      
      var stateAbbrev = null;      
      var route = null;  
      var isState = null;
      var deliveryZones = null;
      var deliveryPoints = null;    
      var latLong = null;
      var dataLayer = new VEShapeLayer();
      var searchShapeLayer = new VEShapeLayer();
      
      function distanceSort() {
        var i, j, k, first, next;        
        j = allStores.length - 1;
        for (i = 0; i < allStores.length; ++i) {
          next = allStores[i];
          next[23] = (3959.1 * Math.acos(Math.cos(toRad(latLong.Latitude)) * Math.cos(toRad(next[1])) * Math.cos(toRad(next[2]) - toRad(latLong.Longitude)) + Math.sin(toRad(latLong.Latitude)) * Math.sin(toRad(next[1]))));
          allStores[i] = next;
        }
        for (i = 0; i < j; ++i) {
          k = i + 1;
          first = allStores[i];
          next = allStores[k];
          if (first[23] > next[23]) {
            swapStores(i, k);
            if (i > 0) { i = i - 2; } 
          }
        }      
        loadDisplayNear(1, null);
      }
      
      function alphaSort(StateName) {
        var i, j, k, first, next;
        StateName = StateName.toUpperCase();
        j = allStores.length - 1;

        for (i = 0; i < j; ++i) {
          k = i + 1;
          first = allStores[i];
          next = allStores[k];
          if (first[5].toUpperCase() > next[5].toUpperCase()) {
            swapStores(i, k);
            if (i > 0) { i = i - 2; } 
          }
        }         
        loadDisplayNear(0, StateName);      
      }
      
      function swapStores(First, Last) {
        var tempStore = allStores[First];
        allStores[First] = allStores[Last];
        allStores[Last] = tempStore;                                  
      }
      
      function loadDisplayNear(byDistance, StateName) {         
        var strBuild;
        var newRow;
        var newCell;
        var i = 0;
        var j = 0;
        var k = 0;
        var curStore;  
        var distance = 100;
        var resultsTable = null;      
        document.getElementById('locResults').innerHTML = "<table id=\"tblResults\"></table>" ;                        
        resultsTable = document.getElementById('tblResults');
        newRow = resultsTable.insertRow(k);
        newCell = newRow.insertCell(0);
        newCell.innerHTML = "LOCATION";
        newCell.className = "heading-loc";
        newCell = newRow.insertCell(1);
        newCell.innerHTML = "SERVICES";
        newCell.className = "heading";
        newCell = newRow.insertCell(2);
        newCell.innerHTML = "INFORMATION";
        newCell.className = "heading";
        if (byDistance == 1) {
          newCell = newRow.insertCell(3);
          newCell.innerHTML = "DISTANCE";
          newCell.className = "heading-dis";
        }       
        if (document.getElementById(locStart).className == "hidden"){
          distance = document.getElementById("ddlDistance2").value;
        } else {
          distance = document.getElementById("ddlDistance1").value;
        }
        curStore = allStores[0];
        while (i < allStores.length && ((curStore[23] < distance && byDistance == 1) || (byDistance == 0))  ) {
          if ((byDistance == 0 && curStore[6] == StateName) || (byDistance == 1)) {
            k = k + 1;
            j = j + 1;
            newRow = resultsTable.insertRow(k);
            newCell = newRow.insertCell(0);                
            strBuild = "<div style='margin-bottom: 3px; font-weight: bold;'>" + curStore[5] + " #" + curStore[0]; 
            strBuild += "</div>";                
            if (curStore[3] != 'TBD') {
              strBuild += "<div style='margin-bottom: 3px;'>" + curStore[3] + "</div>";
            }
            strBuild += "<div style='margin-bottom: 3px;'>" + curStore[5];
            strBuild += ", " + curStore[6] + " " + curStore[7] + "</div>";                
            if (curStore[8] != '555-555-5555') {
              strBuild += "<div style='margin-bottom: 3px;'>p: " + curStore[8] + "</div>";
            }
            if (curStore[9] != '555-555-5555') {
              strBuild += "<div style='margin-bottom: 3px;'>f: " + curStore[9] + "</div>";
            }
            if (curStore[0] == 302 || curStore[0] == 404 || curStore[0] == 448) {
              strBuild += "<div style='margin-bottom: 3px; font-weight: bold;'>For Catering Call<br />1-888-778-2234</div>";                          
            } else if (curStore[15] == 1) {
              strBuild += "<div style='margin-bottom: 3px; font-weight: bold;'>For Catering Call<br />1-888-QDOBA2GO</div>";            
            }
            newCell.innerHTML = strBuild;
            if (j % 2 == 0){
              newCell.className = "r-location";
            } else {
              newCell.className = "alt-bg r-location";
            }
            
            // Services Column
            newCell = newRow.insertCell(1);            
            strBuild = "";                
            if (curStore[12] == 1) {
              strBuild += "<div style='margin-bottom: 3px;'><a class='text' title='Online Ordering' href='https://qdoba.com/Order/Default.aspx?sid=" + curStore[0] + "'>Order Online</a></div>"; 
            } 
            if (curStore[14] == 1) {
              strBuild += "<div style='margin-bottom: 3px;'><a class='text' title='Learn more about Qdoba Catering' href='http://www.qdoba.com/Catering.aspx '>Catering</a></div>";
            }            
            if (curStore[13] == 1) { 
              strBuild += "<div style='margin-bottom: 3px;'>Regular Menu Delivery</div>";
            }
            if (curStore[21] == 1) {
              strBuild += "<div style='margin-bottom: 3px;'>Catering Delivery</div>";
            }            
            if (curStore[16] == 1) {
              strBuild += "<div style='margin-bottom: 3px;'><a class='text' href='ILoveQdoba/Rewards.aspx' title='Rewards'>Loyalty Rewards</a></div>";
            }
            if (curStore[17] == 1) {
              strBuild += "<div style='margin-bottom: 3px;'><a class='text' href='ILoveQdoba/Catering.aspx' title='Catering Rewards'>Catering Rewards</a></div>";
            }
            newCell.innerHTML = strBuild;
            if (j % 2 == 0){
              newCell.className = "r-services";
            } else {
              newCell.className = "alt-bg r-services";
            }
            
            // Information Column
            newCell = newRow.insertCell(2);                
            strBuild = "";              
            if (curStore[18] == 1) {
              strBuild += "<div style='margin-bottom: 3px;'><a class='text' href='Locations.aspx' title='View Store Hours' target='_blank' onclick=\"shoInfoWindow('hours', '" + curStore[0] + "');return false;\">Store Hours</a></div>";
            }               
            strBuild += "<div style='margin-bottom: 3px;'><a class='text' href='#' onclick=\"javascript:funcDirectionsPopup('" + i + "')\">Get Directions</a></div>";
            
            if (curStore[0] == '551') {
                strBuild += "<div style='margin-bottom: 3px;'><a class='text' href='Documents/fax_menu_551.doc' title='Fax Menu' target='_blank'>Fax Menu</a></div>";
            } else {
                strBuild += "<div style='margin-bottom: 3px;'><a class='text' href='Documents/fax.pdf' title='Fax Menu' target='_blank'>Fax Menu</a></div>";
            }
            
            if (curStore[19] != '') {
              strBuild += "<div style='margin-bottom: 3px;'><a class='text' href='mailto:" + curStore[19] + "?Subject=Online Inquiry' title='E-Mail Store'>E-Mail</a></div>";
            } else {
              strBuild += "<div style='margin-bottom: 3px;'><a class='text' href='mailto:lp@qdoba.com?Subject=Online Inquiry about Store " + curStore[0] + "' title='E-Mail Store'>E-Mail</a></div>";
            }                       
            if (curStore[20] > 0) {
              strBuild += "<div style='margin-bottom: 3px;'><a class='text' href='http://www.qdoba.com/FranchiseSites/Default.aspx?sid=" + curStore[20] + "' title='Local Store Website'>Local Website</a></div>";            
            }        
            
            // Distance Column           
            newCell.innerHTML = strBuild;
            if (j % 2 == 0){
              newCell.className = "r-info";
            } else {
              newCell.className = "alt-bg r-info";
            }
            if (byDistance == 1) {           
              newCell = newRow.insertCell(3); 
              if (j % 2 == 0){
                newCell.className = "r-distance";
              } else {
                newCell.className = "alt-bg r-distance";
              }                              
              if (curStore[23] == 'unknown') {
                newCell.innerHTML =curStore[23]
              } else {
                newCell.innerHTML = roundNumber(curStore[23], 2) + ' MILES';
              }
            }
            if (curStore[22] != '') {
              k = k + 1; 
              newRow = resultsTable.insertRow(k);
              newCell = newRow.insertCell(0);
              if (byDistance == 1) {
                newCell.colSpan = "4";              
              } else {
                newCell.colSpan = "3";
              }
              newCell.innerHTML = "<div style='width: 100%; margin-bottom: 3px; font-weight: bold; text-align: center; color: #d54126;'>New Location Opening on " + curStore[22] + "!</div>";
              if (j % 2 == 0){
                newCell.className = "r-opening";
              } else {
                newCell.className = "alt-bg r-opening";
              }                            
            }
          }
          ++i;
          curStore = allStores[i];
        }
        if (k == 0) {
          newRow = resultsTable.insertRow(1);
          newCell = newRow.insertCell(0);
          newCell.colSpan = "4";
          newCell.innerHTML = "<div style='width: 100%; margin-bottom: 3px; font-weight: bold; text-align: center; padding-top: 10px; padding-bottom: 10px;'>No Qdoba locations were found based off of your search criteria</div>";
        }                
      } 
      
      function shoInfoWindow(type, sid) {
            var url = 'Locations.aspx';
            var w = 225;
            var h = 330;
            if (type=='online') {
                url = 'Viewer.aspx?t=' + type + '&sid=' + sid;
                w = 550;
                h = 330;                
            } else {
                if ((type=='cateringdelivery')) {
                    url = 'ILoveQdoba/Catering.aspx';
                    w = 550;
                    h = 250;
                } else if ((type=='delivery')) {
                    url = 'Viewer.aspx?t=' + type + '&sid=' + sid;
                    w = 550;
                    h = 250;
                } else if (type=='catering') {
                    url = 'ILoveQdoba/Catering.aspx';
                    w = 850;
                    h = 650;                
                } else if ((type=='rewards')) {
                    url = 'ILoveQdoba/Rewards.aspx';
                    w = 550;
                    h = 330;                
                } else if ((type=='cateringrewards')) {
                    url = 'ILoveQdoba/Catering.aspx';
                    w = 550;
                    h = 330;                              
                } else {
                    if (type=='hours') {
                        url = 'Shared/Hours.aspx?t=ono&sid=' + sid;
                        w = 550;
                        h = 330;                
                    } else {
                        if (type=='map') {
                            url = 'https://www.qdoba.com/Order/Map/Default.aspx?type=storeid&id=' + sid;
                            w = 850;
                            h = 650;                
                        } else {
                            alert('You selected ' + type + ' which is not  configured yet!');
                            return false;
                        }
                    }
                }
            }    
            window.open(url,'','scrollbars=yes,menubar=no,height='+h+',width='+w+',resizable=yes,toolbar=no,location=no,status=no');            
            return false;
        }
        
      function loadBubbles() {   
        var curStore;
        for (i = 0; i < allStores.length; i++) {
          curStore = allStores[i];
          shape = new VEShape(VEShapeType.Pushpin, new VELatLong(curStore[1], curStore[2]));
          shape.SetTitle('<span class=""bubbleTitle"">Qdoba Mexican Grill</span>'); 
          if (curStore[0] == 302 || curStore[0] == 404 || curStore[0] == 448) {                     
            shape.SetDescription('<span class="bubbleDescription">' + curStore[3] + '<br />' + curStore[5] + ', ' + curStore[6] + ' ' + curStore[7] + '<br />p: ' + curStore[8] +'<br />f: ' + curStore[9] + '<br /><b>For Catering Call<br />1-888-778-2234</b></span>');               
          } else if (curStore[15] == 1) {
            shape.SetDescription('<span class="bubbleDescription">' + curStore[3] + '<br />' + curStore[5] + ', ' + curStore[6] + ' ' + curStore[7] + '<br />p: ' + curStore[8] +'<br />f: ' + curStore[9] + '<br /><b>For Catering Call<br />1-888-QDOBA2GO</b></span>');          
          } else {
            shape.SetDescription('<span class="bubbleDescription">' + curStore[3] + '<br />' + curStore[5] + ', ' + curStore[6] + ' ' + curStore[7] + '<br />p: ' + curStore[8] +'<br />f: ' + curStore[9] + '</span>');
          }
          shape.SetCustomIcon('<img src="Images/cactus.gif" alt=""/>'); 
          shape.ShowIcon(); 
          map.AddShape(shape);              
        }                
      }
      
      function toRad(deg) {return deg * Math.PI/180;}     
      
      function initializeMap(passed) {  
        if (passed == '-1'){
          address = document.getElementById('txtSearch').value;
        }
        else {address = passed;}
        
        if (address != "") {          
          document.getElementById(locStart).className = "hidden";
          document.getElementById('locMap').className = "";    
          document.getElementById('locResults').className = "";      
          map = new VEMap('map');   
          map.AttachEvent('ontokenerror', MyHandleTokenError);
          map.AttachEvent('ontokenexpire', MyHandleTokenExpire);    
          map.SetClientToken(token);          
          isState = checkState(address);
          
          if (isState == true) {            
            map.LoadMap(latLong, altitude, VEMapStyle.Road, false, VEMapMode.Mode2D, false, 0, null);                        
            alphaSort(address);            
          }
          else {           
            map.LoadMap();                                       
            map.Find(null, address, null, null, null, null, null, null, null, null, findCallback);
          }          
          document.getElementById('pnlLocation').innerText = address;          
          loadBubbles();          
        } else { 
          alert('Please enter your search criteria or select a state.');
          document.getElementById('txtSearch').focus();
        }
      } 
      
      function findCallback(distanceDdl) {
        latLong = map.GetCenter();    
        distanceSort();     
      }
      
      function findLocation() {
        document.getElementById(locStart).className = "hidden";
        document.getElementById('locMap').className = "";    
        document.getElementById('locHeader').className = "";
        document.getElementById('locResults').className = "";
        document.getElementById('locDetails').className = "hidden";
        document.getElementById('print').className = "hidden";
        document.getElementById('locDirections').className = "hidden";
        document.getElementById('directions').className = "hidden";                  
        searchShapeLayer.DeleteAllShapes();          
        address = document.getElementById('txtSearch1').value;         
        if (address != "") {        
          isState = checkState(address)
          if (isState == true) { 
            map.SetCenterAndZoom(latLong, altitude);
            alphaSort(address);              
          } else {
            map.Find(null, address, null, null, null, null, null, null, null, null, findCallback);
            mapView = map.GetMapView();    
          }            
            document.getElementById('pnlLocation').innerText = address;  
        }
        else
        {
          alert('Please enter your search criteria.');
          document.getElementById('txtSearch1').focus();    
        }        
      }
      function funcDirectionsPopup(store) {        
        var curStore = allStores[store];            
        document.getElementById('txtSltedStore').text = store;
        document.getElementById('DirectionsPopup').className = "DirectionsPopup";
        document.getElementById('inputTo').innerText = "Store " + curStore[0] + " in " + curStore[5] + ", " + curStore[6];     
        document.getElementById('txtFromAddress').value = document.getElementById('pnlLocation').innerText;          
        document.getElementById('btnGetDirs').focus();
      }
      function closeDirectionsPopup() {
        document.getElementById('DirectionsPopup').className = "hidden";        
      }
      function viewStoreDetail() {
        var store = document.getElementById('txtSltedStore').text;
        var curStore = allStores[store];
        document.getElementById("DirectionsPopup").className = "hidden";
        document.getElementById(locStart).className = "hidden";
        document.getElementById('print').className = "hidden";
        document.getElementById('locMap').className = "locMap"; 
        document.getElementById('locHeader').className = "hidden";
        document.getElementById('locResults').className = "hidden";
        document.getElementById('locDirections').className = "locDirections";
        document.getElementById('locDetails').className = "locDetails";
        document.getElementById('directions').className = ""; 
        document.getElementById('destination').className = "destination2";
        document.getElementById('DirectionsTo').innerText = curStore[0];
        document.getElementById('DirectionsCity').innerText = curStore[5];
        document.getElementById('DirectionsFrom').value = document.getElementById('txtFromAddress').value;
        latLong = new VELatLong(curStore[1], curStore[2], 13);
        map.SetCenterAndZoom(latLong, 13);
        document.getElementById('destination').innerHTML = "<h3>" + curStore[5] + " #" + curStore[0] + "</h3>" + curStore[3] + "<br />" + curStore[5] + ", " + curStore[6] + " " + curStore[7] + "<br />" + curStore[8] + "<br />" + curStore[9] + " fax";                             
        if (curStore[10] != '' && curStore[11] != '') {
          drawPolygon(store);                   
          map.AddShapeLayer(searchShapeLayer);
        }    
        GetDirections();                  
      }
      function drawPolygon(store) {
        var PointsLat ;
        var PointsLong ;
        var NPointsLat ;
        var NPointsLong ;
        var curStore = allStores[store];
        NPointsLat = curStore[10].split(';');
        NPointsLong = curStore[11].split(';');
        try {                    
          for(i=0; i<NPointsLat.length; ++i) {
            if (NPointsLat[i] != '') {            
              PointsLat = NPointsLat[i].split(',');
              PointsLong = NPointsLong[i].split(',');              
              var points = new Array();
              for (j=0; j<PointsLat.length; ++j) {
                points[j] = new VELatLong(PointsLat[j]+'',PointsLong[j]+'');
              }      
              var polygon = new VEShape(VEShapeType.Polygon, points);                    
              polygon.HideIcon();
              searchShapeLayer.AddShape(polygon);  
            }
         }         
       }
       catch(err2){alert(err2);}         
      }
      function GetResults(locations) {
        var s="Results for " + latLong.Latitude + ", " + latLong.Longitude + ": ";
        if(locations) {for(var i=0;i<locations.length;i++) {s+=locations[i].Name;}}
        else {s+='No Result found.';}       
      }                                 
      function GetDirections() {
        try {       
          ClearAll();
          document.getElementById('destination').className = "destination";
          document.getElementById('print').className = "print";
          document.getElementById('directions').innerHTML = "<div style='color: green; width:400px;text-align:center; font-style: italic;padding-top:10px;'>Processing Request<br>Please wait...</div>";
          address = document.getElementById('DirectionsFrom').value;
          var myOptions = new VERouteOptions();
          myOptions.SetBestMapView = true; 
          myOptions.RouteCallback = myRouteHandler;  
          var locations = new Array(address, latLong);     
          map.GetDirections(locations, myOptions);            
          var p = document.getElementById('print');
          if (p!=null) { p.style.display=''; }
        }  
        catch (e) {alert(e.message);}       
      }                     
      function myRouteHandler(route) {
        try {
          var legs = route.RouteLegs;           
          var turns = "<ul>";
          var numTurns = 0;           
          var leg = null;                      
          for(var i = 0; i < legs.length; i++) {                            
            leg = legs[i];              
            var turn = null;                            
            for(var j = 0; j < leg.Itinerary.Items.length; j ++) {                  
              turn = leg.Itinerary.Items[j];                
              numTurns++;                  
              turns += "<li>\t" + turn.Text + " (" + turn.Distance.toFixed(1) + " mi)</li>";
            }            
          } 
          turns += "</ul><br />Total distance: " + route.Distance.toFixed(1)
          document.getElementById('directions').innerHTML = turns;
        }
        catch (e){alert(e.message);}      
      }      
      function ClearAll() {
        map.DeleteRoute();
        document.getElementById('directions').innerHTML = "";
        document.getElementById('directions').innerText = "";
        document.getElementById('directions').innerContent = "";      
      }      
      function myRouteHandler(route) {
        try {
          var legs = route.RouteLegs;           
          var turns = "<ul>";
          var numTurns = 0;           
          var leg = null;                      
          for(var i = 0; i < legs.length; i++) {                            
            leg = legs[i];              
            var turn = null;                            
            for(var j = 0; j < leg.Itinerary.Items.length; j ++) {                  
              turn = leg.Itinerary.Items[j];                
              numTurns++;                  
              turns += "<li>\t" + turn.Text + " (" + turn.Distance.toFixed(1) + " mi)</li>";
            }            
          }            
          turns += "<li>Total distance: "+route.Distance.toFixed(1)+"</li></ul>"
          document.getElementById('directions').innerHTML = turns;
          document.getElementById('directions').className = "directions";
        }
        catch (e) { alert(e.message); }      
      }      
      function checkState(searchAddress) {
        searchAddress = searchAddress.toUpperCase();      
        switch(searchAddress) {
          case "AL":
          case "ALABAMA":
            latLong = new VELatLong("32.7481996268034", "-86.84790752828121", 6);
            altitude = 6;
            stateAbbrev = "AL";
            return true;
          case "AK":
          case "ALASKA":
            latLong = new VELatLong("64.5", "-154.3053127080202", 4);
            altitude = 4;
            stateAbbrev = "AK";
            return true;
          case "AZ":
          case "ARIZONA":
            latLong = new VELatLong("34.293227791786194", "-111.6645884513855", 6);
            altitude = 6;
            stateAbbrev = "AZ";
            return true;
          case "AR":
          case "ARKANSAS":
            latLong = new VELatLong("34.89976108074188", "-92.43923909962177", 7);
            altitude = 7;
            stateAbbrev = "AR";
            return true;
          case "CA":
          case "CALIFORNIA":
            latLong = new VELatLong("37.14814022183418", "-119.64424878358841", 5);
            altitude = 5;
            stateAbbrev = "CA";
            return true;
          case "CO":
          case "COLORADO":
            latLong = new VELatLong("38.998549953103065", "-105.54782822728157", 6);
            altitude = 6;
            stateAbbrev = "CO";
            return true;
          case "CT":
          case "CONNECTICUT":
            latLong = new VELatLong("41.57517984509468", "-72.73831129074096", 8);
            altitude = 8;
            stateAbbrev = "CT";
            return true;
          case "DE":
          case "DELAWARE":
            latLong = new VELatLong("39.15", "-75.44497668743133", 8);
            altitude = 8;
            stateAbbrev = "DE";
            return true;
          case "DC":
          case "DISTRICT OF COLUMBIA":
          case "DISTRICT COLUMBIA":
          case "WASHINGTON DC":
            latLong = new VELatLong("38.90465185046196", "-77.01634213328361", 6);
            altitude = 6;
            stateAbbrev = "DC";
            return true;
          case "FL":
          case "FLORIDA":
            latLong = new VELatLong("28.381999880075454", "-81.75800286233425", 6);
            altitude = 6;
            stateAbbrev = "FL";
            return true;
          case "GA":
          case "GEORGIA":
            latLong = new VELatLong("33.2", "-83.42698663473129", 7);
            altitude = 7;
            stateAbbrev = "GA";
            return true;
          case "HI":
          case "HAWAII":
            latLong = new VELatLong("20.6", "-157.5", 7);
            altitude = 7;
            stateAbbrev = "HI";
            return true;
          case "ID":
          case "IDAHO":
            latLong = new VELatLong("45", "-114.65937003493309", 6);
            altitude = 6;
            stateAbbrev = "ID";
            return true;
          case "IL":
          case "ILLINOIS":
            latLong = new VELatLong("40.124149695038795", "-89.14862796664238", 6);
            altitude = 6;
            stateAbbrev = "IL";
            return true;
          case "IN":
          case "INDIANA":
            latLong = new VELatLong("39.91992227733135", "-86.28179915249347", 6);
            altitude = 6;
            stateAbbrev = "IN";
            return true;
          case "IA":
          case "IOWA":
            latLong = new VELatLong("42.07463063299656", "-93.50005276501179", 7);
            altitude = 7;
            stateAbbrev = "IA";
            return true;
          case "KS":
          case "KANSAS":
            latLong = new VELatLong("38.484710454940796", "-97.85", 7);
            altitude = 7;
            stateAbbrev = "KS";
            return true;
          case "KY":
          case "KENTUCKY":
            latLong = new VELatLong("37.7", "-85.28771214187145", 7);
            altitude = 7;
            stateAbbrev = "KY";
            return true;
          case "LA":
          case "LOUISIANA":
            latLong = new VELatLong("31.2", "-92.60800167918205", 7);
            altitude = 7;
            stateAbbrev = "LA";
            return true;
          case "ME":
          case "MAINE":
            latLong = new VELatLong("45.27503974735737", "-69.19777661561966", 6);
            altitude = 6;
            stateAbbrev = "ME";
            return true;
          case "MD":
          case "MARYLAND":
            latLong = new VELatLong("39.0330009162426", "-76.39700263738632", 7);
            altitude = 7;
            stateAbbrev = "MD";
            return true;
          case "MA":
          case "MASSACHUSETTS":
            latLong = new VELatLong("42.36399807035923", "-71.53299696743488", 8);
            altitude = 8;
            stateAbbrev = "MA";
            return true;
          case "MI":
          case "MICHIGAN":
            latLong = new VELatLong("43.4", "-84", 7);
            altitude = 7;
            stateAbbrev = "MI";
            return true;
          case "MN":
          case "MINNESOTA":
            latLong = new VELatLong("46.349109560251236", "-94.19831827282905", 6);
            altitude = 6;
            stateAbbrev = "MN";
            return true;
          case "MS":
          case "MISSISSIPPI":
            latLong = new VELatLong("32.71060176193714", "-89.65254195034504", 6);
            altitude = 6;
            stateAbbrev = "MS";
            return true;
          case "MO":
          case "MISSOURI":
            latLong = new VELatLong("38.36755022406578", "-92.4773097038269", 7);
            altitude = 7;
            stateAbbrev = "MO";
            return true;
          case "MT":
          case "MONTANA":
            latLong = new VELatLong("47.03351944684982", "-110.4", 6);
            altitude = 6;
            stateAbbrev = "MT";
            return true;
          case "NE":
          case "NEBRASKA":
            latLong = new VELatLong("41.52711130678654", "-99", 7);
            altitude = 7;
            stateAbbrev = "NE";
            return true;
          case "NV":
          case "NEVADA":
            latLong = new VELatLong("38.2", "-116.65541030466556", 6);
            altitude = 6;
            stateAbbrev = "NV";
            return true;
          case "NH":
          case "NEW HAMPSHIRE":
            latLong = new VELatLong("43.680980801582336", "-71.57203651964664", 7);
            altitude = 7;
            stateAbbrev = "NH";
            return true;
          case "NJ":
          case "NEW JERSEY":
            latLong = new VELatLong("40.08277125656605", "-74.64991696178913", 7);
            altitude = 7;
            stateAbbrev = "NJ";
            return true;
          case "NM":
          case "NEW MEXICO":
            latLong = new VELatLong("34.421371668577194", "-106.10838308930397", 6);
            altitude = 6;
            stateAbbrev = "NM";
            return true;
          case "NY":
          case "NEW YORK":
            latLong = new VELatLong("42.90378928184509", "-75.57048797607422", 6);
            altitude = 6;
            stateAbbrev = "NY";
            return true;
          case "NC":
          case "NORTH CAROLINA":
            latLong = new VELatLong("35.51551043987274", "-79.09996792674064", 7);
            altitude = 7;
            stateAbbrev = "NC";
            return true;
          case "ND":
          case "NORTH DAKOTA":
            latLong = new VELatLong("47.446319460868835", "-100", 7);
            altitude = 7;
            stateAbbrev = "ND";
            return true;
          case "OH":
          case "OHIO":
            latLong = new VELatLong("40.3", "-82.70934283733368", 7);
            altitude = 7;
            stateAbbrev = "OH";
            return true;
          case "OK":
          case "OKLAHOMA":
            latLong = new VELatLong("35.58348834514618", "-97.50827014446258", 7);
            altitude = 7;
            stateAbbrev = "OK";
            return true;
          case "OR":
          case "OREGON":
            latLong = new VELatLong("43.94086807966232", "-120.60077615082264", 6);
            altitude = 6;
            stateAbbrev = "OR";
            return true;
          case "PA":
          case "PENNSYLVANIA":
            latLong = new VELatLong("40.896690264344215", "-77.83888980746269", 7);
            altitude = 7;
            stateAbbrev = "PA";
            return true;
          case "RI":
          case "RHODE ISLAND":
            latLong = new VELatLong("41.66", "-71.54493682086468", 9);
            altitude = 9;
            stateAbbrev = "RI";
            return true;
          case "SC":
          case "SOUTH CAROLINA":
            latLong = new VELatLong("33.874809220433235", "-80.85331723093986", 7);
            altitude = 7;
            stateAbbrev = "SC";
            return true;
          case "SD":
          case "SOUTH DAKOTA":
            latLong = new VELatLong("44.43613797426224", "-100.23049168288708", 6);
            altitude = 6;
            stateAbbrev = "SD";
            return true;
          case "TN":
          case "TENNESSEE":
            latLong = new VELatLong("35.842979326844215", "-86.5", 7);
            altitude = 7;
            stateAbbrev = "TN";
            return true;                
          case "TX":
          case "TEXAS":
            latLong = new VELatLong("31.43672950565815", "-99.3069226294756", 6);
            altitude = 6;
            stateAbbrev = "TX";
            return true;
          case "UT":
          case "UTAH":
            latLong = new VELatLong("39.32377986609936", "-111.67822279036045", 6);
            altitude = 6;
            stateAbbrev = "UT";
            return true;
          case "VT":
          case "VERMONT":
            latLong = new VELatLong("44.07521054148674", "-72.66275011003017", 7);
            altitude = 7;
            stateAbbrev = "VT";
            return true;
          case "VA":
          case "VIRGINIA":
            latLong = new VELatLong("37.51023106276989", "-78.64920057356357", 7);
            altitude = 7;
            stateAbbrev = "VA";
            return true;
          case "WA":
          case "WASHINGTON":
            latLong = new VELatLong("47.411869168281555", "-120.58416724205017", 7);
            altitude = 7;
            stateAbbrev = "WA";
            return true;
          case "WV":
          case "WEST VIRGINIA":
            latLong = new VELatLong("38.64255107939243", "-80.61370074748993", 7);
            altitude = 7;
            stateAbbrev = "WV";
            return true;
          case "WI":
          case "WISCONSIN":
            latLong = new VELatLong("43.85", "-90.5", 7);
            altitude = 7;
            stateAbbrev = "WI";
            return true;
          case "WY":
          case "WYOMING":
            latLong = new VELatLong("42.999629974365234", "-107.55145244300365", 6);
            altitude = 6;
            stateAbbrev = "WY";
            return true; 
          default:
            return false;
        }
      }     
      function printDirections() {
        fnSelect('directions');
        print();
      }
      function fnSelect(objId) {
		    fnDeSelect();
		    if (document.selection) {
		    var range = document.body.createTextRange();
 	            range.moveToElementText(document.getElementById(objId));
		    range.select();
		    }
		    else if (window.getSelection) {
		    var range = document.createRange();
		    range.selectNode(document.getElementById(objId));
		    window.getSelection().addRange(range);
		    }
	    }	    
	    function fnDeSelect() {
		    if (document.selection) document.selection.empty(); 
		    else if (window.getSelection)
                    window.getSelection().removeAllRanges();
	    }
      function MyHandleTokenError() {alert('Token is invalid.');}
      function MyHandleTokenExpire() {alert('Token has expired.');}