
(function($) {
    var printAreaCount = 0;

    $.fn.printArea = function()
        {
            var ele = $(this);

            var idPrefix = "printArea_";

            //removePrintArea( idPrefix + printAreaCount );

            //printAreaCount++;

            /*var iframeId = idPrefix + printAreaCount;
            var iframeStyle = 'position:absolute;width:0px;height:0px;left:-500px;top:-500px;';

            iframe = document.createElement('IFRAME');

            $(iframe).attr({ style : iframeStyle,
                             id    : iframeId
                           });

            document.body.appendChild(iframe);

            var doc = iframe.contentWindow.document;*/
			var NewWindow = window.open("", "","width=800,height=600,toolbar=no,directories=no,menubar=no,locations=no,status=no,scrollbars=yes,resizable=no,fullscreen=no");
			NewWindow.document.open();


            $(document).find("link")
                .filter(function(){
                        return $(this).attr("rel").toLowerCase() == "stylesheet";
                    })
                .each(function(){
                        //doc.write('<link type="text/css" rel="stylesheet" href="' + $(this).attr("href") + '" >');
                        NewWindow.document.writeln('<link type="text/css" rel="stylesheet" href="' + $(this).attr("href") + '" >');
                    });
			NewWindow.document.writeln('<div class="' + $(ele).attr("class") + '" style="margin:15px;">' + $(ele).html() + '</div>');
            //doc.write('<div class="' + $(ele).attr("class") + '">' + $(ele).html() + '</div>');
            //doc.close();
			NewWindow.document.close();
			NewWindow.focus();
			NewWindow.print();


            /*var frameWindow = iframe.contentWindow;
            frameWindow.close();
            frameWindow.focus();
            frameWindow.print();*/
        }

    var removePrintArea = function(id)
        {
            $( "iframe#" + id ).remove();
        };

})(jQuery);


