/*
 * File:        KeyTable.min.js
 * Version:     1.1.1
 * Author:      Allan Jardine (www.sprymedia.co.uk)
 * 
 * Copyright 2009 Allan Jardine, all rights reserved.
 *
 * This source file is free software, under either the GPL v2 license or a
 * BSD (3 point) style license, as supplied with this software.
 * 
 * This source file is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE. See the license files for details.
 */
function KeyTable(q){this.block=false;this.event={remove:{}};this.fnGetCurrentPosition=function(){return[c,a]
};this.fnGetCurrentData=function(){return m.innerHTML};this.fnGetCurrentTD=function(){return m
};var f=null;var m=null;var c=null;var a=null;var G=null;var i="focus";var w=false;
var r={action:[],esc:[],focus:[],blur:[]};var e=null;var n;var s;var C=false;function B(H){return function(I,L,K){if((I==null||typeof I=="number")&&(L==null||typeof L=="number")&&typeof K=="function"){x(H,I,L,K)
}else{if(typeof I=="object"&&typeof L=="function"){var J=j(I);x(H,J[0],J[1],L)}else{alert("Unhandable event type was added: x"+I+"  y:"+L+"  z:"+K)
}}}}function d(H){return function(I,L,K){if((I==null||typeof arguments[0]=="number")&&(L==null||typeof arguments[1]=="number")){if(typeof arguments[2]=="function"){F(H,I,L,K)
}else{F(H,I,L)}}else{if(typeof arguments[0]=="object"){var J=j(I);if(typeof arguments[1]=="function"){F(H,J[0],J[1],L)
}else{F(H,J[0],J[1])}}else{alert("Unhandable event type was removed: x"+I+"  y:"+L+"  z:"+K)
}}}}for(var o in r){if(o){this.event[o]=B(o);this.event.remove[o]=d(o)}}function x(K,H,J,I){r[K].push({x:H,y:J,fn:I})
}function F(N,I,M,K){var L=0;for(var J=0,H=r[N].length;J<H-L;J++){if(typeof K!="undefined"){if(r[N][J-L].x==I&&r[N][J-L].y==M&&r[N][J-L].fn==K){r[N].splice(J-L,1);
L++}}else{if(r[N][J-L].x==I&&r[N][J-L].y==M){r[N].splice(J,1);return 1}}}return L
}function A(M,H,L){var K=0;var I=r[M];for(var J=0;J<I.length;J++){if((I[J].x==H&&I[J].y==L)||(I[J].x==null&&I[J].y==L)||(I[J].x==H&&I[J].y==null)||(I[J].x==null&&I[J].y==null)){I[J].fn(E(H,L),H,L);
K++}}return K}function b(L,T){if(m==L){return}if(typeof T=="undefined"){T=true}if(m!==null){p(m)
}jQuery(L).addClass(i);if(e){var J=e.fnSettings();var O=g(L)[1];var P=w;while(O>=J.fnDisplayEnd()){if(J._iDisplayLength>=0){if(J._iDisplayStart+J._iDisplayLength<J.fnRecordsDisplay()){J._iDisplayStart+=J._iDisplayLength
}}else{J._iDisplayStart=0}e.oApi._fnCalculateEnd(J)}while(O<J._iDisplayStart){J._iDisplayStart=J._iDisplayLength>=0?J._iDisplayStart-J._iDisplayLength:0;
if(J._iDisplayStart<0){J._iDisplayStart=0}e.oApi._fnCalculateEnd(J)}e.oApi._fnDraw(J);
w=P}var M=j(L);m=L;c=M[0];a=M[1];if(T){var Q=document.documentElement.clientHeight;
var S=document.documentElement.clientWidth;var K=document.body.scrollTop||document.documentElement.scrollTop;
var N=document.body.scrollLeft||document.documentElement.scrollLeft;var H=L.offsetHeight;
var I=L.offsetWidth;var R=y(L);if(R[1]+H>K+Q){z(R[1]+H-Q)}else{if(R[1]<K){z(R[1])
}}if(R[0]+I>N+S){t(R[0]+I-S)}else{if(R[0]<N){t(R[0])}}}A("focus",c,a)}function u(){p(m);
c=null;a=null;m=null;k()}function p(H){jQuery(H).removeClass(i);A("blur",c,a)}function l(H){var I=this;
while(I.nodeName!="TD"){I=I.parentNode}b(I);D()}function h(N){if(G.block||!w){return true
}if(N.metaKey||N.altKey||N.ctrlKey){return true}var I,O;var L,H;if(e){var M=e.fnSettings();
L=M.aoColumns.length;H=M.aiDisplay.length;var K=g(m);if(K===null){return}c=K[0];a=K[1]
}else{L=f.getElementsByTagName("tr")[0].getElementsByTagName("td").length;H=f.getElementsByTagName("tr").length
}var J=(N.keyCode==9&&N.shiftKey)?-1:N.keyCode;switch(J){case 13:A("action",c,a);
return true;case 27:if(!A("esc",c,a)){u()}break;case -1:case 37:if(c>0){I=c-1;O=a
}else{if(a>0){I=L-1;O=a-1}else{if(J==-1&&n){C=true;s.focus();setTimeout(function(){C=false
},0);w=false;u();return true}else{return false}}}break;case 38:if(a>0){I=c;O=a-1}else{return false
}break;case 9:case 39:if(c<L-1){I=c+1;O=a}else{if(a<H-1){I=0;O=a+1}else{if(J==9&&n){C=true;
s.focus();setTimeout(function(){C=false},0);w=false;u();return true}else{return false
}}}break;case 40:if(a<H-1){I=c;O=a+1}else{return false}break;default:return true}b(E(I,O));
return false}function D(){if(!w){w=true}}function k(){w=false}function E(H,J){if(e){var I=e.fnSettings();
if(typeof I.aoData[I.aiDisplay[J]]!="undefined"){return I.aoData[I.aiDisplay[J]].nTr.getElementsByTagName("td")[H]
}else{return null}}else{return jQuery("tr:eq("+J+")>td:eq("+H+")",f)[0]}}function j(I){if(e){var H=e.fnSettings();
return[jQuery("td",I.parentNode).index(I),jQuery("tr",I.parentNode.parentNode).index(I.parentNode)+H._iDisplayStart]
}else{return[jQuery("td",I.parentNode).index(I),jQuery("tr",I.parentNode.parentNode).index(I.parentNode)]
}}function z(H){document.documentElement.scrollTop=H;document.body.scrollTop=H}function t(H){document.documentElement.scrollLeft=H;
document.body.scrollLeft=H}function y(J){var I=0;var H=0;if(J.offsetParent){I=J.offsetLeft;
H=J.offsetTop;J=J.offsetParent;while(J){I+=J.offsetLeft;H+=J.offsetTop;J=J.offsetParent
}}return[I,H]}function g(O){var M=e.fnSettings();for(var K=0,H=M.aiDisplay.length;
K<H;K++){var N=M.aoData[M.aiDisplay[K]].nTr;var I=N.getElementsByTagName("td");for(var J=0,L=I.length;
J<L;J++){if(I[J]==O){return[J,K]}}}return null}function v(H,J){G=J;if(typeof H=="undefined"){H={}
}if(typeof H.focus=="undefined"){H.focus=[0,0]}if(typeof H.table=="undefined"){H.table=jQuery("table.KeyTable")[0]
}if(typeof H.focusClass!="undefined"){i=H.focusClass}if(typeof H.datatable!="undefined"){e=H.datatable
}if(typeof H.initScroll=="undefined"){H.initScroll=true}if(typeof H.form=="undefined"){H.form=false
}n=H.form;f=H.table.getElementsByTagName("tbody")[0];if(n){var I=document.createElement("div");
s=document.createElement("input");I.style.height="1px";I.style.width="0px";I.style.overflow="hidden";
if(typeof H.tabIndex!="undefined"){I.tabIndex=H.tabIndex}I.appendChild(s);H.table.parentNode.insertBefore(I,H.table.nextSibling);
jQuery(s).focus(function(){if(!C){w=true;C=false;b((typeof H.focus.nodeName!="undefined"?H.focus:E(H.focus[0],H.focus[1])),H.initScroll);
setTimeout(function(){s.blur()},0)}});w=false}else{b((typeof H.focus.nodeName!="undefined"?H.focus:E(H.focus[0],H.focus[1])),H.initScroll);
D()}if(jQuery.browser.mozilla||jQuery.browser.opera){jQuery(document).bind("keypress",h)
}else{jQuery(document).bind("keydown",h)}if(e){jQuery("td",e.fnGetNodes()).click(l)
}else{jQuery("td",f).click(l)}jQuery(document).click(function(L){var M=L.target;var K=false;
while(M){if(M==H.table){K=true;break}M=M.parentNode}if(!K){u()}})}v(q,this)};