// 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;

	//extract (toegevoegd EV)
	var extractXMLMode=1111;
	var imsExtractURL = imsURL + '&CustomService=Extract'



// 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
//extract (toegevoegd EV)
       }  else if (XMLMode==1111) {
		parseExtractResponse(theReply);
//logis toevoeging (soms wordt useCustomFunction opgeroepen ipv processLogisXML
	} else if (XMLMode > 9000) {
              processLogisXML(theReply)
// einde logis toevoeging
	} else {
		alert(msgList[55] + XMLMode + msgList[56]);
	}
	hideLayer("LoadData");
}

// add custom stuff to Map XML request. . . between selection and geocode
function addCustomToMap1(){
	var customString = "";
// wordt hier ingelaten, maar uitgecommentarieerd, zodat we later nog
// dynamisch geladen kaarten kunnen voorzien.
// is echter niet meer nodig voor editeren, dus de variabele logisEditShapeXML vervalt
// if (typeof logisEditShapeXML != 'undefined') {
//        customString = logisEditShapeXML;
// } else {
        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("logisEditShapeXML:" + logisEditShapeXML);
	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(){
//logis aanpassing : toevoegen dynamisch geladen kaarten.
    var customString = "";
//	return customString;
 if (logisDynFile != "") { 
    //alert("In customstring:"+logisDynFile);	
    return logisDynFile;       	
 }
 else {
    return customString;
 }
}
// einde logis aanpassing

// extract layers to download
function extractIt() {
	hideLayer("measureBox");
	//alert(msgList[51]);

//extract (toegevoegd EV)
if (checkIfActiveLayerAvailable()) {
   sendExtractRequest();
  }
}

function sendExtractRequest(){
 var extractAXL="";
 //extractAXL += '<?xml version="1.0" encoding="UTF-8"?>\n';
 extractAXL += '<ARCXML version="1.1">\n';
 extractAXL += '<REQUEST>\n';
 extractAXL += ' <GET_EXTRACT>\n';
 extractAXL += '   <PROPERTIES>\n';
 extractAXL += '     <ENVELOPE minx="' + forceComma(eLeft) + '" miny="' + forceComma(eBottom) + '" maxx="' + forceComma(eRight) + '" maxy="' + forceComma(eTop) + '" />\n';
 extractAXL += '       <LAYERLIST nodefault="true">\n';
 extractAXL += '         <LAYERDEF id="' + ActiveLayer + '" visible="true" />\n';
 extractAXL += '       </LAYERLIST>\n';
 extractAXL += '   </PROPERTIES>\n';
 extractAXL += ' </GET_EXTRACT>\n';
 extractAXL += '</REQUEST>\n';
 extractAXL += '</ARCXML>\n';

//alert (extractAXL);

sendToServer(imsExtractURL, extractAXL ,extractXMLMode);


//alert("extract laag = " + ActiveLayer);

}


function parseExtractResponse(theResponse){

  var extractURL = getURL(theResponse);
  //alert(extractURL);
  if(extractURL!="")  var Win1 = open(extractURL);
 
}
