//http://www.ajaxray.com/blog/2007/11/09/interactive-character-limit-for-textarea-using-jquery/
//Usage:
// onkeyup="limitChars(this, # of characters, 'name for div where message will appear')
/*
Resources for limiting words:
http://www.webdeveloper.com/forum/archive/index.php/t-46863.html (looks like a reasonable replacement).
http://www.hscripts.com/scripts/JavaScript/character-count.php (may be too simple)
http://javascript.internet.com/forms/limit-characters-and-words-entered.html (seems pretty complicated)


*/

function limitChars(textarea, limit, infodiv)

{
		var text = textarea.value; 
		var textlength = text.length;
		var info = document.getElementById(infodiv);

		 
		if(textlength > limit)
		{
				info.innerHTML = 'Please limit your answer to no more than '+limit+' characters!';
				textarea.value = text.substr(0,limit);
				return false;
		}

		else

		{
				info.innerHTML = 'You have '+ (limit - textlength) +' characters left.';
				return true;
		}

}

/*
  http://www.webdeveloper.com/forum/archive/index.php/t-46863.html 
  Modified with techniques from above
*/
function checkWordLen(obj, wordLen, infodiv){
	var len = obj.value.split(/[\s]+/);
	
	
	var info = document.getElementById(infodiv);
	if(len.length > wordLen){
		info.innerHTML = '<span class="err">Please limit your answer to no more than '+wordLen+' words!</span>';
		var objstr = len.slice(0,wordLen).join(" ");
		var textlength = objstr.length;
		obj.value = obj.value.substr(0,textlength-1);
		obj.focus() ;
		return false;
		
	}
	else {
		info.innerHTML = 'You have '+ (wordLen - len.length +1 ) +' words left.';
		return true;
	}
	return true;
}

