﻿<!--

var strCN = "";
var nowDateTime = false;
var responseText = new Array();
var aryElement = new Array();

// ==============================================================================================================
// 	
// ==============================================================================================================

function FormFind(thsForm)
{
	if (thsForm.Code.title == "" || thsForm.Code.value == "")
	{
		alert("請輸入關鍵字");
		thsForm.Code.focus();
		return false;
	}

	switch (thsForm.Purpose.value)
	{
		case "title":
		case "content":

			thsForm.action = "Refer.htm";

			break;

		default:

			thsForm.action = "Find.htm";

			break;
	}

	return true;
}

// ==============================================================================================================
// 	回傳此元素為 tagName 的父節點
// ==============================================================================================================

function ParentNodeTagName(objElement, ElementTagName)
{
	ElementTagName = ElementTagName.toUpperCase();

	do
	{
		objElement = objElement.parentNode;
	}
	while (objElement.tagName != ElementTagName)

	return objElement;
}

// ==============================================================================================================
// 	套用 css
// ==============================================================================================================

function hrefClassName(strApply)
{
	setCookie("Apply", strApply);

	document.getElementById("cssApply").href = "css/" + strApply + "/default.css";
}

function initClassName()
{
	var strApply = getCookie("Apply");

	if (strApply == "")
		hrefClassName("yellow");
	else
		hrefClassName(strApply);
}

// ==============================================================================================================
// 	亂數
// ==============================================================================================================

function Rnd()
{
	var theDate = new Date();

	return theDate.getMinutes() + "" + theDate.getSeconds() + "" + theDate.getMilliseconds() + "" + Math.floor(Math.random()*10000000000000000);
}

// ==============================================================================================================
// 	Ajax
// ==============================================================================================================

function Ajax()
{
	this.XMLHTTP = false;

	this.receives = function () 	{

	}

	this.reqeust = function () 	{

		var thsClass = this;

		this.XMLHTTP.onreadystatechange = function ()	{

			if (thsClass.XMLHTTP.readyState == 4 && thsClass.XMLHTTP.status == 200)
				thsClass.receives();
		}
	}

	if (window.XMLHttpRequest)
	{
		this.XMLHTTP = new XMLHttpRequest();

		this.reqeust();
	}
	else if (window.ActiveXObject)
	{
		try
		{
			this.XMLHTTP = new ActiveXObject("Msxml2.XMLHTTP");

			this.reqeust();
		}
		catch (e)
		{
			try
			{

				this.XMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");

				this.reqeust();
			}
			catch (e)
			{
			}
		}
	}
}

// ==============================================================================================================
// 
// ==============================================================================================================

function LogState(thsElement)
{
	thsElement = thsElement.parentNode;

	var oAjax = new Ajax();

	if (oAjax.XMLHTTP)
	{
		oAjax.receives = function () 	{

			var strCN = oAjax.XMLHTTP.responseText;

			strCN = RTrim(LTrim(strCN));

			if (strCN == "")
			{
				thsElement.innerHTML = "<a class='top-login' href='Interface.htm'>登入</a>";
			}
			else
			{
				thsElement.innerHTML = "<a class='top-login' href='Logout.aspx'>登出</a>";

				thsElement = document.getElementById("tdLogState");

				thsElement.innerHTML = "　　　<a href='My/" + encodeURIComponent(strCN) + "' class='topgrouplink' style='font-size: 12px;'>" + strCN + "</a>，您好～進入「<a href='Interface.htm' class='topgrouplink' style='font-size: 12px;'>我的管理介面</a>」";
			}
		}

		var url = "XML/WorldLog.aspx?rnd=" + Rnd();

		oAjax.XMLHTTP.open("GET", url, true);
		oAjax.XMLHTTP.send(null);
	}
}

// ==============================================================================================================
// 	模組設定
// ==============================================================================================================

function JSON_Handle(strName)
{
	aryElement[strName] = new Array();

	var objElement = document.getElementsByName(strName);

	for (var i=0; i<objElement.length; i++)
		aryElement[strName][i] = objElement[i];
}

// ==============================================================================================================
// 	廣告模組
// ==============================================================================================================

function JSON_Advertise(thsElement)
{
	thsElement = ParentNodeTagName(thsElement, "TD");

	var oJSON = responseText["advertise"];

	if (oJSON)
	{
		var strId, strUrl, strText;
		var strHTML = "<table width='100%' border='0' cellpadding='0' cellspacing='0'><tr>";

		for (var i=1; i<oJSON.ADVERTISE.length; i++)
		{
			strId = oJSON.ADVERTISE[i].ID;
			strUrl = oJSON.ADVERTISE[i].URL;
			strText = oJSON.ADVERTISE[i].TEXT;

			strHTML += "<td align='center' nowrap><a href='http://ad.cnyes.com/cnYESAD/adredir.asp?ciid=" + strId + "&url=" + strUrl + "' target='_blank' class='LinkTop'>" + strText + "</a></td>";
		}

		strHTML += "</tr></table>";

		thsElement.innerHTML = strHTML;
	}
}

// ==============================================================================================================
// 	最新情報模組
// ==============================================================================================================

function JSON_NewInfo(thsElement)
{
	thsElement = ParentNodeTagName(thsElement, "TD");

	var oJSON = responseText["newinfo"];

	if (oJSON)
	{
		var strId, strTitle, strDateTime;
		var strHTML = "<table width='100%' border='0' cellpadding='2' cellspacing='1'>";

		for (var i=1; i<oJSON.DOCUMENT.length; i++)
		{
			strId = oJSON.DOCUMENT[i].ID;
			strTitle = oJSON.DOCUMENT[i].TITLE;
			strDateTime = FormatDateTime(oJSON.DOCUMENT[i].DATETIME, "yyyy/m/d h:n:s");
	
			strHTML += "<tr>";
			strHTML += "<td></td>";
			strHTML += "<td width='10'><img src='images/arrow.gif' /></td>";
			strHTML += "<td>";
			strHTML += "<a href='My/cnyesblog/Content.htm?DocumentId=" + strId + "' class='newsstation'>" + HTMLEncode(strTitle) + "</a>";
	
			if ((new Date(strDateTime)) >= nowDateTime)
				strHTML += "<img src='images/new.gif'>";

			strHTML += "</td>";
			strHTML += "</tr>";
		}
	
		strHTML += "</table>";

		thsElement.innerHTML = strHTML;
	}
}

// ==============================================================================================================
// 	康樂股長
// ==============================================================================================================

function JSON_CnyesFun(thsElement)
{
	thsElement = ParentNodeTagName(thsElement, "TD");

	var oJSON = responseText["cnyesfun"];

	if (oJSON)
	{
		var strMy = encodeURIComponent(oJSON.CN);
		var strSummary = oJSON.SUMMARY;

		strSummary = strSummary.replace("<P>", "<div>");
		strSummary = strSummary.replace("</P>", "</div>");

		var strHTML = "<table width='100%' border='0' cellspacing='0' cellpadding='3'>";

		strHTML += "<tr>";
		strHTML += "<td>";
		strHTML += "<a class='main-title' href='My/cnyes-fun/Content.htm?DocumentId=" + oJSON.ID + "'><span style='font-size: 14px;'>" + HTMLEncode(oJSON.TITLE) + "</span></a>";
		strHTML += "<div><a class='content-link' href='My/" + strMy + "/Content.htm?DocumentId=" + oJSON.ID + "'>" + strSummary + "</a></div>";
		strHTML += "</td>";
		strHTML += "</tr>";
		strHTML += "</table>";

		thsElement.innerHTML = strHTML;
	}
}

// ==============================================================================================================
// 	熱門投票
// ==============================================================================================================

function VoteSubmit(thsForm)
{
	thsForm = ParentNodeTagName(thsForm, "FORM");

	if (thsForm.choice.length)
	{
		for (var i=0; i<thsForm.choice.length; i++)
		{
			if (thsForm.choice[i].checked)
			{
				thsForm.submit();
				return false;
			}
		}
	}
	else
	{
		if (thsForm.choice.checked)
		{
			thsForm.submit();
			return false;
		}
	}

	alert("您尚未作答");

	return false;
}

function JSON_Vote(thsElement)
{
	thsElement = ParentNodeTagName(thsElement, "TD");

	var oJSON = responseText["vote"];
	
	if (oJSON)
	{
		var strHTML;

		if (oJSON.SN == "")
		{
			strHTML = "";
		}
		else
		{
			strHTML = "<table width='100%' border='0' cellpadding='0' cellspacing='1' style='background-color:#CCCCCC;'>";
			strHTML += "<tr>";
			strHTML += "<td class='barbg-overall' height='30'>";
			strHTML += "<table width='100%' border='0' cellpadding='0' cellspacing='0'>";
			strHTML += "<tr>";
			strHTML += "<td><img src='images/blank.gif' width='20' height='10' alt='' /><span class='bartitle'>熱門投票</span></td>";
			strHTML += "<td align='right' valign='bottom'><a href='http://news.cnyes.com/vote.asp' class='content-linkwhite'>more</a>&nbsp;</td>";
			strHTML += "</tr>";
			strHTML += "</table>";
			strHTML += "</td>";
			strHTML += "</tr>";
			strHTML += "<tr>";
			strHTML += "<td style='background-color:#FFFFFF;'>";
			strHTML += "<form method='POST' action='http://news.cnyes.com/save.asp' onsubmit='return CheckData(this);' style='margin:0;'>";
			strHTML += "<table width='100%' border='0' cellpadding='0' cellspacing='3' class='content'>";
			strHTML += "<tr><td colspan='2'>" + HTMLEncode(oJSON.QUESTION) + "</td></tr>";
	
			if (oJSON.CHOICE1 != "")
				strHTML += "<tr><td valign='top'><input type='radio' name='choice' value='1'></td><td width='100%'>" + HTMLEncode(oJSON.CHOICE1) + "</td></tr>";
	
			if (oJSON.CHOICE2 != "")
				strHTML += "<tr><td valign='top'><input type='radio' name='choice' value='2'></td><td width='100%'>" + HTMLEncode(oJSON.CHOICE2) + "</td></tr>";
	
			if (oJSON.CHOICE3 != "")
				strHTML += "<tr><td valign='top'><input type='radio' name='choice' value='3'></td><td width='100%'>" + HTMLEncode(oJSON.CHOICE3) + "</td></tr>";
	
			if (oJSON.CHOICE4 != "")
				strHTML += "<tr><td valign='top'><input type='radio' name='choice' value='4'></td><td width='100%'>" + HTMLEncode(oJSON.CHOICE4) + "</td></tr>";
	
			if (oJSON.CHOICE5 != "")
				strHTML += "<tr><td valign='top'><input type='radio' name='choice' value='5'></td><td width='100%'>" + HTMLEncode(oJSON.CHOICE5) + "</td></tr>";
	
			strHTML += "<tr><td colspan='2' align='right'><a href='#' onclick='return VoteSubmit(this);'><img src='http://news.cnyes.com/images/send.gif' border='0'></a><a href='http://news.cnyes.com/vote.asp'><img src='http://news.cnyes.com/images/result.gif' border='0'></a></td></tr>";
			strHTML += "</table>";
			strHTML += "<input type='hidden' name='sn' value='" + oJSON.SN + "'>";
			strHTML += "</form>";
			strHTML += "</td>";
			strHTML += "</tr>";
			strHTML += "</table>";
		}

		thsElement.innerHTML = strHTML;
	}
}

// ==============================================================================================================
// 	世界俱樂部模組
// ==============================================================================================================

function JSON_BlogKind(thsElement)
{
	thsElement = ParentNodeTagName(thsElement, "TD");

	var oJSON = responseText["blogkind"];
	
	if (oJSON)
	{
		var j;
		var strHTML = "<table width='100%' border='0' cellpadding='0' cellspacing='1'><tr valign='top'>";
	
		for (var i=1; i<oJSON.MENU.length; i++)
		{
			strHTML += "<td>";
			strHTML += "<table width='100%' border='0' cellpadding='0' cellspacing='0' background='images/leftsidemenubg.gif'>";
			strHTML += "<tr height='25'><td background='" + oJSON.MENU[i].MENUIMAGE + "' align='center' class='content'>" + HTMLEncode(oJSON.MENU[i].MENUNAME) + "</td></tr>";
	
			for (j=1; j<oJSON.MENU[i].KIND.length; j++)
				strHTML += "<tr height='25'><td colspan='2'>&nbsp;<a href='Find.htm?purpose=blog&Code=" + oJSON.MENU[i].KIND[j].KINDID + "&KindName=" + encodeURIComponent(oJSON.MENU[i].KIND[j].KINDNAME) + "' class='club'>" + HTMLEncode(oJSON.MENU[i].KIND[j].KINDNAME) + "</a>&nbsp;<span class='number'>" + oJSON.MENU[i].KIND[j].COUNT + "</span></td></tr>";
	
			strHTML += "</table>";
			strHTML += "</td>";
	
			if (i % 2 == 0)
				strHTML += "</tr><tr valign='top'>";
		}
	
		strHTML += "</tr></table>";
		strHTML = strHTML.replace("<tr valign='top'></tr>", "");

		thsElement.innerHTML = strHTML;
	}
}

// ==============================================================================================================
// 	熱門投資講座模組
// ==============================================================================================================

function JSON_Invest(thsElement)
{
	thsElement = ParentNodeTagName(thsElement, "TD");

	var oJSON = responseText["invest"];
	
	if (oJSON)
	{
		var strTitle;
		var objElement = document.createElement("DIV");
		var strHTML = "<table width='100%' border='0' cellpadding='0' cellspacing='5'>";
	
		for (var i=0; i<oJSON.INVEST.length; i++)
		{
			strTitle = oJSON.INVEST[i].TITLE;
			strTitle = strTitle.replace("<font color=#660099>", "");
			strTitle = strTitle.replace("</font>", "");

			objElement.innerHTML = strTitle;

			strHTML += "<tr><td><a href='" + oJSON.INVEST[i].LINK + "' class='content-link'>" + objElement.innerHTML + "</a></td></tr>";
		}

		strHTML += "</table>";

		thsElement.innerHTML = strHTML;
	}
}

// ==============================================================================================================
// 	計數器
// ==============================================================================================================

function BrowserCounter()
{
	var Request = new aspRequest(document.URL);
	var strPath = Request.path;
	var strFile = Request.file;

	if (strFile.toLowerCase() == "default.aspx")
		strFile = "";

	var strScriptName = strPath + strFile;

	if (strScriptName != "")
		document.writeln("<iframe src='Browser.aspx?SCRIPT_NAME=" + strScriptName + "' marginwidth='0' marginheight='0' scrolling='no' border='0' frameborder='0' width='0' height='0'></iframe>")
}

// ==============================================================================================================
// 	實作 SQL 的 LTrim 方法
// ==============================================================================================================

function LTrim(strString)
{
	var strChar = " ";
	var i = 0;

	while (i < strString.length && strChar == " ")
	{
		strChar = strString.charAt(i);
	
		i++;
	}

	if (strChar == " ")
		return "";
	else
		return strString.substring((--i), strString.length);
}

// ==============================================================================================================
// 	實作 SQL 的 RTrim 方法
// ==============================================================================================================

function RTrim(strString)
{
	var strChar = " ";
	var i = strString.length - 1;

	while (i >= 0 && strChar == " ")
	{
		strChar = strString.charAt(i);
	
		i--;
	}

	if (strChar == " ")
		return "";
	else
		return strString.substring(0, (i+2));
}

// ==============================================================================================================
// 	實作 ASP 的 FormatDateTime() 方法
// ==============================================================================================================

function FormatDateTime(strDateTime, strFormat)
{
	var iHour = 0;

	strDateTime = strDateTime.toLowerCase();

	while (strDateTime.indexOf("&nbsp;") >= 0)
		strDateTime = strDateTime.replace("&nbsp;", " ");

	strDateTime = strDateTime.replace("-", "/");
	strDateTime = strDateTime.replace("-", "/");
	strDateTime = strDateTime.replace("上午", "");
	strDateTime = strDateTime.replace("am", "");

	if (strDateTime.indexOf("下午") >= 0)
	{
		strDateTime = strDateTime.replace("下午", "");
		iHour = 12;
	}

	if (strDateTime.indexOf("pm") >= 0)
	{
		strDateTime = strDateTime.replace("pm", "");
		iHour = 12;
	}

	strDateTime = new Date(strDateTime);

	if (strDateTime.getTime())
	{
		var strYear, strMonth, strDay, strHour, strMinute, strSecond, strMilliSecond;

		strYear = strDateTime.getFullYear();
		strMonth = "00" + (strDateTime.getMonth() + 1);
		strDay = "00" + strDateTime.getDate();
		strHour = "00" + (strDateTime.getHours() + iHour);
		strMinute = "00" + strDateTime.getMinutes();
		strSecond = "00" + strDateTime.getSeconds();
		strMilliSecond = strDateTime.getMilliseconds() + "000";

		strMonth = strMonth.substr(strMonth.length-2, 2);
		strDay = strDay.substr(strDay.length-2, 2);
		strHour = strHour.substr(strHour.length-2, 2);
		strMinute = strMinute.substr(strMinute.length-2, 2);
		strSecond = strSecond.substr(strSecond.length-2, 2);
		strMilliSecond = strMilliSecond.substr(0, 3);

		if (strHour == "12")
			strHour = "00";
		else if (strHour == "24")
			strHour = "12";

		strFormat = strFormat.replace("yyyy", strYear);
		strFormat = strFormat.replace("yy", strYear);
		strFormat = strFormat.replace("ms", strMilliSecond);
		strFormat = strFormat.replace("m", strMonth);
		strFormat = strFormat.replace("d", strDay);
		strFormat = strFormat.replace("h", strHour);
		strFormat = strFormat.replace("n", strMinute);
		strFormat = strFormat.replace("s", strSecond);

		return strFormat;
	}
	else
	{
		return "";
	}
}

// ==============================================================================================================
// 	實作 ASP 的 Replace() 方法
// ==============================================================================================================

function Replace(strString, strSub, strRep)
{
	var i = strString.indexOf(strSub);
	var strSubLen = strSub.length;
	var strRepLen = strRep.length;

	while (i >= 0)
	{
		strString = strString.substring(0, i) + strRep + strString.substring((i + strSubLen), strString.length);

		i = strString.indexOf(strSub, (i+strRepLen));
	}

	return strString;
}

// ==============================================================================================================
// 	實作 ASP 的 HTMLEncode 方法
// ==============================================================================================================

function HTMLEncode(strString)
{
	strString = Replace(strString, "&", "&amp;");

	while (strString.indexOf("<") >= 0)
		strString = strString.replace("<", "&lt;");

	while (strString.indexOf(">") >= 0)
		strString = strString.replace(">", "&gt;");

	while (strString.indexOf("\"") >= 0)
		strString = strString.replace("\"", "&quot;");

	return strString;
}

// ==============================================================================================================
// 	實作 ASP.NET 的 HTMLDecode 方法
// ==============================================================================================================

function HTMLDecode(strString)
{
	while (strString.indexOf("&lt;") >= 0)
		strString = strString.replace("&lt;", "<");

	while (strString.indexOf("&gt;") >= 0)
		strString = strString.replace("&gt;", ">");

	while (strString.indexOf("&quot;") >= 0)
		strString = strString.replace("&quot;", "\"");

	while (strString.indexOf("&amp;") >= 0)
		strString = strString.replace("&amp;", "&");

	return strString;
}

// ==============================================================================================================
// 	實作 ASP 的 Request.QueryString 物件
// ==============================================================================================================

function aspRequest(url)
{
	if (url)
	{
	}
	else
	{
		url = document.URL;
	}

	var urlpath, urlhash, urlary, varname, varval;
	var urlfile = (url + "?").split("?")[0];
	var urlquerystring = url.replace(urlfile, "");
	var s = urlfile.indexOf(":");
	var e = urlfile.lastIndexOf("/") + 1;

	s += 3;
	s = urlfile.indexOf("/", s);

	this.host = urlfile.substring(0, s);

	urlpath = urlfile.substring(s, e);
	urlfile = urlfile.substring(e, urlfile.length);
	urlquerystring = urlquerystring.replace("?", "");

	s = urlquerystring.lastIndexOf("#");

	if (s >= 0)
	{
		urlhash = urlquerystring.substring((s+1), urlquerystring.length);
		urlquerystring = urlquerystring.substring(0, s);
	}
	else
	{
		urlhash = "";
	}

	urlary = ("&" + urlquerystring).split("&");

	this.path = urlpath;
	this.file = urlfile;
	this.hash = urlhash;
	this.aryQueryString = new Array();

	for (var i=1; i<urlary.length; i++)
	{
		varname = (urlary[i] + "=").split("=")[0];
		varval = urlary[i].replace(varname + "=", "");
		varname = varname.toLowerCase();

		if (this.aryQueryString[varname])
			this.aryQueryString[varname] += "," + varval;
		else
			this.aryQueryString[varname] = varval;
	}

	this.QueryString = function (strQuery) {

		if (strQuery && strQuery != "")
		{
			strQuery = strQuery.toLowerCase();

			if (this.aryQueryString[strQuery])
				return this.aryQueryString[strQuery];
			else
				return "";
		}
		else
		{
			return urlquerystring;
		}
	}
}

// ==============================================================================================================
// 	Cookie 的操作
// ==============================================================================================================

function setCookie(theName, theValue)
{
	var theDate = new Date("2020/1/1 18:56:35");

	document.cookie = theName + "=" + escape(theValue) + ";expires=" + theDate.toUTCString();
}

function delCookie(theName)
{
	setCookie(theName, "");

	var theDate = new Date("1970/1/1 00:00:01");
	
	document.cookie = theName + "=;expires=" + theDate.toUTCString();
}

function getCookie(theName)
{
	theName += "=";

	var theCookie = document.cookie + ";";
	var s = theCookie.indexOf(theName);

	if (s < 0)
		return "";
	else
		return unescape(theCookie.substring((s + theName.length), theCookie.indexOf(";", s)));
}

// ==============================================================================================================
// 	顯示分頁數字
// ==============================================================================================================

function PageLine(Request, PageIndex, PageSize, RecordCount)
{
	var urlquery = "";
	var urlparam = "?";
	var PageCount = Math.ceil(RecordCount / PageSize);

	if ( (!isNaN(PageIndex)) && Number(PageIndex) > 0)
		PageIndex = Number(PageIndex);
	else
		PageIndex = 1;

	for (var varname in Request.aryQueryString)
	{
		if (varname != "pageindex" && varname != "")
		{
			urlquery += urlparam + varname + "=" + Request.aryQueryString[varname];
			urlparam = "&";
		}
	}
	
	i = PageIndex;

	if ((i + 4) > PageCount)
		i -= 4;
	
	if (i <= 4)
		i = 1;
	else
		i -= 4;

	var PageEnd = i + 9;
	var strHTML = "<table border='0' width='100%' cellspacing='3' cellpadding='0'><tr><td align='left'>共 " + RecordCount + " 筆</td><td align='center' class='Document-Title'>";

	if (PageIndex <= 1)
	{
		strHTML += "&lt;&lt;&nbsp;&nbsp;&lt;&nbsp; ";
	}
	else
	{
		strHTML += "<a href='" + Request.path + Request.file + urlquery + "'>&lt;&lt;</a>&nbsp;&nbsp;";

		var nxtPageIndex = PageIndex - 1;

		if (nxtPageIndex == 1)
			strHTML += "<a href='" + Request.path + Request.file + urlquery + "'>&lt;</a>";
		else
			strHTML += "<a href='" + Request.path + Request.file + urlquery + urlparam + "PageIndex=" + nxtPageIndex + "'>&lt;</a>";
	}

	if (RecordCount > 0)
	{
		for (; i<PageEnd && i<=PageCount; i++)
		{
			if (i == PageIndex)
			{
				strHTML += " <font color='#FF0000'>" + i + "</font> ";
			}
			else
			{
				if (i == 1)
					strHTML += " <a href='" + Request.path + Request.file + urlquery + "'>" + i + "</a> ";
				else
					strHTML += " <a href='" + Request.path + Request.file + urlquery + urlparam + "PageIndex=" + i + "'>" + i + "</a> ";
			}
		}
	}
	else
	{
		strHTML += " 1 ";
	}

	if (PageIndex >= PageCount)
		strHTML += "&gt;&nbsp;&nbsp;&gt;&gt;";
	else
		strHTML += "<a href='" + Request.path + Request.file + urlquery + urlparam + "PageIndex=" + (PageIndex+1) + "'>&gt;</a>&nbsp;&nbsp;<a href='" + Request.path + Request.file + urlquery + urlparam + "PageIndex=" + PageCount + "'>&gt;&gt;</a>";
	
	strHTML += "</td><td align='right'>" + PageIndex + " / " + PageCount + " 頁</td></tr></table>";

	return strHTML;
}

//-->