﻿var is_opera_d  =  navigator.userAgent.toLowerCase().indexOf('opera') != -1;
var is_ie = navigator.appName.indexOf("Microsoft") != -1;
String.prototype.trim = function()
{
	return this.replace(/(^[ |　]*)|([ |　]*$)/g, "");
}

function $1(s)
{
	if(document.getElementById)
	{
		return eval('document.getElementById("' + s + '")');
	}
	else if (is_ie)
	{
		return eval('document.all.' + s);
	}
	else
	{
		return eval('document[' + s + ']');
	}
}
function $$(s)
{
	return document.frames ? document.frames[s] : $1(s).contentWindow;
}
function $c(s)
{
	return document.createElement(s);
}

function dialog()
{
	var titile = '';
	var auto = 'y';
	var width = 240;
	var height = 120;
	var src = "";
	var path = "/Controls/DialogBox/";
	var sFunc = '<input id="dialogOk" type="button" value=" 确 定 " onclick="new dialog().reset();" /> <input id="dialogCancel" type="button" value=" 取 消 " onclick="new dialog().reset();" />';
	var sClose = '<input type="image" id="dialogBoxClose" onclick="new dialog().reset();" src="' + path + 'close.gif" border="0" width="16" height="16" align="absmiddle" />';
	var sBody = '\
		<table id="dialogBodyBox" border="0" align="center" cellpadding="0" cellspacing="6" width="100%">\
			<tr height="10"><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="5"><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:80;display:none;"></iframe>\
	';

	var sBox = '\
		<div id="dialogBox" style="border:1px solid #1e4775;display:none;z-index:100;width:'+width+'px;">\
		<table width="100%" border="0" cellpadding="0" cellspacing="0">\
			<tr height="24" bgcolor="#6795B4">\
				<td>\
					<table onselectstart="return false;" style="-moz-user-select:none;" width="100%" border="0" cellpadding="0" cellspacing="0" style="background-color:#5499dc;  height:25px; border-top:1px solid #92c3ec;">\
						<tr>\
							<td width="6" height="24"></td>\
							<td id="dialogBoxTitle" onmousedown="new dialog().moveStart(event, \'dialogBox\')" style="color:#fff;cursor:move;font-size:12px;font-weight:bold;">&nbsp;</td>\
							<td id="dialogClose" width="20" align="right" valign="middle">\
								' + sClose + '\
							</td>\
							<td width="6"></td>\
						</tr>\
					</table>\
				</td>\
			</tr>\
			<tr id="dialogHeight" style="height:' + height + '" valign="top">\
				<td id="dialogBody" bgcolor="#ffffff">' + sBody + '</td>\
			</tr>\
		</table></div>\
		<div id="dialogBoxShadow" style="display:none;z-index:90;"></div>\
	';
	var sBG = '\
		<div id="dialogBoxBG" style="position:absolute;top:0px;left:0px;width:100%;height:100%;filter:alpha(opacity=20);opacity=0;background:#333333"></div>\
	';

	this.show = function()
	{
		this.middle('dialogBox');
		var dialogIframBG = $1("dialogIframBG"); 
		var dialogBox = $1('dialogBox');
		dialogBox.style.top="100px";
		if (dialogIframBG)
		{
			dialogIframBG.style.top = dialogBox.style.top;
			dialogIframBG.style.left = dialogBox.style.left;
			dialogIframBG.style.width = dialogBox.offsetWidth;
			dialogIframBG.style.height = dialogBox.offsetHeight;
			dialogIframBG.style.display = 'block';
		}
		if (!is_opera_d) {
			this.shadow();
		}
	}

	this.reset = function()
	{
		this.close();
	}

	this.close = function()
	{
		//var s=document.getElementsByTagName("select"); 
		//for(var j=0;j<s.length;j++){s[j].style.display="";}
		if ($1('dialogIframBG'))
		{
			$1('dialogIframBG').style.display = 'none';
		}
		$1('dialogBox').style.display='none';
		$1('dialogBoxBG').style.display='none';
		$1('dialogBoxShadow').style.display = "none";
		$1('dialogBody').innerHTML = sBody;
	}
	this.html = function(_sHtml)
	{
		$1("dialogBody").innerHTML = _sHtml;
		this.show();
	}

	this.init = function(big_msg)
	{
		var dialogCase = $1('dialogCase');
		dialogCase && dialogCase.parentNode.removeChild(dialogCase);
		var oDiv = document.createElement('span');
		oDiv.id = "dialogCase";
		if ('yes' == big_msg)
		{
			oDiv.innerHTML = sBG + sBox;
		}
		else
		{
			oDiv.innerHTML = !is_opera_d ? sBG + sIfram + sBox : sBG + sBox;
		}
		document.body.appendChild(oDiv);
		$1('dialogBoxBG').style.height = document.body.scrollHeight;
	}

	this.button = function(_sId, _sFuc)
	{
		var myElement = $1(_sId);
		if(myElement)
		{
			myElement.style.display = '';
			if(myElement.addEventListener)
			{
				myElement.act && myElement.removeEventListener('click', function(){eval(myElement.act)}, false);
				myElement.act = _sFuc;
				myElement.addEventListener('click', function(){eval(_sFuc)}, false);
			}
			else
			{
				myElement.act && myElement.detachEvent('onclick', function(){eval(myElement.act)});
				myElement.act = _sFuc;
				myElement.attachEvent('onclick', function(){eval(_sFuc)});
			}
		}
	}

	this.shadow = function()
	{
		var oShadow = $1('dialogBoxShadow');
		var oDialog = $1('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;
		oShadow['style']['left'] = oDialog.offsetLeft + 6;
		oShadow['style']['width'] = oDialog.offsetWidth;
		oShadow['style']['height'] = oDialog.offsetHeight;
	}

	this.open = function(_sUrl, _sMode)
	{
		this.show();
		if(!_sMode || _sMode == "no" || _sMode == "yes"){
			var openIframe = "<iframe width='100%' height='100%' name='iframe_parent' id='iframe_parent' src='" + _sUrl + "' frameborder='0' scrolling='" + _sMode + "'></iframe>";
			$1("dialogBody").innerHTML = openIframe;
		}
	}

	this.showWindow = function(_sUrl, _iWidth, _iHeight, _sMode)
	{
		var oWindow;
		var sLeft = (screen.width) ? (screen.width - _iWidth)/2 : 0;
		var iTop = -80 + (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)
	{
		$1('dialogFunc').innerHTML = sFunc;
		$1('dialogClose').innerHTML = sClose;
		$1('dialogBodyBox') == null ? $1('dialogBody').innerHTML = sBody : function(){};
		var dialogMsg = $1('dialogMsg');
		if (dialogMsg) {
			dialogMsg.innerHTML = _sMsg
			if (width > 400 && height > 300)
			{
				dialogMsg['style']['fontWeight'] = "bold";
				dialogMsg['style']['fontSize'] = "15px";
				dialogMsg['style']['color'] = "#ff9900";
				dialogMsg['style']['height'] = "150px";
			}
		}
		_sOk && _sOk != "" ? this.button('dialogOk', _sOk) : $1('dialogOk').style.display = 'none';
		_sCancel && _sCancel != "" ? this.button('dialogCancel', _sCancel) : $1('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 = $1('dialogBoxShadow');
		var oDialog = $1('dialogBox');
		var oHeight = $1('dialogHeight');

		if(_sVal != '')
		{
			switch(_oAttr)
			{
				case 'title':
					$1('dialogBoxTitle').innerHTML = _sVal;
					title = _sVal;
					break;
				case 'width':
					oDialog['style']['width'] = _sVal;
					width = _sVal;
					break;
				case 'height':
					oHeight['style']['height'] = _sVal;
					height = _sVal;
					break;
				case 'src':
					$1('dialogMsgDiv').innerHTML = '\
						<table border="0" align="center" cellpadding="0" cellspacing="0" width="100%">\
							<tr>\
								<td width="30%" align="center"><img id="dialogBoxFace" src="' + path + 'error.gif" /></td>\
								<td id="dialogMsg" style="font-size:12px;line-height:180%;" width="70%"></td>\
							</tr>\
						</table>\
					';
					$1('dialogBoxFace') ? $1('dialogBoxFace').src = path + _sVal + '.gif' : function(){};
					src = _sVal;
					break;
				case 'auto':
					auto = _sVal;			   
			}
		}
		this.middle('dialogBox');
		oShadow['style']['top'] = oDialog.offsetTop + 6;
		oShadow['style']['left'] = oDialog.offsetLeft + 6;
		oShadow['style']['width'] = oDialog.offsetWidth;
		oShadow['style']['height'] = oDialog.offsetHeight;
	}
    this.showClose=function (sh)
    {
        $1('dialogBoxClose').style.display=sh;
    }
	this.moveStart = function (event, _sId)
	{
		var oObj = $1(_sId);
		oObj.onmousemove = mousemove;
		oObj.onmouseup = mouseup;
		oObj.setCapture ? oObj.setCapture() : function(){};
		oEvent = window.event ? window.event : event;
		var dragData = {x : oEvent.clientX, y : oEvent.clientY};
		var backData = {x : parseInt(oObj.style.top), y : parseInt(oObj.style.left)};
		function mousemove()
		{
			var oEvent = window.event ? window.event : event;
			var iLeft = oEvent.clientX - dragData["x"] + parseInt(oObj.style.left);
			var iTop = oEvent.clientY - dragData["y"] + parseInt(oObj.style.top);
			oObj.style.left = iLeft;
			oObj.style.top = iTop;
			$1('dialogBoxShadow').style.left = iLeft + 6;
			$1('dialogBoxShadow').style.top = iTop + 6;
			if ($1('dialogIframBG'))
			{
				$1('dialogIframBG').style.left = iLeft;
				$1('dialogIframBG').style.top = iTop;
			}
			dragData = {x: oEvent.clientX, y: oEvent.clientY};

		}
		function mouseup()
		{
			var oEvent = window.event ? window.event : event;
			oObj.onmousemove = null;
			oObj.onmouseup = null;
			if(oEvent.clientX < 1 || oEvent.clientY < 1 || oEvent.clientX > document.body.clientWidth || oEvent.clientY > document.body.clientHeight){
				oObj.style.left = backData.y;
				oObj.style.top = backData.x;
				$1('dialogBoxShadow').style.left = backData.y + 6;
				$1('dialogBoxShadow').style.top = backData.x + 6;
				if ($1('dialogIframBG'))
				{
					$1('dialogIframBG').style.left = backData.y;
					$1('dialogIframBG').style.top = backData.x;
				}
			}
			oObj.releaseCapture ? oObj.releaseCapture() : function(){};
		}
	}

	this.hideModule = function(_sType, _sDisplay)
	{
		var aIframe = parent.document.getElementsByTagName("iframe");
		var aType = document.getElementsByTagName(_sType);
		var iChildObj, iChildLen;
		for (var i = 0; i < aType.length; i++)
		{
			aType[i].style.display	= _sDisplay;
		}
		for (var j = 0; j < aIframe.length; j++)
		{
			iChildObj = document.frames ? document.frames[j] : aIframe[j].contentWindow;
			try
			{
				iChildLen = iChildObj.document.body.getElementsByTagName(_sType).length;
				for (var k = 0; k < iChildLen; k++)
				{
					iChildObj.document.body.getElementsByTagName(_sType)[k].style.display = _sDisplay;
				}
			}
			catch (e){}
		}
	}

	this.middle = function(_sId)
	{
		try
		{
			var myElement = $1(_sId);
			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 = (document.body.clientWidth / 2) - (myElement.offsetWidth / 2);
		var iTop = -80 + (sClientHeight / 2 + sScrollTop) - (myElement.offsetHeight / 2);
		var sTop = iTop > 0 ? iTop : (sClientHeight / 2 + sScrollTop) - (myElement.offsetHeight / 2);
		myElement['style']['display'] = '';
		myElement['style']['position'] = "absolute";
		myElement['style']['left'] = sleft;
		myElement['style']['top'] = sTop;
	}
}

function error_msg(msg, click, icon, title)
{
    click = click ? click : ' ';
    icon = icon ? icon : '';
    title = title ? title : '系统提示信息';
    dg=new dialog();
    dg.init();
    dg.set('src', get_icon());
    dg.set('title', title);
    dg.event(msg, click, '', click);
}

function confirm_msg(msg, click_ok, click_no, title, width, height)
{
    click_ok = click_ok ? click_ok : ' ';
    click_no = click_no ? click_no : ' ';
    title = title ? title : '系统提示信息';

    dg=new dialog();
    dg.init();
    dg.set('src', get_icon(''));
    dg.set('title', title);
	if (width)
    {
        dg.set('width', width);
    }
    if (height)
    {
        dg.set('height', height);
    }
    dg.event(msg, click_ok, click_no, click_no);
	$1("dialogOk").value="继续提交";
	$1("dialogCancel").value="我要修改";
}

function get_icon(icons)
{
	var icon = 'error';
	return icon;
}

function DialogBox(_sUrl, _sWidth, _sHeight, _sTitle, _sScroll,showClose)
{
	//var s=document.getElementsByTagName("select"); 
	//for(var j=0;j<s.length;j++){s[j].style.display="none";}
	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.set('close','none');
	oEdit.showClose(showClose);
	oEdit.open(_sUrl, _sScroll != "yes" ? 'no' : 'yes');
}

function alert1(_sWidth, _sHeight, _sTitle)
{
	var oEdit = new dialog();
	oEdit.init('yes');
	oEdit.set('title', "系统提示信息" );
	oEdit.set('width', _sWidth);
	oEdit.set('height', _sHeight);
	oEdit.event(_sTitle,'');
	oEdit.button('dialogOk',"");
	issubmit=false;
}
