var gDir ;
var arrHotels=null;
var currentHotel= 0;
var tempHotel=null;
var arrDistance=new Array();
var lastDistance=0;
listen(window, 'load', initgDir);
listen(window, 'unload',GUnload);
function initgDir()
{
	if (GBrowserIsCompatible())    
	{   
        gDir = new GDirections();//map, document.getElementById("directions"));
        GEvent.addListener(gDir, "load", gdirLoaded);
        GEvent.addListener(gDir, "error", gdirError);
   } 
}
function setDirections(fromAddress, toAddress, locale) {
	
      gDir.load("from: " + fromAddress + " to: " + toAddress, { "locale": locale });
}

function gdirLoaded()
{
	var distance = new Number(gDir.getDistance().meters)
	//arrDistance.push(distance);
	try {
		distance= distance / 1000	
	} catch (e)
	{
		alert(e);
	}
	
	 filterdistance(distance);
	if (currentHotel == tempHotel.length-1)
	{
		
		currentHotel=0;

		displaySearchResult (arrDistance);
		arrDistance=new Array();
	} else {
		currentHotel++;
		startCalculating();
	}
		
		
}



function gdirError()
{
		var c = gDir.getStatus().code
		var msg=msg_NOHOTELFOUND;
		if (c ==602)
		{
			currentHotel++;
			startCalculating()
		}
}

