// JavaScript Document
var printAreaframeWindow;
(function($) {
    var printAreaCount = 0;
	

    $.fn.printArea = function()
        {
            var ele = $(this);
			var PrintHtmlObj = $(ele).clone();
			$(PrintHtmlObj).find('script').remove();
			
            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;
			$(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") + '" >');
                    });
			doc.write('<div class="' + $(ele).attr("class") + ' printarea" id="' + $(ele).attr("id") + '">' + $(PrintHtmlObj).html() + '</div>');
            doc.close();
			
			printAreaframeWindow = iframe.contentWindow;
           
			
			while($(printAreaframeWindow.document).find('.printarea').length == 0);
			lokObj = $(printAreaframeWindow.document).find('.printarea')
			setTimeout('printAreaframeWindow.focus();printAreaframeWindow.print();printAreaframeWindow.close();',2000);
			/*if($(frameWindow.document).find('.printarea').length == 0)
				alert("EJ OK");
			else
				alert("OK");*/
				
			
			
           
        }	

    var removePrintArea = function(id)
        {
            $( "iframe#" + id ).remove();
        };

})(jQuery);

