///
///   DSCovery Search Clients
///
DScript.DScovery.DScoveryContainer = DScript.HTML.HTMLControls.Control.extend
({
        content : function()
        {
            return document.getElementById(this.context.id).firstChild;
        },
        
        Render : function(sender)
        {
            eObj = Json.evaluate( sender );

            if ( (typeof(eObj) == 'object' ) && (eObj.Message) )
            {
                exceptionObj = Json.evaluate(eObj.Message);
                console.group(exceptionObj);
                console.error( 'Message: ' + exceptionObj["Message"]);
                console.log( 'Source: ' + exceptionObj["Source"] );
                console.log( 'Stack: ' + exceptionObj["StackTrace"] );
                console.groupEnd();
            }
            else if ( (typeof(eObj) == 'object' ) && (eObj.innerHTML) )
            {
                this.context.HTMLControl().innerHTML = eObj.innerHTML;
                
                if (this.context.PostRender) this.context.PostRender();
            }
        },
        
        onCallBack : function(sender)
        {
            WebForm_DoCallback(this.context.id,Json.toString(sender.context),this.Render,this, function( args )
            {
                exceptionObj = Json.evaluate( args );
                console.group(exceptionObj);
                console.error( 'Message: ' + exceptionObj["Message"] );
                console.log( 'Stack: ' + exceptionObj["StackTrace"] );
                console.groupEnd();
            },
            true);
        },
        
        onPostBack : function(sender)
        {
            if ($('__DSCOVERYDATA'))
                $('__DSCOVERYDATA').value = Json.toString(DScript.DScovery.DataGroups.context);
            __doPostBack(this.context.id, Json.toString(sender.context));
        },
        
        onUpdate : function(sender)
        {
            if (DScript.DScovery.DScoveryManager.ayncmode == 1)
            {
                this.onCallBack(sender);
            }
            else if (DScript.DScovery.DScoveryManager.ayncmode == 0)
            {
                this.onPostBack(sender);
            }
        },
            
        toString : function()
        {
          return Json.toString(this.context);
        }
});
