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

if (!rwoId) {
    swal("Error", "Cannot get Reconditioning Work Order ID.", "error");
    return false;
}

params["reconditioning_wo_id"] = rwoId;

return true;			
		}
	}

	if ( !pageObj.buttonEventAfter[ gid ] ) {
		pageObj.buttonEventAfter[ gid ] = function( result, ctrl, pageObj, proxy, pageid, rowData, row, params ) {
			var ajax = ctrl;
			console.log("Recon to RISP result:", result);

if (!result) {
    swal("Unable to Create RISP", "No response from server. Please check PHP error log.", "error");
    return;
}

if (result.success) {
    swal({
        title: "RISP Created",
        text: result.message,
        icon: "success",
        button: "Open RISP"
    }).then(function () {
        window.location.href = "raw_material_request_edit.php?editid1=" + result.risp_id;
    });
} else {
    swal("Unable to Create RISP", result.message, "error");
}
		}
	}

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

};

