//YAHOO.util.Event.addListener( window, 'load', function( e ) /* ~750ms for this call */
YAHOO.util.Event.onDOMReady( function( e ) /* ~750ms for this call */
{
	//var myLogReader = new YAHOO.widget.LogReader( 'log' ); 
	YAHOO.util.Event.addListener( Ext.query( 'button[type="reset"]' ), 'click', function( e )
	{
		YAHOO.util.Dom.removeClass( Ext.query( 'div.fieldset.validate.info' ), 'info' );
		YAHOO.util.Dom.removeClass( Ext.query( 'div.fieldset.validate.warning' ), 'warning' );
		YAHOO.util.Dom.removeClass( Ext.query( 'div.fieldset.validate.error' ), 'error' );
		YAHOO.UP.util.hide( Ext.query( 'div.note.validate.shown' ) );
		YAHOO.UP.util.hide( Ext.query( 'div.result' ) );

		var myForm = YAHOO.UP.form.getForm( this );
		YAHOO.util.Dom.removeClass( myForm, 'submitted' );
		YAHOO.util.Dom.removeClass( YAHOO.util.Dom.getElementsByClassName( 'showOnNonHeavyEvent', myForm ), 'showOnNonHeavyEvent' );
		YAHOO.util.Dom.removeClass( YAHOO.util.Dom.getElementsByClassName( 'currentlyValid', myForm ), 'currentlyValid' );

		YAHOO.UP.events.fire( 'form-reset-' + myForm.getAttribute( 'id' ) );
		YAHOO.UP.events.fire( 'form-resetall' );
		//YAHOO.util.Dom.removeClass( YAHOO.util.Dom.getElementsByClassName( 'allFieldsValid', myForm ), 'allFieldsValid' );
	} );

	/* check if the input is valid on submit */
	YAHOO.util.Event.addListener( document.getElementsByTagName( 'form' ), 'submit', function( e )
	{
		/* console.log( e ); */
		if( e ) YAHOO.util.Event.stopEvent( e );

		if( !YAHOO.UP.validation.validate() )
		{
			YAHOO.UP.util.hide( Ext.query( 'div.result' ) );
			YAHOO.UP.util.show( YAHOO.util.Dom.get( 'failureMessage' ) );
			YAHOO.util.Dom.addClass( this, 'submitted' );
			YAHOO.UP.events.fire( 'form-error-' + this.getAttribute( 'id' ) );
			YAHOO.UP.events.fire( 'form-errorall' );
			YAHOO.UP.validation.updateProgress.call( this );
		} else {
			YAHOO.UP.util.hide( Ext.query( 'div.result' ) );
			YAHOO.UP.events.fire( 'form-send-' + this.getAttribute( 'id' ) );
			YAHOO.UP.events.fire( 'form-sendall' );
			//YAHOO.UP.util.show( YAHOO.util.Dom.get( 'inProgressMessage' ) );
		}
		return false;
	} );

	/* enable javascript button (disabled by default, otherwise would be able to submit form before javascript loads (and validations) */
	YAHOO.UP.util.each( Ext.query( 'button[type="submit"].disabled' ), function( j, element )
	{
		//if( element.getAttribute( 'disabled' ) ) element.removeAttribute( 'disabled' );
		YAHOO.UP.form.enable( element );
	} );

	// generic adds both light and heavy listeners.
	// light listeners are delta events inside form elements (keyup, click, etc)
	// heavy listeners are fired when the user is done with a form element (blur, change, etc)
	// medium listeners are heavy listeners with light listeners for those elements that are clicked instead of typed into.

	//YAHOO.UP.validation.addGenericListener( YAHOO.UP.form.getAllElements(), YAHOO.UP.validation.updateProgress );
	YAHOO.UP.validation.addMediumListener( YAHOO.UP.form.getAllElements(), YAHOO.UP.validation.updateProgress, function( element )
	{
		return YAHOO.UP.form.getForm( element );
	}, true );

	/* add the listeners to the form to do validation */
	var validatedDivs = Ext.query( 'div.fieldset.validate' );
	for( var j = 0; j < validatedDivs.length; j++ )
	{
		YAHOO.UP.validation.addListenersToDiv( validatedDivs[ j ] );
	}

	YAHOO.UP.validation.addListenersToAll( YAHOO.UP.form.getAllElements() );

	/* add the quick link modifiers for dates, now, +1h, etc */
	YAHOO.UP.util.each( Ext.query( 'div.note.quickLinks' ), function( i, obj )
	{
		if( document.getElementById( obj.getAttribute( 'valdi:id_date' ) ) || document.getElementById( obj.getAttribute( 'valdi:id_time' ) ) || document.getElementById( obj.getAttribute( 'valdi:id_timeZone' ) ) )
		{
			YAHOO.UP.util.each( Ext.query( 'a', obj ), function( j, linkObj )
			{
				var arg = {
					date: ( obj.getAttribute( 'valdi:id_date' ) ? document.getElementById( obj.getAttribute( 'valdi:id_date' ) ) : null ),
					time: ( obj.getAttribute( 'valdi:id_time' ) ? document.getElementById( obj.getAttribute( 'valdi:id_time' ) ) : null ),
					zone: ( obj.getAttribute( 'valdi:id_timeZone' ) ? document.getElementById( obj.getAttribute( 'valdi:id_timeZone' ) ) : null ),
					minutes: ( linkObj.getAttribute( 'valdi:modifyMinutes' ) ? YAHOO.UP.util.Math.parseInt( linkObj.getAttribute( 'valdi:modifyMinutes' ) ) : 0 ),
					dateOverride: ( linkObj.getAttribute( 'valdi:overrideDate' ) ? linkObj.getAttribute( 'valdi:overrideDate' ) : '' ),
					timeOverride: ( linkObj.getAttribute( 'valdi:overrideTime' ) ? linkObj.getAttribute( 'valdi:overrideTime' ) : '' ),
					timeZoneOverride: ( linkObj.getAttribute( 'valdi:overrideTimeZone' ) ? linkObj.getAttribute( 'valdi:overrideTimeZone' ) : '' )
				};
				YAHOO.util.Event.addListener( linkObj, 'click', YAHOO.UP.form.quickDateModify, arg );
			} );
		}
	} );

	YAHOO.util.Event.addListener( Ext.query( 'input.textbox[valdi:modify="toUpperCase"]' ), 'blur', function( e )
	{
		if( !YAHOO.UP.validation.isWhiteListed( this, e, true ) )
		{
			this.value = this.value.toUpperCase();
		}
	} );
	YAHOO.util.Event.addListener( Ext.query( 'input.textbox[valdi:modify="toUpperCase"]' ), 'keypress', function( e )
	{
		/* var newCharCode = (String.fromCharCode( YAHOO.util.Event.getCharCode( e ))).toUpperCase().charCodeAt(0);
		return YAHOO.util.Event.setCharCode( newCharCode ); */

		// this is IE only code :(
		try {
			var key = window.event.keyCode;
			if ((key > 0x60) && (key < 0x7B)) window.event.keyCode = key-0x20;
		} catch(e) {}
	} );
	// TODO: doesn't support negative values yet
	YAHOO.util.Event.addListener( Ext.query( 'input.textbox[valdi:modify="numericOnly"]' ), 'blur', function( e )
	{
		if( !YAHOO.UP.validation.isWhiteListed( this, e, true ) )
		{
			this.value = this.value.replace( /[^(0-9)]/g, '' );
		}
	} );
	// TODO: doesn't support negative values yet
	YAHOO.util.Event.addListener( Ext.query( 'input.textbox[valdi:modify="numericOnly"]' ), 'keypress', function( e )
	{
		var code = YAHOO.util.Event.getCharCode( e );
		if( ( code > 57 || code < 48 ) && YAHOO.UP.util.keyboard.isDisplayKey( e ) )
		{
			YAHOO.util.Event.stopEvent( e );
		}
	} );

	// enter key submits on text inputs?
	/* YAHOO.UP.util.each( document.getElementsByTagName( 'form' ), function( j, formObj )
	{
		if( formObj.getAttribute( 'valdi:enterKeySubmits' ) == 'false' )
		{
			YAHOO.util.Event.addListener( Ext.query( 'input[type="text"]', formObj ), 'keypress', function( e )
			{
				if( YAHOO.util.Event.getCharCode( e ) == 13 )
				{
					YAHOO.util.Event.preventDefault( e );
				}
			} );
		}
	} ); */

	YAHOO.util.Event.addListener( window, 'unload', YAHOO.UP.cache.clear );
} );

YAHOO.namespace( 'UP.validation' );
// returns a boolean indicating whether to cancel the action
YAHOO.UP.validation.validate = function( groupId, root )
{
	var stopSubmit = false;
	var validatedDivs;
	if( groupId == null )
		validatedDivs = Ext.query( 'div.fieldset.validate', root );
	else
		validatedDivs = Ext.query( 'div.fieldset.validate[valdi:validateGroup="' + groupId + '"]', root );

	for( var j = 0; j < validatedDivs.length; j++ )
	{
		// this code was used to not include validateGroup's in the global validate function.
		//if( groupId != null || ( groupId == null && validatedDivs[ j ].getAttribute( 'valdi:validateGroup' ) == null ) )
		var validationNotes = YAHOO.UP.validation.getAllNotes( validatedDivs[ j ] );
		YAHOO.UP.util.each( validationNotes, function( i, obj )
		{
			var elements = YAHOO.UP.validation.getAllElementsForNote( validatedDivs[ j ], obj );
			if( obj.getAttribute( 'valdi:type' ) )
			{
				var checkFunction;
				if( obj.getAttribute( 'valdi:supptype' ) )
				{
					checkFunction = YAHOO.UP.validation.getValidationFunction( obj.getAttribute( 'valdi:supptype' ), obj.getAttribute( 'valdi:namespace' ) );
				} else {
					checkFunction = YAHOO.UP.validation.getValidationFunction( obj.getAttribute( 'valdi:type' ), obj.getAttribute( 'valdi:namespace' ) );
				}
				YAHOO.UP.util.each( elements, function( j, formElement )
				{
					if( !checkFunction( formElement ) ) stopSubmit = true;
				} );
			}
		} );
	}
	return !stopSubmit;
};

/* YAHOO.UP.validation.resetGroup = function( groupId )
{
	YAHOO.UP.util.each( Ext.query( 'div.fieldset.validate[valdi:validateGroup="' + groupId + '"]' ), function( j, divElement )
	{
		YAHOO.util.Dom.removeClass( divElement, 'validate' );
		YAHOO.util.Dom.removeClass( divElement, 'error' );
		YAHOO.util.Dom.removeClass( divElement, 'warning' );
		YAHOO.util.Dom.removeClass( divElement, 'info' );
		YAHOO.UP.util.hide( Ext.query( 'div.note', divElement ) );

		YAHOO.util.Dom.removeClass( YAHOO.util.Dom.getElementsByClassName( 'showOnNonHeavyEvent', divElement ), 'showOnNonHeavyEvent' );
		YAHOO.util.Dom.removeClass( YAHOO.util.Dom.getElementsByClassName( 'currentlyValid', divElement ), 'currentlyValid' );		
	} );
}; */
YAHOO.UP.validation.setValidateOn = function( divElement )
{
	if( !YAHOO.util.Dom.hasClass( divElement, 'validate' ) ) YAHOO.util.Dom.addClass( divElement, 'validate' );
	YAHOO.UP.validation.addListenersToDiv( divElement );
};
YAHOO.UP.validation.setValidateOff = function( divElement )
{
	YAHOO.UP.validation.removeListenersFromDiv( divElement );
	YAHOO.util.Dom.removeClass( divElement, 'validate' );
	YAHOO.util.Dom.removeClass( divElement, 'error' );
	YAHOO.util.Dom.removeClass( divElement, 'warning' );
	YAHOO.util.Dom.removeClass( divElement, 'info' );
	YAHOO.UP.util.hide( Ext.query( 'div.note', divElement ) );
};
YAHOO.UP.validation.isWhiteListed = function( formElement, event, bDontValidateAfterSubmit )
{
	if( bDontValidateAfterSubmit == null )
		bDontValidateAfterSubmit = !YAHOO.util.Dom.hasClass( YAHOO.UP.form.getForm( formElement ), 'submitted' );

	var value = YAHOO.UP.form.getValue( formElement );
	var whiteList = formElement.getAttribute( 'valdi:whiteList' );
	if( whiteList != null )
	{
		var aWhiteList = whiteList.split( '|' );
		for( var j = 0; j < aWhiteList.length; j++ )
			if( aWhiteList[ j ] == value ) return true;
	}

	return event != null && YAHOO.UP.validation.isPassiveWhiteListed( formElement, event ) && bDontValidateAfterSubmit;
};
YAHOO.UP.validation.isPassiveWhiteListed = function( formElement, event )
{
	var value = YAHOO.UP.form.getValue( formElement );
	var passiveWhiteList = formElement.getAttribute( 'valdi:passiveWhiteList' );
	if( passiveWhiteList != null )
	{
		var aWhiteList = passiveWhiteList.split( '|' );
		for( var j = 0; j < aWhiteList.length; j++ )
			if( aWhiteList[ j ] == value ) return true;
	}
	return false;
};
YAHOO.UP.validation.addListenersToAll = function( elements )
{
	// provides a slightly darker background on focus.
	YAHOO.util.Event.addListener( elements, 'focus', function( e )
	{
		var formElement = YAHOO.UP.form.getElement( this );
		var parentDiv = YAHOO.UP.form.getParentDivElement( formElement );
		//YAHOO.util.Dom.removeClass( Ext.query( 'div.focused' ), 'focused' );
		if( !YAHOO.util.Dom.hasClass( parentDiv, 'focused' ) )
		{
			YAHOO.util.Dom.addClass( parentDiv, 'focused' );
		}
	} );
	YAHOO.util.Event.addListener( elements, 'blur', function( e )
	{
		var formElement = YAHOO.UP.form.getElement( this );
		var parentDiv = YAHOO.UP.form.getParentDivElement( formElement );
		YAHOO.util.Dom.removeClass( parentDiv, 'focused' );
	} );
};
YAHOO.UP.validation.addListenersToDiv = function( divElement )
{
	var validationNotes = YAHOO.UP.validation.getAllNotes( divElement );
	YAHOO.UP.util.each( validationNotes, function( i, obj ) {
		// local function
		var addListeners = YAHOO.UP.validation.getAddListenerFunction( obj.getAttribute( 'valdi:supptype' ) ? obj.getAttribute( 'valdi:supptype' ) : obj.getAttribute( 'valdi:type' ), obj.getAttribute( 'valdi:namespace' ) );
		addListeners( obj, YAHOO.UP.validation.getAllElementsForNote( divElement, obj ) );
	} );
};
YAHOO.UP.validation.removeListenersFromDiv = function( divElement )
{
	// we're removing all listeners, then adding the defaults.
	var elements = YAHOO.UP.form.getAllElements( divElement );
	YAHOO.UP.util.each( elements, function( j, formElement )
	{
		var myClass = YAHOO.UP.form.getClass( formElement );
		var lightEvent = myClass.getEventType();
		if( lightEvent ) YAHOO.util.Event.removeListener( formElement, lightEvent );
		var heavyEvent = myClass.getHeavyEventType();
		if( heavyEvent ) YAHOO.util.Event.removeListener( formElement, heavyEvent );
	} );
	YAHOO.UP.validation.addListenersToAll( elements );
};
YAHOO.UP.validation.isValid = function( /* Wrapped Html Form Element */formElement )
{
	var isValid = true;
	// only execute those listener events which are classified as 'heavy' events for those form elements.
	if( formElement instanceof Array )
	{
		YAHOO.UP.util.each( formElement, function( j, obj )
		{
			YAHOO.UP.util.each( YAHOO.util.Event.getListeners( obj ), function( k, listener )
			{
				if( listener.type == YAHOO.UP.form.getClass( formElement ).getHeavyEventType() && listener.fn.apply( listener.adjust/* obj */ ) == false ) // if function doesn't return a boolean value, it isn't applicable to our check
				{
					isValid = false;
				}
			} );
		} );
	} else {
		YAHOO.UP.util.each( YAHOO.util.Event.getListeners( formElement ), function( j, listener )
		{
			if( listener.type == YAHOO.UP.form.getClass( formElement ).getHeavyEventType() && listener.fn.apply( listener.adjust/* formElement */ ) == false ) // if function doesn't return a boolean value, it isn't applicable to our check
			{
				isValid = false;
			}
		} );
	}
	return isValid;
};
/* override is the Boolean test that we want to use as a return value if we don't want to use the form element validators */
YAHOO.UP.validation.setValue = function( /* Wrapped Html Form Element */formElement, newValue, /* Boolean */ignoreValidators, /*Boolean */ override )
{
	if( ignoreValidators == null ) ignoreValidators = false;
	if( override == null ) override = true;

	YAHOO.UP.form.setValue( formElement, newValue );
	if( ignoreValidators ) return override;

	return YAHOO.UP.validation.isValid( formElement );
};
YAHOO.UP.validation.getAddListenerFunction = function( /* String */ shortName, validationNameSpace )
{
	if( validationNameSpace == null ) validationNameSpace = '';
	else validationNameSpace += '.';
	return YAHOO.UP.util.getFunction( 'YAHOO.UP.validation.' + validationNameSpace + 'add' + shortName.substr( 0, 1 ).toUpperCase() + shortName.substr( 1 ) + 'Listener' );
};
YAHOO.UP.validation.getValidationFunction = function( /* String */ shortName, validationNameSpace )
{
	if( validationNameSpace == null ) validationNameSpace = '';
	else validationNameSpace += '.';
	return YAHOO.UP.util.getFunction( 'YAHOO.UP.validation.' + validationNameSpace + 'is' + shortName.substr( 0, 1 ).toUpperCase() + shortName.substr( 1 ) );
};
YAHOO.UP.validation.getNoteSeverity = function( /* Note Div Element */noteElement )
{
	return noteElement.getAttribute( 'valdi:priority' ) ? noteElement.getAttribute( 'valdi:priority' ) : 'error';
};
YAHOO.UP.validation.getAllNotes = function( /* Parent Div Element */divElement )
{
	return Ext.query( 'div.note.validate', divElement );
};
YAHOO.UP.validation.getNote = function( /* Parent Div Element */divElement, /* Wrapped Html Form Element */formElement, type )
{
	var allNotes = YAHOO.UP.validation.getAllNotesForElement( divElement, formElement );
	for( var j = 0; j < allNotes.length; j++ )
	{
		if( allNotes[ j ].getAttribute( 'valdi:type' ).indexOf( type ) > -1 )
		{
			return allNotes[ j ];
		}
	}
	//throw new Error( 'Could not find specific note in getNote() for ' + type );
};
YAHOO.UP.validation.getAllNotesForElement = function( /* Parent Div Element */divElement, /* Wrapped Html Form Element */formElement )
{
	var queryString = YAHOO.UP.util.String.each( 'div.note[valdi:id=*]', formElement, function( i, obj )
	{
		return ', div.note[valdi:id=\'' + obj.getAttribute( 'id' ) + '\']';
	} );
	//console.log( formElement, Ext.query( queryString, divElement ) );
	return Ext.query( queryString, divElement );
};
YAHOO.UP.validation.getAllElementsForNote = function( /* Parent Div Element */divElement, /* Note Div Element */noteElement )
{
	if( !noteElement ) return [];

	var validation_id = noteElement.getAttribute( 'valdi:id' );
	var allElements = YAHOO.UP.form.getAllElements( divElement );
	if( validation_id && validation_id == '*' )
	{
		return allElements;
	} else if( validation_id ) {
		var elements = [];
		for( var j = 0; j < allElements.length; j++ )
		{
			if( ( validation_id + ' ' ).indexOf( allElements[ j ].getAttribute( 'id' ) + ' ' ) > -1 )
			{
				elements.push( allElements[ j ] );
			}
		}
		return elements;
	}
};
YAHOO.UP.validation.addLightListener = function( elements, callback, /* Function or Object */scope, /* Boolean */changeScope )
{
	YAHOO.UP.util.each( elements, function( j, formElement )
	{
		var newObject = null;
		if( changeScope == null ) changeScope = false;
		if( YAHOO.lang.isFunction( scope ) && scope != null ) newObject = scope( formElement );
		else if( scope != null ) newObject = scope;

		var lightEvent = YAHOO.UP.form.getClass( formElement ).getEventType();
		if( lightEvent ) YAHOO.util.Event.addListener( formElement, lightEvent, callback, newObject, changeScope );
	} );
};
YAHOO.UP.validation.addMediumListener = function( elements, callback, /* Function or Object */scope, /* Boolean */changeScope )
{
	YAHOO.UP.util.each( elements, function( j, formElement )
	{
		var newObject = null;
		if( changeScope == null ) changeScope = false;
		if( YAHOO.lang.isFunction( scope ) && scope != null ) newObject = scope( formElement );
		else if( scope != null ) newObject = scope;

		var myClass = YAHOO.UP.form.getClass( formElement );
		if( !myClass.isDeltaElement() )
		{
			var lightEvent = myClass.getEventType();
			if( lightEvent ) YAHOO.util.Event.addListener( formElement, lightEvent, callback, newObject, changeScope );
		} else {
			var heavyEvent = myClass.getHeavyEventType();
			if( heavyEvent ) YAHOO.util.Event.addListener( formElement, heavyEvent, callback, newObject, changeScope );
		}
	} );
};
YAHOO.UP.validation.addHeavyListener = function( elements, callback, /* Function or Object */scope, /* Boolean */changeScope )
{
	YAHOO.UP.util.each( elements, function( j, formElement )
	{
		var newObject = null;
		if( changeScope == null ) changeScope = false;
		if( YAHOO.lang.isFunction( scope ) && scope != null ) newObject = scope( formElement );
		else if( scope != null ) newObject = scope;

		var heavyEvent = YAHOO.UP.form.getClass( formElement ).getHeavyEventType();
		if( heavyEvent ) YAHOO.util.Event.addListener( formElement, heavyEvent, callback, newObject, changeScope );
	} );
};
YAHOO.UP.validation.addGenericListener = function( elements, callback, /* Function or Object */scope, /* Boolean */changeScope )
{
	YAHOO.UP.util.each( elements, function( j, formElement )
	{
		var newObject = null;
		if( changeScope == null ) changeScope = false;
		if( YAHOO.lang.isFunction( scope ) && scope != null ) newObject = scope( formElement );
		else if( scope != null ) newObject = scope;

		var heavyEvent = YAHOO.UP.form.getClass( formElement ).getHeavyEventType();
		if( heavyEvent ) YAHOO.util.Event.addListener( formElement, heavyEvent, callback, newObject, changeScope );

		var lightEvent = YAHOO.UP.form.getClass( formElement ).getEventType();
		if( lightEvent ) YAHOO.util.Event.addListener( formElement, lightEvent, callback, newObject, changeScope );
	} );
};
/* YAHOO.UP.validation.hasError = function( parentDiv )
{
	return YAHOO.util.Dom.hasClass( parentDiv, 'error' ) || YAHOO.util.Dom.hasClass( parentDiv, 'warning' ) || YAHOO.util.Dom.hasClass( parentDiv, 'info' );
}; */
YAHOO.UP.validation.addNotEmptyListener = function( note, elements )
{
	YAHOO.UP.validation.addGenericListener( elements, YAHOO.UP.validation.isNotEmptyEvent );
};
YAHOO.UP.validation.isNotEmptyEvent = function( e )
{
	var returnValue = YAHOO.UP.validation.isNotEmpty( YAHOO.UP.form.getElement( this ), e );
	// return (false) statement was causing a bug in IE 6 that wouldn't allow unchecking of a single checkbox
	if( !YAHOO.UP.form.isRadio( this ) && !YAHOO.UP.form.isCheckBox( this ) )
	{
		return returnValue;
	}
};
YAHOO.UP.validation.isNotEmpty = function( /* Wrapped Html Form Element */formElement, event )
{
	return YAHOO.UP.validation.execute( formElement, 'notEmpty', event, YAHOO.UP.validation.checkNotEmpty );
};
YAHOO.UP.validation.checkEmpty = function( formElement, event )
{
	return !YAHOO.UP.validation.checkNotEmpty( formElement, event );
};
YAHOO.UP.validation.checkNotEmpty = function( formElement, event )
{
	var value = YAHOO.UP.form.getValue( formElement );
	return YAHOO.UP.validation.rawNotEmpty( value );
};
YAHOO.UP.validation.rawEmpty = function( value )
{
	return !YAHOO.UP.validation.rawNotEmpty( value );
}
YAHOO.UP.validation.rawNotEmpty = function( value )
{
	return value && value != '' && value != [] && value != [''] && value.length > 0;
};
YAHOO.UP.validation.addNotEqualToListener = function( note, elements )
{
	YAHOO.UP.validation.addGenericListener( elements, YAHOO.UP.validation.isNotEqualToEvent );
};
YAHOO.UP.validation.isNotEqualToEvent = function( e )
{
	return YAHOO.UP.validation.isNotEqualTo( YAHOO.UP.form.getElement( this ), e );
};
YAHOO.UP.validation.isNotEqualTo = function( /* Wrapped Html Form Element */formElement, event )
{
	if( YAHOO.UP.validation.isWhiteListed( formElement, event ) )
	{
		return YAHOO.UP.validation.execute( formElement, 'notEqualTo', event, function() { return true; } );
	} else {
		return YAHOO.UP.validation.execute( formElement, 'notEqualTo', event, function( formElement, event )
		{
			var divElement = YAHOO.UP.form.getParentDivElement( formElement );
			var note = YAHOO.UP.validation.getNote( divElement, formElement, 'notEqualTo' );

			var isValid = true;
			var targetIds = note.getAttribute( 'valdi:id_target' );
			if( !YAHOO.UP.validation.isPassiveWhiteListed( formElement, event ) && targetIds )
			{
				YAHOO.UP.util.each( targetIds.split( ' ' ), function( j, str )
				{
					if( YAHOO.UP.validation.checkNotEmpty( formElement ) )
					{
						var value = YAHOO.UP.form.getValue( formElement );
						var comparisonValue = YAHOO.UP.form.getAvailableValueRaw( document.getElementById( str ) );
						var isValueArray = YAHOO.lang.isArray( value );
						var isCompareArray = YAHOO.lang.isArray( comparisonValue );
						if( YAHOO.UP.util.Math.XOR( isValueArray, isCompareArray ) )
						{
							if( YAHOO.UP.util.Array.hasValue( value, comparisonValue ) ) isValid = false;
						} else { // both arrays or both not arrays.
							if( comparisonValue == value ) isValid = false;
						}
					}
				} );
			}
			return isValid;
		} );
	}
};
YAHOO.UP.validation.addTimeListener = function( note, elements )
{
	YAHOO.UP.validation.addGenericListener( elements, YAHOO.UP.validation.isTimeEvent );
};
YAHOO.UP.validation.isTimeEvent = function( e )
{
	return YAHOO.UP.validation.isTime( YAHOO.UP.form.getElement( this ), e );
};
YAHOO.UP.validation.isTime = function( /* Wrapped Html Form Element */formElement, event )
{
	if( YAHOO.UP.validation.isWhiteListed( formElement, event ) )
	{
		return YAHOO.UP.validation.execute( formElement, 'time', event, function() { return true; } );
	} else {
		return YAHOO.UP.validation.execute( formElement, 'time', event, function( formElement, event )
		{
			// normalize when minutes are fully typed in
			// allow an empty hour or minute string => 00
			var value = YAHOO.UP.form.getValue( formElement );
			var isValid = (new RegExp( '^((0?[0-9])|(1[0-9])|(2[0-3]))[^0-9]?(0?[0-9]|[1-5][0-9])?$' )).test( value );
			var strippedValue = ( new String( value ) ).replace( /[^0-9]/g, '' );
			var normalizedValue = ( new String( value ) ).replace( /[^0-9]/g, ':' );
			var isAmbiguous = false;
			var normalizeValue = false;
			var autoComplete = false;
			var isHeavyEvent = YAHOO.UP.form.isHeavyEvent( formElement, event );

			if( strippedValue.length == 1 )
			{
				var hour = YAHOO.UP.util.Math.parseInt( strippedValue );
				var minute = 0;
				autoComplete = true;
			} else if( isValid && strippedValue.length == 4 ) {
				var hour = YAHOO.UP.util.Math.parseInt( strippedValue.substr( 0, 2 ) );
				var minute = YAHOO.UP.util.Math.parseInt( strippedValue.substr( 2 ) );
				normalizeValue = true;
			} else if( isValid && strippedValue.length == 2 ) {
				if( ( YAHOO.UP.util.Math.parseInt( strippedValue ) >= 24 || normalizedValue.indexOf( ':' ) > -1 )
					&& YAHOO.UP.util.Math.parseInt( strippedValue.substr( 1 ) ) >= 6 )
				{
					var hour = YAHOO.UP.util.Math.parseInt( strippedValue.substr( 0, 1 ) );
					var minute = YAHOO.UP.util.Math.parseInt( strippedValue.substr( 1 ) );
					normalizeValue = true;
				} else if( YAHOO.UP.util.Math.parseInt( strippedValue ) < 24 ) {
					var hour = YAHOO.UP.util.Math.parseInt( strippedValue );
					var minute = 0;
					autoComplete = true;
				} else {
					var hour = YAHOO.UP.util.Math.parseInt( strippedValue.substr( 0, 1 ) );
					var minute = YAHOO.UP.util.Math.parseInt( strippedValue.substr( 1, 1 ) );
					autoComplete = true;
				}
			} else if( isValid && strippedValue.length == 3 && normalizedValue.indexOf( ':' ) > -1 ) {
				var split = normalizedValue.split( ':' );
				var hour = YAHOO.UP.util.Math.parseInt( split[ 0 ] );
				var minute = YAHOO.UP.util.Math.parseInt( split[ 1 ] );
				if( split[ 1 ].length == 2 || minute >= 6 ) normalizeValue = true;
			} else if( isValid && strippedValue.length == 3 ) {
				if( YAHOO.UP.util.Math.parseInt( strippedValue.substr( 0, 1 ) ) >= 2 && YAHOO.UP.util.Math.parseInt( strippedValue.substr( 1, 1 ) ) >= 6 )
				{
					isValid = false;
				} else if( YAHOO.UP.util.Math.parseInt( strippedValue.substr( 0, 1 ) ) < 2 && YAHOO.UP.util.Math.parseInt( strippedValue.substr( 1, 1 ) ) >= 6 ) {
					var hour = YAHOO.UP.util.Math.parseInt( strippedValue.substr( 0, 2 ) );
					var minute = YAHOO.UP.util.Math.parseInt( strippedValue.substr( 2 ) );
				} else if( YAHOO.UP.util.Math.parseInt( strippedValue.substr( 0, 2 ) ) >= 24 && YAHOO.UP.util.Math.parseInt( strippedValue.substr( 1, 1 ) ) < 6 ) {
					var hour = YAHOO.UP.util.Math.parseInt( strippedValue.substr( 0, 1 ) );
					var minute = YAHOO.UP.util.Math.parseInt( strippedValue.substr( 1 ) );
					normalizeValue = true;
				} else {
					// assume first two digits are the hour instead of throwing error message.
					var hour = YAHOO.UP.util.Math.parseInt( strippedValue.substr( 0, 2 ) );
					var minute = YAHOO.UP.util.Math.parseInt( strippedValue.substr( 2 ) );
					autoComplete = true;
				}
			}

			var isValidOrAutoComplete = isValid || (isHeavyEvent && autoComplete );
			var valueChanged = formElement.value != YAHOO.UP.util.Time.padFormat( hour, minute );

			if( isValidOrAutoComplete && !isAmbiguous && hour!= null && minute != null && ( isHeavyEvent || normalizeValue ) && valueChanged )
			{
				/* formElement.value = YAHOO.UP.util.Time.padFormat( hour, minute );
				return YAHOO.UP.validation.isTime( formElement ); */
				return YAHOO.UP.validation.setValue( formElement, YAHOO.UP.util.Time.padFormat( hour, minute ), true );
			} else {
				return isValid && !isAmbiguous;
			}
		} );
	}
};
YAHOO.UP.validation.addTimeZoneListener = function( note, elements )
{
	YAHOO.UP.util.each( elements, function( j, formElement )
	{
		YAHOO.util.Event.addListener( note.getAttribute( 'valdi:fordate' ), YAHOO.UP.form.getClass( formElement ).getEventType(), YAHOO.UP.validation.isTimeZoneEvent, formElement, true );
	} );
};
YAHOO.UP.validation.isTimeZoneEvent = function( e )
{
	return YAHOO.UP.validation.isTimeZone( YAHOO.UP.form.getElement( this ), e );
};
/* called on keyup from text date element */
YAHOO.UP.validation.isTimeZone = function( /* Wrapped Html Time Zone Form Element */formElement, event )
{
	if( YAHOO.UP.validation.isWhiteListed( formElement, event ) )
	{
		return YAHOO.UP.validation.execute( formElement, 'timeZone', event, function() { return true; } );
	} else {
		return YAHOO.UP.validation.execute( formElement, 'timeZone', event, function( formElement, event )
		{
			var value = YAHOO.UP.form.getValue( formElement );
			var divElement = YAHOO.UP.form.getParentDivElement( formElement );
			var note = YAHOO.UP.validation.getNote( divElement, formElement, 'timeZone' );
			if( note && note.getAttribute( 'valdi:fordate' ) )
			{
				var validateAgainstDate = document.getElementById( note.getAttribute( 'valdi:fordate' ) );
				if( validateAgainstDate )
				{
					var split = validateAgainstDate.value.split( '/' );
					var date = new Date( split[ 2 ], split[ 0 ] - 1, split[ 1 ] );
					var isDST = YAHOO.UP.util.Date.isDaylightSavingTime( date );

					/* var isDSTZone = value.indexOf( 'D' ) > -1;
					if( !isDSTZone || isDSTZone && isDST ) {
						return true;
					} else {
						return false;
					} */

					var options = Ext.query( 'option', formElement );
					YAHOO.UP.util.each( options, function( j, optionElement ) {
						var timeOffset = YAHOO.UP.util.Math.parseInt( optionElement.innerHTML.substr( 5, 2 ) );
						if( optionElement.innerHTML == ''
							|| optionElement.innerHTML.indexOf( 'UTC' ) > -1
							|| optionElement.innerHTML.indexOf( 'DT' ) > -1 && isDST
							|| optionElement.innerHTML.indexOf( 'ST' ) > -1 && !isDST )
						{
						} else if( isDST )
						{
							optionElement.innerHTML = optionElement.innerHTML.substr( 0, 1 ) + 'DT (' + ( timeOffset + 1 ) + ')';
						} else {
							optionElement.innerHTML = optionElement.innerHTML.substr( 0, 1 ) + 'ST (' + ( timeOffset - 1 ) + ')';
						}
					} );
					return true;
				}
			}
		} );
	}
};
YAHOO.namespace( 'UP.validation.Date' );
YAHOO.namespace( 'UP.validation.Date.TwoDigit' );
YAHOO.namespace( 'UP.validation.Date.ThreeDigit' );
YAHOO.namespace( 'UP.validation.Date.FourDigit' );
/* Handles MD MM comparisons to see if they are ambiguous */
YAHOO.UP.validation.Date.TwoDigit.isAmbiguous = function( /* Stripped Date String */strippedValue )
{
	if( strippedValue.substr( 0, 1 ) == '1' && ( strippedValue.substr( 1, 1 ) == '1' || strippedValue.substr( 1, 1 ) == '2' ) )
	{
		return true;
	} else {
		return false;
	}
};
/* Assumes Valid and not Ambiguous, Returns if MM is true (otherwise can assume MD) */
YAHOO.UP.validation.Date.TwoDigit.isTwoDigitMonth = function( /* Stripped Date String */strippedValue )
{
	return strippedValue.substr( 0, 1 ) == '0' || strippedValue.substr( 1, 1 ) == '0';
};
/* Handles MDD MMD comparisons to see if they are ambiguous */
YAHOO.UP.validation.Date.ThreeDigit.isAmbiguous = function( /* Stripped Date String */strippedValue )
{
	if( strippedValue.substr( 0, 1 ) == '1' && YAHOO.UP.util.Math.parseInt( strippedValue.substr( 1, 1 ) ) <= 2 && strippedValue.substr( 2, 1 ) != '0' )
	{
		return true;
	} else {
		return false;
	}
};
/* Assumes Valid and not Ambiguous, Returns if MMD is true (otherwise can assume MDD) */
YAHOO.UP.validation.Date.ThreeDigit.isTwoDigitMonth = function( /* Stripped Date String */strippedValue )
{
	return strippedValue.substr( 0, 1 ) == '0' && strippedValue.substr( 2, 1 ) != '0';
};
/* Handles MDYY MMDD comparisons to see if they are ambiguous */
YAHOO.UP.validation.Date.FourDigit.isAmbiguous = function( /* Stripped Date String */strippedValue )
{
	if( YAHOO.UP.validation.Date.TwoDigit.isAmbiguous( strippedValue ) 
		&& ( strippedValue.substr( 2, 2 ) == '19' || strippedValue.substr( 2, 2 ) == '20' ) )
	{
		return true;
	} else {
		return false;
	}
};
/* Assumes Valid and not Ambiguous, Returns if MMDD is true (otherwise can assume MDYY) */
YAHOO.UP.validation.Date.FourDigit.isTwoDigitMonth = function( /* Stripped Date String */strippedValue )
{
	var firstTwoChars = YAHOO.UP.util.Math.parseInt( strippedValue.substr( 0, 2 ) );
	if( strippedValue.substr( 0, 1 ) == '0'
		|| ( firstTwoChars >= 1 && firstTwoChars <= 12 )
		|| strippedValue.substr( 2, 2 ) != '19'
		|| strippedValue.substr( 2, 2 ) != '20' ) return true;
	else return false;
	
	/* return YAHOO.UP.util.Math.parseInt( strippedValue.substr( 1, 1 ) ) < 3 &&
				( strippedValue.substr( 0, 1 ) == '0'
				|| strippedValue.substr( 1, 1 ) == '0'
				|| strippedValue.substr( 2, 2 ) != '19'
				|| strippedValue.substr( 2, 2 ) != '20' ); */
};
YAHOO.UP.validation.getRealDateObj = function( /* Date String */value )
{
	var propDateObj = YAHOO.UP.validation.getDateObj( value );

	if( propDateObj[ 'other' ][ 'isValid' ] )
		return new Date( propDateObj[ 'year' ], propDateObj[ 'month' ] - 1, propDateObj[ 'day' ] );
	/* if( propDateObj[ 'other' ][ 'isValid' ] ) return new Date( propDateObj[ 'year' ], propDateObj[ 'month' ] - 1, propDateObj[ 'day' ] );
	else return null; */
};
YAHOO.UP.validation.getDateObj = function( /* Date String */value )
{
	var rawDay, rawMonth, rawYear;
	var isValid = (new RegExp( '^(0?[1-9]|1[012])[- /.]?(0?[1-9]|[12][0-9]|3[01])[- /.]?([12][0-9])?[0-9]{2}$' )).test( value );
	var strippedValue = ( new String( value ) ).replace( /[^0-9]/g, '' );
	var normalizedValue = ( new String( value ) ).replace( /[^0-9]/g, '/' );
	var firstSeparatorIndex = normalizedValue.indexOf( '/' );
	var isAmbiguous = false;
	var normalizeValue = false;
	var forceTwoYearNormalizeValue = false;

	/* Autocomplete Code for 2, 3 or 4 character strings ON HEAVY EVENT ONLY
		M
		MM
		MD (nonambiguous) or M/D
		MMD (nonambiguous) or MM/D
		MDD (nonambiguous) or M/DD
		MMDD or MM/DD (keep in mind that MDYY is out there )
		converts to MM/DD/YYYY with the missing parts defaulted to the current day and/or current year.

		Keep in mind that if the values are ambiguous, we are going to assume that it is a two digit month.
	 */
	var autoComplete = false;
	if( (new RegExp( '^(0?[1-9]|1[012])[- /.]?(0?[1-9]|[12][0-9]|3[01])?$' )).test( value ) )
	{
		if( strippedValue.length == 1 )
		{
			rawMonth = strippedValue;
			autoComplete = true;
		} else if( strippedValue.length == 2 ) {
			if( firstSeparatorIndex == 1 || !YAHOO.UP.validation.Date.TwoDigit.isAmbiguous( strippedValue ) )
			{
				if( !YAHOO.UP.validation.Date.TwoDigit.isAmbiguous( strippedValue )
					&& YAHOO.UP.validation.Date.TwoDigit.isTwoDigitMonth( strippedValue ) )
				{
					rawMonth = strippedValue;
				} else {
					rawMonth = strippedValue.substr( 0, 1 );
					rawDay = strippedValue.substr( 1 );
				}
				autoComplete = true;
			} else if( YAHOO.UP.validation.Date.TwoDigit.isAmbiguous( strippedValue ) ) {
				// ambiguous, assume two digit month
				rawMonth = strippedValue;
				autoComplete = true;
			}
		} else if( strippedValue.length == 3 ) {
			if( firstSeparatorIndex > -1 || !YAHOO.UP.validation.Date.ThreeDigit.isAmbiguous( strippedValue ) )
			{
				if( firstSeparatorIndex == 2 || ( !YAHOO.UP.validation.Date.ThreeDigit.isAmbiguous( strippedValue )
					&& YAHOO.UP.validation.Date.ThreeDigit.isTwoDigitMonth( strippedValue ) ) )
				{
					// MM/D or nonambiguous MMD
					rawMonth = strippedValue.substr( 0, 2 );
					rawDay = strippedValue.substr( 2 );
					autoComplete = true;
				} else if( firstSeparatorIndex == 1 || ( !YAHOO.UP.validation.Date.ThreeDigit.isAmbiguous( strippedValue )
					&& !YAHOO.UP.validation.Date.ThreeDigit.isTwoDigitMonth( strippedValue ) ) )
				{
					// M/DD or nonambiguous MDD
					rawMonth = strippedValue.substr( 0, 1 );
					rawDay = strippedValue.substr( 1 );
					autoComplete = true;
				}
			} else if( YAHOO.UP.validation.Date.ThreeDigit.isAmbiguous( strippedValue ) ) {
				// ambiguous, assume two digit month
				rawMonth = strippedValue.substr( 0, 2 );
				rawDay = strippedValue.substr( 2 );
				autoComplete = true;
			}
		} else if( strippedValue.length == 4 ) {
			if( !YAHOO.UP.validation.Date.FourDigit.isAmbiguous( strippedValue ) )
			{
				if( YAHOO.UP.validation.Date.FourDigit.isTwoDigitMonth( strippedValue ) )
				{
					rawMonth = strippedValue.substr( 0, 2 );
					rawDay = strippedValue.substr( 2 );
					autoComplete = true;
				} // else is MDYY, handled below
			} else {
				// ambiguous, assume two digit month
				rawMonth = strippedValue.substr( 0, 2 );
				rawDay = strippedValue.substr( 2 );
				autoComplete = true;
			}
		}

		if( autoComplete )
		{
			var now = new Date();
			if( rawDay == null ) rawDay = now.getDate() < 10 ? '0' + now.getDate() : '' + now.getDate();
			if( rawYear == null ) rawYear = '' + now.getFullYear();
		}
		//console.log( autoComplete, rawDay, rawMonth, rawYear );
	}

	/* type A: MDDYY and MMDYY
	 * type A4: MDDYYYY and MMDYYYY
	 * type B: MDYYYY and MMDDYY
	 * type C: MD/YYYY and MM/DDYY
	 * type D: MMD/YY and MDD/YY
	 * type D4: MMD/YYYY and MDD/YYYY
	 */
	var isTypeA = value.length == strippedValue.length && value.length == 5;
	var isTypeA4 = value.length == strippedValue.length && value.length == 7;
	var isTypeB = value.length == strippedValue.length && value.length == 6;
	var isTypeC = value.length == 7 && strippedValue.length == 6 && firstSeparatorIndex == 2;
	var isTypeD = value.length == 6 && strippedValue.length == 5 && firstSeparatorIndex == 3;
	var isTypeD4 = value.length == 8 && strippedValue.length == 7 && firstSeparatorIndex == 3;

	var maybeAmbiguous = isTypeA || isTypeA4 || isTypeD || isTypeD4 || isTypeB || isTypeC;

	if( isTypeA || isTypeA4 || isTypeD || isTypeD4 )
	{
		if( YAHOO.UP.validation.Date.ThreeDigit.isAmbiguous( strippedValue ) )
		{
			isAmbiguous = true;
		} else if( YAHOO.UP.validation.Date.ThreeDigit.isTwoDigitMonth( strippedValue ) ) {
			rawMonth = strippedValue.substr( 0, 2 );
			rawDay = strippedValue.substr( 2, 1 );
			rawYear = strippedValue.substr( 3 );
		} else {
			rawMonth = strippedValue.substr( 0, 1 );
			rawDay = strippedValue.substr( 1, 2 );
			rawYear = strippedValue.substr( 3 );
		}
	} else if( isTypeB || isTypeC )	{
		if( YAHOO.UP.validation.Date.FourDigit.isAmbiguous( strippedValue ) )
		{
			isAmbiguous = true;
		} else if( YAHOO.UP.validation.Date.FourDigit.isTwoDigitMonth( strippedValue ) ) {
			rawMonth = strippedValue.substr( 0, 2 );
			rawDay = strippedValue.substr( 2, 2 );
			rawYear = strippedValue.substr( 4 );
		} else {
			rawMonth = strippedValue.substr( 0, 1 );
			rawDay = strippedValue.substr( 1, 1 );
			rawYear = strippedValue.substr( 2 );
		}
	}

	if( isTypeC || isTypeD ) forceTwoYearNormalizeValue = true;

	if( isValid && !maybeAmbiguous && !autoComplete )
	{
		var separatorCount = YAHOO.UP.util.String.count( normalizedValue, '/' );
		if( strippedValue.length == 4 || strippedValue.length == 8 ) {
			if( strippedValue.length == 4 )
			{
				rawMonth = strippedValue.substr( 0, 1 );
				rawDay = strippedValue.substr( 1, 1 );
				rawYear = strippedValue.substr( 2, 2 );
				// don't forceTwoYearNormalizeValue, could be on their way to typing a 5+ digit date.
			} else { // strippedValue.length == 8
				rawMonth = strippedValue.substr( 0, 2 );
				rawDay = strippedValue.substr( 2, 2 );
				rawYear = strippedValue.substr( 4 );
			}
		} else if( separatorCount == 2 ) {	
			var splitValue = normalizedValue.split( '/' );
			rawMonth = splitValue[ 0 ];
			rawDay = splitValue[ 1 ];
			rawYear = splitValue[ 2 ];
			forceTwoYearNormalizeValue = true;
		} else if( separatorCount == 1 ) { // separatorCount == 1
			if( firstSeparatorIndex == 1 ) /* M/DYYYY or M/DDYY or M/DDYYYY */
			{
				rawMonth = value.substr( 0, 1 );
				if( value.length == 5 || value.length == 7 )
				{
					rawDay = value.substr( 2, 1 );
					rawYear = value.substr( 3 );
					forceTwoYearNormalizeValue = true;
				} else {
					rawDay = value.substr( 2, 2 );
					rawYear = value.substr( 4 );
				}
			} else if( firstSeparatorIndex == 2 ) { /* MM/DYY or MM/DYYYY */
				rawMonth = value.substr( 0, 2 );
				rawDay = value.substr( 3, 1 );
				rawYear = value.substr( 4 );
			} else { /* MMDD/YY */
				rawMonth = value.substr( 0, 2 );
				rawDay = value.substr( 2, 2 );
				rawYear = value.substr( 5 );
				forceTwoYearNormalizeValue = true;
			}
		}
	}

	var isAllHaveValues = rawMonth != null && rawDay != null && rawYear != null;

	/* var isOneCharMissing = (new RegExp( '^[1-9][/](0[1-9]|[12][0-9]|3[01])[/]([12][0-9])[0-9]{2}$' )).test( value )
								|| (new RegExp( '^(0[1-9]|1[012])[/][1-9][/]([12][0-9])[0-9]{2}$' )).test( value ); */
	var isOneCharMissing = ( new RegExp( '^(0?[1-9])[/](0?[1-9])[/]([12][0-9])[0-9]{2}$' ) ).test( value );

	if( isValid && !isAmbiguous && isAllHaveValues && strippedValue.length > 4 )
	{
		if( rawYear.length == 4 && !isOneCharMissing ) normalizeValue = true;
		else if( rawYear.length == 2 && forceTwoYearNormalizeValue && rawYear != '19' && rawYear != '20' && !isOneCharMissing ) normalizeValue = true;
	}

	var month, day, year;
	if( isAllHaveValues )
	{
		month = YAHOO.UP.util.Math.parseInt( rawMonth );
		day = YAHOO.UP.util.Math.parseInt( rawDay );
		year = YAHOO.UP.util.Math.parseInt( rawYear );
		if( year < 100 && year > 50 ) year += 1900;
		else if( year <= 50 && year >= 0 ) year += 2000;
	}

	return {
		month: month,
		day: day,
		year: year,
		other:
		{
			isValid: isValid && !isAmbiguous && isAllHaveValues,
			isAmbiguous: isAmbiguous,
			normalizeValue: normalizeValue,
			isAutoComplete: autoComplete
		}
	};
};
YAHOO.UP.validation.addDateListener = function( note, elements )
{
	YAHOO.UP.validation.addGenericListener( elements, YAHOO.UP.validation.isDateEvent );
};
YAHOO.UP.validation.isDateEvent = function( e )
{
	return YAHOO.UP.validation.isDate( YAHOO.UP.form.getElement( this ), e );
};
YAHOO.UP.validation.isDate = function( /* Wrapped Html Form Element */formElement, event )
{
	if( YAHOO.UP.validation.isWhiteListed( formElement, event ) )
	{
		return YAHOO.UP.validation.execute( formElement, 'date', event, function() { return true; } );
	} else {
		return YAHOO.UP.validation.execute( formElement, 'date', event, YAHOO.UP.validation.isDateCheckFunction );
	}
};
YAHOO.UP.validation.isDateCheckFunction = function( formElement, event )
{
	var day, month, year;
	var value = YAHOO.UP.form.getValue( formElement );
	
	var obj 			= YAHOO.UP.validation.getDateObj( value );
	var day 			= obj[ 'day' ];
	var month 			= obj[ 'month' ];
	var year 			= obj[ 'year' ];
	var isValid			= obj[ 'other' ][ 'isValid' ];
	var isAmbiguous		= obj[ 'other' ][ 'isAmbiguous' ];
	var normalizeValue	= obj[ 'other' ][ 'normalizeValue' ];
	var isAutoComplete 	= obj[ 'other' ][ 'isAutoComplete' ];

	YAHOO.UP.validation.subNote( formElement, 'date', 'ambiguous', isValid && isAmbiguous );

	var isInPast = false;
	var isWithinRange = true;
	if( isValid || isAutoComplete )
	{
		if( YAHOO.UP.validation.hasSubNote( formElement, 'date', 'future' ) )
		{
			var now = new Date();
			var input = new Date( year, month-1, day+1 );
			isInPast = (now.getTime()-input.getTime()) > 0;
		}

		var isNotValidMonth = month == 0 || month > 12;
		YAHOO.UP.validation.subNote( formElement, 'date', 'month', isNotValidMonth, { month: month } );

		if( !isNotValidMonth )
		{
			var isNotValidDays = true;
			/* if( isValid && !isAmbiguous && isAllHaveValues )
			{ */
			if( day <= YAHOO.UP.util.Date.getDaysInMonth( year, month ) ) isNotValidDays = false;

			YAHOO.UP.validation.subNote( formElement, 'date', 'overflow', isNotValidDays,
			{
				year: year,
				month: YAHOO.UP.util.Date.getMonth( month ),
				days: YAHOO.UP.util.Date.getDaysInMonth( year, month ) 
			} );

			if( YAHOO.UP.validation.hasSubNote( formElement, 'date', 'future' ) )
			{
				YAHOO.UP.validation.subNote( formElement, 'date', 'future', !isNotValidDays && isInPast,
				{
					month: month,
					day: day,
					year: year,
					todaysMonth: now.getMonth() + 1,
					todaysDay: now.getDate(),
					todaysYear: now.getFullYear()
				} );
			}

			if( YAHOO.UP.validation.hasSubNote( formElement, 'date', 'within' ) )
			{
				var withinSubNote = YAHOO.UP.validation.getFirstSubNote( formElement, 'date', 'within' );

				// default is now
				var minDays = withinSubNote.getAttribute( 'valdi:minDays' ) != null ? YAHOO.UP.util.Math.parseInt( withinSubNote.getAttribute( 'valdi:minDays' ) ) : 0;
				var minNow = new Date();
				minNow.setTime( minNow.getTime() + minDays*1000*60*60*24 );

				var input = new Date( year, month-1, day+1 );
				isWithinRange = (input.getTime()-minNow.getTime()) > 0;

				// default is forever
				if( withinSubNote.getAttribute( 'valdi:maxDays' ) != null )
				{
					var maxDays = YAHOO.UP.util.Math.parseInt( withinSubNote.getAttribute( 'valdi:maxDays' ) );
					var maxNow = new Date();
					maxNow.setTime( maxNow.getTime() + maxDays*1000*60*60*24 );
					isWithinRange = isWithinRange && (maxNow.getTime()-input.getTime()) > 0;
				}

				YAHOO.UP.validation.subNote( formElement, 'date', 'within', !isNotValidDays && !isWithinRange );
			}
		}
	}
	//console.log( isInPast );
	//console.log( isValid && !isNotValidDays && !isNotValidMonth && !isInPast );

	var isHeavyEvent			= YAHOO.UP.form.isHeavyEvent( formElement, event );
	var isValidOrAutoCompleted 	= isValid || ( isHeavyEvent && isAutoComplete );
	var isChangedValue 			= formElement.value != YAHOO.UP.util.Date.padFormat( day, month, year );
	//console.log( isValidOrAutoCompleted, 'm:' + month + ' d:' + day + ' y:' + year + ' valid:' + isValid + ' amb:' + isAmbiguous + ' norm:' + normalizeValue + ' force:' + isHeavyEvent + ' past:' + isInPast );
	//console.log( isValidOrAutoCompleted, !isNotValidMonth, !isNotValidDays, ( isHeavyEvent || normalizeValue ), isChangedValue );
	if( isValidOrAutoCompleted && !isNotValidMonth && !isNotValidDays && ( isHeavyEvent || normalizeValue ) && isChangedValue )
	{
		/* formElement.value = YAHOO.UP.util.Date.padFormat( day, month, year );
		return YAHOO.UP.validation.isDate( formElement ); */
		return YAHOO.UP.validation.setValue( formElement, YAHOO.UP.util.Date.padFormat( day, month, year ), true, !isInPast && isWithinRange );
	} else {
		return isValid && !isNotValidDays && !isNotValidMonth && !isInPast && isWithinRange;
	}
};
YAHOO.UP.validation.getDateFromDay = function( day, dayModifier )
{
	day = YAHOO.UP.util.Math.parseInt( day );
	var now = new Date();
	if( dayModifier != null && YAHOO.lang.isNumber( dayModifier ) ) now.setTime( now.getTime() + dayModifier*1000*60*60*24 );
	if( day < now.getDate() ) {
		//if( ( now.getMonth() + 2 ) > 12 )
		if( ( now.getMonth() + 1 ) > 12 )
		{
			//month = (now.getMonth() + 2) - 12;
			month = (now.getMonth() + 1) - 12;
			year = now.getFullYear() + 1;
		} else {
			//month = now.getMonth() + 2;
			month = now.getMonth() + 1;
			year = now.getFullYear();
		}
	} else {
		//month = now.getMonth() + 1;
		month = now.getMonth();
		year = now.getFullYear();
	}
	return new Date( year, month, day );
};
YAHOO.UP.validation.hasSubNote = function( formElement, type, subType )
{
	var parentDiv = YAHOO.UP.form.getParentDivElement( formElement );
	if( YAHOO.UP.validation.getSubNote( formElement, type, subType ).length > 0 )
	{
		return true;
	} else {
		return false;
	}
};
YAHOO.UP.validation.getFirstSubNote = function( formElement, type, subType )
{
	var parentDiv = YAHOO.UP.form.getParentDivElement( formElement );
	return Ext.queryOne( 'span[valdi:subtype="' + subType + '"]', YAHOO.UP.validation.getNote( parentDiv, formElement, type ) );
};
YAHOO.UP.validation.getSubNote = function( formElement, type, subType )
{
	var parentDiv = YAHOO.UP.form.getParentDivElement( formElement );
	return Ext.query( 'span[valdi:subtype="' + subType + '"]', YAHOO.UP.validation.getNote( parentDiv, formElement, type ) );
};
YAHOO.UP.validation.subNote = function( formElement, type, subType, booleanTest, objVariables )
{
	var subNote = YAHOO.UP.validation.getSubNote( formElement, type, subType );
	if( booleanTest )
	{
		if( subNote )
		{
			if( objVariables )
			{
				for( var j in objVariables )
				{
					Ext.query( 'span.' + j, subNote )[0].innerHTML = objVariables[ j ];
				}
			}
			//if( YAHOO.util.Dom.hasClass( subNote, 'hidden' ) && !YAHOO.util.Dom.hasClass( subNote, 'shown' ) ) 
			YAHOO.util.Dom.replaceClass( subNote, 'hidden', 'shown' );
		}
		return false;
	} else if( subNote && !booleanTest && YAHOO.util.Dom.hasClass( subNote, 'shown' ) ) {
		YAHOO.util.Dom.replaceClass( subNote, 'shown', 'hidden' );
	}
	return true;
};

YAHOO.UP.validation.execute = function( /* Wrapped Html Form Element */formElement, type, event, checkFunction )
{
	var divElement = YAHOO.UP.form.getParentDivElement( formElement );
	var parentFieldSetDiv = YAHOO.UP.form.__scanForParentFieldset( divElement );
	var note = YAHOO.UP.validation.getNote( divElement, formElement, type );
	var noteElements = YAHOO.UP.validation.getAllElementsForNote( divElement, note );
	var resultsValid = true;
	if( checkFunction != YAHOO.UP.validation.checkNotEmpty && YAHOO.UP.form.getValue( formElement ) == '' ) // empty is valid
	{ // this says that empty is ok for all things except for checknotempty.
	} else {
		for( var j = 0; j < noteElements.length; j++ )
		{
			if( !checkFunction( noteElements[ j ], event ) ) resultsValid = false;
		}
	}

	var isHeavyEvent = YAHOO.UP.form.isHeavyEvent( formElement, event );
	var noteSeverity = note ? YAHOO.UP.validation.getNoteSeverity( note ) : null;
	if( !resultsValid )
	{
		if( isHeavyEvent || ( YAHOO.util.Dom.hasClass( note, 'showOnNonHeavyEvent' ) && YAHOO.util.Dom.hasClass( YAHOO.UP.form.getForm( formElement ), 'submitted' ) ) ) // and is invalid
		{
			YAHOO.UP.util.show( note );
			if( !YAHOO.util.Dom.hasClass( divElement, noteSeverity ) )
			{
				YAHOO.util.Dom.addClass( divElement, noteSeverity );
				/* var elementDiv = YAHOO.UP.form.getElementDiv( divElement );
				YAHOO.util.Dom.setStyle( elementDiv, 'opacity', '0' );
				(new YAHOO.util.Anim( elementDiv, { opacity: { to: 1 } }, 0.5, YAHOO.util.Easing.easeOut)).animate(); */
			}
		}
		YAHOO.util.Dom.removeClass( Ext.query( 'div.element', divElement ), 'currentlyValid' );
	} else {
		YAHOO.UP.util.hide( note );
		if( Ext.query( 'div.note.validate.shown', divElement ).length == 0 )
		{
			YAHOO.util.Dom.removeClass( divElement, noteSeverity );
		}
		/* YAHOO.util.Dom.addClass( note, 'showOnNonHeavyEvent' );
		if( !YAHOO.util.Dom.hasClass( parentFieldSetDiv, 'info' ) && !YAHOO.util.Dom.hasClass( parentFieldSetDiv, 'warning' ) && !YAHOO.util.Dom.hasClass( parentFieldSetDiv, 'error' ) )
		{
			YAHOO.util.Dom.addClass( Ext.query( 'div.element', divElement ), 'currentlyValid' );
		} */
	}

	/* if( YAHOO.UP.form.getAllElements( parentFieldSetDiv, null, 'div.fieldset.validate' ).length == YAHOO.UP.form.getAllElements( parentFieldSetDiv, 'currentlyValid', 'div.fieldset.validate' ).length )
	{
		YAHOO.util.Dom.addClass( parentFieldSetDiv, 'allFieldsValid' );
	} else {
		YAHOO.util.Dom.removeClass( parentFieldSetDiv, 'allFieldsValid' );
	} */

	return resultsValid;
};
YAHOO.UP.validation.updateProgress = function( e )
{
	// make sure the scope is set to the form object.
	// (???) make sure this has already been submitted at least once.
	// there is a bug here where it doesn't update right away because the view does not update.
	var totalElements = Ext.query( 'div.fieldset.validate', this ).length;
	var warningElements = Ext.query( 'div.fieldset.validate.info, div.fieldset.validate.warning, div.fieldset.validate.error', this ).length;
	var percentCorrect = Math.round( ( totalElements - warningElements ) * 100 / totalElements );
	if( YAHOO.util.Dom.hasClass( this, 'submitted' ) )
	{
		YAHOO.UP.util.hide( Ext.query( 'div.result' ) );
		if( percentCorrect == 100 )
		{
			YAHOO.UP.util.show( YAHOO.util.Dom.get( 'resubmitMessage' ) );
		} else {
			var failureMessage = YAHOO.util.Dom.get( 'failureMessage' );
			YAHOO.UP.util.show( failureMessage );

			//YAHOO.util.Dom.setStyle( Ext.query( 'div.status div.filled', failureMessage ), 'width', '' + percentCorrect + '%' );

			YAHOO.UP.util.autoComplete( failureMessage );
		}
	}
};
YAHOO.UP.validation.getNumberOfProblems = function()
{
	var warningElements = Ext.query( 'div.fieldset.validate.info, div.fieldset.validate.warning, div.fieldset.validate.error' ).length;
	return warningElements + ' problem' + ( warningElements != 1 ? 's' : '' );
};

YAHOO.namespace( 'UP.form' );
YAHOO.UP.form.callRaw = function( /* Child Html Form Element */formElement, func )
{
	return func( YAHOO.UP.form.getElement( formElement ) );
};
YAHOO.UP.form.getForm = function( /* Wrapped Html Form Element */formElement )
{
	var parentDiv;
	if( formElement && formElement.nodeName && YAHOO.UP.form.isButton( formElement ) ) parentDiv = formElement;
	else parentDiv = YAHOO.UP.form.getParentDivElement( formElement );

	if( parentDiv.parentNode.parentNode.nodeName.toLowerCase() == 'form' ) return parentDiv.parentNode.parentNode;
	else {
		// in case other methods fail, scan for fieldset div 5 levels up.
		var j = 0;
		var element = parentDiv;
		while( j < 9 )
		{
			if( element.parentNode.nodeName.toLowerCase() == 'form' )
			{
				return element.parentNode;
			} else {
				j++;
				element = element.parentNode;
			}
		}
		throw new Error( 'Could not find Form in scan for ID: ' + formElement.getAttribute( 'id' ) );
	}
};
YAHOO.UP.form.getParentDivElement = function( /* Wrapped Html Form Element */formElement )
{
	if( ( YAHOO.UP.form.isRadioArray( formElement ) || YAHOO.UP.form.isCheckBoxArray( formElement ) ) )
	{
		// checkbox and radios are stored inside labels.
		return YAHOO.UP.form.__scanForFieldset( formElement[ 0 ] );
	} else if( YAHOO.util.Dom.hasClass( formElement.parentNode.parentNode, 'fieldset' ) ) {
		return formElement.parentNode.parentNode;
	} else {
		return YAHOO.UP.form.__scanForFieldset( formElement );
	}
};
YAHOO.UP.form.__scanForFieldset = function( formElement )
{
	// in case other methods fail, scan for fieldset div 5 levels up.
	var j = 0;
	var element = formElement;
	while( j < 5 )
	{
		if( YAHOO.util.Dom.hasClass( element.parentNode, 'fieldset' ) )
		{
			return element.parentNode;
		} else {
			j++;
			element = element.parentNode;
		}
	}
	throw new Error( 'Could not find Parent Div Element in scan for ID: ' + formElement.getAttribute( 'id' ) );
};
YAHOO.UP.form.__scanForParentFieldset = function( nodeElement )
{
	var j = 0;
	var element = nodeElement;
	while( j < 5 )
	{
		if( element.parentNode.nodeName.toLowerCase() == 'fieldset' )
		{
			return element.parentNode;
		} else {
			j++;
			element = element.parentNode;
		}
	}
	throw new Error( 'Could not find Parent Fieldset in scan for ID: ' + nodeElement );
};
YAHOO.UP.form.getElementDiv = function( /* Parent Div Element */divElement )
{
	return YAHOO.util.Dom.getElementsByClassName( 'element', 'div', divElement )[ 0 ];
};
YAHOO.UP.form.getAllElements = function( /* Parent Div Element */divElement, /* String */withClassName, /* String */queryPrefix )
{
	if( withClassName == null )
	{
		str = '';
	} else if( YAHOO.lang.isArray( withClassName ) ) {
		str = '.' + withClassName.join( '.' );
	} else if( YAHOO.lang.isString( withClassName ) ) {
		str = '.' + withClassName;
	}

	if( queryPrefix == null )
		queryPrefix = '';

	var allElements = Ext.query( queryPrefix + ' div.element.primary' + str + ' input[type=text], ' + queryPrefix + ' div.element.primary' + str + ' select, ' + queryPrefix + ' div.element.primary' + withClassName + ' textarea', divElement ); //, div.element.primary button, , div.element.primary input[type=button]
	var groupedRadioElement = Ext.query( queryPrefix + ' div.element.primary' + str + ' input[type=radio]', divElement );
	var groupedCheckBoxElement = Ext.query( queryPrefix + ' div.element.primary' + str + ' input[type=checkbox]', divElement );

	if( groupedRadioElement.length > 0 ) allElements.push( groupedRadioElement );
	if( groupedCheckBoxElement.length > 0 ) allElements.push( groupedCheckBoxElement );

	return allElements;
};

/* returns a Wrapped Html Form Element (for Radios, Checkboxes) */
YAHOO.UP.form.getElement = function( /* Child Html Form Element */formElement )
{
	if( YAHOO.lang.isArray( formElement ) ) formElement = formElement[ 0 ];

	if( YAHOO.UP.form.isRadio( formElement ) ) return Ext.query( 'input[type=radio]', YAHOO.UP.form.getParentDivElement( formElement ) );
	else if( YAHOO.UP.form.isCheckBox( formElement ) ) return Ext.query( 'input[type=checkbox]', YAHOO.UP.form.getParentDivElement( formElement ) );
	else if( YAHOO.UP.form.isText( formElement )
			|| YAHOO.UP.form.isPassword( formElement )
			|| YAHOO.UP.form.isTextArea( formElement )
			|| YAHOO.UP.form.isSelectMultiple( formElement )
			|| YAHOO.UP.form.isSelect( formElement )
			|| YAHOO.UP.form.isButton( formElement ) ) return formElement;
	else throw new Error( 'Could not find matching wrapper element.' );
};
YAHOO.UP.form.getClass = function( /* Wrapped Html Form Element */formElement )
{
	// make sure array checks are first
	if( YAHOO.UP.form.isRadioArray( formElement ) ) return YAHOO.UP.form.Radio;
	else if( YAHOO.UP.form.isCheckBoxArray( formElement ) ) return YAHOO.UP.form.CheckBox;
	else if( YAHOO.UP.form.isText( formElement ) ) return YAHOO.UP.form.Text;
	else if( YAHOO.UP.form.isPassword( formElement ) ) return YAHOO.UP.form.Password;
	else if( YAHOO.UP.form.isTextArea( formElement ) ) return YAHOO.UP.form.TextArea;
	else if( YAHOO.UP.form.isSelect( formElement ) ) return YAHOO.UP.form.Select;
	else if( YAHOO.UP.form.isButton( formElement ) ) return YAHOO.UP.form.Button;
	else throw new Error( 'Could not find matching class for the form element.' );
};

YAHOO.UP.form.Text = function() {};
YAHOO.UP.form.Password = function() {};
YAHOO.UP.form.TextArea = function() {};
YAHOO.UP.form.Radio = function() {};
YAHOO.UP.form.CheckBox = function() {};
YAHOO.UP.form.Select = function() {};
YAHOO.UP.form.Button = function() {};

YAHOO.UP.form.getValueRaw = function( /* Child Html Form Element */formElement )
{
	if( YAHOO.lang.isString( formElement ) ) formElement = YAHOO.util.Dom.get( formElement );
	return YAHOO.UP.form.getValue( YAHOO.UP.form.getElement( formElement ) );
};
YAHOO.UP.form.getValue = function( /* Wrapped Html Form Element */formElement )
{
	// if formElement is a checkbox or a radio and not an array, get the element first.
	return YAHOO.UP.form.getClass( formElement ).getValue( formElement );
};
YAHOO.UP.form.Text.getValue = function( /* Wrapped Html Form Element */formElement )
{
	return formElement.value;
};
YAHOO.UP.form.Password.getValue = YAHOO.UP.form.Text.getValue;
YAHOO.UP.form.TextArea.getValue = YAHOO.UP.form.Text.getValue;
YAHOO.UP.form.Radio.getValue = function( /* Wrapped Html Form Element */formElement )
{
	for( var j = 0; j < formElement.length; j++ )
	{
		if( YAHOO.UP.form.isRadio( formElement[ j ] ) && formElement[ j ].checked ) return formElement[ j ].value;
	}
};
YAHOO.UP.form.CheckBox.getValue = function( /* Wrapped Html Form Element */formElement )
{
	var values = [];
	for( var j = 0; j < formElement.length; j++ )
	{
		if( YAHOO.UP.form.isCheckBox( formElement[ j ] ) && formElement[ j ].checked ) values.push( formElement[ j ].value );
	}
	return values;
};
YAHOO.UP.form.Select.getValue = function( /* Wrapped Html Form Element */formElement )
{
	var values = [];
	if( formElement.options.length == 0 ) return values;
	YAHOO.UP.util.each( formElement.options, function( i, obj )
	{
		if( obj.selected )
		{
			values.push( obj.getAttribute( 'value' ) );
		}
	} );
	return values;
};
YAHOO.UP.form.Button.getValue = YAHOO.UP.form.Text.getValue;

YAHOO.UP.form.getAvailableValueRaw = function( /* Child Html Form Element */formElement )
{
	if( YAHOO.lang.isString( formElement ) ) formElement = YAHOO.util.Dom.get( formElement );
	return YAHOO.UP.form.getAvailableValue( YAHOO.UP.form.getElement( formElement ) );
};
YAHOO.UP.form.getAvailableValue = function( /* Wrapped Html Form Element */formElement )
{
	return YAHOO.UP.form.getClass( formElement ).getAvailableValue( formElement );
};
YAHOO.UP.form.Text.getAvailableValue = YAHOO.UP.form.Text.getValue
YAHOO.UP.form.Password.getAvailableValue = YAHOO.UP.form.Password.getValue;
YAHOO.UP.form.TextArea.getAvailableValue = YAHOO.UP.form.TextArea.getValue;
YAHOO.UP.form.Radio.getAvailableValue = function( /* Wrapped Html Form Element */formElement )
{
	/* for( var j = 0; j < formElement.length; j++ )
	{
		if( YAHOO.UP.form.isRadio( formElement[ j ] ) ) return formElement[ j ].value;
	} */
	var values = [];
	for( var j = 0; j < formElement.length; j++ )
	{
		if( YAHOO.UP.form.isRadio( formElement[ j ] ) ) values.push( formElement[ j ].value );
	}
	return values;
};
YAHOO.UP.form.CheckBox.getAvailableValue = function( /* Wrapped Html Form Element */formElement )
{
	var values = [];
	for( var j = 0; j < formElement.length; j++ )
	{
		if( YAHOO.UP.form.isCheckBox( formElement[ j ] ) ) values.push( formElement[ j ].value );
	}
	return values;
};
YAHOO.UP.form.Select.getAvailableValue = function( /* Wrapped Html Form Element */formElement )
{
	var values = [];
	YAHOO.UP.util.each( Ext.query( 'option', formElement ), function( i, obj )
	{
		values.push( obj.getAttribute( 'value' ) );
	} );
	return values;
};
YAHOO.UP.form.Button.getAvailableValue = YAHOO.UP.form.Button.getValue;

YAHOO.UP.form.setValueRaw = function( /* Html Form Element */formElement, value )
{
	if( YAHOO.lang.isString( formElement ) ) formElement = YAHOO.util.Dom.get( formElement );
	YAHOO.UP.form.setValue( YAHOO.UP.form.getElement( formElement ), value );
};
YAHOO.UP.form.setValue = function( /* Wrapped Html Form Element */formElement, value )
{
	YAHOO.UP.form.getClass( formElement ).setValue( formElement, value );
};
YAHOO.UP.form.Text.setValue = function( formElement, value ) { formElement.value = value; };
YAHOO.UP.form.Password.setValue = YAHOO.UP.form.Text.setValue;
YAHOO.UP.form.TextArea.setValue = YAHOO.UP.form.Text.setValue;
YAHOO.UP.form.Radio.setValue = function( /* Wrapped Html Form Element */formElement, /* String */value )
{
	for( var j = 0; j < formElement.length; j++ )
	{
		if( YAHOO.UP.form.isRadio( formElement[ j ] ) && value == formElement[ j ].value ) formElement[ j ].checked = true;
		else formElement[ j ].checked = false;
	}
};
YAHOO.UP.form.CheckBox.setValue = function( /* Wrapped Html Form Element */formElement, /* String */value )
{
	for( var j = 0; j < formElement.length; j++ )
	{
		if( YAHOO.UP.form.isCheckBox( formElement[ j ] ) )
		{
			if( YAHOO.UP.util.Array.hasValue( value, formElement[ j ].value ) ) formElement[ j ].checked = true;
			else formElement[ j ].checked = false;
		}
	}
};
YAHOO.UP.form.Select.setValue = function( /* Wrapped Html Form Element */formElement, /* String */value )
{
	if( (typeof value).toLowerCase() == 'string' ) value = [ value ];

	if( formElement.options.length == 0 ) return;
	YAHOO.UP.util.each( formElement.options, function( i, obj )
	{
		var isSelected = YAHOO.UP.util.Array.hasValue( value, obj[ 'value' ] );
		try {
			obj[ 'selected' ] = isSelected;
		} catch( e ) {}
	} );
};
YAHOO.UP.form.Button.setValue = YAHOO.UP.form.Text.setValue;

YAHOO.UP.form.Text.getEventType = function() { return 'keyup'; };
YAHOO.UP.form.Password.getEventType = function() { return 'keyup'; };
YAHOO.UP.form.TextArea.getEventType = function() { return 'keyup'; };
YAHOO.UP.form.Radio.getEventType = function() { return 'click'; };
YAHOO.UP.form.CheckBox.getEventType = function() { return 'click'; };
YAHOO.UP.form.Select.getEventType = function() { return 'click'/* null */; };
YAHOO.UP.form.Button.getEventType = function() { return 'click'; };

YAHOO.UP.form.Text.isDeltaElement = function() { return true; };
YAHOO.UP.form.Password.isDeltaElement = function() { return true; };
YAHOO.UP.form.TextArea.isDeltaElement = function() { return true; };
YAHOO.UP.form.Radio.isDeltaElement = function() { return false; };
YAHOO.UP.form.CheckBox.isDeltaElement = function() { return false; };
YAHOO.UP.form.Select.isDeltaElement = function() { return false; };
YAHOO.UP.form.Button.isDeltaElement = function() { return false; };

YAHOO.UP.form.getHeavyEventType = function( /* Wrapped Html Form Element */formElement )
{
	return YAHOO.UP.form.getClass( formElement ).getHeavyEventType();
};
YAHOO.UP.form.Text.getHeavyEventType = function() { return 'blur'; };
YAHOO.UP.form.Password.getHeavyEventType = function() { return 'blur'; };
YAHOO.UP.form.TextArea.getHeavyEventType = function() { return 'blur'; };
YAHOO.UP.form.Radio.getHeavyEventType = function() { return 'change'; };
YAHOO.UP.form.CheckBox.getHeavyEventType = function() { return 'change'; };
YAHOO.UP.form.Select.getHeavyEventType = function() { return 'change'; };
YAHOO.UP.form.Button.getHeavyEventType = function() { return 'click'; };

YAHOO.UP.form.isHeavyEvent = function( /* Wrapped Html Form Element */formElement, event )
{
	return !event || event.type == YAHOO.UP.form.getClass( formElement ).getHeavyEventType();
};

YAHOO.UP.form.isText = function( element )
{
	return element.nodeName.toLowerCase() == 'input' && element.getAttribute( 'type' ) == 'text';
};
YAHOO.UP.form.isPassword = function( element )
{
	return element.nodeName.toLowerCase() == 'input' && element.getAttribute( 'type' ) == 'password';
};
YAHOO.UP.form.isTextArea = function( element )
{
	return element.nodeName.toLowerCase() == 'textarea';
};
YAHOO.UP.form.isRadio = function( element )
{
	return element.nodeName.toLowerCase() == 'input' && element.getAttribute( 'type' ) == 'radio';
};
YAHOO.UP.form.isCheckBox = function( element )
{
	return element.nodeName.toLowerCase() == 'input' && element.getAttribute( 'type' ) == 'checkbox';
};
YAHOO.UP.form.isRadioArray = function( /* Array */elements )
{
	return YAHOO.UP.form.isElementArray( elements, YAHOO.UP.form.isRadio );
};
YAHOO.UP.form.isCheckBoxArray = function( /* Array */elements )
{
	return YAHOO.UP.form.isElementArray( elements, YAHOO.UP.form.isCheckBox );
};
YAHOO.UP.form.isElementArray = function( /* Array */elements, /* function */checkFunction )
{
	var allElements = false;
	if( elements.length > 0 )
	{
		allElements = true;
		for( var j = 0; j < elements.length; j++ )
		{
			if( !checkFunction( elements[ j ] ) )
			{
				allElements = false;
				break;
			}
		}
	}
	return allElements;
};
YAHOO.UP.form.isSelectMultiple = function( element )
{
	return element.nodeName.toLowerCase() == 'select' && element.getAttribute( 'multiple' ) == 'multiple';
};
YAHOO.UP.form.isSelect = function( element )
{
	return element.nodeName.toLowerCase() == 'select';
};
YAHOO.UP.form.isButton = function( element )
{
	return element.nodeName.toLowerCase() == 'button'
			|| element.nodeName.toLowerCase() == 'input' && element.getAttribute( 'type' ) == 'submit'
			|| element.nodeName.toLowerCase() == 'input' && element.getAttribute( 'type' ) == 'reset'
			|| element.nodeName.toLowerCase() == 'input' && element.getAttribute( 'type' ) == 'button';
};
YAHOO.UP.form.disable = function( element )
{
	element.disabled = true;
	YAHOO.util.Dom.addClass( element, 'disabled' );
};
YAHOO.UP.form.enable = function( element )
{
	element.disabled = false;
	YAHOO.util.Dom.removeClass( element, 'disabled' );
};

YAHOO.UP.form.quickDateModify = function( e, arg )
{
	var dateElement = arg[ 'date' ];
	var timeElement = arg[ 'time' ];
	var timeZoneElement = arg[ 'zone' ];

	//if( dateValue != null && dateValue == '' && timeValue != null & timeValue == '' )
	/* if date or time already exists, modify those? */
	var now = new Date();
	if( arg[ 'minutes' ] )
	{
		now.setTime( now.getTime() + arg[ 'minutes' ] * 60 * 1000 );
	}

	if( dateElement )
	{
		if( arg[ 'dateOverride' ] ) YAHOO.UP.validation.setValue( dateElement, arg[ 'dateOverride' ] );
		else YAHOO.UP.validation.setValue( dateElement, YAHOO.UP.util.Date.padFormat( now.getDate(), now.getMonth() + 1, now.getFullYear() ), true );
	}

	if( timeElement )
	{
		if( arg[ 'timeOverride' ] ) YAHOO.UP.validation.setValue( dateElement, arg[ 'timeOverride' ] );
		else YAHOO.UP.validation.setValue( dateElement, YAHOO.UP.util.Time.padFormat( now.getHours(), now.getMinutes() ), true );
	}

	if( timeZoneElement )
	{
		if( arg[ 'timeZoneOverride' ] ) YAHOO.UP.validation.setValue( dateElement, arg[ 'timeZoneOverride' ] );
		else YAHOO.UP.util.Time.defaultTimeZone( timeZoneElement );
	}
};

