
/* grabbing */
function dlproap_trigger_grab( url ) {
	jQuery( "#poststuff #dlproap_source" ).val( url );
	dlproap_js_grab();
}

function dlproap_js_grab() {
	var target       = document.URL;
	var url_position = jQuery( "#dlproap_source" ).offset().top - 100;

	var url = jQuery( "#dlproap_source" ).val();
	var pageidbool = jQuery( "#pageidbool" ).val();
	if ( url == '' ) {
		alert( "Grabber aborted !, You did not fill any url :(" );
		jQuery( "#dlproap_source" ).attr( 'Please input url here!' ).focus();
		return false;
	}

	jQuery( "html, body" ).animate( { scrollTop: url_position }, "slow" );
	jQuery( "#dlproap_grab_button" ).text( "Wait.." ).prop( "disabled",true );
	jQuery( "#dlproap_source" ).prop( "disabled",true );
	var data = {
		'action':'dlpro_autopost_grab_content',
		'url':url,
		'pageidbool':pageidbool,
	};
	jQuery.ajax(
		{
			data: data,
			type: "POST",
			timeout: 15000,
			url: dlproap_object.ajax_url,
			success:function( res ) {
				if ( res.api_status == 0 ) {
					alert( res.api_message );
					jQuery( "#dlproap_grab_button" ).text( "Grab URL" ).prop( "disabled",false );
					jQuery( "#dlproap_source" ).prop( "disabled",false );
					return false;
				}

				if ( res.title !== '' ) {
					jQuery( "input[name=post_title]" ).val( res.title ).blur(); 
				} 

				jQuery( "#dlproap_grab_button" ).text( "Grab URL" ).prop( "disabled",false );
				jQuery( "#dlproap_source" ).prop( "disabled",false );

				jQuery('.message_box').html('test'); 
				
				setTimeout(
					function() {
						jQuery( "html, body" ).animate( { scrollTop: 0 }, "slow" );
					},
					600
				);
			},
			error: function(request, status, err) {
				//alert( "Opsss sorry : " + status + " " + err );
				jQuery( "#dlproap_grab_button" ).text( "Grab URL" ).prop( "disabled",false );
				jQuery( "#dlproap_source" ).prop( "disabled",false );
			}
		}
	);
}