// 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=false;
	// 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) {
						// insert code here
						return false;
					
				}
				if (toolMode == 1002) {
						// insert code here

				}

}

// 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 = "";
	//alert("GOT: formationDisplay: " + formationDisplay); 
	//aimsCustomPresent=false;
	/*
		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';
	*/
		customString += '<LAYER type="featureclass" name="' + vegSelectedName + '" visible="true" id="' + vegSelectId + '">\n';
		customString += '  <DATASET fromlayer="' + VegFormLayer + '" />\n';
		//customString += '  <SPATIALQUERY where="' + vegLookupField + '=&apos;' + vegLookupField + '&apos;" />\n';
		if (formationDisplay==0 && aimsCustomPresent2)
		{
			//alert("Looking up: " + vegLookupField); 
			customString += '    <VALUEMAPRENDERER lookupfield="' + vegLookupField + '">\n';
			customString += '      <EXACT value="1" label="' + fldText[0] + '" >\n';
			customString += '        <SIMPLEPOLYGONSYMBOL boundarytransparency="0.0" filltransparency="0.8" fillcolor="' + fldRBGValues[0] + '" boundarycolor="0,0,0" boundarycaptype="round" />\n';
			customString += '      </EXACT>\n';
			customString += '    </VALUEMAPRENDERER>\n';
		}
		else {
			customString += '  <GROUPRENDERER>\n';
			customString += '    <VALUEMAPRENDERER lookupfield="' + vegLookupField + '">\n';
			customString += '      <EXACT value="1" label="' + areaclasspcs_esc[1] + '" >\n';
			customString += '        <SIMPLEPOLYGONSYMBOL boundarytransparency="0.0" filltransparency="0.8" fillcolor="255,255,0" boundarycolor="0,0,0" boundarycaptype="round" />\n';
			customString += '      </EXACT>\n';
			customString += '      <EXACT value="2" label="' + areaclasspcs_esc[2] + '" >\n';
			customString += '        <SIMPLEPOLYGONSYMBOL boundarytransparency="0.0" filltransparency="0.8" fillcolor="250,176,0" boundarycolor="0,0,0" boundarycaptype="round" />\n';
			customString += '      </EXACT>\n';
			customString += '      <EXACT value="3" label="' + areaclasspcs_esc[3] + '" >\n';
			customString += '        <SIMPLEPOLYGONSYMBOL boundarytransparency="0.0" filltransparency="0.8" fillcolor="255,127,0" boundarycolor="0,0,0" boundarycaptype="round" />\n';
			customString += '      </EXACT>\n';
			customString += '      <EXACT value="4" label="' + areaclasspcs_esc[4] + '" >\n';
			customString += '        <SIMPLEPOLYGONSYMBOL boundarytransparency="0.0" filltransparency="0.8" fillcolor="255,0,0" boundarycolor="0,0,0" boundarycaptype="round" />\n';
			customString += '      </EXACT>\n';
			customString += '    </VALUEMAPRENDERER>\n';
			customString += '  </GROUPRENDERER>\n';
		}
		customString += '\n</LAYER>\n';
	return customString;
}

// add custom stuff to Map XML request. . . between clickpoints and copyright
function addCustomToMap2_test(){
	var customString = "";
  if(formationDisplay > 0)
  {
    vegSelectedName = fldText[formationDisplay];
    var posDot = vegFormationLookupField.lastIndexOf("."); 
    vegLookupField = vegFormationLookupField.substring(0,posDot+1) + fldValues[formationDisplay];
    //alert("Using the following for vegForm: " + vegLookupField);

    return addCustomToMap1();
  }
	//alert("vegFormationLookupField: " + vegFormationLookupField); 
    customString += '<LAYER type="featureclass" name="' + vegFormationName + '" visible="true" id="' + vegFormationId + '">\n';
		customString += '  <DATASET fromlayer="' + VegFormLayer + '" />\n';
		//customString += '  <SPATIALQUERY where="' + vegLookupField + '=&apos;' + vegLookupField + '&apos;" />\n';
		customString += '  <GROUPRENDERER>\n';
if (formationDisplay!=0) {
		customString += '    <VALUEMAPRENDERER lookupfield="' + vegFormationLookupField + '">\n';
    for (var i = 0; i<fldValues.length; i++)
    {
      // check if a single formation was selected (formationDisplay == i)
      // or all of them have been selected: (formationDisplay == -1)
      if (formationDisplay == -1 || formationDisplay == i)
      {
    		customString += '      <EXACT value="' + fldValues[i] + '" label="' + fldText[i] + '" >\n';
	    	customString += '        <SIMPLEPOLYGONSYMBOL boundarytransparency="0.0" filltransparency="0.8" fillcolor="' + fldRBGValues[i] + '" boundarycolor="0,0,0" boundarycaptype="round"></SIMPLEPOLYGONSYMBOL>\n';
		    customString += '      </EXACT>\n';

        // break out of loop if formationDisplay > -1
        // meaning that a single formation was selected
        if (formationDisplay > -1) break; 
      }
    }
}
else if (formationDisplay!=0) {
    var posDot = vegFormationLookupField.lastIndexOf("."); 
    var tmpVegFormationLookupField = vegFormationLookupField.substring(0,posDot+1) + fldValues[formationDisplay];

		customString += '    <VALUEMAPRENDERER lookupfield="' + tmpVegFormationLookupField + '">\n';
    	customString += '      <EXACT value="1" label="' + fldText[formationDisplay] + '" >\n';
	    customString += '        <SIMPLEPOLYGONSYMBOL boundarytransparency="0.0" filltransparency="0.8" fillcolor="' + fldRBGValues[i] + '" boundarycolor="0,0,0" boundarycaptype="round"></SIMPLEPOLYGONSYMBOL>\n';
		customString += '      </EXACT>\n';

}
		customString += '    </VALUEMAPRENDERER>\n';
		customString += '  </GROUPRENDERER>\n';
		customString += '\n</LAYER>\n';
    //parent.TitleFrame.document.getElementById("divTmp").innerHTML = customString; 
    //alert("customString: \n" + customString); 
	return customString;
}

// add custom stuff to Map XML request. . . between clickpoints and copyright
function addCustomToMap2(){
	var customString = "";

  if(formationDisplay > -1)
  {
    vegSelectedName = fldText[formationDisplay];
    var posDot = vegFormationLookupField.lastIndexOf("."); 
    vegLookupField = vegFormationLookupField.substring(0,posDot+1) + fldValues[formationDisplay];
    //alert("Using the following for vegForm: " + vegLookupField);

    return addCustomToMap1();
  }
	
    customString += '<LAYER type="featureclass" name="' + vegFormationName + '" visible="true" id="' + vegFormationId + '">\n';
		customString += '  <DATASET fromlayer="' + VegFormLayer + '" />\n';
		//customString += '  <SPATIALQUERY where="' + vegLookupField + '=&apos;' + vegLookupField + '&apos;" />\n';
		customString += '  <GROUPRENDERER>\n';
		customString += '    <VALUEMAPRENDERER lookupfield="' + vegFormationLookupField + '">\n';
    for (var i = 0; i<fldValues.length; i++)
    {
      // check if a single formation was selected (formationDisplay == i)
      // or all of them have been selected: (formationDisplay == -1)
      if (formationDisplay == -1 || formationDisplay == i)
      {
    		customString += '      <EXACT value="' + fldValues[i] + '" label="' + fldText[i] + '" >\n';
	    	customString += '        <SIMPLEPOLYGONSYMBOL boundarytransparency="0.0" filltransparency="0.8" fillcolor="' + fldRBGValues[i] + '" boundarycolor="0,0,0" boundarycaptype="round"></SIMPLEPOLYGONSYMBOL>\n';
		    customString += '      </EXACT>\n';

        // break out of loop if formationDisplay > -1
        // meaning that a single formation was selected
        if (formationDisplay > -1) break; 
      }
    }
		customString += '    </VALUEMAPRENDERER>\n';
		customString += '  </GROUPRENDERER>\n';
		customString += '\n</LAYER>\n';
    //parent.TitleFrame.document.getElementById("divTmp").innerHTML = customString; 
    //alert("customString: \n" + 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]);
}


