(function($) {
    $.fn.jqDrag = function(h) { return i(this, h, 'd'); };
    $.fn.jqResize = function(h) { return i(this, h, 'r'); };
    $.jqDnR = { dnr: {}, e: 0,
        drag: function(v) {
            if (M.k == 'd') E.css({ left: M.X + v.pageX - M.pX, top: M.Y + v.pageY - M.pY });
            else E.css({ width: Math.max(v.pageX - M.pX + M.W, 0), height: Math.max(v.pageY - M.pY + M.H, 0) });
            return false;
        },
        stop: function() { $().unbind('mousemove', J.drag).unbind('mouseup', J.stop); }
    };
    var J = $.jqDnR, M = J.dnr, E = J.e,
    i = function(e, h, k) {
    return e.each(function() {
        h = (h) ? $(h, e) : e;
        h.bind('mousedown', { e: e, k: k }, function(v) {
            var d = v.data, p = {}; E = d.e;
            if (E.css('position') != 'relative') { try { E.position(p); } catch (e) { } }
            M = { X: p.left || f('left') || 0, Y: p.top || f('top') || 0, W: f('width') || E[0].scrollWidth || 0, H: f('height') || E[0].scrollHeight || 0, pX: v.pageX, pY: v.pageY, k: d.k };
            $().mousemove($.jqDnR.drag).mouseup($.jqDnR.stop);
            return false;
        });
    });
},
f = function(k) { return parseInt(E.css(k)) || false; };
})(jQuery);


$.fn.popshow_window = function(html) {
    var me = this;
    $(me).html("<table width='150px' height=100% border=0  class=clsTitleBarBGColor cellpadding=0 cellspacing=0 bgcolor='#FFFFFF' style='border: 0 solid #fff'><tr><td valign=top height=20 ><table border=0 cellpadding=0 cellspacing=0 height=0 width=100%><tr><th  height=10 style=cursor:move width=100% bgcolor=#efefef><div id=popshow_drag><font color='#FFFFFF'>&nbsp;&nbsp;</font></div></th><td  bgcolor='#D7D7D7' height=18><div id='popshow_imgclose' style='cursor:pointer;background-color:#dddddd;width:15px;height:18px; font-family:Verdana, Geneva, sans-serif; font-size:15px; padding-left:5px; padding-right:2px'>X</div></td></tr></table><table cellpadding=0 cellspacing=0 border=0 width=100%><tr><td style='padding:1px' width='100%' height='100%' valign=top><div id=popshowcont>" + html + "</div></td></tr></table></td></tr><tr><td height=1><table border=0 cellpadding=0 cellspacing=0  width='100%'><tr><th  height=1  width=100% > </th><td ><div id=popshow_resize style='cursor:se-resize; position: absolute;'></div></td></tr></table></td></tr></table>");
    $(me).css("{visibility:hidden,position:absolute,left:0,top:0,width:480,height:200,z-index:1000,background-color:000eee,border:1px solid #CCC}");
    $(me).css("visibility", "hidden");
    $(me).css("position", "absolute");
    $(me).css("left", "0");
    $(me).css("top", "0");
    $(me).css("height", "10");
    $(me).css("z-index", "1000");
    $(me).css("width", "10");
    $(me).css("left", "0");
    $(me).css("background-color", "#EEE");
    $(me).css("border", "solid 1px #CCC");
    $(me).find('#popshow_imgclose').click(function() {
        $("#popshowcont").html('');
        $(me).empty();
        $(me).css("visibility", "hidden");		
		var overlayer = document.getElementById("overlayer");          
        overlayer.style.display = "none" ;   
    });
	$("#overlayer").click(function()
	{
	
		$(me).empty();
        $(me).css("visibility", "hidden");		
		$("#popshowcont").html('');
		this.style.display = "none";								  
	})
    $(me).jqDrag('#popshow_drag').jqResize('#popshow_resize');
}

var xx = 0, yy = 0;
function mm() {
    sx = window.document.body.scrollLeft;
    sy = window.document.body.scrollTop;
    //alert(sx + "-mm-" + sy);
    xx = window.event.x + sx;
    yy = window.event.y + sy;
    //alert(xx + "-mm-" + yy);
};
function openpopshow(width) {
    $("#popshow").popshow_window('<div id="gedit"></div>');
    var ww = $(document).width();
    var dw = $("#popshow").width();
    xx = xx - dw / 2;
    if (xx < 0) xx = 10;
    if ((xx + dw) > ww) xx = ww - dw - 50;
    //alert(xx+"--"+yy);
	//$("#TipsWin").css("left",(($(document).width())/2-(parseInt(div宽度)/2))+"px"); 	
    $("#popshow").css("left", (($(document).width())/2-(parseInt(width)/2)));
    $("#popshow").css("top", 50);
    $("#popshow").css("visibility", "visible");
	var overlayer = document.getElementById("overlayer");     
    overlayer.style.display = "block" ;   
}

function close_window() {
    document.all.popshow.style.visibility = "hidden";
    document.all.gedit.innerHTML = '';

	
}
function startDownload(url, enddo) {
     $.ajax({
        type: "GET",
        cache:false,
        url: url,
        dataType: "html",
        success: function(ht) {
            enddo(ht);
        }
    });
}


