var def_border_color		= "#000";
var def_move_background		= "#8395BE";
var def_dialog_background	= "#FFFFFF";
var def_dialog_shadow_color	= "#000000";
var def_back_layer_color	= "#DFDFDF";
var def_title				= "系统提示：";
var def_shadow				= 5;
var def_shadow_opacity		= 20;
var def_back_layer_opacity	= 20;
var def_dialog_width		= 300;
var def_dialog_height		= 180;
var def_loading_flash		= "http://image2.sina.com.cn/book/forum/tmpl/images/loading.swf";
var def_close_url			= new Image();
var def_close_url_over		= new Image();
var def_button_enter		= new Image();
var def_button_close		= new Image();
var def_button_cancel		= new Image();
var def_loading_gif			= new Image();
def_close_url.src			= "http://image2.sina.com.cn/book/f_nice/dialogClose0.gif";
def_close_url_over.src		= "http://image2.sina.com.cn/book/f_nice/dialogCloseF.gif"
def_button_enter.src		= "http://image2.sina.com.cn/book/f_nice/ent.gif";
def_button_close.src		= "http://image2.sina.com.cn/book/f_nice/close.gif";
def_button_cancel.src		= "http://image2.sina.com.cn/book/f_nice/cancel.gif";
def_loading_gif.src			= "http://image2.sina.com.cn/book/f_nice/loading.gif";
var def_dialog_icon			= new Image();
var def_dialog_confirm_icon	= new Image();
var def_dialog_alert_icon		= new Image();
def_dialog_icon.src			= "http://image2.sina.com.cn/blog/tmpl/v3/images/dialog/2.gif";
def_dialog_confirm_icon.src	= "http://image2.sina.com.cn/blog/tmpl/v3/images/dialog/6.gif";
def_dialog_alert_icon.src		= "http://image2.sina.com.cn/blog/tmpl/v3/images/dialog/3.gif";
var dlg_time_out;
var time_out = 0;

dw('<div id="_dialog_client_back_layer" onselectstart="return false" style="position:absolute;background:' + def_back_layer_color + ';top:0;left:0;width:0px;height:0px;display:none;-moz-opacity:0;filter:Alpha(Opacity = 0);z-index:90;"></div>');
dw('<div id="_waiting" onselectstart="return false" style="position:absolute;display:none;top:0px;left:0px;width:' + def_loading_gif.width + 'px;height:' + def_loading_gif.height + 'px;z-index:91;"><img src="' + def_loading_gif.src + '" border="0" alt="" /></div>');
dw('<div id="_loading" onselectstart="return false" style="position:absolute;display:none;top:0px;left:0pxz-index:92;"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="16" height="16"><param name="wmode" value="transparent" /><param name="movie" value="' + def_loading_flash + '" /><param name="quality" value="high" /><embed src="' + def_loading_flash + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent" width="16" height="16"></embed></object></div>');
dw('<div id="_shadow" onselectstart="return false" style="position:absolute;width:0px;height:0px;background:' + def_dialog_shadow_color + ';-moz-opacity:' + def_shadow_opacity/100 + ';filter:Alpha(Opacity = ' + def_shadow_opacity + ');display:none;z-index:93;"></div>\
<div id="_dialog_box" onselectstart="return false" style="position:absolute;width:0px;height:0px;border:' + def_border_color + ' 1px solid;background:' + def_dialog_background + ';display:none;z-index:99;">\
<div id="_top_box"  onmousedown="new dialog().drag(event, \'_dialog_box\');" style="clear:both;border-top:#FFF 1px solid;background:#8395BE;padding:0;magin:0;height:25px;cursor:move">\
<div id="_move_box" onselectstart="return false"  style="float:left;color:#FFF;text-align:left;width:90%;line-height:25px;margin-left:3px;font-weight:bold; font:Arial, Helvetica, sans-serif;">' + def_title + '</div>\
<div id="_close_box" onselectstart="return false" style="float:right;line-height:25px;margin-right:3px;margin-top:3px;cursor:hand"><input type="image" onclick="new dialog().reset();" src="' + def_close_url.src + '" border="0" onmouseover="this.src =\'' + def_close_url_over.src + '\'" onmouseout="this.src =\'' + def_close_url.src + '\'" /></div>\
</div>\
<div id="_dialog_zone" onselectstart="return false" style="clear:both;padding:0;magin:0;"></div>\
</div>\
');
dw('<div id="_win" onselectstart="return false" style="background:url(http://image2.sina.com.cn/book/forum/tmpl/images/win_bg.gif) repeat-x;border:1px #CCC solid;text-align:center;width:200px;height:100px;line-height:50px;position:absolute;display:none;top:0;left:0;z-index:94;"></div>');

function dialog()
{
	var bt_enter	= "<input type=\"image\"  style=\margin:0;padding:0\"  onclick=\"new dialog().reset();\" src =\"" + def_button_enter.src + "\" border=\"0\" id=\"_dialog_enter\"  />";
	var bt_close	= "<input type=\"image\" style=\margin:0;padding:0\"  onclick=\"new dialog().reset();\" src =\"" + def_button_close.src + "\" border=\"0\" id=\"_dialog_close\"  />";
	var bt_cancel	= "<input type=\"image\" style=\margin:0;padding:0\"  onclick=\"new dialog().reset();\" src =\"" + def_button_cancel.src + "\" border=\"0\" id=\"_dialog_cancel\"  />";
	this.init = function()
	{
	}
	this.showWaiting = function()
	{
		if ($("_waiting").style.display == "")
		{
			return;
		}
		this.display($("_waiting"));
		this.middle($("_waiting"));
		
		dlg_time_out = setInterval(function(){
			time_out++;
			if (time_out > 10){
				clearInterval(dlg_time_out);
				time_out = 0;
				show_error("连接超时，请重试！");
			}
		}, 1000);
	}
	this.showLoading = function  ()
	{
		if ($("_loading").style.display == "")
		{
			return;
		}
		this.display($("_loading"));
		this.middle($("_loading"));
		dlg_time_out = setInterval(function(){
			time_out++;
			if (time_out > 10){
				clearInterval(dlg_time_out);
				time_out = 0;
				show_error("连接超时，请重试！");
			}
		}, 1000);
	}
	this.showIframe = function(iframe, s)
	{
		s = isNull(s) ? "no" : s;
		var f = "<iframe src=\"" + iframe + "\" frameborder=\"0\" width=\"100%\" height=\"100%\" scrolling=\"" + s + "\"></iframe>";
		this.showHtml(f);
	}
	this.showBox = function()
	{
		this.display($("_dialog_box"));
		this.display($("_shadow"), 1);
		this.middle($("_dialog_box"));
		this.middle($("_shadow"), def_shadow);
	}
	this.showHtml = function(h)
	{
		$("_dialog_zone").innerHTML = h;
		this.showBox();
	}
	this.showWin = function(msg, func)
	{
		$("_win").innerHTML = msg + "<p>" + bt_enter;
		this.display($("_win"));
		this.display($("_shadow"), 1);
		this.middle($("_win"));
		this.middle($("_shadow"), 5);
		this.setFunc(func);
	}
	this.showDialog = function(msg, type, func, title)
	{
		var icon = def_dialog_icon.src;
		var butt = bt_enter;
		this.setTitle(title);
		switch (type)
		{
			case 'confirm':
				icon = def_dialog_confirm_icon.src;
				butt = bt_enter + "　" + bt_cancel;
				break;
			case 'close':
				butt = bt_enter + "　" + bt_close;
				break;
			case 'alert':
				icon = def_dialog_alert_icon.src;
				break;
		}
		var h = "<div style=\"width:100%;height:100%;margin:0 auto;clear:both;\">\
		<div style=\"width:60px;height:60px;margin:20px 5px 0px 20px;float:left;\"><img src=\"" + icon + "\" alt=\"\"></div>\
		<div style=\"width:180px;height:50px;margin:30px 5px 10px 5px;float:left;text-align:left;\">" + msg + "</div>\
		<div style=\"width:200px;margin:0 auto;padding-top:10px;clear:both;text-align:center\">" + butt + "</div>\
		</div>";
		this.setBox();
		this.showHtml(h);
		this.setFunc(func);
	}
	this.setFunc = function(f)
	{
		if (!isNull(f))
		{
			$("_dialog_enter").onclick = function(){
				new dialog().reset();
				eval(f);
			}
		}
		$("_dialog_enter").focus();
	}
	this.setTitle = function(t)
	{
		if (!isNull(t))
		{
			$("_move_box").innerHTML = t;
		}
	}
	this.setBox = function(w, h)
	{
		if (isNull(w))
		{
			w = def_dialog_width;
		}
		if (isNull(h))
		{
			h = def_dialog_height;
		}
		$("_shadow").style.width = w + 'px';
		$("_shadow").style.height = h + 'px';
		$("_dialog_box").style.width = w + 'px';
		$("_dialog_box").style.height = h + 'px';
		$("_dialog_zone").style.width = w + 'px';
		$("_dialog_zone").style.height = h - 25 + "px";
	}
	this.setPosition = function(t, l)
	{
		$("_dialog_box").style.top = t + 'px';
		$("_dialog_box").style.left = l + 'px';
		$("_shadow").style.top = t + def_shadow + 'px';
		$("_shadow").style.left = l + def_shadow +'px';
	}
	this.middle = function(obj, pos)
	{
		var sWidth	= document.documentElement.clientWidth;
		var sHeight	= document.documentElement.clientHeight;
		var sSrolltop	= document.documentElement.scrollTop;
		var sScrollleft	= document.documentElement.scrollLeft;
		if (isNull(pos))
		{
			pos = 0;
		}
		obj.style.top		= sHeight/2 - obj.offsetHeight/2 + sSrolltop + pos + 'px';
		obj.style.left		= sWidth/2 - obj.offsetWidth/2 + sScrollleft + pos + 'px';
	}
	this.display = function(obj, flag)
	{
		if (isNull(flag) || flag == 0)
		{
			this.back_layer();
		}
		obj.style.display = "";
	}
	this.reset = function()
	{
		clearInterval(dlg_time_out);
		time_out = 0;
		this.setTitle(def_title);
		$("_dialog_client_back_layer").style.display	= "none";
		$("_loading").style.display						= "none";
		$("_waiting").style.display						= "none";
		$("_dialog_box").style.display					= "none";
		$("_shadow").style.display						= "none";
		$("_win").style.display							= "none";
		$("_dialog_client_back_layer").style.filter		= "alpha(opacity = 0)";
		$("_dialog_client_back_layer").style.opacity	= 0;
		$("_dialog_zone").innerHTML						= "";
	}

	this.back_layer = function()
	{
		if ($("_dialog_client_back_layer").style.display == "")
		{
			return;
		}
		$("_dialog_client_back_layer").style.filter		= "alpha(opacity = 0)";
		$("_dialog_client_back_layer").style.opacity	= 0;
		$("_dialog_client_back_layer").style.display = "";
		$("_dialog_client_back_layer").style.width	= document.documentElement.scrollWidth + "px";
		$("_dialog_client_back_layer").style.height	= document.documentElement.scrollHeight + "px";
		var a		= 0;
		var mm	= setInterval(function(){
		if (a > def_back_layer_opacity)
		{
			clearInterval(mm);
		}
		else
		{
			$("_dialog_client_back_layer").style.filter = "alpha(opacity = " + a + ")";
			$("_dialog_client_back_layer").style.opacity = a/100;
			a += 10;;
		}}, 100);
	}
	this.drag = function(evt,obj)
	{
		var e =  evt;
		if ($("_move_box").setCapture)
		{
			$("_move_box").setCapture();
		}
		mLeft = e.clientX - parseInt($(obj).style.left);
		mTop = e.clientY - parseInt($(obj).style.top);
		$(obj).onmousemove = function(){
			$(obj).style.left = e.clientX - mLeft  + "px";
			$(obj).style.top = e.clientY - mTop + "px";
			$("_shadow").style.left = e.clientX - mLeft + def_shadow + 'px';
			$("_shadow").style.top = e.clientY - mTop + def_shadow + 'px';
		};
		$(obj).onmouseup =  function(){
			if ($("_move_box").releaseCapture)
			{
				$("_move_box").releaseCapture();
			}
			$(obj).onmouseup = null;
			$(obj).onmousemove = null;
		};
	}
}
//声明DIALOG
var _dialog = new dialog();
function reset(){
	_dialog.reset();
}
function show_error(str, func){
	reset();
	_dialog.showDialog(str, "alert", func);
}
function show_win(str, func){
	reset();
	_dialog.showWin(str, func);
}
function show_confirm(str, func){
	reset();
	_dialog.showDialog(str, "confirm", func);
}
function show_send(){
	reset();
	_dialog.showWaiting();
}
function show_loading(){
	reset();
	_dialog.showLoading();
}
function show_frame(u, w, h, t, s){
	reset();
	_dialog.setTitle(t);
	_dialog.setBox(w, h);
	_dialog.showIframe(u, s);
}