
			var round = 0;
			var finalRound = 0;
			var ids;
			var timeSegment = 1000;
			var scoreFlashIds = "";
			var reload = true;
			var finals = "";
			var updateSegment = 10;
			var finalUpdateSegment = 5;
			var blackList = '|';
			var thisRoundOfEvents = "";
										//NFL NCAAF MLB NHL NCAAB  NBA
			var leagueNumPeriods =     [0,4,4,0,0,9,3,2,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2];
			var xmlTarget;
			var localCache = "";
			var Season = getCurrentSeason( thisLeague ).substring(0,4);
			var timePeriod;
			if ( thisLeague == "NFL" || thisLeague == "NCAAF" ) {
				timePeriod = Week;
				Year = Season;
			} else {
				timePeriod = Period;
			}
	
			function timer() {
				window.setTimeout("refreshScores();", timeSegment );
			} 	

			function refreshScores() {
				timer();	
							

			 	finalRound++;
			 	if ( finalRound > finalUpdateSegment ) {
			 		finalRound = 0;
			 		if ( finals.indexOf("<br>") != -1 ) {
						populateScores( finals, true,  thisLeague, timePeriod, Year );
						//populateScores( finals, true, false, thisLeague, timePeriod, Year );
						finals = "";
					}
			 	}
				
			 	var url = "";
			 	
			 	if ( reload ) {
			 		url = "data\\"+thisLeague+"ScoresAndMatchup\\Xml\\"+Year+"\\"+timePeriod+"\\"+thisLeague+"ScoresAndMatchupsInProgress_"+timePeriod+".xml?code="+getRandom( thisLeague );
			 		reload = false;
			 		xmlTarget = "InProcess";
			 		populateScores( cInclude( null, url ), false, thisLeague, timePeriod, Year );
			 	} else {
			 		round++;
			 		if ( round > updateSegment ) {
			 			url = "data\\"+thisLeague+"ScoresAndMatchup\\Xml\\"+Year+"\\"+timePeriod+"\\"+thisLeague+"ScoresAndMatchupsUpdate_"+timePeriod+".xml?code="+getRandom( thisLeague );
			 			xmlTarget = "Update";
			 			round = 0;
			 			//alert("url" + url);
			 			populateScores( cInclude( null, url ), false, thisLeague, timePeriod, Year );
			 		}
			 	} 
			}

			function populateScores( updateXml, inFinalCycle, thisLeague, timePeriod, year ) {

				//alert("here:" + updateXml);
				//alert("inFinalCycle: "+inFinalCycle);
				if ( updateXml.indexOf("EventID") != -1 && updateXml.indexOf("<br>") != -1 ) {
				
					var eventRows = updateXml.split("<br>");
					thisRoundOfEvents = "";

					for ( var eventRow=0; eventRow<(eventRows.length-1); eventRow++ ) {

						var rawData = eventRows[eventRow];

						if ( rawData.indexOf("EventID") != -1 ) {
							
							var EventID = rawData.substring( rawData.indexOf( "<EventID>" ) + 9, rawData.indexOf( "</EventID>" ) );  
							var LeagueID = parseInt( rawData.substring( rawData.indexOf( "<LeagueID>" ) + 10, rawData.indexOf( "</LeagueID>" ) ) );  
													
							var ScoreStatus = rawData.substring( rawData.indexOf( "<ScoreStatus>" ) + "ScoreStatus".length + 2, rawData.indexOf( "</ScoreStatus>" ) ); 
							var VisitScore = 0;
							var HomeScore = 0;
							var VisitScores = 0;
							var HomeScores = 0;
							if ( rawData.indexOf( "<VisitScore>" ) != -1 ) {
								VisitScore = parseInt(rawData.substring( rawData.indexOf( "<VisitScore>" ) + "<VisitScore>".length, rawData.indexOf( "</VisitScore>" ) ) ); 
							}
							if ( rawData.indexOf( "<HomeScore>" ) != -1 ) {
								HomeScore = parseInt( rawData.substring( rawData.indexOf( "<HomeScore>" ) + "<HomeScore>".length, rawData.indexOf( "</HomeScore>" ) ) ); 
							}

							if ( rawData.indexOf( "<VisitScores>" ) != -1 ) {
								VisitScores = replacestring(rawData.substring( rawData.indexOf( "<VisitScores>" ) + "<VisitScores>".length, rawData.indexOf( "</VisitScores>" ) ), "|", "", true ); 
							}
							if ( rawData.indexOf( "<HomeScores>" ) != -1 ) {
								HomeScores = replacestring( rawData.substring( rawData.indexOf( "<HomeScores>" ) + "<HomeScores>".length, rawData.indexOf( "</HomeScores>" ) ), "|", "", true ); 
							}
							
							var detailStatus  = "";
							if ( rawData.indexOf( "<Details>" ) != -1 ) {
								detailStatus = rawData.substring( rawData.indexOf( "<Details>" ) + "Details".length + 2, rawData.indexOf( "</Details>" ) ); 
							}
														
							var index = localCache.indexOf( EventID + "," ) + EventID.length;

							var oldScore = localCache.substring( index+1, localCache.indexOf( "|", index+1 ) );
							if ( ( oldScore != ( ScoreStatus + "," + VisitScore + "," + HomeScore + "," + VisitScores + "," + HomeScores + "," + detailStatus) ) || ScoreStatus.indexOf("Final") != -1 ) {
							
								localCache = replacestring( localCache, EventID + "," + oldScore + "|", "", true );
								localCache += ( EventID + "," + ScoreStatus + "," + VisitScore + "," + HomeScore + "," + VisitScores + "," + HomeScores  + "," + detailStatus + "|"  );
								//alert(localCache);

								if ( rawData.indexOf( "<ScoreStatus>" ) == -1 && rawData.indexOf( "<ScoreStatus />" ) == -1 ) {
									var currentScoreboard = document.getElementById('current'+EventID);	
									var pastScoreboard = document.getElementById('past'+EventID);	
									var futureScoreboard = document.getElementById('future'+EventID);	
									if ( pastScoreboard != null ) { pastScoreboard.className = 'hidden'; }
									if ( futureScoreboard != null ) { futureScoreboard.className = 'visible'; }
									if ( currentScoreboard != null ) { currentScoreboard.className = 'hidden'; }
								} else { 				
									var content = null;
									if ( xmlTarget == "Update" ) {										
										content = cInclude( null, "data/"+thisLeague+"ScoresAndMatchup/Shtml/"+year+"/"+timePeriod+"/"+EventID+".html?code="+getRandom( thisLeague ) );
										if ( content.indexOf( "cannot access" ) != -1 || content.indexOf( "no games" ) != -1 ) {
											content = cInclude( null, "data/"+thisLeague+"ScoresAndMatchup/Shtml/"+year+"/"+timePeriod+"/"+EventID+".html?code="+getRandom( thisLeague ) );
											if ( content.indexOf( "cannot access" ) != -1 || content.indexOf( "no games" ) != -1 ) {
												content = cInclude( null, "data/"+thisLeague+"ScoresAndMatchup/Shtml/"+year+"/"+timePeriod+"/"+EventID+".html?code="+getRandom( thisLeague ) );
												if ( content.indexOf( "cannot access" ) != -1 || content.indexOf( "no games" ) != -1 ) {
													content = null;
												}
											}
										}
									} else {									
										var pastScoreboard = document.getElementById('past'+EventID);
										
										if ( pastScoreboard != null &&  pastScoreboard.className == "visible" ) {
											var currentDiv = document.getElementById( "currentContainer"+EventID );
											if ( currentDiv != null ) {
												currentDiv.className = 'hidden'; 
											}
										}
									}
									
									updateScoreBox( rawData, content, inFinalCycle, ScoreStatus, VisitScore, HomeScore, LeagueID, EventID );
								}		
							}				
						}
					}
					if ( scoreFlashIds != "" ) {
						flashScoreBox();
					}						
				}
			}


			function updateScoreBox( contentXml, content, inFinalCycle, ScoreStatus, VisitScore, HomeScore, LeagueID, EventID ) {
				
				var homeTotal = 0;
				var visitTotal = 0;
				var displayDiv = "Current";
				
				if ( !( ScoreStatus.indexOf("Final") != -1 || ScoreStatus.indexOf("Cancelled") != -1 || ScoreStatus.indexOf("Deleted") != -1 ) ) {

					var VisitScores = "";
					var HomeScores = "";
					
					/*
					if ( contentXml.indexOf( "<VisitScores>" ) != -1 ) {
						VisitScores = contentXml.substring( contentXml.indexOf( "<VisitScores>" ) + "<VisitScores>".length, contentXml.indexOf( "</VisitScores>" ) );  
					}
					if ( contentXml.indexOf( "<HomeScores>" ) != -1 ) {
						HomeScores = contentXml.substring( contentXml.indexOf( "<HomeScores>" ) + "<HomeScores>".length, contentXml.indexOf( "</HomeScores>" ) );  
					}
					*/
					
					
					//ensure nodes exist
					var FirstHalfScore = "";
					if ( contentXml.indexOf( "<FirstHalfScore>" ) != -1 ) {
						FirstHalfScore = contentXml.substring( contentXml.indexOf( "<FirstHalfScore>" ) + "<FirstHalfScore>".length, contentXml.indexOf( "</FirstHalfScore>" ) );  
						var isFirstHalfThere = document.getElementById("CurrentFirstHalfScore"+EventID );
						if ( isFirstHalfThere != null ) {
							if (isFirstHalfThere.value != FirstHalfScore){
								scoreFlashIds = scoreFlashIds + "FirstHalfScore~"+EventID + ",6,"+FirstHalfScore+","+FirstHalfScore+"|";
							}
						}	
					}					

					var SecondHalfScore = "";
					if ( contentXml.indexOf( "<SecondHalfScore>" ) != -1 ) {
						SecondHalfScore = contentXml.substring( contentXml.indexOf( "<SecondHalfScore>" ) + "<SecondHalfScore>".length, contentXml.indexOf( "</SecondHalfScore>" ) );  
						var isSecondHalfThere = document.getElementById("CurrentSecondHalfScore"+EventID );
						if ( isSecondHalfThere != null ) {
							if (isSecondHalfThere.value != SecondHalfScore){
						
								scoreFlashIds = scoreFlashIds + "SecondHalfScore~"+EventID + ",6,"+SecondHalfScore+","+SecondHalfScore+"|";
							}
						}
					}					

					
					//eval( "var isThere = document.forms[0].half0"+EventID );
					/*
					eval( "var isThere = document.forms[0].CurrentHomeScore"+EventID );

					if ( isThere != null ) {
						if ( ( LeagueID == 51 ) && ( VisitScores != "" && HomeScores != "" ) ) {	
							var HomeScoresArray = HomeScores.split("|");
							var VisitScoresArray = VisitScores.split("|");
							for ( var per=0; per<leagueNumPeriods[LeagueID]+1; per++ ) {

										var oldNum;
										eval( "oldNum = document.forms[0].CurrentHomeScores"+(per+1)+EventID+".value" );
										//eval( "oldNum = document.forms[0].half"+ per+ EventID+".value" );
										
										if ( oldNum == "" ) {
											oldNum = "-";
										}
										if ( oldNum != HomeScoresArray[per] ) {
											scoreFlashIds = scoreFlashIds + "HomeScores" +(per+1)+"~"+EventID + ",6,"+HomeScoresArray[per]+","+HomeScoresArray[per]+"|";
										}

										eval( "oldNum = document.forms[0].CurrentVisitScores"+(per+1)+EventID+".value" );
										if ( oldNum == "" ) {
											oldNum = "-";
										}
										if ( oldNum != VisitScoresArray[per] ) {
											scoreFlashIds = scoreFlashIds + "VisitScores" +(per+1)+"~"+EventID + ",6,"+VisitScoresArray[per]+","+VisitScoresArray[per]+"|";
										}
									
									homeTotal += ( HomeScoresArray[per] == '-' ? 0 : parseInt( HomeScoresArray[per] ) );
									visitTotal += ( VisitScoresArray[per] == '-' ? 0 : parseInt( VisitScoresArray[per] ) );
					
							}						
						}
						
						eval( "document.forms[0].CurrentHomeScore"+EventID+".value = "+homeTotal+";" );
						eval( "document.forms[0].CurrentVisitScore"+EventID+".value = "+visitTotal+";" );
					}*/
					//changes = true;
					
				} else {
					displayDiv = "Past";
					homeTotal = HomeScore;
					visitTotal = VisitScore;
				}
				
				
				if ( content != null ) {

					var currentScoreboard = document.getElementById('current'+EventID);	
					var pastScoreboard = document.getElementById('past'+EventID);	
					var futureScoreboard = document.getElementById('future'+EventID);	
					if ( displayDiv == "Current" || ( displayDiv == "Past" && blackList.indexOf("|"+EventID+"|") == -1 ) ) {
						var currentDiv = document.getElementById( "currentContainer"+EventID );
						//alert(currentDiv);
						if ( currentDiv != null ) {
							currentDiv.innerHTML = content;
							//alert("update");
							if ( displayDiv == "Past" ) {
								finals += ( contentXml + "<br>");
								finalRound = 0;
								blackList += ( "|"+EventID+"|" );
								if ( pastScoreboard != null ) { pastScoreboard.className = 'hidden'; }
								if ( currentScoreboard != null ) { currentScoreboard.className = 'visible'; }//
							} else if ( displayDiv == "Current" ) {
								if ( currentScoreboard != null ) { currentScoreboard.className = 'visible'; }
								if ( pastScoreboard != null ) { pastScoreboard.className = 'hidden'; }//
							} 
							if ( futureScoreboard != null ) { futureScoreboard.className = 'hidden'; }
 				
						} else {
							var pastDiv = document.getElementById( "pastContainer"+EventID );
							if ( pastDiv != null ) {
								pastDiv.innerHTML = content;
							}
						}
					} else {
						var pastDiv = document.getElementById( "pastContainer"+EventID );
						if ( pastDiv != null ) {
							pastDiv.innerHTML = content;
						}
						var currentDiv = document.getElementById( "currentContainer"+EventID );
						if ( currentDiv != null ) {
							currentDiv.className = 'hidden'; 
						}

						if ( pastScoreboard != null ) { pastScoreboard.className = 'visible'; }
						if ( futureScoreboard != null ) { futureScoreboard.className = 'hidden'; }
						if ( currentScoreboard != null ) { currentScoreboard.className = 'hidden'; }

					}
				}
			}
			


			function flashScoreBox() {

				if ( scoreFlashIds != '' ) {
					//alert("flash");
					//alert(scoreFlashIds)
					var flashLine = scoreFlashIds.substring( 0, scoreFlashIds.length - 1 );
					var scoreFlashArray = flashLine.split("|");
					for ( var t=0; t<scoreFlashArray.length; t++ ) {
						//alert(t);
						var scoreId = scoreFlashArray[t].split(",");
						var count = scoreId[1];
						var oldScore = scoreId[2];
						var newScore = scoreId[3];
						var scoreString = replacestring( scoreId[0],'~', '', true );
						var temp = document.getElementById("Current"+scoreString );
						if ( parseInt( count ) == 0 ) {
							//remove
							//alert("remove");
							scoreFlashIds = replacestring( scoreFlashIds, scoreId[0]+',0,'+oldScore+','+newScore+'|', '', true );
							if ( temp != null ) {
								eval( "document.forms[0].Current"+scoreString+".value='" + newScore + "'" );
								//document.getElementById(Current"+scoreString+".value='" + newScore + "'" );
							}
						} else {
							scoreFlashIds = replacestring( scoreFlashIds, scoreId[0]+','+count+','+oldScore+','+newScore+'|', scoreId[0]+','+(count-1)+','+oldScore+','+newScore+'|', true );
							count = count - 1;
							if ( temp != null ) {
								var eventIDString = scoreId[0].split("~");
								var borderDiv = document.getElementById( "CurrentBorder"+eventIDString[1] );
								
								var borderColor = '#000000';
								if ( thisLeague == "NFL" ) {
									borderColor = '#D6E2D6';
								} else if ( thisLeague == "NCAAF" ) {
									borderColor = '#AFBEAF';
								} else if ( thisLeague == "NBA" ) {
									borderColor = '#D6D6BA';
								} else if ( thisLeague == "NCAAB" ) {
									borderColor = '#FFCC80';
								} else if ( thisLeague == "NHL" ) {
									borderColor = '#D0D3DF';
								} else if ( thisLeague == "MLB" ) {
									borderColor = '#B0C2D9';
								} else if ( thisLeague == "WC" ) {
									borderColor = '#B0C2D9';
								}
								
								if ( count % 2 ) {		
									if ( scoreString.indexOf("ScoreStatus") == -1 ) {	
										//alert("red");												
										eval( "document.forms[0].Current"+scoreString+".style.color = '#900';" );
										eval( "document.forms[0].Current"+scoreString+".style.fontWeight = 'bolder'" );
										eval( "document.forms[0].Current"+scoreString+".value='" + newScore + "'" );
									}
									if ( borderDiv != null ) { eval( "borderDiv.style.borderColor = '#900';" ); } 
								} else {
									if ( scoreString.indexOf("ScoreStatus") == -1 ) {	
										//alert("off");															
										eval( "document.forms[0].Current"+scoreString+".style.color = '#000';" );
										eval( "document.forms[0].Current"+scoreString+".style.fontWeight = 'normal'" );
										eval( "document.forms[0].Current"+scoreString+".value='" + oldScore + "'" );
									}
									if ( borderDiv != null ) { eval( "borderDiv.style.borderColor = '"+borderColor+"';" ); } 
								}
							}
						}					
					}
					window.setTimeout("flashScoreBox();", 1000 );
				}	
			}

			function replacestring(str_normal,str_find,str_replace,int_case_insensitive)
			{
				if (arguments.length<3 || str_find=="" || str_normal=="" || typeof("".split)!="function")
					return(str_normal);

				//no parm means default, "case SENSITIVE"...
				if(!(int_case_insensitive))
					return(str_normal.split(str_find)).join(str_replace);

				str_find=str_find.toLowerCase();

				var rv="";
				var ix=str_normal.toLowerCase().indexOf(str_find);
				while(ix>-1)
				{
					rv+=str_normal.substring(0,ix)+str_replace;
					str_normal=str_normal.substring(ix+str_find.length);
					ix=str_normal.toLowerCase().indexOf(str_find);
				}
				return(rv+str_normal);
			}
			
					
		function getRandom( thisLeague ) {
			var currentTime = new Date();
			var randomnumber = thisLeague +":"+ currentTime.getDay() +":"+ currentTime.getMonth() +":"+ currentTime.getFullYear() +":"+ currentTime.getHours() +":"+ currentTime.getMinutes() +":"+ currentTime.getSeconds();
			return randomnumber
		}	
											
		function cInclude(id, url) {
		var req = false;
		// For Safari, Firefox, and other non-MS browsers
		if (window.XMLHttpRequest) {
			try {
			req = new XMLHttpRequest();
			} catch (e) {
			req = false;
			}
		} else if (window.ActiveXObject) {
			// For Internet Explorer on Windows
			try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				req = false;
			}
			}
		}
			
			
		if (req) {
			// Synchronous request, wait till we have it all
			var randomnumber = Math.floor(Math.random()*1000001);
			req.open('GET', url + '?' + randomnumber, false);
			req.send(null);
			return req.responseText;
				
		} else {
			element.innerHTML =
		"Sorry, your browser does not support " +
			"XMLHTTPRequest objects. This page requires " +
			"Internet Explorer 5 or better for Windows, " +
			"or Firefox for any system, or Safari. Other " +
			"compatible browsers may also exist.";
		}
}

