/*****************
Trip planner related functions and variables.
Add/remove, map icons and markers, trip planner management, marker and map management


*****************************/

var theSeason = "w";
var theCategory = "";
var iconWidth = 82;
var iconHeight = 41;

activitiesIconWidth = 97;
activitiesIconHeight = 53;

pubsIconWidth = 89;
pubsIconHeight = 55;

diningIconWidth = 89;
diningIconHeight = 46;


var smartWindowOffsetYCP = new YCoordPoint(0,55);//move the info window above the icon
var iconImageOffsetYCP = new YCoordPoint(-21,0);//align point of graphic with actual lat/lon point on map
		
//this method should be called at the top of the page, after the body tag
function updateSeasonCat(s,c)
{
	theSeason = s;
	theCategory = c;
}
/*
addTPItemToMarkerArray
method called from loadTripPlanner.cfm, creates a new YMarker object, sets it's custom properties,
then adds it to the TPMarkerArray for future mapping by the mapTPMarkers() method

*/

var TPObjectArray = new Array();
/*
returns Boolean
used to maintain unique TP items

*/
function isListingInTripPlanner(id,cat)
{
	var wellIsIt = false;
	for(var i=0;i < TPObjectArray.length;i++)
	{
		if(TPObjectArray[i].dbid == id && TPObjectArray[i].tpCategory == cat)
		{
			wellIsIt = true;
			return true;
		}
	}
	if(!wellIsIt)
	{
		return false;
	}
}

function hasTripPlannerItems()
{
	return TPObjectArray.length;//0 items = false, anything else = true
}

/*
add a new YMarker object to the TPArray
*/
function addItemToTPObjectArray(lat,lon,name,imageFile,theContactHTML,dbid,tpCategory,labelNumber)
{
	//make sure this item has not already been added
	//use tpCategory argument to determine icon to use once ready
	var newObject = new Object();
	
	newObject.dbid = dbid;
	newObject.lat = lat;
	newObject.lon = lon;
	newObject.name = name;
	newObject.tpCategory = tpCategory;
	newObject.imageFile = imageFile;
	newObject.theContactHTML = theContactHTML;
	newObject.labelNumber = labelNumber;
	newObject.markerIDString = "";
		
	TPObjectArray.push(newObject);
	
}

function removeTPObject(id,cat)
{
	var tmpArray = new Array();//store all values in this array EXCEPT for the match
	for(var i=0;i < TPObjectArray.length;i++)
	{
		if(TPObjectArray[i].dbid == id && TPObjectArray[i].tpCategory == cat)
		{
			//we found the item, DON'T DO ANYthing
		}
		else//add this item, we want to keep it
		{
			tmpArray.push(TPObjectArray[i]);
		}
	}
	//reset the TP Array, so it now contains one less value
	TPObjectArray = tmpArray;
}

/*
add all of the YMarker objects in the TPArray to the map
uses the array of markers and their respective YGeoPoint objects to determine and set best zoom level of map
*/
function mapTPMarkers()
{
	resetMap();
	var tmpYGPArray = new Array();
	for(var i = 0;i < TPObjectArray.length;i++)
	{
		var labelClass = "label";//default WHITE labels, test for dining or activities
		var iWidth = iconWidth;
		var	iHeight = iconHeight;
		
		//determine icon dimensions by category, also label class should be set here
		if(TPObjectArray[i].tpCategory == 'Activities')
		{
			labelClass = "activitiesLabel";
			iWidth = activitiesIconWidth;
			iHeight = activitiesIconHeight;
		}
		else if(TPObjectArray[i].tpCategory == 'Dining')
		{
			labelClass = "diningLabel";
			iWidth = diningIconWidth;
			iHeight = diningIconHeight;
		}
		else if(TPObjectArray[i].tpCategory == 'Pubs')
		{
			labelClass = "pubsLabel";
			iWidth = pubsIconWidth;
			iHeight = pubsIconHeight;
		}
		
		var newMarker = new YMarker(new YGeoPoint(TPObjectArray[i].lat,TPObjectArray[i].lon),new YImage("i/icons/"+TPObjectArray[i].tpCategory+".png",new YSize(iWidth,iHeight),smartWindowOffsetYCP,iconImageOffsetYCP));
		
		
		//add YGeoPoint to array
		tmpYGPArray.push(newMarker.YGeoPoint);
		
		newMarker.addLabel("<div class='"+labelClass+"'>"+TPObjectArray[i].labelNumber+"</div>");
		newMarker.isTPMarker = 1;
		newMarker.name = TPObjectArray[i].name;
		newMarker.theContactHTML = TPObjectArray[i].theContactHTML;
		newMarker.dbid = TPObjectArray[i].dbid;//id from the lp database, used to store trip planner items and to query for more info 
		newMarker.isTPListing = 1;//use when displaying info window, identify items that are already in the user's TP
		newMarker.tpCategory = TPObjectArray[i].tpCategory;//for use when opening info window
	
		if(TPObjectArray[i].imageFile != "")//set up the appropriate directory
		{
			if(TPObjectArray[i].tpCategory.toLowerCase() == 'lodging')
			{
				newMarker.imageFile = 'lodging/'+TPObjectArray[i].imageFile;
			}
			else
			{
				if(theSeason == "s")
				{
					newMarker.imageFile = "pix-s/"+TPObjectArray[i].imageFile;
				}
				else
				{
					newMarker.imageFile = "pix-w/"+TPObjectArray[i].imageFile;
				}
			}
		}
		else//they have no image, ouch
		{
			newMarker.imageFile = "";
		}
		map.addOverlay(newMarker);
		YEvent.Capture(newMarker,EventsList.MouseClick,function(){
														openInfoWindow(this.id);
														});
		
		//store the new marker ID with it's corresponding TPObject, for opening an info window when clicking the TP listing text link (right hand div)
		TPObjectArray[i].markerIDString = newMarker.id;
	}
	
	//update the map to the best view
	updateToBestView(tmpYGPArray);
	
}
/*
function invoked when user clicks one of the TP text links in the TP listing DIV
loops through TPObjectArray looking for match on dbid,cat
Once found, it then accesses the markerIDString attribute that was set when the mapTPMArkers function (above) was run.
The markerIDString vaalue is then passed to the openInfoWindow function

*/
function openTPInfoWindowByDBID(theDBID,cat)
{
	for(var i=0;i < TPObjectArray.length;i++)
	{
		if(TPObjectArray[i].dbid == theDBID && TPObjectArray[i].tpCategory == cat)
		{
			//we found the item, access it's markerIDString value, use to open info window
			openInfoWindow(TPObjectArray[i].markerIDString);
			break;
		}
	}
	
	
}
/*
hide the search markers, remove the TP YMarkers

*/

function hideMarkers()
{
	//hide the search results markers, remove the TP markers
	var tmpMarkerArray = map.getMarkerIDs();
	for(var i = 0;i < tmpMarkerArray.length;i++)
	{
		if(!map.getMarkerObject(tmpMarkerArray[i]).isVenue)//make sure this is NOT a venue
		{
			if(map.getMarkerObject(tmpMarkerArray[i]).isTPMarker)//remove it from the map
			{
				map.removeMarker(tmpMarkerArray[i]);
			}
			else//just HIDE the search results
			{
				map.getMarkerObject(tmpMarkerArray[i]).hide();
			}
		}
	}
}

function showSearchResultMarkers()
{
	//make the search results markers visible
	var tmpMarkerArray = map.getMarkerIDs();
	for(var i = 0;i < tmpMarkerArray.length;i++)
	{
		map.getMarkerObject(tmpMarkerArray[i]).unhide();
	}
}

function resetMap()
{
	//hide the search results markers
	hideMarkers();
	//Add the ORDA Venues to the map
	var whiteface = new YMarker(new YGeoPoint(44.356,-73.87),new YImage("i/icons/venueWhiteface.png",new YSize(78,56),smartWindowOffsetYCP,new YCoordPoint(-38,0)));
	//whiteface.addLabel("<div class='venueLabel'>Whiteface Mountain</div>");
	//add custom properties for info window display
	whiteface.name = "Whiteface Mountain Ski Center";
	whiteface.isVenue = true;
	map.addOverlay(whiteface);
	YEvent.Capture(whiteface,EventsList.MouseClick,function(){
														openInfoWindow(whiteface.id);
														});
	var hovenburg = new YMarker(new YGeoPoint(44.217,-73.925),new YImage("i/icons/venueHovenburg.png",new YSize(149,54),smartWindowOffsetYCP,new YCoordPoint(-74,0)));
	//hovenburg.addLabel("<div class='venueLabel'>Olympic Sports Complex</div>");
	//add custom properties for info window display
	hovenburg.name = "Olympic Sports Complex";
	hovenburg.isVenue = true;
	map.addOverlay(hovenburg);
	YEvent.Capture(hovenburg,EventsList.MouseClick,function(){
														openInfoWindow(hovenburg.id);
														});
														
	var jumps = new YMarker(new YGeoPoint(44.257,-73.969),new YImage("i/icons/venueJumping.png",new YSize(74,58),smartWindowOffsetYCP,new YCoordPoint(-37,0)));
	//jumps.addLabel("<div class='venueLabel'>Olympic Ski Jumping Complex</div>");
	//add custom properties for info window display
	jumps.name = "Olympic Ski Jumping Complex";
	jumps.isVenue = true;
	map.addOverlay(jumps);
	YEvent.Capture(jumps,EventsList.MouseClick,function(){
														openInfoWindow(jumps.id);
														});
		
	var arena = new YMarker(new YGeoPoint(44.28289,-73.9879),new YImage("i/icons/venueOlympicCenter.png",new YSize(72,54),smartWindowOffsetYCP,new YCoordPoint(-37,0)));
	//arena.addLabel("<div class='venueLabel'>Olympic Center</div>");
	//add custom properties for info window display
	arena.name = "Olympic Center";
	arena.isVenue = true;
	map.addOverlay(arena);
	YEvent.Capture(arena,EventsList.MouseClick,function(){
														openInfoWindow(arena.id);
														});
	arena.dbid = 2505;
	jumps.dbid = 2483;
	hovenburg.dbid = 2563;
	whiteface.dbid = 2572;

	
	arena.name = "Olympic Center";
	jumps.name = "Olympic Ski Jumping Complex";
	hovenburg.name = "Olympic Sports Complex";
	whiteface.name = "Whiteface Mountain Ski Center";
	
	arena.theContactHTML = "2634 Main Street<br />Lake Placid, NY 12946<br />518-523-1655<br />800-462-6236<br /><a href='http://www.whitefacelakeplacid.com' target='_blank'>http://www.whitefacelakeplacid.com</a>";
	jumps.theContactHTML = "Route 73<br />Lake Placid, NY 12946<br />518-523-2202<br />800-462-6236<br /><a href='http://www.whitefacelakeplacid.com' target='_blank'>http://www.whitefacelakeplacid.com</a>";
	hovenburg.theContactHTML = "220 Bobrun Lane<br />Lake Placid, NY 12946<br />518-523-4436<br />800-462-6236<br /><a href='http://www.olympicsportscomplex.com' target='_blank'><br />http://www.olympicsportscomplex.com";
	whiteface.theContactHTML = "Route 86<br />Wilmington, NY 12997<br />518-946-2223<br />800-462-6236<br /><a href='http://www.whiteface.com' target='_blank'><br />http://www.whiteface.com";
	

	arena.isTPListing = 0;//use when displaying info window, identify items that are already in the user's TP
	arena.tpCategory = 'Activities';//for use when opening info window
	jumps.isTPListing = 0;
	jumps.tpCategory = 'Activities';
	hovenburg.isTPListing = 0;
	hovenburg.tpCategory = 'Activities';
	whiteface.isTPListing = 0;
	whiteface.tpCategory = 'Activities';
		
	arena.imageFile = "pix-w/olympic-center.jpg";
	jumps.imageFile = "pix-w/ski-jump.jpg";
	hovenburg.imageFile = "pix-w/bobsled-w05.jpg";
	whiteface.imageFile = "pix-w/Whiteface-W06.jpg";
	
}


function addMarkerToMap(lat,lon,name,labelText,imageFile,address,city,zip,url,phone,dbid,isTripPlannerListing,isLodgingHasPackages)
{
	var labelClass = "label";//default WHITE labels, test for dining or activities
	var iWidth = iconWidth;
	var	iHeight = iconHeight;
	
	//determine icon dimensions by category, also label class should be set here
	if(theCategory == 'Activities')
	{
		labelClass = "activitiesLabel";
		iWidth = activitiesIconWidth;
		iHeight = activitiesIconHeight;
	}
	else if(theCategory == 'Dining')
	{
		labelClass = "diningLabel";
		iWidth = diningIconWidth;
		iHeight = diningIconHeight;
	}
	else if(theCategory == 'Pubs')
	{
		labelClass = "pubsLabel";
		iWidth = pubsIconWidth;
		iHeight = pubsIconHeight;
	}
		
	var newMarker = new YMarker(new YGeoPoint(lat,lon),new YImage("i/icons/"+theCategory+".png",new YSize(iWidth,iHeight),smartWindowOffsetYCP,iconImageOffsetYCP));

	newMarker.addLabel("<div class='"+labelClass+"'>"+labelText+"</div>");
	
	/*
		add custom properites to this YMarker so that we can access them when an info window is opened,
		and also if/when they 
	
	*/
	var htmlURL = "";
	if(url != '')
	{
		if(url.indexOf("http") != -1)
		{
			htmlURL = "<a href='"+url+"' target='_blank'>"+url+"</a>";
		}
		else
		{
			htmlURL = "<a href='http://"+url+"' target='_blank'>"+url+"</a>";
		}
	}
	
	newMarker.name = name;
	newMarker.theContactHTML = address+"<br />"+city+", NY "+zip+"<br />"+phone+"<br />"+htmlURL;
	newMarker.dbid = dbid;//id from the lp database, used to store trip planner items and to query for more info 
	newMarker.isTPListing = isTripPlannerListing;//use when displaying info window, identify items that are already in the user's TP
	newMarker.tpCategory = theCategory;//for use when opening info window
	newMarker.isLodgingHasPackages = isLodgingHasPackages;
	
	if(imageFile != "")//set up the appropriate directory
	{
		if(theCategory.toLowerCase() == 'lodging')
		{
			newMarker.imageFile = 'lodging/'+imageFile;
		}
		else
		{
			if(theSeason == "s")
			{
				newMarker.imageFile = "pix-s/"+imageFile;
			}
			else
			{
				newMarker.imageFile = "pix-w/"+imageFile;
			}
		}
	}
	else//they have no image, ouch
	{
		newMarker.imageFile = "";
	}
	map.addOverlay(newMarker);
	YEvent.Capture(newMarker,EventsList.MouseClick,function(){
														openInfoWindow(newMarker.id);
														});
	
	//add this new marker to our container for future mapping
	return newMarker.id;
}


/*
	closeInfoWindows()
	get rid of any open windows
	
*/
function closeInfoWindows()
{
	var idArray = map.getMarkerIDs();//array of marker ids
	for(var i = 0;i < idArray.length;i++)
	{
		map.getMarkerObject(idArray[i]).closeSmartWindow();
	}
}

/*
	openInfoWindow()
	called when listing is clicked, passes id that was returned when the marker was created
	
*/
function openInfoWindow(id)
{
	closeInfoWindows();
	//map.getMarkerObject(id).openAutoExpand();
	map.panToLatLon(map.getMarkerObject(id).YGeoPoint);
	//check for image, establish img tag
	var theImageCode = "";
	if(map.getMarkerObject(id).imageFile != "")
	{
		var theImageCode = "<img src='http://lakeplacid.com/dbsearch/"+map.getMarkerObject(id).imageFile+"'><br />";
	}
	
	var theTPString = "";
	if(map.getMarkerObject(id).isTPListing)//set up the removal link if this is a TP listing
	{
		theTPString = "<span class='tripPlannerText'>Trip planner item<br />";
		theTPString = theTPString+"<a href=\"javascript:removeFromTripPlanner("+map.getMarkerObject(id).dbid+",'"+map.getMarkerObject(id).tpCategory+"');\" title='remove item'>remove</a>";
	}
	else//set up the add link, handling code
	{
		theTPString = "<a href=\"javascript:addToTripPlanner('"+map.getMarkerObject(id).dbid+"','"+map.getMarkerObject(id).tpCategory+"','"+id+"');\">Add to trip planner</a>";
	}
	
	var packagesHTML = "";
	if(map.getMarkerObject(id).isLodgingHasPackages)//add the click for ski packages link
	{
		packagesHTML = "<div class='skiPackages'><a href='https://www.lakeplacid.com/reservations/?start' target='_blank'>Click here for Ski &amp; Stay packages</a>&nbsp;&nbsp;<a href='https://www.lakeplacid.com/reservations/?start' target='_blank'><img src='i/icons/snowflakeOnWhite.gif' border='0' style='text-decoration:none;' align='middle' title='Ski &amp; Stay Packages Available' /></a></div>";
	}
	
	map.getMarkerObject(id).setSmartWindowColor("blue");
	
	map.getMarkerObject(id).openSmartWindow("<div class='markerInfoWindow'>"+theImageCode+map.getMarkerObject(id).name+"<br />"+map.getMarkerObject(id).theContactHTML+"<br /><a href=\"javascript:popDetails('"+map.getMarkerObject(id).tpCategory+"',"+map.getMarkerObject(id).dbid+");\">click for full description</a>"+packagesHTML+"<br /><br /><a href=\"javascript:zoomToStreet('"+id+"')\";>zoom to street</a><br /><br />"+theTPString+"</div>");
	
	
	//map.showSmartWindow(map.getMarkerObject(id).YGeoPoint,"<div class='markerInfoWindow'>"+theImageCode+map.getMarkerObject(id).name+"<br />"+map.getMarkerObject(id).theContactHTML+"<br /><br /><a href=\"javascript:zoomToStreet('"+id+"')\";>zoom to street</a><br /><br />"+theTPString+"</div>");
	
}
/*
updateTOBestView(YGeoPointArray)
given an Array of YGeoPoints, update the map view

*/
function updateToBestView(arrayYGP)
{
	if(arrayYGP.length > 0)
	{
		var tmpZoomAndCenterObject = map.getBestZoomAndCenter(arrayYGP);
		map.setZoomLevel(tmpZoomAndCenterObject.zoomLevel);
		map.panToLatLon(tmpZoomAndCenterObject.YGeoPoint);
	}
}


function openVenueInfoWindow(id)
{
	closeInfoWindows();
	//map.getMarkerObject(id).openAutoExpand();
	map.panToLatLon(map.getMarkerObject(id).YGeoPoint);
	//check for image, establish img tag
	
	
	map.getMarkerObject(id).openSmartWindow("<div class='markerInfoWindow'>"+map.getMarkerObject(id).name+"<br /><br /><a href=\"javascript:popDetails('Activities',"+map.getMarkerObject(id).dbid+");\">click for full description</a><br /><a href=\"javascript:zoomToStreet('"+id+"')\";>zoom to street</a></div>");
	
}

function zoomToStreet(markerIDString)
{
	map.drawZoomAndCenter(map.getMarkerObject(markerIDString).YGeoPoint,2);
}

function zoomToLatLon(latitude,longitude)
{
	map.drawZoomAndCenter(new YGeoPoint(latitude,longitude),2);
}


/*******************************************************/
/*	Trip Planner updating functions  */


function addToTripPlanner(theID,theCAT,markerID)
{
	closeInfoWindows();
	
	if(!isListingInTripPlanner(theID,theCAT))//only add if NOT already added
	{
		addItemToTPObjectArray(map.getMarkerObject(markerID).YGeoPoint.Lat,map.getMarkerObject(markerID).YGeoPoint.Lon,map.getMarkerObject(markerID).name,map.getMarkerObject(markerID).imageFile,map.getMarkerObject(markerID).theContactHTML,theID,theCAT);
	}
	
	var xmlHttp;
  try
	{    // Firefox, Opera 8.0+, Safari    
			xmlHttp=new XMLHttpRequest();    }
  catch (e)
	{    // Internet Explorer    
		try
	  {      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
	catch (e)
	  {      try
		{        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
	  catch (e)
		{
			document.location = 'addToTripPlanner.cfm?id='+theID+'&cat='+theCAT;
		}
	  }
	}
	xmlHttp.onreadystatechange=function()
	  {
	  if(xmlHttp.readyState==4)
		{
			
			//updateTripPlanner();
			var currentURL = document.location.toString();
			var zLevelPos = currentURL.toLowerCase().indexOf('zlevel=');
			if(zLevelPos != -1)//remove the zoom level, carefully, doctor!!
			{
				var tmpString = currentURL.substring(zLevelPos, currentURL.length);//grab &zlevel= plus rest of string
				if(tmpString.length <= 9)//this was last variable, just rewrite the thing
				{
					document.location = currentURL.substring(0,zLevelPos)+"&zLevel="+map.getZoomLevel();
				}
				else//there were other variables after zlevel, maintain these values
				{
					var nextVarPos = tmpString.indexOf("&");
					var otherURLVars = tmpString.substring(nextVarPos);//grab the & and anything after it
					document.location = currentURL.substring(0,zLevelPos)+"&zLevel="+map.getZoomLevel()+otherURLVars;
				}
			}
			else//there was no zlevel reference, so add it
			{
				if(currentURL.toLowerCase().indexOf('?') == -1)
				{
					document.location = document.location+"?zLevel="+map.getZoomLevel();
				}
				else
				{
					document.location = document.location+"&zLevel="+map.getZoomLevel();
				}
			}

		}
	  }
	var queryURL = 'CFHandlers/addToTripPlanner.cfm?id='+theID+'&cat='+theCAT;
	xmlHttp.open("GET",queryURL,true);
	xmlHttp.send(null);
}

function removeFromTripPlanner(theID,theCAT)
{
	if(confirm('Are you sure you want to remove this item from your trip planner?'))
	{
		closeInfoWindows();
		//update the local TPObject array
		removeTPObject(theID,theCAT);
		var xmlHttp;
		try
		{    // Firefox, Opera 8.0+, Safari    
			xmlHttp=new XMLHttpRequest();
		}
		catch (e)
		{    // Internet Explorer    
			try
			{
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e)
			{
				try
				{
					xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e)
				{
					document.location = 'remove_item.cfm?id='+theID+'&cat='+theCAT;
				}
			}
		}
		//nothing was caught, proceed
		xmlHttp.onreadystatechange=function()
		{
			if(xmlHttp.readyState==4)
			{
				//query was sucessful, call update to refresh TP DIV = updateTripPlanner();
				
				//changed functionality, reload page to keep TP numbering synched between javascript object and cold fusion output
				document.location = "http://whitefacelakeplacidinfo.com/tripplanner/";
			}
		}
		
		var queryURL = 'CFHandlers/remove_item.cfm?id='+theID+'&cat='+theCAT;
		xmlHttp.open("GET",queryURL,true);
		xmlHttp.send(null);
	}//end of if confirm
}



//******************************************************

/************
submit the directions from address form to a specific listing, as determined by the pop up window
******************/
function directionsSubmit(){
	if(document.forms[0].saddr.value != ""){document.forms[0].submit();}else{alert("Please enter your starting address!");}
}

/******
map a trip planner item, use appropriate icon, no numbering
****/
//use this temp marker as a reference to the tp icons as they are placed on the map, we want to remove them once "unfocused"
var tmpMarkerID = 0;
function removeTempTPMarker()
{
	if(tmpMarkerID != 0)
	{
		map.removeMarker(tmpMarkerID);
	}
}

function tripPlannerListingWindow(dbid,longitude,latitude,item_name,category,imageFile,contactInfo)
{
	removeTempTPMarker();

	var imageHTML = '';
	if(imageFile != "")//set up the appropriate directory
	{
		if(category.toLowerCase() == 'lodging')
		{
			imageHTML = '<img src="http://lakeplacid.com/dbsearch/lodging/'+imageFile+'">';
		}
		else
		{
			if(theSeason == "s")
			{
				imageHTML = '<img src="http://lakeplacid.com/dbsearch/pix-s/'+imageFile+'">';
			}
			else
			{
				imageHTML = '<img src="http://lakeplacid.com/dbsearch/pix-w/'+imageFile+'">';
			}
		}
	}
	
	var htmlStr = imageHTML+'<p>'+item_name+'<br />'+contactInfo;
	
	//need to adjust for appropriate icon
	//DO WE NEED THIS ICON, OR WILL INFO WINDOW SUFFICE??
	/*
	
	var newTMPMarker = new YMarker(new YGeoPoint(latitude,longitude),new YImage("i/icons/snowflake.gif",new YSize(30,56),0));
	
	tmpMarkerID = newTMPMarker.id;//for remove function
	map.addOverlay(newTMPMarker);
	
	*/
	var theTPString = "<span class='tripPlannerText'>Trip planner item<br /><a href=\"javascript:removeFromTripPlanner("+dbid+",'"+category+"');\" title='remove item'>remove</a>";
	
	var ygp = new YGeoPoint(latitude,longitude);
	
	
	map.panToLatLon(ygp);
	map.showSmartWindow(ygp,"<div class='markerInfoWindow'>"+htmlStr+"<br /><br /><a href='javascript:zoomToLatLon("+latitude+","+longitude+")';>zoom to street</a><br /><br />"+theTPString+"</div>");
	
	//remove the marker once the user clicks somewhere else
	YEvent.Capture(map,EventsList.MouseClick ,function(){
													   		removeTempTPMarker();}
													   );

}