
// Begin ClearForm.js
//
// Author:				Steve Seaquist, Trusted Mission Solutions, 09/11/2008
//
// Revision History:	01/28/2009, SRS:	Added support for jquery.FCKEditor. Added this header and inline comments. 
//						09/11/2008, SRS:	Original implementation. 

function ClearForm	(pForm, pValueToUseForSelectedIndex)
{
var	sLen			= pForm.elements.length;
for	(var i = 0; i < sLen; i++)
	{
	var	sElement	= pForm.elements[i];
	var	sType		= sElement.type.toLowerCase();
	if		((sType == "checkbox") || (sType == "radio"))
		sElement.checked	= false;
	else if	(sType == "select-one")
		sElement.selectedIndex	= pValueToUseForSelectedIndex;
	else if	(sType == "select-multiple")
		{
		var	sOptsLen	= sElement.options.length;
		for	(var j = 0; j < sOptsLen; j++)
			sElement.options[j].selected	= false;
		}
	else if	((sType != "button")
		&&	 (sType != "hidden")
		&&	 (sType != "image")
		&&	 (sType != "reset")
		&&	 (sType != "submit"))
		sElement.value	= "";
	}

// In case the user is using /library/javascripts/jquery/jquery.FCKEditor/jquery.FCKEditors.SBA.js: 
if	(window.$)									// Without jQuery, can't have any jquery.FCKEditor instances. 
	if	(window.SlafGetRichTextEditors)			// Function defined in jquery.FCKEditors.SBA.js. 
		{
		var	sRichTextEditors		= window.SlafGetRichTextEditors();
		for	(var i = 0; i < sRichTextEditors.length; i++)
			{
			var	sHTMLElement		= sRichTextEditors[i];
			if	(sHTMLElement.fck)	// Don't error if **this** RichTextEditor isn't the FCKEditor. 
				{
				var	sErrored		= false;
				try					{FCKeditorAPI.GetInstance(sHTMLElement.name).SetHTML("");}
				catch (e)			{sErrored	= true;}
				if	(sErrored)
					{// DOM Navigation done only as a last resort. Could change with new FCKEditor versions. 
					var	sOuterFrame				= document.getElementById(sHTMLElement.name);
					var	sInnerFrame				= sOuterFrame.contentWindow.document
													.getElementById("xEditingArea").firstChild;
					var	sInnerBody				= null;	// Just defining it in one place, at this point. 
					if	($.browser.msie)
						sInnerBody				= sInnerFrame.contentWindow.document.body;
					else
						sInnerBody				= sInnerFrame.contentDocument.body;
					sInnerBody.innerHTML		= "";
					}
				}
			}
		}

// The following was originally for the Rich Text Editor ggedit.js (= "green grass editor", because it uses mootools.js). 
// Then ggedit and mootools proved to be much too flakey, so we replaced it with jquery.FCKEditor. But it doesn't really 
// hurt anything to leave the following in and let developers do something extra on clear (if they use this script). 

if	(window.DoSomethingExtraOnClear)
	window.DoSomethingExtraOnClear(pForm);

}

// End ClearForm.js

