// DATE: 12/28/2007
function CheckIt(detect, string)
{
	var theInfo = new Object();

	theInfo.place = detect.indexOf(string) + 1;
	theInfo.string = string;
	
	if (theInfo.place == 0)
	{
		theInfo = null;
	}

	return theInfo;
}

function BrowserDetect()
{
	var info;
	var browser = new Object();
	
	browser.detect = navigator.userAgent.toLowerCase();
	
	browser.OS = '';
	browser.browserType = '';
	browser.version = '';

	if (info = CheckIt(browser.detect, 'msie')) browser.browserType = "Internet Explorer";
	else if (info = CheckIt(browser.detect, 'firefox')) browser.browserType = "Firefox";
	else if (info = CheckIt(browser.detect, 'safari')) browser.browserType = "Safari";
	else if (info = CheckIt(browser.detect, 'omniweb')) browser.browserType = "OmniWeb";
	else if (info = CheckIt(browser.detect, 'opera')) browser.browserType = "Opera";
	else if (info = CheckIt(browser.detect, 'webtv')) browser.browserType = "WebTV";
	else if (info = CheckIt(browser.detect, 'icab')) browser.browserType = "iCab";
	else if (info = CheckIt(browser.detect, 'konqueror'))
	{
		browser.browserType = "Konqueror";
		browser.OS = "Linux";
	}
	else if (info = CheckIt(browser.detect, 'mozilla'))
	{
		browser.browserType = "Netscape Navigator";
		browser.version = browser.detect.charAt(8);
	}
	else browser.browserType = "An unknown browser";
	
	if (browser.version == '') browser.version = browser.detect.charAt(info.place + info.string.length);
	
	if (browser.OS == '')
	{
		if (CheckIt(browser.detect, 'linux')) browser.OS = "Linux";
		else if (CheckIt(browser.detect, 'x11')) browser.OS = "Unix";
		else if (CheckIt(browser.detect, 'mac')) browser.OS = "Mac";
		else if (CheckIt(browser.detect, 'win')) browser.OS = "Windows";
		else browser.OS = "an unknown operating system";
	}
	
	return browser;
}

function ShowFCKEditor(editorId)
{
	var b = BrowserDetect();
	if (b.browserType != 'Internet Explorer')
	{
		//FCKeditorAPI.GetInstance(editorId).EditorDocument.designMode = 'on';
		FCKeditorAPI.GetInstance(editorId).MakeEditable();
	}
}

function __CM_FCK_CreateHtml(Id, Value, BasePath, Width, Height, ToolBar)
{
	if (typeof(document.__fckGenerated) == 'undefined' || typeof(document.__fckGenerated[Id]) == 'undefined' || document.__fckGenerated[Id] == false)
	{
		if (typeof(showMessage) == "function") { showMessage('One moment while the WYSIWYG editor loads... <img src="/elements/images/ajax/progress_indicator.gif" alt="Loading..." />'); }
		
		var b = BrowserDetect();
		if (b.browserType == "Internet Explorer" && b.version < 7)
		{
			// IE6 Rendering Hack to circumvent display bug when a div with an editor is in it is first displayed and the editor won't render
			setTimeout("__CM_FCK_InternalCreateHtml('" + Id + "', '" + Value + "', '" + BasePath + "', '" + Width + "', '" + Height + "', '" + ToolBar + "');", 1);
		}
		else
		{
			__CM_FCK_InternalCreateHtml(Id, Value, BasePath, Width, Height, ToolBar);
		};
	} else {
		ShowFCKEditor(Id);
	}
}

function __CM_FCK_ReplaceTextArea(Id, BasePath, Width, Height, ToolBar)
{
	if (typeof(document.__fckGenerated) == 'undefined' || typeof(document.__fckGenerated[Id]) == 'undefined' || document.__fckGenerated[Id] == false)
	{
		if (typeof(showMessage) == "function") { showMessage('One moment while the WYSIWYG editor loads... <img src="/elements/images/ajax/progress_indicator.gif" alt="Loading..." />'); }

		var b = BrowserDetect();
		if (b.browserType == "Internet Explorer" && b.version < 7)
		{
			// IE6 Rendering Hack to circumvent display bug when a div with an editor is in it is first displayed and the editor won't render
			setTimeout("__CM_FCK_InternalReplaceTextArea('" + Id + "', '" + BasePath + "', '" + Width + "', '" + Height + "', '" + ToolBar + "');", 1);
		}
		else
		{
			__CM_FCK_InternalReplaceTextArea(Id, BasePath, Width, Height, ToolBar);
		}
	} else {
		ShowFCKEditor(Id);
	}
}

function __CM_FCK_InternalCreateHtml(Id, Value, BasePath, Width, Height, ToolBar)
{
	var node = document.getElementById(Id + 'Field');
	var childNodes = node.getElementsByTagName('div');
	
	for (var i=0; i<childNodes.length; i++)
	{
		if (childNodes[i].className == 'input')
		{
			var fck = new FCKeditor(Id, Width, Height, ToolBar, Value);
			fck.BasePath = BasePath;
			childNodes[i].innerHTML = fck.CreateHtml();
			
			break;
		}
	}
}

function __CM_FCK_InternalReplaceTextArea(Id, BasePath, Width, Height, ToolBar)
{
	var fck = new FCKeditor(Id, Width, Height, ToolBar);
	fck.BasePath = BasePath;
	fck.ReplaceTextarea();
}

function FCKeditor_OnComplete(fck)
{
	if (typeof(document.__fckGenerated) == 'undefined')
	{
		document.__fckGenerated = new Object();
	}
	document.__fckGenerated[fck.Name] = true;
	
	if (typeof(FCKeditor_ChainedComplete) != 'undefined') { FCKeditor_ChainedComplete(fck); }
	if (typeof(hideMessage) == "function") { hideMessage(); }
}

function isEqualTo(value, options) {
	return (value == jQuery("#" + options.equals).val());
}
function ifHasValue(value, options) {
	var element = jQuery("#" + options.ifhasvalue);
	if(value != ''){
		return true
	}
	if(element.val() != '')
	{
		return false;	
	}	
	return true;
}
