// <script language="JavaScript">
var boolDebug=false


//===================================================================================
// DynastyVision Play-By-Play Display
// Version 3.1
// for SimDynasty (http://www.simdynasty.com)
// By Chris La Mantia
//===================================================================================
// Change Control
// IN - 05/17/11 - CL - Cached object pointers to increase performance
// IN - 01/08/11 - CL - Added setting to start DV paused
// IN - 07/11/10 - CL - Fixed logos not swapping when player faces disabled.
// IN - 05/04/10 - CL - Use JSP rendering for faces for IE6 and below; write OOT for current game using live data; save all DV speeds
// IN - 03/25/10 - CL - Changed faces to use prerendered faces with composited caps
// IN - 02/01/10 - CL - Changed paramter for .jpg to prevent logged warnings
// IN - 01/25/10 - CL - Adding artificial turf image 
// IN - 11/18/09 - CL - Adding stadium info 
// IN - 06/16/09 - CL - Added faces to Dynasty Vision 
// IN - 05/28/08 - CL - Added pitcher icons to make the difference between leftys and rightys more visible 
// IN - 05/20/08 - CL - Added city code for Montreal

debug("Debugging is enabled, if you are not participating in debugging we apologize for the inconvenience.")

function detectKey(e)
{
	var keynum;

	if(window.event) // IE
	{
		keynum = window.event.keyCode;
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keynum = e.which;
	}

	if(keynum==32) {
		pause();
	}
}
document.onkeydown = detectKey

function imagestatus()
{
   var intLoaded=0
   var intIndex;
   var intInterval=100
   var intTimeout=(1000/intInterval)*15
   
   clearTimeout(oImageTimer);
   oImageTimer=null;
   if(aImages) { 
      for(intIndex=0; intIndex<aImgNames.length; intIndex++) {
         if(aImages[aImgNames[intIndex]]) {
            if(aImages[aImgNames[intIndex]].complete==true) {
               intLoaded++;
            }
         }
      }
      if(strDVType=="normal") {
         for(intIndex=0; intIndex<aNDImgNames.length; intIndex++) {
            if(aImages["nd-"+aNDImgNames[intIndex]]) {
               if(aImages["nd-"+aNDImgNames[intIndex]].complete==true) {
                  intLoaded++;
					}
            }
         }
      }
      if(aImages["logoH"]) {
         if(aImages["logoH"].complete==true) {
            intLoaded++;
         }
      }
      if(aImages["logoV"]) {
         if(aImages["logoV"].complete==true) {
            intLoaded++;
         }
      }
      if(boolUseJspFaces==false) {
			if(aImages["capH"]) {
				if(aImages["capH"].complete==true) {
					intLoaded++;
				}
			}
			if(aImages["capV"]) {
				if(aImages["capV"].complete==true) {
					intLoaded++;
				}
			}
      }
      
      if(strDVMode=="full"&&strDVType=="normal") {
         for(intIndex=0; intIndex<aOOTImages.length; intIndex++) {
            if(aOOTImages[intIndex]) {
               if(aOOTImages[intIndex].complete==true) {
                  intLoaded++;
               }
            }
         }
		}
		if(intDVFaces==1) {
			if(aPlayerData) {
				for(intIndex=0;intIndex<aPlayerData.length;intIndex++) {
					if(aPlayerData[intIndex]) {
						if(aPlayerData[intIndex]["iFace"]) {
							if(aPlayerData[intIndex]["iFace"].complete==true) {
								intLoaded++;
							}
						}	
					}
				}
			}
      }
		
      intImageLoadTime++
      
      if(obj("ImageLoadStatus")) {
         obj("ImageLoadStatus").innerHTML=intLoaded.toString()+" of "+intTotalImages.toString()+" images loaded"
      }
      for(intIndex=0;intIndex<20;intIndex++) {
         if(intIndex<intLoaded*(20/intTotalImages)) {
            if(obj("ImgLoadBar"+intIndex.toString())) {
               obj("ImgLoadBar"+intIndex.toString()).style.backgroundColor="#00E000"
            }
         }
      }
      if(((intLoaded>=intTotalImages)||(intImageLoadTime>intTimeout)||(boolCancelLoad==true))&&(boolLoadReady==true)) {
         debug("Found all images")
         debug("Ready to run window_onload2()")
         window_onload2()
      } else {
         oImageTimer=setTimeout('imagestatus()',intInterval)
      }
   } else {
      oImageTimer=setTimeout('imagestatus()',intInterval)
   }
}

// Array definitions
var aImages
var aImgNames
var aLineIndex
var aNDImgNames
var aOOTImages=new Array()
var aOOTIndex=new Array()
var aPlayerIndex
var arLastAtBat
var arLineObjects
var aStadiums
var aTeamData
var aPlayerData

arLastAtBat=new Array
arLineObjects=new Array   


// Flags
var boolCancelLoad=false
var boolcolor="on"
var boolComplete
var boolcount="on"
var boolInnAdv=false
var boolLoadReady=false
var boolShowAll=false
var boolUseJspFaces=false

// Image objects
var imgHomeLogo
var imgVisLogo

// Numeric variables
var intDataBlockVer;
var intBalls
var intBatterID=null
var intCurID
var intCurInning
var intCurrentLine
var intImageLoadTime=0
var intInningHalf
var intInnScore
var intInterval
var intLoadedImages=0
var intNodeCount
var intLineCount=0
var intOnBase
var intOOTCount=0
var intOOTLineNo=0
var intOOTScroll=0
var intOldBatterID=null
var intOuts
var intPrevBatterID=0
var intScoreH
var intScoreV
var intSeed
var intStartInning=1
var intStrikes
var intTotalImages=0
var floatTimeMinutes=1
var intTimeHours=7

// Objects
var oAdvanceTimer
var oBatterLineTag
var oBatterTimer
var oImageTimer
var oLastLineTag
var oLineTag
var oRecapParent
var oRecapWindow
var oTimer

// Strings
var strCurTeam
var strDVType="normal"
var strDVMode="full"
var intDVFaces=1
var strHome
var strOldBatter
var strSetBatter
var strStatusBuffer
var strVisitor
var strHomeCap
var strVisitorCap

//===================================================================================
// Set up color commentary buffer
// Necessary for Netscape 6 and any other browsers that don't support scrollIntoView()
//===================================================================================
var aCCBuffer=new Array()
var intCCBufferSize=5
for(var intIndex=0;intIndex<intCCBufferSize;intIndex++) {
   aCCBuffer[intIndex]=""
}
var boolUseBuffer=false
if(oBrowser.isNS && oBrowser.versionMajor<=6) {
   boolUseBuffer=true
}
if(oBrowser.isIE && oBrowser.versionMajor<=5 && oBrowser.isMac ) {
   boolUseBuffer=true
}

if(oBrowser.isIE && oBrowser.versionMajor<=6) {
   boolUseJspFaces=true
}


//===================================================================================
// Color queue variables
// The color queue is a circular buffer
// Elements are added at intColorQueueTail and popped from intColorQueueHead
//===================================================================================
var aColorQueue=new Array()
var intColorQueueTail=0
var intColorQueueHead=0
var intColorQueueSize=40

for(var intIndex=0;intIndex<intColorQueueSize;intIndex++)
{
   aColorQueue[intIndex]=new Array()
   aColorQueue[intIndex]["Text"]=""
   aColorQueue[intIndex]["Event"]=""
   aColorQueue[intIndex]["Class"]=""
   aColorQueue[intIndex]["Object"]=null
}


//===================================================================================
// Default stadium names
// Used when a team's stadium name is not found
//===================================================================================

aStadiums=new Array()
aStadiums["WAS"]="Washington Stadium"
aStadiums["NYA"]="New York Stadium"
aStadiums["BAL"]="Baltimore Stadium"
aStadiums["DET"]="Detroit Stadium"
aStadiums["CLE"]="Cleveland Stadium"
aStadiums["CHA"]="Chicago Park"
aStadiums["BOS"]="Boston Park"
aStadiums["KC"]="Kansas City Stadium"
aStadiums["CIN"]="Cincinnati Field"
aStadiums["BRO"]="Brooklyn Field"
aStadiums["CHN"]="Chicago Field"
aStadiums["STL"]="St. Louis Park"
aStadiums["PHI"]="Philadelphia Park"
aStadiums["PIT"]="Pittsburgh Field"
aStadiums["MIL"]="Milwaukee Stadium"
aStadiums["NYN"]="New York Grounds"
aStadiums["LAN"]="Los Angeles Stadium" 
aStadiums["SF"]="San Francisco Park"
aStadiums["ATL"]="Atlanta Field"
aStadiums["SD"]="San Diego Park"
aStadiums["COL"]="Colorado Stadium"
aStadiums["ARI"]="Arizona Stadium"
aStadiums["FLA"]="Florida Stadium"
aStadiums["HOU"]="Houston Stadium"
aStadiums["LAA"]="Los Angeles Field"
aStadiums["MIN"]="Minnesota Stadium"
aStadiums["OAK"]="Oakland Field"
aStadiums["SEA"]="Seattle Stadium"
aStadiums["TEX"]="Texas Park"
aStadiums["TB"]="Tampa Bay Stadium"
aStadiums["TOR"]="Toronto Stadium"
aStadiums["MON"]="Montreal Stadium"
aStadiums["HOME"]="Dynasty Stadium"

//===================================================================================
// City data for out-of-town scoreboards
//===================================================================================

var aCities=new Array("BAL","BOS","CHA","CLE","DET","KC","NYA","WAS",
	"BRO","CHN","CIN","MIL","NYN","PHI","PIT","STL",
	"LAA","MIN","OAK","SEA","TB","TEX","TOR",
	"ARI","ATL","COL","FLA","HOU","LAN","SD","SF","MON");

var aCityIDs=new Array()
for(var intIndex=0;intIndex<aCities.length;intIndex++) {
   aCityIDs[aCities[intIndex]]=intIndex+1
}

var aTimeZones=new Array()
aTimeZones["WAS"]=3
aTimeZones["NYA"]=3
aTimeZones["BAL"]=3
aTimeZones["DET"]=3
aTimeZones["CLE"]=3
aTimeZones["CHA"]=2
aTimeZones["BOS"]=3
aTimeZones["KC"]=2
aTimeZones["CIN"]=3
aTimeZones["BRO"]=3
aTimeZones["CHN"]=2
aTimeZones["STL"]=2
aTimeZones["PHI"]=3
aTimeZones["PIT"]=3
aTimeZones["MIL"]=2
aTimeZones["NYN"]=3
aTimeZones["LAN"]=0 
aTimeZones["SF"]=0 
aTimeZones["ATL"]=3
aTimeZones["SD"]=0
aTimeZones["COL"]=1
aTimeZones["ARI"]=0
aTimeZones["FLA"]=3
aTimeZones["HOU"]=2
aTimeZones["LAA"]=0
aTimeZones["MIN"]=2
aTimeZones["OAK"]=0
aTimeZones["SEA"]=0
aTimeZones["TEX"]=2
aTimeZones["TB"]=3
aTimeZones["TOR"]=3
aTimeZones["MON"]=3


var aOOTData=new Array();
for(var intIndex=0;intIndex<8;intIndex++) {
   aOOTData[intIndex]=new Array();
   aOOTData[intIndex]["Inning"]="1 Top"   
   aOOTData[intIndex]["ScoreH"]=0   
   aOOTData[intIndex]["ScoreV"]=0   
}

// Time synch is calculated as:
// intNodeCount*.64+((OOTTZ-HomeTZ)*30)
// Games with negative numbers haven't started yet



//===================================================================================
// Set up timing data
//===================================================================================

var aSpeedInterval=new Array(10000,8000,6000,5000,4000,3000,2000,1000,500,1)
var intSpeed=4
LoadDVPrefs()

//===================================================================================
// Set up positions table
//===================================================================================
var aPositions=new Array("","P","C","1B","2B","3B","SS","LF","CF","RF");

//===================================================================================
// Set up lineup arrays
//===================================================================================
var aLineup=new Array;
aLineup["H"]=new Array;
aLineup["V"]=new Array;
var aBatterID=new Array() 
aBatterID["H"]=0  // Number in the batting order that's currently up
aBatterID["V"]=0


function window_onload()
{
   var oHome
   var oVisitor
   var intIndex
   var boolForceEnd
   var boolParentFound
   var oEnum
   var strGameDate
	
   if(strDVMode=="basic") {
      obj("dvmain").width=282
      obj("PBPColumn").style.display="none"
      obj("cbspacer").width=10
   } 
   if(strDVMode=="none") {
      obj("statuscaption").innerHTML="Showing box score..."
   }
   intCurInning=0
   intInningHalf=4
   strCurTeam="H"
   intInnScore=0
   intBalls=0
   intStrikes=0
   intCurID=0
   intNodeCount=0
   intOnBase=0
   intOuts=0
   boolComplete=false
   strOldBatter=""
   strSetBatter=""
   intBalls=0
   intStrikes=0
	
   debug("Entering function: window_onload")
   
   // Set up clock
   var myDate=new Date(eval('"'+obj("strGameDate").innerHTML+'"'))
   if(myDate.getDay() == 0) {
      // It's Sunday; make it a day game
      intTimeHours=3
   }
   
   oRecapWindow=obj("RecapWindow")   
   oRecapParent=obj("RecapWindow")   
   boolParentFound=false  
   // Check for abort
   if(strDVMode) {
      if(strDVMode=="none") {
         boolCancelLoad=true
         boolShowAll=true;
      }
   }   
   intIndex=0
   // Netscape strikes again... no parentElement
	
   while(boolParentFound==false&&intIndex<10) {
      oRecapParent=((oRecapParent.parentElement)?oRecapWindow.parentElement:oRecapParent.parentNode);
      if(oRecapParent) {
         if(oRecapParent.tagName) {
            if(oRecapParent.tagName.toLowerCase()=="td") {
               boolParentFound=true
            }
         }
      }
      intIndex++
   }   
   //alert(oRecapParent.tagName)
   if(strDVMode!="basic") {
      oRecapParent.style.display="none"
   }
   //alert("Index start")   
   // Seed random number generator
   intSeed=100;
	
	for(intIndex=10;intIndex<35;intIndex++) {
		if(aPlayerData) {
			if(aPlayerData[intIndex]){  // Check for a valid object
				intSeed+=aPlayerData[intIndex]["pID"]
			}
		}
   }
   randseed(intSeed);
   // Set up team data for backward compatibility
   if(!aTeamData) {
      aTeamData=new Array;
   } 
   if(!aTeamData["H"]) {
      aTeamData["H"]=new Array;
   } 
   if(!aTeamData["V"]) {
      aTeamData["V"]=new Array;
   } 
   if(!aTeamData["H"]["TeamCity"]) {
      aTeamData["H"]["TeamCity"]="Home";
      aTeamData["H"]["TeamName"]="Team";
   } 
   if(!aTeamData["V"]["TeamCity"]) {
      aTeamData["V"]["TeamCity"]="Visitor";
      aTeamData["V"]["TeamName"]="Team";
   } 
   if(!aTeamData["H"]["TeamCityCode"]) {
      aTeamData["H"]["TeamCityCode"]="HOME" 
   }
   if(!aTeamData["V"]["TeamCityCode"]) {
      aTeamData["V"]["TeamCityCode"]="VIS"
   }
   if(!aTeamData["H"]["LogoNum"]) {
      aTeamData["H"]["LogoNum"]=1
   }
   if(!aTeamData["V"]["LogoNum"]) {
      aTeamData["V"]["LogoNum"]=1
   }
   if(!aTeamData["H"]["DisplayType"]) {
      aTeamData["H"]["DisplayType"]="dm"  
   } 
   aTeamData["H"]["BatterNum"]=1
   aTeamData["V"]["BatterNum"]=1
   
   // Since we already have team data in the datablock, add on fields for in-game data
   aTeamData["H"]["Runs"]=0
   aTeamData["H"]["Hits"]=0
   aTeamData["H"]["Errors"]=0
   aTeamData["H"]["LOB"]=0
   aTeamData["V"]["Runs"]=0
   aTeamData["V"]["Hits"]=0
   aTeamData["V"]["Errors"]=0
   aTeamData["V"]["LOB"]=0
	
	//===================================================================================
	// Preload images
	//===================================================================================
	
	if(strDVType=="normal") {
		aImgNames = new Array(
			"b-off",
			"b-on",
			"ball",
			"hit",
			"error",
			"batterHL",
			"batterHR",
			"batterVL",
			"batterVR",
			"catcherH",
			"catcherV",
			//      "cb-logo",
			"cb-slower",
			//      "cb-lspacer",
			"cb-lighton",
			"cb-lightoff",
			//      "cb-rspacer",
			"cb-faster",
			"cb-pause",
			"cb-end",
			//      "cb-count",
			//      "cb-color",
			"cb-slower-dn",
			"cb-faster-dn",
			"cb-end-dn",
			//      "cb-count-dn",
			//      "cb-color-dn",
			//      "cb-lspacer-dn",
			//      "cb-lighton-dn",
			//      "cb-lightoff-dn",
			"cb-spacer",
			"cb-pause-dn",
			"error",
			//      "field",
			"hit",
			"inn",
			"o-off",
			"o-on",
			"out",
			"pitcherHL",
			"pitcherHR",
			"pitcherVL",
			"pitcherVR",
			"playerblank",
			"playerHL",
			"playerHR",
			"playerVL",
			"playerVR",
			"runnerH",
			"runnerV",
			"s-off",
			"s-on",
			"spacer",
			"strike",
			"time"
			);
	} else {
		aImgNames = new Array(
			//      "b-off",
			//      "b-on",
			"batterHL",
			"batterHR",
			//      "batterVL",
			//      "batterVR",
			//      "catcherH",
			"catcherV",
			//      "cb-logo",
			"cb-slower",
			//      "cb-lspacer",
			"cb-lighton",
			"cb-lightoff",
			//      "cb-rspacer",
			"cb-faster",
			"cb-pause",
			"cb-end",
			//      "cb-count",
			//      "cb-color",
			"cb-slower-dn",
			"cb-faster-dn",
			"cb-end-dn",
			//      "cb-count-dn",
			//      "cb-color-dn",
			//      "cb-lspacer-dn",
			//      "cb-lighton-dn",
			//      "cb-lightoff-dn",
			"cb-pause-dn",
			"cb-spacer",
			//      "field",
			"o-off",
			"o-on",
			//      "pitcherHL",
			//      "pitcherHR",
			"pitcherVL",
			"pitcherVR",
			"playerblank",
			//      "playerHL",
			//      "playerHR",
			"playerVL",
			"playerVR",
			"runnerH",
			//      "runnerV",
			//      "s-off",
			//      "s-on",
			"spacer"
			);
	}
	
	aNDImgNames = new Array(
		"0",
		"1",
		"2",
		"3",
		"4",
		"5",
		"6",
		"7",
		"8",
		"9",
		"blank",
		"blankh",
		"1h",
		"r",
		"h",
		"e",
		"colon"
		);
	
	aImages=new Array();
	intTotalImages=aImgNames.length
	intLoadedImages=0
	for(var intIndex=0; intIndex<aImgNames.length; intIndex++) {
		aImages[aImgNames[intIndex]] = new Image();
		aImages[aImgNames[intIndex]].src = "/images/dv-"+aImgNames[intIndex]+".gif";
		
	}
	
	oImageTimer=setTimeout('imagestatus()',20)
	
   // Load scoreboard display numeric images
   if(strDVType=="normal") {
      for(intIndex=0; intIndex<aNDImgNames.length; intIndex++) {
         aImages["nd-"+aNDImgNames[intIndex]] = new Image();
         aImages["nd-"+aNDImgNames[intIndex]].src = "/images/dv-nd-"+aTeamData["H"]["DisplayType"]+aNDImgNames[intIndex]+".gif";
      }
      intTotalImages+=aNDImgNames.length
   }
	
   // Load team images
   aImages["logoH"]= new Image();
   aImages["logoV"]= new Image();
   intTotalImages+=2;
	strHomeCap=aTeamData["H"]["TeamCityCode"].toLowerCase()+aTeamData["H"]["LogoNum"].toString();
	strVisitorCap=aTeamData["V"]["TeamCityCode"].toLowerCase()+aTeamData["V"]["LogoNum"].toString();
   aImages["logoH"].src = "facejpg.jsp?cap="+strHomeCap+"&width=52&filetype=.jpg";
   aImages["logoV"].src = "facejpg.jsp?cap="+strVisitorCap+"&width=52&filetype=.jpg";
   if(boolUseJspFaces==false) {
		if(intDVFaces==1) {
			aImages["capH"]= new Image();
			aImages["capV"]= new Image();
			intTotalImages+=2;
			aImages["capH"].src = "facejpg.jsp?cap="+strHomeCap+"&mode=dvcap&filetype=.png";
			aImages["capV"].src = "facejpg.jsp?cap="+strVisitorCap+"&mode=dvcap&filetype=.png";
		}
   }
   
   // Set up out-of-town scoreboards
   for(intIndex=0;intIndex<aCities.length;intIndex++) {
      if(arAllGames) {
         if(arAllGames[aCities[intIndex]]) {
            // We found out of town scoreboard data
            aOOTIndex[intOOTCount++]=aCities[intIndex]
         }
      }
   }
	
   // Load out-of-town team images
   if(strDVType) {   
      if((strDVType=="lite")||(strDVMode=="basic")) {
         for(intIndex=0;intIndex<intOOTCount*2;intIndex++) {
            aOOTImages[intIndex]=new Image()
            aOOTImages[intIndex].src = "/images/dv-placeholder.gif"
         }
      } else {
         LoadOOTImages(intOOTCount)
      } 
   } else {
      LoadOOTImages(intOOTCount)
   }
	
   // Create index and load lineups
   aPlayerIndex=new Array;
   aPlayerNameIndex=new Array;
   aPlayerNameIndex["H"]=new Array;
   aPlayerNameIndex["V"]=new Array;
   if(intDataBlockVer>=2) {
      if(aPlayerData){  // Check for a valid object
         for(intIndex=0;intIndex<aPlayerData.length;intIndex++) {
            if(aPlayerData[intIndex]){  // Check for a valid object
               // Add to index
               if(aPlayerData[intIndex]["pID"]) {
                  aPlayerIndex[aPlayerData[intIndex]["pID"].toString()]=intIndex
                  aPlayerNameIndex[aPlayerData[intIndex]["pTeam"]][aPlayerData[intIndex]["pName"]]=intIndex
               }
               if(aPlayerData[intIndex]["pID"] && intDVFaces==1 ) {
						// Look for player images 
						if(aPlayerData[intIndex]["pFace"]) {
							if(aPlayerData[intIndex]["pFace"]!=0) {
								var intAge=20;
								var strFace=aPlayerData[intIndex]["pFace"].toString();
								var strFaceURL="/images/playerfacesdv/face"+strFace;
								if(aPlayerData[intIndex]["pOSAge"]) {
									if(aPlayerData[intIndex]["pOSAge"]>15) {
										intAge=aPlayerData[intIndex]["pOSAge"];
									}
								}
								if(boolUseJspFaces==false) {
									var imgage=intAge+(aPlayerData[intIndex]["pFace"] % 4);
									var imgagelevel = 1;
									if(imgage>21) imgagelevel=2; // 19-22
									if(imgage>31) imgagelevel=3; // 29-32
									if(imgage>40) imgagelevel=4; // 38-41
									strFaceURL+="-"+imgagelevel.toString();
									strFaceURL+="-dv.jpg";
								} else {
									strFaceURL="/facejpg.jsp?face="+strFace;
									if(aPlayerData[intIndex]["pTeam"]=="H") {
										strFaceURL+="&cap="+strHomeCap+"&width=52&filetype=.jpg";
									} else {
										strFaceURL+="&cap="+strVisitorCap+"&width=52&filetype=.jpg";
									}
								}
								aPlayerData[intIndex]["iFace"]= new Image();
								intTotalImages++;
								aPlayerData[intIndex]["iFace"].src = strFaceURL;
							}
						}
					}
					
					// Look for starting lineup
               if(aPlayerData[intIndex]["pBO"]){
                  if(aPlayerData[intIndex]["pLinOrd"]){
                     if(aPlayerData[intIndex]["pLinOrd"]==1) {
                        if(aPlayerData[intIndex]["pTeam"]=="A") {
                           aPlayerData[intIndex]["pTeam"]="V";
                        }
                        aLineup[aPlayerData[intIndex]["pTeam"]][aPlayerData[intIndex]["pBO"]]=aPlayerData[intIndex]["pID"].toString()
                     }
                  }
               }
            }
         }
      }
   }
   aBatterID["H"]=aLineup["H"][9]
   aBatterID["V"]=aLineup["V"][9]
   
   
   // Set up line index
   // Complicated line indexing due to some browsers treating whitespace as nodes
   aLineIndex=new Array;
   intCurrentLine=0;
   boolForceEnd=false
   intNodeCount=0
   debug("Starting indexer")
   oLineTag=oRecapWindow.childNodes[0]
   
   for(intNodeCount=0;intNodeCount<oRecapWindow.childNodes.length;intNodeCount++) {  // Needs to be -1 for Mac
      oLineTag=oRecapWindow.childNodes[intNodeCount]
      var intNodeFound=false
      if(oLineTag) {
         if(oLineTag.nodeType) {
            if(oLineTag.nodeType==1) {
               if(oLineTag.tagName) {
                  if(oLineTag.tagName.toLowerCase()=="span") {
                     intNodeFound=true
                     aLineIndex[intCurrentLine++]=oLineTag
                  }
               }
            }
         }
      }
      if(intNodeCount%50==0) {
         debug(intNodeCount)
      }
   }
   oLineTag=null
   debug("Line count: "+intCurrentLine.toString())
   intNodeCount=0
   boolLoadReady=true
   debug("Exiting function: window_onload")
}

function window_onload2() 
{
   debug("Entering function: window_onload2")
   // Set up control bar   
   setspeed(intSpeed)
   obj("CBslower").src=aImages["cb-slower"].src
   obj("CBfaster").src=aImages["cb-faster"].src
   obj("CBpause").src=aImages["cb-pause"].src
   obj("CBend").src=aImages["cb-end"].src
   obj("cbspacer").src=aImages["cb-spacer"].src
   // **************
   // Disable count and color controls until they do something
   //
   //obj("CBcount").src=aImages["cb-count"].src
   //obj("CBcolor").src=aImages["cb-color"].src
   //obj("CBcountlight").src=aImages["cb-light"+boolcount].src
   //obj("CBcolorlight").src=aImages["cb-light"+boolcolor].src
   //obj("CBcountlight").src=aImages["cb-spacer50"].src
   //obj("CBcolorlight").src=aImages["cb-spacer50"].src
   //obj("CBcount").src=aImages["cb-spacer50"].src
   //obj("CBcolor").src=aImages["cb-spacer50"].src
   //obj("CBcountlight").onmousedown=""
   //obj("CBcolorlight").onmousedown=""
   //obj("CBcount").onmousedown=""
   //obj("CBcolor").onmousedown=""
   //obj("CBcountlight").onmouseup=""
   //obj("CBcolorlight").onmouseup=""
   //obj("CBcount").onmouseup=""
   //obj("CBcolor").onmouseup=""
   //obj("CBcountlight").onmouseout=""
   //obj("CBcolorlight").onmouseout=""
   //obj("CBcount").onmouseout=""
   //obj("CBcolor").onmouseout=""
   //obj("CBcountlight").title=""
   //obj("CBcolorlight").title=""
   //obj("CBcount").title=""
   //obj("CBcolor").title=""
   
   // Initialize static images
   if(strDVType=="lite") {
      obj("LDStrikeCell").innerHTML="<SPAN Class='sblabel'>STRIKE</span>"
      obj("LDBallCell").innerHTML="<SPAN Class='sblabel'>BALL</span>"
      obj("LDOutCell").innerHTML="<SPAN Class='sblabel'>OUT</span>"
      obj("LDInnCell").innerHTML="<SPAN Class='sblabel'>INN</span>"
      obj("LDHitCell").innerHTML="<SPAN Class='sblabel'>H</span>"
      obj("LDErrorCell").innerHTML="<SPAN Class='sblabel'>E</span>"
      obj("LDTimeCell").innerHTML="<SPAN Class='sblabel'>TIME</span>"
   } else {
      obj("LDStrike").src=aImages["strike"].src
      obj("LDBall").src=aImages["ball"].src
      obj("LDOut").src=aImages["out"].src
      obj("LDInn").src=aImages["inn"].src
      obj("LDHit").src=aImages["hit"].src
      obj("LDError").src=aImages["error"].src
      obj("LDTime").src=aImages["time"].src
   }
	
   // Blank or preset all scoreboard displays
   for(intIndex=1;intIndex<=9;intIndex++) {
      SetDMD("LineScoreHead"+intIndex.toString(),intIndex)
      SetDMD("LineScoreV"+intIndex.toString(),-1)
      SetDMD("LineScoreH"+intIndex.toString(),-1)
   }
   SetDMD("LineScoreVR",0)
   SetDMD("LineScoreVH",0)
   SetDMD("LineScoreVE",0)
   SetDMD("LineScoreHR",0)
   SetDMD("LineScoreHH",0)
   SetDMD("LineScoreHE",0)
   if(strDVType=="normal") {
      obj("LDSBLineScoreHeadR").src=aImages["nd-r"].src
      obj("LDSBLineScoreHeadH").src=aImages["nd-h"].src
      obj("LDSBLineScoreHeadE").src=aImages["nd-e"].src
      obj("LDSBClockColon").src=aImages["nd-colon"].src
   } else {
      obj("LDSBLineScoreHeadRCell").innerHTML="R"
      obj("LDSBLineScoreHeadHCell").innerHTML="H"
      obj("LDSBLineScoreHeadECell").innerHTML="E"
      obj("LDSBClockColonCell").innerHTML=":"
   }
   SetDMD("ScoreV",0)
   SetDMD("ScoreH",0)
   SetDMD("Inning",1)
   SetDMD("OOTHScore1",-1)
   SetDMD("OOTVScore1",-1)
   SetDMD("OOTHScore2",-1)
   SetDMD("OOTVScore2",-1)
   
   // Set up scoreboard
   obj("LDSBVisitingTeam").innerHTML=aTeamData["V"]["TeamCityCode"]
   obj("LDSBHomeTeam").innerHTML=aTeamData["H"]["TeamCityCode"]
   obj("LDTeamNameV").innerHTML=aTeamData["V"]["TeamCity"]
   obj("LDTeamNameH").innerHTML=aTeamData["H"]["TeamCity"]
   if(aTeamData["V"]["TeamID"]) {
      obj("LDTeamNameV").href="depth.jsp?teamid="+aTeamData["V"]["TeamID"].toString()
   } 
   if(aTeamData["H"]["TeamID"]) {
      obj("LDTeamNameH").href="depth.jsp?teamid="+aTeamData["H"]["TeamID"].toString()
   } 
	
   obj("dvDefTeamLogo").style.backgroundImage="url(" + aImages["logoH"].src + ")";
   obj("dvOffTeamLogo").style.backgroundImage="url(" + aImages["logoV"].src + ")";
	obj("dvDefTeamCap").style.display = "none";
	obj("dvOffTeamCap").style.display = "none";
   
   
   UpdateLights("S",0)
   UpdateLights("B",0)
   UpdateLights("O",0)
   if(strDVType=="lite") {
      obj("LDHLamp").src=aImages["o-off"].src
      obj("LDELamp").src=aImages["o-off"].src
      obj("LDTeamUpH").src=aImages["o-off"].src
      obj("LDTeamUpV").src=aImages["o-on"].src
   } else {
      obj("LDHLamp").src=aImages["b-off"].src
      obj("LDELamp").src=aImages["s-off"].src
      obj("LDTeamUpH").src=aImages["o-off"].src
      obj("LDTeamUpV").src=aImages["o-on"].src
   }
   SetDMD("ENum",-1)
	
	
   // Set up stadium info
   if(!aTeamData["H"]["StadiumName"]) {
      aTeamData["H"]["StadiumName"]=""
   }
   if(aTeamData["H"]["StadiumName"].length<2) {
      aTeamData["H"]["StadiumName"]=aStadiums[aTeamData["H"]["TeamCityCode"]]
   }
   if(aTeamData["H"]["StadiumName"]) {
      obj("StadiumWelcome").innerHTML="Welcome To "+aTeamData["H"]["StadiumName"]
   }
   obj("LiveDisplay").style.display=''
   obj("imageload").style.display='none'
   if(aTeamData["H"]["City"]!="Home") {
      var strIntro="<b>Welcome to "+aTeamData["H"]["TeamCity"]
      +"</b><br />for today's game between<br />"
      +"<b>The "+aTeamData["V"]["TeamCity"]+" "+aTeamData["V"]["TeamName"]+"</b><br />and<br />"
      +"<b>The "+aTeamData["H"]["TeamCity"]+" "+aTeamData["H"]["TeamName"]+"</b><hr color=#FFFFA0>"
      AddToPBP(strIntro,"intro",true)      
   }

	// Load field image
	var intStadID = 0;
	var intSurface = 0;
	if(aTeamData["H"]["StadiumID"]) {
		intStadID=aTeamData["H"]["StadiumID"]
	}
	if(aTeamData["H"]["Surface"]) {
		intSurface=aTeamData["H"]["Surface"]
	}
	if(intSurface==0) {
		obj("dvField").style.backgroundImage="url('images/dv-stadium" + intStadID +".gif')"
	} else {
		obj("dvField").style.backgroundImage="url('images/dv-stadium" + intStadID +"-turf.gif')"
	}

	if(aTeamData["H"]["LeftFence"]) {
		obj("dvFenceDistLeft").innerHTML=aTeamData["H"]["LeftFence"] + "/" + aTeamData["H"]["LeftFenceHeight"] + "'";
	} else {
		obj("dvFenceDistLeft").innerHTML="320/8'"
	}
	if(aTeamData["H"]["LeftCenterFence"]) {
		obj("dvFenceDistLeftCenter").innerHTML=aTeamData["H"]["LeftCenterFence"] + "/" + aTeamData["H"]["LeftCenterFenceHeight"] + "'";
	} else {
		obj("dvFenceDistLeftCenter").innerHTML="385/8'"
	}
	if(aTeamData["H"]["CenterFence"]) {
		obj("dvFenceDistCenter").innerHTML=aTeamData["H"]["CenterFence"] + "/" + aTeamData["H"]["CenterFenceHeight"] + "'";
	} else {
		obj("dvFenceDistCenter").innerHTML="405/8'"
	}
	if(aTeamData["H"]["RightCenterFence"]) {
		obj("dvFenceDistRightCenter").innerHTML=aTeamData["H"]["RightCenterFence"] + "/" + aTeamData["H"]["RightCenterFenceHeight"] + "'";
	} else {
		obj("dvFenceDistRightCenter").innerHTML="385/8'"
	}
	if(aTeamData["H"]["RightFence"]) {
		obj("dvFenceDistRight").innerHTML=aTeamData["H"]["RightFence"] + "/" + aTeamData["H"]["RightFenceHeight"] + "'";
	} else {
		obj("dvFenceDistRight").innerHTML="320/8'"
	}
	
		
	
   if(oRecapWindow) {
		
      if(boolShowAll==false) {
      	if(intDVStart==1) {
				AdvanceGame()
				if(intStartInning>1 && intStartInning<=9) {
					AdvanceToInning(intStartInning)
				}
         } else {
				obj("CBpause").src=aImages["cb-pause-dn"].src
         }
      } else {
         ShowAll(0)
      }
      
   } else {
      alert("Cannot find recap window!")
   }
   debug("Exiting function: window_onload2")
}


function pause()
{
   if(oTimer) {
      clearTimeout(oTimer)
      oTimer=null
      obj("CBpause").src=aImages["cb-pause-dn"].src
   } else {
      AdvanceGame()
      obj("CBpause").src=aImages["cb-pause"].src
   }
	
}

function getDim(el)
{
	// Get the true top of an element
   for (var ly=0;el!=null;ly+=el.offsetTop,el=el.offsetParent);
   return (ly)
}

function AdvanceGame()
{
   var oPause
   AdvanceLine(0)
	//   if(AdvanceLine(0)==0) {
   oTimer=setTimeout('AdvanceGame()',intInterval)
	//oPause=obj("btnPause")
	//if(oPause) {
	//   oPause.value='Pause'
	//}
	//   }
}

function AdvanceToInning(intInningStop)
{
   if(intInningStop>1) {
      if(intInningStop>intCurInning) {
         SetStatus("Advancing to Inning "+intInningStop)
         oAdvanceTimer=setTimeout("ShowAll("+intInningStop.toString()+")",10)
      }
   }
}

function ShowAll(intInningStop)
{
   if(oBatterTimer) {
      clearTimeout(oBatterTimer)
      oBatterTimer=null;
   }
   if(oImageTimer) {
      clearTimeout(oImageTimer)
      oImageTimer=null;
   }
   if(intInningStop<2) {
      boolShowAll=true
   }
   if(oRecapWindow) {
      intDone=0
      while(intDone==0) {
         intDone=AdvanceLine(intInningStop)
      }
   }
}


var boolClockStop=false

function AdvanceLine(intInningStop)
{
	
   var strCurID
   var strNextID
   var oTag
   var intNextID
   var strInningTag
   var strInningHead
   var intGameOver=0
   var oLOB
   var strCurBatter
   var boolForceEnd   
   var strEvent=null
	
   boolForceEnd=false
   
   // Update out-of-town scoreboard data
   if(boolShowAll==false&&strDVMode=="full" && boolClockStop==false) {
      intOOTLineNo=parseInt(intNodeCount*.58)
      boolClockStop=true
      for(intIndex=0;intIndex<intOOTCount;intIndex++) {
         if(arAllGames[aOOTIndex[intIndex]][intOOTLineNo]) {
            if(arAllGames[aOOTIndex[intIndex]][intOOTLineNo]["Inning"]) {
               aOOTData[intIndex]["Inning"]=arAllGames[aOOTIndex[intIndex]][intOOTLineNo]["Inning"]
            }
         }
         if(arAllGames[aOOTIndex[intIndex]][intOOTLineNo]) {
            if(arAllGames[aOOTIndex[intIndex]][intOOTLineNo]["ScoreH"]) {
               aOOTData[intIndex]["ScoreH"]=parseInt(arAllGames[aOOTIndex[intIndex]][intOOTLineNo]["ScoreH"])
            }
         }
         if(arAllGames[aOOTIndex[intIndex]][intOOTLineNo]) {
            if(arAllGames[aOOTIndex[intIndex]][intOOTLineNo]["ScoreV"]) {
               aOOTData[intIndex]["ScoreV"]=parseInt(arAllGames[aOOTIndex[intIndex]][intOOTLineNo]["ScoreV"])
            }
         }
         if(aOOTData[intIndex]["Inning"].substring(0,1)!="F" && intMyGameID!=arAllGames[aOOTIndex[intIndex]][0]['BoxScoreID']) {
				boolClockStop=false;
         }
      }
   }
	
   // Update out-of-town scoreboard display
   if(intInningStop<=intCurInning&&boolShowAll==false&&strDVMode=="full") {
      if((intLineCount % 2 == 0 && intInningStop<intCurInning)||(intLineCount==0)) { // Rotate every other line
         intOOTScroll+=2
         if(intOOTScroll>=intOOTCount) {
            intOOTScroll=0
         }      
			
         for(intIndex=0;intIndex<2;intIndex++) {
            if(intOOTScroll+intIndex<intOOTCount) {
               obj("OOTLeague"+(intIndex+1).toString()).innerHTML=arAllGames[aOOTIndex[intOOTScroll+intIndex]][0]['League']
               obj("OOTLeague"+(intIndex+1).toString()).href="boxscore.jsp?boxscoreid="+arAllGames[aOOTIndex[intOOTScroll+intIndex]][0]['BoxScoreID']+"&cityid="+aCityIDs[arAllGames[aOOTIndex[intOOTScroll+intIndex]][0]['CityCodeH']]
               obj("OOTLeague"+(intIndex+1).toString()).title="Click to watch "+arAllGames[aOOTIndex[intOOTScroll+intIndex]][0]['CityCodeV']+" at "+arAllGames[aOOTIndex[intOOTScroll+intIndex]][0]['CityCodeH']
               obj("OOTVCityCode"+(intIndex+1).toString()).innerHTML=arAllGames[aOOTIndex[intOOTScroll+intIndex]][0]['CityCodeV']
               obj("OOTHCityCode"+(intIndex+1).toString()).innerHTML=arAllGames[aOOTIndex[intOOTScroll+intIndex]][0]['CityCodeH']
               obj("OOTVLogo"+(intIndex+1).toString()).src=aOOTImages[(intOOTScroll+intIndex)*2].src
               obj("OOTHLogo"+(intIndex+1).toString()).src=aOOTImages[(intOOTScroll+intIndex)*2+1].src
               // If this is our own game, display from the live data
               if(intMyGameID==arAllGames[aOOTIndex[intOOTScroll+intIndex]][0]['BoxScoreID']) {
               	var strInnHalf="Top";
               	if(strCurTeam=="H") strInnHalf="Bot";
               	
               	if(boolComplete==true) {
               		if(intCurInning==9) {
               			obj("OOTInn"+(intIndex+1).toString()).innerHTML="F"
               		} else {
               			obj("OOTInn"+(intIndex+1).toString()).innerHTML="F " + intCurInning;
               		}
               	} else {
               		obj("OOTInn"+(intIndex+1).toString()).innerHTML=intCurInning + " " + strInnHalf;
               	}
						SetDMD("OOTHScore"+(intIndex+1),aTeamData["H"]["Runs"])
						SetDMD("OOTVScore"+(intIndex+1),aTeamData["V"]["Runs"])
               } else {
						obj("OOTInn"+(intIndex+1).toString()).innerHTML=aOOTData[intOOTScroll+intIndex]["Inning"]
						SetDMD("OOTHScore"+(intIndex+1),aOOTData[intOOTScroll+intIndex]["ScoreH"])
						SetDMD("OOTVScore"+(intIndex+1),aOOTData[intOOTScroll+intIndex]["ScoreV"])
               }
            } else {
               obj("OOTLeague"+(intIndex+1).toString()).innerHTML="&nbsp;"
               obj("OOTLeague"+(intIndex+1).toString()).href="#"
               obj("OOTLeague"+(intIndex+1).toString()).title="&nbsp;"
               obj("OOTVCityCode"+(intIndex+1).toString()).innerHTML="&nbsp;"
               obj("OOTHCityCode"+(intIndex+1).toString()).innerHTML="&nbsp;"
               obj("OOTVLogo"+(intIndex+1).toString()).src="/images/dv-placeholder.gif"
               obj("OOTHLogo"+(intIndex+1).toString()).src="/images/dv-placeholder.gif"
               obj("OOTInn"+(intIndex+1).toString()).innerHTML="&nbsp;"
               SetDMD("OOTHScore"+(intIndex+1),-1)
               SetDMD("OOTVScore"+(intIndex+1),-1)
            }
         }
      }
   }
	
   // Increment line count (counts total passes through loop, not nodes)
   intLineCount++
   // obj("LDTeamNameV").innerHTML=intLineCount.toString();   
   
   if(boolComplete==true) {
      // Update the time
      if(boolClockStop==false&&strDVMode=="full") {
			intNodeCount++
			UpdateClock(1.3)  // 1 minute 
		}
      return(1)
   }
   
   
   if(intColorQueueHead!=intColorQueueTail) {
      // Process event queue
      // If an item is in the queue, display it and exit
      ProcessColorQueue();
      return(0);
   }
	
   strEvent=null;
   if(oLineTag) {
      oLastLineTag=oLineTag
      if(oLineTag.getAttribute('sdEvent',false)) {
         strEvent=oLineTag.getAttribute('sdEvent',false)         
      }
   }
   
   if(intNodeCount<aLineIndex.length){
      oLineTag=aLineIndex[intNodeCount]
   } else {
      boolForceEnd=true
      oLineTag=null
   }
	
   // Check for a change in batters
   if(boolShowAll==false && boolForceEnd==false) {
      if(oLineTag) {
         if(oLineTag.getAttribute('sdBatterID',false)) {
            if(parseFloat(oLineTag.getAttribute('sdBatterID',false))!=aBatterID[strCurTeam]) {
               // Okay, the ID's don't match.  Either there's a new batter,
               // a pinch hitter, or it's the end of the inning.  We need to make sure 
               // which.
					intSkip=0;
               if(strEvent) {
                  if(EventCode(strEvent)=="PH") {
                     // It's a pinch hitter
                     var aPHData=EventData(strEvent)
                     var intOldPID,intNewPID
                     intOldPID=aPHData[1].toString()
                     intNewPID=aPHData[0].toString()
                     ReplacePlayer(strCurTeam,intOldPID,intNewPID)
                     // UpdateDueUp(strCurTeam,intNewPID)
                     
                  } else {
	                  if(EventCode(strEvent)=="LO" || EventCode(strEvent)=="IN") {
								intSkip=1;
							}
							
                  }
               }
					if(intSkip==0) {
						aBatterID[strCurTeam]=parseFloat(oLineTag.getAttribute('sdBatterID',false))
					}
            }
         }
      }
		
      // Temporary processing for replacements
      if(oLineTag) {
         if(strEvent) {
				if((EventCode(strEvent).toString()=="DR")||(EventCode(strEvent).toString()=="RP")) {
					// It's a replacement
					var aRPData=EventData(strEvent)
					if(EventCode(strEvent).toString()=="RP") {  // Special case: Put RP in #9 hole
						ReplacePlayer(strOtherTeam(),"RP",aRPData[0].toString())
					} else {
						ReplacePlayer(strOtherTeam(),aRPData[1].toString(),aRPData[0].toString())
					}
				} 
			}
		}
		
		// Temporary processing for hits and errors
		if(strDVType=="lite") {
			obj("LDHLamp").src=aImages["o-off"].src
			obj("LDELamp").src=aImages["o-off"].src
		} else {
			obj("LDHLamp").src=aImages["b-off"].src
			obj("LDELamp").src=aImages["s-off"].src
		}
		SetDMD("ENum",-1)
		if(oLineTag) {
			if(strEvent) {
				if((EventCode(strEvent)=="1B")||
					(EventCode(strEvent)=="2B")||
				(EventCode(strEvent)=="3B")||
				(EventCode(strEvent)=="HR")) {
				// It's a hit
				if(strDVType=="lite") {
					obj("LDHLamp").src=aImages["o-on"].src
				} else {
					obj("LDHLamp").src=aImages["b-on"].src
				}
				
				aTeamData[strCurTeam]["Hits"]++
				SetDMD("LineScore"+strCurTeam+"H",aTeamData[strCurTeam]["Hits"])
				}
				if(EventCode(strEvent)=="ER") {
					// It's an error
					if(strDVType=="lite") {
						obj("LDELamp").src=aImages["o-on"].src
					} else {
						obj("LDELamp").src=aImages["s-on"].src
					}
					
					aTeamData[strOtherTeam()]["Errors"]++
					SetDMD("LineScore"+strOtherTeam()+"E",aTeamData[strOtherTeam()]["Errors"])
					SetDMD("ENum",strEvent.substring(2,3))
				}
			}    
		}
	}
	
   intNodeCount++
	
	
   
   // How events are handled
   // If the event descriptor has a callback, call the callback 
   // function which will place events on the color queue, then exit the function.
   // The final color queue event will contain the object ID, which is then processed.
   // If there is no callback, process for stats immediately.
   // The original line tag will not be processed again, so any information that needs to be displayed for it must be added to the color queue.
	
   // Set seed for current play
   intSeed+=intNodeCount;
   randseed(intSeed);
	
   // Parse for ball/strike count
	
	
   // Parse events
	//   if((oLineTag)) {         
	//      if(oLineTag.getAttribute('sdEvent',false)!=null) {
	// Check for hits and errors
	//if(aEventTable
	//      }
	//   }
	
   //if((oLineTag)||(boolForceEnd=true)) {         
	
   // Update the time
   UpdateClock(1.3)  // 1 minute 18 seconds
   if(oLineTag && boolShowAll==false) {
      if(strDVMode=="basic") {         
         oLineTag.style.display=""
      }
		// Count baserunners
		// if(oLineTag.className!='NewInning'&&oLineTag.innerHTML!="END"&&boolForceEnd==false) {
		//    intOnBase=0;
		//    if(oLineTag.getAttribute('sd1B',false)!=null) {
		//       if(oLineTag.getAttribute('sd1B',false)!="") {
		//          intOnBase++
		//       }
		//    }
		//    if(oLineTag.getAttribute('sd2B',false)!=null) {
		//       if(oLineTag.getAttribute('sd2B',false)!="") {
		//          intOnBase++
		//       }
		//    }
		//    if(oLineTag.getAttribute('sd3B',false)!=null) {
		//       if(oLineTag.getAttribute('sd3B',false)!="") {
		//          intOnBase++
		//       }
		//    }
		//  }
		
      // Parse live display events
      if(boolShowAll==false) {
         if(intInningStop<intCurInning) {
            AddToPBP(oLineTag.innerHTML,oLineTag.className,true)
         } else {
            AddToPBP(oLineTag.innerHTML,oLineTag.className,false)
         }
         //obj("ColorCommentary").innerHTML="<SPAN>test</SPAN>"
         if(intInningStop<intCurInning) {
            //obj("ColorCommentary").scrollTop=obj("ColorCommentary").scrollHeight
				// Simulate lights
				//intBalls+=Math.floor(Math.random()*3)
				//intStrikes+=Math.floor(Math.random()*2)
				if(intBalls>3) intBalls=3
					if(intStrikes>3) intStrikes=2
					
					if(oLineTag.innerHTML.indexOf(" walks.")>0) {
						// It's a walk!
						intBalls=4
					}
					if(oLineTag.innerHTML.indexOf(" strikes out.")>0) {
						// It's a strikeout!
						intStrikes=3
					}
					if(oLineTag.innerHTML.indexOf(" now 2 strikes")>0) {
						intStrikes=2
					}
					
					UpdateLights("S",intStrikes)
					UpdateLights("B",intBalls)
					
					
					if(oLineTag.getAttribute('sdPitcher',false)!=null) {
						obj("dvPitcherLink").innerHTML=oLineTag.getAttribute('sdPitcher',false)
						SetPStats(parseFloat(oLineTag.getAttribute('sdPitcherID',false)))
					}
					if(oLineTag.getAttribute('sdBatter',false)!=null) {
						strSetBatter=oLineTag.getAttribute('sdBatter',false)
						oBatterLineTag=oLineTag
						oBatterTimer=setTimeout('SetBatterInfo()',intInterval/2.5)
					}
					if(oLineTag.getAttribute('sdOuts',false)!=null) {
						UpdateLights('O',oLineTag.getAttribute('sdOuts',false));
						intOuts=oLineTag.getAttribute('sdOuts',false)
					}
					if(oLineTag.getAttribute('sd1B',false)!=null) {
						if(oLineTag.getAttribute('sd1B',false)=="") {
							SetBase("1B","Off","","")
						} else {
							SetBase("1B","On",innerHTML=oLineTag.getAttribute('sd1B',false),"")
						}
					}
					if(oLineTag.getAttribute('sd2B',false)!=null) {
						if(oLineTag.getAttribute('sd2B',false)=="") {
							SetBase("2B","Off","","")
						} else {
							SetBase("2B","On",innerHTML=oLineTag.getAttribute('sd2B',false),"")
						}
					}
					if(oLineTag.getAttribute('sd3B',false)!=null) {
						if(oLineTag.getAttribute('sd3B',false)=="") {
							SetBase("3B","Off")
						} else {
							SetBase("3B","On",innerHTML=oLineTag.getAttribute('sd3B',false),"")
						}
					}
         }
      }
      if(oLineTag.className=='score') {
			
         // A run was scored
         intInnScore++;
         SetLineScore(strCurTeam,intCurInning,intInnScore)
         aTeamData[strCurTeam]["Runs"]++
         SetDMD("Score"+strCurTeam,aTeamData[strCurTeam]["Runs"])
         SetDMD("LineScore"+strCurTeam+"R",aTeamData[strCurTeam]["Runs"])
      }
      
      if(oLineTag.className=='NewInning') {
         // Inning's over!
         UpdateDueUp(null,null)
         
         // Insert LOB text
         // if(intInningHalf>4) {
         //   AddLOBText()
         // }
			
         strCurTeam=strOtherTeam()
         if(strCurTeam=="V") {
            intCurInning++
            SetDMD("Inning",intCurInning)
            if(intInningStop>1) {
               if(intCurInning>=intInningStop) {
                  intGameOver=intCurInning
                  SetStatus(null)
               }
            }
         }
         if(intInningStop<intCurInning) {
            UpdateDueUp(strCurTeam,aBatterID[strCurTeam])
         }
         
         intInnScore=0
         intOuts=0
         if(intInningStop<=intCurInning&&boolForceEnd==false&&boolShowAll==false) {
            //obj("dvOffTeamLogo").src=aImages["logo"+strCurTeam].src
            //obj("dvDefTeamLogo").src=aImages["logo"+strOtherTeam()].src
            SetBase("1B","Off","","")
            SetBase("2B","Off","","")
            SetBase("3B","Off","","")
            UpdateLights("S",0)
            UpdateLights("B",0)
            UpdateLights("O",0)
            if(strDVType=="lite") {
               obj("LDTeamUp"+strCurTeam).src=aImages["o-on"].src
               obj("LDTeamUp"+strOtherTeam()).src=aImages["o-off"].src
            } else {
               obj("LDTeamUp"+strCurTeam).src=aImages["b-on"].src
               obj("LDTeamUp"+strOtherTeam()).src=aImages["b-off"].src
            }
            if(intDVFaces==0) {
            	// Set logos
            	if(strCurTeam=="H") {
						obj("dvDefTeamLogo").style.backgroundImage="url(" + aImages["logoV"].src + ")";
						obj("dvOffTeamLogo").style.backgroundImage="url(" + aImages["logoH"].src + ")";
					} else {
						obj("dvDefTeamLogo").style.backgroundImage="url(" + aImages["logoH"].src + ")";
						obj("dvOffTeamLogo").style.backgroundImage="url(" + aImages["logoV"].src + ")";
					}
            }
            SetFielders(strOtherTeam())
         }
			
         intInningHalf++
         // Hide previous half innings
         if(boolShowAll==false) {
            if(strDVMode=="basic") {
               if(arLineObjects[intInningHalf-3]) {
                  for(var intHideIndex=0; intHideIndex<arLineObjects[intInningHalf-3].length; intHideIndex++) {
                     if(arLineObjects[intInningHalf-3][intHideIndex]) {
								arLineObjects[intInningHalf-3][intHideIndex].style.display="none"
                     }
						}
               }
            }
            if((intCurInning>9)&&(strCurTeam=="V")) {
               // Shift line score display if we are in extra innings
               for(var intIndex=1;intIndex<9;intIndex++) {
                  if(strDVType!="normal") {
                     obj("LDSBLineScoreHead"+intIndex.toString()).innerHTML=obj("LDSBLineScoreHead"+(intIndex+1).toString()).innerHTML
                     obj("LDSBLineScoreV"+intIndex.toString()).innerHTML=obj("LDSBLineScoreV"+(intIndex+1).toString()).innerHTML
                     obj("LDSBLineScoreH"+intIndex.toString()).innerHTML=obj("LDSBLineScoreH"+(intIndex+1).toString()).innerHTML
                  } else {
                     obj("LDSBLineScoreHead"+intIndex.toString()+"Ones").src=obj("LDSBLineScoreHead"+(intIndex+1).toString()+"Ones").src
                     obj("LDSBLineScoreHead"+intIndex.toString()+"Tens").src=obj("LDSBLineScoreHead"+(intIndex+1).toString()+"Tens").src
                     obj("LDSBLineScoreV"+intIndex.toString()+"Ones").src=obj("LDSBLineScoreV"+(intIndex+1).toString()+"Ones").src
                     obj("LDSBLineScoreV"+intIndex.toString()+"Tens").src=obj("LDSBLineScoreV"+(intIndex+1).toString()+"Tens").src
                     obj("LDSBLineScoreH"+intIndex.toString()+"Ones").src=obj("LDSBLineScoreH"+(intIndex+1).toString()+"Ones").src
                     obj("LDSBLineScoreH"+intIndex.toString()+"Tens").src=obj("LDSBLineScoreH"+(intIndex+1).toString()+"Tens").src
                  }
               }
               SetDMD("LineScoreHead9",intCurInning)
               SetDMD("LineScoreV9",-1)
               SetDMD("LineScoreH9",-1)
            }
            SetLineScore(strCurTeam,intCurInning,0)
         }
      }
      if(arLineObjects) {
         if(arLineObjects[intInningHalf]) {
            arLineObjects[intInningHalf][arLineObjects[intInningHalf].length]=oLineTag
         } else {
            arLineObjects[intInningHalf]=new Array
            arLineObjects[intInningHalf][0]=oLineTag
         }
      }
		
   } else {
      intGameOver=1
      boolComplete=true
      // AddLOBText()
      // AddTotalLOBText()
      AddToPBP("<b>END OF GAME</b>","intro",true)      
      
      for(intIndex=0;intIndex<aLineIndex.length;intIndex++) {
			aLineIndex[intIndex].style.display=""
      }
		
      // for(var intHalfInningIndex=0;intHalfInningIndex<arLineObjects.length;intHalfInningIndex++) {
      //   if(arLineObjects[intHalfInningIndex]) {
      //      for(var intHideIndex=0;intHideIndex<arLineObjects[intHalfInningIndex].length;intHideIndex++) {
      //         if(arLineObjects[intHalfInningIndex][intHideIndex]) {
      //            arLineObjects[intHalfInningIndex][intHideIndex].style.display=""
      //         }
      //      }
      //   }
      //}
      
      // Hide DynastyVision, unhide box score and line score
      //alert("About to unhide")
      //oRecapWindow.parentElement.style.display=""
      oRecapParent.style.display=""
      obj("LineScoreTable").style.display='block'
      obj("ShowAllLink").style.display='none'
      if(boolShowAll==true) {
			obj("BoxScores").style.display='block'
			obj("LiveDisplay").style.display='none'
			obj("imageload").style.display='none'
      } else {
         obj("DVToggle").style.display='block'
      }
      
      // Unhide line score elements for backward compatibility
      obj("HitsHead").style.visibility='visible'
      obj("ErrorsHead").style.visibility='visible'
      obj("InnHRuns").style.visibility='visible'
      obj("InnVRuns").style.visibility='visible'
      obj("InnHHits").style.visibility='visible'
      obj("InnHErrs").style.visibility='visible'
      obj("InnVHits").style.visibility='visible'
      obj("InnVErrs").style.visibility='visible'
      obj("WinningPitcher").style.visibility='visible'
      for(intIndex=1;;intIndex++) {
         if(!obj("InnV"+intIndex.toString()))
            break;
         if(intIndex<=9) {
				if(obj("InnV"+intIndex)) { 
					obj("InnV"+intIndex.toString()).style.visibility='visible'
				}
				if(obj("InnH"+intIndex)) {  // May not be a score in the 9th for H
					obj("InnH"+intIndex.toString()).style.visibility='visible'
				}
         } else {
            obj("InnV"+intIndex.toString()).style.display=''
            obj("InnH"+intIndex.toString()).style.display=''
            obj("InnHead"+intIndex.toString()).style.display=''
         }
      }
   }
	
   return(intGameOver)
}

function DVToggle()
{
   if(obj("BoxScores").style.display=='block') {
      obj("BoxScores").style.display='none'
      obj("LiveDisplay").style.display='block'
      obj("DVToggle").innerHTML='Show Box Score'
      
   } else {
      obj("BoxScores").style.display='block'
      obj("LiveDisplay").style.display='none'
      obj("DVToggle").innerHTML='Show DynastyVision'
   }   
}

function SetFielders(strTeamChar)
{
   var strTeam
   strTeam=strTeamChar
   if(strDVType=="lite") {
      strTeam="V"
   }
   for(var intIndex=1;intIndex<=9;intIndex++) {
      obj("dvImg"+aPositions[intIndex]).src=aImages["player"+strTeam+"R"].src
      obj("dvImg"+aPositions[intIndex]).title=aPositions[intIndex]+": Unknown"
      obj("dvField"+aPositions[intIndex]).href="#"
   }
   for(var intIndex=1;intIndex<=9;intIndex++) {
      if(playerinfo(aLineup[strTeam][intIndex],"pPos")) {
			switch(playerinfo(aLineup[strTeam][intIndex],"pPos")) {
			case 1:
				obj("dvImgP").src=aImages["pitcher"+strTeam+playerinfo(aLineup[strTeam][intIndex],"pThrows")].src;
				break;	
			case 2:
				obj("dvImgC").src=aImages["catcher"+strTeam].src
				break;	
			default:
				obj("dvImg"+aPositions[playerinfo(aLineup[strTeam][intIndex],"pPos")]).src=aImages["player"+strTeam+playerinfo(aLineup[strTeam][intIndex],"pThrows")].src
         }
         obj("dvImg"+aPositions[playerinfo(aLineup[strTeam][intIndex],"pPos")]).title=aPositions[playerinfo(aLineup[strTeam][intIndex],"pPos")]+": "+playerinfo(aLineup[strTeam][intIndex],"pName")
         obj("dvField"+aPositions[playerinfo(aLineup[strTeam][intIndex],"pPos")]).href="player.jsp?id="+playerinfo(aLineup[strTeam][intIndex],"pID")
      }
   }
}

function SetBase(strBase, strState, strRunner, strRunnerID)
{
   var strBaseID
   var intRunnerID
   var strTeam
   
   if(strDVType=="lite") {
      strTeam="H"
   } else {
      strTeam=strCurTeam   
   }
   
   
   if((!strRunnerID)||(strRunnerID=="")) {
      // Try to find ID
      if(aPlayerNameIndex[strCurTeam][strRunner]>=0) {
         intRunnerID=aPlayerData[aPlayerNameIndex[strCurTeam][strRunner]]["pID"]
      } 
   } else {
      intRunnerID=parseFloat(strRunnerID)
   }
   strBaseID="dvImgRun"+strBase
   if(strState=="Off") {
      obj(strBaseID).src=aImages["playerblank"].src
      obj(strBaseID).title=""
      obj("LDOn"+strBase).innerHTML="&nbsp;"
      obj("LDOn"+strBase).href="#"
      obj("dvFieldRunner"+strBase).href="#"
      obj("LDStolenBases"+strBase).innerHTML="&nbsp;&nbsp;" 
      obj("LDCaughtStealing"+strBase).innerHTML="&nbsp;&nbsp;"
   } else {
      obj(strBaseID).src=aImages["runner"+strTeam].src
      obj(strBaseID).title=strRunner
      obj("LDOn"+strBase).innerHTML=strRunner
      if(intRunnerID){
         obj("LDOn"+strBase).href="player.jsp?id="+intRunnerID.toString()
         obj("dvFieldRunner"+strBase).href="player.jsp?id="+intRunnerID.toString()
         if(playerinfo(intRunnerID,"pSB")>=0) {
            obj("LDStolenBases"+strBase).innerHTML=playerinfo(intRunnerID,"pSB")
         } else {
            obj("LDStolenBases"+strBase).innerHTML="&nbsp;&nbsp;" 
         }
         if(playerinfo(intRunnerID,"pCS")>=0) {
            obj("LDCaughtStealing"+strBase).innerHTML=playerinfo(intRunnerID,"pCS")
         } else {
            obj("LDCaughtStealing"+strBase).innerHTML="&nbsp;&nbsp;" 
         }
      } else {
         obj("LDOn"+strBase).href="#"
         obj("dvFieldRunner"+strBase).href="#"
         obj("LDStolenBases"+strBase).innerHTML="&nbsp;&nbsp;"
         obj("LDCaughtStealing"+strBase).innerHTML="&nbsp;&nbsp;"
      }
   }
}

function SetBatterInfo()
{
   var strHand
   var intBatterID
   var strTeam
   if(strDVType=="lite") {
      strTeam="H"
   } else {
      strTeam=strCurTeam   
   }
   
	//   if(strSetBatter!=strOldBatter) {
	//      arLastAtBat[strOldBatter]=oBatterLineTag.innerHTML
	//      strOldBatter=strSetBatter
	//   }
	//   if(strSetBatter=="") {
	//      window.document.getElementById("LDLastAB").innerHTML="&nbsp;"
	//   } else {
	//      if(arLastAtBat[strSetBatter]) {
	//         window.document.getElementById("LDLastAB").innerHTML=arLastAtBat[strSetBatter]
	//      } else {
	//         window.document.getElementById("LDLastAB").innerHTML="&nbsp;"
	//      }
	//   }
   clearTimeout(oBatterTimer);
   oBatterTimer=null;
   ClearBatterImage()
   intBatterID=oBatterLineTag.getAttribute('sdBatterID',false)
   if(intBatterID>0) {
      strHand=playerinfo(intBatterID,"pBats")
      if(strHand=="B") {
         // Switch hitter: go to opposite of pitcher's hand
         strHand="L"
         if(playerinfo(aLineup[strOtherTeam()][9],"pThrows")) {
            if(playerinfo(aLineup[strOtherTeam()][9],"pThrows")=="L") {
               strHand="R"
            }
         }
      }
      if(strHand) {
      } else {
         strHand="R"
      }
      obj("dvImgBatter"+strHand).src=aImages["batter"+strTeam+strHand].src
      obj("dvImgBatter"+strHand).title=playerinfo(intBatterID,"pName")
      obj("dvFieldBatter"+strHand).href="player.jsp?id="+intBatterID.toString()
   }
   obj("dvBatterLink").innerHTML=strSetBatter   
   SetBStats(intBatterID)

   // Update due up display
   UpdateDueUp(strCurTeam,parseFloat(oLineTag.getAttribute('sdBatterID',false)))
	
   intStrikes=0
   intBalls=0
   UpdateLights("S",0)
   UpdateLights("B",0)
   if(strDVType=="lite") {
      obj("LDHLamp").src=aImages["o-off"].src
      obj("LDELamp").src=aImages["o-off"].src
   } else {
      obj("LDHLamp").src=aImages["b-off"].src
      obj("LDELamp").src=aImages["s-off"].src
   }
   SetDMD("ENum",-1)
}
function ClearBatterImage()
{
   obj("dvImgBatterL").src=aImages["playerblank"].src
   obj("dvImgBatterR").src=aImages["playerblank"].src
   obj("dvImgBatterL").title=""
   obj("dvImgBatterR").title=""
   obj("dvFieldBatterL").href="#"
   obj("dvFieldBatterR").href="#"
}

function UpdateLights(strTypeChar,intValue)
{
   // type is S for strike, B for ball, O for out
   var upperbound
   var intLampIndex
   var strType
   if(strDVType=="lite") {
      strType="o"
   } else {
      strType=strTypeChar
   }
   upperbound=3
   if(strTypeChar=="B")
      upperbound=4
   for(intLampIndex=1;intLampIndex<=upperbound;intLampIndex++) {
      if(obj("LD"+strTypeChar+intLampIndex.toString())) {
         if(intValue>=intLampIndex) {
            obj("LD"+strTypeChar+intLampIndex.toString()).src=aImages[strType.toLowerCase()+"-on"].src
         }	else {
            obj("LD"+strTypeChar+intLampIndex.toString()).src=aImages[strType.toLowerCase()+"-off"].src
         }
      } else {
         alert("Light not found! Type="+strType+", value="+intLampIndex)
      }
   }
}

function AddLOBText()
{
   oLastLineTag.innerHTML=oLastLineTag.innerHTML+"<span><b>Runners left on base: "+intOnBase.toString()+"</b><br /><br /></span>"
   // obj("ColorCommentary").innerHTML+="<p class='cclob'>Runners left on base: "+intOnBase.toString()+"</p>"
   aTeamData[strCurTeam]["LOB"]+=intOnBase
}

function AddTotalLOBText()
{
   oLastLineTag.innerHTML=oLastLineTag.innerHTML+"<span><b>"+aTeamData["V"]["TeamCity"]+" total runners left on base: "+aTeamData["V"]["LOB"].toString()+"</b><br />"
   oLastLineTag.innerHTML=oLastLineTag.innerHTML+"<span><b>"+aTeamData["H"]["TeamCity"]+" total runners left on base: "+aTeamData["H"]["LOB"].toString()+"</b></span>"
}

//===================================================================================
// Control bar control functions
//    CBDown(strButton)
//       Sets the "pushed in" image
//    CBUp(strButton)
//       Sets the "pushed out" image and executes the function
//    CBOff(strButton)
//       Sets the "pushed out" image without executing the function
//===================================================================================

function CBDown(strButton)
{
   obj("CB"+strButton).src=aImages["cb-"+strButton+"-dn"].src
   if(strButton=="color" || strButton=="count") {
      obj("CB"+strButton+"spacer").src=aImages["cb-lspacer-dn"].src
      obj("CB"+strButton+"light").src=aImages["cb-light"+eval("bool"+strButton)+"-dn"].src
   }
}

function CBOff(strButton)
{
   obj("CB"+strButton).src=aImages["cb-"+strButton].src
   if(strButton=="color" || strButton=="count") {
      obj("CB"+strButton+"spacer").src=aImages["cb-lspacer"].src
      obj("CB"+strButton+"light").src=aImages["cb-light"+eval("bool"+strButton)].src
   }
   if(!oTimer) {
      obj("CBpause").src=aImages["cb-pause-dn"].src
   }   
}

function CBUp(strButton)
{
   if(strButton=="faster") {
      faster()
   }
   if(strButton=="slower") {
      slower()
   }
   if(strButton=="end") {
      ShowAll(0)
   }
   if(strButton=="pause") {
      pause()
   }     
   CBOff(strButton)
   if(strButton=="color" || strButton=="count") {
      if(eval("bool"+strButton)=="off") {
         if(strButton=="color") {
            boolcolor="on"
         } else {
            boolcount="on"
         }
      } else {
         if(strButton=="color") {
            boolcolor="off"
         } else {
            boolcount="off"
         }
      }
      obj("CB"+strButton+"light").src=aImages["cb-light"+eval("bool"+strButton)].src
      SaveDVPrefs()
   }
}

function faster() 
{
   if(intSpeed<aSpeedInterval.length-1) {
      intSpeed++
      setspeed(intSpeed)
      if(oTimer) {
         clearTimeout(oTimer)
         oTimer=null
      }
      if(oRecapWindow) {
			obj("CBpause").src=aImages["cb-pause"].src
         AdvanceGame()
      }
   }
}

function slower()
{
   if(intSpeed>0) {
      intSpeed--
      setspeed(intSpeed)
   }
}

function setspeed(intNewSpeed)
{
   intSpeed=intNewSpeed;
   intInterval=aSpeedInterval[intSpeed];
   UpdateSpeedLights();
   SaveDVPrefs();
}

function UpdateSpeedLights()
{
   for(var intIndex=1;intIndex<=9;intIndex++) {
      obj("CBSpeedLight"+intIndex.toString()).title="Current speed "+intSpeed.toString()+"; click to set speed to "+intIndex.toString();
      if(intIndex<=intSpeed) {
         obj("CBSpeedLight"+intIndex).src=aImages["cb-lighton"].src;
      } else {
         obj("CBSpeedLight"+intIndex).src=aImages["cb-lightoff"].src;
      }
   }
}

function SaveDVPrefs()
{
   var exp = new Date();
   exp.setTime(exp.getTime()+10368000000); // Cookie expires in 120 days
   //if(intSpeed<8) {  // Don't save speeds higher than 7
   document.cookie = "dv-speed=" + intSpeed + "; expires=" + exp.toGMTString();
   //}
   document.cookie = "dv-color=" + boolcolor + "; expires=" + exp.toGMTString(); 
   document.cookie = "dv-count=" + boolcount + "; expires=" + exp.toGMTString(); 
}

function LoadDVPrefs() 
{
	var aCookie = document.cookie.split("; ");
	for (var i=0; i < aCookie.length; i++) {
		var aCrumb = aCookie[i].split("=");
		if (aCrumb[0]=="dv-speed") 
			intSpeed=aCrumb[1];
		if (aCrumb[0]=="dv-color") 
			boolcolor=aCrumb[1];
		if (aCrumb[0]=="dv-count") 
			boolcount=aCrumb[1];
	}
}
//===================================================================================
// Color queue functions
//===================================================================================

function ProcessColorQueue()
{
   // Pop the bottom item off the queue and dispatch any events
   AddToPBP(aColorQueue[intColorQueueHead]["Text"],aColorQueue[intIndex]["Class"],true)
   if(aColorQueue[intColorQueueHead]["Event"]) {
      if(aColorQueue[intColorQueueHead]["Event"]!="") {
         RegisterEvent(aColorQueue[intColorQueueHead]["Event"],aColorQueue[intColorQueueHead]["Object"])
      }
   }
   intColorQueueHead++
   if(intColorQueueHead>=intColorQueueSize) {
      intColorQueueHead=0
   }
}

function AddColorQueue(strText,strClass,strEvent,oObject)
{
   if(strText) {
      aColorQueue[intColorQueueTail]["Text"]=strText
   } else {
      aColorQueue[intColorQueueTail]["Text"]=""
   }   
   if(strClass) {
      aColorQueue[intColorQueueTail]["Class"]=strClass
   } else {
      aColorQueue[intColorQueueTail]["Class"]=""
   }
   if(strEvent) {
      aColorQueue[intColorQueueTail]["Event"]=strEvent
   } else {
      aColorQueue[intColorQueueTail]["Event"]=""
   }
   if(oObject) {
      aColorQueue[intColorQueueTail]["Object"]=oObject
   } else {
      aColorQueue[intColorQueueTail]["Object"]=null
   }
   intColorQueueTail++
   if(intColorQueueTail>=intColorQueueSize) {
      intColorQueueTail=0
   }
}

function AddToPBP(strText,strClass,boolScroll)
{
   var strTextBuf
   if(strDVMode=="basic") {
      return;
   }
   
   if(boolUseBuffer) {
      strTextBuf="<span"
		
      if(strClass) {
         if(strClass!="") {
            strTextBuf+=" class='cc"+strClass+"'"
         }
      }
      strTextBuf+=">"+strText+"</span><br />"
      for(var intIndex=0;intIndex<intCCBufferSize-1;intIndex++) {
         aCCBuffer[intIndex]=aCCBuffer[intIndex+1]
      }
      aCCBuffer[intCCBufferSize-1]=strTextBuf
      strTextBuf=""
      for(var intIndex=0;intIndex<intCCBufferSize;intIndex++) {
         strTextBuf+=aCCBuffer[intIndex]
      }      
      obj("ColorCommentary").innerHTML=strTextBuf
   } else {
      strTextBuf="<p"
		
      if(strClass) {
         if(strClass!="") {
            strTextBuf+=" class='cc"+strClass+"'"
         }
      }
      strTextBuf+=">"+strText+"</p>"
      if(strDVMode=="full") {
         obj("ColorCommentary").innerHTML+=strTextBuf
         if(boolScroll) {
            obj("ColorCommentary").scrollTop=obj("ColorCommentary").scrollHeight
         }
      }
   }
}

function RegisterEvent(strEvent,oObject)
{
	// Updates stats and display for event
}
function ColorEvent(strEvent,oObject)
{
	// Creates color queue entries for event
	if(strEvent=="" || boolcolor=="off") {
		// If color commentary is off or there is no event, just add object to queue and exit
		AddColorQueue(oObject.innerHTML,oObject.className,oObject.getAttribute('sdEvent',false),oObject)
		return(0);
	}
	// We need to process events
	
}

//===================================================================================
// SetDMD(strField, intValue)
//    Sets the scoreboard dot-matrix displays to a two-digit value
//    If value is negative, blank the display
//===================================================================================

function SetDMD(strField, intValue)
{
   if(boolShowAll==false) {
      if(strDVType=="lite") {
         if(obj("LDSB"+strField)) {
            if(intValue<0) {
               obj("LDSB"+strField).innerHTML = "&nbsp;&nbsp;"
            } else {
               if(intValue<10) {
                  obj("LDSB"+strField).innerHTML = "&nbsp;"+intValue
               } else {
                  obj("LDSB"+strField).innerHTML = intValue
               }
            }
         }
      } else {
         if(intValue<0) {
            obj("LDSB"+strField+"Ones").src = aImages["nd-blank"].src
            if(obj("LDSB"+strField+"Tens")) {
               obj("LDSB"+strField+"Tens").width = 4
               obj("LDSB"+strField+"Tens").src = aImages["nd-blankh"].src
            }
         } else {
            var strValue=intValue.toString()
            obj("LDSB"+strField+"Ones").src = aImages["nd-"+strValue.substring(strValue.length-1,strValue.length)].src
            if(obj("LDSB"+strField+"Tens")) {
               if(strValue.length>1) {
                  if(strValue.substring(strValue.length-2,strValue.length-1)=="1") {
                     obj("LDSB"+strField+"Tens").width = 4
                     obj("LDSB"+strField+"Tens").src = aImages["nd-1h"].src
                  } else {
                     obj("LDSB"+strField+"Tens").width = 10
                     obj("LDSB"+strField+"Tens").src = aImages["nd-"+strValue.substring(strValue.length-2,strValue.length-1)].src
                  }
               } else {
                  obj("LDSB"+strField+"Tens").width = 4
                  obj("LDSB"+strField+"Tens").src=aImages["nd-blankh"].src
               }
            }
         }
      }
   }
}

function FindPlayer(strPlayer,strTeam)
{
   // This function is likely temporary.
   // Find a player database record based on player name and team (H or V).
   // Returns database index, or -1 if not found
	
   var intInd;
	
   for(intInd=0;intInd<=50;intInd++) {
		// Search for player in database
      if(aPlayerData[intInd]!=null) {
         if(aPlayerData[intInd]["pName"]!=null) {
            if(aPlayerData[intInd]["pName"]==strPlayer /* && aPlayerData[intInd]["pTeam"]==strTeam */) {  
               // We have a match
               return(intInd);                  
            }  
         }
      }
   }
   return(-1);
}

function UpdateDueUp(strTeam,intBatterID)
{
   var intIndex
   var intBO=0
   var boolBlank=true
   var intPlayerID
   
   if(intDataBlockVer>=2) { // Minimum supported data block version
      if(strTeam) {
         if(intBatterID) {
            intBO=FindInLineup(strTeam,intBatterID)
         }
         if(intBO>0) {
            boolBlank=false
            obj("DueUpCityID").innerHTML="&nbsp;FOR "+aTeamData[strTeam]["TeamCityCode"].toUpperCase()
            for(intIndex=1;intIndex<4;intIndex++) {
               intBO++
               if(intBO>9) {
                  intBO=1
               }
               if(aLineup[strTeam][intBO]) {
                  intPlayerID=aLineup[strTeam][intBO]
                  obj("DueUpBO"+intIndex.toString()).innerHTML=intBO.toString()
                  if(aPositions[playerinfo(intPlayerID,"pPos")]) {
                     obj("DueUpPos"+intIndex.toString()).innerHTML=aPositions[playerinfo(intPlayerID,"pPos")]
                  }
                  if(playerinfo(intPlayerID,"pName")) {
                     obj("DueUp"+intIndex.toString()).innerHTML=playerinfo(intPlayerID,"pName")
                  }
                  obj("DueUp"+intIndex.toString()).href="player.jsp?id="+intPlayerID.toString()
                  obj("DueUpAvg"+intIndex.toString()).innerHTML=GetBattingAvg(intPlayerID)
               }
            }
         } 
      }
   }
   if(boolBlank==true) {
      obj("DueUpCityID").innerHTML="&nbsp;"
		
      for(intIndex=1;intIndex<4;intIndex++) {
         obj("DueUpBO"+intIndex.toString()).innerHTML="&nbsp;"
         obj("DueUpPos"+intIndex.toString()).innerHTML="&nbsp;"
         obj("DueUp"+intIndex.toString()).innerHTML="&nbsp;"
         obj("DueUp"+intIndex.toString()).href="#"
         obj("DueUpAvg"+intIndex.toString()).innerHTML="&nbsp;"
      }
   }
}

function FindInLineup(strTeam,strBatterID)
{
   var intIndex
   var intBO=0
   
   if(intDataBlockVer>=2) { // Minimum supported data block version
      if(strTeam) {
         if(strBatterID) {
            // Find current batting order
            for(intIndex=1;intIndex<10;intIndex++) {
               if(aLineup[strTeam][intIndex]==strBatterID.toString()) {
                  intBO=intIndex
                  intIndex+=9
               }
            }
         }
      }
   }
   return(intBO)
}

function ReplacePlayer(strTeam,strOldPlayerID,strNewPlayerID)
{
   var intBO
   
   if(strOldPlayerID=="RP") {
      // Special case for relief pitcher - just put him in #9 hole
      aLineup[strTeam][9]=strNewPlayerID
      SetFielders(strTeam)
   } else {
      intBO=FindInLineup(strTeam,strOldPlayerID)
      if(intBO>0) {
         aLineup[strTeam][intBO]=strNewPlayerID
         if(strTeam!=strCurTeam) {
            SetFielders(strTeam)
         }
      } else {
         // alert("Cannot replace player "+intOldPlayerID+" with "+intNewPlayerID)
      }
   } 
}
function SetBStats(intPlayerID)
{
   // Sets batter statistics based on player database ID.
   // If intPlayerDB is -1 or not found, blanks stats.
   //
   // This function also sets the link target for the player's name, but does NOT set the player's name.
	
   var strAvg
   var intABBuf
   var intHitsBuf
   var intAvgBuf
   var intPlayerDB
   
   if(intPlayerID) {
      if(aPlayerIndex[intPlayerID.toString()]>=0) {
         intPlayerDB=aPlayerIndex[intPlayerID.toString()]
      }
   }
	
   obj("dvBatterLink").href="#"
   //obj("dvAB").innerHTML="&nbsp;"
   obj("dvHits").innerHTML="&nbsp;"
   obj("dvHR").innerHTML="&nbsp;"
   obj("dvSB").innerHTML="&nbsp;"
   obj("dvBB").innerHTML="&nbsp;"
   obj("dvAVG").innerHTML="&nbsp;"
   obj("dvRBI").innerHTML="&nbsp;"
   obj("dvBGames").innerHTML="&nbsp;"
   if(aPlayerData) {
      if(aPlayerData[intPlayerDB]>=0){  // Check for a valid object
         obj("dvBatterLink").href="player.jsp?id="+aPlayerData[intPlayerDB]["pID"]
         //obj("dvAB").innerHTML=aPlayerData[intPlayerDB]["pAB"]
         obj("dvBGames").innerHTML=aPlayerData[intPlayerDB]["pBGames"]
         obj("dvHits").innerHTML=aPlayerData[intPlayerDB]["pHits"]
         obj("dvHR").innerHTML=aPlayerData[intPlayerDB]["pHR"]
         obj("dvSB").innerHTML=aPlayerData[intPlayerDB]["pSB"]
         obj("dvRBI").innerHTML=aPlayerData[intPlayerDB]["pRBI"]
         obj("dvBB").innerHTML=aPlayerData[intPlayerDB]["pBB"]
         obj("dvAVG").innerHTML=GetBattingAvg(aPlayerData[intPlayerDB]["pID"])
			if(aPlayerData[intPlayerDB]["iFace"]) {
				//obj("dvOffTeamLogo").src=aPlayerData[intPlayerDB]["iFace"].src;
				obj("dvOffTeamLogo").style.backgroundImage="url(" + aPlayerData[intPlayerDB]["iFace"].src + ")";
				if(boolUseJspFaces==false) {
					obj("dvOffTeamCap").src=aImages["cap"+aPlayerData[intPlayerDB]["pTeam"]].src;
					obj("dvOffTeamCap").style.display="";
				}
			} else {
				if(aPlayerData[intPlayerDB]["pID"]) {
					if(aPlayerData[intPlayerDB]["pID"]>0) {
						obj("dvOffTeamCap").style.display="none";
						obj("dvOffTeamLogo").src=aImages["logo"+aPlayerData[intPlayerDB]["pTeam"]].src;
					}
				}
			}
      } else {
			//obj("dvOffTeamLogo").src=aImages["logo"+strCurTeam].src
		}
   } else {
		//obj("dvOffTeamLogo").src=aImages["logo"+strCurTeam].src
	}
}

function GetBattingAvg(intPlayerID)
{
   var strAvg
   var intABBuf
   var intHitsBuf
   var intAvgBuf
   var intPlayerDB
   var strTmp
   
   strAvg="---"
   if(aPlayerIndex[intPlayerID.toString()]>=0) {
      intPlayerDB=aPlayerIndex[intPlayerID.toString()]
   } else {
      return("&nbsp;")
   }
   
	
   if(aPlayerData[intPlayerDB]>=0){  // Check for a valid object
      intABBuf=parseInt(aPlayerData[intPlayerDB]["pAB"])
      intHitsBuf=parseInt(aPlayerData[intPlayerDB]["pHits"])
      if(intABBuf>1) {
         if(intABBuf==intHitsBuf) {
				strAvg="1.000"
         } else {
            strTmp=Math.round((intHitsBuf*1000)/intABBuf).toString()
            strAvg="."
            for(var intIndex=0;intIndex<(3-strTmp.length);intIndex++) {
               strAvg+="0"
            }
            strAvg+=strTmp
         }
      }
   }
   return(strAvg)
}



function SetPStats(intPlayerID)
{
   // Sets pitcher statistics based on player database ID.
   // If intPlayerDB is -1 or not found, blanks stats.
   //
   // This function also sets the link target for the player's name, but does NOT set the player's name.
	
   var strERA
   var intIPBuf
   var intERBuf
   var intERABuf
   var strIP   
   var intPlayerDB
   
   obj("dvPitcherLink").href="#"
   obj("dvWins").innerHTML="&nbsp;"
   obj("dvLosses").innerHTML="&nbsp;"
   obj("dvSaves").innerHTML="&nbsp;"
   obj("dvIP").innerHTML="&nbsp;"
   obj("dvPGames").innerHTML="&nbsp;"
   obj("dvK").innerHTML="&nbsp;"
   // obj("dvER").innerHTML="&nbsp;"
   obj("dvERA").innerHTML="&nbsp;"
   if(aPlayerIndex[intPlayerID.toString()]>=0) {
      intPlayerDB=aPlayerIndex[intPlayerID.toString()]
      if(aPlayerData[intPlayerDB]>=0){  // Check for a valid object
         obj("dvPitcherLink").href="player.jsp?id="+aPlayerData[intPlayerDB]["pID"]
         obj("dvWins").innerHTML=aPlayerData[intPlayerDB]["pWins"]
         obj("dvLosses").innerHTML=aPlayerData[intPlayerDB]["pLosses"]
         obj("dvSaves").innerHTML=aPlayerData[intPlayerDB]["pSaves"]
         obj("dvIP").innerHTML=aPlayerData[intPlayerDB]["pIP"]
         obj("dvPGames").innerHTML=aPlayerData[intPlayerDB]["pPGames"]
         obj("dvK").innerHTML=aPlayerData[intPlayerDB]["pPSO"]
			if(aPlayerData[intPlayerDB]["iFace"]) {
				// obj("dvDefTeamLogo").src=aPlayerData[intPlayerDB]["iFace"].src;
				obj("dvDefTeamLogo").style.backgroundImage="url(" + aPlayerData[intPlayerDB]["iFace"].src + ")";
				if(boolUseJspFaces==false) {
					obj("dvDefTeamCap").src=aImages["cap"+aPlayerData[intPlayerDB]["pTeam"]].src;
					obj("dvDefTeamCap").style.display="";
				}
			} else {
				obj("dvDefTeamLogo").src=aImages["logo"+aPlayerData[intPlayerDB]["pTeam"]].src
				obj("dvDefTeamCap").style.display="none";
			}
			
         //obj("dvER").innerHTML=aPlayerData[intPlayerDB]["pER"]
         // We need to convert partial innings to proper values, i.e. 3.1 innings becomes 3.33 innings
			
         intIPBuf=Math.floor(aPlayerData[intPlayerDB]["pIP"]);
         intIPBuf=intIPBuf + (((aPlayerData[intPlayerDB]["pIP"]) % 1) * 3.33333);
			intERABuf = (parseInt(aPlayerData[intPlayerDB]["pER"])  * 9.0) / (1.0 * intIPBuf);
			intERABuf = (Math.round(intERABuf*100))/100;
         if(intERBuf>0) {
            strERA="99.99"
         } else {
            strERA="---"
         }
         if(intIPBuf>0) {
				strERA = intERABuf.toString();
				if(intERABuf % 1 == 0) { strERA = strERA + ".00"; }
				else if(intERABuf < 10) {
					if(strERA.length < 4) { strERA = strERA + "0"; }
				}
				else if(strERA.length == 4) { strERA = strERA + "0"; }
         }
         obj("dvERA").innerHTML=strERA
      }
   }
}

function SetLineScore(strTeam,intInning,intScore)
{
   var intInningCol
   intInningCol=intInning
   if(intInningCol>9) {
      intInningCol=9
   }
   SetDMD("LineScore"+strTeam+intInningCol.toString(),intScore)
}

function UpdateClock(floatTime)
{
   // Add the specified amount of time to the clock
   floatTimeMinutes+=floatTime
   while(floatTimeMinutes>=60) {
      floatTimeMinutes-=60
      intTimeHours++
   }
   while(intTimeHours>12) {
      intTimeHours-=12
   }
   
   // Display the clock
   SetDMD("ClockHours",intTimeHours)
   if(strDVType!="normal") {
      if(floatTimeMinutes<10) {
         obj("LDSBClockMin").innerHTML="0"+parseInt(floatTimeMinutes).toString()
      } else {
         obj("LDSBClockMin").innerHTML=parseInt(floatTimeMinutes).toString()
      }
   } else {
      if(floatTimeMinutes<10) {
         SetDMD("ClockMinTens",0)
      } else {
         SetDMD("ClockMinTens",parseInt(floatTimeMinutes/10))
      }
      SetDMD("ClockMinOnes",parseInt(floatTimeMinutes) % 10)
   }
}

function LoadOOTImages(intOOTCount)
{
   intTotalImages+=(intOOTCount*2)
   for(var intIndex=0;intIndex<intOOTCount*2;intIndex+=2) {
      aOOTImages[intIndex]=new Image()
      aOOTImages[intIndex].src = "/images/"+arAllGames[aOOTIndex[intIndex/2]][0]['CityCodeV'].toLowerCase()+arAllGames[aOOTIndex[intIndex/2]][0]['LogoV']+"16.gif"
      aOOTImages[intIndex+1]=new Image()
      aOOTImages[intIndex+1].src = "/images/"+arAllGames[aOOTIndex[intIndex/2]][0]['CityCodeH'].toLowerCase()+arAllGames[aOOTIndex[intIndex/2]][0]['LogoH']+"16.gif"
   }
	
}

function SetStatus(strMessage)
{
   if(strMessage) {
      strStatusBuffer=obj("StadiumWelcome").innerHTML
      obj("StadiumWelcome").innerHTML="<SPAN style='COLOR: #60FF60'>"+strMessage+"</SPAN>"
   } else {
      obj("StadiumWelcome").innerHTML=strStatusBuffer
   }
}

function debug(strMessage)
{
   if(boolDebug) {
      alert(strMessage)
   }
}

function EventCode(strEvent)
{
   return(strEvent.substring(0,2))
}

function EventData(strEvent)
{
   if(strEvent) {
      if(strEvent.length) {
         if(strEvent.length>2) {
            return(strEvent.substring(2,strEvent.length).split(","))
         }
      }
   }
   return(null)
}

//===================================================================================
// obj(strObjID)
//    Helper function to find objects
//    Replaces window.document.getElementById(strObjID)
//===================================================================================
var aObjCache=new Object();
function obj(strObjID)
{
	var boolObjFound=false;
	var oObj=null;
	if(aObjCache[strObjID]) {
		boolObjFound=true;
		oObj=aObjCache[strObjID];
	}
	if(boolObjFound==false) {
		oObj=window.document.getElementById(strObjID);
		aObjCache[strObjID]=oObj;
	}
	return oObj;
}

//===================================================================================
// playerinfo(strPlayerID,strField)
//    Helper function to find players
//===================================================================================
function playerinfo(strPlayerID,strField)
{
   if(strPlayerID) {
      if(intDataBlockVer) {
         if(intDataBlockVer>=2) {
            if(aPlayerIndex[strPlayerID.toString()]>=0) {
               if(aPlayerData[aPlayerIndex[strPlayerID.toString()]][strField]!=null) {
                  return(aPlayerData[aPlayerIndex[strPlayerID.toString()]][strField])
               }
            } 
         }
      }
   }
   return(null)
}

//===================================================================================
// strOtherTeam()
//    Helper function to find team in the field
//===================================================================================
function strOtherTeam()
{
   if(strCurTeam=="H") {
      return("V")
   } else {
      return("H")
   }
}
//===================================================================================
//
// Random number generator
//
// Using this in case random number implementations vary among JavaScript interpreters
//  
// Usage: randnum(x) 
//        Generates a random number from 0 to x-1
//
//        randseed(seed)
//        Seed random number generator
//
//===================================================================================

var rngA=16807         /* multiplier */
var rngM=2147483647    /* 2**31 - 1 */
var rngQ=127773        /* m div a */
var rngR=2836          /* m mod a */
var rngRandom=1

function nextlongrand(seed)
{
	var lo, hi;
	
	lo = rngA * (seed & 0xFFFF);
	hi = rngA * (seed >> 16);
	lo += (hi & 0x7FFF) << 16;
	if (lo > rngM)
	{
		lo &= rngM;
		++lo;
	}
	lo += hi >> 15;
	if (lo > rngM)
	{
		lo &= rngM;
		++lo;
	}
	return lo;
}

function randnum(randmax)                     /* return next random long */
{
	rngRandom = nextlongrand(rngRandom);
	return rngRandom % randmax;
}

function randseed(seed)      /* to seed it */
{
	rngRandom = seed ? (seed & rngM) : 1;  /* nonzero seed */
}

// </script>

