/*
  selectbox.js: Used for marking and selecting a rectangular area.
                Used for selecting an area for running the Ecological Portfolio Model on.
*/

OpenLayers.Control.SelectBox =
  OpenLayers.Class( OpenLayers.Control, {
    type: OpenLayers.Control.TYPE_TOOL,
    draw: function() {
      this.handler = new OpenLayers.Handler.Box( this, {done: this.selectBox}, {keyMask: this.keyMask} );
    },
//    previousCursor: "",
    selectBox: function(position) {
      if (position instanceof OpenLayers.Bounds) {
        this.map.div.style.cursor = this.previousCursor; 
        this.handler.deactivate();      // turn off select box tool after selection
        // convert box pixel values to lat/lon 
        var ul = this.map.getLonLatFromPixel(new OpenLayers.Pixel(position.left, position.top));
        var lr = this.map.getLonLatFromPixel(new OpenLayers.Pixel(position.right, position.bottom));
        // go to EPM parameters
        OpenEPMParms(ul.lon, ul.lat, lr.lon, lr.lat);
      }
      else {   // pixel
        alert("A box must be selected to run the EPM.");
      }
    },
    CLASS_NAME: "OpenLayers.Control.SelectBox"
  });

