function updatePromoIframe(clip) {
  var pr_userid         = $j('#pr_userid').val();
  var pr_id_categorie   = $j('#pr_id_categorie').val();
  var pr_stil           = $j('#pr_stil').val();
  var pr_thumb          = $j('#pr_thumb').val();
  var pr_sort           = $j('#pr_sort').val();
  var pr_items_per_page = $j('#pr_items_per_page').val();
  var pr_titlu          = $j('#pr_titlu').is(':checked') ? 1 : 0;
  var pr_fb_like        = $j('#pr_fb_like').is(':checked') ? 1 : 0;

  $j('#promo_iframe').attr({
    src: "/account/ipromo?userid=" + pr_userid +
    "&pr_id_categorie=" + pr_id_categorie +
    "&pr_stil=" + pr_stil +
    "&pr_thumb=" + pr_thumb +
    "&pr_sort=" + pr_sort +
    "&pr_items_per_page=" + pr_items_per_page +
    "&pr_titlu=" + pr_titlu +
    "&pr_fb_like=" + pr_fb_like
  });

  var iframe_code = '<iframe width="100%" height="100%" frameborder="0" style="border: 1px solid #B4B4B4;" src="http://www.myposter.ro/account/ipromo/userid/' + pr_userid + '/pr_id_categorie/' + pr_id_categorie + '/pr_stil/' + pr_stil + '/pr_thumb/' + pr_thumb + '/pr_sort/' + pr_sort + '/pr_items_per_page/' + pr_items_per_page + '/pr_titlu/' + pr_titlu + '/pr_fb_like/' + pr_fb_like + '" allowtransparency="true"></iframe>';
  $j('#ipromo_code').val(iframe_code);

  clip.setText(iframe_code);
}

$j(document).ready(function() {

  if ($j("#promo_iframe").length > 0) {

    //Create a new clipboard client
    var clip = new ZeroClipboard.Client();
    clip.setHandCursor( true );

    //Grab the text from the textarea
    var txt = $j("#ipromo_code").text();
    clip.setText(txt);

    //Glue the clipboard client to the container div
    var textarea = $j("#ipromo_code_cont");
    clip.glue('ipromo_code', 'ipromo_code_cont');

    //Add a complete event to let the user know the text was copied
    clip.addEventListener('complete', function(client, text) {
      alert("Textul a fost copiat in clipboard.\nAcum puteti face Paste in site-ul Dvs.");
    });

    $j('#pr_userid, #pr_id_categorie, #pr_stil, #pr_thumb, #pr_sort, #pr_items_per_page').change(function() {
      updatePromoIframe(clip);
    });
    $j('#pr_titlu, #pr_fb_like').click(function() {
      updatePromoIframe(clip);
    });

  }

});
