// Handler used for marquee graph marquee zoom operations
/**
 * @constructor
 */
var   DvtGraphMarqueeZoomHandler = function(context, chart, bounds, zoomMode, zoomDirection)
{
    this.InitZoom(context, chart, bounds, zoomMode, zoomDirection);
}  

DvtGraphMarqueeZoomHandler.TOK_X =  "__X__" ;
DvtGraphMarqueeZoomHandler.TOK_Y =  "__Y__" ;
DvtGraphMarqueeZoomHandler.TOK_W =  "__W__" ;
DvtGraphMarqueeZoomHandler.TOK_H =  "__H__" ;

DvtObj.createSubclass(DvtGraphMarqueeZoomHandler, DvtGraphMarqueeZoomHandlerBase, "DvtGraphMarqueeZoomHandler");

DvtGraphMarqueeZoomHandler.prototype.InitZoom = function(context, chart, bounds, zoomMode, zoomDirection) {
    this.m_chart = chart;
    var panelBehavior = DvtGraphMarqueeZoomHandler.convertDirection(zoomDirection);
    DvtGraphMarqueeZoomHandler.superclass.InitZoom.call(this, context, chart, bounds, zoomMode, panelBehavior);
}

DvtGraphMarqueeZoomHandler.convertDirection = function(direction) {
    if (direction == DvtGraphCore.DATA_ZOOM_BOTH) {
        return DvtGraphMarqueeHandler.PANEL_BEHAVIOR_BOTH;
    } else if (direction == DvtGraphCore.DATA_ZOOM_HORIZ) {
        return DvtGraphMarqueeHandler.PANEL_BEHAVIOR_HORIZ;
    } else if (direction == DvtGraphCore.DATA_ZOOM_VERT) {
        return DvtGraphMarqueeHandler.PANEL_BEHAVIOR_VERT;
    }
    return DvtGraphMarqueeHandler.PANEL_BEHAVIOR_BOTH;
}

DvtGraphMarqueeZoomHandler.prototype.HandleMarqueeDone = function() {
   //  Terminate zoom interactivity.  
   this._isMarqueeEnabled = false ;
   
   //---------------------------//
   //    Fire the event to js   //
   //---------------------------//
   var  initJs  = null;
   var  finalJs  = null;
   var  bSingleClick = null;
   
   //TODO: implement events
   
   //  If a rubber band rect has width and height < 2, we treat this a single click.

   if (this._panelWidth  < 2 && this._panelHeight < 2)
   {
      if (this.m_bZoomIn && (this.m_chart._zoomInClickEventJs != null))
      {
        initJs = this.m_chart._zoomInClickEventJs ;
      }
      else  if ( (! this.m_bZoomIn) && (this.m_chart._zoomOutClickEventJs != null) )
      {
        initJs = this.m_chart._zoomOutClickEventJs ;
      }
      bSingleClick = true ;                  // m_iBandRectWidth and m_iBandRectHeight
                                             // not used for single-click event.
   }
   else
   {
      //  Have a complete rubber band rect

      if (this.m_bZoomIn && (this.m_chart._zoomInRectEventJs != null))
      {
        initJs = this.m_chart._zoomInRectEventJs ;
      }
      else if ( (! this.m_bZoomIn) && (this.m_chart._zoomOutRectEventJs != null))
      {
        initJs =  this.m_chart._zoomOutRectEventJs ;
      }
   }

   // The event wants coords relative to the View (which is really m_Container),
   // so we need to map the rubber band rect coords.
   var  mappedX = this._panelX + this.x ;
   var  mappedY = this._panelY + this.y ;

   //  Emit the event
   if (initJs != null)
   {
     finalJs = initJs.replace(DvtGraphMarqueeZoomHandler.TOK_X, mappedX);
     finalJs = finalJs.replace(DvtGraphMarqueeZoomHandler.TOK_Y, mappedY);

     if (! bSingleClick)                               
     {
        finalJs = finalJs.replace(DvtGraphMarqueeZoomHandler.TOK_W, this._panelWidth);
        finalJs = finalJs.replace(DvtGraphMarqueeZoomHandler.TOK_H, this._panelHeight);
     }                                  

     if (finalJs != null)
     {
       //BUG 34184877 - MAKE DVT COMPATIBLE WITH CSP STANDARDS
       var jsArray = finalJs.match(/'(.*?)'/g);
       var src = jsArray[0].replace(/\'/g, "");
       var eventData = jsArray[2].replace(/\'/g, "");
       var bi_gdzXData = jsArray[3].replace(/\'/g, "");
       var bi_gdzYData = jsArray[4].replace(/\'/g, "");
       if(jsArray.length>5)
       {
         var bi_gdzWData = jsArray[5].replace(/\'/g, "");
         var bi_gdzHData = jsArray[6].replace(/\'/g, "");
         AdfPage.PAGE.findComponent(src).getPeer().sendToServerPPR({source:src ,event: eventData ,bi_gdzX: bi_gdzXData ,bi_gdzY: bi_gdzYData ,bi_gdzW: bi_gdzWData ,bi_gdzH: bi_gdzHData});
       }
       else
       {
         AdfPage.PAGE.findComponent(src).getPeer().sendToServerPPR({source:src ,event: eventData ,bi_gdzX: bi_gdzXData ,bi_gdzY: bi_gdzYData});
       }
     }
   }

}


/**
 */ 

DvtGraphMarqueeZoomHandler.prototype.updateCursor = function() {
// TODO: add cursor support
   if(this.isInBounds(null))
   {
     if(this._isMarqueeEnabled) {
        if (this.m_bMouseDown) {
            var selectCursor = DvtSelectionEffectUtils.getSelectingCursor();
            this.m_chart.setCursor("pointer");
        } else {
            // TODO: in the future, this will be a zoom in cursor
            this.m_chart.setCursor("pointer");
        }
     } else {
        // No cursor should be shown
        this.removeCursor();
        return;
     }
   }
   else {
     // Cursor is not in plotArea, hide it
     this.removeCursor();
   }
}  

/*----------------------------------------------------------------------*/
/*    removeCursor()                                               */
/*----------------------------------------------------------------------*/
DvtGraphMarqueeZoomHandler.prototype.removeCursor = function() {
    this.m_chart.setCursor("default");
}
