﻿var MaxPageSize=1;
var MinPageSize=1;
var DefaultPageNo=1;

function GoToContentPage(guid,articleGuid,formName,attFolder,attCategory,attName,lguid,dguid)
{	
	var contentPosting="";	
	var bResult=false;
	
	if (attCategory == "OpenNew")
	{
		if (attFolder =='' && document.getElementById("gFolder_" + articleGuid)!=null)		
			attFolder = document.getElementById("gFolder_" + articleGuid).innerHTML;

		contentPosting = "/CONTENT/" + attFolder + "/" + attName;
		oStyle  = "height=" + window.screen.availHeight + ",width=" + window.screen.availWidth;		
		oStyle += ",left=0,top=0,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes";		
		window.open(contentPosting,"_blank",oStyle);	
		bResult = true;
	}
	else
	/*if (attCategory == "HTML" || 
		attCategory == "Download" || 
		attCategory == "Other" ||
		attCategory == "")		*/
	{
		var currentChnGuid="";
		if (document.getElementById('_CHNGUID') !=null)	
			currentChnGuid = document.getElementById('_CHNGUID').value;

		contentPosting += "&GUID=" + guid;
		contentPosting += "&_GUID=" + articleGuid;
		contentPosting += "&MODE=CL"; // Default Content Layout
		//contentPosting += "&MODE=PL"; // Default Pager Layout
		//contentPosting += "&MODE=1";
		contentPosting += "&SRC=Content"; //????
		contentPosting += "&_CHNGUID=" + currentChnGuid;
		contentPosting += "&_ENDCHNNAME=" + escape(formName);
		contentPosting += GetFilterCriteria();
		contentPosting += "&HISTORY=YES";
		
		// determine previous XPATH
		if (dguid && document.all(dguid))
		{ 
			//alert("測試訊息\n"+unescape(document.all(dguid).getAttribute("XPATH")));
			if (document.all(dguid).getAttribute("XPATH"))
				contentPosting += "&PREV_XPATH=" + document.all(dguid).getAttribute("XPATH");
			if (document.all(dguid).getAttribute("URL"))
				contentPosting += "&PREV_URL=" + document.all(dguid).getAttribute("URL").replace(/&/g, "^");
		}
		
		//alert(contentPosting);
		AJAX_Send("Svc_Content.asp?a=a" + contentPosting,lguid,'');			
		bResult=true; 
	}

	/*if (!bResult)	alert("上稿的附件種類不符此表單[ " + formName + " ]內容需求!");*/
}

function _GoToContentPage(guid,articleGuid,formName,attFolder,attCategory,attName,caller)
{	
	var contentPosting;
	var currentChnGuid = "";
	
	if (document.getElementById('_CHNGUID') !=null)	
		currentChnGuid = document.getElementById('_CHNGUID').value;	

	if (attCategory == "HTML" || 
		attCategory == "Download" || 
		attCategory == "Other" ||
		attCategory == "")		
	{	
		//if (caller == "HOME")	
		//	contentPosting = "/WarrantNet/Content?";
		//else
			contentPosting = "/WarrantNet/Chn_Admin/Content?";
		contentPosting += "DSGUID=" + guid + "&_GUID=" + articleGuid;
		contentPosting += "&MODE=1";
		contentPosting += "&SRC=Content";
		contentPosting += "&_CHNGUID=" + currentChnGuid;
		contentPosting += "&_ENDCHNNAME=" + escape(formName);
		alert (contentPosting);
		window.location.href=contentPosting;
		return;
	}

	if (attCategory == "OpenNew")
	{	
		//contentPosting =  attFolder + attName;
		contentPosting = "/CONTENT/" + attFolder + "/" + attName;
		//alert("測試訊息!\n"+contentPosting);
		oStyle  = "height=" + window.screen.availHeight + ",width=" + window.screen.availWidth;		
		oStyle += "left=0,top=0,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes";	
		alert(contentPosting );
		window.open(contentPosting,"_blank",oStyle);	
		return;
	}
	else
	{	
		contentPosting = "/WarrantNet/Chn_Admin/Redirect?DSGUID=" + guid + "&_GUID=" + articleGuid;		
		oStyle  = "height=" + window.screen.availHeight + ",width=" + window.screen.availWidth;		
		oStyle += "left=0,top=0,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes";		
		window.open(contentPosting,"_blank",oStyle);
		return;
	}

	alert("上稿的附件種類不符此表單[ " + formName + " ]內容需求!");
}

function DivBlockVisible(pDivID,bAlwaysDisplay)
{
	try
	{	
		var strContent="";
		var spanID = "MainContent_" + pDivID;
		var tdPagerID = "PagerTD_" + pDivID;
		var oItems = document.getElementById(spanID);
		
		bAlwaysDisplay = bAlwaysDisplay==null ? false: bAlwaysDisplay;
		
		if (oItems !=null)
		{
			for(itemIndex=0;itemIndex<oItems.children.length;itemIndex++)
			{
				strContent +=oItems.children.item(itemIndex).innerText;			
			}
			
			if (strContent.length<=0)
			{	
				if (!bAlwaysDisplay)
					ShowHindeObj(pDivID,"OFF");					
				ShowHindeObj(tdPagerID,"OFF");
				return false;
			}
			else
			{	
				ShowHindeObj(pDivID,"ON");
				ShowHindeObj(tdPagerID,"ON");				
				return true;
			}
		} 
	}
	catch(e)
	{
		alert(e.message);
	}
	return false;
}

function ShowHindeObj(pObjID,pStatus)
{
	var oObj = document.getElementById(pObjID);
	if (oObj != null)
	{
		switch (pStatus)
		{
		case "ON":
			oObj.style.display ="";
			break;
		case "OFF":
			oObj.style.display ="none";
			break;
		default:
			break;
		}
	}
}

function DoPadding(pDivID,pTopN,pMsg)
{		
	try 
	{	
		var sHTML="";	
		var oPadding = document.getElementById("PaddingDiv_" + pDivID);;
		var topN = isNaN(parseInt(pTopN)) ? 0 : parseInt(pTopN);		
		if (DivBlockVisible(pDivID,true))
		{		
			var oSpan = document.getElementById("MainContent_" + pDivID);
			var selN = oSpan.childNodes.length;
			var paddingCount = topN - selN;
			
			for(i=0;i<paddingCount;i++)
			{	
				sHTML += "<TR height='15px'><TD class='c15'>&nbsp;</TD></TR>";				
			}	
			
			if (sHTML !="" && oPadding != null)
			{
				sHTML= "<Table cellpadding='0' cellspacing='0' align='center'>" + sHTML + "</Table>";											
				oPadding.insertAdjacentHTML("beforeEnd",sHTML);
			}				
		}
		else
		{	
			var midRow = parseInt(topN/2);
			
			for(i=0;i<topN;i++)
			{	
				if (i==midRow)
					sHTML += "<TR height='15px'><TD  class='c15'>" + pMsg + "</TD></TR>";				
				else
					sHTML += "<TR height='15px'><TD  class='c15'>&nbsp;</TD></TR>";				
			}
			
			if (sHTML !="" && oPadding != null)
			{
				sHTML= "<Table cellpadding='0' cellspacing='0' align='center'>" + sHTML + "</Table>";								
				oPadding.insertAdjacentHTML("beforeEnd",sHTML);
			}
		} 	
	}
	catch(e)
	{	
		//alert(e.number & 0xFFFF);
		alert(e.description);
	}
}