/*
 * File:        TableTools.min.js
 * Version:     2.0.0.dev
 * Author:      Allan Jardine (www.sprymedia.co.uk)
 * 
 * Copyright 2009-2010 Allan Jardine, all rights reserved.
 *
 * This source file is free software, under either the GPL v2 license or a
 * BSD (3 point) style license, as supplied with this software.
 * 
 * This source file is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE. See the license files for details.
 */
var TableToolsInit={oFeatures:{bCsv:true,bXls:true,bCopy:true,bPrint:true},oBom:{bCsv:true,bXls:true},bIncFooter:true,bIncHiddenColumns:false,sPrintMessage:"",sPrintInfo:"<h6>Print view</h6><p>Please use your browser's print function to print this table. Press escape when finished.",sTitle:"",sSwfPath:"media/swf/ZeroClipboard.swf",iButtonHeight:30,iButtonWidth:30,sCsvBoundary:"'",_iNextId:1};
(function(j){function D(p){function E(a){_nTools=document.createElement("div");_nTools.className="TableTools";l=TableToolsInit._iNextId++;g=j.extend(true,{},TableToolsInit);e=a.oDTSettings;F=v(e.nTable,"dataTables_wrapper");ZeroClipboard.moviePath=g.sSwfPath;g.oFeatures.bCopy&&G();g.oFeatures.bCsv&&H();g.oFeatures.bXls&&I();g.oFeatures.bPrint&&J();return _nTools}function H(){var a=document.createElement("div");a.id="ToolTables_CSV_"+l;a.style.height=g.iButtonHeight+"px";a.style.width=g.iButtonWidth+
"px";a.className="TableTools_button TableTools_csv";_nTools.appendChild(a);var b=new ZeroClipboard.Client;b.setHandCursor(true);b.setAction("save");b.setCharSet("UTF8");b.setBomInc(g.oBom.bCsv);b.setFileName(w()+".csv");b.addEventListener("mouseOver",function(){a.className="TableTools_button TableTools_csv_hover"});b.addEventListener("mouseOut",function(){a.className="TableTools_button TableTools_csv"});b.addEventListener("mouseDown",function(){q(b,r(",",TableToolsInit.sCsvBoundary))});o(b,a,"ToolTables_CSV_"+
l,"Save as CSV")}function I(){var a=document.createElement("div");a.id="ToolTables_XLS_"+l;a.style.height=g.iButtonHeight+"px";a.style.width=g.iButtonWidth+"px";a.className="TableTools_button TableTools_xls";_nTools.appendChild(a);var b=new ZeroClipboard.Client;b.setHandCursor(true);b.setAction("save");b.setCharSet("UTF16LE");b.setBomInc(g.oBom.bXls);b.setFileName(w()+".xls");b.addEventListener("mouseOver",function(){a.className="TableTools_button TableTools_xls_hover"});b.addEventListener("mouseOut",
function(){a.className="TableTools_button TableTools_xls"});b.addEventListener("mouseDown",function(){q(b,r("\t"))});o(b,a,"ToolTables_XLS_"+l,"Save for Excel")}function G(){var a=document.createElement("div");a.id="ToolTables_Copy_"+l;a.style.height=g.iButtonHeight+"px";a.style.width=g.iButtonWidth+"px";a.className="TableTools_button TableTools_clipboard";_nTools.appendChild(a);var b=new ZeroClipboard.Client;b.setHandCursor(true);b.setAction("copy");b.addEventListener("mouseOver",function(){a.className=
"TableTools_button TableTools_clipboard_hover"});b.addEventListener("mouseOut",function(){a.className="TableTools_button TableTools_clipboard"});b.addEventListener("mouseDown",function(){q(b,r("\t"))});b.addEventListener("complete",function(){var c=x.split("\n");alert("Copied "+(c.length-1)+" rows to the clipboard")});o(b,a,"ToolTables_Copy_"+l,"Copy to clipboard")}function J(){var a=document.createElement("div");a.style.height=g.iButtonHeight+"px";a.style.width=g.iButtonWidth+"px";a.className="TableTools_button TableTools_print";
a.title="Print table";_nTools.appendChild(a);j(a).hover(function(){a.className="TableTools_button TableTools_print_hover"},function(){a.className="TableTools_button TableTools_print"});j(a).click(function(){y(e.nTable);_iPrintSaveStart=e._iDisplayStart;_iPrintSaveLength=e._iDisplayLength;e._iDisplayStart=0;e._iDisplayLength=-1;e.oApi._fnCalculateEnd(e);e.oApi._fnDraw(e);var b=e.anFeatures;for(var c in b)if(c!="i"&&c!="t"){m.push({node:b[c],display:"block"});b[c].style.display="none"}var d=document.createElement("div");
d.className="TableTools_PrintInfo";d.innerHTML=g.sPrintInfo;document.body.appendChild(d);if(g.sPrintMessage!==""){n=document.createElement("p");n.className="TableTools_PrintMessage";n.innerHTML=g.sPrintMessage;document.body.insertBefore(n,document.body.childNodes[0])}z=j(window).scrollTop();window.scrollTo(0,0);j(document).bind("keydown",null,A);setTimeout(function(){j(d).fadeOut("normal",function(){document.body.removeChild(d)})},2E3)})}function A(a){if(a.keyCode==27){K();window.scrollTo(0,z);if(n){document.body.removeChild(n);
n=null}e._iDisplayStart=_iPrintSaveStart;e._iDisplayLength=_iPrintSaveLength;e.oApi._fnCalculateEnd(e);e.oApi._fnDraw(e);j(document).unbind("keydown",A)}}function K(){for(var a=0,b=m.length;a<b;a++)m[a].node.style.display=m[a].display;m.splice(0,m.length)}function y(a){for(var b=a.parentNode,c=b.childNodes,d=0,h=c.length;d<h;d++)if(c[d]!=a&&c[d].nodeType==1){var k=j(c[d]).css("display");if(k!="none"){m.push({node:c[d],display:k});c[d].style.display="none"}}b.nodeName!="BODY"&&y(b)}function o(a,b,
c,d){document.getElementById(c)?a.glue(b,d):setTimeout(function(){o(a,b,c,d)},100)}function w(){var a;a=g.sTitle!==""?g.sTitle:document.getElementsByTagName("title")[0].innerHTML;return"\u00a1".toString().length<4?a.replace(/[^a-zA-Z0-9_\u00A1-\uFFFF\.,\-_ !\(\)]/g,""):a.replace(/[^a-zA-Z0-9_\.,\-_ !\(\)]/g,"")}function v(a,b){return a.className.match(b)||a.nodeName=="BODY"?a:v(a.parentNode,b)}function s(a,b,c){return b===""?a:b+a.replace(c,"\\"+b)+b}function t(a){a=B(a,2048);var b=document.createElement("div"),
c,d,h,k="";c=0;for(d=a.length;c<d;c++){h=a[c].lastIndexOf("&");if(h!=-1&&a[c].length>=8&&h>a[c].length-8){a[c].substr(h);a[c]=a[c].substr(0,h)}b.innerHTML=a[c];k+=b.childNodes[0].nodeValue}return k}function B(a,b){for(var c=[],d=a.length,h=0;h<d;h+=b)h+b<d?c.push(a.substring(h,h+b)):c.push(a.substring(h,d));return c}function q(a,b){b=B(b,8192);a.clearText();for(var c=0,d=b.length;c<d;c++)a.appendText(b[c])}function r(a,b){var c,d,h,k,i="",f="",C=navigator.userAgent.match(/Windows/)?"\r\n":"\n";if(typeof b==
"undefined")b="";var u=new RegExp(b,"g");c=0;for(d=e.aoColumns.length;c<d;c++)if(g.bIncHiddenColumns===true||e.aoColumns[c].bVisible){f=e.aoColumns[c].sTitle.replace(/\n/g," ").replace(/<.*?>/g,"");if(f.indexOf("&")!=-1)f=t(f);i+=s(f,b,u)+a}i=i.slice(0,a.length*-1);i+=C;h=0;for(k=e.aiDisplay.length;h<k;h++){c=0;for(d=e.aoColumns.length;c<d;c++)if(g.bIncHiddenColumns===true||e.aoColumns[c].bVisible){f=e.aoData[e.aiDisplay[h]]._aData[c];if(typeof f=="string"){f=f.replace(/\n/g," ");f=f.replace(/<img.*?\s+alt\s*=\s*(?:"([^"]+)"|'([^']+)'|([^\s>]+)).*?>/gi,
"$1$2$3");f=f.replace(/<.*?>/g,"")}else f=f+"";f=f.replace(/^\s+/,"").replace(/\s+$/,"");if(f.indexOf("&")!=-1)f=t(f);i+=s(f,b,u)+a}i=i.slice(0,a.length*-1);i+=C}i.slice(0,-1);if(g.bIncFooter){c=0;for(d=e.aoColumns.length;c<d;c++)if(e.aoColumns[c].nTf!==null&&(g.bIncHiddenColumns===true||e.aoColumns[c].bVisible)){f=e.aoColumns[c].nTf.innerHTML.replace(/\n/g," ").replace(/<.*?>/g,"");if(f.indexOf("&")!=-1)f=t(f);i+=s(f,b,u)+a}i=i.slice(0,a.length*-1)}return x=i}var g,F,m=[],z=0,n=null,e,x,l;return E(p)}
typeof j.fn.dataTable=="function"&&typeof j.fn.dataTableExt.sVersion!="undefined"?j.fn.dataTableExt.aoFeatures.push({fnInit:function(p){return new D({oDTSettings:p})},cFeature:"T",sFeature:"TableTools"}):alert("Warning: TableTools requires DataTables 1.5 or greater - www.datatables.net/download")})(jQuery);

