// ------------------------------------------------------------------------------
//
//    generic_lib.js
//
//    Copyright, 2005 Precision Software Inc.
// 
// ------------------------------------------------------------------------------
// 
// ------------------------------------------------------------------------------
//



/*
   REVISIONS
   ---------

   DATE        CHANGE DESCRIPTION
   ----------  ----------------------------------------------------------------
   2005-11-07  BASELINE ESTABLISHED
   2005-12-11  Added str_replace

*/



// ------------------------------------------------------------------------------
function getSel()
{
	var txt = '';
	var foundIn = '';
	if (window.getSelection)
	{
	   // Mozilla, Safari
	   // ---------------
		txt = window.getSelection();
		foundIn = 'window.getSelection()';
	}
	else if (document.getSelection)
	{
	   // Explorer 5.2 Mac
	   // ----------------
		txt = document.getSelection();
		foundIn = 'document.getSelection()';
	}
	else if (document.selection)
	{
	   // Explorer 5/6 windows
	   // --------------------
		txt = document.selection.createRange().text;
		foundIn = 'document.selection.createRange()';
	}
	else return('');

	return(txt)
}


function str_replace(str_find, replace_str, str_normal, int_case_insensitive)
{
	if (arguments.length<3 || str_find=="" || str_normal=="" || typeof("".split)!="function")
		return(str_normal);

	//no parm means default, "case SENSITIVE"...
	if(!(int_case_insensitive))
		return(str_normal.split(str_find)).join(replace_str);

	str_find=str_find.toLowerCase();

	var rv="";
	var ix=str_normal.toLowerCase().indexOf(str_find);
	while(ix>-1)
	{
		rv+=str_normal.substring(0,ix)+replace_str;
		str_normal=str_normal.substring(ix+str_find.length);
		ix=str_normal.toLowerCase().indexOf(str_find);
	};
	return(rv+str_normal);
};//end function replacestring

