function iscoord(strString) {
	// check for valid numeric strings	
	var strValidChars = "0123456789.-";
	var strChar;
	var blnResult = true;
	var i;

	if (strString.length == 0) return false;
	// test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++) {
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1) {
			blnResult = false;
		}
	}
	return blnResult;
}
function help(f, page) {
	openpage_dim(f, page, 400, 300);
}
function getCoord(coord_obj) {
	if (coord_obj) if (iscoord(coord_obj.value)) return coord_obj.value;
	return '';
}
function getLatLon(page) {
	var start_lat, start_lon;
	start_lat = getCoord(document.getElementById('lat'));
	start_lon = getCoord(document.getElementById('lon'));

	/* If start lat/lon specified, build up the new page url. */
	if (start_lat.length > 0 || start_lon.length > 0) page += '?start_zoom=7';
	if (start_lat.length > 0) page += '&start_lat=' + start_lat;
	if (start_lon.length > 0) page += '&start_lon=' + start_lon;
	openpage_dim(null, page, 800, 600);
}
function setLatLon(lat, lon) {
	var lat_obj = document.getElementById('lat');
	var lon_obj = document.getElementById('lon');
	lat = lat.replace(' ','');
	lon = lon.replace(' ','');
	if (lat_obj) lat_obj.value = lat;
	if (lon_obj) lon_obj.value = lon;
}
function openpage_dim(f, page, width, height) {
	var w=width, h=height;	
	var left = Math.floor( (screen.width - w) / 2);
	var top = Math.floor( (screen.height - h) / 2);
	var winParms = "top=" + top + ", left=" + left + ", width=" + w + ", height=" + h;
	var win = window.open(page, 'asdfadf', 'location=0, resizable=1, toolbar=0, menubar=0, status=0,' + winParms);
}
function openpage(page) {
	var x=50, y=50, w=570, h=450; 
	var win = window.open(page, "Locations", "width=" + w + ", height=" + h +
			/* "toolbar=0,resizable=0,status=0,menubar=0,location=1"); */
    		"");
	win.moveTo(x,y);
}
function trim(s) {
	var l = 0; 
	if (s != null) {
		var r = s.length - 1;
		while (l < s.length && s[l] == ' ') l++; 
		while (r > l && s[r] == ' ')	r-=1;
		return s.substring(l, r+1);
	}
}
function onClickTextInput(obj, default_txt) {
	if (obj) {
		if (trim(obj.value) == default_txt) {
			obj.value = ''; 
			obj.style.color = "#000";
		} else {
			obj.style.color = "#000";
		}
	}
}
function onBlurTextInput(obj, default_txt) {
	if (obj) {
		if (trim(obj.value) == '') {
			obj.value = default_txt; 
			obj.style.color = "#AAA";
		} else if (trim(obj.value) == default_txt) {
			obj.style.color = "#AAA";
		}
	}
}
