	var map = null;
	var points = new Array();
	var marker = null;
	var start_marker = null;
	var end_marker = null;
	var track = null;
	var listener = null;
	var descriptions = new Array();
	var markers = new Array();
	var datarequest = null;
	var red;
	var yellow;
	var green;
	var poi_marker = null;
	var coordinates = null;
	var centerPoint = 0;
	var nm = "";

		var red = new GIcon(G_DEFAULT_ICON, 'http://maps.google.com/mapfiles/ms/micons/red-dot.png');
		var yellow = new GIcon(G_DEFAULT_ICON, 'http://maps.google.com/mapfiles/ms/micons/yellow-dot.png');
		var green = new GIcon(G_DEFAULT_ICON, 'http://maps.google.com/mapfiles/ms/micons/green-dot.png');

	//var map = null;
	var markers = new Array();
	var marker;
	var listener = null;
	
      				
	function create_map()
	{	
		map = new GMap2(document.getElementById("umbmap"));

		try
		{
			lat = parseFloat(document.forms['tracks'].elements['latitude'].value);
			lng = parseFloat(document.forms['tracks'].elements['longitude'].value);
			zoom = parseInt(document.forms['tracks'].elements['zoom'].value);
			map.setCenter(new GLatLng(lat,lng),zoom);
		}
		catch(e)
		{
			map.setCenter(new GLatLng(41.2008730659043,-75.47538757324219),9);
		}
       		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		//var overview = new GOverviewMapControl(new GSize(200,200));
		//GEvent.addListener(overview, "zoomend", function() { overview.setZoom(map.getZoom()+5); }); 

		//overview.setMapType(G_HYBRID_MAP);
		//overview.setZoom(8);
		//map.addControl(new GScaleControl());
		//map.addControl(overview);

		listener = GEvent.addListener(map, 'click', moveto);		
		//showicons();	



	
		green.iconSize = new GSize(32,32);
		yellow.iconSize = new GSize(32,32);
		red.iconSize = new GSize(32,32);

		try
		{	if(document.location.inStr('umb_street_map.html',0) != -1)
			{
				track = document.forms['tracks'].track.value;
				loadtrack(track);			
			}
		}
		catch(e)
		{

		}
		//marker = new GMarker(new GLatLng(41.2008730659043,-75.47538757324219),green);
		
		//map.addOverlay(marker);
//marker.hide();

	}
	function moveto(obj,latlong)
	{
		
		try
		{
		
			longitude = latlong.lng();
			latitude = latlong.lat();
			try
			{

				document.forms['mapform'].elements['latitude'].value = String(latitude);
				document.forms['mapform'].elements['longitude'].value = String(longitude);
			}
			catch(e)
			{
			}
			map.panTo(new GLatLng(latitude,longitude));
			document.forms['map_values'].elements['latitude'].value = (latitude+'').substr(0,8);
			document.forms['map_values'].elements['longitude'].value = (longitude+'').substr(0,8);

		}
		catch(e)
		{
			try
			{
				if(typeof(obj.strurl) != "undefined")
					//msg_box_open(obj.strurl,345,350);
					window.open(obj.strurl);
			}
			catch(e)
			{
			//	alert(e);
			}
		}
	}
	function markit(latitude,longitude)
	{
		alert(latitude+','+longitude);
		try
		{	marker.hide();
			marker.setLatLng(new GLatLng(latitude,longitude));
			marker.show();
			map.panTo(marker.getLatLng());

		}
		catch(e)
		{
			alert(e.message);
		}
	}
	function iconclick(index)
	{
		try 
		{
			if(poi[index][4] == 1)
			{
				msg_box_open('http://www.poconosskipackages.com/directions/property_info.php?pid='+poi[index][5],475,375);
			}
			else if(poi[index][4] == 9)
			{
				msg_box_open("http://www.poconosskipackages.com/images/mountains/details/"+poi[index][5]+".htm",420,305);
			}
			else
			{
				msg_box_open(unescape(poi[index][2])+"<a href='javascript:parent.msg_box_close();'>Close</a>",420,305);
			}
		}
		catch(e)
		{
			alert(e);
		}

		if(!e) var e = window.event;
		if(e) e.cancelBubble = true;
		if(e) e.returnValue = false;
		return;
	}
	function showlayer(l)
	{
			
		showicons();
		return false;
	}
	function display_icon(lat,lng,txt,img)
	{
		var tack_icon = new GIcon(); 
		var tmarker = null;

	        tack_icon.iconSize = new GSize(24, 24);
        	tack_icon.iconAnchor = new GPoint(24, 24);
		tack_icon.image = 'http://www.uppermtbethel.org/mapicons/tack.png';

	        opts = { icon: tack_icon, "clickable": true, "title": "letter A", "labelText": "", "labelOffset": new GSize(-24, -24) };
		opts['title'] = unescape(txt);

		tmarker = new GMarker(new GLatLng(lat,lng),opts);

		map.addOverlay(tmarker);

	}
	function showicons()
	{
	
        var icon = new GIcon();

		map.clearOverlays();
		icon.image = 'http://www.poconosskipackages.com/directions/cabin.png';
        icon.iconSize = new GSize(24, 24);
        icon.iconAnchor = new GPoint(24, 24);
        //icon.infoWindowAnchor = new GPoint(25, 7);

        opts = { 
          "icon": icon,
          "clickable": true,
          "title": "letter A",
          "labelText": "",
          "labelOffset": new GSize(-24, -24)
        };	
	
		markers.lenght = 0;
		for(i = 0; i < poi.length;i++)
		{
		
			try
			{
				switch(poi[i][4])
				{
					case 1:
							if(document.forms[1].elements['show_lodging'].checked)
							{
								icon.image = 'http://www.poconosskipackages.com/directions/cabin.png';
								opts['labelText'] = "<img src='transparent.png' title='"+unescape(poi[i][2])+"' onclick=\"javascript:iconclick("+i+");\">";
								opts['title'] = unescape(poi[i][2]);
								markers[markers.length] = new LabeledMarker(new GLatLng(poi[i][0],poi[i][1]),opts);			
								map.addOverlay(markers[markers.length-1]);							
							}				
							break;
					case 9:
							if(document.forms[1].elements['show_skiresorts'].checked)
							{
								icon.image = 'http://www.poconosskipackages.com/directions/ski.png';
								opts['labelText'] = "<img src='transparent.png' title='"+unescape(poi[i][2])+"' onclick=\"javascript:iconclick("+i+");\">";
								opts['title'] = unescape(poi[i][2]);
								markers[markers.length] = new LabeledMarker(new GLatLng(poi[i][0],poi[i][1]),opts);			
								map.addOverlay(markers[markers.length-1]);							
							}
							break;
					case 13:
							if(document.forms[1].elements['show_attractions'].checked)
							{
								icon.image = 'http://www.poconosskipackages.com/directions/attractions.png';
								opts['labelText'] = "<img src='transparent.png' title='"+unescape(poi[i][2])+"' onclick=\"javascript:iconclick("+i+");\">";
								opts['title'] = unescape(poi[i][2]);
								markers[markers.length] = new LabeledMarker(new GLatLng(poi[i][0],poi[i][1]),opts);			
								map.addOverlay(markers[markers.length-1]);	
							}
							break;				
				}
			}
			catch(e)
			{
			alert(e);
			}
		}
	}
	
	function zoomIn()
	{
		map.zoomIn();
	}
	function zoomOut()
	{
		map.zoomOut();
	}
	function reset()
	{
			map.setCenter(new GLatLng(41.19725651800892,-75.17257690429687),9);





	}

	var dataRequest;
	/****************************************************************************************/
	function request(provider,data)
	{

		try
		{
			document.getElementById('wait').style.display = 'block';
			document.getElementById('wait').style.visible = 'visible';
			if (window.XMLHttpRequest)
			{
				dataRequest = new XMLHttpRequest();
				dataRequest.onreadystatechange=response_handler;
				dataRequest.open("POST",provider,true);
				dataRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				dataRequest.send(data);
  			}
			else if (window.ActiveXObject)
			{
				dataRequest = new ActiveXObject("Microsoft.XMLHTTP")
				if (dataRequest)
				{ 
    					dataRequest.onreadystatechange=response_handler;
    					dataRequest.open("POST",provider,true);
					dataRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					dataRequest.send(data);
				}
  			}
		}
		catch(err)
		{
			alert("Javascript Error(submit_form):\r\n"+err.description);
		}

	}
	/****************************************************************************************/
	function response_handler()
	{

		if (dataRequest.readyState == 4)
  		{ 
			strData = dataRequest.responseText;	
//alert("response from server:"+strData);
			try
			{
				eval(dataRequest.responseText);			

			}
			catch(err)
			{						
				alert("Error(response_handler): \r\n"+err);
				//msg_window_close();
			}	

			dataRequest = null;
			document.getElementById('wait').style.display = 'none';
			document.getElementById('wait').style.visible = 'invisible';

    		}
	}

	function loadtrack(trk)
	{
		track = trk;

		request('/scripts/gettrack.php','nm='+track);
	}

	function displayroute()
	{
		route = "";


		if(track != null)
		{
			map.removeOverlay(track);
			map.clearOverlays();
			track = null;
			points.length = 0;
			poi_marker = null;
		}
		//if(document.forms['tracking'].elements['pointlist'].length > 0)
		pIndex = 0;
		if(coordinates.length > 0)
		{
			for(i = 0; i < coordinates.length; i++,pIndex++)
			{			
				//p = document.forms['tracking'].elements['pointlist'].options[i].text.split(',');
				if(coordinates[pIndex][0] != "0" && coordinates[pIndex][1] != "0")
				{
					points[pIndex] = new GLatLng(coordinates[pIndex][0],coordinates[pIndex][1]);
					points[pIndex] = new GLatLng(coordinates[pIndex][0],coordinates[pIndex][1]);
				}
				else
				{//$i++;
					track = new GPolyline(points,"#0000ff", 5);
					map.addOverlay(track);
					points.length = 0;
//alert("Next Segment");
				}
				//if(descriptions[i] != "")
				//{
				//markers[i] = new GMarker(new GLatLng(p[0],p[1]));
				//GEvent.addListener(markers[i],"click",describepoint);						
				//map.addOverlay(markers[i]);
				//markers[i].openInfoWindowHtml( descriptions[i] );	
				//}
			
			}

			track = new GPolyline(points,"#0000ff", 5);
			map.addOverlay(track);

			//start = document.forms['tracking'].elements['pointlist'].options[0].text.split(',');
			start = new GPoint(coordinates[0][0],coordinates[0][1]);
			//stop = document.forms['tracking'].elements['pointlist'].options[document.forms['tracking'].elements['pointlist'].options.length-1].text.split(',');

			start_marker = new GMarker(new GLatLng(coordinates[0][0],coordinates[0][1]),green);
			end_marker = new GMarker(new GLatLng(coordinates[coordinates.length-1][0],coordinates[coordinates.length-1][1]),red);
			//GEvent.addListener(start_marker, "click",describepoint);
			//GEvent.addListener(end_marker, "click",describepoint);
			map.addOverlay(start_marker);
			map.addOverlay(end_marker);

			try 
			{
				if(document.forms['map_values'].elements['autopan'].checked == true)
				{
					lat = coordinates[Math.round(coordinates.length/2)][0];
					lng = coordinates[Math.round(coordinates.length/2)][1];
//alert(lat+","+lng);
					//map.setCenter(new GLatLng(lat,lng),map.getZoom());
					document.forms['map_values'].elements['latitude'].value = (lat+'').substr(0,8);
					document.forms['map_values'].elements['longitude'].value = (lng+'').substr(0,8);

					map.panTo(new GLatLng(lat,lng));
					

				}
			}
			catch(e)
			{
				alert(e);
			}
			//center_track();
			getDistance();
		}

		return false;
	}


function getDistance()
{
	
	//start = coordinates[0];
	begin = new GLatLng(coordinates[0][0],coordinates[0][1]);
	current = new GLatLng(coordinates[0][0],coordinates[0][1]);
	distance = 0;

	for(i = 0; i < coordinates.length-1; i++)
	{
		//coord = document.forms['tracking'].elements['pointlist'].options[i].text.split(',');
		tmpcoord = new GLatLng(coordinates[i][0],coordinates[i][1]);
		distance += current.distanceFrom(tmpcoord);
		current = tmpcoord;		
	
	}
	//document.forms['tracking'].elements['distance'].value = (distance * 0.000621371192);

	centerDistance = 0;
	current = new GLatLng(coordinates[0][0],coordinates[0][1]);
	for(i = 0; i < coordinates.length-1; i++)
	{
		//coord = document.forms['tracking'].elements['pointlist'].options[i].text.split(',');
		tmpcoord = new GLatLng(coordinates[i][0],coordinates[i][1]);
		centerDistance += current.distanceFrom(tmpcoord);
		if(centerDistance >= (distance / 2))
		{
			centerPoint = i;
			break;
		}
		else
		current = tmpcoord;		
	
	}
	
	//map.centerAndZoom(new GLatLng(coordinates[centerPoint][0],coordinates[centerPoint][1]));

	/*try
	{
		lat = parseFloat(document.forms['tracks'].elements['latitude'].value);
		lng = parseFloat(document.forms['tracks'].elements['longitude'].value);
		zoom = parseInt(document.forms['tracks'].elements['zoom'].value);
		map.setCenter(new GLatLng(lat,lng),zoom);
	}
	catch(e)
	{
		map.setCenter(new GLatLng(-75.17257690429687, 41.19725651800892),9);
	}*/

	try
	{
		document.forms['map_values'].distance.value = (distance * 0.000621371192).toFixed(4);
	}
	catch(e)
	{
		alert(e);
	}

}
function center_track()
{

//	start = coordinates[0];
//	stop =  coordinates[coordinates.length-1];
//alert(start+"\r\n"+stop);
	//start = document.forms['tracking'].elements['pointlist'].options[0].text.split(',');
	//stop = document.forms['tracking'].elements['pointlist'].options[document.forms['tracking'].elements['pointlist'].options.length-1].text.split(',');

//	xcenter = abs(start[0] - stop[0]) / 2;
//	ycenter = abs(start[1] - stop[1]) / 2;

//	alert("Latitude: "+(start[0]+ycenter)+"\r\nLongitude: "+(start[1]+xcenter));


	map.setCenter(marker.getLatLng() ,map.getZoom());

	
}

function doSearch(term)
{

	request('scripts/gettrack.php','nm='+"http://www.poconosatlas.com/scripts/umb.php?search="+term);

	return false;
}

function tagit()
{
	var latitude = document.forms['map_values'].elements['latitude'].value;
	var longitude = document.forms['map_values'].elements['longitude'].value;
//	var description = prompt('Please enter a description of the location.\r\nMaximum of 128 characters','');
	

	var windowstr = "<html>";
	windowstr += "<head>";
	windowstr += "<title>Geo Tag Information</title>";
	windowstr += "</head>";
	windowstr += "<body bgcolor='#FFFFCC'>";
	windowstr += "<center><p style='margin:0px'><H3>This feature is not complete!</H3></p></center>";
	windowstr += "<p style='margin-top: 0; margin-bottom: 0'>";
	windowstr += "Please enter a description for this location.";
	windowstr += "<p style='margin-top: 0; margin-bottom: 0'>Maximum number of characters is 128.";
	windowstr += "<form method='post' action='/scripts/save_location.php'>";
	windowstr += "<p style='margin-top: 0; margin-bottom: 0'>Longitude: <input type='text' name='longitude' size='20' value='"+longitude+"' READONLY>";
	windowstr += "<p style='margin-top: 0; margin-bottom: 0'>Latitude:<input type='text' name='latitude' size='20' value='"+latitude+"' READONLY>";
	windowstr += "<p style='margin-top: 0; margin-bottom: 0'>User ID: (registration email): <input type='text' name='umbtid' size='30'>";
	windowstr += "<p style='margin-top: 0; margin-bottom: 0'>Description of location: <input type='text' name='description' size='50'>";
	windowstr += "<center>";
	windowstr += "<p style='margin-top: 0; margin-bottom: 0'><input type='submit' value='Submit' name='B1'><input type='button' value='Close' name='cancel' onClick='parent.msg_box_close();'>";
	windowstr += "</form>";
	windowstr += "</center>";
	windowstr += "</body>";
	windowstr += "</html>";

	msg_box_open(windowstr,500,250)
//	alert("This feature is not complete.\r\nDescription:"+description+"\r\nLatitude:"+latitude+"\r\nLongitude:"+longitude);
}

