//弹出框
//时间: 2009年1月2日15:40:31
//http://www.ilegal.cn
//使用方法：
//	function postevent(ev){
//	getADialog('addEvent',false,'hidden',true,false,true,466,'center','2','添加一个活动',ev);
//	$.get('ajax_add_event.php?ac=post',
//    function(data){
//	 document.getElementById('popue_box').innerHTML=data;//替换弹出框中的内容
//    }
//    );
//	}
//popup_top.png
//css/popup_middle.png
//css/popup_bottom.png
//images/close-x.gif
document.write('<img src="css/popup_top.png" style="display:none;" />');
document.write('<img src="css/popup_middle.png" style="display:none;" />');
document.write('<img src="css/popup_bottom.png" style="display:none;" />');
document.write('<img src="images/close-x.gif" style="display:none;" />');
var ___Dialog = new Array();//全局对话框对象
function getADialog(pAc,pLock,pLockMode,pShadowFlag,pResize,pDrag,pWidth,pAlign,pBotton,pTitle,pev){
	 var action = pAc;
	___Dialog[action] = new Dialog();
	___Dialog[action].DialogObject = "___Dialog['" + action + "']";
	___Dialog[action].DialogId += action;
	___Dialog[action].DialogLock = pLock;//锁定背景
	___Dialog[action].DialogLockMode = pLockMode;//iframe//hidden//覆盖select控件模式
	___Dialog[action].DialogShadowFlag = pShadowFlag;//渐变
	___Dialog[action].DialogResize = pResize;//可改变大小
	___Dialog[action].DialogDrag = pDrag;//允许移动
	___Dialog[action].DialogWidth = pWidth;
	___Dialog[action].DialogTop = -1;
	___Dialog[action].DialogLeft = -1;
	___Dialog[action].DialogAlign = pAlign;//位置
	___Dialog[action].DialogCtrl = pBotton;//按钮
	___Dialog[action].DialogTitle = pTitle;
	___Dialog[action].ShowDialog(pev, ___Dialog);//___Dialog\zIndex轴切换
	
}
function g_CloseDialog(opEvent){
	___Dialog[opEvent].CloseDialog();
}

function Dialog(){
	var _C = this;//当前实例
	
	this.ie = window.navigator.userAgent.indexOf("MSIE") != -1;
	
	this._DOC = "___DOC";//锁定document-DIV/ID后缀
	this._IFRAME = "___IFRAME";
	this._CONTEXT = "___CONTEXT";//内容DIV/ID
	this._CONTROL = "___CONTROL";//控制栏DIV/ID
	this._MAIN = "___MAIN";//内容显示区
	this._BUTTON = "___BUTTON";
	this._CTRLBTN = "___CTRLBTN";
	this._BAR = "___BAR";
	this._RESIZEBAR = "___RESIZEBAR";

	this.OffsX = 0;
	this.OffsY = 0;
	this.OffsDialog = {//窗体记录数据
			ss : false,//最大化
			sx : 0,
			sy : 0,
			ss2: false,//最小化
			hh : 0
	}
	
	this.DialogArray = null;//全局对话框对象备份
	this.DialogType = "panel";//类型panel,alert
	this.DialogLock = false;//锁定document
	this.DialogLockMode = "iframe";//iframe//hidden
	this.DialogTitle = "&nbsp;";
	this.DialogHtml = "";
	this.DialogBakHtml = "";//运行期直接改内容时有需要备份上次HTML
	this.DialogId = "___DialogObject";
	this.DialogTag = 0;//变量
	this.DialogParent = null;
	this.DialogShadowFlag = false;
	this.DialogShadowDelay = 5;
	this.DialogShadowInterval = this.ie?25:0.25;
	this.DialogAlpha = this.ie?100:1.0;
	this.DialogLockAlpha = this.ie?50:0.5;
	this.DialogDragAlpha = this.ie?75:0.75;
	this.ResizeIng = false;
	this.DialogResize = false;
	this.DragIng = false;
	this.DialogDrag = true;//允许移动
	this.DialogDragPixel = 5;//移动窗体象素
	this.DialogAlign = "auto";//center\auto{top/left/width/height}
	this.DialogTop = -1; // -1 自动判断 + 绝对位置
	this.DialogLeft = -1;
	this.DialogWidth = -1;
	this.DialogHeight = -1; // -1 自动 -2 body可见高度+自动  -3 body可见高度+绝对
	this.ScrollWidth = this.ie?0:20;//滚动条宽度
	this.DialogReAlign = true;//重置位置
	this.DialogzIndex = 100;//同一级别对话框需所有实例设为同一值
	this.DialogCtrl = "-1";//控制按钮 012
	this.DialogBar = true;
	this.DialogObject = "dialog1";
	this.DialogClose = ".CloseDialog()";
	this.DialogShadow = ".ShadowDialog()";
	this.DialogWinMax = ".WinMaxDialog(this)";
	this.DialogWinMin = ".WinMinDialog(this)";
	this.DialogSwitch = ".SwitchDialogzIndex(___Dialog, true)";
	//this.DialogCtrl0 = '<img src="js/dialog/dialog-min.gif" title="最小化" style="cursor:default" onclick="{[___DialogWinMin]}" />';
	//this.DialogCtrl1 = '<img src="js/dialog/dialog-max.gif" title="最大化/还原" style="cursor:default" onclick="{[___DialogWinMax]}" />';
	this.DialogCtrl2 = '<img src="images/close-x.gif" title="关闭" style="cursor:default" onclick="{[___DialogClose]}" />';
	this.DialogBox = '\
<div class="wPopup-beta png" onmousedown="{[___DialogSwitch]}" style="padding-LEFT: 12px;">\
<div class="header" id="{[___DialogBar]}">\
    <div class="popup-left" onmouseover="{[___DialogSwitch]}" id="{[___DialogControl]}" >\
    <div class="title_btn" style="text-align:right">\
	<span style="float:left">{[___DialogTitle]}</span>\
	<span id="{[___DialogCtrlButton]}">{[___DialogCtrlBtn]}</span>\
	</div>\
    </div>\
</div>\
<div class="content popup-content clearfix" id="{[___DialogMain]}">\
<div class="inner">\
{[___DialogTypeHtml]}\
</div>\
</div>\
<div class="footer">\
<div class="popup-left"></div>\
<div id="{[___DialogResizeBar]}" class="dialog_css7">&nbsp;</div>\
</div>\
</div>';
	this.DialogLoadIng = '\
						<div style="padding:5px 0 0" id="popue_box"><center><img src="image/my/loading.gif" /></center></div>';
	this.DialogPanel = '\
					  <div id="{[___DialogContext]}"></div>';
	this.DialogAlert = '\
					  <div id="{[___DialogContext]}"></div>\
					  <div style="padding:10px 5px 0" id="{[___DialogButton]}">\
					  <center><img src="js/dialog/dialog-cancel.gif" onclick="{[___DialogClose]}" /></center>\
					  </div>';
				
	//事件
	this.ShowDialog = function(ev, dl, parent){		
		
		var bpos = {
			sw : 0,
			sh : 0,
			cw : 0,
			ch : 0,
			sx : 0,
			sy : 0
		};

		var el = this.$(parent);

		if(el){

			this.DialogParent = parent;

			bpos = {
				sw : parseInt(el.offsetWidth),
				sh : parseInt(el.offsetHeight),
				cw : parseInt(el.offsetWidth),
				ch : parseInt(el.offsetHeight),
				sx : parseInt(el.offsetLeft),
				sy : parseInt(el.offsetTop)
			};
		}else{
			bpos = {
				//解决有无<!DOCTYPE html PUBLIC 得到的宽和高不同的bug
				sw : ((document.documentElement.scrollWidth==0)?document.body.scrollWidth:document.documentElement.scrollWidth),
				sh : ((document.documentElement.scrollHeight==0)?document.body.scrollHeight:document.documentElement.scrollHeight),
				cw : ((document.documentElement.clientWidth==0)?document.body.clientWidth:document.documentElement.clientWidth),
				ch : ((document.documentElement.clientHeight==0)?document.body.clientHeight:document.documentElement.clientHeight),
				sx : this.ie?((document.documentElement.scrollLeft==0)?document.body.scrollLeft:document.documentElement.scrollLeft):window.scrollX,
				sy : this.ie?((document.documentElement.scrollTop==0)?document.body.scrollTop:document.documentElement.scrollTop):window.scrollY
			};
		}
		if(dl){
			this.DialogArray = dl;
			this.SwitchDialogzIndex(false);//还原全部
		}
		
		var dialog = false;//对话框是否已经存在
		
		var ___DialogDoc = this.$(this.DialogId + this._DOC);//是否存在
		var ___Dialog = this.$(this.DialogId);
		if(___Dialog)dialog = true;
				
		if(!___DialogDoc)___DialogDoc = document.createElement("DIV");
		___DialogDoc.id = this.DialogId + this._DOC;
		
		if(this.DialogLock){
			with(___DialogDoc.style){
				position = "absolute";
				zIndex = this.DialogzIndex + 3;
				top = "0";
				left = "0";
				width = Math.max(document.body.scrollWidth, document.body.clientWidth) + "px";
				height = Math.max(document.body.scrollHeight, document.body.clientHeight)  + "px";
				backgroundColor = "#ffffff";//被注释的背景颜色的
				if(this.ie){
					filter = this.DialogShadowFlag ? "Alpha(Opacity=0)" : "Alpha(Opacity=" + this.DialogLockAlpha + ")";//0完全透明
				}else{
					MozOpacity = this.DialogShadowFlag ? 0.0 : this.DialogLockAlpha;//0.0完全透明
				}
			}
		}
		 
		if(!___Dialog)___Dialog = document.createElement("DIV");
		___Dialog.id = this.DialogId;
		//___Dialog.className = 'wPopup-beta png';
		
		with(___Dialog.style){
			position = "absolute";
			zIndex = this.DialogzIndex + 5;
			if(this.DialogWidth != -1)width = this.DialogWidth + "px";
//			backgroundColor = "#ffffff";
//			if(this.ie){
//				filter = this.DialogShadowFlag ? "Alpha(Opacity=0)" : "Alpha(Opacity=" + this.DialogAlpha + ")";
//			}else{
//				MozOpacity = this.DialogShadowFlag ? 0.0 : this.DialogAlpha;
//			}			
		}
		
		___DialogTypeHtml = this.DialogBox;

		switch(this.DialogType){
			case "alert":
				___DialogTypeHtml = ___DialogTypeHtml.replace(/\{\[___DialogTypeHtml\]\}/g, this.DialogAlert);			
				break;
			default:
				___DialogTypeHtml = ___DialogTypeHtml.replace(/\{\[___DialogTypeHtml\]\}/g, this.DialogPanel);
		}
		___DialogTypeHtml = ___DialogTypeHtml.replace(/\{\[___DialogControl\]\}/g, this.DialogId + this._CONTROL);
		
		var ___DialogCtrlBtn = "&nbsp;";
		var ___DialogCtrlBtn_Width = 0;
		if(this.DialogCtrl.indexOf("0") != -1){
			___DialogCtrlBtn += this.DialogCtrl0 + "&nbsp;";
			___DialogCtrlBtn_Width += 30;
		}
		if(this.DialogCtrl.indexOf("1") != -1){
			___DialogCtrlBtn += this.DialogCtrl1 + "&nbsp;";
			___DialogCtrlBtn_Width += 30;
		}
		if(this.DialogCtrl.indexOf("2") != -1){
			___DialogCtrlBtn += this.DialogCtrl2 + "&nbsp;";
			___DialogCtrlBtn_Width += 30;
		}
		___DialogTypeHtml = ___DialogTypeHtml.replace(/\{\[___DialogCtrlBtn\]\}/g, ___DialogCtrlBtn);
		___DialogTypeHtml = ___DialogTypeHtml.replace(/\{\[___DialogCtrlBtn_Width\]\}/g, ___DialogCtrlBtn_Width);
		___DialogTypeHtml = ___DialogTypeHtml.replace(/\{\[___DialogWinMin\]\}/g, this.DialogObject + this.DialogWinMin);
		___DialogTypeHtml = ___DialogTypeHtml.replace(/\{\[___DialogWinMax\]\}/g, this.DialogObject + this.DialogWinMax);
		___DialogTypeHtml = ___DialogTypeHtml.replace(/\{\[___DialogMain\]\}/g, this.DialogId + this._MAIN);
		___DialogTypeHtml = ___DialogTypeHtml.replace(/\{\[___DialogContext\]\}/g, this.DialogId + this._CONTEXT);
		___DialogTypeHtml = ___DialogTypeHtml.replace(/\{\[___DialogClose\]\}/g, this.DialogObject + this.DialogClose);
		___DialogTypeHtml = ___DialogTypeHtml.replace(/\{\[___DialogSwitch\]\}/g, this.DialogArray ? this.DialogObject + this.DialogSwitch : "javascript:void(0)");		

		___DialogTypeHtml = ___DialogTypeHtml.replace(/\{\[___DialogCtrlButton\]\}/g, this.DialogId + this._BUTTON);		
		___DialogTypeHtml = ___DialogTypeHtml.replace(/\{\[___DialogButton\]\}/g, this.DialogId + this._CTRLBTN);		
		___DialogTypeHtml = ___DialogTypeHtml.replace(/\{\[___DialogBar\]\}/g, this.DialogId + this._BAR);		
		___DialogTypeHtml = ___DialogTypeHtml.replace(/\{\[___DialogResizeBar\]\}/g, this.DialogId + this._RESIZEBAR);		

		___DialogTypeHtml = ___DialogTypeHtml.replace(/\{\[___DialogTitle\]\}/g, this.DialogTitle);		

		___Dialog.innerHTML = ___DialogTypeHtml;	
		
		document.body.appendChild(___Dialog);
		
		try{
			if(!this.DialogBar)this.$(this.DialogId + this._BAR).style.display = "none";
			if(!this.DialogResize)this.$(this.DialogId + this._RESIZEBAR).style.display = "none";
		}catch(e){}
		
		this.OffsDialog.hh = ___Dialog.offsetHeight - this.$(this.DialogId + this._MAIN).offsetHeight;
		
		if(this.DialogHtml == ""){
			this.$(this.DialogId + this._CONTEXT).innerHTML = this.DialogLoadIng;
		}else{
			this.$(this.DialogId + this._CONTEXT).innerHTML = this.DialogHtml;
		}
		
		if(this.DialogHeight == -2){
			if(this.$(this.DialogId + this._MAIN).offsetHeight > (document.body.clientHeight - this.OffsDialog.hh - this.ScrollWidth))
				this.$(this.DialogId + this._MAIN).style.height = (document.body.clientHeight - this.OffsDialog.hh - this.ScrollWidth) + "px";
		}else if(this.DialogHeight == -3){
			this.$(this.DialogId + this._MAIN).style.height = (document.body.clientHeight - this.OffsDialog.hh - this.ScrollWidth) + "px";
		}else if(this.DialogHeight == -1){
			//
		}else{
			this.$(this.DialogId + this._MAIN).style.height = this.DialogHeight + "px";
		}
		
		if(this.ie)this.$(this.DialogId + this._MAIN).style.width = "100%";//解决IE/FF兼容
		if(this.ie)this.$(this.DialogId + this._CONTEXT).style.width = "100%";//解决IE/FF兼容
		
		//完成___Dialog内容后
		if(!dialog || this.DialogReAlign){
			var ppos = this.GetDialogPos(ev, parent, ___Dialog, bpos);//得到最佳显示位置
			with(___Dialog.style){//调整位置
				if(this.DialogTop != -1)top = this.DialogTop + "px";
				else top = ppos.y + "px";
				if(this.DialogLeft != -1)left = this.DialogLeft + "px";
				else left = ppos.x + "px";
			}	
		}
		
		if(!this.DialogLock){
			with(___DialogDoc.style){
				position = "absolute";
				zIndex = this.DialogzIndex + 3;
				if(!dialog || this.DialogReAlign){
					top = ___Dialog.style.top;
					left = ___Dialog.style.left;
				}
				width = ___Dialog.offsetWidth + "px";
				height = ___Dialog.offsetHeight + "px";
				if(this.ie){
					filter = "Alpha(Opacity=0)";//0完全透明
				}else{
					MozOpacity = 0.0;//0.0完全透明
				}
			}
		}
		document.body.appendChild(___DialogDoc);
		
		if(this.ie){
			if(this.DialogLockMode == "iframe"){
				___DialogDoc.innerHTML = this.IframeDialog(___DialogDoc);//IE用来屏蔽select/object
			}else{
				this.HideShowCovered();
			}
		}

		if(this.DialogDrag)
			this.$(this.DialogId + this._CONTROL).onmousedown = this.DragStart;

		if(this.DialogResize)
			this.$(this.DialogId + this._RESIZEBAR).onmousedown = this.ResizeStart;

		if(this.DialogShadowFlag)this.ShadowDialog();
	}
	
	this.IframeDialog = function(o){
		return '<iframe id="' + this.DialogId + this._IFRAME + '" src="about:blank" scrolling="no" frameborder="0" \
				style="position:absolute; filter:Alpha(Opacity=0); top:0; left:0; z-index:'+(parseInt(o.style.zIndex) + 1)+';  width:'+o.offsetWidth+'px; \
				height:'+o.offsetHeight+'px;">\
				</iframe>';
	}
	
	this.ShadowDialog = function(){//渐变显示面板
	
	  	var ___DialogDoc = this.$(this.DialogId + this._DOC);
	  	var ___Dialog = this.$(this.DialogId);
		
		try{
			if(this.ie){
				if(___DialogDoc.filters.alpha.opacity < this.DialogLockAlpha && this.DialogLock)
					___DialogDoc.filters.alpha.opacity = Number(___DialogDoc.filters.alpha.opacity) + this.DialogShadowInterval;
				else ___DialogDoc.filters.alpha.opacity = this.DialogLockAlpha;
				if(___Dialog.filters.alpha.opacity < this.DialogAlpha)
					___Dialog.filters.alpha.opacity = Number(___Dialog.filters.alpha.opacity) + this.DialogShadowInterval;
				else ___Dialog.filters.alpha.opacity = this.DialogAlpha;
				
				if(___DialogDoc.filters.alpha.opacity < this.DialogLockAlpha || ___Dialog.filters.alpha.opacity < this.DialogAlpha){
					setTimeout(this.DialogObject + this.DialogShadow, this.DialogShadowDelay);
				}
			}else{
				if(___DialogDoc.style.MozOpacity < this.DialogLockAlpha && this.DialogLock)
					___DialogDoc.style.MozOpacity = Number(___DialogDoc.style.MozOpacity) + this.DialogShadowInterval;
				else ___DialogDoc.style.MozOpacity = this.DialogLockAlpha;
				if(___Dialog.style.MozOpacity < this.DialogAlpha)
					___Dialog.style.MozOpacity = Number(___Dialog.style.MozOpacity) + this.DialogShadowInterval;
				else ___Dialog.style.MozOpacity = this.DialogAlpha;
				
				if(___DialogDoc.style.MozOpacity < this.DialogLockAlpha || ___Dialog.style.MozOpacity < this.DialogAlpha){
					setTimeout(this.DialogObject + this.DialogShadow, this.DialogShadowDelay);
				}	
			}
		}catch(e){}
	}
	
	this.CloseDialog = function(){//关闭面板
	
	  	var ___DialogDoc = this.$(this.DialogId + this._DOC);
	  	var ___Dialog = this.$(this.DialogId);
		
		try{
			if(this.DialogShadowFlag){
				if(this.ie){
					document.body.removeChild(___DialogDoc);
					document.body.removeChild(___Dialog);代码
					___DialogDoc.filters.alpha.opacity -= this.DialogShadowInterval;
					___Dialog.filters.alpha.opacity -= this.DialogShadowInterval;
					this.DragEnd();
					if(this.DialogLockMode == "hidden")this.HideShowCovered(true);	
					//这里直接关闭，下面是渐变关闭的
//					if(___DialogDoc.filters.alpha.opacity > 0 || ___Dialog.filters.alpha.opacity > 0){
//						setTimeout(this.DialogObject + this.DialogClose, this.DialogShadowDelay);
//					}else{
//						document.body.removeChild(___DialogDoc);
//						document.body.removeChild(___Dialog);
//						
//						this.DragEnd();
//						
//						if(this.DialogLockMode == "hidden")this.HideShowCovered(true);				
//					}
				}else{
					___DialogDoc.style.MozOpacity -= this.DialogShadowInterval;
					___Dialog.style.MozOpacity -= this.DialogShadowInterval;
					
					if(___DialogDoc.style.MozOpacity > 0 || ___Dialog.style.MozOpacity > 0){
						setTimeout(this.DialogObject + this.DialogClose, this.DialogShadowDelay);
					}else{
						document.body.removeChild(___DialogDoc);
						document.body.removeChild(___Dialog);
						
						this.DragEnd();
					}				
				}
			}else{		
				document.body.removeChild(___DialogDoc);
				document.body.removeChild(___Dialog);
			
				this.DragEnd();
			
				if(this.ie && (this.DialogLockMode == "hidden"))this.HideShowCovered(true);
			}
		}catch(e){}
	}
	
	this.DialogSetHtml = function(html, add){
		var ___DialogContext = this.$(this.DialogId + this._CONTEXT);
		if(___DialogContext){
			if(add){
				___DialogContext.innerHTML += html;	
			}else{
				___DialogContext.innerHTML = html;	
			}
		}
		this.UpdateDialogSize();
	}
	
	this.DialogGetHtml = function(){
		var ___DialogContext = this.$(this.DialogId + this._CONTEXT);
		if(___DialogContext)return ___DialogContext.innerHTML;
		return "";
	}
	
	this.DialogBakUpHtml = function(){
		this.DialogBakHtml = this.DialogGetHtml();
	}
	
	this.DialogRestoreHtml = function(){
		this.DialogSetHtml(this.DialogBakHtml);
	}

	this.DialogSetTitle = function(title, add){
		var ___DialogControl = this.$(this.DialogId + this._CONTROL);
		if(___DialogControl){
			if(add){
				___DialogControl.innerHTML += title;	
			}else{
				___DialogControl.innerHTML = title;	
			}
		}
	}
	
	this.DialogGetTitle = function(){
		var ___DialogControl = this.$(this.DialogId + this._CONTROL);
		if(___DialogControl)return ___DialogControl.innerHTML;
		return "";
	}
	
	this.ShowHideButton = function(vl){
	  	var ___DialogBtn = this.$(this.DialogId + this._BUTTON);
	  	var ___DialogCtrBtn = this.$(this.DialogId + this._CTRLBTN);
		
		if(___DialogBtn)___DialogBtn.style.display = vl;
		if(___DialogCtrBtn)___DialogCtrBtn.style.display = vl;
	}
	
	this.WinMinDialog = function(el){

		el.src = this.OffsDialog.ss2 ? "js/dialog/dialog-min.gif" : "js/dialog/dialog-min2.gif";

		var ___CC = this.$(this.DialogId + this._MAIN);		
		
		___CC.style.display = this.OffsDialog.ss2 ? "" : "none";
		if(this.DialogResize)this.$(this.DialogId + this._RESIZEBAR).style.display = this.OffsDialog.ss2 ? "" : "none";		
				
		this.OffsDialog.ss2 = !this.OffsDialog.ss2;
		
		this.UpdateDialogSize();		
	}

	this.WinMaxDialog = function(el){
		
		el.src = this.OffsDialog.ss ? "js/dialog/dialog-max.gif" : "js/dialog/dialog-max2.gif";

		postX = this.ie?document.body.scrollLeft:window.scrollX,
		postY = this.ie?document.body.scrollTop:window.scrollY
		
		var ___C = this.$(this.DialogId);
		var ___CC = this.$(this.DialogId + this._MAIN);
		
		if(!this.OffsDialog.ss){
			this.OffsDialog.sx = this.DialogLeft == -1 ? ___C.offsetLeft : this.DialogLeft;
			this.OffsDialog.sy = this.DialogTop == -1 ? ___C.offsetTop : this.DialogTop;
		}
	
		___C.style.top = this.OffsDialog.ss ? this.OffsDialog.sy + "px" : postY + "px";
		___C.style.left = this.OffsDialog.ss ? this.OffsDialog.sx + "px" : postX + "px";
		___C.style.width = this.OffsDialog.ss ? 
								(this.DialogWidth != -1 ? this.DialogWidth + "px" : "") : "";
		
		var ___CC_Height = "";
		
		if(this.OffsDialog.ss){
			if(this.DialogHeight == -2){
				___CC_Height = "";
			}else if(this.DialogHeight == -3){
				___CC_Height = (document.body.clientHeight - this.OffsDialog.hh - this.ScrollWidth) + "px";
			}else if(this.DialogHeight == -1){
				___CC_Height = "";
			}else{
				___CC_Height = this.DialogHeight + "px";
			}
		}else{
			___CC_Height = (document.body.clientHeight - this.OffsDialog.hh - this.ScrollWidth) + "px"
		}

		___CC.style.height =  ___CC_Height;
			
		this.OffsDialog.ss = !this.OffsDialog.ss;	
		
		this.UpdateDialogSize();
		
	}
	
	this.UpdateDialogSize = function(){
		
		var ___C = this.$(this.DialogId);
		var ___CC = this.$(this.DialogId + this._MAIN);
		
		if(this.DialogHeight == -2){
			if(___CC.offsetHeight > (document.body.clientHeight - this.OffsDialog.hh - this.ScrollWidth))
				___CC.style.height = (document.body.clientHeight - this.OffsDialog.hh - this.ScrollWidth) + "px";
		}else if(this.DialogHeight == -3){
			___CC.style.height = (document.body.clientHeight - this.OffsDialog.hh - this.ScrollWidth) + "px";
		}else if(this.DialogHeight == -1){
			___CC.style.height = "";
		}else{
			___CC.style.height = this.DialogHeight + "px";
		}
		
		if(this.DialogReAlign && !this.OffsDialog.ss && !this.OffsDialog.ss2){//允许调整及不是最大化/最小化时
			var ppos = this.GetDialogPos2(___C);
			___C.style.top = this.DialogTop == -1 ? ppos.y + "px" : this.DialogTop;
			___C.style.left = this.DialogLeft == -1 ? ppos.x + "px" : this.DialogLeft;
		}

		if(this.DialogLock){
			var ___DC = this.$(this.DialogId + this._DOC);
			___DC.style.top = "0";
			___DC.style.left = "0";
			___DC.style.width = Math.max(document.body.scrollWidth, document.body.clientWidth) + "px";
			___DC.style.height = Math.max(document.body.scrollHeight, document.body.clientHeight) + "px";			
			if(this.ie && (this.DialogLockMode == "iframe")){
				var ___FC = this.$(this.DialogId + this._IFRAME);
				___FC.style.top = "0";
				___FC.style.left = "0";
				___FC.style.width = ___DC.style.width;
				___FC.style.height = ___DC.style.height;
			}
		}else{
			var ___DC = this.$(this.DialogId + this._DOC);
			___DC.style.height = ___C.offsetHeight + "px";
			___DC.style.width = ___C.offsetWidth + "px";
			if(this.ie && (this.DialogLockMode == "iframe")){
				var ___FC = this.$(this.DialogId + this._IFRAME);
				___FC.style.width = ___DC.style.width;
				___FC.style.height = ___DC.style.height;
			}
			if(this.DialogReAlign){
				___DC.style.top = ___C.style.top;
				___DC.style.left = ___C.style.left;
			}
		}
		
		if(this.ie && (this.DialogLockMode == "hidden"))this.HideShowCovered();
	}
	
	this.HideShowCovered = function (op) {
		var el = null;
		var epos = new Array();
		var p = {x:0, y:0};
		if(this.DialogArray){
			for(var key in this.DialogArray){
				el = this.$(this.DialogArray[key].DialogId + this._DOC);
				if(el){
					p = this.GetAbsolutePos(el);
					epos[epos.length] = {
						id  : this.DialogArray[key].DialogId,
						EX1 : p.x,
						EX2 : el.offsetWidth + p.x,
						EY1 : p.y,
						EY2 : el.offsetHeight + p.y
					}
				}
			}
		}else{
			el = this.$(this.DialogId + this._DOC);
			if(el){
				p = this.GetAbsolutePos(el);
				epos[epos.length] = {
					id  : this.DialogId,
					EX1 : p.x,
					EX2 : el.offsetWidth + p.x,
					EY1 : p.y,
					EY2 : el.offsetHeight + p.y
				}
			}
		}
		if(epos)this.HideShowCoveredObject(epos, op);
	}
	
	this.HideShowCoveredObject = function(epos, op){
		var tags = new Array("object","applet", "iframe", "select");
		var cpos = {el:null, CX1:0, CX2:0, CY1:0, CY2:0};
		var cp = {x:0, y:0};
	
		for (var k = tags.length; k > 0; ) {
			var ar = document.getElementsByTagName(tags[--k]);
			var cc = null;
		
			for (var i = ar.length; i > 0;) {
				cc = ar[--i];
		
				cp = this.GetAbsolutePos(cc);
				cpos = {
					el : cc,
					CX1 : cp.x,
					CX2 : cc.offsetWidth + cp.x,
					CY1 : cp.y,
					CY2 : cc.offsetHeight + cp.y
				}
				
				if(!cc.getAttribute("dialog_hideshow_object_visibility"))
					if(cc.currentStyle.visibility)
						cc.setAttribute("dialog_hideshow_object_visibility", cc.currentStyle.visibility);
				if (op && !this.HideShowCoveredCheck(epos, cpos)) {
					cc.style.visibility = cc.getAttribute("dialog_hideshow_object_visibility");
				}else if(!this.HideShowCoveredCheck(epos, cpos)){
					cc.style.visibility = cc.getAttribute("dialog_hideshow_object_visibility");
				} else {
					cc.style.visibility = "hidden";
				}
			}
		}		
	}
	
	this.HideShowCoveredCheck = function(epos, cpos){//in:true
		var value = false;
		var el = null;

		for(var i = 0; i < epos.length; i ++){
			if((cpos.CX1 > epos[i].EX2) || (cpos.CX2 < epos[i].EX1) || (cpos.CY1 > epos[i].EY2) || (cpos.CY2 < epos[i].EY1)){
				//
			}else{				
				if(this.ParentIdCheck(cpos.el, epos[i].id)){
					el = this.$(epos[i].id);
					if(el){//在内部且当前对话框
						if((this.DialogzIndex + 2) < el.style.zIndex)return false;
					}
				}else{//不在内部正常处理
					value = true;
				}
			}
		}
		return value;
	}
	
	this.ParentIdCheck = function(el, pid){
		var pel = el.parentNode;
		while(true){
			if(!pel)break;
			if(pel.id)if(pel.id == pid)return true;
			pel = pel.parentNode;
		}
		return false;
	}
		
	this.GetAbsolutePos = function(el) {
		var SL = 0, ST = 0;
		var is_div = /^div$/i.test(el.tagName);
		if (is_div && el.scrollLeft)
			SL = el.scrollLeft;
		if (is_div && el.scrollTop)
			ST = el.scrollTop;
		var r = { x: el.offsetLeft - SL, y: el.offsetTop - ST };
		if (el.offsetParent) {
			var tmp = this.GetAbsolutePos(el.offsetParent);
			r.x += tmp.x;
			r.y += tmp.y;
		}
		return r;
	}
	
	this.SwitchDialogzIndex = function(op) {
		
		var ___C = null;
		for(var key in this.DialogArray){
			___C = this.$(this.DialogArray[key].DialogId + this.DialogArray[key]._DOC);
			if(___C)___C.style.zIndex = this.DialogArray[key].DialogzIndex;
			if(this.ie && (this.DialogArray[key].DialogLockMode == "iframe")){
				___C = this.$(this.DialogArray[key].DialogId + this.DialogArray[key]._IFRAME);
				if(___C)___C.style.zIndex = this.DialogArray[key].DialogzIndex + 1;
			}
			___C = this.$(this.DialogArray[key].DialogId);
			if(___C)___C.style.zIndex = this.DialogArray[key].DialogzIndex + 2;
		}
		
		if(op){
			___C = this.$(this.DialogId + this._DOC);
			if(___C)___C.style.zIndex = this.DialogzIndex + 3;
			if(this.ie && (this.DialogLockMode == "iframe")){
				___C = this.$(this.DialogId + this._IFRAME);
				if(___C)___C.style.zIndex = this.DialogzIndex + 4;
			}
			___C = this.$(this.DialogId);
			if(___C)___C.style.zIndex = this.DialogzIndex + 5;
		}
		
		if(this.ie && (this.DialogLockMode == "hidden"))this.HideShowCovered();		
	}
	
	this.GetDialogPos = function(ev, parent, ob, bpos){//计算最佳位置
		//var epos = this.ie?{x:ev.clientX, y:ev.clientY}:{x:ev.pageX, y:ev.pageY};//鼠标位置
		var eobj = null;
		if(parent){
			eobj = this.$(parent);
		}else if(ev){
			eobj = this.ie?ev.srcElement:ev.currentTarget;//事件对象
		}
		
		var ppos = {x: 0, y: 0};
		
		if(eobj){
			var opos = this.GetAbsolutePos(eobj);//对象位置		
//			alert(opos.x);//点击的地方的x坐标
//			alert(opos.y);//点击的地方的y坐标
//			alert(eobj.offsetHeight);//点击的地方的y坐标
			ppos = {x: opos.x, y: opos.y + eobj.offsetHeight};
		}

		if(this.DialogAlign == "center"){
			ppos.x = Math.floor((bpos.cw - ob.offsetWidth) / 2) + bpos.sx;
			ppos.y = Math.floor((bpos.ch - ob.offsetHeight) / 2) + bpos.sy;
//            alert(ppos.x);//点击的地方的x坐标
//			alert(ppos.y);//点击的地方的y坐标

		}else{
			if(ppos.x + ob.offsetWidth > bpos.sx + bpos.cw)
				ppos.x = ppos.x - (ob.offsetWidth - eobj.offsetWidth);
		
			if(ppos.y + ob.offsetHeight > bpos.sy + bpos.ch)
				ppos.y = ppos.y - eobj.offsetHeight - ob.offsetHeight;
		}
		
		if(ppos.x < bpos.sx)ppos.x = bpos.sx;
		if(ppos.y < bpos.sy)ppos.y = bpos.sy;
		
		return ppos;
	}
	
	this.GetDialogPos2 = function(el){//计算最佳位置
		
		var ppos = {x: el.offsetLeft, y: el.offsetTop};

		
		var bpos = {
			sw : 0,
			sh : 0,
			cw : 0,
			ch : 0,
			sx : 0,
			sy : 0
		};

		var pel = this.$(this.DialogParent);

		if(pel){

			bpos = {
				sw : parseInt(pel.offsetWidth),
				sh : parseInt(pel.offsetHeight),
				cw : parseInt(pel.offsetWidth),
				ch : parseInt(pel.offsetHeight),
				sx : parseInt(pel.offsetLeft),
				sy : parseInt(pel.offsetTop)
			};
		}else{
			bpos = {
				sw : document.body.scrollWidth,
				sh : document.body.scrollHeight,
				cw : document.body.clientWidth,
				ch : document.body.clientHeight,
				sx : this.ie?document.body.scrollLeft:window.scrollX,
				sy : this.ie?document.body.scrollTop:window.scrollY
			};
		}

		if(this.DialogAlign == "center"){
			ppos.x = Math.floor((bpos.cw - el.offsetWidth) / 2) + bpos.sx;
			ppos.y = Math.floor((bpos.ch - el.offsetHeight) / 2) + bpos.sy;
		}else{
			if(ppos.x + el.offsetWidth > bpos.sx + bpos.cw)
				ppos.x = bpos.sx + bpos.cw - el.offsetWidth;
		
			if(ppos.y + el.offsetHeight > bpos.sy + bpos.ch)
				ppos.y = bpos.sy + bpos.ch - el.offsetHeight;
		}
		
		if(ppos.x < bpos.sx)ppos.x = bpos.sx;
		if(ppos.y < bpos.sy)ppos.y = bpos.sy;
		
		return ppos;
	}	
	
	this.DragStart = function(ev) {
		
		if(_C.DragIng)return;

		var posX;
		var posY;

		if (_C.ie) {
			posY = window.event.clientY + document.body.scrollTop;
			posX = window.event.clientX + document.body.scrollLeft;
		} else {
			posY = ev.clientY + window.scrollY;
			posX = ev.clientX + window.scrollX;
		}
		var st = _C.$(_C.DialogId);
		
		if(!st)return;
		
		_C.OffsX = posX - parseInt(st.style.left);
		_C.OffsY = posY - parseInt(st.style.top);
	
//		with(_C.$(_C.DialogId).style){
//			if(_C.DialogDragAlpha != -1){
//				if(_C.ie){
//					filter = "Alpha(Opacity=" + _C.DialogDragAlpha + ")";
//				}else{
//					MozOpacity = _C.DialogDragAlpha;
//				}
//			}
//		}
	
		//设置事件
		document.onmousemove = _C.DragIt;
		document.onmouseup = _C.DragEnd;
	
		_C.DragIng = true;
		
		return _C.StopEvent(ev);		
	}
	
	this.DragIt = function(ev) {
	
		if(!_C.DragIng)return;
	
		var posX;
		var posY;
		if (_C.ie) {
			posY = window.event.clientY + document.body.scrollTop;
			posX = window.event.clientX + document.body.scrollLeft;
		} else {
			posX = ev.pageX;
			posY = ev.pageY;
		}
		var st = _C.$(_C.DialogId);
		
		if(!st)return;
		
		with(st.style){
			if(Math.abs((parseInt(left) - (posX - _C.OffsX))) >= _C.DialogDragPixel )left = (posX - _C.OffsX) + "px";
			if(Math.abs((parseInt(top) - (posY - _C.OffsY))) >= _C.DialogDragPixel )top = (posY - _C.OffsY) + "px";
		}
		
		if(!_C.DialogLock){
			
			var dt = _C.$(_C.DialogId + _C._DOC);
			
			if(!dt)return;
			
			with(dt.style){
				left = st.style.left;
				top = st.style.top;
				width = st.scrollWidth + "px";
				for(var i = 0; i < dt.childNodes.length; i ++){
					if(dt.childNodes[i].style){
						dt.childNodes[i].style.width = dt.style.width;
					}
				}
			}
		}				
		
		if(_C.ie && (_C.DialogLockMode == "hidden"))_C.HideShowCovered();
		
		return _C.StopEvent(ev);	
		
	}
	
	this.DragEnd = function(ev) {
		if(!_C.DragIng)return;
		
		if(_C.DialogDragAlpha != -1){			

			var st = _C.$(_C.DialogId);
			
//			if(!st)return;	
//
//			if(_C.ie){
//				st.style.filter = "Alpha(Opacity=" + _C.DialogAlpha + ")";
//			}else{
//				st.style.MozOpacity = _C.DialogAlpha;
//			}
		}
		
		_C.RemoveEvent(document, "mousemove", _C.DragIt);
		_C.RemoveEvent(document, "mouseup", _C.DragEnd);
		_C.DragIng = false;		
	}
	
	this.ResizeStart = function(ev){

		if(_C.ResizeIng)return;

		ev = window.event || ev;
		
		var st = _C.$(_C.DialogId);
		var stp = _C.GetAbsolutePos(st);
		st.cx = stp.x;
		//st.cy = stp.y;
		
		document.onmousemove = _C.ResizeIt;
		document.onmouseup = _C.ResizeEnd;
		
		_C.ResizeIng = true;
		
		return _C.StopEvent(ev);
	}
	
	this.ResizeIt = function(ev){
		if(!_C.ResizeIng)return;

		ev = window.event || ev; 
		var st = _C.$(_C.DialogId);
		st.style.width = (ev.clientX - st.cx) + "px";
		//st.style.height = (ev.clientY - st.cy) + "px";
		
		_C.UpdateDialogSize();
	}
	
	this.ResizeEnd = function(ev){
		if(!_C.ResizeIng)return;
		
		_C.RemoveEvent(document, "mousemove", _C.ResizeIt);
		_C.RemoveEvent(document, "mouseup", _C.ResizeEnd);
		_C.ResizeIng = false;		
	}
	
	this.StopEvent = function(ev) {
		ev || (ev = window.event);
		if (_C.ie) {
			ev.cancelBubble = true;
			ev.returnValue = false;
		} else {
			ev.preventDefault();
			ev.stopPropagation();
		}
		return false;
	}
	
	this.RemoveEvent = function(el, evname, func) {
		if (el.detachEvent) { // IE
			el.detachEvent("on" + evname, func);
		} else if (el.removeEventListener) { // Gecko / W3C
			el.removeEventListener(evname, func, true);
		} else {
			el["on" + evname] = null;
		}
	}
	
	this.$ = function(en){
		try{
			var el = document.getElementById(en);
			if(el)return el;
			return false;
		}catch(e){
			return false;
		}
	}
}

function offset(obj, r){
	if (obj.offsetWidth>=obj.offsetHeight && obj.offsetWidth>r) {obj.style.width=r+'px';}
	if (obj.offsetHeight>=obj.offsetWidth && obj.offsetHeight>r) {obj.style.height=r+'px';}
}

