function handleUnload(){
	if(window.map || window.geocoder){
		GUnload();
	}else{
	}
}

function handleLoad(p){
	if(window.usingGMap == true){
			loadMap();
		
	}else if(window.usingGeocoder){
			loadGeocoder();
	}
}
function valSearch(f){
	var cf = new Array("parkCity","parkState","parkZip");
	var valid = true;
	var message, fix;
	var parkNamePresent = false;
	var parkZipPresent = false;
	if(f.parkName.value != ""){
		parkNamePresent = true;
	}
	if(f.parkZip.value != ""){
		parkZipPresent = true;
	}
	if(!parkNamePresent){
		if(f.parkCity.value != "" && f.parkState.selectedIndex == 0){
			valid = false;
			message = "You must enter a state to begin this search!";
			fix = f.parkState;
		}else if(f.parkState.selectedIndex > 0 && f.parkCity.value == ""){
			valid = false;
			message = "You must enter a city to begin this search!";
			fix = f.parkCity;
		}
	}else{
		if(f.parkCity.value == "" && f.parkState.selectedIndex == 0){
			valid = false;
			message = "You must enter a city and state or zipcode to begin this search";
			fix = f.parkCity;
		}else if(f.parkCity.value != "" && f.parkState.selectedIndex == 0){
			valid = false;
			message = "You must enter a state to begin this search!";
			fix = f.parkState;
		}else if(f.parkState.selectedIndex > 0 && f.parkCity.value == ""){
			valid = false;
			message = "You must enter a city to begin this search!";
			fix = f.parkCity;
		}
	}
			
	if(!parkZipPresent && !parkNamePresent && f.parkCity.value == "" && f.parkState.selectedIndex == 0){
		valid = false;
		message = "You must either enter a campground name, city and state or a zipcode to begin a search!";
		fix = f.parkName;
	}
	if(parkZipPresent && !valid){
		valid = true;
	}
	
	if(!valid){
		alert(message);
		fix.focus();
	}else{
		if(f.displayStyle[1].checked == true){
			var mf = document.mapForm;
			for(var i=0; i<cf.length; i++){
				mf[cf[i]].value = f[cf[i]].value;
			}
			mf.submit()
			return false;
		}
	}
	
	return valid;
}
function valUser(f){
	var valid = true;
	var message, fix;
	if(f.username.value == "" || f.password.value == ""){
		valid = false;
		message = "Enter your username and password before continuing!";
		fix = f.username;
	}
	if(!valid){
		alert(message);
		fix.focus();
	}
	return valid;
}
function dec2Deg(deg){
	if(deg < 0){
		deg = deg + (deg*2);
	}
	if(deg < 0){
		return "N/A";
	}else{
		var degs = parseInt(deg);
		var rem = deg - (degs * 1.0);
		var mins = rem * 60.0;
		var rem2 = mins - (parseInt(mins)*1.0);
		var secs = parseInt(rem2*60.0);
		var out = degs + "° "+mins+"' "+secs+"\"";
		return out;
	}
}

function valStartAdd(f){
	var valid = true;
	var message, fix;
	if(f.sAddress.value == ""){
		valid = false;
		message = "Please enter the starting address!";
		fix = f.sAddress;
	}else if(f.sCity.value == ""){
		valid = false;
		message = "Please enter the starting city!";
		fix = f.sCity;
	}else if(f.sState.selectedIndex == 0){
		valid = false;
		message = "Please select a starting state!";
		fix = f.sState;
	}else if(f.sZip.value == ""){
		valid = false;
		message = "Please enter the starting zip code!";
		fix = f.sZip;
	}
	if(!valid){
		alert(message);
		fix.focus();
	}
	return valid;
}

function simpleGeocode(c,s,z){
	var add = [];
	add.push(c);
	add.push(s);
	add.push(z);
	var v = {};
	v = getLatLng(add.join(', '));
	alert("VL: "+v.lat+" VN: "+v.lng);
	return v;
}
var map = null;
var geocoder = null;
function loadGeocoder() {
if (GBrowserIsCompatible()) {
	geocoder = new GClientGeocoder();
}
}

function getLatLng(address) {
if (geocoder) {
	var ll = {};
	geocoder.getLatLng(address,function(point) {
    	if (!point) {
        	alert(address + " not found");
        } else {
            var marker = new GMarker(point);
            var latlng = marker.getPoint();
			
			ll.lat = latlng.lat().toString();
			ll.lng = latlng.lng().toString();
           // marker.openInfoWindowHtml(address);
        }
   }
   );
   return ll;
}else{
	alert("Geocoder not available");
}
}
