﻿
var uWinBg=null,uWin=null,
	uWinWidth,uWinHeight,
	uboolWinClk=0,uintWinPreX=0,uintWinPreY=0;

//创建窗口
function CreateWin(intWidth,intHeight)
{
	uWinWidth=intWidth,uWinHeight=intHeight;
	var pw=document.body.scrollWidth,ph=document.body.scrollHeight,
		cw=document.documentElement.clientWidth,ch=document.documentElement.clientHeight,
		sw=document.documentElement.scrollLeft,sh=document.documentElement.scrollTop;
	if(pw<cw)
		pw=cw;
	if(ph<ch)
		ph=ch;
	uWinBg=document.createElement('div');
	uWinBg.className='winbg winbgb';
	uWinBg.style.width=String(pw)+'px';
	uWinBg.style.height=String(ph)+'px';
	uWinBg.innerHTML='<iframe width=100% height=100% class=winbgb></iframe>';
	document.body.appendChild(uWinBg);

	uWin=document.createElement('div');
	uWin.className='win';
	if(window.navigator.userAgent.toLowerCase().indexOf('msie 6.0')>0)
	{
		//ie6.0
		uWin.style.cssText='position:absolute;left:expression(offsetParent.scrollLeft+(offsetParent.clientWidth-'+String(intWidth)
			+')/2);top:expression(offsetParent.scrollTop+(offsetParent.clientHeight-'+String(intHeight)+')/2);';
	}
	else
	{
		//其他浏览器
		uWin.style.cssText='position:fixed;';
		uWin.style.left=String(/*sw+*/(cw-intWidth)/2-10)+'px';
		uWin.style.top=String(/*sh+*/(ch-intHeight)/2-10<0?0:/*sh+*/(ch-intHeight)/2-10)+'px';
	}
	uWin.style.width=String(intWidth)+'px';
	uWin.style.height=String(intHeight)+'px';
	uWin.innerHTML='<div class=\'wintitle t_12\' onmousedown=uboolWinClk=1; onmouseout=uboolWinClk=0; onmouseup=uboolWinClk=0; onmousemove=MoveWin(event);>'
		+'<li id=divWinTitle class=f_l></li>'
		+'<li class=\'f_r w17\'><img id=bClose class=cr_hand title=关闭窗口 onclick=CloseWin(); onmouseover=this.src=\'/img/btWinClose-a.gif\'; onmouseout=this.src=\'/img/btWinClose.gif\'; src=/img/btWinClose.gif></li>'
		+'<div class=c_b></div></div>'
		+'<div id=divWin class=\'pd_5 ox_h oy_h\'></div>';
	document.body.appendChild(uWin);
	/*try
	{
		document.getElementById('bClose').addEventListener('click',CloseWin,false);
	}
	catch(ex)
	{
		document.getElementById('bClose').attachEvent('onclick',CloseWin);
	}*/
}

//关闭窗口
function CloseWin()
{
	document.body.removeChild(uWin);
	document.body.removeChild(uWinBg);
}

function MoveWin(event)
{
	if(uboolWinClk)
	{
		if(uintWinPreX==0&&uintWinPreY==0)
			uintWinPreX=event.clientX,uintWinPreY=event.clientY;
		else
		{
			var x=parseInt(uWin.style.left)+event.clientX-uintWinPreX,y=parseInt(uWin.style.top)+event.clientY-uintWinPreY;
			if(x>0&&y>0&&x<document.documentElement.clientWidth-uWinWidth&&y<document.documentElement.clientHeight-uWinHeight)
				uWin.style.left=String(x)+'px',uWin.style.top=String(y)+'px';
			uintWinPreX=event.clientX,uintWinPreY=event.clientY;
		}
		try
		{
			window.getSelection().removeAllRanges();
 		}
		catch(ex)
		{
			document.selection.empty();
		}
	}
	else
		uintWinPreX=uintWinPreY=0;
}

