/***************************************************************************
 * Name:		decode.js
 * Purpose: decodes the variables specified in the URL, e.g. 
 *          file.html?scen=value1&env=value2, and stores them
 *          for use in the same page
 * Version:	0.5, 21.11.2002 
 * Author:	Stefan Fronzek
 * Changes:	0.2: multiple selection is possible for some variables ->
 *               file.html?arrScenSel=A1&arrScenSel=A2
 *          0.3: arrSpScenSel added for selection of specific scenarios
 *          0.4: clModel changed to arrClModel, season added
 *          0.5: s added for checking if a scatter-plot should be displayed
 ***************************************************************************/

// initialise the dynamic variables with default values
//var scen			= "no selection";	// scenario family -> not needed
var arrScenSel = new Array();	// scenario family for multiple selection
var env				= "no selection";
var arrSpScenSel = new Array();	// specific scenarios (e.g. A1C, A1T)
var time			= "no selection";
var arrTimeSel = new Array();
var variable	= "no selection";
var present		= "no selection";
var season		= "no selection";	// seasons for climate scenarios
var arrClModelSel = new Array();
var s		= "no selection";	// switch for selecting to show a scatter plot

// call the decode function
decode();

// put the variables to an array with associate names in order to address
// the variable correctly in the printSelector-function (-> functions.js)
var dynVariables = new Array();
//dynVariables["scen"] = scen;
dynVariables["arrScenSel"] = arrScenSel;
dynVariables["env"] = env;
dynVariables["arrSpScenSel"] = arrSpScenSel;
//dynVariables["time"] = time;
dynVariables["arrTimeSel"] = arrTimeSel;
dynVariables["variable"] = variable;
dynVariables["present"] = present;
dynVariables["season"] = season;
dynVariables["arrClModelSel"] = arrClModelSel;
//dynVariables["arrEnvSel"] = arrEnvSel;

// decode the values given with the URL to the FINSKEN variables
function decode() {
	var url	 = window.location.search;
	if (url != "") {
		// skip the first character ('?')
		url = url.substring(1,url.length);
		// divide the string to value pairs
		liste = url.split("&");

		// tmp-storage of scen fam
		arrTmp = new Array();

		for (i=0;i<=liste.length-1;i++) {
			temp = liste[i].split("=");

			if(temp.length == 2) {
				// replace the + with blank
				temp[1] = temp[1].replace(/\+/g," ");
				// reconstruct the escape sequence
				temp[1] = unescape(temp[1]);	

				// assign the value if the according variable is specified
				if(temp[0] == "arrScenSel") arrScenSel.push(temp[1]);
				if(temp[0] == "env") env = temp[1];
				if(temp[0] == "arrSpScenSel") arrSpScenSel.push(temp[1]);
				if(temp[0] == "arrTimeSel") arrTimeSel.push(temp[1]);
				if(temp[0] == "variable") variable = temp[1];
				if(temp[0] == "present") present = temp[1];
				if(temp[0] == "season") season = temp[1];
				if(temp[0] == "arrClModelSel") arrClModelSel.push(temp[1]);
				if(temp[0] == "s") s = temp[1];
			}
		}
	}
}
