/*
 * 
 * Textarea Word Count Jquery Plugin 
 * Version 1.0
 * 
 * Copyright (c) 2008 Roshan Bhattarai
 * website : http://roshanbh.com.np
 * 
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 * 
*/
//Set no-conflict

$j.fn.wordCount = function(){

	var total_words;
		
	//for each keypress function on text areas
//	this.keypress(function()
//	{ 
//		//total_words=this.value.split(/[\s\.\?]+/).length;
//		total_words=this.value.length + 1;
//		$j('#display_count').html(total_words);
//	
//	});	
	this.keypress(function(event){
	    var key = event.which;
	   
	    if (key == 8)
	    {
	        if (total_words == 0)
	        {
	            total_words=this.value.length;
	        }
	        else
	        {
	            total_words=this.value.length - 1;
	        }
	    }
	    else
	    {
	        total_words=this.value.length + 1;
	    }
	    
	    $j('#display_count').html(total_words);
	    
	});
};

