﻿// DATA ==========================================================================================================================
/**************************************************
*  Company: IFP 
*  Name   : IFP Dicionary Class
*  Version: 1.0.0.0000
*  Created: 07/08/2008
*  Updated: 07/16/2008
*  Author : Max Bitran
***************************************************/
function IFPDictionary()
{
    this.Length = 0;
    this.Add = mAdd;
    this.Delete = mDelete;
    this.ToKeys = mToKeys;
    this.Copy = mCopy;
    
    this.OnAdd = "";
    
    var array1 = new Array();
    var array2 = new Array();
    
    function mAdd()
    {                
        for (i=0; i < mAdd.arguments.length; i+=2) 
        {
            this[mAdd.arguments[i]] = mAdd.arguments[i+1]; this.Length++; 
            array1[this.Length-1] = mAdd.arguments[i];
            array2[this.Length-1] = mAdd.arguments[i+1];
        }
        if (this.OnAdd != "")
        { this.OnAdd(mAdd.arguments[0]); }        
    };                      
    function mDelete(key)
    { 
        return mToKeys();
        for (i=0; i < mDelete.arguments.length; i++) 
        { this[mDelete.arguments[i]] = null; this.Length--; }
    };                      
    function mToKeys()
    {  return array1; };
    function mCopy()
    {
        var newObject = new IFPDictionary();
        var i, b; b = this.ToKeys();
        for (i in b)
        { newObject.Add(b[i]); }
        return newObject;
    };      
    function mContains(key)
    { }      
};
//--------------------------------------------------------------------------------------------------------------------------------
/**************************************************
*  Company: IFP 
*  Name   : IFP Data Table Class
*  Version: 1.0.0.0000
*  Created: 07/15/2008
*  Updated: 07/16/2008
*  Author : Max Bitran
***************************************************/
function IFPDataTable(name)
{
    // Public Properties and internal fields
    this.Rows = new Array();  var rows = this.Rows;
    this.Columns = new IFPDictionary(); var columns = this.Columns;
    this.PrimaryKeys = new Array(); var primaryKeys = this.PrimaryKeys;
    
    // Public Methods - Declaration
    this.AddRow = mAddRow;     
    this.SetRow = mSetRow;       
    this.DeleteRow = mDeleteRow;            
    
    // Public Events
    this.OnAddRow = "";
    this.OnDeleteRow = "";
    this.OnRowContentChanged = "";     
    this.OnCellContentChanged = "";     
    
    { // Constructor
        this.Name = name;
        this.Columns.OnAdd = mOnColumnAdd; 
    }
    
    // Public Methods - Implementation
    function mAddRow(params)
    {        
        if (this.Columns.Length == mAddRow.arguments.length)
        { 
            this.Rows[this.Rows.length] = this.Columns.Copy(); 
            var i = 0; var b = this.Columns.ToKeys();
            for (i in b)
            {  this.Rows[this.Rows.length-1][b[i]] = mAddRow.arguments[i]; }
            
            if (this.OnAddRow != "")
            { this.OnAddRow(); }
        }
    }; 
    function mSetRow(params)
    {        
        var rowIndex = -1;
        if (this.Columns.Length == mSetRow.arguments.length)
        { 
            var i = 0; var b = this.Columns.ToKeys();
            for (j in this.Rows)
            {
                if (this.Rows[j][this.PrimaryKeys[0]] == mSetRow.arguments[0])
                {
                    rowIndex = j;
                    for (i in b)
                    { this.Rows[rowIndex][b[i]] = mSetRow.arguments[i]; }
                }                     
            }
            
            if (this.OnRowContentChanged != "")
            { this.OnRowContentChanged(this.Rows[rowIndex], rowIndex); }        
        }
    };
    function mSetCell(params)
    {        
        if (this.Columns.Length == mSetRow.arguments.length)
        { 
            var i = 0; var b = this.Columns.ToKeys();
            for (i in b)
            {  this.Rows[this.Rows.length-1][b[i]] = mSetRow.arguments[i]; }
            
            if (this.OnCellContentChanged != "")
            { this.OnCellContentChanged(cell); }        
        }
    };
    function mDeleteRow(rowIndex)
    { 
        this.Rows.splice(rowIndex, 1); 
        if (this.OnDeleteRow != "")
        { this.OnDeleteRow(rowIndex); }
    }; 
    
    // Internal Event Handlers
    function mOnColumnAdd(columnName)
    { 
        if (columns.Length == 1)
        { primaryKeys[0] = columnName; }    
    }; 
    
    // Private Methods
};
// END DATA ======================================================================================================================

// AJAX ==========================================================================================================================
function IFPXmlHTPPRequestManager(login)
{     
    this.Url = "";
    this.Headers = new IFPDictionary();
                                         
    this.Send = mSend;
    this.Run = mRun;
    
    var method = "GET";                                   
    var id = "";
    var index = "";
    var headers;
    var onResponseReceived;
     
    this.OnResponseReceived = "";
    
    function mRun()
    {
        onResponseReceived = this.OnResponseReceived;
        if (login != undefined)
        { login.Url = this.Url; }
        this.Send();
    }
               
    function mSend()
    { 
        var request;
        request = mSelectBrowser(); 
        if (login != undefined)
        { 
            request.RequestObject.open(method, login.Url, true); 
            request.RequestObject.onreadystatechange = CheckResponseStateLogin;
            headers = login.Headers;
        }
        else
        { 
            request.RequestObject.open(method, this.Url, true); 
            request.RequestObject.onreadystatechange = CheckResponseState;
            var params = this.Headers['Params'];
            this.Headers = headers;
            this.Headers['Params'] = params;
        }   
       
        mLoadHeaders(request);            
        
        if (request.Browser == "IE")
        { request.RequestObject.Send(null); }
        else
        { request.RequestObject.send(null); }
        login = undefined;
    }    
    
    function mSelectBrowser()
    {
        request = new Request();
        if (window.XMLHttpRequest) 
        {
            if (navigator.appVersion.indexOf("MSIE 7") != -1) // IE6, 5, 4 ... 
            { 
                request.Browser = "IE"; 
                request.RequestObject = new ActiveXObject("Microsoft.XMLHTTP"); 
            } 
            else // IE7, Firefox, Safari, etc 
            {
                request.Browser = "!IE"; 
                request.RequestObject = new XMLHttpRequest();
            }
        }
        else if (window.ActiveXObject) // IE6, 5, 4 ... 
        { 
            request.Browser = "IE"; 
            try 
            { request.RequestObject = new ActiveXObject("Msxml2.XMLHTTP"); }    
            catch (e)
            { request.RequestObject = new ActiveXObject("Microsoft.XMLHTTP"); }                
        }     
        return request;                 
    }
    
    function mLoadHeaders(request)
    {
        var i, b, dic;
        if (login != undefined)
        { b = login.Headers.ToKeys(); dic = login.Headers; }
        else
        { b = headers.ToKeys(); dic = headers; }
        
        for (i in b) 
        {	
            try
            {   
                if (b[i] == 'Id')
                { headers[b[i]] = id; } 
                if (b[i] == 'Index')
                { headers[b[i]] = index; } 
                request.RequestObject.setRequestHeader(b[i], headers[b[i]]); 
            }	           
            catch(ex)
            { }
        }	
    }
    // Event handlers
    function CheckResponseStateLogin()
    {
        if (request.RequestObject.readyState == 4)
        {
            if (request.RequestObject.status == 200)
            {
                id = request.RequestObject.getResponseHeader('Id');
                index = request.RequestObject.getResponseHeader('Index')
            }       
        }
    }
    function CheckResponseState()
    {
        if (request.RequestObject.readyState == 4)
        {
            if (request.RequestObject.status == 200)
            { 
                if (request.RequestObject.responseText != "" && request.RequestObject.responseText != -1)
                {
                    var result = request.RequestObject.responseText;
                    if (onResponseReceived != "")
                    { onResponseReceived(result); }
                    //WriteLog('timer', time.substr(time.lastIndexOf(",")+1)); 
                }
            }
        }
    }
}
// Request
function Request()
{
    this.RequestObject = null;
    this.Browser = "!IE";
}
// END AJAX ======================================================================================================================

// GUI ===========================================================================================================================
/**************************************************
*  Company: IFP 
*  Name   : IFP HTML Table Class
*  Version: 1.0.0.0000
*  Created: 07/15/2008
*  Updated: 07/17/2008
*  Author : Max Bitran
***************************************************/
function IFPHTMLTable(dataSource)
{
    // Public Properties and internal fields
    this.Rows = 0; var rows = this.Rows;
    this.Columns = 0; var columns = this.Columns;
    this.Style = new IFPHTMLTableStyles(); var style = this.Style;
    
    // Public Methods - Declaration
    this.Show = mShow;
    this.LoadCssFromFile = mLoadCssFromFile;
    this.SetRowStyle =mSetRowStyle;
    
    // Public Events
    this.OnTableContentChange = "";
    
    { // Constructor
        this.DataSource = dataSource; var ds = this.DataSource;
        this.DataSource.OnAddRow = mOnDataSourceEventAddRow;
        this.DataSource.OnRowContentChanged = mOnDataSourceEventRowChanged;
        this.DataSource.OnCellContentChanged = mOnDataSourceEventCellChanged;
    }
        
    // Public Methods - Implementation
    function mShow()
    {
        TopHeader();
        
        if (this.DataSource != "")
        {
            TopHeader();
        
            var row, cell, innerText;
            this.Rows = dataSource.Rows.length;
            this.Columns = dataSource.Columns.Length;

            var docTable     = document.createElement("table");
            var docTablebody = document.createElement("tbody");
            
            docTable.id = dataSource.Name;

            docTablebody.appendChild(LoadHeader());
            
            for(var j = 0; j < this.Rows; j++) 
            {
                row = document.createElement("tr");
                for(var i = 0; i < this.Columns; i++) 
                {
                    cell = document.createElement("td");  
                    cell.ondblclick = function() 
                                        {
                                            if ( mOnTableContentCellClick != "")
                                            { mOnTableContentCellClick(); }
                                        };     
                    var innerContent;                                        
                    if(dataSource.Columns.ToKeys()[i] == "[p]")
                    { 
                    	innerContent = document.createElement('img')
                      	innerContent.id = "[p]" + j;
                		innerContent.setAttribute("src", "./Images/NoArrow.gif");
                        innerContent.setAttribute("alt", "Arrows");
                    }
                    else
                    { innerContent = document.createTextNode(dataSource.Rows[j][dataSource.Columns.ToKeys()[i]]); }
                    
                    var headerFont = document.createElement("font");
                    headerFont.setAttribute('face', 'Lucida Sans Unicode');
            
                    headerFont.appendChild(innerContent);           

                    cell.appendChild(headerFont);
                    row.appendChild(cell);                   
                    cell.id = dataSource.Columns.ToKeys()[i];   
                    
                    // Cell Style ----------------------------------------------------
                                  
                    if (i == 0)
                    { cell.style.textAlign = 'left'; }
                    else
                    { cell.style.textAlign = 'right'; }                                                           
                    
                    if (dataSource.Columns.ToKeys()[i] != dataSource.PrimaryKeys[0])
                    {
                        if (j%2 != 0)
                        { cell.style.color = '#DCDCDC'; }
                        else
                        { cell.style.color = '#FFFFFF'; }                                                   
                    } 
                    
                    cell.style.height = '15';         		
                    // ----------------------------------------------------------------                    
                }
                docTablebody.appendChild(row);
                row.id = dataSource.Columns.ToKeys()[i];   
                
                // Row Style ----------------------------------------------------
                row.style.textAlign = 'left';
                row.style.fontWeight = 'normal';
                //row.style.setAttribute('font', 'Verdana');
                if (j%2 != 0)
                { row.style.backgroundColor = '#DCDCDC'; } 
                else
                { row.style.backgroundColor = '#FFFFFF'; } 
                row.style.color = '#0C1C4D';           		
                // --------------------------------------------------------------                        
            }
        }
        docTable.appendChild(docTablebody);
        document.body.appendChild(docTable);
        
        // Table Style  ----------------------------------------------------
        docTable.setAttribute("cellSpacing", "0");
        docTable.setAttribute("width", "200");
        
        docTable.style.paddingTop = '0';
        docTable.style.paddingBottom = '0';
        docTable.style.paddingLeft = '6';
        docTable.style.paddingRight = '6';
        docTable.style.fontSize = '9pt';
        docTable.style.position = 'absolute';
        docTable.style.top = '0px';
        docTable.style.left = '0px';        
        //  ----------------------------------------------------------------
        
        disableSelection(document.body);
    };
    function mSetRowStyle()
    {
        var row = mSetRowStyle.arguments[0]*1;
        var style = mSetRowStyle.arguments[1];
    
        var color = '';
        var arrow = '';
            
        if (style.Color == "Red")
        { color = '#CC0000'; arrow = "ArrowDown"; }
        else if (style.Color == "Black")
        { color = '#000000'; arrow = "NoArrow"; }
        else if (style.Color == "Green")
        { color = '#009900'; arrow = "ArrowUp"; }
        
        try
        {        
            document.getElementById(ds.Name).rows[row+1].cells[1].style.color = color;
            document.getElementById("[p]"+row).src = "./Images/" + arrow + ".gif";
            document.getElementById(ds.Name).rows[row+1].cells[3].style.color = color;
            document.getElementById(ds.Name).rows[row+1].cells[4].style.color = '#000000';
        }
        catch(ex)
        { }
    };
    function mLoadCssFromFile(file)
    {
        //alert("Not implemented exception"); 
    };
       
    // Internal Event Handlers 
    function mOnDataSourceEventRowChanged()
    {
        if (mOnDataSourceEventRowChanged.arguments.length != 0)
        {   
            var row = mOnDataSourceEventRowChanged.arguments[0];        
            var rowIndex = mOnDataSourceEventRowChanged.arguments[1]*1;
            rowIndex++;
            
            var b = mOnDataSourceEventRowChanged.arguments[0].ToKeys();
            for (i=0;i<dataSource.Columns.Length;i++)
            { 
                if (b[i].indexOf("[p]") == -1)
                { document.getElementById(dataSource.Name).rows[rowIndex*1].cells[i].childNodes[0].innerHTML = row[b[i]]; } 
            }
        }
    };
    
    function mOnTableContentCellClick()
    {
        //alert("Row added on the Data Source " + dataSource.Name); 
    };
    function mOnDataSourceEventCellChanged()
    {
        //alert("Row added on the Data Source " + dataSource.Name); 
    };
    function mOnDataSourceEventAddRow()
    {
        //alert("Row added on the Data Source " + dataSource.Name); 
    };
    
    // Private Methods
    function LoadHeader()
    { 
        var cols = dataSource.Columns.Length;
        var headerRow = document.createElement("tr");
        var headerCell, headerCellText;
        for(var i = 0; i < cols; i++) 
        { 
            headerCell = document.createElement("td");
            headerCellText = document.createTextNode(dataSource.Columns.ToKeys()[i]); 
            
            var headerFont = document.createElement("font");
            headerFont.setAttribute('face', 'Lucida Sans Unicode');
            
            headerFont.appendChild(headerCellText);           

            headerCell.appendChild(headerFont);            
            
            headerRow.appendChild(headerCell);
            
            // Cell Style ----------------------------------------------------------------
            if(headerCellText.data =="[p]")
            { headerCell.style.color = '#DCDCDC'; }
            if (i!=0)
            { headerCell.style.textAlign = 'center'; }
            // ---------------------------------------------------------------------------
        }
        
        // Row Style ----------------------------------------------------------------       
        headerRow.style.fontWeight = 'normal';
        // headerRow.style.fontFamily = 'Verdana';
        headerRow.style.backgroundColor = '#DCDCDC'; 
        headerRow.style.color = '#0C1C4D';           		
        // ---------------------------------------------------------------------------
        return headerRow;
    }    
    function TopHeader()    
    {   
        var docTable     = document.createElement("table");
        var docTablebody = document.createElement("tbody");
        
        docTable.id = "CrossRatesHeader";
           
        var row = document.createElement("tr");
        var cell1 = document.createElement("td");
        var cell2 = document.createElement("td");
                            
        innerText = document.createTextNode("Currency Rates");
        
        var headerFont = document.createElement("font");
        headerFont.setAttribute('face', 'Lucida Sans');
        headerFont.setAttribute('size', '2');    
            
        headerFont.appendChild(innerText);           

        cell1.appendChild(headerFont);
        
   		var fileref = document.createElement('img')
 		fileref.setAttribute("src", "./Images/Powered.gif");
        fileref.setAttribute("alt", "Powered By");
        fileref.setAttribute("align", "center");
        cell1.appendChild(fileref);
        
        row.appendChild(cell1);
        row.appendChild(cell2);
        
        docTablebody.appendChild(row);
        
        docTable.appendChild(docTablebody);
        document.body.appendChild(docTable);

        // Table Style  ----------------------------------------------------
        docTable.setAttribute("cellSpacing", "0");
        docTable.setAttribute("border", "0");
        
        docTable.style.paddingTop = '0';
        docTable.style.paddingBottom = '0';
        docTable.style.paddingLeft = '6';
        docTable.style.paddingRight = '6';
        docTable.style.fontSize = '9pt';
        docTable.style.width = '200';
        docTable.style.position = 'absolute';
        docTable.style.top = '0px';
        docTable.style.left = '0px'; 
        // -----------------------------------------------------------------
    };
};       
//--------------------------------------------------------------------------------------------------------------------------------
/**************************************************
*  Company: IFP 
*  Name   : IFP HTML Table Cell Class
*  Version: 1.0.0.0000
*  Created: 07/16/2008
*  Updated: 07/16/2008
*  Author : Max Bitran
***************************************************/
function IFPHTMLTableCell(rowNumber, columnName)
{
    this.RowNumber = rowNumber;
    this.columnName = columnName; 
};
//--------------------------------------------------------------------------------------------------------------------------------
/**************************************************
*  Company: IFP 
*  Name   : IFP HTML Table Styles Class
*  Version: 1.0.0.0000
*  Created: 07/16/2008
*  Updated: 07/16/2008
*  Author : Max Bitran
***************************************************/
function IFPHTMLTableStyles()
{
    this.TableStyle = new HTMLStyle();
    this.TableBodyStyle = new HTMLStyle();
    this.TableRowStyle = new HTMLStyle();
    this.TableHeaderRowStyle = new HTMLStyle();
    this.TableCellStyle = new HTMLStyle();        
}
//--------------------------------------------------------------------------------------------------------------------------------
/**************************************************
*  Company: IFP 
*  Name   : IFP HTML Style Class
*  Version: 1.0.0.0000
*  Created: 07/16/2008
*  Updated: 07/16/2008
*  Author : Max Bitran
***************************************************/
function HTMLStyle()
{
    this.Color = "White";
}
//--------------------------------------------------------------------------------------------------------------------------------
/**************************************************
*  Company: IFP 
*  Name   : IFP 
*  Version: 1.0.0.0000
*  Created: 
*  Updated: 
*  Author : Max Bitran
***************************************************/
function GraphicObject()
{
    this.Items = new IFPDictionary();

    this.Render = mRender;
    
    var itemCounter = 0;    

    function mRender()
    {
    };
};
//--------------------------------------------------------------------------------------------------------------------------------
Form.prototype = new GraphicObject();
function Form()
{    
    var properties = "<v:rect style='width:100pt;height:75pt' fillcolor=\"#FFFCDF\" strokecolor=\"#000000\" strokeweight=\"1pt\"/>"   
    document.body.innerHTML = properties;    
};
// END GUI =======================================================================================================================

// UTILS =========================================================================================================================
function Using(file)
{
	if (file.indexOf(".js")!=-1)
	{
		fileref = document.createElement('script')
		fileref.setAttribute("type","text/javascript");
		fileref.setAttribute("src", file);
	}
	else if (file.indexOf(".css")!=-1)
	{
		fileref = document.createElement("link")
		fileref.setAttribute("rel", "stylesheet");
		fileref.setAttribute("type", "text/css");
		fileref.setAttribute("href", file);
	}
	document.getElementsByTagName("head").item(0).appendChild(fileref)
}
//--------------------------------------------------------------------------------------------------------------------------------
function Sleep(milliseconds) 
{
    var date = new Date();
    var curDate = null;

    do 
    { curDate = new Date(); } 
    while(curDate-date < milliseconds);
} 
//--------------------------------------------------------------------------------------------------------------------------------
function WriteLog(place, text)
{
    if (place*1 == 0)
    { document.write(text);} 
    else if (place*1 == 1)
    { status = text;} 
    else             
    { document.getElementById(place).innerHTML = text; }
}    
// END UTILS =====================================================================================================================













// TO FIX
/**************************************************
*  Company: IFP 
*  Name   : IFP Data Table Class
*  Version: 1.0.0.0000
*  Created: 07/15/2008
*  Updated: 07/16/2008
*  Author : Max Bitran
***************************************************/
function IFPDataTable_Modified(name)
{
    // Public Properties and internal fields
    this.Rows = new Array();  var rows = this.Rows;
    this.Columns = new IFPDictionary(); var columns = this.Columns;
    this.PrimaryKeys = new Array(); var primaryKeys = this.PrimaryKeys;
    
    // Public Methods - Declaration
    this.AddRow = mAddRow;     
    this.SetRow = mSetRow;       
    this.DeleteRow = mDeleteRow;            
    
    // Public Events
    this.OnAddRow = "";
    this.OnDeleteRow = "";
    this.OnRowContentChanged = "";     
    this.OnCellContentChanged = "";     
    
    { // Constructor
        this.Name = name;
        this.Columns.OnAdd = mOnColumnAdd; 
    }
    
    // Public Methods - Implementation
    function mAddRow(params)
    {        
        if (this.Columns.Length == mAddRow.arguments.length)
        { 
            this.Rows[this.Rows.length] = this.Columns.Copy(); 
            var i = 0; var b = this.Columns.ToKeys();
            for (i in b)
            {  this.Rows[this.Rows.length-1][b[i]] = mAddRow.arguments[i]; }
            
            if (this.OnAddRow != "")
            { this.OnAddRow(); }
        }
    }; 
    function mSetRow(params)
    {        
        var rowIndex = -1;
        if (this.Columns.Length == mSetRow.arguments.length)
        { 
            var i = 0; var b = this.Columns.ToKeys();
            for (j in this.Rows)
            {
                if (this.Rows[j][this.PrimaryKeys[0]] == mSetRow.arguments[0])
                {
                    rowIndex = j;
                    for (i in b)
                    { this.Rows[rowIndex][b[i]] = mSetRow.arguments[i]; }
                }                     
            }
            
            if (this.OnRowContentChanged != "")
            { this.OnRowContentChanged(this.Rows[rowIndex], rowIndex); }        
        }
    };
    function mSetCell(params)
    {        
        if (this.Columns.Length == mSetRow.arguments.length)
        { 
            var i = 0; var b = this.Columns.ToKeys();
            for (i in b)
            {  this.Rows[this.Rows.length-1][b[i]] = mSetRow.arguments[i]; }
            
            if (this.OnCellContentChanged != "")
            { this.OnCellContentChanged(cell); }        
        }
    };
    function mDeleteRow(rowIndex)
    { 
        this.Rows.splice(rowIndex, 1); 
        if (this.OnDeleteRow != "")
        { this.OnDeleteRow(rowIndex); }
    }; 
    
    // Internal Event Handlers
    function mOnColumnAdd(columnName)
    { 
        if (columns.Length == 1)
        { primaryKeys[0] = columnName; }    
    }; 
    
    // Private Methods
};

//================================================================================================================================

/**************************************************
*  Company: IFP 
*  Name   : IFP HTML Table Class
*  Version: 1.0.0.0000
*  Created: 07/15/2008
*  Updated: 07/20/2008
*  Author : Max Bitran
***************************************************/
function IFPHTMLTable_Modified(dataSource)
{
    // Public Properties and internal fields
    this.Rows = 0; var rows = this.Rows;
    this.Columns = 0; var columns = this.Columns;
    this.Style = new IFPHTMLTableStyles(); var style = this.Style;
    
    // Public Methods - Declaration
    this.Show = mShow;
    this.LoadCssFromFile = mLoadCssFromFile;
    this.SetRowStyle =mSetRowStyle;
    
    // Public Events
    this.OnTableContentChange = "";
    
    { // Constructor
        this.DataSource = dataSource; var ds = this.DataSource;
        this.DataSource.OnAddRow = mOnDataSourceEventAddRow;
        this.DataSource.OnRowContentChanged = mOnDataSourceEventRowChanged;
        this.DataSource.OnCellContentChanged = mOnDataSourceEventCellChanged;
    }
        
    // Public Methods - Implementation
    function mShow()
    {
        if (this.DataSource != "")
        {
            //TopHeader();
        
            var row, cell, innerText;
            this.Rows = dataSource.Rows.length;
            this.Columns = dataSource.Columns.Length;

            var docTable     = document.createElement("table");
            var docTablebody = document.createElement("tbody");
            
            docTable.id = dataSource.Name;

            //docTablebody.appendChild(LoadHeader());
            
            for(var j = 0; j < this.Rows; j++) 
            {
                row = document.createElement("tr");
                for(var i = 0; i < this.Columns; i++) 
                {
                    cell = document.createElement("td");  
                    cell.ondblclick = function() 
                                        {
                                            if ( mOnTableContentCellClick != "")
                                            { mOnTableContentCellClick(); }
                                        };     
                    var innerContent;                                        
                    if(dataSource.Columns.ToKeys()[i] == "[p]")
                    { 
                    	innerContent = document.createElement('img')
                      	innerContent.id = "[p]" + j;
                		innerContent.setAttribute("src", dataSource.Rows[j]["[p]"]);
                        innerContent.setAttribute("alt", "Graphics");
                    }
                    else
                    { innerContent = document.createTextNode(dataSource.Rows[j][dataSource.Columns.ToKeys()[i]]); }
                    
                    var headerFont = document.createElement("font");
                    headerFont.setAttribute('face', 'Lucida Sans Unicode');
            
                    headerFont.appendChild(innerContent);           

                    cell.appendChild(headerFont);
                    row.appendChild(cell);                   
                    cell.id = dataSource.Columns.ToKeys()[i];   
                    
                    // Cell Style ----------------------------------------------------
                    cell.style.textAlign = 'left'; 
                    if (dataSource.Columns.ToKeys()[i] != dataSource.PrimaryKeys[0])
                    {
                        if (j%2 != 0)
                        { cell.style.color = '#DCDCDC'; }
                        else
                        { cell.style.color = '#FFFFFF'; }                                                   
                    } 
                    
                    cell.style.height = '15';         		
                    // ----------------------------------------------------------------                    
                }
                docTablebody.appendChild(row);
                row.id = dataSource.Columns.ToKeys()[i];   
                
                // Row Style ----------------------------------------------------
                row.style.textAlign = 'left';
                row.style.fontWeight = 'normal';
                //row.style.setAttribute('font', 'Verdana');
                if (j%2 != 0)
                { row.style.backgroundColor = '#DCDCDC'; } 
                else
                { row.style.backgroundColor = '#FFFFFF'; } 
                row.style.color = '#0C1C4D';           		
                // --------------------------------------------------------------                        
            }
            docTable.appendChild(docTablebody);
            document.body.appendChild(docTable);
            
            // Table Style  ----------------------------------------------------
            docTable.setAttribute("cellSpacing", "0");
            docTable.setAttribute("width", "100");
            
            docTable.style.paddingTop = '0';
            docTable.style.paddingBottom = '0';
            docTable.style.paddingLeft = '6';
            docTable.style.paddingRight = '6';
            docTable.style.fontSize = '9pt';
            docTable.style.position = 'absolute';
            docTable.style.top = '0px';
            docTable.style.left = '0px';        
            //  ----------------------------------------------------------------
        }
        else
        { 
        }
    };
    
    function mSetRowStyle()
    {
        var row = mSetRowStyle.arguments[0]*1;
        var style = mSetRowStyle.arguments[1];
    
        var color = '';
        var arrow = '';
            
        if (style.Color == "Red")
        { color = '#CC0000'; arrow = "ArrowDown"; }
        else if (style.Color == "Black")
        { color = '#000000'; arrow = "NoArrow"; }
        else if (style.Color == "Green")
        { color = '#009900'; arrow = "ArrowUp"; }
        
        try
        {        
            document.getElementById(ds.Name).rows[row+1].cells[1].style.color = color;
            document.getElementById("[p]"+row).src = "./Images/" + arrow + ".gif";
            document.getElementById(ds.Name).rows[row+1].cells[3].style.color = color;
            document.getElementById(ds.Name).rows[row+1].cells[4].style.color = '#000000';
        }
        catch(ex)
        { }
    };
    function mLoadCssFromFile(file)
    { 
        //alert("Not implemented exception"); 
    };
       
    // Internal Event Handlers 
    function mOnDataSourceEventRowChanged()
    {
        if (mOnDataSourceEventRowChanged.arguments.length != 0)
        {   
            var row = mOnDataSourceEventRowChanged.arguments[0];        
            var rowIndex = mOnDataSourceEventRowChanged.arguments[1]*1;
            rowIndex++;
            
            var b = mOnDataSourceEventRowChanged.arguments[0].ToKeys();
            for (i=0;i<dataSource.Columns.Length;i++)
            { 
                if (b[i].indexOf("[p]") == -1)
                { document.getElementById(dataSource.Name).rows[rowIndex*1].cells[i].childNodes[0].innerHTML = row[b[i]]; } 
                else
                { document.getElementById(dataSource.Name).rows[rowIndex*1].cells[i].childNodes[0].setAttribute("src", row[b[i]]); }
            }
        }
    };

    function mOnTableContentCellClick()
    {
        //alert("Row added on the Data Source " + dataSource.Name); 
    };
    function mOnDataSourceEventCellChanged()
    {
        //alert("Row added on the Data Source " + dataSource.Name); 
    };
    function mOnDataSourceEventAddRow()
    {
        //alert("Row added on the Data Source " + dataSource.Name); 
    };
    
    // Private Methods
    function LoadHeader()
    { 
        var cols = dataSource.Columns.Length;
        var headerRow = document.createElement("tr");
        var headerCell, headerCellText;
        for(var i = 0; i < cols; i++) 
        { 
            headerCell = document.createElement("td");
            headerCellText = document.createTextNode(dataSource.Columns.ToKeys()[i]); 
            
            var headerFont = document.createElement("font");
            headerFont.setAttribute('face', 'Lucida Sans Unicode');
            
            headerFont.appendChild(headerCellText);           

            headerCell.appendChild(headerFont);            
            
            headerRow.appendChild(headerCell);
            
            // Cell Style ----------------------------------------------------------------
            if(headerCellText.data =="[p]")
            { headerCell.style.color = '#DCDCDC'; }
            // ---------------------------------------------------------------------------
        }
        
        // Row Style ----------------------------------------------------------------
        headerRow.Align = 'left'; 
        headerRow.style.fontWeight = 'normal';
        // headerRow.style.fontFamily = 'Verdana';
        headerRow.style.backgroundColor = '#DCDCDC'; 
        headerRow.style.color = '#0C1C4D';           		
        // ---------------------------------------------------------------------------
        return headerRow;
    }    
    function TopHeader()    
    {   
        var docTable     = document.createElement("table");
        var docTablebody = document.createElement("tbody");
        
        docTable.id = "CrossRatesHeader";
           
        var row = document.createElement("tr");
        var cell1 = document.createElement("td");
        var cell2 = document.createElement("td");
                            
        innerText = document.createTextNode("Currency Rates");
        
        var headerFont = document.createElement("font");
        headerFont.setAttribute('face', 'Lucida Sans');
        headerFont.setAttribute('size', '2');    
            
        headerFont.appendChild(innerText);           

        cell1.appendChild(headerFont);
        
//   	   var fileref = document.createElement('img')
// 		   fileref.setAttribute("src", "./Images/Powered.gif");
//         fileref.setAttribute("alt", "Powered By");
//         fileref.setAttribute("align", "center");
//         cell1.appendChild(fileref);
        
        row.appendChild(cell1);
        row.appendChild(cell2);
        
        docTablebody.appendChild(row);
        
        docTable.appendChild(docTablebody);
        document.body.appendChild(docTable);

        // Table Style  ----------------------------------------------------
        docTable.setAttribute("cellSpacing", "0");
        docTable.setAttribute("border", "0");
        
        docTable.style.paddingTop = '0';
        docTable.style.paddingBottom = '0';
        docTable.style.paddingLeft = '6';
        docTable.style.paddingRight = '6';
        docTable.style.fontSize = '9pt';
        docTable.style.width = '200';
        docTable.style.position = 'absolute';
        docTable.style.top = '0px';
        docTable.style.left = '0px'; 
        // -----------------------------------------------------------------
    };
};       


function disableSelection(target)
{
    if (typeof target.onselectstart!="undefined") //IE route
	{ target.onselectstart=function(){return false}; }
    else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
	{ target.style.MozUserSelect="none"; }
    else //All other route (ie: Opera)
	{ target.onmousedown=function(){return false}; }
    target.style.cursor = "default"
}

//Sample usages
//disableSelection(document.body) //Disable text selection on entire body
//disableSelection(document.getElementById("mydiv")) //Disable text selection on element with id="mydiv"

