// ArcIMSparam.js
// javascript file with parameters specific to calling page

//***************************************************************************
//*			parameters File for HTML Template		    *
//***************************************************************************

// get machine name
var hostName = document.location.host;
// common portion of url
var esriBlurb = "/servlet/com.esri.esrimap.Esrimap?ServiceName="
// make URL for getting mapservice catalog
var catURL = "http://" + hostName + esriBlurb + "catalog";
// make prefix for URL
var serverURL  = "http://" + hostName + esriBlurb;

//*********************************************************************
//*	 variables para pintar la geometría de las búsquedas          *
//*********************************************************************
// 'diferenciaEnX' y 'diferenciaEnY' contienen la diferencia de tamaño en X/Y cuando se dibuja la toponimia
// en situaciones donde el extent de lo que se quiere dibujar no mantiene el aspecto del tamaño de la venta de visualización
var diferenciaEnX = 0;
var diferenciaEnY = 0;
var TipoBusqueda = 1; // 1: callejero; 2: toponimia
var GeometriaVML = "";
var GeometriaPrec = 5; // precisión a la hora de dibujar la geometría
var limpiarGeometria = true;
var minGeomScale = 1500;
var VML_minX=0;
var VML_minY=0;
var VML_maxX=0;
var VML_maxY=0;
var infoBuffer=10;
/* Variable booleana que indica si el mapa ha sido cargado (aunque ya hayamos recibido la ruta de la imagen) */
var mapLoaded = true;

/* Variable de inicio del path de medicion */
var defaultMeasureVML = "m0,0 l0,0 e";
var MeasureVML = ""; // path de la medida
var ElementosDeMedida = 0; // numero de elementos de medida (siempre uno)

// importante para el uso de la ventana del mapa de situación (rojo())
var panDirection = 0; // indica qué botón de cambio de desplazamiento se ha pulsado
var rojoDibujado = false; // indica si la caja del mapa de situacion ya esta posicionada y no hace falta pintarla de nuevo

//*********************************************************************
//*			parameters set by Designer			                     *
//*********************************************************************
var MiServidor = 'pre.sitcan.com';
var imsURL = 'http://' + MiServidor + '/servlet/com.esri.esrimap.Esrimap?ServiceName=Canarias';
var imsOVURL = 'http://' + MiServidor + '/servlet/com.esri.esrimap.Esrimap?ServiceName=Canarias';
var imsQueryURL= imsURL + "&CustomService=Query";
var imsGeocodeURL= imsURL + "&CustomService=Geocode";

//initial map extent
var startLeft = 364388.032178;
var startRight = 364979.645965;
var startTop = 3153270.916564;
var startBottom = 3152839.115333;
//maximum map extent
var limitLeft = 311000.5;
var limitRight = 391000.5;
var limitTop = 3164999.5;
var limitBottom = 3097499.5;

// selección del tamaño de la imagen, constantes de ancho y alto, e índice actual de tamaño
var iWidths = new Array();
var iHeights = new Array();
// Grande: 675x420
// Pequeña: 430x280
iWidths[0] = 430;
iWidths[1] = 675;
iHeights[0] = 280;
iHeights[1] = 420;
var iIndexWH = 1;

var MapUnits = "Meters";
var ScaleBarUnits = "Meters";

var mapBackColor = "0,0,0";
var ovBoxSize = 3;
var zoomBoxColor = "#ff0000";

// para definir si se presentan o no las capas del servicio activo
var CapasVisibles = true;

// variables for map pixel offset from upper left corner of frame
	// horizontal offset
var hspc = 0;
	// vertical offset
var vspc = 0;

//panning factor for arrow buttons
var panFactor = 50/100;
//zoom factors for v.3
var zoomFactor = 2;

// margin factor for zooming in on selected lines and polygons - based on feature width and height. . . margin will be selectMargin * width or height
var selectMargin = 25/100;
// margin margin factor for zooming in on selected points - based on full extent. . . margin will be selectPointMargin * fullWidth or fullHeight
var selectPointMargin = 25/1000;

// display coords in status line
var showXYs=true;

// Have ArcXML responses URL encoded? Will not work with multi-byte characters
var doURLencode = false;

// automatically adjust for ArcMapServer, if necessary
	// North Arrow size is smaller from ArcMapServer
var autoAdjustForArcMapServer = true;

var NorthArrowSize = "15";
var NorthArrowCoords = "20 35";
// MapUnits=DEGREES,FEET,METERS
// ScaleBarUnits=KILOMETERS,METERS,MILES,FEET
var ScaleBarPrecision = 2;
var numDecimals = ScaleBarPrecision;

// setup test for Nav 4.0
var isIE = false;
var isNav = (navigator.appName.indexOf("Netscape")>=0);
var isNav4 = false;
var isIE4 = false;
var is5up = false;

if (isNav) {
	if (parseFloat(navigator.appVersion)<5) {
		isNav4=true;
		//alert("Netscape 4.x or older");
	} else {
		is5up = true;
	}
} else {
	isIE4=true;
	isIE=true;
	if ((navigator.appVersion.indexOf("MSIE 5")>0) || (navigator.appVersion.indexOf("MSIE 6")>0)) {
		isIE4 = false;
		is5up = true;
		//alert("IE5");
	}
}	
		
/**************************************
* Extended Map parameters
**************************************/

// index of initial active layer. . . if more than or equal to layer count top layer used
var ActiveLayerIndex=99;

// toggle the check of non-listing of layers in LayerList and Legend
// if true, noListLayer array must have an element defined for each layer
var hideLayersFromList=true;
// layers that will be listed in the LayerList or Legend
	// Note: This does not affect map display
var noListLayer = new Array();
// noListLayer[0] = false;
// noListLayer[1] = false;
// noListLayer[2] = false;
// noListLayer[3] = true;	// this one will not be listed
// noListLayer[4] = false;

// Click points - Measure/Shape Select/Shape Buffer
var clickMarkerColor="255,0,0";
var clickMarkerType="Circle";
var clickMarkerSize="6";

// fields to be returned in identify/selection/query request. . . #ALL#=all fields
var selectFields= "#ALL#";
//var selectFields= "#ID# #SHAPE#";
// swap out the list of returned fields? 
//If true, a list must be defined in selFieldList[n] for each layer to update selectFields
var swapSelectFields=false;
// array for each layer's returned fields if swapSelectFields=true
var selFieldList = new Array();
// sample set for world - if not #ALL#, id and shape fields required. Separate with a space
selFieldList[0]="NAME COUNTRY POPULATION #ID# #SHAPE#";
selFieldList[1]="URL #ID# #SHAPE#";
selFieldList[2]="#ALL#";
selFieldList[3]="#ALL#";
selFieldList[4]="#ALL#";
selFieldList[5]="NAME CONTINENT #ID# #SHAPE#";
selFieldList[6]="#ALL#";

// use the field alias in the data display? 
//If true, a list must be defined in fieldAliasList[n] for each layer defining aliases for those fields needing them
var useFieldAlias=false;
// array for aliases for each layer's returned fields if useFieldAlias=true
var fieldAliasList  = new Array();
// sample set for world - fieldname:alias pairs separated by a bar (|)... if no aliases, use empty string ("")
fieldAliasList[0]="NAME:City Name|POPULATION:Population";
fieldAliasList[1]="";
fieldAliasList[2]="";
fieldAliasList[3]="";
fieldAliasList[4]="";
fieldAliasList[5]="NAME:CountryName";
fieldAliasList[6]="";

/**************************************
* Legend parameters - aimsLegend.js
**************************************/

// legend map size
var legWidth=170;
var legHeight=300;
var legFont="Arial";
var legTitle=""; //Leyenda

/**************************************
* Options parameters - aimsOptions.js
**************************************/

// minimal acceptable geocode score for candidate
var geocodePointColor = "77,181,249";
var geocodePointOutColor = "0,0,63";
var geocodePointSize = "12";

// the starting point. . . it all starts here on loading
var oInterval = "";
function checkLoad() {
	// comprobamos que diversos frames hayan completado su carga antes de inicializar la aplicación
	if (parent.PostFrame.document.readyState=="complete"
		&& parent.herramientas.document.readyState=="complete"
		&& parent.barrainferior.document.readyState=="complete") {
		window.clearInterval(oInterval);
		startMap();
		if (parent.resPeq) parent.ToolFrame.cambiar();
	}
}
function checkParams() {
	appDir = getPath(document.location.pathname);
	
	if (isIE)
		if (hasLayer("theTop")) document.all.theTop.style.cursor = "crosshair";
		
	// if starting extents zero'd then flag to get start from mapservice
	if ((startLeft!=0) && (startRight!=0)) getStartingExtent=false;
	// if limit extents zero'd then flag to get max from mapservice
	if ((limitLeft!=0) && (limitRight!=0)) {
		getLimitExtent=false;
		enforceFullExtent=true;
	}
	if (aimsNavigationPresent) {
		// Set up event capture for mouse movement
		if (isNav4) {
			document.captureEvents(Event.MOUSEMOVE);
			document.captureEvents(Event.MOUSEDOWN);
			document.captureEvents(Event.MOUSEUP);
			//document.captureEvents(Event.MOUSEOUT);
		}
		document.onmousemove = getMouse;
		//document.onmousedown = chkMouseDown;
		document.onmousedown = mapTool;
		document.onmouseup = chkMouseUp;
		//document.onmouseout = chkMouseOut;
	}
	
	/* herramienta por defecto al iniciar la aplicacion: zoomin */
	clickFunction("zoomin");
	
	/* Formulario jsForm */
	//parent.PostFrame.document.location="jsForm.htm";

	/* Mapa de situacion, servicios y busquedas */
	parent.herramientas.document.location="pages/frames/herramientas.htm";

	/* Escala, coordenadas y capas del servicio activo */
	parent.barrainferior.document.location = "pages/frames/barrainferior.htm";

	/* Hay que comprobar que herramientas y barrainferior se han cargado antes de llamar a startMap() */
	oInterval = window.setInterval("checkLoad()", 500);
	//startMap();
}
