/*
    WebPage object:
        Represents a webpage. It could contain web controls.(WebControl objects)
        Parameter:
            config object:
                configuration object which contains:
                    url: a link to a html page which will be load via Ajax request
                    container: the ID of an html tag in which the specified html page will be loaded
*/
WebPage = Class.create({
    
    initialize : function(config)
    {
        this.config = config;
        this.webControls = {};
        this.webControlIndex = 0;
    },
    
    // Adds a WebControl to this WebPage.
    AddWebControl : function(webControl)
    {
        this.webControls[this.webControlIndex++] = webControl;
    },
    
    /*
        Gets the HTML source specified in the config object called 'url'. (this.config.url)
        and put it into the specified div. (this.config.container)
    */
    Show : function()
    {
        if(this.config.InitializeWebPage != null)
        {
            this.config.InitializeWebPage();
        }
        
        new Ajax.Updater(
            this.config.container,
            this.config.url,
            {
                asynchronous : false,
                onComplete: this.ShowOnComplete.bind(this)
            }
        );
    },
    
    // Shows all contained WebControl
    ShowOnComplete : function(originalRequest)
    {
        for(var i = 0; i < this.webControlIndex; i++)
        {
            this.webControls[i].Show();
        }
        
        if(this.config.Show != null) this.config.Show();
        if(this.config.AddEvents != null) this.config.AddEvents();
    }    
});
