//  Copyright (c) 1999-2002 by A Plus Consultants, L.L.C.
//  No part of this script may be used for any purpose without prior
//  written permission. Contact richard@aplusconsultants.com.
/*
	JavaScript Functions: (PREPARED FOR COMPRESSION.)
	These functions all contribute to scripting form validation.

	This is a list of functions contained in this script:

	bIsChanged(oE)
*/

function bIsChanged(oE) {
/*
	Created:
		07/22/2002
	Purpose:
		Compare the current value of the named element or element array
		to the original (default) value to see if there has been a change.
	Comments:
		Input types handled are:
		checkbox, radio, select-one, select-multiple, text, and textarea.
	REMINDER: select-multiple is not completely coded.
*/
	var oEA = new Array();
	//	Regular expression to find carriage returns in a string.
	var reCR = new RegExp("(\\r)", "gi");
	var sDefVal = "";
	var sTmpVal = "";
	var sVal = "";

	//	Determine if we are dealing with an array of elements.
	if (oE.length) {
		oEA = oE;
	}
	else {
		//	If not create one, so that the rest of code can process easily.
		oEA["0"] = oE;
	}

	for (ii = 0; ii < oEA.length; ii++) {
		if (oEA[ii].type == "textarea" || oEA[ii].type == "text") {
			/*
				The .defaultValue of the textarea does not have new line
				(\n) characters, which means that it will have 'n' fewer
				characters than an unchanged .value property where 'n' is
				the number carriage returns (\r) in the file.
			*/
			sTmpVal = oEA[ii].defaultValue;
			if (oEA[ii].type == "textarea") {
				//	Replace the carriage returns with
				//	carriage return / line feed pairs.
				sTmpVal = sTmpVal.replace(reCR, "\r\n");
			}
			sDefVal += sTmpVal;
			sVal += oEA[ii].value;
		}
		else if (oEA[ii].type == "checkbox" || oEA[ii].type == "radio") {
			sDefVal += oEA[ii].defaultChecked;
			sVal += oEA[ii].checked;
		}
		else if (oEA[ii].type == "select-one") {
			sDefVal += oEA[ii].options[oEA[ii].selectedIndex].defaultValue;
			sVal += oEA[ii].options[oEA[ii].selectedIndex].value;
		}
		else if (oEA[ii].type == "select-multiple") {
			sDefVal += oEA[ii].options[oEA[ii].selectedIndex].defaultValue;
			sVal += oEA[ii].options[oEA[ii].selectedIndex].value;
		}
		//	There is no need to go through the whole array. As soon as
		//	there is a difference, we can exit.
		if (sDefVal != sVal) {
			break;
		}
	}
	return !(sDefVal == sVal);
}
/*
Created:	07/22/2002
Change History:
07/22/2002:	Added bIsChanged(oE)
*/
