$extend( SK, {

	initSiteEnquiry: function()
	{
		if ( !$( 'form_contact' ) )
			return;
			
		$( 'form_contact_sendAnother' ).addEvent( 'click', function( e ) {
			$( 'form_contact' ).show();
			$( 'form_contact_success' ).hide();
		});
		
		$( 'form_contact' ).addEvent( 'submit', function(e) {
			
			e.stop();
			
			// Define data
			var data = {
				contactName: $( 'form_contact_contactName' ).value,
				emailAddress: $( 'form_contact_emailAddress' ).value,
				phoneNumber: $( 'form_contact_phoneNumber' ).value,
				message: $( 'form_contact_message' ).value,
				weddingDate: $( 'form_contact_weddingDate' ).value
			};
			
			
			// Check values
   			if ( data.contactName == 'Full name' || !data.contactName )
   				data.contactName = '';
			
			if ( !/^[\w\-]+(\.[\w\-]+)*@[\w\-]+\.([\w\-]+\.)*[a-z]{2,}$/i.test( data.emailAddress ) )
			{
				alert( 'That is not a valid email address, please try again.' );
				$( 'form_contact_emailAddress' ).focus();
				return;
			}
			
			if ( data.message == 'Brief message' || !data.message )
				data.message = '';
			
			
			// Send name string as summary
			data.name = data.contactName + ' - ' + ( data.message > 250 ? data.message.slice( 0, 250 ) + '...' : data.message );
			
			
			// Validate fields
			if ( !SK.FormTools.validateFields( data, {
					'contactName': 'Please enter your full name before trying to send the form.',
					'message': 'Please enter your message before trying to send the form.'
				}))
				return;
			
			
			$( 'form_contact_submit' ).set( 'value', '...' ).set( 'disabled', true );
				
			
			Aurora.callAPI({
				
				key: 'create enquiry',
				data: data,
				
				onComplete: function( rtnData ) {
					
					$( 'form_contact_submit' ).set( 'value', 'Submit' ).set( 'disabled', false );
					
					if ( rtnData.success )
					{
						if( data.weddingDate.length )
						{
							$( 'success_message' ).set( 'html', 'we look forward to meeting you and hope to make ' + rtnData.data.weddingDate + '  the most amazing day you can imagine!' );
						}	
						else
						{					
							$( 'success_message' ).set( 'html', 'your message has been sent.' );
						}

						$( 'form_contact_success' ).show();
						$( 'form_contact' ).hide();
						
						$( 'form_contact_success_contactName' ).set( 'html', rtnData.data.contactName );
						
						var clearFields = [ 'contactName', 'emailAddress', 'phoneNumber', 'message', 'weddingDate' ];
						
						clearFields.each( function( field ) {
						
							$( 'form_contact_' + field ).set( 'value', '' ).fireEvent( 'blur' );
						
						});					
					}
					else
					{
						alert( "Sorry, there was an error sending your message. Please reload the page and try again.\n\nIf you continue to get this message, please get in contact with us." );
						return;
					}
					
				}
				
			});
			
		});
	
	}

});

window.addEvent( 'domready', function() {

	SK._initHooks = [ SK.initSiteEnquiry() ];

});