     //Begin Browser Utilities 
function alertSize() {
          var myWidth = 0, myHeight = 0;
          if( typeof( window.innerWidth ) == 'number' ) {
               //Non-IE
               myWidth = window.innerWidth;
               myHeight = window.innerHeight;
          } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
               //IE 6+ in 'standards compliant mode'
               myWidth = document.documentElement.clientWidth;
               myHeight = document.documentElement.clientHeight;
          } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
               //IE 4 compatible
               myWidth = document.body.clientWidth;
               myHeight = document.body.clientHeight;
          }
          window.alert( 'Width = ' + myWidth );
          window.alert( 'Height = ' + myHeight );
          }            
     //End Browser Utilities 

function reSize() {
          
     var windowWidth = 0; 
     var windowHeight = 0;
     var menu_width = 201; // Make this one greater than that defined in the style
     var padding = 1; // css padding X 2
     var menu_padding_top = 10;
     var menu_padding_bottom = 10;
     var menu_padding_left = 10;
     var menu_padding_right = 10;
     var main_padding_left = 10;
     var main_padding_right = 10;
     var main_padding_top = 10;
     var main_padding_bottom = 10;
     var content_padding_bottom = 20;

     if( typeof( window.innerWidth ) == 'number' ) {
         //Non-IE
         windowWidth = window.innerWidth;
         windowHeight = window.innerHeight;
     } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
         //IE 6+ in 'standards compliant mode'
         windowWidth = document.documentElement.clientWidth;
         windowHeight = document.documentElement.clientHeight;
     } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
         //IE 4 compatible
         windowWidth = document.body.clientWidth;
         windowHeight = document.body.clientHeight;
     }
     var main_width = windowWidth-menu_width+1;
     var main_height = windowHeight;
     var menu_height = windowHeight;
          
     document.getElementById("menu").style.width = (menu_width-1)+"px";
     document.getElementById("menu").style.height = (menu_height-menu_padding_top-menu_padding_bottom)+"px"; 
                 
     document.getElementById("main").style.left = (menu_width+menu_padding_left+menu_padding_right)+"px";
     document.getElementById("main").style.width = (main_width-1)+"px";
     document.getElementById("main").style.height = (main_height)+"px";
          
     document.getElementById("content").style.top = (18)+"px";
     document.getElementById("content").style.left = (9)+"px";
     document.getElementById("content").style.width = (main_width-menu_padding_left-menu_padding_right-main_padding_left-main_padding_right)+"px";
     document.getElementById("content").style.height = (main_height-30)+"px";
	 document.getElementById("helpPopup").style.width = (main_width-menu_padding_left-menu_padding_right-main_padding_left-main_padding_right)+"px";
}

function loadData(){
     reSize();
     displayStatus("Loading User and Trip Data - Please Wait!", true); // Display Message and Progressbar
     makeRequest('gps-server.php?command=get-users', gotUsers);
	 //refreshTrack();
}

function setFilters() {
     //user='+suser+'&pt='+spt+'&v='+validFlag+
	 //document.getElementById("varTest").innerHTML = 'setFilters: '+document.json.users[document.json.users.selectedIndex].text;
     filters = '&user='+document.json.users[document.json.users.selectedIndex].text; // get the currently selected user
	 //filters = '&user='+document.optionsForm.users[document.optionsForm.users.selectedIndex].text; // get the currently selected user
     if (document.getElementById('vp').checked) { // check whether to use only valid points
        filters = filters+'&v=true';
        filters = filters+'&pt=b'; 
     }else{ 
        filters = filters+'&v=false'; // if not using valid only check to point types to use
        if (document.forms['optionsForm'].pt[0].checked) { filters = filters+'&pt=g'; }
        if (document.forms['optionsForm'].pt[1].checked) { filters = filters+'&pt=c'; }
        if (document.forms['optionsForm'].pt[2].checked) { filters = filters+'&pt=b'; } 
     }
	//if (selectedDate != '') { filters = filters+'&sdate='+selectedDate; }
	//if (sdate != '') { 
	//	filters = filters+'&a='+accuracy+'&gap='+gap+'&sdate='+sdate; 
	//}else{
		filters = filters+'&a='+accuracy+'&gap='+gap; // add on accuracy and gap values
	//}
    // filters = filters+'&l='+lim;
    // document.getElementById("announce").innerHTML = filters;
}

function showOptions() {

	if(document.getElementById("optionsPopup").style.display == 'block') { //optionsPopup
		document.getElementById("optionsPopup").style.display = 'none';
	}else{
		document.getElementById("optionsPopup").style.display = 'block';
	}
}

function closeOptions() {
	//alert('I got to closeOptions');
	document.getElementById("optionsPopup").style.display = 'none';
} 

function showHelp() {

	if(document.getElementById("helpPopup").style.display == 'block') { //optionsPopup
		document.getElementById("helpPopup").style.display = 'none';
	}else{
		document.getElementById("helpPopup").style.display = 'block';
	}
}

function closeHelp() {
	//alert('I got to closeOptions');
	document.getElementById("helpPopup").style.display = 'none';
}   

function processTrack(){
     displayStatus("Loading Map Data - Please Wait!", true); // Display Message and Progressbar
     setFilters();
    //  document.getElementById("announce").innerHTML ='gps-server.php?command=get-track'+filters+'&start='+track_start[document.json.tracks.value]+'&stop='+track_stop[document.json.tracks.value];
     //var requestString = 'gps-server.php?command=get-track'+filters+'&start='+track_start[document.json.tracks.value]+'&stop='+track_stop[document.json.tracks.value];
     //var requestString = 'gps-server.php?command=get-track'+filters+'&start='+track_start[document.json.tracks.value]+'&stop='+track_stop[document.json.tracks.value];     
	 var requestString = 'gps-server.php?command=get-track'+filters+'&start='+track_start[document.json.tracks.value]+'&stop='+track_stop[document.json.tracks.value]; 
     makeRequest(requestString, gotTrack);
}
function refreshTrack(){
	// first get last data point
	//extract last day
	//get tracks for last day
	//
	//document.json.tracks.selectedIndex = 0;
	//latestTime = track_stop[document.json.tracks.value];
    //setFilters();
	//document.getElementById("infoBox").innerHTML = '<span>syear: ' + syear + '</span>';
	//latestTime = track_stop[document.json.tracks.value]-1;
	latestTime = 0; // Set the latestTime current latest end track time
	var command_string = 'gps-server.php?command=get-data-days'+filters+'&syear='+syear;
    displayStatus("Retriving New User Data Information - Please Standby!", true);
    makeRequest(command_string, getLatestTracks);
}

function displayMostRecentTrack() {
	document.json.tracks.selectedIndex = 0;
	//displayTrackInfo(n_start_time, n_stop_time, num_points);
	 if (track_stop[0] > latestTime) {
		//latestTime = track_stop[document.json.tracks.value]; // Set the latestTime current latest end track time
		
		displayStatus("Loading Map Data - Please Wait!", true); // Display Message and Progressbar
		//setFilters(); 
		//var requestString = 'gps-server.php?command=get-track'+filters+'&start='+track_start[document.json.tracks.value]+'&stop='+track_stop[document.json.tracks.value]; 
		//var requestString = 'gps-server.php?command=get-track'+filters+'&start='+track_start[document.json.tracks.value]+'&stop='+track_stop[document.json.tracks.value];
		//document.getElementById("infoBox").innerHTML = '<span>Track start: ' + 0 + '</span>';
		//document.getElementById("infoBox").innerHTML = '<span>Track start: ' + track_start[0] + '</span>';
		buildCal(sdate);
		var requestString = 'gps-server.php?command=get-track'+filters+'&start='+track_start[0]+'&stop='+track_stop[0];
		makeRequest(requestString, gotTrack);
		//buildCal(sdate);
		document.getElementById("optionsPopup").style.display = 'none';
		document.getElementById("helpPopup").style.display = 'none';
	}
	//displayTrackInfo(n_start_time, n_stop_time, num_points);
}
     
function userChange() {
     //if (document.forms['json'].validPoints[0] === true) { validFlag = 'true'; }else{ validFlag = 'false'; }
     if (document.getElementById('vp').checked === true) { validFlag = 'true'; }else{ validFlag = 'false'; }
     //   document.getElementById("announce").innerHTML = validFlag;
     //suser = document.json.users[document.json.users.selectedIndex].text;
     setFilters();
     //var command_string = 'gps-server.php?command=get-data-days&user='+suser+'&year='+syear+'&pt='+spt+'&v='+validFlag;
	 var command_string = 'gps-server.php?command=get-data-days'+filters+'&syear='+syear;
     displayStatus("Retriving New User Data Information - Please Standby!", true);
     makeRequest(command_string, gotDataDays);
}

function optionChange() {
     //if (document.forms['json'].validPoints[0] === true) { validFlag = 'true'; }else{ validFlag = 'false'; }
     if (document.getElementById('vp').checked === true) { validFlag = 'true'; }else{ validFlag = 'false'; }
     //   document.getElementById("announce").innerHTML = validFlag;
     //suser = document.json.users[document.json.users.selectedIndex].text;
     setFilters();
     //var command_string = 'gps-server.php?command=get-data-days&user='+suser+'&year='+syear+'&pt='+spt+'&v='+validFlag;
	 //var command_string = 'gps-server.php?command=get-tracks'+filters+'&syear='+syear;
	 var command_string = 'gps-server.php?command=get-tracks'+filters+'&sdate='+sdate;
     displayStatus("Retriving New User Data Information - Please Standby!", true);
     makeRequest(command_string, gotDataDays);
}
     
function pointChange(choice) {
     //if (document.forms['json'].validPoints[0] === true) { validFlag = 'true'; }else{ validFlag = 'false'; }
     if (choice == 0) { spt = 'g'; }
     if (choice == 1) { spt = 'c'; }
     if (choice == 2) { spt = 'b'; }
	 //for ($i=0; $i<2; $i++) { document.forms['json'].pt[$i].checked = false; } // uncheck all choices
	 for ($i=0; $i<2; $i++) { document.forms['optionsForm'].pt[$i].checked = false; } // uncheck all choices
     //document.forms['json'].pt[choice].checked = true; // Now set the one which was clicked
	 document.forms['optionsForm'].pt[choice].checked = true; // Now set the one which was clicked
     displayStatus("Updating Trip Information - Please Standby!", true);
	 userChange();
    // makeRequest('gps-server.php?command=get-last-point&user='+suser+'&pt='+spt+'v='+validFlag, gotLastPoint);  
}

function vpClicked() {
          if (document.getElementById('vp').checked) {
             document.getElementById("pointtype").innerHTML = '';
         }else{
             pointtype_html = '<li class="lable">Point Types to Use:</li>'+        
                         '<li class="radio"><input class="radio" type="radio" name="pt" value="g" onclick="pointChange(0)" checked>&nbsp; GPS: </li>'+
                         '<li class="radio"><input class="radio" type="radio" name="pt" value="c" onclick="pointChange(1)">&nbsp; Cell Tower: </li>'+
                         '<li class="radio"><input class="radio" type="radio" name="pt" value="b" onclick="pointChange(2)">&nbsp; Both: </li>';
             document.getElementById("pointtype").innerHTML = pointtype_html;  
         }
         userChange();
}

function pinAllClicked() {
         if (document.getElementById('pinAll').checked) {
             pins = true;
         }else{
             pins = false;  
         }
         processTrack();
}

function displayStatus(message, progress) {
         // first clear the track info data
         document.getElementById("track_start_time").innerHTML = "";
         document.getElementById("track_stop_time").innerHTML = "";
         document.getElementById("track_num_points").innerHTML = "";
         document.getElementById("track_sec_per_point").innerHTML = "";     
         // display the message and turn on the progress bar on or off
         document.getElementById("track_message").innerHTML = message;       
         if (progress == true) { 
            pbar.showBar(); 
         }else{
            pbar.hideBar();        
         }
}

function displayTrackInfo(d_start_time, d_stop_time, num_points) { 
         pbar.hideBar(); // hide the progress bar        
         document.getElementById("track_message").innerHTML = ""; // clear the status message        
         //document.getElementById("track_stop_time").innerHTML = "<font color='navy'><b>Stop Time: </b></font>"+d_stop_time;
		 var stop_time = new Date(d_stop_time); //  * 1000 to convert from unix time stamp to javascript date
		 var start_time = new Date(d_start_time);
		 document.getElementById("track_stop_time").innerHTML = "<font color='navy'><b>Stop Time: </b></font>"+stop_time.toLocaleString();
         document.getElementById("track_start_time").innerHTML = "<font color='navy'><b>Start Time: </b></font>"+start_time.toLocaleString();                  
         document.getElementById("track_num_points").innerHTML = "<font color='navy'><b>Number of Points: </b></font>"+num_points;
         //document.getElementById("track_sec_per_point").innerHTML = "<font color='navy'><b>Seconds/Point: </b></font>"+parseInt((d_stop_time-d_start_time)/num_points/1000);
		 //document.getElementById("track_sec_per_point").innerHTML = "<font color='navy'><b>Seconds/Point: </b></font>"+(Date.parse(d_stop_time) - Date.parse(d_start_time));
		 document.getElementById("track_sec_per_point").innerHTML = "<font color='navy'><b>Seconds/Point: </b></font>"+parseInt(((d_stop_time - d_start_time) / num_points) / 1000);
}
function displayAddress(lat, lon) {
        // window.alert(lat+" , "+lon);
//         var request = 'http://ws.geonames.org/findNearestAddressJSON?lat=' + lat + '&lng='  + lon;
         makeRequest('gps-server.php?command=get-address&lat='+lat+'&lon='+lon, gotAddress);
}

function closeInfoBox() {
	document.getElementById("infoBox").innerHTML = '';
	document.getElementById("infoBox").style.display = 'none';
	markerID = -1; // Sice we closed it we set this so next click will open it again
	//document.getElementById("infoBox").innerHTML = '<a href="http://gnbi.com/BlazingSaddles"><img border=1 src=http://gnbi.com/BlazingSaddles/images/MSbike.gif alt="MS Bikathon Team Blazing Saddles"></a>';
}
