// 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;

	var floodStatus = 0;
	



// custom function for handling clicks 
// 		flow redirected here when
//		toolMode set to >=1000
function customMapTool(e) {
				//===============================
				// Ditch Inventory
				// Akinmade 4/24/2002
				//===============================
				if (toolMode == 1001) {
					if (checkIfActiveLayerAvailable()) {
						selectDitch(e);
					}
				}
				//===============================
				if (toolMode == 1002) {
						// insert code here

				}

}


function useCustomFunction(theReply) {
	//=========================================
	// Receive reply from server... Flow redirected here due to custom function
	// Flood Plain Analysis
	// Cycles through all flood plain layers to find an intersection
	// LaCombe 09/19/2002
	//=========================================

	if (XMLMode==1001) {

		var Win1 = parent.TextFrame;
		Win1.document.open();
		var t = parent.MapFrame;
		
		var floodCount = justGetFeatureCount(theReply);
		//alert("Flood Count:" + floodCount);
		
		if (floodCount==0) {
			
			if (floodStatus==0) {
				FloodBuffer(6);
				floodStatus = 2;
			} else if (floodStatus==2) {
				FloodBuffer(7);
				floodStatus = 3;
			} else if (floodStatus==3) {
				Win1.document.writeln('<tr><td align="left" bgcolor="#000063"><FONT face=Verdana size=2 color="#000063"><b>This parcel is not located within the Floodway, 100 Year Flood Plain, or the 500 year Flood Plain.</b></FONT></td></tr>');
			}

		} else { 
		
				//alert(baseURL);
				
				Win1.document.location="http://maps.sagagis.org/Vassar/FloodExist.htm"
				

				//display intersecting flood plain
				t.LayerVisible[t.bufferTargetLayerIndex]=1;
				//bufferIt();
				t.sendMapXML();
				floodStatus = 1;
		}
		
		
	//=========================================		
	} else {
		alert(msgList[55] + XMLMode + msgList[56]);
	}
}

// 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]);
}

//function DisplayForm() {
	//alert("Hello");
	//var webParams = win1.document.location.search;
	//win1.document.open("FloodForm.pdf" + webParams);
//}

///=======================================================
// Custom Functions for Flood Inalysis
// performs the buffer selection of selected parcel and any intersecting flood plains
// Joe LaCombe - 09/20/02
//========================================================
function FloodBuffer(i) {
		
		var Win1 = parent.TextFrame;
		Win1.document.open();
		var t = parent.MapFrame;		
		floodStatus = 0;
		
		var f = document.forms[0];
		t.bufferDistance = 0;			
	    t.bufferTargetLayerIndex = i;
		//alert(i);
		t.drawTargetLayer=true;
		t.getBufferedData=false;
				
				if (t.bufferDistance>=0) {
					//t.bufferIt();
						var buffString = "";
						//bufferSmoothEdges = bufferDistance /1001;
						//alert(selectionMode);
						queryStartRecord=0;
						//showRetrieveData();
						switch(selectionMode) {
							case 1:
								buffString = writeQueryBufferXML();
								break
							case 2:
								buffString = writeEnvelopeBufferXML();
								break
							case 3:
								buffString = writeShapeBufferXML(clickType-1);
								break
						}
						
			// - goes to aimsXML.sendtoserver - Server response then redirected to 
			//   aimsCustom.useCustomFunction(above in script)
			
						sendToServer(imsQueryURL,buffString,1001);
						
				} else {
		
				}

}	


function loadMapViews(yourLyrName) {

	var t = parent.MapFrame;
	
	for (var i=0;i<LayerName.length;i++) {
	
		 //alert ("aimsXML/LyrName=" + LayerName[i]);
		 if (t.LayerName[i] == yourLyrName) {
		 
			t.ActiveLayer=t.LayerID[i];
			t.ActiveLayerType=t.LayerType[i];
			t.ActiveLayerIndex=i;
			t.LayerVisible[i] = 1;
			t.setActiveLayer(i);	
		 	break;
		 }
	}

}
