﻿var map = null;
var detailspanel = null;
var tiles=new Array();
var totalNumberOfTiles=0;
var currentView='r';
var currentViewBeforeBirsEye='';
var secondsToWait=3*1000;
var secondsToWaitSearching=5*10000;
var doPoly=false;
var returnedStartAddressInfos=null;
var startAddressIndexUsed=0;
var returnedStores=null;
var currentLeftHandDiv=null;
var isMapExpanded=false;
var currentSelectedStore=0;
var returnedDrivingAddressInfos=null;
var drivingDirectionsAddressIndexUsed=0;
var drivingDirectionSegments=null;
var currentlyShowingMap="";
var drivingDirectionsTime=0;
var drivingDirectionsMiles=0;
var showDetailView=true;
var scene=null;
var otherStoreCount=0;
var changeLocationHTML="<span class='changelocation'><a href='' onclick='SwitchToStartAddressFromListOfStores(); return false;'>search for a different location</a></span>";

var poly=null;
var pts = [];
var lineColors = ['red','green','blue','orange','yellow','gray','white'];
var currLineColor = 0;
var isPanning = false;
var bSaf = (navigator.userAgent.indexOf('Safari') != -1);
var bMoz = (navigator.appName == 'Netscape');

var w = window; var d = document; var browserType; if (w.opera) { if (w.print && d.childNodes) { browserType = "opera7"; } else { if (w.print) { browserType = "opera6"; } else { browserType = "opera5orLess"; }}}

function TestAjax()
{
	// check and see if we are safari or not
	if(bSaf)
	{
		window.location="/storelocator/noajax.aspx";
	}
	var intTimeOut=self.setTimeout("TestAjax_Timeout()", 5*1000);
	// make a call off to AJAX
	ajax.SupportAjax(intTimeOut,TestAjax_Callback);
}
function TestAjax_Callback(response)
{	// clear out the timeout
	try
	{
		self.clearTimeout(response.value);
	}
	catch(ex)
	{
	}
	// start the process
	StartStore();
}
function TestAjax_Timeout()
{
	// we didn't get anything back from the ajax call in the time period
	window.location="/storelocator/noajax.aspx";
}
function GetSessionInfo()
{
	var historyObject=new Object();
	historyObject.ReturnedStores=returnedStores;
	historyObject.returnedStartAddressInfos=returnedStartAddressInfos;
	historyObject.startAddressIndexUsed=startAddressIndexUsed;
	historyObject.returnedDrivingAddressInfos=returnedDrivingAddressInfos;
	historyObject.drivingDirectionsAddressIndexUsed=drivingDirectionsAddressIndexUsed;
	historyObject.drivingDirectionSegments=drivingDirectionSegments;
	historyObject.drivingDirectionsTime=drivingDirectionsTime;
	historyObject.drivingDirectionsMiles=drivingDirectionsMiles;
	historyObject.scene=scene;
	historyObject.otherStoreCount=otherStoreCount;
	return historyObject;
}

function ProcessBack(newLocation,historyObject)
{
	//alert('ProcessBack');
	// init all the vars
	returnedStores=historyObject.ReturnedStores;
	returnedStartAddressInfos=historyObject.returnedStartAddressInfos;
	startAddressIndexUsed=historyObject.startAddressIndexUsed;
	returnedDrivingAddressInfos=historyObject.returnedDrivingAddressInfos;
	drivingDirectionsAddressIndexUsed=historyObject.drivingDirectionsAddressIndexUsed;
	drivingDirectionSegments=historyObject.drivingDirectionSegments;
	drivingDirectionsTime=historyObject.drivingDirectionsTime;
	drivingDirectionsMiles=historyObject.drivingDirectionsMiles;
	scene=historyObject.scene;
	otherStoreCount=historyObject.otherStoreCount;

	switch(newLocation)
	{
	case 'startaddress':
		RemoveDrivingDirectionsPopup();
		UpdateDiv(currentLeftHandDiv,"none",0,"");
		UpdateDiv("enterStartAddressDiv","block",0,"");
		UpdateDiv("mapContainerDiv","none",0,"");
		UpdateDiv("instructionsDiv","block",0,"");
		break;
	case 'startaddresslist':
		RemoveDrivingDirectionsPopup();
		UpdateDiv(currentLeftHandDiv,"none",0,"");
		UpdateDiv("matchingAddressDiv","block",0,CreateMoreThenOneStartAddressReturnedHtml());
		UpdateDiv("mapContainerDiv","none",0,"");
		UpdateDiv("instructionsDiv","block",0,"");
		break;
	case 'listofstores':
		RemoveDrivingDirectionsPopup();
		UpdateDiv(currentLeftHandDiv,"none",0,"");
		UpdateDiv("instructionsDiv","none",0,"");
		UpdateDiv("storesListDiv","block",0,CreateReturnedStoresListHtml());
		UpdateDiv("mapContainerDiv","block",0,"");
		DrawStoresMap();
		break;
	case 'drivingaddresslist':
		UpdateDiv(currentLeftHandDiv,"none",0,"");
		UpdateDiv("drivingMatchingAddressDiv","block",0,CreateMoreThenOneDrivingAddressReturnedHtml());
		UpdateDiv("mapContainerDiv","block",0,"");
		DrawStoresMap();
		break;
	case 'drivingdirections':
		// hide whatever is listed on the left, and display the matchingaddress
		UpdateDiv(currentLeftHandDiv,"none",0,"");
		UpdateDiv("drivingDirectionDiv","block",0,CreateDrivingDirectionsHtml(0,0));
		UpdateDiv("mapContainerDiv","block",0,"");
		DrawDrivingMap();
	case 'detailview':
		currentlyShowingMap="BirdsEye";
		currentViewBeforeBirsEye=currentView;
		map.SetObliqueScene(scene.GetID());
		var intTimeOut=self.setTimeout("ShowDetailedViewStep2()", .5*1000);
	}
}
function RemoveDrivingDirectionsPopup()
{
//alert('RemoveDrivingDirectionsPopup');
	// get rid of the panel
	if (detailspanel != null)
	{
		document.body.removeChild(detailspanel);
		detailspanel = null;
	}
}
function DisplayDrivingDirectionsPopup(z,div,storeOrDriving)
{
//alert('DisplayDrivingDirectionsPopup')


	// set the current store
	currentSelectedStore=z;
	
	var temp=document.getElementById("mapdrawing");
	temp=div;
	var oNode=temp;
	//alert(oNode);
	
	var offsetX=0;
	var offsetY=0;
	
	while (oNode!=null)
	{
		offsetX+=oNode.offsetLeft;
		offsetY+=oNode.offsetTop;
		//alert(offsetX + ',' + offsetY);
		oNode=oNode.offsetParent;
	}
	
	// set the location of the panel
	
	var placeX=offsetX+20;
	var placeY=offsetY+20;
     // make sure we have only one panel at a time 
	RemoveDrivingDirectionsPopup()	
	
	// id,x,y,width,height,color,zIndex,title,body,footer,mouseovertitle,bOpaque
	detailspanel=document.createElement("div");
	detailspanel.id="storePopup";
	// set its location	
	detailspanel.style.top=(placeY)+ 'px';
	detailspanel.style.left=(placeX)+ 'px';

	//detailspanel.style.width='150px'; taken care of in OverRideMapControl.css - see .VE_Panel_el
	//detailspanel.style.height='150px';
	detailspanel.style.position="absolute";
	detailspanel.style.zIndex=31;
	detailspanel.className='VE_Panel_el_Large';
	
	if(storeOrDriving==0)
	{
		detailspanel.innerHTML=GetStoreText();
		detailspanel.style.height="300px";
	}
	else
	{
		detailspanel.innerHTML=CreateBlankDrivingDirectionHtml();
	}

	// append the div to the body
	document.body.appendChild(detailspanel);
}
function ShowDrivingDirectionsPopup(num,storeOrDriving)
{
  //alert('ShowDrivingDirectionsPopup');
  
	// remove the panel
	RemoveDrivingDirectionsPopup();
	var temp=document.getElementById("storepindiv" + num);
	//alert(temp);
    if (temp != null)
    {
        DisplayDrivingDirectionsPopup(num,temp,storeOrDriving);
    }
	
}
function centermapstores(num,storeOrDriving)
{
   // alert('centermapstores');
	// remove the panel
	RemoveDrivingDirectionsPopup();
	// move the image
	//map.SetCenterAndZoom(returnedStores[num].Latitude,returnedStores[num].Longitude,13);
	 var LA = new VELatLong(returnedStores[num].Latitude, returnedStores[num].Longitude); 
	 map.SetCenter(LA);
	  
	 
	 // set the flag to show the popup when the move is complete
	self.setTimeout("ShowDrivingDirectionsPopup(" + num + "," + storeOrDriving + ")", .5*1000);
}
function centermapdriving(num)
{
	// move the image
	if(num<drivingDirectionSegments.length)
	{
	    var LA = new VELatLong(drivingDirectionSegments[num].Latitude,drivingDirectionSegments[num].Longitude); 
		map.SetCenter(LA);
	}
	else
	{
	    var LA = new VELatLong(returnedStores[currentSelectedStore].Latitude, returnedStores[currentSelectedStore].Longitude); 
		map.SetCenter(LA);
	}
}
function GetCurrentView(currentView)
{
    //alert('GetCurrentView');
	switch(currentView)
	{
	case 'r':
		return 'Road';
	case 'h':
		return 'Hybrid';
	case 'a':
		return 'Aerial';
	case 'o':
		return 'BirdsEye';
	}
}
function onerror(e)
{
	if(e!="too much recursion")
	{
		//alert(e.error);
		//alert(e.view.sceneID);
		//var e1 = getClass(e);
		//alert(e1);
	}
}
function onchangeview(e)
{
	if(currentView!=e.view.mapStyle)
	{
		var textChange='ChangeFrom' + GetCurrentView(currentView) + 'To' + GetCurrentView(e.view.mapStyle);
		self.setTimeout("UpdateTiles('" + textChange + "')", secondsToWait);
		currentView=e.view.mapStyle;
	}
}
function onstartcontinuouspan(e)
{
//alert('onstartcontinuouspan');

	RemoveDrivingDirectionsPopup();
}
function onendpan(e)
{
	RemoveDrivingDirectionsPopup();
	self.setTimeout("UpdateTiles(GetCurrentView(currentView) + 'Pan')", secondsToWait);
}
function onstartzoom(e)
{
//alert('onstartzoom');

	RemoveDrivingDirectionsPopup()
	if(doPoly)
	{
		map.clearPolylines();
	}
}
function onendzoom(e)
{
	self.setTimeout("UpdateTiles(GetCurrentView(currentView) + 'Zoom')", secondsToWait);

	if(currentlyShowingMap=="BirdsEye")
	{
		if(map.GetZoomLevel()==1)
		{
			UpdateDiv("zoomBird","inline",0,"");	
			UpdateDiv("unZoomBird","none",0,"");
		}
		else
		{
			UpdateDiv("zoomBird","none",0,"");	
			UpdateDiv("unZoomBird","inline",0,"");
		}
	}


	if(doPoly)
	{
		if (poly) 
		{
			//alert('drawing');
			map.drawPolyline(poly, 1.0);
		}
	}
}
function onresize(e)
{
//alert('onresize');
	self.setTimeout("UpdateTiles(GetCurrentView(currentView) + 'Resize')", secondsToWait);
}
function onchangemapstyle(e)
{
//alert('onchangemapstyle')
	if(currentView!=e.GetMapStyle())
	{
		var textChange='ChangeFrom' + GetCurrentView(currentView) + 'To' + GetCurrentView(e.view.mapStyle);
		self.setTimeout("UpdateTiles('" + textChange + "')", secondsToWait);
		currentView=e.view.mapStyle;
	}
}
function UpdateTiles(WhatHappened)
{
	//alert("UpdateTiles-" + WhatHappened);
    var i=0;
    var j=0;
    var foundTile=false;
    var numberOfTilesToStart=totalNumberOfTiles;
	// try and count the images
	var mainMap=document.getElementById("mapdrawing");
	var subMap=document.getElementById("mapdrawing");
	var subMaps=subMap.getElementsByTagName("img");
	for(i=0;i<subMaps.length;i++)
	{
		if(tiles[subMaps[i].src]==null)
		{
			tiles[subMaps[i].src]='1';
			totalNumberOfTiles++;
		}
	}

	////Commented by Nitin Gupta - Starts
	////ajax.RecordVeEvent(currentlyShowingMap + "-" + WhatHappened,totalNumberOfTiles-numberOfTilesToStart, maps_ether_callback);
	////Commented by Nitin Gupta - Ends	
		

	////Added by Nitin Gupta - Starts
	ajax.RecordVeEvent(currentlyShowingMap + "-" + WhatHappened,totalNumberOfTiles-numberOfTilesToStart);
	////Added by Nitin Gupta - Ends	
}

function maps_ether_callback(response) {}

function getRidOfWheel()
{
	var strCode = new String(Msn.VE.MapControl);
	//alert(strCode);
	strCode = strCode.replace('x.attachEvent("onmousewheel",eo);','')
	strCode = strCode.replace('x.addEventListener("DOMMouseScroll",eo,false);','');
	//strCode = strCode.replace(/this.GetFailureRate\s*=\s*pu;/,  'this.GetFailureRate=pu; this.map = j; this.getVar = function (varName) { return eval(varName); }; ' + strNewCode);
	//alert(strCode);
	if (!bMoz) 
	{
		if(browserType==null)
		{
			strCode = strCode.replace('function(x,V)', '');		
			Msn.VE.MapControl = function (x,V) {  eval(strCode) };
		}
		else
		{
			// opera, so do nothing
		}
	} 
	else
	{
		Msn.VE.MapControl = eval(strCode);
	}
}
function CancelAjaxRequest()
{
	alert('search timeout reached');
}
function SubmitStartAddress()
{
	// check and make sure something is filled out
	var singleLine=document.getElementById("Locatordefault1_txtSingleLine");
	//var zipCode=document.getElementById("Locatordefault1_zip");
	//var address=document.getElementById("Locatordefault1_addr");
	//var city=document.getElementById("Locatordefault1_place");
	//var state=document.getElementById("Locatordefault1_uStates");
	if(singleLine.value!="")
	{
		// show the searchign div
		UpdateDiv("enterStartAddressDiv","none",0,"");
		//alert('sending request');
		UpdateDiv("searchingDiv","block",0,CreateStartingAddressSearchHtml());
		// add to the url for history
		//dhtmlHistory.add("startaddress", singleLine.value);
		// set the timeout
		var intTimeOut=self.setTimeout("CancelAjaxRequest()", secondsToWaitSearching);
		// do the verify ot make sure data is in there
		ajax.LookupAddress(singleLine.value,"","","","",intTimeOut,"StartAddress",SubmitStartAddress_Callback);
	}
	else
	{
		alert('Please enter a starting location');
	}
}

// return value as "response.value"
// should be an FindAddressReturn
// array of AddressInfo objects
// error as a string if there is one
function SubmitStartAddress_Callback(response)
{
	if(response.error!=null)
	alert(response.error.Message)
    
	UpdateDiv("searchingDiv","none",0,"");
	// clear out the timeout
	try
	{
		self.clearTimeout(response.value.TimeOutVar);
	}
	catch(ex)
	{
	}
	// check for an error
	if (response.error != null)
	{
		// not sure what to do here
		alert('error looking up address: ' + response.error);
		return;
	}
	var divHtml="";
	// see if we got an error back
	if(response.value.Error!="")
	{
		divHtml=CreateErrorParsingStartingAddressHtml();
	}
	// check how many we got back
	returnedStartAddressInfos=response.value.ReturnAddresses;
	if(returnedStartAddressInfos!=null)
	{
		if(returnedStartAddressInfos.length==0)
		{
			// this is bad
			divHtml=CreateNoStartingAddressesReturnedHtml();
		}
		else if(returnedStartAddressInfos.length==1)
		{
			FindStores(0);
			return;
		}
		else
		{
			// forulate the html
			divHtml=CreateMoreThenOneStartAddressReturnedHtml();
		}
	}
	else
	{
		// some sort of error happened
		// we need to do something here
		// the error has already been logged on the back end
	}
	// show the address info
	UpdateDiv("matchingAddressDiv","block",0,divHtml);
	// add to the url for history
	dhtmlHistory.add("startaddresslist", GetSessionInfo());
}
// takes the index of the returnedStartAddressInfos array to use for the search
// starts an AJAX call to get all the stores
function FindStores(arrayIndexToUse)
{
	// update the address to use
	startAddressIndexUsed=arrayIndexToUse;
	// update the display
	UpdateDiv("matchingAddressDiv","none",0,"");
	// get the value of the textbox
	var singleLine=document.getElementById("Locatordefault1_txtSingleLine");
	singleLine.value=returnedStartAddressInfos[arrayIndexToUse].FormattedAddress;
	// create the html
	UpdateDiv("searchingDiv","block",0,CreateSearchingStoresSearchHtml());
	// set the timeout
	var intTimeOut=self.setTimeout("CancelAjaxRequest()", secondsToWaitSearching);
	// start hte AJAX call
	ajax.FindStores(returnedStartAddressInfos[arrayIndexToUse].Latitude,returnedStartAddressInfos[arrayIndexToUse].Longitude,intTimeOut,FindStores_Callback);
}
// return value as "response.value"
// should be an FindStoresReturn object
// contaning an array of stores and OtherStoreCount
function FindStores_Callback(response)
{
	UpdateDiv("searchingDiv","none",0,"");
	if (response.error != null)
	{
		// not sure what to do here
		alert('error looking up stores: ' + response.error);
		return;
	}
	// clear out the timeout
	try
	{
		self.clearTimeout(response.value.TimeOutVar);
	}
	catch(ex)
	{
	}
	// check how many came back
	returnedStores=response.value.TheseStores;
	otherStoreCount=response.value.OtherStoreCount;
	var divHtml=GetStoreListHtml();
	// make the store list div visible
	UpdateDiv("storesListDiv","block",0,divHtml);
	if(returnedStores!=null)
	{
		// hide hte instructions div
		UpdateDiv("instructionsDiv","none",0,"");
		// make the map div visible
		UpdateDiv("mapContainerDiv","block",0,"");
		// draw the stores
		DrawStoresMap();
	}	
	// add to the url for history
	dhtmlHistory.add("listofstores", GetSessionInfo());
}
// starts looking for driving directions
function StartDrivingDirections()
{

	UpdateDiv(currentLeftHandDiv,"none",0,"");
	UpdateDiv("searchingDiv","block",0,CreateFindingDrivingAddressSearchHtml());
	// set the timeout
	var intTimeOut=self.setTimeout("CancelAjaxRequest()", secondsToWaitSearching);
	// start the ajax call
	
	var singleLine=document.getElementById("enddrivingdirections");
//	var options = new VERouteOptions(); 
//	options.RouteCallback = onGotRoute;
//	 
//	 var LA = new VELatLong(returnedStores[currentSelectedStore].Latitude,returnedStores[currentSelectedStore].Longitude);
//	  var LA1 = new VELatLong(returnedStores[0].Latitude,returnedStores[0].Longitude);
//	map.GetDirections([LA,LA1],options);

	ajax.LookupAddress(singleLine.value,"","","","",intTimeOut,"DrivingDirections",StartDirectionAddress_Callback);

}

// return value as "response.value"
// should be an FindAddressReturn
// array of AddressInfo objects
// error as a string if there is one
function StartDirectionAddress_Callback(response)
{
	////Commented By Nitin Gupta - Starts
	////UpdateDiv("searchingDiv","none",0,"");
	////Commented By Nitin Gupta - Ends
	////Added By Nitin Gupta - Starts
	UpdateDiv("searchingDrivingDiv","none",0,"");
	////Added By Nitin Gupta - Ends
	// clear out the timeout
	try
	{
		self.clearTimeout(response.value.TimeOutVar);
	}
	catch(ex)
	{
	}
	if (response.error != null)
	{
		// not sure what to do here
		alert('error looking up address: ' + response.error);
		return;
	}
	var divHtml="";
	// see if we got an error back
	if(response.value.Error!="")
	{
		divHtml=CreateErrorParsingDrivingAddressHtml();
	}
	// check how many we got back
	returnedDrivingAddressInfos=response.value.ReturnAddresses;
	if(returnedDrivingAddressInfos!=null)
	{
		if(returnedDrivingAddressInfos.length==0)
		{
			// this is bad
			divHtml=CreateNoDrivingAddressesReturnedHtml();
		}
		else if(returnedDrivingAddressInfos.length==1)
		{
			GetDrivingDirections(0);
			return;
		}
		else
		{
			// forulate the html
			divHtml=CreateMoreThenOneDrivingAddressReturnedHtml();
		}
	}
	// show the address info
	UpdateDiv("drivingMatchingAddressDiv","block",0,divHtml);
	
	// add to the url for history
	dhtmlHistory.add("drivingaddresslist", GetSessionInfo());
}
function GetDrivingDirections(i)
{
    UpdateDiv(currentLeftHandDiv,"none",0,"");
	// set which address to use
	drivingDirectionsAddressIndexUsed=i;
	// create the html	
	////Commented By Nitin Gupta - Starts
	////UpdateDiv("searchingDiv","block",0,CreateDrivingDirectionsSearchHtml());
	////Commented By Nitin Gupta - Ends
	////Added By Nitin Gupta - Starts
	UpdateDiv("searchingDrivingDiv","block",0,CreateDrivingDirectionsSearchHtml());
	////Added By Nitin Gupta - Ends
	// set the timeout
	var intTimeOut=self.setTimeout("CancelAjaxRequest()", secondsToWaitSearching);
	// start the AJAX call
	ajax.GetDrivingDirections(returnedDrivingAddressInfos[i].Latitude,returnedDrivingAddressInfos[i].Longitude,returnedStores[currentSelectedStore].Latitude,returnedStores[currentSelectedStore].Longitude,intTimeOut,GetDrivingDirection_Callback);
}

function GetDrivingDirection_Callback(response)
{
    	//alert('sanjay');
	////Commented By Nitin Gupta - Starts
	////UpdateDiv("searchingDiv","none",0,"");
	////Commented By Nitin Gupta - Ends
	//alert('abc1');
	////Added By Nitin Gupta - Starts
	UpdateDiv("searchingDrivingDiv","none",0,"");
	////Added By Nitin Gupta - Ends
	if(response.error != null)
	{
		// not sure what to do here
		alert('error getting driving directions: ' + response.error);
		return;
	}
	// clear out the timeout
	try
	{
	//alert('abc');
	//alert(response.value.TimeOutVar);
		self.clearTimeout(response.value.TimeOutVar);
	}
	catch(ex)
	{
	}
	// start by removing the panel
	
	RemoveDrivingDirectionsPopup();
	currentlyShowingMap="Driving";
	drivingDirectionSegments=response.value.Segments;

	if(drivingDirectionSegments!=null)
	{
	    //alert('inner');
		drivingDirectionsTime=response.value.TripTime;
		drivingDirectionsMiles=response.value.Distance;
		// create the html for the driving directions
		var html=CreateDrivingDirectionsHtml();
		// update the div
		UpdateDiv("drivingDirectionDiv","block",0,html);
		// draw the map
		DrawDrivingMap();
		
		//alert(response.value.VEDirections);
		//Swap out name of "VE_Directions.Populate" to be "OurDrivingDirectionPopulate"
		var tempLines=response.value.VEDirections;
		//tempLines=tempLines.replace('VE_Directions.Populate','OurDrivingDirectionPopulate');
		//var tempLines1=eval(tempLines);
		//eval(tempLines);
		
		// add to the url for history
		dhtmlHistory.add("drivingdirections", GetSessionInfo());
	}
}
function OurDrivingDirectionPopulate(startAddress,startLatLon,endAddress,endLatLon,steps,lats,lons,distance,distanceUnit,time,bestViewRectangle,routeRegionsByZoomLevel,zoomLevelsForGeneralizedLines)
{
	// set some vars
	var routeHighlightWeight=6;
	var routeHighlightColor="#11DD11";
	var routeHighlightZIndex=4;
	var routeHighlight=null;
	
	// create the routes
	//var route=new VE_Route("veDD",startAddress,startLatLon,endAddress,endLatLon,distance,distanceUnit,time,steps,lats,lons,bestViewRectangle,routeRegionsByZoomLevel,zoomLevelsForGeneralizedLines);
	var displayedRoute=new VE_Route("veDD",startAddress,startLatLon,endAddress,endLatLon,distance,distanceUnit,time,null,lats,lons,bestViewRectangle,routeRegionsByZoomLevel,zoomLevelsForGeneralizedLines);
	// set the best viewpoint
	//SetViewport(bestViewRectangle[0].latitude,bestViewRectangle[0].longitude,bestViewRectangle[1].latitude,bestViewRectangle[1].longitude);
	// create the route highlights
	if(displayedRoute!=null&&displayedRoute.latitudes!=null&&displayedRoute.longitudes!=null&&displayedRoute.routeRegionsByZoomLevel!=null&&displayedRoute.zoomLevelsForGeneralizedLines!=null)
	{
		routeHighlight=map.AddLine("veDDHighlight",displayedRoute.latitudes,displayedRoute.longitudes,routeHighlightWeight,routeHighlightColor,routeHighlightZIndex,displayedRoute.routeRegionsByZoomLevel,displayedRoute.zoomLevelsForGeneralizedLines);
		routeHighlight.ChangeVisibility(true);
		routeHighlight.Show();
	}

}
function InitMap()
{
    var LA = new VELatLong(returnedStores[0].Latitude, returnedStores[0].Longitude);

    var pinPoint = null;
    var pinPixel = null;

    map = new VEMap('mapdrawing');
    map.LoadMap(LA, 9, VEMapStyle.Road);

//    var pin = new VEShape(VEShapeType.Pushpin, LA);
//    pin.SetCustomIcon(15);
//    pin.SetTitle('');
//    pin.SetDescription("pinunhighligh");
//    map.AddShape(pin);
    
    //map.AttachEvent("onchangemapstyle", onchangemapstyle);
	map.AttachEvent("onendpan", onendpan);
	map.AttachEvent("onendzoom", onendzoom);
	map.AttachEvent("onresize", onresize);
	map.AttachEvent('onstartzoom', onstartzoom);
	map.AttachEvent('onerror',onerror);

}
function RemoveBirdsEyeLabel()
{
//alert('RemoveBirdsEyeLabel');
	// find the birds eye div, and change the text
	var tempDiv=document.getElementById("mapnavdashboard");
	//alert(tempDiv);
	var allSubDivs=tempDiv.getElementsByTagName("DIV");
	//alert(allSubDivs);
	for(var i=0;i<allSubDivs.length;i++)
	{
		if(allSubDivs[i].innerHTML=="bird's eye")
		{
			tempDiv.removeChild(allSubDivs[i]);
		}
	}
}
function onunload_procedure()
{
	if(map!=null)
	{
		//map.DetachEvent("onchangemapstyle", onchangemapstyle);
		map.DetachEvent("onendpan", onendpan);
		map.DetachEvent("onendzoom", onendzoom);
		map.DetachEvent("onresize", onresize);
		map.DetachEvent('onstartzoom', onstartzoom);
	}
}
function SwitchToStartAddressFromListOfStores()
{
	UpdateDiv("storesListDiv","none",0,"");
	////Added by Nitin Gupta - Starts	
	UpdateDiv("matchingAddressDiv","none",0,"");
	UpdateDiv("mapContainerDiv","none",0,"");
	////Added by Nitin Gupta - Ends
	UpdateDiv("enterStartAddressDiv","block",0,"");
	// remove a popup if there is one
	RemoveDrivingDirectionsPopup();
	// add in the bookmark
	dhtmlHistory.add("startaddress", GetSessionInfo());
}
function SwitchToStartAddressFromListOfAddresses()
{
	UpdateDiv("matchingAddressDiv","none",0,"");
	UpdateDiv("enterStartAddressDiv","block",0,"");
	// add in the bookmark
	dhtmlHistory.add("startaddress", GetSessionInfo());
}
function ChangeToDrivingDirections()
{
	// change the text of the div to be get driving directions
	UpdateDiv("storePopup","",0,CreateBlankDrivingDirectionHtml());
}
function ChangeFromDrivingDirections()
{
	// change the text of the div to be get driving directions
	UpdateDiv("storePopup","",0,GetStoreText());
}
function SwtichFromDrivingDirectionsToStores()
{
//alert('SwtichFromDrivingDirectionsToStores');
	UpdateDiv("drivingDirectionDiv","none",0,"");
	UpdateDiv("storesListDiv","block",0,CreateReturnedStoresListHtml());
	// get rid of the popup
	RemoveDrivingDirectionsPopup()	
	// force a redraw of the map
	DrawStoresMap();
	dhtmlHistory.add("listofstores", GetSessionInfo());
}
function ExpandMap()
{
	UpdateDiv(currentLeftHandDiv,"none",0,"");
	UpdateDiv("mapContainerDiv","",700,"");
	UpdateDiv("mapdrawing","",700,"");
	UpdateDiv("expandMap","none",0,"");
	UpdateDiv("unExpandMap","block",0,"");
	isMapExpanded=true;
	//move the popup if needed
	if(detailspanel!=null)
	{
		var temp=detailspanel.style.left;
		temp=temp.replace('px','')
		temp-=350;
		temp=temp + 'px';
		detailspanel.style.left=temp;
	}
}
function UnExpandMap()
{
	////Commented by Nitin Gupta - Starts
	UpdateDiv("mapContainerDiv","",890,"");
	UpdateDiv("mapdrawing","",890,"");
	////Commented by Nitin Gupta - Ends
	UpdateDiv("expandMap","block",0,"");
	UpdateDiv("unExpandMap","none",0,"");
	UpdateDiv(currentLeftHandDiv,"block",0,"");
	isMapExpanded=false;
	//move the popup if needed
	if(detailspanel!=null)
	{
		var temp=detailspanel.style.left;
		temp=temp.replace('px','')
		temp-=-350;
		temp=temp + 'px';
		detailspanel.style.left=temp;
	}
}
function UpdateDiv(divName, style, size, html)
{
	var tempDiv=document.getElementById(divName);
	if(tempDiv!=null)
	{
		if(style!=""){tempDiv.style.display=style};
		if(style=="block"){if(divName=="drivingMatchingAddressDiv" | divName=="storesListDiv" | divName=="matchingAddressDiv" | divName=="searchingDiv" | divName=="drivingDirectionDiv" | divName=="enterStartAddressDiv"){currentLeftHandDiv=divName;}}
		////Commented By Nitin Gupta - Starts
		////if(size>0){tempDiv.style.width=size + 'px'};
		////Commented By Nitin Gupta - Ends
		if(html!=""){tempDiv.innerHTML=html};
	}
}
function DrawDrivingMap()
{
    //alert('DrawDrivingMap');
	// init the map
	if(map==null)
	{
		InitMap();
	}
	// clear all the pushpins away
	map.Clear();
	// create all the new LatLong for getting the right sized map
	var llArray = new Array();
	if(drivingDirectionSegments!=null)
	{
		for(var i=0;i<drivingDirectionSegments.length;i++)
		{
			// add this cordinate to the list to get the best view
			var l1 = new VELatLong(drivingDirectionSegments[i].Latitude,drivingDirectionSegments[i].Longitude);
			llArray.push(l1);
		}
		// add in the final spot
		var l1 = new VELatLong(returnedStores[currentSelectedStore].Latitude,returnedStores[currentSelectedStore].Longitude);
		llArray.push(l1);
		// figure out the best view for everything
		map.SetMapView(llArray);
		// add in the pushpins
		for(var i=0;i<drivingDirectionSegments.length;i++)
		{
	    var LA1 = new VELatLong(drivingDirectionSegments[i].Latitude, drivingDirectionSegments[i].Longitude);

        var pin = new VEShape(VEShapeType.Pushpin, LA1);
        
        pin.SetCustomIcon(GetPinDivDrivingDirectionsHtml(i));
        map.AddShape(pin);      
			//map.AddPushpin("driving" + i,	drivingDirectionSegments[i].Latitude, drivingDirectionSegments[i].Longitude, 15, 15, "pinunhighlight", GetPinDivDrivingDirectionsHtml(i),2);
		}
		var LA1 = new VELatLong(returnedStores[currentSelectedStore].Latitude, returnedStores[currentSelectedStore].Longitude);

        var pin = new VEShape(VEShapeType.Pushpin, LA1);
        
        pin.SetCustomIcon(GetPinDivDrivingDirectionsHtml(drivingDirectionSegments.length));
        map.AddShape(pin);
		//map.AddPushpin("driving" + drivingDirectionSegments.length, returnedStores[currentSelectedStore].Latitude, returnedStores[currentSelectedStore].Longitude, 15, 15, "pinunhighlight", GetPinDivDrivingDirectionsHtml(drivingDirectionSegments.length),2);
	}
}
function DrawStoresMap()
{
//alert('DrawStoresMap');
	// make sure map is the correct size
	UnExpandMap();
	
	var llArray = new Array();
	// init the map
	if(map==null)
	{
		InitMap();
	}
	currentlyShowingMap="Stores";
	// add this cordinate to the list to get the best view
	for(var i=0;i<returnedStores.length;i++)
	{
		var l1 = new VELatLong(returnedStores[i].Latitude,returnedStores[i].Longitude);
		llArray.push(l1);
	}
	// add in the cordinate we were looking for to make sure it is in the view
	var l1 = new VELatLong(returnedStartAddressInfos[startAddressIndexUsed].Latitude,returnedStartAddressInfos[startAddressIndexUsed].Longitude);
	llArray.push(l1);
	
//	// figure out the best view for everything
	map.SetMapView(llArray);
	// clear out all pins that might be on the map already
	map.Clear();
	// add in the pushpins
	for(var i=0;i<returnedStores.length;i++)
	{
	    var LA = new VELatLong(returnedStores[i].Latitude, returnedStores[i].Longitude);

        var pin = new VEShape(VEShapeType.Pushpin, LA);
        
        pin.SetCustomIcon(GetStorePinDivHtml(i));
        map.AddShape(pin);      
	    
		
	}
}
function ShowDetailedView()
{
	currentlyShowingMap="BirdsEye";
	currentViewBeforeBirsEye=currentView;
	scene=eval(returnedStores[currentSelectedStore].BirdsEye);
	map.SetObliqueScene(scene.GetID());
	var intTimeOut=self.setTimeout("ShowDetailedViewStep2()", .5*1000);
}

function ShowDetailedViewStep2()
{	
	// get rid of the popup
	RemoveDrivingDirectionsPopup()	
	// expand the map out
	ExpandMap();
	// hide the dashboard
	UpdateDiv("mapnavdashboard","none",0,"");
	// clear the pins
	map.Clear();
	// add the pushpin back in
	var LA = new VELatLong(returnedStores[currentSelectedStore].Latitude, returnedStores[currentSelectedStore].Longitude);

    var pin = new VEShape(VEShapeType.Pushpin, LA);

    //pin.SetCustomIcon(GetStorePinDivHtml(i));
    map.AddShape(pin); 
	//map.AddPushpin("store",	returnedStores[currentSelectedStore].Latitude, returnedStores[currentSelectedStore].Longitude, 15, 15, "pindetail", "MG",2);
	// make the correct things visbile
	UpdateDiv("expandMap","none",0,"");	
	UpdateDiv("unExpandMap","none",0,"");	
	UpdateDiv("zoomBird","inline",0,"");	
	UpdateDiv("birdView","inline",0,"");	
	UpdateDiv("backToStore","inline",0,"");	
	UpdateDiv("storesListDiv","none",0,"");	
	// reset the dropdown
	var temp=document.getElementById("BirdViewSelect");
	temp.value="North";	
	// add to the url for history
	dhtmlHistory.add("detailview", GetSessionInfo());
}
function ZoomBird()
{
	map.ZoomIn();
}
function UnZoomBird()
{
	map.ZoomOut();
}
function ChangeBirdView()
{
	var temp=document.getElementById("BirdViewSelect");
	map.SetObliqueOrientation(temp.value);
}
function ChangeFromBirdsEyeToStoreList()
{
	currentlyShowingMap="Stores";
	// resize the map back to size
	UnExpandMap();
	// make all the divs go away
	UpdateDiv("zoomBird","none",0,"");	
	UpdateDiv("unZoomBird","none",0,"");	
	UpdateDiv("birdView","none",0,"");	
	UpdateDiv("backToStore","none",0,"");
	UpdateDiv("storesListDiv","block",0,"");
	UpdateDiv("mapnavdashboard","block",0,"");		
	// remove the pins
	map.Clear();
	// bring back the list of stores
	map.SetMapStyle(currentViewBeforeBirsEye);
	var intTimeOut=self.setTimeout("DrawStoresMap()", .5*1000);
	// add in the bookmark
	dhtmlHistory.add("listofstores", GetSessionInfo());
}
function highlightstore(div)
{
	highlight('store',div);
}
function unhighlightstore(div)
{
	unhighlight('store',div);
}
function highlightdriving(div)
{
	highlight('driving',div);
}
function unhighlightdriving(div)
{
	unhighlight('driving',div);
}
function highlight(part,div)
{
	var temp=document.getElementById(part + div);
	if(temp!=null)
	{
		temp.className='pinhighlight';
	}
	
	temp=document.getElementById(part + "row" + div);
	if(temp!=null)
	{
		temp.className='pinhighlight';
	}
}
function unhighlight(part,div)
{
	var temp=document.getElementById(part + div);
	if(temp!=null)
	{
		temp.className='pinunhighlight';
	}

	temp=document.getElementById(part + "row" + div);
	if(temp!=null)
	{
		temp.className='pinunhighlight';
	}
}
function GetStoreListHtml()
{	
	var divHtml="";	
	if(returnedStores!=null)
	{
		divHtml=CreateReturnedStoresListHtml();		
		// check and see if we need to add in the other store info
		if(returnedStores[0].MilesToPoint>20)
		{
			////Commented by Nitin Gupta - Starts
			////divHtml+=CreateOtherStoresFoundHtml(otherStoreCount);
			////Commented by Nitin Gupta - Ends
		}
	}
	else
	{
		// show the no store message
		divHtml=CreateNoStoresFoundHtml();
		// add in the number of other locations
		////Commented by Nitin Gupta - Starts
		////divHtml+=CreateOtherStoresFoundHtml(otherStoreCount);
		////Commented by Nitin Gupta - Ends
	}
	return divHtml;
}

function CreateSearchingHtml(html)
{
	var returnHtml="<p id='text'>" + html + "</p>";
	////Commented by Nitin gupta - Starts 
	////returnHtml+="<p id='img'><img src='" + staticPath + "/hv_content/images/storelocator/test_timer2.gif' height='28' width='39' /></p>";
	////Commented by Nitin gupta - Ends
	////Added by Nitin gupta - Starts
	returnHtml+="<p id='img'><img src='" + staticPath + "/content/img/locator/test_timer2.gif' height='28' width='39' /></p>";
	////Added by Nitin gupta - Ends
	return returnHtml;
}
function CreateErrorParsingStartingAddressHtml()
{
	var divHtml="<p>Error parsing the address entered.<br />";
	divHtml+=changeLocationHTML+"</p>";
	return divHtml;
}
function GetStoreListingTableRow(i)
{
	////Commented by Nitin Gupta - Starts
	/*
	var firstrow = (i == 0) ? " first" : "";
	var tempString="<tr onmouseover='highlightstore(" + i + ")' onmouseout='unhighlightstore(" + i + ")'>";
	tempString+="<td rowspan=2 valign='top' class='left"+firstrow+"' style='text-align:center'><a href='' onclick='centermapstores(" + i + ",0); return false;'><div class='pinunhighlight' id='storerow" + i + "'>" + (i+1) + "</div></a></td>";
	tempString+="<td colspan=2 class='top"+firstrow+"'><a href='' onclick='centermapstores(" + i + ",0); return false;'>" + returnedStores[i].StoreName + "</a> <span class='storeDistance'>(" + returnedStores[i].MilesToPoint + " miles)</span></td>";
	tempString+="</tr><tr onmouseover='highlightstore(" + i + ")' onmouseout='unhighlightstore(" + i + ")'>";
	//tempString+="<td>" + returnedStores[i].Address + "<br>" + returnedStores[i].City + ", " + returnedStores[i].State + " " + returnedStores[i].ZipCode + " </td>";

	if (returnedStores[i].IsHDAvailable=="True")
	{
		tempString+="<td>" + returnedStores[i].Address + "<br>" + returnedStores[i].City + ", " + returnedStores[i].State + " " + returnedStores[i].ZipCode;
		tempString+= "<br/><br/><img src='" + staticPath + "/hv_content/images/storelocator/bluray.gif' alt='Blu-ray DVDs are available at this store' title='Blu-ray DVDs are available at this store'/></td>";
	}
	else
		tempString+="<td>" + returnedStores[i].Address + "<br>" + returnedStores[i].City + ", " + returnedStores[i].State + " " + returnedStores[i].ZipCode + " </td>";
	
	tempString+="<td>" + returnedStores[i].Phone + "<br><a href='' onclick='centermapstores(" + i + ",1); return false;'>Driving Directions</a></td>";
	tempString+="</tr>";
	*/

	////Commented by Nitin Gupta - Starts

	////Added by nitin Gupta - Starts

		var tempString="<tr onmouseover='highlightstore(" + i + ")' onmouseout='unhighlightstore(" + i + ")'>";
	tempString+="<td class='rank' style='text-align:center'><a href='' onclick='centermapstores(" + i + ",0); return false;'><div class='pinunhighlight' id='storerow" + i + "'>" + (i+1) + "</div></a></td>";
	tempString+="<td class='distance'>" + returnedStores[i].MilesToPoint + " miles</td>";
	tempString+="<td class='store'>" + returnedStores[i].StoreName + " - " + returnedStores[i].Address + ", " + returnedStores[i].City + ", " + returnedStores[i].State + " " + returnedStores[i].ZipCode + "</td>";
	tempString+="<td class='phone'>" + returnedStores[i].Phone + "</td>";
	tempString+="<td class='directions'><a href='' onclick='centermapstores(" + i + ",1); return false;'>Driving Directions</a></td>";
	tempString+="</tr>";
	////Added by nitin Gupta - Starts

	return tempString;
}
function GetStorePinDivHtml(i)
{
	var divText="";
	divText+="<div ";
	divText+="id='storepindiv" + (i) + "' ";
	divText+="class='pinunhighlight' ";
	divText+="onmouseover='highlightstore(" + (i) + ");' ";
	divText+="onmouseout='unhighlightstore(" + (i) + ");' ";
	divText+="onclick='centermapstores(" + (i) + ",0);'";
	divText+=">";
	divText+=(i+1);
	divText+="</div>";
	return divText;
}
function GetPinDivDrivingDirectionsHtml(i)
{
	var divText="";
	divText+="<div ";
	divText+="id='drivingpindiv" + (i) + "' ";
	divText+="class='pinunhighlight' ";
	divText+="onmouseover='highlightdriving(" + (i) + ");' ";
	divText+="onmouseout='unhighlightdriving(" + (i) + ");' ";
	divText+="onclick='centermapdriving(" + (i) + ",this,event);'";
	divText+=">";
	divText+=i;
	divText+="</div>";
	return divText;
}
function GetStoreText()
{
	var panelText="";
	panelText+="<p>" + returnedStores[currentSelectedStore].StoreName + "<br>";
	panelText+=returnedStores[currentSelectedStore].Address + "<br>";
	panelText+=returnedStores[currentSelectedStore].City + ", " + returnedStores[currentSelectedStore].State + " " + returnedStores[currentSelectedStore].ZipCode + "<br>";
	panelText+=returnedStores[currentSelectedStore].Phone + "<br>";
	if(returnedStores[currentSelectedStore].Hours!="")
	{
		panelText+="<br><b>Hours of Operation:</b><br>";
		var hours=returnedStores[currentSelectedStore].Hours
		/*
		hours=hours.replace('Monday','Mo');
		hours=hours.replace('Thursday','Th');
		hours=hours.replace('Friday','Fr');
		hours=hours.replace('Saturday','Sa');
		hours=hours.replace('Sunday','Su');
		
		hours=hours.replace('Monday','Mon');
		hours=hours.replace('Thursday','Thu');
		hours=hours.replace('Friday','Fri');
		hours=hours.replace('Saturday','Sat');
		hours=hours.replace('Sunday','Sun');
		*/
		////Commented by Nitin Gupta - Starts
		////panelText+=hours + "<br>";
		////Commented by Nitin Gupta - Ends
		////Added by Nitin Gupta - Starts	
		panelText+=hours + "<br>";
		////Added by Nitin Gupta - Ends
	}
	panelText+="<a href='' onclick='ChangeToDrivingDirections(); return false;'>Get Driving Directions</a></p>";
	if(showDetailView)
	{
		if(returnedStores[currentSelectedStore].BirdsEye!="")
		{
			//panelText+="<a href='' onclick='ShowDetailedView(); return false;'>Show Detailed View</a></p>";
		}
	}
	return panelText;
}
function CreateBlankDrivingDirectionHtml()
{	
	// get the value of the textbox
	var singleLine=document.getElementById("Locatordefault1_txtSingleLine");
	var htmlText="<p><strong>Driving directions to:</strong><br />"+returnedStores[currentSelectedStore].Address + "<br />" + returnedStores[currentSelectedStore].City + ", " + returnedStores[currentSelectedStore].State + " " + returnedStores[currentSelectedStore].ZipCode+"</strong></p>";
	htmlText+="<p><strong>Starting From:</strong><br /><textarea id='enddrivingdirections' cols=16 rows=2>" + singleLine.value + " </textarea><br />";
	htmlText+="<a href='' onclick='StartDrivingDirections(); return false'>Get Directions</a></p><p><a href='' onclick='ChangeFromDrivingDirections(); return false;'>Back to Info</a></p>";
	return htmlText;
}
function CreateNoStartingAddressesReturnedHtml()
{
	////Commented by Nitin Gupta - Starts
	////var divHtml="<h3>No addresses returned.</h3>";
	////Commented by Nitin Gupta - Ends
	////Added by Nitin Gupta - Starts
	var divHtml="<h3>No matching addresses was found.</h3>";
	////Added by Nitin Gupta - Ends
	divHtml+="<p>"+changeLocationHTML+"</p>";
	return divHtml;
}
function CreateMoreThenOneStartAddressReturnedHtml()
{
	var divHtml="<p><strong>We couldn't find and exact match.<br />Please choose the closest match below.</strong><br /><span class='changelocation'>Or </span>";
	divHtml+=changeLocationHTML+"</p><br />";
	for(var i=0;i<returnedStartAddressInfos.length;i++)
	{
		divHtml+='<p><a href="" onclick="FindStores('
		divHtml+=i;
		divHtml+='); return false;")>';
		divHtml+=returnedStartAddressInfos[i].FormattedAddress;
		divHtml+='</a></p>';
	}
	return divHtml;
}
function CreateReturnedStoresListHtml()
{
//alert('CreateReturnedStoresListHtml');
	var divHtml="";
	if(returnedStores.length==1)
	{
		divHtml+="<p>There is ";
	}
	else
	{
		divHtml+="<p>There are ";
	}
	divHtml+="<strong>" + returnedStores.length + " GameCrazy Store"+((i==1)?"":"s")+"</strong> near:<br />";
	divHtml+="<strong>" + returnedStartAddressInfos[startAddressIndexUsed].FormattedAddress + "</strong><br />";
	divHtml+=changeLocationHTML+"</p><br />";

	divHtml+="<table cellspacing='0' cellpadding='0' rules='all' width='99%'>";
	//divHtml+="<tr class='CellHeader'>";
	//divHtml+="<td><font size=-2>&nbsp;</font></td>";
	//divHtml+="<td><font size=-2>Miles</font></td>";
	//divHtml+="<td><font size=-2>Info</font></td>";
	//divHtml+="</tr>";
	for(var i=0;i<returnedStores.length;i++)
	{
		// add the html for this row
		divHtml+=GetStoreListingTableRow(i);
	}
	divHtml+="</table>";
	return divHtml;
}
function CreateNoStoresFoundHtml()
{
	var divHtml="There were no GameCrazy stores within 70 miles of your location.<br>";
	divHtml+=changeLocationHTML+ "<br><br>";
	return divHtml;
}
function CreateOtherStoresFoundHtml(i)
{
	var tempHtml="<p class='changelocation'>We found <strong>" + i + " Movie Gallery</strong> store"+((i==1)?"":"s")+" close to your location. <strong>Hollywood Video</strong> is owned by <strong>Movie Gallery</strong>.<br />"
	tempHtml+="<a href='/offsite.aspx?url=http://www.moviegallery.com/storelocator/default.aspx' target='_blank'>View the MovieGallery stores near you.</a></p>";
	return tempHtml;
}
function CreateNoDrivingAddressesReturnedHtml()
{
	////Commented by Nitin Gupta - Starts
	////return divHtml="<p>No addresses match was returned for the driving direction address you entered.</p>";
	////Commented by Nitin Gupta - Ends
	////Added by Nitin Gupta - Starts
	return divHtml="<h3>Driving Directions</h3><p>No addresses match was returned for the driving direction address you 		entered.  Please change your address, and try again.</p>";
	////Added by Nitin Gupta - Ends
	//divHtml+=changeLocationHTML;
}
function CreateErrorParsingDrivingAddressHtml()
{
	var divHtml="Error parsing the driving address entered.<br>";
	//divHtml+=changeLocationHTML;
	return divHtml;
}
function CreateMoreThenOneDrivingAddressReturnedHtml()
{
	////Commented by Nitin Gupta - Starts
	////divHtml="<p>Your driving address returned more then one matching address, please select the best match:</p>";
	////Commented by Nitin Gupta - Ends
	////Added by Nitin Gupta - Starts
	divHtml="<h3>Driving Directions</h3><p>Your driving address returned more then one matching address, please select the best match:</p>";
	////Added by Nitin Gupta - Ends
	for(var i=0;i<returnedDrivingAddressInfos.length;i++)
	{
		divHtml+='<a href="" onclick="GetDrivingDirections(';
		divHtml+=i;
		divHtml+='); return false;")>';
		divHtml+=returnedDrivingAddressInfos[i].FormattedAddress;
		divHtml+='</a>';
	}
	return divHtml;
}
function CreateDrivingDirectionsSearchHtml()
{
	////Commented by Nitin Gupta - Starts	
	////var html="Calculating directions from<br>";
	////Commented by Nitin Gupta - Ends
	////Added by Nitin Gupta - Starts
	var html="<h3>Driving Directions</h3>Calculating directions from<br>";
	////Added by Nitin Gupta - Ends
	html+=returnedDrivingAddressInfos[drivingDirectionsAddressIndexUsed].FormattedAddress + "<br>";
	html+="to<br>";
	////Commented by Nitin Gupta - Starts	
	////html+=returnedStores[currentSelectedStore].Address + ", " + returnedStores[currentSelectedStore].City + ", " + 	returnedStores[currentSelectedStore].State + " " + returnedStores[currentSelectedStore].ZipCode + "<br>";
	////Commented by Nitin Gupta - Ends
	////Added by Nitin Gupta - Starts
	html+=returnedStores[currentSelectedStore].Address + ", " + returnedStores[currentSelectedStore].City + ", " + 		returnedStores[currentSelectedStore].State + " " + returnedStores[currentSelectedStore].ZipCode + "</br>";
	////Added by Nitin Gupta - Ends
	return CreateSearchingHtml(html);
}
function CreateFindingDrivingAddressSearchHtml()
{
	// get the address
	var singleLine=document.getElementById("enddrivingdirections");
	////Commented by Nitin Gupta - Starts	
	////var html="Finding Address For:<br>" + singleLine.value;
	////Commented by Nitin Gupta - Ends	
	////Added by Nitin Gupta - Starts
	var html="<h3>Driving Directions</h3></br>Looking for a matching address for:<br>" + singleLine.value;
	////Added by Nitin Gupta - Ends
	return CreateSearchingHtml(html);
}
function CreateSearchingStoresSearchHtml()
{
	var singleLine=document.getElementById("Locatordefault1_txtSingleLine");
	////Commented by Nitin Gupta - Starts	
	////var html="Searching For Stores near: " + singleLine.value;
	////Commented by Nitin Gupta - Ends	
	////Added by Nitin Gupta - Starts
	var html="<h3>Finding Stores</h3><br>Searching For Stores near: " + singleLine.value;
	////Added by Nitin Gupta - Ends	
	return CreateSearchingHtml(html);
}
function CreateStartingAddressSearchHtml()
{
	var html;
	var singleLine=document.getElementById("Locatordefault1_txtSingleLine");
	//var zipCode=document.getElementById("Locatordefault1_zip");
	//var address=document.getElementById("Locatordefault1_addr");
	//var city=document.getElementById("Locatordefault1_place");
	//var state=document.getElementById("Locatordefault1_uStates");
	if(singleLine.value!='')
	{
		////Commented by Nitin Gupta - Starts	
		html="Searching For Address: " + singleLine.value;
		////Commented by Nitin Gupta - Ends	
		////Added by Nitin Gupta - Starts	
		html="<h3>Finding Stores</h3><br>Searching For Address: " + singleLine.value;
		////Added by Nitin Gupta - Ends	
	}
	/*
	else if(zipCode.value!='')
	{
		html="Searching For: " + zipCode.value;
	}
	else
	{
		html="Searching For: " + address.value + "," + city.value + "," + state.value;
	}
	*/
	return CreateSearchingHtml(html);
}
function CreateDrivingDirectionsHtml()
{
	var html="<h3 style='padding-bottom:0; margin-bottom:0; line-height:1.2;'>Driving Directions:</h3>";
	html+="<span class='changelocation'><a href='' onclick='SwtichFromDrivingDirectionsToStores(); return false;'>Back to store</a></span><br /><br />";
	html+="<p><strong>Start: </strong>" + returnedDrivingAddressInfos[drivingDirectionsAddressIndexUsed].FormattedAddress + "<br />";
	html+="<strong>End: </strong>" + returnedStores[currentSelectedStore].Address + ", " + returnedStores[currentSelectedStore].City + ", " + returnedStores[currentSelectedStore].State + "<br />"; //  " + returnedStores[currentSelectedStore].ZipCode + "
	html+="<strong>Total Distance: </strong>" + drivingDirectionsMiles.toFixed(2) + " miles<br />";
	var minutes=drivingDirectionsTime/60;
	html+="<strong>Estimated Total Time: </strong>" + minutes.toFixed(0) + " minutes</p>";
	html+="<br />";
	html+="<table cellspacing='0' cellpadding='0' rules='all' width='99%'><tr><td>&nbsp;</td><td><strong>Directions</strong></td><td><strong>Miles</strong></td></tr>";	
	for(var i=0;i<drivingDirectionSegments.length;i++)
	{
		html+="<tr onmouseover='highlightdriving(" + i + ")' onmouseout='unhighlightdriving(" + i + ")'>";
		html+="<td valign='top' class='left'><a href='' onclick='centermapdriving(" + i + "); return false;'><div class='pinunhighlight' id='drivingrow" + i + "'>" + (i) + "</div></a></td>";
		html+="<td>" + drivingDirectionSegments[i].Instruction + "</font></td><td>" + drivingDirectionSegments[i].Distance.toFixed(1) + "</td></tr>";
	}
	html+="<tr onmouseover='highlightdriving(" + (drivingDirectionSegments.length) + ")' onmouseout='unhighlightdriving(" + (drivingDirectionSegments.length) + ")'>";
	//html+="<td>" + i + "</td><td>" + drivingDirectionSegments[i].Instruction + "</font></td><td>" + drivingDirectionSegments[i].Distance.toFixed(1) + "</td></tr>";
	html+="<td valign='top' class='left'><a href='' onclick='centermapdriving(" + (drivingDirectionSegments.length) + "); return false;'><div class='pinunhighlight' id='drivingrow" + (drivingDirectionSegments.length) + "'>" + (drivingDirectionSegments.length) + "</div></a></td>";
	html+="<td colspan=2>";
	html+="Arrive at " + returnedStores[currentSelectedStore].StoreName + "<br>";
	html+=returnedStores[currentSelectedStore].Address + "<br>" + returnedStores[currentSelectedStore].City + ", " + returnedStores[currentSelectedStore].State + " " + returnedStores[currentSelectedStore].ZipCode + "<br>" + returnedStores[currentSelectedStore].Phone;
	html+="</td>";
	html+="</table>";
	return html;
}
       
         function onGotRoute(route)
         {
           // Unroll route
           var legs     = route.RouteLegs;
           var turns    = "Total distance: " + route.Distance.toFixed(1) + " mi\n";
           var numTurns = 0;
           var leg      = null;

           // Get intermediate legs
            for(var i = 0; i < legs.length; i++)
            {
               // Get this leg so we don't have to derefernce multiple times
               leg = legs[i];  // Leg is a VERouteLeg object
                  
               // Unroll each intermediate leg
               var turn = null;  // The itinerary leg
                  
               for(var j = 0; j < leg.Itinerary.Items.length; j ++)
               {
                  turn = leg.Itinerary.Items[j];  // turn is a VERouteItineraryItem object
                  numTurns++;
                  turns += numTurns + ".\t" + turn.Text + " (" + turn.Distance.toFixed(1) + " mi)\n";
               }
            }
            alert(turns);
            
         }
      
         
    

	            