﻿// JScript 文件

//**********************
//***   遮罩层对象   ***
//**********************
var MaskDiv = function(){


    //***********************************************
    //**                创建遮罩层                 **
    //**    hidarray 需要隐藏的对象数组(标签ID)    **
    //***********************************************
    this.Create = function CreatMaskDiv(hidarray){
        //防止促发按钮超出遮罩层促发时处理
        if($("#MaskID")[0]){
            this.Del(hidarray);
        }
        var wnd = $(window), doc = $(document);
        if(wnd.height() > doc.height()){ //当高度少于一屏
            wHeight = wnd.height(); 
        }else{//当高度大于一屏
            wHeight = doc.height();   
        }
        //隐藏hidarray
        if(hidarray != null){
            for(var i = 0; i < hidarray.length; i++){
                $(hidarray[i]).css({display:"none"});
            }
        }
        //创建遮罩背景
        $("body").append("<div ID=MaskID></div>");
        $("body").find("#MaskID").width(doc.width()-20).height(wHeight).css({position:"absolute",top:"0px",left:"0px",background:"#ccc",filter:"Alpha(opacity=70);",opacity:"0.3",zIndex:"100"});
    }
    
    
    
    //***********************************************
    //**                删除遮罩层                 **
    //**    bloarray 需要显示的对象数组(标签ID)    **
    //***********************************************
    this.Del = function DelMaskDiv(bloarray){
        //显示select控件
        if(bloarray != null){
            for(var i = 0; i < bloarray.length; i++){
                $(bloarray[i]).css({display:"block"});
            }
        }
        $("#OperateID").empty();
        $("#OperateID").remove();
        $("#MaskID").empty();
        $("#MaskID").remove();
    }
    
    
    
    //************************************************
    //**         在遮罩层上加入操作层               **
    //**    OperateDiv 创建操作对话框的html代码     **
    //**       ptable 创建对话框的标签ID            **
    //************************************************
    this.Add = function Add(OperateDiv,ptable){
        var operatediv = "<div id=\"OperateID\">"+OperateDiv+"</div>";
        $("body").append(operatediv);
        divHeight = document.documentElement.scrollTop + document.documentElement.clientHeight - (document.documentElement.clientHeight - parseInt($("#OperateID").height()))/2 - parseInt($("#OperateID").height()) - 60;
        divWidth = (parseInt($(window).width()) - parseInt($(ptable).width()))/2+document.documentElement.scrollLeft;
        $("#OperateID").css({position:"absolute",top:divHeight+"px",left:divWidth+"px",background:"white",zIndex:"101"});
    }
    
    
    
    //*********************************************************
    //**    当窗口大小改变时改变蒙版大小和AJAX对话框位置     **
    //**            ptable 创建对话框的标签ID                **
    //*********************************************************
    this.WinResize = function WRez(ptable){
        if($("#MaskID")[0]){
            var wnd = $(window), doc = $(document);
            if(wnd.height() > doc.height()){ //当高度少于一屏
                wHeight = wnd.height(); 
            }else{//当高度大于一屏
                wHeight = doc.height();   
            }
            $("body").find("#MaskID").width(doc.width()).height(wHeight);
            if($("#OperateID")[0]){
                divHeight = document.documentElement.scrollTop + document.documentElement.clientHeight - (document.documentElement.clientHeight - parseInt($("#OperateID").height()))/2 - parseInt($("#OperateID").height()) - 60;
                divWidth = (parseInt($(window).width()) - parseInt($(ptable).width()))/2+document.documentElement.scrollLeft;
                $("#OperateID").css({top:divHeight+"px",left:divWidth+"px"});
            }
        }
    }
    
    
    
    //**************************
    //**    创建请求动画层    **
    //**************************
    this.AddAjaxMovie = function AAMov(img){
        var moviediv = "<img id=\"loadImg\" src=\""+img+"\" alt=\"\" />";
        $("body").append(moviediv);
        divHeight = document.documentElement.scrollTop + document.documentElement.clientHeight - (document.documentElement.clientHeight - parseInt($("#loadImg").height()))/2 - parseInt($("#loadImg").height()) - 60;
        divWidth = (parseInt($(window).width()) - parseInt($("#loadImg").width()))/2+document.documentElement.scrollLeft;
        $("#loadImg").css({position:"absolute",top:divHeight+"px",left:divWidth+"px",zIndex:"102"});
    }
    
    
    
    //**************************
    //**    删除请求动画层    **
    //**************************
    this.DelAjaxMovie = function DAMov(){
        if($("#loadImg")[0]){
            $("#loadImg").remove();
        }
    }
}


//退出对话框
function canclediv() {
    //删除遮罩层
    if (maskDiv == null)
        maskDiv = new MaskDiv();
    maskDiv.Del(null);
}


//        坐标取值
//        document.documentElement.scrollTop+document.documentElement.clientHeight
//        divPageMask.style.width = document.body.scrollWidth;
//        divPageMask.style.height = document.body.scrollHeight>document.body.clientHeight?document.body.scrollHeight:document.body.clientHeight;
//        divOpenWin.style.left = (document.body.offsetWidth - divOpenWin.offsetWidth) / 2;
//        divOpenWin.style.top = (document.body.offsetHeight - divOpenWin.offsetHeight) / 2;