/**
* Function which gets parameters (GET vars) from the URL query. If it has a
* valid action and the correct parameters, load the correspondent content,
* otherwise loads the default chart specified in startsession.
*
* Valid actions: loadchart, chartentry, search and  htmlpage.
*
* For loadchart action: liid, dspy and dspp are required.
* eg.: .../index.html?action=loadchart&liid=41&dspy=2000&dspp=51
*
* For chartentry action: liid and sart are required.
* eg.: ../index.html?action=chartentry&liid=41&sart=42877
*
* For search action: term is required (may include spaces) 
* eg.: ../index.html?action=search&term=bon jovi
*
* For htmlpage action: page is required
* eg.: ../index.html?action=htmlpage&page=about
*
* @return void
*/
function frontController() {
	//check if "action" var was sent
	var action = $.getUrlVar('action');
	if (action) {
		//if positive, call correspondent action
		switch (action) {
			case 'loadchart': {
				//loadchart - liid, dspy and dspp are required
				var liid = parseInt($.getUrlVar('liid'));
				var dspy = parseInt($.getUrlVar('dspy'));
				var dspp = parseInt($.getUrlVar('dspp'));
				if (liid && dspy && dspp) {
					loadChart(liid, dspy, dspp);
					break;
				}
			}
			case 'chartentry': {
				//chartentry (details) - liid and sart are required
				var liid = parseInt($.getUrlVar('liid'));
				var sart = parseInt($.getUrlVar('sart'));
				if (liid && sart) {
					loadChartEntry(liid, sart);
					break;
				}
			}
			case 'search': {
				//search - term is required (may include spaces, decoding is used)
				var term = $.getUrlVar('term');
				if (term) {
					doSearch(term);
					break;
				}
			}
			case 'htmlpage': {
				//htmlpage - page is required
				var page = $.getUrlVar('page');
				if (page) {
					loadHtmlPage(page);
					break;
				}
			}
			default : {
				//If there is no valid action or valid parameters, show msg to load default chart
				showContent('\
					<p class="msg ui-state-highlight ui-corner-all">\
						<span class="ui-icon ui-icon-info"></span>\
						Ogiltig parameter i URL. Klicka <a href="#" onclick="loadChart(' + DEFAULT.liid + ', ' + DEFAULT.dspy + ', ' + DEFAULT.dspp + ');">här</a> för att hämta startlistan.\
					</p>');
				break;
			}
		}
	}
	else {
		//If there is no action sent, load default chart
		loadChart(DEFAULT.liid, DEFAULT.dspy, DEFAULT.dspp);
	}	
}

