/**
*	A LouGIS library by Lounaispaikka.
*	@copyright Lounaispaikka, www.lounaispaikka.fi <CC BY-SA 3.0>
*	@version 2011-12-19T13:31:44+02:00
*/
var ajaxCount=0;String.prototype.capitalize=function(){return this.charAt(0).toUpperCase()+this.slice(1)};function prettyTitle(a){a=a;a=str_replace("_"," ",a);a=a.toLowerCase();return a=a.capitalize()}
function str_replace(a,b,d,g){var f=0,i=0,c="",e="",h=0,j=0;a=[].concat(a);b=[].concat(b);d=d;var k=b instanceof Array,l=d instanceof Array;d=[].concat(d);if(g)this.window[g]=0;f=0;for(h=d.length;f<h;f++)if(d[f]!==""){i=0;for(j=a.length;i<j;i++){c=d[f]+"";e=k?b[i]!==undefined?b[i]:"":b[0];d[f]=c.split(a[i]).join(e);if(g&&d[f]!==c)this.window[g]+=(c.length-d[f].length)/a[i].length}}return l?d:d[0]}function ilog(a){firebug(a)}function firebug(a){window.console.log(a)}
function prettyInteger(a,b){a=Math.round(a);var d=0;if(b!=null){a=a.toString().split("");var g=a.length,f;for(f=0;f<b&&f<g;f++)d+=a[f]*Math.pow(10,g-f-1);if(a[f]>4)d+=Math.pow(10,g-f)}else d=a;d=Ext.util.Format.number(d,"0,0");return str_replace(","," ",d)}function prettyDecimal(a,b){if(b==null)b="00";a=Ext.util.Format.number(a,"0,0."+b);return str_replace([",","."],[" ",","],a)}
function t(){switch(arguments.length){case 0:return false;case 1:return arguments[0];default:for(var a=arguments[0],b=1;b<arguments.length;b++)if(a.indexOf("%"+b)>=0)a=str_replace("%"+b,arguments[b],a);return a}}function notify(a,b){Ext.ux.Growl.notify({title:a,message:b,iconCls:"x-growl-icon",alignment:"br-br",offset:[-6,-25]})}
function viewportSize(){var a,b;if(typeof window.innerWidth!="undefined"){a=window.innerWidth;b=window.innerHeight}else if(typeof document.documentElement!="undefined"&&typeof document.documentElement.clientWidth!="undefined"&&document.documentElement.clientWidth!=0){a=document.documentElement.clientWidth;b=document.documentElement.clientHeight}else{a=document.getElementsByTagName("body")[0].clientWidth;b=document.getElementsByTagName("body")[0].clientHeight}var d=Array();d.height=b;d.width=a;return d}
function maxElementHeight(a){var b=viewportSize();return b.height>a?a:b.height-20}function maxElementWidth(a){var b=viewportSize();return b.width>a?a:b.width-20}function growlRequest(a){Ext.Ajax.on("beforerequest",addAjaxNotify,this);Ext.Ajax.on("requestcomplete",removeAjaxNotify,this);Ext.Ajax.request(a)}function getJsonOfStore(a){var b=[];a=a.getRange();for(var d=0;d<a.length;d++)b.push(a[d].data);return Ext.encode(b)}
function getUrlParam(a){a=a.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");a=(new RegExp("[\\?&]"+a+"=([^&#]*)")).exec(window.location.href);return a==null?"":a[1]}
function getJsonOfTree(a){function b(c){var e=[];if(c.hasChildNodes()){e.id=c.id;e.text=c.text;e.parentId=c.parentNode.id;e.isLeaf=false;e.isChecked=empty(c.attributes.checked)?"no":c.attributes.checked?"yes":"no";if(empty(c.attributes.layerId))e.isChecked="no";else e.layerId=c.attributes.layerId;for(var h=0;h<c.childNodes.length;++h)e.push(b(c.childNodes[h]))}else{e.id=c.id;e.text=c.text;e.parentId=c.parentNode.id;e.isLeaf=true;e.isChecked=empty(c.attributes.checked)?"no":c.attributes.checked?"yes":
"no";if(empty(c.attributes.layerId))e.isChecked="no";else e.layerId=c.attributes.layerId}return e}function d(c){var e="";if(c.isLeaf)e+='{ "id": "'+c.id+'", "parent": "'+c.parentId+'", "text": "'+c.text+'", "isLeaf": "'+c.isLeaf+'", "isChecked": "'+c.isChecked+'", "layerId": "'+c.layerId+'" }';else{e+='{ "id": "'+c.id+'", "parent": "'+c.parentId+'", "text": "'+c.text+'", "isLeaf": "'+c.isLeaf+'", "isChecked": "'+c.isChecked+'", "layerId": "'+c.layerId+'", "children": [';for(var h=0;h<c.length;++h){e+=
d(c[h],c.parentId);if(h<c.length-1)e+=","}e+="] }"}return e}a=Ext.getCmp(a).root.childNodes;if(a==undefined)return false;for(var g="[",f=0;f<a.length;++f){var i=d(b(a[f]));g+=i;if(f<a.length-1)g+=","}g+="]";return g}var addAjaxNotify=function(){ajaxCount++;ajaxCount==1&&Ext.ux.Growl.notify({title:t(""),message:t(""),iconCls:"x-growl-icon",alignment:"br-br",offset:[-6,-25],pin:true,id:"ajaxNotify"})},removeAjaxNotify=function(){ajaxCount--;if(ajaxCount<1){var a=Ext.get("ajaxNotify");a!=null&&a.remove()}};
function empty(a){var b;if(a===""||a===0||a==="0"||a===null||a===false||typeof a==="undefined")return true;if(typeof a=="object"){for(b in a)return false;return true}return false}function getElementsByClassName(a,b){return a.getElementsByClassName?a.getElementsByClassName(b):function(d,g){if(g==null)g=document;var f=[],i=g.getElementsByTagName("*"),c=i.length,e=new RegExp("(^|\\s)"+d+"(\\s|$)"),h,j;for(j=h=0;h<c;++h)if(e.test(i[h].className)){f[j]=i[h];++j}return f}(b,a)}
function nl2br(a){return(a+"").replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g,"$1<br />$2")};

