
/*
 * Badges.js
 * 
 * Functions needed for badge handling on the profile page
 * 
 * use this include on the jsp-page.
 * <script type="text/javascript" language="JavaScript1.2" src="includes/badges.js"></script> 
 */



// other badge related js-functions moved to this script-file when finished
	var needsReload = false;
	
	function openSettings() {
		$('settings_open').style.display = 'block';
	}
	
	function closeSettings() {
		var confirmBox = getStyleObject("settings_open");
		confirmBox.visibility="hidden";	
		confirmBox.zIndex = -1;
		//TODO this works, but can this be done without realoading the whole page. 
		if (needsReload) {
			needsReload = false;
			window.location.reload();
		}
	}	

	function updateBadgeState(e) {
		var urli = './jsp/simple/input.jsp';
		var params = encodeURI(
				'update_badge=true&id=' + e.value 
				+ '&active=' + e.checked);
		
		new Ajax.Request(urli, {
				asynchronous: true,
				method: "get",
				parameters: params + '',
				onSuccess: function(transport){
					var response = transport.responseText;
					needsReload = true;
				},
				onFailure: function(){ }
		});
	}

	function nextBadgesOld(start) {
		
		var urli = './jsp/simple/input.jsp';
		var params = encodeURI(
				'next_badge=true&' 
				+ '&start=' + start);

		new Ajax.Request(urli, {
			asynchronous: true,
			method: "get",
			parameters: params + '',
			onSuccess: function(transport){
				var response = transport.responseText;
				$('settings_badge').innerHTML = ''+response;
			},
			onFailure: function(){}
		});
		
	}