restrictions = new Array();
restrictionGrupoCount = 0;

restrictionList = new Array();
restrictionListCount = 0;

function addGrupo(nombre) {
	idx = restrictionGrupoCount;

	restrictions[idx] = new Array();
	restrictions[idx]["nombre"] = nombre; 
	restrictions[idx]["count"] = 0;

	restrictionGrupoCount++;
}

function addSubgrupo(grupo, nombre) {
	idx = restrictions[grupo]["count"];

	restrictions[grupo][idx] = new Array();
	restrictions[grupo][idx]["nombre"] = nombre; 
	restrictions[grupo][idx]["count"] = 0;

	restrictions[grupo]["count"]++;
}

function addRestriction(grupo, subgrupo, id, nombre, showResultCount, tooltip) {
	idx = restrictions[grupo][subgrupo]["count"];

	restrictions[grupo][subgrupo][idx] = new Array();
	restrictions[grupo][subgrupo][idx]["ID"] = id;
	restrictions[grupo][subgrupo][idx]["NOMBRE"] = nombre;
	if (tooltip) {
		restrictions[grupo][subgrupo][idx]["TOOLTIP"] = tooltip;
	} else {
		restrictions[grupo][subgrupo][idx]["TOOLTIP"] = nombre;
	}
	restrictions[grupo][subgrupo][idx]["showResultCount"] = showResultCount;
		// numero de capas asociadas a esta restriccion
	restrictions[grupo][subgrupo][idx]["count"] = 0;

	restrictions[grupo][subgrupo]["count"]++;

	// actualizar tambien la lista unidimensional paralela
	restrictionList[restrictionListCount] = new Array();
	restrictionList[restrictionListCount]["grupo"] = grupo;
	restrictionList[restrictionListCount]["subgrupo"] = subgrupo;
	restrictionList[restrictionListCount]["subsubgrupo"] = idx;
	//restrictionList[restrictionListCount]["esGFI"] = isGFI;
	restrictionList[restrictionListCount]["showResultCount"] = showResultCount;
	restrictionList[restrictionListCount]["ID"] = id;
	restrictionListCount++;
}

function addLayerToRestriction(idRestriccion, idLayer) {
	var posLayer = getIndexQueryableLayer(idLayer);

	if (posLayer == -1) {
		alert("Capa con id " + idLayer + " no encontrada");
	}
	addItemToRestriction(idRestriccion, idLayer, posLayer, false);
}

gfiCount = 0;
gfiList = new Array();

function addGFIToRestriction(idRestriccion, urlGFI) {
	gfiList[gfiCount] = new Array();
	gfiList[gfiCount]["url"] = urlGFI;

	addItemToRestriction(idRestriccion, urlGFI, gfiCount, true);

	gfiCount++;
}

function addItemToRestriction(idRestriccion, valor, posic, esGFI) {
	var idx = -1;
	for (kk = 0; kk < restrictionListCount; kk++) {
		if (restrictionList[kk]["ID"] == idRestriccion) {
			idx = kk;
		}
	}

	if (idx == -1) {
		alert("Restricción con id " + idRestriccion + " no encontrada");
		return -1;
	} else {
		var grupo = restrictionList[idx]["grupo"];
		var subgrupo = restrictionList[idx]["subgrupo"];
		var subsubgrupo = restrictionList[idx]["subsubgrupo"];

		idx2 = restrictions[grupo][subgrupo][subsubgrupo]["count"];
		restrictions[grupo][subgrupo][subsubgrupo][idx2] = new Array();
		restrictions[grupo][subgrupo][subsubgrupo][idx2]["value"] = valor;
		restrictions[grupo][subgrupo][subsubgrupo][idx2]["posicion"] = posic; 
		restrictions[grupo][subgrupo][subsubgrupo][idx2]["esGFI"] = esGFI;
		restrictions[grupo][subgrupo][subsubgrupo]["count"]++;
	}
}

addGrupo("Datos generales");
addGrupo("Datos temáticos");

addSubgrupo(0, "");
addSubgrupo(1, "Series de Ortofotos");
addSubgrupo(1, "Educación");
addSubgrupo(1, "Hidrografía");
addSubgrupo(1, "Medio Ambiente");
addSubgrupo(1, "Usos del suelo");
addSubgrupo(1, "Minas");
addSubgrupo(1, "Transporte");
addSubgrupo(1, "Cuadrículas de referencia");

addRestriction(0, 0, "Información General", "Información General", false);
addRestriction(0, 0, "Ficheros descargables", "<img border='0' src='images/descargaMini.png'>&nbsp;Ficheros descargables", true, "Ficheros descargables");

addRestriction(1, 0, "Series de Ortofotos", "Fechas de Vuelo", true);
addRestriction(1, 1, "Educación", "Zonas y centros educativos", true);
addRestriction(1, 2, "Ríos", "Ríos", true);
addRestriction(1, 3, "Especies amenazadas", "Especies amenazadas", true);
addRestriction(1, 3, "Humedales", "Humedales", true);
addRestriction(1, 3, "Red Natural de Aragón", "Red Natural de Aragón", true);
addRestriction(1, 3, "Gestores de residuos", "Gestores de residuos", true);
addRestriction(1, 4, "CLC 1990 Nivel 3", "CLC 1990 Nivel 3", true);
addRestriction(1, 4, "CLC 2000 Nivel 3", "CLC 2000 Nivel 3", true);
addRestriction(1, 5, "Minas", "Catastro Minero", true);
addRestriction(1, 6, "Carreteras", "Carreteras", true);
addRestriction(1, 7, "Cuadrícula 1:50.000", "Cuadrícula 1:50.000", true);
addRestriction(1, 7, "Cuadricula UTM 10 Km", "Cuadricula UTM 10 Km", true);

urlGFI_EDUCA = server + '/sitarGFI?ServiceName=AragonReferencia&REQUEST=GetFeatureInfo&VERSION=1.0.0&SRS=EPSG:23030&QUERY_LAYERS=TROIDES&INFO_FORMAT=text/xml&FEATURE_COUNT=200';

addLayerToRestriction("Información General","Provincia");
addLayerToRestriction("Información General","FechaVueloRec");
addLayerToRestriction("Información General","Comarca");
addLayerToRestriction("Información General","Municipio");
addLayerToRestriction("Información General","Localidad");

addLayerToRestriction("Series de Ortofotos","FechaVueloSer");

addLayerToRestriction("Educación","Zon_Educa");
addLayerToRestriction("Educación","Cen_Educa");
addGFIToRestriction("Educación", urlGFI_EDUCA);

addLayerToRestriction("Ríos","Rio");
addLayerToRestriction("Red Natural de Aragón","ENP");
addLayerToRestriction("Red Natural de Aragón","PORN");
addLayerToRestriction("Red Natural de Aragón","ZEPA");
addLayerToRestriction("Red Natural de Aragón","LIC");

addLayerToRestriction("Minas","CatMin");

addLayerToRestriction("Carreteras","RedCarCod");

addLayerToRestriction("Especies amenazadas","BorCho");
addLayerToRestriction("Especies amenazadas","CypCal");
addLayerToRestriction("Especies amenazadas","FalNau");
addLayerToRestriction("Especies amenazadas","KraCer");
addLayerToRestriction("Especies amenazadas","GypBar");
addLayerToRestriction("Especies amenazadas","VelPse");
addLayerToRestriction("Especies amenazadas","MarAur");
addLayerToRestriction("Especies amenazadas","AusPal");
addLayerToRestriction("Humedales","Humedales");
addLayerToRestriction("Gestores de residuos","GesRes");

addLayerToRestriction("Cuadrícula 1:50.000","Cuad50k");
addLayerToRestriction("Cuadricula UTM 10 Km","CuaUTM10k");

addLayerToRestriction("CLC 1990 Nivel 3","CLC1990_N3");
addLayerToRestriction("CLC 2000 Nivel 3","CLC2000_N3");

urlGFI_SITAR = server + '/sitarGFI?ServiceName=AragonReferencia&REQUEST=GetFeatureInfo&VERSION=1.0.0&SRS=EPSG:23030&QUERY_LAYERS=ED,EV&INFO_FORMAT=text/xml&FEATURE_COUNT=300';
addGFIToRestriction("Ficheros descargables", urlGFI_SITAR);
