﻿// display_mapidentify.js


var identifyFilePath = "";
var identifyImageType = "png";

function SingleSelect(divid) {
    map = Maps[divid];
    //MapPoint(map.controlName, "MapIdentify", false);
    MapPoint(map.get_uniqueID(), "MapIdentify", false);
    map.divObject.onmousedown = MapIdClick;
}

// Set up Identify tool
function MapIdentify(divid) {
    map = Maps[divid];
    //MapPoint(map.controlName, "MapIdentify", false);
    MapPoint(map.get_uniqueID(), "MapIdentify", false);
    //map.divObject.onmousedown = MapIdClick;
    RemoveMouseDownHandlers(map)
    map.add_mouseDown(MapIdClick);
//    map.add_mouseDown(function(e) {
//        console.dir(e);
//        debugger
//        e.toScreenPoint();
//    });

    map.set_cursor("pointer");
    
}

//function GetXY(e) {
//    //console.dir(e);
//     if (isNav) {
//         mouseX=e._mouseDragState.mousedownX;
//         mouseY = e._mouseDragState.mousedownY;
//         } else {
//         mouseX=mouseX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
//         mouseY=mouseY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
//         // Added to adjust to cursor hot spot in IE
//         if (document.all) {
//             mouseX -= 3;
//             mouseY -= 3;
//         };
//         // Added to adjust to cursor hot spot in IE
//         var box = calcElementPosition("Map1");
//         mouseX -= box.left;
//         mouseY -= box.top;
//     }
//    return false;
//}


function MapIdClick2(sender, args) {
}
// Event handler for Identify
function MapIdClick(e) {    
    var toolMode = map.__activeToolMode;
    if (toolMode != "MapIdentify") return;
 //   map.cursor = map.divObject.style.cursor;
    //map.divObject.style.cursor = "wait";
    //console.dir(e);
	GetXY(e);
	//var box = calcElementPosition(map.containerDivId);
//	var box = calcElementPosition("Map1");
//	zleft = mouseX - box.left;
//	ztop = mouseY - box.top;

	zleft = mouseX;
	ztop = mouseY;

	map.xMin=zleft;
	map.yMin=ztop;
	var idCount = document.getElementById("identifycounter").value;
    idCount++;
    document.getElementById("identifycounter").value = idCount;
	var div = document.getElementById("IdentifyLocation_" + idCount);
	if (div==null) {
	    addIdentifyLocation(idCount);
	}
	//map.getTopLeftTile();
//	var fpBody = document.getElementById('Results_TaskResults1');
//	var html = fpBody.innerHTML;
//	fpBody.innerHTML = "<div><img src='images/callbackActivityIndicator.gif' align='middle'/> Getting Information. . .</div>" + html;
	//showFloatingPanel('Results');
//	fpBody=document.getElementById('Results_BodyRow');
//	if (fpBody.style.display=="none")
//	    toggleFloatingPanelState('Results','images/collapse.gif','images/expand.gif');

	var message = "ControlID=Map1&ControlType=Map&EventArg=MapIdentify&Map1_mode=MapIdentify&minx=" + zleft + "&miny=" + ztop + "&idnum=" + idCount;
	//var context = map.controlName;
	var context = map.get_uniqueID();
	eval(identifyCallbackFunctionString);
	//eval(map.identifyCallbackFunctionString);
	var div = document.getElementById("IdentifyLocation_" + idCount);
	//alert(div.innerHTML);
	// point is bottom center... 2 pixels up for shadow
	var cWidth = Math.floor(div.clientWidth / 2);
	var cHeight = div.clientHeight;
	//alert(cWidth + " x " + cHeight); // width and height might not be available on first time.... if so, approximate size needed
	if (cWidth==0) cWidth = 12;
	if (cHeight == 0) cHeight = 29;	
	var idLeft = zleft - cWidth;
	var idTop = ztop - cHeight + 2; // add two back for icon bottom
//	var idLeft = zleft - parseInt(map.divObject.style.left) - cWidth;
//	var idTop = ztop - parseInt(map.divObject.style.top) - cHeight + 2; // add two back for icon bottom
//	if (isIE) {
//	    idTop+=2; 
//	    //idLeft+=2;
//	}
	window.setTimeout('moveLayer("IdentifyLocation_' + idCount + '", ' + idLeft + ', ' + idTop + '); showLayer("IdentifyLocation_' + idCount + '");', 0);
	map.mode = map.tempMode;
	map.actionType = map.tempAction;
	map.cursor = map.tempCursor;
	return false;
	
}

function addIdentifyLocation(id) {
    //alert(document.getElementById("identifycounter").value);
    var content = '<div id="IdentifyLocation_' + id + '" style="position: absolute; left: 0px; top: 0px; visibility: hidden;color:red;">';
    if (isIE  && ieVersion < 7 && (identifyImageType.toLowerCase()=="png")) 
	    content += '<img src="' + identifyFilePath + 'images/blank.gif" alt="" border="0"  hspace="0" vspace="0" style="filter:  progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + identifyFilePath + 'images/identify-map-icon.png\');" />' + id + '\n';
	else
	    content += '<img src="' + identifyFilePath + 'images/identify-map-icon.png" alt="" border="0"  hspace="0" vspace="0" />' + id + '\n';
    content += '</div>';
    //alert(content);
    //map.overlayObject.insertAdjacentHTML("BeforeEnd", content);
    var m = document.getElementById(map.get_uniqueID());
    m.insertAdjacentHTML("BeforeEnd", content);
}
