﻿<!--
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.aspx";

			break;

		default:

			thsForm.action = "Find.aspx";

			break;
	}

	return true;
}

// ==============================================================================================================
// 	廣告模組
// ==============================================================================================================

function RequestWorldAdvertise(thsElement)
{
	var httpRequest = AjaxRequest();
	var objElement = ParentNodeTagName(thsElement, "TD");
	
	if (httpRequest && objElement)
	{
		var Request = new aspRequest(document.URL);
		var UserBlog = new getUserBlog(Request);
	
		httpRequest.onreadystatechange = function() {
	
			if (httpRequest.readyState == 4 && httpRequest.status == 200)
			{
				var oJSON = eval("(" + httpRequest.responseText + ")");
				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>";

				objElement.innerHTML = strHTML;
			}
		}

		var url = "Xml/AdvertiseJS.aspx?AD_TAG=CNYESBLOG_1,CNYESBLOG_2,CNYESBLOG_3,CNYESBLOG_4&rnd=" + Rnd();
	
		httpRequest.open("GET", url, true);
		httpRequest.send(null);
	}
}

// ==============================================================================================================
// 	最新情報模組
// ==============================================================================================================

function RequestWorldNews(thsElement, strBlog)
{
	var objElement = ParentNodeTagName(thsElement, "TD");
	var httpRequest = AjaxRequest();
	var theDateTime = new Date(nowDateTime);

	theDateTime.setDate(theDateTime.getDate()-1);

	strBlog = encodeURIComponent(strBlog);

	if (httpRequest && objElement && strBlog != "")
	{
		httpRequest.onreadystatechange = function() {
	
			if (httpRequest.readyState == 4 && httpRequest.status == 200)
			{
				var strId, strTitle, strDateTime;
				var oJSON = eval("(" + httpRequest.responseText + ")");
				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/" + strBlog + "/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>";
	
				objElement.innerHTML = strHTML;
			}
		}

		var url = "Xml/WorldNews.aspx?CN=" + strBlog + "&rnd=" + Rnd();

		httpRequest.open("GET", url, true);
		httpRequest.send(null);
	}
}

// ==============================================================================================================
// 	yesFUN 康樂股長
// ==============================================================================================================

function RequestFun(thsElement)
{
	var objElement = ParentNodeTagName(thsElement, "TD");
	var httpRequest = AjaxRequest();
	
	if (httpRequest && objElement)
	{
		httpRequest.onreadystatechange = function() {
	
			if (httpRequest.readyState == 4 && httpRequest.status == 200)
			{
				var xmldoc = httpRequest.responseXML;
				var rowsElement = xmldoc.getElementsByTagName("rows");
				var strHTML = "<table width='100%' border='0' cellspacing='0' cellpadding='3'>";

				if (rowsElement.length > 0)
				{
					var strId, strMy, strTitle, strSummary;

					for (var i=0; i<rowsElement.length; i++)
					{
						strId = getNodeValue(rowsElement[i].childNodes[0]);
						strTitle = InnerEncode(rowsElement[i].childNodes[1].firstChild.data);
						strSummary = InnerDecode(rowsElement[i].childNodes[2].firstChild.data);
						strMy = rowsElement[i].childNodes[3].firstChild.data;
						strMy = encodeURIComponent(strMy);
	
						strSummary = strSummary.replace("<P>", "<div>");
						strSummary = strSummary.replace("</P>", "</div>");
	
						strHTML += "<tr>";
						strHTML += "<td>";
						strHTML += "<a class='main-title' href='My/" + strMy + "/Content.htm?DocumentId=" + strId + "'><span style='font-size: 14px;'>" + strTitle + "</span></a>";
						strHTML += "<div><a class='content-link' href='My/" + strMy + "/Content.htm?DocumentId=" + strId + "'>" + strSummary + "</a></div>";
						strHTML += "</td>";
						strHTML += "</tr>";
					}
				}
	
				strHTML += "</table>";
	
				objElement.innerHTML = strHTML;
			}
		}

		var url = "Xml/WorldSummary.aspx?CN=cnyes-fun&rnd=" + Rnd();

		httpRequest.open("GET", url, true);
		httpRequest.send(null);
	}
}

// ==============================================================================================================
// 	熱門投票
// ==============================================================================================================

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 RequestWorldVote(thsElement)
{
	var objElement = ParentNodeTagName(thsElement, "TD");
	var httpRequest = AjaxRequest();
	
	if (httpRequest && objElement)
	{
		httpRequest.onreadystatechange = function() {
	
			if (httpRequest.readyState == 4 && httpRequest.status == 200)
			{
				var strHTML = "";
				var xmldoc = httpRequest.responseXML;
	
				if (xmldoc)
				{
					var rowsElement = xmldoc.getElementsByTagName("vote");
	
					if (rowsElement.length > 0 && rowsElement[0].childNodes.length > 0 && rowsElement[0].childNodes[0].firstChild)
					{
						var strSN = rowsElement[0].childNodes[0].firstChild.data;
						var strChoice1 = rowsElement[0].childNodes[1].firstChild.data;
						var strChoice2 = rowsElement[0].childNodes[2].firstChild.data;
						var strChoice3 = rowsElement[0].childNodes[3].firstChild.data;
						var strChoice4 = rowsElement[0].childNodes[4].firstChild.data;
						var strChoice5 = rowsElement[0].childNodes[5].firstChild.data;
						var strQuestion = rowsElement[0].childNodes[6].firstChild.data;
		
						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(strQuestion) + "</td></tr>";
	
						if (strChoice1 != "")
							strHTML += "<tr><td valign='top'><input type='radio' name='choice' value='1'></td><td width='100%'>" + HTMLEncode(strChoice1) + "</td></tr>";
	
						if (strChoice2 != "")
							strHTML += "<tr><td valign='top'><input type='radio' name='choice' value='2'></td><td width='100%'>" + HTMLEncode(strChoice2) + "</td></tr>";
	
						if (strChoice3 != "")
							strHTML += "<tr><td valign='top'><input type='radio' name='choice' value='3'></td><td width='100%'>" + HTMLEncode(strChoice3) + "</td></tr>";
	
						if (strChoice4 != "")
							strHTML += "<tr><td valign='top'><input type='radio' name='choice' value='4'></td><td width='100%'>" + HTMLEncode(strChoice4) + "</td></tr>";
	
						if (strChoice5 != "")
							strHTML += "<tr><td valign='top'><input type='radio' name='choice' value='5'></td><td width='100%'>" + HTMLEncode(strChoice5) + "</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='" + strSN + "'>";
						strHTML += "</form>";
						strHTML += "</td>";
						strHTML += "</tr>";
						strHTML += "</table>";
					}
				}
	
				objElement.innerHTML = strHTML;
			}
		}
	
		var url = "Xml/WorldVote.aspx?rnd=" + Rnd();
	
		httpRequest.open("GET", url, true);
		httpRequest.send(null);
	}
}

// ==============================================================================================================
// 	世界俱樂部模組
// ==============================================================================================================

function RequestBlogKind(thsElement)
{
	var objElement = ParentNodeTagName(thsElement, "TD");
	var httpRequest = AjaxRequest();
	
	if (httpRequest && objElement)
	{
		httpRequest.onreadystatechange = function() {
	
			if (httpRequest.readyState == 4 && httpRequest.status == 200)
			{
				var xmldoc = httpRequest.responseXML;
				var aryRows = new Array();
				var rowsElement = xmldoc.getElementsByTagName("rows");
				var strId, strName, strImage, sNo, i, j;
	
				for (i=0; i<rowsElement.length; i++)
				{
					strId = rowsElement[i].childNodes[0].firstChild.data;
	
					if (!aryRows[strId])
						aryRows[strId] = new Array;
	
					sNo = aryRows[strId].length;
	
					aryRows[strId][sNo] = new Array();
	
					for (j=0; j<rowsElement[i].childNodes.length; j++)
						aryRows[strId][sNo][j] = rowsElement[i].childNodes[j].firstChild.data;
				}
	
				var strHTML = "<table width='100%' border='0' cellpadding='0' cellspacing='1'><tr valign='top'>";
	
				rowsElement = xmldoc.getElementsByTagName("items");
	
				for (i=0; i<rowsElement.length; i++)
				{
					strId = rowsElement[i].childNodes[0].firstChild.data;
					strName = rowsElement[i].childNodes[1].firstChild.data;
					strImage = rowsElement[i].childNodes[2].firstChild.data;
	
					strHTML += "<td>";
					strHTML += "<table width='100%' border='0' cellpadding='0' cellspacing='0' background='images/leftsidemenubg.gif'>";
					strHTML += "<tr height='25'><td background='" + strImage + "' align='center' class='content'>" + strName + "</td></tr>";
	
					for (j=0; j<aryRows[strId].length; j++)
						strHTML += "<tr height='25'><td colspan='2'>&nbsp;<a href='Find.aspx?purpose=blog&Code=" + aryRows[strId][j][1] + "&KindName=" + encodeURIComponent(aryRows[strId][j][2]) + "' class='club'>" + InnerEncode(aryRows[strId][j][2]) + "</a>&nbsp;<span class='number'>" + aryRows[strId][j][3] + "</span></td></tr>";
	
					strHTML += "</table>";
					strHTML += "</td>";
	
					if (i % 2 == 1)
						strHTML += "</tr><tr valign='top'>";
				}
	
				strHTML += "</tr></table>";
				strHTML = strHTML.replace("<tr valign='top'></tr></table>", "</table>");

				objElement.innerHTML = strHTML;
			}
		}

		var url = "Xml/BlogKind.aspx?rnd=" + Rnd();

		httpRequest.open("GET", url, true);
		httpRequest.send(null);
	}
}

// ==============================================================================================================
// 	熱門投資講座模組
// ==============================================================================================================

function RequestInvest(thsElement)
{
	var objElement = ParentNodeTagName(thsElement, "TD");
	var httpRequest = AjaxRequest();
	
	if (httpRequest && objElement)
	{
		httpRequest.onreadystatechange = function() {
	
			if (httpRequest.readyState == 4 && httpRequest.status == 200)
			{
				var strTitle, strLink;
				var xmldoc = httpRequest.responseXML;
				var rowsElement = xmldoc.getElementsByTagName("rows");
				var strHTML = "<table width='100%' border='0' cellpadding='0' cellspacing='5'>";
	
				for (var i=0; i<rowsElement.length; i++)
				{
					strTitle = rowsElement[i].childNodes[0].firstChild.data;
					strLink = rowsElement[i].childNodes[1].firstChild.data;
					strTitle = HTMLDecode(strTitle);
					strTitle = strTitle.replace("<font color=#660099>", "");
					strTitle = strTitle.replace("</font>", "");
					strHTML += "<tr><td><a href='" + strLink + "' class='content-link'>" + HTMLDecode(strTitle) + "</td></tr>";
				}

				strHTML += "</table>";
	
				objElement.innerHTML = strHTML;
			}
		}

		var url = "Xml/Invest.aspx?rnd=" + Rnd();

		httpRequest.open("GET", url, true);
		httpRequest.send(null);
	}
}

// ==============================================================================================================
// 
// ==============================================================================================================

function SplitLevel(strString, strChar, level)
{
	var aryLevel = new Array();
	var s = 0;
	var j = 0;
	var n = level - 1;
	var i = strString.indexOf(strChar);
	var strLen = strChar.length;

	while (i >= 0 && j < n)
	{
		aryLevel[j++] = strString.substring(s, i);
		
		s = i + strLen;
		i = strString.indexOf(strChar, s);
	}

	aryLevel[j++] = strString.substring(s, strString.length);

	for (; j<level; j++)
		aryLevel[j] = "";

	return aryLevel;
}
//-->