/**
 *  Removes leading whitespaces
 **/
String.prototype.trimLeft = function trimLeft() 
{
    return this.replace(/^\s/, "");
}

/**
 *  Removes ending whitespaces
 **/
String.prototype.trimRight = function trimRight() 
{
    return this.replace(/\s+$/, "");
}

/**
 *  Removes leading and ending whitespaces
 *  Alternative example:  this.replace(/^\s+|\s+$/g, "");
 **/
String.prototype.trim = function trim() 
{
    var newStr = this.trimLeft();
    return newStr.trimRight();
}

/**
 *  Returns true if value only contains spaces
 **/
function isBlank(val)
{
    var isValueBlank = true;
    if (val != null) 
    {
        for (var i = 0; i < val.length; i++) 
        {
            if ((val.charAt(i) != ' ') && 
                (val.charAt(i) != "\t") && 
                (val.charAt(i) != "\n") && 
                (val.charAt(i) != "\r")) 
            { 
                isValueBlank = false;
                break;
            }
        }
    }
    return isValueBlank;
}

/**
 *  Returns true if value is a 1-character digit
 **/
function isDigit(num) 
{
    var isDig = false;
    if (num.length == 1)
    {
        var string="1234567890";
        if (string.indexOf(num) != -1) { isDig = true; }
    }
    return isDig;
}

/**
 *  Returns true if value contains all digits
 **/
function isInteger(val)
{
    var isInt = true;
    if (isBlank(val)) 
    { 
        isInt = false; 
    }
    else
    {
        for (var i = 0; i < val.length; i++)
        {
            if (!isDigit(val.charAt(i))) 
            { 
                isInt = false;
                break;
            }
        }
    }
    return isInt;
}

/**
 *  Returns true if the value is equal to the specified character
 **/
function isSpecificChar(specificChar, val)
{
    return val == specificChar;
}

/**
 *  Returns true if the value is of the format "mm/dd/yyyy"
 **/
function isValidDate(val)
{
	return val.search(/^[0-9]{1,2}[-\/.][0-9]{1,2}[-\/.][0-9]{4}$/) != -1;
/*	
    var isValid = false;
    var arrMDY = val.split("/");
    if (arrMDY.length == 3)
    {
        if ((arrMDY[0].length == 2 && isInteger(arrMDY[0])) && 
            (arrMDY[1].length == 2 && isInteger(arrMDY[1])) && 
            (arrMDY[2].length == 4 && isInteger(arrMDY[2])))
        {
            isValid = true;
        }
    }
    return isValid;
*/
}

/**
 *  StringBuilder: Concatenate 2 or more string character sequences together.
 *  Functions:
 *      StringBuilder() - Initializes a prototype member array.
 *      append(string)  - By using the built-in "push" function, the "string" 
 *                        value is added to tne end of the array.
 *      toString()      - By using the built-in "join" function, the array of 
 *                        strings are concatenated (joined) together.
 *  Example usage:
 *      function example(str)
 *      {
 *          var sb = new StringBuilder();
 *          sb.append("<td class='display' align='center' valign='middle'>\n");
 *          sb.append(str);
 *          sb.append("</td>\n");
 *          return sb.toString();
 *      }
 **/
function StringBuilder() 
{ 
    this.sb = []; 
} 

StringBuilder.prototype.append = function append(string) 
{ 
    this.sb.push(string); 
    return this; 
};

StringBuilder.prototype.toString = function toString() 
{ 
    return this.sb.join(""); 
};
// END StringBuilder

/**
 *  Print the given number of html spaces.
 **/
function htmlSpacing(numSpaces)
{
    var htmlSpaces = "";
    for (var i = 0; i < numSpaces; i++)
    {
        htmlSpaces += "&nbsp;";
    }
    return htmlSpaces;
}

/**
 *  Basic mouseover code
 **/
function MM_swapImgRestore()    // v3.0
{
    var i, x, a = document.MM_sr;
    for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++)
    {
        x.src = x.oSrc;
    }
}

function MM_preloadImages()     // v3.0
{
    var d = document;
    if (d.images)
    { 
        if (!d.MM_p)
        {
            d.MM_p = new Array();
        }
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; 
        for (i = 0; i < a.length; i++)
        {
            if (a[i].indexOf("#") != 0)
            { 
                d.MM_p[j] = new Image;
                d.MM_p[j++].src = a[i];
            }
        }
    }
}

function MM_findObj(n, d)       // v4.01
{
    var p, i, x;
    if (!d)
    {
        d = document;
    }
    if ((p = n.indexOf("?")) > 0 && parent.frames.length) 
    {
        d = parent.frames[n.substring(p + 1)].document;
        n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all)
    {
        x = d.all[n];
    }
    for (i = 0; !x && i < d.forms.length; i++)
    {
        x = d.forms[i][n];
    }
    for (i = 0; !x && d.layers && i < d.layers.length; i++)
    {
        x = MM_findObj(n,d.layers[i].document);
    }
    if (!x && d.getElementById)
    {
        x = d.getElementById(n);
    }
    return x;
}

function MM_swapImage()         // v3.0
{
    var i, j = 0, x, a = MM_swapImage.arguments;
    document.MM_sr = new Array;
    for (i = 0; i < (a.length - 2); i += 3)
    {
        if ((x = MM_findObj(a[i])) != null)
        {
            document.MM_sr[j++] = x;
            if (!x.oSrc)
            {
                x.oSrc = x.src;
            }
            x.src = a[i + 2];
        }
    }
}
// END basic mouseover code