var _topLayer=null;
//---拖放操作函数封装
var isIE = (document.all) ? true : false;
var _$ = function (id) {
	return "string" == typeof id ? document.getElementById(id) : id;
};
var Class = {
	create: function() {
		return function() { this.initialize.apply(this, arguments); }
	}
};
var Extend = function(destination, source) {
	for (var property in source) {
		destination[property] = source[property];
	}
};
var Bind = function(object, fun) {
	return function() {
		return fun.apply(object, arguments);
	}
};
var BindAsEventListener = function(object, fun) {
	return function(event) {
		return fun.call(object, (event || window.event));
	}
};
var CurrentStyle = function(element){
	return element.currentStyle || document.defaultView.getComputedStyle(element, null);
};
function addEventHandler(oTarget, sEventType, fnHandler) {
	if (oTarget.addEventListener) {
		oTarget.addEventListener(sEventType, fnHandler, false);
	} else if (oTarget.attachEvent) {
		oTarget.attachEvent("on" + sEventType, fnHandler);
	} else {
		oTarget["on" + sEventType] = fnHandler;
	}
};
function removeEventHandler(oTarget, sEventType, fnHandler) {
    if (oTarget.removeEventListener) {
        oTarget.removeEventListener(sEventType, fnHandler, false);
    } else if (oTarget.detachEvent) {
        oTarget.detachEvent("on" + sEventType, fnHandler);
    } else { 
        oTarget["on" + sEventType] = null;
    }
};
function getDirection(el,ev) {
	if(el.childNodes(1).style.display=="none")
		return"";
	var xPos, yPos, offset, dir;
	dir = "";
	xPos = ev.clientX;
	yPos = ev.clientY;
	offset = 4; //The distance from the edge in pixels
	if (yPos<el.offsetTop+offset) dir += "n";
	else if ( yPos > el.offsetTop+el.offsetHeight-offset) dir += "s";
	if (xPos<el.offsetLeft+offset) dir += "w";
	else if (xPos > el.offsetLeft+el.offsetWidth-offset) dir += "e";
	if(dir)
		el.style.cursor = dir+"-resize";
	else
		el.style.cursor = "default";
	return dir;
};
//拖放程序
var WebWinDrag = Class.create();
WebWinDrag.prototype = {
  //拖放对象
  initialize: function(drag, options) {
	this.Drag = _$(drag);//拖放对象
	this._x = this._y = 0;//记录鼠标相对拖放对象的位置
	this._marginLeft = this._marginTop = 0;//记录margin
	//事件对象(用于绑定移除事件)
	this._fM = BindAsEventListener(this, this.Move);
	this._fS = Bind(this, this.Stop);
	this.SetOptions(options);
	this.Limit = !!this.options.Limit;
	this.mxLeft = parseInt(this.options.mxLeft);
	this.mxRight = parseInt(this.options.mxRight);
	this.mxTop = parseInt(this.options.mxTop);
	this.mxBottom = parseInt(this.options.mxBottom);
	
	this.LockX = !!this.options.LockX;
	this.LockY = !!this.options.LockY;
	this.Lock = !!this.options.Lock;
	
	this.onStart = this.options.onStart;
	this.onMove = this.options.onMove;
	this.onStop = this.options.onStop;
	
	this._Handle = _$(this.options.Handle) || this.Drag;
	this._mxContainer = _$(this.options.mxContainer) || null;
	
	this.Drag.style.position = "absolute";
	this.dir="";
	//透明
	if(isIE && !!this.options.Transparent){
		//填充拖放对象
		with(this._Handle.appendChild(document.createElement("div")).style){
			width = height = "100%"; backgroundColor = "#fff"; filter = "alpha(opacity:0)";
		}
	}
	//修正范围
	this.Repair();
	addEventHandler(this._Handle, "mousedown", BindAsEventListener(this, this.Start));
	if(this.Drag.idx>0)
	addEventHandler(this._Handle, "mousemove", BindAsEventListener(this, this.preMove));
  },
  //设置默认属性
  SetOptions: function(options) {
	this.options = {//默认值
		Handle:			"",//设置触发对象（不设置则使用拖放对象）
		Limit:			false,//是否设置范围限制(为true时下面参数有用,可以是负数)
		mxLeft:			0,//左边限制
		mxRight:		9999,//右边限制
		mxTop:			0,//上边限制
		mxBottom:		9999,//下边限制
		mxContainer:	"",//指定限制在容器内
		LockX:			false,//是否锁定水平方向拖放
		LockY:			false,//是否锁定垂直方向拖放
		Lock:			false,//是否锁定
		Transparent:	false,//是否透明
		onStart:		function(){},//开始移动时执行
		onMove:			function(){},//移动时执行
		onStop:			function(){}//结束移动时执行
	};
	Extend(this.options, options || {});
  },
  //准备拖动
  Start: function(oEvent) {
	if(this.Lock){ return; }
	this.Repair();
	//记录鼠标相对拖放对象的位置
	this._x = oEvent.clientX - this.Drag.offsetLeft;
	this._y = oEvent.clientY - this.Drag.offsetTop;
	
	//记录鼠标当前位置
	this._mx=oEvent.clientX;
	this._my=oEvent.clientY;
	//记录margin
	this._marginLeft = parseInt(CurrentStyle(this.Drag).marginLeft) || 0;
	this._marginTop = parseInt(CurrentStyle(this.Drag).marginTop) || 0;
	//mousemove时移动 mouseup时停止
	addEventHandler(document, "mousemove", this._fM);
	addEventHandler(document, "mouseup", this._fS);
	if(isIE){
		//焦点丢失
		addEventHandler(this._Handle, "losecapture", this._fS);
		//设置鼠标捕获
		this._Handle.setCapture();
	}else{
		//焦点丢失
		addEventHandler(window, "blur", this._fS);
		//阻止默认动作
		oEvent.preventDefault();
	};
	if(this.Drag.ext_win.idx>0)
	{
		this.dir=getDirection(this.Drag,oEvent);
		if(this.dir)
		{
			//this.Drag.childNodes(3).style.border="#ff0000 dotted 1px"
			_dragDiv.style.left=this.Drag.style.left;
			_dragDiv.style.top=this.Drag.style.top;
			_dragDiv.style.width=this.Drag.style.width;
			_dragDiv.style.height=this.Drag.style.height;
			_dragDiv.style.zIndex=this.Drag.style.zIndex+1;
			_dragDiv.style.display="block";
		}
	}
	//
	//附加程序
	this.onStart();
  },
  //修正范围
  Repair: function() {
	if(this.Limit){
		//修正错误范围参数
		this.mxRight = Math.max(this.mxRight, this.mxLeft + this.Drag.offsetWidth);
		this.mxBottom = Math.max(this.mxBottom, this.mxTop + this.Drag.offsetHeight);
		//如果有容器必须设置position为relative来相对定位，并在获取offset之前设置
		!this._mxContainer || CurrentStyle(this._mxContainer).position == "relative" || (this._mxContainer.style.position = "relative");
	}
  },
  preMove:function(oEvent)
  {
	  if(!this.Drag.draging)
		  getDirection(this.Drag,oEvent)
  },
  //拖动
  Move: function(oEvent) {
	 this.Drag.draging=true;
	//判断是否锁定
	if(this.Lock){ this.Stop(); return; };
	//清除选择
	window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
	if(this.dir=="")
	{
		//设置移动参数
		var iLeft = oEvent.clientX - this._x, iTop = oEvent.clientY - this._y;
		//设置范围限制
		var mxLeft = this.mxLeft, mxRight = this.mxRight, mxTop = this.mxTop, mxBottom = this.mxBottom;
		if(this.Limit){
			//如果设置了容器，再修正范围参数
			if(!!this._mxContainer){
				mxLeft = Math.max(mxLeft, 0);
				mxTop = Math.max(mxTop, 0);
				mxRight = Math.min(mxRight, this._mxContainer.clientWidth);
				mxBottom = Math.min(mxBottom, this._mxContainer.clientHeight);
			};
			//修正移动参数
			iLeft = Math.max(Math.min(iLeft, mxRight - this.Drag.offsetWidth), mxLeft);
			iTop = Math.max(Math.min(iTop, mxBottom - this.Drag.offsetHeight), mxTop);
			
		}
		else
		{
			mxLeft =  30-this.Drag.offsetWidth;
			mxTop = 30-this.Drag.clientHeight;
			mxRight =document.body.clientWidth+this.Drag.offsetWidth-30;
			mxBottom =document.body.clientHeight+this.Drag.clientHeight-30;
			//修正移动参数
			iLeft = Math.max(Math.min(iLeft, mxRight - this.Drag.offsetWidth), mxLeft);
			iTop = Math.max(Math.min(iTop, mxBottom - this.Drag.offsetHeight), mxTop);
			
		}
		//设置位置，并修正margin
		if(!this.LockX){ this.Drag.style.left = iLeft - this._marginLeft + "px"; }
		if(!this.LockY){ this.Drag.style.top = iTop - this._marginTop + "px"; }
	}
	else //改变大小
	{
		var extWid,extHi;
		if(this.dir.indexOf("w")!=-1)
		{
			extWid= this._mx-oEvent.clientX;
			_dragDiv.style.left=_dragDiv.offsetLeft-extWid;
			_dragDiv.style.width=Math.max(160,_dragDiv.offsetWidth+extWid);
			this._mx=oEvent.clientX;
		}
		if( this.dir.indexOf("e")!=-1)
		{
			extWid= oEvent.clientX-this._mx;
			_dragDiv.style.width=Math.max(160,_dragDiv.offsetWidth+extWid);
			this._mx=oEvent.clientX;
		}
		if(this.dir.indexOf("n")!=-1)
		{
			extHi= this._my-oEvent.clientY;
			_dragDiv.style.top=_dragDiv.offsetTop-extHi;
			_dragDiv.style.height =Math.max(100,_dragDiv.offsetHeight+extHi);
			this._my=oEvent.clientY;
		}
		if(this.dir.indexOf("s")!=-1)
		{
			extHi= oEvent.clientY-this._my;
			_dragDiv.style.height =Math.max(100,_dragDiv.offsetHeight+extHi);
			this._my=oEvent.clientY;
		}
}
	//附加程序
	this.onMove();
  },
  //停止拖动
  Stop: function() {
	  this.Drag.draging=false;
	//移除事件
	removeEventHandler(document, "mousemove", this._fM);
	removeEventHandler(document, "mouseup", this._fS);
	if(isIE){
		removeEventHandler(this._Handle, "losecapture", this._fS);
		this._Handle.releaseCapture();
	}else{
		removeEventHandler(window, "blur", this._fS);
	};
	if(this.dir)//改变大小
	{
		this.Drag.ext_win.resize({
								 left:_dragDiv.offsetLeft,
								 top:_dragDiv.offsetTop,
								 width:_dragDiv.offsetWidth,
								 height:_dragDiv.offsetHeight});
		_dragDiv.style.display="none";
	}
	//附加程序
	this.onStop();
  }
};
//webBtn
webBtn =  function (btnText,clickFunc,pwin)
{
	
	this.btnText=btnText;
	this._clkFunc=clickFunc;
	this.ext_win=pwin;
	this.createBtnTable();
};
webBtn.prototype.createBtnTable=function()
{
	var tab=document.createElement("table");
	tab.className="webBtn";
	tab.cellPadding=0;
	tab.cellSpacing=0;
	
	var trObj=tab.insertRow();
	var tdObj=trObj.insertCell();
		tdObj.id="btn-left";
		
		tdObj=trObj.insertCell();
		tdObj.id="btn-mid";
		tdObj.align="center";
		tdObj.noWrap =true;
		tdObj.innerHTML="<a class='btn-a' href='#' onclick='return false'>"+this.btnText+"</a>";
		tdObj=trObj.insertCell();
		tdObj.id="btn-right";
	
	var btnRow=this.ext_win.divDlg.all("_extBtn");
	if(btnRow.childNodes.length>0)
		btnRow.insertBefore(tab,btnRow.childNodes(0));
	else
		btnRow.insertBefore(tab);
	this.tab=tab;
	this.tab.attachEvent("onmouseover", BindAsEventListener(this, this.onMouseOver));
	this.tab.attachEvent("onmouseout",BindAsEventListener(this, this.onMouseOut));
	this.tab.attachEvent("onmousedown",BindAsEventListener(this, this.onMouseDown));
	this.tab.attachEvent("onclick",BindAsEventListener(this, this.onClick));
};
webBtn.prototype.onMouseOver=function(ev)
{
	this.tab.className="webBtnOver";
	ev.cancelBubble = true;
};
webBtn.prototype.onMouseOut=function(ev)
{
	this.tab.className="webBtn";
	ev.cancelBubble = true;
};
webBtn.prototype.onMouseDown=function(ev)
{
	this.tab.className="webBtnDown";
	this.tab.rows(0).cells(1).childNodes(0).focus();
	ev.cancelBubble = true;
};
webBtn.prototype.onClick=function(ev)
{
	this._clkFunc();
	ev.cancelBubble = true;
};
webBtn.prototype.getText=function()
{
	return this.tab.rows(0).cells(1).innerText;
};
//-----------------------


var _progWin=null;
function webTips(msg)
{
	
	var tit="";
	var tipsMsg="";
	tit="提示信息";
var tipsMsg="<table cellpadding=4 cellspacing=0 height=100% width=100% style='padding-top:8px ' border=0  ><tr><td width=45 valign=top><img src='/lib/webWin/img/smile.gif' align=left style='padding:4px'></td><td class='tipsMsg' style='padding:12px'>"+msg+"</td></tr></table>";
	var tipsWin=createExtMsg(tit,300,120);
	tipsWin.divDlg.childNodes(1).style.tableLayout ="";
	var dlgFm=tipsWin.divDlg.all("_extDlgFm");
	dlgFm.innerHTML=tipsMsg;
	tipsWin.divDlg.all("close").style.display="block";
	if(tipsWin.visible)
		tipsWin.hide();
	tipsWin.addButton("确定","ext_msg.hide()");
	tipsWin.show();
	tipsWin.resize({width:dlgFm.offsetWidth+4});
	_progWin=null;
	return;
};

function webAlert(msg)
{
	var tit="";
	var tipsMsg="";
	tit="出错啦！！！";
var tipsMsg="<table cellpadding=4 cellspacing=0 height=100% width=100% style='padding-top:8px ' border=0  ><tr><td width=45 valign=top><img src='/lib/webWin/img/cry.gif' align=left style='padding:4px'></td><td class='tipsMsg' style='padding:12px'>"+msg+"</td></tr></table>";	
	var tipsWin=createExtMsg(tit,300,120);
	var dlgFm=tipsWin.divDlg.all("_extDlgFm");
	tipsWin.divDlg.childNodes(1).style.tableLayout ="";
	dlgFm.innerHTML=tipsMsg;
	
	tipsWin.divDlg.all("close").style.display="block";
	if(tipsWin.visible)
		tipsWin.hide();
	tipsWin.addButton("确定","ext_msg.hide()");
	
	tipsWin.show();
	tipsWin.resize({width:dlgFm.offsetWidth+4});
	_progWin=null;
	return;
};

function showProgTips(tit,msg,_wid)
{
	var tipsMsg="";
	var tipsMsg="<table cellpadding=0 cellspacing=0  border=0 height=100% width=100% ><tr ><td><table cellpadding=0 cellspacing=0  border=0 height=23 width=100%  bgcolor=#ffffff  style='border:1px solid #000000;'><tr ><td align=center style='position:relative;'><div id=_progBar style='border:none;width:0%;height:21px; position:absolute;left:0px;top:0px; background-image:url(/lib/webWin/img/bar_bg.gif);display:none'></div><div style='padding:4px;width:100%;height:23px;background:transparent; position:absolute;left:0px;top:0px;' ><img src='/lib/webWin/img/waiting.gif' align='absmiddle' style='padding-right:4px'><span id=_progMsg>"+msg+"</span></div></td></tr></table></td></tr></table>";
	var wid=350;
	if(_wid)
		wid=_wid;
		
	var tipsWin=createExtMsg(tit,wid,80);
	tipsWin.divDlg.childNodes(1).style.tableLayout ="fixed";
	var dlgFm=tipsWin.divDlg.all("_extDlgFm");
	dlgFm.innerHTML=tipsMsg;
	tipsWin.divDlg.all("close").style.display="none";
	if(tipsWin.visible)
		tipsWin.hide();
	tipsWin.show();
	_progWin=tipsWin;
	return;
};
function showProgBar(tit,msg,_wid)
{
	showProgTips(tit,msg,_wid);
}
function updateProgBar(tit,percent,msg)
{
	var per;
	if(_progWin==null)
		return;
	
	per=percent*100;
	if(per>100)
		per=100;
	_progWin.divDlg.childNodes(0).rows(0).cells(1).innerText=tit;
	var progBar=_progWin.divDlg.all("_progBar");
	if(percent=0)
		progBar.style.display="none";
	else
		progBar.style.display="block";
	progBar.style.width=per+"%";
	var _progMsg=_progWin.divDlg.all("_progMsg");
	_progMsg.innerText=msg;
};
function hideProgBar()
{
	try{ext_msg.hide();}catch(err){};
}
function hideProgTips()
{
	try{ext_msg.hide();}catch(err){};
}
var ext_msg=null;
function createExtMsg(tit,width,height)
{
	var dlgObj=_$("_extTipsDlg");
	dlgObj.childNodes(0).rows(0).cells(2).width=19;
	var extDlgFm=dlgObj.all("_extDlgFm");
	if(ext_msg==null)
	{
		ext_msg=new extWin(dlgObj,tit,"","",false,false,width,height,true);
	}
	else
	{
		ext_msg.clearButton();
		ext_msg.resetWin(tit,"","",false,false,width,height,true);
		
	}
	return ext_msg;
};

//winManager
extWinMgr=function(winNum)
{
	this.head=null;
	this.end=null;
	if(winNum)
		this.maxWinNum=winNum;
	else
		this.maxWinNum=50;
	this.winNum=1;
};
extWinMgr.prototype.add=function(win)
{
	if(this.end==null)
	{
		this.end=this.head=win;
		win.prev=win.next=null;
	}
	else
	{
		this.end.next=win;
		win.prev=this.end;
		win.next=null;
		this.end=win;
		
	}
};

extWinMgr.prototype.getExistExtWin=function(urlID)
{
	if(this.head==null)
		return null;
	var p=this.head;
	while(p!=null)
	{
		if(p.urlID==urlID)
			return p;
		p=p.next;
	}
	return null;
};

extWinMgr.prototype.getFreeWin=function()
{
	if(this.head==null)
		return null;
	var p=this.head;
	while(p!=null)
	{
		if(!p.visible)
			return p;
		p=p.next;
	}
	return null;
};

extWinMgr.prototype.getExtWinDiv=function()
{
	with(this)
	{
		if(winNum>=maxWinNum)
			return null;
		 var idx=winNum++;
 		 var tmpObj;
		tmpObj=_$("_extDlg_"+idx);
		if(tmpObj)
			return tmpObj;
			
		tmpObj=document.createElement("div");
		tmpObj.id="_extDlg_"+idx;
		tmpObj.idx=idx;
		tmpObj.style.position="absolute";
		tmpObj.style.display="none";
		tmpObj.className="webWin";
		tmpObj.innerHTML=_$("_extDlg").innerHTML;
		tmpObj.childNodes(0).rows(0).cells(2).width=19;
		tmpObj.childNodes(0).rows(0).cells(2).childNodes(0).className="collapse";
		tmpObj.childNodes(0).rows(0).cells(3).width=21;
		
		document.body.appendChild(tmpObj);
		tmpObj._dlgFm="_extDlgFm_"+idx;
		tmpObj.all("_extDlgFm").id=tmpObj._dlgFm;
		return tmpObj;
	}
};

extWinMgr.prototype.moveToTop=function(win)
{
	with(this)
	{
		if(end==win)
			return;
		if(head==win)
		{
			head=win.next;
			win.next.prev=null;
		}
		else
		{
			win.prev.next=win.next;
			win.next.prev=win.prev;
		}
		end.next=win;
		win.prev=end;
		win.next=null;
		end=win;
		return;
	}
};
extWinMgr.prototype.topWin=function()
{
	with(this)
	{
		if(end==null)
			return nul;
		var p=end;
		while(p!=null)
		{
			if(p.visible)
				return p;
			p=p.prev;
		}
		return null;
	}
};
extWinMgr.prototype.popWin=function()
{
	with(this)
	{
		if(end==null)
			return nul;
		var p=end;
		while(p!=null)
		{
			if(p.visible)
				return p;
			p=p.prev;
		}
		return null;
	}
};

extWinMgr.prototype.createWebWin=function(Inf)
{
	var ext_target,win;
	
	if(Inf.target)
		ext_target=Inf.target;
	else
	try
	{ext_target=main;}catch(Err){ext_target=mainFm.main;}

	var url=Inf.url;		
	var p=url.indexOf("?");
	var urlID=null;
	if(p==-1)
		urlID=url;
	else
		urlID=url.substring(0,p);
	urlID=urlID.replace("/","_");
	
	var extDlgFm=null;
	var dlgObj=null;
	var dt=null;
	var win=this.getExistExtWin(urlID);
	
	if(win)//已经存在
	{
		win.ext_target=ext_target;
		if(win.url!=url)
			win.dirty=true;
		else
			win.dirty=false;
		win.url=url;
		win.divDlg.childNodes(0).rows(0).cells(1).innerHTML=Inf.tit;
		win.clearButton();
	}
	else
	{
		
		dlgObj=this.getExtWinDiv();
		if(dlgObj==null)
		{
			win=this.getFreeExtWin();
			if(win==null)
				return null;
			win.dirty=true;
			win.clearButton();
			win.ext_target=ext_target;
			extDlgFm=win.divDlg.all(win._dlgFm);
			win.resetWin(Inf.tit,url,urlID,Inf.left,Inf.top,Inf.width,Inf.height,Inf.isModal);

		}
		else{//新建立
			var idx=0;
			
			idx=dlgObj.idx;
			extDlgFm=dlgObj.all(dlgObj._dlgFm);
			win=new extWin(dlgObj,Inf.tit,url,urlID,Inf.left,Inf.top,Inf.width,Inf.height,Inf.isModal);
			win.dirty=true;
			win.ext_target=ext_target;
			win.idx=idx;
			extDlgFm.ext_win=win;
			extDlgFm.ext_target=ext_target;
			win._dlgFm=dlgObj._dlgFm;
			win._dlgWin=extDlgFm.contentWindow;
			win.winMgr=this;
			this.add(win);		
		}
	}
	win.clearOnHide=false;
	return win;
};


var extTop=null;
var ext_WinMgr=new extWinMgr();
function createExtWin(tit,url,width,height,target,_isModalDialog)
{
	var isModalDialog=true;
	if(createExtWin.arguments.length>=6)
		isModalDialog=_isModalDialog;
	return ext_WinMgr.createWebWin(
			{
				tit:tit,
				url:url,
				width:width,
				height:height,
				target:target,
				isModal:isModalDialog
			}
						);

};
function createWebWin(inf)
{
	return ext_WinMgr.createWebWin(inf);
}
extWin =  function (divDlg,tit,url,urlID,_left,_top,width,height,_isModalDialog)
{
	//初始化成员
		this.dirty=true;
		this.idx=0;
		this.ext_target=window;
		this._dlgFm="";//frame的id
		this._dlgWin=null;//frame对应窗体
		this.dialog=null;
		this.showBtn=false;
		this.divDlg=divDlg;
		this.visible=false;
		this.buttonArr=null;
		this.buttonNum=0;
		this.prev=null;
		this.next=null;
		this.urlID=urlID;
	    this.url=url;
		this._isModalDialog=_isModalDialog;
		this.winMgr=null;
		this.clearOnHide=false;
		this.anchorIt=false;
		this.anchorX=0;
		this.anchorY=0;
		this.onHideFunc=null;
		
		divDlg.ext_win=this;
		var pos;
		var posArr;
		var left=_left;
		var top=_top;
		if(urlID!="")
		{
			pos=getExtPos(urlID);
			if(pos!=null)
			{
				posArr=pos.split(",");
				left=posArr[0];
				top:posArr[1];
			}
		}
		 else
		 	pos=null;

		this.dialog = new BasicDialog(divDlg, { 
			tit:tit,
			left:left,
			top:top,
			width:width,
			height:height,
			isModalDialog:_isModalDialog
			});
	if(!divDlg.drag)
	{
		divDlg.drag = new WebWinDrag(divDlg.id, { mxContainer: "", Handle: "", Limit: false,
		onStart: function(){divDlg.ext_win.show(true,true)},
		onMove: function(){},
		onStop: function(){}
			});
	}

};
extWin.prototype.resetWin=function(tit,url,urlID,_left,_top,width,height,_isModalDialog)
{
	this.urlID=urlID;
	this.url=url;
	this._isModalDialog=_isModalDialog;
	var pos;
	var left=_left;
	var top=_top;
	if(urlID!="")
	{
		pos=getExtPos(urlID);
		if(pos!=null)
		{
			posArr=pos.split(",");
			left=posArr[0];
			top:posArr[1];
		}
	}
	 else
		pos=null;
		
	this.dialog.reset( { 
			tit:tit,
			left:left,
			top:top,
			width:width,
			height:height,
			isModalDialog:_isModalDialog
		});
};
extWin.prototype.resize=function(inf)
{
	this.dialog.resize(inf);

};
extWin.prototype.move=function(left,top)
{
	this.resize({left:left,
				   top:top
				});

};

extWin.prototype.addButton=function(btnText,fnStr)
{
	for(var i=0;i<this.buttonNum;i++)
	{
		if(this.buttonArr[i].getText()==btnText)
			return;;
	}
	if(this.buttonArr==null)
		this.buttonArr=new Array();
		
	this.buttonArr[this.buttonNum]=new webBtn(btnText,function(){eval(fnStr);return false},this);
	this.buttonNum++;
	if(this.buttonNum==1)
	{
		this.divDlg.childNodes(1).rows(1).style.display="block";
		//this.resize({isModalDialog:this._isModalDialog})
		this.dialog.adjustBtnArea();
	}
	return this.buttonArr[this.buttonNum-1];
};
extWin.prototype.clearButton=function()
{
	this.divDlg.childNodes(1).rows(1).cells(1).innerHTML="";
	this.divDlg.childNodes(1).rows(1).style.display="none";
	this.buttonNum=0;
};

extWin.prototype.show=function(_noReload,_isOnfocus)
{
	var noReload=false,isOnfocus=false;
	switch(arguments.length)
	{
		case 2:
			isOnfocus=_isOnfocus;
		case 1:
			noReload=_noReload;
	}
	if(this.idx>0&&isOnfocus)
	{
		if(this.winMgr.topWin==this)//已经显示在顶层
			return;
		if(this._isModalDialog)//摸态窗口
			return;
	}
	this.visible=true;
	if(this.idx>0 )
	{
		if(!noReload || this.dirty) 
		{
			var extDlgFm=this.divDlg.all(this._dlgFm);
			extDlgFm.src="about:blank";
			extDlgFm.contentWindow.offscreenBuffering=true;
			var dt=new Date();
			var url=this.url;
			if(url.indexOf("?")>=0)
				url=url+"&_sID="+dt.getTime();
			else
				url=url+"?_sID="+dt.getTime();
			extDlgFm.src=url;
		}
		else
		{
			try{this._dlgWin.getWebWin();}catch(err){}
			}
	}
	if(this.winMgr && this.idx>0)
	{
		this.winMgr.moveToTop(this);
		extTop=this;
	}
	this.dirty=false;
	this.dialog.show();//this.showBtn.dom);
	
	
};
extWin.prototype.hide=function(isMan) //是否手工关闭
{
	var ext_win;
	this.visible=false;
	this.inUse=false;
	
	if(this.clearOnHide)
	{
		var extDlgFm=this.divDlg.all(this._dlgFm);
		extDlgFm.src="about:blank";
	}
	this.dialog.hide();
	
	try
	{
		if(this.onHideFunc)
			this.onHideFunc(isMan);
	}catch(err){}
	if(this.winMgr)
	{
		ext_win=this.winMgr.popWin();
		extTop=ext_win;
		//ext_win.show(true,false);
		if(ext_win!=null && ext_win.dialog.isModalDialog)
			_MM_showTopMask(ext_win.dialog._layer);	
	}
	else
	{
		extTop=null;
	}
	

};
function saveExtPos(dlgObj)
{
	var x= dlgObj._layer.style.pixelLeft;	
	var y= dlgObj._layer.style.pixelTop;
	SetCookie("ext_"+dlgObj.urlID,x+","+y);

};

function getExtPos(urlID)
{

	return GetCookie("ext_"+urlID);
	
};


BasicDialog=function (dlg,inf)
{
	var left,top,wid,hi;
	this.left=0;
	this.top=0;
	this.wid=inf.width;
	this.hi=inf.heigh;
	this._layer=dlg;
	this._layer.dlgObj=this;
	this.reset(inf);
};
BasicDialog.prototype.resize=function (inf)
{
	var left,top,wid,hi;
	with(this._layer)
	{
			wid=(inf.width?inf.width:this.wid);
			hi=(inf.height?inf.height:this.hi);
			if(wid>document.body.clientWidth-40)
				wid=document.body.clientWidth-40;
			if(hi>document.body.clientHeight-40)
				hi=document.body.clientHeight-40;
			left=(inf.left?inf.left:(document.body.clientWidth-wid)/2);
			top=(inf.top?inf.top:(document.body.offsetHeight-hi)/3);
			if(left<0)
				left=0;
			if(top<0)
				top=0;				
	}
	this.width=wid;
	this.hi=hi;
	this.left=left;
	this.top=top;

	with(this._layer)
	{
		style.left=left;
		style.top=top;
		if(childNodes(1).style.display=="none")
				return;
		style.width=wid;
		style.height=hi;
		with(childNodes(0))
		{
			style.left=0;
			style.top=0;
			style.width=wid;
			style.height=25;
			if(inf.tit)
				rows(0).cells(1).innerHTML=inf.tit;
		}
		with(childNodes(1))
		{
				var DlgFm=null;
				style.left=0;
				style.top=0;
				
				style.width=wid;
				style.height=hi-25-12;
				dlgFm=all(this._layer._dlgFm);
				dlgFm.style.width=dlgFm.parentElement.clientWidth;
				
				if( rows(1).style.display=="block")
					dlgFm.style.height=hi-25-12-7-30;
				else
					dlgFm.style.height=hi-25-12-7;
		}
		
		with(childNodes(2))
		{
				style.left=0;
				style.top=0;
				style.width=wid;
				style.height=12;
		}
		with(childNodes(3))
		{
				style.top=0;
				style.width=wid;
				style.height=hi;
		}
	}
};
BasicDialog.prototype.adjustBtnArea=function ()
{
	with(this._layer.childNodes(1))
	{	
		var dlgFm=all(this._layer._dlgFm);
		if( rows(1).style.display=="block")
			dlgFm.style.height=this.hi-25-12-7-30;
		else
			dlgFm.style.height=this.hi-25-12-7;	
	}
};
BasicDialog.prototype.reset=function (inf)
{
	this.resize(inf);
    if(inf.isModalDialog)
		this.isModalDialog=inf.isModalDialog;
	else
		this.isModalDialog=false;

};
BasicDialog.prototype.adjustWin=function()
{
	with(this._layer)
	{
		if(offsetLeft+offsetWidth>document.body.clientWidth)
			style.left=document.body.clientWidth-offsetWidth;
		if(offsetTop+offsetHeight>document.body.clientHeight)
			style.top=document.body.clientHeight-offsetHeight;
			
	}

};
BasicDialog.prototype.show=function(_isOnfocus)
{
	var isOnFocus=false;
	if(arguments.length==1)
		isOnfocus=_isOnfocus;
	if(_topLayer!=null)
	{
	 	if(_topLayer!=this._layer)
			this._layer.style.zIndex=_topLayer.style.zIndex-0+2;
	}
	else
		this._layer.style.zIndex=10;

	_topLayer=this._layer;	
	
    if(this.isModalDialog)
		_MM_showTopMask(this._layer);	
	this._layer.style.display="block";
	this._layer.style.visibility="visible";

  
   if(this._layer.idx>0 && !isOnFocus )//重画窗口
   {
		var dlgFm=this._layer.all(this._layer._dlgFm);
		dlgFm.style.width=dlgFm.parentElement.clientWidth;
		dlgFm.style.height=dlgFm.parentElement.clientHeight-7;
   }
};
BasicDialog.prototype.hide=function()
{
	this.adjustWin();
	var _winObj=this._layer.childNodes(1);
	if(_winObj.style.display=='none')
		_MM_collapseWin(this._layer);
	if(this._layer.style.display!="none")
		saveExtPos(this);
	this._layer.style.display="none";
	this._layer.style.visibility="hidden";
    if(this.isModalDialog)
	{
		 var topMask=_$("_topMask");
 		 topMask.style.display="none";

	}
	
};
function _MM_collapseWin(_winObj)
{
	var _layerObj=_winObj;
	while(_layerObj.className!="webWin")
		_layerObj=_layerObj.parentElement;
	with(_layerObj)
	{
		if(childNodes(1).style.display!="none")
		{
			childNodes(0).rows(0).cells(2).childNodes(0).className="collapse_a";
			childNodes(1).style.display="none";
			childNodes(2).style.display="none";
			childNodes(3).style.height=childNodes(0).offsetHeight;
			if(_layerObj.ext_win.anchorIt)
				_layerObj.ext_win.move(_layerObj.ext_win.anchorX,_layerObj.ext_win.anchorY);
		}
		else
		{
			childNodes(0).rows(0).cells(2).childNodes(0).className="collapse";
			childNodes(1).style.display="block";
			childNodes(2).style.display="block";
			childNodes(3).style.height=childNodes(0).offsetHeight+childNodes(1).offsetHeight+childNodes(2).offsetHeight;
			if(_layerObj.ext_win.anchorIt)
				_layerObj.ext_win.move(_layerObj.ext_win.anchorX,_layerObj.ext_win.anchorY-_layerObj.ext_win.dialog.hi);
			
			
		}
	}
};
function _MM_closeWin(_winObj)
{
	var _layerObj=_winObj;
	while(_layerObj.className!="webWin")
		_layerObj=_layerObj.parentElement;
	_layerObj.ext_win.hide(true);
};

function _MM_showTopMask(pLayer){ 
     var topMask=_$("_topMask");
	 with(topMask)
	 {
		 style.width=document.body.clientWidth+"px";
		 style.height=document.body.clientHeight+"px";
		 style.filter ="progid:DXImageTransform.Microsoft.Alpha(Opacity																=12)";
	
		 style.zIndex=pLayer.style.zIndex-1; 
		 pLayer.mzIndex=style.zIndex;
		 pLayer.mzDisplay=style.display;
		 style.display="block";
	 }
	 
} ;
function _MM_hideTopMask(pLayer){ 
    var topMask=_$("_topMask");
	with(topMask)
	{
	 	style.zIndex= pLayer.mzIndex;
   		style.display=pLayer.mzDisplay;
	   if( style.display=="none")
   	      style.filter ="progid:DXImageTransform.Microsoft.Alpha(Opacity																=0)";
	}
}
