function calc_statistic() { var alltext = document.getElementById('textarea_id').value; //Remove all symbols \r while (alltext != alltext.replace("\r\n", "\n")) alltext = alltext.replace("\r\n", "\n"); //Number of lines lines = alltext.split("\n"); document.getElementById('txtLines').value = lines.length; //Number of characters document.getElementById('txtChars').value = alltext.length; //Number of words words = alltext.split(/[\s.,\W]+/); document.getElementById('txtWords').value = words.length; //Longest line length max_line_length = 0; for (var i=0; i max_line_length) max_line_length = line_length } document.getElementById('txtLongest').value = max_line_length; } function format_one_pass(text, user_max_line_length) { var newtext = "" var part_of_line = "" var number_lines var temp_symbol lines = text.split("\n") number_lines = lines.length //Cycle for each line for (var i=0; i user_max_line_length) { //Get piece of line from 0 to user_max_line_length+1 //We need to operate with following situation: when space symbol has position //user_max_line_length+1, so we don't need so add /n immediately after position user_max_line_length, //because fist symbol in next line will be a space part_of_line = lines[i].substr(0, user_max_line_length) //Anylaze this part of line if (part_of_line.indexOf(" ") == -1) { //If this line has no space symbols - so add hard \n //We need to check that symbol after \n will not be an space temp_symbol = lines[i].charAt(user_max_line_length) if (temp_symbol == " ") lines[i] = lines[i].substring(0,user_max_line_length) + "\n" + lines[i].substring(user_max_line_length+1) else lines[i] = lines[i].substring(0,user_max_line_length) + "\n" + lines[i].substring(user_max_line_length) } else { //This part of line has space symbol //Search last space symbol last_space_position = part_of_line.lastIndexOf(" ") lines[i] = lines[i].substring(0,last_space_position) + "\n" + lines[i].substring(last_space_position+1) } } //Do not add new line symbol to last line if (i != number_lines-1) newtext = newtext + lines[i] + "\n" else newtext = newtext + lines[i] } return newtext } function format() { var alltext = document.getElementById('textarea_id').value var user_max_line_length = document.getElementById('user_max_line_length').value var formated_text var previous_symbol //Remove all symbols \r while (alltext != alltext.replace("\r\n", "\n")) alltext = alltext.replace("\r\n", "\n"); //We need to remove all \n symbols, but remain groups of \n var last_new_line = alltext.lastIndexOf("\n") var current_new_line = alltext.indexOf("\n") while (current_new_line < last_new_line) { current_new_line = alltext.indexOf("\n") previous_symbol = alltext.charAt(current_new_line-1) next_symbol = alltext.charAt(current_new_line+1) if ((next_symbol != "\n") && (previous_symbol != "\r")) alltext = alltext.substring(0, current_new_line) + " " + alltext.substring(current_new_line+1) else alltext = alltext.substring(0, current_new_line) + "\r" + alltext.substring(current_new_line+1) } //Replace all \r for \n while (alltext != alltext.replace("\r", "\n")) alltext = alltext.replace("\r", "\n"); //For this moment we can have situation, where string "\n " was transformed to " " (2 spaces) //so replace " " for " " while (alltext != alltext.replace(" ", " ")) alltext = alltext.replace(" ", " "); formated_text = alltext while (formated_text != format_one_pass(formated_text, user_max_line_length)) formated_text = format_one_pass(formated_text, user_max_line_length); document.getElementById('textarea_id').value = formated_text //Recalc statistic calc_statistic(); } function show_editor() { var output = "" var yourserver = 'http://www.fighting-fathers.com/emailformatter/' output = "
" output = output + "" output = output + "" output = output + "

" output = output + "


Please Type or Paste Your Email To Be Formatted Into The Box Above

Select All     Copy to Clip Board     Clear

Maximum Line Length:

Statistics  
Character Count (Spaces count):
Line Count (Blank lines count):
Word Count:
Longest Line:


" output = output + "
" output = output + "" output = output + "Click Here To Add This FREE Email Formatter To Your Website!" output = output + "
" document.write(output) } function SelectAll() { //Select all text in the textarea var alltext = document.getElementById('textarea_id') alltext.focus() alltext.select() } function CopyAll() { var alltext = document.getElementById('textarea_id') therange = alltext.createTextRange() therange.execCommand("Copy") window.status="Text copied to clipboard" setTimeout("window.status=''",2400); } function ClearAll() { var alltext = document.getElementById('textarea_id') alltext.value = "" calc_statistic() }