var timer = null;
function updateimage(){
  var now = new Date().getTime() / 1000;
  $('#image_bg').attr('src','/img.php?nocache=' + now);
}
function changetext(){
		  var txt1 = $.trim($('#txt1').val());
		  var txt2 = $.trim($('#txt2').val());
		  var txt3 = $.trim($('#txt3').val());
		  if (txt1 == '') txt1 = 'DEL';
		  if (txt2 == '') txt2 = 'DEL';
		  if (txt3 == '') txt3 = 'DEL';
		  
      $.post('/set.php',
        {text1: txt1,
         text2: txt2,
         text3: txt3,
         fontid: $('#fontname').val()},
         function(){updateimage()}
      );
}
function changetextt(){
    changetext();
}
function changeprinttype(){
      if ($('#printtype').val() == 2) {$('#texts').show();$('#pics').hide();}
      if ($('#printtype').val() == 1) {$('#texts').hide();$('#pics').show();}
      $.post('/set.php', {printtype: $('#printtype').val()}, function(){updateimage()});
}
jQuery(document).ready(function($){
    changeprinttype();
    $('#image_select').change(function(){
        $.post('/set.php', {imageid: $(this).val()}, function(){updateimage()});
    });
    $('#printtype').change(function(){
        changeprinttype();
    });
    $('#fontname').change(function(){
        $.post('/set.php', {fontid: $('#fontname').val()}, function(){updateimage()});
    });
    $('#colorid').change(function(){
        $.post('/set.php', {colorid: $('#colorid').val()}, function(){updateimage()});
    });
    $('.text_fields').change(function(){
        changetext();
    });
    $('.text_fields').keyup(function(){
        if (timer) {
            clearTimeout(timer);
        }
        timer = setTimeout(changetext, 500);
    });
})
