// check if access to cgi via httprequest is available
var cgiSupported = bbcjs.http.supported?true:false;

if (cgiSupported)
{
	// add "ajax" to body classnames to allow separate styling for ajax version
	bbcjs.dom.addClassName(document.documentElement,"ajax");
	// add functions to be called when page has loaded
	bbcjs.addOnLoadItem( function()
	{
		dynActions.showActionsTabsInit();
		dynActions.lhnavAjaxLinks();
		dynActions.addCheckCategoriesButtons();
		dynActions.loadIDStoreData();
	});
}

var dynActions = new Object();

dynActions.Pagination = { pagesize: 25, enabled: true };

//define array containing values to sort on
dynActions.sortingTabs = [
	{ title: "Effective",	sort_on: "co2actual",			sort_sense: 'desc'},
	{ title: "Popular",		sort_on: "popularityrating",	sort_sense: 'desc'},
	{ title: "Easy",			sort_on: "easiness",				sort_sense: 'desc'},
	{ title: "Cheapness",	sort_on: "costrating",			sort_sense: 'desc'}
	//{ title: "Credible",		sort_on: "controversy",			sort_sense: 'asc'}
];
// set default column to sort on
dynActions.sort_on = dynActions.sortingTabs[0];

//define array containing values to sort on
dynActions.ratingsList = [
	{ title: "CO<sub>2</sub> reduction",	parameter: "co2rating"			},
	{ title: "Popularity",						parameter: "popularityrating"	},
	{ title: "Easiness",							parameter: "easiness"			},
	{ title: "Cheapness",								parameter: "costrating"			}
	//{ title: "Controversy",						parameter: "controversy"		},
];

// array used to hold references to actions to be displayed on page
dynActions.ActionsToDisplay = new Array();

// used to store number of actions a user is doing
dynActions.your_actions_count = 0;

// define variables set in page
dynActions.date_started = ''; // holds the current date received from the server in format: YYYYMMDD
dynActions.showactions = ''; // are we displaying all actions or only actions a user is doing?

//define function to add onclick handlers to showactions tabs
dynActions.showActionsTabsInit = function()
{
	$('showactions-all').onclick = function()
	{
		dynActions.switchToAllActions();
		return false;
	};
	$('showactions-your').onclick = function()
	{
		dynActions.switchToYourActions();
		return false;
	};
}

dynActions.lhnavAjaxLinks = function(){
	if($("nav-actions")){
		var yourActionLink = bbcjs.dom.first($("nav-actions"));
		yourActionLink.onclick = function(){
			dynActions.switchToYourActions();
			return false;
		};
	}
	if($("nav-things")){
		var findActionLinks = bbcjs.dom.first($("nav-things"));
		findActionLinks.onclick = function(){
			dynActions.switchToAllActions();
			return false;
		};
	}
}

//define function to switch to 'all actions' view
dynActions.switchToAllActions = function()
{
	bbcjs.dom.attr(bbcjs.dom.parent( $('showactions-all') ),'class','selected');
	bbcjs.dom.removeClassName( bbcjs.dom.parent( $('showactions-your') ), 'selected' );
	dynActions.showactions = 'all';
	dynActions.displayActions();
}

//define function to switch to 'your actions' view
dynActions.switchToYourActions = function()
{
	bbcjs.dom.attr(bbcjs.dom.parent( $('showactions-your') ),'class','selected');
	bbcjs.dom.removeClassName( bbcjs.dom.parent( $('showactions-all') ), 'selected' );
	dynActions.checkCategories('all');
	dynActions.showactions = 'your';
	dynActions.displayActions();
}

//define function to display sorting tabs
dynActions.displaySortingTabs = function()
{
	bbcjs.trace("display sorting tabs called");
	var htmlString = "";
	for (i=0; i<this.sortingTabs.length; i++)
	{
		var thisTab = this.sortingTabs[i];
		if (thisTab == this.sort_on)
		{
			htmlString += '<li class="selected"><strong>'+ thisTab.title +'</strong></li>';
		}
		else
		{
			htmlString += '<li><a href="#" onclick="return dynActions.sortActions(dynActions.sortingTabs['+ i +']);">'+ thisTab.title +'</a></li>';
		}
	}
	$('sorting-tabs').innerHTML = htmlString;
}

//define function to sort actions
dynActions.sortActions = function(sortingTab)
{
	bbcjs.trace('sortActions called');
	bbcjs.trace('sort sense: ' + sortingTab.sort_sense);
	if (sortingTab.sort_sense == 'desc')
	{
		this.qeData.Actions.sort(function (a,b) { return b[sortingTab.sort_on] - a[sortingTab.sort_on]; });		
	}
	else
	{
		this.qeData.Actions.sort(function (a,b) { return a[sortingTab.sort_on] - b[sortingTab.sort_on]; });
	}
	this.sort_on = sortingTab;
	this.displaySortingTabs();
	this.displayActions();
	return false;
}

//define function to display actions
dynActions.displayActions = function()
{
	bbcjs.trace("display Actions");
	
	this.ActionsToDisplay = [];
	
	for (i=0;i<this.qeData.Actions.length;i++)
	{
		var thisAction = this.qeData.Actions[i];
		var display = false;
		
		// if we are on the 'your actions' part only display actions that a user is doing
		// if we are on the 'all actions' screen don't display actions where display=false
		if ((this.showactions == 'your' && thisAction.doing_this) || (this.showactions == 'all' && thisAction.display != false))
		{
			for (j=0;j<thisAction.categories.length;j++)
			{
				if(this.qeData.UserData.Categories['category_'+thisAction.categories[j]])
				{
					display = true;
					break;
				}
			}
			if (display)
			{
				this.ActionsToDisplay.push(thisAction);
			}
		}
	}
	bbcjs.trace("this.ActionsToDisplay: "+bbcjs.obj2list(this.ActionsToDisplay));
	this.displayActionsPage(0);
}

//define function to display a page of actions
dynActions.displayActionsPage = function(page)
{
	bbcjs.trace("display Actions page");
	var action_list_html = '';
	var pagesize = this.Pagination.pagesize;
	var total_hits = this.ActionsToDisplay.length;
	var range_start = this.Pagination.enabled?page*pagesize:0;
	var range_end = this.Pagination.enabled?((total_hits < (page+1)*pagesize)?total_hits:(page+1)*pagesize):total_hits;
	for (i=range_start;i<range_end;i++)
	{
		var thisAction = this.ActionsToDisplay[i];
		action_list_html += this.createAction(thisAction);
	}
	$('action-list').innerHTML = action_list_html;
	//display pagination
	this.displayPagination(page,range_start,range_end);
};

//define function to display action
dynActions.createAction = function(thisAction)
{
	var link2article = '/bloom/actions/'+ thisAction.name +'.shtml';
	var html_li = '<li';
	if ((thisAction.active == false) || (thisAction.doing_this))
	{
		html_li += ' class="'+ ((thisAction.active == false)?'notsuited':'') + (thisAction.doing_this?((thisAction.active == false)?' doing':'doing'):'') + '"';
	}
	html_li += '>';
	
	// add flower
	html_li += '<div class="flower"><a href="'+ link2article + '"><img src="/bloom/images/flowers/flowers_75x75/'+ thisAction.name +'.jpg" width="75" height="75" alt="Flower representing the \''+ thisAction.title +'\' action" /></a></div>';
	
	// start: create and add element 'overview'
	html_li += '<div class="overview">';
	html_li += '<a href="#" class="more-less" onclick="return dynActions.actionShowMoreOrLess(this);"></a>';
	html_li += '<h3><a href="'+ link2article + '">'+ thisAction.title +'</a></h3>'; 

	// if a user is doing this action display the seed
	if (thisAction.doing_this) {
		html_li += this.createElemDoingThis(thisAction);
	}
	
	//start: create and add element 'more'
	html_li += '<div class="more">';
	html_li += '<p class="teaser">'+ thisAction.teaser +'</p>';

	html_li += '<ul class="ratings">';
	
	for (var i=0; i<this.sortingTabs.length; i++)
	{
		var thisRating = this.ratingsList[i];
		var value_1to5 = Math.ceil(thisAction[thisRating.parameter]);
		html_li += '<li>';
		html_li += '<em>'+ thisRating.title +'</em>';
		html_li += '<img src="/bloom/images/bars-'+ value_1to5 +'.gif" width="52" height="27" alt="'+ value_1to5 +' out of 5" />';
		html_li += '</li>';
	}
	html_li += '</ul>';

	html_li += '</div>';
	//end: create and add element 'more'
	
	html_li += '</div>';
	// end: create and add element overview
	
	//create and add element 'trythis'
	html_li += '<div class="trythis">';
	html_li += '<p><a href="'+ link2article + '">Wait tell me more</a></p>';

	html_li += '<p class="add-remove"><a href="#" onclick="return dynActions.actionAddRemove('+ thisAction.id +',this)">'+ (thisAction.doing_this?'Not doing this anymore':'Ok, I\'ll try this') +'</a></p>';

	html_li += '</div>';
	
	// created and add horizontal ruler
	html_li += '<div class="hr-thin"><hr /></div>';

	return html_li;
}
// start: functions to create parts of the action HTML
dynActions.createElemDoingThis = function(ThisAction)
{
	var elemDoingThis = '<p class="doingthis"><img src="/bloom/images/beans/beans_22x24/'+ ThisAction.name +'.gif" width="22" height="24" alt="Seed representing the \''+ ThisAction.title +'\' action" /><em>You\'re doing this</em></p>';
	return elemDoingThis;
}
// end : functions to create parts of the action HTML


//define function to display pagination
dynActions.displayPagination = function(page,range_start,range_end)
{
	var pagesize = this.Pagination.pagesize;
	var total_hits = this.ActionsToDisplay.length;
	if (total_hits > 0) $('pagination-info').innerHTML = 'Showing '+ (range_start+1) +' - '+ range_end +' of '+ total_hits +' actions';
	else if ((this.showactions == 'your') && (this.your_actions_count == 0))
	{
		$('pagination-info').innerHTML = "You haven't collected any actions yet. Click the 'View all actions' tab at the top of this page to find carbon-cutting actions.";
	}
	else $('pagination-info').innerHTML = "Showing no actions - please select at least one category";
	
	var htmlString = '';
	if (total_hits > pagesize)
	{
		// if there are more hits than the page size
		if (this.Pagination.enabled && (total_hits > pagesize))
		{
			//and pagination is used we display the pagination links
			htmlString += '<a href="#" onclick="return dynActions.paginationEnableDisable(false);" id="show-all">Show all</a>';
			htmlString += '<h3>Page</h3>';
			
			//insert previous page link if we're not on the first page
			if (page > 0)
			{
				htmlString += '<li><a href="#action-list-a" onclick="dynActions.displayActionsPage('+ (page-1) +');" class="arrow" title="previous page"><img src="/bloom/images/browse-pagination-left.gif" width="8" height="9" alt="previous page"></a></li>';
			}
	
			//insert page number links
			for (i=0; i < (total_hits/pagesize); i++)
			{
				htmlString += '<li'+ ((i > 0)?' class="pipe"':'') +'>';
				if (i == page)
				{
					htmlString += '<strong>'+ (i+1) +'</strong>';
				}
				else
				{
					htmlString += '<a href="#action-list-a" onclick="dynActions.displayActionsPage('+ i +');" title="page '+ (i+1) +'">'+ (i+1) +'</a>';
				}
				htmlString += '</li>';
			}
	
			//insert next page link if we're not on the last page
			if ((page+1) < (total_hits/pagesize))
			{
				htmlString += '<li><a href="#action-list-a" onclick="dynActions.displayActionsPage('+ (page+1) +');" class="arrow" title="next page"><img src="/bloom/images/browse-pagination-right.gif" width="8" height="9" alt="next page"></a></li>';
			}
		}
		else
		{
			//otherwise we only add a link to enable pagination again
			htmlString += '<a href="#" onclick="return dynActions.paginationEnableDisable(true);" id="show-all">Show '+ pagesize +' per page</a>';
		}
	}
	$('page-navigation').innerHTML = htmlString;
}

//define function to disable or enable pagination
dynActions.paginationEnableDisable = function(use_pagination)
{
	// either enable or disable pagination depending on use_pagination value (true|false)
	this.Pagination.enabled = use_pagination?true:false;
	this.displayActionsPage(0);
	return false;
}

//define function to show more details for an action
dynActions.actionShowMoreOrLess = function(LinkHandle)
{
	actionLi = bbcjs.dom.parent(bbcjs.dom.parent(LinkHandle));
	// if the action is set to show all
	if (bbcjs.dom.hasClassName(actionLi,'showall'))
	{
		//remove the showall class name
		bbcjs.dom.removeClassName(actionLi,'showall');
		//change the icon back to a plus sign
		bbcjs.dom.removeClassName(LinkHandle,'less-icon');
	}
	//otherwise
	else
	{
		//add the showall class name
		bbcjs.dom.addClassName(actionLi,'showall');
		//change the icon to a minus sign
		bbcjs.dom.addClassName(LinkHandle,'less-icon');
	}
	return false;
}

//define function to add or remove an action to/from idstore
dynActions.actionAddRemove = function(action_id,LinkHandle)
{
	// get this actions Object from the qeData Array
	var ThisAction;
	for (key in this.qeData.Actions)
	{
		if (this.qeData.Actions[key].id == action_id)
		{
			ThisAction = this.qeData.Actions[key];
			break;
		}
	}

	var adding_it = ThisAction.doing_this?false:true;
	ThisAction.doing_this = adding_it;

	var ElemTryThis = bbcjs.dom.parent(bbcjs.dom.parent(LinkHandle));
	var ElemThisAction = bbcjs.dom.parent(ElemTryThis);
	var ElemOverview = bbcjs.dom.previous(ElemTryThis);
	var ElemMore = bbcjs.dom.getElementsByClassName('more','div',ElemOverview)[0];
	if (adding_it)
	{
		this.saveIDStoreData('action_status_'+ action_id + '=true;action_started_'+ action_id +'='+ this.date_started);
		bbcjs.dom.addClassName(ElemThisAction,'doing'); // add class to change style to show user is doing this action
		myP = bbcjs.dom.elem('p',null,'test');
		bbcjs.dom.before(ElemMore,this.createElemDoingThis(ThisAction)); // add the doing this bean and text
	}
	else
	{
		this.saveIDStoreData('action_status_'+ action_id + '=false');
		bbcjs.dom.removeClassName(ElemThisAction,'doing'); // add class to change style to show user is not doing this action
		bbcjs.dom.empty(bbcjs.dom.previous(ElemMore));
	}
	var ElemP = bbcjs.dom.parent(LinkHandle);
	bbcjs.dom.empty(ElemP);
	var ElemA = '<a href="#" onclick="return dynActions.actionAddRemove('+ action_id +',this)">'+ (adding_it?'Not doing this anymore':'Ok, I\'ll try this') +'</a>';
	bbcjs.dom.append(ElemP,ElemA);
	
	this.refreshYourActionsCount(); // refresh 'your actions' count
	
	// if we are in your actions view we need to refresh the actions
	if (this.showactions == 'your')
	{
		this.displayActions();
	}

	return false;
}

//define function to refresh 'your actions' count
dynActions.refreshYourActionsCount = function()
{
	var yourActionsCount = 0;
	for (key in this.qeData.Actions)
	{
		if (this.qeData.Actions[key].doing_this)
		{
			yourActionsCount++;
		}
	}
	this.your_actions_count = yourActionsCount;
	$('showactions-your').innerHTML = 'View your actions ('+ yourActionsCount + ')';
}

//define function to refresh actions
dynActions.refreshActions = function()
{
	for (i=0;i<this.qeData.Actions.length;i++)
	{
		thisP = $('action_'+this.qeData.Actions[i].id);
		if (thisP)
		{
			if (this.qeData.Actions[i].active) bbcjs.dom.removeClassName(thisP,'inactive');
			else bbcjs.dom.addClassName(thisP,'inactive');
		}
	}
}

//define function to modify actions
dynActions.modifyActions = function()
{
	for (i=0;i<this.qeData.Actions.length;i++)
	{
		var active = true;
		for (key in this.qeData.Actions[i].RequiredAnswers)
		{
			//bbcjs.trace('key: '+key + ' val: '+this.qeData.UserData.Answers[key] + 'req: '+this.qeData.Actions[i].RequiredAnswers[key]);
			if(this.qeData.UserData.Answers[key] && this.qeData.UserData.Answers[key] != this.qeData.Actions[i].RequiredAnswers[key])
			{
				active = false;
				break;
			}
		}
		this.qeData.Actions[i].active = active;
	}
	bbcjs.trace("after modifyActions: "+bbcjs.obj2list(this.qeData.Actions));
}

//define function to add check / uncheck categories buttons
dynActions.addCheckCategoriesButtons = function()
{
	var elemList = '<ul id="select-all-or-none"><li><a href="#" onclick="return dynActions.checkCategories(true);">Select all</a></li><li><a href="#" onclick="return dynActions.checkCategories(false);">Unselect all</a></li></ul>';
	// add the list of links after the categories list
	bbcjs.dom.before(bbcjs.dom.next($('category-list')),elemList);
}

//define function to check all or no category boxes
dynActions.checkCategories = function(check_all)
{
	var checkBoxes = $('category-list').getElementsByTagName('INPUT');
	for (var i=0; i<checkBoxes.length; i++)
	{
		checkBoxes[i].checked = check_all;
		this.qeData.UserData.Categories[checkBoxes[i].name] = check_all;
	}
	this.displayActions();
	this.saveDataDelayed();
	return false;
}

//define function to display categories list
dynActions.displayCategories = function()
{
	var htmlString = "";
	var topics = this.qeData.topics;
	for (i=0; i<topics.length; i++)
	{
		htmlString += (i==0)?'<li id="first-col">':'<li>';
		htmlString += '<h3>' + topics[i].topic + '</h3>';
		htmlString += '<ol>';
		var cats = topics[i].categories;
		for (j=0; j<cats.length; j++)
		{
			var catId = 'category_'+ cats[j].id;
			htmlString += '<li>';
			htmlString += '<input type="checkbox" id="'+ catId +'" name="'+ catId +'" value="yes" onclick="dynActions.changeCategory(this);"'+ (this.qeData.UserData.Categories[catId]?' CHECKED':'') + '>';
			htmlString += '<label for="'+ catId +'">'+ cats[j].title +'</label>';
			htmlString += '</li>';
		}
		htmlString += '</ol>';
		htmlString += '</li>';
	}
	htmlString += '<li id="bottom-pad"></li>';
	$('category-list').innerHTML = htmlString;
};

//define function to display questions
dynActions.displayQuestions = function()
{
	var htmlString = "";
	for (q_key in this.qeData.Questions)
	{
		//bbcjs.trace("question key: "+q_key);
		var thisQ = this.qeData.Questions[q_key];
		var show = true;
		for (key in thisQ.RequiredAnswers)
		{
			bbcjs.trace('key: '+ key + ' .. ' + this.qeData.UserData.Answers[key] + ' : ' + thisQ.RequiredAnswers[key]);
			if (this.qeData.UserData.Answers[key] != thisQ.RequiredAnswers[key])
			{
				show = false;
				break;
			}
		}
		//bbcjs.trace("id: "+ thisQ.id + " show: "+show);
		if (!show && this.qeData.UserData.Answers['answer_'+thisQ.id])
		{
			bbcjs.trace ("exists: "+thisQ.id);
			this.qeData.UserData.Answers['answer_'+thisQ.id] = "";
		}

	}
	
	//if we are editing an umbrella action build only umbrella questions
	if (this.umbrellaAction || this.showing_all_questions)
	{
		var qOrder;
		if (this.umbrellaAction)
		{
			bbcjs.trace("building questions for: " + this.umbrellaAction.id);
			//bbcjs.trace("question order: " + this.umbrellaAction.questionorder);
			qOrder = this.umbrellaAction.questionorder;
		}
		for (var i=0;i<qOrder.length;i++)
		{
			var thisQ = this.qeData.Questions['question_'+qOrder[i]];
			var show = true;
			for (key in thisQ.RequiredAnswers)
			{
				bbcjs.trace("required answer key: "+key);
				if (this.qeData.UserData.Answers[key] != thisQ.RequiredAnswers[key])
				{
					show = false;
					break;
				}
			}
			if (show) htmlString += this.buildQuestion(thisQ);
		}
	}
	
	bbcjs.trace ("answers: "+bbcjs.obj2list(this.qeData.UserData.Answers));
	$( 'questions' ).innerHTML = htmlString;
}

//define function to return a question element
dynActions.buildQuestion = function(qRef)
{
	bbcjs.trace('building question: '+qRef);
	var out_str = ""; 
	out_str += '<p>'+qRef.title;
	if (qRef.info)
	{
		out_str += ' <a href="#" onclick="alert(\''+ qRef.info.message +'\');">'+ qRef.info.text +'</a>';
	}
	out_str += '<br />';
	var message;
	var answer_name = 'answer_'+qRef.id;
	for (j=0;j<qRef.options.length;j++)
	{
		out_str += '<input id="'+ answer_name +'_'+ qRef.options[j].value +'" type="radio" name="'+ answer_name +'" value="'+ qRef.options[j].value +'" onclick="dynActions.questionAnswered(this.name,this.value)"';
		if (this.qeData.UserData.Answers['answer_'+qRef.id] == qRef.options[j].value)
		{
			out_str += ' CHECKED';
			message = qRef.options[j].message;
		}
		out_str += ' />';
		out_str += '<label for="'+ answer_name +'_'+ qRef.options[j].value +'">'+ qRef.options[j].value +'</label>';
	}
	out_str += '</p>';
	// only display the message if displaying umbrella action questions
	if (this.umbrellaAction && message) out_str += '<p>'+message+'</p>';
	return out_str;
};


//define function to handle category check boxes
dynActions.changeCategory = function(checkBox)
{
	if (!cgiSupported) return true;
	catId = checkBox.name;
	this.qeData.UserData.Categories[catId] = checkBox.checked;
	this.displayActions();
	this.saveDataDelayed();
};

//define function to handle question radio buttons
dynActions.questionAnswered = function(q_name,q_value)
{
	if (!cgiSupported) return true;
	bbcjs.trace("q_name: "+q_name+" q_value: "+q_value);
	this.qeData.UserData.Answers[q_name] = q_value;
	this.modifyActions();
	this.refreshActions();
	this.displayQuestions();
	this.saveDataDelayed();
};

//define function to open umbrella action
dynActions.editUmbrella = function(umbrella_id)
{
	if (!cgiSupported) return true;
	// set the umbrella object to this umbrella's data object
	for (key in this.qeData.Actions)
	{
		bbcjs.trace(this.qeData.Actions[key].id + ": " + umbrella_id);
		if (this.qeData.Actions[key].id == umbrella_id)
		{
			this.umbrellaAction = this.qeData.Actions[key];
			break;
		}
	}
	bbcjs.dom.hide($('categories'));
	bbcjs.dom.show($('backToList'));
	bbcjs.dom.hide($('answer_all'));
	this.displayActions();
	this.displayQuestions();
	return false;
}

//define function to return to normal listing display
dynActions.backToList = function()
{
	if (!cgiSupported) return true;
	if (this.umbrellaAction)
	{
		delete this.umbrellaAction;
		this.displayActions();
	}
	bbcjs.dom.hide($('backToList'));
	bbcjs.dom.show($('categories'));
	bbcjs.dom.show($('answer_all'));
	this.displayQuestions();
	return false;
}

// load data from IDStore and QueryEngine
dynActions.loadIDStoreData = function()
{
	bbcjs.trace('loadIDStoreData() called');
	bbcjs.dom.setStyle($('loading'),{display:'block'});
	cache_buster=parseInt(Math.random()*99999999); // cache buster
	bbcjs.http.get('/bloom/browsejson?'+cache_buster,this.loadIDStoreData.Params);
}

// functions to handle onLoad and onError for QE
dynActions.loadIDStoreData.Params = {
	onLoad : function (response)
	{
		bbcjs.dom.hide($('loading'));
		bbcjs.trace('<b>data loaded</b>');
		dynActions.qeData = eval('(' + response.text() + ')');
		bbcjs.trace(bbcjs.obj2list(dynActions.qeData));
		dynActions.modifyActions();
		dynActions.sortActions(dynActions.sort_on);
		dynActions.displayCategories();
		dynActions.refreshYourActionsCount(); 
		bbcjs.dom.setStyle($('blq-content'),{display:'block'});
	},
	onError : function (response){
		// $('status').innerHTML = '<span>Error loading data</span>';
	}
};


//define function to save data in idstore (delayed)
dynActions.saveDataDelayed = function()
{
	window.clearTimeout(this.saveDataDelayedTimeout);
	this.saveDataDelayedTimeout = window.setTimeout("dynActions.saveIDStoreCategoriesAnswers();", 2000);
};

//send request to idstore to store changes to the users categories and answers
dynActions.saveIDStoreCategoriesAnswers = function(action_id) {
	bbcjs.trace("saveIDStoreCategoriesAnswers() called");
	var data_string = '';
	// send all categories
	for (key in this.qeData.UserData.Categories)
	{
		data_string += key + '=' + this.qeData.UserData.Categories[key] + ';';
	}
	// send all answers		
	for (key in this.qeData.UserData.Answers)
	{
		data_string += key + '=' + this.qeData.UserData.Answers[key] + ';';
	}
	this.saveIDStoreData(data_string);
}

//send data to idstore
dynActions.saveIDStoreData = function(data_string) {
	bbcjs.trace("saveIDStoreData called");
	var ajax_string = "/bloom/ajax?" + data_string;
	bbcjs.http.get(ajax_string,this.saveIDStoreData.Params);
}

dynActions.saveIDStoreData.Params = {
	onLoad : function (response)
	{
		bbcjs.trace('<b>ID store data sent</b>');
	},
	onError : function (response)
	{
		// $('status').innerHTML = '<span>Error saving data</span>';
	}
};