function watchThisList(listid, username, loggedIn)
{
    document.getElementById('watch_this_list').disabled = true;
	if (loggedIn == 'true')
	{
	    var nextpage = "/webservices/root/process/lists?listAjax=watch_list&watcher=" + username + "&listid=" + listid;
		var a = new Ajax.Request(nextpage, {method: 'get', onSuccess: watchThisListSuccess});
        return false;
	}
	else
	{
        var url = "/wcpa/servlet/org.oclc.lac.lists.ListEditorServlet?listAjax=watch_list&withlogin=true&watcher=" + username + "&listid=" + listid;
		showLoginPopupDiv('Watch This List', '', '/account/${oclcnum}?page=login&redirect=' + url);
		document.getElementById('watch_this_list').disabled = false;
	}
}
function watchThisListSuccess(transport, json)
{
	var message = eval(transport.responseText);
	document.getElementById('watch_this_list').disabled = false;

	if (message[0] == "success")
	{
		$('watch_message').style.display = "block";
		$('div_watch_error').style.display = "none";
        $('div_watch_exists_error').style.display = "none";
		$('div_watch_success').style.display = "block";
        $('div_watch_stop_success').style.display = "none";

		$('watch_button').style.display = "none";
		$('watch_stop_button').style.display = "block";
	}
	else if (message[0] == "error")
	{
		$('watch_message').style.display = "block";
		$('div_watch_error').style.display = "block";
        $('div_watch_exists_error').style.display = "none";
		$('div_watch_success').style.display = "none";
        $('div_watch_stop_success').style.display = "none";
	}
	else if (message[0] == "exists")
	{
		$('watch_message').style.display = "block";
		$('div_watch_error').style.display = "none";
        $('div_watch_exists_error').style.display = "block";
		$('div_watch_success').style.display = "none";
        $('div_watch_stop_success').style.display = "none";

		$('watch_button').style.display = "none";
		$('watch_stop_button').style.display = "block";
	}
	else if (message[0] == "['login']")
	{
		window.location.href = "/webservices/root/process/lists?listAjax=watch_list";
//				;&listid=" + listid + "&watcher=";// + message[1];
	}

}

function stopWatchingThisList(listid, username)
{
	document.getElementById('stop_watch_this_list').disabled = true;
	var nextpage = "/webservices/root/process/lists?listAjax=watch_list_stop&listid=" + listid + "&watcher=" + username;
	var a = new Ajax.Request(nextpage, {method: 'get', onSuccess: stopWatchingThisListSuccess});
	return false;
}

function stopWatchingThisListSuccess(transport, json)
{
	var message = eval(transport.responseText);
	document.getElementById('stop_watch_this_list').disabled = false;

	if (message[0] == "success")
	{
		$('watch_message').style.display = "block";
		$('div_watch_error').style.display = "none";
        $('div_watch_exists_error').style.display = "none";
		$('div_watch_success').style.display = "none";
        $('div_watch_stop_success').style.display = "block";

		$('watch_button').style.display = "block";
		$('watch_stop_button').style.display = "none";
	}
	else if (message[0] == "error")
	{
		$('watch_message').style.display = "block";
		$('div_watch_error').style.display = "block";
        $('div_watch_exists_error').style.display = "none";
        $('div_watch_success').style.display = "none";
        $('div_watch_stop_success').style.display = "none";
	}
}

function watchThisListGeneric()
{
	$('watch_message').style.display = "block";
	$('div_watch_error').style.display = "none";
    $('div_watch_exists_error').style.display = "none";
	$('div_watch_success').style.display = "block";
    $('div_watch_stop_success').style.display = "none";
}

