function inputChange(obj) {
  obj.style.backgroundPosition = (obj.value == '')?'0px 0px':'0px -31px';
}


function prepStr(str) {
  str = str.toLowerCase();
  str = str.replace(/['"-]/g, "");
  str = str.replace(/\W/g, " ");
  str = str.replace(/\s+/g, " ");
  return str;
}

function wordCount(str) {
  var wordArray = new Array();
  str = prepStr(str);
  var tempArray = str.split(' ').sort();
  var count = 0;

  // Iterate through all the words
  for (var i = 0; i < tempArray.length; i++) {
	  if(tempArray[i] != "")
	  {
		  count++;
	  }
  }
  
  return count;
}

function textCounter(field, counter_id, maxlimit) {
	wordcount = wordCount(field.value);
	element = document.getElementById(counter_id);
	if (wordcount > maxlimit) {
	 element.innerHTML = wordcount;
	 element.style.color = '#FF0000';
	} else {
		element.innerHTML = wordcount;
		element.style.color = '';
  }
}


