<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=$##TEMPL_CHARSET##">
<title>$##MSG_TITLE##</title>

$IF_COMPACT_JS
<script type="text/javascript" src="/$##DATA_TYPE##/j45/submenu.js?m=$V45_JS_VER"></script>

<script type="text/javascript" src="/j45/OJTEngine.js?m=$V45_JS_VER"></script>
<script type="text/javascript" src="/j45/PortalLayout.js?m=$V45_JS_VER"></script>
<script type="text/javascript" src="/j45/PortalModule.js?m=$V45_JS_VER"></script>
$IF_COMPACT_JS_else
<script type="text/javascript" src="/j45/libm2k.js?m=$V45_JS_VER"></script>
<script type="text/javascript" src="/$##DATA_TYPE##/j45/msgtw.js?m=$V45_JS_VER"></script>
<script type="text/javascript" src="/j45/Basic.js?m=$V45_JS_VER"></script>
<script type="text/javascript" src="/j45/GlobalObj.js?m=$V45_JS_VER"></script>
<script type="text/javascript" src="/j45/MAJAXEngine.js?m=$V45_JS_VER"></script>
<script type="text/javascript" src="/j45/OTLoader.js?m=$V45_JS_VER"></script>
<script type="text/javascript" src="/j45/RSSParser.js?m=$V45_JS_VER"></script>
<script type="text/javascript" src="/j45/OJTEngine.js?m=$V45_JS_VER"></script>
<script type="text/javascript" src="/j45/OEDispatcher.js?m=$V45_JS_VER"></script>
<script type="text/javascript" src="/j45/PostSubmit.js?m=$V45_JS_VER"></script>
<script type="text/javascript" src="/j45/ToolBar.js?m=$V45_JS_VER"></script>
<script type="text/javascript" src="/j45/hreffunc.js?m=$V45_JS_VER"></script>
<script type="text/javascript" src="/j45/adbook2.js?m=$V45_JS_VER"></script>

<script type="text/javascript" src="/j45/PortalLayout.js?m=$V45_JS_VER"></script>
<script type="text/javascript" src="/j45/PortalModule.js?m=$V45_JS_VER"></script>
$$IF_COMPACT_JS

<link rel="stylesheet" href="/$##DATA_TYPE##/c45/$SCHEME_02m2kv4.css?m=$V45_CSS_VER" type="text/css">
<style>
.FPUnreadMail {
	font-size: 12px;
	font-style: normal;
	line-height: 14px;
	color: #FF0000;
	font-family: Arial, Helvetica, sans-serif;
	font-weight: bold;
}
.FPTotalMail {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
	line-height: 14px;
	color: #0076A3;
}
.FPLink {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
	line-height: 14px;
	color: #0076A3;
}

.sylUL {
	line-height: 1px;
	border-top:1px #CDCDC5 solid;
}

.FPLink A:link {text-decoration: underline; color: #0076A3}

.ModuleBlock {
	width: 100%;
	border:1px solid #999999;
	padding: 2px; 
}
.DragBlock {
	padding: 2px;
}
.ContentBlock {
	padding: 2px;
}
</style>
<script type="text/javascript">
<!--
var sg_st1stCallData=new Array();
$IF_GROUP
sg_st1stCallData[Panel_AnnounceBoard.szID]=$fpAnnJS
$$IF_GROUP
sg_st1stCallData[Panel_Capacity.szID]=$fpCapJS
sg_st1stCallData[Panel_AllMboxInfo.szID]=$fpBoxJS
sg_st1stCallData[Panel_AdbStatistic.szID]=$fpAdbJS
sg_st1stCallData[Panel_UserLog.szID]=$fpLogJS
sg_st1stCallData[Panel_Forward.szID]=$fpForwardJS
/*
*/
PanelRegistry.DecideSetup({bOnline: $IF_ONLINE true $IF_ONLINE_else false $$IF_ONLINE , bCalendar: $IF_CALENDAR true $IF_CALENDAR_else false $$IF_CALENDAR , bGroup: $IF_GROUP true $IF_GROUP_else false $$IF_GROUP , bEnews: $ifenews true $ifenews_else false $$ifenews});

GlobalObjStore("crumb", $crumb);
var stLM=new LayoutManager();

function PurgeTrash()
{ 
	if ( confirm("$##MSG_0001##!JM") ) { 
		var pMainWnd = GetMainWindow(); 
		if (pMainWnd) { 
			var szBack = escape('portal?cmd=show');
			pMainWnd.BlockExec("/cgi-bin/trash_purge?crumb=$crumb&m=$magic&back=" + szBack, "fullIframe", 0); 
		} 
	}
}

function PurgeSpam()
{ 
	if ( confirm("$##MSG_0002##!JM") ) {
		var pMainWnd = GetMainWindow(); 
		if (pMainWnd) { 
			var szBack = escape('portal?cmd=show');
			pMainWnd.BlockExec("/cgi-bin/trash_purge?crumb=$crumb&mbox=@.spam&m=$magic&back=" + szBack, "fullIframe", 0); 
		} 
	}
}

function ShowAllLayout()
{
	var hLayoutRegistry=GlobalObjLoad("LayoutRegistry");
	var rgLayoutInfos=hLayoutRegistry.GetLayoutInfos();

	var selectLayouts=document.getElementById("allLayoutSelect");
	var i=0;
	var j=selectLayouts.options.length;
	for(var i=j-1;i>=0;i--)
		selectLayouts.options[i]=null;

	for(var i=0;i<rgLayoutInfos.length;i++){
		var stLayoutInfo=rgLayoutInfos[i];
		selectLayouts.options[i]=new Option(stLayoutInfo.szName, stLayoutInfo.szID, false,true);
	}

	var stCurLayout=stLM.GetLayout();
	for(var i=0;i<selectLayouts.options.length;i++){
		if(selectLayouts.options[i].value==stCurLayout.GetID()){
			selectLayouts.selectedIndex=i;
			break;
		}
	}
}


function ChangeLayout()
{
	stLM.Clear();
	var selectLayouts=document.getElementById("allLayoutSelect");
	var szSelectValue=selectLayouts.options[selectLayouts.selectedIndex].value;
	var stLayoutInfo=LayoutRegistry.GetLayoutInfo(szSelectValue);
	if(null!=stLayoutInfo){
		stLM.Clear();
		stLM.SetLayout(new stLayoutInfo());
		stLM.Render();
	}
	SaveLayout();
}

function ShowAddNewPanel()
{
	stLM.ShowModPanel();
	return ;
}

function ModuleShow(szModuleID)
{
	var stModule=null;
	stModule=stLM.GetPanel(szModuleID);
	if(null!=stModule){
		stModule.Show();
	}
	return ;
}
function ModuleShowConfiguration(szModuleID)
{
	var stModule=null;
	stModule=stLM.GetPanel(szModuleID);
	if(null!=stModule){
		stModule.ShowConfContext();
	}
	return ;
}

var sg_AJAXEngine=new MAJAXEngine(null, null);
function SaveLayout()
{
	var szQry="/cgi-bin/portal?cmd=setlayout&m="+GetMagicNo()+"&m=$magic";
	szQry+="&layout="+stLM.GetLayout().GetID();
	szQry+=stLM.GetSaveQry();
	sg_AJAXEngine.SetURL(szQry);
	sg_AJAXEngine.DoRequestByPost();
	
	return ;
}

function ModuleConfirmDel(nID)
{
	if(confirm("$##MSG_0003##!JM")){
		var szURL="/cgi-bin/portal?cmd=delpanel&lmid="+nID+"&m="+GetMagicNo();
		self.location.href=szURL;
	}
	return ;
}

function s_FindModule()
{
	var stRearBase=document.getElementById("rearbase");
	var rgChildren=stRearBase.childNodes;
	for(var i=0;i<rgChildren.length;i++){
		var stElement=rgChildren[i];
		if("DIV"==stElement.nodeName){
			var szModule=stElement.getAttribute("szModule");
			var szOrder=stElement.getAttribute("szOrder");
			var nX=stElement.getAttribute("nX");
			var nY=stElement.getAttribute("nY");
			var nWidth=stElement.getAttribute("nWidth");
			var nHeight=stElement.getAttribute("nHeight");
			if(0!=parseInt(stElement.id))
				stLM.AddPanel(stElement.id, szModule, szOrder, nX, nY, nWidth, nHeight);
		}
	}
}

function GetV45AllNewHtml()
{
	return ("/$##DATA_TYPE##/v45_rss_all_news.html");
}

function init()
{
	var stOTLoader=new OTLoader("/$##DATA_TYPE##/portal.xml?m="+GetMagicNo());
	stOTLoader.Load();
	GlobalObjStore("TemplateLoder", stOTLoader);
	
	s_FindModule();

	if(""=="$szLayout"){
		stLM.SetLayout(new Layout());
	}else{
		eval("stLM.SetLayout(new $szLayout());");
	}
	
	ConfLoaderAdapter.SetModules(stLM.GetPanels());
	var szConfData="";
$lpJS
	szConfData+="$nID$szConf\n";
$$lpJS
/*
	var szInvokeData="m="+GetMagicNo()+"&cmd=getconf&showall=1";
	var stEngine=new MAJAXEngine("/cgi-bin/portal?"+szInvokeData, ConfLoaderAdapter);
	stEngine.SetASync(false);
	stEngine.DoRequest();
*/	

	ConfLoaderAdapter.ProcData(szConfData);

	stLM.Render();
	ShowAllLayout();
}


var ConfLoaderAdapter={
	rgstModules: null,
	bReRender: false,
	rgstRecs: [],
	SetModules: function(rgstModules){
		if(null!=rgstModules&& "undefined"!=typeof(rgstModules))
			this.rgstModules=rgstModules;
	},
	GetModules: function(){
		return this.rgstModules;
	},
	SetReRender: function(bReRender){
		if(null==bReRender || "undefined"==typeof(bReRender))
			return ;
		
		if(true==bReRender)	
			this.bReRender=true;
		else
			this.bReRender=false;
	},
	GetReRender: function(){
		return this.bReRender;
	},
	
	ProcData: function(szData){
		this.ParseRec(szData);

		var rgPanels=this.GetModules();
		if(null!=rgPanels){
			for(var i=0;i< rgPanels.length;i++){
				var stPanel=rgPanels[i];
				var rgPair=this.GetRecord(stPanel.GetID());
				if(null!=rgPair && "undefined" != typeof(rgPair)){
					stPanel.LoadConf(rgPair);
					if(this.GetReRender()){
						writeHistory(stPanel.GetID()+ " "+rgPair+" will rerender");
						stPanel.Show();
					}
				}
			} 
		}
	},
	OnReadyState: function(stAJAXRequest){
		if(4 == stAJAXRequest.readyState && 200 == stAJAXRequest.status){
			var repText=stAJAXRequest.responseText;
			this.rgstRecs=[];
			this.ProcData(repText);
		}
	},
	ParseRec: function(szText){
		var rgszRecs=szText.split("\n");
		for(var i=0;i<rgszRecs.length;i++){
			var szRec=rgszRecs[i];
			var rgszFields=szRec.split("\t");
			if(rgszFields.length < 1)
				continue;

			for(var j=1;j<rgszFields.length;j++){
				if(-1==rgszFields[j].indexOf("=")){
					rgszFields.splice(j, 1);
					j--;
				}
			}
			if(2 <= rgszFields.length){
				this.SetRecord(rgszFields[0], rgszFields.slice(1));
			}
		}
		
		return ;
	},
	SetRecord: function(szKey, rgPair){
		if("undefined"!=typeof(rgPair) && "undefined"!=typeof(rgPair)){
			this.rgstRecs[szKey]=rgPair;
		}
		return ;
	},
	GetRecord: function(szKey)	{
		return this.rgstRecs[szKey];
	}
};



function GetSubmitStr(stForm)
{
	var szRet="";
	for(var i=0;i<stForm.elements.length;i++){
		var stField=stForm.elements[i];
		if(stField.name=="")
			continue;
		if(i!=0)
			szRet+="&";
		if(stField.type=="checkbox" && true==stField.checked){
			szRet+=stField.name+"="+escape(stField.value);
		}else if(stField.type=="radio" && true==stField.checked){
			szRet+=stField.name+"="+escape(stField.value);
		}else if(stField.type=="select-one"){
			szRet+=stField.name+"="+escape(stField.options[stField.selectedIndex].value);
		}else if(stField.type=="select-multiple"){
			var rgOptions=stField.options;
			for(var j=0;j<rgOptions.length;j++)
				if(rgOptions[j].selected)
					szRet+=stField.name+"="+escape(rgOptions[j].value);
		}else{
			szRet+=stField.name+"="+escape(stField.value);
		}
	}
	
	return szRet;
}

function ModuleFormDoSubmit(szID)
{
	var stModule=stLM.GetPanel(szID);
	ConfLoaderAdapter.SetModules(stLM.GetPanels());
	ConfLoaderAdapter.SetReRender(true);

	var stForm=document.forms["prefset"+szID];
	var szInvokeData=GetSubmitStr(stForm)+"&m="+GetMagicNo()+"&crumb=$crumb&cmd=setconf&lmid="+szID;
	var stEngine=new MAJAXEngine("/cgi-bin/portal?"+szInvokeData, ConfLoaderAdapter);
	stEngine.DoRequest();

	return false;
}

function ModuleFormChk(szID)
{
	var stModule=stLM.GetPanel(szID);
	var stForm=document.forms["prefset"+szID];
	if(stModule && stForm){
		if(stModule.FormChk){
			if(true==stModule.FormChk(stForm)){
				ModuleFormDoSubmit(szID);
			}
		}else{
			ModuleFormDoSubmit(szID);
		}
	}
	return false;
}


var DDAux={
	stSrc: null,
	stAuxDiv: null,
	stOffset: null,
	SetSrc: function(stElement){
		this.stSrc=stElement;
	},
	GetSrc: function(){
		return this.stSrc;
	},
	SetAuxDiv: function(stAuxDiv){
		this.stAuxDiv=stAuxDiv;
	},
	GetAuxDiv: function(){
		return this.stAuxDiv;
	},
	GetHeight: function(){
		var stSrc=this.GetSrc();
		if(stSrc)
			return stSrc.offsetHeight;
		return 0;
	},
	SetOffset: function(stOffset){
		if(null==stOffset || "undefined"==typeof(stOffset))
			return ; 
		this.stOffset=stOffset;
	},
	GetOffset: function(){
		if(null==this.stOffset)
			return {x:0, y:0};
		return this.stOffset;
	},

	GetCenterPoint: function(){
		var divAux=this.GetAuxDiv();
		if(null!=divAux){
			var stTopLeft=getPosition(divAux);
			var xPos=0, yPos=0;
			xPos = stTopLeft.x + (divAux.offsetWidth/2);
			yPos = stTopLeft.y + (divAux.offsetHeight/2);
			return {x: xPos, y:yPos};
		}
		return null;
	},
	
	
	Show: function(stPos){
		var stElement=this.GetSrc();
		var nWidth=((0<=parseInt(stElement.offsetWidth))?parseInt(stElement.offsetWidth):0);
		var nHeight=((0<=parseInt(stElement.offsetHeight))?parseInt(stElement.offsetHeight):0);
		var divAux=document.createElement("DIV");

		divAux.id="AUX"+stElement.id;
		document.body.appendChild(divAux);
		divAux.style.display = 'block';
		divAux.style.width  = nWidth+"px";
		divAux.style.height = nHeight+"px";
		divAux.style.position = 'absolute';
		var stCloneDiv=stElement.cloneNode(true);
		stCloneDiv.id="CLONE"+stElement.id;
		divAux.appendChild(stCloneDiv);
		
		this.SetAuxDiv(divAux);
	},
	Hide: function(){
		document.body.removeChild(this.GetAuxDiv());
		this.SetAuxDiv(null);
	},

	Move: function(stPos, rgContainers){
		var divAux=this.GetAuxDiv();
		var stOffset=this.GetOffset();
		
		// move our helper div to wherever the mouse is (adjusted by mouseOffset)
		divAux.style.left = (stPos.x-stOffset.x)+"px";
		divAux.style.top  = (stPos.y-stOffset.y)+"px";
		
		if(null!=this.ChkHoverBlocks(rgContainers, true)){
			divAux.style.opacity = 90/100;
			divAux.style.filter ="alpha(opacity="+90+")";
		}else{
			divAux.style.opacity = 20/100;
			divAux.style.filter ="alpha(opacity="+20+")";
		}
	},
	
	ChkHoverBlocks: function(rgBlocks, bContainer){
		var stCPoint=this.GetCenterPoint();
		if(rgBlocks && stCPoint){
			for(var i=0;i<rgBlocks.length;i++){
				var stPosBlock = getPosition(rgBlocks[i]);
				var nStartLeft=stPosBlock.x;
				var nStartTop=stPosBlock.y;
				var nAuxHeight=(true==bContainer)?this.GetHeight():0;
				if((nStartLeft < stCPoint.x) && (nStartTop < stCPoint.y) &&
					((nStartLeft + rgBlocks[i].offsetWidth) > stCPoint.x) &&
					((nStartTop  + rgBlocks[i].offsetHeight + nAuxHeight) > stCPoint.y)){
						return rgBlocks[i];
				}
			}
		}
		return null;
	}

};


function ModuleMoving(stPos, szModuleID)
{
	var stContainer=DDAux.ChkHoverBlocks(stLM.GetLayout().GetAllContainer(), true);
	var stModule=stLM.GetPanel(szModuleID);	
	if(null == stContainer){
		stModule.Display(false);
	}else{
		var stBefNode=DDAux.ChkHoverBlocks(stLM.GetPanelsDiv(), false);
		if(null==stBefNode){
			stContainer.appendChild(stModule.GetElement());
		}else{
			stContainer.insertBefore(stModule.GetElement(), stBefNode);
		}
		stModule.Display();
	}
}

function ModuleStartToDrag(stEvent, szModuleID)
{
	var OnMouseUp= function (ev){
		ModuleStartToDrag.bModuleMoving=false;
		ev = ev || window.event;

		var stPos=mouseCoords(ev);
		DDAux.Hide();

		var stModule=stLM.GetPanel(szModuleID);
		stModule.Hide(false);
		stModule.Display();

		document.body.onmouseup=ModuleStartToDrag.OrigMouseUp;
		document.body.onmousemove=ModuleStartToDrag.OrigMouseMove;
		ModuleStartToDrag.OrigMouseUp=null;
		ModuleStartToDrag.OrigMouseMove=null;
		SaveLayout();
		return false;
	};

	var OnMouseMove= function (ev){
		if(true==ModuleStartToDrag.bModuleMoving){
			ev = ev || window.event;
			var stPos=mouseCoords(ev);
	
			DDAux.Move(stPos, stLM.GetLayout().GetAllContainer());
			ModuleMoving(stPos, szModuleID);
			return false;
		}
	};

	var bDown=true;
	(function(){
		if(true==ModuleStartToDrag.bModuleMoving){
			OnMouseUp(stEvent);
			return ;
		}
		stModule=stLM.GetPanel(szModuleID);
		if(stModule){
			stEvent = stEvent || window.event;

			DDAux.SetSrc(stModule.GetElement());
			DDAux.SetOffset(getMouseOffset(stModule.GetElement(), stEvent));
			DDAux.Show(mouseCoords(stEvent));
			stModule.Hide();

			bDown=false;

			ModuleStartToDrag.OrigMouseUp=document.body.onmouseup;
			ModuleStartToDrag.OrigMouseMove=document.body.onmousemove;
			document.body.onmouseup=OnMouseUp;
			document.body.onmousemove=OnMouseMove;
			ModuleStartToDrag.bModuleMoving=true;
		}
	})();
	return bDown;
}
ModuleStartToDrag.OrigMouseUp=null;
ModuleStartToDrag.OrigMouseMove=null;
ModuleStartToDrag.bModuleMoving=false;
ModuleStartToDrag.stAux=null;

function writeHistory(szMsg){
	return ;
	historyDiv = document.getElementById("History1");
	if(historyDiv){
		historyDiv.appendChild(document.createTextNode(szMsg));
		historyDiv.appendChild(document.createElement('BR'));
		historyDiv.scrollTop += 50;
	}
}

//-->
</script>
<STYLE>
LEGEND {
	FONT-WEIGHT: bold; FONT-SIZE: 12px; COLOR: #666699; FONT-FAMILY: verdana, tahoma, arial
}
FIELDSET {
	PADDING-RIGHT: 3px; PADDING-LEFT: 3px; PADDING-BOTTOM: 3px; PADDING-TOP: 3px
}
.History {
	FONT-SIZE: 10px; OVERFLOW: auto; WIDTH: 100%; FONT-FAMILY: verdana, tahoma, arial; HEIGHT: 82px
}
</STYLE>
</head>
<body style="margin: 0px; padding: 0px;" onload="init();" >
<script language="JavaScript">CreatePageTitle("$##MSG_0004##!JM");</script>
<div align="right">
	<button type="button" onclick="ShowAddNewPanel();" class="TextButton" >$##MSG_0005##</button>
	<select id="allLayoutSelect" onchange="ChangeLayout();" class="NormalText"></select>
</div>
<div id="rearbase" style="width: 100%; display: none;">
$lpDIV	
<div id="$nID" szModule="$szModule" szOrder="$szOrder" nX="$nX" nY="$nY" nWidth="$nWidth" nHeight="$nHeight" style="width: 100%; padding-bottom: 20px; padding-right: 5px; position: relative;"></div>
$$lpDIV
</div>
<!--
<FIELDSET>
<LEGEND>History</LEGEND>
<DIV class=History id=History1></DIV></FIELDSET>
-->
</body>
</html>
