/*** Editor Script Wrapper ***/
var oScripts=document.getElementsByTagName("script");
var sEditorPath;
for(var i=0;i<oScripts.length;i++)
{
	var sSrc=oScripts[i].src.toLowerCase();
	if (sSrc.indexOf("scripts/innovaeditor.js") != -1)
	 { sEditorPath=oScripts[i].src.replace(/innovaeditor.js/, ""); }
}


// catch bad browser (Mac IE) -- standard mac IE string:
//if (!preg_match('/^Mozilla\/\d+\.\d+ \(compatible; ?MSIE \d+\.\d+; ?Mac_P(ower)?PC/', $_SERVER['HTTP_USER_AGENT']))

/***********
// in mac safari this function exists but always returns undefined
//  this is used when writing html to the editor document/window
oTest = document.open("text/html","replace");
// HOWEVER, in that case, it works fine to just use the document itself
if (!oTest) { oTest = document; }
***********/


// easily turn off the html editor whenever we want
if (true)
{
	// internet exploder or mozilla/firefox/netscape
	//  although the real diff between those two is how to do text selections
	//  (document.selection vs document.getSelection and the wild diffs from there)
	var mozFolder = (navigator.appName.indexOf('Microsoft') != -1 ? '' : 'moz/');

	// the REAL mac safari problem is that it:
	//  lacks the ability to programmatically select webpage content!
	var sel = (window.getSelection ? window.getSelection() : {'addRange' : 1});
	if (!sel.addRange)
	{
		// define the REPLACE func for mac safari
		//  -- handles newlines to br tags and back
		function InnovaEditor (varName)
		{
			this.REPLACE = function (idName)
			{
				// replace br tags with newlines
				var i = document.getElementById(idName);
				i.value = i.value.replace(/<br>|<br \/>/gi, "\n");

				// keep track of this finagling we're doing
				f = document.createElement("input");
				f.name = "macsafari"; f.type = "hidden"; f.value = "1";
				i.form.appendChild(f);

				// replace newlines with brs for this content
				i.form.onsubmit = function () {
				 { i.value = i.value.replace(/(\r\n|\n|\r)/g, '<br />'); return true; }; }

				// add a message to suggest the user switch browsers
				f = document.createElement("p");
				f.innerHTML = "<b>The browser you are using does not have the ability to handle all the features of this page.  To get enhanced functionality (a full wysiwyg html editor), please use a different browser for this page.</b>";
				i.form.appendChild(f);
			};
		}
	}

	// IE, FF and Opera/etc (using FF version) use the actual innova editor
	else { document.write("<scr"+"ipt src='"+sEditorPath+mozFolder+"editor.js'></scr"+"ipt>"); }
}


// we need an empty declaration of InnovaEditor to avoid JS errors
else { function InnovaEditor (varName) { this.REPLACE = function (idName) {}; } }

