var w3c=(document.getElementById)? true: false;
var agt=navigator.userAgent.toLowerCase();
var ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1) && (agt.indexOf("omniweb") == -1));

function IeTrueBody()
{
	return (document.compatMode && document.compatMode!="BackCompat") ? document.documentElement : document.body;
}

function GetScrollTop()
{
	return ie ? IeTrueBody().scrollTop : window.pageYOffset;
}
function getPageScroll()
{
	var yScroll;
	if (self.pageYOffset) yScroll = self.pageYOffset;
	else if (document.documentElement && document.documentElement.scrollTop) yScroll = document.documentElement.scrollTop;
	else if (document.body) yScroll = document.body.scrollTop;
	arrayPageScroll = new Array('',yScroll);
	return arrayPageScroll;
}

function getPageSize()
{
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY)
	{
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	}
	else if (document.body.scrollHeight > document.body.offsetHeight)
	{ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	}
	else
	{ // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight)
	{  // all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	{ // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	}
	else if (document.body)
	{ // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight) pageHeight = windowHeight;
	else pageHeight = yScroll;
	if(xScroll < windowWidth) pageWidth = windowWidth;
	else pageWidth = xScroll;
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight,xScroll,yScroll);
	return arrayPageSize;
//return pageHeight;
}

$(document).ready(function () {
							
	// 为表单中的提交按钮添加事件
	$('.tform').unbind('submit');
	$('.tform').submit(function () {
		postPageContent($('.tform').attr('action'), $('.tform').formSerialize());
		return false;
	});
	
	
		// 关闭信息框
	var closeMessageWindows = function () {
		$('#MaskLayer').hide();
		$('#StatusLayer').hide();
		$('#WaitingLayer').hide();
		return true;
	};
	

	
	/**
		 * 显示等待内容
		 */
	var showWaitingLayer = function () {
		//$('#StatusLayer').hide();
		$('#MaskLayer').height($(document).height());
		$('#MaskLayer').show();
		page_size = getPageSize();
		$('#WaitingLayer').css('top', GetScrollTop() + (page_size[3] - $('#WaitingLayer').height()) / 2 + 'px');
		$('#WaitingLayer').show();
	};
	
	// AJAX GET方式获取内容
	var getPageContent = function (url, showSuccess) {
		//显示等待
		showWaitingLayer();
		$.ajax({
			type : 'GET',
			url : url,
			dataType : 'html',
			error: showErrorMessage,
			success : showSuccess
		});
	};
	
		// AJAX POST 方式获取内容
	var postPageContent = function (url, data) {
		showWaitingLayer();
		$.ajax({
			type : 'POST',
			url : url,
			data : data,
			dataType : 'html',
			error: showErrorMessage,
			success : showStatusLayer
		});
	};
	// 显示错误信息
	var showErrorMessage = function (XMLHttpRequest, textStatus, errorThrown) {
		showStatusLayer(XMLHttpRequest.responseText);
	};
	
	var showStatusLayer = function (html_data) {
			$('#WaitingLayer').hide();
			$('#MaskLayer').height($(document).height());
			$('#MaskLayer').show();
			$('#StatusLayer').html(html_data);
			page_size = getPageSize();
			$('#StatusLayer').css('top', GetScrollTop() + (page_size[3] - $('#StatusLayer').height()) / 2 + 'px');
			$('#StatusLayer').show();
		};
		
	$('#CloseButton').click(closeMessageWindows);
	$('.CloseButton').click(closeMessageWindows);

})