var registroProcess = {
	initRegistro: function(){
		this.eventosPais()
		this.iniciarPluginSelect()
		this.eventoAfiliacion()
		this.validacion_claves(1)
		this.validar_nombre_usuario()
		this.validar_password_seguro();
		this.validar_identidad()
		this.registrarAfiliado()
    this.filtrar_caracteres()
	},
	registrarAfiliado: function(){
    var IdiomaJavaScript = procesosGeneralesMillennium.varIdiomaJavaScript()
    $("form[name=FormRegistrarUsuario]").submit(function(event){
      event.preventDefault()

      var captcha_resp =  $("#g-recaptcha-response").val();
      $("input[name=valCaptcha]").val(captcha_resp);

      procesosGeneralesMillennium.desactivarBoton('buttonCrearCuenta');

      $.ajax({
        type: "POST",
        dataType: "json",
        url: "includes/ajax_registro.php", 
        data: $("form[name=FormRegistrarUsuario]").serialize(),
        success: function(result){
          if(result.rps){
            if(result.respuesta.tipo_registro){
              window.location='registro-pago-'+result.respuesta.usuario;
            }else{
              swal({
                title: IdiomaJavaScript.javascript_text_132,
                text: result.mensaje,
                type: 'success',
                confirmButtonColor: '#3085d6',
                confirmButtonText: 'Ok!',
                allowOutsideClick: false
              }).then(function(){
                  window.location='registro-bienvenida-'+result.respuesta.usuario;
              })
            }
          }else{
            ((result.respuesta.error==1)? $("#usuario").focus():'');
            ((result.respuesta.error==2)? $("#clave").focus():'');
            ((result.respuesta.error==3)? $("#identidad").focus():'');
            ((result.respuesta.error==6)? $("#politica").focus():'');
            ((result.respuesta.error==7)? $("#email").focus():'');
            ((result.respuesta.error==8)? $("#campo_adicional1").focus():'');
            ((result.respuesta.error==9)? $("#campo_adicional2").focus():'');
            ((result.respuesta.error==10)? $("#campo_adicional3").focus():'');
            ((result.respuesta.error==11)? $("#campo_adicional4").focus():'');
            ((result.respuesta.error==12)? $("#campo_adicional5").focus():'');
            ((result.respuesta.error==13)? $("#afiliacion").focus():'');
            swal("Disculpe!", result.mensaje, "warning");

            if(result.respuesta.captcha){
              grecaptcha.reset();
            }
          }
        },error: function(XMLHttpRequest, textStatus, errorThrown){ 
          console.log('Se ha producido un problema, por favor contacte con soporte.');
        },complete: function(){
          procesosGeneralesMillennium.activarBoton('buttonCrearCuenta', IdiomaJavaScript.javascript_text_133 );
        }
      });

    })
	},
	eventosPais: function(){
		var self = this

		if($("#pais").length>0){
            $("#pais").change(function(){
            	
               	var pais = $(this).val();
               
               	$.ajax({
                  	type: "POST",
                  	dataType: "json",
                  	url: "includes/ajax_registro.php", 
                  	data: {"case":'recargaDePaises', "pais":pais},
                  	success: function(result){
                     	if(result.rps){
                        	$(".ajax_estado_pais").html(result.respuesta);
                     	}

                     	$("#estado_pais").select2()
                  	},error: function(XMLHttpRequest, textStatus, errorThrown){ 
                     	console.log('Se ha producido un problema, por favor contacte con soporte.');
                  	}
               	});
            });
        }
	},
  filtrar_caracteres: function(){
    $("input[name=usuario]").keypress(function(event){
      
      tecla = (document.all)?event.keyCode : event.which;

      //Tecla de retroceso para borrar, siempre la permite
      if(tecla==8){
        return true;
      }

      // Patron de entrada, en este caso solo acepta numeros y letras
      patron = /[A-Za-z0-9]/;
      tecla_final = String.fromCharCode(tecla);
      return patron.test(tecla_final);
    });
  },
	validar_nombre_usuario: function(){

		//Validar Usuario
    $("input[name=usuario]").blur(function(){
      var usuario = $(this).val().trim();
      usuario = usuario.replace(/\s/g, '').toLowerCase();

      $.ajax({
        type: "POST",
        dataType: "json",
        url: "includes/ajax_registro.php", 
        data: {"case":'ValidarUsuarioRegistro', "usuario":usuario},
        success: function(result){
          if(result.rps){
            $(".alert-0").removeClass('text-danger').addClass('text-success').html(result.mensaje);
          }else{
            $(".alert-0").removeClass('text-success').addClass('text-danger').html(result.mensaje);
          } 

          $("#usuario").val(usuario);
        },error: function(XMLHttpRequest, textStatus, errorThrown){ 
          console.log('Se ha producido un problema, por favor contacte con soporte.')
        }
      });
    }); 
	},
	validar_identidad:function(){
		$("input[name=identidad]").blur(function(){
            var identidad = $(this).val().trim();
            identidad = identidad.replace(/\s/g, '');

            $.ajax({
               	type: "POST",
               	dataType: "json",
               	url: "includes/ajax_registro.php", 
               	data: {"case":'ValidarIdentidadRegistro', "identidad":identidad},
               	success: function(result){
                  	if(result.rps){
                     	$(".alert-3").removeClass('text-danger').addClass('text-success').html(result.mensaje);
                  	}else{
                     	$(".alert-3").removeClass('text-success').addClass('text-danger').html(result.mensaje);
                } 

                $("#identidad").val(identidad);

               	},error: function(XMLHttpRequest, textStatus, errorThrown){ 
                  	console.log('Se ha producido un problema, por favor contacte con soporte.')
               }
            });
        }); 
	},
	validar_password_seguro: function(){
		var self = this

		$("input[name=clave]").blur(function(){
            var clave = $(this).val();
           
            $.ajax({
               	type: "POST",
               	dataType: "json",
               	url: "includes/ajax_registro.php", 
               	data: {"case":'ValidarClaveSeguraRegistro', "clave":clave},
               	success: function(result){
                  	if(result.rps){
                     	$(".alert-1").removeClass('text-danger').addClass('text-success').html(result.mensaje);
                  	}else{
                     	$(".alert-1").removeClass('text-success').addClass('text-danger').html(result.mensaje);
                  	}

                  	self.validacion_claves(2)
               	},error: function(XMLHttpRequest, textStatus, errorThrown){ 
                  	console.log('Se ha producido un problema, por favor contacte con soporte.')
               	}
            });
        }); 
	},
	validacion_claves: function(modo = 1){
		var self = this

		switch(modo){
		    case 1:
		        $("input[name=repita_clave]").blur(function(){
		        	var rep_clave 	= $(this).val();
		        	self.validacion_claves_start(rep_clave)
		        })

		        break;
		    case 2:
		    	var rep_clave 	= $("#repita_clave").val();
		        self.validacion_claves_start(rep_clave)
		        break;
		}
	},
	validacion_claves_start(rep_clave){
    var IdiomaJavaScript = procesosGeneralesMillennium.varIdiomaJavaScript()
        var clave 		= $("#clave").val();
       
        if(rep_clave != clave){
           $(".alert-2").removeClass('text-success').addClass('text-danger').html('<em class="fa fa-close"></em> '+IdiomaJavaScript.javascript_text_134 );
        }else{
           $(".alert-2").text('');
        }
	},
	eventoAfiliacion:function(){
    var IdiomaJavaScript = procesosGeneralesMillennium.varIdiomaJavaScript()
		var self = this

		if($("#pagos_por_afiliacion_detalles").length>0){
            $("select[name=afiliacion]").change(function(){
               //pagos_por_afiliacion_detalles
               var afiliacion = $(this).val();//$("select[name=afiliacion]").val();
               $("#pagos_por_afiliacion_detalles").html('<em class="fa fa-spin fa-spinner"></em> '+IdiomaJavaScript.javascript_text_135);

               	$.ajax({
                  	type: "POST",
                  	dataType: "json",
                  	url: "includes/ajax_registro.php", 
                  	data: {"case":'detallesPagoAfiliacion', "id":afiliacion},
                  	success: function(result){
                     	$("#pagos_por_afiliacion_detalles").fadeOut("slow", function(){
                        $(this).fadeIn().html(result.respuesta);
                      })

                  	},error: function(XMLHttpRequest, textStatus, errorThrown){ 
                     	console.log('Se ha producido un problema, por favor contacte con soporte.');
                  	}
               	});
            })
        }
	},
	iniciarPluginSelect: function(){
		$(document).ready(function(){ 
			if($("#pais").length>0){
				//$("#pais").select2()
			}

			if($("#estado_pais").length>0){
				//$("#estado_pais").select2()
			}

			if($("#afiliacion").length>0){
				//$("#afiliacion").select2()
			}
		})
	}
}

var registrarPagoProcess = {
  initRegistroProcess: function(afiliado){
    this.hideAlert()
    this.validarComprobante()
    this.registrarPago()
    this.cambioMenbresiaMetodoPago(afiliado)
    this.changeAfiliacion()
    this.generarBotonPaypal(afiliado)
    this.generarBotonPayuLatam(afiliado)
    this.generarBotonConekta(afiliado)
    this.generarBotonBitcoin(afiliado)
    this.generarBotonCoinbase(afiliado)
    this.generarBotonEpayco(afiliado)
    this.generarBotonMercadoPago(afiliado)
    this.generarBotonCoinPayments(afiliado)
    this.finalizarBotonAuthorize(afiliado)

    $('#datetimepicker1').datetimepicker({
      viewMode: 'years',
      format: 'YYYY-MM-DD'
    });
  },
  hideAlert: function(){
    $("input[type=radio]").click(function(){
      if($('input[type=radio]:checked').attr('value')==1){
        $(".alert").fadeIn();
        $(".contenido_from_deposito").fadeIn();

        $("select[name=banco]").attr('required','required')
        $("input[name=soporte]").removeAttr('required','required')
        $("input[name=datetimepicker1]").removeAttr('required','required')

      }else{

        $(".alert").fadeOut();
        $(".contenido_from_deposito").fadeOut();

        $("select[name=banco]").removeAttr('required')
        $("input[name=soporte]").removeAttr('required')
        $("input[name=datetimepicker1]").removeAttr('required')
      }



    });
  },
  validarComprobante: function(){
    $("input[name=soporte]").blur(function(){
      var comprobante = $(this).val();

      $(".alert-0").text('');

      if(comprobante!=''){
        $.ajax({
          type: "POST",
          dataType: "json",
          url: "includes/ajax_registro.php", 
          data: {"case":'validarComprobante', "comprobante":comprobante},
          success: function(result){
            if(!result.rps){
              $(".alert-0").text(result.mensaje);
            }
          },error: function(XMLHttpRequest, textStatus, errorThrown){ 
            console.log('Se ha producido un problema, por favor contacte con soporte.');
          }
        });
      }
      
    });
  },
  cambioMenbresiaMetodoPago: function(afiliado){
    var IdiomaJavaScript = procesosGeneralesMillennium.varIdiomaJavaScript()
    $("button[name=CambioDeMembresiaMetodoPay]").click(function(){
        swal({
          type: 'warning',
          title: IdiomaJavaScript.javascript_text_136,
          showCancelButton: true,
          confirmButtonText:IdiomaJavaScript.javascript_text_120,
          cancelButtonText: IdiomaJavaScript.javascript_text_121,
          showLoaderOnConfirm: true,
          preConfirm: () => {
            return new Promise((resolve) => {

                procesosGeneralesMillennium.desactivarBoton('CambioDeMembresiaMetodoPay');
  
                $.ajax({
                  type: "POST",
                  dataType: "json",
                  url: "includes/ajax_registro.php", 
                  data: {"case":"CambiarMetodoMembresia", "usuario":afiliado},
                  success: function(result){
                    if(result.rps){
                      location.reload();
                    }else{
                      swal("Disculpe!", result.mensaje, "warning");

                      procesosGeneralesMillennium.activarBoton('CambioDeMembresiaMetodoPay', IdiomaJavaScript.javascript_text_137);
                    }
                  },error: function(XMLHttpRequest, textStatus, errorThrown){ 
                    console.log('Se ha producido un problema, por favor contacte con soporte.');
                  }
                });
                
            })
          },
          allowOutsideClick: () => !swal.isLoading()
        }).then((result) => {
            
        })
     });
  },
  changeAfiliacion: function(){
    var IdiomaJavaScript = procesosGeneralesMillennium.varIdiomaJavaScript()
    $("form[name=Afiliacion_change]").submit(function(event){
      event.preventDefault()

      swal({
          type: 'warning',
          title: IdiomaJavaScript.javascript_text_136,
          showCancelButton: true,
          confirmButtonText: IdiomaJavaScript.javascript_text_120,
          cancelButtonText: IdiomaJavaScript.javascript_text_121,
          showLoaderOnConfirm: true,
          preConfirm: () => {
            return new Promise((resolve) => {

                procesosGeneralesMillennium.desactivarBoton('Cambiar_Afiliacion');
            
                $.ajax({
                  type: "POST",
                  dataType: "json",
                  url: "includes/ajax_registro.php", 
                  data: $("form[name=Afiliacion_change]").serialize(),
                  success: function(result){
                    if(result.rps){
                      location.reload();
                    }else{
                      swal("Disculpe!", result.mensaje, "warning");

                      procesosGeneralesMillennium.activarBoton('Cambiar_Afiliacion', IdiomaJavaScript.javascript_text_138);
                    }      
                  },error: function(XMLHttpRequest, textStatus, errorThrown){ 
                    console.log('Se ha producido un problema, por favor contacte con soporte.');
                  }
                });  
                
            })
          },
          allowOutsideClick: () => !swal.isLoading()
        }).then((result) => {
            
        })

    });
  },
  registrarPago: function(){
    var IdiomaJavaScript = procesosGeneralesMillennium.varIdiomaJavaScript()
    var self = this

    $("form[name=FormRegistrarPago]").submit(function(event){
      event.preventDefault()

      procesosGeneralesMillennium.desactivarBoton('buttonRegistrarPago');

      $.ajax({
        type: "POST",
        dataType: "json",
        url: "includes/ajax_registro.php", 
        data: $("form[name=FormRegistrarPago]").serialize(),
        success: function(result){
          if(result.rps){

            switch(result.respuesta.tipo){
              case 1:
                  window.location=result.respuesta.redireccion;

                  break;
              case 2:
                  $("form[name=FormRegistrarPago]").html(result.mensaje);
                  $(".PaypalForm").html(result.respuesta.form);
                  $("#formPaypal").submit();

                  break;

              case 3:
                  $("form[name=FormRegistrarPago]").html(result.respuesta.mensaje);
                  $(".PayuLatamForm").html(result.respuesta.form);
                  $("#formPayuLatam").submit();
                break;

              case 4:
                  $("form[name=FormRegistrarPago]").html(result.respuesta.html);
                  indexProcessTwo.fancyBox2()
              break;

              case 5:
                  $("form[name=FormRegistrarPago]").html(result.respuesta.html);
                  self.webSocket(result.respuesta.input_address, result.respuesta.afiliado)
              break;

              case 6:
                 $("form[name=FormRegistrarPago]").html(result.mensaje);
                 $(".Coinbase").html(result.respuesta.html);
                 $("#coinbase").submit();
              break;

              case 7:
                  keypublic = result.respuesta.clavepublica;                        
                        handler = ePayco.checkout.configure({
                           key: keypublic.trim(),
                           test: false
                  });        
                  
                  $("form[name=FormRegistrarPago]").html(result.mensaje);       
                            
                  var data = result.respuesta.data;
                  handler.open(data);
              break;

              case 8:
                  
                  $("form[name=FormRegistrarPago]").html(result.mensaje);
                  setTimeout(function(){ window.location=result.respuesta.form }, 2000);

              break;

              case 9:
                  window.location=result.respuesta.redireccion;
              break;

              case 10:
                  $("form[name=FormRegistrarPago]").html(result.mensaje);
                  $(".CoinPaymentsForm").html(result.respuesta.form);
                  $("#formCoinPayments").submit();
              break;
            }
            
          }else{
            swal({
              title: "Disculpe!",
              type: "warning",
              html: result.mensaje
            });

            procesosGeneralesMillennium.activarBoton('buttonRegistrarPago', IdiomaJavaScript.javascript_text_139);
          }
          
        },error: function(XMLHttpRequest, textStatus, errorThrown){ 
          console.log('Se ha producido un problema, por favor contacte con soporte.');
          procesosGeneralesMillennium.activarBoton('buttonRegistrarPago', IdiomaJavaScript.javascript_text_139);
        },complete: function(){
          
        }
      });
    });
  },
  generarBotonMercadoPago: function(afiliado){
    $("button[name=GenerarBotonPagoMercadoPago]").click(function(){

      $.ajax({
        type: "POST",
        dataType: "json",
        url: "includes/ajax_registro.php", 
        data: {"case":'GenerarBotonPagoMercadoPago',"usuario":afiliado},
        success: function(result){
          if(result.rps){
            setTimeout(function(){ window.location=result.respuesta}, 2000);
          }else{
            $(".generando_boton_afiliado").html(result.respuesta);
          }
        },error: function(XMLHttpRequest, textStatus, errorThrown){ 
          console.log('Se ha producido un problema, por favor contacte con soporte.');
        }
      });
    })
  },
  generarBotonPaypal: function(afiliado){
    $("button[name=GenerarBotonPagoPaypal]").click(function(){

      $.ajax({
        type: "POST",
        dataType: "json",
        url: "includes/ajax_registro.php", 
        data: {"case":'GenerarBotonPagoPaypal',"usuario":afiliado},
        success: function(result){
          if(result.rps){
            $(".generando_boton_afiliado").html(result.respuesta);
          }else{
            $(".generando_boton_afiliado").html(result.respuesta);
          }       
        },error: function(XMLHttpRequest, textStatus, errorThrown){ 
          console.log('Se ha producido un problema, por favor contacte con soporte.');
        }
      });
    })
  },
  generarBotonPayuLatam: function(afiliado){
    $("button[name=GenerarBotonPagoPayuLatam]").click(function(){

      $.ajax({
        type: "POST",
        dataType: "json",
        url: "includes/ajax_registro.php", 
        data: {"case":'GenerarBotonPagoPayuLatam',"usuario":afiliado},
        success: function(result){
          if(result.rps){
            $(".generando_boton_afiliado").html(result.respuesta);
          }else{
            $(".generando_boton_afiliado").html(result.respuesta);
          }
        },error: function(XMLHttpRequest, textStatus, errorThrown){ 
          console.log('Se ha producido un problema, por favor contacte con soporte.');
        }
      });
    })
  },
  generarBotonConekta: function(afiliado){
    $("button[name=GenerarBotonPagoConekta]").click(function(){
          
      $.ajax({
         type: "POST",
         dataType: "json",
         url: "includes/ajax_registro.php", 
         data: {"case":'GenerarBotonPagoConekta0', "usuario":afiliado},
         success: function(result){
            if(result.rps){
               $(".generando_boton_afiliado").html(result.mensaje);
            }else{
               $(".generando_boton_afiliado").html(result.mensaje);
            }
            
         },error: function(XMLHttpRequest, textStatus, errorThrown){ 
            console.log('Se ha producido un problema, por favor contacte con soporte.');
         }
      });
    })
  },
  finalizarBotonAuthorize: function(afiliado){
    $("form[name=card-form]").submit(function(event){
      event.preventDefault();
          
      $.ajax({
         type: "POST",
         dataType: "json",
         url: "includes/ajax_registro.php", 
         data: $("form[name=card-form]").serialize(),
         success: function(result){
            $("form[name=card-form]").html(result.mensaje.texto)
         },error: function(XMLHttpRequest, textStatus, errorThrown){ 
            console.log('Se ha producido un problema, por favor contacte con soporte.');
         }
      });
    })
  },
  generarBotonCoinPayments: function(afiliado){
    $("button[name=GenerarBotonPagoCoinPayments]").click(function(){

      $.ajax({
        type: "POST",
        dataType: "json",
        url: "includes/ajax_registro.php", 
        data: {"case":'GenerarBotonPagoCoinPayments',"usuario":afiliado},
        success: function(result){
          if(result.rps){
            $(".generando_boton_afiliado").html(result.respuesta);
          
          }else{
            $(".generando_boton_afiliado").html(result.respuesta);
          }       
        },error: function(XMLHttpRequest, textStatus, errorThrown){ 
          console.log('Se ha producido un problema, por favor contacte con soporte.');
        }
      });
    })
  },
  generarBotonBitcoin: function(user){
    var self = this

    $("button[name=GenerarBotonPagoBitcoin]").click(function(){
        $.ajax({
          type: "POST",
          dataType: "json",
          url: "includes/ajax_registro.php", 
          data: {"case":'GenerarBotonPagoBitcoin2', "usuario":user},
          success: function(result){

            $("form[name=FormRegistrarPago]").html(result.respuesta.html)

            self.webSocket(result.respuesta.input_address, user);

          },error: function(){ 
            console.log('Se ha producido un problema, por favor contacte con soporte.');
          }
        });
    })
  },
  generarBotonCoinbase: function(user){
    var self = this

    $("button[name=generarBotonCoinbase]").click(function(){
        $.ajax({
          type: "POST",
          dataType: "json",
          url: "includes/ajax_registro.php", 
          data: {"case":'generarBotonCoinbase', "usuario":user},
          success: function(result){

            $(".generando_boton_afiliado").html(result.respuesta);

          },error: function(){ 
            console.log('Se ha producido un problema, por favor contacte con soporte.');
          }
        });
    })
  },
  generarBotonEpayco: function(afiliado){
    $("button[name=GenerarBotonPagoEpayco]").click(function(){

      $.ajax({
        type: "POST",
        dataType: "json",
        url: "includes/ajax_registro.php", 
        data: {"case":'GenerarBotonPagoEpayco',"usuario":afiliado},
        success: function(result){
          if(result.rps){
            $(".generando_boton_afiliado").html(result.respuesta.form_epayco);
          }else{
            $(".generando_boton_afiliado").html(result.respuesta);
          }       
        },error: function(XMLHttpRequest, textStatus, errorThrown){ 
          console.log('Se ha producido un problema, por favor contacte con soporte.');
        }
      });
    })
  },
  accionesConekta: function(conektaOnKeyPublic, orden){
    var self = this
    var IdiomaJavaScript = procesosGeneralesMillennium.varIdiomaJavaScript()
    Conekta.setPublishableKey(conektaOnKeyPublic);

    $("#card-form").submit(function(event){
      var $form = $(this);

      // Previene hacer submit más de una vez
      $form.find("button").prop("disabled", true);

      $("button[name=pagarConekta]").html("<em class=\'fa fa-spin fa-spinner\'></em> "+IdiomaJavaScript.javascript_text_101);

      Conekta.token.create($form, conektaSuccessResponseHandler, conektaErrorResponseHandler);
      //Conekta.Token.create($form, conektaSuccessResponseHandler, conektaErrorResponseHandler); //v5+
      // Previene que la información de la forma sea enviada al servidor
      return false;
    });

    var conektaSuccessResponseHandler = function(token){
      var $form = $("#card-form");
      // Inserta el token_id en la forma para que se envíe al servidor
      $form.append($("<input type=\'hidden\' name=\'conektaTokenId\'>").val(token.id));

      self.accionesConekta2(token.id, orden);
      //$form.get(0).submit();
    };

    var conektaErrorResponseHandler = function(response){
      var $form = $("#card-form");

      /* Muestra los errores en la forma */
      $form.find(".card-errors").text(response.message_to_purchaser);
      $form.find("button").prop("disabled", false);
      $("button[name=pagarConekta]").html(IdiomaJavaScript.javascript_text_140);
    };
  },
  accionesConekta2: function(token, id){
    var IdiomaJavaScript = procesosGeneralesMillennium.varIdiomaJavaScript()
    $.ajax({
      type: "POST",
      dataType: "json",
      url: "includes/ajax_registro.php", 
      data: {"case":'FinalizarCompraConektaPublicoOrden',"token":token, "IdToken":id},
      success: function(result){
        $('#myModalSmall2').modal('hide');
        $("button[name=pagarConekta]").removeAttr('disabled').html(IdiomaJavaScript.javascript_text_140);

        if(result.rps){  
          $(".pagarConekta").fadeOut().html(result.mensaje).fadeIn();
        }else{
          $(".alert").html(result.mensaje);
          $(".errores").fadeIn();
        }
      },error: function(XMLHttpRequest, textStatus, errorThrown){ 
        //alert('Se ha producido un error, por favor contacte con soporte. Evaluador de Captcha');  
      }
    });
  },
  webSocket: function(address, user){

    var self = this

    try{
      ws = new WebSocket('wss://ws.blockchain.info/inv');

      //if (!ws) return;
      ws.onmessage = function(e){
        try{
          ws.close();

          $.ajax({
            type: "POST",
            dataType: "json",
            url: "includes/ajax_registro.php", 
            data: {"case":'GenerarBotonPagoBitcoin2', "usuario":user},
            success: function(result){

              $("form[name=FormRegistrarPago]").html(result.respuesta.html)

              self.webSocket(address, user);

            },error: function(){ 
              console.log('Se ha producido un problema, por favor contacte con soporte.');
            }
          });
        }catch(e){
          console.log(e.data);
        }
      };

      ws.onopen = function(){
        ws.send('{"op":"addr_sub", "addr":"'+address+'"}');
      };
    }catch(e){
      console.log(e);
    }
  }

}