text: function Captcha() {
      var alpha = new Array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');
      var i;
      for (i = 0; i < 6; i++) {
          var a = alpha[Math.floor(Math.random() * alpha.length)];
          var b = alpha[Math.floor(Math.random() * alpha.length)];
          var c = alpha[Math.floor(Math.random() * alpha.length)];
          var d = alpha[Math.floor(Math.random() * alpha.length)];
          var e = alpha[Math.floor(Math.random() * alpha.length)];
          var f = alpha[Math.floor(Math.random() * alpha.length)];
          var g = alpha[Math.floor(Math.random() * alpha.length)];
      }
      var code = a + ' ' + b + ' ' + ' ' + c + ' ' + d + ' ' + e + ' ' + f + ' ' + g;
      CreaIMG(code);                  //linea cambiada llamando a la función para crear la imagen en un canvas
  }
  
  function ValidCaptcha(mainCaptcha, txtInput) {
      var string1 = removeSpaces(getElementValue(mainCaptcha));
      var string2 = removeSpaces(getElementValue(txtInput));
      if (string1 == string2) {
          return true;
      }
      else {
          Captcha(mainCaptcha);
          return false;
      }
  }
  function removeSpaces(string) {
      return string.split(' ').join('');
  }
  
  function CreaIMG(texto) {
      var ctxCanvas = document.getElementById('captcha').getContext('2d');
      document.getElementById("mainCaptcha").textContent = texto;
      var fontSize = "30px";
      var fontFamily = "Arial";
      var width = 250;
      var height = 50;
      //tamaño
      ctxCanvas.canvas.width = width;
      ctxCanvas.canvas.height = height;
      //color de fondo
      ctxCanvas.fillStyle = "whitesmoke";
      ctxCanvas.fillRect(0, 0, width, height);
      //puntos de distorsion
      ctxCanvas.setLineDash([7, 10]);
      ctxCanvas.lineDashOffset = 5;
      ctxCanvas.beginPath();
      var line;
      for (var i = 0; i < (width); i++) {
          line = i * 5;
          ctxCanvas.moveTo(line, 0);
          ctxCanvas.lineTo(0, line);
      }
      ctxCanvas.stroke();
      //formato texto
      ctxCanvas.direction = 'ltr';
      ctxCanvas.font = fontSize + " " + fontFamily;
      //texto posicion
      var x = (width / 9);
      var y = (height / 3) * 2;
      //color del borde del texto
      ctxCanvas.strokeStyle = "yellow";
      ctxCanvas.strokeText(texto, x, y);
      //color del texto
      ctxCanvas.fillStyle = "red";
      ctxCanvas.fillText(texto, x, y);
  }