// Copyright (C) 2009-2010 SomeonesGottaDoIt
// JavaScript Document
function showAddComment() {
	var c = document.getElementById('AddCommentDiv');
	// is there a space for comments?
	if (c) {
		// if so, show it
		var s = c.style;
		s.display = "block";
	}
}

function hideAddComment() {
	var c = document.getElementById('AddCommentDiv');
	// is there a space for comments?
	if (c) {
		// if so, hide it
		var s = c.style;
		s.display = "none";
		// clear the contents of the form
		document.getElementById('cmtname').value = '';
		document.getElementById('cmtlocation').value = '';
		document.getElementById('comment').value = '';
	}
}

function toggleComments() {
	var c = document.getElementById('ShowCommentsDiv');
	// is there a space for comments?
	if (c) {
		var vc = document.getElementById("vc");
		var s = c.style;
		if (s.display != "block") {
			s.display = "block";
			vc.innerHTML = "hide";
		}
		else {
			s.display = "none";
			vc.innerHTML = "view";
		}
	}
}

function validate_comment_form(form, action) {
	switch (action) {
		case "Add":
			// validate submission
			if (document.getElementById('cmtname').value == '') {
				// no name specified
				alert('Please tell us your name!');
				return false;
			}
			if (document.getElementById('comment').value == '') {
				// no category specified
				alert('You haven\'t written a comment! Please tell us what you think...');
				return false;
			}
			if (document.getElementById('kData').value == '') {
				// no review!
				alert('Please enter the title from the top of the page in the appropriate location!');
				return false;
			}
			break;
		case "Update":
			// validate...
			if (document.getElementById('cmtname').value == '') {
				// no name specified
				alert('Please specify your name!');
				return false;
			}
			if (document.getElementById('comment').value == '') {
				// no category specified
				alert('You haven\'t written a comment!');
				return false;
			}
			break;
		case "Cancel":
			// nothing to do
			break;
		case "Reject":
			var num = document.getElementById('num');
			if (!num) {
				// must have got here via the link, which shouldn't be possible...
				alert("unexpected action: " + action);
				return false;
			}
			else {
				num = num.value;
			}
			return confirm("Deleting comment \"" + num + "\" cannot be undone, are you sure?");
			break;
		case "Accept":
		case "Edit":
			// shouldn't see actions of Edit or Accept
			alert("unexpected action: " + action);
			return false;
		default:
			// WTF?!
			alert("unrecognised action: " + action);
			return false;
	}
	return true;
}