
	// Returns a parameter in the URL corresponding to name
	function gup(name) {
	  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	  var regexS = "[\\?&]"+name+"=([^&#]*)";
	  var regex = new RegExp( regexS );
	  var results = regex.exec( window.location.href );
	  if( results == null ) return "";
	  else return results[1];
	}
	
	// Returns the distance between 2 latitudes and longitudes in kilometers
	function distance(lat1, lon1, lat2, lon2) {
	  var R = 6371; // km
      var dLat = (lat2-lat1) * Math.PI / 180;
      var dLon = (lon2-lon1) * Math.PI / 180; 
      var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
        Math.cos(lat1 * Math.PI / 180) * Math.cos(lat2 * Math.PI / 180) * 
        Math.sin(dLon/2) * Math.sin(dLon/2); 
      var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); 
      return (R * c);
	}
	
	// Clears a text field when clicked
	function clearText(field) {
		if (field.defaultValue == field.value) field.value = '';
		else if (field.value == '') field.value = field.defaultValue;
	}
 
	// Easily define an array of constants
	function makeArray() {
		for (i = 0; i<makeArray.arguments.length; i++)
          this[i + 1] = makeArray.arguments[i];
	}
	
	// Show a pulldown with dates for "num" days in select box "id"
	function daysPulldown(id, num) {
		var months = new makeArray('Jan','Feb','Mar', 'Apr','May','Jun','Jul','Aug','Sep', 'Oct','Nov','Dec');
		var days = new makeArray('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
			
		var now = new Date();
		now = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0);
		var theDay = new Date(now.getTime());
		document.getElementById(id).options[0] = new Option("Today, "+months[theDay.getMonth()+1]+" "+theDay.getDate(),0);
		theDay = new Date(now.getTime()+(1*24*60*60*1000));
		document.getElementById(id).options[1] = new Option("Tomorrow, "+months[theDay.getMonth()+1]+" "+theDay.getDate(),1);
		for (var i=2; i<num; i++) {
			theDay = new Date(now.getTime()+(i*24*60*60*1000));
			document.getElementById(id).options[i] = new Option(days[(theDay.getDay()%7)+1]+", "+months[theDay.getMonth()+1]+" "+theDay.getDate(),i);
		}
	}
 
    function getHTTPObject() {
      var xmlhttp;
      /*@cc_on
      @if (@_jscript_version >= 5)
        try {
          xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
          try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
          } catch (E) {
            xmlhttp = false;
          }
        }
      @else
        xmlhttp = false;
      @end @*/
      if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        try {
          xmlhttp = new XMLHttpRequest();
          xmlhttp.overrideMimeType("text/xml");
        } catch (e) {
          xmlhttp = false;
        }
      }
      return xmlhttp;
    }
