
var m_zbxZoom;
var m_Pan;
//variable for measure
var XYarray = new Array();
var XYCoordarray = new Array();
var XYCount = -1;
var dist=0;
var offsetGeo=-2;
var m_Circle;
function resetMeasure() {
XYCount =-1;
XYarray = new Array();
XYCoordarray = new Array();
dist=0;
}

/*********************************
	FUNCTION START
**********************************/
function MarqueeStart() {
	var theObj;
	theObj = document.getElementById('LoadImage');
	theObj.style.visibility = 'visible';
}
/*********************************
	END
**********************************/
function fDblClick(sUniqueID) {
    if (!(isEventOverMap(sUniqueID, event.clientX, event.clientY))) {	
		return;
	} 
   var t = document.getElementById('fldToolActive'+sUniqueID);
   var toolActive = parseInt(t.value);
   if ((toolActive==5)||(toolActive==6)||(toolActive==10)||(toolActive==11)||(toolActive==13)) {} else{	
		return;
	} 
   var m_divMap;
   m_divMap = document.getElementById('divMap'+sUniqueID);
   XYCount += 1;
   XYarray[XYCount] = new point(event.clientX-(parseInt(m_divMap.style.left)) + document.body.scrollLeft, event.clientY-(parseInt(m_divMap.style.top)) + document.body.scrollTop);
   XYCoordarray[XYCount] = toMapPoint(event.clientX, event.clientY, sUniqueID);
   if ((toolActive==5)||(toolActive==11)){
      dist += twoPntDistance(XYCoordarray[XYCount-1].x,XYCoordarray[XYCount-1].y,XYCoordarray[XYCount].x,XYCoordarray[XYCount].y);
      var txtTot = document.getElementById('ctlTxtMeasureTotal'+sUniqueID);
      if (txtTot==null) {} else {
         var fldScaleMeasure = document.getElementById('fldScaleMeasure'+sUniqueID);
         var fldFactorConversionMeasure = document.getElementById('fldFactorConversionMeasure'+sUniqueID);
         txtTot.value=fRound(dist,fldScaleMeasure,parseFloat(fldFactorConversionMeasure.value));
      }      
      if (toolActive==11){
         buildShape(sUniqueID, toolActive.toString());
      }
   }else if ((toolActive==6)||(toolActive==10)){
      var txtAreaTot = document.getElementById('ctlTxtMeasureAreaTotal'+sUniqueID);
      if (txtAreaTot==null) {} else {
         txtAreaTot.value=fArea(sUniqueID);
      }
      if (toolActive==10){
         buildShape(sUniqueID, toolActive.toString());
      }      
   }else if (toolActive==13){
      buildShape(sUniqueID, toolActive.toString());
   }
   document.releaseCapture();
   resetMeasure();
}
function getCoords() {
   var points = '';
   var i,max;
   for (i = 0, max = XYarray.length; i < max;  i++) {
     points += XYarray[i].x+','+XYarray[i].y+' ';
   }
   return points;
}
function buildShape(sUniqueID, toolActive) {
   var fldCoordinateSeparator = document.getElementById('fldCoordinateSeparator'+sUniqueID);
   var fldTupleSeparator = document.getElementById('fldTupleSeparator'+sUniqueID);
   var sCoo='';
   var j;
   for (j = 0, max = (XYarray.length); j < max; j++){
     sCoo += (XYarray[j].x).toString() + fldCoordinateSeparator.value + (XYarray[j].y).toString() + fldTupleSeparator.value;
   }
   // CALL MarqueeStart
   MarqueeStart();
   // END
   __doPostBack(sUniqueID, toolActive.toString()+'|'+sCoo);
}
function twoPntDistance(x1,y1,x2,y2) {
 var dist;
 var dX = Math.abs(x1 - x2);
 var dY = Math.abs(y1 - y2);
 dist = Math.sqrt(Math.pow(dX,2) + Math.pow(dY,2));
 return dist;  
}
function fArea(sUniqueID) {
 var area=0;
 var XY = new Array();
 for (j = 0, max = (XYCoordarray.length); j < max; j++){
   XY[j]= XYCoordarray[j];
 }
 if (fArea.arguments.length == 3){ 
   XY[XY.length]= new point(fArea.arguments[1],fArea.arguments[2]);
 }
 if (XY.length < 3){ 
 }else{ 
   var y0 = XY[XY.length-1].y; 
   var SumPar = (XY[1].x - XY[XY.length-1].x) * (XY[0].y - y0);
   for (j = 1, max = (XY.length-1); j < max; j++){     SumPar += (XY[j+1].x - XY[j-1].x) * (XY[j].y - y0);   }
   area = Math.abs(SumPar /2);
 }
 var fldScaleMeasureArea = document.getElementById('fldScaleMeasureArea'+sUniqueID);
 var fldFactorConversionMeasureArea = document.getElementById('fldFactorConversionMeasureArea'+sUniqueID);
 area = fRound(area, fldScaleMeasureArea, parseFloat(fldFactorConversionMeasureArea.value));
 return area;  
}
function fMouseDown(sUniqueID) {
 if (!(isEventOverMap(sUniqueID, event.clientX, event.clientY))) {	
		return;
 } 
 var t = document.getElementById('fldToolActive'+sUniqueID);
 var toolActive = parseInt(t.value);
 if ((toolActive==1)||(toolActive==2)||(toolActive==4)||(toolActive==5)||(toolActive==6)||(toolActive==7)||(toolActive==9)||(toolActive==10)||(toolActive==11)||(toolActive==12)||(toolActive==13)||(toolActive==14)||(toolActive==15)) {
 }else{
   return;
 }
  var m_divMap;
  m_divMap = document.getElementById('divMap'+sUniqueID);
  m_divMap.setCapture();
  if ((toolActive==1)||(toolActive==2)||(toolActive==9)) { 
        if (toolActive==9){
           m_divZoomBox = document.getElementById('divSelectByRectBox'+sUniqueID)
        }else{
           m_divZoomBox = document.getElementById('divZoomBox'+sUniqueID)
        }
		m_zbxZoom = new cZoom(m_divZoomBox);
		m_zbxZoom.offsetX(parseInt(m_divMap.style.left));
		m_zbxZoom.offsetY(parseInt(m_divMap.style.top));
		m_zbxZoom.show();
		m_zbxZoom.start(event.clientX, event.clientY);
  }else if (toolActive==4) {
		var m_Map; 
	    m_Map = document.getElementById(sUniqueID);
		//m_Map.style.visibility ='hidden';
		hideLayer(sUniqueID);
		var m_theImage; 
		m_theImage = document.getElementById('MapPanID'+sUniqueID);
		m_theImage.src = m_Map.src;
		showLayer('divMapPan'+sUniqueID);
		m_Pan = new cPan();
		m_Pan.start(event.clientX, event.clientY);
  }else if ((toolActive==5)||(toolActive==6)||(toolActive==10)||(toolActive==11)||(toolActive==13)||(toolActive==14)||(toolActive==15)) {
        XYCount += 1;
        XYarray[XYCount] = new point(event.clientX-(parseInt(m_divMap.style.left)) + document.body.scrollLeft, event.clientY-(parseInt(m_divMap.style.top)) + document.body.scrollTop);
        XYCoordarray[XYCount] = toMapPoint(event.clientX, event.clientY, sUniqueID);
        if ((toolActive==5)||(toolActive==11)||(toolActive==15)){
           if (XYarray.length > 1) {
              dist += twoPntDistance(XYCoordarray[XYCount-1].x,XYCoordarray[XYCount-1].y,XYCoordarray[XYCount].x,XYCoordarray[XYCount].y);
           }
           var txtTot = document.getElementById('ctlTxtMeasureTotal'+sUniqueID);
           if (txtTot==null) {} else {
              var fldScaleMeasure = document.getElementById('fldScaleMeasure'+sUniqueID);
              var fldFactorConversionMeasure = document.getElementById('fldFactorConversionMeasure'+sUniqueID);
              txtTot.value=fRound(dist,fldScaleMeasure,parseFloat(fldFactorConversionMeasure.value));
           }
           if ((XYarray.length == 2) && (toolActive==15)) {
              buildShape(sUniqueID, toolActive.toString());
           }
        }else if ((toolActive==6)||(toolActive==10)){
           var txtAreaTot = document.getElementById('ctlTxtMeasureAreaTotal'+sUniqueID);
           if (txtAreaTot==null) {} else {
               txtAreaTot.value=fArea(sUniqueID);
           }
        }else if ((toolActive==13)||(toolActive==14)){      
           var html='';
           var fldBorderColorSelectByPolygon=document.getElementById('fldBorderColorSelectByPolygon'+sUniqueID);
           var fldBorderWidthSelectByPolygon=document.getElementById('fldBorderWidthSelectByPolygon'+sUniqueID);
           var fldColorSelectByPolygon=document.getElementById('fldColorSelectByPolygon'+sUniqueID);
           var fldOpacitySelectByPolygon=document.getElementById('fldOpacitySelectByPolygon'+sUniqueID);
           var fldDimensionPxPoint=document.getElementById('fldDimensionPxPoint'+sUniqueID);
           var DimensionPxPoint2=Math.round((parseInt(fldDimensionPxPoint.value))/2);
           if (toolActive==13) {
              for (j = 0, max = (XYarray.length); j < max; j++) {
                   html += '<v:oval id="vmlSelectByMultipoint'+sUniqueID+'" style="position:absolute; left:'+((XYarray[j].x)-DimensionPxPoint2+offsetGeo).toString()+'px;top:'+((XYarray[j].y)-DimensionPxPoint2+offsetGeo).toString()+'px;width:' + fldDimensionPxPoint.value + 'px;height:' + fldDimensionPxPoint.value + 'px" strokeweight="' + fldBorderWidthSelectByPolygon.value + '" strokecolor="' + fldBorderColorSelectByPolygon.value + '" filled="true" > <v:fill opacity="' + fldOpacitySelectByPolygon.value + '" color="' + fldColorSelectByPolygon.value + '"  /> </v:oval>';
              }
              el = document.getElementById('divMapMeasure'+sUniqueID);
              el.innerHTML = html;
           }else if (toolActive==14){
                   html += '<v:oval id="vmlSelectByPoint'+sUniqueID+'" style="position:absolute; left:'+((XYarray[0].x)-DimensionPxPoint2+offsetGeo).toString()+'px;top:'+((XYarray[0].y)-DimensionPxPoint2+offsetGeo).toString()+'px;width:' + fldDimensionPxPoint.value + 'px;height:' + fldDimensionPxPoint.value + 'px" strokeweight="' + fldBorderWidthSelectByPolygon.value + '" strokecolor="' + fldBorderColorSelectByPolygon.value + '" filled="true" > <v:fill opacity="' + fldOpacitySelectByPolygon.value + '" color="' + fldColorSelectByPolygon.value + '"  /> </v:oval>';
                   el = document.getElementById('divMapMeasure'+sUniqueID);
                   el.innerHTML = html;
                   buildShape(sUniqueID, toolActive.toString());
           }
        }
  } else if (toolActive==7){      
        var sCoo = ((event.clientX-parseInt(m_divMap.style.left) + document.body.scrollLeft).toString())+'|'+((event.clientY-parseInt(m_divMap.style.top) + document.body.scrollTop).toString());
		// CALL MarqueeStart
		MarqueeStart();
		// END
        __doPostBack(sUniqueID, toolActive.toString()+'|'+sCoo);
  } else if (toolActive==12){      
        if (m_Circle==null) {
            m_Circle = new cCircle();
		    m_Circle.offsetX(parseInt(m_divMap.style.left) );
		    m_Circle.offsetY(parseInt(m_divMap.style.top));
		    m_Circle.start(event.clientX, event.clientY);
        }else{
            m_Circle.stop();
            var sCoo = m_Circle.left().toString() +'|'+ m_Circle.top().toString()+'|'+ m_Circle.width().toString()+'|'+ m_Circle.height().toString();
            // CALL MarqueeStart
			MarqueeStart();
			// END
            __doPostBack(sUniqueID, toolActive.toString()+'|'+sCoo);
        }
  }
}
function fCursor(sUniqueID, iToolMode) {
 var m_divMap;
 m_divMap = document.getElementById('divMap'+sUniqueID);
 var t = document.getElementById('fldToolActive'+sUniqueID);
 t.value = iToolMode.toString();
 switch(iToolMode) {
		case 1:
			m_divMap.style.cursor = 'crosshair'; 
			showLayer('divZoomIn'+sUniqueID);
			hideLayer('divZoomOut'+sUniqueID);
			hideLayer('divPan'+sUniqueID);
			hideLayer('divMeasure'+sUniqueID);
			hideLayer('divMeasureArea'+sUniqueID);
			hideLayer('divIdentify'+sUniqueID);
			hideLayer('divSelectByRect'+sUniqueID);
			hideLayer('divSelectByPolygon'+sUniqueID);
			hideLayer('divSelectByPolyline'+sUniqueID);
			hideLayer('divSelectByCircle'+sUniqueID);
			hideLayer('divSelectByMultipoint'+sUniqueID);
			hideLayer('divSelectByPoint'+sUniqueID);
			hideLayer('divSelectByLine'+sUniqueID);
			break;
		case 2:
		    m_divMap.style.cursor = 'crosshair';
			showLayer('divZoomOut'+sUniqueID);
			hideLayer('divZoomIn'+sUniqueID);
			hideLayer('divPan'+sUniqueID);
			hideLayer('divMeasure'+sUniqueID);
			hideLayer('divMeasureArea'+sUniqueID);
			hideLayer('divIdentify'+sUniqueID);
			hideLayer('divSelectByRect'+sUniqueID);
			hideLayer('divSelectByPolygon'+sUniqueID);
			hideLayer('divSelectByPolyline'+sUniqueID);
			hideLayer('divSelectByCircle'+sUniqueID);
			hideLayer('divSelectByMultipoint'+sUniqueID);
			hideLayer('divSelectByPoint'+sUniqueID);
			hideLayer('divSelectByLine'+sUniqueID);
			break;	
		case 4:
			m_divMap.style.cursor = 'move';
			showLayer('divPan'+sUniqueID);
			hideLayer('divZoomIn'+sUniqueID);
			hideLayer('divZoomOut'+sUniqueID);
			hideLayer('divMeasure'+sUniqueID);
			hideLayer('divMeasureArea'+sUniqueID);
			hideLayer('divIdentify'+sUniqueID);
			hideLayer('divSelectByRect'+sUniqueID);
			hideLayer('divSelectByPolygon'+sUniqueID);
			hideLayer('divSelectByPolyline'+sUniqueID);
			hideLayer('divSelectByCircle'+sUniqueID);
			hideLayer('divSelectByMultipoint'+sUniqueID);
			hideLayer('divSelectByPoint'+sUniqueID);
			hideLayer('divSelectByLine'+sUniqueID);
			break;
		case 5:
			m_divMap.style.cursor = 'crosshair';
			showLayer('divMeasure'+sUniqueID);
			hideLayer('divZoomIn'+sUniqueID);
			hideLayer('divZoomOut'+sUniqueID);
			hideLayer('divPan'+sUniqueID);
			hideLayer('divMeasureArea'+sUniqueID);
			hideLayer('divIdentify'+sUniqueID);
			hideLayer('divSelectByRect'+sUniqueID);
			hideLayer('divSelectByPolygon'+sUniqueID);
			hideLayer('divSelectByPolyline'+sUniqueID);
			hideLayer('divSelectByCircle'+sUniqueID);
			hideLayer('divSelectByMultipoint'+sUniqueID);
			hideLayer('divSelectByPoint'+sUniqueID);
			hideLayer('divSelectByLine'+sUniqueID);
			break;
		case 6:
			m_divMap.style.cursor = 'crosshair';
			showLayer('divMeasureArea'+sUniqueID);
			hideLayer('divZoomIn'+sUniqueID);
			hideLayer('divZoomOut'+sUniqueID);
			hideLayer('divPan'+sUniqueID);
			hideLayer('divMeasure'+sUniqueID);
			hideLayer('divIdentify'+sUniqueID);
			hideLayer('divSelectByRect'+sUniqueID);
			hideLayer('divSelectByPolygon'+sUniqueID);
			hideLayer('divSelectByPolyline'+sUniqueID);
			hideLayer('divSelectByCircle'+sUniqueID);
			hideLayer('divSelectByMultipoint'+sUniqueID);
			hideLayer('divSelectByPoint'+sUniqueID);
			hideLayer('divSelectByLine'+sUniqueID);
			break;
		case 7:
			m_divMap.style.cursor = 'crosshair';
			showLayer('divIdentify'+sUniqueID);
			hideLayer('divMeasureArea'+sUniqueID);
			hideLayer('divZoomIn'+sUniqueID);
			hideLayer('divZoomOut'+sUniqueID);
			hideLayer('divPan'+sUniqueID);
			hideLayer('divMeasure'+sUniqueID);
			hideLayer('divSelectByRect'+sUniqueID);
			hideLayer('divSelectByPolygon'+sUniqueID);
			hideLayer('divSelectByPolyline'+sUniqueID);
			hideLayer('divSelectByCircle'+sUniqueID);
			hideLayer('divSelectByMultipoint'+sUniqueID);
			hideLayer('divSelectByPoint'+sUniqueID);
			hideLayer('divSelectByLine'+sUniqueID);
			break;
		case 9:
			m_divMap.style.cursor = 'crosshair';
			showLayer('divSelectByRect'+sUniqueID);
			hideLayer('divIdentify'+sUniqueID);
			hideLayer('divMeasureArea'+sUniqueID);
			hideLayer('divZoomIn'+sUniqueID);
			hideLayer('divZoomOut'+sUniqueID);
			hideLayer('divPan'+sUniqueID);
			hideLayer('divMeasure'+sUniqueID);
			hideLayer('divSelectByPolygon'+sUniqueID);
			hideLayer('divSelectByPolyline'+sUniqueID);
			hideLayer('divSelectByCircle'+sUniqueID);
			hideLayer('divSelectByMultipoint'+sUniqueID);
			hideLayer('divSelectByPoint'+sUniqueID);
			hideLayer('divSelectByLine'+sUniqueID);
			break;
		case 10:
			m_divMap.style.cursor = 'crosshair';
			showLayer('divSelectByPolygon'+sUniqueID);
			hideLayer('divSelectByRect'+sUniqueID);
			hideLayer('divIdentify'+sUniqueID);
			hideLayer('divMeasureArea'+sUniqueID);
			hideLayer('divZoomIn'+sUniqueID);
			hideLayer('divZoomOut'+sUniqueID);
			hideLayer('divPan'+sUniqueID);
			hideLayer('divMeasure'+sUniqueID);
			hideLayer('divSelectByPolyline'+sUniqueID);
			hideLayer('divSelectByCircle'+sUniqueID);
			hideLayer('divSelectByMultipoint'+sUniqueID);
			hideLayer('divSelectByPoint'+sUniqueID);
			hideLayer('divSelectByLine'+sUniqueID);
		    break;	
		case 11:
			m_divMap.style.cursor = 'crosshair';
			showLayer('divSelectByPolyline'+sUniqueID);
			hideLayer('divSelectByRect'+sUniqueID);
			hideLayer('divIdentify'+sUniqueID);
			hideLayer('divMeasureArea'+sUniqueID);
			hideLayer('divZoomIn'+sUniqueID);
			hideLayer('divZoomOut'+sUniqueID);
			hideLayer('divPan'+sUniqueID);
			hideLayer('divMeasure'+sUniqueID);
			hideLayer('divSelectByPolygon'+sUniqueID);
			hideLayer('divSelectByCircle'+sUniqueID);
			hideLayer('divSelectByMultipoint'+sUniqueID);
			hideLayer('divSelectByPoint'+sUniqueID);
			hideLayer('divSelectByLine'+sUniqueID);
		    break;	
		case 12:
			m_divMap.style.cursor = 'crosshair';
			showLayer('divSelectByCircle'+sUniqueID);
			hideLayer('divSelectByRect'+sUniqueID);
			hideLayer('divIdentify'+sUniqueID);
			hideLayer('divMeasureArea'+sUniqueID);
			hideLayer('divZoomIn'+sUniqueID);
			hideLayer('divZoomOut'+sUniqueID);
			hideLayer('divPan'+sUniqueID);
			hideLayer('divMeasure'+sUniqueID);
			hideLayer('divSelectByPolygon'+sUniqueID);
			hideLayer('divSelectByPolyline'+sUniqueID);
			hideLayer('divSelectByMultipoint'+sUniqueID);
			hideLayer('divSelectByPoint'+sUniqueID);
			hideLayer('divSelectByLine'+sUniqueID);
		    break;	
		case 13:
			m_divMap.style.cursor = 'crosshair';
			showLayer('divSelectByMultipoint'+sUniqueID);
			hideLayer('divSelectByRect'+sUniqueID);
			hideLayer('divIdentify'+sUniqueID);
			hideLayer('divMeasureArea'+sUniqueID);
			hideLayer('divZoomIn'+sUniqueID);
			hideLayer('divZoomOut'+sUniqueID);
			hideLayer('divPan'+sUniqueID);
			hideLayer('divMeasure'+sUniqueID);
			hideLayer('divSelectByPolygon'+sUniqueID);
			hideLayer('divSelectByPolyline'+sUniqueID);
			hideLayer('divSelectByCircle'+sUniqueID);
			hideLayer('divSelectByPoint'+sUniqueID);
			hideLayer('divSelectByLine'+sUniqueID);
		    break;	
		case 14:
			m_divMap.style.cursor = 'crosshair';
			showLayer('divSelectByPoint'+sUniqueID);
			hideLayer('divSelectByRect'+sUniqueID);
			hideLayer('divIdentify'+sUniqueID);
			hideLayer('divMeasureArea'+sUniqueID);
			hideLayer('divZoomIn'+sUniqueID);
			hideLayer('divZoomOut'+sUniqueID);
			hideLayer('divPan'+sUniqueID);
			hideLayer('divMeasure'+sUniqueID);
			hideLayer('divSelectByPolygon'+sUniqueID);
			hideLayer('divSelectByPolyline'+sUniqueID);
			hideLayer('divSelectByCircle'+sUniqueID);
			hideLayer('divSelectByMultipoint'+sUniqueID);
			hideLayer('divSelectByLine'+sUniqueID);
		    break;	
		case 15:
			m_divMap.style.cursor = 'crosshair';
			showLayer('divSelectByLine'+sUniqueID);
			hideLayer('divSelectByRect'+sUniqueID);
			hideLayer('divIdentify'+sUniqueID);
			hideLayer('divMeasureArea'+sUniqueID);
			hideLayer('divZoomIn'+sUniqueID);
			hideLayer('divZoomOut'+sUniqueID);
			hideLayer('divPan'+sUniqueID);
			hideLayer('divMeasure'+sUniqueID);
			hideLayer('divSelectByPolygon'+sUniqueID);
			hideLayer('divSelectByPolyline'+sUniqueID);
			hideLayer('divSelectByCircle'+sUniqueID);
			hideLayer('divSelectByMultipoint'+sUniqueID);
			hideLayer('divSelectByPoint'+sUniqueID);
		    break;	
		default:
		    m_divMap.style.cursor = 'default';
		    break;	
	}
  hideLayer('imgLoading'+sUniqueID);
  setTracker(sUniqueID);
}
function fMouseMove(sUniqueID) {
if (!(isEventOverMap(sUniqueID, event.clientX, event.clientY))) {	
		return;
	} 
var m_txtX;
m_txtX = document.getElementById('ctlTxtCoordX'+sUniqueID);
var m_txtY;
m_txtY = document.getElementById('ctlTxtCoordY'+sUniqueID);
var m_fldScaleXY;
m_fldScaleXY = document.getElementById('fldScaleXY'+sUniqueID);
if ((m_txtX==null)||(m_txtY==null)) {} else {
reportCoords(toMapPoint(event.clientX, event.clientY, sUniqueID), m_txtX, m_txtY,m_fldScaleXY,sUniqueID);}
 var t = document.getElementById('fldToolActive'+sUniqueID);
 var toolActive = parseInt(t.value);
  if((toolActive==1)||(toolActive==2)||(toolActive==9)){
		if (m_zbxZoom==null) {
			return;
		}
		if (m_zbxZoom.isInProgress()) {
			m_zbxZoom.update(event.clientX, event.clientY);
		}
  }else if (toolActive==4){
        if (m_Pan==null) {
            return;
        }
        if (m_Pan.isInProgress()) {
			var m_divMap;
			m_divMap = document.getElementById('divMap'+sUniqueID);
			var m_Map; 
			m_Map = document.getElementById(sUniqueID);
			m_Pan.update(event.clientX, event.clientY);
			var xMove = m_Pan.getWidth();
			var yMove = m_Pan.getHeight();
			var cRight = m_Map.width;
			var cBottom = m_Map.height;
			if (xMove>0) {
				cRight = m_Map.width - xMove;
			}
			if (yMove>0) {
				cBottom = m_Map.height - yMove;
			}
			moveLayer('divMapPan'+sUniqueID,xMove+m_divMap.offsetLeft,yMove+m_divMap.offsetTop);
			clipLayer('divMapPan'+sUniqueID,-xMove,-yMove,cRight,cBottom); 
		}	
  }else if ((toolActive==5)||(toolActive==6)||(toolActive==10)||(toolActive==11)||(toolActive==15)){
	  var m_divMap;
	  m_divMap = document.getElementById('divMap'+sUniqueID);
      if (XYarray.length==0) {
          return;
      }
      var html;
      var points = getCoords();
      var p = toMapPoint(event.clientX, event.clientY, sUniqueID);
      points += (event.clientX - (parseInt(m_divMap.style.left)) + document.body.scrollLeft)+','+(event.clientY - (parseInt(m_divMap.style.top)) + document.body.scrollTop)+' ';
      if ((toolActive==5)||(toolActive==11)||(toolActive==15)){
         var distSegment = twoPntDistance(XYCoordarray[(XYCoordarray.length)-1].x,XYCoordarray[(XYCoordarray.length)-1].y,p.x,p.y);
         var txtSegment = document.getElementById('ctlTxtMeasureSegment'+sUniqueID);
         if (txtSegment==null) {} else {
            var fldScaleMeasure = document.getElementById('fldScaleMeasure'+sUniqueID);
            var fldFactorConversionMeasure = document.getElementById('fldFactorConversionMeasure'+sUniqueID);
            txtSegment.value=fRound(distSegment,fldScaleMeasure,parseFloat(fldFactorConversionMeasure.value));
         }
         var txtTot = document.getElementById('ctlTxtMeasureTotal'+sUniqueID);
         if (txtTot==null) {} else {
            var fldScaleMeasure = document.getElementById('fldScaleMeasure'+sUniqueID);
            var fldFactorConversionMeasure = document.getElementById('fldFactorConversionMeasure'+sUniqueID);
            txtTot.value=fRound(dist+distSegment,fldScaleMeasure,parseFloat(fldFactorConversionMeasure.value));
         }
         if (toolActive==5){
            var fldColorMeasure=document.getElementById('fldBorderColorMeasure'+sUniqueID);
            var fldThicknessMeasure=document.getElementById('fldBorderWidthMeasure'+sUniqueID);
            html = '<v:polyline id="vmlMeasure'+sUniqueID+'" strokeweight="' + fldThicknessMeasure.value + '" strokecolor="' + fldColorMeasure.value + '" filled="false" points="' + points + '"/>';
         }else if ((toolActive==11)||(toolActive==15)){
            var fldColorSelectByPolyline=document.getElementById('fldBorderColorSelectByPolyline'+sUniqueID);
            var fldThicknessSelectByPolyline=document.getElementById('fldBorderWidthSelectByPolyline'+sUniqueID);
            if ((XYarray.length == 2) && (toolActive==15)) {
              html = '<v:polyline id="vmlSelectByLine'+sUniqueID+'" strokeweight="' + fldThicknessSelectByPolyline.value + '" strokecolor="' + fldColorSelectByPolyline.value + '" filled="false" points="' + getCoords() + '"/>';
            }else{
              html = '<v:polyline id="vmlSelectByPolyline'+sUniqueID+'" strokeweight="' + fldThicknessSelectByPolyline.value + '" strokecolor="' + fldColorSelectByPolyline.value + '" filled="false" points="' + points + '"/>';
            }
         }
      }else if ((toolActive==6)||(toolActive==10)){
         if (XYarray.length>1) {points += (XYarray[0].x)+','+(XYarray[0].y);}
         if (toolActive==10){
            var fldBorderColorSelectByPolygon=document.getElementById('fldBorderColorSelectByPolygon'+sUniqueID);
            var fldBorderWidthSelectByPolygon=document.getElementById('fldBorderWidthSelectByPolygon'+sUniqueID);
            var fldColorSelectByPolygon=document.getElementById('fldColorSelectByPolygon'+sUniqueID);
            var fldOpacitySelectByPolygon=document.getElementById('fldOpacitySelectByPolygon'+sUniqueID);
            html = '<v:polyline id="vmlSelectByPolygon'+sUniqueID+'" points="' + points + '" strokeweight="' + fldBorderWidthSelectByPolygon.value + '" strokecolor="' + fldBorderColorSelectByPolygon.value + '" filled="true" > <v:fill opacity="' + fldOpacitySelectByPolygon.value + '" color="' + fldColorSelectByPolygon.value + '"  /> </v:polyline>';
         }else if (toolActive==6){		
            var fldBorderColorMeasureArea=document.getElementById('fldBorderColorMeasureArea'+sUniqueID);
            var fldBorderWidthMeasureArea=document.getElementById('fldBorderWidthMeasureArea'+sUniqueID);
            var fldColorMeasureArea=document.getElementById('fldColorMeasureArea'+sUniqueID);
            var fldOpacityMeasureArea=document.getElementById('fldOpacityMeasureArea'+sUniqueID);
            html = '<v:polyline id="vmlMeasureArea'+sUniqueID+'" points="' + points + '" strokeweight="' + fldBorderWidthMeasureArea.value + '" strokecolor="' + fldBorderColorMeasureArea.value + '" filled="true" > <v:fill opacity="' + fldOpacityMeasureArea.value + '" color="' + fldColorMeasureArea.value + '"  /> </v:polyline>';
         }
         var txtAreaTot = document.getElementById('ctlTxtMeasureAreaTotal'+sUniqueID);
         if (txtAreaTot==null) {} else {
           txtAreaTot.value=fArea(sUniqueID,p.x,p.y);
         }
      }
      el = document.getElementById('divMapMeasure'+sUniqueID);
      el.innerHTML = html;
  }else if (toolActive==12){		
		if (m_Circle==null) {
			return;
		}
		if (m_Circle.isInProgress()) {
			m_Circle.update(event.clientX, event.clientY);
		}else{return}
        var txtTot = document.getElementById('ctlTxtMeasureTotal'+sUniqueID);
        if (txtTot==null) {} else {
           var fldScaleMeasure = document.getElementById('fldScaleMeasure'+sUniqueID);
           var fldFactorConversionMeasure = document.getElementById('fldFactorConversionMeasure'+sUniqueID);
           var xc= toMapPoint(m_Circle.centerX(), m_Circle.centerY(), sUniqueID)
           var xs= toMapPoint(event.clientX, event.clientY, sUniqueID)
           txtTot.value='R: '+(fRound(twoPntDistance(xc.x,xc.y,xs.x,xs.y),fldScaleMeasure,parseFloat(fldFactorConversionMeasure.value))).toString();
        }
        var html;
        var fldBorderColorSelectByPolygon=document.getElementById('fldBorderColorSelectByPolygon'+sUniqueID);
        var fldBorderWidthSelectByPolygon=document.getElementById('fldBorderWidthSelectByPolygon'+sUniqueID);
        var fldColorSelectByPolygon=document.getElementById('fldColorSelectByPolygon'+sUniqueID);
        var fldOpacitySelectByPolygon=document.getElementById('fldOpacitySelectByPolygon'+sUniqueID);
        html = '<v:oval id="vmlSelectByCircle'+sUniqueID+'" style="position:absolute; left:'+(m_Circle.left()+offsetGeo).toString()+'px;top:'+(m_Circle.top()+offsetGeo).toString()+'px;width:' + m_Circle.width().toString() +'px;height:'+m_Circle.height().toString()+'px" strokeweight="' + fldBorderWidthSelectByPolygon.value + '" strokecolor="' + fldBorderColorSelectByPolygon.value + '" filled="true" > <v:fill opacity="' + fldOpacitySelectByPolygon.value + '" color="' + fldColorSelectByPolygon.value + '"  /> </v:oval>';
        el = document.getElementById('divMapMeasure'+sUniqueID);
        el.innerHTML = html;
  }
}
function fMouseUp(sUniqueID) {
  var t = document.getElementById('fldToolActive'+sUniqueID);
  var toolActive = parseInt(t.value);
  if ((toolActive==1)||(toolActive==2)||(toolActive==4)||(toolActive==9)) {
  }else{
    return;
  }
  var sCoo;
  if((toolActive==1)||(toolActive==2)||(toolActive==9)){
		if (m_zbxZoom.isInProgress()) {
			m_zbxZoom.stop();
            if ((Math.abs(m_zbxZoom.getStartX() - m_zbxZoom.getEndX()) < 5) && (Math.abs(m_zbxZoom.getStartY() - m_zbxZoom.getEndY()) < 5))  {	
              sCoo =(m_zbxZoom.getStartX().toString())+'|'+(m_zbxZoom.getStartY().toString())+'|'+(m_zbxZoom.getStartX().toString())+'|'+(m_zbxZoom.getStartY().toString());
            }else{
			  sCoo =(m_zbxZoom.getStartX().toString())+'|'+(m_zbxZoom.getStartY().toString())+'|'+(m_zbxZoom.getEndX().toString())+'|'+(m_zbxZoom.getEndY().toString());
            }
		} else {
			return;
		}
  }else if (toolActive==4){
        if (m_Pan.isInProgress()) {
			m_Pan.stop();
			sCoo=(m_Pan.getStartX().toString())+'|'+(m_Pan.getStartY().toString())+'|'+(m_Pan.getEndX().toString())+'|'+(m_Pan.getEndY().toString());
		} else {
           return;
        }
  }
  document.releaseCapture();
	// CALL MarqueeStart
	MarqueeStart();
	// END
  __doPostBack(sUniqueID, toolActive.toString()+'|'+sCoo);
}
function fPostBack(sUniqueID,toolActive) {
   fCursor(sUniqueID, toolActive);
   if (toolActive==4) {
      showLayer(sUniqueID);
      hideLayer('divMapPan'+sUniqueID);
   }
}
function setTracker(sUniqueID) {
  var fldTrackRefreshTime;
  fldTrackRefreshTime = document.getElementById('fldTrackRefreshTime'+sUniqueID);
  var TrackRefreshTime = parseInt(fldTrackRefreshTime.value);
  if (TrackRefreshTime > 0 ) {
     setInterval("Tracker('"+sUniqueID+"')",TrackRefreshTime);
  }
}
function Tracker(sUniqueID) {
   var t = document.getElementById('fldToolActive'+sUniqueID);
   var toolActive = t.value;
   // CALL MarqueeStart
   MarqueeStart();
   // END
   __doPostBack(sUniqueID, '8|'+toolActive);
}
function isEventOverMap(sUniqueID, eventX, eventY) {
 var m_divMap;
 m_divMap = document.getElementById('divMap'+sUniqueID);
 var TagLeft = parseInt(m_divMap.style.left) - document.body.scrollLeft;
 var TagTop = parseInt(m_divMap.style.top) - document.body.scrollTop;
 var TagWidth = parseInt(m_divMap.style.width);
 var TagHeight = parseInt(m_divMap.style.height);
 if ((eventX <= TagLeft) ||
 (eventY <= TagTop) ||
		(eventX > (TagWidth + TagLeft)) ||
		(eventY > (TagHeight + TagTop))) {
	return false;
 } else {
	return true;
 }
}
function toMapPoint(pageX, pageY, sUniqueID) {
var m_fldXMin;
m_fldXMin = document.getElementById('fldCoordXMin'+sUniqueID);
var m_fldXMax;
m_fldXMax = document.getElementById('fldCoordXMax'+sUniqueID);
var m_Width = (parseFloat(m_fldXMax.value))-(parseFloat(m_fldXMin.value));
var m_fldYMin;
m_fldYMin = document.getElementById('fldCoordYMin'+sUniqueID);
var m_fldYMax;
m_fldYMax = document.getElementById('fldCoordYMax'+sUniqueID);
var m_Height = (parseFloat(m_fldYMax.value))-(parseFloat(m_fldYMin.value));
 var m_divMap;
 m_divMap = document.getElementById('divMap'+sUniqueID);
 var m_iTagLeft = parseInt(m_divMap.style.left) - document.body.scrollLeft;
 var m_iTagTop = parseInt(m_divMap.style.top) - document.body.scrollTop;
 var m_iTagWidth = parseInt(m_divMap.style.width);
 var m_iTagHeight = parseInt(m_divMap.style.height);
var ptPixelsInTag = new point(pageX - m_iTagLeft, pageY - m_iTagTop);
var dblX = parseFloat(m_fldXMin.value) + ((ptPixelsInTag.x / m_iTagWidth) * (m_Width));
var dblY = parseFloat(m_fldYMin.value) + (((m_iTagHeight - ptPixelsInTag.y) / m_iTagHeight) * (m_Height));
return (new point(dblX, dblY));
}
function reportCoords(ptReport, m_txtX, m_txtY, fldScaleXY, sUniqueID) {
 var isCGS;
 var isCGS = document.getElementById('fldIsGCS'+sUniqueID);
 if (isCGS.value =='True') {
    m_txtX.value = fDDtoDMS(ptReport.x,fldScaleXY); 
    m_txtY.value = fDDtoDMS(ptReport.y,fldScaleXY); 
 } else {
    m_txtX.value = fRound(ptReport.x,fldScaleXY,1); 
    m_txtY.value = fRound(ptReport.y,fldScaleXY,1); 
 }
}
function fDDtoDMS(TheValue, fldScale) {
 var TheSgn = '';
if (TheValue < 0) {
 TheValue = Math.abs(TheValue);
 TheSgn = '- ';
}
var D = Math.floor(TheValue);
var DD = ((TheValue-D)*60);
var M = Math.floor(DD);
var S = fRound(((DD-M)*60),fldScale,1);
return (TheSgn + D.toString() + '\u02DA ' + M.toString() + '\' '+ S.toString()+'\'\''); 
}
function fRound(TheValue, fldScale, TheFactor) {
var TheScale = Math.pow(10.0, parseInt(fldScale.value));
return (Math.round((TheValue/TheFactor)*TheScale)/TheScale).toString(); 
}
function fZoomExtent(sUniqueID) {
 var t = document.getElementById('fldToolActive'+sUniqueID);
 var toolActive = t.value;
	// CALL MarqueeStart
	MarqueeStart();
	// END
     __doPostBack(sUniqueID,'3|'+toolActive);
}
function clipLayer(name, clipleft, cliptop, clipright, clipbottom) {		
	var layer = getLayer(name);		
	if (layer != null) {
			layer.clip = 'rect(' + cliptop + ' ' +  clipright + ' ' + clipbottom + ' ' + clipleft +')';
	}
}
function moveLayer(name, x, y) {
  	var layer = getLayer(name);		
	if (layer != null) {
    		layer.left = x + 'px';
   			layer.top  = y + 'px';
	} 
}
function showLayer(name) {		
  	var layer = getLayer(name);		
	if (layer != null) {
   		 	layer.visibility = 'visible';
	}
}
function getLayer(name) {
	    var theObj = document.getElementById(name);
	if (theObj == null) {
	 	return theObj;
	}else{
		return theObj.style;}
}
function hideLayer(name) {		
  	var layer = getLayer(name);		
	if (layer != null) {
	 	layer.visibility = 'hidden';
	}
}
function point(numX,numY) {
this.x = numX;
this.y = numY;
}
function cZoom(divZoomBox) {
	var m_divZoomBox = divZoomBox;
	var m_bInProgress = false;
	var m_iStartX = null;
	var m_iStartY = null;
	var m_iEndX = null;
	var m_iEndY = null;
	var m_offsetX = null;
	var m_offsetY = null;
	this.isInProgress = isInProgress;
	this.getStartX = getStartX;
	this.getStartY = getStartY;
	this.getEndX = getEndX;
	this.getEndY = getEndY;
	this.start = start;
	this.update = update;
	this.stop = stop;
	this.show = show;
	this.hide = hide;
    this.offsetX = offsetX;
    this.offsetY = offsetY;
	function start(x, y) {
		m_iStartX = x - m_offsetX + document.body.scrollLeft;
		m_iStartY = y - m_offsetY + document.body.scrollTop;
		m_iEndX = x - m_offsetX + document.body.scrollLeft;
		m_iEndY = y - m_offsetY + document.body.scrollTop;
		m_divZoomBox.style.left = m_iStartX;
		m_divZoomBox.style.top = m_iStartY;
		m_divZoomBox.style.width = 0;
		m_divZoomBox.style.height = 0;
		m_bInProgress = true;		
	}
	function update(x, y) {
		if (!(m_bInProgress)) {
			return false;
		}
		m_iEndX = x - m_offsetX + document.body.scrollLeft;
		m_iEndY = y - m_offsetY + document.body.scrollTop;
		var iWidth = m_iEndX - m_iStartX;
		var iHeight = m_iEndY - m_iStartY;
		if (iWidth > 0) {
			m_divZoomBox.style.left = m_iStartX;
		} else {
			m_divZoomBox.style.left = m_iEndX;
		}
		if (iHeight > 0) {
			m_divZoomBox.style.top = m_iStartY;
		} else {
			m_divZoomBox.style.top = m_iEndY;
		}
		m_divZoomBox.style.width = Math.abs(iWidth);
		m_divZoomBox.style.height = Math.abs(iHeight);
	}
	function stop() {
		m_bInProgress = false;
	}
	function show() {
		m_divZoomBox.style.visibility = 'visible';
	}
	function hide() {
		m_divZoomBox.style.visibility = 'hidden';
	}
    function getStartX() {
		return m_iStartX;
	}
	function getStartY() {
		return m_iStartY;
	}
	function getEndX() {
		return m_iEndX;
	}
	function getEndY() {
		return m_iEndY;
	}
	function isInProgress() {
		return m_bInProgress;
	}
	function offsetX(dx) {
		m_offsetX = dx;
	}
	function offsetY(dy) {
		m_offsetY = dy;
	}
}
function cPan() {
	var m_bInProgress = false;
	var m_iStartX = null;
	var m_iStartY = null;
	var m_iEndX = null;
	var m_iEndY = null;
	var m_iWidth = null;
    var m_iHeight = null;
	this.isInProgress = isInProgress;
	this.getStartX = getStartX;
	this.getStartY = getStartY;
	this.getEndX = getEndX;
	this.getEndY = getEndY;
    this.getWidth = getWidth;
    this.getHeight = getHeight;
	this.start = start;
	this.update = update;
	this.stop = stop;
    function start(x, y) {
		m_iStartX = x;
		m_iStartY = y;
		m_iEndX = x;
		m_iEndY = y;
		m_bInProgress = true;		
	}
	function update(x, y) {
		if (!(m_bInProgress)) {
			return false;
		}
		m_iEndX = x;
		m_iEndY = y;
		m_iWidth = m_iEndX - m_iStartX;
		m_iHeight = m_iEndY - m_iStartY;
	}
	function stop() {
		m_bInProgress = false;
	}
	function getStartX() {
		return m_iStartX;
	}
	function getStartY() {
		return m_iStartY;
	}
	function getEndX() {
		return m_iEndX;
	}
	function getEndY() {
		return m_iEndY;
	}
	function getHeight() {
		return m_iHeight;
	}
	function getWidth() {
		return m_iWidth;
	}
	function isInProgress() {
		return m_bInProgress;
	}
}
function cCircle() {
	var m_iStartX = null;
	var m_iStartY = null;
	var m_bInProgress = false;
    var m_radius = null;
    var m_left = null;
    var m_top = null;
    var m_width = null;
    var m_height = null;
    var m_offsetX = null;
    var m_offsetY = null;
	this.getRadius = getRadius;
	this.stop = stop;
	this.update = update;
	this.isInProgress = isInProgress;
	this.start = start;
	this.left = left;
	this.top = top;
	this.width = width;
	this.height = height;
	this.offsetX = offsetX;
	this.centerX = centerX;
	this.centerY = centerY;
	this.offsetX = offsetX;
	this.offsetY = offsetY;
    function start(x, y) {
		m_iStartX = x ;
		m_iStartY = y ;
		m_bInProgress = true;		
	}
	function isInProgress() {
		return m_bInProgress;
	}
	function update(x, y) {
		if (!(m_bInProgress)) {
			return false;
		}
		m_radius = Math.round(twoPntDistance(x,y ,m_iStartX, m_iStartY));
		m_left = m_iStartX - m_radius - m_offsetX + document.body.scrollLeft;
		m_top = m_iStartY - m_radius - m_offsetY + document.body.scrollTop;
		m_width = 2 * m_radius;
		m_height = m_width;
	}
	function getRadius() {
		return m_radius;
	}
	function stop() {
		m_bInProgress = false;
	}
	function left() {
		return m_left;
	}
	function top() {
		return m_top;
	}
	function centerX() {
		return m_iStartX;
	}
	function centerY() {
		return m_iStartY;
	}
	function width() {
		return m_width;
	}
	function height() {
		return m_height;
	}
	function offsetX(dx) {
		m_offsetX = dx;
	}
	function offsetY(dy) {
		m_offsetY = dy;
	}
}
