// JavaScript -Content- Document

function display_content(oXML, sTopic, sDivName, sLoading, sRestoreBkgndColor) {
	sContent = "";

	if (!oXML.getElementsByTagName('ERROR_STATUS')[0]) return;
	if (oXML.getElementsByTagName('ERROR_STATUS')[0].firstChild.data!='OK') return;
	nCounter = 0;
	var items = oXML.getElementsByTagName("RECORD");
	sBlogContent = "";
	for (var i = 0 ; i < items.length ; i++) {
		// get one item after another
		var imageurl = "";
		var name = "";
		var pID = "";
		var description = "";
		var url = "";
		var score = "";
		var votes = "";
		var appdate = "";
		var fullname = "";
		var source = "";
		var multipur1 = "";
		var item = items[i];
		if (item.getElementsByTagName("TITLE")[0].firstChild)
			var name = item.getElementsByTagName("TITLE")[0].firstChild.nodeValue;
		if (item.getElementsByTagName("PID")[0].firstChild)
			var pID = item.getElementsByTagName("PID")[0].firstChild.nodeValue;
		if (item.getElementsByTagName("DESCRIPTION")[0].firstChild)
			var description = item.getElementsByTagName("DESCRIPTION")[0].firstChild.nodeValue;
		if (item.getElementsByTagName("URL")[0].firstChild)
			var url = item.getElementsByTagName("URL")[0].firstChild.nodeValue;
		if (item.getElementsByTagName("IMAGE")[0].firstChild)
			var imageurl = item.getElementsByTagName("IMAGE")[0].firstChild.nodeValue;
		if (item.getElementsByTagName("SCORE")[0].firstChild)
			var score = item.getElementsByTagName("SCORE")[0].firstChild.nodeValue;
		if (item.getElementsByTagName("VOTES")[0].firstChild)
			var votes = item.getElementsByTagName("VOTES")[0].firstChild.nodeValue;
		if (item.getElementsByTagName("DATE")[0].firstChild)
			var appdate = item.getElementsByTagName("DATE")[0].firstChild.nodeValue;
		if (item.getElementsByTagName("NAME")[0].firstChild)
			var fullname = item.getElementsByTagName("NAME")[0].firstChild.nodeValue;
		if (item.getElementsByTagName("SOURCE")[0].firstChild)
			var source = item.getElementsByTagName("SOURCE")[0].firstChild.nodeValue;
		if (item.getElementsByTagName("MULTIPURPOSE1")[0].firstChild)
			var multipur1 = item.getElementsByTagName("MULTIPURPOSE1")[0].firstChild.nodeValue;
		
		if (name.length > JS_MAX_TITLE_LENGTH) name = name.substring(0,JS_MAX_TITLE_LENGTH) + "..."; 
		//if (description.length > 160) description = description.substring(0,160) + "...";
		if (source.length > 70) source = source.substring(0,65) + "..."; 
		
		/*****************************************************
		The following section is where you add the calls to all
		modules on the page.  A module must first be positioned
		in the default page formatting, then have a formatting 
		subroutine added to this file, and then be called in 
		this function.
		******************************************************/
//if (sTopic=="editors") alert("2");	
		if (sTopic == "news") sContent = sContent + display_news(sTopic, nCounter, name, description, url, source, appdate);
		if (sTopic == "blogs") sContent = sContent + display_blogs(sTopic, nCounter, name, pID, description, url, score, votes);
		if (sTopic == "websites") sContent = sContent + display_websites(sTopic, nCounter, name, pID, description, url, score, votes);
		if (sTopic == "announcements") sContent = sContent + display_announcements(sTopic, nCounter, name, pID, description, appdate, fullname, imageurl);
		if (sTopic == "discussions") sContent = sContent + display_discussions(sTopic, nCounter, name, pID, description, url, score, votes, fullname, appdate, multipur1);
		if (sTopic == "products") sContent = sContent + display_products(sTopic, nCounter, name, pID, description, url, imageurl, source, score, votes);
		if (sTopic == "editors") {
				sContent = sContent + display_editors(sTopic, nCounter, name, pID, description, url, score, votes);
		}
		nCounter++;
	}
	if(nCounter == 0) {
		sContent = sContent + "<table align=center><tr><td height='145' align=center class='feedtitle'>No records to display</td></tr></table>";
	}
	alterContent(sDivName, sContent);
	SetBkgndColor(sDivName, sRestoreBkgndColor);
	toggleBox(sLoading, 0);						//remove loading timer
}

function display_blogs(sTopic, nCounter, name, pID, description, url, score, votes) {
	sBlogContent = "";
	if ( nCounter!=0 ) sBlogContent = sBlogContent + "<hr size=1/>";

	sBlogContent = sBlogContent + "<div class='ContentDivsNormal' onclick=\"openWindow('"+ url +"')\" onmouseover='DoContentDivMouseOver(this)' onmouseout='DoContentDivMouseOut(this)' title='"+ url +"'>";
	sBlogContent = sBlogContent + "<span class=\"feedtitle\"><a class=\"feedtitle\" href=\"javascript:openWindow('"+ url +"')\">"+ name +"</a> <a class=\"feedtitle\" href=\"javascript:openWindow('"+ url +"')\"><font  class=\"feedprops\" style=\"color:red;\">more</font></a></span><br>";
	sBlogContent = sBlogContent + "<span class=\"feeddesc\">"+ BuildDescription(description, 75, 2) +"</span></div>";
	sBlogContent = sBlogContent + displayVotes(votes, score, pID, sTopic);
	return sBlogContent;
}

function display_editors(sTopic, nCounter, name, pID, description, url, score, votes) {
	sEditorsContent = "";
	if ( nCounter!=0 ) sBlogContent = sBlogContent + "<hr size=1/>";

	sEditorsContent = sEditorsContent + "<div class='ContentDivsNormal' onclick=\"window.open('"+ url +"','"+ name; 
	sEditorsContent = sEditorsContent + "','width=400,height=400,resizable=yes, scrollbars=yes,toolbar=no, location=no,";
	sEditorsContent = sEditorsContent + "status=no,menubar=yes,copyhistory=no')\"";
	sEditorsContent = sEditorsContent + " onmouseover='DoContentDivMouseOver(this)' onmouseout='DoContentDivMouseOut(this)' title='"+ url +"'>";
		
	sEditorsContent = sEditorsContent + "<span class=\"feedtitle\"><a class=\"feedtitle\" href=\"javascript:window.open('"+ url +"','"+
		name +"','width=400,height=400,resizable=yes,scrollbars=yes,toolbar=no,location=no,status=no,menubar=yes,copyhistory=no');"+
		"void(0);\">"+ name +"</a> <a class=\"feedtitle\" href=\"javascript:window.open('"+ url +"','"+ name +
		"','width=400,height=400,resizable=yes,scrollbars=yes,toolbar=no,location=no,status=no,menubar=yes,copyhistory=no');"+
		"void(0);\"><font  class=\"feedprops\" style=\"color:red;\">more</font></a></span><br>";
		
	sEditorsContent = sEditorsContent + "<span class=\"feeddesc\">"+ BuildDescription(description, 75, 4) +"</span></div>";
	sEditorsContent = sEditorsContent + displayVotes(votes, score, pID, sTopic);
	return sEditorsContent;
}

function display_websites(sTopic, nCounter, name, pID, description, url, score, votes) {
	return display_blogs(sTopic, nCounter, name, pID, description, url, score, votes);
}

function display_announcements(sTopic, nCounter, name, pID, description, appdate, fullname, imageurl) {
	sAnmtContent = "";
	sAnmtContent = sAnmtContent + "<td width='32%' align=center valign=bottom>";
	sAnmtContent = sAnmtContent + "<table><tr valign='bottom'><td colspan=2 class='feedtitle' align=center valign=bottom>";
	sAnmtContent = sAnmtContent + name + " ("+ description +") </td></tr>";
	sAnmtContent = sAnmtContent + "<tr valign=top><td colspan='2' class='feedtitle' width='80' height='100' valign='top' align='center>'";
	if(imageurl == '') {
		sAnmtContent = sAnmtContent + "<table height='80' width='100' valign='top'><tr>";
		sAnmtContent = sAnmtContent + "<td height='100' class='feedtitle' style='border:solid 1px' align=center width='100' valign='middle'>No Image Available</td></tr></table>";
		sAnmtContent = sAnmtContent + "<div valign=top>"+ appdate +" - "+ fullname +"</div></td>";
	} else {						
		sAnmtContent = sAnmtContent + "<img border='1' height='150' width='150' src='../upload/"+ imageurl +"'>";
		sAnmtContent = sAnmtContent + "<br>"+ appdate +" - "+ fullname +"</td>";
	}
	sAnmtContent = sAnmtContent + "</tr></table></td> ";
	return sAnmtContent;
}

function display_discussions(sTopic, nCounter, name, pID, description, url, score, votes, fullname, appdate, multipur1) {
	sDscContent = "";
	if ( nCounter!=0 ) sDscContent = sDscContent + "<hr size=1/>";

	sDscContent = sDscContent + "<div class='ContentDivsNormal' onmouseover='DoContentDivMouseOver(this)' onclick='discussionViewAll("+ multipur1 +")' onmouseout='DoContentDivMouseOut(this)' >";
	sDscContent = sDscContent + "<span class=\"feedtitle\"><a class=\"feedtitle\"  href=\"javascript:discussionViewAll("+ multipur1 +")\">"+ name +"</a></span><br>";
	sDscContent = sDscContent + "<span class=\"feedprops\"><font style=\"color:green;\">"+ fullname +" - on</font> "+ appdate +"  ";
	sDscContent = sDscContent + "<div class='feeddesc'>"+ BuildDescription(description, 75, 2) +"<a class='feedprops' href='javascript:discussionViewAll("+ multipur1 +")'><font color=red>more </font></a></div></div>";
	sDscContent = sDscContent + displayVotes(votes, score, pID, sTopic);
	
	return sDscContent;
}

function display_products(sTopic, nCounter, name, pID, description, url, imageurl, source, score, votes) {
	sProdContent = "";
	//$Description = BuildDescription($Description, 55, 4);
	if ( nCounter!=0 ) sProdContent = sProdContent + "<hr size=1/>";

	if (source == 'internal') {
		sRedirectMethod = "location='"+ url.replace("&amp;","&") +"'";
	} else {
		sRedirectMethod = "openWindow('"+ url.replace("&amp;","&") +"')";
	}	
	sProdContent = sProdContent + "<table width='98%' cellpadding='2' align='center' cellspacing='0' border='0' ";
	sProdContent = sProdContent + "onClick=\""+ sRedirectMethod +"\" class='ContentDivsNormal' onmouseover='DoContentDivMouseOver(this)' onmouseout='DoContentDivMouseOut(this)'>";
	sProdContent = sProdContent + "<tr><td rowspan='3' height='55' width='89' align='center' valign='middle'>";
	sProdContent = sProdContent + "<a style='cursor:pointer' onClick=\""+ sRedirectMethod +"\">";
	sProdContent = sProdContent + "<img border='0' align='center' valign='middle' src=\""+ JS_CONSTANT_PATH_TO_ROOT +"/nongenericcontent/images/Products/"+ imageurl +"\"></a></td>";
	sProdContent = sProdContent + "<td valign='top'><span class='feedtitle'><a href=\"javascript:openWindow('"+ url +"')\">"+ name +"</a></span>";
	sProdContent = sProdContent + "<br><span class='feeddesc'>"+ BuildDescription(description, 60, 4) +"</span></td></tr></table>";
	sProdContent = sProdContent + displayVotes(votes, score, pID, sTopic);					
	return sProdContent;
}

function display_news(sTopic, nCounter, name, description, url, source, appdate) {
	sNewsContent = "";
	if ( nCounter!=0 ) sNewsContent = sNewsContent + "<hr size=1/>";
	sNewsContent = sNewsContent + "<div class=\"ContentDivsNormal\" onclick=\"openWindow('"+ url +"')\" onmouseover='DoContentDivMouseOver(this)' onmouseout='DoContentDivMouseOut(this)' title='"+ url +"'>";
	sNewsContent = sNewsContent + "<span class=\"feedtitle\"><a class=\"feedtitle\" href=\"javascript:openWindow('"+ url +"')\">"+ name +"</a></span><br>";
	sNewsContent = sNewsContent + "<span class=\"feedprops\">"+ source +" <font style=\"color:green;\">on</font> "+ appdate +" /  <a class=\"feedprops\" href=\"javascript:openWindow('"+ url +"')\"><font color='red'>more</font> </a></span><br>";
	sNewsContent = sNewsContent + "<div class=\"feeddesc\">"+ BuildDescription(description, 75, 2) +"</div></div>";
	return sNewsContent;
}

function displayVotes(votes, score, pID, sTopic) {
	sScoreContent = "<div align=right><span class=\"ViewAllContentHeadingProps\">";
	if (votes == 0)
		sScoreContent = sScoreContent + "(No Votes)<a href='votinginterface.php?pid="+ pID +"&votesubj="+ sTopic +"' class=\"ViewAllContentHeadingProps\">Rate this item</a>";
	else {
		for (count=0; count < score; count++) {
			sScoreContent = sScoreContent + "<img border=\"0\" src=\"../images/star_vote.gif\" width=\"15\" height=\"12\">";
		}
		sScoreContent = sScoreContent + "("+ votes +" Vote(s)) <a class=\"ViewAllContentHeadingProps\" href='votinginterface.php?pid="+ pID +"&votesubj="+ sTopic +"'>Rate this item</a>";
	}
	sScoreContent = sScoreContent + "</span></div>";
	return sScoreContent;
}

function SetBkgndColor(divID, newcolor) {
	sPreviousColor = '';
	if(document.layers) { // browser="NN4";
		sPreviousColor = document.layers[divID].bgColor;
		document.layers[divID].bgColor = newcolor;
	}
	if(document.all) { // browser="IE";
		eval("sPreviousColor = document.all."+divID+".style.backgroundColor;");
		eval("document.all."+divID+".style.backgroundColor = newcolor;");
	}
	if(!document.all && document.getElementById) { // browser="NN6+ or IE5+ if you're willing to dump the !document.all stuff";
		sPreviousColor = document.getElementById(divID).style.backgroundColor;
		document.getElementById(divID).style.backgroundColor = newcolor;
	}
	return sPreviousColor;
}

