//  COPYRIGHT © 2006 ESRI
//
//  TRADE SECRETS: ESRI PROPRIETARY AND CONFIDENTIAL
//  Unpublished material - all rights reserved under the
//  Copyright Laws of the United States and applicable international
//  laws, treaties, and conventions.
// 
//  For additional information, contact:
//  Environmental Systems Research Institute, Inc.
//  Attn: Contracts and Legal Services Department
//  380 New York Street
//  Redlands, California, 92373
//  USA
// 
//  email: contracts@esri.com

/*
20050921

// display_maptips.js
*/

var maptipBlankImage = "/aspnet_client/ESRI/WebADF/images/pixel.gif";

var mapTipWidth = 150;
var mapTipHeight = 100;
var mapTipExtendedHeight = 150;
var nextExtendedWindowIndex = 0;
var lastExtendIndex = -1;
var lastHoverIndex = -1;
var lastExtendMapId = "";
var extendVisible = false;
var hoverVisible = false;
var maptipXOffset, maptipYOffset;
var maptipString = "";
var mapTipDragMaxTop = 0;
var mapTipDragMaxBottom = 0;

var clickIconPrompt = "Click icon for more information."
var clickHoverPrompt = "Click pop-up for more information."

var mt_panel = null;
var mt_panelDragIndex = 0;
var mt_delay = 2000;
var mt_checkLoad = null;
var esriMTCloseImage = null;
var esriMTCallbackCount = 0;

var mapTipInit = new Array();

// create a definition object for a MapTips control instance
function createMapTipDefinition(controlID, buddyControlID, defaultImagePath, hoverImagePath, selectImagePath, classPrefix, callbackInvocation, mapTipsString, closeImage) {
	MapTipCollections[controlID] = new MapTipsCollectionObject(controlID, buddyControlID, defaultImagePath, hoverImagePath, selectImagePath, classPrefix, callbackInvocation, closeImage);
	maptips = MapTipCollections[controlID];
	esriMTCloseImage = closeImage;
	MapTipCollectionNames[MapTipCollectionNames.length] = controlID;
	//if (maptipHoverPanel==null){ 	    
	    maptipsActive = true;
	//    addMapTipPanels();
	//}
	if (mapTipsString!=null && mapTipsString.length>0)
	{
	    //window.setTimeout("MapTipCollections['" + controlID + "'].addMapTips(\"" + mapTipsString + "\");", 1000);
	    var initializer = "MapTipCollections['" + controlID + "'].addMapTips(\"" + mapTipsString + "\");";
	    mapTipInit.push(initializer);
	    
	    if (window.addEventListener) window.addEventListener("load",InitializeMapTips,false);
        else if (window.attachEvent) window.attachEvent("onload",InitializeMapTips);
	}
}

// Add map tips
function InitializeMapTips()
{
    for (var i = 0; i < mapTipInit.length; ++i)
    {
        var tipInit = mapTipInit[i];
        if (tipInit != null)
        {
            eval(tipInit);
        }
    }
}

// object for requesting and displaying MapTips
function MapTipsCollectionObject(controlID, buddyControlID, defaultImagePath, hoverImagePath, selectImagePath, classPrefix, callbackInvocation, closeImage) {
	this.id = controlID;
	this.mapId = buddyControlID;
	this.map = null;
	this.defaultImage = defaultImagePath;
	this.hoverImage = hoverImagePath;
	this.clickImage = selectImagePath;
	this.closeImage = closeImage;
	this.classPrefix = classPrefix;
	this.callbackFunctionString = (callbackInvocation==null) ? "" : callbackInvocation;
	this.enabled = true;
	this.extendedVisible = new Array();
	this.divHolder = null;
	this.type = "point";
	this.mapTipItems = new Array();
	this.mapTipItemIDs = new Array();
	this.requestedMapTipTiles = new Object();
	this.appCallbackCount = 0;
	
	this.setMap = function() {
		this.map = Maps[this.mapId];
	}
	
	this.requestMapTips = function(mapId) {
	    if (this.mapId==mapId) {
	        this.setMap();
	        var context = this.id;
	        var argument = "";
	        var s = this.map.getViewTilesString();
	        var mts = s.split("|");
	        var i = 0;
	        for (var i=0;i<mts.length;i++) {
	            if (this.requestedMapTipTiles[mts[i]]==null) {
	                var mtxy = mts[i].split(",");
	                argument = "EventArg=MapTips&column=" + mtxy[0] + "&row=" + mtxy[1];
	                this.requestedMapTipTiles[mts[i]] = mts[i];
    	            
	    // Debug stuff to be removed, or at least commented out
   	    if (checkForFormElement(document, 0, "MapDebugBox")) document.forms[0].MapDebugBox.value += "Request: " + this.id + ": " +  argument + "\n"; 
       	
	                eval(this.callbackFunctionString);
	            }
	        }
	        window.setTimeout("MapTipCollections['" + this.id + "'].createPageDivs();",mt_delay);
	    }
	}
	
	this.addMapTips2 = function(response) {
	    // skip the first three elements
	    var paramArray = response.split(":::");
	    for (var i=3;i<paramArray.length;i++) {
	        if (paramArray[i]!=null && paramArray[i].length>0) {
	            var mt = paramArray[i].split("///");
	            this.mapTipItemIDs[this.mapTipItemIDs.length] = mt[2];
	            //MapTipItemObject(mapId, index, left, top, headerText, content, extendedContent)
	            this.mapTipItems[mt[2]] = new MapTipItemObject(paramArray[1], mt[2], mt[0], mt[1], mt[3], "", mt[4]);
	       } 
	    }
	    this.createPageDivs();
	}

	this.addMapTips = function(response) {
	    if (maptipHoverPanel==null){ 
	        setupMapTipPanels();
	    }
	    // skip the first three elements
	    var paramArray = unescape(response).split(":::");
	    if (this.map==null) this.setMap();
	    if (this.map==null) return;
	    var div = document.getElementById(this.map.maptipDivId);
	    //if (
        this.mapTipItemIDs = new Array();
        this.mapTipItems = null;
        this.mapTipItems = new Array();
        
        this.requestedMapTipTiles = new Object();
		var s = "";
		if (div!=null) {
		    div.style.visibility = "visible";
		    //div.innerHTML = "";
		}
		this.map.getTopLeftTile();
		var left = this.map.currentLeftColumn * this.map.tileWidth + this.map.currentXOffset;
		var top = this.map.currentTopRow * this.map.tileHeight + this.map.currentYOffset;
		var right = left + this.map.viewWidth;
		var bottom = top + this.map.viewHeight;
	    for (var i=3;i<paramArray.length;i++) {
	        if (paramArray[i]!=null && paramArray[i].length>0) {
	            var mt = paramArray[i].split("///");
	            this.mapTipItemIDs[this.mapTipItemIDs.length] = mt[2];
	            //MapTipItemObject(mapId, index, left, top, headerText, content, extendedContent)
	            this.mapTipItems[mt[2]] = new MapTipItemObject(paramArray[1], mt[2], mt[0], mt[1], mt[3], "", mt[4]);
	            //MapTipItemObject(mapId, index, left, top, headerText, content, extendedContent)
	            maptip = this.mapTipItems[mt[2]];
			    x = maptip.left;
			    y = maptip.top;
			    tipId = 'MapTipHotSpot_' + this.id + '_' + maptip.index;
			    //tipId = '<div id="MapTipHotSpotImg_' + this.id + '_' + maptip.index;
    			
			    mtimg = document.getElementById(tipId);
			    //if (x>left && x<right && y>top && y<bottom) {
			        //if (mtimg==null)
			        s += '<div id="' + tipId + '" onmouseover="this.style.cursor=\'pointer\'" onmouseout="MapTipCollections[\'' + this.id + '\'].hide(\'hover\')" onmousedown="MapTipCollections[\'' + this.id + '\'].click(\'' + maptip.index +'\',event)" style="position: absolute; left: ' + (maptip.left - this.map.gridXOffset) + 'px; top: ' + (maptip.top - this.map.gridYOffset) + 'px;"><img id="MapTipHotSpotImg_' + this.id + '_' + maptip.index + '" name="MapTipHotSpotImg_' + this.id + '_' + maptip.index + '" src="' +this.defaultImage + '" alt="" ></div>\n';
			        //s += '<div id="' + tipId + '" onmouseover="MapTipCollections[\'' + this.id + '\'].showTip(\'' + maptip.index +'\',event)" onmouseout="MapTipCollections[\'' + this.id + '\'].hide(\'hover\')" onmousedown="MapTipCollections[\'' + this.id + '\'].click(\'' + maptip.index +'\',event)" style="position: absolute; left: ' + (maptip.left - this.map.gridXOffset) + 'px; top: ' + (maptip.top - this.map.gridYOffset) + 'px;"><img id="MapTipHotSpotImg_' + this.id + '_' + maptip.index + '" name="MapTipHotSpotImg_' + this.id + '_' + maptip.index + '" src="' +this.defaultImage + '" ></div>\n';
			        //s += '<img onmouseover="MapTipCollections[\'' + this.id + '\'].showTip(\'' + maptip.index +'\',event)" onmouseout="MapTipCollections[\'' + this.id + '\'].hide(\'hover\')" onmousedown="MapTipCollections[\'' + this.id + '\'].click(\'' + maptip.index +'\',event)" style="position: absolute; left: ' + maptip.left + 'px; top: ' + maptip.top + 'px;" id="' + tipId + '" name="' + tipId + '" src="' +this.defaultImage + '" >\n';
		            this.extendedVisible[maptip.index] = false;
		        //}
		     }
	    }
		if (s.length>0) {
		    if (div!=null) {
		        div.style.display = "";
		        if (esriMTCallbackCount == esriCurrentResponseCount) {
		            var s2 = div.innerHTML;
		            div.innerHTML = s2 + s;
		        } else 
		            div.innerHTML = s; 
		    }
		}
        //else if ( div != null ) // Bug: para multiplas MapTips funcionarem teve que se inserir esta linha em baixo
        else if (( div != null )&& (div.innerHTML == "") && (esriMTCallbackCount == esriCurrentResponseCount))
            div.style.display = "none";
        else if (esriMTCallbackCount != esriCurrentResponseCount)
            div.innerHTML = "";
            
        esriMTCallbackCount = esriCurrentResponseCount; 
	}

	
	this.showTip = function(index, e) {
		//if ((this.enabled) && (!hoverVisible)){
		if (this.enabled) {
			getXY(e);
			if (index!=lastExtendIndex)
				mt_manager.show(this, index, "hover");
			if ((this.hoverImage!="") && (index!=lastExtendIndex)) {
				var imgObj = document.images["MapTipHotSpotImg_" + this.id + "_" + index];
				if (imgObj!=null) imgObj.src = this.hoverImage;
				lastHoverIndex = index;
			}
			//hoverVisible=true;
		}
	}
	
	this.hide = function(which) {
		mt_manager.hide(which);
		if (this.defaultImage!="" && lastExtendIndex!=lastHoverIndex  && this.type.toLowerCase()=="point") {
			var imgObj = document.images["MapTipHotSpotImg_" + this.id + "_" + lastHoverIndex];
			if (imgObj!=null) imgObj.src = this.defaultImage;
		}
	}
	
	this.click = function(index, e) {
		getXY(e);
		if (!this.extendedVisible[index]) {
			this.resetDefaultIcons();
			mt_manager.show(this, index, "extended");
			lastExtendIndex=index;
			extendVisible = true;
			mt_manager.windowIndex++;
			if (mt_manager.windowIndex==mt_manager.maxExtendedWindows) mt_manager.windowIndex = 0;
			this.hide("hover");
			if (this.clickImage!="" && this.type.toLowerCase()=="point") {
				var imgObj = document.images["MapTipHotSpotImg_" + this.id + "_" + index];
				if (imgObj!=null) imgObj.src = this.clickImage;
			}
		}
		
	}
	
	this.resetDefaultIcons = function() {
		if (this.defaultImage!="" && this.type.toLowerCase()=="point") {
			var imgObj
			for (var i=0;i<this.mapTipItemIDs.length;i++) {
				imgObj = document.images["MapTipHotSpotImg_" + this.id + "_" + this.mapTipItemIDs[i]];
				if (imgObj!=null) imgObj.src = this.defaultImage;
			}		
		}
	}
	
	this.hideIcons = function(iconDiv) {
		if (iconDiv!=null) iconDiv.style.visibility = "hidden";
	}
	
	this.showIcons = function() {
		if (iconDiv!=null) iconDiv.style.visibility = "visible";
	}
	

}// MapTipCollectionObject

function MapTipItemObject(mapId, index, left, top, headerText, content, extendedContent) {
	this.mapId = mapId
	this.index = index;
	this.shape = "point";
	this.left = left;
	this.top = top;
	this.headerText = headerText;
	this.content = (content!=null && content.length>0) ? content : "";
	this.extendedContent = (extendedContent!=null && extendedContent.length>0) ? extendedContent : "";
	this.iconImage = "";
	this.iconHoverImage = "";
	this.iconClickImage = "";
	this.divId = "MapTipHotSpot_" + this.mapId + "_" + this.index;
	this.imageId = "MapTipHotSpotImage_" + this.mapId + "_" + this.index;
		
	this. setImages = function(iconImage, iconHoverImage, iconClickImage) {
		// these must be set before the item is added to the collection
		this.iconImage = iconImage;
		this.iconHoverImage = iconHoverImage;
		this.iconClickImage = iconClickImage;
	}
}

function MapTipWindowObject(width, classPrefix, type) {
	inheritsFrom(new PageElementObject("dummy", 0, 0, 0, 0), this);
	this.width = (width!=null) ? width: mapTipWidth;	
	this.type = (type!=null && type.length>0) ? type : "point"; // valid values: point, circle, polygon
	this.hoverHeight = mapTipHeight;
	this.extendedHeight = mapTipExtendedHeight;
	this.classPrefix = (classPrefix!=null && classPrefix.length>0) ? classPrefix: "Custom_";
	this.hoverHeaderClass = this.classPrefix + "MapTipHoverHeaderStyle";
	this.extendedHeaderClass = this.classPrefix + "MapTipExtendedHeaderStyle";
	this.bodyClass = this.classPrefix + "MapTipBodyStyle";
	this.contentClass = this.classPrefix + "MapTipContentsStyle";
	this.closeClass = this.classPrefix + "MapTipCloseStyle";
	this.maxExtendedWindows = 10;
	this.windowIndex = 0;
	this.closeButtonImage = esriMTCloseImage;
	
	this.hoverDivObject = null;
	this.hoverDivId = "MapTipHoverContainerDiv";
	this.hoverHeaderCell = null;
	this.hoverHeaderId= "MapTipHoverHeaderCell";
	this.hoverContentCell = null;
	this.hoverContentId = "MapTipHoverContentCell"
	this.extendedDivObject = new Array();
	this.extendedDivId = new Array();
	this.extendedHeaderCell = new Array();
	this.extendedHeaderId = new Array();
	this.extendedContentCell = new Array();
	this.extendedContentId = new Array();
	this.extendedIndex = new Array();

	this.createDivs = function(styleSheet) {
//	    if (styleSheet==null)
//	        styleSheet = defaultStylePath + "maptips.css";
//        var oLink = document.createElement("link");
//        oLink.rel = "stylesheet";
//        oLink.type = "text/css";
//        oLink.href = styleSheet;
//        document.body.appendChild(oLink);
 
	    var s = '<div id="MapTipHoverContainerDiv" class="' + this.bodyClass + '" style="position: absolute; left: 0px; top: 0px; width: 250px; visibility: hidden;">';
		s +=  '      <div class="' + this.hoverHeaderClass +'"  id="MapTipHoverHeaderCell" >';
		//                 Header
		s +=  '      </div>';
		s +=  '      <div class="' + this.contentClass + '"  id="MapTipHoverContentCell" >';
		//	    Content Content Content Content Content  
		s +=  '      </div>';
	    s +=  '</div>';
	    for (var i=0;i<this.maxExtendedWindows;i++) {
	        s +=  '<div id="MapTipExtendedContainerDiv_' + i + '" class="' + this.bodyClass + '" style="position: absolute; left: 0px; top: 0px; width: 250px; z-index: ' + (20000 + i ) + '; visibility: hidden;" onmouseover="mt_manager.bringToFront(' + i + '); mt_manager.showClickIcon(' + i + ');" onmousedown="dragMapTipStart(event,mt_manager,' + i + ');">';
			s +=  '        <div class="' + this.extendedHeaderClass + '"  id="MapTipExtendedHeaderCell_' + i + '" >';
		    //                     Header
			s +=  '        </div>';

		    s +=  '    <div class="' + this.contentClass + '"  id="MapTipExtendedContentCell_' + i +'" >';
			    //    Content Content Content Content Content Content Content Content Content Content Content 
		    s +=  '    </div>';
		    //s +=  '    <div style="position: absolute; left: 0px; top: 0px; cursor: move;"><img src="' + maptipBlankImage + '" width="250" height="25" hspace="0" vspace="0" /></div>';
			s +=  '    <div  id="MapTipExtendedCloseCell_' + i + '" class="' + this.closeClass + '">';
			s +=  '	        <img src="' + esriMTCloseImage + '" alt="" hspace="0" vspace="0" border="0" align="middle"  onmousedown="closeExtendedMapTip(' + i + ')" onmouseover="this.style.cursor=\'pointer\'" />';
			s +=  '    </div>';
	        s +=  '</div>';

		    this.extendedDivObject[i] = null;
		    this.extendedDivId[i] = "MapTipExtendedContainerDiv_" + i;
		    this.extendedHeaderCell[i] = null;
		    this.extendedHeaderId[i] = "MapTipExtendedHeaderCell_" + i;
		    this.extendedContentCell[i] = null;
		    this.extendedContentId[i] = "MapTipExtendedContentCell_" + i;
		    this.extendedIndex[i] = -1;
	    }
        
        
	    var style = "background-color: transparent; position: absolute;";
        addDiv("MapTipPanelHolder", s, 0, 0, 1, 1, "visible", style)
    	
	    //document.writeln(s);
	    if (!isIE) 
		    window.setTimeout("mt_manager.setObjects();",100);
	    else 
		    this.setObjects();
	}
	
	this.setObjects = function() {
		this.hoverDivObject = document.getElementById(this.hoverDivId);
		maptipHoverPanel = this.hoverDivObject;
		this.hoverHeaderCell = document.getElementById(this.hoverHeaderId);
		this.hoverContentCell = document.getElementById(this.hoverContentId);
		for (var i=0;i<this.maxExtendedWindows;i++) {
			this.extendedDivObject[i] = document.getElementById(this.extendedDivId[i]);
			this.extendedHeaderCell[i] = document.getElementById(this.extendedHeaderId[i]);
			this.extendedContentCell[i] = document.getElementById(this.extendedContentId[i]);
		}
		
		if (this.type.toLowerCase()!="point")
			hideLayer("MapTipLayerDiv_" + maptips.id);

	}
	
	this.setPosition = function (maptipItem , which) {
		//alert(maptipItem.divId);
		var left, top, x, y;
		var winWidth = getWinWidth();
		var winHeight = getWinHeight();
//		if (this.type.toLowerCase()=="point") {
//			var box = calcElementPosition(maptipItem.divId);		
//			x = box.left + maptipItem.shape.width; // + (Math.round(rect.width/2));
//			y = box.top + maptipItem.shape.height; //+ (Math.round(rect.height/2));
//		} else {
			x = mouseX;
			y = mouseY;
//		}
		if (x>winWidth-this.width) 
			left = x - (this.width + 10);
		else 
			left = x + 1;
		if (which.toLowerCase()=="extended"){
			if (y>winHeight - this.extendedHeight)
				top = y-this.hoverHeight + 10;
			else 
				top = y - 10;
			this.extendedDivObject[this.windowIndex].style.left = left + "px";
			this.extendedDivObject[this.windowIndex].style.top = top + "px";
		} else {
			if (y>winHeight - this.hoverHeight)
				top = y-this.hoverHeight + 10;
			else 
				top = y - 10;
			this.hoverDivObject.style.left = left + "px";
			this.hoverDivObject.style.top = top + "px";
		}
	}
	
	this.show = function(maptipCollection, index, which) {
		maptip = maptipCollection.mapTipItems[index];
		if (maptip!=null) {
		    this.setHeader(maptip.headerText, which);
		    this.setExtendedContent(maptip.extendedContent);
		    this.setContent(maptip.content, this.type);		
		    if (which!=null && which.toLowerCase()=="extended") {
			    //var content = maptip.content + maptip.extendedContent;

			    this.setPosition(maptip, "extended");
			    showLayer(this.extendedDivId[this.windowIndex]);
			    this.extendedIndex[this.windowIndex] = index
			    maptips.extendedVisible[index] = true;
			    lastExtendIndex = index;
			    lastExtendMapId = maptipCollection.id;
			    extendVisible = true;
    			
		    } else {
			    //window.status = "hoverVisible=" + hoverVisible;
			    if (!maptips.extendedVisible[index]) {
			    this.hoverDivObject.onmousedown = hoverClick;
			    lastHoverIndex = index;
			    this.setPosition(maptip, "hover");
			    showLayer(this.hoverDivId);
			    hoverVisible = true;
			    }
		    }
		}
	}
	
	this.showAt = function(x, y, which) {
		if (which!=null && which.toLowerCase()=="extended") {
			this.extendedDivObject[this.windowIndex].style.left = x + "px";
			this.extendedDivObject[this.windowIndex].style.top = y + "px";
			showLayer(this.extendedDivId[this.windowIndex]);
			extendVisible = true;

		} else {
			this.hoverDivObject.style.left = x + "px";
			this.hoverDivObject.style.top = y + "px";
			showLayer(this.hoverDivId);
		}
	}
	
	this.setHeader = function(header, which) {
		if (which!=null && which.toLowerCase()=="extended")
			this.extendedHeaderCell[this.windowIndex].innerHTML = header;
		else 
			this.hoverHeaderCell.innerHTML = header;
	}
	
	this.setContent = function(content, type) {
		if (type=="point")
			content += clickIconPrompt;
		else 
			content += "<br>" + clickHoverPrompt;
		this.hoverContentCell.innerHTML = content;
	}
	
	this.setExtendedContent = function(content) {
		//alert(content);
		this.extendedContentCell[this.windowIndex].innerHTML = content;
		
	}
	
	this.hide = function(which, index) {
		if (which!=null && which.toLowerCase()=="extended") {
			index = (index!=null) ? index : this.windowIndex;
			hideLayer(this.extendedDivId[index]);
			MapTipCollections[lastExtendMapId].extendedVisible[this.extendedIndex[n]] = false;
			extendVisible = false;
			//if (
		} else {
			//window.status = "mt_manager.hide()";
			hideLayer(this.hoverDivId);
			hoverVisible = false;
		}
	}
	
	this.hideAll = function(iconDiv) {
		hideLayer(this.hoverDivId);
		hoverVisible = false;
		for (var i=0;i<this.maxExtendedWindows;i++) {
			hideLayer(this.extendedDivId[i]);
			maptips.extendedVisible[this.extendedIndex[i]] = false;
		}
		extendVisible = false;
		if (iconDiv!=null) {
			maptips.hideIcons(iconDiv);
		} else {
			maptips.resetDefaultIcons();
		}
	}
	
	this.bringToFront = function(index) {
		var zc = 20000;
		for (var i=0;i<this.maxExtendedWindows;i++) {
			if (i==index) {
				this.extendedDivObject[i].style.zIndex = 20000 + this.maxExtendedWindows;
			} else {
				this.extendedDivObject[i].style.zIndex = zc;
				zc++;
			}
		}
	}
	
	this.showClickIcon = function(index) {
		maptips.resetDefaultIcons();
		if (maptips.clickImage!="" && this.type.toLowerCase()=="point") {
			var imgObj = document.images["MapTipHotSpotImg_" + maptips.id + "_" + this.extendedIndex[index]];
			if (imgObj!=null) imgObj.src = maptips.clickImage;
		}
	}
}

// object for managing MapTips popups
function MapTipsPanelManagerObject() {

}

function closeExtendedMapTip(n) {
	hideLayer("MapTipExtendedContainerDiv_" + n);
	MapTipCollections[lastExtendMapId].extendedVisible[mt_manager.extendedIndex[n]] = false;
	MapTipCollections[lastExtendMapId].resetDefaultIcons();
	extendVisible = false;
	lastExtendIndex = -1;
}

function dragMapTipStart(e, manager, index) {
	getXY(e);
	mt_manager = manager;
	mt_panelDragIndex = index;
	mt_panel = mt_manager.extendedDivObject[index];	
	//mt_panel = mt_manager.extendedHeaderCell[index];
	mt_panel.onmousemove = dragMapTipMove;
	mt_panel.onmouseup = dragMapTipEnd;
	var box = calcElementPosition(manager.extendedHeaderId[index]);
	maptipXOffset = mouseX-box.left;
	maptipYOffset = mouseY-box.top;
	tempMouseMove = document.onmousemove;
	tempMouseUp = document.onmouseup;
	document.onmousemove = dragMapTipMove;
	document.onmouseup = dragMapTipEnd;
    mapTipDragMaxRight = getWinWidth() - 5;
    mapTipDragMaxBottom = getWinHeight() - 5;

	return false;
}

function dragMapTipMove(e) {
	getXY(e);
	if (mouseX < 5) mouseX = 5;
	if (mouseY < 5) mouseY = 5;
	if (mouseX > mapTipDragMaxRight) mouseX = mapTipDragMaxRight;
	if (mouseY > mapTipDragMaxBottom) mouseY = mapTipDragMaxBottom;
	mt_panel.style.left = (mouseX-maptipXOffset) + "px";
	mt_panel.style.top = (mouseY-maptipYOffset) + "px";
	return false;
}

function dragMapTipEnd(e) {
	//mt_panel = mt_manager.extendedHeaderCell[mt_panelDragIndex];
	mt_panel.onmousemove = null;
	mt_panel.onmouseup = null;
	document.onmousemove = null;
	document.onmouseup = null;
    return false;
}

function setupMapTipPanels() {
    //alert("setupMapTipPanels()");
    mt_manager = new MapTipWindowObject();
    mt_manager.createDivs();
}

function addMapTipPanels() {
//    if (webPageIsLoaded) {
//        setupMapTipPanels();
//        window.clearInterval(mt_checkLoad);
//    }
    window.setTimeout("setupMapTipPanels()", 1500);
}


function hoverClick(e) {
	maptips.click(lastHoverIndex, e);
	return false;
}


