﻿function querystring(param) {
    var a = window.location.search.substring(1);
    b = a.split("&");
    for (var i = 0; i < b.length; i++) {
        var c = b[i].split("=");
        if (c[0] == param) 
            return c[1];
    }
}

/*
function showTopErr(msg) {
    document.getElementById('topmsg').style.display = 'block';
    document.getElementById('topmsg').className = 'error';
    document.getElementById('topmsg').innerHTML = msg;
}
*/

// php port
function print_r(elem) {
    var s = '';
    for (property in elem) {
        s += property + ': ' + elem[property] + '' + '\n';
    }
    alert(s);
}

function getDuplicates(arr) {
    var len = arr.length,
      out = [],
      counts = {};

    for (var i = 0; i < len; i++) {
        var item = arr[i];
        var count = counts[item];
        counts[item] = counts[item] >= 1 ? counts[item] + 1 : 1;
    }

    for (var item in counts) {
        if (counts[item] > 1)
            out.push(item);
    }

    return out;
}

String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g, "");
}
String.prototype.ltrim = function() {
    return this.replace(/^\s+/, "");
}
String.prototype.rtrim = function() {
    return this.replace(/\s+$/, "");
}
String.prototype.isEmail = function() {
    var emailPattern = /^[a-zA-Z0-9._+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
    return emailPattern.test(this);
}
