var g_bDebugMode = false;

(function(){
	"use strict";
	//非调试模式禁用右键环境菜单和全局选择复制
	if (!g_bDebugMode){
		var releaseEventDisabler = function(){event.returnValue = false;};
		document.oncontextmenu = releaseEventDisabler;
		document.onselectstart = releaseEventDisabler;
		document.ondragstart = releaseEventDisabler;
		return;
	}
}());

var g_scrollBarWidth = 0;
function getScrollBarWidth () {
	"use strict";
	if (g_scrollBarWidth !== 0) {return g_scrollBarWidth;}
	var inner = document.createElement('p');
	inner.style.width = "100%";
	inner.style.height = "200px";

	var outer = document.createElement('div');
	outer.style.position = "absolute";//指定绝对定位从而不影响文档其它元素的位置
	outer.style.top = "0px";
	outer.style.left = "0px";
	outer.style.visibility = "hidden";
	outer.style.width = "200px";
	outer.style.height = "150px";
	outer.style.overflow = "hidden";
	outer.appendChild (inner);

	document.body.appendChild(outer);
	var w1 = parseInt(inner.offsetWidth);
	outer.style.overflow = 'scroll';
	var w2 = parseInt(inner.offsetWidth);
	if (w1 === w2) {w2 = parseInt(outer.offsetWidth);}

	document.body.removeChild(outer);
	g_scrollBarWidth = w1 - w2;
	return g_scrollBarWidth;
}

function ResizeContent(){
	"use strict";
	var scrollBarWidth = getScrollBarWidth();
	/*var arVersion = navigator.appVersion.split("MSIE");
	var version = parseFloat(arVersion[1]);
	var strInfo = "IE Version:"+arVersion+"\nScrollBarWidth:"+scrollBarWidth+"\n";*/
	//有些页面标题用Title做ID，有些页面标题用MainTitle做ID
	var objTitle = document.getElementById("Title");
	if (!objTitle){objTitle = document.getElementById("MainTitle");}
	var objCont = document.getElementById("MainContent");
	var objText = document.getElementById("MainText");

	/*strInfo += "objCont:"+objCont+"\nobjText"+objText+"\nobjTitle" +
		objTitle + "\n";
	strInfo += "document.width:"+document.height+"\n";
		strInfo += "document.documentElement.clientWidth:"+document.documentElement.clientWidth+"\n";
		strInfo += "document.documentElement.clientHeight:"+document.documentElement.clientHeight+"\n";
		strInfo += "document.body.clientWidth:"+document.body.clientWidth+"\n";
		strInfo += "document.body.clientHeight:"+document.body.clientHeight+"\n";
		strInfo += "document.body.scrollWidth:"+document.body.scrollWidth+"\n";
		strInfo += "document.body.scrollHeight:"+document.body.scrollHeight+"\n";
		strInfo += "document.body.offsetWidth:"+document.body.offsetWidth+"\n";
		strInfo += "document.body.offsetHeight:"+document.body.offsetHeight+"\n";
		strInfo += "objTitle.clientHeight:"+objTitle.clientHeight+"\n";*/
	if (objTitle && objCont){
		var windowWidth = document.documentElement.clientWidth;
		var windowHeight = document.documentElement.clientHeight;
		if (parseInt(windowWidth) === 0)//早期IE版本不支持documentElement
		{
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}
		var titleHeight = objTitle.clientHeight;
		objCont.style.top = '0px';
		objCont.style.width = windowWidth + 'px';
		objCont.style.height = Math.max(0, windowHeight - titleHeight) + 'px';
		var nWidth;
		if (objCont.scrollHeight > parseInt(objCont.style.height)){
			nWidth = windowWidth - 12 - scrollBarWidth;
		}else{
			nWidth = windowWidth - 12;
		}
		//try{
		objText.style.width = (nWidth < 0 ? 0 : nWidth) + 'px';
		//}
		//catch(e){}
	}
	/*strInfo += "objCont.style.width:" + objCont.style.width + "\n";
	strInfo += "objCont.style.height:" + objCont.style.height + "\n";
	strInfo += "objText.style.width:" + objText.style.width + "\n";
	strInfo += "objText.style.height:" + objText.style.height + "\n";
	alert(strInfo);*/
}

var ScrollPos = 0;

function OnBodyLoad()
{
	//alert("load\n");
	ResizeContent();
    try{
		MainContent.scrollTop = ScrollPos;
	}catch(e){};
}

function LoadAll()
{
	try{
		ScrollPos = MainText.getAttribute("Scroll");
	}catch(e){};
}

function SaveAll()
{
	MainText.setAttribute("Scroll", MainContent.scrollTop);
}

function WebTest()
{
	alert("This is Web function!");
}

function ReContentPNG(){
	//window.external.测试();
	correctPNG();
	ResizeContent();
}