1/*
2 * File:        jquery.dataTables.js
3 * Version:     1.8.2
4 * Description: Paginate, search and sort HTML tables
5 * Author:      Allan Jardine (www.sprymedia.co.uk)
6 * Created:     28/3/2008
7 * Language:    Javascript
8 * License:     GPL v2 or BSD 3 point style
9 * Project:     Mtaala
10 * Contact:     allan.jardine@sprymedia.co.uk
11 *
12 * Copyright 2008-2011 Allan Jardine, all rights reserved.
13 *
14 * This source file is free software, under either the GPL v2 license or a
15 * BSD style license, as supplied with this software.
16 *
17 * This source file is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the license files for details.
20 *
21 * For details please refer to: http://www.datatables.net
22 */
23
24/*
25 * When considering jsLint, we need to allow eval() as it it is used for reading cookies
26 */
27/*jslint evil: true, undef: true, browser: true */
28/*globals $, jQuery,_fnExternApiFunc,_fnInitialise,_fnInitComplete,_fnLanguageProcess,_fnAddColumn,_fnColumnOptions,_fnAddData,_fnCreateTr,_fnGatherData,_fnBuildHead,_fnDrawHead,_fnDraw,_fnReDraw,_fnAjaxUpdate,_fnAjaxParameters,_fnAjaxUpdateDraw,_fnServerParams,_fnAddOptionsHtml,_fnFeatureHtmlTable,_fnScrollDraw,_fnAdjustColumnSizing,_fnFeatureHtmlFilter,_fnFilterComplete,_fnFilterCustom,_fnFilterColumn,_fnFilter,_fnBuildSearchArray,_fnBuildSearchRow,_fnFilterCreateSearch,_fnDataToSearch,_fnSort,_fnSortAttachListener,_fnSortingClasses,_fnFeatureHtmlPaginate,_fnPageChange,_fnFeatureHtmlInfo,_fnUpdateInfo,_fnFeatureHtmlLength,_fnFeatureHtmlProcessing,_fnProcessingDisplay,_fnVisibleToColumnIndex,_fnColumnIndexToVisible,_fnNodeToDataIndex,_fnVisbleColumns,_fnCalculateEnd,_fnConvertToWidth,_fnCalculateColumnWidths,_fnScrollingWidthAdjust,_fnGetWidestNode,_fnGetMaxLenString,_fnStringToCss,_fnArrayCmp,_fnDetectType,_fnSettingsFromNode,_fnGetDataMaster,_fnGetTrNodes,_fnGetTdNodes,_fnEscapeRegex,_fnDeleteIndex,_fnReOrderIndex,_fnColumnOrdering,_fnLog,_fnClearTable,_fnSaveState,_fnLoadState,_fnCreateCookie,_fnReadCookie,_fnDetectHeader,_fnGetUniqueThs,_fnScrollBarWidth,_fnApplyToChildren,_fnMap,_fnGetRowData,_fnGetCellData,_fnSetCellData,_fnGetObjectDataFn,_fnSetObjectDataFn*/
29
30(function($, window, document) {
31	/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
32	 * Section - DataTables variables
33	 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
34
35	/*
36	 * Variable: dataTableSettings
37	 * Purpose:  Store the settings for each dataTables instance
38	 * Scope:    jQuery.fn
39	 */
40	$.fn.dataTableSettings = [];
41	var _aoSettings = $.fn.dataTableSettings; /* Short reference for fast internal lookup */
42
43	/*
44	 * Variable: dataTableExt
45	 * Purpose:  Container for customisable parts of DataTables
46	 * Scope:    jQuery.fn
47	 */
48	$.fn.dataTableExt = {};
49	var _oExt = $.fn.dataTableExt;
50
51
52	/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
53	 * Section - DataTables extensible objects
54	 *
55	 * The _oExt object is used to provide an area where user defined plugins can be
56	 * added to DataTables. The following properties of the object are used:
57	 *   oApi - Plug-in API functions
58	 *   aTypes - Auto-detection of types
59	 *   oSort - Sorting functions used by DataTables (based on the type)
60	 *   oPagination - Pagination functions for different input styles
61	 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
62
63	/*
64	 * Variable: sVersion
65	 * Purpose:  Version string for plug-ins to check compatibility
66	 * Scope:    jQuery.fn.dataTableExt
67	 * Notes:    Allowed format is a.b.c.d.e where:
68	 *   a:int, b:int, c:int, d:string(dev|beta), e:int. d and e are optional
69	 */
70	_oExt.sVersion = "1.8.2";
71
72	/*
73	 * Variable: sErrMode
74	 * Purpose:  How should DataTables report an error. Can take the value 'alert' or 'throw'
75	 * Scope:    jQuery.fn.dataTableExt
76	 */
77	_oExt.sErrMode = "alert";
78
79	/*
80	 * Variable: iApiIndex
81	 * Purpose:  Index for what 'this' index API functions should use
82	 * Scope:    jQuery.fn.dataTableExt
83	 */
84	_oExt.iApiIndex = 0;
85
86	/*
87	 * Variable: oApi
88	 * Purpose:  Container for plugin API functions
89	 * Scope:    jQuery.fn.dataTableExt
90	 */
91	_oExt.oApi = { };
92
93	/*
94	 * Variable: aFiltering
95	 * Purpose:  Container for plugin filtering functions
96	 * Scope:    jQuery.fn.dataTableExt
97	 */
98	_oExt.afnFiltering = [ ];
99
100	/*
101	 * Variable: aoFeatures
102	 * Purpose:  Container for plugin function functions
103	 * Scope:    jQuery.fn.dataTableExt
104	 * Notes:    Array of objects with the following parameters:
105	 *   fnInit: Function for initialisation of Feature. Takes oSettings and returns node
106	 *   cFeature: Character that will be matched in sDom - case sensitive
107	 *   sFeature: Feature name - just for completeness :-)
108	 */
109	_oExt.aoFeatures = [ ];
110
111	/*
112	 * Variable: ofnSearch
113	 * Purpose:  Container for custom filtering functions
114	 * Scope:    jQuery.fn.dataTableExt
115	 * Notes:    This is an object (the name should match the type) for custom filtering function,
116	 *   which can be used for live DOM checking or formatted text filtering
117	 */
118	_oExt.ofnSearch = { };
119
120	/*
121	 * Variable: afnSortData
122	 * Purpose:  Container for custom sorting data source functions
123	 * Scope:    jQuery.fn.dataTableExt
124	 * Notes:    Array (associative) of functions which is run prior to a column of this
125	 *   'SortDataType' being sorted upon.
126	 *   Function input parameters:
127	 *     object:oSettings-  DataTables settings object
128	 *     int:iColumn - Target column number
129	 *   Return value: Array of data which exactly matched the full data set size for the column to
130	 *     be sorted upon
131	 */
132	_oExt.afnSortData = [ ];
133
134	/*
135	 * Variable: oStdClasses
136	 * Purpose:  Storage for the various classes that DataTables uses
137	 * Scope:    jQuery.fn.dataTableExt
138	 */
139	_oExt.oStdClasses = {
140		/* Two buttons buttons */
141		"sPagePrevEnabled": "paginate_enabled_previous",
142		"sPagePrevDisabled": "paginate_disabled_previous",
143		"sPageNextEnabled": "paginate_enabled_next",
144		"sPageNextDisabled": "paginate_disabled_next",
145		"sPageJUINext": "",
146		"sPageJUIPrev": "",
147
148		/* Full numbers paging buttons */
149		"sPageButton": "paginate_button",
150		"sPageButtonActive": "paginate_active",
151		"sPageButtonStaticDisabled": "paginate_button paginate_button_disabled",
152		"sPageFirst": "first",
153		"sPagePrevious": "previous",
154		"sPageNext": "next",
155		"sPageLast": "last",
156
157		/* Striping classes */
158		"sStripeOdd": "odd",
159		"sStripeEven": "even",
160
161		/* Empty row */
162		"sRowEmpty": "dataTables_empty",
163
164		/* Features */
165		"sWrapper": "dataTables_wrapper",
166		"sFilter": "dataTables_filter",
167		"sInfo": "dataTables_info",
168		"sPaging": "dataTables_paginate paging_", /* Note that the type is postfixed */
169		"sLength": "dataTables_length",
170		"sProcessing": "dataTables_processing",
171
172		/* Sorting */
173		"sSortAsc": "sorting_asc",
174		"sSortDesc": "sorting_desc",
175		"sSortable": "sorting", /* Sortable in both directions */
176		"sSortableAsc": "sorting_asc_disabled",
177		"sSortableDesc": "sorting_desc_disabled",
178		"sSortableNone": "sorting_disabled",
179		"sSortColumn": "sorting_", /* Note that an int is postfixed for the sorting order */
180		"sSortJUIAsc": "",
181		"sSortJUIDesc": "",
182		"sSortJUI": "",
183		"sSortJUIAscAllowed": "",
184		"sSortJUIDescAllowed": "",
185		"sSortJUIWrapper": "",
186		"sSortIcon": "",
187
188		/* Scrolling */
189		"sScrollWrapper": "dataTables_scroll",
190		"sScrollHead": "dataTables_scrollHead",
191		"sScrollHeadInner": "dataTables_scrollHeadInner",
192		"sScrollBody": "dataTables_scrollBody",
193		"sScrollFoot": "dataTables_scrollFoot",
194		"sScrollFootInner": "dataTables_scrollFootInner",
195
196		/* Misc */
197		"sFooterTH": ""
198	};
199
200	/*
201	 * Variable: oJUIClasses
202	 * Purpose:  Storage for the various classes that DataTables uses - jQuery UI suitable
203	 * Scope:    jQuery.fn.dataTableExt
204	 */
205	_oExt.oJUIClasses = {
206		/* Two buttons buttons */
207		"sPagePrevEnabled": "fg-button ui-button ui-state-default ui-corner-left",
208		"sPagePrevDisabled": "fg-button ui-button ui-state-default ui-corner-left ui-state-disabled",
209		"sPageNextEnabled": "fg-button ui-button ui-state-default ui-corner-right",
210		"sPageNextDisabled": "fg-button ui-button ui-state-default ui-corner-right ui-state-disabled",
211		"sPageJUINext": "ui-icon ui-icon-circle-arrow-e",
212		"sPageJUIPrev": "ui-icon ui-icon-circle-arrow-w",
213
214		/* Full numbers paging buttons */
215		"sPageButton": "fg-button ui-button ui-state-default",
216		"sPageButtonActive": "fg-button ui-button ui-state-default ui-state-disabled",
217		"sPageButtonStaticDisabled": "fg-button ui-button ui-state-default ui-state-disabled",
218		"sPageFirst": "first ui-corner-tl ui-corner-bl",
219		"sPagePrevious": "previous",
220		"sPageNext": "next",
221		"sPageLast": "last ui-corner-tr ui-corner-br",
222
223		/* Striping classes */
224		"sStripeOdd": "odd",
225		"sStripeEven": "even",
226
227		/* Empty row */
228		"sRowEmpty": "dataTables_empty",
229
230		/* Features */
231		"sWrapper": "dataTables_wrapper",
232		"sFilter": "dataTables_filter",
233		"sInfo": "dataTables_info",
234		"sPaging": "dataTables_paginate fg-buttonset ui-buttonset fg-buttonset-multi "+
235			"ui-buttonset-multi paging_", /* Note that the type is postfixed */
236		"sLength": "dataTables_length",
237		"sProcessing": "dataTables_processing",
238
239		/* Sorting */
240		"sSortAsc": "ui-state-default",
241		"sSortDesc": "ui-state-default",
242		"sSortable": "ui-state-default",
243		"sSortableAsc": "ui-state-default",
244		"sSortableDesc": "ui-state-default",
245		"sSortableNone": "ui-state-default",
246		"sSortColumn": "sorting_", /* Note that an int is postfixed for the sorting order */
247		"sSortJUIAsc": "css_right ui-icon ui-icon-triangle-1-n",
248		"sSortJUIDesc": "css_right ui-icon ui-icon-triangle-1-s",
249		"sSortJUI": "css_right ui-icon ui-icon-carat-2-n-s",
250		"sSortJUIAscAllowed": "css_right ui-icon ui-icon-carat-1-n",
251		"sSortJUIDescAllowed": "css_right ui-icon ui-icon-carat-1-s",
252		"sSortJUIWrapper": "DataTables_sort_wrapper",
253		"sSortIcon": "DataTables_sort_icon",
254
255		/* Scrolling */
256		"sScrollWrapper": "dataTables_scroll",
257		"sScrollHead": "dataTables_scrollHead ui-state-default",
258		"sScrollHeadInner": "dataTables_scrollHeadInner",
259		"sScrollBody": "dataTables_scrollBody",
260		"sScrollFoot": "dataTables_scrollFoot ui-state-default",
261		"sScrollFootInner": "dataTables_scrollFootInner",
262
263		/* Misc */
264		"sFooterTH": "ui-state-default"
265	};
266
267	/*
268	 * Variable: oPagination
269	 * Purpose:  Container for the various type of pagination that dataTables supports
270	 * Scope:    jQuery.fn.dataTableExt
271	 */
272	_oExt.oPagination = {
273		/*
274		 * Variable: two_button
275		 * Purpose:  Standard two button (forward/back) pagination
276		 * Scope:    jQuery.fn.dataTableExt.oPagination
277		 */
278		"two_button": {
279			/*
280			 * Function: oPagination.two_button.fnInit
281			 * Purpose:  Initialise dom elements required for pagination with forward/back buttons only
282			 * Returns:  -
283			 * Inputs:   object:oSettings - dataTables settings object
284			 *           node:nPaging - the DIV which contains this pagination control
285			 *           function:fnCallbackDraw - draw function which must be called on update
286			 */
287			"fnInit": function ( oSettings, nPaging, fnCallbackDraw )
288			{
289				var nPrevious, nNext, nPreviousInner, nNextInner;
290
291				/* Store the next and previous elements in the oSettings object as they can be very
292				 * usful for automation - particularly testing
293				 */
294				if ( !oSettings.bJUI )
295				{
296					nPrevious = document.createElement( 'div' );
297					nNext = document.createElement( 'div' );
298				}
299				else
300				{
301					nPrevious = document.createElement( 'a' );
302					nNext = document.createElement( 'a' );
303
304					nNextInner = document.createElement('span');
305					nNextInner.className = oSettings.oClasses.sPageJUINext;
306					nNext.appendChild( nNextInner );
307
308					nPreviousInner = document.createElement('span');
309					nPreviousInner.className = oSettings.oClasses.sPageJUIPrev;
310					nPrevious.appendChild( nPreviousInner );
311				}
312
313				nPrevious.className = oSettings.oClasses.sPagePrevDisabled;
314				nNext.className = oSettings.oClasses.sPageNextDisabled;
315
316				nPrevious.title = oSettings.oLanguage.oPaginate.sPrevious;
317				nNext.title = oSettings.oLanguage.oPaginate.sNext;
318
319				nPaging.appendChild( nPrevious );
320				nPaging.appendChild( nNext );
321
322				$(nPrevious).bind( 'click.DT', function() {
323					if ( oSettings.oApi._fnPageChange( oSettings, "previous" ) )
324					{
325						/* Only draw when the page has actually changed */
326						fnCallbackDraw( oSettings );
327					}
328				} );
329
330				$(nNext).bind( 'click.DT', function() {
331					if ( oSettings.oApi._fnPageChange( oSettings, "next" ) )
332					{
333						fnCallbackDraw( oSettings );
334					}
335				} );
336
337				/* Take the brutal approach to cancelling text selection */
338				$(nPrevious).bind( 'selectstart.DT', function () { return false; } );
339				$(nNext).bind( 'selectstart.DT', function () { return false; } );
340
341				/* ID the first elements only */
342				if ( oSettings.sTableId !== '' && typeof oSettings.aanFeatures.p == "undefined" )
343				{
344					nPaging.setAttribute( 'id', oSettings.sTableId+'_paginate' );
345					nPrevious.setAttribute( 'id', oSettings.sTableId+'_previous' );
346					nNext.setAttribute( 'id', oSettings.sTableId+'_next' );
347				}
348			},
349
350			/*
351			 * Function: oPagination.two_button.fnUpdate
352			 * Purpose:  Update the two button pagination at the end of the draw
353			 * Returns:  -
354			 * Inputs:   object:oSettings - dataTables settings object
355			 *           function:fnCallbackDraw - draw function to call on page change
356			 */
357			"fnUpdate": function ( oSettings, fnCallbackDraw )
358			{
359				if ( !oSettings.aanFeatures.p )
360				{
361					return;
362				}
363
364				/* Loop over each instance of the pager */
365				var an = oSettings.aanFeatures.p;
366				for ( var i=0, iLen=an.length ; i<iLen ; i++ )
367				{
368					if ( an[i].childNodes.length !== 0 )
369					{
370						an[i].childNodes[0].className =
371							( oSettings._iDisplayStart === 0 ) ?
372							oSettings.oClasses.sPagePrevDisabled : oSettings.oClasses.sPagePrevEnabled;
373
374						an[i].childNodes[1].className =
375							( oSettings.fnDisplayEnd() == oSettings.fnRecordsDisplay() ) ?
376							oSettings.oClasses.sPageNextDisabled : oSettings.oClasses.sPageNextEnabled;
377					}
378				}
379			}
380		},
381
382
383		/*
384		 * Variable: iFullNumbersShowPages
385		 * Purpose:  Change the number of pages which can be seen
386		 * Scope:    jQuery.fn.dataTableExt.oPagination
387		 */
388		"iFullNumbersShowPages": 5,
389
390		/*
391		 * Variable: full_numbers
392		 * Purpose:  Full numbers pagination
393		 * Scope:    jQuery.fn.dataTableExt.oPagination
394		 */
395		"full_numbers": {
396			/*
397			 * Function: oPagination.full_numbers.fnInit
398			 * Purpose:  Initialise dom elements required for pagination with a list of the pages
399			 * Returns:  -
400			 * Inputs:   object:oSettings - dataTables settings object
401			 *           node:nPaging - the DIV which contains this pagination control
402			 *           function:fnCallbackDraw - draw function which must be called on update
403			 */
404			"fnInit": function ( oSettings, nPaging, fnCallbackDraw )
405			{
406				var nFirst = document.createElement( 'span' );
407				var nPrevious = document.createElement( 'span' );
408				var nList = document.createElement( 'span' );
409				var nNext = document.createElement( 'span' );
410				var nLast = document.createElement( 'span' );
411
412				nFirst.innerHTML = oSettings.oLanguage.oPaginate.sFirst;
413				nPrevious.innerHTML = oSettings.oLanguage.oPaginate.sPrevious;
414				nNext.innerHTML = oSettings.oLanguage.oPaginate.sNext;
415				nLast.innerHTML = oSettings.oLanguage.oPaginate.sLast;
416
417				var oClasses = oSettings.oClasses;
418				nFirst.className = oClasses.sPageButton+" "+oClasses.sPageFirst;
419				nPrevious.className = oClasses.sPageButton+" "+oClasses.sPagePrevious;
420				nNext.className= oClasses.sPageButton+" "+oClasses.sPageNext;
421				nLast.className = oClasses.sPageButton+" "+oClasses.sPageLast;
422
423				nPaging.appendChild( nFirst );
424				nPaging.appendChild( nPrevious );
425				nPaging.appendChild( nList );
426				nPaging.appendChild( nNext );
427				nPaging.appendChild( nLast );
428
429				$(nFirst).bind( 'click.DT', function () {
430					if ( oSettings.oApi._fnPageChange( oSettings, "first" ) )
431					{
432						fnCallbackDraw( oSettings );
433					}
434				} );
435
436				$(nPrevious).bind( 'click.DT', function() {
437					if ( oSettings.oApi._fnPageChange( oSettings, "previous" ) )
438					{
439						fnCallbackDraw( oSettings );
440					}
441				} );
442
443				$(nNext).bind( 'click.DT', function() {
444					if ( oSettings.oApi._fnPageChange( oSettings, "next" ) )
445					{
446						fnCallbackDraw( oSettings );
447					}
448				} );
449
450				$(nLast).bind( 'click.DT', function() {
451					if ( oSettings.oApi._fnPageChange( oSettings, "last" ) )
452					{
453						fnCallbackDraw( oSettings );
454					}
455				} );
456
457				/* Take the brutal approach to cancelling text selection */
458				$('span', nPaging)
459					.bind( 'mousedown.DT', function () { return false; } )
460					.bind( 'selectstart.DT', function () { return false; } );
461
462				/* ID the first elements only */
463				if ( oSettings.sTableId !== '' && typeof oSettings.aanFeatures.p == "undefined" )
464				{
465					nPaging.setAttribute( 'id', oSettings.sTableId+'_paginate' );
466					nFirst.setAttribute( 'id', oSettings.sTableId+'_first' );
467					nPrevious.setAttribute( 'id', oSettings.sTableId+'_previous' );
468					nNext.setAttribute( 'id', oSettings.sTableId+'_next' );
469					nLast.setAttribute( 'id', oSettings.sTableId+'_last' );
470				}
471			},
472
473			/*
474			 * Function: oPagination.full_numbers.fnUpdate
475			 * Purpose:  Update the list of page buttons shows
476			 * Returns:  -
477			 * Inputs:   object:oSettings - dataTables settings object
478			 *           function:fnCallbackDraw - draw function to call on page change
479			 */
480			"fnUpdate": function ( oSettings, fnCallbackDraw )
481			{
482				if ( !oSettings.aanFeatures.p )
483				{
484					return;
485				}
486
487				var iPageCount = _oExt.oPagination.iFullNumbersShowPages;
488				var iPageCountHalf = Math.floor(iPageCount / 2);
489				var iPages = Math.ceil((oSettings.fnRecordsDisplay()) / oSettings._iDisplayLength);
490				var iCurrentPage = Math.ceil(oSettings._iDisplayStart / oSettings._iDisplayLength) + 1;
491				var sList = "";
492				var iStartButton, iEndButton, i, iLen;
493				var oClasses = oSettings.oClasses;
494
495				/* Pages calculation */
496				if (iPages < iPageCount)
497				{
498					iStartButton = 1;
499					iEndButton = iPages;
500				}
501				else
502				{
503					if (iCurrentPage <= iPageCountHalf)
504					{
505						iStartButton = 1;
506						iEndButton = iPageCount;
507					}
508					else
509					{
510						if (iCurrentPage >= (iPages - iPageCountHalf))
511						{
512							iStartButton = iPages - iPageCount + 1;
513							iEndButton = iPages;
514						}
515						else
516						{
517							iStartButton = iCurrentPage - Math.ceil(iPageCount / 2) + 1;
518							iEndButton = iStartButton + iPageCount - 1;
519						}
520					}
521				}
522
523				/* Build the dynamic list */
524				for ( i=iStartButton ; i<=iEndButton ; i++ )
525				{
526					if ( iCurrentPage != i )
527					{
528						sList += '<span class="'+oClasses.sPageButton+'">'+i+'</span>';
529					}
530					else
531					{
532						sList += '<span class="'+oClasses.sPageButtonActive+'">'+i+'</span>';
533					}
534				}
535
536				/* Loop over each instance of the pager */
537				var an = oSettings.aanFeatures.p;
538				var anButtons, anStatic, nPaginateList;
539				var fnClick = function(e) {
540					/* Use the information in the element to jump to the required page */
541					var iTarget = (this.innerHTML * 1) - 1;
542					oSettings._iDisplayStart = iTarget * oSettings._iDisplayLength;
543					fnCallbackDraw( oSettings );
544					e.preventDefault();
545				};
546				var fnFalse = function () { return false; };
547
548				for ( i=0, iLen=an.length ; i<iLen ; i++ )
549				{
550					if ( an[i].childNodes.length === 0 )
551					{
552						continue;
553					}
554
555					/* Build up the dynamic list forst - html and listeners */
556					var qjPaginateList = $('span:eq(2)', an[i]);
557					qjPaginateList.html( sList );
558					$('span', qjPaginateList).bind( 'click.DT', fnClick ).bind( 'mousedown.DT', fnFalse )
559						.bind( 'selectstart.DT', fnFalse );
560
561					/* Update the 'premanent botton's classes */
562					anButtons = an[i].getElementsByTagName('span');
563					anStatic = [
564						anButtons[0], anButtons[1],
565						anButtons[anButtons.length-2], anButtons[anButtons.length-1]
566					];
567					$(anStatic).removeClass( oClasses.sPageButton+" "+oClasses.sPageButtonActive+" "+oClasses.sPageButtonStaticDisabled );
568					if ( iCurrentPage == 1 )
569					{
570						anStatic[0].className += " "+oClasses.sPageButtonStaticDisabled;
571						anStatic[1].className += " "+oClasses.sPageButtonStaticDisabled;
572					}
573					else
574					{
575						anStatic[0].className += " "+oClasses.sPageButton;
576						anStatic[1].className += " "+oClasses.sPageButton;
577					}
578
579					if ( iPages === 0 || iCurrentPage == iPages || oSettings._iDisplayLength == -1 )
580					{
581						anStatic[2].className += " "+oClasses.sPageButtonStaticDisabled;
582						anStatic[3].className += " "+oClasses.sPageButtonStaticDisabled;
583					}
584					else
585					{
586						anStatic[2].className += " "+oClasses.sPageButton;
587						anStatic[3].className += " "+oClasses.sPageButton;
588					}
589				}
590			}
591		}
592	};
593
594	/*
595	 * Variable: oSort
596	 * Purpose:  Wrapper for the sorting functions that can be used in DataTables
597	 * Scope:    jQuery.fn.dataTableExt
598	 * Notes:    The functions provided in this object are basically standard javascript sort
599	 *   functions - they expect two inputs which they then compare and then return a priority
600	 *   result. For each sort method added, two functions need to be defined, an ascending sort and
601	 *   a descending sort.
602	 */
603	_oExt.oSort = {
604		/*
605		 * text sorting
606		 */
607		"string-asc": function ( a, b )
608		{
609			if ( typeof a != 'string' ) { a = ''; }
610			if ( typeof b != 'string' ) { b = ''; }
611			var x = a.toLowerCase();
612			var y = b.toLowerCase();
613			return ((x < y) ? -1 : ((x > y) ? 1 : 0));
614		},
615
616		"string-desc": function ( a, b )
617		{
618			if ( typeof a != 'string' ) { a = ''; }
619			if ( typeof b != 'string' ) { b = ''; }
620			var x = a.toLowerCase();
621			var y = b.toLowerCase();
622			return ((x < y) ? 1 : ((x > y) ? -1 : 0));
623		},
624
625
626		/*
627		 * html sorting (ignore html tags)
628		 */
629		"html-asc": function ( a, b )
630		{
631			var x = a.replace( /<.*?>/g, "" ).toLowerCase();
632			var y = b.replace( /<.*?>/g, "" ).toLowerCase();
633			return ((x < y) ? -1 : ((x > y) ? 1 : 0));
634		},
635
636		"html-desc": function ( a, b )
637		{
638			var x = a.replace( /<.*?>/g, "" ).toLowerCase();
639			var y = b.replace( /<.*?>/g, "" ).toLowerCase();
640			return ((x < y) ? 1 : ((x > y) ? -1 : 0));
641		},
642
643
644		/*
645		 * date sorting
646		 */
647		"date-asc": function ( a, b )
648		{
649			var x = Date.parse( a );
650			var y = Date.parse( b );
651
652			if ( isNaN(x) || x==="" )
653			{
654			x = Date.parse( "01/01/1970 00:00:00" );
655			}
656			if ( isNaN(y) || y==="" )
657			{
658				y =	Date.parse( "01/01/1970 00:00:00" );
659			}
660
661			return x - y;
662		},
663
664		"date-desc": function ( a, b )
665		{
666			var x = Date.parse( a );
667			var y = Date.parse( b );
668
669			if ( isNaN(x) || x==="" )
670			{
671			x = Date.parse( "01/01/1970 00:00:00" );
672			}
673			if ( isNaN(y) || y==="" )
674			{
675				y =	Date.parse( "01/01/1970 00:00:00" );
676			}
677
678			return y - x;
679		},
680
681
682		/*
683		 * numerical sorting
684		 */
685		"numeric-asc": function ( a, b )
686		{
687			var x = (a=="-" || a==="") ? 0 : a*1;
688			var y = (b=="-" || b==="") ? 0 : b*1;
689			return x - y;
690		},
691
692		"numeric-desc": function ( a, b )
693		{
694			var x = (a=="-" || a==="") ? 0 : a*1;
695			var y = (b=="-" || b==="") ? 0 : b*1;
696			return y - x;
697		}
698	};
699
700
701	/*
702	 * Variable: aTypes
703	 * Purpose:  Container for the various type of type detection that dataTables supports
704	 * Scope:    jQuery.fn.dataTableExt
705	 * Notes:    The functions in this array are expected to parse a string to see if it is a data
706	 *   type that it recognises. If so then the function should return the name of the type (a
707	 *   corresponding sort function should be defined!), if the type is not recognised then the
708	 *   function should return null such that the parser and move on to check the next type.
709	 *   Note that ordering is important in this array - the functions are processed linearly,
710	 *   starting at index 0.
711	 *   Note that the input for these functions is always a string! It cannot be any other data
712	 *   type
713	 */
714	_oExt.aTypes = [
715		/*
716		 * Function: -
717		 * Purpose:  Check to see if a string is numeric
718		 * Returns:  string:'numeric' or null
719		 * Inputs:   mixed:sText - string to check
720		 */
721		function ( sData )
722		{
723			/* Allow zero length strings as a number */
724			if ( typeof sData == 'number' )
725			{
726				return 'numeric';
727			}
728			else if ( typeof sData != 'string' )
729			{
730				return null;
731			}
732
733			var sValidFirstChars = "0123456789-";
734			var sValidChars = "0123456789.";
735			var Char;
736			var bDecimal = false;
737
738			/* Check for a valid first char (no period and allow negatives) */
739			Char = sData.charAt(0);
740			if (sValidFirstChars.indexOf(Char) == -1)
741			{
742				return null;
743			}
744
745			/* Check all the other characters are valid */
746			for ( var i=1 ; i<sData.length ; i++ )
747			{
748				Char = sData.charAt(i);
749				if (sValidChars.indexOf(Char) == -1)
750				{
751					return null;
752				}
753
754				/* Only allowed one decimal place... */
755				if ( Char == "." )
756				{
757					if ( bDecimal )
758					{
759						return null;
760					}
761					bDecimal = true;
762				}
763			}
764
765			return 'numeric';
766		},
767
768		/*
769		 * Function: -
770		 * Purpose:  Check to see if a string is actually a formatted date
771		 * Returns:  string:'date' or null
772		 * Inputs:   string:sText - string to check
773		 */
774		function ( sData )
775		{
776			var iParse = Date.parse(sData);
777			if ( (iParse !== null && !isNaN(iParse)) || (typeof sData == 'string' && sData.length === 0) )
778			{
779				return 'date';
780			}
781			return null;
782		},
783
784		/*
785		 * Function: -
786		 * Purpose:  Check to see if a string should be treated as an HTML string
787		 * Returns:  string:'html' or null
788		 * Inputs:   string:sText - string to check
789		 */
790		function ( sData )
791		{
792			if ( typeof sData == 'string' && sData.indexOf('<') != -1 && sData.indexOf('>') != -1 )
793			{
794				return 'html';
795			}
796			return null;
797		}
798	];
799
800	/*
801	 * Function: fnVersionCheck
802	 * Purpose:  Check a version string against this version of DataTables. Useful for plug-ins
803	 * Returns:  bool:true -this version of DataTables is greater or equal to the required version
804	 *                false -this version of DataTales is not suitable
805	 * Inputs:   string:sVersion - the version to check against. May be in the following formats:
806	 *             "a", "a.b" or "a.b.c"
807	 * Notes:    This function will only check the first three parts of a version string. It is
808	 *   assumed that beta and dev versions will meet the requirements. This might change in future
809	 */
810	_oExt.fnVersionCheck = function( sVersion )
811	{
812		/* This is cheap, but very effective */
813		var fnZPad = function (Zpad, count)
814		{
815			while(Zpad.length < count) {
816				Zpad += '0';
817			}
818			return Zpad;
819		};
820		var aThis = _oExt.sVersion.split('.');
821		var aThat = sVersion.split('.');
822		var sThis = '', sThat = '';
823
824		for ( var i=0, iLen=aThat.length ; i<iLen ; i++ )
825		{
826			sThis += fnZPad( aThis[i], 3 );
827			sThat += fnZPad( aThat[i], 3 );
828		}
829
830		return parseInt(sThis, 10) >= parseInt(sThat, 10);
831	};
832
833	/*
834	 * Variable: _oExternConfig
835	 * Purpose:  Store information for DataTables to access globally about other instances
836	 * Scope:    jQuery.fn.dataTableExt
837	 */
838	_oExt._oExternConfig = {
839		/* int:iNextUnique - next unique number for an instance */
840		"iNextUnique": 0
841	};
842
843
844	/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
845	 * Section - DataTables prototype
846	 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
847
848	/*
849	 * Function: dataTable
850	 * Purpose:  DataTables information
851	 * Returns:  -
852	 * Inputs:   object:oInit - initialisation options for the table
853	 */
854	$.fn.dataTable = function( oInit )
855	{
856		/*
857		 * Function: classSettings
858		 * Purpose:  Settings container function for all 'class' properties which are required
859		 *   by dataTables
860		 * Returns:  -
861		 * Inputs:   -
862		 */
863		function classSettings ()
864		{
865			this.fnRecordsTotal = function ()
866			{
867				if ( this.oFeatures.bServerSide ) {
868					return parseInt(this._iRecordsTotal, 10);
869				} else {
870					return this.aiDisplayMaster.length;
871				}
872			};
873
874			this.fnRecordsDisplay = function ()
875			{
876				if ( this.oFeatures.bServerSide ) {
877					return parseInt(this._iRecordsDisplay, 10);
878				} else {
879					return this.aiDisplay.length;
880				}
881			};
882
883			this.fnDisplayEnd = function ()
884			{
885				if ( this.oFeatures.bServerSide ) {
886					if ( this.oFeatures.bPaginate === false || this._iDisplayLength == -1 ) {
887						return this._iDisplayStart+this.aiDisplay.length;
888					} else {
889						return Math.min( this._iDisplayStart+this._iDisplayLength,
890							this._iRecordsDisplay );
891					}
892				} else {
893					return this._iDisplayEnd;
894				}
895			};
896
897			/*
898			 * Variable: oInstance
899			 * Purpose:  The DataTables object for this table
900			 * Scope:    jQuery.dataTable.classSettings
901			 */
902			this.oInstance = null;
903
904			/*
905			 * Variable: sInstance
906			 * Purpose:  Unique idendifier for each instance of the DataTables object
907			 * Scope:    jQuery.dataTable.classSettings
908			 */
909			this.sInstance = null;
910
911			/*
912			 * Variable: oFeatures
913			 * Purpose:  Indicate the enablement of key dataTable features
914			 * Scope:    jQuery.dataTable.classSettings
915			 */
916			this.oFeatures = {
917				"bPaginate": true,
918				"bLengthChange": true,
919				"bFilter": true,
920				"bSort": true,
921				"bInfo": true,
922				"bAutoWidth": true,
923				"bProcessing": false,
924				"bSortClasses": true,
925				"bStateSave": false,
926				"bServerSide": false,
927				"bDeferRender": false
928			};
929
930			/*
931			 * Variable: oScroll
932			 * Purpose:  Container for scrolling options
933			 * Scope:    jQuery.dataTable.classSettings
934			 */
935			this.oScroll = {
936				"sX": "",
937				"sXInner": "",
938				"sY": "",
939				"bCollapse": false,
940				"bInfinite": false,
941				"iLoadGap": 100,
942				"iBarWidth": 0,
943				"bAutoCss": true
944			};
945
946			/*
947			 * Variable: aanFeatures
948			 * Purpose:  Array referencing the nodes which are used for the features
949			 * Scope:    jQuery.dataTable.classSettings
950			 * Notes:    The parameters of this object match what is allowed by sDom - i.e.
951			 *   'l' - Length changing
952			 *   'f' - Filtering input
953			 *   't' - The table!
954			 *   'i' - Information
955			 *   'p' - Pagination
956			 *   'r' - pRocessing
957			 */
958			this.aanFeatures = [];
959
960			/*
961			 * Variable: oLanguage
962			 * Purpose:  Store the language strings used by dataTables
963			 * Scope:    jQuery.dataTable.classSettings
964			 * Notes:    The words in the format _VAR_ are variables which are dynamically replaced
965			 *   by javascript
966			 */
967			this.oLanguage = {
968				"sProcessing": "Processing...",
969				"sLengthMenu": "Show _MENU_ entries",
970				"sZeroRecords": "No matching records found",
971				"sEmptyTable": "No data available in table",
972				"sLoadingRecords": "Loading...",
973				"sInfo": "Showing _START_ to _END_ of _TOTAL_ entries",
974				"sInfoEmpty": "Showing 0 to 0 of 0 entries",
975				"sInfoFiltered": "(filtered from _MAX_ total entries)",
976				"sInfoPostFix": "",
977				"sInfoThousands": ",",
978				"sSearch": "Search:",
979				"sUrl": "",
980				"oPaginate": {
981					"sFirst":    "First",
982					"sPrevious": "Previous",
983					"sNext":     "Next",
984					"sLast":     "Last"
985				},
986				"fnInfoCallback": null
987			};
988
989			/*
990			 * Variable: aoData
991			 * Purpose:  Store data information
992			 * Scope:    jQuery.dataTable.classSettings
993			 * Notes:    This is an array of objects with the following parameters:
994			 *   int: _iId - internal id for tracking
995			 *   array: _aData - internal data - used for sorting / filtering etc
996			 *   node: nTr - display node
997			 *   array node: _anHidden - hidden TD nodes
998			 *   string: _sRowStripe
999			 */
1000			this.aoData = [];
1001
1002			/*
1003			 * Variable: aiDisplay
1004			 * Purpose:  Array of indexes which are in the current display (after filtering etc)
1005			 * Scope:    jQuery.dataTable.classSettings
1006			 */
1007			this.aiDisplay = [];
1008
1009			/*
1010			 * Variable: aiDisplayMaster
1011			 * Purpose:  Array of indexes for display - no filtering
1012			 * Scope:    jQuery.dataTable.classSettings
1013			 */
1014			this.aiDisplayMaster = [];
1015
1016			/*
1017			 * Variable: aoColumns
1018			 * Purpose:  Store information about each column that is in use
1019			 * Scope:    jQuery.dataTable.classSettings
1020			 */
1021			this.aoColumns = [];
1022
1023			/*
1024			 * Variable: aoHeader
1025			 * Purpose:  Store information about the table's header
1026			 * Scope:    jQuery.dataTable.classSettings
1027			 */
1028			this.aoHeader = [];
1029
1030			/*
1031			 * Variable: aoFooter
1032			 * Purpose:  Store information about the table's footer
1033			 * Scope:    jQuery.dataTable.classSettings
1034			 */
1035			this.aoFooter = [];
1036
1037			/*
1038			 * Variable: iNextId
1039			 * Purpose:  Store the next unique id to be used for a new row
1040			 * Scope:    jQuery.dataTable.classSettings
1041			 */
1042			this.iNextId = 0;
1043
1044			/*
1045			 * Variable: asDataSearch
1046			 * Purpose:  Search data array for regular expression searching
1047			 * Scope:    jQuery.dataTable.classSettings
1048			 */
1049			this.asDataSearch = [];
1050
1051			/*
1052			 * Variable: oPreviousSearch
1053			 * Purpose:  Store the previous search incase we want to force a re-search
1054			 *   or compare the old search to a new one
1055			 * Scope:    jQuery.dataTable.classSettings
1056			 */
1057			this.oPreviousSearch = {
1058				"sSearch": "",
1059				"bRegex": false,
1060				"bSmart": true
1061			};
1062
1063			/*
1064			 * Variable: aoPreSearchCols
1065			 * Purpose:  Store the previous search for each column
1066			 * Scope:    jQuery.dataTable.classSettings
1067			 */
1068			this.aoPreSearchCols = [];
1069
1070			/*
1071			 * Variable: aaSorting
1072			 * Purpose:  Sorting information
1073			 * Scope:    jQuery.dataTable.classSettings
1074			 * Notes:    Index 0 - column number
1075			 *           Index 1 - current sorting direction
1076			 *           Index 2 - index of asSorting for this column
1077			 */
1078			this.aaSorting = [ [0, 'asc', 0] ];
1079
1080			/*
1081			 * Variable: aaSortingFixed
1082			 * Purpose:  Sorting information that is always applied
1083			 * Scope:    jQuery.dataTable.classSettings
1084			 */
1085			this.aaSortingFixed = null;
1086
1087			/*
1088			 * Variable: asStripeClasses
1089			 * Purpose:  Classes to use for the striping of a table
1090			 * Scope:    jQuery.dataTable.classSettings
1091			 */
1092			this.asStripeClasses = [];
1093
1094			/*
1095			 * Variable: asDestroyStripes
1096			 * Purpose:  If restoring a table - we should restore its striping classes as well
1097			 * Scope:    jQuery.dataTable.classSettings
1098			 */
1099			this.asDestroyStripes = [];
1100
1101			/*
1102			 * Variable: sDestroyWidth
1103			 * Purpose:  If restoring a table - we should restore its width
1104			 * Scope:    jQuery.dataTable.classSettings
1105			 */
1106			this.sDestroyWidth = 0;
1107
1108			/*
1109			 * Variable: fnRowCallback
1110			 * Purpose:  Call this function every time a row is inserted (draw)
1111			 * Scope:    jQuery.dataTable.classSettings
1112			 */
1113			this.fnRowCallback = null;
1114
1115			/*
1116			 * Variable: fnHeaderCallback
1117			 * Purpose:  Callback function for the header on each draw
1118			 * Scope:    jQuery.dataTable.classSettings
1119			 */
1120			this.fnHeaderCallback = null;
1121
1122			/*
1123			 * Variable: fnFooterCallback
1124			 * Purpose:  Callback function for the footer on each draw
1125			 * Scope:    jQuery.dataTable.classSettings
1126			 */
1127			this.fnFooterCallback = null;
1128
1129			/*
1130			 * Variable: aoDrawCallback
1131			 * Purpose:  Array of callback functions for draw callback functions
1132			 * Scope:    jQuery.dataTable.classSettings
1133			 * Notes:    Each array element is an object with the following parameters:
1134			 *   function:fn - function to call
1135			 *   string:sName - name callback (feature). useful for arranging array
1136			 */
1137			this.aoDrawCallback = [];
1138
1139			/*
1140			 * Variable: fnPreDrawCallback
1141			 * Purpose:  Callback function for just before the table is redrawn. A return of false
1142			 *           will be used to cancel the draw.
1143			 * Scope:    jQuery.dataTable.classSettings
1144			 */
1145			this.fnPreDrawCallback = null;
1146
1147			/*
1148			 * Variable: fnInitComplete
1149			 * Purpose:  Callback function for when the table has been initialised
1150			 * Scope:    jQuery.dataTable.classSettings
1151			 */
1152			this.fnInitComplete = null;
1153
1154			/*
1155			 * Variable: sTableId
1156			 * Purpose:  Cache the table ID for quick access
1157			 * Scope:    jQuery.dataTable.classSettings
1158			 */
1159			this.sTableId = "";
1160
1161			/*
1162			 * Variable: nTable
1163			 * Purpose:  Cache the table node for quick access
1164			 * Scope:    jQuery.dataTable.classSettings
1165			 */
1166			this.nTable = null;
1167
1168			/*
1169			 * Variable: nTHead
1170			 * Purpose:  Permanent ref to the thead element
1171			 * Scope:    jQuery.dataTable.classSettings
1172			 */
1173			this.nTHead = null;
1174
1175			/*
1176			 * Variable: nTFoot
1177			 * Purpose:  Permanent ref to the tfoot element - if it exists
1178			 * Scope:    jQuery.dataTable.classSettings
1179			 */
1180			this.nTFoot = null;
1181
1182			/*
1183			 * Variable: nTBody
1184			 * Purpose:  Permanent ref to the tbody element
1185			 * Scope:    jQuery.dataTable.classSettings
1186			 */
1187			this.nTBody = null;
1188
1189			/*
1190			 * Variable: nTableWrapper
1191			 * Purpose:  Cache the wrapper node (contains all DataTables controlled elements)
1192			 * Scope:    jQuery.dataTable.classSettings
1193			 */
1194			this.nTableWrapper = null;
1195
1196			/*
1197			 * Variable: bDeferLoading
1198			 * Purpose:  Indicate if when using server-side processing the loading of data
1199			 *           should be deferred until the second draw
1200			 * Scope:    jQuery.dataTable.classSettings
1201			 */
1202			this.bDeferLoading = false;
1203
1204			/*
1205			 * Variable: bInitialised
1206			 * Purpose:  Indicate if all required information has been read in
1207			 * Scope:    jQuery.dataTable.classSettings
1208			 */
1209			this.bInitialised = false;
1210
1211			/*
1212			 * Variable: aoOpenRows
1213			 * Purpose:  Information about open rows
1214			 * Scope:    jQuery.dataTable.classSettings
1215			 * Notes:    Has the parameters 'nTr' and 'nParent'
1216			 */
1217			this.aoOpenRows = [];
1218
1219			/*
1220			 * Variable: sDom
1221			 * Purpose:  Dictate the positioning that the created elements will take
1222			 * Scope:    jQuery.dataTable.classSettings
1223			 * Notes:
1224			 *   The following options are allowed:
1225			 *     'l' - Length changing
1226			 *     'f' - Filtering input
1227			 *     't' - The table!
1228			 *     'i' - Information
1229			 *     'p' - Pagination
1230			 *     'r' - pRocessing
1231			 *   The following constants are allowed:
1232			 *     'H' - jQueryUI theme "header" classes
1233			 *     'F' - jQueryUI theme "footer" classes
1234			 *   The following syntax is expected:
1235			 *     '<' and '>' - div elements
1236			 *     '<"class" and '>' - div with a class
1237			 *   Examples:
1238			 *     '<"wrapper"flipt>', '<lf<t>ip>'
1239			 */
1240			this.sDom = 'lfrtip';
1241
1242			/*
1243			 * Variable: sPaginationType
1244			 * Purpose:  Note which type of sorting should be used
1245			 * Scope:    jQuery.dataTable.classSettings
1246			 */
1247			this.sPaginationType = "two_button";
1248
1249			/*
1250			 * Variable: iCookieDuration
1251			 * Purpose:  The cookie duration (for bStateSave) in seconds - default 2 hours
1252			 * Scope:    jQuery.dataTable.classSettings
1253			 */
1254			this.iCookieDuration = 60 * 60 * 2;
1255
1256			/*
1257			 * Variable: sCookiePrefix
1258			 * Purpose:  The cookie name prefix
1259			 * Scope:    jQuery.dataTable.classSettings
1260			 */
1261			this.sCookiePrefix = "SpryMedia_DataTables_";
1262
1263			/*
1264			 * Variable: fnCookieCallback
1265			 * Purpose:  Callback function for cookie creation
1266			 * Scope:    jQuery.dataTable.classSettings
1267			 */
1268			this.fnCookieCallback = null;
1269
1270			/*
1271			 * Variable: aoStateSave
1272			 * Purpose:  Array of callback functions for state saving
1273			 * Scope:    jQuery.dataTable.classSettings
1274			 * Notes:    Each array element is an object with the following parameters:
1275			 *   function:fn - function to call. Takes two parameters, oSettings and the JSON string to
1276			 *     save that has been thus far created. Returns a JSON string to be inserted into a
1277			 *     json object (i.e. '"param": [ 0, 1, 2]')
1278			 *   string:sName - name of callback
1279			 */
1280			this.aoStateSave = [];
1281
1282			/*
1283			 * Variable: aoStateLoad
1284			 * Purpose:  Array of callback functions for state loading
1285			 * Scope:    jQuery.dataTable.classSettings
1286			 * Notes:    Each array element is an object with the following parameters:
1287			 *   function:fn - function to call. Takes two parameters, oSettings and the object stored.
1288			 *     May return false to cancel state loading.
1289			 *   string:sName - name of callback
1290			 */
1291			this.aoStateLoad = [];
1292
1293			/*
1294			 * Variable: oLoadedState
1295			 * Purpose:  State that was loaded from the cookie. Useful for back reference
1296			 * Scope:    jQuery.dataTable.classSettings
1297			 */
1298			this.oLoadedState = null;
1299
1300			/*
1301			 * Variable: sAjaxSource
1302			 * Purpose:  Source url for AJAX data for the table
1303			 * Scope:    jQuery.dataTable.classSettings
1304			 */
1305			this.sAjaxSource = null;
1306
1307			/*
1308			 * Variable: sAjaxDataProp
1309			 * Purpose:  Property from a given object from which to read the table data from. This can
1310			 *           be an empty string (when not server-side processing), in which case it is
1311			 *           assumed an an array is given directly.
1312			 * Scope:    jQuery.dataTable.classSettings
1313			 */
1314			this.sAjaxDataProp = 'aaData';
1315
1316			/*
1317			 * Variable: bAjaxDataGet
1318			 * Purpose:  Note if draw should be blocked while getting data
1319			 * Scope:    jQuery.dataTable.classSettings
1320			 */
1321			this.bAjaxDataGet = true;
1322
1323			/*
1324			 * Variable: jqXHR
1325			 * Purpose:  The last jQuery XHR object that was used for server-side data gathering.
1326			 *           This can be used for working with the XHR information in one of the callbacks
1327			 * Scope:    jQuery.dataTable.classSettings
1328			 */
1329			this.jqXHR = null;
1330
1331			/*
1332			 * Variable: fnServerData
1333			 * Purpose:  Function to get the server-side data - can be overruled by the developer
1334			 * Scope:    jQuery.dataTable.classSettings
1335			 */
1336			this.fnServerData = function ( url, data, callback, settings ) {
1337				settings.jqXHR = $.ajax( {
1338					"url": url,
1339					"data": data,
1340					"success": function (json) {
1341						$(settings.oInstance).trigger('xhr', settings);
1342						callback( json );
1343					},
1344					"dataType": "json",
1345					"cache": false,
1346					"error": function (xhr, error, thrown) {
1347						if ( error == "parsererror" ) {
1348							alert( "DataTables warning: JSON data from server could not be parsed. "+
1349								"This is caused by a JSON formatting error." );
1350						}
1351					}
1352				} );
1353			};
1354
1355			/*
1356			 * Variable: aoServerParams
1357			 * Purpose:  Functions which are called prior to sending an Ajax request so extra parameters
1358			 *           can easily be sent to the server
1359			 * Scope:    jQuery.dataTable.classSettings
1360			 * Notes:    Each array element is an object with the following parameters:
1361			 *   function:fn - function to call
1362			 *   string:sName - name callback - useful for knowing where it came from (plugin etc)
1363			 */
1364			this.aoServerParams = [];
1365
1366			/*
1367			 * Variable: fnFormatNumber
1368			 * Purpose:  Format numbers for display
1369			 * Scope:    jQuery.dataTable.classSettings
1370			 */
1371			this.fnFormatNumber = function ( iIn )
1372			{
1373				if ( iIn < 1000 )
1374				{
1375					/* A small optimisation for what is likely to be the vast majority of use cases */
1376					return iIn;
1377				}
1378				else
1379				{
1380					var s=(iIn+""), a=s.split(""), out="", iLen=s.length;
1381
1382					for ( var i=0 ; i<iLen ; i++ )
1383					{
1384						if ( i%3 === 0 && i !== 0 )
1385						{
1386							out = this.oLanguage.sInfoThousands+out;
1387						}
1388						out = a[iLen-i-1]+out;
1389					}
1390				}
1391				return out;
1392			};
1393
1394			/*
1395			 * Variable: aLengthMenu
1396			 * Purpose:  List of options that can be used for the user selectable length menu
1397			 * Scope:    jQuery.dataTable.classSettings
1398			 * Note:     This varaible can take for form of a 1D array, in which case the value and the
1399			 *   displayed value in the menu are the same, or a 2D array in which case the value comes
1400			 *   from the first array, and the displayed value to the end user comes from the second
1401			 *   array. 2D example: [ [ 10, 25, 50, 100, -1 ], [ 10, 25, 50, 100, 'All' ] ];
1402			 */
1403			this.aLengthMenu = [ 10, 25, 50, 100 ];
1404
1405			/*
1406			 * Variable: iDraw
1407			 * Purpose:  Counter for the draws that the table does. Also used as a tracker for
1408			 *   server-side processing
1409			 * Scope:    jQuery.dataTable.classSettings
1410			 */
1411			this.iDraw = 0;
1412
1413			/*
1414			 * Variable: bDrawing
1415			 * Purpose:  Indicate if a redraw is being done - useful for Ajax
1416			 * Scope:    jQuery.dataTable.classSettings
1417			 */
1418			this.bDrawing = 0;
1419
1420			/*
1421			 * Variable: iDrawError
1422			 * Purpose:  Last draw error
1423			 * Scope:    jQuery.dataTable.classSettings
1424			 */
1425			this.iDrawError = -1;
1426
1427			/*
1428			 * Variable: _iDisplayLength, _iDisplayStart, _iDisplayEnd
1429			 * Purpose:  Display length variables
1430			 * Scope:    jQuery.dataTable.classSettings
1431			 * Notes:    These variable must NOT be used externally to get the data length. Rather, use
1432			 *   the fnRecordsTotal() (etc) functions.
1433			 */
1434			this._iDisplayLength = 10;
1435			this._iDisplayStart = 0;
1436			this._iDisplayEnd = 10;
1437
1438			/*
1439			 * Variable: _iRecordsTotal, _iRecordsDisplay
1440			 * Purpose:  Display length variables used for server side processing
1441			 * Scope:    jQuery.dataTable.classSettings
1442			 * Notes:    These variable must NOT be used externally to get the data length. Rather, use
1443			 *   the fnRecordsTotal() (etc) functions.
1444			 */
1445			this._iRecordsTotal = 0;
1446			this._iRecordsDisplay = 0;
1447
1448			/*
1449			 * Variable: bJUI
1450			 * Purpose:  Should we add the markup needed for jQuery UI theming?
1451			 * Scope:    jQuery.dataTable.classSettings
1452			 */
1453			this.bJUI = false;
1454
1455			/*
1456			 * Variable: oClasses
1457			 * Purpose:  Should we add the markup needed for jQuery UI theming?
1458			 * Scope:    jQuery.dataTable.classSettings
1459			 */
1460			this.oClasses = _oExt.oStdClasses;
1461
1462			/*
1463			 * Variable: bFiltered and bSorted
1464			 * Purpose:  Flags to allow callback functions to see what actions have been performed
1465			 * Scope:    jQuery.dataTable.classSettings
1466			 */
1467			this.bFiltered = false;
1468			this.bSorted = false;
1469
1470			/*
1471			 * Variable: bSortCellsTop
1472			 * Purpose:  Indicate that if multiple rows are in the header and there is more than one
1473			 *           unique cell per column, if the top one (true) or bottom one (false) should
1474			 *           be used for sorting / title by DataTables
1475			 * Scope:    jQuery.dataTable.classSettings
1476			 */
1477			this.bSortCellsTop = false;
1478
1479			/*
1480			 * Variable: oInit
1481			 * Purpose:  Initialisation object that is used for the table
1482			 * Scope:    jQuery.dataTable.classSettings
1483			 */
1484			this.oInit = null;
1485
1486			/*
1487			 * Variable: aoDestroyCallback
1488			 * Purpose:  Destroy callback functions
1489			 * Scope:    jQuery.dataTable.classSettings
1490			 */
1491			this.aoDestroyCallback = [];
1492		}
1493
1494		/*
1495		 * Variable: oApi
1496		 * Purpose:  Container for publicly exposed 'private' functions
1497		 * Scope:    jQuery.dataTable
1498		 */
1499		this.oApi = {};
1500
1501
1502		/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1503		 * Section - API functions
1504		 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1505
1506		/*
1507		 * Function: fnDraw
1508		 * Purpose:  Redraw the table
1509		 * Returns:  -
1510		 * Inputs:   bool:bComplete - Refilter and resort (if enabled) the table before the draw.
1511		 *             Optional: default - true
1512		 */
1513		this.fnDraw = function( bComplete )
1514		{
1515			var oSettings = _fnSettingsFromNode( this[_oExt.iApiIndex] );
1516			if ( typeof bComplete != 'undefined' && bComplete === false )
1517			{
1518				_fnCalculateEnd( oSettings );
1519				_fnDraw( oSettings );
1520			}
1521			else
1522			{
1523				_fnReDraw( oSettings );
1524			}
1525		};
1526
1527		/*
1528		 * Function: fnFilter
1529		 * Purpose:  Filter the input based on data
1530		 * Returns:  -
1531		 * Inputs:   string:sInput - string to filter the table on
1532		 *           int:iColumn - optional - column to limit filtering to
1533		 *           bool:bRegex - optional - treat as regular expression or not - default false
1534		 *           bool:bSmart - optional - perform smart filtering or not - default true
1535		 *           bool:bShowGlobal - optional - show the input global filter in it's input box(es)
1536		 *              - default true
1537		 */
1538		this.fnFilter = function( sInput, iColumn, bRegex, bSmart, bShowGlobal )
1539		{
1540			var oSettings = _fnSettingsFromNode( this[_oExt.iApiIndex] );
1541
1542			if ( !oSettings.oFeatures.bFilter )
1543			{
1544				return;
1545			}
1546
1547			if ( typeof bRegex == 'undefined' )
1548			{
1549				bRegex = false;
1550			}
1551
1552			if ( typeof bSmart == 'undefined' )
1553			{
1554				bSmart = true;
1555			}
1556
1557			if ( typeof bShowGlobal == 'undefined' )
1558			{
1559				bShowGlobal = true;
1560			}
1561
1562			if ( typeof iColumn == "undefined" || iColumn === null )
1563			{
1564				/* Global filter */
1565				_fnFilterComplete( oSettings, {
1566					"sSearch":sInput,
1567					"bRegex": bRegex,
1568					"bSmart": bSmart
1569				}, 1 );
1570
1571				if ( bShowGlobal && typeof oSettings.aanFeatures.f != 'undefined' )
1572				{
1573					var n = oSettings.aanFeatures.f;
1574					for ( var i=0, iLen=n.length ; i<iLen ; i++ )
1575					{
1576						$('input', n[i]).val( sInput );
1577					}
1578				}
1579			}
1580			else
1581			{
1582				/* Single column filter */
1583				oSettings.aoPreSearchCols[ iColumn ].sSearch = sInput;
1584				oSettings.aoPreSearchCols[ iColumn ].bRegex = bRegex;
1585				oSettings.aoPreSearchCols[ iColumn ].bSmart = bSmart;
1586				_fnFilterComplete( oSettings, oSettings.oPreviousSearch, 1 );
1587			}
1588		};
1589
1590		/*
1591		 * Function: fnSettings
1592		 * Purpose:  Get the settings for a particular table for extern. manipulation
1593		 * Returns:  -
1594		 * Inputs:   -
1595		 */
1596		this.fnSettings = function( nNode  )
1597		{
1598			return _fnSettingsFromNode( this[_oExt.iApiIndex] );
1599		};
1600
1601		/*
1602		 * Function: fnVersionCheck
1603		 * Notes:    The function is the same as the 'static' function provided in the ext variable
1604		 */
1605		this.fnVersionCheck = _oExt.fnVersionCheck;
1606
1607		/*
1608		 * Function: fnSort
1609		 * Purpose:  Sort the table by a particular row
1610		 * Returns:  -
1611		 * Inputs:   int:iCol - the data index to sort on. Note that this will
1612		 *   not match the 'display index' if you have hidden data entries
1613		 */
1614		this.fnSort = function( aaSort )
1615		{
1616			var oSettings = _fnSettingsFromNode( this[_oExt.iApiIndex] );
1617			oSettings.aaSorting = aaSort;
1618			_fnSort( oSettings );
1619		};
1620
1621		/*
1622		 * Function: fnSortListener
1623		 * Purpose:  Attach a sort listener to an element for a given column
1624		 * Returns:  -
1625		 * Inputs:   node:nNode - the element to attach the sort listener to
1626		 *           int:iColumn - the column that a click on this node will sort on
1627		 *           function:fnCallback - callback function when sort is run - optional
1628		 */
1629		this.fnSortListener = function( nNode, iColumn, fnCallback )
1630		{
1631			_fnSortAttachListener( _fnSettingsFromNode( this[_oExt.iApiIndex] ), nNode, iColumn,
1632			 	fnCallback );
1633		};
1634
1635		/*
1636		 * Function: fnAddData
1637		 * Purpose:  Add new row(s) into the table
1638		 * Returns:  array int: array of indexes (aoData) which have been added (zero length on error)
1639		 * Inputs:   array:mData - the data to be added. The length must match
1640		 *               the original data from the DOM
1641		 *             or
1642		 *             array array:mData - 2D array of data to be added
1643		 *           bool:bRedraw - redraw the table or not - default true
1644		 * Notes:    Warning - the refilter here will cause the table to redraw
1645		 *             starting at zero
1646		 * Notes:    Thanks to Yekimov Denis for contributing the basis for this function!
1647		 */
1648		this.fnAddData = function( mData, bRedraw )
1649		{
1650			if ( mData.length === 0 )
1651			{
1652				return [];
1653			}
1654
1655			var aiReturn = [];
1656			var iTest;
1657
1658			/* Find settings from table node */
1659			var oSettings = _fnSettingsFromNode( this[_oExt.iApiIndex] );
1660
1661			/* Check if we want to add multiple rows or not */
1662			if ( typeof mData[0] == "object" )
1663			{
1664				for ( var i=0 ; i<mData.length ; i++ )
1665				{
1666					iTest = _fnAddData( oSettings, mData[i] );
1667					if ( iTest == -1 )
1668					{
1669						return aiReturn;
1670					}
1671					aiReturn.push( iTest );
1672				}
1673			}
1674			else
1675			{
1676				iTest = _fnAddData( oSettings, mData );
1677				if ( iTest == -1 )
1678				{
1679					return aiReturn;
1680				}
1681				aiReturn.push( iTest );
1682			}
1683
1684			oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
1685
1686			if ( typeof bRedraw == 'undefined' || bRedraw )
1687			{
1688				_fnReDraw( oSettings );
1689			}
1690			return aiReturn;
1691		};
1692
1693		/*
1694		 * Function: fnDeleteRow
1695		 * Purpose:  Remove a row for the table
1696		 * Returns:  array:aReturn - the row that was deleted
1697		 * Inputs:   mixed:mTarget -
1698		 *             int: - index of aoData to be deleted, or
1699		 *             node(TR): - TR element you want to delete
1700		 *           function:fnCallBack - callback function - default null
1701		 *           bool:bRedraw - redraw the table or not - default true
1702		 */
1703		this.fnDeleteRow = function( mTarget, fnCallBack, bRedraw )
1704		{
1705			/* Find settings from table node */
1706			var oSettings = _fnSettingsFromNode( this[_oExt.iApiIndex] );
1707			var i, iAODataIndex;
1708
1709			iAODataIndex = (typeof mTarget == 'object') ?
1710				_fnNodeToDataIndex(oSettings, mTarget) : mTarget;
1711
1712			/* Return the data array from this row */
1713			var oData = oSettings.aoData.splice( iAODataIndex, 1 );
1714
1715			/* Remove the target row from the search array */
1716			var iDisplayIndex = $.inArray( iAODataIndex, oSettings.aiDisplay );
1717			oSettings.asDataSearch.splice( iDisplayIndex, 1 );
1718
1719			/* Delete from the display arrays */
1720			_fnDeleteIndex( oSettings.aiDisplayMaster, iAODataIndex );
1721			_fnDeleteIndex( oSettings.aiDisplay, iAODataIndex );
1722
1723			/* If there is a user callback function - call it */
1724			if ( typeof fnCallBack == "function" )
1725			{
1726				fnCallBack.call( this, oSettings, oData );
1727			}
1728
1729			/* Check for an 'overflow' they case for dislaying the table */
1730			if ( oSettings._iDisplayStart >= oSettings.aiDisplay.length )
1731			{
1732				oSettings._iDisplayStart -= oSettings._iDisplayLength;
1733				if ( oSettings._iDisplayStart < 0 )
1734				{
1735					oSettings._iDisplayStart = 0;
1736				}
1737			}
1738
1739			if ( typeof bRedraw == 'undefined' || bRedraw )
1740			{
1741				_fnCalculateEnd( oSettings );
1742				_fnDraw( oSettings );
1743			}
1744
1745			return oData;
1746		};
1747
1748		/*
1749		 * Function: fnClearTable
1750		 * Purpose:  Quickly and simply clear a table
1751		 * Returns:  -
1752		 * Inputs:   bool:bRedraw - redraw the table or not - default true
1753		 * Notes:    Thanks to Yekimov Denis for contributing the basis for this function!
1754		 */
1755		this.fnClearTable = function( bRedraw )
1756		{
1757			/* Find settings from table node */
1758			var oSettings = _fnSettingsFromNode( this[_oExt.iApiIndex] );
1759			_fnClearTable( oSettings );
1760
1761			if ( typeof bRedraw == 'undefined' || bRedraw )
1762			{
1763				_fnDraw( oSettings );
1764			}
1765		};
1766
1767		/*
1768		 * Function: fnOpen
1769		 * Purpose:  Open a display row (append a row after the row in question)
1770		 * Returns:  node:nNewRow - the row opened
1771		 * Inputs:   node:nTr - the table row to 'open'
1772		 *           string|node|jQuery:mHtml - the HTML to put into the row
1773		 *           string:sClass - class to give the new TD cell
1774		 */
1775		this.fnOpen = function( nTr, mHtml, sClass )
1776		{
1777			/* Find settings from table node */
1778			var oSettings = _fnSettingsFromNode( this[_oExt.iApiIndex] );
1779
1780			/* the old open one if there is one */
1781			this.fnClose( nTr );
1782
1783			var nNewRow = document.createElement("tr");
1784			var nNewCell = document.createElement("td");
1785			nNewRow.appendChild( nNewCell );
1786			nNewCell.className = sClass;
1787			nNewCell.colSpan = _fnVisbleColumns( oSettings );
1788
1789			if( typeof mHtml.jquery != 'undefined' || typeof mHtml == "object" )
1790			{
1791				nNewCell.appendChild( mHtml );
1792			}
1793			else
1794			{
1795				nNewCell.innerHTML = mHtml;
1796			}
1797
1798			/* If the nTr isn't on the page at the moment - then we don't insert at the moment */
1799			var nTrs = $('tr', oSettings.nTBody);
1800			if ( $.inArray(nTr, nTrs) != -1 )
1801			{
1802				$(nNewRow).insertAfter(nTr);
1803			}
1804
1805			oSettings.aoOpenRows.push( {
1806				"nTr": nNewRow,
1807				"nParent": nTr
1808			} );
1809
1810			return nNewRow;
1811		};
1812
1813		/*
1814		 * Function: fnClose
1815		 * Purpose:  Close a display row
1816		 * Returns:  int: 0 (success) or 1 (failed)
1817		 * Inputs:   node:nTr - the table row to 'close'
1818		 */
1819		this.fnClose = function( nTr )
1820		{
1821			/* Find settings from table node */
1822			var oSettings = _fnSettingsFromNode( this[_oExt.iApiIndex] );
1823
1824			for ( var i=0 ; i<oSettings.aoOpenRows.length ; i++ )
1825			{
1826				if ( oSettings.aoOpenRows[i].nParent == nTr )
1827				{
1828					var nTrParent = oSettings.aoOpenRows[i].nTr.parentNode;
1829					if ( nTrParent )
1830					{
1831						/* Remove it if it is currently on display */
1832						nTrParent.removeChild( oSettings.aoOpenRows[i].nTr );
1833					}
1834					oSettings.aoOpenRows.splice( i, 1 );
1835					return 0;
1836				}
1837			}
1838			return 1;
1839		};
1840
1841		/*
1842		 * Function: fnGetData
1843		 * Purpose:  Return an array with the data which is used to make up the table
1844		 * Returns:  array array string: 2d data array ([row][column]) or array string: 1d data array
1845		 *           or string if both row and column are given
1846		 * Inputs:   mixed:mRow - optional - if not present, then the full 2D array for the table
1847		 *             if given then:
1848		 *               int: - return data object for aoData entry of this index
1849		 *               node(TR): - return data object for this TR element
1850		 *           int:iCol - optional - the column that you want the data of. This will take into
1851		 *               account mDataProp and return the value DataTables uses for this column
1852		 */
1853		this.fnGetData = function( mRow, iCol )
1854		{
1855			var oSettings = _fnSettingsFromNode( this[_oExt.iApiIndex] );
1856
1857			if ( typeof mRow != 'undefined' )
1858			{
1859				var iRow = (typeof mRow == 'object') ?
1860					_fnNodeToDataIndex(oSettings, mRow) : mRow;
1861
1862				if ( typeof iCol != 'undefined' )
1863				{
1864					return _fnGetCellData( oSettings, iRow, iCol, '' );
1865				}
1866				return (typeof oSettings.aoData[iRow] != 'undefined') ?
1867					oSettings.aoData[iRow]._aData : null;
1868			}
1869			return _fnGetDataMaster( oSettings );
1870		};
1871
1872		/*
1873		 * Function: fnGetNodes
1874		 * Purpose:  Return an array with the TR nodes used for drawing the table
1875		 * Returns:  array node: TR elements
1876		 *           or
1877		 *           node (if iRow specified)
1878		 * Inputs:   int:iRow - optional - if present then the array returned will be the node for
1879		 *             the row with the index 'iRow'
1880		 */
1881		this.fnGetNodes = function( iRow )
1882		{
1883			var oSettings = _fnSettingsFromNode( this[_oExt.iApiIndex] );
1884
1885			if ( typeof iRow != 'undefined' )
1886			{
1887				return (typeof oSettings.aoData[iRow] != 'undefined') ? oSettings.aoData[iRow].nTr : null;
1888			}
1889			return _fnGetTrNodes( oSettings );
1890		};
1891
1892		/*
1893		 * Function: fnGetPosition
1894		 * Purpose:  Get the array indexes of a particular cell from it's DOM element
1895		 * Returns:  int: - row index, or array[ int, int, int ]: - row index, column index (visible)
1896		 *             and column index including hidden columns
1897		 * Inputs:   node:nNode - this can either be a TR, TD or TH in the table's body, the return is
1898		 *             dependent on this input
1899		 */
1900		this.fnGetPosition = function( nNode )
1901		{
1902			var oSettings = _fnSettingsFromNode( this[_oExt.iApiIndex] );
1903			var sNodeName = nNode.nodeName.toUpperCase();
1904
1905			if ( sNodeName == "TR" )
1906			{
1907				return _fnNodeToDataIndex(oSettings, nNode);
1908			}
1909			else if ( sNodeName == "TD" || sNodeName == "TH" )
1910			{
1911				var iDataIndex = _fnNodeToDataIndex(oSettings, nNode.parentNode);
1912				var anCells = _fnGetTdNodes( oSettings, iDataIndex );
1913
1914				for ( var i=0 ; i<oSettings.aoColumns.length ; i++ )
1915				{
1916					if ( anCells[i] == nNode )
1917					{
1918						return [ iDataIndex, _fnColumnIndexToVisible(oSettings, i ), i ];
1919					}
1920				}
1921			}
1922			return null;
1923		};
1924
1925		/*
1926		 * Function: fnUpdate
1927		 * Purpose:  Update a table cell or row - this method will accept either a single value to
1928		 *             update the cell with, an array of values with one element for each column or
1929		 *             an object in the same format as the original data source. The function is
1930		 *             self-referencing in order to make the multi column updates easier.
1931		 * Returns:  int: 0 okay, 1 error
1932		 * Inputs:   object | array string | string:mData - data to update the cell/row with
1933		 *           mixed:mRow -
1934		 *             int: - index of aoData to be updated, or
1935		 *             node(TR): - TR element you want to update
1936		 *           int:iColumn - the column to update - optional (not used of mData is an array or object)
1937		 *           bool:bRedraw - redraw the table or not - default true
1938		 *           bool:bAction - perform predraw actions or not (you will want this as 'true' if
1939		 *             you have bRedraw as true) - default true
1940		 */
1941		this.fnUpdate = function( mData, mRow, iColumn, bRedraw, bAction )
1942		{
1943			var oSettings = _fnSettingsFromNode( this[_oExt.iApiIndex] );
1944			var iVisibleColumn, i, iLen, sDisplay;
1945			var iRow = (typeof mRow == 'object') ?
1946				_fnNodeToDataIndex(oSettings, mRow) : mRow;
1947
1948			if ( $.isArray(mData) && typeof mData == 'object' )
1949			{
1950				/* Array update - update the whole row */
1951				oSettings.aoData[iRow]._aData = mData.slice();
1952
1953				for ( i=0 ; i<oSettings.aoColumns.length ; i++ )
1954				{
1955					this.fnUpdate( _fnGetCellData( oSettings, iRow, i ), iRow, i, false, false );
1956				}
1957			}
1958			else if ( mData !== null && typeof mData == 'object' )
1959			{
1960				/* Object update - update the whole row - assume the developer gets the object right */
1961				oSettings.aoData[iRow]._aData = $.extend( true, {}, mData );
1962
1963				for ( i=0 ; i<oSettings.aoColumns.length ; i++ )
1964				{
1965					this.fnUpdate( _fnGetCellData( oSettings, iRow, i ), iRow, i, false, false );
1966				}
1967			}
1968			else
1969			{
1970				/* Individual cell update */
1971				sDisplay = mData;
1972				_fnSetCellData( oSettings, iRow, iColumn, sDisplay );
1973
1974				if ( oSettings.aoColumns[iColumn].fnRender !== null )
1975				{
1976					sDisplay = oSettings.aoColumns[iColumn].fnRender( {
1977						"iDataRow": iRow,
1978						"iDataColumn": iColumn,
1979						"aData": oSettings.aoData[iRow]._aData,
1980						"oSettings": oSettings
1981					} );
1982
1983					if ( oSettings.aoColumns[iColumn].bUseRendered )
1984					{
1985						_fnSetCellData( oSettings, iRow, iColumn, sDisplay );
1986					}
1987				}
1988
1989				if ( oSettings.aoData[iRow].nTr !== null )
1990				{
1991					/* Do the actual HTML update */
1992					_fnGetTdNodes( oSettings, iRow )[iColumn].innerHTML = sDisplay;
1993				}
1994			}
1995
1996			/* Modify the search index for this row (strictly this is likely not needed, since fnReDraw
1997			 * will rebuild the search array - however, the redraw might be disabled by the user)
1998			 */
1999			var iDisplayIndex = $.inArray( iRow, oSettings.aiDisplay );
2000			oSettings.asDataSearch[iDisplayIndex] = _fnBuildSearchRow( oSettings,
2001				_fnGetRowData( oSettings, iRow, 'filter' ) );
2002
2003			/* Perform pre-draw actions */
2004			if ( typeof bAction == 'undefined' || bAction )
2005			{
2006				_fnAdjustColumnSizing( oSettings );
2007			}
2008
2009			/* Redraw the table */
2010			if ( typeof bRedraw == 'undefined' || bRedraw )
2011			{
2012				_fnReDraw( oSettings );
2013			}
2014			return 0;
2015		};
2016
2017
2018		/*
2019		 * Function: fnShowColoumn
2020		 * Purpose:  Show a particular column
2021		 * Returns:  -
2022		 * Inputs:   int:iCol - the column whose display should be changed
2023		 *           bool:bShow - show (true) or hide (false) the column
2024		 *           bool:bRedraw - redraw the table or not - default true
2025		 */
2026		this.fnSetColumnVis = function ( iCol, bShow, bRedraw )
2027		{
2028			var oSettings = _fnSettingsFromNode( this[_oExt.iApiIndex] );
2029			var i, iLen;
2030			var iColumns = oSettings.aoColumns.length;
2031			var nTd, nCell, anTrs, jqChildren, bAppend, iBefore;
2032
2033			/* No point in doing anything if we are requesting what is already true */
2034			if ( oSettings.aoColumns[iCol].bVisible == bShow )
2035			{
2036				return;
2037			}
2038
2039			/* Show the column */
2040			if ( bShow )
2041			{
2042				var iInsert = 0;
2043				for ( i=0 ; i<iCol ; i++ )
2044				{
2045					if ( oSettings.aoColumns[i].bVisible )
2046					{
2047						iInsert++;
2048					}
2049				}
2050
2051				/* Need to decide if we should use appendChild or insertBefore */
2052				bAppend = (iInsert >= _fnVisbleColumns( oSettings ));
2053
2054				/* Which coloumn should we be inserting before? */
2055				if ( !bAppend )
2056				{
2057					for ( i=iCol ; i<iColumns ; i++ )
2058					{
2059						if ( oSettings.aoColumns[i].bVisible )
2060						{
2061							iBefore = i;
2062							break;
2063						}
2064					}
2065				}
2066
2067				for ( i=0, iLen=oSettings.aoData.length ; i<iLen ; i++ )
2068				{
2069					if ( oSettings.aoData[i].nTr !== null )
2070					{
2071						if ( bAppend )
2072						{
2073							oSettings.aoData[i].nTr.appendChild(
2074								oSettings.aoData[i]._anHidden[iCol]
2075							);
2076						}
2077						else
2078						{
2079							oSettings.aoData[i].nTr.insertBefore(
2080								oSettings.aoData[i]._anHidden[iCol],
2081								_fnGetTdNodes( oSettings, i )[iBefore] );
2082						}
2083					}
2084				}
2085			}
2086			else
2087			{
2088				/* Remove a column from display */
2089				for ( i=0, iLen=oSettings.aoData.length ; i<iLen ; i++ )
2090				{
2091					if ( oSettings.aoData[i].nTr !== null )
2092					{
2093						nTd = _fnGetTdNodes( oSettings, i )[iCol];
2094						oSettings.aoData[i]._anHidden[iCol] = nTd;
2095						nTd.parentNode.removeChild( nTd );
2096					}
2097				}
2098			}
2099
2100			/* Clear to set the visible flag */
2101			oSettings.aoColumns[iCol].bVisible = bShow;
2102
2103			/* Redraw the header and footer based on the new column visibility */
2104			_fnDrawHead( oSettings, oSettings.aoHeader );
2105			if ( oSettings.nTFoot )
2106			{
2107				_fnDrawHead( oSettings, oSettings.aoFooter );
2108			}
2109
2110			/* If there are any 'open' rows, then we need to alter the colspan for this col change */
2111			for ( i=0, iLen=oSettings.aoOpenRows.length ; i<iLen ; i++ )
2112			{
2113				oSettings.aoOpenRows[i].nTr.colSpan = _fnVisbleColumns( oSettings );
2114			}
2115
2116			/* Do a redraw incase anything depending on the table columns needs it
2117			 * (built-in: scrolling)
2118			 */
2119			if ( typeof bRedraw == 'undefined' || bRedraw )
2120			{
2121				_fnAdjustColumnSizing( oSettings );
2122				_fnDraw( oSettings );
2123			}
2124
2125			_fnSaveState( oSettings );
2126		};
2127
2128		/*
2129		 * Function: fnPageChange
2130		 * Purpose:  Change the pagination
2131		 * Returns:  -
2132		 * Inputs:   string:sAction - paging action to take: "first", "previous", "next" or "last"
2133		 *           bool:bRedraw - redraw the table or not - optional - default true
2134		 */
2135		this.fnPageChange = function ( sAction, bRedraw )
2136		{
2137			var oSettings = _fnSettingsFromNode( this[_oExt.iApiIndex] );
2138			_fnPageChange( oSettings, sAction );
2139			_fnCalculateEnd( oSettings );
2140
2141			if ( typeof bRedraw == 'undefined' || bRedraw )
2142			{
2143				_fnDraw( oSettings );
2144			}
2145		};
2146
2147		/*
2148		 * Function: fnDestroy
2149		 * Purpose:  Destructor for the DataTable
2150		 * Returns:  -
2151		 * Inputs:   -
2152		 */
2153		this.fnDestroy = function ( )
2154		{
2155			var oSettings = _fnSettingsFromNode( this[_oExt.iApiIndex] );
2156			var nOrig = oSettings.nTableWrapper.parentNode;
2157			var nBody = oSettings.nTBody;
2158			var i, iLen;
2159
2160			/* Flag to note that the table is currently being destoryed - no action should be taken */
2161			oSettings.bDestroying = true;
2162
2163			/* Restore hidden columns */
2164			for ( i=0, iLen=oSettings.aoDestroyCallback.length ; i<iLen ; i++ ) {
2165				oSettings.aoDestroyCallback[i].fn();
2166			}
2167
2168			/* Restore hidden columns */
2169			for ( i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
2170			{
2171				if ( oSettings.aoColumns[i].bVisible === false )
2172				{
2173					this.fnSetColumnVis( i, true );
2174				}
2175			}
2176
2177			/* Blitz all DT events */
2178			$(oSettings.nTableWrapper).find('*').andSelf().unbind('.DT');
2179
2180			/* If there is an 'empty' indicator row, remove it */
2181			$('tbody>tr>td.'+oSettings.oClasses.sRowEmpty, oSettings.nTable).parent().remove();
2182
2183			/* When scrolling we had to break the table up - restore it */
2184			if ( oSettings.nTable != oSettings.nTHead.parentNode )
2185			{
2186				$(oSettings.nTable).children('thead').remove();
2187				oSettings.nTable.appendChild( oSettings.nTHead );
2188			}
2189
2190			if ( oSettings.nTFoot && oSettings.nTable != oSettings.nTFoot.parentNode )
2191			{
2192				$(oSettings.nTable).children('tfoot').remove();
2193				oSettings.nTable.appendChild( oSettings.nTFoot );
2194			}
2195
2196			/* Remove the DataTables generated nodes, events and classes */
2197			oSettings.nTable.parentNode.removeChild( oSettings.nTable );
2198			$(oSettings.nTableWrapper).remove();
2199
2200			oSettings.aaSorting = [];
2201			oSettings.aaSortingFixed = [];
2202			_fnSortingClasses( oSettings );
2203
2204			$(_fnGetTrNodes( oSettings )).removeClass( oSettings.asStripeClasses.join(' ') );
2205
2206			if ( !oSettings.bJUI )
2207			{
2208				$('th', oSettings.nTHead).removeClass( [ _oExt.oStdClasses.sSortable,
2209					_oExt.oStdClasses.sSortableAsc,
2210					_oExt.oStdClasses.sSortableDesc,
2211					_oExt.oStdClasses.sSortableNone ].join(' ')
2212				);
2213			}
2214			else
2215			{
2216				$('th', oSettings.nTHead).removeClass( [ _oExt.oStdClasses.sSortable,
2217					_oExt.oJUIClasses.sSortableAsc,
2218					_oExt.oJUIClasses.sSortableDesc,
2219					_oExt.oJUIClasses.sSortableNone ].join(' ')
2220				);
2221				$('th span.'+_oExt.oJUIClasses.sSortIcon, oSettings.nTHead).remove();
2222
2223				$('th', oSettings.nTHead).each( function () {
2224					var jqWrapper = $('div.'+_oExt.oJUIClasses.sSortJUIWrapper, this);
2225					var kids = jqWrapper.contents();
2226					$(this).append( kids );
2227					jqWrapper.remove();
2228				} );
2229			}
2230
2231			/* Add the TR elements back into the table in their original order */
2232			if ( oSettings.nTableReinsertBefore )
2233			{
2234				nOrig.insertBefore( oSettings.nTable, oSettings.nTableReinsertBefore );
2235			}
2236			else
2237			{
2238				nOrig.appendChild( oSettings.nTable );
2239			}
2240
2241			for ( i=0, iLen=oSettings.aoData.length ; i<iLen ; i++ )
2242			{
2243				if ( oSettings.aoData[i].nTr !== null )
2244				{
2245					nBody.appendChild( oSettings.aoData[i].nTr );
2246				}
2247			}
2248
2249			/* Restore the width of the original table */
2250			if ( oSettings.oFeatures.bAutoWidth === true )
2251			{
2252			  oSettings.nTable.style.width = _fnStringToCss(oSettings.sDestroyWidth);
2253			}
2254
2255			/* If the were originally odd/even type classes - then we add them back here. Note
2256			 * this is not fool proof (for example if not all rows as odd/even classes - but
2257			 * it's a good effort without getting carried away
2258			 */
2259			$(nBody).children('tr:even').addClass( oSettings.asDestroyStripes[0] );
2260			$(nBody).children('tr:odd').addClass( oSettings.asDestroyStripes[1] );
2261
2262			/* Remove the settings object from the settings array */
2263			for ( i=0, iLen=_aoSettings.length ; i<iLen ; i++ )
2264			{
2265				if ( _aoSettings[i] == oSettings )
2266				{
2267					_aoSettings.splice( i, 1 );
2268				}
2269			}
2270
2271			/* End it all */
2272			oSettings = null;
2273		};
2274
2275		/*
2276		 * Function: fnAdjustColumnSizing
2277		 * Purpose:  Update table sizing based on content. This would most likely be used for scrolling
2278		 *   and will typically need a redraw after it.
2279		 * Returns:  -
2280		 * Inputs:   bool:bRedraw - redraw the table or not, you will typically want to - default true
2281		 */
2282		this.fnAdjustColumnSizing = function ( bRedraw )
2283		{
2284			var oSettings = _fnSettingsFromNode(this[_oExt.iApiIndex]);
2285			_fnAdjustColumnSizing( oSettings );
2286
2287			if ( typeof bRedraw == 'undefined' || bRedraw )
2288			{
2289				this.fnDraw( false );
2290			}
2291			else if ( oSettings.oScroll.sX !== "" || oSettings.oScroll.sY !== "" )
2292			{
2293				/* If not redrawing, but scrolling, we want to apply the new column sizes anyway */
2294				this.oApi._fnScrollDraw(oSettings);
2295			}
2296		};
2297
2298		/*
2299		 * Plugin API functions
2300		 *
2301		 * This call will add the functions which are defined in _oExt.oApi to the
2302		 * DataTables object, providing a rather nice way to allow plug-in API functions. Note that
2303		 * this is done here, so that API function can actually override the built in API functions if
2304		 * required for a particular purpose.
2305		 */
2306
2307		/*
2308		 * Function: _fnExternApiFunc
2309		 * Purpose:  Create a wrapper function for exporting an internal func to an external API func
2310		 * Returns:  function: - wrapped function
2311		 * Inputs:   string:sFunc - API function name
2312		 */
2313		function _fnExternApiFunc (sFunc)
2314		{
2315			return function() {
2316					var aArgs = [_fnSettingsFromNode(this[_oExt.iApiIndex])].concat(
2317						Array.prototype.slice.call(arguments) );
2318					return _oExt.oApi[sFunc].apply( this, aArgs );
2319				};
2320		}
2321
2322		for ( var sFunc in _oExt.oApi )
2323		{
2324			if ( sFunc )
2325			{
2326				/*
2327				 * Function: anon
2328				 * Purpose:  Wrap the plug-in API functions in order to provide the settings as 1st arg
2329				 *   and execute in this scope
2330				 * Returns:  -
2331				 * Inputs:   -
2332				 */
2333				this[sFunc] = _fnExternApiFunc(sFunc);
2334			}
2335		}
2336
2337
2338
2339		/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2340		 * Section - Local functions
2341		 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2342
2343		/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2344		 * Section - Initialisation
2345		 */
2346
2347		/*
2348		 * Function: _fnInitialise
2349		 * Purpose:  Draw the table for the first time, adding all required features
2350		 * Returns:  -
2351		 * Inputs:   object:oSettings - dataTables settings object
2352		 */
2353		function _fnInitialise ( oSettings )
2354		{
2355			var i, iLen, iAjaxStart=oSettings.iInitDisplayStart;
2356
2357			/* Ensure that the table data is fully initialised */
2358			if ( oSettings.bInitialised === false )
2359			{
2360				setTimeout( function(){ _fnInitialise( oSettings ); }, 200 );
2361				return;
2362			}
2363
2364			/* Show the display HTML options */
2365			_fnAddOptionsHtml( oSettings );
2366
2367			/* Build and draw the header / footer for the table */
2368			_fnBuildHead( oSettings );
2369			_fnDrawHead( oSettings, oSettings.aoHeader );
2370			if ( oSettings.nTFoot )
2371			{
2372				_fnDrawHead( oSettings, oSettings.aoFooter );
2373			}
2374
2375			/* Okay to show that something is going on now */
2376			_fnProcessingDisplay( oSettings, true );
2377
2378			/* Calculate sizes for columns */
2379			if ( oSettings.oFeatures.bAutoWidth )
2380			{
2381				_fnCalculateColumnWidths( oSettings );
2382			}
2383
2384			for ( i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
2385			{
2386				if ( oSettings.aoColumns[i].sWidth !== null )
2387				{
2388					oSettings.aoColumns[i].nTh.style.width = _fnStringToCss( oSettings.aoColumns[i].sWidth );
2389				}
2390			}
2391
2392			/* If there is default sorting required - let's do it. The sort function will do the
2393			 * drawing for us. Otherwise we draw the table regardless of the Ajax source - this allows
2394			 * the table to look initialised for Ajax sourcing data (show 'loading' message possibly)
2395			 */
2396			if ( oSettings.oFeatures.bSort )
2397			{
2398				_fnSort( oSettings );
2399			}
2400			else if ( oSettings.oFeatures.bFilter )
2401			{
2402				_fnFilterComplete( oSettings, oSettings.oPreviousSearch );
2403			}
2404			else
2405			{
2406				oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
2407				_fnCalculateEnd( oSettings );
2408				_fnDraw( oSettings );
2409			}
2410
2411			/* if there is an ajax source load the data */
2412			if ( oSettings.sAjaxSource !== null && !oSettings.oFeatures.bServerSide )
2413			{
2414				var aoData = [];
2415				_fnServerParams( oSettings, aoData );
2416				oSettings.fnServerData.call( oSettings.oInstance, oSettings.sAjaxSource, aoData, function(json) {
2417					var aData = json;
2418					if ( oSettings.sAjaxDataProp !== "" )
2419					{
2420						var fnDataSrc = _fnGetObjectDataFn( oSettings.sAjaxDataProp );
2421						aData = fnDataSrc( json );
2422					}
2423
2424					/* Got the data - add it to the table */
2425					for ( i=0 ; i<aData.length ; i++ )
2426					{
2427						_fnAddData( oSettings, aData[i] );
2428					}
2429
2430					/* Reset the init display for cookie saving. We've already done a filter, and
2431					 * therefore cleared it before. So we need to make it appear 'fresh'
2432					 */
2433					oSettings.iInitDisplayStart = iAjaxStart;
2434
2435					if ( oSettings.oFeatures.bSort )
2436					{
2437						_fnSort( oSettings );
2438					}
2439					else
2440					{
2441						oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
2442						_fnCalculateEnd( oSettings );
2443						_fnDraw( oSettings );
2444					}
2445
2446					_fnProcessingDisplay( oSettings, false );
2447					_fnInitComplete( oSettings, json );
2448				}, oSettings );
2449				return;
2450			}
2451
2452			/* Server-side processing initialisation complete is done at the end of _fnDraw */
2453			if ( !oSettings.oFeatures.bServerSide )
2454			{
2455				_fnProcessingDisplay( oSettings, false );
2456				_fnInitComplete( oSettings );
2457			}
2458		}
2459
2460		/*
2461		 * Function: _fnInitComplete
2462		 * Purpose:  Draw the table for the first time, adding all required features
2463		 * Returns:  -
2464		 * Inputs:   object:oSettings - dataTables settings object
2465		 */
2466		function _fnInitComplete ( oSettings, json )
2467		{
2468			oSettings._bInitComplete = true;
2469			if ( typeof oSettings.fnInitComplete == 'function' )
2470			{
2471				if ( typeof json != 'undefined' )
2472				{
2473					oSettings.fnInitComplete.call( oSettings.oInstance, oSettings, json );
2474				}
2475				else
2476				{
2477					oSettings.fnInitComplete.call( oSettings.oInstance, oSettings );
2478				}
2479			}
2480		}
2481
2482		/*
2483		 * Function: _fnLanguageProcess
2484		 * Purpose:  Copy language variables from remote object to a local one
2485		 * Returns:  -
2486		 * Inputs:   object:oSettings - dataTables settings object
2487		 *           object:oLanguage - Language information
2488		 *           bool:bInit - init once complete
2489		 */
2490		function _fnLanguageProcess( oSettings, oLanguage, bInit )
2491		{
2492			oSettings.oLanguage = $.extend( true, oSettings.oLanguage, oLanguage );
2493
2494			/* Backwards compatibility - if there is no sEmptyTable given, then use the same as
2495			 * sZeroRecords - assuming that is given.
2496			 */
2497			if ( typeof oLanguage.sEmptyTable == 'undefined' &&
2498			     typeof oLanguage.sZeroRecords != 'undefined' )
2499			{
2500				_fnMap( oSettings.oLanguage, oLanguage, 'sZeroRecords', 'sEmptyTable' );
2501			}
2502
2503			/* Likewise with loading records */
2504			if ( typeof oLanguage.sLoadingRecords == 'undefined' &&
2505			     typeof oLanguage.sZeroRecords != 'undefined' )
2506			{
2507				_fnMap( oSettings.oLanguage, oLanguage, 'sZeroRecords', 'sLoadingRecords' );
2508			}
2509
2510			if ( bInit )
2511			{
2512				_fnInitialise( oSettings );
2513			}
2514		}
2515
2516		/*
2517		 * Function: _fnAddColumn
2518		 * Purpose:  Add a column to the list used for the table with default values
2519		 * Returns:  -
2520		 * Inputs:   object:oSettings - dataTables settings object
2521		 *           node:nTh - the th element for this column
2522		 */
2523		function _fnAddColumn( oSettings, nTh )
2524		{
2525			var iCol = oSettings.aoColumns.length;
2526			var oCol = {
2527				"sType": null,
2528				"_bAutoType": true,
2529				"bVisible": true,
2530				"bSearchable": true,
2531				"bSortable": true,
2532				"asSorting": [ 'asc', 'desc' ],
2533				"sSortingClass": oSettings.oClasses.sSortable,
2534				"sSortingClassJUI": oSettings.oClasses.sSortJUI,
2535				"sTitle": nTh ? nTh.innerHTML : '',
2536				"sName": '',
2537				"sWidth": null,
2538				"sWidthOrig": null,
2539				"sClass": null,
2540				"fnRender": null,
2541				"bUseRendered": true,
2542				"iDataSort": iCol,
2543				"mDataProp": iCol,
2544				"fnGetData": null,
2545				"fnSetData": null,
2546				"sSortDataType": 'std',
2547				"sDefaultContent": null,
2548				"sContentPadding": "",
2549				"nTh": nTh ? nTh : document.createElement('th'),
2550				"nTf": null
2551			};
2552			oSettings.aoColumns.push( oCol );
2553
2554			/* Add a column specific filter */
2555			if ( typeof oSettings.aoPreSearchCols[ iCol ] == 'undefined' ||
2556			     oSettings.aoPreSearchCols[ iCol ] === null )
2557			{
2558				oSettings.aoPreSearchCols[ iCol ] = {
2559					"sSearch": "",
2560					"bRegex": false,
2561					"bSmart": true
2562				};
2563			}
2564			else
2565			{
2566				/* Don't require that the user must specify bRegex and / or bSmart */
2567				if ( typeof oSettings.aoPreSearchCols[ iCol ].bRegex == 'undefined' )
2568				{
2569					oSettings.aoPreSearchCols[ iCol ].bRegex = true;
2570				}
2571
2572				if ( typeof oSettings.aoPreSearchCols[ iCol ].bSmart == 'undefined' )
2573				{
2574					oSettings.aoPreSearchCols[ iCol ].bSmart = true;
2575				}
2576			}
2577
2578			/* Use the column options function to initialise classes etc */
2579			_fnColumnOptions( oSettings, iCol, null );
2580		}
2581
2582		/*
2583		 * Function: _fnColumnOptions
2584		 * Purpose:  Apply options for a column
2585		 * Returns:  -
2586		 * Inputs:   object:oSettings - dataTables settings object
2587		 *           int:iCol - column index to consider
2588		 *           object:oOptions - object with sType, bVisible and bSearchable
2589		 */
2590		function _fnColumnOptions( oSettings, iCol, oOptions )
2591		{
2592			var oCol = oSettings.aoColumns[ iCol ];
2593
2594			/* User specified column options */
2595			if ( typeof oOptions != 'undefined' && oOptions !== null )
2596			{
2597				if ( typeof oOptions.sType != 'undefined' )
2598				{
2599					oCol.sType = oOptions.sType;
2600					oCol._bAutoType = false;
2601				}
2602
2603				_fnMap( oCol, oOptions, "bVisible" );
2604				_fnMap( oCol, oOptions, "bSearchable" );
2605				_fnMap( oCol, oOptions, "bSortable" );
2606				_fnMap( oCol, oOptions, "sTitle" );
2607				_fnMap( oCol, oOptions, "sName" );
2608				_fnMap( oCol, oOptions, "sWidth" );
2609				_fnMap( oCol, oOptions, "sWidth", "sWidthOrig" );
2610				_fnMap( oCol, oOptions, "sClass" );
2611				_fnMap( oCol, oOptions, "fnRender" );
2612				_fnMap( oCol, oOptions, "bUseRendered" );
2613				_fnMap( oCol, oOptions, "iDataSort" );
2614				_fnMap( oCol, oOptions, "mDataProp" );
2615				_fnMap( oCol, oOptions, "asSorting" );
2616				_fnMap( oCol, oOptions, "sSortDataType" );
2617				_fnMap( oCol, oOptions, "sDefaultContent" );
2618				_fnMap( oCol, oOptions, "sContentPadding" );
2619			}
2620
2621			/* Cache the data get and set functions for speed */
2622			oCol.fnGetData = _fnGetObjectDataFn( oCol.mDataProp );
2623			oCol.fnSetData = _fnSetObjectDataFn( oCol.mDataProp );
2624
2625			/* Feature sorting overrides column specific when off */
2626			if ( !oSettings.oFeatures.bSort )
2627			{
2628				oCol.bSortable = false;
2629			}
2630
2631			/* Check that the class assignment is correct for sorting */
2632			if ( !oCol.bSortable ||
2633				 ($.inArray('asc', oCol.asSorting) == -1 && $.inArray('desc', oCol.asSorting) == -1) )
2634			{
2635				oCol.sSortingClass = oSettings.oClasses.sSortableNone;
2636				oCol.sSortingClassJUI = "";
2637			}
2638			else if ( oCol.bSortable ||
2639			          ($.inArray('asc', oCol.asSorting) == -1 && $.inArray('desc', oCol.asSorting) == -1) )
2640			{
2641			  oCol.sSortingClass = oSettings.oClasses.sSortable;
2642			  oCol.sSortingClassJUI = oSettings.oClasses.sSortJUI;
2643			}
2644			else if ( $.inArray('asc', oCol.asSorting) != -1 && $.inArray('desc', oCol.asSorting) == -1 )
2645			{
2646				oCol.sSortingClass = oSettings.oClasses.sSortableAsc;
2647				oCol.sSortingClassJUI = oSettings.oClasses.sSortJUIAscAllowed;
2648			}
2649			else if ( $.inArray('asc', oCol.asSorting) == -1 && $.inArray('desc', oCol.asSorting) != -1 )
2650			{
2651				oCol.sSortingClass = oSettings.oClasses.sSortableDesc;
2652				oCol.sSortingClassJUI = oSettings.oClasses.sSortJUIDescAllowed;
2653			}
2654		}
2655
2656		/*
2657		 * Function: _fnAddData
2658		 * Purpose:  Add a data array to the table, creating DOM node etc
2659		 * Returns:  int: - >=0 if successful (index of new aoData entry), -1 if failed
2660		 * Inputs:   object:oSettings - dataTables settings object
2661		 *           array:aData - data array to be added
2662		 * Notes:    There are two basic methods for DataTables to get data to display - a JS array
2663		 *   (which is dealt with by this function), and the DOM, which has it's own optimised
2664		 *   function (_fnGatherData). Be careful to make the same changes here as there and vice-versa
2665		 */
2666		function _fnAddData ( oSettings, aDataSupplied )
2667		{
2668			var oCol;
2669
2670			/* Take an independent copy of the data source so we can bash it about as we wish */
2671			var aDataIn = ($.isArray(aDataSupplied)) ?
2672				aDataSupplied.slice() :
2673				$.extend( true, {}, aDataSupplied );
2674
2675			/* Create the object for storing information about this new row */
2676			var iRow = oSettings.aoData.length;
2677			var oData = {
2678				"nTr": null,
2679				"_iId": oSettings.iNextId++,
2680				"_aData": aDataIn,
2681				"_anHidden": [],
2682				"_sRowStripe": ""
2683			};
2684			oSettings.aoData.push( oData );
2685
2686			/* Create the cells */
2687			var nTd, sThisType;
2688			for ( var i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
2689			{
2690				oCol = oSettings.aoColumns[i];
2691
2692				/* Use rendered data for filtering/sorting */
2693				if ( typeof oCol.fnRender == 'function' && oCol.bUseRendered && oCol.mDataProp !== null )
2694				{
2695					_fnSetCellData( oSettings, iRow, i, oCol.fnRender( {
2696						"iDataRow": iRow,
2697						"iDataColumn": i,
2698						"aData": oData._aData,
2699						"oSettings": oSettings
2700					} ) );
2701				}
2702
2703				/* See if we should auto-detect the column type */
2704				if ( oCol._bAutoType && oCol.sType != 'string' )
2705				{
2706					/* Attempt to auto detect the type - same as _fnGatherData() */
2707					var sVarType = _fnGetCellData( oSettings, iRow, i, 'type' );
2708					if ( sVarType !== null && sVarType !== '' )
2709					{
2710						sThisType = _fnDetectType( sVarType );
2711						if ( oCol.sType === null )
2712						{
2713							oCol.sType = sThisType;
2714						}
2715						else if ( oCol.sType != sThisType && oCol.sType != "html" )
2716						{
2717							/* String is always the 'fallback' option */
2718							oCol.sType = 'string';
2719						}
2720					}
2721				}
2722			}
2723
2724			/* Add to the display array */
2725			oSettings.aiDisplayMaster.push( iRow );
2726
2727			/* Create the DOM imformation */
2728			if ( !oSettings.oFeatures.bDeferRender )
2729			{
2730				_fnCreateTr( oSettings, iRow );
2731			}
2732
2733			return iRow;
2734		}
2735
2736		/*
2737		 * Function: _fnCreateTr
2738		 * Purpose:  Create a new TR element (and it's TD children) for a row
2739		 * Returns:  void
2740		 * Inputs:   object:oSettings - dataTables settings object
2741		 *           int:iRow - Row to consider
2742		 */
2743		function _fnCreateTr ( oSettings, iRow )
2744		{
2745			var oData = oSettings.aoData[iRow];
2746			var nTd;
2747
2748			if ( oData.nTr === null )
2749			{
2750				oData.nTr = document.createElement('tr');
2751
2752				/* Special parameters can be given by the data source to be used on the row */
2753				if ( typeof oData._aData.DT_RowId != 'undefined' )
2754				{
2755					oData.nTr.setAttribute( 'id', oData._aData.DT_RowId );
2756				}
2757
2758				if ( typeof oData._aData.DT_RowClass != 'undefined' )
2759				{
2760					$(oData.nTr).addClass( oData._aData.DT_RowClass );
2761				}
2762
2763				/* Process each column */
2764				for ( var i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
2765				{
2766					var oCol = oSettings.aoColumns[i];
2767					nTd = document.createElement('td');
2768
2769					/* Render if needed - if bUseRendered is true then we already have the rendered
2770					 * value in the data source - so can just use that
2771					 */
2772					if ( typeof oCol.fnRender == 'function' && (!oCol.bUseRendered || oCol.mDataProp === null) )
2773					{
2774						nTd.innerHTML = oCol.fnRender( {
2775							"iDataRow": iRow,
2776							"iDataColumn": i,
2777							"aData": oData._aData,
2778							"oSettings": oSettings
2779						} );
2780					}
2781					else
2782					{
2783						nTd.innerHTML = _fnGetCellData( oSettings, iRow, i, 'display' );
2784					}
2785
2786					/* Add user defined class */
2787					if ( oCol.sClass !== null )
2788					{
2789						nTd.className = oCol.sClass;
2790					}
2791
2792					if ( oCol.bVisible )
2793					{
2794						oData.nTr.appendChild( nTd );
2795						oData._anHidden[i] = null;
2796					}
2797					else
2798					{
2799						oData._anHidden[i] = nTd;
2800					}
2801				}
2802			}
2803		}
2804
2805		/*
2806		 * Function: _fnGatherData
2807		 * Purpose:  Read in the data from the target table from the DOM
2808		 * Returns:  -
2809		 * Inputs:   object:oSettings - dataTables settings object
2810		 * Notes:    This is a optimised version of _fnAddData (more or less) for reading information
2811		 *   from the DOM. The basic actions must be identical in the two functions.
2812		 */
2813		function _fnGatherData( oSettings )
2814		{
2815			var iLoop, i, iLen, j, jLen, jInner,
2816			 	nTds, nTrs, nTd, aLocalData, iThisIndex,
2817				iRow, iRows, iColumn, iColumns, sNodeName;
2818
2819			/*
2820			 * Process by row first
2821			 * Add the data object for the whole table - storing the tr node. Note - no point in getting
2822			 * DOM based data if we are going to go and replace it with Ajax source data.
2823			 */
2824			if ( oSettings.bDeferLoading || oSettings.sAjaxSource === null )
2825			{
2826				nTrs = oSettings.nTBody.childNodes;
2827				for ( i=0, iLen=nTrs.length ; i<iLen ; i++ )
2828				{
2829					if ( nTrs[i].nodeName.toUpperCase() == "TR" )
2830					{
2831						iThisIndex = oSettings.aoData.length;
2832						oSettings.aoData.push( {
2833							"nTr": nTrs[i],
2834							"_iId": oSettings.iNextId++,
2835							"_aData": [],
2836							"_anHidden": [],
2837							"_sRowStripe": ''
2838						} );
2839
2840						oSettings.aiDisplayMaster.push( iThisIndex );
2841						nTds = nTrs[i].childNodes;
2842						jInner = 0;
2843
2844						for ( j=0, jLen=nTds.length ; j<jLen ; j++ )
2845						{
2846							sNodeName = nTds[j].nodeName.toUpperCase();
2847							if ( sNodeName == "TD" || sNodeName == "TH" )
2848							{
2849								_fnSetCellData( oSettings, iThisIndex, jInner, $.trim(nTds[j].innerHTML) );
2850								jInner++;
2851							}
2852						}
2853					}
2854				}
2855			}
2856
2857			/* Gather in the TD elements of the Table - note that this is basically the same as
2858			 * fnGetTdNodes, but that function takes account of hidden columns, which we haven't yet
2859			 * setup!
2860			 */
2861			nTrs = _fnGetTrNodes( oSettings );
2862			nTds = [];
2863			for ( i=0, iLen=nTrs.length ; i<iLen ; i++ )
2864			{
2865				for ( j=0, jLen=nTrs[i].childNodes.length ; j<jLen ; j++ )
2866				{
2867					nTd = nTrs[i].childNodes[j];
2868					sNodeName = nTd.nodeName.toUpperCase();
2869					if ( sNodeName == "TD" || sNodeName == "TH" )
2870					{
2871						nTds.push( nTd );
2872					}
2873				}
2874			}
2875
2876			/* Sanity check */
2877			if ( nTds.length != nTrs.length * oSettings.aoColumns.length )
2878			{
2879				_fnLog( oSettings, 1, "Unexpected number of TD elements. Expected "+
2880					(nTrs.length * oSettings.aoColumns.length)+" and got "+nTds.length+". DataTables does "+
2881					"not support rowspan / colspan in the table body, and there must be one cell for each "+
2882					"row/column combination." );
2883			}
2884
2885			/* Now process by column */
2886			for ( iColumn=0, iColumns=oSettings.aoColumns.length ; iColumn<iColumns ; iColumn++ )
2887			{
2888				/* Get the title of the column - unless there is a user set one */
2889				if ( oSettings.aoColumns[iColumn].sTitle === null )
2890				{
2891					oSettings.aoColumns[iColumn].sTitle = oSettings.aoColumns[iColumn].nTh.innerHTML;
2892				}
2893
2894				var
2895					bAutoType = oSettings.aoColumns[iColumn]._bAutoType,
2896					bRender = typeof oSettings.aoColumns[iColumn].fnRender == 'function',
2897					bClass = oSettings.aoColumns[iColumn].sClass !== null,
2898					bVisible = oSettings.aoColumns[iColumn].bVisible,
2899					nCell, sThisType, sRendered, sValType;
2900
2901				/* A single loop to rule them all (and be more efficient) */
2902				if ( bAutoType || bRender || bClass || !bVisible )
2903				{
2904					for ( iRow=0, iRows=oSettings.aoData.length ; iRow<iRows ; iRow++ )
2905					{
2906						nCell = nTds[ (iRow*iColumns) + iColumn ];
2907
2908						/* Type detection */
2909						if ( bAutoType && oSettings.aoColumns[iColumn].sType != 'string' )
2910						{
2911							sValType = _fnGetCellData( oSettings, iRow, iColumn, 'type' );
2912							if ( sValType !== '' )
2913							{
2914								sThisType = _fnDetectType( sValType );
2915								if ( oSettings.aoColumns[iColumn].sType === null )
2916								{
2917									oSettings.aoColumns[iColumn].sType = sThisType;
2918								}
2919								else if ( oSettings.aoColumns[iColumn].sType != sThisType &&
2920								          oSettings.aoColumns[iColumn].sType != "html" )
2921								{
2922									/* String is always the 'fallback' option */
2923									oSettings.aoColumns[iColumn].sType = 'string';
2924								}
2925							}
2926						}
2927
2928						/* Rendering */
2929						if ( bRender )
2930						{
2931							sRendered = oSettings.aoColumns[iColumn].fnRender( {
2932									"iDataRow": iRow,
2933									"iDataColumn": iColumn,
2934									"aData": oSettings.aoData[iRow]._aData,
2935									"oSettings": oSettings
2936								} );
2937							nCell.innerHTML = sRendered;
2938							if ( oSettings.aoColumns[iColumn].bUseRendered )
2939							{
2940								/* Use the rendered data for filtering/sorting */
2941								_fnSetCellData( oSettings, iRow, iColumn, sRendered );
2942							}
2943						}
2944
2945						/* Classes */
2946						if ( bClass )
2947						{
2948							nCell.className += ' '+oSettings.aoColumns[iColumn].sClass;
2949						}
2950
2951						/* Column visability */
2952						if ( !bVisible )
2953						{
2954							oSettings.aoData[iRow]._anHidden[iColumn] = nCell;
2955							nCell.parentNode.removeChild( nCell );
2956						}
2957						else
2958						{
2959							oSettings.aoData[iRow]._anHidden[iColumn] = null;
2960						}
2961					}
2962				}
2963			}
2964		}
2965
2966		/*
2967		 * Function: _fnBuildHead
2968		 * Purpose:  Create the HTML header for the table
2969		 * Returns:  -
2970		 * Inputs:   object:oSettings - dataTables settings object
2971		 */
2972		function _fnBuildHead( oSettings )
2973		{
2974			var i, nTh, iLen, j, jLen;
2975			var anTr = oSettings.nTHead.getElementsByTagName('tr');
2976			var iThs = oSettings.nTHead.getElementsByTagName('th').length;
2977			var iCorrector = 0;
2978			var jqChildren;
2979
2980			/* If there is a header in place - then use it - otherwise it's going to get nuked... */
2981			if ( iThs !== 0 )
2982			{
2983				/* We've got a thead from the DOM, so remove hidden columns and apply width to vis cols */
2984				for ( i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
2985				{
2986					nTh = oSettings.aoColumns[i].nTh;
2987
2988					if ( oSettings.aoColumns[i].sClass !== null )
2989					{
2990						$(nTh).addClass( oSettings.aoColumns[i].sClass );
2991					}
2992
2993					/* Set the title of the column if it is user defined (not what was auto detected) */
2994					if ( oSettings.aoColumns[i].sTitle != nTh.innerHTML )
2995					{
2996						nTh.innerHTML = oSettings.aoColumns[i].sTitle;
2997					}
2998				}
2999			}
3000			else
3001			{
3002				/* We don't have a header in the DOM - so we are going to have to create one */
3003				var nTr = document.createElement( "tr" );
3004
3005				for ( i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
3006				{
3007					nTh = oSettings.aoColumns[i].nTh;
3008					nTh.innerHTML = oSettings.aoColumns[i].sTitle;
3009
3010					if ( oSettings.aoColumns[i].sClass !== null )
3011					{
3012						$(nTh).addClass( oSettings.aoColumns[i].sClass );
3013					}
3014
3015					nTr.appendChild( nTh );
3016				}
3017				$(oSettings.nTHead).html( '' )[0].appendChild( nTr );
3018				_fnDetectHeader( oSettings.aoHeader, oSettings.nTHead );
3019			}
3020
3021			/* Add the extra markup needed by jQuery UI's themes */
3022			if ( oSettings.bJUI )
3023			{
3024				for ( i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
3025				{
3026					nTh = oSettings.aoColumns[i].nTh;
3027
3028					var nDiv = document.createElement('div');
3029					nDiv.className = oSettings.oClasses.sSortJUIWrapper;
3030					$(nTh).contents().appendTo(nDiv);
3031
3032					var nSpan = document.createElement('span');
3033					nSpan.className = oSettings.oClasses.sSortIcon;
3034					nDiv.appendChild( nSpan );
3035					nTh.appendChild( nDiv );
3036				}
3037			}
3038
3039			/* Add sort listener */
3040			var fnNoSelect = function (e) {
3041				this.onselectstart = function() { return false; };
3042				return false;
3043			};
3044
3045			if ( oSettings.oFeatures.bSort )
3046			{
3047				for ( i=0 ; i<oSettings.aoColumns.length ; i++ )
3048				{
3049					if ( oSettings.aoColumns[i].bSortable !== false )
3050					{
3051						_fnSortAttachListener( oSettings, oSettings.aoColumns[i].nTh, i );
3052
3053						/* Take the brutal approach to cancelling text selection in header */
3054						$(oSettings.aoColumns[i].nTh).bind( 'mousedown.DT', fnNoSelect );
3055					}
3056					else
3057					{
3058						$(oSettings.aoColumns[i].nTh).addClass( oSettings.oClasses.sSortableNone );
3059					}
3060				}
3061			}
3062
3063			/* Deal with the footer - add classes if required */
3064			if ( oSettings.oClasses.sFooterTH !== "" )
3065			{
3066				$(oSettings.nTFoot).children('tr').children('th').addClass( oSettings.oClasses.sFooterTH );
3067			}
3068
3069			/* Cache the footer elements */
3070			if ( oSettings.nTFoot !== null )
3071			{
3072				var anCells = _fnGetUniqueThs( oSettings, null, oSettings.aoFooter );
3073				for ( i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
3074				{
3075					if ( typeof anCells[i] != 'undefined' )
3076					{
3077						oSettings.aoColumns[i].nTf = anCells[i];
3078					}
3079				}
3080			}
3081		}
3082
3083
3084		/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
3085		 * Section - Drawing functions
3086		 */
3087
3088		/*
3089		 * Function: _fnDrawHead
3090		 * Purpose:  Draw the header (or footer) element based on the column visibility states. The
3091		 *           methodology here is to use the layout array from _fnDetectHeader, modified for
3092		 *           the instantaneous column visibility, to construct the new layout. The grid is
3093		 *           traversed over cell at a time in a rows x columns grid fashion, although each
3094		 *           cell insert can cover multiple elements in the grid - which is tracks using the
3095		 *           aApplied array. Cell inserts in the grid will only occur where there isn't
3096		 *           already a cell in that position.
3097		 * Returns:  -
3098		 * Inputs:   object:oSettings - dataTables settings object
3099		 *           array objects:aoSource - Layout array from _fnDetectHeader
3100		 *           boolean:bIncludeHidden - If true then include the hidden columns in the calc,
3101		 *             - optional: default false
3102		 */
3103		function _fnDrawHead( oSettings, aoSource, bIncludeHidden )
3104		{
3105			var i, iLen, j, jLen, k, kLen;
3106			var aoLocal = [];
3107			var aApplied = [];
3108			var iColumns = oSettings.aoColumns.length;
3109			var iRowspan, iColspan;
3110
3111			if ( typeof bIncludeHidden == 'undefined' )
3112			{
3113				bIncludeHidden = false;
3114			}
3115
3116			/* Make a copy of the master layout array, but without the visible columns in it */
3117			for ( i=0, iLen=aoSource.length ; i<iLen ; i++ )
3118			{
3119				aoLocal[i] = aoSource[i].slice();
3120				aoLocal[i].nTr = aoSource[i].nTr;
3121
3122				/* Remove any columns which are currently hidden */
3123				for ( j=iColumns-1 ; j>=0 ; j-- )
3124				{
3125					if ( !oSettings.aoColumns[j].bVisible && !bIncludeHidden )
3126					{
3127						aoLocal[i].splice( j, 1 );
3128					}
3129				}
3130
3131				/* Prep the applied array - it needs an element for each row */
3132				aApplied.push( [] );
3133			}
3134
3135			for ( i=0, iLen=aoLocal.length ; i<iLen ; i++ )
3136			{
3137				/* All cells are going to be replaced, so empty out the row */
3138				if ( aoLocal[i].nTr )
3139				{
3140					for ( k=0, kLen=aoLocal[i].nTr.childNodes.length ; k<kLen ; k++ )
3141					{
3142						aoLocal[i].nTr.removeChild( aoLocal[i].nTr.childNodes[0] );
3143					}
3144				}
3145
3146				for ( j=0, jLen=aoLocal[i].length ; j<jLen ; j++ )
3147				{
3148					iRowspan = 1;
3149					iColspan = 1;
3150
3151					/* Check to see if there is already a cell (row/colspan) covering our target
3152					 * insert point. If there is, then there is nothing to do.
3153					 */
3154					if ( typeof aApplied[i][j] == 'undefined' )
3155					{
3156						aoLocal[i].nTr.appendChild( aoLocal[i][j].cell );
3157						aApplied[i][j] = 1;
3158
3159						/* Expand the cell to cover as many rows as needed */
3160						while ( typeof aoLocal[i+iRowspan] != 'undefined' &&
3161						        aoLocal[i][j].cell == aoLocal[i+iRowspan][j].cell )
3162						{
3163							aApplied[i+iRowspan][j] = 1;
3164							iRowspan++;
3165						}
3166
3167						/* Expand the cell to cover as many columns as needed */
3168						while ( typeof aoLocal[i][j+iColspan] != 'undefined' &&
3169						        aoLocal[i][j].cell == aoLocal[i][j+iColspan].cell )
3170						{
3171							/* Must update the applied array over the rows for the columns */
3172							for ( k=0 ; k<iRowspan ; k++ )
3173							{
3174								aApplied[i+k][j+iColspan] = 1;
3175							}
3176							iColspan++;
3177						}
3178
3179						/* Do the actual expansion in the DOM */
3180						aoLocal[i][j].cell.rowSpan = iRowspan;
3181						aoLocal[i][j].cell.colSpan = iColspan;
3182					}
3183				}
3184			}
3185		}
3186
3187		/*
3188		 * Function: _fnDraw
3189		 * Purpose:  Insert the required TR nodes into the table for display
3190		 * Returns:  -
3191		 * Inputs:   object:oSettings - dataTables settings object
3192		 */
3193		function _fnDraw( oSettings )
3194		{
3195			var i, iLen;
3196			var anRows = [];
3197			var iRowCount = 0;
3198			var bRowError = false;
3199			var iStripes = oSettings.asStripeClasses.length;
3200			var iOpenRows = oSettings.aoOpenRows.length;
3201
3202			/* Provide a pre-callback function which can be used to cancel the draw is false is returned */
3203			if ( oSettings.fnPreDrawCallback !== null &&
3204			     oSettings.fnPreDrawCallback.call( oSettings.oInstance, oSettings ) === false )
3205			{
3206			     return;
3207			}
3208
3209			oSettings.bDrawing = true;
3210
3211			/* Check and see if we have an initial draw position from state saving */
3212			if ( typeof oSettings.iInitDisplayStart != 'undefined' && oSettings.iInitDisplayStart != -1 )
3213			{
3214				if ( oSettings.oFeatures.bServerSide )
3215				{
3216					oSettings._iDisplayStart = oSettings.iInitDisplayStart;
3217				}
3218				else
3219				{
3220					oSettings._iDisplayStart = (oSettings.iInitDisplayStart >= oSettings.fnRecordsDisplay()) ?
3221						0 : oSettings.iInitDisplayStart;
3222				}
3223				oSettings.iInitDisplayStart = -1;
3224				_fnCalculateEnd( oSettings );
3225			}
3226
3227			/* Server-side processing draw intercept */
3228			if ( oSettings.bDeferLoading )
3229			{
3230				oSettings.bDeferLoading = false;
3231				oSettings.iDraw++;
3232			}
3233			else if ( !oSettings.oFeatures.bServerSide )
3234			{
3235				oSettings.iDraw++;
3236			}
3237			else if ( !oSettings.bDestroying && !_fnAjaxUpdate( oSettings ) )
3238			{
3239				return;
3240			}
3241
3242			if ( oSettings.aiDisplay.length !== 0 )
3243			{
3244				var iStart = oSettings._iDisplayStart;
3245				var iEnd = oSettings._iDisplayEnd;
3246
3247				if ( oSettings.oFeatures.bServerSide )
3248				{
3249					iStart = 0;
3250					iEnd = oSettings.aoData.length;
3251				}
3252
3253				for ( var j=iStart ; j<iEnd ; j++ )
3254				{
3255					var aoData = oSettings.aoData[ oSettings.aiDisplay[j] ];
3256					if ( aoData.nTr === null )
3257					{
3258						_fnCreateTr( oSettings, oSettings.aiDisplay[j] );
3259					}
3260
3261					var nRow = aoData.nTr;
3262
3263					/* Remove the old striping classes and then add the new one */
3264					if ( iStripes !== 0 )
3265					{
3266						var sStripe = oSettings.asStripeClasses[ iRowCount % iStripes ];
3267						if ( aoData._sRowStripe != sStripe )
3268						{
3269							$(nRow).removeClass( aoData._sRowStripe ).addClass( sStripe );
3270							aoData._sRowStripe = sStripe;
3271						}
3272					}
3273
3274					/* Custom row callback function - might want to manipule the row */
3275					if ( typeof oSettings.fnRowCallback == "function" )
3276					{
3277						nRow = oSettings.fnRowCallback.call( oSettings.oInstance, nRow,
3278							oSettings.aoData[ oSettings.aiDisplay[j] ]._aData, iRowCount, j );
3279						if ( !nRow && !bRowError )
3280						{
3281							_fnLog( oSettings, 0, "A node was not returned by fnRowCallback" );
3282							bRowError = true;
3283						}
3284					}
3285
3286					anRows.push( nRow );
3287					iRowCount++;
3288
3289					/* If there is an open row - and it is attached to this parent - attach it on redraw */
3290					if ( iOpenRows !== 0 )
3291					{
3292						for ( var k=0 ; k<iOpenRows ; k++ )
3293						{
3294							if ( nRow == oSettings.aoOpenRows[k].nParent )
3295							{
3296								anRows.push( oSettings.aoOpenRows[k].nTr );
3297							}
3298						}
3299					}
3300				}
3301			}
3302			else
3303			{
3304				/* Table is empty - create a row with an empty message in it */
3305				anRows[ 0 ] = document.createElement( 'tr' );
3306
3307				if ( typeof oSettings.asStripeClasses[0] != 'undefined' )
3308				{
3309					anRows[ 0 ].className = oSettings.asStripeClasses[0];
3310				}
3311
3312				var sZero = oSettings.oLanguage.sZeroRecords.replace(
3313					'_MAX_', oSettings.fnFormatNumber(oSettings.fnRecordsTotal()) );
3314				if ( oSettings.iDraw == 1 && oSettings.sAjaxSource !== null && !oSettings.oFeatures.bServerSide )
3315				{
3316					sZero = oSettings.oLanguage.sLoadingRecords;
3317				}
3318				else if ( typeof oSettings.oLanguage.sEmptyTable != 'undefined' &&
3319				     oSettings.fnRecordsTotal() === 0 )
3320				{
3321					sZero = oSettings.oLanguage.sEmptyTable;
3322				}
3323
3324				var nTd = document.createElement( 'td' );
3325				nTd.setAttribute( 'valign', "top" );
3326				nTd.colSpan = _fnVisbleColumns( oSettings );
3327				nTd.className = oSettings.oClasses.sRowEmpty;
3328				nTd.innerHTML = sZero;
3329
3330				anRows[ iRowCount ].appendChild( nTd );
3331			}
3332
3333			/* Callback the header and footer custom funcation if there is one */
3334			if ( typeof oSettings.fnHeaderCallback == 'function' )
3335			{
3336				oSettings.fnHeaderCallback.call( oSettings.oInstance, $(oSettings.nTHead).children('tr')[0],
3337					_fnGetDataMaster( oSettings ), oSettings._iDisplayStart, oSettings.fnDisplayEnd(),
3338					oSettings.aiDisplay );
3339			}
3340
3341			if ( typeof oSettings.fnFooterCallback == 'function' )
3342			{
3343				oSettings.fnFooterCallback.call( oSettings.oInstance, $(oSettings.nTFoot).children('tr')[0],
3344					_fnGetDataMaster( oSettings ), oSettings._iDisplayStart, oSettings.fnDisplayEnd(),
3345					oSettings.aiDisplay );
3346			}
3347
3348			/*
3349			 * Need to remove any old row from the display - note we can't just empty the tbody using
3350			 * $().html('') since this will unbind the jQuery event handlers (even although the node
3351			 * still exists!) - equally we can't use innerHTML, since IE throws an exception.
3352			 */
3353			var
3354				nAddFrag = document.createDocumentFragment(),
3355				nRemoveFrag = document.createDocumentFragment(),
3356				nBodyPar, nTrs;
3357
3358			if ( oSettings.nTBody )
3359			{
3360				nBodyPar = oSettings.nTBody.parentNode;
3361				nRemoveFrag.appendChild( oSettings.nTBody );
3362
3363				/* When doing infinite scrolling, only remove child rows when sorting, filtering or start
3364				 * up. When not infinite scroll, always do it.
3365				 */
3366				if ( !oSettings.oScroll.bInfinite || !oSettings._bInitComplete ||
3367				 	oSettings.bSorted || oSettings.bFiltered )
3368				{
3369					nTrs = oSettings.nTBody.childNodes;
3370					for ( i=nTrs.length-1 ; i>=0 ; i-- )
3371					{
3372						nTrs[i].parentNode.removeChild( nTrs[i] );
3373					}
3374				}
3375
3376				/* Put the draw table into the dom */
3377				for ( i=0, iLen=anRows.length ; i<iLen ; i++ )
3378				{
3379					nAddFrag.appendChild( anRows[i] );
3380				}
3381
3382				oSettings.nTBody.appendChild( nAddFrag );
3383				if ( nBodyPar !== null )
3384				{
3385					nBodyPar.appendChild( oSettings.nTBody );
3386				}
3387			}
3388
3389			/* Call all required callback functions for the end of a draw */
3390			for ( i=oSettings.aoDrawCallback.length-1 ; i>=0 ; i-- )
3391			{
3392				oSettings.aoDrawCallback[i].fn.call( oSettings.oInstance, oSettings );
3393			}
3394			$(oSettings.oInstance).trigger('draw', oSettings);
3395
3396			/* Draw is complete, sorting and filtering must be as well */
3397			oSettings.bSorted = false;
3398			oSettings.bFiltered = false;
3399			oSettings.bDrawing = false;
3400
3401			if ( oSettings.oFeatures.bServerSide )
3402			{
3403				_fnProcessingDisplay( oSettings, false );
3404				if ( typeof oSettings._bInitComplete == 'undefined' )
3405				{
3406					_fnInitComplete( oSettings );
3407				}
3408			}
3409		}
3410
3411		/*
3412		 * Function: _fnReDraw
3413		 * Purpose:  Redraw the table - taking account of the various features which are enabled
3414		 * Returns:  -
3415		 * Inputs:   object:oSettings - dataTables settings object
3416		 */
3417		function _fnReDraw( oSettings )
3418		{
3419			if ( oSettings.oFeatures.bSort )
3420			{
3421				/* Sorting will refilter and draw for us */
3422				_fnSort( oSettings, oSettings.oPreviousSearch );
3423			}
3424			else if ( oSettings.oFeatures.bFilter )
3425			{
3426				/* Filtering will redraw for us */
3427				_fnFilterComplete( oSettings, oSettings.oPreviousSearch );
3428			}
3429			else
3430			{
3431				_fnCalculateEnd( oSettings );
3432				_fnDraw( oSettings );
3433			}
3434		}
3435
3436		/*
3437		 * Function: _fnAjaxUpdate
3438		 * Purpose:  Update the table using an Ajax call
3439		 * Returns:  bool: block the table drawing or not
3440		 * Inputs:   object:oSettings - dataTables settings object
3441		 */
3442		function _fnAjaxUpdate( oSettings )
3443		{
3444			if ( oSettings.bAjaxDataGet )
3445			{
3446				oSettings.iDraw++;
3447				_fnProcessingDisplay( oSettings, true );
3448				var iColumns = oSettings.aoColumns.length;
3449				var aoData = _fnAjaxParameters( oSettings );
3450				_fnServerParams( oSettings, aoData );
3451
3452				oSettings.fnServerData.call( oSettings.oInstance, oSettings.sAjaxSource, aoData,
3453					function(json) {
3454						_fnAjaxUpdateDraw( oSettings, json );
3455					}, oSettings );
3456				return false;
3457			}
3458			else
3459			{
3460				return true;
3461			}
3462		}
3463
3464		/*
3465		 * Function: _fnAjaxParameters
3466		 * Purpose:  Build up the parameters in an object needed for a server-side processing request
3467		 * Returns:  bool: block the table drawing or not
3468		 * Inputs:   object:oSettings - dataTables settings object
3469		 */
3470		function _fnAjaxParameters( oSettings )
3471		{
3472			var iColumns = oSettings.aoColumns.length;
3473			var aoData = [], mDataProp;
3474			var i;
3475
3476			aoData.push( { "name": "sEcho",          "value": oSettings.iDraw } );
3477			aoData.push( { "name": "iColumns",       "value": iColumns } );
3478			aoData.push( { "name": "sColumns",       "value": _fnColumnOrdering(oSettings) } );
3479			aoData.push( { "name": "iDisplayStart",  "value": oSettings._iDisplayStart } );
3480			aoData.push( { "name": "iDisplayLength", "value": oSettings.oFeatures.bPaginate !== false ?
3481				oSettings._iDisplayLength : -1 } );
3482
3483			for ( i=0 ; i<iColumns ; i++ )
3484			{
3485			  mDataProp = oSettings.aoColumns[i].mDataProp;
3486				aoData.push( { "name": "mDataProp_"+i, "value": typeof(mDataProp)=="function" ? 'function' : mDataProp } );
3487			}
3488
3489			/* Filtering */
3490			if ( oSettings.oFeatures.bFilter !== false )
3491			{
3492				aoData.push( { "name": "sSearch", "value": oSettings.oPreviousSearch.sSearch } );
3493				aoData.push( { "name": "bRegex",  "value": oSettings.oPreviousSearch.bRegex } );
3494				for ( i=0 ; i<iColumns ; i++ )
3495				{
3496					aoData.push( { "name": "sSearch_"+i,     "value": oSettings.aoPreSearchCols[i].sSearch } );
3497					aoData.push( { "name": "bRegex_"+i,      "value": oSettings.aoPreSearchCols[i].bRegex } );
3498					aoData.push( { "name": "bSearchable_"+i, "value": oSettings.aoColumns[i].bSearchable } );
3499				}
3500			}
3501
3502			/* Sorting */
3503			if ( oSettings.oFeatures.bSort !== false )
3504			{
3505				var iFixed = oSettings.aaSortingFixed !== null ? oSettings.aaSortingFixed.length : 0;
3506				var iUser = oSettings.aaSorting.length;
3507				aoData.push( { "name": "iSortingCols",   "value": iFixed+iUser } );
3508				for ( i=0 ; i<iFixed ; i++ )
3509				{
3510					aoData.push( { "name": "iSortCol_"+i,  "value": oSettings.aaSortingFixed[i][0] } );
3511					aoData.push( { "name": "sSortDir_"+i,  "value": oSettings.aaSortingFixed[i][1] } );
3512				}
3513
3514				for ( i=0 ; i<iUser ; i++ )
3515				{
3516					aoData.push( { "name": "iSortCol_"+(i+iFixed),  "value": oSettings.aaSorting[i][0] } );
3517					aoData.push( { "name": "sSortDir_"+(i+iFixed),  "value": oSettings.aaSorting[i][1] } );
3518				}
3519
3520				for ( i=0 ; i<iColumns ; i++ )
3521				{
3522					aoData.push( { "name": "bSortable_"+i,  "value": oSettings.aoColumns[i].bSortable } );
3523				}
3524			}
3525
3526			return aoData;
3527		}
3528
3529		/*
3530		 * Function: _fnServerParams
3531		 * Purpose:  Add Ajax parameters from plugins
3532		 * Returns:  -
3533		 * Inputs:   object:oSettings - dataTables settings object
3534		 *           array objects:aoData - name/value pairs to send to the server
3535		 */
3536		function _fnServerParams( oSettings, aoData )
3537		{
3538			for ( var i=0, iLen=oSettings.aoServerParams.length ; i<iLen ; i++ )
3539			{
3540				oSettings.aoServerParams[i].fn.call( oSettings.oInstance, aoData );
3541			}
3542		}
3543
3544		/*
3545		 * Function: _fnAjaxUpdateDraw
3546		 * Purpose:  Data the data from the server (nuking the old) and redraw the table
3547		 * Returns:  -
3548		 * Inputs:   object:oSettings - dataTables settings object
3549		 *           object:json - json data return from the server.
3550		 *             The following must be defined:
3551		 *               iTotalRecords, iTotalDisplayRecords, aaData
3552		 *             The following may be defined:
3553		 *               sColumns
3554		 */
3555		function _fnAjaxUpdateDraw ( oSettings, json )
3556		{
3557			if ( typeof json.sEcho != 'undefined' )
3558			{
3559				/* Protect against old returns over-writing a new one. Possible when you get
3560				 * very fast interaction, and later queires are completed much faster
3561				 */
3562				if ( json.sEcho*1 < oSettings.iDraw )
3563				{
3564					return;
3565				}
3566				else
3567				{
3568					oSettings.iDraw = json.sEcho * 1;
3569				}
3570			}
3571
3572			if ( !oSettings.oScroll.bInfinite ||
3573				   (oSettings.oScroll.bInfinite && (oSettings.bSorted || oSettings.bFiltered)) )
3574			{
3575				_fnClearTable( oSettings );
3576			}
3577			oSettings._iRecordsTotal = json.iTotalRecords;
3578			oSettings._iRecordsDisplay = json.iTotalDisplayRecords;
3579
3580			/* Determine if reordering is required */
3581			var sOrdering = _fnColumnOrdering(oSettings);
3582			var bReOrder = (typeof json.sColumns != 'undefined' && sOrdering !== "" && json.sColumns != sOrdering );
3583			if ( bReOrder )
3584			{
3585				var aiIndex = _fnReOrderIndex( oSettings, json.sColumns );
3586			}
3587
3588			var fnDataSrc = _fnGetObjectDataFn( oSettings.sAjaxDataProp );
3589			var aData = fnDataSrc( json );
3590
3591			for ( var i=0, iLen=aData.length ; i<iLen ; i++ )
3592			{
3593				if ( bReOrder )
3594				{
3595					/* If we need to re-order, then create a new array with the correct order and add it */
3596					var aDataSorted = [];
3597					for ( var j=0, jLen=oSettings.aoColumns.length ; j<jLen ; j++ )
3598					{
3599						aDataSorted.push( aData[i][ aiIndex[j] ] );
3600					}
3601					_fnAddData( oSettings, aDataSorted );
3602				}
3603				else
3604				{
3605					/* No re-order required, sever got it "right" - just straight add */
3606					_fnAddData( oSettings, aData[i] );
3607				}
3608			}
3609			oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
3610
3611			oSettings.bAjaxDataGet = false;
3612			_fnDraw( oSettings );
3613			oSettings.bAjaxDataGet = true;
3614			_fnProcessingDisplay( oSettings, false );
3615		}
3616
3617
3618		/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
3619		 * Section - Options (features) HTML
3620		 */
3621
3622		/*
3623		 * Function: _fnAddOptionsHtml
3624		 * Purpose:  Add the options to the page HTML for the table
3625		 * Returns:  -
3626		 * Inputs:   object:oSettings - dataTables settings object
3627		 */
3628		function _fnAddOptionsHtml ( oSettings )
3629		{
3630			/*
3631			 * Create a temporary, empty, div which we can later on replace with what we have generated
3632			 * we do it this way to rendering the 'options' html offline - speed :-)
3633			 */
3634			var nHolding = document.createElement( 'div' );
3635			oSettings.nTable.parentNode.insertBefore( nHolding, oSettings.nTable );
3636
3637			/*
3638			 * All DataTables are wrapped in a div
3639			 */
3640			oSettings.nTableWrapper = document.createElement( 'div' );
3641			oSettings.nTableWrapper.className = oSettings.oClasses.sWrapper;
3642			if ( oSettings.sTableId !== '' )
3643			{
3644				oSettings.nTableWrapper.setAttribute( 'id', oSettings.sTableId+'_wrapper' );
3645			}
3646
3647			oSettings.nTableReinsertBefore = oSettings.nTable.nextSibling;
3648
3649			/* Track where we want to insert the option */
3650			var nInsertNode = oSettings.nTableWrapper;
3651
3652			/* Loop over the user set positioning and place the elements as needed */
3653			var aDom = oSettings.sDom.split('');
3654			var nTmp, iPushFeature, cOption, nNewNode, cNext, sAttr, j;
3655			for ( var i=0 ; i<aDom.length ; i++ )
3656			{
3657				iPushFeature = 0;
3658				cOption = aDom[i];
3659
3660				if ( cOption == '<' )
3661				{
3662					/* New container div */
3663					nNewNode = document.createElement( 'div' );
3664
3665					/* Check to see if we should append an id and/or a class name to the container */
3666					cNext = aDom[i+1];
3667					if ( cNext == "'" || cNext == '"' )
3668					{
3669						sAttr = "";
3670						j = 2;
3671						while ( aDom[i+j] != cNext )
3672						{
3673							sAttr += aDom[i+j];
3674							j++;
3675						}
3676
3677						/* Replace jQuery UI constants */
3678						if ( sAttr == "H" )
3679						{
3680							sAttr = "fg-toolbar ui-toolbar ui-widget-header ui-corner-tl ui-corner-tr ui-helper-clearfix";
3681						}
3682						else if ( sAttr == "F" )
3683						{
3684							sAttr = "fg-toolbar ui-toolbar ui-widget-header ui-corner-bl ui-corner-br ui-helper-clearfix";
3685						}
3686
3687						/* The attribute can be in the format of "#id.class", "#id" or "class" This logic
3688						 * breaks the string into parts and applies them as needed
3689						 */
3690						if ( sAttr.indexOf('.') != -1 )
3691						{
3692							var aSplit = sAttr.split('.');
3693							nNewNode.setAttribute('id', aSplit[0].substr(1, aSplit[0].length-1) );
3694							nNewNode.className = aSplit[1];
3695						}
3696						else if ( sAttr.charAt(0) == "#" )
3697						{
3698							nNewNode.setAttribute('id', sAttr.substr(1, sAttr.length-1) );
3699						}
3700						else
3701						{
3702							nNewNode.className = sAttr;
3703						}
3704
3705						i += j; /* Move along the position array */
3706					}
3707
3708					nInsertNode.appendChild( nNewNode );
3709					nInsertNode = nNewNode;
3710				}
3711				else if ( cOption == '>' )
3712				{
3713					/* End container div */
3714					nInsertNode = nInsertNode.parentNode;
3715				}
3716				else if ( cOption == 'l' && oSettings.oFeatures.bPaginate && oSettings.oFeatures.bLengthChange )
3717				{
3718					/* Length */
3719					nTmp = _fnFeatureHtmlLength( oSettings );
3720					iPushFeature = 1;
3721				}
3722				else if ( cOption == 'f' && oSettings.oFeatures.bFilter )
3723				{
3724					/* Filter */
3725					nTmp = _fnFeatureHtmlFilter( oSettings );
3726					iPushFeature = 1;
3727				}
3728				else if ( cOption == 'r' && oSettings.oFeatures.bProcessing )
3729				{
3730					/* pRocessing */
3731					nTmp = _fnFeatureHtmlProcessing( oSettings );
3732					iPushFeature = 1;
3733				}
3734				else if ( cOption == 't' )
3735				{
3736					/* Table */
3737					nTmp = _fnFeatureHtmlTable( oSettings );
3738					iPushFeature = 1;
3739				}
3740				else if ( cOption ==  'i' && oSettings.oFeatures.bInfo )
3741				{
3742					/* Info */
3743					nTmp = _fnFeatureHtmlInfo( oSettings );
3744					iPushFeature = 1;
3745				}
3746				else if ( cOption == 'p' && oSettings.oFeatures.bPaginate )
3747				{
3748					/* Pagination */
3749					nTmp = _fnFeatureHtmlPaginate( oSettings );
3750					iPushFeature = 1;
3751				}
3752				else if ( _oExt.aoFeatures.length !== 0 )
3753				{
3754					/* Plug-in features */
3755					var aoFeatures = _oExt.aoFeatures;
3756					for ( var k=0, kLen=aoFeatures.length ; k<kLen ; k++ )
3757					{
3758						if ( cOption == aoFeatures[k].cFeature )
3759						{
3760							nTmp = aoFeatures[k].fnInit( oSettings );
3761							if ( nTmp )
3762							{
3763								iPushFeature = 1;
3764							}
3765							break;
3766						}
3767					}
3768				}
3769
3770				/* Add to the 2D features array */
3771				if ( iPushFeature == 1 && nTmp !== null )
3772				{
3773					if ( typeof oSettings.aanFeatures[cOption] != 'object' )
3774					{
3775						oSettings.aanFeatures[cOption] = [];
3776					}
3777					oSettings.aanFeatures[cOption].push( nTmp );
3778					nInsertNode.appendChild( nTmp );
3779				}
3780			}
3781
3782			/* Built our DOM structure - replace the holding div with what we want */
3783			nHolding.parentNode.replaceChild( oSettings.nTableWrapper, nHolding );
3784		}
3785
3786
3787		/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
3788		 * Section - Feature: Filtering
3789		 */
3790
3791		/*
3792		 * Function: _fnFeatureHtmlTable
3793		 * Purpose:  Add any control elements for the table - specifically scrolling
3794		 * Returns:  node: - Node to add to the DOM
3795		 * Inputs:   object:oSettings - dataTables settings object
3796		 */
3797		function _fnFeatureHtmlTable ( oSettings )
3798		{
3799			/* Chack if scrolling is enabled or not - if not then leave the DOM unaltered */
3800			if ( oSettings.oScroll.sX === "" && oSettings.oScroll.sY === "" )
3801			{
3802				return oSettings.nTable;
3803			}
3804
3805			/*
3806			 * The HTML structure that we want to generate in this function is:
3807			 *  div - nScroller
3808			 *    div - nScrollHead
3809			 *      div - nScrollHeadInner
3810			 *        table - nScrollHeadTable
3811			 *          thead - nThead
3812			 *    div - nScrollBody
3813			 *      table - oSettings.nTable
3814			 *        thead - nTheadSize
3815			 *        tbody - nTbody
3816			 *    div - nScrollFoot
3817			 *      div - nScrollFootInner
3818			 *        table - nScrollFootTable
3819			 *          tfoot - nTfoot
3820			 */
3821			var
3822			 	nScroller = document.createElement('div'),
3823			 	nScrollHead = document.createElement('div'),
3824			 	nScrollHeadInner = document.createElement('div'),
3825			 	nScrollBody = document.createElement('div'),
3826			 	nScrollFoot = document.createElement('div'),
3827			 	nScrollFootInner = document.createElement('div'),
3828			 	nScrollHeadTable = oSettings.nTable.cloneNode(false),
3829			 	nScrollFootTable = oSettings.nTable.cloneNode(false),
3830				nThead = oSettings.nTable.getElementsByTagName('thead')[0],
3831			 	nTfoot = oSettings.nTable.getElementsByTagName('tfoot').length === 0 ? null :
3832					oSettings.nTable.getElementsByTagName('tfoot')[0],
3833				oClasses = (typeof oInit.bJQueryUI != 'undefined' && oInit.bJQueryUI) ?
3834					_oExt.oJUIClasses : _oExt.oStdClasses;
3835
3836			nScrollHead.appendChild( nScrollHeadInner );
3837			nScrollFoot.appendChild( nScrollFootInner );
3838			nScrollBody.appendChild( oSettings.nTable );
3839			nScroller.appendChild( nScrollHead );
3840			nScroller.appendChild( nScrollBody );
3841			nScrollHeadInner.appendChild( nScrollHeadTable );
3842			nScrollHeadTable.appendChild( nThead );
3843			if ( nTfoot !== null )
3844			{
3845				nScroller.appendChild( nScrollFoot );
3846				nScrollFootInner.appendChild( nScrollFootTable );
3847				nScrollFootTable.appendChild( nTfoot );
3848			}
3849
3850			nScroller.className = oClasses.sScrollWrapper;
3851			nScrollHead.className = oClasses.sScrollHead;
3852			nScrollHeadInner.className = oClasses.sScrollHeadInner;
3853			nScrollBody.className = oClasses.sScrollBody;
3854			nScrollFoot.className = oClasses.sScrollFoot;
3855			nScrollFootInner.className = oClasses.sScrollFootInner;
3856
3857			if ( oSettings.oScroll.bAutoCss )
3858			{
3859				nScrollHead.style.overflow = "hidden";
3860				nScrollHead.style.position = "relative";
3861				nScrollFoot.style.overflow = "hidden";
3862				nScrollBody.style.overflow = "auto";
3863			}
3864
3865			nScrollHead.style.border = "0";
3866			nScrollHead.style.width = "100%";
3867			nScrollFoot.style.border = "0";
3868			nScrollHeadInner.style.width = "150%"; /* will be overwritten */
3869
3870			/* Modify attributes to respect the clones */
3871			nScrollHeadTable.removeAttribute('id');
3872			nScrollHeadTable.style.marginLeft = "0";
3873			oSettings.nTable.style.marginLeft = "0";
3874			if ( nTfoot !== null )
3875			{
3876				nScrollFootTable.removeAttribute('id');
3877				nScrollFootTable.style.marginLeft = "0";
3878			}
3879
3880			/* Move any caption elements from the body to the header */
3881			var nCaptions = $(oSettings.nTable).children('caption');
3882			for ( var i=0, iLen=nCaptions.length ; i<iLen ; i++ )
3883			{
3884				nScrollHeadTable.appendChild( nCaptions[i] );
3885			}
3886
3887			/*
3888			 * Sizing
3889			 */
3890			/* When xscrolling add the width and a scroller to move the header with the body */
3891			if ( oSettings.oScroll.sX !== "" )
3892			{
3893				nScrollHead.style.width = _fnStringToCss( oSettings.oScroll.sX );
3894				nScrollBody.style.width = _fnStringToCss( oSettings.oScroll.sX );
3895
3896				if ( nTfoot !== null )
3897				{
3898					nScrollFoot.style.width = _fnStringToCss( oSettings.oScroll.sX );
3899				}
3900
3901				/* When the body is scrolled, then we also want to scroll the headers */
3902				$(nScrollBody).scroll( function (e) {
3903					nScrollHead.scrollLeft = this.scrollLeft;
3904
3905					if ( nTfoot !== null )
3906					{
3907						nScrollFoot.scrollLeft = this.scrollLeft;
3908					}
3909				} );
3910			}
3911
3912			/* When yscrolling, add the height */
3913			if ( oSettings.oScroll.sY !== "" )
3914			{
3915				nScrollBody.style.height = _fnStringToCss( oSettings.oScroll.sY );
3916			}
3917
3918			/* Redraw - align columns across the tables */
3919			oSettings.aoDrawCallback.push( {
3920				"fn": _fnScrollDraw,
3921				"sName": "scrolling"
3922			} );
3923
3924			/* Infinite scrolling event handlers */
3925			if ( oSettings.oScroll.bInfinite )
3926			{
3927				$(nScrollBody).scroll( function() {
3928					/* Use a blocker to stop scrolling from loading more data while other data is still loading */
3929					if ( !oSettings.bDrawing )
3930					{
3931						/* Check if we should load the next data set */
3932						if ( $(this).scrollTop() + $(this).height() >
3933							$(oSettings.nTable).height() - oSettings.oScroll.iLoadGap )
3934						{
3935							/* Only do the redraw if we have to - we might be at the end of the data */
3936							if ( oSettings.fnDisplayEnd() < oSettings.fnRecordsDisplay() )
3937							{
3938								_fnPageChange( oSettings, 'next' );
3939								_fnCalculateEnd( oSettings );
3940								_fnDraw( oSettings );
3941							}
3942						}
3943					}
3944				} );
3945			}
3946
3947			oSettings.nScrollHead = nScrollHead;
3948			oSettings.nScrollFoot = nScrollFoot;
3949
3950			return nScroller;
3951		}
3952
3953		/*
3954		 * Function: _fnScrollDraw
3955		 * Purpose:  Update the various tables for resizing
3956		 * Returns:  node: - Node to add to the DOM
3957		 * Inputs:   object:o - dataTables settings object
3958		 * Notes:    It's a bit of a pig this function, but basically the idea to:
3959		 *   1. Re-create the table inside the scrolling div
3960		 *   2. Take live measurements from the DOM
3961		 *   3. Apply the measurements
3962		 *   4. Clean up
3963		 */
3964		function _fnScrollDraw ( o )
3965		{
3966			var
3967				nScrollHeadInner = o.nScrollHead.getElementsByTagName('div')[0],
3968				nScrollHeadTable = nScrollHeadInner.getElementsByTagName('table')[0],
3969				nScrollBody = o.nTable.parentNode,
3970				i, iLen, j, jLen, anHeadToSize, anHeadSizers, anFootSizers, anFootToSize, oStyle, iVis,
3971				iWidth, aApplied=[], iSanityWidth,
3972				nScrollFootInner = (o.nTFoot !== null) ? o.nScrollFoot.getElementsByTagName('div')[0] : null,
3973				nScrollFootTable = (o.nTFoot !== null) ? nScrollFootInner.getElementsByTagName('table')[0] : null,
3974				ie67 = $.browser.msie && $.browser.version <= 7;
3975
3976			/*
3977			 * 1. Re-create the table inside the scrolling div
3978			 */
3979
3980			/* Remove the old minimised thead and tfoot elements in the inner table */
3981			var nTheadSize = o.nTable.getElementsByTagName('thead');
3982			if ( nTheadSize.length > 0 )
3983			{
3984				o.nTable.removeChild( nTheadSize[0] );
3985			}
3986
3987			if ( o.nTFoot !== null )
3988			{
3989				/* Remove the old minimised footer element in the cloned header */
3990				var nTfootSize = o.nTable.getElementsByTagName('tfoot');
3991				if ( nTfootSize.length > 0 )
3992				{
3993					o.nTable.removeChild( nTfootSize[0] );
3994				}
3995			}
3996
3997			/* Clone the current header and footer elements and then place it into the inner table */
3998			nTheadSize = o.nTHead.cloneNode(true);
3999			o.nTable.insertBefore( nTheadSize, o.nTable.childNodes[0] );
4000
4001			if ( o.nTFoot !== null )
4002			{
4003				nTfootSize = o.nTFoot.cloneNode(true);
4004				o.nTable.insertBefore( nTfootSize, o.nTable.childNodes[1] );
4005			}
4006
4007			/*
4008			 * 2. Take live measurements from the DOM - do not alter the DOM itself!
4009			 */
4010
4011			/* Remove old sizing and apply the calculated column widths
4012			 * Get the unique column headers in the newly created (cloned) header. We want to apply the
4013			 * calclated sizes to this header
4014			 */
4015			if ( o.oScroll.sX === "" )
4016			{
4017				nScrollBody.style.width = '100%';
4018				nScrollHeadInner.parentNode.style.width = '100%';
4019			}
4020
4021			var nThs = _fnGetUniqueThs( o, nTheadSize );
4022			for ( i=0, iLen=nThs.length ; i<iLen ; i++ )
4023			{
4024				iVis = _fnVisibleToColumnIndex( o, i );
4025				nThs[i].style.width = o.aoColumns[iVis].sWidth;
4026			}
4027
4028			if ( o.nTFoot !== null )
4029			{
4030				_fnApplyToChildren( function(n) {
4031					n.style.width = "";
4032				}, nTfootSize.getElementsByTagName('tr') );
4033			}
4034
4035			/* Size the table as a whole */
4036			iSanityWidth = $(o.nTable).outerWidth();
4037			if ( o.oScroll.sX === "" )
4038			{
4039				/* No x scrolling */
4040				o.nTable.style.width = "100%";
4041
4042				/* I know this is rubbish - but IE7 will make the width of the table when 100% include
4043				 * the scrollbar - which is shouldn't. When there is a scrollbar we need to take this
4044				 * into account.
4045				 */
4046				if ( ie67 && (nScrollBody.scrollHeight >
4047					nScrollBody.offsetHeight || $(nScrollBody).css('overflow-y') == "scroll")  )
4048				{
4049					o.nTable.style.width = _fnStringToCss( $(o.nTable).outerWidth()-o.oScroll.iBarWidth );
4050				}
4051			}
4052			else
4053			{
4054				if ( o.oScroll.sXInner !== "" )
4055				{
4056					/* x scroll inner has been given - use it */
4057					o.nTable.style.width = _fnStringToCss(o.oScroll.sXInner);
4058				}
4059				else if ( iSanityWidth == $(nScrollBody).width() &&
4060				   $(nScrollBody).height() < $(o.nTable).height() )
4061				{
4062					/* There is y-scrolling - try to take account of the y scroll bar */
4063					o.nTable.style.width = _fnStringToCss( iSanityWidth-o.oScroll.iBarWidth );
4064					if ( $(o.nTable).outerWidth() > iSanityWidth-o.oScroll.iBarWidth )
4065					{
4066						/* Not possible to take account of it */
4067						o.nTable.style.width = _fnStringToCss( iSanityWidth );
4068					}
4069				}
4070				else
4071				{
4072					/* All else fails */
4073					o.nTable.style.width = _fnStringToCss( iSanityWidth );
4074				}
4075			}
4076
4077			/* Recalculate the sanity width - now that we've applied the required width, before it was
4078			 * a temporary variable. This is required because the column width calculation is done
4079			 * before this table DOM is created.
4080			 */
4081			iSanityWidth = $(o.nTable).outerWidth();
4082
4083			/* We want the hidden header to have zero height, so remove padding and borders. Then
4084			 * set the width based on the real headers
4085			 */
4086			anHeadToSize = o.nTHead.getElementsByTagName('tr');
4087			anHeadSizers = nTheadSize.getElementsByTagName('tr');
4088
4089			_fnApplyToChildren( function(nSizer, nToSize) {
4090				oStyle = nSizer.style;
4091				oStyle.paddingTop = "0";
4092				oStyle.paddingBottom = "0";
4093				oStyle.borderTopWidth = "0";
4094				oStyle.borderBottomWidth = "0";
4095				oStyle.height = 0;
4096
4097				iWidth = $(nSizer).width();
4098				nToSize.style.width = _fnStringToCss( iWidth );
4099				aApplied.push( iWidth );
4100			}, anHeadSizers, anHeadToSize );
4101			$(anHeadSizers).height(0);
4102
4103			if ( o.nTFoot !== null )
4104			{
4105				/* Clone the current footer and then place it into the body table as a "hidden header" */
4106				anFootSizers = nTfootSize.getElementsByTagName('tr');
4107				anFootToSize = o.nTFoot.getElementsByTagName('tr');
4108
4109				_fnApplyToChildren( function(nSizer, nToSize) {
4110					oStyle = nSizer.style;
4111					oStyle.paddingTop = "0";
4112					oStyle.paddingBottom = "0";
4113					oStyle.borderTopWidth = "0";
4114					oStyle.borderBottomWidth = "0";
4115					oStyle.height = 0;
4116
4117					iWidth = $(nSizer).width();
4118					nToSize.style.width = _fnStringToCss( iWidth );
4119					aApplied.push( iWidth );
4120				}, anFootSizers, anFootToSize );
4121				$(anFootSizers).height(0);
4122			}
4123
4124			/*
4125			 * 3. Apply the measurements
4126			 */
4127
4128			/* "Hide" the header and footer that we used for the sizing. We want to also fix their width
4129			 * to what they currently are
4130			 */
4131			_fnApplyToChildren( function(nSizer) {
4132				nSizer.innerHTML = "";
4133				nSizer.style.width = _fnStringToCss( aApplied.shift() );
4134			}, anHeadSizers );
4135
4136			if ( o.nTFoot !== null )
4137			{
4138				_fnApplyToChildren( function(nSizer) {
4139					nSizer.innerHTML = "";
4140					nSizer.style.width = _fnStringToCss( aApplied.shift() );
4141				}, anFootSizers );
4142			}
4143
4144			/* Sanity check that the table is of a sensible width. If not then we are going to get
4145			 * misalignment - try to prevent this by not allowing the table to shrink below its min width
4146			 */
4147			if ( $(o.nTable).outerWidth() < iSanityWidth )
4148			{
4149				/* The min width depends upon if we have a vertical scrollbar visible or not */
4150				var iCorrection = ((nScrollBody.scrollHeight > nScrollBody.offsetHeight ||
4151					$(nScrollBody).css('overflow-y') == "scroll")) ?
4152						iSanityWidth+o.oScroll.iBarWidth : iSanityWidth;
4153
4154				/* IE6/7 are a law unto themselves... */
4155				if ( ie67 && (nScrollBody.scrollHeight >
4156					nScrollBody.offsetHeight || $(nScrollBody).css('overflow-y') == "scroll")  )
4157				{
4158					o.nTable.style.width = _fnStringToCss( iCorrection-o.oScroll.iBarWidth );
4159				}
4160
4161				/* Apply the calculated minimum width to the table wrappers */
4162				nScrollBody.style.width = _fnStringToCss( iCorrection );
4163				nScrollHeadInner.parentNode.style.width = _fnStringToCss( iCorrection );
4164
4165				if ( o.nTFoot !== null )
4166				{
4167					nScrollFootInner.parentNode.style.width = _fnStringToCss( iCorrection );
4168				}
4169
4170				/* And give the user a warning that we've stopped the table getting too small */
4171				if ( o.oScroll.sX === "" )
4172				{
4173					_fnLog( o, 1, "The table cannot fit into the current element which will cause column"+
4174						" misalignment. The table has been drawn at its minimum possible width." );
4175				}
4176				else if ( o.oScroll.sXInner !== "" )
4177				{
4178					_fnLog( o, 1, "The table cannot fit into the current element which will cause column"+
4179						" misalignment. Increase the sScrollXInner value or remove it to allow automatic"+
4180						" calculation" );
4181				}
4182			}
4183			else
4184			{
4185				nScrollBody.style.width = _fnStringToCss( '100%' );
4186				nScrollHeadInner.parentNode.style.width = _fnStringToCss( '100%' );
4187
4188				if ( o.nTFoot !== null )
4189				{
4190					nScrollFootInner.parentNode.style.width = _fnStringToCss( '100%' );
4191				}
4192			}
4193
4194
4195			/*
4196			 * 4. Clean up
4197			 */
4198
4199			if ( o.oScroll.sY === "" )
4200			{
4201				/* IE7< puts a vertical scrollbar in place (when it shouldn't be) due to subtracting
4202				 * the scrollbar height from the visible display, rather than adding it on. We need to
4203				 * set the height in order to sort this. Don't want to do it in any other browsers.
4204				 */
4205				if ( ie67 )
4206				{
4207					nScrollBody.style.height = _fnStringToCss( o.nTable.offsetHeight+o.oScroll.iBarWidth );
4208				}
4209			}
4210
4211			if ( o.oScroll.sY !== "" && o.oScroll.bCollapse )
4212			{
4213				nScrollBody.style.height = _fnStringToCss( o.oScroll.sY );
4214
4215				var iExtra = (o.oScroll.sX !== "" && o.nTable.offsetWidth > nScrollBody.offsetWidth) ?
4216				 	o.oScroll.iBarWidth : 0;
4217				if ( o.nTable.offsetHeight < nScrollBody.offsetHeight )
4218				{
4219					nScrollBody.style.height = _fnStringToCss( $(o.nTable).height()+iExtra );
4220				}
4221			}
4222
4223			/* Finally set the width's of the header and footer tables */
4224			var iOuterWidth = $(o.nTable).outerWidth();
4225			nScrollHeadTable.style.width = _fnStringToCss( iOuterWidth );
4226			nScrollHeadInner.style.width = _fnStringToCss( iOuterWidth+o.oScroll.iBarWidth );
4227
4228			if ( o.nTFoot !== null )
4229			{
4230				nScrollFootInner.style.width = _fnStringToCss( o.nTable.offsetWidth+o.oScroll.iBarWidth );
4231				nScrollFootTable.style.width = _fnStringToCss( o.nTable.offsetWidth );
4232			}
4233
4234			/* If sorting or filtering has occured, jump the scrolling back to the top */
4235			if ( o.bSorted || o.bFiltered )
4236			{
4237				nScrollBody.scrollTop = 0;
4238			}
4239		}
4240
4241		/*
4242		 * Function: _fnAdjustColumnSizing
4243		 * Purpose:  Adjust the table column widths for new data
4244		 * Returns:  -
4245		 * Inputs:   object:oSettings - dataTables settings object
4246		 * Notes:    You would probably want to do a redraw after calling this function!
4247		 */
4248		function _fnAdjustColumnSizing ( oSettings )
4249		{
4250			/* Not interested in doing column width calculation if autowidth is disabled */
4251			if ( oSettings.oFeatures.bAutoWidth === false )
4252			{
4253				return false;
4254			}
4255
4256			_fnCalculateColumnWidths( oSettings );
4257			for ( var i=0 , iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
4258			{
4259				oSettings.aoColumns[i].nTh.style.width = oSettings.aoColumns[i].sWidth;
4260			}
4261		}
4262
4263
4264		/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
4265		 * Section - Feature: Filtering
4266		 */
4267
4268		/*
4269		 * Function: _fnFeatureHtmlFilter
4270		 * Purpose:  Generate the node required for filtering text
4271		 * Returns:  node
4272		 * Inputs:   object:oSettings - dataTables settings object
4273		 */
4274		function _fnFeatureHtmlFilter ( oSettings )
4275		{
4276			var sSearchStr = oSettings.oLanguage.sSearch;
4277			sSearchStr = (sSearchStr.indexOf('_INPUT_') !== -1) ?
4278			  sSearchStr.replace('_INPUT_', '<input type="text" />') :
4279			  sSearchStr==="" ? '<input type="text" />' : sSearchStr+' <input type="text" />';
4280
4281			var nFilter = document.createElement( 'div' );
4282			nFilter.className = oSettings.oClasses.sFilter;
4283			nFilter.innerHTML = '<label>'+sSearchStr+'</label>';
4284			if ( oSettings.sTableId !== '' && typeof oSettings.aanFeatures.f == "undefined" )
4285			{
4286				nFilter.setAttribute( 'id', oSettings.sTableId+'_filter' );
4287			}
4288
4289			var jqFilter = $("input", nFilter);
4290			jqFilter.val( oSettings.oPreviousSearch.sSearch.replace('"','&quot;') );
4291			jqFilter.bind( 'keyup.DT', function(e) {
4292				/* Update all other filter input elements for the new display */
4293				var n = oSettings.aanFeatures.f;
4294				for ( var i=0, iLen=n.length ; i<iLen ; i++ )
4295				{
4296					if ( n[i] != $(this).parents('div.dataTables_filter')[0] )
4297					{
4298						$('input', n[i]).val( this.value );
4299					}
4300				}
4301
4302				/* Now do the filter */
4303				if ( this.value != oSettings.oPreviousSearch.sSearch )
4304				{
4305					_fnFilterComplete( oSettings, {
4306						"sSearch": this.value,
4307						"bRegex":  oSettings.oPreviousSearch.bRegex,
4308						"bSmart":  oSettings.oPreviousSearch.bSmart
4309					} );
4310				}
4311			} );
4312
4313			jqFilter.bind( 'keypress.DT', function(e) {
4314				/* Prevent default */
4315				if ( e.keyCode == 13 )
4316				{
4317					return false;
4318				}
4319			} );
4320
4321			return nFilter;
4322		}
4323
4324		/*
4325		 * Function: _fnFilterComplete
4326		 * Purpose:  Filter the table using both the global filter and column based filtering
4327		 * Returns:  -
4328		 * Inputs:   object:oSettings - dataTables settings object
4329		 *           object:oSearch: search information
4330		 *           int:iForce - optional - force a research of the master array (1) or not (undefined or 0)
4331		 */
4332		function _fnFilterComplete ( oSettings, oInput, iForce )
4333		{
4334			/* Filter on everything */
4335			_fnFilter( oSettings, oInput.sSearch, iForce, oInput.bRegex, oInput.bSmart );
4336
4337			/* Now do the individual column filter */
4338			for ( var i=0 ; i<oSettings.aoPreSearchCols.length ; i++ )
4339			{
4340				_fnFilterColumn( oSettings, oSettings.aoPreSearchCols[i].sSearch, i,
4341					oSettings.aoPreSearchCols[i].bRegex, oSettings.aoPreSearchCols[i].bSmart );
4342			}
4343
4344			/* Custom filtering */
4345			if ( _oExt.afnFiltering.length !== 0 )
4346			{
4347				_fnFilterCustom( oSettings );
4348			}
4349
4350			/* Tell the draw function we have been filtering */
4351			oSettings.bFiltered = true;
4352			$(oSettings.oInstance).trigger('filter', oSettings);
4353
4354			/* Redraw the table */
4355			oSettings._iDisplayStart = 0;
4356			_fnCalculateEnd( oSettings );
4357			_fnDraw( oSettings );
4358
4359			/* Rebuild search array 'offline' */
4360			_fnBuildSearchArray( oSettings, 0 );
4361		}
4362
4363		/*
4364		 * Function: _fnFilterCustom
4365		 * Purpose:  Apply custom filtering functions
4366		 * Returns:  -
4367		 * Inputs:   object:oSettings - dataTables settings object
4368		 */
4369		function _fnFilterCustom( oSettings )
4370		{
4371			var afnFilters = _oExt.afnFiltering;
4372			for ( var i=0, iLen=afnFilters.length ; i<iLen ; i++ )
4373			{
4374				var iCorrector = 0;
4375				for ( var j=0, jLen=oSettings.aiDisplay.length ; j<jLen ; j++ )
4376				{
4377					var iDisIndex = oSettings.aiDisplay[j-iCorrector];
4378
4379					/* Check if we should use this row based on the filtering function */
4380					if ( !afnFilters[i]( oSettings, _fnGetRowData( oSettings, iDisIndex, 'filter' ), iDisIndex ) )
4381					{
4382						oSettings.aiDisplay.splice( j-iCorrector, 1 );
4383						iCorrector++;
4384					}
4385				}
4386			}
4387		}
4388
4389		/*
4390		 * Function: _fnFilterColumn
4391		 * Purpose:  Filter the table on a per-column basis
4392		 * Returns:  -
4393		 * Inputs:   object:oSettings - dataTables settings object
4394		 *           string:sInput - string to filter on
4395		 *           int:iColumn - column to filter
4396		 *           bool:bRegex - treat search string as a regular expression or not
4397		 *           bool:bSmart - use smart filtering or not
4398		 */
4399		function _fnFilterColumn ( oSettings, sInput, iColumn, bRegex, bSmart )
4400		{
4401			if ( sInput === "" )
4402			{
4403				return;
4404			}
4405
4406			var iIndexCorrector = 0;
4407			var rpSearch = _fnFilterCreateSearch( sInput, bRegex, bSmart );
4408
4409			for ( var i=oSettings.aiDisplay.length-1 ; i>=0 ; i-- )
4410			{
4411				var sData = _fnDataToSearch( _fnGetCellData( oSettings, oSettings.aiDisplay[i], iColumn, 'filter' ),
4412					oSettings.aoColumns[iColumn].sType );
4413				if ( ! rpSearch.test( sData ) )
4414				{
4415					oSettings.aiDisplay.splice( i, 1 );
4416					iIndexCorrector++;
4417				}
4418			}
4419		}
4420
4421		/*
4422		 * Function: _fnFilter
4423		 * Purpose:  Filter the data table based on user input and draw the table
4424		 * Returns:  -
4425		 * Inputs:   object:oSettings - dataTables settings object
4426		 *           string:sInput - string to filter on
4427		 *           int:iForce - optional - force a research of the master array (1) or not (undefined or 0)
4428		 *           bool:bRegex - treat as a regular expression or not
4429		 *           bool:bSmart - perform smart filtering or not
4430		 */
4431		function _fnFilter( oSettings, sInput, iForce, bRegex, bSmart )
4432		{
4433			var i;
4434			var rpSearch = _fnFilterCreateSearch( sInput, bRegex, bSmart );
4435
4436			/* Check if we are forcing or not - optional parameter */
4437			if ( typeof iForce == 'undefined' || iForce === null )
4438			{
4439				iForce = 0;
4440			}
4441
4442			/* Need to take account of custom filtering functions - always filter */
4443			if ( _oExt.afnFiltering.length !== 0 )
4444			{
4445				iForce = 1;
4446			}
4447
4448			/*
4449			 * If the input is blank - we want the full data set
4450			 */
4451			if ( sInput.length <= 0 )
4452			{
4453				oSettings.aiDisplay.splice( 0, oSettings.aiDisplay.length);
4454				oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
4455			}
4456			else
4457			{
4458				/*
4459				 * We are starting a new search or the new search string is smaller
4460				 * then the old one (i.e. delete). Search from the master array
4461			 	 */
4462				if ( oSettings.aiDisplay.length == oSettings.aiDisplayMaster.length ||
4463					   oSettings.oPreviousSearch.sSearch.length > sInput.length || iForce == 1 ||
4464					   sInput.indexOf(oSettings.oPreviousSearch.sSearch) !== 0 )
4465				{
4466					/* Nuke the old display array - we are going to rebuild it */
4467					oSettings.aiDisplay.splice( 0, oSettings.aiDisplay.length);
4468
4469					/* Force a rebuild of the search array */
4470					_fnBuildSearchArray( oSettings, 1 );
4471
4472					/* Search through all records to populate the search array
4473					 * The the oSettings.aiDisplayMaster and asDataSearch arrays have 1 to 1
4474					 * mapping
4475					 */
4476					for ( i=0 ; i<oSettings.aiDisplayMaster.length ; i++ )
4477					{
4478						if ( rpSearch.test(oSettings.asDataSearch[i]) )
4479						{
4480							oSettings.aiDisplay.push( oSettings.aiDisplayMaster[i] );
4481						}
4482					}
4483			  }
4484			  else
4485				{
4486			  	/* Using old search array - refine it - do it this way for speed
4487			  	 * Don't have to search the whole master array again
4488					 */
4489			  	var iIndexCorrector = 0;
4490
4491			  	/* Search the current results */
4492			  	for ( i=0 ; i<oSettings.asDataSearch.length ; i++ )
4493					{
4494			  		if ( ! rpSearch.test(oSettings.asDataSearch[i]) )
4495						{
4496			  			oSettings.aiDisplay.splice( i-iIndexCorrector, 1 );
4497			  			iIndexCorrector++;
4498			  		}
4499			  	}
4500			  }
4501			}
4502			oSettings.oPreviousSearch.sSearch = sInput;
4503			oSettings.oPreviousSearch.bRegex = bRegex;
4504			oSettings.oPreviousSearch.bSmart = bSmart;
4505		}
4506
4507		/*
4508		 * Function: _fnBuildSearchArray
4509		 * Purpose:  Create an array which can be quickly search through
4510		 * Returns:  -
4511		 * Inputs:   object:oSettings - dataTables settings object
4512		 *           int:iMaster - use the master data array - optional
4513		 */
4514		function _fnBuildSearchArray ( oSettings, iMaster )
4515		{
4516			if ( !oSettings.oFeatures.bServerSide )
4517			{
4518				/* Clear out the old data */
4519				oSettings.asDataSearch.splice( 0, oSettings.asDataSearch.length );
4520
4521				var aArray = (typeof iMaster != 'undefined' && iMaster == 1) ?
4522				 	oSettings.aiDisplayMaster : oSettings.aiDisplay;
4523
4524				for ( var i=0, iLen=aArray.length ; i<iLen ; i++ )
4525				{
4526					oSettings.asDataSearch[i] = _fnBuildSearchRow( oSettings,
4527						_fnGetRowData( oSettings, aArray[i], 'filter' ) );
4528				}
4529			}
4530		}
4531
4532		/*
4533		 * Function: _fnBuildSearchRow
4534		 * Purpose:  Create a searchable string from a single data row
4535		 * Returns:  -
4536		 * Inputs:   object:oSettings - dataTables settings object
4537		 *           array:aData - Row data array to use for the data to search
4538		 */
4539		function _fnBuildSearchRow( oSettings, aData )
4540		{
4541			var sSearch = '';
4542			if ( typeof oSettings.__nTmpFilter == 'undefined' ) {
4543				oSettings.__nTmpFilter = document.createElement('div');
4544			}
4545			var nTmp = oSettings.__nTmpFilter;
4546
4547			for ( var j=0, jLen=oSettings.aoColumns.length ; j<jLen ; j++ )
4548			{
4549				if ( oSettings.aoColumns[j].bSearchable )
4550				{
4551					var sData = aData[j];
4552					sSearch += _fnDataToSearch( sData, oSettings.aoColumns[j].sType )+'  ';
4553				}
4554			}
4555
4556			/* If it looks like there is an HTML entity in the string, attempt to decode it */
4557			if ( sSearch.indexOf('&') !== -1 )
4558			{
4559				nTmp.innerHTML = sSearch;
4560				sSearch = nTmp.textContent ? nTmp.textContent : nTmp.innerText;
4561
4562				/* IE and Opera appear to put an newline where there is a <br> tag - remove it */
4563				sSearch = sSearch.replace(/\n/g," ").replace(/\r/g,"");
4564			}
4565
4566			return sSearch;
4567		}
4568
4569		/*
4570		 * Function: _fnFilterCreateSearch
4571		 * Purpose:  Build a regular expression object suitable for searching a table
4572		 * Returns:  RegExp: - constructed object
4573		 * Inputs:   string:sSearch - string to search for
4574		 *           bool:bRegex - treat as a regular expression or not
4575		 *           bool:bSmart - perform smart filtering or not
4576		 */
4577		function _fnFilterCreateSearch( sSearch, bRegex, bSmart )
4578		{
4579			var asSearch, sRegExpString;
4580
4581			if ( bSmart )
4582			{
4583				/* Generate the regular expression to use. Something along the lines of:
4584				 * ^(?=.*?\bone\b)(?=.*?\btwo\b)(?=.*?\bthree\b).*$
4585				 */
4586				asSearch = bRegex ? sSearch.split( ' ' ) : _fnEscapeRegex( sSearch ).split( ' ' );
4587				sRegExpString = '^(?=.*?'+asSearch.join( ')(?=.*?' )+').*$';
4588				return new RegExp( sRegExpString, "i" );
4589			}
4590			else
4591			{
4592				sSearch = bRegex ? sSearch : _fnEscapeRegex( sSearch );
4593				return new RegExp( sSearch, "i" );
4594			}
4595		}
4596
4597		/*
4598		 * Function: _fnDataToSearch
4599		 * Purpose:  Convert raw data into something that the user can search on
4600		 * Returns:  string: - search string
4601		 * Inputs:   string:sData - data to be modified
4602		 *           string:sType - data type
4603		 */
4604		function _fnDataToSearch ( sData, sType )
4605		{
4606			if ( typeof _oExt.ofnSearch[sType] == "function" )
4607			{
4608				return _oExt.ofnSearch[sType]( sData );
4609			}
4610			else if ( sType == "html" )
4611			{
4612				return sData.replace(/\n/g," ").replace( /<.*?>/g, "" );
4613			}
4614			else if ( typeof sData == "string" )
4615			{
4616				return sData.replace(/\n/g," ");
4617			}
4618			else if ( sData === null )
4619			{
4620				return '';
4621			}
4622			return sData;
4623		}
4624
4625
4626		/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
4627		 * Section - Feature: Sorting
4628		 */
4629
4630		/*
4631	 	 * Function: _fnSort
4632		 * Purpose:  Change the order of the table
4633		 * Returns:  -
4634		 * Inputs:   object:oSettings - dataTables settings object
4635		 *           bool:bApplyClasses - optional - should we apply classes or not
4636		 * Notes:    We always sort the master array and then apply a filter again
4637		 *   if it is needed. This probably isn't optimal - but atm I can't think
4638		 *   of any other way which is (each has disadvantages). we want to sort aiDisplayMaster -
4639		 *   but according to aoData[]._aData
4640		 */
4641		function _fnSort ( oSettings, bApplyClasses )
4642		{
4643			var
4644				iDataSort, iDataType,
4645				i, iLen, j, jLen,
4646				aaSort = [],
4647			 	aiOrig = [],
4648				oSort = _oExt.oSort,
4649				aoData = oSettings.aoData,
4650				aoColumns = oSettings.aoColumns;
4651
4652			/* No sorting required if server-side or no sorting array */
4653			if ( !oSettings.oFeatures.bServerSide &&
4654				(oSettings.aaSorting.length !== 0 || oSettings.aaSortingFixed !== null) )
4655			{
4656				if ( oSettings.aaSortingFixed !== null )
4657				{
4658					aaSort = oSettings.aaSortingFixed.concat( oSettings.aaSorting );
4659				}
4660				else
4661				{
4662					aaSort = oSettings.aaSorting.slice();
4663				}
4664
4665				/* If there is a sorting data type, and a fuction belonging to it, then we need to
4666				 * get the data from the developer's function and apply it for this column
4667				 */
4668				for ( i=0 ; i<aaSort.length ; i++ )
4669				{
4670					var iColumn = aaSort[i][0];
4671					var iVisColumn = _fnColumnIndexToVisible( oSettings, iColumn );
4672					var sDataType = oSettings.aoColumns[ iColumn ].sSortDataType;
4673					if ( typeof _oExt.afnSortData[sDataType] != 'undefined' )
4674					{
4675						var aData = _oExt.afnSortData[sDataType]( oSettings, iColumn, iVisColumn );
4676						for ( j=0, jLen=aoData.length ; j<jLen ; j++ )
4677						{
4678							_fnSetCellData( oSettings, j, iColumn, aData[j] );
4679						}
4680					}
4681				}
4682
4683				/* Create a value - key array of the current row positions such that we can use their
4684				 * current position during the sort, if values match, in order to perform stable sorting
4685				 */
4686				for ( i=0, iLen=oSettings.aiDisplayMaster.length ; i<iLen ; i++ )
4687				{
4688					aiOrig[ oSettings.aiDisplayMaster[i] ] = i;
4689				}
4690
4691				/* Do the sort - here we want multi-column sorting based on a given data source (column)
4692				 * and sorting function (from oSort) in a certain direction. It's reasonably complex to
4693				 * follow on it's own, but this is what we want (example two column sorting):
4694				 *  fnLocalSorting = function(a,b){
4695				 *  	var iTest;
4696				 *  	iTest = oSort['string-asc']('data11', 'data12');
4697				 *  	if (iTest !== 0)
4698				 *  		return iTest;
4699				 *    iTest = oSort['numeric-desc']('data21', 'data22');
4700				 *    if (iTest !== 0)
4701				 *  		return iTest;
4702				 *  	return oSort['numeric-asc']( aiOrig[a], aiOrig[b] );
4703				 *  }
4704				 * Basically we have a test for each sorting column, if the data in that column is equal,
4705				 * test the next column. If all columns match, then we use a numeric sort on the row
4706				 * positions in the original data array to provide a stable sort.
4707				 */
4708				var iSortLen = aaSort.length;
4709				oSettings.aiDisplayMaster.sort( function ( a, b ) {
4710					var iTest, iDataSort, sDataType;
4711					for ( i=0 ; i<iSortLen ; i++ )
4712					{
4713						iDataSort = aoColumns[ aaSort[i][0] ].iDataSort;
4714						sDataType = aoColumns[ iDataSort ].sType;
4715						iTest = oSort[ (sDataType?sDataType:'string')+"-"+aaSort[i][1] ](
4716							_fnGetCellData( oSettings, a, iDataSort, 'sort' ),
4717							_fnGetCellData( oSettings, b, iDataSort, 'sort' )
4718						);
4719
4720						if ( iTest !== 0 )
4721						{
4722							return iTest;