var textoFondoMudo = " ";

var textoFondoMapaNiveles = 4;
var textoFondoMapaNivel = new Array();
var textoFondoMapa = new Array();
textoFondoMapaNivel[0] = 15010;
textoFondoMapa[0] = "Fondo: MTN 25.000";
textoFondoMapaNivel[1] = 100010;
textoFondoMapa[1] = "Fondo: MTN 50.000";
textoFondoMapaNivel[2] = 400010;
textoFondoMapa[2] = "Fondo: MTN 200.000";
textoFondoMapaNivel[3] = 10000010;
textoFondoMapa[3] = "Fondo: MTN 1.000.000";

var textoFondoMapaPorDefecto = "MTN";

var textoFondoFotoNiveles = 3;
var textoFondoFotoNivel = new Array();
var textoFondoFoto = new Array();
textoFondoFotoNivel[0] = 16047;
textoFondoFoto[0] = "Fondo: PNOA 50 cm. 2009";
textoFondoFotoNivel[1] = 530010;
textoFondoFoto[1] = "Fondo: SPOT 2005";
textoFondoFotoNivel[2] = 10000010;
textoFondoFoto[2] = "Fondo: MODIS 2009";

var textoFondoFotoPorDefecto = "Fondo: MODIS 2009";

var idxWMSFondoFoto = 0;

function changeFondoFoto(idxWMS) {
	if (document.getElementById('bgFotoShowId').disabled) {
		if (wmsList[idxWMS]["visib"] == true) {
			wmsList[0]["visib"] = false;
			idxWMSFondoFoto = idxWMS;
		} else {
			wmsList[0]["visib"] = true;
			idxWMSFondoFoto = 0;
		}
	} else {
		if (wmsList[idxWMS]["visib"] == true) {
			idxWMSFondoFoto = idxWMS;
		} else {
			idxWMSFondoFoto = 0;
		}
	}
	updateFVueloQuery(idxWMSFondoFoto);

}

function updateFVueloQuery(idxWMSFondoFoto) {
	if (idxWMSFondoFoto != -1) {
		if (fVueloQuery[idxWMSFondoFoto]) {
			whereQuery["FechaVueloRec"] = fVueloQuery[idxWMSFondoFoto];
		} else {
			whereQuery["FechaVueloRec"] = defaultFVueloQuery;
		}
	} else {
		whereQuery["FechaVueloRec"] = imposibleFVueloQuery;
	}
}

function getTextoFondoFoto(idxWMSFondoFoto) {
	if (idxWMSFondoFoto != -1) {
		if (textoFondoArray[idxWMSFondoFoto]) {
			return textoFondoArray[idxWMSFondoFoto];
		}
	}

	var escalaActual = getMapScale(false);
	for (var i=0; i < textoFondoFotoNiveles; i++) {
		if (escalaActual <= textoFondoFotoNivel[i]) {
			return textoFondoFoto[i];
		}
	}
	return textoFondoFotoPorDefecto;
}

function getTextoFondoMapa() {
	var escalaActual = getMapScale(false);
	for (var i=0; i < textoFondoMapaNiveles; i++) {
		if (escalaActual <= textoFondoMapaNivel[i]) {
			return textoFondoMapa[i];
		}
	}
	return textoFondoMapaPorDefecto;
}

function getTextoFondo() {
	if (document.getElementById('bgFotoShowId')) {
		if (document.getElementById('bgFotoShowId').disabled) {
			return getTextoFondoFoto(idxWMSFondoFoto);
		} else if (document.getElementById('bgMapaShowId').disabled) {
			return getTextoFondoMapa();
		} else {
			return textoFondoMudo;
		}
	} else {
		return textoFondoFotoPorDefecto;
	}
}

function showFondoMapa() {
	document.getElementById('bgMapaShowId').disabled = true;
	document.getElementById('bgFotoShowId').disabled = false;
	document.getElementById('bgMudoShowId').disabled = false;

	updateFVueloQuery(-1);

	if (idxWMSFondoFoto != 0) {
		wmsList[idxWMSFondoFoto]["visib"] = false;
		clearWMS(idxWMSFondoFoto);
	}
	wmsList[0]["url"] = fondoMapa;
	wmsList[0]["visib"] = true;
	clearWMS(0);
	updateWMS(0);
	
	updateAcetateMarca();

	setColorMarcas("#0000ff");
	updateMapClicks();
	if (isGeoreferencing) {
		updateGeorefMapClicks(jgPoint, pointRecordset, jgPointLabel);
	}
	if (isHistorico) {
		updateGeorefMapClicks(jgHistorico, historicoRecordset, jgHistoricoLabel);
	}
}

function showFondoFoto() {
	document.getElementById('bgFotoShowId').disabled = true;
	document.getElementById('bgMapaShowId').disabled = false;
	document.getElementById('bgMudoShowId').disabled = false;

	updateFVueloQuery(idxWMSFondoFoto);

	clearWMS(0);
	wmsList[0]["url"] = fondoFoto;
	if (idxWMSFondoFoto != 0) {
		wmsList[idxWMSFondoFoto]["visib"] = true;
		wmsList[0]["visib"] = false;
	}
	clearWMS(idxWMSFondoFoto);
	updateWMS(idxWMSFondoFoto);

	updateAcetateMarca();

	setColorMarcas("#ffff00");
	updateMapClicks();
	if (isGeoreferencing) {
		updateGeorefMapClicks(jgPoint, pointRecordset, jgPointLabel);
	}
	if (isHistorico) {
		updateGeorefMapClicks(jgHistorico, historicoRecordset, jgHistoricoLabel);
	}
}

function showFondoMudo() {
	document.getElementById('bgFotoShowId').disabled = false;
	document.getElementById('bgMapaShowId').disabled = false;
	document.getElementById('bgMudoShowId').disabled = true;

	updateFVueloQuery(-1);

	if (idxWMSFondoFoto != 0) {
		wmsList[idxWMSFondoFoto]["visib"] = false;
		clearWMS(idxWMSFondoFoto);
	}
	wmsList[0]["url"] = fondoMudo;
	wmsList[0]["visib"] = true;
	clearWMS(0);
	updateWMS(0);

	updateAcetateMarca();

	setColorMarcas("#0000ff");
	updateMapClicks();
	if (isGeoreferencing) {
		updateGeorefMapClicks(jgPoint, pointRecordset, jgPointLabel);
	}
	if (isHistorico) {
		updateGeorefMapClicks(jgHistorico, historicoRecordset, jgHistoricoLabel);
	}
}


