Runner.buttonEvents['394099'] = function( pageObj, proxy, pageid ) {
	var gid = '394099';
	//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["production_plan_detail_id"] = row.getFieldValue("production_plan_detail_id");

if (!params["production_plan_detail_id"]) {
    swal("Error", "No Production Plan Detail selected.", "error");
    return false;
}

return confirm("Create Production Work Order for this production plan item?");			
		}
	}

	if ( !pageObj.buttonEventAfter[ gid ] ) {
		pageObj.buttonEventAfter[ gid ] = function( result, ctrl, pageObj, proxy, pageid, rowData, row, params ) {
			var ajax = ctrl;
			if (!result) {
    swal("Error", "No response from server. Please check PHP error log.", "error");
    return;
}

if (result.success) {
    swal({
        title: "Created",
        text: result.message,
        icon: "success",
        button: "OK"
    }).then(function () {
        window.location.href = "production_work_order_edit.php?editid1=" + result.production_work_order_id;
    });
} else {
    swal("Unable to create", result.message, "warning");
}
		}
	}

	$('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 ]} );
	});

};

