var iconArray = [];
var legendString = "";
var legendCount = 7;
var legendCounter = 1;
var legendColSize = 4;

var onClickText = 'javascript:alert("Locus customers can access their site data by clicking here!")';

function set_legend_count(legendNum) {
	legendCount = legendNum;
}

function update_legend() {
	
	legendString = legendString + '<img src="eSite_SiteSearch/star_white.png">EPA Sites of Concern<img src="/e2/esiteportal/images/1pix_trans.gif" width="5" height="1" ><img src="eSite_SiteSearch/circle_white.png">State Sites of Concern';
	
	document.getElementById("legend").innerHTML = "<b>" + legendString + "</b>" ;
}

function register_icon (iconName, iconFile, iconWidth, iconHeight, iconType) {

	var icon = new GIcon();
	iconFile = 'eSite_SiteSearch/' + iconFile;
  	icon.image = iconFile;
  	icon.shadow = '/gfx/maps/markers/shadow50.png';
  	icon.iconSize = new GSize(iconWidth, iconHeight);
  	icon.shadowSize = new GSize(iconWidth, iconHeight);
  	icon.iconAnchor = new GPoint((iconWidth/2), (iconHeight/2));
  	icon.infoWindowAnchor = new GPoint(9, 1);
	//alert(icon.image);
  	iconArray.push(icon);

	legendString = legendString + ' <img src="' +iconFile + '" > ' + iconType + '<img src="/e2/esiteportal/images/1pix_trans.gif" width="5" height="1" >';
	if (legendCounter == legendCount) {
		legendString = legendString ;
		}
	if ((legendCounter >= legendColSize) && (legendCounter % legendColSize == 0) && (legendCounter < legendCount)) {
		legendString = legendString + '<br><br>';
		}

	legendCounter = legendCounter + 1;
}

function add_location(xVal, yVal, idVal, descVal, iconIndex, showLabel, addrVal, locCount, programVal) {

	var point = new GLatLng(yVal, xVal);
	var idText = "<b>" + descVal + "</b><br><i>" + programVal + "</i><br>" + addrVal
	var thisIcon = iconArray[iconIndex];

	var marker = new PdMarker(point, thisIcon);
	marker.id=idVal;
	marker.setTooltip(descVal);
	if (locCount > 0) {
		idText = idText + "<br><a class='style2' href='google.cfm?site_id=" + idVal + "' target='_new'>View wells in new window</a>"
		}
	if (idVal == 'Martinez') {
		idText = idText + "<br><a href='https://www.locusfocus.com/eim' target='_new'><img src='eSite_SiteSearch/button_signin_nls.JPG' border=0></a>" }
	else {
		idText = idText + "<br><a href='"+ onClickText + "'><img src='eSite_SiteSearch/button_signin_nls.JPG' border=0></a>" }
	marker.setDetailWinHTML(idText);
	map.addOverlay(marker);

	GEvent.addListener(marker, "mouseover", function() {
		//marker.setImage("icon/dd-start.png"); // change graphic
		//marker.topMarkerZIndex(); // bring marker to top
	}); 

	GEvent.addListener(marker, "mouseout", function() {
		//marker.restoreImage();
		//marker.restoreMarkerZIndex();
	});	
}

function zoom_to_locations() {
	map.zoomToMarkers(5);
}

function clear_locations() {
	map.clearOverlays();
	//iconArray = [];
	//legendCounter = 1;
	//legendString = "<B>";
}

function addRing(x, y, radius, color) {

    	var pts = getRingCoords(x, y, radius);
    	var ring = new GPolyline(pts, color, 8);
    	map.addOverlay(ring);

}

function getRingCoords(x, y, radius) {

    	var pts = [];
    	var angle;

    	for (var i=0; i < 41; i++) {
      		angle = (360 / (41 - 1)) * i;
      		pts.push(getCoordAtAngle(x, y, radius, angle));
    	}

    	return pts;

}

function getCoordAtAngle(x, y, radius, angle) {

    	var nx = 0;
    	var ny = 0;
    	var DEG_2_RAD = 0.017453292519943295769236907684886;
    	var RAD_2_DEG = 57.295779513082320876798154814105;
    	var FEET_PER_DEGREE = 69.04545;

    	nx = x + radius * Math.cos((90 - angle) * DEG_2_RAD) / FEET_PER_DEGREE / Math.cos(y * DEG_2_RAD);
    	ny = y + radius * Math.sin((90 - angle) * DEG_2_RAD) / FEET_PER_DEGREE;
    	return new GPoint(nx, ny);

}

