var _topLayer=null;
//---拖放操作函数封装
var isIE = (document.all) ? true : false;
var _$ = function (id) {
	return "string" == typeof id ? document.getElementById(id) : id;
};
////////////////////////////
WDrag=function(drag,options)
{
	this.Drag = _$(drag);//拖放对象
	this.dir="";
	this.Limit = !!options.Limit;
	this.caller= options.caller;//||null;
	this.Drag.style.position = "absolute";
	this.Repair();
	$(this.Drag).mousedown({caller:this},function(e){e.data.caller.Start(e);});
	$(this.Drag).bind("mousemove",{caller:this},this.moveMove);
	
}
WDrag.prototype.getDirection=function (el,ev) {

	if($(el).children()[1].style.display=="none")
		return "";
	
	var xPos, yPos, offset, dir;
	dir = "";
	xPos = ev.pageX;
	yPos = ev.pageY;
	var p=$(el).offset();
	
	offset = 8; //The distance from the edge in pixels
	if (yPos<p.top+offset) dir += "n";
	else if ( yPos > p.top+el.offsetHeight-offset) dir += "s";
	if (xPos<p.left+offset) dir += "w";
	else if (xPos > p.left+el.offsetWidth-offset) dir += "e";
	if(dir)
		el.style.cursor = dir+"-resize";
	else
		el.style.cursor = "default";
	//document.title="xPos="+xPos+" el.left="+(el.left)
	return dir;
};
WDrag.prototype.moveMove=function(e)
 {
	if(!e.data.caller.draging)
		  e.data.caller.getDirection(e.data.caller.Drag,e)
 }

  //修正范围
WDrag.prototype.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");
	}
  }
WDrag.prototype.Start=function(oEvent)
 {
	
	if(this.Lock){ return; }
	
	this.Repair();
	
	//记录对象位置
	var p=$(this.Drag).offset()
	this.x=p.left;
	this.y=p.top;
	
	//记录鼠标当前位置
	this._mx = oEvent.pageX;// - this.Drag.offsetLeft;
	this._my = oEvent.pageY;// - this.Drag.offsetTop;
	//记录鼠标相对拖放对象的位置
	this._x = this._mx-this.x 
	this._y =this._my-this.y 
	this.wid=$(this.Drag).width();
	this.hi=$(this.Drag).height();
	this.win_wid=$(document).width();
	this.win_hi=$(document).height();

	//alert("this._x="+this._x+" this._y="+this._y);
	this.Drag.draging=true;
//	$("#"+this.Drag.ext_win._dlgFm,this.Drag)[0].style.display="none"
	$(this.Drag).unbind("mousemove",this.moveMove);
	$(document).bind("mousemove",{caller:this},this.Move);
	$(document).bind("mouseup",{caller:this},this.Stop);
	if(isIE){
		//焦点丢失
		//addEventHandler(this._Handle, "losecapture", this._fS);
		$(this.Drag).bind("losecapture",{caller:this},this.Stop);
		//设置鼠标捕获
		this.Drag.setCapture();
		
		//window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);  

	}else{
		//焦点丢失
		$(window).bind("blur",{caller:this},this.Stop);
		//this.Drag.addEventListener("mousemove",moveing,true);
		//阻止默认动作
		oEvent.preventDefault();
	};
	$(this.Drag).children()[4].style.display=""
	if(!this.Drag.ext_win.dialog.isModalDialog)
		_MM_showTopMask(this.Drag,true);	
	this.dir=this.getDirection(this.Drag,oEvent);
	if(this.dir=="")//移动
		this.Drag.style.cursor="move"
	else
	{
		_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="";
	}
	var maskDiv=$(this.Drag).children()[4];
	maskDiv.style.width=this.Drag.style.width;
	maskDiv.style.height=this.Drag.style.height;
	
	if(this.caller)try{this.caller.onDragStart()}catch(err){};

  }
 WDrag.prototype.Move=function(oEvent) 
 {
	 var dragger=oEvent.data.caller;
	dragger.Drag.draging=true;
	
	//判断是否锁定
	if(dragger.Lock){ dragger.Stop(); return; };
	//清除选择
	window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();

    var iLeft, iTop;
	
	if(dragger.dir=="")//拖动
	{
		iLeft = oEvent.pageX - dragger._x, iTop = oEvent.pageY - dragger._y;
		
		var mxLeft  =30-dragger.wid;
		var mxTop   =-15;//30-dragger.hi;//.clientHeight;
		var mxRight =dragger.win_wid+dragger.wid-30;
		var mxBottom=dragger.win_hi+dragger.hi-30;
		//修正移动参数
		iLeft = Math.max(Math.min(iLeft, mxRight - dragger.Drag.offsetWidth), mxLeft);
		iTop = Math.max(Math.min(iTop, mxBottom - dragger.Drag.offsetHeight), mxTop);
		//设置位置，并修正margin
		if(!dragger.LockX){  dragger.Drag.style.left = iLeft  + "px"; }
		if(!dragger.LockY){  dragger.Drag.style.top = iTop  + "px"; }

	}
	else //改变大小
	{
		var extWid,extHi;
		var wid,hi,p;
		if(isIE)
		{
			wid=_dragDiv.offsetWidth;
			hi=_dragDiv.offsetHeight;
			p={left:_dragDiv.offsetLeft,top:_dragDiv.offsetTop};
		}
		else
		{
			wid=$(_dragDiv).width();
			hi=$(_dragDiv).height();
			p=$(_dragDiv).offset();
		}
		
		if(dragger.dir.indexOf("w")!=-1)
		{
			extWid= dragger._mx-oEvent.pageX;
			_dragDiv.style.left=p.left-extWid;
			_dragDiv.style.width=Math.max(160,wid+extWid);
			dragger._mx=oEvent.pageX;
		}
		if( dragger.dir.indexOf("e")!=-1)
		{
			extWid= oEvent.pageX-dragger._mx;
			_dragDiv.style.width=Math.max(160,wid+extWid);
			dragger._mx=oEvent.pageX;
		}
		if(dragger.dir.indexOf("n")!=-1)
		{
			extHi= dragger._my-oEvent.pageY;
			_dragDiv.style.top=p.top-extHi;
			_dragDiv.style.height =Math.max(100,hi+extHi);
			dragger._my=oEvent.pageY;
		}
		if(dragger.dir.indexOf("s")!=-1)
		{
			extHi= oEvent.pageY-dragger._my;
			
			_dragDiv.style.height =Math.max(100,hi+extHi);
			dragger._my=oEvent.pageY;
		}
		
	}
	//附加程序
	if(dragger.caller)try{dragger.caller.onDragMove()}catch(err){};
	
  };
  WDrag.prototype.Stop=function(e) 
 { 
 
     var dragger=e.data.caller;
	// $("#"+dragger.Drag.ext_win._dlgFm,dragger.Drag)[0].style.display=""
	  dragger.Drag.draging=false;
	  $(dragger.Drag).children()[4].style.display="none"
	if(!dragger.Drag.ext_win.dialog.isModalDialog)
		  _MM_hideTopMask(dragger.Drag);	
		//移除事件
		$(dragger.Drag).bind("mousemove",{caller:dragger},dragger.moveMove);
		$(document).unbind("mousemove", dragger.Move);
		$(document).unbind( "mouseup", dragger.Stop);
		
		if(isIE){
			$(dragger.Drag).unbind( "losecapture", dragger.Stop);
			dragger.Drag.releaseCapture();
		}else{
			$(window).unbind( "blur", dragger.Stop);
		
		};

  	  var p=$(dragger.Drag).offset()
	  var x_diff=0,y_diff=0;
	  if(!dragger.LockX)
		  x_diff=(p.left-dragger.x);
	  else
	  	y_diff=(p.top-dragger.y);	  	
		
	if(dragger.dir)//改变大小
	{
		dragger.Drag.ext_win.resize({
								 left:_dragDiv.offsetLeft,
								 top:_dragDiv.offsetTop,
								 width:_dragDiv.offsetWidth,
								 height:_dragDiv.offsetHeight});
		_dragDiv.style.display="none";
	}
		
	 //附加程序
	
	 if(dragger.caller)try{dragger.caller.onDragEnd({x_diff:x_diff,y_diff:y_diff})} catch(err){};
  }
 ////////////////////////////////////////
//webChk
webChk=  function (btnText,clickFunc,pwin,chkVal,chkStat)
{
	this.btnText=btnText;
	this._clkFunc=clickFunc;
	this.ext_win=pwin;
	this.chkVal=chkVal;
	this.chkStat=chkStat;
	this.createWebChk();
};
webChk.prototype.createWebChk=function()
{
	var sp=document.createElement("span");
	sp.innerHTML="<input type=checkBox value='"+this.chkVal+"'><span onclick='previousSibling.click();return false' style='cursor:hand'>"+this.btnText+"</span>"

	var btnRow=this.ext_win.divDlg.all("_extBtn");
	if(btnRow.childNodes.length>0)
		btnRow.insertBefore(sp,btnRow.childNodes(0));
	else
		btnRow.insertBefore(sp);
	sp.className="webChk"
	sp.childNodes(0).attachEvent("onclick",BindAsEventListener(this, this.onClick));
	sp.childNodes(1).attachEvent("onmouseover", BindAsEventListener(this, this.onMouseOver));
	sp.childNodes(1).attachEvent("onmouseout",BindAsEventListener(this, this.onMouseOut));
	
	if(this.chkStat)
		sp.childNodes(0).checked=true;
	this.sp=sp;
}
webChk.prototype.getText=function()
{
	return this.sp.childNodes(1).innerText;
};
webChk.prototype.setText=function(btnText)
{
	this.btnText=btnText;
	this.sp.childNodes(1).innerText=btnText;
};
webChk.prototype.onClick=function(ev)
{
	this._clkFunc();
	ev.cancelBubble = true;
};
webChk.prototype.onMouseOver=function(ev)
{
	this.sp.childNodes(1).style.color="#ff0000";
	ev.cancelBubble = true;
};
webChk.prototype.onMouseOut=function(ev)
{
	this.sp.childNodes(1).style.color="#000000";
	ev.cancelBubble = true;
};


//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(-1);
	tdObj.id="btn-left";
	
	tdObj=trObj.insertCell(-1);
	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(-1);
	tdObj.id="btn-right";

	var btnRow=$("#_extBtn",this.ext_win.divDlg)[0];
    var c=$(btnRow).children();

	if(c.length>0)
		$(c[0]).before(tab);
	else
		$(btnRow).prepend(tab);
	
	this.tab=tab;
	$(tab).mouseover({caller:this},function(e)
		{
			e.data.caller.tab.className="webBtnOver";
			e.stopPropagation();
		})
	$(tab).mouseout({caller:this},function(e)
		{
			e.data.caller.tab.className="webBtn";
			e.stopPropagation();
		})
	$(tab).mousedown({caller:this},function(e)
		{
			e.data.caller.tab.className="webBtnDown";
			try{e.data.caller.tab.rows(0).cells(1).childNodes(0).focus()}catch(err){};
			e.stopPropagation();
		})
	$(tab).click({caller:this},function(e)
		{
			e.data.caller._clkFunc();
			e.stopPropagation();
			return false;
		})
};

webBtn.prototype.getText=function()
{
	return this.tab.rows(0).cells(1).innerText;
};
webBtn.prototype.setText=function(btnText)
{
	this.btnText=btnText;
	this.tab.rows(0).cells(1).innerText=btnText;
};
//-----------------------


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).children()[1].style.tableLayout ="";
	var dlgFm=$("#_extDlgFm",tipsWin.divDlg)[0];
	
	dlgFm.innerHTML=tipsMsg;
	$("#close",tipsWin.divDlg)[0].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=$("#_extDlgFm",tipsWin.divDlg)[0];
	tipsWin.divDlg.childNodes(1).style.tableLayout ="";
	dlgFm.innerHTML=tipsMsg;
	$("#close",tipsWin.divDlg)[0].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% style='margin-bottom:5px' ><tr ><td><table cellpadding=0 cellspacing=0   height=22 width=100%  bgcolor=#ffffff  style='border:1px solid #000000;table-layout:fixed;position:relative;'><tr ><td align=center style=''><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='width:100%;height:21px;background:transparent; position:relative;left:0px;top:0px;padding-top:2px' ><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).children()[1].style.tableLayout ="fixed";
	
	var dlgFm=$("#_extDlgFm",tipsWin.divDlg)[0];
	dlgFm.innerHTML=tipsMsg;
	
	$("#close",tipsWin.divDlg)[0].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;
	$("tr",_progWin.divDlg)[0].cells(1).innerText=tit;
	
	var progBar=$("#_progBar",_progWin.divDlg)[0];
	
	if(percent=0)
		progBar.style.display="none";
	else
		progBar.style.display="block";
	progBar.style.width=per+"%";
	var _progMsg=$("#_progMsg",_progWin.divDlg)[0];
	_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).children()[0].rows(0).cells(2).width=19;
	var extDlgFm=$("#_extDlgFm",dlgObj)[0];
	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;
		var tab=$(tmpObj).children()[0];
		tab.rows(0).cells(2).width=19;
		tab.rows(0).cells(2).childNodes(0).className="collapse";
		tab.rows(0).cells(3).width=21;
		
		document.body.appendChild(tmpObj);
		
		tmpObj._dlgFm="_extDlgFm_"+idx;
		
		$("#_extDlgFm",tmpObj)[0].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).children()[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._dlgFm,win.divDlg)[0];
			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._dlgFm,dlgObj)[0];
			
			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 _dargDiv=$("_dargDiv")[0];
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 WDrag(divDlg.id, {
								caller:this,
								mxContainer: "", 
								Limit: false,
		onStart: function(){divDlg.ext_win.show(true,true)},
		onMove: function(){},
		onStop: function(){}
			});
	}
	if($("#close",divDlg).length>0)
		$("#close",divDlg)[0].ext_win=this;
};
extWin.prototype.beginDrag=function(dif)
{
}

extWin.prototype.onDragStart=function(dif)
{/*
	if(this.divDlg.drag.dir)
	{
		_dragDiv.style.left=this.divDlg.style.left;
		_dragDiv.style.top=this.divDlg.style.top;
		_dragDiv.style.width=this.divDlg.style.width;
		_dragDiv.style.height=this.divDlg.style.height;
		_dragDiv.style.zIndex=this.divDlg.style.zIndex+1;
		_dragDiv.style.display="block";
	}
*/		
}
extWin.prototype.onDragMove=function(dif)
{
}
extWin.prototype.onDragEnd=function(dif)
{
}

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.addExtHTML=function(extHTML)
{
	var btnRow=$("#_extBtn",this.divDlg)[0];
//	if($("#extHTML_SP",btnRow).length>0)
		btnRow.insertAdjacentHTML("afterBegin","<span id='extHTML_SP'  style='clear:none;float:left;'>"+extHTML+"</span>");
}

extWin.prototype.addChkBtn=function(btnText,fnStr,chkVal,chkStat)
{
	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 webChk(btnText,function(){eval(fnStr);return false},this,chkVal,chkStat);
	this.buttonNum++;
	if(this.buttonNum==1)
	{
		this.divDlg.childNodes(1).rows(1).style.display="block";
		this.dialog.adjustBtnArea();
	}
	return this.buttonArr[this.buttonNum-1];		
}

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).children()[1].rows(1).style.display="";
		this.dialog.adjustBtnArea();

	}
	return this.buttonArr[this.buttonNum-1];
};
extWin.prototype.setButton=function(btnText,btnTextNew)
{
	for(var i=0;i<this.buttonNum;i++)
	{
		if(this.buttonArr[i].getText()==btnText)
		{
			this.buttonArr[i].setText(btnTextNew);
			return;
		}
	}
};
extWin.prototype.clearButton=function()
{
	var rItem=$(this.divDlg).children()[1].rows(1);
	rItem.cells(1).innerHTML="";
	rItem.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._dlgFm,this.divDlg)[0];//.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._dlgFm,this.divDlg)[0];// 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;
	
	var cNode=$(this._layer).children();
	
	with(this._layer)
	{
		style.left=left;
		style.top=top;
		if(cNode[1].style.display=="none")
			return;
		
		style.width=wid;
		style.height=hi;
		
		with(cNode[0])
		{
			style.left=0;
			style.top=0;
			style.width=wid;
			style.height=25;
			if(inf.tit)
				rows(0).cells(1).innerHTML=inf.tit;
		}
	
		
		var DlgFm=null;
		with(cNode[1])
		{
				style.left=0;
				style.top=0;
				
				style.width=wid;
				style.height=hi-25-12;
				if(this._layer._dlgFm)
				{
					dlgFm=$("#"+this._layer._dlgFm,cNode[1])[0];
					dlgFm.style.width=$(cNode[1]).width()-12;
					if( rows(1).style.display=="block")
						dlgFm.style.height=hi-25-12-7-30;
					else
						dlgFm.style.height=hi-25-12-7
				}
				
		}
		with(cNode[2])
		{
				style.left=0;
				style.top=0;
				style.width=wid;
				style.height=12;
		}
		
		with(cNode[3])
		{
				style.top=0;
				style.width=wid;
				style.height=hi;
		}
		if(DlgFm!=null)
			with(cNode[4])
			{
					style.top=25;
					style.left=6;
					style.width=dlgFm.style.width;
					style.height=dlgFm.style.height;
			}
		
		
	}
};
BasicDialog.prototype.adjustBtnArea=function ()
{
	if(!this._layer._dlgFm)
		return;
	var c=$(this._layer).children();
	with(c[1])
	{	
		var dlgFm=$("#"+this._layer._dlgFm)[0];
		if( rows(1).style.display!="none")
			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="";
	this._layer.style.visibility="visible";

  
   if(this._layer.idx>0 && !isOnFocus )//重画窗口
   {
		var dlgFm=$("#"+this._layer._dlgFm,this._layer)[0];//.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).children()[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;
	var cNode=$(_layerObj).children();
	with(_layerObj)
	{
		if(cNode[1].style.display!="none")
		{
			cNode[0].rows(0).cells(2).childNodes(0).className="collapse_a";
			cNode[1].style.display="none";
			cNode[2].style.display="none";
			cNode[4].style.height=cNode[3].style.height=childNodes(0).offsetHeight;
			cNode[4].style.display="none";
			if(_layerObj.ext_win.anchorIt)
				_layerObj.ext_win.move(_layerObj.ext_win.anchorX,_layerObj.ext_win.anchorY);
			//alert(_layerObj.outerHTML);
			_layerObj._hi=_layerObj.style.height
			_layerObj.style.height=childNodes(0).offsetHeight
		}
		else
		{
			cNode[0].rows(0).cells(2).childNodes(0).className="collapse";
			cNode[1].style.display="";
			cNode[2].style.display="";
			cNode[3].style.height=cNode[0].offsetHeight+cNode[1].offsetHeight+cNode[2].offsetHeight;
			cNode[4].style.display="";
			if(_layerObj.ext_win.anchorIt)
				_layerObj.ext_win.move(_layerObj.ext_win.anchorX,_layerObj.ext_win.anchorY-_layerObj.ext_win.dialog.hi);
			_layerObj.style.height=_layerObj._hi
			
		}
	}
};
function _MM_closeWin(_winObj)
{
	var _layerObj=_winObj;
	while(_layerObj.className!="webWin")
		_layerObj=_layerObj.parentElement;
	_layerObj.ext_win.hide(true);
};

function _MM_showTopMask(pLayer,isTransparent){ 
     var topMask=_$("_topMask");
	 var mask="";
	 with(topMask)
	 {
		 style.width=document.body.clientWidth+"px";
		 style.height=document.body.clientHeight+"px";
		 if(isTransparent)
			 className="top_mask";
		 else
		 	className="top_unmask";
		 style.zIndex=pLayer.style.zIndex-1; 
		 pLayer.mzIndex=style.zIndex;
		 pLayer.mzDisplay=style.display;
		 style.display="";
		 style.filter ="progid:DXImageTransform.Microsoft.Alpha(Opacity=10)";			 
	 }
} ;
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)";
	}
}
//WTips
var _tipsTab='<table  width="100%"  cellspacing="0" cellpadding="0" style="table-layout:fixed;border:1px solid #98C0F4;" id="msgTab" border=0 ><colgroup><col><col width=20></colgroup><tr><td  height="23" background="/lib/webWin/tipImg/bar_bg.gif">&nbsp;友情提示</td><td background="/lib/webWin/tipImg/bar_bg.gif"  align="center"  ><img id="_tipClose" src="/lib/webWin/tipImg/close.gif" onMouseOver="this.src=\'/lib/webWin/tipImg/close_on.gif\'" onMouseOut="this.src=\'/lib/webWin/tipImg/close.gif\'"  style="cursor:hand"></td></tr><tr><td valign="top" colspan=2 bgcolor=#efefef id=_tipsMsg style="padding:2px"></td></tr></table>'

WTips=function()
{
	this._div=null;
	this._timer=null;
	this._interval=null;
	this.step=2;
	this.top=0;
	this.bottom=20;
	this.hi=0;

}
WTips.prototype.init=function(wid,hi,msg)
{
	this.top=$(window).height()-hi-this.bottom;
	this.hi=hi;
	var _div=null;
	if(this._div==null)
	{
		 _div=document.createElement("div");
		_div.id="_wTipsDiv";
		//_div.style.backgroundColor ="#ff0000";
		_div.style.borderStyle  ="none";
		_div.style.width=wid;
		_div.style.height=this.bottom;
		_div.style.display="none";
		_div.style.overflow ="hidden";
		_div.style.position="absolute";
		_div.innerHTML=_tipsTab
		document.body.appendChild(_div);
		$("#msgTab",_div)[0].style.height=hi;
		$("#_tipClose",_div).bind("click",{wSort:this},function(e){
			e.data.wSort.hide();
			}
		)
		this._div=_div;		
	}
	else
	{
		if(this._timer!=null)
		{
			clearTimeout(this._timer);	
			this._timer=null
		}
		if(this._interval!=null)
			clearInterval(wTip._interval);
		 _div=this._div;
		_div.style.width=wid;
		_div.style.height=this.bottom;
		_div.style.display="none";
		$("#msgTab",_div)[0].style.height=hi;
	}
	$("#_tipsMsg",_div)[0].innerHTML=msg;
	var layer_wid= $(_div).width()
	var left=$(window).width()-layer_wid-5	;
	this._div.style.top=$(window).height()-this.bottom;
	this._div.style.left=left;
}
WTips.prototype.moveUp=function(wTip)
{
	var p=$(wTip._div).position();
	var y=p.top;
	if(y-wTip.step<wTip.top)
	{
		y=this.top;//移动到位，延期隐藏
		wTip._div.style.top=y;
		wTip._div.style.height=this.hi;
		clearInterval(wTip._interval);
		this._interval=null;
		this._timer=setTimeout(function(){wTip.hide()},10000);
	}
	else
	{
		y=y-wTip.step;
		wTip._div.style.top=y;
		wTip._div.style.height=$(wTip._div).height()-0+wTip.step;
	}
}
WTips.prototype.moveDown=function(wTip)
{
	var p=$(wTip._div).position();
	var y=p.top;

	if(y+wTip.step>$(window).height()-1)
	{
		y=$(window).height();//移动到位，延期隐藏
		wTip._div.style.top=y;
		wTip._div.style.height=0;
		wTip._div.style.display="none"
		clearInterval(wTip._interval);
		this._interval=null;
	}
	else if(y+wTip.step+$(wTip._div).height()>$(window).height()-1)
	{
		y=y+wTip.step;
		wTip._div.style.top=y;
		wTip._div.style.height=$(window).height()-y-2;
	}
	else
	{
		y=y+wTip.step;
		wTip._div.style.top=y;
	
	}
}
WTips.prototype.show=function(msg,_wid,_hi)
{
	var wid=240,hi=120;
	if(_wid)
		wid=_wid;
	if(_hi)
		hi=_hi;
	this.mouseOn=true;
	this.init(wid,hi,msg);
	this._div.style.display="";
	var ss=this;
	this._interval=setInterval(function(){ss.moveUp(ss)},10);
}
WTips.prototype.hide=function()
{
	var ss=this;
	if(this._timer!=null)
	{
		clearTimeout(this._timer);	
		this._timer=null
	}
	if(this._interval!=null)
		clearInterval(wTip._interval);
	this._interval=setInterval(function(){ss.moveDown(ss)},10);
}
WTips.wTips=null;
WTips.tips=function(msg,wid,hi)
{
	if(WTips.wTips==null)
		WTips.wTips	=new WTips();
	WTips.wTips.show(msg,wid,hi);	
}
