﻿/********************************************************************************
 Copyright © Exbos Limited 2009. All rights reserved.
 Exbos Limited is a Limited Liability Company registered in England and Wales.
 Registered company number 06130291.
*********************************************************************************
 THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
 OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
 LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 FITNESS FOR A PARTICULAR PURPOSE.
*********************************************************************************
 THIS CODE IS LICENSED FOR USE ONLY WITHIN THIS WEB SITE ON THIS DOMAIN. 
 THE CODE MAY NOT BE USED ON ANY OTHER WEB SITE, EITHER WHOLLY OR PARTIALLY, 
 WITHOUT PRIOR WRITTEN PERMISSION.
********************************************************************************/

// The main system object
var System = new Object();

// Core system variables
System._listTypes = new Array();
System._listObjects = new Array();
System._iTotalObjects = 0;
System._bLoaded = false;
System.EmptyFunction = function(){}
System.AbstractFunction = function(){throw System.CreateObject("System.Exception", -1, "Pure virtual call!");}
System.Version = "Unknown Version";

// Core namespaces
System.Controls = new Object();
System.Ajaxlets = new Object();
System.Events = new Object();
System.Services = new Object();
System.Extensions = new Object();
System.DockAreas = new Array();
System.Dialogs = new Object();
System.Xml = new Object();
System.Mouse = new Object();
System.Mouse.X = 0;
System.Mouse.Y = 0;
System.Mouse.LeftButtonPressed = false;

// Globals
System.Globals = new Object();
System.Globals._asXmlDocumentProgIds = ["Msxml2.DOMDocument.4.0", "Msxml2.DOMDocument.3.0", "Msxml2.DOMDocument", "Msxml.DOMDocument"];
System.Globals._asXmlHttpRequestProgIds = ["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"];
System.Globals.CorePath = "Scripts";
System.Globals.RemoteFileProvider = "RemoteFileSystem.ashx";
System.Globals.ZIndex = 100;
System.Globals.DragObject = null;
System.Globals.DragOffsetX = null;        
System.Globals.DragOffsetY = null;
System.Globals.ResizeOffsetX = null;
System.Globals.ResizeOffsetY = null;
System.Globals.ResizeObject = null;
System.Globals.ResizeStartWidth = null;
System.Globals.ResizeStartHeight = null;

/// <summary>
/// Creates a wrapper around a function alowing it to be safely called in the
/// correct context. This prevents invalid 'this' references when the method
/// is being called as part of the DHTML event model.
/// </summary>
/// <param name="contextObject">Context the mehtod will be called under</param>
/// <param name="delegateMethod">Method to be called</param>
/// <author initials="LH">Lee Hesselden</author>	
/// <change initials="LH" date="15/01/2007">Created</change>
System.CreateDelegate = function(contextObject, delegateMethod)
{   
    return function()
    {
        return delegateMethod.apply(contextObject, arguments);
    }    
}       

/// <summary>
/// Creates a cross browser compatible XML document object. This will work with
/// difering version of internet explorer and mozilla.
/// </summary>
/// <author initials="LH">Lee Hesselden</author>	
/// <change initials="LH" date="15/01/2007">Created</change>
System.CreateXmlDocument = function()
{
    try
    {
        // Check for mozilla
        if(typeof HTMLElement == "undefined")
        {
            
            // Try all supported versions of MSXML
            for(var iProgIdIndex = 0; iProgIdIndex < System.Globals._asXmlDocumentProgIds.length; iProgIdIndex++)
            {
                try
                {
                    return new ActiveXObject(System.Globals._asXmlDocumentProgIds[iProgIdIndex]); 
                }
                catch(ex)
                {
                    // Do nothing try and find a compatible version
                }
            }

            // No support objects found unable to continue
            throw System.CreateObject("System.Exception", -1, "Unable to create a compatible XmlDocument object.");   

        }
        else
        {                   
            // Use mozilla document model
            return document.implementation.createDocument("", "", null);
        }
    }
    catch(ex)
    {
        // Error creating the XmlDocument 
        throw System.CreateObject("System.Exception", -1, "Unable to create a compatible XmlDocument object.", ex);   
    }
}

/// <summary>
/// Creates a cross browser compatible XmlHttpRequest object. This will work
/// with difering version of internet explorer and mozilla.
/// </summary>
/// <author initials="LH">Lee Hesselden</author>	
/// <change initials="LH" date="15/01/2007">Created</change>
System.CreateXmlHttpRequest = function()
{
    try
    {
        // Check for mozilla
        if(!window.XMLHttpRequest)
        {
            
            // Try all supported versions of XmlHttpRequest
            for(var iProgIdIndex = 0; iProgIdIndex < System.Globals._asXmlHttpRequestProgIds.length; iProgIdIndex++)
            {
                try
                {
                    return new ActiveXObject(System.Globals._asXmlHttpRequestProgIds[iProgIdIndex]);
                }
                catch(ex)
                {
                    // Do nothing try and find a compatible version
                }
            }

            // No support objects found unable to continue
            throw System.CreateObject("System.Exception", -1, "Unable to create a compatible XmlHttpRequest object.");  

        }
        else
        {        
            // Use mozilla request model
            return new window.XMLHttpRequest();
        } 
    }
    catch(ex)
    {
        // Error creating the XmlDocument 
        throw System.CreateObject("System.Exception", -1, "Unable to create a compatible XmlHttpRequest object.", ex);   
    }           
}

System.GetType = function(sName)
{
    var type;
    
    // Extract the type object by name
    type = System._listTypes[sName];
    if(type == null)
    {
        throw System.CreateObject("System.Exception", -1, "Type requested \"" + sName + "\" could not be found");
    }
    
    // Load the types code base if required
    if(!type.IsLoaded())
    {
        type.Load();
    }      
    
    // Return the type object
    return type;
}

System.CreateObject = function(typeObject)
{

    var objectNew;
    var typeBase;
    var inheritanceChain;    
    
    try
    {

        // Convert string to type object
        if(typeof(typeObject) == "string")
        {
            typeObject = System.GetType(typeObject);
        }
    
        // Last constructor is top of chain
        inheritanceChain = new Array();
        inheritanceChain[inheritanceChain.length] = typeObject.Constructor;
            
        // Follow base objects building the inheritance chain
        typeBase = typeObject.BaseType;
        while(typeBase != null)
        {   
            if(!typeBase.IsLoaded())typeBase.Load();     
            inheritanceChain[inheritanceChain.length] = typeBase.Constructor;
            typeBase = typeBase.BaseType;
        }
        
        // Create the new object
        objectNew = new Object();
                
        // Go back through the inheritance chain constructing the class from the base up
        for(var iBaseIndex = inheritanceChain.length - 1; iBaseIndex >= 0; iBaseIndex--)
        {
            // Call each constructor with the arguments on the object
            inheritanceChain[iBaseIndex].apply(objectNew, Array.prototype.slice.call(arguments, 1 ));
        }      
    
        // Store new object and increase object live counter
        objectNew._type = typeObject;        
        objectNew._iObjectId = System._listObjects.length;
        System._listObjects[System._listObjects.length] = objectNew;
        System._iTotalObjects++;
    
        // Return the constructed object
        return objectNew;
        
    }
    catch(ex)
    {
        throw System.CreateObject("System.Exception", -1, "Unable to create the object \"" + typeObject.Name + "\"", ex);
    }
}

System.ExtendObject = function(objectToExtend, typeExtender)
{

    var typeBase;
    var inheritanceChain;    

    try
    {
        
        // Convert string to type object
        if(typeof(typeExtender) == "string")
        {
            typeExtender = System.GetType(typeExtender);
        }
    
        // Don't ever extend with something the object has already inherited or been extended by
        if(objectToExtend.GetType().IsSubclassOf(typeExtender) || objectToExtend.IsExtendedBy(typeExtender))
        {
            throw System.CreateObject("System.Exception", -1, "Object already extended by or inherits from the extension \"" + typeExtender.Name + "\"");
        }
    
        // Last constructor is top of chain
        inheritanceChain = new Array();
        inheritanceChain[inheritanceChain.length] = typeExtender.Constructor;
            
        // Follow base objects building the inheritance chain
        typeBase = typeExtender.BaseType;
        while(typeBase != null)
        {   
            // Don't ever extend with something the object has already inherited or been extended by
            if(!objectToExtend.GetType().IsSubclassOf(typeBase) &&
               !objectToExtend.IsExtendedBy(typeBase))
            {
                if(!typeBase.IsLoaded())typeBase.Load();     
                inheritanceChain[inheritanceChain.length] = typeBase.Constructor;
            }
            typeBase = typeBase.BaseType;
        }
        
        // Go back through the inheritance chain constructing the class from the base up
        for(var iBaseIndex = inheritanceChain.length - 1; iBaseIndex >= 0; iBaseIndex--)
        {
            // Call each constructor with the arguments on the object
            inheritanceChain[iBaseIndex].apply(objectToExtend, Array.prototype.slice.call( arguments, 1 ));
        }      
    
        // Note extension
        if(!objectToExtend.Extensions)objectToExtend.Extensions = new Array();
        objectToExtend.Extensions[objectToExtend.Extensions.length] = typeExtender;
    
        // Return the constructed object
        return objectToExtend;
    }
    catch(ex)
    {
        throw System.CreateObject("System.Exception", -1, "Unable to apply the extension \"" + typeExtender.Name + "\"", ex);
    }    

}

System.Imports = function(sName, sCodeFile)
{
    var typeNew;

    // Modify code file to include root folder
    sCodeFile = sCodeFile.replace("~", System.Globals.CorePath);
        
    // Check if the type is already known
    if(System._listTypes[sName] == null)
    {    
        // Create a simple type for the import
        typeNew = System.CreateObject("System.Type", sName, sCodeFile);

        // Add the new type to the list
        System._listTypes[sName] = typeNew;
    }
    else
    {
        // Just do nothing
        return;
    }
}

System.PreLoadImports = function()
{
    for(sKey in System._listTypes)
    {
        if(System._listTypes[sKey].Name)
        {
            System._listTypes[sKey].Load();
        }
    }
}

System.RegisterSystemClass = function(sTypeName, ctorType, sBaseTypeName)
{
 
    var typeSystem = new Object();
    
    // Setup type
    typeSystem.Name = sTypeName;
    typeSystem.CodeFile = "";  
    typeSystem.Constructor = ctorType;    
    if(sBaseTypeName && sBaseTypeName != null)  typeSystem.BaseType = System.GetType(sBaseTypeName);    
    
    // Standard functionality
    typeSystem.IsLoaded = function() { return true; }
    typeSystem.Load = function() { return true; }
    typeSystem.IsSubclassOf = function(typeObject) { if(typeObject == sTypeName) return true;else return false; }
    
    // Register type
    System._listTypes[sTypeName] = typeSystem;
    
}

System.RegisterClass = function(sTypeName, ctorType, sBaseTypeName)
{
    try
    {
    
                    
        // Register type if required
        if(System._listTypes[sTypeName] == null)
        {
            System._listTypes[sTypeName] = System.CreateObject("System.Type", sTypeName, "");        
        }
            
        // Set constructor
        System._listTypes[sTypeName].Constructor = ctorType
        
        // Register base type if required
        if(sBaseTypeName)
        {
            
            // Create base type if not found
            if(System._listTypes[sBaseTypeName] == null)
            {
                System._listTypes[sBaseTypeName] = System.CreateObject("System.Type", sBaseTypeName, "");                
            }
            
            // If base type exisits it must have it's code file or it must be loaded
            if((System._listTypes[sBaseTypeName].CodeFile ==  null || 
                System._listTypes[sBaseTypeName].CodeFile.length == 0) &&
               System._listTypes[sBaseTypeName].Constructor == null)
            {
                try
                {
                    System._listTypes[sBaseTypeName].Constructor = eval(sBaseTypeName);
                    if(System._listTypes[sBaseTypeName].Constructor == null) throw -1;
                }
                catch(ex)
                {
                    throw System.CreateObject("System.Exception", -1, "Specified base class \"" + sBaseTypeName + "\" for derived class \"" + sTypeName + "\" has not been registered. If the base class exists in a seperate file use the System.Imports command to include a reference.");    
                }
            }
            
            // Register base constructor
            System._listTypes[sTypeName].BaseType = System._listTypes[sBaseTypeName];

        }
    
    }
    catch(ex)
    {
        throw System.CreateObject("System.Exception", -1, "Unable to register the specified class \"" + sTypeName + "\"", ex);
    }
    
}



// < --------------- OBJECT
System.Object = function()
{

    this.Extensions = new Array();
    
    this.GetType = function()
    {
        return this._type;
    }
    
    this.GetUniqueObjectId = function()
    {
        return this._iObjectId;
    }            
    
    this.IsExtendedBy = function(typeExtension)
    {
   
        for(var iExtension = 0; iExtension < this.Extensions.length; iExtension++)
        {
            if(typeExtension.Name == this.Extensions[iExtension].Name)
            {
                return true;
            }
        }
        return false;    
    }
    
    this.Dispose = function()
    {                        
    
        // Check already disposed
        if(this._isDisposed == true) return;
        
        // remove object reference
        System._listObjects[this._iObjectId] = null;
        this._isDisposing = true;
        
        // attempt to dispose properties
        for(var property in this)
        {
            
            // Ignore dispose
            if(property == "_type" ||
               property == "_isDisposing" ||
               property.indexOf("Dispose") >= 0 ||
               this[property] == null) continue;
        
            // Call property dispose
            if(typeof(this[property]) == "object" &&
               this[property]._isDisposing != true &&
               this[property]._isDisposed != true &&
               typeof(this[property].Dispose) == "function")
            {
                this[property].Dispose();
            }            
               
            // Attempt delete
            delete this[property];
            this[property] = null;
            
        }     
        
        // Set to disposed
        this._isDisposed = true;          
        
    }
    
}

System.RegisterSystemClass("System.Object", System.Object);






//< ------------- TYPE
System.Type = function(sName, sCodeFile)
{    
    this.Name = sName;
    this.CodeFile = sCodeFile;  
    this.Constructor = null;
    this.BaseType = null;
    
    this.IsLoaded = function()
    {
        return (this.Constructor  != null);
    }
    
    this.IsSubclassOf = function(typeObject)
    {
    
         // Convert string to type object
        if(typeof(typeObject) == "string")
        {
            typeObject = System.GetType(typeObject);
        }
        
        // If class names are the same we have a match
        if(this.Name == typeObject.Name)
        {
            return true;
        }
        // If not check the base classes
        else if(this.BaseType != null)
        {
            return this.BaseType.IsSubclassOf(typeObject);   
        }
        // If no base classes then this isn't a sub class
        else
        {
            return false;
        }
    
    }
    
    this.Load = function()
    {
        var oHttpRequest;

        try
        {                
            
            // Check not already loaded
            if(this.IsLoaded()) return;
                    
            try
            {
                // Check if the constructor is already loaded for multiple types in one file
                this.Constructor = eval(this.Name);
                if(this.Constructor  != null) return;
            }
            catch(ex){ }
            
            // Check for code file
            if(this.CodeFile == null || this.CodeFile.length == 0)
            {
                throw System.CreateObject("System.Exception", -1, "Unable to establish the code file containing the type \"" + this.Name + "\"");
            }

            // Send request                
            oHttpRequest = System.CreateXmlHttpRequest();
            oHttpRequest.open("GET", this.CodeFile, false);
            oHttpRequest.send(null);

            // Execute script
            eval(oHttpRequest.responseText);    
            
            // Grab the constructor        
            this.Constructor = eval(this.Name);        
              
        }
        catch(ex)
        {
            // Error loading script
            throw System.CreateObject("System.Exception", -1, "Unable to load the requested code file \"" + this.CodeFile + "\"", ex);
        }
    }


}

System.RegisterSystemClass("System.Type", System.Type, "System.Object");











//< ------------- EXCEPTION
System.Exception = function(iNumber, sMessage, exInner)
{

    this.Number = iNumber;
    this.Message = sMessage;
    this.InnerException = exInner;
    
    this.toString = function()
    {
    
        var sText;
    
        sText = "Number: " + this.Number;
        sText += "\r\nMessage: " + this.Message;
        if(this.InnerException != null) sText += "\r\n\r\n" + this.InnerException.toString();
                  
        return sText;                  
    
    }
   
}

System.RegisterSystemClass("System.Exception", System.Exception, "System.Object");



System.Events.EventData = function()
{

    this.ClientX = 0;
    this.ClientY = 0;
    this.OffsetX = 0;
    this.OffsetY = 0;    
    this.RelatedElement = null;
    this.TargetElement = null;
    this.ReturnValue = true;
    this.OwnerControl = null;

    this.LoadBrowserEvent = function(eventBrowser, ownerControl)
    {

        // Client coords
        this.ClientX = eventBrowser.clientX;
        this.ClientY = eventBrowser.clientY;
        this.KeyCode = eventBrowser.keyCode;
        this.ShiftKey = eventBrowser.shiftKey;
        this.PreventDefault = false;
        
        // Owner Cheiron Control
        this.OwnerControl = ownerControl;
        
        // Target element
        if(eventBrowser.target)
        {
            // Target element
            this.TargetElement = eventBrowser.target;
            
            // Related element
            this.RelatedElement = eventBrowser.relatedElement;
            
            // offset coords
            this.OffsetX = eventBrowser.layerX;
            this.OffsetY = eventBrowser.layerY;
        }
        else
        {
            // Target element
            this.TargetElement = eventBrowser.srcElement;

            // Related element
            this.RelatedElement = eventBrowser.toElement;
            
            // offset coords
            this.OffsetX = eventBrowser.offsetX;
            this.OffsetY = eventBrowser.offsetY;

        }
        
        // Correct offset based on caller
        if(this.OwnerControl && this.OwnerControl.HtmlContainer != this.TargetElement)
        {
            var objectRelative;
            
            objectRelative = this.TargetElement;
            do
            {
                if(objectRelative.style.posLeft)
                {
                    this.OffsetX += objectRelative.style.posLeft;  
                    this.OffsetY += objectRelative.style.posTop;  
                }
                else
                {
                    this.OffsetX += Number(objectRelative.style.left.replace("px", ""));  
                    this.OffsetY += Number(objectRelative.style.top.replace("px", ""));  
                }
                objectRelative = objectRelative.parentNode;
            }
            while(objectRelative != null &&
                  objectRelative != this.OwnerControl.HtmlContainer &&
                  objectRelative.style);
        }
    
    }

}


//< ------------- EVENT
System.Events.Event = function(objectOwner, sName, elementHtml)
{

    this.Owner = objectOwner;
    this.Handlers = new Array();   
    this.HtmlElement = elementHtml;
    this.Name = sName;
     
    this.Attach = function()
    {
    
        try
        {
            // Attach to the html element if available
            if(this.HtmlElement != null && this.Name != null)
            {               
                // Attach
                this.HtmlElement[this.Name.toLowerCase()] = System.CreateDelegate(this, this.BrowserCompatibleInvoke);
            }
        }
        catch(ex)
        {
            throw System.CreateObject("System.Exception", -1, "Unable to attach to the \"" + this.Name + "\" event", ex);
        }    
        
    }
    
    this.BrowserCompatibleInvoke = function(eventData)
    {
        
        var eventCompatible;
        
        // Make cross browser event data
        if(!eventData) eventData = window.event;
        eventCompatible = System.CreateObject("System.Events.EventData");
        eventCompatible.LoadBrowserEvent(eventData, this.Owner); 
        
        // Invoke with compatible event
        this.Invoke(eventCompatible);
        
        // Firefox prevent default call
        if(eventCompatible.PreventDefault == true && eventData.preventDefault)
        {
            eventData.preventDefault();
        }
        
        // Mark result
        eventData.returnValue = eventCompatible.ReturnValue;
        return eventCompatible.ReturnValue;
    }

    this.Invoke = function(eventCompatible)
    {    
        
        var bResult;
        var bIndividualResult;   
        var aEventData;                   

        // Must have an event data object
        if(!eventCompatible) eventCompatible = System.CreateObject("System.Events.EventData");
                       
        // Build arguments
        aEventData = new Array();
        aEventData[0] = eventCompatible;        
        
        // Call each handler pasisng the event details
        bResult = true;
        for(var iHandlerIndex = 0; this.Handlers != null && iHandlerIndex < this.Handlers.length; iHandlerIndex++)
        {
            if(this.Handlers[iHandlerIndex] != null)
            {
                bIndividualResult = this.Handlers[iHandlerIndex].apply(this, aEventData);
                if(bIndividualResult == false || bIndividualResult == true) bResult = bIndividualResult;
            }
        }
        
        // Return event result
        eventCompatible.ReturnValue = bResult;
        return bResult;
    }
           
    this.AddHandler = function(delegateHandler)
    {

        // If this is the first time a handler has been added tie up any DHTML event
        if(this.Handlers.length == 0)
        {
            this.Attach();
        }
        
        // Add the handler       
        this.Handlers[this.Handlers.length] = delegateHandler;
        
    }   

    this.RemoveHandler = function(delegateHandler)
    {
    }   
    
    this.ClearHandlers = function()
    {
        for(var iHandler = 0; iHandler < this.Handlers.length; iHandler++)
        {
            this.Handlers[iHandler] = null;
        }
        this.Handlers = new Array();  
    }
 
}

// Register class with system
System.RegisterSystemClass("System.Events.EventData", System.Events.EventData, "System.Object");
System.RegisterSystemClass("System.Events.Event", System.Events.Event, "System.Object");

// Attach system events
System.OnMouseMove = System.CreateObject("System.Events.Event");
System.OnMouseUp = System.CreateObject("System.Events.Event");
System.OnMouseDown = System.CreateObject("System.Events.Event");
System.OnWindowResize = System.CreateObject("System.Events.Event");
System.OnLoad = System.CreateObject("System.Events.Event");
System.OnKeyDown = System.CreateObject("System.Events.Event");

//< ------------- EXTEND INTRINSIC OBJECTS
Array.prototype.Add = function(itemToAdd)
{
    this.push(itemToAdd);
}

String.prototype.trim = function()
{
	return this.replace(/^\s+|\s+$/g,"");
}

String.prototype.ltrim = function()
{
	return this.replace(/^\s+/,"");
}

String.prototype.rtrim = function()
{
	return this.replace(/\s+$/,"");
}


System._evMouseMove = function(eventData)
{   

   // Check event attach
   if(!eventData) eventData = window.event;
    if(!System.OnMouseMove) return;
       
    // Fire full event if attached
    System.OnMouseMove.Invoke(eventData);

    System.Mouse.X = eventData.clientX;
    System.Mouse.Y = eventData.clientY;

    if(System.Globals.DragObject == null && System.Globals.ResizeObject == null) return;
    if(eventData.preventDefault)
    {
        eventData.preventDefault();
    }
    else
    {
        eventData.returnValue = false;
        return false;
    }
}

System._evWindowResize = function()
{
        
    // Fire full event if attached
    System.OnWindowResize.Invoke(new Object());
}

System._evWindowLoad = function()
{

    // Prevent re-running
    if(System._bLoaded == true) return;
    System._bLoaded = true;

    // Run any defined main 
    if(typeof(window.Main) == "function")
    {
        window.Main();
    }
    
   // Check event attach
    if(!System.OnLoad) return;    
    
    // Fire load events
    System.OnLoad.Invoke(new Object());
}

System._evKeyDown = function(eventData)
{

    if(!eventData)eventData = event;

    // Invoke key down
    System.OnKeyDown.Invoke(eventData.keyCode);

}

System._evMouseDown = function(eventData)
{

    if(!eventData)eventData = event;
    
    System.Mouse.LeftButtonPressed = true;

    // Invoke mouse down
    System.OnMouseDown.Invoke(new Object());

}

System._evMouseUp = function(eventData)
{

    if(!eventData)eventData = event;
    
    System.Mouse.LeftButtonPressed = false;
    
    // Invoke mouse down
    System.OnMouseUp.Invoke(new Object());

}
window.document.onmousemove = System._evMouseMove;
window.document.onmousedown = System._evMouseDown;
window.document.onmouseup = System._evMouseUp;
window.onresize = System._evWindowResize;
window.onload = System._evWindowLoad;
window.document.onkeydown = System._evKeyDown;

// Rectangle class
System.Rectangle = function()
{
    this.Top = 0;
    this.Left = 0;
    this.Bottom = 0;
    this.Right = 0;
    
    this.SetAll= function(iValue)
    {
        this.Top = iValue;
        this.Left = iValue;
        this.Bottom = iValue;
        this.Right = iValue;    
    }
}
// Register class with system
System.RegisterClass("System.Rectangle", System.Rectangle, "System.Object");

//Point class

System.Point = function()
{
    this.X = 0;
    this.Y = 0;
}
// Register class with system
System.RegisterClass("System.Point", System.Point, "System.Object");

// Helper function Messagebox
System.MessageBox = function(sTitle, sText, sIconUrl)
{
    var messageBox;
    
    messageBox = System.CreateObject("System.Dialogs.MessageBox");
    messageBox.Initialize();
    messageBox.Show(sTitle, sText, sIconUrl);
    return messageBox;
}

// Helper function Confirm Box
System.ConfirmBox = function(sTitle, sText, sIconUrl, delegateYes, delegateNo)
{
    var confirmBox;
    
    confirmBox = System.CreateObject("System.Dialogs.ConfirmBox");
    confirmBox.Initialize();
    confirmBox.Show(sTitle, sText, sIconUrl);
    if(delegateYes) confirmBox.OnYes.AddHandler(delegateYes);
    if(delegateNo) confirmBox.OnNo.AddHandler(delegateNo);
    return confirmBox;
}

// Helper function Input Box
System.InputBox = function(sTitle, sPrompt, sText, sIconUrl, delegateOK, delegateCancel)
{
    var inputBox;
    
    inputBox = System.CreateObject("System.Dialogs.InputBox");
    inputBox.Initialize();
    inputBox.Show(sTitle, sPrompt, sText, sIconUrl);
    if(delegateOK) inputBox.OnOK.AddHandler(delegateOK);
    if(delegateCancel) inputBox.OnCancel.AddHandler(delegateCancel);
    return inputBox;
}

// Helper function Pick Box
System.PickBox = function(sTitle, sPrompt, sIconUrl, delegateOK, delegateCancel)
{
    var pickBox;
    
    pickBox = System.CreateObject("System.Dialogs.PickBox");
    pickBox.Initialize();
    pickBox.Show(sTitle, sPrompt, sIconUrl);
    if(delegateOK) pickBox.OnOK.AddHandler(delegateOK);
    if(delegateCancel) pickBox.OnCancel.AddHandler(delegateCancel);
    return pickBox;
}

// Mozilla compatibility layer
if(typeof HTMLElement != "undefined")
{
    window.eval("HTMLElement.prototype.innerText getter = function(){var tmp = this.innerHTML.replace(/<br>/gi,\"\\n\");return tmp.replace(/<[^>]+>/g,\"\");}");
    window.eval("HTMLElement.prototype.innerText setter = function(txtStr){var parsedText = document.createTextNode(txtStr);this.innerHTML = '';this.appendChild( parsedText );}");
    window.eval("function selectNodes(doc,path,contextNode){contextNode =contextNode ?contextNode :doc;var xpath =new XPathEvaluator();var result =xpath.evaluate(path,contextNode,doc.createNSResolver(doc.documentElement),XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);var nodeList =new Array(result.snapshotLength);for(var i =0;i <result.snapshotLength;i++){nodeList[i]=result.snapshotItem(i);}return nodeList;}\nXMLDocument.prototype.selectNodes =function(path,contextNode){return selectNodes(this,path,contextNode);};");
    window.eval("function selectSingleNode(doc,path,contextNode){path +='[1]';var nodes =selectNodes(doc,path,contextNode);if (nodes.length !=0){for (var i =0;i <nodes.length;i++){if (nodes[i]){return nodes[i];}}}return null;}\nXMLDocument.prototype.selectSingleNode =function(path,contextNode){return selectSingleNode(this,path,contextNode);}");
    window.eval("Document.prototype.loadXML = function(strXML){var objDOMParser = new DOMParser();var objDoc = objDOMParser.parseFromString(strXML, \"text/xml\");while (this.hasChildNodes())this.removeChild(this.lastChild);for (var i=0; i < objDoc.childNodes.length; i++){var objImportedNode = this.importNode(objDoc.childNodes[i], true);this.appendChild(objImportedNode);}}");    
    window.eval("Node.prototype.xml getter = function () {var objXMLSerializer = new XMLSerializer;var strXML = objXMLSerializer.serializeToString(this);return strXML;}");
    window.eval("Node.prototype.text getter = function () {return this.textContent;}");
    window.eval("Node.prototype.text setter = function (sText) {this.textContent = sText;}");    
}
