/* ###############################################################################################

Namespaces:

NJKCS
        .About
        .AddToFavorites ()
        .CheckParentUrl (requiredUrl)
        .DisplayError (message)
        .HasBrowserFeature (name)
        .SetParameter (name [, value])
        .GetParameter (name [, defaultValue])
        .GetQueryString (item [,defaultValue])
        .GetLibraryUrl()
        .GetScriptBaseUrl([scriptName])
        .GetAbsoluteUrl (url)
        .LoadScript (url [, language])
        .LoadCSS (url)
        .PreloadImage (url)
        .SwapImage (element, url)
        .CreateElement (tagName)
        .SetElementAttribute (element, attributeName, attributeValue)
        .SetStyleAttribute (element, attributeName, attributeValue)
        .GetElement (id)
        .GetParentElementByTag (element, tagName)
        .SetElementContent (element, content)
        .GetCursorXY (event)
        .GetElementLeft (element)
        .GetElementTop (element)
        .GetElementWidth (element)
        .GetElementHeight (element)
        .OpenWindow (url, name [, attributes])
        .OpenPopup (url, name [, attributes])
        .OpenModalDialog (url, name [, attributes])
        .OpenPopupImage (url [,width, height])
        .OpenPopupHelp (url [,width, height])
        .SizeWindow (width, height [, center])
        .MaximiseWindow()
        .BustFrameset()
        .GetFrame(frameName)
        .SetWindowTitle([title])
        
        .WindowAttributes()

NJKCS.Events
        .AddEvent (element, eventType, handler, useCapture)
        .RemoveEvent (element, eventType, handler, useCapture)
        .Rationalise (event)
        
NJKCS.ErrorHandler
        .errorReportingUrl
        
        .AddGlobalHandler()
        .RemoveGlobalHandler()
        .HandleError (message, url, line)

NJKCS.Cookies
        .SetCookie (name, value [,days])  
        .GetCookie (name)
        .DeleteCookie (name)
        
NJKCS.Forms
        .InitialiseForm (form)
        .ValidateForm (form)

NJKCS.Utils
        .DateAdd (string, int, date)
        .Trim (string)
        .LTrim (string)
        .RTrim (string)
        .Capitalise (string)
        .StringBuilder(string)
            .Append(string)
            .Clear()
            .toString()        

############################################################################################### */
/// <name>addNameSpace</name>
/// <summary>
/// Add the addNamespace function to the window if it does not already exist. This function is used to 
/// create the appropriate object hierachy from the supplied name
/// </summary>
/// <param name="ns">Namespace to be added</param>
/// <example>addNamespace("NJKCS");</example>

if ( ! window.addNamespace )
{
    window.addNamespace = function( ns ) 
    {
        var nsParts = ns.split(".");
        var root    = window;

        for( var i = 0; i < nsParts.length; i++ )
        {
            if( typeof(root[nsParts[i]]) == "undefined" )
            {
                root[nsParts[i]] = new Object();
            }
            root = root[nsParts[i]];
        }
    }
}

/* ############################################################################################### */
/* ############################################################################################### */
/* ------------------------------------------------------------------------------------------------- 
Namespace : NJKCS

Create the Main NJKCS library object and generate the properties and methods. All properties and 
methods are then available to be called via the full namespace hierarchy
------------------------------------------------------------------------------------------------- */

addNamespace("NJKCS");          // Create the core namespace

/* -------------------------------------------------------------------------------------------------
Create the default properties
------------------------------------------------------------------------------------------------- */

/// <name>NJKCS.majorVersion</name>
/// <summary>Property to return the major version of the script</summary>
/// <returns>Major version number of the script</returns>

NJKCS.majorVersion = "0";    

/// <name>NJKCS.minorVersion</name>
/// <summary>Property to return the minor version of the script</summary>
/// <returns>Minor version number of the script</returns>

NJKCS.minorVersion = "5";
NJKCS.debug        = false;
NJKCS.UNDEFINED;

NJKCS._settings         = new Object();
NJKCS._browserFeatures  = new Object();
NJKCS._loadedFiles      = new Array();

/* -------------------------------------------------------------------------------------------------
Returns about information for the NJKCS library

Return: String - Contains about information

Usage:  NJKCS.About()
------------------------------------------------------------------------------------------------- */
NJKCS.About = function ()
{
    var sAbout = "NJKCS Core Library v" + this.majorVersion + "." + this.minorVersion + 
                 " (" + NJKCS.GetScriptBaseUrl("njkcs.js") + ")";

    return sAbout;
}

/* -------------------------------------------------------------------------------------------------
Adds this url to hte favorites list

Return: nothing

Usage:  NJKCS.AddToFavorites()
------------------------------------------------------------------------------------------------- */
NJKCS.AddToFavorites = function ()
{
    alert("TODO : AddToFavorites");
}

/* ----------------------------------------------------------------------------------------
 Checks to see if the parent URL is of the specified file

Return: True if Parent URL is OK, false if not
---------------------------------------------------------------------------------------- */
NJKCS.CheckParentUrl = function (requiredUrl)
{
    var fReturn = false;
    var sBuffer = top.location.pathname.toLowerCase();

    if (sBuffer.substring(0, requiredUrl.length) == requiredUrl.toLowerCase()) {

        fReturn = true;

    }

    return fReturn;
}

/* -------------------------------------------------------------------------------------------------
Displays the error message to the user

Return: Nothing

Usage:  NJKCS.DisplayError(message)
------------------------------------------------------------------------------------------------- */
NJKCS.DisplayError = function (message)
{
    alert(message);
}

/* ------------------------------------------------------------------------------------------------ 
Retrieves true or false to indicate is a particular feature is available in the current browser

Return: Boolean - True if browser has feature, false if not

Usage:  NJKCS.HasBrowserFeature
------------------------------------------------------------------------------------------------- */
NJKCS.HasBrowserFeature = function (name)
{
    var fReturn  = false;
    
    if (typeof(NJKCS._browserFeatures[name]) != "undefined") 
    {
        fReturn = NJKCS._browserFeatures[name];
    }
    else
    {
        switch (name.toUpperCase())
        {
            case "DHTML":   
                fReturn = (document.getElementById || document.all || document.layers) ? true : false; 
                break;
        }
    }

    NJKCS._browserFeatures[name] = fReturn;

    return fReturn;
}

/* ------------------------------------------------------------------------------------------------ 
Sets a named parameter to the specified value for later recovery. The parameter name is case-sensitive

Return: Boolean - True if set, false if not

Usage:  NJKCS.SetParameter(name)
        NJKCS.SetParameter(name, value)
------------------------------------------------------------------------------------------------- */
NJKCS.SetParameter = function (name, value)
{
    NJKCS._settings[name] = value;

    return true;
}

/* ------------------------------------------------------------------------------------------------ 
Retrieves the value of a named parameter if the value is not found the default value is returned.
The parameter name is case-sensitive

Return: Various - The parameter value

Usage:  NJKCS.GetParameter(name)
        NJKCS.GetParameter(name, defaultValue)
------------------------------------------------------------------------------------------------- */
NJKCS.GetParameter = function (name, defaultValue)
{
    var value = (typeof(NJKCS._settings[name]) == "undefined") ? defaultValue : NJKCS._settings[name];

    // Fix bool values
    if (value == "true" || value == "false")
    {
        value = (value == "true");
    }

    return value;
}

/* ------------------------------------------------------------------------------------------------
This function returns the value of the query string item, if the item is not specified in the query 
string the default value is returned (if specified)

Usage:  NJKCS.GetQueryString(name)
        NJKCS.GetQueryString(name, defaultValue)
        
------------------------------------------------------------------------------------------------ */
NJKCS.GetQueryString = function (item, defaultValue) {

    var i = 0; 
    var j = 0; 
    var search  = location.search.substring(1).split('&');      // Split the search string into parts
    var sItem   = item.toUpperCase();
    var sBuffer = "";

    if (location.search.toUpperCase().indexOf(sItem) != -1) 
    {
        for ( i = 0 ; i < search.length ; i++ )
        {
            // Locate the next = sign
            
            var iEquals = search[i].indexOf("=");
            
            if (iEquals == -1)
            {
                // There is no equals sign in the search, therefore a key only

                if (search[i].toUpperCase() == sItem)
                {
                    return "";      // Matches so return blank
                }
            }
            else
            {
                sBuffer = search[i].substring(0, sItem.length + 1).toUpperCase();

                if (sBuffer == sItem + "=") 
                {        
                    sBuffer = search[i].substring(sItem.length + 1, search[i].length); 
        
                    return window.unescape(sBuffer);
                }
            }
        }
    }

    // Item does not exist in the query string

    return defaultValue;
}

/* ------------------------------------------------------------------------------------------------- 
Retrieves the URL location of the NJKCS library

Return: String - Library url

Usage:  NJKCS.GetLibraryUrl()
------------------------------------------------------------------------------------------------- */
NJKCS.GetLibraryUrl = function ()
{
    var sUrl = NJKCS.GetScriptBaseUrl().toLowerCase();
    
    return sUrl.split('njkcs.lib')[0] + "NJKCS.Lib";
}

/* ------------------------------------------------------------------------------------------------- 
Retrieves the location where the script is loaded from. If the name of the script is omitted then this
script is assumed

Return: String - Script url

Usage:  NJKCS.GetScriptBaseUrl()
        NJKCS.GetScriptBaseUrl(url)
        
------------------------------------------------------------------------------------------------- */
NJKCS.GetScriptBaseUrl = function (scriptName)
{
    var sUrl = "";
    
    if (typeof(scriptName) == 'undefined') scriptName = "njkcs.js";

    var elements = document.getElementsByTagName('script');

    for (var i=0; i<elements.length; i++) 
    {
        var sSrc = elements[i].src.toLowerCase()
       
        if (sSrc && (sSrc.indexOf(scriptName.toLowerCase()) != -1))
        {
            sSrc = NJKCS.GetAbsoluteUrl(sSrc);
            sUrl = sSrc.substring(0, sSrc.lastIndexOf('/'));
            break;
        }
    }

    return sUrl;
}

/* ------------------------------------------------------------------------------------------------- 
Translates the specified URL to an absolute URL based upon its location relative to the current
page. If the URL specified is already in absolute form it is returned unchanged

Return: String

Usage:  NJKCS.GetAbsoluteUrl(url)
------------------------------------------------------------------------------------------------- */
NJKCS.GetAbsoluteUrl = function (url)
{
    var sBuffer = "";
    var sUrl    = url.split('?')[0];

    if (sUrl.substring(0,4).toLowerCase() == "http")
    {
        sBuffer = url;
    }
    else if (sUrl.substring(0,1) == "/")
    {
        sBuffer = window.location.href.substring(0, window.location.href.indexOf('/',7)) + url;
    }
    else
    {
        var s1 = sUrl;
        var s2 = window.location.href.split('?')[0];
        var idx1;
        var idx2; 
        
        s1 = sUrl.substring(0, sUrl.lastIndexOf('/')).split('/');
        s2 = s2.substring(0, s2.lastIndexOf('/')).split('/');

        idx1 = s1.length;
        idx2 = s2.length-1;

        for (var i=0; i<s1.length; i++)
        {
            if (s1[i] == '..')      // Go up a level
            {
                s2[idx2] = "";
                idx2--;
            }
            else
            {
                idx2++;
                s2[idx2] = s1[i]; 
            }
        }

        sBuffer = "";
        for (var i=0; i<idx2+1; i++)
        {
            sBuffer += s2[i] + "/";
        }        
        
        if (typeof(url.split('?')[1]) == 'undefined')
        {
            sBuffer += sUrl.substring(sUrl.lastIndexOf('/')+1);
        }
        else
        {
            sBuffer += sUrl.substring(sUrl.lastIndexOf('/')+1) + "?" + url.split('?')[1];
        }
    }
        
    return sBuffer;
}

/* ------------------------------------------------------------------------------------------------- 
Loads the specified script from the specified url

Return: Nothing

Usage:  NJKCS.LoadScript(url)
        NJKCS.LoadScript(url, language)
------------------------------------------------------------------------------------------------- */
NJKCS.LoadScript = function (url, language)
{
    if (typeof(language) == 'undefined') language = "javascript";

    var sBuffer = NJKCS.GetAbsoluteUrl(url).toLowerCase();
    
    for (var i=0; i<this._loadedFiles.length; i++)
    {
        if (this._loadedFiles[i] == sBuffer)
        {
            return;
        }
    }

    document.write('<sc' + 'ript language="' + language + '" type="text/javascript" src="' + url + '"></script>');

    this._loadedFiles[this._loadedFiles.length] = sBuffer;
}

/* ------------------------------------------------------------------------------------------------- 
Loads the specified stylesheet from the specified url

Return: Nothing

Usage:  NJKCS.LoadCSS(url)
------------------------------------------------------------------------------------------------- */
NJKCS.LoadCSS = function (url)
{
    var sBuffer = NJKCS.GetAbsoluteUrl(url).toLowerCase();

    for (var i=0; i<this._loadedFiles.length; i++)
    {
        if (this._loadedFiles[i] == sBuffer)
        {
            return;
        }
    }

    document.write('<link href="' + url + '" rel="stylesheet" type="text/css" />');

    this._loadedFiles[this._loadedFiles.length] = sBuffer;
};


/* ------------------------------------------------------------------------------------------------- 
Preloads the specified image

Return: Nothing

Usage:  NJKCS.PreloadImage(url)
------------------------------------------------------------------------------------------------- */
NJKCS.PreloadImage = function (url)
{
    if (typeof(window.images) == 'undefined')
    {
        window.images = new Object();
    }

    var oImg    = new Image();
    
    oImg.src = url;

    window.images[url] = oImg;
}

/* ----------------------------------------------------------------------------------------
Swaps the specified image on the element to the one specified

Return:

Usage:
------------------------------------------------------------------------------------------------- */
NJKCS.SwapImage = function (element, url)
{    
    if (typeof(element) != 'object')
    {
        element = NJKCS.GetElement(element);     // Must have been given the id
    }
     
    if (element)                                 // Did we find it ?
    {
        element.src = url;                       // Change the image       
    }
}

/* ------------------------------------------------------------------------------------------------- 
Creates a new element on the page. If the element can't be created null is returned

Return: Object - element or Null

Usage:  NJKCS.CreateElement(tagName);
------------------------------------------------------------------------------------------------- */
NJKCS.CreateElement = function (tagName)
{
    var element = null;

    if (document.createElement)
    {
        element = document.createElement(tagName);
    }

    return element;
}

/* ------------------------------------------------------------------------------------------------- 
Sets an attribute of the specified element. 

The element can be specified as either a string ID or a reference to the element. If a string is 
specified the element will be located using NJKCS.GetElement

Return: Boolean - True is set, false if not

Usage:  NJKCS.SetElementAttribute(element, attributeName, attributeValue)

Example:    NJKCS.SetElementAttribute('span1', 'width', 100);
            NJKCS.SetElementAttribute(objectRef, 'width', 100);
------------------------------------------------------------------------------------------------- */
NJKCS.SetElementAttribute = function (element, attributeName, attributeValue)
{
    var fReturn = false;
    
    // Locate the element if only the ID was supplied

    if (typeof(element) != 'object')
    {
        element = NJKCS.GetElement(element);     // Must have been given the id
    }

    if (element != NJKCS.UNDEFINED) 
    {
        switch (attributeName.toLowerCase())
        {
            case "style":
                // Styles dont always work when assigned to the style attribute so parse
                // the style and apply directly as style attributes

                var aParts = attributeValue.split(';');

                for (var i in aParts)
                {
                    if (aParts[i] != "")
                    {
                        var sName  = aParts[i].split(':')[0];
                        var sValue = aParts[i].split(':')[1];

                        NJKCS.SetStyleAttribute(element, NJKCS.Utils.Trim(sName), NJKCS.Utils.Trim(sValue));
                    }
                }
                break;

            default:
                element.setAttribute(attributeName, attributeValue);
                break;
        }
        
        fReturn = true;
    }

    return fReturn;
}

/* ------------------------------------------------------------------------------------------------- 
Sets a style attribute of the specified element

The element can be specified as either a string ID or a reference to the element. If a string is 
specified the element will be located using NJKCS.GetElement

Return: Boolean - True is set, false if not

Usage:  NJKCS.SetStyleAttribute(element, attributeName, attributeValue)

Example:    NJKCS.SetStyleAttribute('span1', 'width', 100);
            NJKCS.SetStyleAttribute(objectRef, 'width', 100);
------------------------------------------------------------------------------------------------- */
NJKCS.SetStyleAttribute = function (element, attributeName, attributeValue)
{
    var fReturn = false;
    
    // Locate the element if only the ID was supplied

    if (typeof(element) != 'object')
    {
        element = NJKCS.GetElement(element);     // Must have been given the id
    }

    if (element != NJKCS.UNDEFINED)
    {
        // Ensure that the style name is OK for scripting, generally it is capitalised words with
        // the exception of the first word which is all lowercase

        var sName = attributeName;
        
        if (attributeName.indexOf("-") != -1)
        {
            var sName = attributeName.toLowerCase();
            
            var aWords = sName.split("-");
            
            for (var i=1; i<aWords.length; i++)
            {
                aWords[i] = NJKCS.Utils.Capitalise(aWords[i]);
            }
            
            sName = aWords.join("");
        }
        
        // Catch any anomilies here and translate the name
        switch (sName.toLowerCase())
        {
            //case "background-color":    sName = "backgroundColor";  break;
            default:
        }

        if (typeof(element.style[sName]) == 'undefined')
        {
            alert("'" + sName + "' = '" + attributeValue + "'" + "\n\n" + element.style[sName]);    
        }
        else
        {
            element.style[sName] = attributeValue;
            fReturn = true;
        }
    }

    return fReturn;
}

/* ------------------------------------------------------------------------------------------------- 
Locates the named element on the page if the element is not found undefined (NJKCS.UNDEFINED) is
returned

Return: Object - the located element, undefined if not found

Usage   NJKCS.GetElement(id)
------------------------------------------------------------------------------------------------- */
NJKCS.GetElement = function (id)
{
    var element = NJKCS.UNDEFINED;
    
    if (typeof(id) != "undefined")
    {
        if (typeof(id) == "object")
        {
            // We have been given an object, just return it if it is an HTML element
            element = id;
        }
        else
        {    
            if (document.getElementById)
            {
                element = document.getElementById(id);
            }
            else if (document.all)
            {
                element = document.all[id];
            }
            else if (document.layers)
            {
                element = document.layers[id];
            }
        }

        if(element == null) element = NJKCS.UNDEFINED;
        if(typeof(element) == 'undefined') element = NJKCS.UNDEFINED;
    }
    
    return element;
}

/* -------------------------------------------------------------------------------------------------
Locates the parent element with the specified TAG. If the parent element is not found null is returned

The element can be specified as either a string ID or a reference to the element. If a string is 
specified the starting element will be located using NJKCS.GetElement

Return: Object - the located element, Null if not found

Usage:  NJKCS.GetParentElementByTag(element, tagName)

Example:    NJKCS.GetParentElementByTag('span1', 'tr');
            NJKCS.GetParentElementByTag(objectRef, 'tr');
------------------------------------------------------------------------------------------------- */
NJKCS.GetParentElementByTag = function (element, tagName)
{
    tagName = tagName.toUpperCase();

    if (typeof(element) != 'object')
    {
        element = NJKCS.GetElement(element);     // Must have been given the id
    }

    if (element != NJKCS.UNDEFINED)
    {
        var oParent = element;

        while (typeof(oParent) != 'undefined' && oParent != null)
        {
            if (oParent.tagName)
            {
                if (oParent.tagName.toUpperCase() == tagName) return oParent;
            }
            
            if (oParent.parentElement)
            {
                oParent = oParent.parentElement;
            }
            else if (oParent.parentNode)
            {
                oParent = oParent.parentNode;
            }
            else
            {
                oParent = null;
            }
        }
    }

    return null;
}

/* ------------------------------------------------------------------------------------------------- 
Sets the content of the specified element. If sucessful true is returned

The element can be specified as either a string ID or a reference to the element. If a string is 
specified the element will be located using NJKCS.GetElement

Return: True if set, false if not

Usage:  NJKCS.SetElementContent(element, content)

Example:    NJKCS.SetElementContent('span1', 'this is some text');
            NJKCS.SetElementContent(objectRef, 'this is some text');
------------------------------------------------------------------------------------------------- */
NJKCS.SetElementContent =  function (element, content)
{
    var fReturn = false;
    
    if (typeof(element) != 'object')
    {
        element = NJKCS.GetElement(element);
    }

    if (element != NJKCS.UNDEFINED)
    {
        if (document.getElementById)
        {
            element.innerHTML = '';                 // Get around IE bug
            element.innerHTML = content;            // set content
            fReturn = true;
        }
        else if (document.layers)
        {
            element.document.open();
            element.document.write('<P>' + content + '</P>');
            element.document.close();
            fReturn = true;
        }
        
    }

    return fReturn;
}

/* ------------------------------------------------------------------------------------------------- 
Returns the current cursor coordinates as an object with X and Y properties

Return: Object - contains X and Y as properties, null if cursor cannot be determined

Usage:  NJKCS.GetCursorXY(event);

Example:    NJKCS.GetCursorXY(event);
------------------------------------------------------------------------------------------------- */
NJKCS.GetCursorXY = function (evnt)
{
    //var e = (window.event) ? window.event : evnt;
    var e = evnt;
    
    if ( ! e) return null;
    
    var oXY = new Object();
    
    if(document.layers)
    {
        oXY.X = e.pageX;
        oXY.Y = e.pageY;            
    }
    else if(window.opera)
    {
        oXY.X = e.clientX;
        oXY.Y = e.clientY;            
    }
    else if(document.all)
    {
        oXY.X = (e.clientX + document.body.scrollLeft);
        oXY.Y = (e.clientY + document.body.scrollTop);            
    }
    else if(document.getElementById)
    {
        oXY.X = e.pageX;
        oXY.Y = e.pageY;            
    }
    else
    {
        return null;
    }
    
    return oXY;
}

/* ------------------------------------------------------------------------------------------------- 
Returns the left position of an element. If the position cant be determined null is returned

The element can be specified as either a string ID or a reference to the element. If a string is 
specified the element will be located using NJKCS.GetElement

Return: Integer or null is value cant be calculated

Usage:  NJKCS.GetElementLeft('span1')
        NJKCS.GetElementLeft(objectRef)
------------------------------------------------------------------------------------------------- */
NJKCS.GetElementLeft = function (element)
{
    if (typeof(element) != 'object')
    {
        element = NJKCS.GetElement(element);
    }
    
    if (element != NJKCS.UNDEFINED)
    {
        var iLeft   = 0;
        
        if (element.offsetParent)
        {
            while (element.offsetParent)
            {
                iLeft   += element.offsetLeft
                element = element.offsetParent;
            }
        }
        else if (element.x)
        {
            iLeft += element.x;
        }
    
        return iLeft;    
    }

    return null;
}

/* ------------------------------------------------------------------------------------------------- 
Returns the top position of an element. If the position cant be determined null is returned

The element can be specified as either a string ID or a reference to the element. If a string is 
specified the element will be located using NJKCS.GetElement

Return: Integer or null is value cant be calculated

Usage:  NJKCS.GetElementTop('span1')
        NJKCS.GetElementTop(objectRef)
------------------------------------------------------------------------------------------------- */
NJKCS.GetElementTop = function (element)
{
    if (typeof(element) != 'object')
    {
        element = NJKCS.GetElement(element);
    }
    
    if (element != NJKCS.UNDEFINED)
    {
        var iTop    = 0;

        if (element.offsetParent)
        {
            while (element.offsetParent)
            {
                iTop    += element.offsetTop;
                element = element.offsetParent;
            }
        } 
        else if (element.y)
        {
            iTop += element.y;
        } 
    
        return iTop;
    }
    
    return null;
}

/* ------------------------------------------------------------------------------------------------- 
Returns the width of an element. If the width cant be determined null is returned

The element can be specified as either a string ID or a reference to the element. If a string is 
specified the element will be located using NJKCS.GetElement

Return: Integer or null is value cant be calculated

Usage:  NJKCS.GetElementWidth('span1')
        NJKCS.GetElementWidth(objectRef)
------------------------------------------------------------------------------------------------- */
NJKCS.GetElementWidth = function (element)
{
    if (typeof(element) != 'object')
    {
        element = NJKCS.GetElement(element);
    }
    
    if (element != NJKCS.UNDEFINED)
    {
        return element.offsetWidth;    
    }

    return null;
}

/* ------------------------------------------------------------------------------------------------- 
Returns the height of an element. If the height cant be determined null is returned

The element can be specified as either a string ID or a reference to the element. If a string is 
specified the element will be located using NJKCS.GetElement

Return: Integer or null is value cant be calculated

Usage:  NJKCS.GetElementHeight('span1')
        NJKCS.GetElementHeight(objectRef)
------------------------------------------------------------------------------------------------- */
NJKCS.GetElementHeight = function (element)
{
    if (typeof(element) != 'object')
    {
        element = NJKCS.GetElement(element);
    }
    
    if (element != NJKCS.UNDEFINED)
    {
        return element.offsetHeight;
    }
    
    return null;
}

/* ------------------------------------------------------------------------------------------------- 
Defines a set of attributes that specify how a window is to appear

Return: Object - initialised with window attributes

Usage:  var o = new NJKCS.WindowAttributes();
------------------------------------------------------------------------------------------------- */
NJKCS.WindowAttributes = function()
{
    this.autosize   = false;    // If set to true the window should attempt to size to its content
    this.width      = undefined;
    this.height     = undefined;
    this.top        = undefined;
    this.left       = undefined;
    this.scrollBars = undefined;
    this.statusBar  = undefined;
    this.menuBar    = undefined;
    this.toolBar    = undefined;
}

/* ------------------------------------------------------------------------------------------------- 
Opens a window containing the specified url and set the focus to it. If a name for the window is not 
specified a blank window is opened. 

Return: Window Object

Usage:  NJKCS.OpenWindow(url)
        NJKCS.OpenWindow(url, name)
        NJKCS.OpenWindow(url, name, attributes)
------------------------------------------------------------------------------------------------- */
NJKCS.OpenWindow = function (url, name, attributes)
{
    var sFeatures   = "";  
    var sHTML;
    
    if (name       == this.UNDEFINED) name = "_blank";
    if (attributes != this.UNDEFINED) 
    {
        sFeatures = "width=" + attributes.width + "," + 
                    "height=" + attributes.height + "," +
                    "top=" + attributes.top + "," + 
                    "left=" + attributes.left + "," +
                    "status=" + ((attributes.statusBar) ? 1 : 0) + "," +
                    "toolbar=" + ((attributes.toolBar) ? 1 : 0) + "," +
                    "resizable=yes";    
    }
    
    var oWin = window.open(url, name, sFeatures);
    
    try
    {
        if ( ! oWin.opener) oWin.opener = self;

        if (oWin.focus) oWin.focus();
    }
    catch (e)
    {
    }

}

/* ------------------------------------------------------------------------------------------------- 
Opens a popup window containing the specified url the focus is set to the window. 
The generated window object is returned to the caller.

Return: Window Object

Usage:  NJKCS.OpenPopup(url)
        NJKCS.OpenPopup(url, name)
        NJKCS.OpenPopup(url, name, attributes)
------------------------------------------------------------------------------------------------- */
NJKCS.OpenPopup = function (url, name, attributes)
{
    var sFeatures   = "";  
    var sHTML;
    
    if (name       == this.UNDEFINED) name = "popupWindow";
    if (attributes == this.UNDEFINED) attributes = new NJKCS.WindowAttributes();

    if ( ! attributes.width)      attributes.width      = 500;
    if ( ! attributes.height)     attributes.height     = 400;
    if ( ! attributes.top)        attributes.top        = 50;
    if ( ! attributes.left)       attributes.left       = 50;
    if ( attributes.scrollBars == this.UNDEFINED) attributes.scrollBars = true;
    if ( attributes.statusBar  == this.UNDEFINED) attributes.statusBar  = true;
    if ( attributes.toolBar    == this.UNDEFINED) attributes.toolBar    = true;
    
    if (screen.availHeight < attributes.height) {
        attributes.height = screen.availHeight - 100;
    }
    if (screen.availWidth < attributes.width) {
        attributes.width = screen.availWidth - 150;
    }

    sFeatures = "width=" + attributes.width + "," + 
                "height=" + attributes.height + "," +
                "top=" + attributes.top + "," + 
                "left=" + attributes.left + "," +
                "status=" + ((attributes.statusBar) ? 1 : 0) + "," +
                "scrollbars=" + ((attributes.scrollBars) ? 1 : 0) + "," +
                "toolbar=" + ((attributes.toolBar) ? 1 : 0) + "," +
                "resizable=yes";

    var oWin = window.open(url, name, sFeatures);

    try
    {
        if ( ! oWin.opener) oWin.opener = self;

        if (oWin.focus) oWin.focus();
    }
    catch (e)
    {
    }
    
    return oWin;
}

/* ------------------------------------------------------------------------------------------------- 
Opens a modal dialog window containing the specified url the focus is set to the newloy opened window.
The window is a dialog window so that it will always remain on top of the opening window.

Return: Nothing

Usage:  NJKCS.OpenModalDialog(url)
        NJKCS.OpenModalDialog(url, name)
        NJKCS.OpenModalDialog(url, name, attributes)
------------------------------------------------------------------------------------------------- */
NJKCS.OpenModalDialog = function (url, name, attributes)
{
    var sFeatures   = "";  
    var sHTML;
    
    if (name       == this.UNDEFINED) name = "dialogWindow";
    if (attributes == this.UNDEFINED) attributes = new NJKCS.WindowAttributes();

    if ( ! attributes.width)     attributes.width     = 250;
    if ( ! attributes.height)    attributes.height    = 300;
    if ( ! attributes.top)       attributes.top       = 50;
    if ( ! attributes.left)      attributes.left      = 50;
    if ( attributes.scrollBars == this.UNDEFINED) attributes.scrollBars = true;
    if ( attributes.statusBar  == this.UNDEFINED) attributes.statusBar  = true;
    if ( attributes.toolBar    == this.UNDEFINED) attributes.toolBar    = true;
    
    if (screen.availHeight < attributes.height) {
        attributes.height = screen.availHeight - 100;
    }
    if (screen.availWidth < attributes.width) {
        attributes.width = screen.availWidth - 150;
    }

    sFeatures = "dialogWidth:" + attributes.width + "px;" + 
                "dialogHeight:" + attributes.height + "px;" +
                "dialogTop:" + attributes.top + "px;" + 
                "dialogLeft:" + attributes.left + "px;" +
                "scroll:" + ((attributes.scrollBars) ? 1 : 0) + ";" +
                "status:" + ((attributes.statusBar) ? 1 : 0) + ";" +
                "resizable:yes;";
    
    var oWin = window.showModalDialog(url, name, sFeatures);
    
}


/* ---------------------------------------------------------------------------------------------------------
This fuction will display a large image in a seperate popup window

--------------------------------------------------------------------------------------------------------- */
NJKCS.OpenPopupImage = function (url, width, height)
{
    var sFeatures;  
    var iWidth  = 600;
    var iHeight = 500;
    var sHTML;
    
    if (width  != this.UNDEFINED) iWidth  = width;
    if (height != this.UNDEFINED) iHeight = height;
   
    if (screen.availHeight < iHeight) {
        iHeight = screen.availHeight - 50;
    }

    sFeatures = "width=" + iWidth + "," + 
                "height=" + iHeight + "," +
                "resizable=yes," +
                "top=" + ((screen.availHeight - iHeight) / 2) + "," + 
                "left=" + (screen.availWidth - iWidth) / 2;

    sHTML = "<html>" +
            "<head>" +
            "<title>Image Viewer</title>" + 
            "</head>" +
            "<body leftmargin='0' rightmargin='0' topmargin='0'>" +
            "<table width='100%' height='100%' cellpadding='0' cellspacing='0' border='0'>" +
            "<tr><td align='center' valign='middle'><a href='javascript:window.close();'><img src='" + url + "' border='0'></a></td></tr>" +
            "<tr><td height='10' align='center'><a href='javascript:window.close();'>Click to close</a></td></tr>" +
            "</table>" +
            "</body>" +
            "</html>"
    
    var oWin = window.open("", "Picture", sFeatures);

    oWin.document.open();
    oWin.document.write(sHTML);
    oWin.document.close();

    try
    {
        if (oWin.focus) oWin.focus();
    }
    catch (e)
    {
    }

}

//---------------------------------------------------------------------------------------------------------
// This fuction will display a large image in a seperate popup window
//
NJKCS.OpenPopupHelp = function (helpID, width, height)
{
    var sFeatures;  
    var iWidth  = 250;
    var iHeight = 300;
    var sHTML;
    
    if (width  != this.UNDEFINED) iWidth  = width;
    if (height != this.UNDEFINED) iHeight = height;
    
    if (screen.availHeight < iHeight) {
        iHeight = screen.availHeight - 50;
    }

    sFeatures = "width=" + iWidth + "," + 
                "height=" + iHeight + "," +
                "resizable=yes," +
                "top=100," + 
                "left=100";
    
    var oWin = window.open("/PopupHelp.aspx?HelpID=" + helpID , "popupHelp", sFeatures);

    try
    {
        if ( ! oWin.opener) oWin.opener = self;

        if (oWin.focus) oWin.focus();
    }
    catch (e)
    {
    }

}

//-------------------------------------------------------------------------------
// Description: Sets the window to the specified size and centers it if reqired
//
// Usage:   NJKCS.SizeWindow(width, height)
//          NJKCS.SizeWindow(width, height, center)
//          NJKCS.SizeWindow(width, height, center, effects)
//
NJKCS.SizeWindow = function (width, height, center, effects)
{
    var INTERVAL  = 30;
    var INCREMENT = 20
    var oWin = self;
    var x = (screen.availWidth-width)/2
    var y = (screen.availHeight-height)/2;
        
    if (center  == this.UNDEFINED) center  = true;
    if (effects == this.UNDEFINED) effects = "none";

    iLeft = window.screenLeft;
    iTop  = window.screenTop;

    effects = effects.toLowerCase();
    
    switch (effects)
    {
        default:
            if ( center ) { oWin.moveTo(x,y); }
            oWin.resizeTo(width,height);
            break;
    }

    return;
}

//------------------------------------------------------------------------
// Description: Maximises the current window
//
// Usage    NJKCS.MaximiseWindow()
//
NJKCS.MaximiseWindow = function ()
{
    var win = self;
    
    win.moveTo(0,0);
    win.resizeTo(screen.availWidth, screen.availHeight);
}

//----------------------------------------------------------------------------------
// Description: If the current window is running within somebody elses frameset it will 
//              open a new window within which to operate
//
// Usage: NJKCS.BustFrameset()
//
NJKCS.BustFrameset = function ()
{
    if (top != self) {
        top.location.replace(self.location.href)
        return true;
    }
}

//---------------------------------------------------------------------------------
// Description: Locates the frame with the specified name and returns a reference to it
//
// Usage:    NJKCS.GetFrame(frameName)
//
NJKCS.GetFrame = function (frameName)
{
    var oFrame;
    var i;
    
    if (frameName != this.UNDEFINED)
    {
        // locate the target window by examining the frames in this document and parents

        if (typeof(window.frames[frameName]) == "object") 
        {
            oFrame = window.frames[frameName];
        }
        
        if (typeof(parent.frames[frameName]) == "object")
        {
            oFrame = parent.frames[frameName]; 
        }
    
    }
    
    return oFrame;
}

//------------------------------------------------------------------
// Description: Sets the title of the browser window to that specified, or the title
//              of the active document if a title is not specified
//
// Usage:   NJKCS.SetWindowTitle()
//          NJKCS.SetWindowTitle(title)
//
NJKCS.SetWindowTitle = function (title)
{
    if (title == this.UNDEFINED) 
    { 
        title = document.title;
    }
    
    top.document.title = theTitle;
}

/* ############################################################################################### */
/* ############################################################################################### */
/* ------------------------------------------------------------------------------------------------- 
Namespace : NJKCS.Events

Create the NJKCS.Events library object. All properties and methods are then available to be called 
via the full namespace hierarchy
------------------------------------------------------------------------------------------------- */

addNamespace("NJKCS.Events");          // Create the NJKCS.Events namespace

/* ------------------------------------------------------------------------------------------------- 
Adds the specified event handler to the specified element/object

The element can be specified as either a string ID or a reference to the element. If a string is 
specified the element will be located using NJKCS.GetElement

Return: true if assigned, false if not

Usage:  NJKCS.Events.AddEvent(element, eventType, handler)
        NJKCS.Events.AddEvent(element, eventType, handler, useCapture)
------------------------------------------------------------------------------------------------- */
NJKCS.Events.AddEvent = function (element, eventType, handler, useCapture)
{
    var fReturn = false;
    
    if (typeof(element) != 'object')
    {
        element = NJKCS.GetElement(element);
    }
    if (element != NJKCS.UNDEFINED)
    {
        if (typeof(handler) != 'function')
        {
            NJKCS.DisplayError("NJKCS.Events.AddEvent : Specified handler is not a function");
        }
        else
        {
            var capt = (useCapture == null) ? false : useCapture;

            if (element.attachEvent)
            {
                element.attachEvent("on" + eventType, handler);
            }
            else if (element.addEventListener)
            {
                element.addEventListener(eventType, handler, capt); 
            }
            else if (typeof(element[eventType]) == "function")
            {
                var fOld = element[eventType];
                element[eventType] = function(e){ fOld(e); handler(e); };
            }
            else
            {
                element[eventType] = handler;
            };
        
            //EventCache.add( eventTarget, eventType, fDest, capt );
            fReturn = true;
        }
    }
    
    return fReturn;
} 

/* ------------------------------------------------------------------------------------------------- 
Removes the specified event handler from the specified element/object

The element can be specified as either a string ID or a reference to the element. If a string is 
specified the element will be located using NJKCS.GetElement

Return: true if removed, false if not

Usage:  NJKCS.Events.RemoveEvent(element, eventType, handler)
        NJKCS.Events.RemoveEvent(element, eventType, handler, useCapture)
------------------------------------------------------------------------------------------------- */
NJKCS.Events.RemoveEvent = function(element, eventType, handler, useCapture)
{
    var fReturn = false;
    
    if (typeof(element) != 'object')
    {
        element = NJKCS.GetElement(element);
    }
    
    if (element != NJKCS.UNDEFINED)
    {
        var capt = (useCapture == null) ? false : useCapture;

        if (element.removeEventListener)
        {
            element.removeEventListener(eventType, handler, capt);
            fReturn = true;
        }
        else if (element.detachEvent)
        {
            var r = element.detachEvent("on" + eventType, handler);
            fReturn = true;
        }
        else
        {
            // alert("Handler could not be removed");
        }
    }
    
    return fReturn;
}

/* ------------------------------------------------------------------------------------------------- 
Rationalise a supplied event so that the most common properties are also available. The model is 
based upon the IE model

Return: the supplied event with additional properties

Usage:  NJKCS.Events.Rationalise(event)
------------------------------------------------------------------------------------------------- */
NJKCS.Events.Rationalise = function(e)
{
    if (e.target)
    {
        e.srcElement = e.target;
    }

    return e;
}

/* ############################################################################################### */
/* ############################################################################################### */
/* -------------------------------------------------------------------------------------------------
Namespace : NJKCS.Cookies

Create the NJKCS.Cookies library object. All properties and methods are then available to be called 
via the full namespace hierarchy
------------------------------------------------------------------------------------------------- */

addNamespace("NJKCS.Cookies");          // Create the NJKCS.Cookies namespace

/* ------------------------------------------------------------------------------------------------- 
Sets the value of a cookie

Return: True if set, flase if not

Usage:  NJKCS.Cookies.SetCookie(name, value)
        NJKCS.Cookies.SetCookie(name, value, days)
------------------------------------------------------------------------------------------------- */
NJKCS.Cookies.SetCookie = function (name, value, days)
{
    var expires = "";
    
    if (days)
    {
        // Set the expiration time
        var date = new Date();

        date.setTime(date.getTime() + (days*24*60*60*1000));
        expires = "; expires=" + date.toGMTString();
    }

    document.cookie = name + "=" + value + expires + "; path=/";

    return true;
}

/* ------------------------------------------------------------------------------------------------- 
Returns the value of a cookie. If the cookie can't be located null will be returned

Return: Value of the cookie or null

Usage:  NJKCS.Cookies.GetCookie(name)
------------------------------------------------------------------------------------------------- */
NJKCS.Cookies.GetCookie = function (name)
{
    var nameEQ  = name + "=";
    var ca      = document.cookie.split(';');

    for(var i=0; i < ca.length; i++)
    {
        var c = ca[i];

        while (c.charAt(0)==' ')
        {
            c = c.substring(1,c.length);
        }
        if (c.indexOf(nameEQ) == 0)
        {
            return c.substring(nameEQ.length, c.length);
        }
    }

    return null;
}

/* ------------------------------------------------------------------------------------------------- 
Removes a cookie from the cookie collection.

Return: True if deleted, false if not

Usage:  NJKCS.Cookies.DeleteCookie(name)
------------------------------------------------------------------------------------------------- */
NJKCS.Cookies.DeleteCookie = function (name)
{
    return NJKCS.Cookies.SetCookie(name, "", -1);
}

/* ############################################################################################### */
/* ############################################################################################### */
/* ------------------------------------------------------------------------------------------------- 
Namespace : NJKCS.ErrorHandler

Create the error handler object and generate the properties and methods. All properties and 
methods are then available to be called via the full namespace hierarchy
------------------------------------------------------------------------------------------------- */

addNamespace("NJKCS.ErrorHandler");

/* -------------------------------------------------------------------------------------------------
Create the default properties
------------------------------------------------------------------------------------------------- */

NJKCS.ErrorHandler.errorReportingUrl = null;

/* ------------------------------------------------------------------------------------------------- 
Create the windows error handler
------------------------------------------------------------------------------------------------- */
NJKCS.ErrorHandler.AddGlobalHandler = function()
{
    if ( ! window.onerror)
    {
        window.onerror = function(message, url, line) 
        {
            return NJKCS.ErrorHandler.HandleError(message, url, line);
        }
    }
}

/* ------------------------------------------------------------------------------------------------- 
Removes the windows error handler
------------------------------------------------------------------------------------------------- */
NJKCS.ErrorHandler.RemoveGlobalHandler = function()
{
    if (window.onerror)
    {
        window.onerror = null;
    }
}

/* ------------------------------------------------------------------------------------------------- 
Process an error

Syntax: HandleError(err)
        HandleError(message, url, line)
------------------------------------------------------------------------------------------------- */
NJKCS.ErrorHandler.HandleError = function (message, url, line)
{
    var err      = new Object();
    var sMessage = "";
    
    if (typeof(message) == "object")
    {
        err.name      = message.name;
        err.message   = message.message;        
        if (message.fileName)   err.location = message.fileName;
        if (message.lineNumber) err.line     = message.lineNumber;        
    }
    else
    {
        err.name      = "Unknown";
        err.message   = message;
        if (url)    err.location = url;
        if (line)   err.line     = line;
    }

    if ( ! err.location) err.location = window.location.href.split('?')[0];

    sMessage += "Error: " + err.name + "\n\n" +
                err.message + "\n\n" +
                "Location: " + err.location + "\n" +
                "Line: " + err.line
                
    alert(sMessage);

    if (this.errorReportingUrl != null)
    {
        alert("Error reporting to server has not been implemented");
    }
    
    return true;
}

/* ############################################################################################### */
/* ############################################################################################### */
/* ------------------------------------------------------------------------------------------------- 
Namespace : NJKCS.Forms

Form utility and processing functions
------------------------------------------------------------------------------------------------- */

addNamespace("NJKCS.Forms");

//--------------------------------------------------------------------------------------------------
// This routine will iterate through all the input controls on the specified form and initialises the
// field according to the propertiy settings as follows:
//
//      datatype    :   string, date, number
//      mandatory   :   if exists it is taken that a value must be supplied
//
NJKCS.Forms.InitialiseForm = function (form)
{
    if (typeof(form) == "undefined") return false;

    for (var i=0; i < form.length; i++) {
        
        var e = form[i];
        
        if (typeof(e) != "undefined") {

            switch (e.tagName) {
            
                case "INPUT":
                    if (e.mandatory) {
                        e.style.backgroundImage    = "url(" + NJKCS.GetLibraryUrl() + "/images/mandatory.gif)";
                        e.style.backgroundRepeat   = "no-repeat";
                        e.style.backgroundPosition = "top right";
                    }
                    break;
                    
                case "SELECT":
                    if (e.mandatory) {
                        e.style.backgroundImage    = "url(" + NJKCS.GetLibraryUrl() + "/images/mandatory.gif)";
                        e.style.backgroundRepeat   = "no-repeat";
                        e.style.backgroundPosition = "top right";
                    }
                    break;
                    
                case "TEXTAREA":

                    if (e.mandatory) {
                        e.style.backgroundImage    = "url(" + NJKCS.GetLibraryUrl() + "/images/mandatory.gif)";
                        e.style.backgroundRepeat   = "no-repeat";
                        e.style.backgroundPosition = "top right";
                    }
                    break;
                    
                default:
                    //alert(e.tagName);
            }
        }

    }
    
    return true;
}

// ------------------------------------------------------------------------------------------------------------------
// This routine will iterate through all the input controls on the specified form and validate the values according
// to the propertiy settings as follows:
//
//      datatype    :   string, date, number
//      mandatory   :   optional, mandatory
//
NJKCS.Forms.ValidateForm = function (form) 
{
    if (typeof(form) == "undefined") return false;

    var sErrorMessages = "";

    for (var i=0; i<form.length; i++) {
    
        var e = form[i];
        
        if (typeof(e) != "undefined") {

            switch (e.tagName) {
            
                case "INPUT":
                case "SELECT":
                case "TEXTAREA":

                    if (e.mandatory) {
                    
                        if (e.value == "") {
                            e.style.backgroundColor = "yellow";
                            sErrorMessages += "Field " + e.name + " is mandatory\n";
                        }
                    }
                    break;
                    
                default:
                    //alert(e.tagName);
            }
        }
    }

    if (sErrorMessages != "") {
    
        alert("The following input errors were detected :\n\n" + sErrorMessages);
        return false;
            
    }
    else {
        return true;
    }
}

/* ############################################################################################### */
/* ############################################################################################### */
/* ------------------------------------------------------------------------------------------------- 
Namespace : NJKCS.Utils

Utility functions
------------------------------------------------------------------------------------------------- */

addNamespace("NJKCS.Utils");

/* -------------------------------------------------------------------------------------------------
Create the default properties
------------------------------------------------------------------------------------------------- */

//-------------------------------------------------------------------------------------------
// Valid intervals are:
//
//      yyyy    Year 
//      q       Quarter 
//      m       Month 
//      y       Day of year 
//      d       Day 
//      w       Weekday 
//      ww      Week of year 
//      h       Hour 
//      n       Minute 
//      s       Second 
//
NJKCS.Utils.DateAdd = function (interval, count, startDate)
{
    var oDate  = new Date(startDate)

    switch (interval)
    {
        case "Y":       oDate.setYear(oDate.getYear() + count);     break;
        case "M":       oDate.setMonth(oDate.getMonth() + count);   break;
        case "D":       oDate.setDate(oDate.getDate() + count);     break;
        default:        oDate = "dateAdd incorrect interval " + interval;
    }

    return oDate;
}

/* -------------------------------------------------------------------------------------------------
Removes both leading and trailing space from the supplied string

Return: String with leading and trailing spaces removed

Usage:  NJKCS.Utils.Trim(value)
------------------------------------------------------------------------------------------------- */
NJKCS.Utils.Trim = function (value)
{
    if (value == null)
    {
        return "";
    }
    else if (value.length < 1)
    {
        return "";
    }
    else
    {
        value = NJKCS.Utils.RTrim(value);
        value = NJKCS.Utils.LTrim(value);

        return value;
    }
}

/* -------------------------------------------------------------------------------------------------
Removes trailing space from the supplied string

Return: String with trailing spaces removed

Usage:  NJKCS.Utils.RTrim(value)
------------------------------------------------------------------------------------------------- */
NJKCS.Utils.RTrim = function (value)
{
    if (value == null)
    {
        return "";
    }
    else if (value.length < 1)
    {
        return "";
    }
    else
    {
        var sSpace  = String.fromCharCode(32);
        var sTemp   = "";
        var iTemp   = value.length - 1;

        while (iTemp > -1)
        {
            if (value.charAt(iTemp) != sSpace)
            {
                sTemp = value.substring(0, iTemp+1);
                break;
            }
            iTemp = iTemp-1;
        }
    
        return sTemp;
    }
}

/* -------------------------------------------------------------------------------------------------
Remove leading space from the supplied string

Return: String with leading spaces removed

Usage:  NJKCS.Utils.LTrim(value)
------------------------------------------------------------------------------------------------- */
NJKCS.Utils.LTrim = function (value)
{
    if (value == null)
    {
        return "";
    }
    else if (value.length < 1)
    {
        return "";
    }
    else
    {
        var sSpace = String.fromCharCode(32);
        var iLength = value.length;
        var sTemp   = "";
        var iTemp   = 0;

        while (iTemp < iLength)
        {
            if(value.charAt(iTemp) != sSpace)
            {
                sTemp = value.substring(iTemp, iLength);
                break;
            }
            iTemp = iTemp + 1;
        }
        
        return sTemp;
    }
}

/* -------------------------------------------------------------------------------------------------
Capitalises the supplied string

Return: String Capitalised

Usage:  NJKCS.Utils.Capitalise(value)
------------------------------------------------------------------------------------------------- */
NJKCS.Utils.Capitalise = function (value)
{    
    if (value == null)
    {
        return "";
    }
    else if (value.length == 1)
    {
        return value.toUpperCase();
    }
    else
    {
        return value.substring(0,1).toUpperCase() + value.substring(1).toLowerCase() 
    }
}

/* -------------------------------------------------------------------------------------------------
Initializes a new instance of the StringBuilder class and appends the given value if supplied

Return: Object - Initialised string builder

Usage:  var s = new NJKCS.Utils.StringBuilder()
        var s = new NJKCS.Utils.StringBuilder(value)

------------------------------------------------------------------------------------------------- */
NJKCS.Utils.StringBuilder = function(value)
{
    this._strings = new Array("");
    this.Append(value);
}

/* -------------------------------------------------------------------------------------------------
Appends the given value to the end of this instance.

Return: Nothing

Usage:  s.Append(value)
------------------------------------------------------------------------------------------------- */
NJKCS.Utils.StringBuilder.prototype.Append = function (value)
{
    if (value)
    {
        this._strings.push(value);
    }
}

/* -------------------------------------------------------------------------------------------------
Clears the string buffer

Return: Nothing

Usage:  s.Clear()
------------------------------------------------------------------------------------------------- */
NJKCS.Utils.StringBuilder.prototype.Clear = function ()
{
    this._strings.length = 1;
}

/* -------------------------------------------------------------------------------------------------
Converts this instance to a String.

Return: Nothing

Usage:  s.Clear()
------------------------------------------------------------------------------------------------- */
NJKCS.Utils.StringBuilder.prototype.toString = function ()
{
    return this._strings.join("");
}

/* ------------------------------------------------------------------------------------------------- 
Extend standard data types by modifying the prototype
------------------------------------------------------------------------------------------------- */

// <object>.prototype.<function> = function () { ????? }

/* ------------------------------------------------------------------------------------------------- 
Include other scripts
------------------------------------------------------------------------------------------------- */

NJKCS.LoadScript(NJKCS.GetLibraryUrl() + "/Scripts/NJKCS.Debug.js");
NJKCS.LoadScript(NJKCS.GetLibraryUrl() + "/Scripts/NJKCS.AJAX.js");

