// **********************************************************************************************
//
// Project:      LA CITY PLANNING ZIMAS IMS
// Version:      Release 1.0
//
// File:         dhtml.js
// Language:     JavaScript 1.2
// Created:      ?
// Author:       ESRI, modified by James Richards, Daniel Elroi, LA DCP
// Description:  Contains all of the generic helper functions for manipulating DHTML Layers.
//               Specific helper functions for manipulating layers as part of panning, zooming
//               etc. are found in functions.js
// Dependencies: functions.js
// Issues:       
//
// **********************************************************************************************


// ^*********************************************************************************************
//
// Project:      LA CITY PLANNING ZIMAS IMS
// Version:      Release 1.0
//
// Script:       boxIt(m_iTrackingBoxLeft, m_iTrackingBoxTop, m_iTrackingBoxRight, m_iTrackingBoxBottom)
// Type:         Subroutine
// Description:  Clips and displays the four layers that make up the rubberband box
// Called by:    startTrackingBox
// Arguments in: iLeft - Left side of box in screen pixels (inner measure)
//               iTop - Top side of box in screen pixels (inner measure)
//               iRight - Right side of box in screen pixels (inner measure)
//               iBottom - Bottom side of box in screen pixels (inner measure)
// Globals in:   m_iHorizontalPos
//               m_iVerticalPos
//               OVBOXSIZE
// Calls:        clipLayer
//               showLayer
// Output:       
// Returns:      N/A
// Globals out:  m_bPanning
//               m_iMouseX
//               m_iMouseY
// History:      Original - ESRI ArcIMS 4.0 HTML Viewer
//               12/10/02: Daniel Elroi, LA DCP: Modified for ZIMAS variables
//
// v*********************************************************************************************
function boxIt(iLeft,iTop,iRight,iBottom) {
  iTop = iTop + m_iVerticalPos;
  iBottom = iBottom + m_iVerticalPos;
  iLeft = iLeft + m_iHorizontalPos;
  iRight = iRight + m_iHorizontalPos;

  clipLayer("trackingBoxTop", iLeft, iTop, iRight, iTop + OVBOXSIZE);
  clipLayer("trackingBoxLeft", iLeft, iTop, iLeft + OVBOXSIZE, iBottom);
  clipLayer("trackingBoxRight", iRight - OVBOXSIZE, iTop, iRight, iBottom);
  clipLayer("trackingBoxBottom", iLeft, iBottom - OVBOXSIZE, iRight, iBottom);	
  showLayer("trackingBoxTop");
  showLayer("trackingBoxLeft");
  showLayer("trackingBoxRight");
  showLayer("trackingBoxBottom");
}










// ^*********************************************************************************************
//
// Project:      LA CITY PLANNING ZIMAS IMS
// Version:      Release 1.0
//
// Script:       clipLayer(sName,iClipLeft,iClipTop,iClipRight,iClipBottom)
// Type:         Subroutine
// Description:  Function to clip the display of a DHTML layer
// Called by:    setClip
// Arguments in: sName - Layer name
//               iClipLeft - Outer left edge of rubberband box
//               iClipTop - Outer top edge of rubberband box
//               iClipRight - Outer right edge of rubberband box
//               iClipBottom - Outer bottom edge of rubberband box
// Globals in:   
// Calls:        
// Output:       
// Returns:      
// Globals out:  
// History:      Original - ESRI ArcIMS 4.0 HTML Viewer
//               12/11/02: Daniel Elroi, LA DCP: Modified for ZIMAS variables
//
// v*********************************************************************************************

function clipLayer(sName, iClipLeft, iClipTop, iClipRight, iClipBottom) {		
  var layer = getLayer(sName);
  var iNewWidth = iClipRight - iClipLeft;
  var iNewHeight = iClipBottom - iClipTop;
  layer.height = iNewHeight;
  layer.width	= iNewWidth;
  layer.top	= iClipTop  + "px";
  layer.left	= iClipLeft + "px";
}










// ^*********************************************************************************************
//
// Project:      LA CITY PLANNING ZIMAS IMS
// Version:      Release 1.0
//
// Script:       clipLayer2(sName, iClipLeft, iClipTop, iClipRight, iClipBottom)
// Type:         Subroutine
// Description:  Clip layer display to iClipLeft, iClipTop, iClipRight, iClipBottom 
//               (Not working with Mozilla Milestone 12 (Nav5))
// Called by:    panMouse
// Arguments in: sName - Layer name
//               iClipLeft - Outer left edge of rubberband box
//               iClipTop - Outer top edge of rubberband box
//               iClipRight - Outer right edge of rubberband box
//               iClipBottom - Outer bottom edge of rubberband box
// Globals in:   
// Calls:        
// Output:       
// Returns:      
// Globals out:  
// History:      Original - ESRI ArcIMS 4.0 HTML Viewer
//               12/10/02: Daniel Elroi, LA DCP: Modified for ZIMAS variables
//
// v*********************************************************************************************
function clipLayer2(sName, iClipLeft, iClipTop, iClipRight, iClipBottom) {
  var objLayer = getLayer(sName);
  objLayer.clip = 'rect(' + iClipTop + ' ' +  iClipRight + ' ' + iClipBottom + ' ' + iClipLeft +')';
}










// ^*********************************************************************************************
//
// Project:      LA CITY PLANNING ZIMAS IMS
// Version:      Release 1.0
//
// Script:       createLayer(sName, iLeft, iTop, iWidth, iHeight, bVisible, sContent)
// Type:         Subroutine
// Description:  Create a DHTML layer
// Called by:    map.asp
// Arguments in: sName - Name of new layer to be created
//               iTop - Top side of layer in screen pixels (inner measure)
//               iLeft - Left side of layer in screen pixels (inner measure)
//               iWidth - Width of layer in screen pixels
//               iHeight - Height of layer in screen pixels
//               bVisible - Toggle to make layer visible
//               sContent - Contents of the layers
// Globals in:   
// Calls:        
// Output:       
// Returns:      
// Globals out:  
// History:      Original - ESRI ArcIMS 4.0 HTML Viewer
//               12/13/02: Daniel Elroi, LA DCP: Modified for ZIMAS variables
//
// v*********************************************************************************************
function createLayer(sName, iLeft, iTop, iWidth, iHeight, bVisible, sContent) {
  var layer;
  document.writeln('<div id="' + sName + '" style="position:absolute; overflow:hidden; left:' + iLeft + 'px; top:' + iTop + 'px; width:' + iWidth + 'px; height:' + iHeight + 'px;' + '; z-index:1; visibility:' + (bVisible ? 'visible;' : 'hidden;') +  '">');
  document.writeln(sContent);
  document.writeln('</div>');
}









// ^*********************************************************************************************
//
// Project:      LA CITY PLANNING ZIMAS IMS
// Version:      Release 1.0
//
// Script:       createLayerDynamic(sName, iLeft, iTop, iWidth, iHeight, bVisible, sContent)
// Type:         Subroutine
// Description:  Create a DHTML layer after page exists
// Called by:    map.asp
// Arguments in: sName - Name of new layer to be created
//               iTop - Top side of layer in screen pixels (inner measure)
//               iLeft - Left side of layer in screen pixels (inner measure)
//               iWidth - Width of layer in screen pixels
//               iHeight - Height of layer in screen pixels
//               bVisible - Toggle to make layer visible
//               sContent - Contents of the layers
// Globals in:   
// Calls:        
// Output:       
// Returns:      
// Globals out:  
// History:      Original - ESRI ArcIMS 4.0 HTML Viewer
//               12/13/02: Daniel Elroi, LA DCP: Modified for ZIMAS variables
//
// v*********************************************************************************************
function createLayerDynamic(sName, iLeft, iTop, iWidth, iHeight, bVisible, sContent) {
  var objDiv = document.createElement('div');
  objDiv.id = sName;
  objDiv.style = 'position:absolute; overflow:hidden; left:' + iLeft + 'px; top:' + iTop + 'px; width:' + iWidth + 'px; height:' + iHeight + 'px;' + '; z-index:1; visibility:' + (bVisible ? 'visible;' : 'hidden;') +  '';
  window.document.body.appendChild(objDiv);
}












// ^*********************************************************************************************
//
// Project:      LA CITY PLANNING ZIMAS IMS
// Version:      Release 1.0
//
// Script:       getLayer(sName)
// Type:         Function
// Description:  Gets and returns layer sName
// Called by:    clipLayer2
// Arguments in: sName - Name of layer to be retrieved
// Globals in:   
// Calls:        
// Output:       
// Returns:      layer
// Globals out:  
// History:      Original - ESRI ArcIMS 4.0 HTML Viewer
//               12/11/02: Daniel Elroi, LA DCP: Modified for ZIMAS variables
//
// v*********************************************************************************************
function getLayer(sName) {
  if (isIE4) {
    objLayer = eval('document.all.' + sName + '.style');
    return(objLayer);
  } else if (is5up) {
    var theObj = document.getElementById(sName);
    return theObj.style
  }
  else
  return(null);
}










// ^*********************************************************************************************
//
// Project:      LA CITY PLANNING ZIMAS IMS
// Version:      Release 1.0
//
// Script:       hideLayer(sName)
// Type:         Subroutine
// Description:  Toggles layer sName to invisible
// Called by:    stopTrackingBox
// Arguments in: sName - Name of layer to be made visible
// Globals in:   
// Calls:        
// Output:       
// Returns:      
// Globals out:  
// History:      Original - ESRI ArcIMS 4.0 HTML Viewer
//               12/10/02: Daniel Elroi, LA DCP: Modified for ZIMAS variables
//
// v*********************************************************************************************
function hideLayer(sName) {
  var layer = getLayer(sName);		
 	layer.visibility = "hidden";
}










// ^*********************************************************************************************
//
// Project:      LA CITY PLANNING ZIMAS IMS
// Version:      Release 1.0
//
// Script:       moveLayer(sName, iX, iY)
// Type:         Subroutine
// Description:  move layer sName to x,y
// Called by:    startPan, panMouse
// Arguments in: name - Name of main map layer (currently hardcoded to "theMap")
//               iX    - Upper-left X coordinate of map
//               iY    - Upper-left Y coordinate of map
// Globals in:   
// Calls:        
// Output:       Moves layer
// Returns:      
// Globals out:  
// History:      Original - ESRI ArcIMS 4.0 HTML Viewer
//               12/06/02: Daniel Elroi, LA DCP: Modified for ZIMAS variables
//
// v*********************************************************************************************

function moveLayer(sName, iX, iY) {		
  var layer = getLayer(sName);		
  layer.left = iX + "px";
  layer.top  = iY + "px";
}










// ^*********************************************************************************************
//
// Project:      LA CITY PLANNING ZIMAS IMS
// Version:      Release 1.0
//
// Script:       showLayer(sName)
// Type:         Subroutine
// Description:  Toggles layer sName to visible
// Called by:    startTrackingBox
// Arguments in: sName - Name of layer to be made visible
// Globals in:   
// Calls:        
// Output:       
// Returns:      
// Globals out:  
// History:      Original - ESRI ArcIMS 4.0 HTML Viewer
//               12/10/02: Daniel Elroi, LA DCP: Modified for ZIMAS variables
//
// v*********************************************************************************************
function showLayer(sName) {		
  var objLayer = getLayer(sName);		
  objLayer.visibility = "visible";
}











// ^*********************************************************************************************
//
// Project:      LA CITY PLANNING ZIMAS IMS
// Version:      Release 1.0
//
// Script:       setLayerBackgroundColor(sName, sColor)
// Type:         Subroutine
// Description:  Function to set the background color of a DHTML layer
// Called by:    map.asp
// Arguments in: sName - 
//               sColor - 
// Globals in:   
// Calls:        
// Output:       
// Returns:      
// Globals out:  
// History:      Original - 2001: J Richards
//
// v*********************************************************************************************
function setLayerBackgroundColor(sName, sColor)
{
  // Note: sColor is a string hex value, such as "#ff00cc"
  var layer = getLayer(sName);
  if (layer != null) {
    layer.backgroundColor = sColor;
  }
}










// ^*********************************************************************************************
//
// Project:      LA CITY PLANNING ZIMAS IMS
// Version:      Release 1.0
//
// Script:       setLayerVisibility(sName, bVisible)
// Type:         Subroutine
// Description:  Function to set the visibility of a DHTML layer
// Called by:    map.asp
// Arguments in: sName - 
//               bVisible - 
// Globals in:   
// Calls:        getLayer
// Output:       
// Returns:      
// Globals out:  
// History:      Original - 2001: J Richards
//
// v*********************************************************************************************
function setLayerVisibility(sName, bVisible) 
{
  var layer = getLayer(sName);
  if (layer != null) {
    if (bVisible) {
      layer.visibility = "visible";
    }
    else { // not bVisible
      layer.visibility = "hidden";
    }
  }
}








// **********************************************************************************************
// ************************************** END OF SCRIPTS ****************************************
// **********************************************************************************************
