
RouteDraw.prototype.OnWaypointUpdate = function(){
	var str = '';
	var point = this.FirstPoint;
	var teller = 0;
	while( point ){
		var afstand = point.Previous ? ',m:' + point.Previous.Position.distanceFrom( point.Position ) : null;
		str += teller + ':' + point.Position.lat() + ',' + point.Position.lng() + afstand + '<br>';
		teller ++;
		point = point.Next;
	}
}

RouteDraw.prototype.OnDistanceUpdate = function() {
	//document.getElementById( 'Distance' ).innerHTML = distance;
	routeDistance = this.GetDistance()/1000;
	var totDist = fix(routeDistance,2);
	$('currentDist').innerHTML = totDist + currentUnit;
	$('currentTime').innerHTML = 'End time: ' + getFixTime(totDist) + 'min';
	if (currentUnit == "miles") {
	$('currentSpeed').innerHTML = fix(currentSpeed,1) + " mph";
	} else {
		$('currentSpeed').innerHTML = fix(currentSpeed,1) + " km/h ";
	}

}

RouteDraw_Point.prototype.OnHeightResponse = function() {

	if (hPlot == null) 
			hPlot = new heightsPlot(); 

	hPlot.addHeight (this.Height);
	hPlot.addDistance(this.Distance/1000);
	hPlot.insertGraph();

/*
	distancesBuffer.push ( this.Distance/1000 );
	heightsBuffer.push ( this.Height )

	var hImg = document.getElementById('heightImage');
  var params = "";
	if ( newr && heightsBuffer.length > 0 && distancesBuffer.length == heightsBuffer.length) {

					var totDist  = 0;
					for ( i in heightsBuffer )
					{
												 params += "&h[]=" + heightsBuffer[ i ];
					}

					for ( i in distancesBuffer )
					{
												 totDist += distancesBuffer [ i ];
												 params += "&d[]=" + totDist;
					}
	}

	hImg.src = '../routes/heightGraph.php?q' + params;
	hImg.style.display = 'block';
  hImg.onclick = function () { this.style.display = 'none' }
	*/
}

var NieuweRouteInfo = null;

RouteDraw.prototype.SaveRouteForm = function( Info ){
	NieuweRouteInfo = Info;
	var marker = new GMarker( this.FirstPoint.Position );
	this.Map.addOverlay( marker );
	marker.openExtInfoWindow(
    this.Map,
    "RaboWindow",
    "A moment please...",
    {
			beakOffset: 0,
			paddingX: 60,
			paddingY: 20,
			ajaxUrl: Map_Config.Url.InfoForm,
			ajaxCallback:RouteSaveFormNewInit
		}
  );
}

function RouteSaveFormNewInit(){
	var form = document.forms[ 'RouteSave' ];
	form.zipcode.value = NieuweRouteInfo.StartInfo.Zipcode;
	form.place.value = NieuweRouteInfo.StartInfo.Place;
	form.region.value = NieuweRouteInfo.StartInfo.Region;
	form.countrycode.value = NieuweRouteInfo.StartInfo.CountryCode;
	form.distance.value = Math.round( NieuweRouteInfo.Distance / 100 ) / 10;
	
	/* Important, post the points */
  form.route.value = JSON.stringify( NieuweRouteInfo.Route );
}

function canSaveRouteForm( frm ){
	if ( frm.name.value == '' ){
		alert( "Please fill in a name for the route" );
		return false;
	}
	return true;
}
