﻿function $(id)
{
    return document.getElementById(id);
}


function createWin(w,h,title,url)
{
    var titleW = w-34;
    var ifrmH = h - 30;
    var str = '<div id="DivWin" class="winfrm">'+
    '<div class="winhead">'+
        '<div id="DivWinTitle" style="width:'+titleW+'px;float:left;" class="wintitle">'+
         '☑ '+title+
         '</div>'+
 '<input type="image" onclick="javascript:close($(\'DivWin\'));" style="width:18px;height:18px;"   src="/images/space/dialogclose.gif"/ >'+
     '</div>'+         
     '<div class="wincontent">'+
            '<iframe id="FrmWin"  src="about:blank"   width="100%"  scrolling="no" frameborder="0"></iframe> '+
         '</div>'+
 '</div>';
  $("SpanWin").innerHTML = str;
    var x=window.screen.availWidth/2-w/2;
    var y=window.screen.availHeight/2-h/2-100;
//   if(y>250) y = 250;
    var o = $('DivWin');
    o.style.position = 'absolute';
    o.style.left = x+"px";
    o.style.top = y+"px";
    o.style.width = w+"px";
    o.style.height = h+"px";   
//    o.style.display = '';
   // o.style.visibility = 'visible';
    $('DivWinTitle').style.cursor = 'move';
    drag($('DivWin'),$('DivWinTitle'));
    var frm = $('FrmWin');
    frm.src  = url;
    frm.height = ifrmH;
}

 
/*************************************
拖动层
o:拖动的对象
t:标题栏
**************************************/
function drag(o,t)
{
	o.firstChild.onmousedown=function(){return false;};
	 
	o.onmousedown=function(a)
	{
		var d=document;if(!a)a=window.event;
		var x=a.layerX?a.layerX:a.offsetX,y=a.layerY?a.layerY:a.offsetY;		 
		if(o.setCapture)
			o.setCapture();
		else if(window.captureEvents)
			window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
		o.style.className = 'winfrm-active';
		t.style.className = 'winhead-active';
		

		d.onmousemove=function(a){
			if(!a)a=window.event;
			if(!a.pageX)a.pageX=a.clientX;
			if(!a.pageY)a.pageY=a.clientY;
			var tx=a.pageX-x,ty=a.pageY-y;
			o.style.left = tx+"px";
			o.style.top = ty+"px";
		};

		d.onmouseup=function(){
			if(o.releaseCapture)
				o.releaseCapture();
			else if(window.captureEvents)
				window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
			o.style.className = 'winfrm';
		    t.style.className = 'winhead';
			d.onmousemove=null;
			d.onmouseup=null;
		};
	};
}


function close(o)
{
    o.style.display = 'none';
}


/*************************************
在限定区域内拖动
o:拖动的对象
r:区域，形如[200,400,30,30]
**************************************/
function dragEx(o,r){
	o.firstChild.onmousedown=function(){return false;};
	o.onmousedown=function(a){
		var d=document;if(!a)a=window.event;
		var x=a.layerX?a.layerX:a.offsetX,y=a.layerY?a.layerY:a.offsetY;
		if(o.setCapture)
			o.setCapture();
		else if(window.captureEvents)
			window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);

		d.onmousemove=function(a){
			if(!a)a=window.event;
			if(!a.pageX)a.pageX=a.clientX;
			if(!a.pageY)a.pageY=a.clientY;
			var tx=a.pageX-x,ty=a.pageY-y;
			o.style.left=tx<r[0]?r[0]:tx>r[1]?r[1]:tx;
			o.style.top=ty<r[2]?r[2]:ty>r[3]?r[3]:ty;
		};

		d.onmouseup=function(){
			if(o.releaseCapture)
				o.releaseCapture();
			else if(window.captureEvents)
				window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
			d.onmousemove=null;
			d.onmouseup=null;
		};
	};
 }
