$this = $( '#mod_contactform' ).find( 'form' );

$this.bind( 'click', function(e) {

	$target = $( e.target );
	
	if( $target.hasClass( 'contact-btn' ) ) {
	
		var error = false;
		
		fields = new Array();
		labels = new Array();
	
		$this.find( '.input-row' ).each( function( index ) {
		
			$input_row = $( this );
			$field = $input_row.find( '.contact-field' );
			
			name = $field.attr( 'name' );
			val = $field.val();
			label = $input_row.find( '.contact-label' ).html();
			
			if( $field.attr( 'type' ) == 'checkbox' ) {
			
				label = val;
				val = 'no';
			
				if( $field.attr('checked') ) {
				
					val = 'yes';
				
				}
			
			}
		
			if( $input_row.hasClass( 'req-true' ) ) {
			
				if( val == '' ) {
				
					$input_row.find( '.error' ).fadeIn();
					error = true;
					
				}
			
			}
			
			fields[index] = val;
			labels[index] = label;
		
		});
		
		values = {
			'fields[]': fields,
			'labels[]': labels
		}
		
		if( error == false ) {

			$.post( '/modules/mod_contactform/mod_contactform_ajax.php', values );
			$this.fadeOut( function() {
			
				$( '.contact-success' ).fadeIn();
			
			});
		
		}
	
	}

});
