<!--
//© 2000-2005 L.C. Enterprises
//http://LCen.com

var strGlobalMessage = " ('+': Valid | '-': Not yet valid | '!': Must be entered correctly)";
var strErrorMessage = "This field can't be validated dynamically!";
var objCurrentForm = null;
var arrStatusImages;
var blnShowStatusInfo;

var isNetscape475 = navigator.appName.toUpperCase() == "NETSCAPE" && navigator.appVersion.substring(0, 4) == '4.75';
var isNetscape6 = navigator.appName.toUpperCase() == "NETSCAPE" && navigator.appVersion.substring(0, 3) == '5.0';
if(isNetscape6) strErrorMessage = "This field can't be validated correctly by this browser!";

function CheckRegExp(strPattern, strWhat) //--------------------------
{
	if(strWhat == null) return false;
	var objRegExp = new RegExp(strPattern, "i"); //Ignore Case
	return (objRegExp.test(strWhat));
}

function CheckField(objField) //--------------------------
{
	if(!isNetscape6)
	{
		return (eval(CheckRegExp(objField.Config[0], objField.value))) ? 1 : 0; //1 = Valid / 0 = Invalid
	}
	else //Validation failed
	{
		return -1;
	}
}                                                                    

function ShowState(intValid, objField, blnCurrentlyEditing) //--------------------------
{
    var imgControl = window.document.images[objField.name + "_Img"];
	var strMessage = objField.Config[1]; //Success

    if(imgControl != null && intValid >= 0) //Validation was successful
	{
		var intImage = 0; //Valid

		if(intValid == 0) //Invalid
		{
			intImage = blnCurrentlyEditing ? 1 : 2; //1 = Failed while editing / 2 = Attention
			strMessage = objField.Config[2]; //Failed
		}

		if(imgControl.state != intImage)
		{
			if(blnShowStatusInfo) window.status = strMessage + strGlobalMessage;
			imgControl.src = arrStatusImages[intImage];
			imgControl.state = intImage;
		}
    }
	else
	{
		if(blnShowStatusInfo) window.status = strErrorMessage;
    }
}

function showOnFocus(objField) //--------------------------
{
	ShowState(CheckField(objField), objField, true);
}

function showOnBlur(objField) //Lost Focus --------------------------
{
	ShowState(CheckField(objField), objField, false);
}

function showOnKeyUp(objField) //--------------------------
{
	if(isNetscape475)
		showOnKeyN(objField);
	else
		ShowState(CheckField(objField), objField, true);
}

function showOnKeyN(objField) //--------------------------
{
	objField.blur();
	objField.focus();
}

function CheckForm(objForm, blnShowErrors) //Check all fields in a form --------------------------
{
	var strMessage = "";
	var objFields = objForm.elements;
	var objFirstFieldThatFailed = null;

	for (var i = 0; i < objFields.length; i++)
	{
		var objTestField = objFields[i];

		if(objTestField.Config != null) //Config exists
		{
			var imgControl = window.document.images[objTestField.name + "_Img"];
			var intValid = CheckField(objTestField);

			if(intValid >= 0) //Validation was successful
			{
				if(intValid == 0) //Invalid
				{
					if(imgControl != null) imgControl.src = arrStatusImages[2];
					if(objFirstFieldThatFailed == null) objFirstFieldThatFailed = objTestField;
					var strInputName = document.all[objTestField.name + "_Lbl"].innerText;
					if(strInputName == null || strInputName == '') strInputName = objTestField.name;
					strMessage += strInputName + ": " + objTestField.Config[2] + ".\n";
				}
				else //Valid
				{
					if(imgControl != null) imgControl.src = arrStatusImages[0];
				}
			}
		}
	}

	if(objFirstFieldThatFailed != null) objFirstFieldThatFailed.focus(); //Set focus
	if(blnShowErrors &&  strMessage != "") alert(strMessage); //Show error msg

	return strMessage == ""; //Empty error msg = true (no errors ocurrred)
}

function CheckAllForms() //Update status of all forms --------------------------
{
	var blnValid = true;

	for (var i = document.forms.length - 1; i >= 0; i--)
	{
		var objForms = document.forms[i];

		if(!CheckForm(objForms, false)) blnValid = false; //Check fields in form
	}

	return blnValid;
}

function getStringValue(objField) //--------------------------
{
	if(objField.type == "select-one")
	{
		return objField.options[objField.selectedIndex].value;
	}
	else if(objField[0] != null && objField[0].type == "radio")
	{
		for (var i in objField)
		{
			if(objField[i].checked == "1") return objField[i].value;
		}
	}
	else if(objField.value != null)
	{
		return objField.value;
	}

	return "";
}

function getBooleanValue(objField) //--------------------------
{
	return (objField.type == "checkbox") ? (objField.checked ? true : false) : ((getStringValue(objField) != "") ? true : false);
}
//-->
