
function Alert()
{
    this._clientId = null;
    this._onOK = null;
    this._onCancel = null;
    this._ignoreBkg = false;
    
	this.Init = function(id)
	{
	    this._clientId = id;
	    
	    // Add handlers so we can call functions associated with this object.
        $addHandlers($get("alertContent"), {keypress:this.CheckKey}, this);
        $addHandlers($get("confAOk"), {click:this.OK}, this);
        $addHandlers($get("confACancel"), {click:this.Close}, this);
        $addHandlers($get("confAClose"), {click:this.Close}, this);

        // Setup a method to cleanup
        var delDispose = Function.createDelegate(this, this.Dispose);
        Sys.Application.add_unload(delDispose);
	}
    
        // Clean up after ourself
	this.Dispose = function()
	{
        $clearHandlers($get("alertContent"));
        $clearHandlers($get("confAOk"));
        $clearHandlers($get("confACancel"));
        $clearHandlers($get("confAClose"));
	}

    // Open the confirmation popup.
    this.OpenConfirm = function(title1, title2, msg, onOK, onCancel)
    { 
        // Make sure the cancel button is visible.
        showDIV('confCancel');

        this.Show(title1, title2, msg, onOK, onCancel);
    }

    // Open popup in alert mode.
    this.OpenAlert = function(title1, title2, msg, onOK)
    { 
        // alert mode does not have the Cancel button.
        hideDIV('confCancel');

        this.Show(title1, title2, msg, onOK, onOK);
    }

    this.Close = function()
    {
        this.Hide();
        
        if(null != this._onCancel)
        {
            this._onCancel();
        }
        
        return false;
    }

    this.OK = function()
    {
        this.Hide();
        
        if(null != this._onOK)
        {
            this._onOK();
        }

        return false;
    }
    
    // Internal function
    this.Show = function(title1, title2, msg, onOK, onCancel)
    {
        $get('confTitle1').innerHTML = title1;
        $get('confTitle2').innerHTML = title2;
        $get('confMsg').innerHTML = msg;
        
              
        if('undefined' != typeof(onOK))
        {
            this._onOK = onOK;
        }
        else
        {
            this._onOK = null;
        }

        if('undefined' != typeof(onCancel))
        {
            this._onCancel = onCancel;
        }
        else
        {
            this._onCancel = null;
        }
        
        // If the background Div is visible, we won't change it when showing/hiding the alert.
        this._ignoreBkg = !Sys.UI.DomElement.containsCssClass($get('alertBackground'), 'hide');

        if(!this._ignoreBkg)
        {
            showAlertBackground();
        }
        
        // Show the alert.
        showDIV('alertContent');
    }
    
    // Internal function
    this.Hide = function()
    {
        if(!this._ignoreBkg)
        {
            hideAlertBackground();
        }
        
        hideDIV('alertContent');
        this._ignoreBkg = false;
    }

    this.CheckKey = function(evt)
    {
        // evt is a Sys.UI.DomEvent object
     
        if (mapKeyToAction(evt))
        { 
            setEnterPress();
            this.OK();
            return false;
        }
    }
}







