/** public void handleException throws Error : Catchall method to route all CobaltError instances

  * appropriately, and just throw every other kind like normal.

  * @param Error exception Exception to handle

  */

handleException = function(exception) {

	if (exception instanceof CobaltError) exception.handleException();

	else throw exception;

}

/** public class CobaltError : Base JavaScript error for all other cblt errors to subclass. */

function CobaltError() {

	this.titleKey = "INCORRECT.INFORMATION";

	this.messageKeys = ["ERRORMESSAGE.INCORRECT.DATA"];

}

/** public void handleException : Default implementation of method to handle errors. */

CobaltError.prototype.handleException = function() {}



/** public static class FormUtility : Useful mechanisms for validating forms. */

FormUtility = {

	/** public static String HIGHLIGHT_COLOR : Default highlight color for error fields */

	HIGHLIGHT_COLOR : "#FFFF66",

	/** public static String LABEL_COLOR : Default label color relating to error fields */

	LABEL_COLOR : "#FF0000",

	/** private Array highlightedFields : List of highlighted fields after validation fails */

	highlightedFields : [],

	/** private Map initializedFieldVOs : Storage for lazy loaded FieldVOs, for performance */

	initializedFieldVOs : {},

	/** private Map sections : Storage for initted FieldVOs, keyed by section name */

	sections : {},

	/** public void changeFieldsColor : Change field backgrounds to the specified color.

	  * @param Array fieldList List of fields to change color

	  * @param String Hex color string, e.g. FF0000

	  */

	changeFieldsColor : function(fieldList, color) {

		var currElem, currElemType;

		for (var i=0; i<fieldList.length; i++) {

			var currElem = fieldList[i];

			if (!currElem) break;

			currType = currElem.type;

			if ((currType != "button") && (currType != "submit") && (currType != "reset") && (currType != "hidden")) {

				if (!currElem.length || currType == "select-one") {

					currElem.style.backgroundColor = color;

				} else {

					for (var j=0; j<currElem.length; j++) currElem[j].style.backgroundColor = color;

				}

			}

		}

	},

	/** public void changeLabelColor : Change label text to the specified color.

	  * @param Array fieldList List of fields to change color

	  * @param String Hex color string, e.g. FF0000

	  */

	changeLabelColor : function(fieldList, color) {

		//document.getElementsByTagName("label").style.color = "000000";

		var currElem, currElemType;

		for (var i=0; i<fieldList.length; i++) {

			var currElem = fieldList[i];

			if (!currElem) break;

			currType = currElem.type;

			labelId = currElem.name + "_label";

			if ((currType != "button") && (currType != "submit") && (currType != "reset") && (currType != "hidden")) {

				if (!currElem.length || currType == "select-one") {

					document.getElementById(labelId).style.color = color;					

				} else {

					for (var j=0; j<currElem.length; j++) currElem[j].style.backgroundColor = color;

				}

			}

		}

	},

	/** public Array getBadlyFormatted : Get a list of fields failing format validation in a section.

	  * @param HTMLElement section Form, div, etc. to search for bad fields in

	  * @return List of badly formatted fields

	  */

	getBadlyFormatted : function(section) {

		var formattedFields = FormUtility.getFormattedFields(section);

		var fields = [];

		for (var fieldName in formattedFields) {

			var field = formattedFields[fieldName];

			var ruleMethod = FormUtility.getFormatRule(field);

			var className = (field.length && !field.name) ? field[0].className : field.className;

			if ((className.indexOf("disabled") == -1) && (!ruleMethod || !ruleMethod(field.value))) fields.push(field);

		}

		return fields;

	},

	/** public Map getFormattedFields : Get the set of fields that have formatting rules in a section.

	  * @param HTMLElement section Form, div, etc. to search for formatted fields in

	  * @return List of formatted fields

	  */

	getFormattedFields : function(section) {

		if (!section) return {};

		if (!FormUtility.sections[section.id]) FormUtility.registerFields(section);

		return FormUtility.sections[section.id]["formatted"];

	},

	/** public Function getFormatRule : Get the function object which maps to a field's formatRule.

	  * Handles dot-separated references, e.g. "Foo.isBar".

	  * @param HTMLForm field Form field to find the formatRule function of

	  * @return Format rule function

	  */

	getFormatRule : function(field) {

		var references = FormUtility.getFieldVO(field).getFormatRule().split(".");

		var formatRule = window;

		for (var i=0; i<references.length; i++) {

			if (formatRule[references[i]]) formatRule = formatRule[references[i]];

			else return null;

		}

		return formatRule;

	},

	/** public Array getFieldsByTagName : Get a list of the specified element type in a section.

	  * @param HTMLElement section Form, div, etc. to retrieve fields in

	  * @param String tagName Tag name of element to search for

	  * @return List of elements

	  */

	getFieldsByTagName : function(section, tagName) {

		var fieldsCollection = section.getElementsByTagName(tagName);

		var fieldsArray = [];

		for (var i=0; i<fieldsCollection.length; i++) fieldsArray.push(fieldsCollection[i]);

		return fieldsArray;

	},

	/** public Array getFieldVO : Get a FormFieldVO|GroupFormFieldVO for the specified formField,

	  * lazy loading the initted FieldVOs.

	  * @param HTMLFormField formField Field to wrap in a FieldVO

	  * @return Initialized FieldVO

	  */

	getFieldVO : function(formField) {

		if (!FormUtility.initializedFieldVOs[formField.name]) {

			var form = formField.form;

			var fieldVO = (form[formField.name] == formField) ? new FormFieldVO(formField) : new GroupFormFieldVO(form[formField.name]);

			FormUtility.initializedFieldVOs[formField.name] = fieldVO;

		}

		return FormUtility.initializedFieldVOs[formField.name];

	},

	/** public Array getMissingRequired : Get a list of required fields failing validation in a section.

	  * @param HTMLElement section Form, div, etc. to search for empty required fields in

	  * @return List of empty required fields

	  */

	getMissingRequired : function(section) {

		var requiredFields = FormUtility.getRequiredFields(section);

		var fields = [];

		for (var fieldName in requiredFields) {

			var field = requiredFields[fieldName];

			var className = (field.length && !field.name) ? field[0].className : field.className;

			if ((className.indexOf("disabled") == -1) && !isCompleted(field)) fields.push(field);

		}

		return fields;

	},

	/** public Array getLengthRequired : Get a list of required fields failing validation in a section.

	  * @param HTMLElement section Form, div, etc. to search for 500 length required fields in

	  * @return List of empty required fields

	  */

	getLengthRequired : function(section) {

		var requiredFields = FormUtility.getRequiredFields(section);

		var fields = [];

		for (var fieldName in requiredFields) {

			var field = requiredFields[fieldName];

			var values=field.value.split(",");			

			if(values.length > 500)	fields.push(field);			

		}

		return fields;

	},

	/** public Map getRequiredFields : Get the set of required fields in a section.

	  * @param HTMLElement section Form, div, etc. to search for required fields in

	  * @return List of required fields

	  */

	getRequiredFields : function(section) {

		if (!section) return {};

		if (!FormUtility.sections[section.id]) FormUtility.registerFields(section);

		return FormUtility.sections[section.id]["required"];

	},

	/** public void highlightFields : Highlight specified fields.

	  * @param Array fieldList List of fields to highlight

	  */

	highlightFields : function(fieldList) {

		FormUtility.changeFieldsColor(fieldList, FormUtility.HIGHLIGHT_COLOR);

		FormUtility.highlightedFields = fieldList;

	},

	/** public void colorLabels : Change the color of the label text for the specified fields.

	  * @param Array fieldList List of fields to highlight

	  */

	colorLabels : function(fieldList) {

		FormUtility.changeLabelColor(fieldList, FormUtility.LABEL_COLOR);

		FormUtility.highlightedFields = fieldList;

	},

	/** public void registerFields : Find and lazy load fields in a section, for performance.

	  * @param HTMLElement section Form, div, etc. to register fields in

	  */

	registerFields : function(section) {

		if (section.tagName.toLowerCase() == "form") {

			var allFields = section.elements;

		} else {

			var allFields = FormUtility.getFieldsByTagName(section, "input");

			allFields = allFields.concat(FormUtility.getFieldsByTagName(section, "textarea"));

			allFields = allFields.concat(FormUtility.getFieldsByTagName(section, "select"));

		}

		FormUtility.sections[section.id] = {};

		FormUtility.sections[section.id]["formatted"] = {};

		FormUtility.sections[section.id]["required"] = {};

		for (var i=0; i<allFields.length; i++) {

			if (!allFields[i].name) continue;

			var fieldVO = FormUtility.getFieldVO(allFields[i]);

			if (!FormUtility.sections[section.id]["formatted"][allFields[i].name] && fieldVO.getFormatRule()) FormUtility.sections[section.id]["formatted"][allFields[i].name] = fieldVO.getField();

			if (!FormUtility.sections[section.id]["required"][allFields[i].name] && fieldVO.isRequired()) FormUtility.sections[section.id]["required"][allFields[i].name] = fieldVO.getField();

		}

	},

	/** public void resetErrors : Un-highlight previous error fields and labels, hide error messages, etc.

	  * @param Array errorElements Array of error message HTMLElements

	  */

	resetErrors : function(errorElements, labelType) {

		FormUtility.unHighlightFields();

		if(labelType == "label" || labelType == "both") FormUtility.unHighlightLabels();

		

		FormUtility.highlightedFields = [];

		if (!errorElements) return;

		for (var i=0; i<errorElements.length; i++) {

			if (errorElements[i] && errorElements[i].style) errorElements[i].style.display = "none";

		}

	},

	/** public void unHighlightFields : Un-highlight specified fields.

	  * @param Array fieldList List of fields to un-highlight

	  */

	unHighlightFields : function(fieldList) {

		if (!fieldList) var fieldList = FormUtility.highlightedFields;

		FormUtility.changeFieldsColor(fieldList, "");

	},

	/** public void unHighlightLabels : Un-highlight specified labels.

	  * @param Array fieldList List of fields to un-highlight associated labels

	  */

	unHighlightLabels : function(fieldList) {

		if (!fieldList) var fieldList = FormUtility.highlightedFields;

		FormUtility.changeLabelColor(fieldList, "000000");

	}

};



/** public class FormFieldVO : Wrapper for HTMLFormField elements. Provides an easy way to get

  * custom field attribute values.

  */

FormFieldVO = function(field) {

	this.classType = "FormFieldVO";

	this.field = field;

	return this;

}

/** public HTMLFormField getField : Get this instance's HTML form field.

  * @return HTML form field

  */

FormFieldVO.prototype.getField = function() {return this.field; }

/** public String getFormatRule : Get the value of the form field's "formatRule" attribute, if any.

  * @return Name of format rule

  */

FormFieldVO.prototype.getFormatRule = function() { return (this.field.getAttribute("formatRule") || null); }

/** public Array getGroup : Get all fields by this field's name; e.g. radio array.

  * @return Group field

  */

FormFieldVO.prototype.getGroup = function() {

	var group = this.field.form[this.getName()];

	return group;

}

/** public boolean isRequired : Get the value, or just the existence, of the form field's "required" attribute.

  * @return True if "required" attribute is present, or set to "true"

  */

FormFieldVO.prototype.isRequired = function() { return ((this.field.getAttribute("required") == "") || (this.field.getAttribute("required") == "true")) ? true : false; }

/** public String toString : Useful toString for debugging.

  * @return String representation of this instance

  */

FormFieldVO.prototype.toString = function() {

	return this.classType + ": " + this.field.name + "; required: " + this.isRequired() + "; formatRule: " + this.getFormatRule();

}



/** public class GroupFormFieldVO : Wrapper for grouped HTMLFormField elements, e.g. radio arrays.

  * Provides an easy way to get custom field attribute values.

  */

GroupFormFieldVO = function(groupField) {

	this.classType = "GroupFormFieldVO";

	this.groupField = groupField;

	this.fieldVOs = [];

	for (var i=0; i<this.groupField.length; i++) this.fieldVOs.push(new FormFieldVO(this.groupField[i]));

	return this;

}

/** public HTMLFormField getField : Get this instance's HTML form field group.

  * @return HTML form field group

  */

GroupFormFieldVO.prototype.getField = function(index) { return this.groupField; }

/** public Array getFieldVOs : Get an array of each single field in the group, wrapped in a FormFieldVO.

  * @return Array of FormFieldVOs

  */

GroupFormFieldVO.prototype.getFieldVOs = function(index) { return this.fieldVOs; }

/** public String getFormatRule : Get the value of the 1st single field's "formatRule" attribute, if any.

  * @return Name of format rule, as defined by the 1st field in the group

  */

GroupFormFieldVO.prototype.getFormatRule = function() { return (this.groupField[0].getAttribute("formatRule") || null); }

/** public boolean isRequired : Get the value, or just the existence,

  * of the 1st single field's form field's "required" attribute.

  * @return True if "required" attribute is present, or set to "true", as defined by the 1st field in the group

  */

GroupFormFieldVO.prototype.isRequired = function() { return ((this.groupField[0].getAttribute("required") == "") || (this.groupField[0].getAttribute("required") == "true")) ? true : false; }

/** public String toString : Useful toString for debugging.

  * @return String representation of this instance

  */

GroupFormFieldVO.prototype.toString = function() {

	return this.classType + ": " + this.getField()[0].name + "; required: " + this.isRequired() + "; formatRule: " + this.getFormatRule();

}



/** public boolean isNumeric : Check if string contains only numeric characters.

  * @param String str String to check

  * @return True if string contains only numeric characters

  */

function isNumeric(str) {

	var numberRE = new RegExp("^[" + _VALIDATION_NUMERIC + "]*$");

	return numberRE.test(str);

}

/** public boolean isPercentage : Check if string contains only percentage. 

  * @param String str String to check

  * @return True if string contains only numeric characters

  */

function isPercentage(str) {

	//var percentageRE = /(^(100(?:\.0{1,2})?))|(?!^0*$)(?!^0*\.0*$)^\d{1,2}(\.\d{1,2})?$/;
	var percentageRE = /(^(100(?:\.0{1,2})?))|^\d{1,2}(\.\d{1,2})?$/;

	return percentageRE.test(str);

}

/** public boolean isAlpha : Check if string contains only alphabetic characters.

  * @param String str String to check

  * @return True if string contains only alphabetic characters

  */

function isAlpha(str) {

	var alphaRE = new RegExp("^[" + _VALIDATION_ALPHA + "]*$");

	return alphaRE.test(str);

}



/** public boolean isHexaDecimal : Check if string contains only A-F and 0-9.

  * @param String str String to check

  * @return True if string contains only A-F, a-f and 0-9

  */

function isHexaDecimal(str) {

        return (!_VALIDATION_HEXA.test(str));           	

}

/** public boolean isName : Check if string contains only alphabetic characters and ' used in names.

  * @param String str String to check

  * @return True if string contains only alphabetic characters

  */

function isName(str) {

	var nameRE = new RegExp("^[" + _VALIDATION_NAME + "]*$");

	return nameRE.test(str);

}



/** public boolean isAlphaNumeric : Check if string contains only alphanumeric characters.

  * @param String str String to check

  * @return True if string contains only alphanumeric characters

  */

function isAlphaNumeric(str) {

	var alphanumRE = new RegExp("^[" + _VALIDATION_ALPHANUMERIC + "]*$");

	return alphanumRE.test(str);

}



/** public boolean isStockOrVIN : Check if string contains only alphanumeric characters with out blank chars.

  * @param String str String to check

  * @return True if string contains only alphanumeric characters

  */

function isStockOrVIN(str) {

	var alphanumRE = new RegExp("^[" + _VALIDATION_ALPHANUMERIC_WITHOUT_BLANKCHARS + "]*$");

	return alphanumRE.test(str);

}



/** public boolean isWebID : Check if string contains only alphanumeric characters and hyphen(-).

  * @param String str String to check

  * @return True if string contains only alphanumeric characters and hyphen(-)

  */

function isWebID(str) {

	var alphanumRE = new RegExp("^[" + _VALIDATION_ALPHANUMERIC_WITH_HYPHEN + "]*$");

	return alphanumRE.test(str);

}



/** public boolean hasNoQuotes : Check if string contains no double quotes (").

  * @param String str String to check

  * @return True if string contains no double quotes

  */

function hasNoQuotes(str) { return hasNoCustom(str, "\""); }



/** public boolean hasNoHTML : Check if string contains no HTML characters ("<>).

  * @param String str String to check

  * @return True if string contains no HTML characters

  */

function hasNoHTML(str) { return hasNoCustom(str, "\"<>"); }



/** public boolean hasNoCustom : Check if string contains none of the specified characters

  * @param String str String to check

  * @param String customBadChars Disallowed characters

  * @return True if string contains no custom characters

  */

function hasNoCustom(str, customBadChars) {

	if (!customBadChars) return true;

	var badCharsRE = new RegExp("^[^" + customBadChars + "]*$");

	return badCharsRE.test(str);

}



/** public boolean isAssetName : Check if string meets MAMS asset name requirements.

  * @param String str String to check

  * @return True if string meets MAMS asset name requirements

  */

function isAssetName(str) { return _VALIDATION_ASSETNAME.test(str); }



/** public boolean isLibraryName : Check if string meets MAMS library name requirements.

  * @param String str String to check

  * @return True if string meets MAMS library name requirements

  */

function isLibraryName(str) { return _VALIDATION_LIBRARYNAME.test(str); }



/** public boolean isEmail : Check if string has a valid email address format.

  * @param String str String to check

  * @return True if string has a valid email address format

  */

function isEmail(str) { return _VALIDATION_EMAIL.test(str); }



/** public boolean isAbsoluteUrl : Check if string is an absolute URL. 

  * @param String str String to check

  * @return True if string is an absolute url

  */

function isAbsoluteUrl(str) {

	var protocolRE = /^[a-z]+:(\/\/)?/i;

	return protocolRE.test(str);

}



/** public boolean isSitePageUrl : Check if string is a site page or an external url. 

  * @param String str String to check

  * @return True if string does not contain any "." chars

  */

function isSitePageUrl(str) {

	return (str.indexOf(".") == -1) ? true : false;

}



/** public boolean isPhoneFax : Check if string has a valid phone/fax format (includes alpha chars).

  * @param String str String to check

  * @return True if string has a valid phone/fax format

  */

function isPhoneFax(str) { return _VALIDATION_PHONEFAX.test(str); }



/** public boolean isPhoneFax : Check if string has a valid phone/fax format (doesn't include alpha chars).

  * @param String str String to check

  * @return True if string has a valid phone/fax format

  */

function isNumericPhoneFax(str) { return _VALIDATION_NUMERIC_PHONEFAX.test(str); }



/** public boolean isZip : Check if string has a valid zip format.

  * @param String str String to check

  * @return True if string has a valid zip format

  */

function isZip(str) { return _VALIDATION_ZIP.test(str); }



/** public boolean isFreeformDate : Check if string has a valid date format, e.g. mm/dd/yyyy.

  * @param String str String to check

  * @return True if string has a valid date format

  */

var strGlobalDate = null;

function isFreeformDate(str) { 

	strGlobalDate = str;

	return _VALIDATION_DATE.test(str); 

}



function isValidEndDate(str) {

	convertedGlobalDate = new Date(strGlobalDate);

	convertedGlobalDate = convertedGlobalDate.toLocaleDateString();

	localizedGlobalDate = new Date(convertedGlobalDate);

	startDateMilliseconds = localizedGlobalDate.getTime();

	endDate = new Date(str);

	endDate = endDate.toLocaleDateString();

	localizedEndDate = new Date(endDate);

	endDateMilliseconds = localizedEndDate.getTime();

	if(startDateMilliseconds > endDateMilliseconds) return false;

	if(isFreeformDate(str)) return true;

}



/** public boolean isYear : Check if year is valid.

  * @param String str Year to check

  * @return True if string is a valid year

  */



function isYear(str) {

	var _allyears = new RegExp("^" + _VALIDATION_DATE_ALLYEARS + "?$");

	return _allyears.test(str);

}



/** public boolean isAddress : Check if string contains only valid address characters.

  * @param String str String to check

  * @return True if string contains valid characters

  */

function isAddress(str) { return _VALIDATION_ADDRESS.test(str); }



/** public boolean isMoney : Check if string contains only valid monetary characters.

  * @param String str String to check

  * @return True if string contains valid characters

  */

function isMoney(str) { return _VALIDATION_MONEY.test(str); }



/** public boolean isCity : Check if string contains only valid city characters.

  * @param String str String to check

  * @return True if string contains valid characters

  */

function isCity(str) { return _VALIDATION_CITY.test(str); }



/** public boolean isOdometer : Check if string contains only valid odometer characters.

  * @param String str String to check

  * @return True if string contains valid characters

  */

function isOdometer(str) { return _VALIDATION_ODOMETER.test(str); }



/** public boolean isLatLong : Check if string contains only valid latitude/longitude characters.

  * @param String str String to check

  * @return True if string contains valid characters

  */

function isLatLong(str) { return _VALIDATION_LATLONG.test(str); }



/** public boolean isCCNumber : Check if string has valid credit card number format.

  * @param String str String to check

  * @return True if string has valid format

  */

function isCCNumber(str) { return _VALIDATION_CREDITCARDNUMBER.test(str); }



/** public boolean isSSNumber : Check if string has valid social security number format.

  * @param String str String to check

  * @return True if string has valid format

  */

function isSSNumber(str) { return _VALIDATION_SSN.test(str); }



/** public boolean isSSNumber : Check if string has no special characters except ". and _" 

  * @param String str String to check

  * @return True if string has valid format

  */

function isTrackingVendor(str) { return _VALIDATION_VENDOR.test(str); }



/** public boolean isSSNumber : Check if string has no special characters except ". and _" and blankspaces 

  * @param String str String to check

  * @return True if string has valid format

  */

function isTrackingFields(str) { return _VALIDATION_TRACKINGFIELDS.test(str); }



/** public boolean isCompleted : Check if field has a value entered/selected.

  * @param HTMLFormField field Field to check

  * @return True if field has been completed

  */

function isCompleted(field) {

	if (!field.type && field.length && field.className) return isSelected(field);

	switch (field.type) {

		case "text": case "textfield": case "textarea": case "password": case "file": case "hidden": return (isEmpty(field.value)) ? false : true;

		case "checkbox": case "radio": return (isChecked(field)) ? true : false;

		case "select-one": return (!isEmpty(field.value)) ? true : false;

		case "select-multiple": return (field.options.length) ? true : false;

		default: return true;

	}

}



/** public boolean isEmpty : Check if a string is empty or contains only whitespace chars.

  * @param String str String to check

  * @return True if string is empty

  */

function isEmpty(str) {

	if (str == "") return true;

	var emptyRE = new RegExp("^[" + _VALIDATION_BLANKCHARS + "]*$");

	return emptyRE.test(str);

}



/** public boolean isSelected : Check if a grouped HTML form field has a selected value.

  * @param HTMLFormField field Field to check

  * @return True if field has a selected value

  */

function isSelected(thisSelect, defaultValue) {

	if (arguments.length == 1) var defaultValue = "";

	var currentSelection = getSelected(thisSelect);

	if (!currentSelection || (currentSelection.value == null)) return false;

	else return (currentSelection.value != defaultValue);

}



/** public boolean isChecked : Check if a grouped HTML form field has a checked selection.

  * @param HTMLFormField field Field to check

  * @return True if field has a checked selection

  */

function isChecked(checkObj) { return (getSelected(checkObj)) ? true : false; }



/** public boolean checkMaxLength : Check if a textarea's value is longer than its 'maxlength' attribute.

  * Truncates value if so. Should be called onKeyUp.

  * @param Event e Textfield's keyup event

  * @param HTMLFormField textarea Textarea to check

  * @return True if keyup event should be allowed

  */

function checkMaxLength(e, textarea) {

	var maxLength = parseInt(textarea.getAttribute("maxlength"));

	if ((e.keyCode < 48) && (e.keyCode != 32)) return true;

	if (textarea.value.length == maxLength) return false;

	if (textarea.value.length > maxLength) {

		textarea.value = textarea.value.substring(0, maxLength);

		return false;

	}

	return true;

}



/** public Map getSelected : Get a map of the selected index and value of the specified element.

  * Format: result.index; result.value

  * @param HTMLFormField thiselement Field to get selection of

  * @return Map of field's selection

  */

function getSelected(thiselement) {

	if (thiselement.type == "select-one") {

		var ind = thiselement.selectedIndex;

		if (ind >= 0) return {"index":ind, "value":thiselement.options[ind].value}

	}

	if (thiselement.length) {

		var isCheckbox = (thiselement[0].type == "checkbox") ? true : false;

		var values = new Array();

		var indexes = new Array();

		for (var i=0; i<thiselement.length; i++) {

			if (thiselement[i].checked && !isCheckbox) return {"index":i, "value":thiselement[i].value};

			if (thiselement[i].checked && isCheckbox) {

				values[values.length] = thiselement[i].value;

				indexes[indexes.length] = i;

			}

		}

		if (isCheckbox) {

			if (indexes.length) return {"index":indexes, "value":values};

			else return {"index":null, "value":null};

		}

	} else {

		if (thiselement.checked) return {"index":0, "value":thiselement.value};

	}

	return false;

}



/** public void setSelected : Set the specified group field's selection to the specified value.

  * @param HTMLFormField thiselement Field to set selection of

  * @param String selectvalue Value to select

  */

function setSelected(thiselement, selectvalue) {

	var thiscoll = (thiselement.type == "select-one") ? thiselement.options : thiselement;

	var checkedProperty = (thiselement.type == "select-one") ? "selected" : "checked";

	if (arguments.length == 1) {

		thiselement[0][checkedProperty] = true;

	} else {

		if (thiscoll.length) {

			for (var i=0; i<thiscoll.length; i++) {

				if (thiscoll[i].value == selectvalue) {

					thiscoll[i][checkedProperty] = true;

					break;

				}

			}

		} else {

			if (thiscoll.value == selectvalue) thiscoll[checkedProperty] = true;

			else thiscoll[checkedProperty] = false;

		}

	}

}



/** public void setDisabledStatus : Make a textfield or textarea appear disabled.

  * Blanks the field when disabled, but stores the value and repopulates it when enabled.

  * @param boolean isEnabled True if field should be "enabled"

  * @param HTMLFormField targetElem Field to change state

  */

function setDisabledStatus(isEnabled, targetElem) {

	if (targetElem.disabled) return;

	if (targetElem.value != undefined) {

		// storing currentValue for the first time, or disabling field

		if (!targetElem.getAttribute("currentValue") || !isEnabled) targetElem.setAttribute("currentValue", targetElem.value);

		// set value to stored currentValue if enabled, or "" if disabled

		targetElem.value = (isEnabled) ? targetElem.getAttribute("currentValue") : "";

	}	

	targetElem.className = (isEnabled) ? "" : "disabled";

	targetElem.onfocus = (isEnabled) ? null : function() { emulateDisabled(this); }

}



/** public String capitalize : Capitalize this string instance.

  * @return Capitalized string

  */

String.prototype.capitalize = function() { return this.replace(/^([a-z])/, function(letter) { return letter.toUpperCase(); }); }



function deployFreeformDate(someForm, dateFieldHash) {

	var freeformDateRE = new RegExp("^([0-9]{2})" + _VALIDATION_DATE_DL + "([0-9]{2})" + _VALIDATION_DATE_DL + "([0-9]{4})$");	

	for (var freeformField in dateFieldHash) {

		if (!someForm[freeformField]) return;

		freeformDateRE.exec(someForm[freeformField].value);

		for (var i=0; i<_VALIDATION_DATE_ORDER.length; i++) {		

			if (someForm[dateFieldHash[freeformField][_VALIDATION_DATE_ORDER[i]]]) someForm[dateFieldHash[freeformField][_VALIDATION_DATE_ORDER[i]]].value = eval("RegExp.$" + (i+1));



		}

	}

}

  