﻿
// --------------------------------------------------------------------
// CustomerField Handler
// --------------------------------------------------------------------

function CustomerFieldHandler(textbox, control, updateScript)
{
    this._TextBox = null;
    this._UI = null;
    this._UpdateScript = null;
    
    this._GetTop = function(control)
    {
        if (control.offsetParent)
        {
            return this._GetTop(control.offsetParent) + control.offsetTop;
        }
        else
        {
            return control.offsetTop;
        }
    };
    
    this._GetLeft = function(control)
    {
        if (control.offsetParent)
        {
            return this._GetLeft(control.offsetParent) + control.offsetLeft;
        }
        else
        {
            return control.offsetLeft;
        }
    };
    
    this._Initialize = function(textbox, control, updateScript)
    {
        Framework_CloseDialog();
        Framework_RegisterDialogHandler(this);
        
        this._TextBox = document.getElementById(textbox);
        this._UI = document.getElementById("CustomerField");
        this._UpdateScript = updateScript;
        
        this.Draw();
        this._UI.style.left = this._GetLeft(control) + 2;
        this._UI.style.top = this._GetTop(control) + 1;
        this._UI.style.visibility = "visible";
    };
    
    this.Close = function()
    {
        this._UI.style.visibility = "hidden";
        this._UI.innerHTML = "";
    };
    
    this.UpdateUI = function()
    {
        if (this._UpdateScript)
        {
            eval(this._UpdateScript);
        }
    };
    
    this.Draw = function()
    {
        var Html = "";
        Html += "<iframe src=\"/Popups/Embeded/CustomerFieldPopup.aspx?fieldid=" + this._TextBox.id + "\" frameborder=\"0\" scrolling=\"no\" class=\"CustomerField\"></iframe>";
        
        this._UI.innerHTML = Html;
    };
    
    this._Initialize(textbox, control, updateScript);
}

// --------------------------------------------------------------------
// Event Handlers
// --------------------------------------------------------------------

function CloseNavigation(name)
{
    var OpenedBlock = document.getElementById('Navigation_' + name + '_Opened');
    var ClosedBlock = document.getElementById('Navigation_' + name + '_Closed');
    
    OpenedBlock.style.display = 'none';
    ClosedBlock.style.display = 'inline';
}

function OpenNavigation(name)
{
    var OpenedBlock = document.getElementById('Navigation_' + name + '_Opened');
    var ClosedBlock = document.getElementById('Navigation_' + name + '_Closed');
    
    OpenedBlock.style.display = 'inline';
    ClosedBlock.style.display = 'none';
}

function ViewHistory(name, id)
{
    Framework_OpenWindow("ViewHistory", "/Popups/ViewHistory.aspx?tablename=" + name + "&id=" + id, 700, 500, true, true);
    
    return false;
}