﻿Hardcore.Dialog = function()
{
    var _overlay;
    var _container;
    var _title;
    var _message;
    var _input;
    var _save;
    var _ok;
    var _closetop;
    var _closebottom;
    
    Ext.onReady(this.Initialize.createDelegate(this));
}

Ext.extend(Hardcore.Dialog, Ext.util.Observable,
{
    Initialize : function()
    {
        this.addEvents({"onData": true});
        this._container = Ext.get('DialogContainer');
        this._overlay = Ext.get('overlay');
        this._title = Ext.get('overlaytitle');
        this._message = Ext.get('message');
        this._input = Ext.get('txtDialogInput');
        this._save = Ext.get('DialogSave');
        this._ok = Ext.get('DialogOk');
        
        this._closetop = Ext.get('DialogCloseTop');
        this._closetop.on('click', this.closeClick.createDelegate(this));
        this._closebottom = Ext.get('DialogCloseBottom');
        this._closebottom.on('click', this.closeClick.createDelegate(this));
    },

    closeClick: function(btn, e)
    {
        Utility.Functions.SetVis(this._overlay, false);
        Utility.Functions.SetVis(this._save, false);
        Utility.Functions.SetVis(this._ok, false);
        Utility.Functions.SetVis(this._input, false);
        Utility.Functions.SetVis(this._title, false);
        Utility.Functions.SetVis(this._message, false);
        Utility.Functions.SetVis(this._container, false);
    },
        
    Message: function(title, text)
    {   
        Utility.Functions.SetVis(this._container, true);
        Utility.Functions.SetVis(this._save, false);
        Utility.Functions.SetVis(this._ok, false);
        Utility.Functions.SetVis(this._input, false);
        Utility.Functions.SetVis(this._title, true);
        Utility.Functions.SetVis(this._message, true);
        Utility.Functions.SetVis(this._overlay, true);

        this._title.update(title);
        this._message.update(text);
        this.Reposition();        
    },

    Confirmation: function(title, text)
    {   
        Utility.Functions.SetVis(this._container, true);
        Utility.Functions.SetVis(this._save, false);
        Utility.Functions.SetVis(this._ok, true);
        Utility.Functions.SetVis(this._input, false);
        Utility.Functions.SetVis(this._title, true);
        Utility.Functions.SetVis(this._message, true);
        Utility.Functions.SetVis(this._overlay, true);

        this._title.update(title);
        this._message.update(text);
        this.Reposition();        
    },    

    Input: function(title, text)
    {   
        Utility.Functions.SetVis(this._container, true);
        Utility.Functions.SetVis(this._save, true);
        Utility.Functions.SetVis(this._ok, false);
        Utility.Functions.SetVis(this._input, true);
        Utility.Functions.SetVis(this._title, true);
        Utility.Functions.SetVis(this._message, true);
        Utility.Functions.SetVis(this._overlay, true);   
        
        this._title.update(title);
        this._message.update(text);
        this.Reposition();        
    },

    Content: function(Title, ContentDivID)
    {   
        var contentdiv = new Ext.Element(document.createElement('div'));
        contentdiv.update(Ext.get(ContentDivID).dom.innerHTML);
        
        Utility.Functions.SetVis(this._container, true);
        Utility.Functions.SetVis(this._save, false);
        Utility.Functions.SetVis(this._ok, false);
        Utility.Functions.SetVis(this._input, false);
        Utility.Functions.SetVis(this._title, true);
        Utility.Functions.SetVis(this._message, true);
        Utility.Functions.SetVis(this._overlay, true);  

        this._title.update(Title);
        this._message.update('');
        this._message.appendChild(contentdiv);
        
        if (contentdiv.dom.scrollHeight > 600)
        {
            contentdiv.addClass('DialogScroll');           
        }
        
        this.Reposition();
    },
            
    Reposition : function()
    {
        var wHeight = window.screen.height;
        var wWidth = Functions.TotalWindowWidth();
        
        var wTop = Functions.ScrollTop();
        var oHeight = document.getElementById("DialogContainer").offsetHeight;
        
        this._overlay.setHeight(Functions.TotalWindowHeight());
        this._overlay.setWidth(wWidth);
        this._container.setY(0);
        this._container.setX(0);
        this._container.setXY([(wWidth / 2) - (this._container.getWidth() / 2), ((wHeight / 2) + wTop) - (oHeight / 2) ], true);
        
        var border = Ext.get('DialogBorder');
        border.setWidth(0);
        border.setWidth(this._message.getWidth(), true);
    },
   
    dialogClick: function(btn, e)
    {
        this._overlay.setVisible(false);
    },

    ForgotPassword: function(title, text)
    {   
        Utility.Functions.SetVis(this._container, true);
        Utility.Functions.SetVis(this._save, true);
        Utility.Functions.SetVis(this._ok, false);
        Utility.Functions.SetVis(this._input, true);
        Utility.Functions.SetVis(this._title, true);
        Utility.Functions.SetVis(this._message, true);
        Utility.Functions.SetVis(this._overlay, true);          
       
        this._save.on('click', this.ForgotPassword_click.createDelegate(this));
        
        this._title.update(title);
        this._message.update(text);
        this.Reposition();        
    },
    
    ForgotPassword_click : function()
    {
        Hardcore.AjaxAPI.Customer.ForgotPassword(_input.dom.value, this.ForgotPassword_click_process.createDelegate(this));
    },
    
    ForgotPassword_click_process : function(response)
    {
    
    }    
});