// Live Vote 3.0. Author = Brenden West. Updated - 2-12-01
// Open issues: rounding

// global variables
var LVname = "";

var sVotePrompt = "<FONT FACE='Arial,Helvetica' SIZE=1 class=LVtext>Vote to see results&nbsp;</font>";

var sDisclaimer = "<FONT FACE='Arial,Helvetica' SIZE=1 class=LVtext>Survey results tallied every 60 seconds. Live Votes reflect respondents&#039; views and are <a href='/news/197170.asp' target=_top>not&nbsp;scientifically valid surveys</a>.</FONT>";

var sHeaderVote = "<img src=/modules/livevote/livevote_vote.gif width=148 height=48>";
var sHeaderRes = "<img src=/modules/livevote/livevote_results.gif width=148 height=48>";
var sSubmitImg = "<img src=/modules/livevote/livevote_button.gif width=62 height=22 border=0>";
var sFooter = "<IMG SRC=/modules/livevote/livevote_interactive.gif width=148 height=30><br>" ;
var sBarImg = "/modules/livevote/livevote_bar.gif";

// Formats: 1=single column, 2=choices in n cols, 3=questions in 2 cols, 4=scorecard
var iFmt = 1; var iChoiceCols=2;
var iWidth=148;
var bVoting = true;
var bResults = true;
var bSort = false;
var sUA = navigator.appName.toLowerCase();
var bDhtml = (document.all && sUA.indexOf("webtv") == -1) ? true : false;


function DisplayLV() {
  if (LVname) {
  	if (!bResults) { sVotePrompt = ""; sDisclaimer=""; }
	if (sAnswers) {
		if (sHeaderVote.indexOf("livevote_vote.gif") > 0) {
			sHeaderVote = "<img src=/modules/livevote/livequiz_vote.gif width=148 height=48>";
			sHeaderRes = "<img src=/modules/livevote/livequiz_results.gif width=148 height=48>";
			sSubmitImg = "<img src=/site_elements/submit.gif width=66 height=21 border=0>";
		}
		if (!sPostVoteText) {
			sPostVoteText = "<b>Correct answers are shown in <FONT COLOR=#CC0000>red</FONT>.</b> Percentages indicate how other MSNBC readers responded.</FONT>";
		}
	}

	var aLV = eval("LV_" +LVname);
	if (iFmt>1 && iWidth==148) { iWidth=472; }
	if (iFmt ==4) {
		sHeads = sHeads.split("^");
		sItems = (sHeads[1]) ? sHeads[1].split("|") : "";
		sHeads = sHeads[0].split("|");
	}
	if  (act=="vote" && bVoting) {
		if (bDhtml) {
			sVisRes = " style='display:none' ";
			sPageID0 = "lv_"+LVname;
			sPageID1 = "lv_"+LVname;
			LVDisplayForm();
			act="results";
			LVDisplayRes();
		} else {
			sVisRes = " ";
			sPageID0 = "";
			sPageID1 = "";
			LVDisplayForm();
		}
	} else {
		sVisRes = " ";
		sPageID1 = "";
		LVDisplayRes();
	}
  }
}

function Vote(LVname) {
	var bVoted = false;
	var F = eval("document.fm_"+LVname);
	var qstr = F.elements[0].name+"="+F.elements[0].value+"&" + F.elements[1].name+"="+F.elements[1].value+"&"
	for (var i=2;i<F.elements.length;i++) {
		if (F.elements[i].type=="radio" && F.elements[i].checked) {
			qstr += F.elements[i].name +'=' + F.elements[i].value +'&'
			bVoted = true;
		} else if  ((F.elements[i].type=="text" || F.elements[i].type=="hidden") && F.elements[i].value!="") {
			qstr += F.elements[i].name +"=" + F.elements[i].value +"&";
		}
	}
	if (!bVoted) {
		if (F.writeinopt) {
			if (F.writein.value != "") { 
				F.Q1[F.Q1.length-1].checked = true;
				Vote(LVname);
			 } else {
				alert("Please make a choice before submitting your vote.");
			 }
		} else { alert("Please make a choice before submitting your vote."); }
	}
	else {
		if (document.all && bDhtml) {
			eval("document.all.lv_"+LVname+"[1].style.display=''");
			eval("document.all.lv_"+LVname+"[0].style.display='none'");
			C = eval("document.lvPoster_"+LVname);
			C.src = "/modules/livevote/vote.asp?t=2&"+qstr
// disabled for now	self.scrollTo(0,0); 
		} else {
			F.submit();
		}
	}
}

function LVDisplayForm() {
	var aLV = eval("LV_" +LVname);
	var sTmp = "";

	document.write("</i></font><table ID=\"" + sPageID0 + "\" width=" + iWidth + " border=0 cellpadding=0 cellspacing=0 " + sTableBG + ">");
	document.write("<form method=post action=\"/modules/livevote/vote.asp\" name=\"fm_" + LVname + "\"><input type=hidden name=LVname value=\"" + LVname + "\"><input type=hidden name=author value=" + author + ">");

	if (iFmt==1) {
		if (sHeaderVote != "<!--none-->") {
			document.write("<TR valign=top><TD colspan=3>" + sHeaderVote + "</TD></TR><TR><TD colspan=3 height=15>&nbsp;</TD></TR>");
		}		
		document.write("<TR><TD colspan=3>" +sponsor+ "</TD></TR>");
		if (sPreVoteText) {
			document.write("<TR><TD colspan=3 height=15><SPACER TYPE=BLOCK WIDTH=1></TD></TR><TR><TD width=12><SPACER TYPE=BLOCK WIDTH=1></TD><TD colspan=2><FONT face=arial size=2 class=LVtext>" +sPreVoteText+ "</FONT></TD></TR>");
		}

		for (i=1;i<aLV.length;i++) {
			if (aLV[i]) {
				sTmp += "<TR valign=top><TD width=12>&nbsp;</TD><TD colspan=2><FONT FACE=Arial SIZE=2 class=LVtext><B>" +aLV[i][0][0]+ "</B></FONT></TD></TR><TR><TD colspan=3 height=4><SPACER TYPE=BLOCK WIDTH=1></TD></TR>";
				for (var j=1;j<aLV[i].length;j++) {
					if (aLV[i][j]) {
						var sOptText = aLV[i][j][0];
						if (sOptText.toLowerCase()=="write-in") {
							sOptText = "Write-in<br><input type=hidden name=writeinopt value=" +j+ "><input type=text size=15 name=writein>";
						}
						sTmp += "<TR VALIGN=TOP><TD width=12>&nbsp;</TD><TD WIDTH=18><input type=radio name=Q" + i + " value=" + j + "></TD><TD WIDTH=" + (iWidth-30) + "><FONT FACE='Trebuchet,Arial' SIZE=2 class=LVtext>" + sOptText + "</font></TD></TR>";
					}
				}
				sTmp += "<TR><TD colspan=3 height=10>&nbsp;</TD></TR>";
			}
		}
		document.write(sTmp);

		document.write("<TR><TD colspan=3><img src='/site_elements/clear.gif' height=1 width=12>");
		if (sVer=="wbcst" && document.layers) { 
			var sImgSrc = sSubmitImg.substring(sSubmitImg.indexOf("src=")+4);
			sImgSrc = sImgSrc.substring(0,sImgSrc.indexOf(" "))
			document.write ("<input type=image src='" + sImgSrc + "' border=0>") 
		}
		else { document.write ("<a href='javascript:Vote(\"" +LVname+ "\");'>" + sSubmitImg + "</a>"); }
		document.write("</TD></TR><TR valign=top><TD colspan=3 align=right>" +sFooter+sVotePrompt+ "</TD></TR>");
	}
	else if (iFmt==2) {
		var iWidth2 = (iWidth-18*iChoiceCols+10*(iChoiceCols-1))/iChoiceCols; 
		var nToteCols = 2*iChoiceCols + iChoiceCols-1;

		if (sHeaderVote != "<!--none-->") {
			document.write("<TR><TD align=left colspan=" +nToteCols+ ">" + sHeaderVote + "</TD></TR>");
		}
	
		if (sPreVoteText) {
			document.write("<TR><TD width=18><spacer type=block width=1></TD><TD COLSPAN=" +(nToteCols-1)+ "><FONT face=arial size=2 class=LVtext>" +sPreVoteText+ "</FONT></TD></TR>");
		}
		for (i=1;i<aLV.length;i++) {
			if (aLV[i]) {
				document.write("<TR valign=bottom><TD align=left colspan=" +nToteCols+ "><br><FONT FACE=Arial SIZE=2 class=LVtext><B>" + aLV[i][0][0] + "</B></FONT></TD></TR>");
				var cntr = 0
				for (var j=1;j<aLV[i].length;j++) {
					if (aLV[i][j]) {
					var sOptText = aLV[i][j][0];
					if (sOptText.toLowerCase()=="write-in") {sOptText = "Write-in<br><input type=hidden name=writeinopt value=" +j+ "><input type=text size=15 name=writein>";}
						if (cntr % iChoiceCols == 0) { document.write("<TR><TD HEIGHT=5 colspan=" +nToteCols+ "><SPACER TYPE=BLOCK WIDTH=1></td></tr><TR VALIGN=TOP>"); }
						document.write("<TD width=18><input type=radio name=Q" + i + " value=" + j + "></TD><TD  width=" +iWidth2+ "><FONT FACE='Trebuchet,Arial' SIZE=2 class=LVtext>"+ sOptText +"</font></TD>");
						if (cntr+1 % iChoiceCols == 0) { document.write("</TR>"); }
						else { document.write("<TD WIDTH=10><SPACER TYPE=BLOCK WIDTH=1></TD>"); }
						cntr++
					}
				}
			}
		}
		
		document.write("<tr><td align=left valign=top colspan=" +(nToteCols-1)+ ">");
		if (sVer=="wbcst" && document.layers) { 
			var sImgSrc = sSubmitImg.substring(sSubmitImg.indexOf("src=")+4);
			sImgSrc = sImgSrc.substring(0,sImgSrc.indexOf(" "))
			document.write ("<input type=image src='" + sImgSrc + "' border=0>") 
		}
		else { document.write ("<a href='javascript:Vote(\"" +LVname+ "\");'>" + sSubmitImg + "</a>"); }
		document.write("</td><td valign=top align=right>" +sFooter+sVotePrompt+ "</td></tr>");
	}
	else if (iFmt==3) {
		document.write("<TR><TD width=230>&nbsp;</TD> <TD width=10>&nbsp;</TD> <TD width=230>&nbsp;</TD></TR>");
		document.write("<TR><TD colspan=3><FONT SIZE=3 FACE='ARIAL, TREBUCHET, HELVETICA'><i>Please remember, you must take the survey in order to see how others have responded. Sorry, you can only take the survey once.</i><br>&nbsp;</TD></TR>");
		if (sPreVoteText) {
			document.write("<TR><TD colspan=3><FONT face=arial size=2 class=LVtext>" +sPreVoteText+ "</FONT></TD></TR>");		
		}

		cntr = 0;
		for (i=1;i<aLV.length;i++) {
			if (aLV[i]) {
				if (cntr % 2 == 0 && cntr > 0) {
					document.write("</TABLE></td></tr><tr><td colspan=3 height=8>&nbsp;</td><tr>");
				}
				if (cntr % 2 == 1 && cntr > 0) {
					document.write("</TABLE></td>");
				}
				if (cntr % 2 == 0) {
					document.write("<TR><TD WIDTH=230 ALIGN=LEFT VALIGN=TOP><TABLE BORDER=0 WIDTH=230 CELLSPACING=0 CELLPADDING=0>");
				}
				else if (cntr % 2 == 1) {
					document.write("<TD WIDTH=10></TD><TD WIDTH=230 ALIGN=LEFT VALIGN=TOP><TABLE BORDER=0 WIDTH=230 CELLSPACING=0 CELLPADDING=0>");
				}

				document.write("<TR><TD colspan=3 width=230><font size=3><b>" + (cntr+1) + ". " + aLV[i][0][0] + "</b></font></TD></TR>");
				for (var j=1;j<aLV[i].length;j++) {
					if (aLV[i][j]) {
						document.write("<TR><TD WIDTH=35 valign=top><input type=radio name=Q"+ i +" value="+ j +"></TD><TD WIDTH=3></TD><TD WIDTH=190><font size=3 face='Times New Roman'>"+ aLV[i][j][0] +"</font></TD></TR>");
					}
				}
				cntr++
			}
		}
		document.write("</TABLE></td></tr><tr><td align=right valign=top colspan=3><a href='javascript:Vote(\"" +LVname+ "\");'>" + sSubmitImg + "</a></td></tr>");

	}
	else if (iFmt==4) {
		var iQnum = 1;
		var nGroups = sHeads.length;
		var nItems = (aLV.length-1)/nGroups;

		if (sPreVoteText) {
			document.write("<TR><TD colspan=4><FONT face=arial size=2 class=LVtext>" +sPreVoteText+ "</FONT></TD></TR>");
		}

		for (i=0;i<nGroups;i++) {
			if (sItems.length>1) { // unequal # of items
				nItems = sItems[i];
			}
			document.write("<tr valign=bottom><td colspan=2 width=" + (iWidth-90) + "><font face=arial size3><b>" +sHeads[i]+ "</B></font></td><td colspan=7><img src=/modules/surveys/images/hed_stars.gif height=45 width=115 border=0></td></tr><tr><td colspan=7 bgcolor=#CCCCCC height=3><SPACER TYPE=BLOCK WIDTH=1></td></tr>");

			for (j=0;j<nItems;j++) {
				var bgcolor = (j % 2 == 0) ? "FFFFFF" : "CCCCCC";
				document.write("<tr valign=middle BGCOLOR=" +bgcolor+ "><td width=5><spacer type=block width=1></td><td WIDTH=" + (iWidth-95) + "><font face=arial size=2>"+aLV[iQnum][0][0]+"</font></td>");

				for (var k=1;k<aLV[iQnum].length;k++) {
					document.write("<td width=18><input type=radio value=" +k+ " name=Q" + iQnum + "> </td>");
				}

				document.write("<td width=10 bgcolor=#FFFFFF><SPACER TYPE=BLOCK WIDTH=1></td></tr>");
				iQnum++;
			}

			document.write("<tr><td colspan=8 align=right><img src=/modules/surveys/images/edge_bottom.jpg height=32 width=306></td></tr>");
		}

		document.write("<TR><TD colspan=7><a href='javascript:Vote(\"" +LVname+ "\");'>" + sSubmitImg + "</a></TD></TR>");
	}
	document.write("</TABLE></FORM><img src=/site_elements/clear.gif height=1 width=1 name=lvPoster_" +LVname+ ">");
}

function LVDisplayRes() {
	var aLV = eval("LV_" +LVname);
	var sTmp = "";
	var sClass="";
	document.write("</i></font><table ID=\"" + sPageID1 + "\" " +sVisRes+ " width=" + iWidth + " border=0 cellpadding=0 cellspacing=0 " + sTableBG + ">");
	if (iFmt==1) {	// single vertical column
		document.write("<TR valign=top><TD colspan=2>" + sHeaderRes + "</TD></TR>");
		document.write("<TR><TD colspan=2>" +sponsor+ "</TD></TR>");
		if (sPostVoteText) {
			document.write("<TR><TD colspan=2 height=15><SPACER TYPE=BLOCK WIDTH=1></TD></TR><TR><TD width=12><SPACER TYPE=BLOCK WIDTH=1></TD><TD width=" + (iWidth-12) + "><FONT face=arial size=2 class=LVtext>" +sPostVoteText+ "</FONT></TD></TR>");
		}
		if (bResults) {
			if (sAnswers) {
				sAnswers = sAnswers.split(",");
				sAnsText = sAnsText.split("|");
			}
		for (i=1;i<aLV.length;i++) {
			if (aLV[i]) {
				document.write("<TR><TD colspan=2 height=5><SPACER TYPE=BLOCK WIDTH=1></TD></TR><TR valign=top><TD width=12>&nbsp;</TD><TD  width=" + (iWidth-12) + "><FONT FACE=Arial SIZE=2 class=LVtext><B>" +aLV[i][0][0]+ "</B></FONT></TD></TR><TR><TD colspan=2 height=4><SPACER TYPE=BLOCK WIDTH=1></TD></TR>");

				document.write("<TR><TD width=12><SPACER TYPE=BLOCK WIDTH=1></TD><TD><FONT FACE='verdana' SIZE=1 class=LVtext>* " + aLV[i][0][1] + " responses</FONT></TD></TR>");
				document.write("<TR><TD colspan=2 height=4><SPACER TYPE=BLOCK WIDTH=1></TD></TR>");

				if (bSort) { aLV[i] = SortItems(aLV[i]); }
				for (var j=1;j<aLV[i].length;j++) {
					if (aLV[i][j]) {
						perc = (aLV[i][j][1] > 0) ? Math.round(100*(aLV[i][j][1]/aLV[i][0][1])) : 0;

						// TODO: take sorting into account
						if (sAnswers && j==sAnswers[i-1]) {
							sClass = "LVQuizText";
							sTmp = aLV[i][j][0];
							if (sAnsText[i-1]) { sTmp += sAnsText[i-1]; }
						} else {
							sClass = "LVtext";
							sTmp = aLV[i][j][0];							
						}

						document.write("<TR><TD width=12><SPACER TYPE=BLOCK WIDTH=1></TD><TD><FONT FACE='Trebuchet,Arial' SIZE=2 class=" +sClass+ ">" + sTmp + "</FONT><BR><IMG SRC='" +sBarImg+ "' width="+ perc +" height=10><FONT face='Trebuchet,Arial' size=2 class=LVPerctext>&nbsp;"+ perc +"%</font></TD></TR><TR><TD colspan=2 height=4></TD></TR>");
					}
				}
			}

		}
		}	// end bResults
		document.write("<TR><TD colspan=2 align=right>" +sFooter+ "<br>" +sDisclaimer+ "</TD></TR>");
	}
	else if (iFmt==2) {
		var iWidth2 = (iWidth-10*iChoiceCols)/iChoiceCols;
		var nToteCols = iChoiceCols + iChoiceCols-1;
		document.write("<TR><TD align=left colspan=" +nToteCols+ ">" + sHeaderRes + "</TD></TR>");
		if (sPostVoteText) {
			document.write("<TR><TD colspan=" +nToteCols+ "><FONT face=arial size=2 class=LVtext>" +sPostVoteText+ "</FONT></TD></TR>");
		}
		if (bResults) {
			if (sAnswers) {
				sAnswers = sAnswers.split(",");
				sAnsText = sAnsText.split("|");
			}
		for (i=1;i<aLV.length;i++) {
			if (aLV[i]) {
				var spacer = (i>1) ? '<br>' : '';
				document.write("<TR valign=bottom><TD colspan=" +nToteCols+ ">" +spacer+ "<FONT FACE=Arial SIZE=2 class=LVtext><B>" + aLV[i][0][0] + "</B></FONT><br><FONT FACE='verdana' SIZE=1 class=LVtext><b>* " + aLV[i][0][1] + " responses</b></FONT></TD></TR>");
				var cntr = 0
				for (var j=1;j<aLV[i].length;j++) {
					if (aLV[i][j]) {
						perc = (aLV[i][j][1] > 0) ? Math.round(100*(aLV[i][j][1]/aLV[i][0][1])) : 0;
						if (sAnswers && j==sAnswers[i-1]) {
							sClass = "LVQuizText";
							sTmp = aLV[i][j][0];
							if (sAnsText[i-1]) { sTmp += sAnsText[i-1]; }
						} else {
							sClass = "LVtext";
							sTmp = aLV[i][j][0];							
						}

						if (cntr % iChoiceCols == 0) { document.write("<TR>"); }
						document.write("<TD width=" +iWidth2+ "><FONT FACE='Trebuchet,Arial' SIZE=2 class=" +sClass+ ">" + sTmp + "</FONT><BR><IMG SRC='" +sBarImg+ "' width="+ perc +" height=10><FONT FACE='Trebuchet,Arial' SIZE=2 class=LVPerctext>&nbsp;"+ perc +"%</font></TD>");
						if (cntr+1 % iChoiceCols == 0) { document.write("</TR>"); }
						else { document.write("<TD WIDTH=10><SPACER TYPE=BLOCK WIDTH=1></TD>"); }
						cntr++
					}
				}
			}
		}
		}
		document.write("<tr><td ALIGN=RIGHT colspan=" +nToteCols+ ">" +sFooter+ "<IMG SRC='/i/c.gif' width=12 height=1>" +sDisclaimer+ "</td></tr>");
	}
	else if (iFmt==3) {
		document.write("<TR><TD width=230>&nbsp;</TD><TD width=10>&nbsp;</TD><TD width=230>&nbsp;</TD></TR>");

		if (sPostVoteText) {
			document.write("<TR><TD colspan=3><FONT face=arial size=2 class=LVtext>" +sPostVoteText+ "</FONT></TD></TR>");		
		}

		if (bResults) {
			document.write("<TR><TD colspan=3><font size=3><b>MSNBC reader responses</b></font> (" + aLV[1][0][1] + " respondents)<br><font size=1>* Percentages may not total to 100% for each question due to non-responses<br>&nbsp;</TD></TR>");

			if (sAnswers) {
				document.write("<TR><TD COLSPAN=3><FONT face=arial size=2><b>Correct answers are shown in <FONT COLOR=#CC0000>red</FONT>.</b> Percentages indicate how other MSNBC readers responded.</FONT></TD></TR>");
				sAnswers = sAnswers.split(",");
				sAnsText = sAnsText.split("|");
			}

		cntr = 0
		for (i=1;i<aLV.length;i++) {
			if (aLV[i]) {
				if (cntr % 2 == 0 && cntr > 0) {
					document.write("</TABLE></td></tr><tr><td colspan=3 height=8>&nbsp;</td><tr>");
				}
				if (cntr % 2 == 1 && cntr > 0) {
					document.write("</TABLE></td>");
				}
				if (cntr % 2 == 0) {
					document.write("<TR><TD WIDTH=230 ALIGN=LEFT VALIGN=TOP><TABLE BORDER=0 WIDTH=230 CELLSPACING=0 CELLPADDING=0>");
				}
				else if (cntr % 2 == 1) {
					document.write("<TD WIDTH=10></TD><TD WIDTH=230 ALIGN=LEFT VALIGN=TOP><TABLE BORDER=0 WIDTH=230 CELLSPACING=0 CELLPADDING=0>");
				}

				document.write("<TR><TD colspan=3 width=230><font size=3><b>" + (cntr+1) + ". " + aLV[i][0][0] + "</b></font></TD></TR>");
				for (var j=1;j<aLV[i].length;j++) {
					if (aLV[i][j]) {
						perc = (aLV[i][j][1] > 0) ? Math.round(100*(aLV[i][j][1]/aLV[i][0][1])) : 0;

						if (sAnswers && j==sAnswers[i-1]) {
							sClass = "LVQuizText";
							sTmp = aLV[i][j][0];
							if (sAnsText[i-1]) { sTmp += sAnsText[i-1]; }
						} else {
							sClass = "LVtext";
							sTmp = aLV[i][j][0];							
						}

						document.write("<TR><TD WIDTH=35 valign=top><font size=3 face=Arial><b>"+ perc +"%</b></font></TD><TD WIDTH=3></TD><TD WIDTH=190><font size=3 face='Times New Roman' class=" +sClass+ ">"+ sTmp +"</font></TD></TR>");
					}
				}
				cntr++
			}
		}
		}
		document.write("<TR><TD colspan=3><FONT face=arial size=2 class=LVtext><a href='/news/197170.asp'>About MSNBC Polls</a></TD></TR>");
	}
	else if (iFmt==4) {
		var nGroups = sHeads.length;
		var nItems = (aLV.length-1)/nGroups;
		iQnum = 1;
		
		if (sPostVoteText) {
			document.write("<TR><TD colspan=5><FONT face=arial size=2 class=LVtext>" +sPostVoteText+ "</FONT></TD></TR>");
		}
		if (bResults) {
			document.write("<TR><TD colspan=5><font size=1 face=verdana><b>" + aLV[1][0][1] + " responses</b></font></TD></TR>");

		for (i=0;i<nGroups;i++) {
			if (sItems.length>1) { // unequal # of items
				nItems = sItems[i];
			}

			var Rating = 0;

			document.write("<tr valign=bottom><td colspan=2><font face=arial size3><b>" +sHeads[i]+ "</B></font></td><td colspan=2 align=center><font face=arial size=2><b>Rating</B></font></td><TD width=10><SPACER TYPE=BLOCK WIDTH=1></TD></tr><tr><td colspan=4 bgcolor=#CCCCCC height=2><SPACER TYPE=BLOCK WIDTH=1></td><TD width=10><SPACER TYPE=BLOCK WIDTH=1></TD></tr>");

			for (j=0;j<nItems;j++) {
				var subRating = 0;
				var bgcolor = (j % 2 == 0) ? "FFFFFF" : "CCCCCC";
				for (var k=1;k<aLV[iQnum].length;k++) {
					subRating += aLV[iQnum][k][0]*aLV[iQnum][k][1];
				}

				subRating = (aLV[iQnum][0][1]) ? subRating/aLV[iQnum][0][1] : 0;
				Rating += subRating;
				subRating = Math.round(subRating*100)/100

				document.write("<tr valign=middle BGCOLOR=" +bgcolor+ "><td width=5><spacer type=block width=1></td><td width=" +(iWidth-130)+ "><font face=arial size=2>"+aLV[iQnum][0][0]+"</font></td><td WIDTH=70>" +MakeStars(subRating)+ "</td><td WIDTH=45>" +subRating+ "</td><TD width=10 BGCOLOR=#FFFFFF><SPACER TYPE=BLOCK WIDTH=1></TD></tr>");
				iQnum++;
			}

			// maybe make this conditional
			Rating = Math.round((Rating/nItems)*100)/100
			document.write("<tr><td colspan=4 bgcolor=#CCCCCC height=2><SPACER TYPE=BLOCK WIDTH=1></td><TD width=10><SPACER TYPE=BLOCK WIDTH=1></TD></tr><tr><td colspan=2><b>Overall</b></td><td WIDTH=70><b>" +MakeStars(Rating)+ "</b></td><td WIDTH=45><b>" +Rating+ "</b></td></tr>");
			document.write("<tr><td colspan=5 align=right valign=top height=42><img src=/modules/surveys/images/edge_bottom.jpg height=32 width=306></td></tr>");
		}
		} // end results
		document.write("<TR><TD colspan=5><FONT face=arial size=2 class=LVtext><a href='/news/197170.asp'>About MSNBC Polls</a></TD></TR>");
	}
	document.write("</TABLE>");
}

function SortItems(aTmp1) {
	var aTmp = new Array(0,0);
	bChanged = true;
	while (bChanged) {
		bChanged = false;
		for (var j=1;j<aTmp1.length-1;j++) {	// for each option
			if (aTmp1[j][1]<aTmp1[j+1][1]) {
				aTmp[0] = aTmp1[j];
				aTmp[1] = aTmp1[j+1];

				aTmp1[j+1]=aTmp[0];
				aTmp1[j]=aTmp[1];
				bChanged = true;
			}
		}
	}
	return aTmp1;
}

function MakeStars(rating) {
	var stars = "<SPACER TYPE=BLOCK WIDTH=1>";
	for (var n=0;n<parseInt(rating);n++) {
		stars += "<img src=/modules/surveys/images/star_whole.gif height=10 hspace=2 width=10>";
	}
	stars2 = rating-parseInt(rating);

	if (stars2>=.25 && stars2<.5) { stars += "<img src=/modules/surveys/images/star_1quarter.gif height=10 width=10 hspace=2>"; }

	else if (stars2>=.50 && stars2<.75) { stars += "<img src=/modules/surveys/images/star_half.gif height=10 width=10 hspace=2>"; }

	else if (stars2>=.75) { stars += "<img src=/modules/surveys/images/star_3quarter.gif height=10 width=10 hspace=2>"; }
	return stars;
}
