﻿var bgObj=null;
var msgObj=null
var divContent=null;
var title=null;
var titleClose=null;
function RemoveObj()
{
    if(bgObj!=null)
    {        
        title.removeChild(titleClose);
        msgObj.removeChild(title);
        msgObj.removeChild(divContent);
        document.body.removeChild(msgObj);
        document.body.removeChild(bgObj);        
        divContent=null;
        msgObj=null;
        bgObj=null;             
        titleClose=null;
        title=null;
    }
}
window.onunload=RemoveObj;
function HidePalette(){
    bgObj.style.display='none';
    msgObj.style.display='none';
}
function CreatePalette(w,h)
{
    var   msgw,msgh,bordercolor;
    msgw=w;//提示窗口的宽度
    msgh=h;//提示窗口的高度
    bordercolor= "#ff0000 ";//提示窗口的边框颜色
    var   sWidth,sHeight;
    sWidth=document.documentElement.scrollWidth;
    sHeight=document.documentElement.scrollHeight>document.documentElement.clientHeight ?document.documentElement.scrollHeight:document.documentElement.clientHeight;
    //bgObj
    bgObj=document.createElement("div");
    bgObj.setAttribute('id', 'bgDiv');
    bgObj.style.position="absolute";
    bgObj.style.top='0px';//document.documentElement.scrollTop+'px';
    bgObj.style.background="#000000";
    bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=80,finishOpacity=75";
    bgObj.style.opacity="0.6";
    bgObj.style.left="0";
    bgObj.style.width=sWidth+"px";
    bgObj.style.height=sHeight+'px';
    bgObj.style.zIndex="10000";
    document.body.appendChild(bgObj);
    //msgObj
    msgObj=document.createElement("div")
    msgObj.setAttribute("id", "msgDiv");
    msgObj.style.background="white";
    msgObj.style.border="1px solid "+ bordercolor;
    msgObj.style.position="absolute";
    msgObj.style.left = document.documentElement.scrollLeft+(document.documentElement.clientWidth-w)/2+'px';
    msgObj.style.top = document.documentElement.scrollTop+(document.documentElement.clientHeight-h)/2+'px';
    msgObj.style.width   =   msgw   +   "px";
    msgObj.style.height   =msgh   +   "px";
    msgObj.style.zIndex   =   "10001";
    document.body.appendChild(msgObj);
    
    title=document.createElement( "h4");
    title.setAttribute( "id", "msgTitle");
    title.setAttribute( "align", "left");
    title.style.margin= "0";
    title.style.padding= "3px";
    title.style.background=bordercolor;
    title.style.filter= "progid:DXImageTransform.Microsoft.Alpha(startX=20,   startY=20,   finishX=100,   finishY=100,style=1,opacity=75,finishOpacity=100); ";
    title.style.opacity= "0.75";
    title.style.border= "1px solid "   +   bordercolor;
    title.style.height= "18px";
    title.style.font= "12px   Verdana,   Geneva,   Arial,   Helvetica,   sans-serif ";
    title.style.color= "white";
    
    msgObj.appendChild(title);    
    titleClose=document.createElement( "div");
    titleClose.innerHTML= "[X]";
    titleClose.title="close";
    titleClose.style.position="absolute";
    titleClose.style.left   =  (msgw-50)+ "px";
    titleClose.style.top   =   "3px";
    titleClose.style.cursor= "pointer";    
    titleClose.style.color= "#000000";    
    titleClose.onclick=function(){
        HidePalette()
    }
    title.appendChild(titleClose);  
    
    
    divContent=document.createElement( "div");
    msgObj.appendChild(divContent);
    
    bgObj.style.display='none';
    msgObj.style.display='none';
}

function ShowContent(content){
    if(bgObj==null)
    {
        CreatePalette(700,300);
    }
    
    var   sWidth,sHeight;
    sWidth=document.documentElement.scrollWidth;
    sHeight=document.documentElement.scrollHeight>document.documentElement.clientHeight?document.documentElement.scrollHeight:document.documentElement.clientHeight;
    bgObj.style.width=sWidth+"px";
    bgObj.style.height=sHeight+'px';
    msgObj.style.left = document.documentElement.scrollLeft+(document.documentElement.clientWidth-parseInt(msgObj.style.width.substr(0,msgObj.style.width.length-2)))/2+'px';
    msgObj.style.top ='20px';// document.documentElement.scrollTop+(document.documentElement.clientHeight-parseInt(msgObj.style.height.substr(0,msgObj.style.height.length-2)))/2+'px';
        
    divContent.innerHTML=content;
    bgObj.style.display='';
    msgObj.style.display='';    
}
function SetDialogSize(w,h)
{
    if(msgObj!=null)
    {
        msgObj.style.width = w + "px";
        msgObj.style.height = h + "px";
        titleClose.style.left = (w-50)+ "px";
        msgObj.style.left = document.documentElement.scrollLeft+(document.documentElement.clientWidth-parseInt(msgObj.style.width.substr(0,msgObj.style.width.length-2)))/2+'px';
//        if(document.documentElement.clientHeight<h)
//            msgObj.style.top = document.documentElement.scrollTop+(document.documentElement.clientHeight-parseInt(msgObj.style.height.substr(0,msgObj.style.height.length-2)))/2+'px';
//        else
            //msgObj.style.top ='20px';
        
    }
}
