function global_util(){
    var queryString = new Object;
    this.parseParameter = function() {
        var temp_query = new RegExp ('^[^\\?]+\\?(.*)$');
        if ( ! temp_query.test(location) ) return false;
        var array = temp_query.exec(location);
        queryString.QUERY_STRING = array[1];
        var params = queryString.QUERY_STRING.split(/&/);
        for ( var i = 0; i < params.length; i++ ) {
            var keys = params[i].split(/=/);
            queryString[ keys[0] ] = unescape(keys[1]);
        }

    }

    this.paramValue = function(key) {
        if ( key == null ) {
            alert("param() function has been used incorrectly.\nUSAGE: param(key)");
            return false;
        }
        return queryString[key];
    }

    this.paramNames = function() {
        var paramNames = new Array();

        var params = queryString.QUERY_STRING.split(/&/);
        for ( var i = 0; i < params.length; i++ ) {
            var keys = params[i].split(/=/);
            paramNames[i] = keys[0];
        }

        return paramNames;
    }

    this.parseParameter();

    this.replace = function(string,text,by) {
        var string = new String(string);
        var strLength = string.length, txtLength = text.length;
        if ((strLength == 0) || (txtLength == 0)) return string;
        var i = string.indexOf(text);
        if ((!i) && (text != string.substring(0,txtLength))) return string;
        if (i == -1) return string;
        var newstr = string.substring(0,i) + by;
        if (i+txtLength < strLength)
            newstr += this.replace(string.substring(i+txtLength,strLength),text,by);
        return newstr;
    }

    this.removeNonNumericsFromString = function(getString){
        var newString = '';
        if(getString != ""){
            getStringLen = getString.length - 1;
            for (i=0; i<=getStringLen; i++){
                if(isNaN(getString.charAt(i)) == false || getString.charAt(i) == '.'){
                    newString = newString + getString.charAt(i);
                 }
            }
            return newString;
        }else{
            newString = 0;
            return newString;
        }
    }

    this.removeNonAlphaNumeric = function(getString){
    getString.replace("[0-9]|[ !@#\\$%\\^&\\*\\(\\)_\\+\\-={}\\|:\"<>\\?\\-=\\[\\];',\\./`~'???]","");
    return getString;
    }


    this.checkNonNumericsFromString = function(getString){
        var theStr = getString;
        if (theStr.length < 0) {
         return false;
         }
         var validChars = '0123456789';
         for (var i = 0; i < theStr.length; i++) {
                if (validChars.indexOf(theStr.charAt(i)) == -1){
                return false;
                }
        }
       return true;
    }

    this.formatCurrency = function(strValue) {
        if(strValue != ""){
            strValue = this.removeNonNumericsFromString(strValue);
            dblValue = parseFloat(strValue);
            blnSign = (dblValue == (dblValue = Math.abs(dblValue)));
            dblValue = Math.floor(dblValue*100+0.50000000001);
            intCents = dblValue%100;
            strCents = intCents.toString();
            dblValue = Math.floor(dblValue/100).toString();
            if(intCents<10) strCents = "0" + strCents;
            for (var i = 0; i < Math.floor((dblValue.length-(1+i))/3); i++)
                    dblValue = dblValue.substring(0,dblValue.length-(4*i+3))+','+
                    dblValue.substring(dblValue.length-(4*i+3));
            return (((blnSign)?'':'-') + '&#36;' + dblValue /*+ '.' + strCents*/);
        } else {
            return ('N/A');
        }

    }

    this.remTrailingZeros = function (x) {
        if (x==null) return "";

        var decPos=x.indexOf(".");

        if (decPos>-1) {
            first=x.substring(0,decPos);
            second=x.substring(decPos,x.length);

            while (second.charAt(second.length-1)=="0")
                second=second.substring(0,second.length-1);

            if (second.length>1)
                return first+second;
            else
                return first;
        }

        return x;
    }

    this.truncateString = function(text,charLength){
        var str = text;
        if(str.length > charLength){
            str = str.substring(0, charLength) + "...";
        }
           return str;
    }

      this.replaceElement = function(e,chgAtt,curAtt,newAtt){
        var x=document.getElementsByTagName(e);
        for (i=0;i<x.length;i++){
            if(x[i].getAttribute(chgAtt) == curAtt){
                x[i].setAttribute(chgAtt,newAtt);
            }
        }
    }

    /*
    usage:
    replaceElement -
    e = what element you want to change (i.e. "table");
    chgAtt = attribute you want to change (i.e. "width");
    curAtt = current value
    newatt = new value
    replaceElement("table","width",580,390)

    */

    /*
    parseParameter - returns name/value pair of url query string
    Usage: paramValue(key) - returns value of the param

    replace - replaces items within a string
    Usage: replace(string to evaluate, what you want to replace, replacement string)
    - returns the updated string

    remTrailingZeros - pass in a number. it will remove the zeros at the end of the number

    truncateString - pass in the text you want to truncate and the number of characters that should be displayed.

    formatCurrency - pass in a number and it will format it to currency. 125777 = $125,777

    removeNonNumericsFromString - helper function to formatCurrency. Removes all non numeric items from a string
    */
    /*
      function replace(str,text,by) {
    var strg = new String(str);
    var strLength = strg.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return strg;
    var i = strg.indexOf(text);
    if ((!i) && (text != strg.substring(0,txtLength))) return strg;
    if (i == -1) return strg;
    var newstr = strg.substring(0,i) + by;
    if (i+txtLength < strLength)
        newstr += replace(strg.substring(i+txtLength,strLength),text,by);
    return newstr;
}

function formatCurrency(num) {
    num = num.toString().replace(/\$|\,/g,'');
    if(isNaN(num))
    num = "0";
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num*100+0.50000000001);
    num = Math.floor(num/100).toString();
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
        num = num.substring(0,num.length-(4*i+3))+','+
        num.substring(num.length-(4*i+3));
        return (((sign)?'':'-') + '$' + num);
}

function remTrailingZeros(x) {
var decPos=x.indexOf(".")
    if (decPos>-1){
        first=x.substring(0,decPos);
        second=x.substring(decPos,x.length);
        while (second.charAt(second.length-1)=="0")
            second=second.substring(0,second.length-1);
        if (second.length>1)
            return first+second;
        else
        return first;
        }
    return x;
}

function truncateString(text,charLength){
    var str = text;
    if(str.length > charLength){
        str = str.substring(0, charLength) + "...";
    }
       return str;
}
    */
}

/**
 * Event handler for label.onclick events.
 * Moves the focus and prevents the select box from changing the selection(s).
 * Fixes a problem with IE where clicking on a label makes a
 * select box change its value to the first item in the list.
 * @return false if IE, otherwise true
 * @type boolean
 */
function label_onclick()
{
    var UA = navigator.userAgent;
    var ua = UA.toLowerCase();
    var isIE = ua.indexOf("msie") != -1;
    if(!isIE)
    {
        return true;
    }
    var eLabel = window.event.srcElement;
    var varID = eLabel.htmlFor;
    var eField = document.getElementById(varID);
    eField.focus();
    return false;
}

/**
 * Selects an option for a drop-down listbox.
 * @param pID the id of the select box to work with.
 * @param pValue the value to be selected (if it exists).
 */
function selectOneOptionByValue(pID, pValue)
{
    // Verify parameters.
    if(pID == null)
    {
        return;
    }
    if(pValue == null)
    {
        return;
    }
    var field = $(pID);
    var x = 0;
    var y = field.options.length;
    for(x=0; x<y; x++)
    {
        var o = field.options[x];
        if(o.value == pValue)
        {
            field.selectedIndex = x;
            break;
        }
    }
}
