﻿// Jeff's QueryString Object
var QueryString = {

    keyValuePairs: Array,
    q: "",
    init: function() {

        this.q = window.location.search;
        if (this.q.length > 1) {
            this.q = this.q.substring(1, this.q.length);
        } else {
            this.q = null;
        }
        this.keyValuePairs = new Array();
        if (this.q) {
            for (var i = 0; i < this.q.split("&").length; i++) {
                this.keyValuePairs[i] = this.q.split("&")[i];
            }
        }
    },
    get: function(key) {
        for (var j = 0; j < this.keyValuePairs.length; j++) {
            if (this.keyValuePairs[j].split("=")[0] == key)
                return this.keyValuePairs[j].split("=")[1];
        }
        return false;
    },
    toString: function() { return this.q; },
    getKeys: function() {
        var a = new Array(this.getLength());
        for (var j = 0; j < this.keyValuePairs.length; j++) {
            a[j] = this.keyValuePairs[j].split("=")[0];
        }
        return a;
    },

    getKeyValuePairs: function() { return this.keyValuePairs; },
    getLength: function() { return this.keyValuePairs.length; }

}
QueryString.init();



function valEmail(prmElem) {
    // 1+ (alphanum OR '-' OR '.') then 1 '@' then any (alphanum OR '-') then 1 '.' 
    // then 0+ (alphanum OR '-' OR '.') then 2+ (alphanum); match the whole pattern.
    var pattern = /^[a-zA-Z0-9\-\.]+@{1}[a-zA-Z0-9\-]+\.{1}[a-zA-Z0-9\-\.]*[a-zA-Z0-9]{2,}$/;
    return (prmElem.match(pattern)) ? true : false;
}


String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g, "");
}

