// Open an new poup window with the current document and style it in the print layout (media type = "print").

function printPopUp()
{           
  $(document).ready( function(){
	 $("a[rel='printpreview']").click(function (){
	   var args = "height=700,width=800,scrollTo,resizable=1,scrollbars=1,location=0";
     var popup = window.open(this.href, 'printpreview', args);
     $(popup.document).ready(function(){
        setTimeout(function(){copyContent(popup)}, 50);
      });
      return false;
 		});
  });
  
  function copyContent(popup)
  {
      if (popup.document.body == null)
      {
        setTimeout(function(){copyContent(popup)}, 50);
      }
      else
      {
        var screen = $(document.body).clone(true);
        var print = $("#print_content", popup.document);
        if (print.length == 0)
        {
          setTimeout(function(){copyContent(popup)}, 50);
        }
        else
        {
          $(print).html($(screen).html());
          popup.print();
        }
      }
  }
}
