var checkForm = function() {
	var formEl = dojo.byId( 'enquiry_form' );
	var canSubmit = 1;

	if( formEl ) {
		console.log( 'got the id' );
	} else {
		console.log( 'no id' );
		return;
	}

	dojo.require( "dojo.NodeList-fx" );
	dojo.require( "dojo.fx" );

	// setup for when the submit button is clicked
	dojo.query( '#submit_button' ).connect( 'onclick', function(e) {
		console.log( 'we\'re in the onclick' );

		contact_name 	 = dojo.byId( 'contact_name' );
		contact_subject  = dojo.byId( 'contact_subject' );
		contact_email	 = dojo.byId( 'contact_email' );
		contact_phone	 = dojo.byId( 'contact_phone' );
		contact_security = dojo.byId( 'contact_security' );

		contact_name_pass = 1;
		contact_subject_pass = 1;
		contact_email_pass = 1;
		contact_phone_pass = 1;
		contact_security_pass = 1;

		if( contact_name.value.length == 0 ) {
			contact_name_pass = 0;
			var anim = dojo.fadeOut({ node: "validate_contact_name" });
			dojo.connect( anim, "onEnd", function() {
				dojo.byId( "validate_contact_name" ).innerHTML = 'Name field is required';
				dojo.fadeIn({ node: "validate_contact_name" }).play();
			});
			anim.play();
		}
		if( contact_subject.value.length == 0 ) {
			contact_subject_pass = 0;
			var anim = dojo.fadeOut({ node: "validate_contact_subject" });
			dojo.connect( anim, "onEnd", function() {
				dojo.byId( "validate_contact_subject" ).innerHTML = 'Subject field is required';
				dojo.fadeIn({ node: "validate_contact_subject" }).play();
			});
			anim.play();
		}
		if( contact_email.value.length == 0 ) {
			contact_email_pass = 0;
			var anim = dojo.fadeOut({ node: "validate_contact_email" });
			dojo.connect( anim, "onEnd", function() {
				dojo.byId( "validate_contact_email" ).innerHTML = 'Email field is required';
				dojo.fadeIn({ node: "validate_contact_email" }).play();
			});
			anim.play();
		}
		if( contact_phone.value.length == 0 ) {
			contact_phone_pass = 0;
			var anim = dojo.fadeOut({ node: "validate_contact_phone" });
			dojo.connect( anim, "onEnd", function() {
				dojo.byId( "validate_contact_phone" ).innerHTML = 'Contact Phone field is required';
				dojo.fadeIn({ node: "validate_contact_phone" }).play();
			});
			anim.play();
		}
		if( contact_security.value.length == 0 ) {
			contact_security_pass = 0;
			var anim = dojo.fadeOut({ node: "validate_contact_security" });
			dojo.connect( anim, "onEnd", function() {
				dojo.byId( "validate_contact_security" ).innerHTML = 'Security Code is required';
				dojo.fadeIn({ node: "validate_contact_security" }).play();
			});
			anim.play();
		}

		dojo.query( '#contact_name' ).connect( 'onblur', function(e) {
			if( this.value.length > 0 ) {
				dojo.fadeOut({ node: "validate_contact_name", duration: 500 }).play();
				contact_name_pass = 1;
			}
		});
		dojo.query( '#contact_subject' ).connect( 'onblur', function(e) {
			if( this.value.length > 0 ) {
				dojo.fadeOut({ node: "validate_contact_subject", duration: 500 }).play();
				contact_subject_pass = 1;
			}	
		});
		dojo.query( '#contact_email' ).connect( 'onblur', function(e) {
			if( this.value.length > 0 ) {
				dojo.fadeOut({ node: "validate_contact_email", duration: 500 }).play();
				contact_email_pass = 1;
			}
		});
		dojo.query( '#contact_phone' ).connect( 'onblur', function(e) {
			if( this.value.length > 0 ) {
				dojo.fadeOut({ node: "validate_contact_phone", duration: 500 }).play();
				contact_phone_pass = 1;
			}
		});
		dojo.query( '#contact_security' ).connect( 'onblur', function(e) {
			if( this.value.length > 0 ) {
				dojo.fadeOut({ node: "validate_contact_security", duration: 500 }).play();
				contact_security_pass = 1;
			}
		});

		if( (contact_name_pass == 1) && (contact_subject_pass == 1) && (contact_email_pass == 1) && (contact_phone_pass == 1) && (contact_security_pass == 1)) {
			canSubmit = 1;
		} else {
			canSubmit = 0;
		}

		if( canSubmit == 1 ) {
			formEl.submit();
		} else {
			return false;
		}
	});
}

dojo.addOnLoad( checkForm );
