// JavaScript Document Created by Lee Diggins
<!--
function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.innerText = limitNum - limitField.value.length;
	}
}
var first_word;


var littleWords = new Array("to", "in", "the", "of", "from", "a", "as", "an", "for", "and", "but", "with", "vs.", "or", "by", "if", "on", "v", "at");

var allCaps = new Array("aba", "pdf", "html", "xml", "fcc", "nchica", "hipaa", "glb", "erisa", "ftc", "eeo", "edgar", "osha", "cobra", "eeoc", "irs", "lp", "sec", "u.s.", "uk", "ec", "cmbs", "epa");

function changeCase(textarea) {
	first_word = true;
	var s = textarea.value;

	var str = s.toLowerCase();
	var str_temp = new Array();
	str_temp = str.split(" ");
	
	for (var i = 0; i < str_temp.length; ++i) {
		var pattern = /(^[\'\"]?)(\w)([\w]*)([\.\',:;]?)(.*)/;
		var word = str_temp[i];
		var result = pattern.exec(word);
		if (result != null) {
			str_temp[i] = toTitleCase(result, littleWords, allCaps);
		}
		first_word = getFirstWord(str_temp[i]);
	}

	var currLength = 0;
	for (var i = 0; i < str_temp.length; i++) {
		currLength += str_temp[i].length;
	}
	currLength += str_temp.length - 1;
	
	s = str_temp.join(" ");
	textarea.value = s;
}

function getFirstWord(word) {
	var ret = ( word.charAt(word.length-1) == ":");
	return ret;
}

function isInGroup(word, groupOfWords) {
//	word = word.replace(/:/, "");
	for (var i = 0; i < groupOfWords.length; ++i) {
		if (groupOfWords[i] == word)
			return true;
	}
	return false;
}

function getCase(word, littleWords, allCaps) {
	if (isInGroup(word, littleWords)) {
		return 1;	//return 1 if it is a little word;
	}
	if (isInGroup(word, allCaps)) {
		return 2;	//return 2 if this is an allcaps word;
	}
	return 3;		//return 3 for all other words;
}

function toTitleCase(result, littleWords, allCaps) {
	var word_temp, word_result;
//	result[0] contains the entire match
//	result[1] contains the (leading) ["'] (if any)
//	result[2] contains the first letter
//	result[3] contains the rest of the letters
//	result[4] contains the trailing punctuation (if any)
//	result[5] conains the trailing stuff and junk (if any)

	word_temp = result[2] + result[3];
	var word_case = getCase(word_temp, littleWords, allCaps);

	switch (word_case) {
		case 1:
			if (first_word) {
				first_word = false;
				word_result = result[2].toUpperCase() + result[3];
			} else {
				word_result = word_temp;
			}
			break;
		case 2:
			word_result = word_temp.toUpperCase();
			break;
		case 3:
			word_result = result[2].toUpperCase() + result[3];
			break;
	}

	word_result = result[1] + word_result;
	for (var i = 4; i < result.length; i++) {
		word_result += result[i];
	}

	
	return word_result;
}

function toSpace(textarea) {
	var s = textarea.value;
	s = s.replace(/_/g, " ");
	textarea.value = s;
}


function toUnderScore(textarea) {
	var s = textarea.value;
	s = s.replace(/\s/g, "_");
	textarea.value = s;
}

function clearArea(textarea) {
	textarea.value = "";
}

function getLengthText(TextArea) {
	var len = TextArea.value.length;
	alert("Length in chars\n" + len);
}

function selectTextArea(textarea) {
//	if (textarea.value == "") return;
//	var clip = textarea.createTextRange();
//	clip.execCommand("Cut");
	textarea.select();
}

function copyToClipboard(textarea) {
	if (textarea.value == "") return;
	var clip = textarea.createTextRange();
	clip.execCommand("Copy");
}

function pasteFromClipboard(textarea) {
	textarea.value = "";
	var clip = textarea.createTextRange();
	clip.execCommand("Paste");
}

-->