// -----------------------------------------------------------------------
// Copyright 1999 Manuel de la Herrán Gascón
// mherran@aircenter.net Madrid (Spain).
// http://www.aircenter.net/gaia
// -----------------------------------------------------------------------
// Este código han sido creado originariamente por Manuel de la Herrán Gascón
// -----------------------------------------------------------------------
// Otras contribuciones / Contributed by
// (Tu nombre aquí / Your name here)
// -----------------------------------------------------------------------
// DO NOT REMOVE THIS COPYRIGHT LINES!
// You can copy and paste this code in your own web pages, if you keep this lines.
// You can modify, distribute and sell this code, but keep the copyright lines
// and add your name in "Contributed by". If you are interested in just some 
// special procedures, copy them, and you don't have to keep this lines.
// ¡NO QUITAR ESTAS LINEAS DE COPYRIGHT!
// Puedes copiar y pegar este código en tus propias páginas web, pero manten estas lineas.
// Puedes modificar, distribuir y vender este código, manteniendo las lineas de
// copyright e incluyendo tu nombre en "Otras contribuciones". Si sólo estás
// interesando en unas rutinas, copialas y no hace falta que mantengas estas lineas.
// -----------------------------------------------------------------------
// This program is provided "as is" without any express or implied warranties.
// The author assumes no responsibility for errors, omissions or damages
// resulting from the use of it.
// Este programa se distribuye tal cual, si ninguna garantía implícita o explícita
// El autor no asume ninguna responsabilidad por errores, omisiones o daños
// provocados por su uso
// -----------------------------------------------------------------------
  // --------------------------------------------------------------
  function runButtonClick(numberOfTicks,numberOfBirds,numberOfHumans,map) {
    closeWindows();
    currentTime=0;
    totalWorms = 1;
    // He encontrado problemas para convertir los strings de las cajas de texto en números. Este método funciona
    numberOfTicks++;
    numberOfTicks--;
    totalTimes = numberOfTicks;
    numberOfBirds++;
    numberOfBirds--;
    totalBirds = numberOfBirds;
    numberOfHumans++;
    numberOfHumans--;
    totalHumans = numberOfHumans;
    map++;
    map--;
    predefinedMap = map;
    totalAgents=1+totalBirds+totalHumans;

    initWorld();

    switch (predefinedMap){
       case 1 : 
         break;
       case 2 : 
         var mapShapeData = new Array(totalRows);
         for (var i=1; i <= totalRows; i++)
           mapShapeData[i]="Z33323333333332333333";
         mapShapeData[4]="Z22222222222222222222";
         mapShapeData[10]="Z22222222222222222222";
         mapShapeData[14]="Z22222222222222222222";
         // Cargo el temporal mapShapeData en el mapa real mapShape
         loadMapFromShape(mapShapeData);
         break;
       case 3 : 
         var mapShapeData = new Array(totalRows);
         for (var i=1; i <= totalRows; i++)
           mapShapeData[i]="Z33233233333333333333";
         mapShapeData[7]="Z22222222222222222222";
         mapShapeData[10]="Z22222222222222222222";
         mapShapeData[13]="Z22222222222222222222";
         // Cargo el temporal mapShapeData en el mapa real mapShape
         loadMapFromShape(mapShapeData);
         break;
       default :
         alert('ERRORS CONTROL: Error: Mapa no existe');
    }

    updateInitialWorldStatus();
    // Cabecera de la ventana de informe de ejecución
    resultWindow=window.open("",'resultWindow',"scrollbars=yes,dependent,width=300,height=50,menubar=no");
    resultWindow.moveTo(10,150);
    resultWindowIsVisible=true;
    resultWindow.document.writeln('<br>===Begin Report===<br>');
    resultWindow.document.writeln('<BODY bgcolor="#00BF80"><CENTER><BIG><B>Resultados de la Ejecución</B></BIG></CENTER><P>');
    // Ciclos de ejecución
    for (var i=1; i <= totalTimes; i++) {
      //alert('DEBUG: Comienza el ciclo '+i.toString());
      executeAutomata(); }
    // Pie de la ventana de informe de ejecución
    resultWindow.document.writeln('<br>===End Report===<br>');
  }
  // --------------------------------------------------------------
  function descButtonClick() {
    showDescWindow();
  }

