 /*
 Initial version by Conor D'Arcy
 take an input field and get the value out of it, to 
 replace newline characters.
 The value in the field is replaced by the processed value.
 */
 function processUnwantedCharsInField(inputField) {
	  //get the value of the input
	  var inputVal = inputField.value;
	  //replace all newline with NEWLINE
	  inputVal = replaceNewlineChars(new String(inputVal));
	  //replace the inputted value of the object with the NEWLINE value
	  inputField.value = inputVal;
  }
  
  /*
  Given a String, replace the newline characters with known text
  In this case, the known text is ' *NEWLINE* '
  */
  function replaceNewlineChars(inputVal) {
	  return replaceUndesireableChars(inputVal,"\n", " *NEW LINE* ");
  }
  
  /*
  Generic function to replace undesireable characters with others
  Special treatment for newline as shown below to cope with Windows' (IE's)
  use of carriage return + new line giving different index value than other browsers.
  */
  function replaceUndesireableChars(inputString, stringToCheckFor, replacementSubString) {
	  var newLineChar = new String(stringToCheckFor);
	  checkForLength = newLineChar.length;
	  //special cases
	  //IE uses \r\n, different index from FF, Opera and Safari.
	  if ('\n' == newLineChar && inputString.indexOf('\r\n') != -1) {
		  //need to check for more than just newline, also carriage return
			newLineChar = '\r\n';
			checkForLength = newLineChar.length;
	  }
	  while (inputString.indexOf(newLineChar) != -1) {
		idxVal = inputString.indexOf(newLineChar);
		inputString =	inputString.substring (0, inputString.indexOf(newLineChar)) +
						replacementSubString +
						inputString.substring(inputString.indexOf(newLineChar) + checkForLength);
	}

	return inputString;
  }