
Math.bool=function(){return Math.floor(Math.random()*1.9999)==0;}
Math.rand=function(pMin,pMax,pArrOfExcludedIds){if(typeof(pArrOfExcludedIds)=="undefined")
pArrOfExcludedIds=[];if(pArrOfExcludedIds==null||pArrOfExcludedIds.length==0){return Math.floor(Math.random()*(pMax-pMin+1)+pMin);}
var roll=pArrOfExcludedIds[0];while(pArrOfExcludedIds.contains(roll))
roll=Math.floor(Math.random()*(pMax-pMin+1)+pMin);return roll;}
if(!Array.prototype.contains)Array.prototype.contains=function(obj,pUseStrictTypeComparison){if(typeof(pUseStrictTypeComparison)=="undefined")
pUseStrictTypeComparison=true;var i=this.length;if(pUseStrictTypeComparison){while(i--){if(this[i]===obj){return true;}}}else{while(i--){if(this[i]==obj){return true;}}}
return false;}
if(!Array.prototype.insert)Array.prototype.insert=function(begin,end,v){while(begin+1<end&&this[begin+1]<v){this.swap(begin,begin+1);++begin;}
this[begin]=v;}
if(!Array.prototype.getRand)Array.prototype.getRand=function(){return this[Math.rand(0,this.length-1)];}
if(!Array.prototype.sortNum)Array.prototype.sortNum=function(){return this.sort(function(a,b){return a-b;});}
if(!Array.prototype.shuffle)Array.prototype.shuffle=function(){for(var rnd,tmp,i=this.length;i;rnd=parseInt(Math.random()*i),tmp=this[--i],this[i]=this[rnd],this[rnd]=tmp);};if(!Array.prototype.compare)Array.prototype.compare=function(testArr){if(this.length!=testArr.length)return false;for(var i=0;i<testArr.length;i++){if(this[i].compare){if(!this[i].compare(testArr[i]))return false;}
if(this[i]!==testArr[i])return false;}
return true;}
if(!Array.prototype.findit)Array.prototype.findit=function(pSearchFor,pOnlyReturnFirstIndex,pStrictTypeComparison){if(this.length<1)
return-1;if((typeof(pSearchFor)=="undefined")||(pSearchFor==null))
return false;if((typeof(pOnlyReturnFirstIndex)=="undefined")||(pOnlyReturnFirstIndex==null))
pOnlyReturnFirstIndex=false;if((typeof(pStrictTypeComparison)=="undefined")||(pStrictTypeComparison==null))
pStrictTypeComparison=true;var len=this.length;var i;if(pOnlyReturnFirstIndex){var returnArray=[];if(typeof(pSearchFor)=='function'){for(i=0;i<len;i++){if(pSearchFor.test(this[i])){return i;}}}else if(pStrictTypeComparison){for(i=0;i<len;i++){if(this[i]===pSearchFor){return i;}}}else{for(i=0;i<len;i++){if(this[i]==pSearchFor){return i;}}}
return false;}else{var returnArray=[];if(typeof(pSearchFor)=='function'){for(i=0;i<len;i++){if(pSearchFor.test(this[i])){returnArray.push(i);}}}else if(pStrictTypeComparison){for(i=0;i<len;i++){if(this[i]===pSearchFor){returnArray.push(i);}}}else{for(i=0;i<len;i++){if(this[i]==pSearchFor){returnArray.push(i);}}}
return returnArray.length<=0?false:returnArray;}}
if(!Array.prototype.remove)Array.prototype.remove=function(from,to){var rest=this.slice((to||from)+1||this.length);this.length=from<0?this.length+from:from;return this.push.apply(this,rest);};if(!Array.prototype.swap)Array.prototype.swap=function(a,b){var tmp=this[a];this[a]=this[b];this[b]=tmp;}
if(!Array.prototype.removeit)Array.prototype.removeit=function(a){if(this.length<1)
return;var index=this.findit(a,true,true);if(index<0||index===false)
return;while(index!==false&&index>=0&&this.length>0){this.splice(index,1);index=this.findit(a,true,true);}}
Array.prototype.partition=function(begin,end,pivot,pArrayElementType,pOptionalValueProperty,pOptionalPropertyType){if(!pArrayElementType||pArrayElementType==null)
pArrayElementType='number';if(!pOptionalPropertyType||pOptionalPropertyType==null)
pOptionalPropertyType='number';if(!pOptionalValueProperty)
pOptionalValueProperty=null;var piv=this[pivot];this.swap(pivot,end-1);var store=begin;var ix;if(pArrayElementType=='number'||(pArrayElementType!='string'&&!pOptionalValueProperty)){for(ix=begin;ix<end-1;++ix){if(parseFloat(this[ix])<=parseFloat(piv)){this.swap(store,ix);++store;}}}else if(pArrayElementType=='string'){for(ix=begin;ix<end-1;++ix){if(this[ix].toUpperCase()<=piv.toUpperCase()){this.swap(store,ix);++store;}}}else{if(pOptionalPropertyType=='string'){for(ix=begin;ix<end-1;++ix){if(this[ix].getAttribute(pOptionalValueProperty).toString().toUpperCase()<=piv.getAttribute(pOptionalValueProperty).toString().toUpperCase()){this.swap(store,ix);++store;}}}
else
{for(ix=begin;ix<end-1;++ix){if(parseFloat(this[ix].getAttribute(pOptionalValueProperty))<=parseFloat(piv.getAttribute(pOptionalValueProperty))){this.swap(store,ix);++store;}}}}
this.swap(end-1,store);return store;}
if(!Array.prototype.qsort)Array.prototype.qsort=function(begin,end,pArrayElementType,pOptionalValueProperty,pOptionalPropertyType){if(end-1>begin){var pivot=begin+Math.floor(Math.random()*(end-begin));pivot=this.partition(begin,end,pivot,pArrayElementType,pOptionalValueProperty,pOptionalPropertyType);this.qsort(begin,pivot,pArrayElementType,pOptionalValueProperty,pOptionalPropertyType);this.qsort(pivot+1,end,pArrayElementType,pOptionalValueProperty,pOptionalPropertyType);}}
if(!Array.prototype.quickSort)Array.prototype.quickSort=function(pArrayElementType,pOptionalValueProperty,pOptionalPropertyType){if(this.length<2)
return;if(!pArrayElementType)
pArrayElementType=typeof(this[0]);if(!pOptionalValueProperty)
pOptionalValueProperty=null;if(!pOptionalPropertyType)
pOptionalPropertyType=null;this.qsort(0,this.length,pArrayElementType,pOptionalValueProperty,pOptionalPropertyType);}
if(!Array.prototype.merge_inplace)Array.prototype.merge_inplace=function(begin,begin_right,end){for(;begin<begin_right;++begin){if(this[begin]>this[begin_right]){var v=this[begin];this[begin]=this[begin_right];this.insert(begin_right,end,v);}}}
if(!Array.prototype.msort)Array.prototype.msort=function(begin,end){var size=end-begin;if(size<2)return;var begin_right=begin+Math.floor(size/2);this.msort(begin,begin_right);this.msort(begin_right,end);this.merge_inplace(begin,begin_right,end);}
if(!Array.prototype.merge_sort_inplace)Array.prototype.merge_sort_inplace=function(){this.msort(0,this.length);}
if(!String.prototype.trim)String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"");}
if(!String.prototype.ltrim)String.prototype.ltrim=function(){return this.replace(/^\s+/,"");}
if(!String.prototype.rtrim)String.prototype.rtrim=function(){return this.replace(/\s+$/,"");}
