var globalPSet;
function beachPointsCB(pSet){
	globalPSet = pSet;
  //here's where i append this new layer to the map
  var baseUrl = 'http://' + appbase + '/' + pSet.getParameterValues('submitTo') + '?' + pSet.getParameterQueryString();
  var id = pSet.getParameterValues('layerId');
  var name = pSet.getParameterValues('layerName');
  var title = pSet.getParameterValues('layerName');
  var zdepth = pSet.getParameterValues('zdepth');
  var scaleMin = 0;
  var scaleMax = 10;
  
  //see if this is in the mapobjects wmsLayers dictionary
  var found = false;
  var wms = beachMap.wmsLayers;
  for (var i = 0; i < wms.length; i++) {
    if (wms[i].id == id) {
      found = true;
      //change the baseurl if found
      wms[i].baseUrl = baseUrl;
      wms[i].title = title;
      wms[i].name = name;
      break;
    }
  }
  //if not found, push it on the stack  
  if (!found) {
    beachMap.wmsLayers.push(new WmsLayer(name, title, id, baseUrl, -1*zdepth, name, name, scaleMin, scaleMax, '-180,-90,180,90'));
  }
  
  //remove this layer-
  beachMap.removeLayer(id);
  
	//append this layer
	beachMap.appendLayer(id);
	
	if(beachMap.identifyPopup){
		beachMap.identifyPopup.kill();
	}
}

function identifyBeach(event, map) {
  //map.setToolAction(null);

  event = event || window.event;
  var coordsPx = getRelativeCoords(event, map.pane);
  var ll = map.getLatLonFromPixel(coordsPx[0], coordsPx[1]);

  var args = '';
  
  args += '&queryId=identify';
  args += '&mapscale=' + map.getScale();
  args += '&lat=' + ll[1];
  args += '&long=' + ll[0];
	args += '&baseQueryPath=_status/base_query.jsp';
	if(globalPSet){
	args+="&beachStatus="+globalPSet.getParameterValues("beachStatus");
	} else {
	args+= "&beachStatus=%";
	}
	
  if (map.identifyPopup) map.identifyPopup.kill();
  var ajaxfill = false;
  var c;
  if (!c) {
    c = 'Identifying...';
    ajaxfill = true;
  }
  
  map.identifyPopup = new IdentifyPopup(
    map,
    'Identify',
    c,
    320,
    300,
    ll[1],
    ll[0]
  );
  
  if (ajaxfill) map.identifyPopup.fillContentsAJAX('identify', args, moveToLatLong);
  
  return true;  
  
}

function moveToLatLong(){
	if(document.getElementById("targetLat").innerHTML&&document.getElementById("targetLon").innerHTML){
		var newLat = parseFloat(document.getElementById("targetLat").innerHTML);
		var newLon = parseFloat(document.getElementById("targetLon").innerHTML);
		var coordsPx = beachMap.getPixelFromLatLon(newLat, newLon); 
		beachMap.animateMoveToPx(coordsPx[0], coordsPx[1]);
		beachMap.identifyPopup.lat=beachMap.identifyPopup.centerLat=newLat;
		beachMap.identifyPopup.lon=beachMap.identifyPopup.centerLon=newLon;
		beachMap.identifyPopup.hlX = beachMap.identifyPopup.mapX =(coordsPx[0]); 
		beachMap.identifyPopup.hlY = beachMap.identifyPopup.mapY =(coordsPx[1]);
	}
}
