<!--
//  proxy variables
//  since it is my server, I can leave these blank, its relative to the page
var proxyServerName = "";
var proxyServerPort = "";
// this is the important one, it tells the JSAPI where to send the XML request (the location of the proxy on my own server)
var proxyServerPath = "mapquestAPI/JSAPIProxyPage/JSReqHandler.php";

//mq server variables
var mqPort = "80";
var mqPath = "mq";
var myGExec = new MQExec("geocode.dev.mapquest.com",mqPath,mqPort,proxyServerName,proxyServerPath,proxyServerPort);
var myRExec = new MQExec("route.dev.mapquest.com",mqPath,mqPort,proxyServerName,proxyServerPath,proxyServerPort);


var myTAddress = new MQAddress();
var myFAddress = new MQAddress();
var myGcColl = new MQLocationCollection("MQGeoAddress");
var myRtColl = new MQLocationCollection("MQGeoAddress");
var myOptions = new MQRouteOptions();
var myRtResults = new MQRouteResults();
var myTrkRtColl = new MQTrekRouteCollection();
var myManeuverColl = new MQManeuverCollection();
var myManStr = "";
var myTrkStr = "";
var mySessID = myRExec.createSessionEx(new MQSession());
var myBoundingBox = new MQA.RectLL(new MQA.LatLng(),new MQA.LatLng());
myOptions.setMaxShapePointsPerManeuver(200);


/*
*  populate address objects
*/
function popInfo() {
	if (document.getElementById("btnRoute").value == "Get Route"){
		myFAddress.setStreet(document.getElementById("Fstreet").value);
		myFAddress.setCity(document.getElementById("Fcity").value);
		myFAddress.setState(document.getElementById("Fstate").value);
		myFAddress.setPostalCode(document.getElementById("Fpostalcode").value);
		myFAddress.setCountry(document.getElementById("Fcountry").value);
		myTAddress.setStreet(document.getElementById("Tstreet").value);
		myTAddress.setCity(document.getElementById("Tcity").value);
		myTAddress.setState(document.getElementById("Tstate").value);
		myTAddress.setPostalCode(document.getElementById("Tpostalcode").value);
		myTAddress.setCountry(document.getElementById("Tcountry").value);
		myOptions.setLanguage(document.getElementById("lang").value);
		document.getElementById("btnRoute").value = "Clear Route"
		geocodeThem();
		showDiv('PrintDirections','');
	}
	else {
		showDiv('','PrintDirections');
		document.getElementById("btnRoute").value = "Get Route";
		clearInfo();
	}
}

/*
*  geocode the addresses
*/
function geocodeThem() {
	myGExec.geocode(myFAddress, myGcColl);
	myRtColl.add(myGcColl.get(0));
	myGExec.geocode(myTAddress, myGcColl);
	myRtColl.add(myGcColl.get(0));
	getRoute();
}


/*
*  call doroute
*/
function getRoute() {
	myRExec.doRoute(myRtColl,myOptions,myRtResults,mySessID,myBoundingBox);
	displayIt();
}


/*
*  display the results
*/
function displayIt() {
	var myMinutes = myRtResults.getTime()/60;
	if (myMinutes > 60) {
		if (myMinutes/60 == 1) {
			var myTotTime = "1 hr ";
		}
		else {
			var myTotTime = Math.round((myMinutes/60)*100)/100 + " hrs";
		}
	}
	else {
		var myTotTime = myMinutes + " min";
	}
	var myDist = Math.round(myRtResults.getDistance()*100)/100;

	myTrkRtColl = myRtResults.getTrekRoutes();
	myManeuverColl = myTrkRtColl.get(0).getManeuvers();

	for (intX = 0; intX < myManeuverColl.getSize(); intX ++){
		myManDist = Math.round(myManeuverColl.get(intX).getDistance()*100)/100;
		myManStr = (intX +1) +  ". " + myManeuverColl.get(intX).getNarrative() + "(Distance: " + myManDist + " mi)";
		myTrkStr = myTrkStr + myManStr + "<br/><hr/>";

	}
	document.getElementById("routeDiv").innerHTML = "<hr/><b>DRIVING DIRECTIONS: </b><br/><hr/>" + myTrkStr + "<b>Total Time: </b>" + myTotTime + "<b> Total Distance: </b>" + myDist + " miles<hr/><br/>";

	myMap = new MQA.TileMap(document.getElementById('mapDiv'));
  	myMap.addRouteHighlight(myBoundingBox,"http://map.dev.mapquest.com",mySessID,true);
  	myMap.addControl(new MQA.LargeZoomControl());
	myMap.addControl(new MQA.ViewControl());
	document.getElementById("mapDiv").style.visibility = "visible";
}

/*
*  clear the junk
*/
function clearInfo(){
	myMap.removeRouteHighlight();
	myTrkStr = "";
	myTAddress = new MQAddress();
	myFAddress = new MQAddress();
	myGcColl = new MQLocationCollection("MQGeoAddress");
	myRtColl = new MQLocationCollection("MQGeoAddress");
	myOptions = new MQRouteOptions();
	myRtResults = new MQRouteResults();
	myBoundingBox = new MQA.RectLL(new MQA.LatLng(),new MQA.LatLng());
	document.getElementById("routeDiv").innerHTML = '';
	document.getElementById("mapDiv").style.visibility = "hidden";
	document.getElementById("mapDiv").innerHTML = '';
	mySessID = myRExec.createSessionEx(new MQSession());
}
/*
*	compute distance without mapping
*/
function drivingDistanceOnly(c)
{
	var f=c.form;
	myFAddress.setStreet('3946 Broadway');
	myFAddress.setCity('Grove City');
	myFAddress.setState('OH');
	myFAddress.setPostalCode('43123');
	myFAddress.setCountry('US');

	myTAddress.setStreet(f.addr.value);
	myTAddress.setCity(f.city.value);
	myTAddress.setState(f.geo_state.value);
	myTAddress.setPostalCode(f.postalcode.value);
	myTAddress.setCountry(f.geo_country.value);
	myOptions.setLanguage('english');

	myGExec.geocode(myFAddress, myGcColl);
	myRtColl.add(myGcColl.get(0));
	myGExec.geocode(myTAddress, myGcColl);
	myRtColl.add(myGcColl.get(0));

	myRExec.doRoute(myRtColl,myOptions,myRtResults,mySessID,myBoundingBox);
	c.value = Math.round(myRtResults.getDistance()*100)/100;
	return false;
}
//-->