// aimsCustom.js
/*
*  JavaScript template file for ArcIMS HTML Viewer
*		dependent on aimsXML.js, ArcIMSparam.js, aimsCommon.js, aimsMap.js,
*		aimsLayers.js, aimsDHTML.js
*		aimsClick.js, aimsNavigation.js,
*/

// global variables
	aimsCustomPresent=true;
	// change these to send XML response to custom function.
	// use numbers >= 1000 and match in useCustomFunction()
	// defaults are defined in aimsXML.js and use standard functions
	
	// xml response mode for selection
	selectXMLMode = 6;
	// xml response mode for identify
	identifyXMLMode = 7;
	// xml response mode for query
	queryXMLMode = 8;
	// xml response mode for find
	findXMLMode = 14;
	// xml response mode hyperlink
	hyperlinkXMLMode = 15;





// custom function for handling clicks 
// 		flow redirected here when
//		toolMode set to >=1000
function customMapTool(e) {
				if (toolMode == 1001) {
				// Addedd by Dnyanada 10/24/2003 start
						//first do a clear selection before marking a point
						selectCount=0;
						showBuffer=false;
						highlightedOne="";
						selectPoints.length=0;
						selectLeft.length=0;
						selectRight.length=0;
						selectTop.length=0;
						selectBottom.length=0;
						drawSelectBoundary=false;
						showGeocode=false;
						BufferGeocode = false;
						BufferMuni = false;
						
						clickCount=0;
						totalMeasure=0;
						currentMeasure=0;
						
						var theX = mouseX;
						var theY = mouseY;
						
						getMapXY(theX,theY); //Convert into mapcoordinates
						aimsSetOrigin=true;
						
						legendTemp=legendVisible;
						//legendVisible=false;
						legendVisible=true;//Dnyanada 3/10/2004
						
						//Dnyanada added if statement 1/5/2004
						//alert("mapScaleFactor = " + mapScaleFactor);
						var u = Math.pow(10,numDecimals);
						SetOriginX = parseInt(mapX * u + (5/10)) / u;
						SetOriginY = parseInt(mapY * u + (5/10)) / u;

						var theLabel = SetOriginX +', '+ SetOriginY;
						//commented out by Dnyanada 1/26/2004 start
					//	if (mapScaleFactor > 1000) {
					//	var zoomFactor = 5; //Changed from 8 to 5 by Dnyanada 1/26/2004
					//	alert("ZoomtopointTry above 1000 5");
					//	zoomToPointTry(SetOriginX,SetOriginY,true,theLabel,zoomFactor);
					//	}
					//	else 
					//commented out by Dnyanada 1/26/2004 end
					
						if (mapScaleFactor > 70) 
						//Start Dnyanada zoomto set origin point 12/1/2003
						{
						//alert("ZoomtopointTry above 70 5 ");
							var zoomFactor = 5;//Changed from 6 to 5 by Dnyanada 1/26/2004
							zoomToPointTry(SetOriginX,SetOriginY,true,theLabel,zoomFactor);
						}
						else if (mapScaleFactor > 26) 
						//Start Dnyanada zoomto set origin point 12/1/2003
						{
							var zoomFactor = 4;
							zoomToPointTry(SetOriginX,SetOriginY,true,theLabel,zoomFactor); 
						}
						else{
						
								//1/15/2004
								showGeocode=true;
								geocodeX=SetOriginX;
								geocodeY=SetOriginY;
								geocodeLabel=theLabel;	
								//1/15/2004
																		
							sendMapXML(); //Commented out by Dnyanada 12/1/2003
						}
						//End Dnyanada 12/1/2003
						
						//end Dnyanada						
						
						//showRetrieveMap();
						//var theString = writeXML();
						//var theNum = 5001;
						//sendToServer(imsURL,theString,theNum);
						//return false;
				}
				if (toolMode == 1002) {
						// insert code here	

				}

}



//Code added by Dnyanada to zoom to when searched by coordinates 12/2/2003
//Start
function customMapTool1(mapX,mapY) {						
				selectCount=0;
				showBuffer=false;
				highlightedOne="";
				selectPoints.length=0;
				selectLeft.length=0;
				selectRight.length=0;
				selectTop.length=0;
				selectBottom.length=0;
				drawSelectBoundary=false;
				showGeocode=false;
				BufferGeocode = false;
				BufferMuni = false;		
				clickCount=0;
				totalMeasure=0;
				currentMeasure=0;
				aimsSetOrigin=true;				
				legendTemp=legendVisible;
				
				//legendVisible=false;
				legendVisible=true;//Dnyanada 3/10/2004
						
				var u = Math.pow(10,numDecimals);
				SetOriginX = parseInt(mapX * u + (5/10)) / u
				SetOriginY = parseInt(mapY * u + (5/10)) / u

				var theLabel = SetOriginX +', '+ SetOriginY
				
				//Changed by Dnyanada to zoom to imagery 1/16/2004
				//zoomToPoint(SetOriginX,SetOriginY,true,theLabel); 
				zoomToPointTry(SetOriginX,SetOriginY,true,theLabel,5); //Changed from 3 to 5 by Dnyanada 1/27/2004 
				
						
}

//Dnyanada end 12/2/2003

// send  XML response to custom function
//		flow  redirected here when
//		XMLMode >=1000
function useCustomFunction(theReply) {
	if (XMLMode==1001) {
		// insert code here
	} else if (XMLMode==1002) {
		// insert code here
	} else {
		alert(msgList[55] + XMLMode + msgList[56]);
	}
	hideLayer("LoadData");
}

// add custom stuff to Map XML request. . . between selection and geocode
function addCustomToMap1(){
	var customString = "";
	/*
		customString += '<LAYER type="ACETATE" name="theMode">\n';
		customString += '<OBJECT units="PIXEL">\n<TEXT coord="5 ' + (iHeight-10) + '" label="This is a test">\n';
		customString += '<TEXTMARKERSYMBOL fontstyle="BOLD" fontsize="12" font="ARIAL" fontcolor="' + modeMapColor + '" ';
		customString += 'threed="TRUE" glowing="' + modeMapGlow + '" />\n</TEXT>\n</OBJECT>';
		customString += '\n</LAYER>\n';
	*/
	return customString;
}

// add custom stuff to Map XML request. . . between clickpoints and copyright
function addCustomToMap2(){
	var customString = "";
	
	return customString;
}

// add custom stuff to Map XML request. . . under modeOnMap
function addCustomToMap3(){
	var customString = "";
		/*
		customString += '<LAYER type="ACETATE" name="theMode">\n';
		customString += '<OBJECT units="PIXEL">\n<TEXT coord="5 ' + (iHeight-10) + '" label="This is a test">\n';
		customString += '<TEXTMARKERSYMBOL fontstyle="BOLD" fontsize="12" font="ARIAL" fontcolor="' + modeMapColor + '" ';
		customString += 'threed="TRUE" glowing="' + modeMapGlow + '" />\n</TEXT>\n</OBJECT>';
		customString += '\n</LAYER>\n';
		alert(customString);
		*/
	return customString;
}

// add custom stuff to Map XML request. . . on top of everything
function addCustomToMap4(){
	var customString = "";
	
	return customString;
}

// extract layers to download
function extractIt() {
	hideLayer("measureBox");
	alert(msgList[51]);
}



//Dnyanada start 3/14/2006

//this for zoom to scale functionality
  function doZoomScale(zval) {
     //Added by Dnyanada so the map won't zoom out beyond the initial map extent 5/2/2006
	
	tempMapScale = tempMapScale + (10 * tempMapScale)/100;
	
	//alert ("zval = " + zval);
	//alert ("tempMapScale = " + tempMapScale);
	
	
	if (zval > tempMapScale){
		zval = tempMapScale;
   }
   //end
   saveLastExtent();
   var msize;
   if ( iHeight < iWidth) {
      msize = iHeight
   } else {
      msize = iWidth
   } 
   var midX = eRight - (xDistance / 2);
   var midY = eTop - (yDistance / 2);
   var mscale= (zval * ((msize/96)/12)) * .5;
   eLeft = ((midX) - (mscale));
   eRight =  ((midX) + (mscale));
   eBottom = ( (midY) - (mscale));
   eTop =  ((midY) + (mscale));

   sendMapXML(); 

}	
//end zoom to scale functionality

//End Dnyanada 3/14/2006
