var grSmartSort;function SortObject(a,b){this._recid=a;this._props=b;this._sortid=null;return this}function sortController(){this.dateRE=/^(\d{2})[\/\- ](\d{2})[\/\- ](\d{2})/;return this}sortController.prototype.alpha=function(d,c){d=d[1];c=c[1];if(d>c){return 1}if(d<c){return -1}return 0};sortController.prototype.digit=function(d,c){d=parseInt(d[1]);c=parseInt(c[1]);if(d>c){return 1}if(d<c){return -1}return 0};sortController.prototype.date=function(d,c){d=d[1].replace(dateRE,"$3$1$2");c=c[1].replace(dateRE,"$3$1$2");if(d>c){return 1}if(d<c){return -1}return 0};sortController.prototype.natural=function(f,e){function k(l){var q=[],b=0,p=-1,o=0,d,c;while(d=(c=l.charAt(b++)).charCodeAt(0)){var a=(d==46||(d>=48&&d<=57));if(a!==o){q[++p]="";o=a}q[p]+=c}return q}var g=k(f);var i=k(e);for(x=0;g[x]&&i[x];x++){if(g[x]!==i[x]){var j=Number(g[x]),h=Number(i[x]);if(j==g[x]&&h==i[x]){return j-h}else{return(g[x]>i[x])?1:-1}}}return g.length-i.length};function smartSort(a){this.sort_obs=[];this.recInfos=new String(document.getElementById("ssRecInfoIDs").value).split("~");this.sortController=new sortController();for(var b=0;b<this.recInfos.length;++b){cur_rec=this.recInfos[b];if(!gr_objExists(document.getElementById(cur_rec))){continue}props=document.getElementById(cur_rec).value.split("~");this.sort_obs.push(new SortObject(props.shift(),props))}this.sort_holder=document.createElement("div");this.sort_holder.id="sort_holder";document.body.appendChild(this.sort_holder);return this}smartSort.prototype.load_controls=function(){tmp=document.createElement("div");tmp.id="smartSortControls";content='Sorteer op: <a href="javascript:void(0)" onclick="grSmartSort.sort(1)">Plaats</a><a href="javascript:void(0)" onclick="grSmartSort.sort(6)">Datum</a>';tmp.innerHTML=content;document.body.appendChild(tmp)};smartSort.prototype.set_method=function(a){switch(a){case 0:this.sort_md=0;this.sort_fn=this.sortController.natural;break;case 1:this.sort_md=1;this.sort_fn=this.sortController.alpha;break;case 4:this.sort_md=4;this.sort_fn=this.sortController.digit;break;case 6:this.sort_md=6;this.sort_fn=this.sortController.date;break;default:this.sort_md=1;this.sort_fn=this.sortController.alpha;break}};smartSort.prototype.clear_sorts=function(a){sorters=document.getElementById("SortContainer").getElementsByTagName("a");for(sort in sorters){if(sorters[sort]==a){continue}sorters[sort].className=""}};smartSort.prototype.sort=function(d,f){var a=[];var c="";this.clear_sorts(d);d.className=(d.className=="sorted")?"sorted_reverse":"sorted";this.set_method(f);if(typeof this.sort_fn!="function"||typeof this.sort_md!="number"){return}for(var b=0;b<this.sort_obs.length;++b){sort_ob=this.sort_obs[b];a.push([sort_ob._recid,sort_ob._props[this.sort_md]])}this.sort_holder.innerHTML="";a.sort(this.sort_fn);if(d.className=="sorted_reverse"){a.reverse()}for(var b=0;b<a.length;++b){this.sort_holder.appendChild(document.getElementById(a[b][0]))}for(var b=0;b<a.length;++b){document.getElementById("ObjectsContainer").appendChild(document.getElementById(a[b][0]));c+=a[b][0].replace("RecID","ssRecInfoID")+((b==a.length-1)?"":"~")}document.getElementById("ssRecInfoIDs").value=c;mySmartSelect.addFilter()};smartSort.prototype.recycle=function(a){this.reload(a)};smartSort.prototype.order=function(a){this.reload(a)};smartSort.prototype.reload=function(d){var a,b;try{a=document.getElementById("sort_order");b=document.getElementById("sort_method").value}catch(c){a=null;b=null}if(a==null||b==null){return}this.sort(a,b)};var grSmartSortInit=function(){grSmartSort=new smartSort({})};if(window.addEventListener){window.addEventListener("load",grSmartSortInit,false)}else{if(window.attachEvent){window.attachEvent("onload",grSmartSortInit)}else{window.onload=function(){grSmartSortInit()}}};
