     //Begin JSON Mologogo Server Functions  - Callbacks from JSON Server returns
            function makeRequest(url, callback) {
                http_request = false;
                if (window.XMLHttpRequest) { // Mozilla, Safari,...
                    http_request = new XMLHttpRequest();
                    if (http_request.overrideMimeType) {
                        http_request.overrideMimeType('text/xml');
                    }
                } else if (window.ActiveXObject) { // IE
                    try {
                        http_request = new ActiveXObject("Msxml2.XMLHTTP");
                    } catch (e) {
                        try {
                        http_request = new ActiveXObject("Microsoft.XMLHTTP");
                        } catch (e) {}
                    }
                }
                if (!http_request) {
                    alert('Giving up :( Cannot create an XMLHTTP instance');
                    return false;
                }
                http_request.onreadystatechange = callback;
                http_request.open('GET', url, true);
                http_request.send(null);
            }

            function gotLastPoint() {
                if (http_request.readyState == 4) {
                    if (http_request.status == 200) {                                             
                        eval('var last_point = ' + http_request.responseText);                        
                        // Now that we have values from the last data point get the data days for this user, year and point type
                        //if (suser == '') { suser = last_point.phoneNumber; }
						for (i=0; i<document.json.users.length ; i++) { // loop through the user select choices text till we find a match and select that user index
						//for (i=0; i<document.optionsForm.users.length ; i++) { // loop through the user select choices text till we find a match and select that user index
							if (document.json.users.options[i].text == last_point.user) { document.json.users.selectedIndex = i; }
							//if (document.optionsForm.users.options[i].text == last_point.phoneNumber) { document.optionsForm.users.selectedIndex = i; }
						}
						//document.getElementById("varTest").innerHTML = 'user got-last-point: '+document.json.users[document.json.users.selectedIndex].text+':'+last_point.phoneNumber;
                        syear = last_point.phonetime.substring(0,4);
						//sdate = timeStringToUnixTimestamp(last_point.gpsTime); // set selected date on calendar = date of last point found
						//document.getElementById("varTest").innerHTML = last_point.gpsTime+':'+sdate;
						//buildCal(sdate);
      //Put this logic back in after getting track searches functioning properly                  
                        // If first time called and last point was gps type then use gps points other wise use both gps and cell tower points
                        if (spt == '') {
                              if (last_point.point_type == 'GPS') {
                              //if (last_point.LocationMethod == 8) {   
                                   spt = 'g';
                                   //document.forms['json'].pt[0].checked = true;
								   document.forms['optionsForm'].pt[0].checked = true; 
                              } else {
                                   spt = 'b';
                                   //document.forms['json'].pt[2].checked = true;
								   document.forms['optionsForm'].pt[2].checked = true;
                              }
                        }
                        // if the last point found was valid then set use valid points
                             if (last_point.point_type == 'GPS') { 
                                  //v = 'true';
                                  //document.getElementById('vp').checked = true;
								  //document.getElementById('vp').visible = false;
                                  //document.forms['json'].validPoints[0].checked = true;
                                  // hide the location method menu
                                  //document.getElementById("pointtype").innerHTML = ''; 
                             }else{
                                  //v = 'false';
                                  document.getElementById('vp').checked = false;
                                  //document.forms['json'].validPoints[0].checked = false;
                             }                            
						document.getElementById('vp').checked = false;
						//document.getElementById("accuracySelect").innerHTML = '';
                        point_data = last_point; //set data point values = to last point values                                            
                        setFilters();
                        var command_string = 'gps-server.php?command=get-data-days'+filters+'&syear='+syear;
                        makeRequest(command_string, gotDataDays);
                    } else {
                        alert('There was a problem with the get-last-point request.');
                    }
                }
            }
			
		
            
            function gotTrack() {
                if (http_request.readyState == 4) {
                    if (http_request.status == 200) {                       
                        var track = eval('(' + http_request.responseText + ')');
            //            document.getElementById("varTest").innerHTML = track.points[0][1];
                        //var n_stop_time = new Date(track.points[0][2]*1000);
						var n_stop_time = track.points[0][2]*1000;
                        //var n_start_time = new Date(track.points[track.points.length-1][2]*1000);
						var n_start_time = track.points[track.points.length-1][2]*1000;
                        var num_points = track.points.length;
                        load_map(track);
                        displayTrackInfo(n_start_time, n_stop_time, num_points)
                    } else {
                        alert('There was a problem with the get-track request.'+http_request.readyState+':'+http_request.status);
                    }
                }
            }
			function gotTracks() {
                if (http_request.readyState == 4) {
                    if (http_request.status == 200) {
                    // Return is three arrays track_start, track_stop and track_list
                         var ftracks = eval('(' + http_request.responseText + ')');
                         track_start = ftracks.track_start;
                         track_stop = ftracks.track_stop;
						 document.forms['json'].tracks.options.length = 0; // clear out the previous select options
                         for (i=0; i<ftracks.track_list.length; i++) {
							  document.forms['json'].tracks.options[i] = new Option(ftracks.track_list[i], [i]);
                         }
						 latestTime = track_stop[0]; // Set the latestTime current latest end track time
                    } else {
                        alert('There was a problem with the get-tracks request.');
                    }
                }
                  setFilters();
                  displayStatus("Click on a Leg time period to display a map for that time period!", false);
            }       
            
            function gotUsers() {
                if (http_request.readyState == 4) {
                    if (http_request.status == 200) {
                    // Return is array of all user names

                        // eval('var user_list = ' + http_request.responseText);
                         eval('user_list = ' + http_request.responseText);
                         //document.forms['json'].users.options.length = 0; // clear out the previous select options
						 document.forms['json'].users.options.length = 0; // clear out the previous select options
                         if (suser == "") { suser = user_list.user[0]; } // set suser to last user first time this function is called 
                         for (i=0; i<user_list.user.length; i++) {
                              //document.forms['json'].users.options[i] = new Option(user_list.user[i], [i]);
							  document.forms['json'].users.options[i] = new Option(user_list.user[i], [i]);
                              if (user_list[i] == suser) { document.forms['json'].users.options[i].selected = true; }                            
							  //if (user_list[i] == suser) { document.forms['optionsForm'].users.options[i].selected = true; } 
                         }
                         makeRequest('gps-server.php?command=get-last-point', gotLastPoint);
                    } else {
                        alert('There was a problem with the get-users request.');
                    }
                }
            } 

			function timeStringToDateObject(timeString) { // returns the year/month/day portion of a string of time as a javascript date object
				var ty = timeString.substring(0,4);
				var tm = timeString.substring(5,7);
				var td = timeString.substring(8,10);
				//document.getElementById("varTest").innerHTML = ty+'/'+tm+'/'+td;
				return new Date(ty+'/'+tm+'/'+td);
				//return parseInt(new Date(timeString).getTime().toString().substring(0, 10))
			}	
                        
            function gotDataDays() {
               // Retrieves the array m[] of months and days where data points have been recorded and the last data date (dd)
                if (http_request.readyState == 4) {
                    if (http_request.status == 200) {                                             
                        var data_days = eval('(' + http_request.responseText + ')');
                        dd = data_days.dd;
                        sdays = data_days.sdays;
                        udate = data_days.sdate;
					    sdate = udate*1000; //convert to unix time
                        setFilters();
						buildCal(sdate);
						var request_string = 'gps-server.php?command=get-tracks&sdate='+udate+filters;
                        makeRequest(request_string, gotTracks)
                    } else {
                        alert('There was a problem with the get-data-days request.');
                    }
                }
            }
            function getLatestTracks() {
               // Retrieves the array m[] of months and days where data points have been recorded and the last data date (dd)
                if (http_request.readyState == 4) {
                    if (http_request.status == 200) {                                             
                        var data_days = eval('(' + http_request.responseText + ')');
                        dd = data_days.dd;
                        sdays = data_days.sdays;
                        udate = data_days.sdate;
					    sdate = udate*1000; //convert to unix time
                        setFilters();
						//buildCal(sdate);
						//document.getElementById("infoBox").innerHTML = '&sdate='+udate+filters+'</span>';
						var request_string = 'gps-server.php?command=get-tracks&sdate='+udate+filters;
                        makeRequest(request_string, gotLatestTracks)
                    } else {
                        alert('There was a problem with the get-data-days request.');
                    }
                }
            }			
            function gotLatestTracks() {
				//alert('I got here');
				//document.getElementById("infoBox").innerHTML = '<span>I got here!</span>';
                if (http_request.readyState == 4) {
					
                    if (http_request.status == 200) {
                    // Return is three arrays track_start, track_stop and track_list
                         var ftracks = eval('(' + http_request.responseText + ')');
                         track_start = ftracks.track_start;
                         track_stop = ftracks.track_stop;
						 
						 //document.getElementById("infoBox").innerHTML = '<span>track_start[0]: ' + track_start[0] + '</span>';
						 document.forms['json'].tracks.options.length = 0; // clear out the previous select options
                         for (i=0; i<ftracks.track_list.length; i++) {
							  document.forms['json'].tracks.options[i] = new Option(ftracks.track_list[i], [i]);
                         }
						 displayMostRecentTrack();
                    } else {
                        alert('There was a problem with the get-tracks request.');
                    }
                }
                  //setFilters();
                  //displayStatus("Click on a Leg time period to display a map for that time period!", false);
				  
            }			

            
            function gotAddress() {                     
                if (http_request.readyState == 4) {
                    if (http_request.status == 200) {
                        window.alert(http_request.responseText);                                             
                       // eval(http_request.responseText);                       
                    } else {
                        alert('There was a problem with the get-address request.');
                    }
                }
            }
            
//End of JSON Mologogo Server Functions
       