
// Validates the input fields and writes the notification
function writeNotification(id, url) {
	
	var error = false;
	
	if(id == undefined) {
		var notificationForm = "notificationForm";
		var notificationError = "notificationError";
		var notificationContent = "notificationContent";
		var notificationSuccess = "notificationSuccess";
		var notificationFailure = "notificationFailure";			
	}
	else {
		var notificationForm = "notificationForm" + id;
		var notificationError = "notificationError" + id;
		var notificationContent = "notificationContent" + id;
		var notificationSuccess = "notificationSuccess" + id;
		var notificationFailure = "notificationFailure" + id;
	}
	
	var text = escape(document.getElementById(notificationForm).text.value);
	
	if(text == "") {
		error = true;
		document.getElementById(notificationError).style.display="inline";
	}
		
	if(error == true) {
		return false;
	}
	
	var formValues = Form.serialize(notificationForm);
	
	new Ajax.Request(url, {
		method:"post",
		parameters: formValues,
		onSuccess:function(transport) {
			Effect.SlideUp(notificationContent);
			Effect.Appear(notificationSuccess);
			resetNotificationErrorVisibility(id);
		},
		onFailure:function(transport) {
			Effect.SlideUp(notificationContent);
			Effect.Appear(notificationFailure);
		}
	});
		
	return false;
}

// Resets the visibility of the error divs
function resetNotificationErrorVisibility(id) {
	if(id == undefined) {
		var notificationError = "notificationError";
	}
	else {
		var notificationError = "notificationError" + id;
	}
	document.getElementById(notificationError).style.display="none";
}

// Resets the visibility of the success message div
function resetNotificationMessageVisibility(id) {
	if(id == undefined) {
		var notificationSuccess = "notificationSuccess";
	}
	else {
		var notificationSuccess = "notificationSuccess" + id;
	}	
	document.getElementById(notificationSuccess).style.display="none";
}

// Resets the form and calls the focus method for the form
function resetNotificationForm(id) {
	if(id == undefined) {
		var notificationForm = "notificationForm";
	}
	else {
		var notificationForm = "notificationForm" + id;
	}	
	
	document.getElementById(notificationForm).reset();
	
	if(id == undefined) {
		window.setTimeout("focusNotificationForm()", 500);
	}
	else {
		window.setTimeout("focusNotificationForm('"+id+"')", 500);
	}
}
	
// Focus on the comment form
function focusNotificationForm(id) {
	if(id == undefined) {
		var notificationButton = "notificationButton";
	}
	else {
		var notificationButton = "notificationButton" + id;
	}	
	document.getElementById(notificationButton).focus();
}