Dialog and Form problem

Dialog and Form problem

Hi.

Have the next problem.

Im open a Dialog with: 
  1. <a href="bitacora.php" data-rel="dialog" >Show</a>
Then this open a Dialog, and this dialog have a form. 
  1. <?PHP
  2. header('Content-Type: text/html; charset=UTF-8'); 

  3. include("modulos/variables.php");
  4. if ($_SESSION['estado'] != "OK")
  5.     header("Location: login.php");
  6. include("sql/sql.php");
  7. include("modulos/funciones.php");
  8. //$norden=$_GET['norden'];
  9. //$ncedula=$_GET['ncedula'];

  10. Conectar();
  11. ?>
  12. <!DOCTYPE html> 
  13. <html> 
  14.     <head>
  15.        
  16.         <meta charset="ISO-8859-1"/>
  17.         <title><?echo $_SESSION['titulo']?></title> 
  18.         <meta name="viewport" content="width=device-width, initial-scale=1"> 


  19.         <link rel="shortcut icon" href="favicon.ico">
  20.         <?include ("modulos/header.php");?>
  21.         <script>
  22.             
  23.             
  24.     $(document).on("pageinit", "#mydialog", function(e) {
  25.         function Validator() {
  26.                 
  27.                 if ($("#nota").val()== "")
  28.                 {
  29.                     alert("No es posible guardar una bitacora en blanco. Por favor escribe algo para poder guardarla");
  30.                     return false;
  31.                     }
  32.                   // $("#popupBasic").popup("open");
  33.                 var frm = $('#miformulariofinal');
  34.                 Formularios(frm);
  35.                 $("#boton1").val("Guardando...");
  36.                 $("#boton1").button("refresh");
  37.                 $("#boton1").parent().hide();
  38.                 $("#nota").parent().hide();
  39.                // $('[type="submit"]').button('disable'); 
  40.                 setTimeout(function () {
  41.                 //    window.location.href = "index.php";
  42.               //   $("#popupBasic").popup("close");
  43.     $("#mydialog").dialog('close');      
  44.     return false;
  45.     }, 2000);
  46.     
  47.     
  48.     
  49.             }
  50.         });
  51.         </script>

  52.         <style>
  53.             .jquery-dialog{ 
  54.   overflow-y: auto;
  55.   overflow-x: auto;
  56.   height: 300px; 
  57. .ui-dialog-contain { 
  58.     max-width: 900px;
  59. }
  60.         </style>
  61.         
  62.         
  63.         
  64.     </head> 
  65.     <body> 
  66.         <div data-role="dialog" id="mydialog" >

  67.             <div data-role="header" data-theme="d">
  68.                 <h1>Bitacora de usuarios</h1>

  69.             </div>
  70. <div data-role="popup" id="popupBasic" data-overlay-theme="b">
  71.                     <p>La bitacora esta siendo guardada... <br>Favor espere...<p>
  72.                 </div>
  73.             <div data-role="content" data-theme="c">
  74.                 <form action="guardabitacora.php" method="POST" data-ajax="false" id="miformulariofinal" name="miformulariofinal">
  75.                     <input type="hidden" name="idpaciente" id="idpaciente" value="<?echo $idpaciente;?>" >
  76.                     <label>Nota:</label>
  77.                     <textarea id="nota" name="nota"></textarea>
  78.                     <input type="submit" id="boton1" value="Guardar anotacion" onclick="javascript: return Validator();">
  79.                 </form>
  80.                 <div class="jquery-dialog">
  81.                     <?php
  82.                     $consul="select * from Bitacora where idusuario='$idpaciente' order by fecha desc";
  83.                     $micon=  mysql_query($consul);
  84.                     while($filas=  mysql_fetch_row($micon))
  85.                     {
  86.                         echo '<div><strong>Fecha:</strong>'.$filas[3].'</div>';
  87.                         echo '<div><strong>Nota:</strong>'.$filas[5].'</div>';
  88.                         echo '<div><strong>Usuario:</strong>'.NombreEmpleado($filas[1]).'</div><hr>';
  89.                     }
  90.                     ?>
  91.                 </div>
  92.             </div>
  93.         </div>
  94.     </body>
  95. </html> 

Next, when im write in the text box and submit the function if call the <a> with: 
data-ajax="false" 
If dont write nothing in the form and close the Dialog with the button, return to the after page (and reaload it) by if t he function  Validator()  work and save the form by close the dialog and realod the after page.

Now if the <a> dont have the data-ajax="false" and close the dialog woth the button close and dont reload the after page, but the function  Validator()  is not recognized, the console show a javascript error "function Validator not found" and the form is procces but open the guardabitacora.php

Then im need:
1. Open the dialog and when close or when submit the form close the dialog but DONT reload the after page.


Thanks form your help and cooperation.