// var token = "THE VALUE OF THE TOKEN"

$(document).delegate('#tshirt_color', "change", function () {
  $(".front").removeClass("black navy city-green charcoal chocolate white natural")
  $(".front").addClass($(this).val());
})

var waiter = function (v) {
  if (v.status == 1) {
      setTimeout ("wait_tshirt(token); ", 1000); 
  } else if (v.status == 2) {
    window.location.replace(v.url);
  } else if (v.status == 3) {
    $(".errors").html(v.msg);
  }
}

var wait_tshirt = function (token) {
  var res = jQuery.getJSON("/get_status?token=" + token, waiter);
}

$(function () {
  if ($("#waiter").length) {
    wait_tshirt(token);
  }
})

$(document).delegate(".possible-choice input", "change", function () {
  $(".front").removeClass("tshirt-1 tshirt-2 tshirt-3").addClass("tshirt-" + $(this).val());
  $(".logo img").attr("src", "../images/tshirt-" + $(this).val() + ".png");
})



// Update the QR code in real time 
var imgwaiter = function (v) {
  $(".qrcode img").attr("src", v.uri); 
}

$(document).delegate ('#tshirt_username', "keyup", function () {
    $("#tshirt_username_bis").val ( $(this).val() ); 
  var qr = jQuery.getJSON("/preview?username=" + ($(this).val()), imgwaiter);
});

$(document).delegate ('#tshirt_username_bis', "keyup", function () {
    $("#tshirt_username").val ( $(this).val() ); 
     var qr = jQuery.getJSON("/preview?username=" + ($(this).val()), imgwaiter);
});

/*
$(document).delegate ('#tshirt_username', "keyup", function () {
  
}); */

/*
$(document).delegate ('#tshirt_username', "change", function () {
  var qr = jQuery.getJSON("/preview?username=" + ($(this).val()), imgwaiter);
}); */
