Add javascript in the onclick of a custom button

Hi,

I work with the 7.6 pro version of Sugar and I have added a custom button in the module Quotes that follows the old standard, the 6.7 version. 

I have added the button with this code in the detailviewdefs.php:

'buttons' => 
array (
  0 => 'EDIT',
  1 => 'SHARE',
  2 => 'DUPLICATE',
  3 => 'DELETE',
  4 =>
  array (
    'customCode' => '<form action="index.php" method="POST" name="Quote2Opp" id="form">

            <input id="apriConfiguratoreOfferta" title="apriConfiguratoreOfferta" class="btn" type="button" name="apriConfiguratoreOfferta" value="Apri Configuratore"
            onclick="
            var URL=document.URL;
            var idOfferta = URL.match(\'record=(.*)&\');
            alert(idOfferta[1]);
            sessionStorage.selectedQuoteId=idOfferta[1];
            var arg = \'/Dashboards\';
            var a=app.api.buildURL(arg);
            alert(a);
            function fun(){alert(\'Function call\')};
            fun();
            var homeURL = \'http://localhost/sugarcrm/#Home/3f7529b1-d575-6981-6097-574becea9c9e\';
            var win = window.open(homeURL, \'_self\');

            ">

in the onclick event of the button I want to do some stuff and one of these stuff is the use of a function but, when I declare it, Sugar shows me a 500 error in the browser and it doesn't load the Quotes page.

My problem is that I need to use the function declaration for the callback of an ajax request but in this manner I can't do this.

In the posted code, the error is shown when I insert the 'function fun()' declaration.

Can you help me? 

Thanks

Stefano