CoordConvPanel = function (newId, newParent, newXPosition, newYPosition, newZIndex, newWidth, newHeight, newVisibility, newMapObject, newMapId)
{
  if (arguments.length > 0)
    this.init(newId, newParent, newXPosition, newYPosition, newZIndex, newWidth, newHeight, newVisibility, newMapObject, newMapId);
};

CoordConvPanel.prototype = new GuiWidget();
CoordConvPanel.constructor = CoordConvPanel;
CoordConvPanel.superclass = GuiWidget.prototype;
 
CoordConvPanel.prototype.init = function (newId, newParent, newXPosition, newYPosition, newZIndex, newWidth, newHeight, newVisibility,newMapObject, newMapId)
{
  CoordConvPanel.superclass.init.call(this, newId, newParent, newXPosition, newYPosition, newZIndex, newWidth, newHeight, newVisibility, "");
  this.id = newId;

  if (newMapId!=null)
  {
    this.mapObject = OBJECT_MANAGER.getControl(newMapId);
    this.mapId = newMapId;
  }
  else
  {
    this.mapObject = newMapObject;
    this.mapId = newMapObject.id;
  }
  
  this.mapObject.coordConvControl = this;
  this.CoordConvConfig = new Object;
  this.CoordConvRadioButtonGroup = null;
};

CoordConvPanel.prototype.draw = function()
{
  var ypos = 0;
  var htmlString = '';
  this.CoordConvRadioButtonGroup = this.mapObject.mapPanel.toolbarRadioButtonGroup;

  //declare a widget to contain the query panels.  This will be hidden by default
  this.simplePanelWidget = new GuiWidget(this.id+"themeElement", this.element, 0, 0, 0, this.width(), 230, true, "");
    this.headerCaptionElement = new GuiWidget(this.id+"headerCaptionElement", this.simplePanelWidget.element, 0, 0, 0, this.width(), 20, true, "themeGroupHeader");
    this.headerCaptionElement.element.cbe.innerHtml("Coordinate Locator");
    this.formContainer = new GuiWidget (this.id+"formContainer", this.simplePanelWidget.element, 0, 20, 0, this.width(), 110, true, "QueryObjectBottom");
        //this.SP2LLHeader = new GuiWidget(this.id+"SP2LLHeader", this.formContainer.element, 10, 0, 0, this.width()-10, 20, true, "");
        //this.SP2LLHeader.element.cbe.innerHtml('State Plane to Lat/Lon');
        this.SP2LL_LatHeader = new GuiWidget(this.id+"SP2LL_LatHeader", this.formContainer.element, 10, 0, 0, this.width()-10, 20, true, "coordConvCoordinate");
        this.SP2LL_LatHeader.element.cbe.innerHtml('Lat: ');
        this.SP2LL_LonHeader = new GuiWidget(this.id+"SP2LL_LonHeader", this.formContainer.element, 10, 20, 0, this.width()-10, 20, true, "coordConvCoordinate");
        this.SP2LL_LonHeader.element.cbe.innerHtml('Lon: ');
        this.sp2llButton = new RadioButton(this.id+"sp2llButton", this.formContainer.element, 10, 40, 0, 100,20,true,'coordConvSP2LLButton','',this.CoordConvRadioButtonGroup);
        this.sp2llButton.CoordConvPanel = this;
        this.sp2llButton.clickEvent = function(e)
        {
          this.CoordConvPanel.mapObject.mapPanel.clickMode = 'CoordConvSP2LatLon';
        };
        this.clearSP2LLButton = new ImageButton(this.id+"clearSP2LLButton", this.formContainer.element, 10, 65, 0, 100,20,true,'coordConvClearButton','');
        this.clearSP2LLButton.coordConvPanel = this;
        this.clearSP2LLButton.clickEvent = function(e)
        {
          this.coordConvPanel.SP2LL_LatHeader.element.cbe.innerHtml('Lat: ');
          this.coordConvPanel.SP2LL_LonHeader.element.cbe.innerHtml('Lon: ');
        };
  this.height(this.simplePanelWidget.height());
};

CoordConvPanel.prototype.resize = function(newWidth, newHeight)
{
  this.element.cbe.resizeTo(newWidth, this.height());  
};

CoordConvPanel.prototype.callback = function(data, pendingOperation)
{
  if (data != null)
  {
    switch (pendingOperation)
    {
      case 'CoordConvSP2LatLon':
        var LatDMS = this.dmsToStr(this.decdeg_to_dms(data['lat']));
        var LonDMS = this.dmsToStr(this.decdeg_to_dms(data['lon']));
        this.SP2LL_LatHeader.element.cbe.innerHtml('Lat: '+LatDMS);
        this.SP2LL_LonHeader.element.cbe.innerHtml('Lon: '+LonDMS);
        break;
    }
  }
};

CoordConvPanel.prototype.decdeg_to_dms = function(dd)
{
  var D = Math.floor(dd);
  var dm = (dd-D) * 60;
  var M = Math.floor(dm);
  var S = (dm-M) * 60;
  var arr = new Array(D,M,S);
  return(arr);
};

CoordConvPanel.prototype.dmsToStr = function(dmsArray)
{
  var str = dmsArray[0]+'&deg; '+dmsArray[1]+"' "+Math.floor(dmsArray[2]*100)/100+'"';
  return(str);
};

