
// resize fix for ns4
var origWidth, origHeight;
if (document.layers) {
	origWidth = window.innerWidth; origHeight = window.innerHeight;
	window.onresize = function() { if (window.innerWidth != origWidth || window.innerHeight != origHeight) history.go(0); }
}

var page_loaded; // set true onload (avoid errors onmouseover/out before page loaded)
function initInfoLyr() {
  page_loaded = true; 
  writeToLayer('drivedirinfo', origMsg); // write first message onload
}

function writeToLayer(id, sHTML) {
  if (!page_loaded) return;
  var el = (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? document.layers[id]: null;
  if (!el) return;
  var cntnt = '<div class="info">' + sHTML + '</div>';
  if (typeof el.innerHTML!="undefined") {
      el.innerHTML = cntnt;
  } else if (document.layers) {
			el.document.write(cntnt);
			el.document.close();
  }
}

// Variables for layer content
var origMsg = '<div class="hot">Here is the write layer. Position and style it any way you like.</div>';
var dfltMsg = "";


////drive route:
function showDriveDiv(divname){

if (divname == 'drivedivfrom'){
	document.getElementById('drivedivto').style.display = 'none';
	document.getElementById('drivedivfrom').style.display = 'block';
	}
else {
	document.getElementById('drivedivfrom').style.display ='none';
	document.getElementById('drivedivto').style.display = 'block';
	}
}
function FindLoc(dir){
	
	if(dir =='from'){
		//alert(document.getElementById('txtFrom').value + document.getElementById('fromtxtTo').value);
		map.GetRoute(document.getElementById('txtFrom').value,document.getElementById('fromtxtTo').value,null,null,onGotRoute);
	}else if (dir =='to'){
		//alert(document.getElementById('totxtFrom').value + document.getElementById('txtTo').value);
		map.GetRoute(document.getElementById('totxtFrom').value,document.getElementById('txtTo').value,null,null,onGotRoute);
		}
  //map.GetRoute(document.getElementById('txtFrom').value,document.getElementById('txtTo').value,null,null,onGotRoute);
}

function onGotRoute(route){
		var boxhtml = "<table border='0' width='400' bgcolor='DEE7EF' cellspacing='0' cellpadding='2'><tr><td width='100%'><table border='0' width='100%' cellspacing='0' cellpadding='0' height='36'>";
		boxhtml = boxhtml + "<tr><td id='titleBar' style='cursor:move' width='100%' class='xlBlue'><ilayer width='100%' onSelectStart='return false'><layer width='100%' onMouseover='isHot=true;' onMouseout='isHot=false'>Route info:</layer></ilayer></td><td style='cursor:hand' valign='top'><a href='#' onClick='hideMe();return false'><font color=#ffffff size=4 face=arial  style='text-decoration:none'>X</font></a></td></tr>";
		boxhtml = boxhtml + "<tr><td width='100%' bgcolor='#FFFFFF' style='padding:4px' colspan='2' class='smBlack'>";
		
		var routeinfo="";
		routeinfo+="Total distance: ";
		routeinfo+=   route.Itinerary.Distance+" ";
		routeinfo+=   route.Itinerary.DistanceUnit+"<br>";
		
		
		var steps="";
		var len = route.Itinerary.Segments.length;
		   for(var i = 0; i < len ;i++)
		   {
		      steps+=route.Itinerary.Segments[i].Instruction+" -- (";
		      steps+=route.Itinerary.Segments[i].Distance+") ";
		      steps+=route.Itinerary.DistanceUnit+"<br>";
		   }
		routeinfo+="Steps:\n"+steps;
		
		
		boxhtml = boxhtml + routeinfo;
		boxhtml = boxhtml + "</td></tr></table></td></tr></table>";
		//document.getElementById('theLayer').innerHTML = boxhtml;
		//alert(document.getElementById('theLayer').innerHTML)
		//alert(boxhtml);
		showMe();
		writeToLayer('drivedirinfo', boxhtml);
		//myroutinfobox.style.visibility= ' ';
		//myroutinfobox.innerHTML = routeinfo;
}

function hideMe(){
	
		
	document.getElementById('drivedirinfo').style.display = 'none';

}

function showMe(){
	document.getElementById('drivedirinfo').style.display = 'block';

}
// JavaScript Document
