/************************************************************************
* FILE:			forms.js												*
* AUTHOR:		Richard Shadman											*
*************************************************************************
* USAGE:																*
*************************************************************************


	USING THE DATA TYPE VALIDATION:

1. Create a script include tag within the <HEAD></HEAD> tag of the
document, like this:
<SCRIPT SRC="forms.js"></SCRIPT>

2. Within the initialization of the page include a call to the function
setFormValidation(). You do not need to pass any parameters; this
function will look at every object in the page and set up validation
according to the format below.

3. Add appropriate attributes to input boxes and text areas as needed.
The attributes needed to be set are as follows:

ATTRIBUTE	NAME		DESCRIPTION					VALUES		REQUIRED
************************************************************************
dt			Data Type	First form of validation.	1 (text)	YES
						although listed as required	2 (numeric)
						it must be ommitted in the	3 (date)
						element TEXTAREA.			text
													numeric
													date

maxlength	Max Length	Already handled by INPUT	length in	NO
						elements, it is only added	characters
						here because of added
						support for TEXTAREA.

regexp		Regular		Any regular expression can	Any valid	NO
			Expression  be put here, and if the		regular
						field passes the data type	expression.
						requirement, it will be
						tested against this
						expression. See below for
						examples.

format		Format		An example of the required	N/A			NO
						format in the regular
						expression. if ommitted,
						the regular epxression
						source will be used in the
						error message.
************************************************************************


	USING REQUIRED FIELD VALIDATION:

1. If you have not allready, create a script include tag within the
<HEAD></HEAD> tag of the document, like this:
<SCRIPT SRC="forms.js"></SCRIPT>

2. Call one of the 2 following functions to check required fields.

FUNCTION			DESCRIPTION
************************************************************************
checkRequired()		Returns a string of messages for fields that are 
					required but not inputted. Returns an empty string
					if all required fields are accounted for.

bCheckRequired()	Calls checkRequired(), and alerts the messages, if
					any. The function returns true if all fields are
					accounted for, false if not.
************************************************************************

If your page requires unique form validation beyond the scope of this
file, chances are you will use checkRequired() within another function.
If this file can handle all your form validation, you can use
bCheckRequired() directly on the onsubmit event, as follows:

<FORM action=page.asp method=post onsubmit="return bCheckRequired()">

WARNING!! If the form is submitted by means other than an input button
of type "submit" (i.e. from scripts), the onsubmit event will not be
fired and the above call will be ignored. In such a case incorporate 
the call directly into the script.

3. Add appropriate attributes to the required elements as needed. The
attributes needed to be set are as follows:

ATTRIBUTE	NAME		DESCRIPTION					VALUES		REQUIRED
************************************************************************
required	Required	Attribute that specifies	0 (False)	NO
						whether or not a value		1 (True)
						is required or not. If
						ommitted, value is treated
						as 0 (False).

display		Display		The name of the element		N/A			NO
						that is required, as 
						displayed in the error
						message. If ommitted, the
						element name is used.

nullvalue	NULL Value	Value to be considred "Not	N/A			NO
						Selected" in SELECT box.
						If ommitted, an empty
						string is considered "Not
						Selected".
************************************************************************

	EXAMPLES
1. INPUT BOX EXAMPLES

<INPUT name="email" maxlength=255 dt="text"
	regexp="^(\w[\w\.]+@\w+\.[\w\.]*\w+)$" format="user@domain.com"
	required="1" display="Email Address" />

In the above example, we have a text (dt) input named email. This input
has a specific format for validation (regexp), with a user friendly
display (format) for the error message. This input is required 
(required) and has a user friendly display (display) when it is left
blank.


<INPUT name="startdate" dt="3" />

In the above example, we have a date (dt) input named startdate. This
input is not required, but if entered must be a valid date.


<SELECT name="cmb1" required="1" nullvalue="0">
	<OPTION VALUE="0">Select an option</OPTION>
	...
</SELECT>

In the above example, we have a required select box with a specific 
non selectable value of 0. If any option with a value of 0 is chosen,
this select box will be considered incomplete or not selected.

2. COMMON REGULAR EXPRESSIONS

Regular Expression					Description
************************************************************************
^\w+(\.\w+)*@\w+\.\w+(\.\w+)*$		This is the regular expression to
									test for a valid email address.

^\w+$								This is the regular expression to
									test for word characters only.
									
^(\\\\[^\\\/:\*\?"<>|]*[^\\\/:\*\?"<>| \.]+\\|[a-zA-Z]:\\)[^\\\/:\*\?"<>|]*[^\\\/:\*\?"<>| \.]+(\\[^\\\/:\*\?"<>|]*[^\\\/:\*\?"<>| \.]+)*$
									This regular expression is to test
									for a valid folder path or UNC.

************************************************************************


If you have any questions, ask!
 - rshadman@ceimis.com

************************************************************************/
//Variables
var assocAry = new Array();
var _oSQLFrame = null;
var _sqlCallStack = new Array();
var _sqlInCall = null;
//Classes
function class_FormAssoc(sParentName, sChildName, sType) {
	this.parent = sParentName;
	this.child = sChildName;
	this.type = sType;
}

//Functions

//Callable Public Functions
function setFormValidation(oObject) {
	var sFormula;
	var frmRegExp = /\{[^\{\}]+\}/g;
	var reBlankLine = /^\s*$/gm;
	var reAnon = /^function (anonymous|onchange)/im;
	var reTagName = /(SELECT|TEXTAREA|INPUT)/i;
	var depAry = new Array();
	var objCounter, depCounter;
	var tempObj;
	var currEventHandler = null;
	if (typeof(oObject) != "object")
		oObject = document.body;
	for (objCounter=0;objCounter<oObject.childNodes.length;objCounter++) {
		currEventHandler = null;
		if (reTagName.test(oObject.childNodes[objCounter].tagName) && !oObject.childNodes[objCounter].disabled) {
			if (oObject.childNodes[objCounter].type == "button" || oObject.childNodes[objCounter].type == "submit" || oObject.childNodes[objCounter].type == "checkbox")
				break;
			if (oObject.childNodes[objCounter].getAttribute("regexp") != null && oObject.childNodes[objCounter].getAttribute("regexp").length > 0)
				addValidation(oObject.childNodes[objCounter], validateRegExp);
			switch (oObject.childNodes[objCounter].getAttribute("dt")) {
				case "1" : //Text
				case "text" :
					addHelpText(oObject.childNodes[objCounter], "[Text]");
					break;
				case "2" : // Numeric
				case "numeric" :
					addHelpText(oObject.childNodes[objCounter], "[Numeric]");
					addValidation(oObject.childNodes[objCounter], validateNumber);
					break;
				case "3" : // Date
				case "date" :
					addHelpText(oObject.childNodes[objCounter], "[Date]");
					addValidation(oObject.childNodes[objCounter], validateDate);
					break;
				case "4" : // Formulas
					addHelpText(oObject.childNodes[objCounter], "[Formula]");
					oObject.childNodes[objCounter].readOnly = true;
					sFormula = oObject.childNodes[objCounter].getAttribute("formula");
					if (sFormula != null) {
						depAry = sFormula.match(frmRegExp);
						//alert(depAry.length);
						if (depAry != null) {
							for (depCounter=0;depCounter<depAry.length;depCounter++) {
								tempObj = eval("document.frm." + depAry[depCounter].substr(1,depAry[depCounter].length - 2));
								assocAry[assocAry.length] = new class_FormAssoc(oObject.childNodes[objCounter].name,tempObj.name, "formula");
								if (typeof(tempObj.onchange) == "object" || typeof(tempObj.onchange) == "function")
									if (tempObj.onchange == null || tempObj.onchange.toString().indexOf("checkDependencies") == -1)
										addValidation(tempObj, checkDependencies);
							}
							calcForm(oObject.childNodes[objCounter].name);
						}
					}
					break;
				case "5" : //SQL Tags
					addHelpText(oObject.childNodes[objCounter], "[SQL Tag]");
					oObject.childNodes[objCounter].readOnly = true;
					sFormula = oObject.childNodes[objCounter].getAttribute("sqltag");
					if (sFormula != null) {
						depAry = sFormula.match(frmRegExp);
						for (depCounter=0;depCounter<depAry.length;depCounter++) {
							tempObj = eval("document.frm." + depAry[depCounter].substr(1,depAry[depCounter].length - 2));
							assocAry[assocAry.length] = new class_FormAssoc(oObject.childNodes[objCounter].name, tempObj.name, "sqltag");
							if (typeof(tempObj.onchange) == "object" || typeof(tempObj.onchange) == "function") {
								if (tempObj.onchange == null || tempObj.onchange.toString().indexOf("checkDependencies") == -1) {
									addValidation(tempObj, checkDependencies);
								}
							}
						}
						oObject.childNodes[objCounter].setAttribute("sqltag", sFormula.substr(0, sFormula.indexOf("|")));
						//calcSQL(oObject.childNodes[objCounter].name);
					}
					break;
				default :
					oObject.childNodes[objCounter].title += " [Text]";
					if (oObject.childNodes[objCounter].tagName == "TEXTAREA")
						if (!isNaN(oObject.childNodes[objCounter].getAttribute("maxlength")))
							addValidation(oObject.childNodes[objCounter], validateLength);
					break;
			}
		}
		else
			setFormValidation(oObject.childNodes[objCounter]);
	}
}

function clearFormValidation(oObject) {
	var currEventHandler = "";
	var objCounter;
	var reValTest = /2\(this\)\) \{((.|\n)+)\}else\{return false;\}\n*}$/im;
	var reFuncBody = /^.+\{((.|\n)+)\}$/im;
	var reBlankLine = /^\s*$/gm;
	var reTagName = /(SELECT|TEXTBOX|INPUT)/i;
	var reAnon = /^function (anonymous|onchange)/im;
	if (typeof(oObject) != "object")
		oObject = document.body;
	for (objCounter=0;objCounter<oObject.childNodes.length;objCounter++) {
		currEventHandler = "";
		if (reTagName.test(oObject.childNodes[objCounter].tagName) && !oObject.childNodes[objCounter].disabled) {
			switch (typeof(oObject.childNodes[objCounter].onchange)) {
				case "function" :
					currEventHandler = oObject.childNodes[objCounter].onchange.toString().replace(reBlankLine, "");
					break;
				case "string" :
					currEventHandler = oObject.childNodes[objCounter].onchange.replace(reBlankLine, "");
					break;
				default :
					currEventHandler = "";
					break;
			}
			//if (currEventHandler.substr(9,currEventHandler.indexOf("(") - 9) == "anonymous") {
			if (reAnon.test(currEventHandler)) {
				if (reValTest.test(currEventHandler))
					currEventHandler = RegExp.$1;
				else if (reFuncBody.test(currEventHandler))
					currEventHandler = RegExp.$1;
			}
			else if (currEventHandler.substr(9,8) == "validate")
					currEventHandler = "";
			if (currEventHandler.length > 0) {
				if (oObject.childNodes[objCounter].tagName != "SELECT")
					oObject.childNodes[objCounter].onblur = oObject.childNodes[objCounter].onchange = new Function(currEventHandler);
				else
					oObject.childNodes[objCounter].onchange = new Function(currEventHandler);
			}
			else {
				if (oObject.childNodes[objCounter].tagName != "SELECT")
					oObject.childNodes[objCounter].onblur = oObject.childNodes[objCounter].onchange = null;
				else
					oObject.childNodes[objCounter].onchange = null;
			}
		}
		clearFormValidation(oObject.childNodes[objCounter]);
	}
}
function resetFormValidation() {
	clearFormValidation();
	setFormValidation();
}
function checkRequired(oObject) {
	var sReturn = "";
	if (typeof(oObject) != "object")
		oObject = document.body;
	for (var i=0;i<oObject.childNodes.length;i++) {
		if (oObject.childNodes[i].getAttribute)
			if (oObject.childNodes[i].getAttribute("required") == 1 && !oObject.childNodes[i].disabled)
				if (oObject.childNodes[i].tagName == "SELECT") {
					if (oObject.childNodes[i].value == (typeof(oObject.childNodes[i].getAttribute("nullvalue")) == "string" ? oObject.childNodes[i].getAttribute("nullvalue") : ""))
						sReturn += (oObject.childNodes[i].getAttribute("display") == null ? oObject.childNodes[i].name : oObject.childNodes[i].getAttribute("display"))
								+ " is required.\n";
				}
				else
					if (oObject.childNodes[i].value.length == 0)
						sReturn += (oObject.childNodes[i].getAttribute("display") == null ? oObject.childNodes[i].name : oObject.childNodes[i].getAttribute("display"))
								+ " is required.\n";
		sReturn += checkRequired(oObject.childNodes[i]);
	}
	return sReturn;
}
function bCheckRequired(oObject) {
	var sReturn = "";
	if (typeof(oObject) != "object")
		oObject = document.body;
	sReturn = checkRequired(oObject);
	if (sReturn.length > 0) {
		alert(sReturn);
		returnFirstRequired().focus();
		if (returnFirstRequired().tagName == "INPUT" ||returnFirstRequired().tagName == "TEXTAREA")
			returnFirstRequired().select();
		return false;
	}
	else
		return true;
}
function returnFirstRequired(oObject) {
	var oReturn;
	if (typeof(oObject) != "object")
		oObject = document.body;
	for (var i=0;i<oObject.childNodes.length;i++) {
		if (oObject.childNodes[i].getAttribute)
			if (oObject.childNodes[i].getAttribute("required") == 1 && !oObject.childNodes[i].disabled)
				if (oObject.childNodes[i].value.length == 0)
					return oObject.childNodes[i];
		oReturn = returnFirstRequired(oObject.childNodes[i]);
		if (typeof(oReturn) == "object")
			break;
	}
	return oReturn;
}
function colorCodeRequired(oObject) {
	if (typeof(oObject) != "object")
		oObject = document.body;
	for (var i=0;i<oObject.childNodes.length;i++) {
		switch (oObject.childNodes[i].tagName) {
			case "SELECT" :
			case "INPUT" :
			case "TEXTAREA" :
				if (oObject.childNodes[i].getAttribute("required") == 1 && !oObject.childNodes[i].disabled)
					oObject.childNodes[i].style.backgroundColor = "lightyellow";
				break;
			default :
				colorCodeRequired(oObject.childNodes[i]);
				break;
		}
	}
}
function makeReadOnly(oObject) {
	if (typeof(oObject) != "object")
		oObject = document.body;
	for (var i=0;i<oObject.childNodes.length;i++)
		switch (oObject.childNodes[i].tagName) {
			case "INPUT" :
				if (oObject.childNodes[i].type == "button") {
					oObject.childNodes[i].disabled = true;
					break;
				}
			case "TEXTAREA" :
				oObject.childNodes[i].readOnly = true;
				break;
			case "SELECT" :
				oObject.childNodes[i].disabled = true;
				break;
			default :
				makeReadOnly(oObject.childNodes[i]);
		}
}
//Validation Functions
function validateNumber(that) {
	if (document.all)
		field = event.srcElement;
	else
		field = that.currentTarget;
	return validateNumber2(field);
}
function validateNumber2(field) {
	if (field.value.length == 0)
		return true;
    if(isNaN(field.value)) {
        alert("Field must contain only numbers, no other characters.");
        field.focus();
        field.select();
        return false;
    } else
        return true;
}
function validateDate(that) {
	if (document.all)
		var field = event.srcElement;
	else
		var field = that.currentTarget;
	return validateDate2(field);
}
function validateDate2(field) {
    var sError = "";
    //make sure there is more than just spaces there
    if (field.value.search(/\S/) != -1) {
        var reDate = /^(\d{1,2})\/(\d{1,2})\/(\d{4}|\d{1,2})$/;
        if (!reDate.test(field.value)) {
			alert("Field must be a valid date.\nDate must be in format of (MM/DD/YYYY).");
			field.focus();
			field.select();
			return false;
		}
		var iMonth = Number(RegExp.$1);
		var iDay = Number(RegExp.$2);
		var iYear = Number(RegExp.$3);
		iYear = iYear > 999 ? iYear : iYear < 50 ? (iYear + 2000) : (iYear + 1900);
			
		switch (iMonth) {
			case 1 : case 3 : case 5 : case 7 : case 8 : case 10 : case 12 :
				if (iDay < 1 || iDay > 31)
					sError = "Invalid Day Entered.";
				break;
			case 2 :
				if ((((iYear % 4 == 0) && (iYear % 100 != 0)) || (iYear % 400 == 0))) {
					if (iDay < 1 || iDay > 29)
						sError = "Invalid Day Entered.";
				}
				else {
					if (iDay < 1 || iDay > 28)
						sError = "Invalid Day Entered.";
				}
				break;
			case 4:	case 6:	case 9:	case 11:
				if (iDay < 1 || iDay > 30)
					sError = "Invalid Day Entered.";
				break;
			default :
				sError = "Invalid Month Entered.";
				break;
		}
		if (sError.length > 0) {
			sError += "\nDate must be in format of (MM/DD/YYYY).";
			alert(sError);
			field.focus();
			field.select();
			return false;
		}
		field.value = (iMonth < 10 ? "0" : "") + iMonth + "/" + (iDay < 10 ? "0" : "") + iDay + "/" + iYear;
    }
    return true;
}
function validateRequiredField(that) {
	if (document.all)
		field = event.srcElement;
	else
		field = that.currentTarget;
	return validateRequiredField2(field);
}
function validateRequiredField2(field) {
    if (field.value.search(/\S/) == -1) {
        alert("Field is required. Please enter appropriate information.");
        field.focus();
        return false;
    }
    return true;
}
function validateLength(that) {
	if (document.all)
		var field = event.srcElement;
	else
		var field = that.currentTarget;
	return validateLength2(field);
}
function validateLength2(field) {
    if(field.value.length >= parseInt(field.getAttribute("maxlength"))) {
        alert("Field cannot be longer than " + field.getAttribute("maxlength") + " characters.");
        field.focus();
        field.select();
        return false;
    }
    return true;
}
function validateRegExp(that) {
	if (document.all)
		var field = event.srcElement;
	else
		var field = that.currentTarget;
	return validateRegExp2(field);
}
function validateRegExp2(field) {
	if (field.value.length > 0) {
		var reTest = new RegExp(field.getAttribute("regexp"),"i");
		if (!reTest.test(field.value)) {
			alert("Invalid Format! Format must be \""
					+ (field.getAttribute("format") == null ? field.getAttribute("regexp") : field.getAttribute("format"))
					+ "\".");
			field.focus();
			return false;
		}
	}
	return true;
}

//Formula Functions
function calcForm(sFormEl) {
	var depAry = getDepByName(sFormEl,false);
	var tempObj = eval("document.frm." + sFormEl);
	var tempVal;
	var sFormula = tempObj.getAttribute("formula");
	var regExp;
	var bExecute = true;
	//alert(depAry.length);
	for (var i=0;i<depAry.length;i++) {
		if (depAry[i].type == "formula") {
			tempVal = eval("document.frm." + depAry[i].child + ".value");
			if (tempVal.length == 0)
				tempVal = "0";
			//alert(tempVal);
			if (isNaN(parseInt(tempVal))) {
				bExecute = false;
				break;
			}
			regExp = new RegExp("{" + depAry[i].child + "}","gi")
			sFormula = sFormula.replace(regExp,tempVal);
		}
	}
	if (bExecute)
		tempObj.value = eval(sFormula);
			
	else
		tempObj.value = "##NAN##";
	depAry = getDepByName(sFormEl,true);
	checkDependencies3(depAry);
}
function calcSQL(oDep) {
	if (_oSQLFrame == null) {
		_oSQLFrame = document.createElement("IFRAME");
		document.body.appendChild(_oSQLFrame);
		_oSQLFrame.style.position = "absolute";
		_oSQLFrame.style.width = "0px";
		_oSQLFrame.style.height = "0px";
	}
	if (!isInList(_sqlCallStack, oDep)) {
		_sqlCallStack[_sqlCallStack.length] = oDep;
		if (!_sqlInCall) {
			_sqlInCall = true;
			execSQLCall();
		}
	}
}
function execSQLCall() {
	var sItem = _sqlCallStack.shift();
	var depAry = getDepByName(sItem, false);
	var sReplaceVals = "";
	for (var i=0;i<depAry.length;i++)
		sReplaceVals += depAry[i].child + "," + document.getElementsByName(depAry[i].child)[0].value + ",";
	sReplaceVals = sReplaceVals.substr(0, sReplaceVals.length - 1);
	var sURL = sMCommonPath + "/common/other/sqlexecute.asp?parent=" + sItem + "&sqltag=" + document.getElementsByName(sItem)[0].getAttribute("sqltag") + "&replace=" + sReplaceVals;
	_oSQLFrame.src = sURL;
}
function execSQLCallBack(sParent, sValue) {
	document.getElementsByName(sParent)[0].value = sValue;
	checkDependencies3(getDepByName(sParent, true));
	if (_sqlCallStack.length > 0)
		execSQLCall();
	else
		_sqlInCall = false;
}
//Dependency Functions
function checkDependencies(that) { //dependency is as follows.. the parent depends on all the children, so check by child.
	if (document.all)
		var field = event.srcElement;
	else
		var field = that.currentTarget;
	checkDependencies2(field);
}
function checkDependencies2(field) { //dependency is as follows.. the parent depends on all the children, so check by child.
	var sName = field.name;
	var depAry = getDepByName(sName, true);
	for (var i=0;i<depAry.length;i++)
		checkDependency(depAry[i]);
}
function checkDependencies3(depAry) { //dependency is as follows.. the parent depends on all the children, so check by child.
	for (var i=0;i<depAry.length;i++)
		checkDependency(depAry[i]);
}

//Helper Functions
function addHelpText(oObject, sHelpText) {
	var reHelpText = /(.*)(\s*\[(Text|Numeric|Date|Formula|SQL Tag)\])+/;
	if (reHelpText.test(oObject.title))
		oObject.title = RegExp.$1;
	if (oObject.title.length == 0) {
		if (oObject.parentNode.title.length > 0)
			oObject.title = oObject.parentNode.title + "\n" + sHelpText;
		else if (oObject.parentNode.parentNode.title.length > 0)
			oObject.title = oObject.parentNode.parentNode.title + "\n" + sHelpText;
		else
			oObject.title = sHelpText;
	}
	else {
		oObject.title += "\n" + sHelpText;
	}
}
function addValidation(oObject, ptrValidation) {
	var reBlankLine = /^\s*$/gm;
	var reAnon = /^function (anonymous|onchange)/im;
	var reTagName = /(SELECT|TEXTBOX|INPUT)/i;
	var reMid = /\{return ([^\}\{]+?);\}/im;
	var currEventHandler = oObject.onchange;
	var sValidation = ptrValidation.toString().substr(9,ptrValidation.toString().indexOf("(") - 9);
	switch (typeof(currEventHandler)) {
		case "string" :
			break;
		case "function" :
			if (reAnon.test(currEventHandler.toString()))
				currEventHandler = currEventHandler.toString().substring(currEventHandler.toString().indexOf("{") + 1,currEventHandler.toString().lastIndexOf("}") - 1).replace(reBlankLine, "");
			else if (currEventHandler.toString().indexOf("validate") > -1)
				currEventHandler = "return " + currEventHandler.toString().substr(9,currEventHandler.toString().indexOf("(") - 9) + "2(this);";
			else
				currEventHandler = "return " + currEventHandler.toString().substr(9,currEventHandler.toString().indexOf("(") - 9) + "(this);";
			break;
	}
	if (oObject.getAttribute("regexp") != null && oObject.getAttribute("regexp").length > 0) {
		if (typeof(currEventHandler) == "string" && currEventHandler.length > 0)
			currEventHandler = "if (validateRegExp(this)) {" + currEventHandler + "}else{return false;}";
		else
			currEventHandler = "return validateRegExp(this);"
	}
	if (typeof(currEventHandler) == "string" && currEventHandler.length > 0)
		if (sValidation.indexOf("validate") > -1)
			currEventHandler = "if (" + sValidation + "2(this)) {" + currEventHandler + "}else{return false;}";
		else if (currEventHandler.indexOf("validate") > -1) {
			if (currEventHandler.indexOf("return validate") == 0)
				currEventHandler = "if (" + currEventHandler.substring(7,currEventHandler.indexOf(")") + 1) + ") {return "
									+ sValidation + "2(this);"
									+ "}else{return false;}";
			else
				currEventHandler = currEventHandler.substr(0,currEventHandler.lastIndexOf(") {") + 1)
								+ "if (" + sValidation + "2(this)) {"
								+ currEventHandler.substr(currEventHandler.lastIndexOf(") {") + 9 + sValidation.length)
								+ "}else{return false;}";
		}
		else
			currEventHandler += ";" + sValidation + "2(this);";
			
	else
		currEventHandler = ptrValidation;
	//alert(currEventHandler);
	//if (reMid.test(currEventHandler))
	//	alert(RegExp.$1);
	switch (typeof(currEventHandler)) {
		case "string" :
			if (oObject.tagName != "SELECT")
				oObject.onblur = oObject.onchange = new Function(currEventHandler);
			else
				oObject.onchange = new Function(currEventHandler);
			break;
		case "function" :
			if (oObject.tagName != "SELECT")
				oObject.onblur = oObject.onchange = currEventHandler;
			else
				oObject.onchange = currEventHandler;
			break;
	}
}
function checkDependency(oDep) {
	switch (oDep.type) {
		case "formula" :
			calcForm(oDep.parent);
			break;
		case "sqltag" :
			calcSQL(oDep.parent);
			break;
		default :
			alert(depAry[i].type + " not implemented.");
			break;
	}
}
function getDepByName(sName, isChild) {
	var tempAry = new Array;
	for (var i=0;i<assocAry.length;i++) {
		if (isChild) {
			if (assocAry[i].child == sName)
				tempAry[tempAry.length] = assocAry[i];
		}
		else {
			if (assocAry[i].parent == sName)
				tempAry[tempAry.length] = assocAry[i];
		}
	}
	return tempAry;
}
function isInList(ary, val) {
	for (var i=0;i<ary.length;i++) {
		if (ary[i] == val)
			return true;
	}
	return false;
}
