// 
// File:	utils.js
// Author:	Rob Allen
// Created:	August 22, 2002
//
// Purpose:	Miscellaneous utilities. 
//
// Copyright (c) 2002, ThoughtByDesign. All rights reserved.
// 
// This computer program is protected by copyright law and international treaties.
// Unauthorized reproduction or distribution of this program, or any portion of it,
// may result in severe civil and criminal penalties, and will be prosecuted to the
// maximum extent possible under the law.
// 
// Modification History: 
//	RLA, August 22, 2002, Creation and initial definition
// 


function Utils() {
} // establish name space


function hiliteStringByKeys(sourceStr, keys) {
	var newStr = sourceStr;
	var strLen = sourceStr.length;
	var plausibleMax = 1000;
	var actualMatches = 0;
	for (var i = 0; i < keys.length; i++) {
		var pos = 0;
		while (pos != -1 && pos < strLen && actualMatches < plausibleMax) {
			pos = newStr.toLowerCase().indexOf(keys[i].toLowerCase(),pos);
			if (pos != -1 && pos < strLen) {
				newStr = newStr.substr(0,pos)+"<span class='clsSearchHighlight'>"+newStr.substr(pos, keys[i].length)+"</span>"+newStr.substr(pos+keys[i].length);
				pos += 40+keys[i].length;
				actualMatches++;
			} // if
		} // while
		strLen = newStr.length;
	} // for
	return newStr;
} // hiliteStringByKeys()


function replaceQuote(str) {
	var newStr = str;
	var pos = 0;
	while((pos = newStr.indexOf("'",pos)) != -1) {
		if (pos != -1) {
			// newStr = newStr.substr(0,pos)+"&#39;"+newStr.substr(pos+1);
			newStr = newStr.substr(0,pos)+"&#146;"+newStr.substr(pos+1);
			pos += 1;
		}
	} // while
	return newStr;
} // replaceQuote()


function replaceCarriageReturn(str) {
	var newStr = str;
	var pos = 0;
	while((pos = newStr.indexOf("\n",pos)) != -1) {
		if (pos != -1) {
			newStr = newStr.substr(0,pos)+"<br />"+newStr.substr(pos+1);
			pos += 1;
		}
	} // while
	return newStr;
} // replaceCarriageReturn()


function helpBox(topic) {
	var hBox = window.open("/help/"+topic+".htm","HelpWindow","resizable,width=400,height=380,scrollbars");
	hBox.focus();
} // helpBox()


Utils.k_resume = "Resume";