/* post a comment */
jQuery(document).ready(function() {

	var defaultCommentText = 'Type your comment here...';
	var defCommentTitle ='Provide a descriptive title for your comment here...';
	var defaultCompetingInterest = "A competing interest exists when your professional judgment about a paper could possibly be influenced by considerations other than the paper's validity or importance. Detail possible competing interests here...";

	var guideTextClass = 'contains-guide-text';
	var userTextClass = 'user-supplied-text';

	function emptyText(field, text){
		if(jQuery(field).val() == text) {
			jQuery(field).val('');
		}
	}

	function setToGuideIfDefault(field, defaultText){
		if (field.val() == defaultText){
			field.addClass(guideTextClass);
		}
	}


	function userSupplyingText(element) {
		jQuery(element)
			.removeClass(guideTextClass)
			.addClass(userTextClass);
	}

	function resetClasses(element) {
		jQuery(element)
			.removeClass(userTextClass)
			.addClass(guideTextClass);
	}

	jQuery('.postcomment #commentText')
		.ready(
			function(){
				setToGuideIfDefault(jQuery('.postcomment #commentText'), defaultCommentText);
			}
		)
		.focus(
			function() {
				emptyText(this, defaultCommentText);
				userSupplyingText(this);
			}
		)
		.blur(
			function() {
				if(jQuery(this).val() == '') {
					jQuery(this).val(defaultCommentText);
					resetClasses(this);
				}
			}
		);

	jQuery('.postcomment #commentTitle')
		.ready(
			function(){
				setToGuideIfDefault(jQuery('.postcomment #commentTitle'), defCommentTitle);
			}
		)
		.focus(
			function() {
				emptyText(this, defCommentTitle);
				userSupplyingText(this);
			}
		)
		.blur(
			function() {
				if(jQuery(this).val() == '') {
					jQuery(this).val(defCommentTitle);
					resetClasses(this);
				}
			}
		);

	jQuery('.postcomment #competingInterests')
		.ready(
			function(){
				setToGuideIfDefault(jQuery('.postcomment #competingInterests'), defaultCompetingInterest);
			}
		)
		.focus(
			function() {
				if(jQuery(this).val() == defaultCompetingInterest) {
					emptyText(this, defaultCompetingInterest);
					userSupplyingText(this);
				}
			}
		)
		.blur(
			function() {
				if(jQuery(this).val() == '') {
					jQuery(this).val(defaultCompetingInterest);
					resetClasses(this);
				}
			}
		);
});



