﻿


var dialogFirst = true;
function jQShowDialog(title, content, width, height, cssName) {

    if (dialogFirst == true) {
        var temp_float = new String;
        temp_float = "<div id=\"floatBoxBg\" style=\"height:" + $(document).height() + "px;filter:alpha(opacity=0);opacity:0;\"></div>";
        temp_float += "<div id=\"floatBox\" class=\"floatBox\">";
        temp_float += "<div class=\"title\"><h4></h4><span>关闭</span></div>";
        temp_float += "<div class=\"content\"></div>";
        temp_float += "</div>";
        $("body").append(temp_float);
        dialogFirst = false;
    }

    $("#floatBox .title span").click(function() {
        $("#floatBoxBg").animate({ opacity: "0" }, "normal", function() { $(this).hide(); });
        $("#floatBox").animate({ top: ($(document).scrollTop() - (height == "auto" ? 300 : parseInt(height))) + "px" }, "normal", function() { $(this).hide(); });
    });

    $("#floatBox .title h4").html(title);
    contentType = content.substring(0, content.indexOf(":"));
    content = content.substring(content.indexOf(":") + 1, content.length);
    switch (contentType) {
        case "url":
            var content_array = content.split("?");
            $("#floatBox .content").ajaxStart(function() {
                $(this).html("loading...");
            });
            $.ajax({
                type: content_array[0],
                url: content_array[1],
                data: content_array[2],
                error: function() {
                    $("#floatBox .content").html("error...");
                },
                success: function(html) {
                    $("#floatBox .content").html(html);
                }
            });
            break;
        case "text":
            $("#floatBox .content").html(content);
            break;
        case "id":
            $("#floatBox .content").html($("#" + content + "").html());
            break;
        case "iframe":
            $("#floatBox .content").html("<iframe src=\"" + content + "\" width=\"100%\" height=\"" + (parseInt(height) - 30) + "px" + "\" scrolling=\"auto\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\"></iframe>");
    }

    $("#floatBoxBg").show();
    $("#floatBoxBg").animate({ opacity: "0.5" }, "normal");
    $("#floatBox").attr("class", "floatBox " + cssName);
    $("#floatBox").css({ display: "block", left: (($(document).width()) / 2 - (parseInt(width) / 2)) + "px", top: ($(document).scrollTop() - (height == "auto" ? 300 : parseInt(height))) + "px", width: width, height: height });
    $("#floatBox").animate({ top: ($(document).scrollTop() + 150) + "px" }, "normal");
}



































////批量替换(正则表达式批量替换解决方案)
//String.prototype.replaceAll = function(s1, s2) {
//    return this.replace(new RegExp(s1, "gm"), s2);
//};

//(function($) {

//    var ___id___ = "";
//    var ___settings___ = {};
//    var isMouseDown = false;

//    var currentElement = null;

//    var dropCallbacks = {};
//    var dragCallbacks = {};

//    var bubblings = {};

//    var lastMouseX;
//    var lastMouseY;
//    var lastElemTop;
//    var lastElemLeft;

//    var dragStatus = {};

//    var holdingHandler = false;

//    //获得鼠标位置
//    $.getMousePosition = function(e) {
//        var posx = 0;
//        var posy = 0;

//        if (!e) var e = window.event;

//        if (e.pageX || e.pageY) {
//            posx = e.pageX;
//            posy = e.pageY;
//        }
//        else if (e.clientX || e.clientY) {
//            posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
//            posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
//        }
//        return { 'x': posx, 'y': posy };
//    };

//    //更新位置
//    $.updatePosition = function(e) {
//        var pos = $.getMousePosition(e);

//        var spanX = (pos.x - lastMouseX);
//        var spanY = (pos.y - lastMouseY);
//        var _top = (lastElemTop + spanY) > 0 ? (lastElemTop + spanY) : 0;
//        var _left = (lastElemLeft + spanX) > 0 ? (lastElemLeft + spanX) : 0;
//        $("#" + ___id___).css("top", _top);
//        $("#" + ___id___).css("left", _left);
//    };

//    //向上拖动
//    $.fn.ondrag = function(callback) {
//        return this.each(function() {
//            dragCallbacks[this.id] = callback;
//        });
//    };

//    //向下拖动
//    $.fn.ondrop = function(callback) {
//        return this.each(function() {
//            dropCallbacks[this.id] = callback;
//        });
//    };

//    //结束拖动
//    $.fn.dragOff = function() {
//        return this.each(function() {
//            dragStatus[this.id] = 'off';
//        });
//    };

//    //拖动
//    $.fn.dragOn = function() {
//        return this.each(function() {
//            dragStatus[this.id] = 'on';
//        });
//    };

//    //
//    $.extend({
//        //弹出层基础设置
//        layerSettings: {
//            id: "layerdiv",
//            width: 220,
//            height: 220,
//            templete: '<div style="height:20px; width:@width@px; background-color:#777777;"><span id="@moveid@" style="position:relative; left:0px; top:0px; height:20px; width:100px;"><span id="@titleid@">@title@</span></span><span class="layerclose" style="position:relative; top:0px; float:right; right:20px; color:red;">close</span></div><div style="border:solid #ff0000 1px; width:@width@px; height:@height@px;"><div style="width:100%; height:100%; background-color:#ffffff;" id="@contentid@"></div></div>',
//            content: '',
//            title: '',
//            isbg: true,
//            opacity: 0.3
//        },
//        //设置装载弹出层
//        layerSetup: function(settings) {
//            $.extend($.layerSettings, settings);
//            ___settings___[settings.id] = settings;
//            ___id___ = settings.id;
//        },
//        //
//        layershow: function() {
//            var __bw = $("body").width(); //背景宽
//            var __bh = $("body").height() > $(window).height() ? $("body").height() : $(window).height(); //背景高

//            var _width = $.layerSettings.width; //弹出层宽
//            var _height = $.layerSettings.height; //弹出层高

//            if (document.getElementById(___id___)) return;
//            var _moveid = ___id___ + "_move";
//            var _titleid = ___id___ + "_title";
//            var _contentid = ___id___ + "_content";
//            var _cssurl = $.layerSettings.cssurl;
//            var opacity = $.layerSettings.opacity; //背景透明

//            __index = $.layermaxindex();

//            var __left = (__bw - _width) > 0 ? (__bw - _width) / 2 : 0;
//            var __top = 100;
//            var __bgDiv = '<div id="' + ___id___ + '_background" style="background:#000000; filter:alpha(opacity=' + (opacity * 100) + '); opacity: ' + opacity + '; width:' + __bw + 'px; height:' + __bh + 'px; z-index:' + (__index++) + '; position:absolute; left:0px; top:0px;"></div>';

//            //$.layerSettings.isbg = true 设置弹出层后 锁定网页
//            if ($.layerSettings.isbg) {
//                $("body").append(__bgDiv);
//            }

//            $("body").append('<div id="' + ___id___ + '" style="z-index:' + __index + ';position:absolute; left:' + __left + 'px; top:' + __top + 'px;"></div>');

//            var _templete = $.layerSettings.templete;
//            //替换参数
//            var __templete = _templete.replaceAll("@width@", _width).replaceAll("@height@", _height).replaceAll("@titleid@", _titleid).replaceAll("@contentid@", _contentid).replaceAll("@title@", jQuery.layerSettings.title).replaceAll("@moveid@", _moveid);

//            $("#" + ___id___).append(__templete);
//            $("#" + _contentid).append($.layerSettings.content);
//            $("#" + _titleid).append($.layerSettings.title);

//            //关闭当前操作层
//            var idd = ___id___;
//            $(".layerclose").bind("click", function() {
//                $.layerclose(idd);
//            });

//            //
//            $("#" + ___id___).bind("click", function() {
//                var id = this.id;
//                $.layerSetup(___settings___[id]);
//                $(this).css("z-index", $.layermaxindex());
//            });

//            $(document).bind("click", function(e) {
//                var pos = $.getMousePosition(e);

//            });

//            $(document).mousemove(function(e) {
//                if (isMouseDown && dragStatus[currentElement.id] != 'false') {
//                    $.updatePosition(e);
//                    if (dragCallbacks[currentElement.id] != undefined) {
//                        dragCallbacks[currentElement.id](e, currentElement);
//                    }
//                    return false;
//                }
//            });

//            $(document).mouseup(function(e) {
//                if (isMouseDown && dragStatus[currentElement.id] != 'false') {
//                    isMouseDown = false;
//                    if (dropCallbacks[currentElement.id] != undefined) {
//                        dropCallbacks[currentElement.id](e, currentElement);
//                    }
//                    return false;
//                }
//            });

//            (function() {
//                bubblings[___id___] = true;

//                dragStatus[___id___] = "on";

//                //setHandler
//                bubblings[this.id] = true;

//                dragStatus[_moveid] = "handler";

//                $("#" + _moveid).css("cursor", "move");

//                $("#" + _moveid).mousedown(function(e) {
//                    var id = this.id.replace("_move", "");
//                    ___id___ = id;
//                    $("#" + id).css("z-index", $.layermaxindex());
//                    $.layerSetup(___settings___[id]);
//                    if ((dragStatus[___id___] == "off") || (dragStatus[___id___] == "handler" && !holdingHandler))
//                        return bubblings["#" + ___id___];

//                    isMouseDown = true;
//                    currentElement = $("#" + ___id___);

//                    var pos = $.getMousePosition(e);
//                    lastMouseX = pos.x;
//                    lastMouseY = pos.y;

//                    lastElemTop = document.getElementById(___id___).offsetTop;
//                    lastElemLeft = document.getElementById(___id___).offsetLeft;

//                    $.updatePosition(e);
//                    holdingHandler = true;
//                });

//                $("#" + _moveid).mouseup(function(e) {
//                    holdingHandler = false;
//                });
//                //end setHandler
//            })();
//        },
//        //
//        layerclose: function(__id) {
//            $("#" + __id + "_background").remove();
//            $("#" + __id).remove();
//        },
//        //
//        layermaxindex: function() {
//            var ___index = 0;
//            $.each($("*"), function(i, n) {
//                var __tem = $(n).css("z-index");
//                if (__tem > 0) {
//                    if (__tem > ___index) {
//                        ___index = __tem + 1;
//                    }
//                }
//            });
//            return ___index;
//        }
//    });
//})(jQuery);






























































//var isFirst = true;
//function jQShowDialog(title, content, width, height, className) {

//    //弹出层
//    if (isFirst == true) {
//        var showHtml = "<div id=\"jQuiDialogBox\">";

//        //可操作层
//        showHtml += "<h4></h4><span>关闭</span>";
//        showHtml += "<div id=\"jQuiDialogBoxBody\"></div>";
//        showHtml += "</div>";
//        
//        $("body").append(showHtml);

//        isFirst = false;
//    }

//    //加载操作层数据
//    ///添加标题
//    $("#jQuiDialogBox h4").html(title);

//    ///获取弹出层类型
//    contentType = content.substring(0, content.indexOf(":"));
//    content = content.substring(content.indexOf(":") + 1, content.length);
//    switch (contentType) {
//        case "url": ///加载页面
//            var content_array = content.split("?");
//            $("#jQuiDialogBoxBody").ajaxStart(function() {
//                $(this).html("loading...");
//            });
//            $.ajax({
//                type: content_array[0],
//                url: content_array[1],
//                data: content_array[2],
//                error: function() {
//                    $("#jQuiDialogBoxBody").html("error...");
//                },
//                success: function(html) {
//                    $("#jQuiDialogBoxBody").html(html);
//                }
//            });
//            break;
//        case "text": ///加载字符串
//            $("#jQuiDialogBoxBody").html(content);
//            break;
//        case "id": ///为指定标签追加字符串
//            $("#jQuiDialogBoxBody").html($("#" + content + "").html());
//            break;
//        case "iframe": ///加载Iframe
//            $("#jQuiDialogBoxBody").html("<iframe src=\"" + content + "\" width=\"100%\" height=\"" + (parseInt(height) - 30) + "px" + "\" scrolling=\"auto\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\"></iframe>");
//    }
//    $("#jQuiDialogBox").attr("class", className);
//    $("#jQuiDialogBox").fadeIn("fast");

//    ///透明
//    $("#jQuiDialogBox").fadeTo("slow", 0.98);


//    //隐藏层
//    $("#jQuiDialogBox span").click(
//			    function() {
//			        $("#jQuiDialogBox").fadeOut("slow");
//			    });
//}
