function highlightCurrentMarker(){
	  if (currentMarker != null)
	  {
	  
      var markerPoint = currentMarker.getPoint();

      var polyPoints = Array();

      if (highlightCircle) {
        map.removeOverlay(highlightCircle);
      }

      var mapNormalProj = G_NORMAL_MAP.getProjection();
      var mapZoom = map.getZoom();
      var clickedPixel = mapNormalProj.fromLatLngToPixel(markerPoint, mapZoom);

      var polySmallRadius = 20;

      var polyNumSides = 20;
      var polySideLength = 18;

      for (var a = 0; a<(polyNumSides+1); a++) {
	    var aRad = polySideLength*a*(Math.PI/180);
	    var polyRadius = polySmallRadius; 
       	    var pixelX = clickedPixel.x + 5 + polyRadius * Math.cos(aRad);
	    var pixelY = clickedPixel.y - 10 + polyRadius * Math.sin(aRad);
	    var polyPixel = new GPoint(pixelX,pixelY);
	    var polyPoint = mapNormalProj.fromPixelToLatLng(polyPixel,mapZoom);
	    polyPoints.push(polyPoint);
      }
      // Using GPolygon(points,  strokeColor?,  strokeWeight?,  strokeOpacity?,  fillColor?,  fillOpacity?)
      highlightCircle = new GPolygon(polyPoints,"#000000",2,0.0,"#FF0000",.5);
      map.addOverlay(highlightCircle);
	  }
   }

function spopup(url, img) {
x = screen.availWidth/2-600/2;
y = screen.availHeight/2-800/2;	

supopup = window.open("","_supopup",'width=600,height=800,left='+x+',top='+y+',screenX='+x+',screenY='+y+',scrollbars=1,resizeable');

   if (supopup != null){
      with (supopup.document){
         open()
		  write(" <script language='javascript' type='text/javascript'> ")
		  write("<!-- ")
		  write("	function submitbutton(pressbutton) { ")
		  write("	    var form = document.mailtoForm; ")
		  write("		// do field validation ")
		  write("		if (form.mailto.value == '' || form.from.value == '') { ")
		  write("			alert( 'Please enter your Name and E-Mail address' ); ")
		  write("			return false; ")
		  write("		} ")
		  write("		form.submit(); ")
		  write("	} ")
		  write("--> ")
		  write("</script> ")
		  write("<form action='index.php' name='mailtoForm' method='post'>")
		  write("<div style='padding: 10px;'>")
		  write("<div style='text-align:right'>")
		  write("<a href='javascript: void window.close()'>	Close Window <img src='/components/com_hotspots/images/utils/close.gif' border='0' alt='' title='' /></a>")
		  write("</div>")
		  write("<div class='componentheading'>")
		  write("E-Mail this link to a friend")
		  write("</div>")
		  write("<p>")
		  write("Mailto:")
		  write("		<br />")
		  write("		<input type='text' name='mailto' class='inputbox' size='25' value=''/>")
		  write("	</p>")
		  write("	<p>")
		  write("		Sender:")
		  write("		<br />")
		  write("		<input type='text' name='sender' class='inputbox' value='' size='25' />")
		  write("	</p>")
		  write("	<p>")
		  write("		Your name:")
		  write("		<br />")
		  write("		<input type='text' name='from' class='inputbox' value='' size='25' />")
		  write("	</p>")
		  write("	<p>")
		  write("		Subject:")
		  write("		<br />")
		  write("		<input type='text' name='subject' id='subject' class='inputbox' value='' size='25' />")
		  write("	</p>")
		  write("<p>")
		  write("<div id='mailimg' name='mailimg'>")
		  write("<img src='" + img + "'>")
		  write("</div>")
		  write("		Message:")
		  write("		<br />")
		  write("		<textarea type='text_area' name='bodytext' id='bodytext' class='text_area' value='' rows='4' cols='40'/></textarea>")
		  write("	</p>")
		  write("	<p>")
		  write("		<button class='button' onclick='return submitbutton('send');'>")
		  write("			Send")
		  write("		</button>")
		  write("<button class='button' onclick='window.close();return false;'>")
		  write("			Cancel ")
		  write("		</button>")
		  write("	</p>")
		  write("</div>")
		  
		  write("	<input type='hidden' name='option' value='com_hotspots' />")
		  write("	<input type='hidden' name='view' value='all' />")
		  write("	<input type='hidden' name='task' value='sendmail' />")
		  write("   <input type='hidden' name='imglink' id='imglink' value='" + img + "' />")
		  write("	</form>")
	 
         close()
      }
   }
}


function htmlpopup(w,h,site) {
     x = screen.availWidth/2-w/2;
     y = screen.availHeight/2-h/2;
     var popupWindow = window.open(
     '','','width='+w+',height='+h+',left='+x+',top='+y+',screenX='+x+',screenY='+y);
     popupWindow.document.write(site);
}

function updateImage(todo) {
   var baseUrl = "http://maps.google.com/maps/api/staticmap?";
   var params = [];
   
   params.push("center=" + map.getCenter().lat().toFixed(6) + "," + map.getCenter().lng().toFixed(6));
   params.push("zoom=" + map.getZoom());

   var markerSize = "";
   var markerColor = "";
   var markerLetter = "label:" + catfirstLetter;
   var markerParams = [];
   if (markerSize != "") markerParams.push(markerSize);
   if (markerColor != "") markerParams.push(markerColor);
   if (markerLetter != "") markerParams.push(markerLetter);

   var markersArray = [];
   for (var i = 0; i < markers.length; i++) {
       markersArray.push(markers[i].getLatLng().lat().toFixed(6) + "," + markers[i].getLatLng().lng().toFixed(6));
   }
   
   if (markersArray.length) {
     var markersString = markerParams.join("|");
     if (markerParams.length) markersString += "|";
     markersString += markersArray.join("|");
     params.push("markers=" + markersString);
   }

   var polyColor = "color:0x" + "0000FF" + 80;
   var polyWeight = "weight:" + 5;
   var polyParams = polyColor + "|" + polyWeight;
   for (var i = 0; i < polys.length; i++) {
     var poly = polys[i];
     var polyLatLngs = [];
     for (var j = 0; j < poly.getVertexCount(); j++) {
       polyLatLngs.push(poly.getVertex(j).lat().toFixed(5) + "," + poly.getVertex(j).lng().toFixed(5));
     }
     params.push("path=" + polyParams + "|" + polyLatLngs.join("|"));
   }
   if (map.getCurrentMapType() == G_SATELLITE_MAP) {
     params.push("maptype=satellite");
   }
   if (map.getCurrentMapType() == G_HYBRID_MAP) {
     params.push("maptype=hybrid");
   }
   if (map.getCurrentMapType() == G_PHYSICAL_MAP) {
     params.push("maptype=terrain");
   }

   params.push("size=" + static_mapwidth + "x" + static_mapheight);
   var img = document.createElement("img");
 
   img.src = baseUrl + params.join("&") + "&sensor=false&key=" + api_key ;
   /*  document.getElementById("staticMapIMG").innerHTML = "";
   document.getElementById("staticMapIMG").appendChild(img);
   document.getElementById("staticMapURL").innerHTML = baseUrl + params.join("&") + "&sensor=false&key=" + api_key;*/

   if (todo == 'print')
   {
    //var popupheight2 = (static_mapheight + 100);
	var popupheight2 = 500;
    htmlpopup(static_mapwidth, popupheight2, '<html><head><title>Print</title></head><body Onload="window.print();"><img src="' + baseUrl + params.join("&") + "&sensor=false&key=" + api_key + '"><br /><p align="right"><img src="/components/com_hotspots/images/utils/print.png"><a href="javascript:print();"><font face="Verdana" size="2pt">Print</a></p></body></html>');
   } else {
    spopup('index2.php?option=com_hotspots&view=popupmail', baseUrl + params.join("&") + "&sensor=false&key=" + api_key);
   }
}

function handleErrors(){
	   if (directions.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	     alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + directions.getStatus().code);

           else if (directions.getStatus().code == G_GEO_SERVER_ERROR)
	     alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + directions.getStatus().code);

	   else if (directions.getStatus().code == G_GEO_MISSING_QUERY)
	     alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + directions.getStatus().code);

	   else if (directions.getStatus().code == G_GEO_BAD_KEY)
	     alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + directions.getStatus().code);

	   else if (directions.getStatus().code == G_GEO_BAD_REQUEST)
	     alert("A directions request could not be successfully parsed.\n Error code: " + directions.getStatus().code);

	   else alert("An unknown error occurred.");
}
