function CWIMessageBoxShow(text, caption, icon)
{                
    if(caption == null)
    {
        caption = CWIApplicationName;
    }    
    
    var element = $get("CWIMessageBoxOnClientElement");        
   
    if(element == null)
    {
        var html  = "<span id='CWIMessageBoxOnClientBackground' class='CWIValidationSummaryMessageBoxStyleBackground' style='z-index:10000'></span>";
        html += "<span id='CWIMessageBoxOnClient' style='z-index:10001'>";
        html += "   <div id='CWIMessageBoxOnClientPanel' class='CWIWindowBasePanel' style='z-index:10001;position:absolute; top:0px; left:0px;'>";
        html += "       <div class='CWIWindowBaseDragPanel' style='cursor:normal'>";
        html += "           <table border='0'>";
        html += "               <tr>";
        html += "                   <td style='width:100%;' id='CWIMessageBoxOnClientCaption'></td>";
        html += "   					<td>"
        html += "                           <input type='button' value='' onclick='CWIMessageBoxHide();' class='CWIWindowBaseCloseButton' />";
        html += "                       </td>";
        html += "           	</tr>";
        html += "			</table>";
        html += "       </div>";
        html += "       <div class='CWIWindowBaseContentPanel' style='z-index:10001'>";
        html += "           <BR></BR>";
        html += "           <table>";
        html += "               <tr>";
        html += "                   <td>";
        html += "                       <img id='CWIMessageBoxOnClientIcon' />";
        html += "                   </td>";
        html += "                   <td id='CWIMessageBoxOnClientText' style='width:400px'>";
        html += "                   </td>";
        html += "               </tr>";
        html += "           </table>";
        html += "           <BR></BR>";
        html += "           <div class='CWIMessageBoxButtonPanel'>";
        html += "               <input id='CWIMessageBoxOnClientOkButton' type='button' name value='Ok' onclick='CWIMessageBoxHide();' class='CWIMessageBoxButton' />";
        html += "	      </div>";
        html += "           <BR></BR>";
        html += "	    </div>";
        html += "		</div>";
        html += "</span>";
                
        element = document.body.insertBefore(document.createElement("div"), document.body.firstChild);        
        element.id = "CWIMessageBoxOnClientElement";
        element.style.top = 0;
        element.style.left = 0;
        element.style.width = "100%";
        element.style.height = "100%";
        element.style.position = "absolute";        
        element.style.display = "none";
        element.innerHTML = html;
        element.style.zIndex = 10001;                
    }          
    
    $get("CWIMessageBoxOnClientText").innerHTML = text;
    $get("CWIMessageBoxOnClientCaption").innerHTML = caption;
    
    var iconObj = $get("CWIMessageBoxOnClientIcon");
    if(icon == null)
    {
        iconObj.style.display = "none";
    }
    
    iconObj.src = CWIVirtualPath + "Images/CWIMessageBox/" + icon + ".gif";
    iconObj.style.display = "";        
    
    var panel = $get("CWIMessageBoxOnClientPanel");
    panel.style.marginTop = ((CWIGetClientHeight() / 2) - 95) + "px";
    panel.style.marginLeft = ((CWIGetClientWidth() / 2) - 210) + "px";
    
    var extender = $find(CWIMessageBoxOnClientID + "_CWIWindowBaseExtender");
        
    AjaxControlToolkit.ModalPopupBehavior.callBaseMethod(extender, 'populate');
    extender._attachPopup();        
            
    if(extender._isIE6)
    {
        var iframe = $get("CWII6ComboboxHack");
        
        if(iframe == null)
        {
            iframe = "<iframe id='CWII6ComboboxHack' src='javascript:false;' frameborder='2' tabindex='-1' style='filter:alpha(opacity=0);z-index:9999;display:block;position:absolute;top:0;left:0;width:" + CWIGetClientWidth() +"px;height:" + CWIGetClientHeight() + "px' />";                
            document.body.insertBefore(document.createElement(iframe), document.body.firstChild);
        }
        else
        {
            iframe.style.display = "inline";
        }
    }
    else
    {
        extender.disableTab();
    } 
     
    extender._layout();
    extender._layout();  
               
    if(extender._isIE6)
    {
        var background = $get("CWIMessageBoxOnClientBackground");
        background.style.height = CWIGetClientHeight() + "px";
        background.style.width = CWIGetClientWidth() + "px";                  
    }            
        
    $get("CWIMessageBoxOnClient").style.display = "";
    $get("CWIMessageBoxOnClientBackground").style.display = "";
    element.style.display = "";        
    
    
    $get("CWIMessageBoxOnClientOkButton").focus();
    CWISetFocus($get("CWIMessageBoxOnClientOkButton"));
}

function CWIMessageBoxHide()
{
    var extender = $find(CWIMessageBoxOnClientID + "_CWIWindowBaseExtender");    
    if(extender != null)
    {                        
        if(extender._isIE6)
        {
            var iframe = $get("CWII6ComboboxHack");
            if(iframe != null)
            {
                iframe.style.display = "none";
            }                        
        } 
        else
        {
            extender.restoreTab();
        }
    }

    var obj = $get('CWIMessageBoxOnClientElement');    
    if(obj != null)
    {    
        obj.style.display = 'none';
    }
    
    obj = $get('CWIMessageBoxOnClient');    
    if(obj != null)
    {
        obj.style.display = 'none';
    } 
    
    obj = $get('CWIMessageBoxOnClientBackground');    
    if(obj != null)
    {
        obj.style.display = 'none';
    }        
}

function CWIMessageBoxCentralize()
{
    var b = $get("CWIMessageBoxOnClientBackground");  
    
    if(b != null)
    {        
        var scrollLeft = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
        var scrollTop = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
                                    
        b.style.position = "absolute";        
        b.style.left = scrollLeft + "px";
        b.style.top = scrollTop + "px";

        var clientWidth = CWIGetClientWidth();
        var clientHeight = CWIGetClientHeight();
        
        b.style.width = clientWidth;
        b.style.height = clientHeight;   
        
        var panel = $get("CWIMessageBoxOnClientPanel");
        panel.style.marginTop = (scrollTop + (clientHeight / 2) - 95) + "px";
        panel.style.marginLeft = (scrollLeft + (clientWidth / 2) - 210) + "px";
        
        var extender = $find(CWIMessageBoxOnClientID + "_CWIWindowBaseExtender");
        if(extender._isIE6)
        {
            var iframe = $get("CWII6ComboboxHack");
            
            if(iframe != null)
            {
                iframe.style.left = b.style.left;
                iframe.style.top = b.style.top;
                iframe.style.width = b.style.width;
                iframe.style.height = b.style.height;
            }
        }
    }
}