/*
 * Copyright (C) butor.com. All rights reserved.
 *
 * This software is published under the terms of the GNU Library General
 * Public License (GNU LGPL), a copy of which has been included with this
 * distribution in the LICENSE.txt file. 
 */
 
function toggleWatch(uid, type) {
	showMsg('Toggling watch on ' + uid + ' ...');
	DwrWiki.toggleWatch(uid, createToggleWatchHandler(uid, type));
}

function createToggleWatchHandler(uid, type) {
	return function(resp) {
		if (!resp) {
			// error occurred
			hideMsg();
			return;
		}
		
		showMsg('Toggle watch done.');
		clearMsg();
		if (resp == null) {
			return;
		}
		
		var image  = getElement('watch_' + uid);
		
		// redisplay image
		var url = ACTIONS_PATH +'theme.do?elem=' +
					(type == 'folder' ? 'folder_' : 'res_') +
					(resp == '1' ? '' : 'un') +
					'watched.gif';
		image.src = url;
		image.alt = (type == 'folder' ? 'Folder ' : 'Document ') +(resp == '1' ? 'watched' : 'not watched');
		image.title = image.alt;
	}
}

