function trackPageview() {
}
function getQuickRandInt(low, high){
return Math.floor(Math.random() * (high-low+1) + low);
}
function getQueryStringParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
function decToBin(n){
return parseInt(n).toString(2);
}
function decToHex(n){
return parseInt(n).toString(16);
}
function decToHT(n){
return n ? "H" : "T";
}
/*
function shuffle (a){ //shuffle array
for(var j, x, i = a.length; i; j = parseInt(Math.random() * i), x = a[--i], a[i] = a[j], a[j] = x){};
return a;
};
*/
function shuffle(a) {
var j, x, i;
for (i = a.length - 1; i > 0; i--) {
j = Math.floor(Math.random() * (i + 1));
x = a[i];
a[i] = a[j];
a[j] = x;
}
return a;
}
function getQS() {
var retval = "";
var str = window.location.search;
if (str != "" && str.charAt(0) === '?') {
retval = str.substr(1);
}
return retval;
}
function selectText( containerid ) {
var node = document.getElementById( containerid );
if ( document.selection ) {
var range = document.body.createTextRange();
range.moveToElementText( node );
range.select();
} else if ( window.getSelection ) {
var range = document.createRange();
range.selectNodeContents( node );
window.getSelection().removeAllRanges();
window.getSelection().addRange( range );
}
}
function isCurrLocationWihoutHash(url){
//returns true if the new url is the same except the hash
var curr_url = window.location.pathname + window.location.search;
return curr_url === url;
}
function isCurrHash(hash){
return hash === window.location.hash;
}
function isObjectEmpty(o){
return o ? Object.keys(o).length <= 0 : 1;
}
function querystringToObject(qs) {
try {
return qs ? JSON.parse('{"' + qs.replace(/&/g, '","').replace(/=/g,'":"') + '"}', function(key, value) { return key===""?value:decodeURIComponent(value) }) : {};
} catch (e) {
return {};
}
}
function total_xdigit_combinations(x){
return Math.pow(10, x);
}
function total_xdigit_combinations_hex(x){
return Math.pow(16, x);
}
function total_xdigit_combinations_bin(x){
return Math.pow(2, x);
}
function total_possible_1tox_combinations(n, l, h, order_matters) {
if (typeof order_matters === "undefined") order_matters = false;
var nums_in_range = h - l + 1;
return total_possible_combinations(nums_in_range, n, true, order_matters);
}
function total_possible_combinations(n, r, unique = true, order_matters = false){
if (typeof order_matters === "undefined") order_matters = false;
if (typeof unique === "undefined") unique = true;
if (r > n) {
unique = false; //more numbers being generated than possible therefore asssume not unique
}
if (unique) {
var comb = 1;
for (var i = 0; i < r ; i++){
comb = comb * (n - i);
}
if (!order_matters) { //n choose r
return comb / factorial(r);
} else {
return comb; //n Pick r
}
} else {
return Math.pow(n, r);
}
}
function factorial(n) {
var f = 1;
for (var i = 1; i<= n; i++){
f = f * i;
}
return f;
}
function sortJsonArrayByProperty(objArray, prop, direction){
// usage
// sortJsonArrayByProperty(obj, 'attributes.OBJECTID');
// sortJsonArrayByProperty(obj, 'attributes.OBJECTID', -1);
if (arguments.length<2) throw new Error("sortJsonArrayByProp requires 2 arguments");
var direct = arguments.length>2 ? arguments[2] : 1; //Default to ascending
if (objArray && objArray.constructor===Array){
var propPath = (prop.constructor===Array) ? prop : prop.split(".");
objArray.sort(function(a,b){
for (var p in propPath){
if (a[propPath[p]] && b[propPath[p]]){
a = a[propPath[p]];
b = b[propPath[p]];
}
}
// convert numeric strings to integers
a = a.match(/^\d+$/) ? +a : a;
b = b.match(/^\d+$/) ? +b : b;
return ( (a < b) ? -1*direct : ((a > b) ? 1*direct : 0) );
});
}
}
function replaceBrWithNewLines(str){
return str.replace(/
|
|
/gi, "\n");
}