jQuery( function( $ ) {

    $("#sewmr_form_add").click(function(event) {
    	event.preventDefault();

		var name            = $( '#sewmr_form_name' ).val();
		var email            = $( '#sewmr_form_email' ).val();
		var content         = $( '#sewmr_form_content' ).val();
		var content_image   = $( '#sewmr_form_image' ).val();
		var date       	    = $( '#sewmr_form_date' ).val();
		var rating          = $( '#sewmr_form_rating' ).val();
		var approved        = $( '#sewmr_form_approved' ).prop('checked');
		var verified        = $( '#sewmr_form_verified' ).prop('checked');

		var review_data  = {
			action: 'woocommerce_add_manual_review',
			post_id: sewmr_admin_meta_box.post_id,
			name: name,
			email: email,
			content: content,
			content_image: content_image,
			rating: rating,
			approved: Number(approved),
			verified: Number(verified),
			date: date,
			security: sewmr_admin_meta_box.add_manual_review_nonce
		}

		var $wrapper = $( '#sewmr_form' );

		$wrapper.block({
			message: null,
			overlayCSS: {
				background: '#fff',
				opacity: 0.6
			}
		});

		$.post( sewmr_admin_meta_box.ajax_url, review_data, function( response ) {
			if ( response == '-1' ) {
				$wrapper.stop().css("background-color", "#faa").animate( { backgroundColor: "#fff"} , 1500);
			} else {
				$wrapper.stop().css("background-color", "#ceb").animate({ backgroundColor: "#fff"}, 1500);
				$( '#sewmr_form_name' ).val( '' );
				$( '#sewmr_form_email' ).val( '' );
				$( '#sewmr_form_content' ).val( '' );
				$( '#sewmr_form_image' ).val( '' ); 
				$( '#sewmr_form_rating' ).val( '5' );
			}
			$wrapper.unblock();
		});

		return false;

    });

});
