﻿/// <reference name="MicrosoftAjax.js"/>
Function.prototype.addField = function(name, value, mayBeNull)
{
    /// <param name="name" type="String"></param>
    /// <param name="value" mayBeNull="true"></param>
    /// <returns type="String"></returns>
    var e = Function._validateParams(arguments, [
        { name: "name", type: (type ? type : String) },
        { name: "value", mayBeNull: (mayBeNull == true || mayBeNull == null) }
    ]);
    if (e) throw e;
    var fieldName = "_" + name;
    if (!(fieldName in this.prototype))
    {
        this.prototype[fieldName] = value;
    }
    return fieldName;
}
Function.prototype.addMethod = function(name, method) {
    /// <param name="name" type="String"></param>
    /// <param name="method" type="Function"></param>
    var e = Function._validateParams(arguments, [
        { name: "name", type: String },
        { name: "method", type: Function }
    ]);
    if (e) throw e;
    if (!(name in this.prototype)) {
        this.prototype[name] = method;
    }
}
Function.prototype.addProperty = function(name, initialValue, raisePropertyChanged, mayBeNull, type)
{
    /// <param name="name" type="String"></param>
    /// <param name="initialValue" mayBeNull="true"></param>
    /// <param name="raisePropertyChanged" type="Boolean" optional="true"></param>
    var e = Function._validateParams(arguments, [
        { name: "name", type: (type ? type : String) },
        { name: "initialValue", mayBeNull: (mayBeNull == true || mayBeNull == null) },
        { name: "raisePropertyChanged", type: Boolean, optional: true }
    ]);
    if (e) throw e;
    var fieldName = this.addField(name, initialValue);
    this.addMethod("get_" + name, function() {
        return this[fieldName];
    });
    if (raisePropertyChanged) {
        this.addMethod("set_" + name, function(value) {
            if (value !== this[fieldName]) {
                this[fieldName] = value;
                this.raisePropertyChanged(name);
            }
        });
    } else {
        this.addMethod("set_" + name, function(value) {
            this[fieldName] = value;
        });
    }
}
Function.prototype.addEvent = function(name)
{
    /// <param name="name" type="String"></param>
    var e = Function._validateParams(arguments, [
        { name: "name", type: String }
    ]);
    if (e) throw e;
    this.addMethod("add_" + name, function(handler)
    {
        this.get_events().addHandler(name, handler);
    });
    this.addMethod("remove_" + name, function(handler)
    {
        this.get_events().removeHandler(name, handler);
    });
}
/// <reference name="MicrosoftAjax.js"/>
environment = new function() 
{   
    //this.dev = new function() { return 1; };
    this.dev = "dev";
    //this.dev.value = 1;
    //this.dev.toString = function() { return "dev"; };

    //this.test = new function() { return 2; };
    //this.test.toString = function() { return "test"; };
    this.test = "test";
    
    //this.prod = new function() { return 3; };
    //this.prod.toString = function() { return "prod"; };
    this.prod = "prod";
    
    //return 1;
};

//FOUND THIS HERE: http://www.quirksmode.org/dom/inputfile.html
var W3CDOM = (document.createElement && document.getElementsByTagName);

var Me = window;
var isIE6 = (navigator.appVersion.match(/MSIE 6/));
var appEnvironment = setEnvironment();

function Now() { return new Date(); };

function setEnvironment()
{   switch (window.location.host.split(":")[0].toUpperCase())
    {   case "LOCALHOST":
            //debugger; //Halts the application and begins debugging.
            return environment.dev;
        case "TEST":
            return environment.test;
        default: 
            return environment.prod;
    }
};

function setEnvironmentName(header)
{   if (!header.environmentSet)
    {   header.environmentSet = true;

        if (appEnvironment != environment.prod)
        {   header.innerText = "(" + appEnvironment + ") " + header.innerText;
            document.title = "(" + appEnvironment + ") " + document.title;
        }
    }
};

var using = function(namespace)
{
    Type.registerNamespace(namespace);
    for (var item in window[namespace])
    {
        if (window[item] == null)
            window[item] = object[item];
    }
};

Type.registerNamespace("Sys.Application");
Sys.Application.findComponentsByType = function Sys$Application$findComponentsByType(type)
{
    /// <summary locid="M:J#Sys.Applications.findComponentsByType"></summary>
    /// <returns type="Type[]" mayBeNull="true">Iterates the list of components in Sys.Application and returns an array of those of the specified type.</returns>
    if (arguments.length !== 1) throw Error.parameterCount();

    var e = Function._validateParams(arguments, [{ name: "type", type: Type}]);
    if (e) throw e;

    var components = new Array();
    for (var c in Sys.Application._components)
    {
        var component = (type.isInstanceOfType(Sys.Application._components[c]) ? Sys.Application._components[c] : null);
        if (component != null)
            components.push(component);
    }

    return components;
}

/// <reference path="namespaces.js" />
/// <reference path="enums.js" />
/// <reference path="utilities.js" />
/// <reference path="messageboxes.js" />
//*************************************************************************/
//AJAXControlToolkit library references:
//http://www.asp.net/AJAX/Documentation/Live/ClientReference/default.aspx
//
// $get(id, parent)
//     Shortcut for: document.getElementById(...);
//
// $find(id, parent)
//     Finds AJAXControlToolkit extenders objects, by id.
//*************************************************************************/

//FOUND THIS SOLUTION HERE: http://www.feed-squirrel.com/index.cfm?evt=viewItem&ID=2397
function IsNumeric(x) // Use the this function like this: if (isNumeric(myVar)) { }
{   // Note: this WILL allow a negative number and/or one ends in a decimal: -452 AND Scientific Notation: "1.2345e-2"
    // The "match" function returns NULL if the value didn't match or the value of "x" if it did match.
    return (x == null || x.toString().match(/^[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?$/) != x ? false : true);
};

function Point(x, y)
{
    this.fromElement = function(element)
    {
        element = (typeof (element) == "string" ? document.getElementById(element) : element);

        var left = 0;
        var top = 0;

        if (element.offsetParent)
        {
            left = element.offsetLeft;
            top = element.offsetTop;

            while (element = element.offsetParent)
            {
                left += element.offsetLeft;
                top += element.offsetTop;
            }
        }
        //return [left, top];
        return new Point(left, top);
    };

    this.FromElement = function(element)
    {
        return this.fromElement(element);
    };

    this.X = (IsNumeric(x) ? x : null);
    this.Left = this.X;
    this.x = this.X;
    this.left = this.X;

    this.Y = (IsNumeric(y) ? y : null);
    this.Top = this.Y;
    this.y = this.Y;
    this.top = this.Y;

    this.toString = function()
    {
        return "{ x = " + this.X.toString() + ", y = " + this.Y.toString() + " }";
    };

    this.ToString = function()
    {
        return this.toString();
    };
};

function Size(width, height)
{
    this.fromElement = function(element)
    {
        element = (typeof (element) == "string" ? document.getElementById(element) : element);
        return new Size(element.offsetWidth, element.offsetHeight);
    };

    this.FromElement = function(element)
    {
        return this.fromElement(element);
    };

    this.Width = (IsNumeric(width) ? (width > 0 ? width : 0) : null);
    this.width = this.Width;

    this.Height = (IsNumeric(height) ? (height > 0 ? height : 0) : null);
    this.height = this.Height;

    this.toString = function()
    {
        return "{ width = " + this.width.toString() + ", height = " + this.height.toString() + " }";
    };

    this.ToString = function()
    {
        return this.toString();
    };
};

//String.prototype.trim = function(string)
//{
//    string = (string == null ? this.toString() : string);
//    return this.trimStart(this.trimEnd(string));
//};
//
//String.prototype.trimStart = function(string)
//{
//    string = (string == null ? this.toString() : string);
//    string = (typeof (string) == "string" ? string : string.toString());
//
//    while (string.substring(0, 1) == " ")
//        string = string.substring(1, string.length);
//
//    return string;
//};
//
//String.prototype.trimEnd = function(string)
//{
//    string = (string == null ? this.toString() : string);
//    string = (typeof (string) == "string" ? string : string.toString());
//
//    while (string.substring(string.length - 1, string.length) == " ")
//        string = string.substring(0, string.length - 1);
//
//    return string;
//};
//
//////////////////////////////////////////////////////////////////////
////FOUND THIS HERE: http://www.west-wind.com/WebLog/posts/282495.aspx
//Date.prototype.formatDate = function(format)
//{
//    var date = this;
//    if (!format) format = "MM/dd/yyyy";
//
//    var month = date.getMonth() + 1;
//    var year = date.getFullYear();
//
//    format = format.replace("MM", month.toString().padLeft(2, "0"));
//
//    if (format.indexOf("yyyy") > -1)
//        format = format.replace("yyyy", year.toString());
//    else if (format.indexOf("yy") > -1)
//        format = format.replace("yy", year.toString().substr(2, 2));
//
//    format = format.replace("dd", date.getDate().toString().padLeft(2, "0"));
//
//    var hours = date.getHours();
//    if (format.indexOf("t") > -1)
//    {
//        if (hours > 11)
//            format = format.replace("t", "pm")
//        else
//            format = format.replace("t", "am")
//    }
//
//    if (format.indexOf("HH") > -1)
//        format = format.replace("HH", hours.toString().padLeft(2, "0"));
//
//    if (format.indexOf("hh") > -1)
//    {
//        if (hours > 12) hours - 12;
//        if (hours == 0) hours = 12;
//
//        format = format.replace("hh", hours.toString().padLeft(2, "0"));
//    }
//
//    if (format.indexOf("mm") > -1)
//        format = format.replace("mm", date.getMinutes().toString().padLeft(2, "0"));
//
//    if (format.indexOf("ss") > -1)
//        format = format.replace("ss", date.getSeconds().toString().padLeft(2, "0"));
//
//    return format;
//};
//

String.repeat = function String$repeat(chr, count)
{   /// <summary locid="M:J#String.repeat" />
    /// <param name="chr" type="Char"></param>
    /// <param name="count" type="int"></param>
    /// <returns type="String"></returns>
    var e = Function._validateParams(arguments, [
        {name: "suffix", type: String}
    ]);
    if (e) throw e;
    var str = "";
    for (var x = 0; x < count; x++)
        str += chr;
    return str;
};

String.prototype.padLeft = function(width, pad)
{
    if (!width || width < 1)
        return this;

    if (!pad) pad = " ";

    var length = width - this.length;
    if (length < 1)
        return this.substr(0, width);

    return (String.repeat(pad, length) + this).substr(0, width);
};

String.prototype.padRight = function(width, pad)
{
    if (!width || width < 1)
        return this;

    if (!pad) pad = " ";

    var length = width - this.length;

    if (length < 1)
        this.substr(0, width);

    return (this + String.repeat(pad, length)).substr(0, width);
};

//String.format = function(frmt, args)
//{
//    var offset = (IsArray(args) ? 0 : 1);
//    var values = (offset == 1 ? arguments : args);
//
//    for (var x = 0; x < values.length; x++)
//        frmt = frmt.replace("{" + x + "}", values[x + offset]);
//    return frmt;
//};

String.isNullOrEmpty = function(string)
{
    return (string == null || string == "");
};

String.isEmptyOrNull = function(string)
{
    return String.isNullOrEmpty(string);
};
////////////////////////////////////////////////////////////////////

//Array.prototype.add = function(item, noDuplicates)
//{
//    noDuplicates = (noDuplicates == true ? true : false);
//    if (!(noDuplicates && this.contains(item))) this.push(item);
//};

Array.prototype.insert = function(item, index, noDuplicates)
{
    noDuplicates = (noDuplicates == true ? true : false);
    if (IsNumeric(index))
    {
        if (noDuplicates && this.contains(item))
            return;
        else if (index < this.length)
        {
            for (var i = this.length; i > index; i--)
                this[i] = this[i - 1];
            this[index] = item;
        }
        else
            this.push(item);
    }
};

//Array.prototype.addRange = function(items, noDuplicates)
//{
//    if (!IsArray(items)) return;
//    //    this.concat(items);
//
//    for (var index = 0; index < items.length; index++)
//        this.add(items[index], noDuplicates);
//
//    return this;
//};

Array.prototype.pushRange = function(items)
{
    if (!IsArray(items)) return;

    for (var index = 0; index < items.length; index++)
        this.push(items[index]);

    return this;
};

Array.prototype.contains = function(item)
{
    return (this.indexOf(item) > -1);
};

Array.prototype.indexOf = function(item)
{
    for (var index = 0; index < this.length; index++)
        if (this[index] == item) return index;
    return -1;
};

Array.prototype.remove = function(item)
{
    if (!this.contains(item)) return;

    var index = this.indexOf(item);

    var temp = new Array();
    for (var count = 0; count < this.length; count++)
        if (count <= index) temp.push(this.shift());

    this.concat(temp);
};

//Copyright Robert Nyman, http://www.robertnyman.com
//Free to use if this text is included
function document.getElementsByAttribute(attribute, value, element, tagName)
{
    if (attribute == null && value == null && element == null && tagName == null)
        return new Array();

    attribute = (!IsArray(attribute) ? (attribute == null || typeof (attribute) == "string" ? [attribute] : attribute.attributes) : attribute);

    value = (!IsArray(value) ? [value == null || typeof (value) == "string" ? value : value.toString()] : value);

    var regexs = new Array();
    for (var index = 0; index < value.length; index++)
        regexs[index] = new RegExp("(^|\\s)" + value[index] + "(\\s|$)");

    element = (element == null ? [document] : !IsArray(element) ? [element] : element);
    tagName = (tagName == null ? ["*"] : !IsArray(tagName) ? [tagName] : tagName);

    var elementTagGroups = new Array();
    for (var control; (control = element.shift()) != null; )
    {
        var controls = (typeof (control) == "string" ? [document.getElementById(control)] : [control]);
        if (controls[0] == null) controls = document.getElementsByName(control.replace(/\_/g, "$"));

        for (var c = 0; (control = (c < controls.length ? controls[c] : null)) != null; c++)
        {
            for (var index = 0; index < tagName.length; index++)
            {
                tagName[index] = (typeof (tagName[index]) == "string" ? tagName[index] : tagName[index].tagName);
                elementTagGroups[elementTagGroups.length] = (tagName[index] == "*" && control.all ? control.all : control.getElementsByTagName(tagName[index]));
            }
        }
    }

    var foundElements = new Array();

    for (var regex; (regex = regexs.shift()) != null; )
    {
        for (var index = 0; index < attribute.length; index++)
        {
            var att = attribute[index];
            for (var g = 0, group; (group = (g < elementTagGroups.length ? elementTagGroups[g] : null)) != null; g++)
            {
                for (var e = 0; (element = (e < group.length ? group[e] : null)) != null; e++)
                {
                    if (att == null && !foundElements.contains(element))
                        foundElements.push(element);
                    else
                    {
                        var atValue = (element.getAttribute ? element.getAttribute(att) : null);
                        if (atValue == null) continue;

                        if (typeof (atValue) != "string") atValue = atValue.toString();

                        if (atValue.length > 0)
                        {
                            if (regex && regex.test(atValue))
                            {
                                if (!foundElements.contains(element)) foundElements.push(element);
                            }
                            else
                            {
                                switch (att)
                                {
                                    case "id":
                                        var id = value[value.length - regexs.length - 1].toLowerCase();

                                        var startsWith = id.substring(id.length - 1) == "*";
                                        var endsWith = id.substring(0, 1) == "*";
                                        var contains = (startsWith && endsWith);
                                        var equals = !(startsWith || endsWith);

                                        id = (startsWith ? id.substring(0, id.length - 1) : id);
                                        id = (endsWith ? id.substring(1) : id);

                                        if (!foundElements.contains(element))
                                        {
                                            if (equals)
                                            {
                                                if (element.id.toLowerCase() == id) foundElements.push(element);
                                            }
                                            else if (element.id.toLowerCase().indexOf(id) > -1)
                                            {
                                                if (contains)
                                                    foundElements.push(element);
                                                else if (startsWith && element.id.toLowerCase().indexOf(id) == 0)
                                                    foundElements.push(element);
                                                else if (endsWith && element.id.toLowerCase().indexOf(id) == (element.id.length - id.length))
                                                    foundElements.push(element);
                                            }
                                        }
                                        break;

                                    case "className":
                                        var classNames = element.className.split(" ");
                                        for (var css; (css = classNames.shift()) != null; )
                                        {
                                            if (regex.test(css))
                                            {
                                                if (!foundElements.contains(element)) foundElements.push(element);
                                                break;
                                            }
                                        }
                                        break;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return foundElements;
};

var Controls =
{
    WrapWith: function(type, control, id)
    {
        type = (type == null || typeof (type) == "string" ? type : type.tagName);
        if (type == null) return;

        control = (typeof (control) == "string" ? document.getElementById(control) : control);
        if (control.parentNode == null) return;

        var wrapper = document.createElement(type.toLowerCase());
        if (id != null) wrapper.id = (control.id != null ? control.id : "") + "_" + id;

        var parent = control.parentNode;

        parent.insertBefore(wrapper, control);
        parent.removeChild(control);
        wrapper.appendChild(control);

        return wrapper;
    },

    //    HidePopups: function()
    //    {
    //        var popups = document.getElementsByAttribute("type", "popup");
    //        for (var index = 0, popup = null; (popup = popups[index]) != null; index++)
    //            popup.style.display = "none";
    //    },
    //
    //    ShowPopup: function(offsetControl, popup)
    //    {   popup = (typeof(popup) == "string" ? document.getElementById(popup) : popup);
    //        offsetControl = (typeof(offsetControl) == "string" ? document.getElementById(offsetControl) : offsetControl);
    //        
    //        var center = (offsetControl == screen);
    //                   
    //        if (!popup.positioned)
    //        {   popup.positioned = true;
    //                                   
    //            var position = (offsetControl == null || center ? new Point(0, 0) : new Point().fromElement(popup));
    //            var location = null;
    //
    //            if (offsetControl == null || center)
    //            {   offsetControl = document.getElementsByTagName("body")[0];
    //                
    //                popup.style.left = "-10000";
    //                popup.style.display = "block";
    //                
    //                var size1 = new Size().fromElement(popup);
    //                var size2 = (center ? new Size(screen.availWidth, screen.availHeight) : new Size().fromElement(offsetControl));
    //                
    //                location = new Point((size2.width - size1.width) / 2, (size2.height - size1.height) / 2);
    //            }
    //            else
    //                location = new Point().fromElement(offsetControl);
    //            
    //            var adjust = (offsetControl.tagName.toLowerCase() == "body" ? 0 : new Size().fromElement(offsetControl).height + 2);
    //                
    //            popup.style.left = (location.left - position.left);
    //            popup.style.top = (location.top - position.top) + adjust;
    //
    //            //popup.style.top = findPosY(offsetControl);
    //        }
    //        
    //        if (popup.style.display == "none") popup.style.display = "block";
    //    },

    //GOT THIS HERE: http://www.hunlock.com/blogs/Snippets:_Howto_Grey-Out_The_Screen
    // Pass TRUE to gray out screen, FALSE to ungray 
    // options are optional.  This is a JSON object with the following (optional) properties  
    // opacity:0-100 (Lower number = less grayout, higher = more of a blackout   
    // zindex: # (HTML elements with a higher zindex appear on top of the gray out)
    // bgcolor: #xxxxxx (Standard RGB Hex color code)
    //
    // EX: GrayOutScreen(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});  
    //     Because options is JSON opacity/zindex/bgcolor are all optional and can appear  
    //     in any order.  Pass only the properties you need to set.
    GrayOutScreen: function(enable, options)
    {
        var options = (options != null ? options : {});
        var zindex = (options.zindex != null ? options.zindex : 1000);
        var opacity = (options.opacity != null ? options.opacity : 70);
        var opaque = (opacity / 100);
        var color = (options.color != null ? options.color : "#000000");
        var dark = document.getElementById("darkenScreenObject");
        if (dark == null)
        {   // The dark layer doesn't exist, it's never been created.  
            //So we'll create it here and apply some basic styles.    
            // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917    
            var tbody = document.getElementsByTagName("body")[0];
            var tnode = document.createElement("div");              // Create the layer.
            tnode.innerHTML = ("<!--[if !(IE 7)]><div class=\"IE6DropdownFix\"><iframe></iframe></div><![endif]-->");

            tnode.style.position = "absolute";                      // Position absolutely
            tnode.style.top = "0";                                  // In the top
            tnode.style.left = "0";                                 // Left corner of the page
            tnode.style.overflow = "hidden";                        // Start out Hidden
            tnode.id = "darkenScreenObject";                        // Name it so we can find it later
            tbody.appendChild(tnode);                               // Add it to the web page
            dark = document.getElementById("darkenScreenObject");   // Get the object.
        }

        if (enable)
        {   // Calculate the page width and height
            var pageWidth = "100%";
            var pageHeight = "100%";

            if (document.body && (document.body.scrollWidth || document.body.scrollHeight))
            {
                pageWidth = document.body.scrollWidth + "px";
                pageHeight = document.body.scrollHeight + "px";
            }
            else if (document.body.offsetWidth)
            {
                pageWidth = document.body.offsetWidth + "px";
                pageHeight = document.body.offsetHeight + "px";
            }

            //set the shader to cover the entire page and make it visible.    
            dark.style.width = pageWidth;
            dark.style.height = pageHeight;
            dark.style.opacity = opaque;
            dark.style.MozOpacity = opaque;
            dark.style.filter = "alpha(opacity=" + opacity + ")";
            dark.style.zIndex = zindex;
            dark.style.backgroundColor = color;
            dark.style.display = "block";
        }
        else { dark.style.display = "none"; }
    },

    GetFont: function(control)
    {
        control = (typeof (control) == "string" ? document.getElementById(control) : control);

        var font = new Array("fontWeight", "fontVariant", "fontSize", "fontFamily");
        for (var index = 0; index < font.length; index++)
            font[index] = Controls.GetAppliedStyle(control, font[index]);
        return font;
    },

    //    SetCss: function(control, rule, value, returnCss)
    //    {   control = (typeof(control) == "string" ? document.getElementById(control) : control);
    //        rule = ("ie6" + rule);
    //        
    //        if (!control[rule])
    //        {   control[rule] = true;
    //            control.style[rule.replace("ie6","")] = value;
    //        }
    //        
    //        return returnCss;
    //    },

    //Found this here: http://www.robertnyman.com/2006/04/24/get-the-rendered-style-of-an-element/
    GetAppliedStyle: function(element, cssRule)
    {
        var value = null;
        if (document.defaultView && document.defaultView.getComputedStyle)
            value = document.defaultView.getComputedStyle(element, null).getPropertyValue(cssRule);
        else if (element.currentStyle)
        {
            cssRule = cssRule.replace(/\-(\w)/g, function(match, style) { return style.toUpperCase(); });
            value = element.currentStyle[cssRule];
        }

        //        if (element.style && element.style[cssRule])
        //            value = element.style[cssRule];
        //        else 
        return value;
    },

    EnableCheckboxLabel: function(input, disable)
    {
        if (input.type == "checkbox" || input.type == "radio")
        {
            var control = input.parentNode;
            control.className = (control.className.replace("disabledCheckbox", "") + (control.disabled && input.checked ? " disabledCheckbox" : ""));
            /*control.style.fontStyle = (control.disabled && input.checked ? "italic" : control.style.fontStyle);*/

            switch (input.type.toLowerCase())
            {
                case "radio": control.parentNode.disabled = disable;
                case "checkbox":
                    control.disabled = disable;
                    break;
            }
        }
        return input.style.display;
    },

    ValidateAlphaInput: function(control)
    {
        var e = window.event;
        var sender = (control != null ? control : e != null ? e.srcElement : null);

        //return !((e.keyCode >= 65 && e.keyCode <= 90) || (e.keyCode >= 97 && e.keyCode <= 122));
        return !/[a-zA-Z]/.test(String.fromCharCode(e.keyCode));
    },

    ValidateNumericInput: function(decimal, allowNegative, control)
    {
        allowNegative = (allowNegative == false ? false : true);

        var e = window.event;
        var sender = (control != null ? control : e != null ? e.srcElement : null);

        //var delimiter = (delimiter == null ? "." : delimiter);

        decimal = (IsNumeric(decimal) && decimal > 0 ? decimal : 0);

        var expr = new RegExp("^" + (allowNegative ? "[-]?" : "") + "\\d*(\\.\\d{1," + (decimal > 0 ? decimal : 1) + "})?$"); //^[-]?\d*\.?\d+$

        var char = String.fromCharCode(e.keyCode);
        if (decimal == 0)
        {
            if (char == ".") return false;
            //else if (char == delimiter) return true;
        }

        switch (e.keyCode)
        {   //case 13:    //ENTER
            //case 9:     //ENTER        
            case 35:    //END
            case 36:    //HOME
            case 37:    //LEFT
            case 38:    //UP
            case 39:    //RIGHT OR "'" [Single Quote]
            case 40:    //DOWN OR "(" [SHIFT + 9]
            case 8:     //BACKSPACE
                //if (!e.shiftKey && !e.shiftLeft) return true;
                if (e.type == "keydown") return true;
            default:
                break;
        }

        var text = ""; //(document.all ? document.selection.createRange().text : document.getSelection());
        text = (text == "" ? sender.value : text) + char;

        sender.onblur = function()
        {
            var e = window.event;
            var sender = (e != null ? e.srcElement : null);

            if (sender.value == "-")
                sender.value = "";
            else
            {
                sender.value = sender.value.replace("-.", "-0.");
                if (sender.value.indexOf(".") == 0)
                    sender.value = ("0" + sender.value);
                if (sender.value.indexOf(".") == sender.value.length - 1)
                {
                    if (sender.value.length > 0) sender.value += "0";
                }

                if (parseInt(sender.value.replace("-", "").replace(".", "")) == 0)
                    sender.value = "0";
            }
        }
        //alert("ValidateNumericInput: " + expr.test(text) + " { keyCode = " +  e.keyCode + ", char = \"" + char + "\" }");
        return (text.indexOf(".") == text.length - 1) || expr.test(text);
    },

    AutoHideList: function(list, format)
    {
        var e = window.event;
        var sender = (e != null ? e.srcElement : null);

        if (!list.autoHideEnabled)
        {
            list.autoHideEnabled = true;

            var size = new Size().FromElement(list);
            list.style.display = "none";

            var label = document.createElement("label");
            label.id = list.id + "_label";
            label = (document.getElementById(label.id) != null ? document.getElementById(label.id) : label);

            label.className = list.className;
            label.htmlFor = list.id;
            label.onmouseover = function() { Controls.ShowList(label.htmlFor, true, format); };
            //label.style.verticalAlign = "middle";
            label.style.whiteSpace = "nowrap";
            label.style.display = "inline-block";
            ////label.style.marginTop = "3px";
            ////label.style.marginLeft = "5px";
            label.style.position = "relative";
            //label.style.border = "solid 1px red";
            label.style.top = (3 + parseInt(String.isNullOrEmpty(list.style.top) ? 0 : list.style.top)).toString() + "px";
            label.style.left = (5 + parseInt(String.isNullOrEmpty(list.style.left) ? 0 : list.style.left)).toString() + "px";
            label.innerText = String.format(String.isEmptyOrNull(format) ? "{0}" : format, list.selectedIndex > -1 ? list.options[list.selectedIndex].text : "");

            list.parentNode.insertBefore(label, list);
            list.parentNode.insertBefore(list, label);

            if (size.Width > 0)
                label.style.width = size.Width;
            else
                label.style.width = ((label.offsetWidth > 0 ? label.offsetWidth : label.innerHTML.visualLength()) + 16).toString() + "px";

            if (size.Height > 0) label.style.height = size.Height;

            list = document.getElementById(list.id);
            list.onblur = function() { Controls.ShowList(list, false, format); }
            //EventListener(list).addEventListener("Blur", function(event) { Controls.ShowList(this, false); } ,false);
        }

        return list.style.display;
    },

    ShowList: function(list, show, format)
    {
        list = (typeof (list) == "string" ? document.getElementById(list) : list);
        if (list == null || list.id == null) return;

        var label = document.getElementById(list.id + "_label");
        if (label == null) return;

        show = (show == true ? true : false);

        label.style.display = (show ? "none" : "inline-block");
        list.style.display = (show ? "" : "none");

        if (show)
            list.focus();
        else if (list.options.selectedIndex > -1)
            label.innerText = String.format(String.isEmptyOrNull(format) ? "{0}" : format, list.options[list.selectedIndex].text);
    }
};

//FOUND THIS HERE: http://www.breakingpar.com/bkp/home.nsf/0/87256B280015193F87256C720080D723
function IsArray(object)
{
    if (object && !object.constructor)
        return object.length;

    return (object && object.constructor && object.constructor.toString().indexOf("function Array()") > -1);
};

////////////////////////////////////////////////////////////////////
//FOUND THIS HERE: http: //blog.mastykarz.nl/measuring-the-length-of-a-string-in-pixels-using-javascript/
String.prototype.visualLength = function(font)
{
    var ruler = document.getElementById("_textMeasurer");

    if (ruler == null) ruler = document.createElement("span");

    ruler.id = "_textMeasurer";
    ruler.style.visibility = "hidden";
    ruler.style.display = "";
    ruler.style.whiteSpace = "nowrap";
    ruler.style.font = String.format("{0} {1} {2} {3}", !IsArray(font) ? new Array() : font);
    ruler.innerHTML = this;

    //ERROR: http://weblogs.asp.net/infinitiesloop/archive/2006/11/02/Dealing-with-IE-_2600_quot_3B00_Operation-Aborted_2600_quot_3B002E00_-Or_2C00_-how-to-Crash-IE.aspx
    var body = document.getElementsByTagName("body")[0];
    if (body && !body.contains(ruler)) body.appendChild(ruler);
    //    //if (!document.contains(ruler)) document.appendChild(ruler);

    var width = ruler.offsetWidth;
    ruler.style.display = "none";

    return width;
};

String.prototype.ellipsisText = function(length)
{
    var tmp = this;
    var trimmed = this;
    if (tmp.visualLength() > length)
    {
        trimmed += "...";
        while (trimmed.visualLength() > length)
        {
            tmp = tmp.substring(0, tmp.length - 1);
            trimmed = tmp + "...";
        }
    }

    return trimmed;
};
////////////////////////////////////////////////////////////////////

function IsCallingBack()
{
    return (__pendingCallbacks && __pendingCallbacks.length > 0 && __pendingCallbacks[0] != null);
};

Prompts =
{   ConfirmToggleStatus: function(type, value, del)
    {   del = (del == false ? false : true);
    
        return confirm(String.format("Are you sure you want to {2} {1} {0}?", type.toLowerCase(), String.isEmptyOrNull(value) ? "this" : "the", del ? "delete" : "restore"),
                String.format("{2} {0}: {1}", type, value, del ? "Delete" : "Restore").replace(": undefined", ""),
                confirmButton.yesNo, confirmIcon.exclamation, null, confirmDefault.no) == confirmResult.yes;
    }
}

function $(elementArray)
{
    var values = (IsArray(elementArray) ? elementArray : arguments);

    var elements = new Array();
    for (var index = 0; index < values.length; index++)
    {
        var element = values[index];
        if (typeof element == "string")
            element = document.getElementById(element);

        if (values.length == 1)
            return element;

        elements.push(element);
    }
    return elements;
};

function $fxn(functionNames)
{
    var values = (IsArray(functionNames) ? functionNames : arguments);
    var fxn = null;
    for (var index = 0; index < values.length; index++)
        if (typeof (window[values[index].toString()]) == "function") return values[index].toString();

    return null;
};

/// <reference name="MicrosoftAjax.js" />
/// <reference path="enums.js" />
/// <reference path="utilities.js" />
/// <reference name="MicrosoftAjax.js"/>
/// <reference path="messageboxes.js" />
Type.registerNamespace("Enum");

Enum.IsDefined = function (enumeration, value)
{   for (var property in enumeration)
    {
        if (enumeration[property] == value) { return true; break; }
    }
    return false;
};

//http://ns7.webmasters.com/caspdoc/html/vbscript_msgbox_function.htm
window.confirmResult = { ok: 1, cancel: 2, abort: 3, retry: 4, ignore: 5, yes: 6, no: 7 };
window.confirmButton = { okOnly: 0, okCancel: 1, abortRetryIgnore: 2, yesNoCancel: 3, yesNo: 4, retryCancel: 5 };
window.confirmIcon = { none: 0, critical: 16, question: 32, exclamation: 48, information: 64 };
window.confirmDefault = { button1: 0, button2: 256, button3: 512, button4: 768 }
window.confirmModal = { application: 0, system: 4096 };

window.confirmDefault.ok     = window.confirmDefault.button1;
window.confirmDefault.abort  = window.confirmDefault.button1;
window.confirmDefault.yes    = window.confirmDefault.button1;

window.confirmDefault.cancel = window.confirmDefault.button2;
window.confirmDefault.retry  = window.confirmDefault.button2;
window.confirmDefault.no     = window.confirmDefault.button2;

window.confirmDefault.ignore = window.confirmDefault.button3;

if (!window.Node) var Node =
{
    ELEMENT_NODE: 1,
    ATTRIBUTE_NODE: 2,
    TEXT_NODE: 3,
    CDATA_SECTION_NODE: 4,
    ENTITY_REFERENCE_NODE: 5,
    ENTITY_NODE: 6,
    PROCESSING_INSTRUCTION_NODE: 7,
    COMMENT_NODE: 8,
    DOCUMENT_NODE: 9,
    DOCUMENT_TYPE_NODE: 10,
    DOCUMENT_FRAGMENT_NODE: 11,
    NOTATION_NODE: 12
}

/// <reference name="MicrosoftAjax.js"/>
/// <reference path="enums.js" />

//http://www.delphifaq.com/faq/javascript/f1172.shtml
function window.alert(message, title, button, icon, modal, defaultButton)
{   /// <summary>Displays a more Windowslike message box complete w/title, button(s), icon, and can be displayed modally.</summary>
    /// <param name="message" type="string">The message displayed to the user</param>
    /// <param name="title" type="string" optional="true">The title of the message</param>
    /// <param name="button" type="confirmResult" optional="true" locid="T:J#window.confirmResult"></param>
    /// <param name="icon" type="confirmIcon" optional="true">The icon displayed next to the message</param>
    /// <param name="modal" type="boolean" optional="true">Indicates whether or not the user is forced to interact with the messagebox.</param>
    /// <param name="defaultButton" type="confirmDefault" optional="true">The button that is selected by default. (Pressing 'enter' will click this button.)</param>
    
    title = (title == null ? navigator.appName : title);

    button = (!IsNumeric(button) || !Enum.IsDefined(confirmButton, button) ?
        confirmButton.okOnly : button);

    icon = (!IsNumeric(icon) || !Enum.IsDefined(confirmIcon, icon) ?
        confirmIcon.exclamation : icon);
//document.write(message);
    return window.confirm(message, title, button, icon, modal, defaultButton);
}

function window.confirm(message, title, button, icon, modal, defaultButton)
{   message = (message == null ? "" : message.toString().replace(/\"/g, "\"\"").replace(/\r\n/g, "\"+vbCrLf+\""));
    title = (title == null ? "" : title.toString().replace(/\"/g, "\"\"").replace(/\r\n/g, "\"+vbCrLf+\""));

    button = (!IsNumeric(button) || !Enum.IsDefined(confirmButton, button) ? 
        confirmButton.okCancel : button);
        
    icon = (!IsNumeric(icon) || !Enum.IsDefined(confirmIcon, icon) ? 
        confirmIcon.none : icon);
        
    modal = (!IsNumeric(modal) || !Enum.IsDefined(confirmModal, modal) ? 
        confirmModal.application : modal);
        
    defaultButton = (!IsNumeric(defaultButton) || !Enum.IsDefined(confirmDefault, defaultButton) ? 
        confirmDefault.button1 : defaultButton);

    switch (defaultButton) 
    {   case confirmDefault.retry:
            if (button == confirmButton.retryCancel)
                defaultButton = confirmDefault.button1;
            break;
            
        case confirmDefault.cancel:
            if (button == confirmButton.yesNoCancel)
                defaultButton = confirmDefault.button3;
            break;    
    }

    var msgBox = "result = msgbox(\"" + message + "\", \"" + (button + icon + modal + defaultButton) + "\", \"" +  title + "\")";

    execScript(msgBox, "vbscript");
    return (result);
};

function window.prompt(message, title, defaultText, xpos, ypos, helpFile, context)
{   message = (message == null ? "" : message.toString().replace(/\"/g, "\"\"").replace(/\r\n/g, "\"+vbCrLf+\""));
    title = (title == null ? "" : title.toString().replace(/\"/g, "\"\"").replace(/\r\n/g, "\"+vbCrLf+\""));
    defaultText = (defaultText == null ? "" : defaultText.toString().replace(/\"/g, "\"\"").replace(/\r\n/g, "\"+vbCrLf+\""));
    helpFile = (String.isNullOrEmpty(helpFile) ? null : helpFile.toString());
    
    //FOUND THIS INFO HERE: http://www.vbforums.com/archive/index.php/t-21.html
    //xpos and ypos are in TWIPS !!! Supposedly there are ...
    xpos = (!IsNumeric(xpos) ? 0 : xpos * 15); //(12000 / screen.width)); //... 12000 twips horizontally
    ypos = (!IsNumeric(ypos) ? 0 : ypos * 15); //(9000 / screen.height)); //...  9000 twips vertically
    
    context = (!IsNumeric(context) ? null : context);

    var inputBox = "result = inputbox(\"" + message + "\", \"" + title + "\", \"" + defaultText + "\", " + xpos + ", " + ypos;
    if (!(helpFile == null || context == null))
        inputBox += (", \"" + helpFile + "\", " + context);
    inputBox += ")";
    
    execScript(inputBox, "vbscript");    
    return (result);
};
/// <reference name="MicrosoftAjax.js"/>
var sessionExpired = false;
var sessionTime = 0;
var sessionTimer = null;

var Session = 
{   StartTimer: function(timeout)
    {   sessionTime = timeout;
    
        var body = document.getElementsByTagName("body")[0];
        if (body != null) body.onload = new function() { Session.ResetTimer(); }
    },
    
    StopTimer: function()
    {
        if (sessionTimer != null) window.clearTimeout(sessionTimer); 
    },
    
    ResetTimer: function()
    {   Session.StopTimer();
        sessionTimer = window.setTimeout("Session.HasExpired()", sessionTime); 
    },
    
    HasExpired: function()
    {   sessionExpired = true;
        if (typeof(window.onSessionHasExpired) == "function")
            window.onSessionHasExpired();
        alert("Your session has expired due to inactivity. \r\nThis page needs to be refreshed and is going to be reloaded.", "Session Expired");
        window.location.href = window.location.href;
    }
}
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();