document.write('<div id="disDisplay" style="display:none; background:#F2F2F2; position:absolute; width:0px; height:0px; top:0px; left:0px; opacity:0.6; filter:alpha(opacity=60); overflow:hidden; z-index:10000;"></div>');
document.write('<img id="preShowImg" src="http://www.qkchat.com/img/ajax-loader.gif" style="display:none; position:absolute; top:0; left:0px; z-index:10001;" />');
document.write('<div id="showSystemMessageDiv" style="display:none; position:absolute; top:0; left:0; width:420px; border:2px solid #FF9966; background:#FFFFCA; padding:5px; font-size:13px; z-index:10002;"><div id="showSystemMessage" style="z-index:10003;"></div><div id="closeSystemMessage" style="cursor:pointer; padding:2px; margin:auto; margin-top:25px; border:1px solid #000000; background:#FFFFFF; width:70px; text-align:center;"></div></div>');


var _s_getClientHeight, _s_getClientWidth, _s_getScrollTop, _s_getScrollLeft, _s_windowHeight, _s_windowWidth, _s_topDistance, _s_leftDistance, _s_divWidth;

$(window).keydown(function(e){
	if($('#showSystemMessageDiv').css('display')=="block" && e.keyCode==13){
		return false;
	}
});

$(window).scroll(function(){ reSetPosition(); });
$(window).resize(function(){ reSetPosition(); });


function preShow(){
	// 透明背景
	// =======================================
	_s_getClientHeight=$(document).height();
	_s_getClientWidth=$(document).width();
	$('#disDisplay').css({'height': _s_getClientHeight, 'width': _s_getClientWidth, 'display': 'block'});
	// =======================================
	
	
	// Loading 圖示
	// =======================================
	_s_getScrollTop=$(window).scrollTop();
	_s_getScrollLeft=$(window).scrollLeft();
	_s_windowHeight=$(window).height();
	_s_windowWidth=$(window).width();
	
	_s_topDistance=Math.round((_s_windowHeight)/3)+_s_getScrollTop;
	_s_leftDistance=Math.round((_s_windowWidth)/2)+_s_getScrollLeft-12;
	
	$('#preShowImg').css({'top': _s_topDistance, 'left': _s_leftDistance, 'display': 'block'});
	// =======================================
}

function showSystemMessage(message, action, width, buttonName){
	width		 = width || 420;
	buttonName	 = buttonName || '關閉訊息';
	
	$('#showSystemMessageDiv').css("width", width);
	$('#closeSystemMessage').html(buttonName);
	
	// 透明背景
	// =======================================
	_s_getClientHeight=$(document).height();
	_s_getClientWidth=$(document).width();
	
	$('#disDisplay').css({'height': _s_getClientHeight, 'width': _s_getClientWidth, 'display': 'block'});
	// =======================================
	
	
	// 關閉 Loading 圖示
	// =======================================
	$('#preShowImg').css('display', 'none');
	// =======================================
	
	$('#closeSystemMessage').one('click', function (){ closeSystemMessage(action); });
	
	_s_getScrollTop=$(window).scrollTop();
	_s_getScrollLeft=$(window).scrollLeft();
	_s_windowHeight=$(window).height();
	_s_windowWidth=$(window).width();
	_s_divWidth=$('#showSystemMessageDiv').width();
	
	_s_topDistance=Math.round((_s_windowHeight)/3)+_s_getScrollTop;
	_s_leftDistance=Math.round((_s_windowWidth-_s_divWidth)/2)+_s_getScrollLeft;
	
	$('#showSystemMessage').html(message);
	$('#showSystemMessageDiv').css({'top': _s_topDistance, 'left': _s_leftDistance, 'display': 'block'});
	
	
	_s_topDistance-=Math.round($('#showSystemMessageDiv').height()/3);
	if(_s_topDistance<60){
		_s_topDistance=60;
	}
	
	$('#showSystemMessageDiv').css('top', _s_topDistance);
}


function closeSystemMessage(action){
	action = action || "";
	
	$('#preShowImg').css('display', 'none');
	$('#disDisplay').css('display', 'none');
	$('#showSystemMessageDiv').css('display', 'none');
	
	if(action!="") eval(action);
}

function reSetPosition(){
	if($('#showSystemMessageDiv').css('display')=="block"){
		// 透明背景
		// =======================================
		_s_getClientHeight=$(document).height();
		_s_getClientWidth=$(document).width();
		$('#disDisplay').css({'height': _s_getClientHeight, 'width': _s_getClientWidth, 'display': 'block'});
		// =======================================
		
		_s_getScrollTop=$(window).scrollTop();
		_s_getScrollLeft=$(window).scrollLeft();
		_s_windowHeight=$(window).height();
		_s_windowWidth=$(window).width();
		_s_divWidth=$('#showSystemMessageDiv').width();
		
		_s_topDistance=Math.round((_s_windowHeight)/3)+_s_getScrollTop;
		_s_leftDistance=Math.round((_s_windowWidth-_s_divWidth)/2)+_s_getScrollLeft;
		_s_topDistance-=Math.round($('#showSystemMessageDiv').height()/3);
		if(_s_topDistance<60){
			_s_topDistance=60;
		}
		$('#showSystemMessageDiv').css({'top': _s_topDistance, 'left': _s_leftDistance, 'display': 'block'});
	}
}
