 // two company objects   
 // for NOW the map name must ALWAYS be "map" on the page
 // Third argument is where the results should be put on the page (div)
 // Fourth argument is the ID to set display on the driving directions

	
function createMapRoute( from, to, routeResultsDiv, directions ) {

	if(typeof myMap != 'undefined'){	
			myMap.removeAllPois(); 
		}
		else{	
						myMap = new MQTileMap(document.getElementById('map'));
    // Create a new Large Zoom control attached to the map
    myLZControl = new MQLargeZoomControl(myMap);

		//tell the map to display the control we just attached
	    myMap.addControl(myLZControl);
	
		//Create a map view type control
		myVControl = new MQViewControl(myMap);
		
		/*
		Display control - use the Corner placement constant to specify which corner, plus an MQSize object to specify X and Y "indent" offset
		*/
		myMap.addControl(myVControl, new MQMapCornerPlacement(MQMapCorner.TOP_LEFT, new MQSize(0,0)));
		myMap.removeAllPois();
	}
	

	var gaCollection = new MQLocationCollection("MQGeoAddress");
    //populate the address object with the information from the form
	var address = new MQAddress();
	address.setStreet( from.address );
	address.setCity( from.city );
	address.setState( from.state );
	address.setPostalCode( from.zip );
	geoExec.geocode(address, gaCollection);

	var geoAddr1 = gaCollection.get(0);

	//Set the START image
	point = new MQPoi(geoAddr1.getMQLatLng());
	var myIcon = new MQMapIcon();
	myIcon.setImage("/img/map/map_directions_start.gif",37,11,true,false);
    myMap.addPoi(point);
	point.setIcon(myIcon);        
	address.setStreet( to.address );
	address.setCity( to.city );
	address.setState( to.state );
	address.setPostalCode( to.zip );

	geoExec.geocode(address, gaCollection);
	
	var geoAddr2 = gaCollection.get(0);

	//Set the END image
	point = new MQPoi(geoAddr2.getMQLatLng());
	var myIcon = new MQMapIcon();
	myIcon.setImage("/img/map/map_directions_end.gif",37,11,true,false);
    myMap.addPoi(point);
	point.setIcon(myIcon);        

	var session = new MQSession(); 
    var routeRes = new MQRouteResults();
    var wayPoints = new MQLocationCollection();
    var myBB = new MQRectLL(new MQLatLng(),new MQLatLng());
    wayPoints.add(geoAddr1);
    wayPoints.add(geoAddr2);
    var routeOpt = new MQRouteOptions();

    //create sessionID from the route server
    var sessId = routeExec.createSessionEx(session);

    routeExec.doRoute(wayPoints,routeOpt,routeRes,sessId,myBB);

    myMap.addRouteHighlight(myBB,"http://map.access.mapquest.com",sessId,true);

	var totalTime='';
	
	var myMinutes = routeRes.getTime()/60;
	if (myMinutes > 60) {
		if (myMinutes/60 == 1) {
			totalTime = "1 hr ";
		}
		else {
			totalTime = Math.round((myMinutes/60)*100)/100 + " hrs";
		}
	}
	else {
		totalTime = myMinutes + " min";
	}
	
	var totalDistance = Math.round(routeRes.getDistance()*100)/100 + " miles"; 
	var myTrkStr='';

	var directionsTable = "<table cellpadding=\"4\" cellspacing=\"0\" border=\"0\" width=\"100%\"><tr><td width=\"1%\" valign=\"top\"><b>Start: </b></td><td  valign=\"top\">" + 
        from.address + "<br>" + from.city + ", " + from.state + " " + from.zip + "</td>" +
  						"<td  width=\"1%\" valign=\"top\"><b>End: </b></td><td valign=\"top\">" + 
        to.address + "<br>" + to.city + ", " + to.state + " " + to.zip + 
        				"</td></tr>" +
  						"<tr><td colspan=\"2\" width=\"50%\" ><b>Estimated time: </b>" + totalTime + "</td>" +
  						"<td colspan=\"2\" width=\"50%\"><b>Estimated distance: </b>" + totalDistance + "</td></tr></table>" +
  						"<table cellpadding=\"2\" cellspacing=\"0\" border=\"0\" width=\"100%\">" +
  						"<td colspan=\"3\" ><img src=\"/img/map/map_directions_start.gif\" border=\"0\"></td>";
	var shade = " bkground";
	var colorTD = true;
	var revDirections = "Reverse Route";	
	
	// we want to loop through all the maneuvers in the maneuvercollection for our trekroute
	//we only have one trekroute (only 2 addresses), so we can go straight to the maneuvercollection
	// we loop thru the maneuvercollection - remember it is a zero-based array, so there is one less than the count
	for (counter = 0; counter < routeRes.getTrekRoutes().get(0).getManeuvers().getSize(); counter ++){
		var stepNo = counter + 1;
		var milage = Math.round(routeRes.getTrekRoutes().get(0).getManeuvers().get(counter).getDistance()*100)/100 + " mi";
		var dir = routeRes.getTrekRoutes().get(0).getManeuvers().get(counter).getNarrative();
		if (colorTD == true) {
  			shade = " bgcolor=\"#DDE4D6\" " ;
  			colorTD = false;
		} else {
			shade = "";
			colorTD = true;
		}
		//see if this is the end
  		if(counter == routeRes.getTrekRoutes().get(0).getManeuvers().getSize()-1)
  			directionsTable += "<tr><td valign=\"top\"" + shade + "><b>" + (stepNo) + ".</b></td><td valign=\"top\"" + shade + ">" + dir + "</td><td align=\"center\" valign=\"top\"" + shade + " nowrap>" + milage + "</td></tr>";
 		else {
			directionsTable += "<tr><td valign=\"top\"" + shade + "><b>" + stepNo + ".</b></td><td valign=\"top\"" + shade + ">" + dir + "</td><td align=\"center\" valign=\"top\"" + shade + " nowrap>" + milage + "</td></tr>";
		}
	}
	
	directionsTable += "<td colspan=\"3\" ><img src=\"/img/map/map_directions_end.gif\" border=\"0\"></td></tr>";
	directionsTable += "<tr><td colspan=\"3\"><a href=\"javascript:void(0);\" onclick = \"showReverse('" + to.address + "','" + to.city + "','" + to.state + "','" + to.zip + "','" + from.address + "','" + from.city + "','" + from.state  + "','" + from.zip + "');\">"	+ revDirections + "</a></td></tr>";
	directionsTable += "</table><div id='addressA' style='display:none'>" + from.address + " " + from.city + ", " + from.state + " " + from.zip + "</div><div id='addressB' style='display:none'>" + to.address + " " + to.city + ", " + to.state + " " + to.zip + "</div>";	

	
	document.getElementById( directions).innerHTML = directionsTable;
	document.getElementById( routeResultsDiv ).style.display = 'block';
	
	return false;
}

function showReverse(toAddr, toCity, toState, toZip, fromAddr, fromCity, fromState, fromZip){
	var toAddr=new Company( '',toAddr,toCity,toState,toZip, '', '', '', '', '', '' );
 var fromAddr=new Company( '',fromAddr,fromCity,fromState,fromZip, '', '', '', '', '', '' );
	
	return createMapRoute(toAddr, fromAddr, 'routeResults', 'directions');

}

//I apologize -- I'm duplicating this almost entirely for now to style the mapBusinessFinder stuff differently
//will go back and extract out the styling later
function getMapRoute( from, to, routeResultsDiv, directions ) {

	if(typeof myMap != 'undefined'){	
			myMap.removeAllPois(); 
		}
		else{	
						myMap = new MQTileMap(document.getElementById('map'));
    // Create a new Large Zoom control attached to the map
    myLZControl = new MQLargeZoomControl(myMap);

		//tell the map to display the control we just attached
	    myMap.addControl(myLZControl);
	
		//Create a map view type control
		myVControl = new MQViewControl(myMap);
		
		/*
		Display control - use the Corner placement constant to specify which corner, plus an MQSize object to specify X and Y "indent" offset
		*/
		myMap.addControl(myVControl, new MQMapCornerPlacement(MQMapCorner.TOP_LEFT, new MQSize(0,0)));
		myMap.removeAllPois();
	}

	var gaCollection = new MQLocationCollection("MQGeoAddress");
    //populate the address object with the information from the form
	var address = new MQAddress();
	address.setStreet( from.address );
	address.setCity( from.city );
	address.setState( from.state );
	address.setPostalCode( from.zip );
	geoExec.geocode(address, gaCollection);
	
	var fromAddress = from.address + ' ' + from.city + ', ' + from.state + ' ' + from.zip;
	var toAddress = to.address + ' ' + to.city + ', ' + to.state + ' ' + to.zip;

	var geoAddr1 = gaCollection.get(0);

	//Set the START image
	point = new MQPoi(geoAddr1.getMQLatLng());
	var myIcon = new MQMapIcon();
		myIcon.setImage("/img/map_icona.gif",22,22,true,false);
    myMap.addPoi(point);
	point.setIcon(myIcon);        
	address.setStreet( to.address );
	address.setCity( to.city );
	address.setState( to.state );
	address.setPostalCode( to.zip );

	geoExec.geocode(address, gaCollection);
	
	var geoAddr2 = gaCollection.get(0);

	//Set the END image
	point = new MQPoi(geoAddr2.getMQLatLng());
	var myIcon = new MQMapIcon();
	myIcon.setImage("/img/map_iconb.gif",22,22,true,false);
    myMap.addPoi(point);
	point.setIcon(myIcon);        

	var session = new MQSession(); 
    var routeRes = new MQRouteResults();
    var wayPoints = new MQLocationCollection();
    var myBB = new MQRectLL(new MQLatLng(),new MQLatLng());
    wayPoints.add(geoAddr1);
    wayPoints.add(geoAddr2);
    var routeOpt = new MQRouteOptions();

    //create sessionID from the route server
    var sessId = routeExec.createSessionEx(session);

    routeExec.doRoute(wayPoints,routeOpt,routeRes,sessId,myBB);

    myMap.addRouteHighlight(myBB,"http://map.access.mapquest.com",sessId,true);

	var totalTime='';
	
	var myMinutes = routeRes.getTime()/60;
	if (myMinutes > 60) {
		if (myMinutes/60 == 1) {
			totalTime = "1 hr ";
		}
		else {
			totalTime = Math.round((myMinutes/60)*100)/100 + " hrs";
		}
	}
	else {
		totalTime = myMinutes + " min";
	}
	
	var totalDistance = Math.round(routeRes.getDistance()*100)/100 + " miles"; 
	var myTrkStr='';

	var directionsTable = "<table cellpadding=\"2\" cellspacing=\"0\" border=\"0\" width=\"99%\">";
	var shade = " bkground";
	var colorTD = true;
	var revDirections = "Reverse Route";	
	
	//header for directions -- estimated time and distance
	directionsTable += "<tr><td height=\"10\"></td></tr>";
	directionsTable += "<tr><td valign=\"top\" colspan=\"2\"><b>Estimated time: </b> " + totalTime + "<br /><b>Estimated distance:</b> " + totalDistance + "</td></tr>";
	directionsTable += "<tr><td height=\"10\"></td></tr>";
	// we want to loop through all the maneuvers in the maneuvercollection for our trekroute
	//we only have one trekroute (only 2 addresses), so we can go straight to the maneuvercollection
	// we loop thru the maneuvercollection - remember it is a zero-based array, so there is one less than the count
	for (counter = 0; counter < routeRes.getTrekRoutes().get(0).getManeuvers().getSize(); counter ++){
		var stepNo = counter + 1;
		var milage = Math.round(routeRes.getTrekRoutes().get(0).getManeuvers().get(counter).getDistance()*100)/100 + " mi";
		var dir = routeRes.getTrekRoutes().get(0).getManeuvers().get(counter).getNarrative();
		if (colorTD == true) {
  			shade = " bgcolor=\"#f0f0f0\" " ;
  			colorTD = false;
		} else {
			shade = "";
			colorTD = true;
		}
		//see if this is the end
  		if(counter == routeRes.getTrekRoutes().get(0).getManeuvers().getSize()-1)
  			directionsTable += "<tr><td style=\"border-top:1px solid #CCCCCC\"" + shade + " valign=\"top\"><b>" + (stepNo) + ".</b></td><td style=\"border-top:1px solid #CCCCCC\" valign=\"top\"" + shade + ">" + dir + "</td><td style=\"border-top:1px solid #CCCCCC\" align=\"center\"" + shade + "valign=\"top\" nowrap>" + milage + "</td></tr>";
 		else {
			directionsTable += "<tr><td style=\"border-top:1px solid #CCCCCC\"" + shade + " valign=\"top\"><b>" + stepNo + ".</b></td><td style=\"border-top:1px solid #CCCCCC\" valign=\"top\"" + shade + ">" + dir + "</td><td style=\"border-top:1px solid #CCCCCC\" align=\"center\"" + shade + "valign=\"top\" nowrap>" + milage + "</td></tr>";
		}
	}
	
	directionsTable += "<tr><td style=\"border-top:1px solid #CCCCCC\" colspan=\"3\"><br /></td></tr></table>";	
		
		
	var printURL = "/mapBusinessFinder.do?action=print&addressA=" + fromAddress + "&addressB=" + toAddress;

	$('revDirectionsDiv').innerHTML = "<div style=\"padding:5px 0px\"><a href=\"javascript:openPopup(\'" + printURL + "\');\"><img src=\"/img/icon_printer_friendly2.gif\" border=\"0\" align=\"absmiddle\">&nbsp;</a><a href=\"javascript:openPopup(\'" + printURL + "\');\" rel=\"nofollow\">Print Map and Directions</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"javascript:reverseDirections('" + fromAddress + "','" + toAddress  + "');\" rel=\"nofollow\">Get Reverse Directions</a></div>";
	
	document.getElementById( directions).innerHTML = directionsTable;
	document.getElementById(routeResultsDiv).style.display = 'block';
	
	
	//need to make sure this degrades gracefully if there is no directions div on the page
	if(Element.getHeight('directions') > 300){
		$('directions').setStyle({
			height: '300px',
			overflow:'auto'						
		})
	}

	return false;
}


function getPrintFriendlyMap( from, to, routeResultsDiv, directions ) {

	if(typeof myMap != 'undefined'){	
			myMap.removeAllPois(); 
		}
		else{	
						myMap = new MQTileMap(document.getElementById('map'));
    // Create a new Large Zoom control attached to the map

				myMap.removeAllPois();
	}

	var gaCollection = new MQLocationCollection("MQGeoAddress");
    //populate the address object with the information from the form
	var address = new MQAddress();
	address.setStreet( from.address );
	address.setCity( from.city );
	address.setState( from.state );
	address.setPostalCode( from.zip );
	geoExec.geocode(address, gaCollection);
	
	var fromAddress = from.address + ' ' + from.city + ', ' + from.state + ' ' + from.zip;
	var toAddress = to.address + ' ' + to.city + ', ' + to.state + ' ' + to.zip;

	var geoAddr1 = gaCollection.get(0);

	//Set the START image
	point = new MQPoi(geoAddr1.getMQLatLng());
	var myIcon = new MQMapIcon();
		myIcon.setImage("/img/map_icona.gif",22,22,true,false);
    myMap.addPoi(point);
	point.setIcon(myIcon);        
	address.setStreet( to.address );
	address.setCity( to.city );
	address.setState( to.state );
	address.setPostalCode( to.zip );

	geoExec.geocode(address, gaCollection);
	
	var geoAddr2 = gaCollection.get(0);

	//Set the END image
	point = new MQPoi(geoAddr2.getMQLatLng());
	var myIcon = new MQMapIcon();
	myIcon.setImage("/img/map_iconb.gif",22,22,true,false);
    myMap.addPoi(point);
	point.setIcon(myIcon);        

	var session = new MQSession(); 
    var routeRes = new MQRouteResults();
    var wayPoints = new MQLocationCollection();
    var myBB = new MQRectLL(new MQLatLng(),new MQLatLng());
    wayPoints.add(geoAddr1);
    wayPoints.add(geoAddr2);
    var routeOpt = new MQRouteOptions();

    //create sessionID from the route server
    var sessId = routeExec.createSessionEx(session);

    routeExec.doRoute(wayPoints,routeOpt,routeRes,sessId,myBB);

    myMap.addRouteHighlight(myBB,"http://map.access.mapquest.com",sessId,true);

	var totalTime='';
	
	var myMinutes = routeRes.getTime()/60;
	if (myMinutes > 60) {
		if (myMinutes/60 == 1) {
			totalTime = "1 hr ";
		}
		else {
			totalTime = Math.round((myMinutes/60)*100)/100 + " hrs";
		}
	}
	else {
		totalTime = myMinutes + " min";
	}
	
	var totalDistance = Math.round(routeRes.getDistance()*100)/100 + " miles"; 
	var myTrkStr='';

	var directionsTable = "<table cellpadding=\"2\" cellspacing=\"0\" border=\"0\" width=\"97%\">";
	var shade = " bkground";
	var colorTD = true;
	var revDirections = "Reverse Route";	
	
	//header for directions -- estimated time and distance
	
	directionsTable += "<tr><td valign=\"top\" colspan=\"2\"><b>Estimated time: </b> " + totalTime + "<br /><b>Estimated distance:</b> " + totalDistance + "</td></tr>";
	directionsTable += "<tr><td height=\"10\"></td></tr>";
	// we want to loop through all the maneuvers in the maneuvercollection for our trekroute
	//we only have one trekroute (only 2 addresses), so we can go straight to the maneuvercollection
	// we loop thru the maneuvercollection - remember it is a zero-based array, so there is one less than the count
	for (counter = 0; counter < routeRes.getTrekRoutes().get(0).getManeuvers().getSize(); counter ++){
		var stepNo = counter + 1;
		var milage = Math.round(routeRes.getTrekRoutes().get(0).getManeuvers().get(counter).getDistance()*100)/100 + " mi";
		var dir = routeRes.getTrekRoutes().get(0).getManeuvers().get(counter).getNarrative();
		if (colorTD == true) {
  			shade = " bgcolor=\"#f0f0f0\" " ;
  			colorTD = false;
		} else {
			shade = "";
			colorTD = true;
		}
		//see if this is the end
  		if(counter == routeRes.getTrekRoutes().get(0).getManeuvers().getSize()-1)
  			directionsTable += "<tr><td style=\"border-bottom:1px solid #CCCCCC\"" + shade + " valign=\"top\"><b>" + (stepNo) + ".</b></td><td style=\"border-bottom:1px solid #CCCCCC\" valign=\"top\"" + shade + ">" + dir + "</td><td style=\"border-bottom:1px solid #CCCCCC\" align=\"center\"" + shade + "valign=\"top\" nowrap>" + milage + "</td></tr>";
 		else {
			directionsTable += "<tr><td style=\"border-bottom:1px solid #CCCCCC\"" + shade + " valign=\"top\"><b>" + stepNo + ".</b></td><td style=\"border-bottom:1px solid #CCCCCC\" valign=\"top\"" + shade + ">" + dir + "</td><td style=\"border-bottom:1px solid #CCCCCC\" align=\"center\"" + shade + "valign=\"top\" nowrap>" + milage + "</td></tr>";
		}
	}

	directionsTable += "</table>";	

	
	document.getElementById( directions).innerHTML = directionsTable;
	document.getElementById( routeResultsDiv ).style.display = 'block';
	
	//need to make sure this degrades gracefully if there is no directions div on the page
	

	return false;
}



// Define a company object - assumption that counter always starts at 1
function Company(name,address,city,state,zip,phone,latitude,longitude,companyAddressID,showDetails,counter,imageLocation,showLinks,avgRating,price){

	this.name=name;
	this.address=address;
	this.showDetails = showDetails;	
	this.city=city;
	this.state=state;
	if (zip.length == 4) {
	 zip = "0" + zip;
	}
	if (zip.length == 3) {
	 zip = "00" + zip;
	}
	this.zip=zip;
	this.phone=phone;
	this.url= "/merchant/" + companyAddressID + ".html";
  	this.mapLink="/merchant/map/" + companyAddressID + ".html";
	this.counter=counter;
	this.latitude=latitude;
	this.longitude=longitude;
	if( imageLocation == null ) {
		this.imageName="/img/map/" + (counter) + ".gif"
	}
	else {
		this.imageName=imageLocation;
	}
	this.showLinks=showLinks;
	this.avgRating=avgRating;
	this.price=price;

}

function traverse(top) {
	alert( "traversing" );
	for (var i = 0; i < top.childNodes.length; i++) {
		switch (top.childNodes[i].nodeName.toLowerCase()) {
			case "div":
				alert(top.childNodes[i] + " with name " + top.childNodes[i].id); // do whatever with it if necessary
				traverse(top.childNodes[i]);
				break;
		}
	}
}

function loadMap( mapName, companyObjects, highlightObject, mapType ) {
	
	var theMapType = '';
	if(typeof mapType != 'undefined'){
		theMapType = mapType;
	}


	if(typeof myMap != 'undefined'){	
			myMap.removeAllPois(); 
			myMap.removeRouteHighlight();
		}
		else{	
						myMap = new MQTileMap(document.getElementById('map'));
    // Create a new Large Zoom control attached to the map
    myLZControl = new MQLargeZoomControl(myMap);

		//tell the map to display the control we just attached
	    myMap.addControl(myLZControl);
	
		//Create a map view type control
		myVControl = new MQViewControl(myMap);
		
		/*
		Display control - use the Corner placement constant to specify which corner, plus an MQSize object to specify X and Y "indent" offset
		*/
		myMap.addControl(myVControl, new MQMapCornerPlacement(MQMapCorner.TOP_LEFT, new MQSize(0,0)));
		myMap.removeAllPois();

	}
	
	/*
	Display control - use the Corner placement constant to specify which corner, plus an MQSize object to specify X and Y "indent" offset
	*/
	myMap.addControl(myVControl, new MQMapCornerPlacement(MQMapCorner.TOP_LEFT, new MQSize(0,0)));
	
	if( companyObjects != null ) {
 
		for( counter=0; counter < companyObjects.length; counter++ ) {
		

			myLat=parseFloat(companyObjects[counter].latitude);
			myLong=parseFloat(companyObjects[counter].longitude);			
			latLong = new MQLatLng(companyObjects[counter].latitude, companyObjects[counter].longitude );

 	 	   //Create a new MQPoi object and set its location
   			point = new MQPoi(latLong);
		
			var myIcon = new MQMapIcon();
			if( companyObjects[counter].imageName != null && companyObjects[counter].imageName != '' ||
					companyObjects[counter].imageName == 'null' ) {
				myIcon.setImage(companyObjects[counter].imageName,20,20,true,false);
			}
	
			
    		 //Add the POI to the map
        	myMap.addPoi(point);
			point.setIcon(myIcon);		
			point.setKey( companyObjects[counter].counter );		
	
				
				point.setInfoTitleHTML( companyObjects[counter].name );
	
		
			// Note the onClick in here -- this is in here because of a MapQuest bug :
			// https://trc.mapquest.com/jforum/posts/list/434.page
			// It can be removed when the mapquest bug is fixed

			
			//adding this for a location that isn't a company and doesn't have all this info
			if(companyObjects[counter].showDetails == 'true'){
				if( companyObjects[counter].showLinks == 'true' ) { 
				 var directionsLink = '';
					if(theMapType == 'businessFinder'){
						directionsLink = '<a href=\"javascript:void(0);\" onClick=\"swapBox(\'formBox\');pullName(\'' + escape(companyObjects[counter].name) + '\');validateAddresses(\'' + companyObjects[counter].address + ' ' + companyObjects[counter].city + ', ' + companyObjects[counter].state + ' ' + companyObjects[counter].zip + '\');\">Driving Directions</a>';					
					}
					else{
						directionsLink = "<a href=\"" + companyObjects[counter].mapLink + "\" onClick=\"top.location.href=\'" + companyObjects[counter].mapLink + "'\">Driving Directions</a>";
					}
					var infoContentHTML = companyObjects[counter].name + "<br>" +
	    	  			companyObjects[counter].phone + "<br>" +
	    	  			companyObjects[counter].address + "<br>" +
	    	  			companyObjects[counter].city + ", " + companyObjects[counter].state + " " + companyObjects[counter].zip + "<br />";
	    	  		if (companyObjects[counter].price != "" && companyObjects[counter].price != "0") {
	    	  		    infoContentHTML += "<span style=\"color:green;font-weight:bold;font-size:13px;\">";
	    	  		    for (i=0;i<companyObjects[counter].price;i++) {
	    	  		     infoContentHTML += "$";
	    	  		    }
	    	  		    if (companyObjects[counter].price < 4) {
	    	  		      infoContentHTML += "</span><span style=\"color:#cccccc;font-weight:bold;font-size:13px;\">";
	    	  		      for (j=0;j<(4-companyObjects[counter].price);j++) {
	    	  		       infoContentHTML += "$";
	    	  		      }
	    	  		      infoContentHTML += "</span>";
	    	  		    }
	    	  		    infoContentHTML += "&nbsp;&nbsp;&nbsp;";
	    	  		}
	    	  		if (companyObjects[counter].avgRating != null && companyObjects[counter].avgRating != "" && companyObjects[counter].avgRating != "0.0") {
	    	  		  infoContentHTML += "<img src=\"/img/stars-" + companyObjects[counter].avgRating + ".gif\"/><br />";
	    	  		}
	    	  		infoContentHTML += "<a href=\"" + companyObjects[counter].url + "\" onClick=\"top.location.href=\'" + companyObjects[counter].url + "'\">Read More</a> | " + directionsLink;
	    	  		point.setInfoContentHTML(infoContentHTML); 
		  		}
			  	else {
					var infoContentHTML = companyObjects[counter].name + "<br>" +
	    	  			companyObjects[counter].phone + "<br>" +
	    	  			companyObjects[counter].address + "<br>" +
	    	  			companyObjects[counter].city + ", " + companyObjects[counter].state + " " + companyObjects[counter].zip + "<br />";
	    	  		if (companyObjects[counter].price != "" && companyObjects[counter].price != "0") {
	    	  		    infoContentHTML += "<span style=\"color:green;font-weight:bold;font-size:13px;\">";
	    	  		    for (i=0;i<companyObjects[counter].price;i++) {
	    	  		     infoContentHTML += "$";
	    	  		    }
	    	  		    if (companyObjects[counter].price < 4) {
	    	  		      infoContentHTML += "</span><span style=\"color:#cccccc;font-weight:bold;font-size:13px;\">";
	    	  		      for (j=0;j<(4-companyObjects[counter].price);j++) {
	    	  		       infoContentHTML += "$";
	    	  		      }
	    	  		      infoContentHTML += "</span>";
	    	  		    }
	    	  		    infoContentHTML += "&nbsp;&nbsp;&nbsp;";
	    	  		}
	    	  		if (companyObjects[counter].avgRating != null && companyObjects[counter].avgRating != "" && companyObjects[counter].avgRating != "0.0") {
	    	  		  infoContentHTML += "<img src=\"/img/stars-" + companyObjects[counter].avgRating + ".gif\"/><br />";
	    	  		}
	    	  		point.setInfoContentHTML(infoContentHTML); 
	    	  			}	
					}
					else{
						point.setInfoContentHTML(companyObjects[counter].name);
					}
	  
		  	if( highlightObject != null && highlightObject != '' ) {
		  		if( document.getElementById( highlightObject + (counter+1) ) != null ) {
					
					MQEventManager.addListener(point,"mouseover", function(e) {
						var tableRow = document.getElementById( highlightObject + this.getKey() );
						tableRow.style.background="#d3d0c9";						
					  });
		  
					MQEventManager.addListener(point,"mouseout", function(e) {
						var tableRow = document.getElementById( highlightObject + this.getKey() );
						if (this.getKey() % 2 == 0) {
						tableRow.style.background="#f6f4ea";
						}
						else {
						tableRow.style.background="#ffffff";
						}
					  });
				}	 
			} 
		}
    }	
	
    
    // set map zoom as needed
    // if there are many companies, let the mapping software choose the best fit
			
    if( companyObjects.length == 1 ) {					
	    newCenter = new MQLatLng(companyObjects[0].latitude,companyObjects[0].longitude);	
	    if(theMapType == 'defaultMap') {			
						myMap.setCenter(newCenter,9);
	    }
	    else {		
						myMap.setCenter(newCenter,12);
		}
	   
    }
			else {
			    myMap.bestFit();
			}
		
			
}


function showBasicInfo(poiNumber,elementId){
	if(typeof myMap != 'undefined'){	
		var pois = myMap.getPois();
		var poi;
		poi = pois.getAt(poiNumber);
	 poi.setRolloverEnabled(true);	
	 poi.showRolloverWindow(); 
	 	var highlightRow = document.getElementById(elementId);
		highlightRow.style.background = "#d3d0c9";
	}
}

function hideBasicInfo(poiNumber, elementId){
	if(typeof myMap != 'undefined'){	
		var pois = myMap.getPois();
		var poi;
		poi = pois.getAt(poiNumber);
		var highlightRow = document.getElementById(elementId);
		if (poiNumber % 2 == 0) {
			highlightRow.style.background="#ffffff";
		}
		else {
			highlightRow.style.background="#f6f4ea";
		}
	 myMap.getRolloverWindow().hide();
	 
	}
}

function showDetailInfo(poiNumber, elementId){
	if(typeof myMap != 'undefined'){	
		var pois = myMap.getPois();
		var poi;
		poi = pois.getAt(poiNumber);
		poi.showInfoWindow();
	}
}






