Runner.buttonEvents['66720'] = function( pageObj, proxy, pageid ) {
	var gid = '66720';
	//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;
			// ============================================================
// SAVE APPLICATION CONFIGURATION
// CLIENT BEFORE
// ============================================================

params["environment"] =
    $("#app_environment").val();

params["base_url"] =
    $.trim(
        $("#app_base_url").val()
    );

params["app_is_active"] =
    $("#app_is_active").is(":checked")
        ? 1
        : 0;


// Basic validation

if (
    params["environment"] !== "STAGING" &&
    params["environment"] !== "PRODUCTION"
) {

    alert(
        "Please select a valid environment."
    );

    return false;
}


if (
    params["base_url"] !== "" &&
    !/^https?:\/\//i.test(
        params["base_url"]
    )
) {

    alert(
        "Base URL must start with http:// or https://."
    );

    return false;
}


return true;			
		}
	}

	if ( !pageObj.buttonEventAfter[ gid ] ) {
		pageObj.buttonEventAfter[ gid ] = function( result, ctrl, pageObj, proxy, pageid, rowData, row, params ) {
			var ajax = ctrl;
			// ============================================================
// SAVE APPLICATION CONFIGURATION
// CLIENT AFTER
// ============================================================

if (
    result["success"]
) {

    alert(
        result["message"]
    );

    location.reload();

} else {

    alert(
        result["message"]
        ||
        "Unable to save application configuration."
    );

}
		}
	}

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

};

