
function loadCount(field_id){
	var word_cnt;
	var text = $("#"+field_id).val();
	if(text == ""){
		word_cnt = 0;
	}else{
		word_cnt = $("#"+field_id).val().split(/[\s\.\?]+/).length;
	}
	return word_cnt;
}

jQuery.fn.wordCount = function(params){

	var word_cnt;
	var p = { counterElement:"display_count" };

	if(params){
		jQuery.extend(p, params);
	}

	var count = loadCount(p.field_id);
	$('#'+p.counterElement).html(p.max_words-count);

	this.keypress(function(){
		word_cnt = loadCount(p.field_id);
		var remaining = (p.max_words-word_cnt);
		$('#'+p.counterElement).html(remaining);
	});

	this.change(function(){
		word_cnt = loadCount(p.field_id);
		var remaining = (p.max_words-word_cnt);
		$('#'+p.counterElement).html(remaining);
	});


};


jQuery.fn.inputFocus = function(params){

	var input = this;
	var default_text = input.val();

	this.focus(function(){
		input.val("");
	});

	this.blur(function(){
		var field_val = input.val();
		if(field_val == ""){
			input.val(default_text);
		}	
	});

};

