﻿(function(){function p(b,p){var g=function(a,c){return{type:"select",id:"selSortBy"+a,"default":"",label:"",items:[],setup:function(a){a=a.$.rows[0].cells.length;var d,q;this.clear();for(d=0;d<a;d++)q=d+1,this.add(b.lang.tablesort.column+" "+q,d);c&&this.disable()}}},m=function(a,c){return{type:"select",id:"selSortType"+a,"default":"",label:"",items:[[b.lang.tablesort.alphanumeric,"alphanumeric"],[b.lang.tablesort.numeric,"numeric"],[b.lang.tablesort.date,"date"]],setup:function(a){c&&this.disable()}}},
n=function(a,c){return{type:"radio",id:"rdbOrder"+a,"default":"asc",items:[[b.lang.tablesort.asc,"asc"],[b.lang.tablesort.desc,"desc"]],setup:function(a){if(c)for(a=0;a<this._.children.length;a++)this._.children[a].disable()}}},r=function(){var a=!this.getValue(),c=this.getDialog(),a=a?"disable":"enable",e=this.id.substring(this.id.length-1);c.getContentElement("sort","selSortBy"+e)[a]();c.getContentElement("sort","selSortType"+e)[a]();c=c.getContentElement("sort","rdbOrder"+e);for(e=0;e<c._.children.length;e++)c._.children[e][a]()},
h=function(a){a&&(this.table=a)};h.prototype={sort:function(a,c){var e=function(a,d){var b,e,f;for(f=0;f<c.length;f++){e=c[f];switch(e.type){case "numeric":b=h.sort.numeric(a[e.column],d[e.column]);break;case "date":b=h.sort.date(a[e.column],d[e.column]);break;default:b=h.sort.alpha(a[e.column],d[e.column])}"desc"==e.order&&(b*=-1);if(0!=b)break}return b},d=[],b;switch(a){case "thead":d.push(this.table.$.tHead);break;case "tfoot":d.push(this.table.$.tFoot);break;default:d=this.table.$.tBodies}for(b=
0;b<d.length;b++){var k=[],f;for(f=0;f<d[b].rows.length;f++){var g=[],l;for(l=0;l<d[b].rows[f].cells.length;l++)g.push(this.getInnerText(d[b].rows[f].cells[l]));g.push(d[b].rows[f]);k.push(g)}k.sort(e);for(f=0;f<k.length;f++)d[b].appendChild(k[f][k[f].length-1])}},getInnerText:function(a){var c="function"==typeof a.getElementsByTagName&&a.getElementsByTagName("input").length;if("undefined"==typeof a.textContent||c)if("undefined"==typeof a.innerText||c)if("undefined"==typeof a.text||c)switch(a.nodeType){case 3:if("input"==
a.nodeName.toLowerCase())return a.value.replace(/^\s+|\s+$/g,"");case 4:return a.nodeValue.replace(/^\s+|\s+$/g,"");case 1:case 11:for(var c="",e=0;e<a.childNodes.length;e++)c+=this.getInnerText(a.childNodes[e]);return c.replace(/^\s+|\s+$/g,"");default:return""}else return a.text.replace(/^\s+|\s+$/g,"");else return a.innerText.replace(/^\s+|\s+$/g,"");else return a.textContent.replace(/^\s+|\s+$/g,"")}};h.sort={numeric:function(a,c){var e=parseFloat(a.replace(/[^0-9.-]/g,""));isNaN(e)&&(e=0);var b=
parseFloat(c.replace(/[^0-9.-]/g,""));isNaN(b)&&(b=0);return e-b},alpha:function(a,c){return a==c?0:a<c?-1:1},date:function(a,c){var b=new Date(c),d=(new Date(a)).getTime(),b=b.getTime();return isNaN(d)||isNaN(b)||d==b?0:d-b}};return{title:b.lang.tablesort.title,minWidth:430,minHeight:CKEDITOR.env.ie?180:150,onShow:function(){var a=b.getSelection().getRanges(),c=null;(c=b.getSelection().getSelectedElement())?"table"!=c.getName()&&(c=null):0<a.length&&(c=a[0].getCommonAncestor(!0).getAscendant("table",
!0));(this._.selectedElement=c)&&this.setupContent(c)},onOk:function(){var a=this._.selectedElement;this.commitContent(a);var c,b=[],d;for(d=0;3>d;d++)if(c=this.getContentElement("sort","chkKey"+d),!c||c.getValue())c={},c.column=this.getContentElement("sort","selSortBy"+d).getValue(),c.type=this.getContentElement("sort","selSortType"+d).getValue(),c.order=this.getContentElement("sort","rdbOrder"+d).getValue(),b.push(c);(new h(a)).sort(this.getContentElement("sort","selSort").getValue(),b);return!0},
contents:[{id:"sort",label:b.lang.tablesort.title,elements:[{type:"hbox",widths:["5%","25%","30%","40%"],styles:["vertical-align:top"],children:[{type:"vbox",padding:"5px",children:[{type:"html",html:"\x26nbsp;"},{type:"html",html:"\x26nbsp;"},{type:"checkbox",id:"chkKey1",isChanged:!1,label:"",onChange:r},{type:"checkbox",id:"chkKey2",isChanged:!1,label:"",onChange:r}]},{type:"vbox",padding:"5px",children:[{type:"html",html:b.lang.tablesort.by},g(0),g(1,!0),g(2,!0)]},{type:"vbox",padding:"5px",children:[{type:"html",
html:b.lang.tablesort.type},m(0),m(1,!0),m(2,!0)]},{type:"vbox",padding:"5px",children:[{type:"html",html:b.lang.tablesort.order},n(0),n(1,!0),n(2,!0)]}]},{type:"select",id:"selSort","default":"tbody",label:"",items:[[b.lang.tablesort.head,"thead"],[b.lang.tablesort.body,"tbody"],[b.lang.tablesort.foot,"tfoot"]]}]}]}}CKEDITOR.dialog.add("tablesort",function(b){return p(b,"table")})})();