<!--//

// prints a simple error message on the form
function setErrorMessage(message) {
	var obj;

	if (message != '') {
		if ((obj=findObj('errorLbl')) != null) {
			obj.innerHTML = message;
		}
		displayLayer('errorLbl', '');
	} else {
		displayLayer('errorLbl', 'none');
	}
}

function validateForm(path) {
	var err = 0;
	var errors = 'Sorry, your comment could not be submitted:\n';

	if (!document.form.comments.value) {
		err++;
		errors += ' - please enter your comments\n';
	}

	if (err > 0) {
		alert(errors);
		return false;
	} else {
		form_vars = FormCollect(document.form); //alert('Vars are : ' + form_vars);
		request_str = path + '/comment.html?fa=a_c&' + form_vars;
		passAjaxResponseToFunction(request_str, 'addCommentAjaxResponse');
		return false;
	}

}

// checks the server reply about the stage1 data
function addCommentAjaxResponse(response) {

	var result = response.getElementsByTagName('value')[0].firstChild.nodeValue;

	switch(result) {
		case 'SUCCESS':
			document.location.href = document.location.href ;
			break;
		case 'FAILURE':
			setErrorMessage('Sorry we were unable to add your comment');
			break;
		case 'INVALID_DATA':
			setErrorMessage('Invalid request.');
			break;
		case 'INVALID_CODE':
			setErrorMessage('Please correctly enter the validation code.');
			break;
		default:
			setErrorMessage('A problem occurred.');
			break;
	}

}

//->
