/*
 * Core JavaScript Extension
 * 
 * Copyright (c) 2006-2011 i-deal Studio
 */
String.prototype.toUTF8=function(){var n,s='';for(var i=0,iTextLen=this.length;i<iTextLen;i++){n=this.charCodeAt(i);if(n<0x80)s+=String.fromCharCode(n);else if(n<0x800)s+=String.fromCharCode(0xC0|n>>6)+String.fromCharCode(0x80|n&0x3F);else if(n<0x10000)s+=String.fromCharCode(0xE0|n>>12)+String.fromCharCode(0x80|n>>6&0x3F)+String.fromCharCode(0x80|n&0x3F);else s+=String.fromCharCode(0xF0|n>>18)+String.fromCharCode(0x80|n>>12&0x3F)+String.fromCharCode(0x80|n>>6&0x3F)+String.fromCharCode(0x80|n&0x3F);};return s;};String.prototype.MatchAll=function(re,pockets,limit){if(!(re instanceof RegExp))return null;var R=[],item,i,L;if(re.global)re.lastIndex=0;else re=new RegExp(re.source,'g'+(re.ignoreCase?'i':'')+(re.multiline?'m':''));if(pockets&&typeof pockets!='object')pockets=void 0;while(null!==(item=re.exec(this))){if(pockets){for(i=0,L=item.length;i<L;i++){if(!pockets[i])pockets[i]=[];pockets[i][R.length]=item[i];};};R[R.length]=item;if(limit>0&&R.length>=limit)break;};return R.length?R:null;};String.prototype.LTrim=function(){return this.replace(/^\s+/,'');};String.prototype.RTrim=function(){return this.replace(/\s+$/,'');};String.prototype.Trim=function(){return this.replace(/^\s+|\s+$/g,'');};String.prototype.HtmlEncode=(function(){var o={'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#039;'};return function(){return this.replace(/[&<>"']/g,function(s){return o[s];});};})();String.prototype.HtmlDecode=(function(){var o={'&amp;':'&','&lt;':'<','&gt;':'>','&quot;':'"','&#039;':"'"};return function(){return this.replace(/&(?:amp|[lg]t|quot|#039);/g,function(s){return o[s];});};})();String.prototype.Repeat=function(cnt){var r="";while(--cnt>=0)r+=this;return r;};String.prototype.Split=function(re){return this.length?this.split(re):[];};String.prototype.SubStr=function(start,length){var L=this.length;if(length===void 0)length=L;if(length==0)return"";if(start===void 0)start=0;var Start=(start>=0)?start:L+start;if(Start>L)Start=L;else if(Start<0)Start=0;var End=(length>0)?Start+length:L+length;return this.substring(Start,End);};String.prototype.Splice=function(start,length,replacement){var r='',L=this.length;if(length===void 0)length=L;if(start===void 0)start=0;var Start=(start>=0)?start:L+start;if(Start>L)Start=L;else if(Start<0)Start=0;if(Start>0)r+=this.substring(0,Start);if(replacement&&replacement.length)r+=replacement;var End=(length>=0)?Start+length:L+length;r+=this.substring(End);return r;};String.prototype.Replace=function(re,repl,obj){if(typeof repl=='function'){return this.replace(re,function(){return repl.apply(obj||this,arguments);});}else return this.replace(re,repl);};String.prototype.UrlEncode=function(){return encodeURIComponent(this);};String.prototype.RE=function(){return this.replace(/([\$\^\*\(\)\+\[\]\{\}\|\.\/\?\\])/g,'\\$1');};String.prototype.StrTr=function(from,to){if(typeof from=='object'){var a=[];for(var k in from){a.push(k.toString().RE());};if(a.length){var re=new RegExp('('+a.join('|')+')','g');return this.replace(re,function(k){return(k in from)&&(from[k]!=void 0)?from[k]:'';});}else return''+this;}else if(typeof from=='string'){var L=from.length;if(L){var R={},ch;if(typeof to!='string')to='';for(var i=0;i<L;i++){ch=from.charAt(i);if(!(ch in R))R[ch]=to.charAt(i);};var re=new RegExp('(['+from.RE()+'])','g');return this.replace(re,function(k){return(k in R)&&(R[k]!=void 0)?R[k]:'';});}else return''+this;}else{throw{message:'Invalid argument'};};};String.prototype.Format=function(){var i=0,A=arguments;return this.replace(/%(?:(%)|(?:(\d+):)?([dfsb]))/g,function($0,$1,$2,$3){if(typeof $1==='string')return $1;if(!isNaN($2=+$2))i=$2;switch($3){case'd':return parseInt(A[i++]);case's':return''+A[i++];case'f':return parseFloat(A[i++]);case'b':return!!A[i++];default:return'['+typeof A[i++]+']'};});};Number.prototype.Hex=function(len){var s=this.toString(16).toUpperCase(),L=s.length;if(len>0){if(len>L)s='0'.Repeat(len-L)+s;else if(len<L)s=s.SubStr(-len);};return s;};Array.prototype.Slice=function(start,length){var L=this.length;if(length===void 0)length=L;if(length==0)return[];if(start===void 0)start=0;var Start=(start>=0)?start:L+start;if(Start>L)Start=L;else if(Start<0)Start=0;var End=(length>0)?Start+length:L+length;return this.slice(Start,End);};Array.prototype.Last=function(){var i=this.length;if(i>0)return this[--i];};if(!Array.prototype.indexOf)Array.prototype.indexOf=function(value,start){start=+start;var L=this.length,i=isNaN(start)||(start=Math.floor(start))<0?0:(start<L?start:L-1);for(;i<L;i++)if(this[i]===value)return i;return-1;};Array.prototype.Isset=function(i,undef){return i>=0&&i<this.length&&(!undef||this[i]!==void 0);};Array.prototype.Unset=function(i){var L=this.length;if(i>=0&&i<=--L){var n=i+1;while(i<L)this[i++]=this[n++];this.length=L;};return this;};Array.prototype.Resize=function(length,value){var i=this.length;this.length=length;while(i<length)this[i++]=value;return this;};if(!Array.prototype.unshift||3!==[30].unshift(10,20))Array.prototype.unshift=function(){var cnt=arguments.length;if(cnt){var n=this.length,L;this.length=L=n+cnt;while(n>0)this[--L]=this[--n];while(cnt-->0)this[cnt]=arguments[cnt];};return this.length;};Array.prototype.Splice=function(start,length,replacement){var r=[],L=this.length;if(length===void 0)length=L;if(start===void 0)start=0;var Start=(start>=0)?start:L+start;if(Start>L)Start=L;else if(Start<0)Start=0;if(Start>0)r=r.concat(this.slice(0,Start));if(replacement!=void 0){if(!(replacement instanceof Array))replacement=[replacement];r=r.concat(replacement);};var End=(length>=0)?Start+length:L+length;r=r.concat(this.slice(End));return r;};Array.prototype.Each=function(func,obj){if(func instanceof Function){for(var i=0,L=this.length;i<L;i++){func.call(obj||this,this[i],i);};};return this;};Array.prototype.Insert=function(start,values){if(!(values instanceof Array))values=arguments.length>=2?[values]:[];var cnt=values.length;if(cnt){var n=this.length,L;this.length=L=n+cnt;if(start>n)start=n;else if(start<0)start=0;while(n>start)this[--L]=this[--n];while(cnt-->0)this[start+cnt]=values[cnt];};return this;};
