/*
********************************************************************************************************************************************************************
* Name              : ItemSelectionMain.js
*
* Description       : handle events related to ItemSelectionMain control
*
* Author(S)         : NTHIMMRI
*
* Creation Date     : 3/9/2007
*
* Version           : 1.0
*
*
* Modifications:
*    MOD ID          Date              Developer Name                   Description
*    ------------    --------------    -----------------------------    ----------------------------------------------------
*
* VSS Info:
*      $Archive:
*      $Author:
*              $Date:
*              $Revision:
*
*  COPYRIGHT 2005 TDCI Inc.
********************************************************************************************************************************************************************
*/

ItemSelectionMain = Class.create();
ItemSelectionMain.prototype = 
{
    initialize: function(OuterDivID)
    {
	    // state variables
        this.Initialized = false;
        this.ClientID = OuterDivID;
               
        // object variables
        this.OuterDiv = null;
        this.ContainingDiv = null;
        this.ClientConstructor = null;
        this.Panel = null;
        
        this.OnClick = null;
             
        //Assign references to the object variables
        this.ContainingDiv = $(OuterDivID);
        
        this.ParseInitialValues();

        this.EventHandlerOver = this.MouseOver.bindAsEventListener(this);
        this.EventHandlerOut = this.MouseOut.bindAsEventListener(this);

        this.InitializePanel();
  
        this.Initialized = true;

        return true;
    },
    
    //Helper Function
    ParseInitialValues: function()
    {
         this.OnClientClick = this.ContainingDiv.getAttribute("OnClientClick");
         this.OnClientMouseOver = this.ContainingDiv.getAttribute("OnClientMouseOver");
         this.OnClientMouseOut = this.ContainingDiv.getAttribute("OnClientMouseOut");
         this.ClientConstructor = this.ContainingDiv.getAttribute("GBP");
 
        return true;
    },
    
    //Set Panel to observe button click   
    InitializePanel: function()
    {
        this.Panel = eval(this.ClientConstructor);
        this.Panel.SetClientClickInContext(this, "this.ViewClick(this.Panel.GetSelected(), HandledEvent);");
        
        Event.observe(this.ContainingDiv, 'mouseover', this.EventHandlerOver);
        Event.observe(this.ContainingDiv, 'mouseout', this.EventHandlerOut);
        
        return;
    },
       
    //Event Handler
    ViewClick: function(Commands, HandledEvent)
    {
        var Command;

        if (Commands != null && Commands.length > 0)
        {
            Command = Commands[0];
            
            if (this.OnClientClick.length > 0)
            {
                eval(this.OnClientClick);
            }
        }
        
        return;
    },
    
    MouseOver: function()
    {
        eval(this.OnClientMouseOver);
    },
    
    MouseOut: function()
    {
        eval(this.OnClientMouseOut);
    }
};