function ValidateData(){

if (document.SendData.q1.value == '' && document.SendData.q2.value == ''){
	q1 = document.getElementById("FirstAddress")
	q1.className = 'FirstAddressError'
	q2 = document.getElementById("SecondAddress")
	q2.className = 'SecondAddressError'
}

if (document.SendData.q1.value == '') {
	q1 = document.getElementById("FirstAddress")
	q1.className = 'FirstAddressError'
	document.SendData.q1.focus();
	return false;
	}

if (document.SendData.q2.value == '') {
	q2 = document.getElementById("SecondAddress")
	q2.className = 'SecondAddressError'
	document.SendData.q2.focus();
	return false;
	}
	
else{
	showAddress('pointA','message','pointA','statusA');
	showAddress('pointB','message2','pointB','statusB');
	}
	
}

function ShowValidation(){
	$("#mw-data-validation").slideDown('slow');
}

function HideValidation(){
	$("#mw-data-validation").slideUp('slow');
}

function resetNotFlag(status) {
	document.getElementById(status).value = "NOT"
}

function CheckValue(tgt){
if (tgt.name == 'q1') {
if (tgt.value.length > 2){
q1 = document.getElementById("FirstAddress")
q1.className = 'FirstAddress'
	}
}
if (tgt.name == 'q2') {
if (tgt.value.length > 2){
q2 = document.getElementById("SecondAddress")
q2.className = 'SecondAddress'
	}
}
}

    if (GBrowserIsCompatible()) { 
    var map;
    var geo;
    var reasons=[];

    function load() {
      // ====== Create a Client Geocoder ======
      geo = new GClientGeocoder(); 
      // ====== Array for decoding the failure codes ======
      reasons[G_GEO_SUCCESS]            = "Success";
      reasons[G_GEO_MISSING_ADDRESS]    = "Missing Address: The address was either missing or had no value.";
      reasons[G_GEO_UNKNOWN_ADDRESS]    = "Unknown Address:  No corresponding geographic location could be found for the specified address.";
      reasons[G_GEO_UNAVAILABLE_ADDRESS]= "Unavailable Address:  The geocode for the given address cannot be returned due to legal or contractual reasons.";
      reasons[G_GEO_BAD_KEY]            = "Bad Key: The API key is either invalid or does not match the domain for which it was given";
      reasons[G_GEO_TOO_MANY_QUERIES]   = "Too Many Queries: The daily geocoding quota for this site has been exceeded.";
      reasons[G_GEO_SERVER_ERROR]       = "Server error: The geocoding request could not be successfully processed.";
    }

      // ====== Plot a marker after positive reponse to "did you mean" ======
    function place(tgt,point,status) {
		status.value = "OK"
		point.value = tgt;
    }
	
	function escapequote(str) {
	  return (str+'').replace("'", "&#39;");
	}
	
	function checkStatus(){
		statusA = document.getElementById("statusA");
		statusB = document.getElementById("statusB");
		if(statusA.value == 'NOT' || statusB.value == 'NOT'){
			return false
		}else{
			if(statusA.value == 'OK' && statusB.value == 'OK'){
				document.SendData.submit();
			}
		}
	}
	
	// ====== Geocoding ======
    function showAddress(address,message,point,status) {
		pointA = document.getElementById("pointA");
		pointB = document.getElementById("pointB");
		statusA = document.getElementById("statusA");
		statusB = document.getElementById("statusB");
	  	address = document.getElementById(address).value
		message = document.getElementById(message);
        var search = address;
        // ====== Perform the Geocoding ======        
        geo.getLocations(search, function (result)
          {
            if (result.Status.code == G_GEO_SUCCESS) {
              // ===== If there was more than one result, "ask did you mean" on them all =====
              if (result.Placemark.length > 1) { 
                message.innerHTML = "<div class='add-validation'>Did you mean:</div>";
                // Loop through the results
				for (var i=0; i<result.Placemark.length; i++) {
                  var p = result.Placemark[i].Point.coordinates;
				  document.getElementById(status).value = "NOT"
				  message.innerHTML += +(i+1)+": <a href='javascript:place(" + '"' + escapequote(result.Placemark[i].address) + '"' + ", "+point + ", "+status+");HideValidation();'>"+ result.Placemark[i].address+"<\/a><br />";
                }
				ShowValidation();
              }
              // ===== If there was a single marker =====
              else {
                var p = result.Placemark[0].Point.coordinates;
				if (point == 'pointA'){which = 'First'}
				if (point == 'pointB'){which = 'Second'}
				message.innerHTML = "<div class='add-located'>" + which + " Address: </div>"  +result.Placemark[0].address + " <img src='images/checkmark.png' alt='' title='' style='width:12px; height:9px; padding-left:3px;' />";
				place(p[0],p[1],point,status);
				if (document.getElementById(point).value.length > 3){
				document.getElementById(point).value = result.Placemark[0].address;
				}
				document.getElementById(status).value = "OK"
				checkStatus();
              }
            }
            // ====== Decode the error status ======
            else {
              var reason="Code "+result.Status.code;
              if (reasons[result.Status.code]) {
                reason = reasons[result.Status.code]
              } 
			  document.getElementById("statusA").value = "NOT"
              alert('Could not find "'+search+ '" ' + reason);
            }
          }
        );
      }
    }
    // display a warning if the browser was not compatible
    else {
      alert("Sorry, the Google Maps API is not compatible with this browser");
    }

image1 = new Image();
image1.src = "../images/btn_GetHalfwayLocation_on.gif";

function SetFocus(){
	document.getElementById("statusA").value = "NOT"
	document.getElementById("statusB").value = "NOT"
	document.SendData.q1.focus();
}
