/***************************************************************************
 * Name:		var.js
 * Purpose: This stores variables for the FINSKEN scenario gateway.
 * Version:	0.3b, 26.11.2002 
 *          temporary version that excludes the change-varibles of the acid 
 *          deposition scenarios
 * Author:	Stefan Fronzek, SYKE
 * Changes:	0.2: check for scenario families with only one scenario and set
 *               the specific scenario-variable if needed (this requires
 *               decode.js to be read before this file).
 *          0.3: added values for most scenario fields
 ***************************************************************************/

// GENERAL OPTIONS
// scenario families
var arrScen = new Array("A1","A2","B1","B2");
// environmental areas
var arrEnv = new Array("acid deposition", "atmospheric composition", "socio-economic and technological scenarios", "climate change", "sea level rise");

// options for the CLIMATE CHANGE scenarios
//var arr_cliTime = new Array("2020s","2050s","2080s");
var arr_cliTime = new Array("2010-2039","2040-2069","2070-2099");
var arr_cliVars = new Array("temperature", "precipitation");
var arr_cliSeas = new Array("annual", "Dec-Jan-Feb", "Mar-Apr-May", "Jun-Jul-Aug", "Sep-Oct-Nov");
var arr_cliA1 = new Array("A1");
var arr_cliA2 = new Array("A2");
var arr_cliB1 = new Array("B1");
var arr_cliB2 = new Array("B2");
var arr_cliMultScen = new Array(arr_cliA1, arr_cliA2, arr_cliB1, arr_cliB2);	// sc families with multiple sc

// options for the SEA LEVEL scenarios
var arr_seaTime = new Array();
var arr_seaVars = new Array();
var arr_seaMultScen = arr_cliMultScen;	// just a dummy

// options for the ACID DEPOSITION
var arr_aciTime = new Array("baseline","2020", "2050", "2080");
var arr_aciVars = new Array("sulphur (absolute)","sulphur (change)", "nitrogen (absolute)", "nitrogen (change)");
//var arr_aciVars = new Array("sulphur (absolute)", "nitrogen (absolute)");
var arr_aciA1 = new Array("A1T", "A1C", "A1A", "A1P");
var arr_aciA2 = new Array("A2-MESSAGE");
var arr_aciB1 = new Array("B1A", "B1P");
var arr_aciB2 = new Array("B2-MESSAGE");
var arr_aciMultScen = new Array(arr_aciA1, arr_aciA2, arr_aciB1, arr_aciB2);	// sc families with multiple sc

// options for SOCIO-ECONOMIC scenarios
var arr_socTime = new Array();
var arr_socVars = new Array("population","GDP");
var arr_socMultScen = arr_cliMultScen;	// only used as dummy

// options for ATMOSPHERIC COMPOSITION scenarios
var arr_atmTime = new Array("1999","2010","2050");
var arr_atmVars = new Array("AOT40","CO2");
var arr_atmA1 = new Array("A1C","A1T");
var arr_atmA2 = new Array();
var arr_atmB1 = new Array();
var arr_atmB2 = new Array("B2");
var arr_atmMultScen = new Array(arr_atmA1,arr_atmA2,arr_atmB1,arr_atmB2);

// ARRAY OF ARRAYS for the time slices in the same order as in arrEnv
var arrTimeArray = new Array(arr_aciTime, arr_atmTime, arr_socTime, arr_cliTime, arr_seaTime);
// ARRAY OF ARRAYS for the variables in the same order as in arrEnv
var arrVarsArray = new Array(arr_aciVars, arr_atmVars, arr_socVars, arr_cliVars, arr_seaVars);
// ARRAY OF ARRAYS for the subscenarios or models in the same order as in arrEnv
var arrMultScenArray = new Array(arr_aciMultScen, arr_atmMultScen, arr_socMultScen, arr_cliMultScen, arr_seaMultScen);

/* Automatically set the sub-scenario if the scenario family has only one:
 * check if scenario families have been selected that have only one
 * interpretation; add that to arrSpScenSel if it is not there already
 */
// check if the location-bar variables have been set (i.e. has decode.js been read)
if(typeof arrScenSel != "undefined" && typeof arrSpScenSel != "undefined") {
	// check if the scenario field is set already (specific scenarios depend on 
	// the scen field)
	if(env != "no selection") {
		// loop through selected scenario families
		for(var i=0; i<arrScenSel.length; i++) {
			// determine the position of the scen field
			var nmbEnv = 0;
			for(var n = 0; n < arrEnv.length; n++) {
				if(env == arrEnv[n]) {
					nmbEnv = n;
					break;
				}
			}
			// determine the position of the scen family
			var nmbScen = -1;
			for(var k = 0; k < arrScen.length; k++) {
				if(arrScenSel[i] == arrScen[k]) {
					nmbScen = k;
					break;
				}
			}
			// in case the scen-family has only 1 scenario and it is not yet selected, add
			// it to the array of selected specific scenarios
			if(arrMultScenArray[nmbEnv][nmbScen].length == 1) {
				if (arrSpScenSel.join("").indexOf(arrMultScenArray[nmbEnv][nmbScen][0]) < 0) {
					arrSpScenSel.unshift(arrMultScenArray[nmbEnv][nmbScen][0]);
				}
			}
		}
	}
} else {
	alert("Warning in var.js: decode.js hasn't been read before.");
}
