﻿function MsgBox(iWidth, iHeight,sID,iType){
        var BackObject, FormObject;
        var strID;
        //    检查页面中是否存在该控件.
        
        
        function checkIMBObject(){
            if (document.getElementById("imb_Background")==null){
                var oIframe=document.createElement("<iframe id=\"imb_Background\" src=\"about:blank\" style=\"position:absolute;left:0;top:0;width:0px;height:0px;visibility:hidden;\" frameborder=\"0\"></iframe>");
                document.body.insertBefore(oIframe);   
                //document.body.innerHTML += "<iframe id=\"imb_Background\" src=\"about:blank\" style=\"position:absolute;left:0;top:0;width:0px;height:0px;visibility:hidden;\" frameborder=\"0\"></iframe>";
                //window.imb_Background.document.open();
                window.imb_Background.document.write("<html><body bgcolor=#CCCCCC>&nbsp;</body></html>");
                //window.imb_Background.document.close();
            }
            if (document.getElementById("imb_FormModal")==null){
                var oIframe1=document.createElement("<iframe id=\"imb_FormModal\" src=\"about:blank\" style=\"position:absolute;left:0;top:0;width:0px;height:0px;display:none;border-bottom:3px solid #999999;border-right:3px solid #999999;border-top:1px solid #F8F6C1;border-left:1px solid #F8F6C1;\" frameborder=\"0\"></iframe>");
                document.body.insertBefore(oIframe1); 
                var strHTML="<html>"+
                             "<head><style><!--"+
                              "td,div{font-size:12px;}"+
                              '//--></style><script type="text/javascript" src="../ajax/ajax.js"></script></head>'+
                              //parent.document.getElementsByTagName("head")[0].outerHTML+
                              //"<script>function killerror() {return true;}window.onerror = killerror;</script>"+
                              "<body scroll=no leftmargin=0 topmargin=0>"+
                              "<div id=dAll>"+
                              document.getElementById(sID).innerHTML+
                              "</div>"+
                              "</body>"+
                              "</html>";
                              alert(strHTML);
                               window.imb_FormModal.document.open();
                  window.imb_FormModal.document.write(strHTML);
                   window.imb_FormModal.document.close();
                //document.body.innerHTML += "<iframe id=\"imb_FormModal\" src=\"about:blank\" style=\"position:absolute;left:0;top:0;width:0px;height:0px;display:none;border-bottom:3px solid #999999;border-right:3px solid #999999;border-top:1px solid #F8F6C1;border-left:1px solid #F8F6C1;\" frameborder=\"0\"></iframe>";
//                window.imb_FormModal.document.open();
//                window.imb_FormModal.document.write("<html><head><style><!--");
//                window.imb_FormModal.document.write("td{font-size:12px;");
//                window.imb_FormModal.document.write("//--></style></head><body scroll=no leftmargin=0 topmargin=0>");
//                window.imb_FormModal.document.write(" <div id=dAll><table width=100% height=100% bgcolor=\"#F6F8DF\"><tr><td  align=left><div id=\"imb_Title\" style=\"padding-left:3px;padding-right:3px;BACKGROUND-COLOR: #EDE808 ;height:70%\">");
//                window.imb_FormModal.document.write("</div></td></tr><tr><td align=left><div id=\"imb_Content\" style=\"padding:7px;\">");
//                window.imb_FormModal.document.write("</div></td></tr><tr><td id=\"imb_Body\" align=center>");
//                window.imb_FormModal.document.write("</td></tr></table></div>");
//                window.imb_FormModal.document.write("</body></html>");
//                window.imb_FormModal.document.close();
            }
        }
        
        function checkIMBObject1(){
        if (document.getElementById("imb_Background")==null){
                var oIframe=document.createElement("<div id=\"imb_Background\" style=\"position:absolute;left:0;top:0;width:0px;height:0px;visibility:hidden; background-color:white;\" ></div>");
                document.body.insertBefore(oIframe); 
                //a
            }
            //if (document.getElementById(sID)==null){
                
                if(iType==2){
                if(!document.getElementById("imb_FormModal")){
                var oDiv=document.createElement('div');
                oDiv.id="imb_FormModal";
                oDiv.innerHTML=sID;
                document.body.appendChild(oDiv);
                }
                strID="imb_FormModal";
                document.getElementById("imb_FormModal").style.zIndex="99999";
                }else{
                document.getElementById(sID).style.zIndex="99999";
                strID=sID;
                //document.getElementById(sID).id="imb_FormModal";
                }
            //}
         
        
        }
        
        function selDisp(iType){
         var strDisp=(iType==1?"none":"");
         var strDisp1=(iType==1?"":"none");
         var sel=document.getElementsByTagName("select");
         var i=0;
          for(i=0;i<sel.length;i++){
          sel[i].style.display=strDisp;
          
          }
          if(document.getElementById("frmSub")){
          var sel2=document.getElementById("frmSub").contentWindow.document.getElementsByTagName("select");
          for(i=0;i<sel2.length;i++){
          sel2[i].style.display=strDisp;
          
          }
          }

          var sel1=document.getElementById(strID).getElementsByTagName("select");
          for(i=0;i<sel1.length;i++){
          sel1[i].style.display=strDisp1;
          }
        }
        
        function ShowBefore()
        {
          var smWidth = 420, smHeight = 180, smCaption = "默认对话框", smMessage="您确定执行这项操作吗?", smFunc, smObject, smAlpha, smInterval;
                smWidth = iWidth;
                smHeight = iHeight;

            //    背景的渐显.
            function checkIMBAlpha(){
                smObject.style.filter = "alpha(opacity="+smAlpha+");";
                smAlpha += 10;
                if (smAlpha>60){
                    clearInterval(smInterval);
                }
            }
            if(!iType){
            checkIMBObject();
            }
            else{checkIMBObject1(iType);
            }
            selDisp(1);
            this.BackObject = document.getElementById("imb_Background");
            this.FormObject = document.getElementById(strID);
            smObject = this.BackObject;
            smAlpha = 0;
            this.BackObject.style.left = 0;
            this.BackObject.style.zIndex = 5000;
            this.BackObject.style.top = 0;
            this.BackObject.style.width = document.documentElement.scrollWidth;
            this.BackObject.style.height = document.documentElement.scrollHeight+100;
            this.BackObject.style.visibility = "visible";//"visible";
            smObject.style.filter = "alpha(opacity="+1+");";
            //smObject.style.filter = "alpha(opacity="+20+");";
            smInterval = window.setInterval(checkIMBAlpha, 200);

            var curWindow=parent?parent:window;
             this.FormObject.style.position="absolute";
             setElementCenter(this.FormObject);
            //this.FormObject.style.left =0;// document.body.clientWidth/2 - smWidth/2;
           // alert(curWindow.document.body.clientHeight);
            //alert(curWindow.document.documentElement.clientHeight);
           // alert(curWindow.document.documentElement.scrollTop);
            //this.FormObject.style.top = curWindow.document.documentElement.scrollTop;//curWindow.document.body.clientHeight/2 - smHeight/2;
            this.FormObject.style.width = smWidth;
            this.FormObject.style.height = smHeight;
            this.FormObject.style.display = "block";

       }
       
       //    显示对话框控件.
        this.ShowModal = function(sID,oFunc){
          ShowBefore();
          //a
          // window.imb_FormModal.document.getElementById("dAll").innerHTML =document.getElementById(sID).innerHTML;
           // window.imb_FormModal.document.getElementById("btnSaveSub").onclick=oFunc;
           //alert( window.imb_FormModal.document.body.innerHTML);
//                smFunc = iClickFunc;
//                smCaption = iCaption;
//                smMessage = iMessage;
//            window.imb_FormModal.document.getElementById("imb_Title").innerHTML = "<b>" + smCaption + "</b>" + " -- 操作提示";
//            window.imb_FormModal.document.getElementById("imb_Content").innerHTML = smMessage;
//            if (iOther==null || iOther==""){
//                window.imb_FormModal.document.getElementById("imb_Body").innerHTML = "<input type=submit id=imb_Ok name=imb_Ok value=\"确定\" shortKey=\"T\" > &nbsp; <input type=button id=imb_Cancel name=imb_Cancel value=\"取消\" shortKey=\"C\" >";
//            }else{
//                window.imb_FormModal.document.getElementById("imb_Body").innerHTML = "<input type=button id=imb_Other name=imb_Other value="+iOther+" shortKey=\"O\"> &nbsp; <input type=submit id=imb_Ok name=imb_Ok value=\"确定\" shortKey=\"T\" > &nbsp; <input type=button id=imb_Cancel name=imb_Cancel value=\"取消\" shortKey=\"C\">";
//            window.imb_FormModal.document.getElementById("imb_Other").onclick= function(id){_goUrl(id);}
//            }
//            document.body.disabled = true;
//            
//                function _goUrl(id){
//                parent.document.body.disabled = false;
//                if (smFunc!=null && smFunc!=""){
//                    eval("parent." + smFunc.replace("$",id));
//                }
//                parent.document.getElementById("imb_Background").style.display = "none";
//                parent.document.getElementById("imb_FormModal").style.display = "none";
//            }
//            window.imb_FormModal.document.getElementById("imb_Ok").onclick= function(id){_goUrl(id);}
//            window.imb_FormModal.document.getElementById("imb_Cancel").onclick= function(id){_goUrl(id);}
        }
        
        this.MsgBoxDisplay=function(){
         selDisp(2);
         document.getElementById("imb_Background").style.visibility = "hidden";
         document.getElementById(strID).style.display = "none";
         if(document.getElementById("imb_FormModal"))
         {document.getElementById("imb_FormModal").style.display = "none";}
        }
        
        }
        
var g_rect;
var g_rectFrm;
function setElementCenter(elem){
g_rect=g_rect?g_rect:getPosition(elem)
var rect=g_rect;
var curWin=top?top:window;
if((!elem.document.getElementById("frmSub"))&&curWin.document.getElementById("frmSub")){
g_rectFrm=g_rectFrm?g_rectFrm:getPosition(curWin.document.getElementById("frmSub"));
}

var x=parseInt((curWin.document.documentElement.clientWidth-rect.width)/2);
var y=parseInt((curWin.document.documentElement.clientHeight-rect.height)/2+curWin.document.documentElement.scrollTop);
if(g_rectFrm){x=x-g_rectFrm.left;y=y-g_rectFrm.top;}
//a
elem.style.left=x+'px';
elem.style.top=(y<0?0:y)+'px';
window.onresize=function(){
setElementCenter(elem);
}
}

function getPosition(obj){
var top=0;
var left=0;
var width=obj.offsetWidth==0?obj.style.width.replace("px",""):obj.offsetWidth;
var height=obj.offsetHeight==0?obj.style.height.replace("px",""):obj.offsetHeight;
while(obj.offsetParent){
top+=obj.offsetTop;
left+=obj.offsetLeft;
obj=obj.offsetParent;}

return{"top":top,"left":left,"width":width,"height":height};
}
        
