﻿//>>#99915912 - Jeff 2010/04/30
if (!Function.prototype.CreateDelegate)
  Function.prototype.CreateDelegate = function(instance, method) { return function() { return method.apply(instance, arguments); } }
//<<#99915912 - Jeff 2010/04/30
if (typeof (FarPoint) == "undefined")
  FarPoint = {}
if (typeof (FarPoint.Web) == "undefined")
  FarPoint.Web = {}
if (typeof (FarPoint.Web.Spread) == "undefined")
  FarPoint.Web.Spread = {}

FarPoint.Web.Spread.SpreadChart = function(chartSpread, container) {
  this.chartSpread = chartSpread;
  this.container = container;
  this.eventHandlers = {};
  this.tableChartData = null;
  this.chartID = null;
  this.chart = null;
  this.isActived = null;
};

// Methods.
FarPoint.Web.Spread.SpreadChart.prototype.init = function() {
  this.tableChartData = document.getElementById(this.chartSpread.id + "_XMLDATA");
  this.chartID = this.container.getAttribute("serverID");
  this.chart = this.getChart();
  this.chartStyleInfo = new FarPoint.Web.Spread.SpreadChartStyleInfo(this); //99915104
  this.registerChartItemEvent();
  this.isActived = this.container.getAttribute("isActive") == "true";
  if (this.isActived) {
    this.activeChart();
  }

  if (this.chartSpread.virtualPaging == "true" && this.chartSpread.virtualTop > 0 && this.virtualUpdated != true) {
    this.container.style.top = parseInt(this.container.style.top) + this.chartSpread.virtualTop + "px";
    this.virtualUpdated = true;
  }
};

FarPoint.Web.Spread.SpreadChart.prototype.addChartInfo = function() {
  var node = this.getchartInfoByID(this.chartID);
  if (node != null)
    return node;

  var root = this.getChartInfo();

  if (document.all != null) {
    node = this.tableChartData.createNode("element", "chart", "");
    attr = this.tableChartData.createNode("attribute", "id", "");
    attr.text = this.chartID;
    node.attributes.setNamedItem(attr);
  }
  else {
    node = document.createElement("chart");
    node.setAttribute("id", this.chartID);
  }
  root.appendChild(node);

  return node;
};

FarPoint.Web.Spread.SpreadChart.prototype.getchartInfoByID = function() {
  var root = this.getChartInfo();
  var node;
  if (FpChartUtil.isIE()) {
    node = root.selectSingleNode("./chart[@id='" + this.chartID + "']");
  }
  else {
    node = the_fpSpread.GetElementById(root, this.chartID);
  }
  return node;
};

FarPoint.Web.Spread.SpreadChart.prototype.getChart = function() {
  var chartImage = null;
  var items = this.container.getElementsByTagName("img");
  for (var i = 0; i < items.length; i++) {
    if (items[i].build == null) {
      chartImage = items[i];
      break;
    }
  }
  return chartImage;
};

FarPoint.Web.Spread.SpreadChart.prototype.getChartInfo = function() {
  if (typeof this.tableChartData.documentElement == "undefined") {
    return this.tableChartData.getElementsByTagName("chartinfo")[0];
  }
  else {
    return this.tableChartData.documentElement.selectSingleNode("//chartinfo");
  }
};

FarPoint.Web.Spread.SpreadChart.prototype.getEventTarget = function(event) {
  if (event.target == document && event.currentTarget != null)
    return event.currentTarget;
  if (event.target != null)
    return event.target;
  return event.srcElement;
};

FarPoint.Web.Spread.SpreadChart.prototype.registerChartItemEvent = function() {
  this.attachEvent(this.container, "mousedown", this.containerMousedown, this, null);
  if (this.container.getAttribute("moveChart") != "false") {
    this.attachEvent(document, "mouseup", this.endDragChart, this, null);
    this.attachEvent(this.container, "mouseup", this.endDragChart, this, null);
    this.attachEvent(this.container, "keydown", this.chartKeyDown, this, null);
  }

  if (this.container.getAttribute("sizeChart") != "false") {
    this.buildResizeCorner();
  }
};

FarPoint.Web.Spread.SpreadChart.prototype.activeChart = function() {
  if (this.container.getAttribute("selectChart") != "false") {
    var root = this.getChartInfo();
    var attr = root.attributes.getNamedItem("activechart");
    if (document.all != null) {
      attr = this.tableChartData.createNode("attribute", "activechart", "");
      attr.text = this.chartID;
      root.attributes.setNamedItem(attr);
    }
    else {
      root.setAttribute("activechart", this.chartID);
    }
    // 99915941 CoreyKou 2010.05.06
    this.container.setAttribute("isActive", "true");

    if (FpChartUtil.isIE()) {
      this.chartSpread.SetActiveChartObj(this);
    }
    else {
      the_fpSpread.SetActiveChartObj(this.chartSpread, this);
    }

    this.highlightChart();
  }
};

FarPoint.Web.Spread.SpreadChart.prototype.inactiveChart = function() {
  var activeChart;
  if (FpChartUtil.isIE()) {
    activeChart = this.chartSpread.GetActiveChartObj();
  }
  else {
    activeChart = the_fpSpread.GetActiveChartObj(this.chartSpread);
  }

  if (activeChart != null) {
    activeChart.normalChart();
    var root = this.getChartInfo();
    root.removeAttribute("activechart");
  }
};

FarPoint.Web.Spread.SpreadChart.prototype.scrollChartIntoView = function() {
  var scrollLeft, scrollTop;
  var parentNode = this.container.parentNode;
  this.stopVirtualPaging(); //#99915912 - Jeff 2010/04/29

  if (this.container.offsetLeft < parentNode.scrollLeft) {
    scrollLeft = this.container.offsetLeft;
  }
  else if ((this.container.offsetLeft + this.container.offsetWidth) > (parentNode.clientWidth + parentNode.scrollLeft)) {
    scrollLeft = this.container.offsetLeft + this.container.offsetWidth - parentNode.clientWidth;
  }

  if (this.container.offsetTop < parentNode.scrollTop) {
    scrollTop = this.container.offsetTop;
  }
  else if ((this.container.offsetTop + this.container.offsetHeight) > (parentNode.clientHeight + parentNode.scrollTop)) {
    scrollTop = this.container.offsetTop + this.container.offsetHeight - parentNode.clientHeight;
  }

  if (!FpChartUtil.isIE()) {
    if (scrollLeft != null) parentNode.scrollLeft = scrollLeft;
    if (scrollTop != null) parentNode.scrollTop = scrollTop;
  }
  else {
    var divScroll = document.getElementById(this.chartSpread.id + "_scrollvp");
    if (divScroll != null) {
      if (scrollLeft != null) divScroll.scrollLeft = scrollLeft;
      if (scrollTop != null) divScroll.scrollTop = scrollTop;
      if (scrollTop != null) divScroll.scrollTop = scrollTop;
    }
  }

  this.container.focus();

  if (this.container.select) {
    this.container.select();
  }
  this.startVirtualPaging(); //#99915912 - Jeff 2010/04/29
};

//>>#99915912 - Jeff 2010/04/29  
FarPoint.Web.Spread.SpreadChart.prototype.stopVirtualPaging = function() {
  this.chartSpread.stopVirtualPaging(this.chartSpread);
}

FarPoint.Web.Spread.SpreadChart.prototype.startVirtualPaging = function() {
  var _handler = Function.CreateDelegate(this, this.startVirtualPaging2);
  setTimeout(_handler, 100);
}

FarPoint.Web.Spread.SpreadChart.prototype.startVirtualPaging2 = function() {
  this.chartSpread.startVirtualPaging(this.chartSpread);
}
//<<#99915912 - Jeff 2010/04/29  

FarPoint.Web.Spread.SpreadChart.prototype.cancelDefault = function(event) {
  if (event.preventDefault != null) {
    event.preventDefault();
    event.stopPropagation();
  }
  else {
    event.cancelBubble = true;
    event.returnValue = false;
  }
  return false;
};

FarPoint.Web.Spread.SpreadChart.prototype.buildResizeCorner = function() {
  if (this.container.isBuildCorner != null && this.container.isBuildCorner == true)
    return;
  else
    this.container.isBuildCorner = true;
  this.container.style.height = this.container.clientHeight + 'px';
  this.container.style.width = this.container.clientWidth + 'px';

  var containerBorderWidth = this.container.clientTop;
  var cornerWidth = 7;
  var offsetCorner = Math.floor(cornerWidth / 2);
  var cornerImageUrl = this.chartSpread.getAttribute("chartConerImg");

  var chartObj = this;
  buildOneCorner = function(id, left, top, url, cursor) {
    var corner = document.createElement('IMG');
    corner.build = true;
    corner.src = url;
    corner.style.position = 'absolute';
    corner.style.left = left;
    corner.style.top = top;
    corner.style.cursor = cursor;
    corner.id = id;
    corner.style.display = 'none';
    chartObj.attachEvent(corner, "mousedown", chartObj.startResizeChart, chartObj, null);
    chartObj.attachEvent(corner, "mouseup", chartObj.endResizeChart, chartObj, null);
    chartObj.attachEvent(corner, "click", chartObj.endResizeChart, chartObj, null);
    return corner;
  };

  var id = 'nw-resize';
  var left = (-offsetCorner - (containerBorderWidth * 2)) + 'px';
  var top = (-offsetCorner - (containerBorderWidth * 2)) + 'px';
  var cursor = 'nw-resize';
  var corner = buildOneCorner(id, left, top, cornerImageUrl, cursor);
  this.container.appendChild(corner);

  id = 'ne-resize';
  left = (parseInt(this.container.style.width) - offsetCorner) + 'px';
  top = (-offsetCorner - (containerBorderWidth * 2)) + 'px';
  cursor = 'ne-resize';
  corner = buildOneCorner(id, left, top, cornerImageUrl, cursor);
  this.container.appendChild(corner);

  id = 'sw-resize';
  left = (-offsetCorner - (containerBorderWidth * 2)) + 'px';
  top = (parseInt(this.container.style.height) - offsetCorner) + 'px';
  cursor = 'sw-resize';
  corner = buildOneCorner(id, left, top, cornerImageUrl, cursor);
  this.container.appendChild(corner);

  id = 'se-resize';
  left = (parseInt(this.container.style.width) - offsetCorner) + 'px';
  top = (parseInt(this.container.style.height) - offsetCorner) + 'px';
  cursor = 'se-resize';
  corner = buildOneCorner(id, left, top, cornerImageUrl, cursor);
  this.container.appendChild(corner);

  id = 'n-resize';
  left = (Math.floor(parseInt(this.container.style.width) / 2) - offsetCorner) + 'px';
  top = (-offsetCorner - (containerBorderWidth * 2)) + 'px';
  cursor = 's-resize';
  corner = buildOneCorner(id, left, top, cornerImageUrl, cursor);
  this.container.appendChild(corner);

  id = 's-resize';
  left = (Math.floor(parseInt(this.container.style.width) / 2) - offsetCorner) + 'px';
  top = (parseInt(this.container.style.height) - offsetCorner) + 'px';
  cursor = 's-resize';
  corner = buildOneCorner(id, left, top, cornerImageUrl, cursor);
  this.container.appendChild(corner);

  id = 'w-resize';
  left = (-offsetCorner - (containerBorderWidth * 2)) + 'px';
  top = (Math.floor(parseInt(this.container.style.height) / 2) - offsetCorner - (containerBorderWidth * 2)) + 'px';
  cursor = 'e-resize';
  corner = buildOneCorner(id, left, top, cornerImageUrl, cursor);
  this.container.appendChild(corner);

  id = 'e-resize';
  left = (parseInt(this.container.style.width) - offsetCorner) + 'px';
  top = (Math.floor(parseInt(this.container.style.height) / 2) - offsetCorner - (containerBorderWidth * 2)) + 'px';
  cursor = 'e-resize';
  corner = buildOneCorner(id, left, top, cornerImageUrl, cursor);
  this.container.appendChild(corner);

  this.container.isProcessingResize = false;
};

FarPoint.Web.Spread.SpreadChart.prototype.setResizeCornerPosition = function() {
  var nw_resize, sw_resize, w_resize, n_resize, s_resize, e_resize, ne_resize, se_resize;
  var children;
  if (typeof this.container.children == "undefined") {
    // mozilla
    children = this.container.childNodes;
  }
  else {
    // IE
    children = this.container.children;
  }
  for (var i = 0; i < children.length; i++) {
    switch (children[i].id) {
      case 'nw-resize':
        nw_resize = children[i];
        break;
      case 'sw-resize':
        sw_resize = children[i];
        break;
      case 'w-resize':
        w_resize = children[i];
        break;
      case 'n-resize':
        n_resize = children[i];
        break;
      case 's-resize':
        s_resize = children[i];
        break;
      case 'e-resize':
        e_resize = children[i];
        break;
      case 'ne-resize':
        ne_resize = children[i];
        break;
      case 'se-resize':
        se_resize = children[i];
        break;
    }
  }
  var containerBorderWidth = 1;
  var cornerWidth = 7;
  var offsetCorner = Math.floor(cornerWidth / 2);
  n_resize.style.left = (Math.floor((parseInt(this.container.style.width) + (containerBorderWidth * 2)) / 2) - offsetCorner - (containerBorderWidth * 2)) + 'px';
  s_resize.style.left = (Math.floor((parseInt(this.container.style.width) + (containerBorderWidth * 2)) / 2) - offsetCorner - (containerBorderWidth * 2)) + 'px';
  ne_resize.style.left = (parseInt(this.container.style.width) + (containerBorderWidth * 2) - offsetCorner - (containerBorderWidth * 2)) + 'px';
  e_resize.style.left = (parseInt(this.container.style.width) + (containerBorderWidth * 2) - offsetCorner - (containerBorderWidth * 2)) + 'px';
  se_resize.style.left = (parseInt(this.container.style.width) + (containerBorderWidth * 2) - offsetCorner - (containerBorderWidth * 2)) + 'px';
  se_resize.style.top = (parseInt(this.container.style.height) + (containerBorderWidth * 2) - offsetCorner - (containerBorderWidth * 2)) + 'px';
  s_resize.style.top = (parseInt(this.container.style.height) + (containerBorderWidth * 2) - offsetCorner - (containerBorderWidth * 2)) + 'px';
  sw_resize.style.top = (parseInt(this.container.style.height) + (containerBorderWidth * 2) - offsetCorner - (containerBorderWidth * 2)) + 'px';
  w_resize.style.top = (Math.floor((parseInt(this.container.style.height) + containerBorderWidth) / 2) - offsetCorner - (containerBorderWidth * 2)) + 'px';
  e_resize.style.top = (Math.floor((parseInt(this.container.style.height) + containerBorderWidth) / 2) - offsetCorner - (containerBorderWidth * 2)) + 'px';
};

FarPoint.Web.Spread.SpreadChart.prototype.highlightChart = function() {
  var chartcssClass = this.container.getAttribute("selectedCssClass");
  if (chartcssClass != null && chartcssClass.length > 0) {
    this.container.className = chartcssClass;
  }
  else {
    this.container.style.border = "double 1px red"
  }

  var children;
  if (typeof this.container.children == "undefined") {
    // mozilla
    children = this.container.childNodes;
  }
  else {
    // IE
    children = this.container.children;
  }
  for (var i = 0; i < children.length; i++) {
    if (children[i].id != null && children[i].id.indexOf("-resize") > 0) {
      children[i].style.display = '';
    }
  }

  chartObj = this;
  this.isActived = true;
};

FarPoint.Web.Spread.SpreadChart.prototype.normalChart = function() {
  var chartcssClass = this.container.getAttribute("selectedCssClass");
  if (chartcssClass != null && chartcssClass.length > 0) {
    this.container.className = "";
  }
  else {
    this.container.style.border = "none"
  }

  var children;
  if (typeof this.container.children == "undefined") {
    // mozilla
    children = this.container.childNodes;
  }
  else {
    // IE
    children = this.container.children;
  }
  for (var i = 0; i < children.length; i++) {
    if (children[i].id != null && children[i].id.indexOf("-resize") > 0) {
      children[i].style.display = 'none';
    }
  }

  //99915941 CoreyKou 2010.05.05
  this.container.removeAttribute("isActive");
  this.isActived = false;
};

FarPoint.Web.Spread.SpreadChart.prototype.setChartLocation = function(chartInfo, left, top) {
  if (chartInfo == null)
    return;
  //>>#99915912 - Jeff 2010/05/05
  if (this.chartSpread.virtualPaging == "true" && this.chartSpread.virtualTop > 0)
    top = top - this.chartSpread.virtualTop;
  //<<#99915912 - Jeff 2010/05/05
  var node = chartInfo.getElementsByTagName("location")[0];
  if (document.all != null) {
    if (node == null) {
      node = this.tableChartData.createNode("element", "location", "");
    }
    node.text = left + "," + top;
  }
  else {
    if (node == null) {
      node = document.createElement("location");
    }
    node.innerHTML = left + "," + top;
  }
  chartInfo.appendChild(node);
  if (FpChartUtil.isIE()) {
    this.chartSpread.UpdatePostbackData();
  }
  else {
    the_fpSpread.UpdatePostbackData(this.chartSpread);
  }
};

FarPoint.Web.Spread.SpreadChart.prototype.setChartSize = function(chartInfo, width, height) {
  if (chartInfo == null)
    return;
  var node = chartInfo.getElementsByTagName("size")[0];
  if (document.all != null) {
    if (node == null) {
      node = this.tableChartData.createNode("element", "size", "");
    }
    node.text = width + "," + height;
  }
  else {
    if (node == null) {
      node = document.createElement("size");
    }
    node.innerHTML = width + "," + height;
  }
  chartInfo.appendChild(node);
};

FarPoint.Web.Spread.SpreadChart.prototype.attachEvent = function(target, eventName, handler, sender, argsObject) {
  if (target == null || eventName == null || handler == null)
    return;

  var eventHandler = function(e) {
    e.sender = sender;
    e.args = argsObject;

    handler.call(target, e);
  }

  var targetId = target.id;

  if (targetId == null && target.nodeName == "#document") {
    targetId = "document";
  }
  var handlerName = sender.chartID + ":" + targetId + ":" + eventName;
  var handlerList = this.eventHandlers[handlerName];

  if (handlerList == null) {
    handlerList = {};
    this.eventHandlers[handlerName] = handlerList;
  }

  if (handlerList[handler.toString()] == null) {
    handlerList[handler.toString()] = eventHandler;

    if (target.addEventListener != null) {
      target.addEventListener(eventName, eventHandler, false);
    }
    else
      if (target.attachEvent != null) {
      target.attachEvent("on" + eventName, eventHandler);
    }
  }
};

FarPoint.Web.Spread.SpreadChart.prototype.detachEvent = function(target, eventName, handler, sender) {
  if (target == null || eventName == null || handler == null || this.eventHandlers == null)
    return;

  var targetId = target.id;

  if (targetId == null && target.nodeName == "#document") {
    targetId = "document";
  }
  var handlerName = sender.chartID + ":" + targetId + ":" + eventName;
  var handlerList = this.eventHandlers[handlerName];

  if (handlerList == null)
    return;

  eventHandler = handlerList[handler.toString()];

  if (eventHandler != null) {
    if (target.removeEventListener != null) {
      target.removeEventListener(eventName, eventHandler, false);
    }
    else
      if (target.detachEvent != null) {
      target.detachEvent("on" + eventName, eventHandler);
    }
    handlerList[handler.toString()] = null;
  }
};

FarPoint.Web.Spread.SpreadChart.prototype.fireEvent = function(target, event, left, top, width, height) {
  if (target == null) {
    return;
  }
  if (document.createEvent) {// DOM event model
    var e = document.createEvent("Events");
    e.initEvent(event, true, false);
  }
  else
    if (document.createEventObject) { // IE event model
    var e = document.createEventObject();
  }
  else
    return;

  e.chartObj = this;
  e.top = top;
  e.left = left;
  e.width = width;
  e.height = height;

  if (target.dispatchEvent)
    target.dispatchEvent(e); // DOM
  else
    if (target.fireEvent)
    target.fireEvent("on" + event, e); // IE
};

FarPoint.Web.Spread.SpreadChart.prototype.updateChartImgitem = function() {
  if (this.container.getAttribute("imageDirty") == "true") {
    chartImg = this.getChart();

    if (this.chartSpread.inDesign)
      chartImg.src = chartImg.src;
    else
      chartImg.src = chartImg.src + "#" + Math.random();
  }
};

FarPoint.Web.Spread.SpreadChart.prototype.isLeftButtonClicked = function(event) {
  var chartObj = event.sender;
  if (FpChartUtil.isIE()) {
    return event.button == 1;
  }
  else {
    return event.button == 0;
  }
}

FarPoint.Web.Spread.SpreadChart.prototype.dispose = function() {
  this.detachEvent(this.container, "mousedown", this.containerMousedown, this);
  if (this.container.getAttribute("moveChart") != "false") {
    this.detachEvent(document, "mouseup", this.endDragChart, this);
    this.detachEvent(this.container, "mouseup", this.endDragChart, this);
    this.detachEvent(this.container, "keydown", this.chartKeyDown, this);
  }
};

// Raw Events.
FarPoint.Web.Spread.SpreadChart.prototype.containerMousedown = function(event) {
  var chartObj = event.sender;
  chartObj.chartSpread.SetActiveChart(chartObj.chartID); //99915923 Justin 2010/05/11
  with (chartObj) {
    if (!chartObj.isLeftButtonClicked(event) || container.isResize == true) {
      return;
    }
    if (container.getAttribute("moveChart") != "false") {
      startDragChart(event);
    }
  }
};

FarPoint.Web.Spread.SpreadChart.prototype.startResizeChart = function(event) {
  var chartObj = event.sender;
  with (chartObj) {
    var corner = this;
    container.isDrag == false;
    container.isResize = true;

    attachEvent(document, "mouseup", endResizeChart, chartObj, null);
    attachEvent(document, "click", endResizeChart, chartObj, null);
    attachEvent(document, "selectstart", cancelDefault, chartObj, null);

    corner.isResize = true;
    corner.startX = event.clientX;
    corner.startY = event.clientY;
    if (typeof corner.setCapture != "undefined") {
      corner.setCapture();
    }

    attachEvent(corner, "mousemove", resizeChart, chartObj, null);
    attachEvent(document, "mousemove", resizeChart, chartObj, null);
    currentResizeCorner = corner;
  }
};

FarPoint.Web.Spread.SpreadChart.prototype.resizeChart = function(event) {
  var chartObj = event.sender;

  with (chartObj) {
    if (!chartObj.isLeftButtonClicked(event)) {
      return;
    }

    var corner = currentResizeCorner;

    if (corner == null)
      return;

    var resizeType = corner.id;

    //99915104 Jusitn 2010/05/10: create object o manage style info of chart
    var chartStyleInfo = chartObj.chartStyleInfo;
    var minWidth = Math.max(chartStyleInfo.getStyleWidth(), 18);
    var minHeight = Math.max(chartStyleInfo.getStyleHeight(), 18);
    if (corner == null)
      return;
    if (container.isProcessingResize == true)
      return;
    container.isProcessingResize = true;
    //99916057 CoreyKou 20100508
    container.style.cursor = corner.style.cursor;
    var currentInfo = {
      left: parseInt(container.style.left),
      top: parseInt(container.style.top),
      width: container.clientWidth,
      height: container.clientHeight
    }
    var newInfo = {
      left: currentInfo.left,
      top: currentInfo.top,
      width: currentInfo.width,
      height: currentInfo.height
    }

    if (resizeType == 'e-resize' || resizeType == 'ne-resize' || resizeType == 'se-resize') { /* East resize */
      newInfo.width = Math.max(minWidth, (parseInt(container.style.width) + event.clientX - corner.startX));
    }
    if (resizeType == 's-resize' || resizeType == 'sw-resize' || resizeType == 'se-resize') {
      newInfo.height = Math.max(minHeight, (parseInt(container.style.height) + event.clientY - corner.startY));
    }
    if (resizeType == 'n-resize' || resizeType == 'nw-resize' || resizeType == 'ne-resize') {
      var newTop = Math.max(0, (parseInt(container.style.top) + event.clientY - corner.startY));
      newInfo.height += (currentInfo.top - newTop);
      newInfo.top = newTop;
    }
    if (resizeType == 'w-resize' || resizeType == 'sw-resize' || resizeType == 'nw-resize') {
      var newLeft = Math.max(0, (parseInt(container.style.left) + event.clientX - corner.startX));
      newInfo.width += (currentInfo.left - newLeft);
      newInfo.left = newLeft;
    }
    if (newInfo.height <= minHeight)
      newInfo.height = minHeight + 2; //add some for container border
    if (newInfo.width <= minWidth)
      newInfo.width = minWidth + 2;
    if (newInfo) {
      container.style.left = newInfo.left + 'px';
      container.style.top = newInfo.top + 'px';
      container.style.width = newInfo.width + 'px';
      container.style.height = newInfo.height + 'px';

      chartStyleInfo.setInnerSize(newInfo.width, newInfo.height); //99915104
    }

    setResizeCornerPosition();
    corner.startX = event.clientX;
    corner.startY = event.clientY;
    cancelDefault(event);
    // 99915958 Corey 20100504
    if (FpChartUtil.isIE()) {
      chartObj.chartSpread.ResumeLayout(true);
    }
    container.isProcessingResize = false;
  }
};

FarPoint.Web.Spread.SpreadChart.prototype.endResizeChart = function(event) {
  var chartObj = event.sender;
  with (chartObj) {
    detachEvent(document, "mousemove", resizeChart, chartObj);
    detachEvent(document, "mouseup", endResizeChart, chartObj);
    detachEvent(document, "click", endResizeChart, chartObj);
    detachEvent(document, "selectstart", cancelDefault, chartObj);
    container.isResize = false;
    //99916057 CoreyKou 20100508
    container.style.cursor = "default";
    var corner = currentResizeCorner;
    if (corner != null && corner.isResize != null && corner.isResize == true) {
      corner.isResize = false;
      detachEvent(corner, "mousemove", resizeChart, chartObj);
      if (typeof corner.releaseCapture != "undefined") {
        corner.releaseCapture();
      }
      var chartInfo = addChartInfo();
      var left = parseInt(container.style.left);
      var top = parseInt(container.style.top);
      setChartLocation(chartInfo, left, top);

      var width = parseInt(chart.width);
      var height = parseInt(chart.height);
      setChartSize(chartInfo, width, height);
      if (FpChartUtil.isIE()) {
        chartSpread.RefreshChart();
      }
      else {
        the_fpSpread.RefreshChart(chartSpread);
      }

      fireEvent(container, "resize", left, top, width, height);
    }
    // 99915958 Corey 20100504
    if (FpChartUtil.isIE()) {
      chartObj.chartSpread.ResumeLayout(true);
    }
    currentResizeCorner = null;
    cancelDefault(event);
  }
};

FarPoint.Web.Spread.SpreadChart.prototype.startDragChart = function(event) {
  this.container.style.cursor = "move";
  this.container.isDrag = true;
  this.container.startX = event.clientX;
  this.container.startY = event.clientY;
  this.attachEvent(this.container, "mousemove", this.dragChart, this, null);
  if (typeof this.container.setCapture != "undefined") {
    this.container.setCapture();
  }

  if (!FpChartUtil.isIE()) {
    this.container.setAttribute("tabindex", 0);
  }

  this.attachEvent(document, "mousemove", this.dragChart, this, null);
  this.attachEvent(document, "selectstart", this.cancelDefault, this, null);
};

FarPoint.Web.Spread.SpreadChart.prototype.dragChart = function(event) {
  var chartObj = event.sender;
  with (chartObj) {
    if (!chartObj.isLeftButtonClicked(event)) {
      chartObj.endDragChart(event);
      return;
    }

    if (container.isDrag != null && container.isDrag == true) {
      container.style.left = (parseInt(container.style.left) + event.clientX - container.startX) + 'px';
      container.style.top = (parseInt(container.style.top) + event.clientY - container.startY) + 'px';
      container.startX = event.clientX;
      container.startY = event.clientY;

      chartObj.stopVirtualPaging(); //#99915912 - Jeff 2010/04/29
      var view = document.getElementById(chartSpread.id + "_view");
      fireEvent(view, "scroll");
      chartObj.startVirtualPaging(); //#99915912 - Jeff 2010/04/29
    }
  }
};

FarPoint.Web.Spread.SpreadChart.prototype.chartKeyDown = function(event) {
  var chartObj = event.sender;
  with (chartObj) {
    if (event.keyCode == 38) {
      container.style.top = (parseInt(container.style.top + 0) - 1) + 'px';
    }
    else
      if (event.keyCode == 40) {
      container.style.top = (parseInt(container.style.top + 0) + 1) + 'px';
    }
    else
      if (event.keyCode == 37) {
      container.style.left = (parseInt(container.style.left + 0) - 1) + 'px';
    }
    else
      if (event.keyCode == 39) {
      container.style.left = (parseInt(container.style.left + 0) + 1) + 'px';
    }
    var chartInfo = addChartInfo();
    setChartLocation(chartInfo, parseInt(container.style.left), parseInt(container.style.top));
    cancelDefault(event);

    chartObj.stopVirtualPaging(); //#99915912 - Jeff 2010/04/29
    // Resize Spread
    if (FpChartUtil.isIE()) {
      chartObj.chartSpread.ResumeLayout(true);
    }
    else {
      chartObj.chartSpread.SizeSpread(chartObj.chartSpread);
    }
    chartObj.startVirtualPaging(); //#99915912 - Jeff 2010/04/29
  }
  return false;
};

FarPoint.Web.Spread.SpreadChart.prototype.endDragChart = function(event) {
  var chartObj = event.sender;
  with (chartObj) {
    if (container.isDrag != null && container.isDrag == true) {
      container.style.cursor = "default";
      container.isDrag = false;
      if (typeof container.releaseCapture != "undefined") {
        container.releaseCapture();
      }
      detachEvent(container, "mousemove", dragChart, chartObj);
      detachEvent(document, "mousemove", dragChart, chartObj);
      detachEvent(document, "selectstart", cancelDefault, chartObj);
      cancelDefault(event);
      var chartInfo = addChartInfo();
      var left = parseInt(container.style.left);
      var top = parseInt(container.style.top);
      setChartLocation(chartInfo, left, top);
      fireEvent(container, "move", left, top);

      // Resize Spread
      chartObj.stopVirtualPaging(); //#99915912 - Jeff 2010/04/29
      if (FpChartUtil.isIE()) {
        chartObj.chartSpread.ResumeLayout(true);
      }
      else {
        chartObj.chartSpread.SizeSpread(chartObj.chartSpread);
      }
      chartObj.startVirtualPaging(); //#99915912 - Jeff 2010/04/29
    }
  }
};

//>>99915104 Justin 2010/05/10
//
//Helper class contains information about style of chart
//
FarPoint.Web.Spread.SpreadChartStyleInfo = function(spreadChart) {
  this.spreadChart = spreadChart
  this.init();
}

FarPoint.Web.Spread.SpreadChartStyleInfo.prototype.init = function() {
  var chartImage = this.getChartImage();
  var style = chartImage.style;
  this.width = chartImage.width;
  this.height = chartImage.height;
  this.border = {
    top: style.borderTopWidth != '' ? parseInt(style.borderTopWidth) : 0,
    right: style.borderRightWidth != '' ? parseInt(style.borderRightWidth) : 0,
    bottom: style.borderBottomWidth != '' ? parseInt(style.borderBottomWidth) : 0,
    left: style.borderLeftWidth != '' ? parseInt(style.borderLeftWidth) : 0
  };
  this.margin = {
    top: style.marginTop != '' ? parseInt(style.marginTop) : 0,
    right: style.marginRight != '' ? parseInt(style.marginRight) : 0,
    bottom: style.marginBottom != '' ? parseInt(style.marginBottom) : 0,
    left: style.marginLeft != '' ? parseInt(style.marginLeft) : 0
  };
  this.padding = {
    top: style.paddingTop != '' ? parseInt(style.paddingTop) : 0,
    right: style.paddingRight != '' ? parseInt(style.paddingRight) : 0,
    bottom: style.paddingBottom != '' ? parseInt(style.paddingBottom) : 0,
    left: style.paddingLeft != '' ? parseInt(style.paddingLeft) : 0
  };
}

FarPoint.Web.Spread.SpreadChartStyleInfo.prototype.getChartImage = function() {
  return this.spreadChart.getChart();
}

FarPoint.Web.Spread.SpreadChartStyleInfo.prototype.getStyleWidth = function() {
  return (this.border.left + this.border.right) + (this.margin.left + this.margin.right) + (this.padding.left + this.padding.right);
}

FarPoint.Web.Spread.SpreadChartStyleInfo.prototype.getTotalWidth = function() {
  return this.width + this.getStyleWidth();
}

FarPoint.Web.Spread.SpreadChartStyleInfo.prototype.getStyleHeight = function() {
  return (this.border.top + this.border.bottom) + (this.margin.top + this.margin.bottom) + (this.padding.top + this.padding.bottom);
}

FarPoint.Web.Spread.SpreadChartStyleInfo.prototype.getTotalHeight = function() {
  return this.height + this.getStyleHeight();
}

FarPoint.Web.Spread.SpreadChartStyleInfo.prototype.setInnerSize = function(w, h) {
  var chartImage = this.getChartImage();
  chartImage.style.width = Math.max((w - this.getStyleWidth()), 1) + 'px';
  chartImage.style.height = Math.max((h - this.getStyleHeight()), 1) + 'px';
  this.init();
}
//<<99915104
//
//Helper class for performing common funtionality
//
FarPoint.Web.Spread.ChartUtil = function() {
  this.isIE = function() {
    return this.checkBrowserByName("IE");
  };

  this.checkBrowserByName = function(browsername, version) {
    // Check browser version
    var ua = window.navigator.userAgent;
    var rst = false;
    var bn = ("" + browsername).toLowerCase();
    if ((bn.indexOf("ms") >= 0) || (bn.indexOf("msie") >= 0) || (bn.indexOf("ie") >= 0))
      rst = (ua.indexOf("MSIE") >= 1);
    else
      if ((bn.indexOf("safari") >= 0) || (bn.indexOf("apple") >= 0))
      rst = (ua.indexOf("Safari") >= 1);
    else
      if ((bn.indexOf("ff") >= 0) || (bn.indexOf("firefox") >= 0))
      rst = (ua.indexOf("Firefox") >= 1);
    return rst;
  };
}
FpChartUtil = new FarPoint.Web.Spread.ChartUtil();
