//<SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript">
// 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) {
  // 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) {
  //JSchade CustomFunction addition - begin.
  //Below: these assignments would have normally been done in processXML 3.
  //alert("The reply before IF: " + theReply);
  if(theReply.indexOf("ENVELOPE")==-1){
   alert("ERROR in useCustomFunction: Could not get ENVELOPE, defaulting to 'Whole of SA'");
   //alert("The reply ERROR in IF: " + theReply);
   theReply=parent.strNatEnv;
   //alert("parent.strNatEnv : " + theReplay);
  }
  getXYs(theReply);
  fullLeft = left;
  fullRight = right;
  fullTop = top;
  fullBottom = bottom;
  fullOVLeft = 12.5;
  fullOVRight = 36.5;
  fullOVTop = -21;
  fullOVBottom = -35;
  //limitLeft = left;
  //limitRight = right;
  //limitTop = top;
  //limitBottom = bottom;
  fullWidth = Math.abs(fullRight - fullLeft);
  fullHeight = Math.abs(fullTop - fullBottom);
  fullOVWidth = Math.abs(fullOVRight - fullOVLeft);
  fullOVHeight = Math.abs(fullOVTop - fullOVBottom);
  var posStart=theReply.indexOf("<ENVELOPE ");
  parent.strEnv=theReply.substring(posStart,theReply.indexOf("/",posStart)+2);
  theString = '<ARCXML VERSION="1.0.1">\n<REQUEST>\n<GET_SERVICE_INFO renderer="false" extensions="true" />\n';
  theString += '</REQUEST>\n</ARCXML>';
  sendToServer(imsURL,theString,4);
  useGeocode=false;
  useReverseGeocode=false;
 } else {
  alert("Unknown Mode:" + XMLMode + "\nUnable to execute request.");
 }
  hideLayer("LoadData");
}

// add custom stuff to Map XML request. . . between selection and geocode
function addCustomToMap1(){
var customString = "";
//alert(parent.intPrjNo);

//Highligh features selected from Farmer Registry
if (parent.intPrjNo=="5597"){
customString ='<LAYER type="featureclass" name="Highlighted_Feature" visible="true">\n';
//customString +='<DATASET fromlayer="FARMS" />\n';
customString +='<DATASET fromlayer="'+parent.strAoiLyr+'" />\n';
//customString +='<QUERY where="SDE.V50FARMS.sg_key =&apos;F00100000000101500000&apos;"/>\n';
customString +='<QUERY where="sde:sde.v50farms.sg_key =&apos;'+parent.strSelCap+'&apos;"/>\n';
customString +='<SIMPLERENDERER>\n';
customString +='<SIMPLEPOLYGONSYMBOL fillcolor="255,255,0" filltype="solid" transparency="0.5" boundarycolor="255,255,0"  />\n';
customString +='</SIMPLERENDERER>\n';
customString +='</LAYER>\n';
}

//Highligh features selected from ORGANISATION POINTS (VIEW)
if (parent.intPrjNo=="9738"){
//alert(parent.strSelCap_w)
customString ='<LAYER type="featureclass" name="Highlighted_Feature" visible="true">\n';
customString +='<DATASET fromlayer="183" />\n';
customString +='<QUERY where="org_id =&apos;'+parent.strSelCap_w+'&apos;"/>\n';
customString +='<GROUPRENDERER>\n';
customString +='<SIMPLERENDERER>\n';
customString +='<SIMPLEMARKERSYMBOL transparency="0.8" color="255,0,0" type="square" width="8" outline="255,0,0" antialiasing="true" overlap="true"/>\n';
customString +='</SIMPLERENDERER>\n';
customString +='</GROUPRENDERER>\n';
customString +='</LAYER>\n';
}

//Highligh features selected from FIVIMS
if (parent.intPrjNo=="6016"){
customString ='<LAYER type="featureclass" name="Fivims" visible="true">\n';
customString +='<DATASET fromlayer="'+parent.strAoiLyr+'" />\n';
//customString +='<DATASET fromlayer="22" />\n';
customString +='<QUERY where="'+parent.strSelFld+'=&apos;'+parent.strSelCap+'&apos;"/>\n';
customString +='<SIMPLERENDERER>\n';
customString +='<SIMPLEPOLYGONSYMBOL fillcolor="100,100,100" filltype="fdiagonal" boundarycolor="80,80,80" boundarywidth="3" />\n';
customString +='</SIMPLERENDERER>\n';
customString +='</LAYER>\n';
//alert("Custom String: " + customString);
}

//Highligh features selected from FIVIMS_ZA
if ((parent.intPrjNo=="9426")||(parent.intPrjNo=="9550")||(parent.intPrjNo=="9551")||(parent.intPrjNo=="10574")||(parent.intPrjNo=="10575")||(parent.intPrjNo=="10576")||(parent.intPrjNo=="10937")){
customString ='<LAYER type="featureclass" name="Sekhukhuneland" visible="true">\n';
customString +='<DATASET fromlayer="23" />\n';
customString +='<QUERY where="district=&apos;CBDC3&apos;"/>\n';
customString +='<SIMPLERENDERER>\n';
customString +='<SIMPLEPOLYGONSYMBOL fillcolor="100,100,100" filltype="solid" filltransparency="0.0" boundarycolor="80,80,80" boundarywidth="3" />\n';
customString +='</SIMPLERENDERER>\n';
customString +='</LAYER>\n';
}

//Highligh features selected from WOCAT POINTS
if (parent.intPrjNo=="8639"){
customString ='<LAYER type="featureclass" name="Selected_Features" visible="true">\n';
//customString +='<DATASET fromlayer="'+parent.strAoiLyr+'" />\n';
customString +='<DATASET fromlayer="112" />\n';
//customString +='<QUERY where="sde:sde.v1mwocat_point.questid =&apos;'+parent.strSelCap_w+'&apos;"/>\n';
customString +='<QUERY where="questid =&apos;'+parent.strSelCap_w+'&apos;"/>\n';
customString +='<GROUPRENDERER>';
//customString +='<SIMPLELABELRENDERER field="sde:sde.V1MWOCAT_POINT.questid">';
//customString +='<CALLOUTMARKERSYMBOL fontcolor="0,0,0" transparency="1" antialiasing="true" boundarycolor="0,255,0" backcolor="0,255,0" font="Arial" fontstyle="regular" interval="10" fontsize="8"/>';
//customString +='</SIMPLELABELRENDERER>';
customString +='<SIMPLERENDERER>\n';
customString +='<SIMPLEMARKERSYMBOL transparency="1" color="0,255,0" type="square" width="10" outline="0,255,0" antialiasing="true" overlap="true"/>\n';
customString +='</SIMPLERENDERER>\n';
customString +='</GROUPRENDERER>';
customString +='</LAYER>\n';
}

//Highligh features selected from WOCAT WORLD MAP
if (parent.intPrjNo=="11336"){
customString ='<LAYER type="featureclass" name="Selected_Features" visible="true">\n';
customString +='<DATASET fromlayer="278" />\n';
customString +='<QUERY where="wocat_id =&apos;'+parent.strSelCap_w+'&apos;"/>\n';
customString +='<GROUPRENDERER>';
customString +='<SIMPLERENDERER>\n';
customString +='<SIMPLEMARKERSYMBOL transparency=".4" color="64,255,64" type="circle" width="30" outline="64,255,64" antialiasing="true" overlap="true"/>\n';
customString +='</SIMPLERENDERER>\n';
customString +='</GROUPRENDERER>';
customString +='</LAYER>\n';
//alert(customString)
}
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 = "";
 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("Function not yet enabled.");
}