var auto_close_hand;
var auto_close_hand1;
var auto_close_hand2;

var m_top=150;//
var m_left=200;

var is_opera_d  = (navigator.userAgent.toLowerCase().indexOf('opera') != -1);
String.prototype.trim = function()
{
	return this.replace(/(^[ |　]*)|([ |　]*$)/g, "");
}

function $(s)
{
	if(formmain().getElementById)
	{
		return eval('formmain().getElementById("' + s + '")');
	}
	else
	{
		return eval('formmain().all.' + s);
	}
}
function $$(s)
{
	return formmain().frames?formmain().frames[s]:$(s).contentWindow;
}
function $c(s)
{
	return formmain().createElement(s);
}
function swap(s,a,b,c)
{
	$(s)[a]=$(s)[a]==b?c:b;
}
function exist(s)
{
	return $(s)!=null;
}
function dw(s)
{
	formmain().write(s);
}
function hide(s)
{
	$(s).style.display=$(s).style.display=="none"?"":"none";
}
function isNull(_sVal)
{
	return (_sVal == "" || _sVal == null || _sVal == "undefined");
}
function removeNode(s)
{
	if(exist(s))
	{
		$(s).innerHTML = '';
		$(s).removeNode?$(s).removeNode():$(s).parentNode.removeChild($(s));
	}
}
function formmain()
{
  return parent.document||document
}
function dialog()
{
	var titile = '';
	var auto = 'y';
	var width = 240;
	var height =120;
	var src = "";	
	var sFunc = '<input id="dialogOk" type="button" value="confirm" onclick="new dialog().reset();" /> <input id="dialogCancel" type="button" value="cancel" onclick="new dialog().reset();" />';
	var sClose = '<input type="image" id="dialogBoxClose" onclick="new dialog().reset();" src="images/close.gif" border="0" width="16px" height="16px" align="absmiddle" />';
	var sBody = '\
		<table id="dialogBodyBox" border="0" align="center" cellpadding="0" cellspacing="6" width="100%">\
			<tr height="10px"><td colspan="4"></td></tr>\
			<tr><td colspan="4" align="center">\
			<div id="dialogMsgDiv" style="text-align:center"><div id="dialogMsg" style="font-size:12px;line-height:180%;"></div></div>\
			</td></tr>\
			<tr><td id="dialogFunc" colspan="4" align="center">' + sFunc + '</td></tr>\
			<tr height="5px"><td colspan="4" align="center"></td></tr>\
		</table>\
	';
	var sIfram = '\
		<iframe id="dialogIframBG" name="dialogIframBG" frameborder="0" marginheight="0" marginwidth="0" hspace="0" vspace="0" scrolling="no" style="position:absolute;z-index:8;display:none;"></iframe>\
	';

	var sBox = '\
		<div id="dialogBox" style="border:1px solid #1e4775;display:none;z-index:10;width:'+width+'px;">\
		<table width="100%" border="0" cellpadding="0" cellspacing="0">\
			<tr height="24px" bgcolor="#8CB0E4">\
				<td>\
					<table onselectstart="return false;" style="-moz-user-select:none;" width="100%" border="0" cellpadding="0" cellspacing="0" style="background-color:#8CB0E4  height:25px; border-top:1px solid #92c3ec;">\
						<tr>\
							<td width="6px" height="24px"></td>\
							<td id="dialogBoxTitle" onmousedown="moveStart(event, \'dialogBox\')" style="color:#fff;cursor:move;font-size:12px;font-weight:bold;">&nbsp;</td>\
							<td id="dialogClose" width="20px" align="right" valign="middle">\
								' + sClose + '\
							</td>\
							<td width="6px"></td>\
						</tr>\
					</table>\
				</td>\
			</tr>\
			<tr id="dialogHeight" style="height:' + height + 'px" valign="top">\
				<td id="dialogBody" bgcolor="#ffffff">' + sBody + '</td>\
			</tr>\
		</table></div>\
		<div id="dialogBoxShadow" style="display:none;z-index:9;"></div>\
	';
	var sBG = '\
		<div id="dialogBoxBG" style="position:absolute;top:0px;left:0px;width:100%;height:100%;"></div>\
	';

    //alert(sBody);
	this.show = function()
	{
		this.middle('dialogBox');
		if ($('dialogIframBG'))
		{
			$('dialogIframBG').style.top = $('dialogBox').style.top+"px";
			$('dialogIframBG').style.left = $('dialogBox').style.left+"px";
			$('dialogIframBG').style.width = $('dialogBox').offsetWidth+"px";
			$('dialogIframBG').style.height =$('dialogBox').offsetHeight+"px";
			$('dialogIframBG').style.display = 'block';
		}		
		this.shadow();
	}

	this.reset = function()
	{
		this.close();
	}

    
	this.close = function()
	{
		if ($('dialogIframBG'))
		{
			$('dialogIframBG').style.display = 'none';
		}
		$('dialogBox').style.display='none';
		$('dialogBoxBG').style.display='none';
		$('dialogBoxShadow').style.display = "none";
		$('dialogBody').innerHTML = sBody;
		//window.frames["main"].location.reload();
		//setLastActive();
		//var d=GetCookie("lastactive");
		//alert("d");
	}
	

	this.html = function(_sHtml)
	{
		$("dialogBody").innerHTML = _sHtml;
		this.show();
	}

	this.init = function(big_msg)
	{
		$('dialogCase') ? $('dialogCase').parentNode.removeChild($('dialogCase')) : function(){};
		var oDiv = formmain().createElement('span');
		oDiv.id = "dialogCase";
		if ('yes' == big_msg)
		{
			oDiv.innerHTML = sBG + sBox;
		}
		else
		{
			if (!is_opera_d)
			{
				oDiv.innerHTML = sBG + sIfram + sBox;
			}
			else
			{
				oDiv.innerHTML = sBG + sBox;
			}
		}
		formmain().body.appendChild(oDiv);
		$('dialogBoxBG').style.height = formmain().body.scrollHeight+"px";
	}

	this.button = function(_sId, _sFuc)
	{
		if($(_sId))
		{
			$(_sId).style.display = '';
			if($(_sId).addEventListener)
			{
				if($(_sId).act)
				{
					$(_sId).removeEventListener('click', function(){eval($(_sId).act)}, false);
				}
				$(_sId).act = _sFuc;
				$(_sId).addEventListener('click', function(){eval(_sFuc)}, false);
			}
			else
			{
				if($(_sId).act)
				{
					$(_sId).detachEvent('onclick', function(){eval($(_sId).act)});
				}
				$(_sId).act = _sFuc;
				$(_sId).attachEvent('onclick', function(){eval(_sFuc)});
			}
		}
	}

	this.shadow = function()
	{
		var oShadow = $('dialogBoxShadow');
		var oDialog = $('dialogBox');
		oShadow['style']['position'] = "absolute";
		oShadow['style']['background']	= "#000";
		oShadow['style']['display']	= "";
		oShadow['style']['opacity']	= "0.2";
		oShadow['style']['filter'] = "alpha(opacity=20)";
		oShadow['style']['top'] = (oDialog.offsetTop + 6)+"px";
		oShadow['style']['left'] = (oDialog.offsetLeft + 6)+"px";
		oShadow['style']['width'] = oDialog.offsetWidth+"px";
		oShadow['style']['height'] = oDialog.offsetHeight+"px";
	}

	this.open = function(_sUrl, _sMode,_sHeight)
	{
		this.show();
		if(!_sMode || _sMode == "no" || _sMode == "yes"){
			var openIframe = "<iframe width='100%' height='"+_sHeight+"px' name='iframe_parent' id='iframe_parent' src='" + _sUrl + "' frameborder='0' scrolling='" + _sMode + "'></iframe>";
			$("dialogBody").innerHTML = openIframe;
			//parent.document.getElementById("dialogBody").innerHTML=openIframe;
			//window.frames["iframe_parent"].location.reload();
                        //parent.iframe_parent.location.reload();
                        //var obj=parent.document.getElementById("dialogBody");
                        //obj.innerHTML=openIframe;
                        try
                          {
                             window.frames["iframe_parent"].location=_sUrl;
                            // window.frames["iframe_parent"].location.reload();
                          }
                       catch(exp)
                        {
                             window.frames["iframe_parent"].location=_sUrl;
                        }
			//alert(parent.document.getElementById("dialogBody").innerHTML);
			
		}
	}

	this.showWindow = function(_sUrl, _iWidth, _iHeight, _sMode)
	{
		var oWindow;
		var sLeft = (screen.width) ? (screen.width - _iWidth)/2 : 0;
		var iTop =-90+ (screen.height - _iHeight)/2;
		iTop = iTop > 0 ? iTop : (screen.height - _iHeight)/2;
		var sTop = (screen.height) ? iTop : 0;
		if(window.showModalDialog && _sMode == "m"){
			oWindow = window.showModalDialog(_sUrl,"","dialogWidth:" + _iWidth + "px;dialogheight:" + _iHeight + "px");
		} else {
			oWindow = window.open(_sUrl, '', 'height=' + _iHeight + ', width=' + _iWidth + ', top=' + sTop + ', left=' + sLeft + ', toolbar=no, menubar=no, scrollbars=' + _sMode + ', resizable=no,location=no, status=no');
			this.reset();
		}
	}

	this.event = function(_sMsg, _sOk, _sCancel, _sClose)
	{
		$('dialogFunc').innerHTML = sFunc;
		$('dialogClose').innerHTML = sClose;
		$('dialogBodyBox') == null ? $('dialogBody').innerHTML = sBody : function(){};
		if (width > 400 && height > 300)
		{
			$('dialogMsg') ? $('dialogMsg').innerHTML = _sMsg  : function(){};
			$('dialogMsg') ? $('dialogMsg')['style']['fontWeight'] = "bold" : function(){};
			$('dialogMsg') ? $('dialogMsg')['style']['fontSize'] = "15px" : function(){};
			$('dialogMsg') ? $('dialogMsg')['style']['color'] = "#ff9900" : function(){};
			$('dialogMsg') ? $('dialogMsg')['style']['height'] = "150px" : function(){};
		}
		else
		{
			$('dialogMsg') ? $('dialogMsg').innerHTML = _sMsg  : function(){};
		}

		_sOk && _sOk != "" ? this.button('dialogOk', _sOk) : $('dialogOk').style.display = 'none';
		_sCancel && _sCancel != "" ? this.button('dialogCancel', _sCancel) : $('dialogCancel').style.display = 'none';
		//_sOk ? this.button('dialogOk', _sOk) : _sOk == "" ? function(){} : $('dialogCancel').style.display = 'none';
		//_sCancel ? this.button('dialogCancel', _sCancel) : _sCancel == "" ? function(){} : $('dialogCancel').style.display = 'none';
		_sClose ? this.button('dialogBoxClose', _sClose) : function(){};

		this.show();
	}

	this.set = function(_oAttr, _sVal)
	{
		var oShadow = $('dialogBoxShadow');
		var oDialog = $('dialogBox');
		var oHeight = $('dialogHeight');

		if(_sVal != '')
		{
			switch(_oAttr)
			{
				case 'title':
					$('dialogBoxTitle').innerHTML = "<div style=\"line-height:25px;\"><div style=\"float:left\">"+_sVal+"</div></div>";
					title = _sVal;
					break;
				case 'width':
					oDialog['style']['width'] = _sVal+"px";
					width = _sVal;
					break;
				case 'height':
					oHeight['style']['height'] = _sVal+"px";
					height = _sVal;
					break;
				case 'src':
					$('dialogMsgDiv').innerHTML = '\
						<table border="0" align="center" cellpadding="0" cellspacing="0" width="100%">\
							<tr>\
								<td width="30%" align="center"><img id="dialogBoxFace" src="' + path + 'login_wrong.gif" /></td>\
								<td id="dialogMsg" style="font-size:12px;line-height:180%;" width="70%"></td>\
							</tr>\
						</table>\
					';
					$('dialogBoxFace') ? $('dialogBoxFace').src = path + _sVal + '.gif' : function(){};
					src = _sVal;
					break;
				case 'auto':
					auto = _sVal;
			}
		}
		this.middle('dialogBox');
		oShadow['style']['top'] = (oDialog.offsetTop + 6)+"px";
		oShadow['style']['left'] = (oDialog.offsetLeft + 6)+"px";
		oShadow['style']['width'] = oDialog.offsetWidth+"px";
		oShadow['style']['height'] = oDialog.offsetHeight+"px";
	}




   //弹出框居中
	this.middle = function(_sId)
	{
		try
		{
			var aIframe = parent.document.getElementById("iframe_parent");
		}
		catch (e){}
		if (aIframe) {
			var sClientWidth = aIframe.offsetWidth;
			var sClientHeight = aIframe.offsetHeight;
			var sScrollTop = 0;
		} else {
			var sClientWidth = parent ? parent.document.body.clientWidth : document.body.clientWidth;
			var sClientHeight = parent ? parent.document.body.clientHeight : document.body.clientHeight;
			var sScrollTop = parent ? parent.document.body.scrollTop : document.body.scrollTop;
		}
		var sleft = (formmain().body.clientWidth / 2) - ($(_sId).offsetWidth / 2)-200;
		 var iTop = (sClientHeight / 2 + sScrollTop) - ($(_sId).offsetHeight / 2);
		 var sTop =iTop > 0 ? iTop :100;

		$(_sId)['style']['display'] = '';
		$(_sId)['style']['position'] = "absolute";
		$(_sId)['style']['left'] =m_left+sleft+"px";
		$(_sId)['style']['top'] =m_top+sTop+"px";
	}
}

//调用入口
function openWindow(_sUrl, _sWidth, _sHeight, _sTitle, _sScroll)
{
    //alert(_sUrl);
    //setLastActive();
	var oEdit = new dialog();
	oEdit.init('yes');
    oEdit.set('title', _sTitle ? _sTitle : "系统提示信息" );
    oEdit.set('width', _sWidth);
    oEdit.set('height', _sHeight);
    oEdit.set('auto', 'n');
    oEdit.open(_sUrl, _sScroll != "yes" ? 'no' : 'yes',_sHeight);
    oEdit=null;
    //alert(_surl);
    return false;

}



//关闭窗口
function close()
{
    //alert("d");
     
     
     var oEdit = new dialog();
     oEdit.close();
     oEdit=null;
     
}

    //移动弹出框
   var dragData;
   var backData;
   var oObj;
   moveStart = function (e, _sId)
	{
		oObj = $(_sId);
		oObj.onmousemove = mousemove;
		oObj.onmouseup = mouseup;
		oObj.setCapture ? oObj.setCapture() : function(){};
		oEvent = window.event ? window.event : e;
		dragData = {x : oEvent.clientX, y : oEvent.clientY};
		backData = {x : parseInt(oObj.style.top), y : parseInt(oObj.style.left)};
		//alert(oEvent.clientX)
		//alert(dragData.x+"backData"+backData.x+"aa"+dragData["x"]);
		
	}
	mousemove=function(e)
		{
			var oEvent = window.event ? window.event : e;
			var iLeft = oEvent.clientX- dragData["x"] + parseInt(oObj.style.left);
			var iTop = oEvent.clientY- dragData["y"] + parseInt(oObj.style.top);
			//alert(oEvent.clientX +"ddd"+dragData["x"]+"left"+parseInt(oObj.style.left)+"vdf"+iLeft);
			//alert(oEvent.pageX)
			oObj.style.left = iLeft+"px";
			oObj.style.top = iTop+"px";
			$('dialogBoxShadow').style.left =(iLeft + 6)+"px";
			$('dialogBoxShadow').style.top = (iTop + 6)+"px";
			if ($('dialogIframBG'))
			{
				$('dialogIframBG').style.left = iLeft+"px";
				$('dialogIframBG').style.top = iTop+"px";
			}
			dragData = {x: oEvent.clientX, y: oEvent.clientY};

		}
		
	    mouseup=function(e)
		{
			var oEvent = window.event ? window.event : e;
			oObj.onmousemove = null;
			oObj.onmouseup = null;
			if(oEvent.clientX < 1 || oEvent.clientY < 1 || oEvent.clientX > formmain().body.clientWidth || oEvent.clientY > formmain().body.clientHeight){
				oObj.style.left = backData.y+"px";
				oObj.style.top = backData.x+"px";
				$('dialogBoxShadow').style.left = (backData.y + 6)+"px";
				$('dialogBoxShadow').style.top = (backData.x + 6)+"px";
				if ($('dialogIframBG'))
				{
					$('dialogIframBG').style.left = backData.y+"px";
					$('dialogIframBG').style.top = backData.x+"px";
				}
			}
			oObj.releaseCapture ? oObj.releaseCapture() : function(){};
		}

