
var SelectionLayer= lyrNm[actLyrIndex]; 

var selectData = new Array();
var selectLeft = new Array();
var selectRight = new Array();
var selectTop = new Array();
var selectBottom = new Array();

var selectType = "";
var selectCount = 0;
var selectEnvelope="";

var queryMode=1;

var selectionMode=1;
var setQueryString="";


function f84(e) { //startSelectBox

	f35("theMap",hspc,vspc);
	f72(e);
	// keep it within the MapImage
	if ((mouseX<iWidth) && (mouseY<iHeight)) {
		if (selectBox) {
			f85(e);
		} else {
			x1=mouseX;
			y1=mouseY
			x2=x1+1;
			y2=y1+1;
			zleft=x1;
			ztop=y1;
			zbottom=y1;
			zright=x1
			f41(x1,y1,x2,y2);
			selectBox=true;
			showLayer("zoomBoxTop");
			showLayer("zoomBoxLeft");
			showLayer("zoomBoxRight");
			showLayer("zoomBoxBottom");
		}

	}
	return false;

}

function f85(e) { //stopSelectBox
	selectBox=false;
	var tempLeft=lastLeft;
	var tempRight=lastRight;
	var tempTop=lastTop;
	var tempBottom=lastBottom;

	var xdist=Math.abs(zright-zleft);
	var ydist=Math.abs(zbottom-ztop);
	if ((xdist <= 2) && (ydist <= 2)) {
        f71(mouseX,mouseY);
		tempLeft = mapX-0.2;
		tempTop = mapY-0.2;
		tempRight = mapX+0.2;
		tempBottom = mapY+0.2;

	} else {
	
		pixelX = xDistance / iWidth;
		var theY = iHeight - ztop;
		pixelY = yDistance / iHeight;
		tempTop = pixelY * theY + bottom;
		tempRight = pixelX * zright + left;
		tempLeft = pixelX * zleft + left;
		theY = iHeight - zbottom;
		pixelY = yDistance / iHeight;
		tempBottom = pixelY * theY + bottom;
	}
	window.scrollTo(0,0);
	
	queryStartRecord=1;
	searchTolerance = (xDistance/iWidth) * pixelTolerance;
	drawSelectBoundary=true;
	selectionMode=2;
	selectType=ActLyrTyp;

	hideLayer("zoomBoxTop");
	hideLayer("zoomBoxLeft");
	hideLayer("zoomBoxRight");
	hideLayer("zoomBoxBottom");

	selectEnvelope="maxy='" + tempTop + "' maxx='" + tempRight + "' miny='" + tempBottom + "' minx='" + tempLeft + "'";
reportEnvelope=selectEnvelope; 
	var curland=false;
	for (var i=0;i<layerCount;i++) {
		//alert(lyrNm[i]+"   "+i+"     "+actLyrIndex);
		  if ((lyrNm[i]=="Cadastre")|| (lyrNm[i]=="Cad Areas and Plan Text")) { 
			  if(i==actLyrIndex) {
				  //the active layer is the Cadastre layer
				  curland=true;
	          }
		  }
	}
    if(curland){
       //we need to set the active layer to another layer because tha cadastre is pointing
	   //to a line layer.  We need to goto a poly layer eg:"Cad Areas and Plan Text"  which is 
	   // a hidden layer in the TOC.  This will happen in the asp
		for (var i=0;i<layerCount;i++) {
			//alert(lyrNm[i]+"   "+i+"     "+actLyrIndex);
			  if (lyrNm[i]=="Cad Areas and Plan Text") {
				  	ActLyr=lyrId[i];
	                ActLyrTyp=lyrTyp[i];
	                actLyrIndex=i;
					selectType=ActLyrTyp; 
			  }
		}
        selectCount=0; 
        //reportMode=2;
		//generate a shape (poly) from the envelope
		selectShape="<POLYGON><RING>";
        selectShape=selectShape+"<POINT x='"+tempLeft+"' y='"+tempBottom+"' />";
        selectShape=selectShape+"<POINT x='"+tempLeft+"' y='"+tempTop+"' />";    
        selectShape=selectShape+"<POINT x='"+tempRight+"' y='"+tempTop+"' />";    
        selectShape=selectShape+"<POINT x='"+tempRight+"' y='"+tempBottom+"' />";    
        selectShape=selectShape+"<POINT x='"+tempLeft+"' y='"+tempBottom+"' />";    //for back to first point to finish the polygon
        selectShape=selectShape+'</RING></POLYGON>';    

	    sendToServerASP(66); 
      }else{
        selectCount=0; 
        reportMode=2; 
	    //sendToServerASP(6);
        writeFeatureReport();  
      }
	return true;

}


function f88() { //clearSelection

	hasInActiveQueryLyr=false;
	var theCount = selectCount;
	var theHL = "";
	selectCount=0;

	thelayervariable="";
	searchlayertype="";
	SearchQueryString=""; 
	is_roads=false;

	selectLeft.length=1;
	selectRight.length=1;
	selectTop.length=1;
	selectBottom.length=1;
	drawSelectBoundary=false;
	if (is5up) f103();

	if (toolMode==20) {
		showLayer("measureBox");
		totalMeasure=0;
		currentMeasure=0;
		f13();
	}


	clickCount=0;
    //Mackay for markup
	if(drawing){
		parent.RefreshFrame.document.all("Tabs").src="images/tab_layers.gif";
		parent.TOCFrame.document.location=appDir+"toc.htm";
	}
	clear_Draw_Path();
	draw_Pts=0;
	draw_Str="";
	draw_Points.length=0;
	draw_color.length=0;
	draw_size.length=0;
	pts.length=0;
	pts_color.length=0;
	pts_size.length=0;
	pts_type.length=0;
	pts_count=0;
	drawCount=0;
	linepoints=0;
	drawfirst=true;
	firstpoint="";
	drawing=false;
	LabelX.length=0;
	LabelY.length=0;
	LabelText.length=0;
	LabelColor.length=0;
	LabelSize.length=0;
	LabelCount=0;
	labeltex="";
	dimensioning.length=0; 

	project_pts.length=0;
    project_pts_count=0;
    projectmp=0;

//end mackay cleanup for drawing

	legendTemp=legendVisible;
	legendVisible=false;
	
	if ((is5up==false) || (toolMode!=20)) {
		showLayer("LoadData");
		writeXMLASP(99);
	}


}

 


function MCCselShape() { //called for end of line and polygon selection
	/*selectBox=false;
	var tempLeft=lastLeft;
	var tempRight=lastRight;
	var tempTop=lastTop;
	var tempBottom=lastBottom;

	var xdist=Math.abs(zright-zleft);
	var ydist=Math.abs(zbottom-ztop);
	if ((xdist <= 2) && (ydist <= 2)) {
        f71(mouseX,mouseY);
		tempLeft = mapX-0.2;
		tempTop = mapY-0.2;
		tempRight = mapX+0.2;
		tempBottom = mapY+0.2;

	} else {
	
		pixelX = xDistance / iWidth;
		var theY = iHeight - ztop;
		pixelY = yDistance / iHeight;
		tempTop = pixelY * theY + bottom;
		tempRight = pixelX * zright + left;
		tempLeft = pixelX * zleft + left;
		theY = iHeight - zbottom;
		pixelY = yDistance / iHeight;
		tempBottom = pixelY * theY + bottom;
	}*/
	window.scrollTo(0,0);
	
	queryStartRecord=1;
	searchTolerance = (xDistance/iWidth) * pixelTolerance;
	drawSelectBoundary=true;
	selectionMode=2;
	selectType=ActLyrTyp;

	//hideLayer("zoomBoxTop");
	//hideLayer("zoomBoxLeft");
	//hideLayer("zoomBoxRight");
	//hideLayer("zoomBoxBottom");

	selectShape="";
	if(clickType==3){    //polygons
		selectShape="<POLYGON><RING>";
		for(i=0;i<clickCount;i++){
           selectShape=selectShape+"<POINT x='"+clickPointX[i]+"' y='"+clickPointY[i]+"' />";
        }
        selectShape=selectShape+"<POINT x='"+clickPointX[0]+"' y='"+clickPointY[0]+"' />";    //for back to first point to finish the polygon
        selectShape=selectShape+'</RING></POLYGON>'; 
    }
	if(clickType==2){    //lines
		selectShape="<POLYLINE><PATH>";
		for(i=0;i<clickCount;i++){
           selectShape=selectShape+"<POINT x='"+clickPointX[i]+"' y='"+clickPointY[i]+"' />";    
        }
        selectShape=selectShape+'</PATH></POLYLINE>'; 
    }

	var curland=false;
	for (var i=0;i<layerCount;i++) {
		//alert(lyrNm[i]+"   "+i+"     "+actLyrIndex);
		  if ((lyrNm[i]=="Cadastre")|| (lyrNm[i]=="Cad Areas and Plan Text")) { 
			  if(i==actLyrIndex) {
				  //the active layer is the Cadastre layer
				  curland=true;
	          }
		  }
	}
    if(curland){
       //we need to set the active layer to another layer because tha cadastre is pointing
	   //to a line layer.  We need to goto a poly layer eg:"Cad Areas and Plan Text"  which is 
	   // a hidden layer in the TOC.  This will happen in the asp
		for (var i=0;i<layerCount;i++) {
			//alert(lyrNm[i]+"   "+i+"     "+actLyrIndex);
			  if (lyrNm[i]=="Cad Areas and Plan Text") {
				  	ActLyr=lyrId[i];
	                ActLyrTyp=lyrTyp[i];
	                actLyrIndex=i;
					selectType=ActLyrTyp; 
			  }
		}
        selectCount=0;
	    setQueryString="";
        //reset
clickCount=0;
clickPointX.length=0; 
clickPointY.length=0;
	    sendToServerASP(66);
     }else{
clickCount=0;
clickPointX.length=0;
clickPointY.length=0;
 
		selectCount=0;
	    setQueryString="";
	    writeFeatureReport(); ;
     }
	return true;

}
