// To make the fav and rival bold, we change the style for span *, that requires the style's rule number=candidate's ID number, not a letter ID. //
// Previous favorite, function,  rival, cell clicked and its style. //
	var preFunc=1
	var preFav=1
	var preRival=0
	var preTd="c11"
	var preStyle="T"
//  Names of gif check marks placed in Table I by un- ColorBlts(). //
	C0= new Image(18,18)
	C0.src="C0.gif"
	CR= new Image(18,18)
	CR.src="CR.gif"
//  UnColorT clears all Table II Transfer steps that were colored by clicking a Table I Ballot. //
// It is called by ColorBlts if the previous function was ColorT.  //
// The first 3 lines uncolor the last ballot that was clicked. //
function UnColorSums()	{
	var td0 = document.getElementById(preTd)
	td0.style.backgroundColor="#fff"
	td0.style.color="#00a"
	for ( i = 0; i <tallyCells; i++ )	{
		var idName = Sum_Ids[i]
		var td1 = document.getElementById(idName)
		var idStyle = sumStyles[i]
		var bg = ( idStyle == 1 )	 ? "#fff" : "#f5f5f5"
		td1.style.backgroundColor=bg
	  }
  }
//  Called by clicking a sum cell in Table II or III. //
function ColorBlts( thisTd, thisClass, fav, b_1, b_2, b_3, b_4, b_5, b_6, b_7 )	{
		UnColorBlts()
		UnColorSums()
		preFunc=2;		
		UnCheckSum()

	// Highlight the Sum cell that was clicked. //
	var tdObject = document.getElementById(thisTd)
	var bg0 = ( thisClass == "S" ) ? "#ddd" : "#ffd"
	tdObject.style.backgroundColor=bg0
	tdObject.style.color="#a00"
	tdObject.style.fontWeight="bolder"

	// Hightlight and checkmark the related Ballots. bg=background. //
	for ( i = 1; i < numBallots + 1; i++ )	{
		var bgNum=eval("b_"+ i )
		if ( bgNum == 1 ) {
			var bClr = "#fff"
			var check = "C0"
		}
		else if ( bgNum == 2 )	{
			var bClr = "#ffd"
			var check = "CR"
		}
		else if ( bgNum == 8 )	{
			var check = "C0"
			var bClr = "#ddd"
		}
		var td_id = "td_"+i;
		var tdObj = document.getElementById(td_id)
		tdObj.style.backgroundColor=bClr
		var num1 = i + imgNum
	document.images[num1].src=eval(check+".src")
	}
	// Highlight the Sum column header. //
	var favHeader = "h_" + fav
	var fH = document.getElementById(favHeader)
	fH.style.fontWeight="bolder"
	fH.style.color="#a00"
	if (navigator.appName == "Microsoft Internet Explorer")	{
		document.styleSheets[2].rules[preFav].style.color="#00a"
		document.styleSheets[2].rules[preFav].style.fontWeight="bold"
		document.styleSheets[2].rules[fav].style.color="black"
		document.styleSheets[2].rules[fav].style.fontWeight="bolder"
	}
	else if (navigator.appName != "Opera")	{
		document.styleSheets[2].cssRules[preFav].style.color="#00a"
		document.styleSheets[2].cssRules[preFav].style.fontWeight="600"
		document.styleSheets[2].cssRules[fav].style.color="black"
		document.styleSheets[2].cssRules[fav].style.fontWeight="800"
	}
	preFav=fav
	preTd=thisTd
	preStyle = thisClass
}
function UnColorBlts( )	{
	for ( i =1; i < numBallots; i++ )	{
		var num = i + imgNum
		document.images[num].src=eval("C0.src")
		var idName = Blt_Ids[i]
		var td1 = document.getElementById(idName)
		td1.style.backgroundColor="#fff"
	}
	if (navigator.appName == "Microsoft Internet Explorer")	{
		document.styleSheets[2].rules[preFav].style.color="#00a"
		document.styleSheets[2].rules[preFav].style.fontWeight="bold"
	}
	else		{
		if (navigator.appName != "Opera")	{
			document.styleSheets[2].cssRules[preFav].style.color="#00a"
			document.styleSheets[2].cssRules[preFav].style.fontWeight="bold"
		}
	}
  }
//  Called by ColorSums //
//  Called by clicking a ballot cell in Table I. //
// Two dimensional grid of cells addressed with two for loops: i = column #, j = row #. //
// One for loop would be enough if this works: var td1 = ColorSums[i] //
function ColorSums( thisTd, b_0, b_11, b_12, b_13, b_14, b_21, b_22, b_23, b_24, b_31, b_32, b_33, b_34, b_41, b_42, b_43, b_44, b_51, b_52, b_53, b_54 , b_61, b_62, b_63, b_64 )	{
	if ( preFunc == 2 )	{
		UnCheckSum()
		UnColorBlts()
		preFunc = 1
	}
	else	{
		var pT = document.getElementById(preTd)
		pT.style.backgroundColor="#fff"
		pT.style.color="#00a"
	}
	var td0 = document.getElementById(thisTd)
	td0.style.backgroundColor="#ffd"
	td0.style.color="#a00"
	for ( i = 1; i < tallyRows + 1; i++ )	{
		for ( j = 1; j < tallyCols + 1; j++ )	{
			var td1 = "c"+i+j
			var td2 = document.getElementById(td1)
			var bg1 = eval("b_"+i+j)
			if ( bg1 == 1 )	{
				td2.style.backgroundColor="#fff"
				td2.style.color="#00a"
			}
			else if ( bg1 == 2 )	{
				td2.style.backgroundColor="#ffd"
				td2.style.color="#00a"
			}
			else if ( bg1 == 7 )	{
				td2.style.backgroundColor="#f5f5f5"
				td2.style.color="#00a"
			}
			else if ( bg1 == 8 )	{
				td2.style.backgroundColor="#ddd"
				td2.style.color="#00a"
			}
		}
	}
	preTd=thisTd
  }
//  Called by ColorBlts, always nec. //
// First it uncolors the column header of the last Transfer Step cell that was clicked. //
function UnCheckSum( )	{
	var favHeader = "h_" + preFav
	var fH = document.getElementById(favHeader)
	fH.style.fontWeight="bold"
	fH.style.color="black"
	var pT = document.getElementById(preTd)
	pT.style.color="#00a"
	if ( preStyle == "T")	{
		pT.style.fontWeight="bold"
		pT.style.backgroundColor="#fff"
	}
	else	{
		pT.style.fontWeight="normal"
		pT.style.backgroundColor="#f5f5f5"
	}
}

