$extend( Page, {
	
	initFields: function( value )
	{
		var $enquiryType = $( 'enquiryType' ),
			$userType = $( 'userType' ),
			$enquiryRegarding = $( 'enquiryRegarding' );
		
		$enquiryType.addEvent( 'change', function() {
		
			var value = this.value;
			
			var options = [ { value: '', label: 'Please Select' } ];
			
			switch( value )
			{
				case 'Complaint':
				
					options.push(
						{ value: 'Member', label: 'Member' },
						{ value: 'Complainant', label: 'Complainant' },
						{ value: 'Other', label: 'Other' }
					);
				
				break;
				
				case 'Membership':
				
					options.push(
						{ value: 'Member', label: 'Member' },
						{ value: 'Prospective Member', label: 'Prospective Member' },
						{ value: 'Other', label: 'Other' }
					);
				
				break;
			}
			
			$userType.empty();
			
			options.each( function(o) {
				new Element( 'option', { html: o.label, label: o.label, value: o.value } ).inject( $userType );
			});
			
			checkCombos();
		
		});
		
		$userType.addEvent( 'change', function() {
			checkCombos();
		});
		
		var checkCombos = function() {
		
			var enquiryType = $enquiryType.value,
				userType = $userType.value;
			
			var options = [ { value: '', label: 'Select' } ];
			
			switch( enquiryType )
			{
				case 'Membership':
				
					switch( userType )
					{
						case 'Prospective Member':
						
							options.push(
								{ value: 'Membership Application' },
								{ value: 'Membership Fees' },
								{ value: 'COSL Rules' },
								{ value: 'COSL Constitution' },
								{ value: 'COSL Guidelines' },
								{ value: 'Feedback' },
								{ value: 'Other' }
							);
						
						break;
						
						case 'Member':
						
							options.push(
								{ value: 'Renewing my Membership' },
								{ value: 'Renewal Fees' },
								{ value: 'COSL Constitution' },
								{ value: 'COSL Rules' },
								{ value: 'Other' },
								{ value: 'Feedback' }
							);
						
						break;
					}
				
				break;
				
				case 'Complaint':
				
					switch( userType )
					{
						case 'Member':
						
							options.push(
								{ value: 'COSL Constitution' },
								{ value: 'COSL Rules' },
								{ value: 'COSL Guidelines' },
								{ value: 'Complaint Process' },
								{ value: 'Other' },
								{ value: 'Complaint Fees' },
								{ value: 'Complaint Follow Up' },
								{ value: 'Complaint Decision' },
								{ value: 'Feedback' }
							);
						
						break;
						
						case 'Complainant':
						
							options.push(
								{ value: 'COSL Rules' },
								{ value: 'COSL Guidelines' },
								{ value: 'Complaint Process' },
								{ value: 'Other' },
								{ value: 'Complaint Follow Up' },
								{ value: 'Complaint Decision' }
							);
						
						break;
					}
				
				break;
			}
			
			$enquiryRegarding.empty();
			
			options.each( function(o) {
				new Element( 'option', { html: ( o.label ? o.label : o.value ), label: o.label, value: o.value } ).inject( $enquiryRegarding );
			});
		
		};
	},
	
	displayWarning: function( errors )
	{
		var warnings = $$( '.validation-warning' );
		
		warnings.hide();
		
		if ( !errors.length )
		{
			$log( 'Page is valid.' );
		}
		else
		{
			warnings.each( function(w) {
				w.show().setOpacity(0);
				(function() {
					w.get( 'tween' ).setOptions({ duration: 500, transition: 'linear' }).start( 'opacity', 1 );
				}).delay( 100 );
			});
		}
	}

});

whenReady(function(){

	Page.initFields();

});
