Runner.buttonEvents['396363'] = function( pageObj, proxy, pageid ) {
	var gid = '396363';
	//register a new button
	pageObj.buttonNames[ pageObj.buttonNames.length ] = gid;
		
	if ( !pageObj.buttonEventBefore[ gid ] ) {
		pageObj.buttonEventBefore[ gid ] = function( params, ctrl, pageObj, proxy, pageid, rowData, row, submit ) {		
			var ajax = ctrl;
			params["dispatch_plan_id"] = keys["dispatch_plan_id"];

return confirm("Create Delivery Receipt for this Dispatch Plan?");			
		}
	}

	if ( !pageObj.buttonEventAfter[ gid ] ) {
		pageObj.buttonEventAfter[ gid ] = function( result, ctrl, pageObj, proxy, pageid, rowData, row, params ) {
			var ajax = ctrl;
			if (result && result.success) {
    Runner.displayPopup({
        header: "Success",
        body: result.message
    });

    setTimeout(function() {
        location.reload();
    }, 1000);

} else {
    Runner.displayPopup({
        header: "Error",
        body: result && result.message ? result.message : "Unable to create Delivery Receipt."
    });
}
		}
	}

	$('a[data-event=' + gid + ']').each( function() {
		if ( $(this).closest('.gridRowAdd').length ) {
			return;
		}
		var rowId = Runner.genId();
		var eventId = gid + "_" + rowId;
		$(this).attr( 'data-event', eventId );
		this.id = this.id + "_" + Runner.genId();
		var buttonObj = new Runner.form.Button({
			id: eventId,
			btnName: gid
		});
		buttonObj.init( {args: [ pageObj, proxy, pageid ]} );
	});

};

