/* ***********************************************************
DHTML.js
Javascript for viewer.asp page in Map Viewer 3rd Edition
by Howie Sternberg (howies@snet.net)

Map Viewer is placed in the public domain and is "Freeware". 
Map Viewer may be freely used and redistributed, is provided 
"AS-IS" without warranty of any kind, and there is no technical 
support provided.
--------------------------------------------------------------
Browser compatibility - Supports W3C DOM compatible browsers such
as IE 5, 5.5, and 6; Netscape 7 and Mozilla FireFox 1. Does not 
support IE 4 and Netscape Navigator 4. Support is based on browser
capabilities rather than browser version. Compatibility detected 
by testing for the presence of an object, property or method before
using it in a script.
--------------------------------------------------------------
Acknowledgements - Techniques for cross-platform object positioning
are from "Dynamic HTML:The Definitive Reference" 2nd Edition
by Danny Goodman (http://www.dannyg.com), published by O'Reilly &
Associates (http://www.oreilly.com) ISBN 0-596-00316-1.
--------------------------------------------------------------
History
May 2004, Initial code
Sep 2004, Revised for Map Viewer 2nd Edition
May 2005, Revised for Map Viewer 3rd Edition to only support  
		  W3C DOM compatible browsers 
************************************************************ */

// Global variables
var isCSS, isW3C, isIE, isIE6CSS, isWin; // browser and OS

// Set mouse event handlers and create style objects
function canSupportDHTML() {
	if (document.getElementById) {
        isCSS = (document.body && document.body.style) ? true : false;
        isW3C = (isCSS && document.getElementById) ? true : false;
		isIE6CSS = (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false;
		isIE = navigator.appName.indexOf("Microsoft") >= 0 ? true : false;
		isWin = navigator.userAgent.indexOf("win") ? true : false;
		return true;
	} else {
		return false;
	}
}

// Convert object name string or object reference into a valid element object reference
function getObject(obj) {
    var theObj;
    if (typeof obj == "string") {
        if (isW3C) {
            theObj = document.getElementById(obj);
        }
    } else {
        // pass through object reference
        theObj = obj;
    }
    return theObj;
}

// Convert object name string or object reference into a valid object style reference
function getObjectStyle(obj) {
    var theObj;
    if (typeof obj == "string") {
		theObj = getObject(obj);
		if (theObj && isCSS) {			
        	theObj = theObj.style;
		}
    } else {
        // pass through object reference
        theObj = obj;
    }
    return theObj;
}

// Set the visibility of an object to visible
function showObject(obj) {
	obj.visibility = "visible";
}

// Set the visibility of an object to hidden
function hideObject(obj) {
	obj.visibility = "hidden";
}

// Position an object at a specific pixel coordinate
function moveObject(obj, x, y) {
	obj.left = x + "px";
	obj.top = y + "px";
}

// Set the width and height of an object
function sizeObject(obj, w, h) {
	obj.width = w + "px";
	obj.height = h + "px";
}

// Position an object at a specific pixel coordinate and set width and height
function placeObject(obj, x, y, w, h) {
	obj.left = x + "px";
	obj.top = y + "px";
	obj.width = w + "px";
	obj.height = h + "px";
}

// Retrieve the rendered width of an element
function getObjectWidth(obj)  {
    var elem = getObject(obj);
    var result = 0;
    if (elem.offsetWidth) {
        result = elem.offsetWidth;
    } else if (elem.clip && elem.clip.width) {
        result = elem.clip.width;
    } else if (elem.style && elem.style.pixelWidth) {
        result = elem.style.pixelWidth;
    }
    return parseInt(result);
}

// Retrieve the rendered height of an element
function getObjectHeight(obj)  {
    var elem = getObject(obj);
    var result = 0;
    if (elem.offsetHeight) {
        result = elem.offsetHeight;
    } else if (elem.clip && elem.clip.height) {
        result = elem.clip.height;
    } else if (elem.style && elem.style.pixelHeight) {
        result = elem.style.pixelHeight;
    }
    return parseInt(result);
}

// Retrieve horizontal (x) coordinate of mouse eevent within "mapEvent" element's rectangle.
function getEventX(evt) {
	var x = new Number (0);
	if (evt.x) {				// IE					
		x = evt.x;
	} else if (evt.layerX) {	// NS
		x = evt.layerX;
	}
	return x;
}

// Retrieve vertical (y) coordinate of mouse event within "mapEvent" element's rectangle.
function getEventY(evt) {
	var y = new Number (0);
	if (evt.y) {				// IE				
		y = evt.y;
	} else if (evt.layerY){		// NS
		y = evt.layerY;
	}
	return y;
}

function showDownloadMessage() {
	if (document.getElementById("mapMessage")) {
		document.getElementById("mapMessage").style.visibility = "visible"
	}
}

function hideDownloadMessage() {
	if (document.getElementById("mapMessage")) {
		document.getElementById("mapMessage").style.visibility = "hidden"
	}
}