﻿var MaxPageSize=1;
var MinPageSize=1;
var DefaultPageNo=1;

function _InitialContentDivWidth(pDivID)
{	
	var objDiv = document.getElementById(pDivID);
	if (objDiv != null)
	{
		gUserDefWidth = objDiv.parentElement.width;
		objDiv.parentElement.width="100%";				
	}
}

function GoToMoreIndexPage(guid,lguid,formName,pageSize,curChannel)
{	
	if (formName == '敬告客戶')
		window.location.href = '/Finairport/Chn_3/Chn_3_1_7/Chn_3_1_7_3/Chn_3_1_7_3_5/'; 
	var moreIndexPosting = "";
	var currentChnGuid = "";
	if (document.getElementById('_CHNGUID')) currentChnGuid = document.getElementById('_CHNGUID').value ;
	
	moreIndexPosting += "?GUID=" + guid;
	moreIndexPosting += "&CH=" + curChannel;
	moreIndexPosting += "&MODE=P" ;
	moreIndexPosting += "&_PAGESIZE=" + pageSize;
	moreIndexPosting += "&_PAGENO=" + DefaultPageNo;
	moreIndexPosting += "&SRC=PagerList";
	moreIndexPosting += "&_CHNGUID=" + currentChnGuid;    //CMS channel GUID
	moreIndexPosting += "&_ENDCHNNAME=" + escape(formName); //CMS child channel Name
	moreIndexPosting += "&HISTORY=YES";
	moreIndexPosting += GetFilterCriteria();
	AJAX_Send("Svc_Content.asp" + moreIndexPosting,lguid,'');

	if (document.all.chlName !=null ) 
		document.all.chlName.innerText = formName;
	if (document.all.filterTD != null)		
		document.all.filterTD.style.display="none";
}

function _GoToMoreIndexPage(guid,formName)
{	
	var moreIndexPosting = "/Finairport/Chn_Admin/MoreIndex?DSGUID=" + guid ;
	var currentChnGuid = document.getElementById('_CHNGUID').value;	
	
	moreIndexPosting += "&MODE=P" ;
	moreIndexPosting += "&_PAGESIZE=" + MaxPageSize;
	moreIndexPosting += "&_PAGENO=" + DefaultPageNo;
	moreIndexPosting += "&SRC=PagerList";
	moreIndexPosting += "&_CHNGUID=" + currentChnGuid;    //CMS channel GUID
	moreIndexPosting += "&_ENDCHNNAME=" + escape(formName); //CMS child channel Name
	moreIndexPosting += "&HISTORY=YES";
	moreIndexPosting += GetFilterCriteria();
	window.location.href=moreIndexPosting;	
}

function GoToMoreIndexPageFmHome(guid,formName,cmsPath)
{	
	var moreIndexPosting = "/Finairport/Chn_Admin/MoreIndex?DSGUID=" + guid ;
	var currentChnGuid = "";

	moreIndexPosting += "&MODE=P" ;
	moreIndexPosting += "&_PAGESIZE=" + MaxPageSize;
	moreIndexPosting += "&_PAGENO=" + DefaultPageNo;
	moreIndexPosting += "&SRC=PagerList";
	moreIndexPosting += "&_CHNGUID=" + currentChnGuid;    //CMS channel GUID
	moreIndexPosting += "&_ENDCHNNAME=" + escape(formName); //CMS child channel Name
	moreIndexPosting += "&_CHNPATH=" + cmsPath;	
	moreIndexPosting += "&HISTORY=YES";
	window.location.href=moreIndexPosting;
}

function GoToContentPage(guid,articleGuid,formName,attFolder,attCategory,attName,lguid,dguid,cmsPath,fmEmail,flag1)
{	
	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;
		if (flag1=='Y')
			return;		
	}

	if (cmsPath !=null && cmsPath !='')
	{
		GoToContentPageFmHome(guid,articleGuid,formName,cmsPath);
		bResult = true;
		return;
	}
	//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(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, "^");
		}

		//--- For BT Integrate
		var myQS = new myQuerystring();
		lBT = myQS.get("bs","NO");
		if (lBT != "NO")
		{
			contentPosting+= "&IDNO=2";
		}
		//alert(contentPosting+"\n\n"+lguid);
		if (fmEmail!=null && fmEmail=='Y')
			AJAX_Send("http://www.polaris.com.tw/factory/Svc_Content.asp?a=a" + contentPosting,lguid,'');			
		else
			AJAX_Send("Svc_Content.asp?a=a" + contentPosting,lguid,'');			
		bResult=true; 
	}

	/*if (!bResult)	alert("上稿的附件種類不符此表單[ " + formName + " ]內容需求!");*/
}

function _GoToContentPage(guid,articleGuid,formName,attFolder,attCategory,attName)
{	
	var contentPosting="";	
	var bResult=false;
		
	if (attCategory == "HTML" || 
		attCategory == "Download" || 
		attCategory == "Other" ||
		attCategory == "")		
	{
		contentPosting = "/Finairport/Chn_Admin/Content?DSGUID=" + guid + "&_GUID=" + articleGuid;
		var currentChnGuid="";
		if (document.getElementById('_CHNGUID') !=null)	
			currentChnGuid = document.getElementById('_CHNGUID').value;

		contentPosting += "&MODE=1";
		contentPosting += "&SRC=Content";
		contentPosting += "&_CHNGUID=" + currentChnGuid;
		contentPosting += "&_ENDCHNNAME=" + escape(formName);
		contentPosting += GetFilterCriteria();
		window.location.href=contentPosting;
		bResult=true;
	}

	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;
	}

	if (!bResult)
		alert("上稿的附件種類不符此表單[ " + formName + " ]內容需求!");
}

function GoToContentPageFmHome(guid,articleGuid,formName,cmsPath,attFolder,attCategory,attName)
{	
	var contentPosting="";	
	if (attCategory != null && 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);			
	}

	var contentPosting = "/Finairport/Chn_Admin/Content?DSGUID=" + guid + "&_GUID=" + articleGuid;
	var currentChnGuid="";

	contentPosting += "&MODE=1";
	contentPosting += "&SRC=Content";
	contentPosting += "&_CHNGUID=" + currentChnGuid;
	contentPosting += "&_ENDCHNNAME=" + escape(formName);
	contentPosting += "&_CHNPATH=" + cmsPath;	
	window.location.href=contentPosting;
}

function GoToContentInIFramePage(strUrl,formName)
{	
	if (strUrl != null && strUrl !='')
	{
	var contentPosting = "/Finairport/Chn_Admin/ContentInIFrame?a=a";
	var currentChnGuid="";
	if (document.getElementById('_CHNGUID') !=null)	
		currentChnGuid = document.getElementById('_CHNGUID').value;
	contentPosting += "&_CHNGUID=" + currentChnGuid;
	//contentPosting += "&_ENDCHNNAME=" + escape(formName);
	//strUrl = "#CONTENT#2006#2006-09#2006-09-04#2006-09-04-2323_rad7E879#aa.htm";	
	contentPosting += "&TargetUrl=" + escape(strUrl) ;
	window.location.href=contentPosting;		
	}
}

function GoToCMSPosting(strUrl)
{
	window.location.href=strUrl;
}

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)
		{
			var oSubjects = oItems.getElementsByTagName('SPAN');			
			for(spanIndex=0;spanIndex<oSubjects.length;spanIndex++)
			{
				if (oSubjects[spanIndex].id.indexOf('Spn_Subject_')>=0)
				{
					//var strTemp = oSubjects[spanIndex].innerHTML.toUpperCase();					
					//if (strTemp.indexOf('<P>') >=0 ||
					//	strTemp.indexOf('<BR>') >=0)
					//{ 
						oSubjects[spanIndex].innerHTML = oSubjects[spanIndex].innerText;
					//}					
				}
			}

			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 GetFilterCriteria()
{	
	var queryString="";	
	var countryId=-1;
	var productId=-1;

	if (document.getElementById('Filter_ddlProduct') !=null)
		productId = document.getElementById('Filter_ddlProduct').options[document.getElementById('Filter_ddlProduct').selectedIndex].value;
	if (document.getElementById('Filter_ddlCountry') !=null)
		countryId = document.getElementById('Filter_ddlCountry').options[document.getElementById('Filter_ddlCountry').selectedIndex].value; 

	queryString = MergeFilterString(countryId,productId);

	if (queryString =="")
	{	
		var myQS = new myQuerystring();
		countryId = myQS.get("CountryID",-1);	
		productId = myQS.get("ProductID",-1);	
		queryString = MergeFilterString(countryId,productId);
	}

	return queryString;
}

function MergeFilterString(countryId,productId)
{
	var result="";
	var FilterCmdPatternInXmlForm1 = "&CountryID={0}&ProductID={1}";
	var FilterCmdPatternInXmlForm2 = "&CountryID={0}";	

	if (parseInt(productId,10) > 0 && parseInt(countryId,10) > 0)	
	{
		result = FilterCmdPatternInXmlForm1;
		result = result.replace("{0}",countryId);		
		result = result.replace("{1}",productId);		
	}
		
	if (parseInt(productId,10) <= 0 && parseInt(countryId,10) > 0)
	{
		result = FilterCmdPatternInXmlForm2;
		result = result.replace("{0}",countryId);					
	}

	return result;
}

/* Get QueryString Name,Value pairs from Client-side
*/
function myQuerystring(qs) 
{ 	
	this.params = new Object();
	this.get = myQuerystring_get
	
	if (qs == null)
		qs=location.search.substring(1,location.search.length);

	if (qs.length == 0) return;

	qs = qs.replace(/\+/g, ' ');
	var args = qs.split('&');	

	for (var i=0;i<args.length;i++)
	{
		var value;
		var pair = args[i].split('=');
		var name = unescape(pair[0]);

		if (pair.length == 2)
			value = unescape(pair[1]);
		else
			value = name;
		
		this.params[name] = value;
	}
}

function myQuerystring_get(key, defaultValue) 
{
	if (defaultValue == null) defaultValue = null;
	
	var value=this.params[key];
	if (value==null) value=defaultValue;
	
	return value;
}

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' style='padding-left:5px;'>" + 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>";												
				if (oPadding.children(0) !=null)
				{
					oPadding.removeChild(oPadding.children(0));
				}
				oPadding.insertAdjacentHTML("beforeEnd",sHTML);
			}
		} 	
	}
	catch(e)
	{	
		//alert(e.number & 0xFFFF);
		alert(e.description);
	}
}