
//  -----------------------------------------------------------------
//    Notes:	The purpose of this Javascript File is to control the div resize of the browser - map image
//
//    Global Variables Delcared:         
//           NONE
//
//    Arguments:   
//    Returns:	N/A
//  		E:\WebSite_Default\ArcIMSFrameWorkSource\ArcIMSFrameWork_MapSize.js
//   -----------------------------------------------------------------
//    Orginization:	City of Asheville IT Services
//    Original Code: 	Dave Michelson 1/31/2006
//    Last Update:	Dave Michelson 1/31/2006
//

  function LoadBMV( mPreXml ){
    writeXMLElements();
    setMapDimensions('map_img',window.mProcessor.document.frmXMLRequest);
    //DoButton('Map Refresh',window.mProcessor.document.frmXMLRequest);
    DoUserSetting('MAPSTART','100',window.mProcessor.document.frmXMLRequest,mPreXml);
    setCanvasSize('mapDraw','mapDraw2','map_Canvas');
    obj = new mapAVL;
    obj.SetZoomToPoint('1','2');
    //alert(obj.GetZoomToPoint());   
  }

  function mapAVL(){
    var MaxX;
    var MaxY;
    var MinX;
    var MinY;
    var Mapscale;
    var ActiveLayer;
    var SelectByAttribute;
    var ZoomToSelect;
    var ZoomX;
    var ZoomY;

    this.GetMaxX = function() { return MaxX; }
    this.GetMaxY = function() { return MaxY; }
    this.GetMinX = function() { return MinX; }
    this.GetMinY = function() { return MinY; }
    this.GetMapScale = function() { return Mapscale; }
    this.GetActiveLayer =  function() { return ActiveLayer; }
    this.GetSelectByAttribute =  function() { return SelectByAttribute; }
    this.GetZoomToSelect =  function() { return ZoomToSelect;}
    this.GetZoomToPoint =  function() { return  ZoomX+','+ZoomY;}

    this.SetMaxX = function(newVal) { MaxX = newVal; }
    this.SetMaxY = function(newVal) { MaxY = newVal; }
    this.SetMinX = function(newVal) { MinX = newVal; }
    this.SetMinY = function(newVal) { MinY = newVal; }
    this.SetMapScale = function(newVal) { Mapscale = newVal; }
    this.SetActiveLayer =  function(newVal) { ActiveLayer = newVal; }
    this.SetSelectByAttribute =  function(newVal) { SelectByAttribute = newVal; }
    this.SetZoomToSelect =  function(newVal) { ZoomToSelect = newVal; }
    this.SetZoomToPoint = function(x,y){ ZoomX = x;ZoomY = y; }
  }

  function ResizeBMV(){
    resizethis('map_img',window.mProcessor.document.frmXMLRequest);
    setCanvasSize('mapDraw','mapDraw2','map_Canvas');
  }

  function getMapXY(xIn,yIn) {
    var mouseX;
    var mouseY;
    var pixelX;
    var pixelY;
    var mapX;
    var mapY;

    mouseX = xIn;
    pixelX = xDistance / (mapWidth);
    mapX = pixelX * mouseX +  Number(minX);
    mouseY = mapHeight - (yIn);
    pixelY = yDistance / mapHeight;
    mapY = pixelY * mouseY + Number(minY);

    var MapDimensions = {
      X: Math.round(mapX*10)/10,
      Y: Math.round(mapY*10)/10
    }   
    return MapDimensions;
  }    

  function getImageXY(e) {
    var mouseX;
    var mouseY;

     if (isNav) {
       mouseX=e.pageX-vSpc;
       mouseY=e.pageY-hSpc;
     } else {
       mouseX=event.clientX-vSpc;
       mouseY=event.clientY-hSpc;
     }
    // subtract offsets from page left and top
    mouseX = mouseX;
    mouseY = mouseY;

   var MapImage = {
     X: mouseX,
     Y: mouseY
   }
  return MapImage;
  }	

  function getPostions( myMapWidth , myMapHeight , myMinX , myMaxX , myMinY , myMaxY ){
    var mMapProps =  GetProperties( mMapName )
    var myMapHeight = mMapProps.height
    var myMapHeight = mMapProps.width

    var mPostions = {
      minX: myMinX,
      maxX: myMaxX,
      minY: myMinY,
      maxY: myMaxY,
      xDistance: Math.abs(myMaxX-myMinY),
      yDistance:  Math.abs(myMaxY-myMinY),
      xHalf: xDistance/2,
      yHalf: yDistance/2,
      mouseX: 0,
      mouseY: 0,
      pixelX: xDistance/myMapHeight,
      pixelY: yDistance/myMapWidth
    }
    return mPostions;
  }

  function setPostion(myMapWidth,myMapHeight,myMinX,myMaxX,myMinY,myMaxY){
    minX = myMinX;
    maxX = myMaxX;
    minY = myMinY;
    maxY = myMaxY;
    xDistance = Math.abs(maxX-minX);
    yDistance = Math.abs(maxY-minY);
    xHalf = xDistance/2;
    yHalf = yDistance/2;
    mouseX = 0;
    mouseY = 0;
    pixelX = xDistance/myMapHeight;
    pixelY = yDistance/myMapWidth;
  }

  function setMapDimensions(MyImageElement,MyXmlRequestor){
    var myXMLRequest;
    if (isNav) { 
      mapWidth = (window.innerWidth-netscapeScrollWidth)-(123);
      mapHeight = (window.innerHeight-netscapeScrollWidth)-(123);
    }else{
      mapWidth = (document.body.clientWidth)-(183); 
      mapHeight = (document.body.clientHeight)-(145);
    }
  
   if (mapWidth < 450){
    mapWidth = 450;
   }

   if (mapHeight < 200){
    mapHeight = 200;
   }

   if (MyXmlRequestor == null){
   }else{
     MyXmlRequestor.XML_MapHeight.value = mapHeight;
     MyXmlRequestor.XML_MapWidth.value = mapWidth;
     setPostion(mapWidth,mapHeight,MyXmlRequestor.XML_MinX.value,MyXmlRequestor.XML_MaxX.value,MyXmlRequestor.XML_MinY.value,MyXmlRequestor.XML_MaxY.value)
   }
  }

  function resizethis(MyImageElement,MyXmlRequestor){
    var myXMLRequest;

    if (isNav) { 
      mapWidth = (window.innerWidth-netscapeScrollWidth)-(123);
      mapHeight = (window.innerHeight-netscapeScrollWidth)-(123);
    }else{
      mapWidth = (document.body.clientWidth)-(183); 
      mapHeight = (document.body.clientHeight)-(145);
    }

   if (mapWidth < 450){
    mapWidth = 450;
   }

   if (mapHeight < 200){
    mapHeight = 200;
   }
   MyXmlRequestor.XML_MapHeight.value = mapHeight;
   MyXmlRequestor.XML_MapWidth.value = mapWidth;
   document.getElementById(MyImageElement).style.height = mapHeight+'px';
   document.getElementById(MyImageElement).style.width = mapWidth+'px';
   setPostion(mapWidth,mapHeight,MyXmlRequestor.XML_MinX.value,MyXmlRequestor.XML_MaxX.value,MyXmlRequestor.XML_MinY.value,MyXmlRequestor.XML_MaxY.value) 
  }

  function setCanvasSize(MapCanvas1,MapCanvas2,MapElement){

    var filterVal = 0.50;
    var widthAdd = 0;
    var TopPX;
    var LeftPX;
    var theTocWidth=0;

    var theTOC = GetProperties('mapTOC');
    var scrollWidth = 15;
    var spaceWidth = 5;

    theTocWidth = Number(theTOC.width.replace('px',''));

    //set for accurate placement of canvas
    if(isNav){
      LeftPX = (theTocWidth + scrollWidth + spaceWidth)-2;
      TopPX = 75;
      widthAdd = (window.innerWidth-theTocWidth-scrollWidth-netscapeScrollWidth-(spaceWidth*5));    
      if(isFireFox){
        LeftPX = (theTocWidth + scrollWidth + spaceWidth)-2;
        TopPX = 75;
        widthAdd = (window.innerWidth-theTocWidth-scrollWidth-netscapeScrollWidth-(spaceWidth*5));
      }
    }else{
      LeftPX = theTocWidth + scrollWidth + spaceWidth;
      TopPX = 83;
      widthAdd = mapWidth-spaceWidth;
    }

    //place canvas 1 user interaction driven shapes
    document.getElementById(MapCanvas1).style.top = TopPX+'px';
    document.getElementById(MapCanvas1).style.left = LeftPX+'px';
    document.getElementById(MapCanvas1).style.height = mapHeight +'px';
    document.getElementById(MapCanvas1).style.width = (widthAdd)+'px';
  
    //place canvas 2 finished user interaction driven shapes
    document.getElementById(MapCanvas2).style.top = TopPX+'px';
    document.getElementById(MapCanvas2).style.left = LeftPX+'px';
    document.getElementById(MapCanvas2).style.height = mapHeight +'px';
    document.getElementById(MapCanvas2).style.width = (widthAdd )+'px';

    //place canvas 2 finished user interaction driven shapes
    document.getElementById(MapElement).style.top = TopPX+'px';
    document.getElementById(MapElement).style.left = LeftPX+'px';
    document.getElementById(MapElement).style.height = mapHeight +'px';
    document.getElementById(MapElement).style.width = (widthAdd )+'px';

    //set toc height
    document.getElementById('mapTOC').style.height = mapHeight+'px';

    //set for accurate shape rendering
    if(isNav){
      vSpc = LeftPX;
      hSpc = TopPX;
      if(isFireFox){    
        vSpc = LeftPX-1;
        hSpc = TopPX-1;
      }
   }else{
      vSpc = LeftPX + 3;
      hSpc = TopPX + 3;
   }

  }

  //get element size
  function getMapSize(MyImageElement) {

    var MapDimensions = {
      iWidth: document.getElementById(MyImageElement).style.width,
      iHeight: document.getElementById(MyImageElement).style.height
    }
    return MapDimensions;
  }

   // move layer to x,y
  function moveIt(name, x, y) {	

    var layer = document.getElementById(name).style;	

    layer.left = x + "px";
    layer.top = y + "px";
  }

   // get properties of element
  function GetProperties(name) {	
	
    var layer = document.getElementById(name).style;	

    var mProperites = {
      left: layer.left,
      top:  layer.top,
      width: layer.width,
      height:  layer.height
    }

    return mProperites;

  }