// 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) {
		// 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 = "";	
		//YPMapLogo
		customString += '<LAYER type="ACETATE" name="theMode">\n';
		customString += '<OBJECT units="PIXEL">\n<POINT coord="75 ' + (iHeight-20) + '">\n';
		customString += '<RASTERMARKERSYMBOL overlap ="false" shadow="255,255,255" transparency ="1.0" image="' + sharePath + 'logo\\yplogo_eng.gif" size="146,32" />\n</POINT>\n</OBJECT>';
		customString += '\n</LAYER>\n';
		
		//Copyright
		customString += '<LAYER type="ACETATE" name="theMode">\n';
		customString += '<OBJECT units="PIXEL">\n<POINT coord="124 14">\n';
		customString += '<RASTERMARKERSYMBOL overlap ="false" transparency ="1.0" image="' + sharePath + 'logo\\Copyright_e.gif" size="240,25" />\n</POINT>\n</OBJECT>';
		customString += '\n</LAYER>\n';
		//alert(customString);
	return customString;
}

// add custom stuff to Map XML request. . . between clickpoints and copyright
function addCustomToMap2(){
	//draw sclebar
	var customString = "";
	if (isPrint==true) {		//print map
		customString += '<LAYER type="ACETATE" name="theMode">\n';
		//customString += '<OBJECT units="PIXEL">\n<POINT coords="' + parseInt(iWidth * (6/10)) + coordsDelimiter + '2">\n';
		customString += '<OBJECT units="PIXEL">\n<POINT coords="513 7">\n';
		customString += '<RASTERMARKERSYMBOL overlap ="false" transparency ="1.0" image="' + sharePath + 'logo\\scalebar.jpg" size="124,7" />\n</POINT>\n</OBJECT>';
		customString += '\n</LAYER>\n';
	} else {
		customString += '<LAYER type="ACETATE" name="theMode">\n';
		//customString += '<OBJECT units="PIXEL">\n<POINT coords="' + parseInt(iWidth * (6/10)) + coordsDelimiter + '2">\n';
		customString += '<OBJECT units="PIXEL">\n<POINT coords="650 7">\n';
		customString += '<RASTERMARKERSYMBOL overlap ="false" transparency ="1.0" image="' + sharePath + 'logo\\scalebar.jpg" size="160,7" />\n</POINT>\n</OBJECT>';
		customString += '\n</LAYER>\n';
	}
	isPrint=false;
	//alert(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]);
}


//next function is global function add by TDL

//call by TDLZoomLevel/TDLTouristZoomLevel..., use for zoomin/zoomout tool
function TDLZoomToolControl() {
	var theForm=parent.ToolsFrame.document.forms[0];
	if ((WebPage==8) && (NowLevel==1) && (isLSB==false)){
		toolMode=4;
		theForm.radio1[3].checked=true;	//click info
		//document.all.theTop.style.cursor = "hand";
		document.all.theTop.style.cursor = "crosshair";
		clickFunction('identify');
	} else {
		if (NowLevel<=4) {		
			if (toolMode!=1) {			
				toolMode=1;
				theForm.radio1[1].checked=true;	//zoomin
				document.all.theTop.style.cursor = "crosshair";
			}
		} else {
			toolMode=4;
			theForm.radio1[3].checked=true;	//click info
			//document.all.theTop.style.cursor = "hand";
			document.all.theTop.style.cursor = "crosshair";
			clickFunction('identify');		
		}
	}
}

function TDLprint()
{
	var theForm = document.forms[0];
	var theTitle = "HKCityMap";
	getPrintMap(theTitle);	
}

function getPrintMap(title) {
	printTitle=title;
	var tempWidth = iWidth;
	var tempHeight = iHeight;
	iWidth=630;
	iHeight=600;
	//legVis2=legendVisible;
	//legendVisible=true;
	isPrint=true;
	if (WebPage==6){
	  var theString = TDLWriteXML();
	}else{
	  var theString = writeXML();
	}
	
	iWidth=tempWidth;
	iHeight = tempHeight;
	sendToServer(imsURL,theString,101);
}

// fourth, write the web page
function writePrintPage() {
	var href=document.location.href;
	var href1 = href.toUpperCase();
	var pos = href1.indexOf("MAPFRAME.HTM",0);
	var webURL=href.substring(0,pos)
	//var Win1 = open(webURL+"printmap.htm","PrintMap","");
	var Win1 = open(webURL+"printmap.htm","PrintMap","width=700,height=500,scrollbars=yes, resizable=no");
	Win1.focus();
}