
var x_coordinate = 0;
var y_coordinate = 0;

var xmlSports=''; //contains the 'stripped down' sport names text for checkbox IDs
var xmlSportNames=''; //contains the actual sport names for display inside the filter divs
var xmlSportGenderIDs=''; //contains the sport gender ID's that comprise the XML file
var xmlConferences=''; //contains the 'stripped down' conference names text for checkbox IDs
var xmlConferenceNames=''; //contains the actual conference names for display inside the filter divs
var xmlTeams=''; //contains the 'stripped down' team names text for checkbox IDs
var xmlTeamNames=''; //contains the actual team names for display inside the filter divs

var tickerHeight='';
var tickerWidth='';
var defaultSpeed;
var scrollSpeed;
var scrollerRenderedHeight=''; //this value will designate the content div's rendered height

var scoresXML;

//ApplySettings - invoked from loadXML method and establishes the height and width 
//of the WebTicker as well as the initial scroll speed.  
function ApplySettings(height,width,speed)
{
    tickerHeight = height.length > 0 ? height : '200';
    tickerWidth = width.length > 0 ? width : '200';
    
    //if the speed parameter is missing or == to zero, set the default to 1
    //else make sure that the default speed doesn't go above 5
    /////////////////////////////////////////////////////////////////////////
    if(speed.length == 0 || parseInt(speed,10) == 0)
    {
        defaultSpeed = 1;
        scrollSpeed = 1;        
    }
    else
    {
        defaultSpeed = parseInt(speed,10) <= 5 ? speed : 5;
        scrollSpeed = parseInt(speed,10) <= 5 ? speed : 5;        
    }
    /////////////////////////////////////////////////////////////////////////
 
    //set the heights and widths of the transparent filter divs as well as the actual ticker div
    $('tickerCell').style.height = tickerHeight + 'px';
    $('tickerCell').style.width = tickerWidth + 'px';
    $('webSyncTickerContainer').style.height = tickerHeight + 'px';
    $('webSyncTickerContainer').style.width = tickerWidth + 'px';
    $('sportFilterDiv').style.width = (parseInt(tickerWidth,10)-15) + 'px';
    $('confFilterDiv').style.width = (parseInt(tickerWidth,10)-15) + 'px';
    $('teamsFilterDiv').style.width = (parseInt(tickerWidth,10)-15) + 'px';
    $('tickerTable').style.width = tickerWidth + 'px';
}

function loadXML(url, height, width, speed) 
{
    ApplySettings(height,width,speed);
    
    //IE in Windows does not support document.implementation. If the user
    //is using a Mozilla browser the first condition will be met and createDocument 
    //will render the XML document. Otherwise we need to create an ActiveXObject 
    //DOM object which will represent the XML document in IE.
    ///////////////////////////////////////////////////////////////////////////
    if (document.implementation && document.implementation.createDocument) 
    {
        scoresXML = document.implementation.createDocument("", "", null);
        scoresXML.onload = function(  ) { parseXML(scoresXML); }
    }
    else if (window.ActiveXObject) 
    { 
        scoresXML = new ActiveXObject("Microsoft.XMLDOM");   
        scoresXML.onreadystatechange = function(  ) { if (scoresXML.readyState == 4) parseXML(); }                                         
    }
    ////////////////////////////////////////////////////////////////////////////
    
    scoresXML.load(url);
}
 

function parseXML() 
{
    //get all of the elements within the XML doc
	var items = scoresXML.getElementsByTagName("ROWS");
	
	if(items.length > 0)
	{
	    var webSyncFeed = "" ;
	    
	    for(var i = 0; i < items.length; i++) 
	    {
	        var e = items[i];

            //Here we place all unique teams, sports and conferences into a string that designates
            //which ones are available for use in the filters and checkboxes
            ////////////////////////////////////////////////////////////////////////////////////////////
	        var hmTeam = Clean(e.getAttribute('HomeTmName'));
	        if(xmlTeams.match('~' + hmTeam + '~') != '~' + hmTeam + '~')
	        {
	            xmlTeams = xmlTeams + hmTeam + '~';
	            xmlTeamNames = xmlTeamNames + e.getAttribute('HomeTmName').replace('\'', '`') + '~';
	        }

	        var vsTeam = Clean(e.getAttribute('VisTmName'));
	        if(xmlTeams.match('~' + vsTeam + '~') != '~' + vsTeam + '~')
	        {
	            xmlTeams = xmlTeams + vsTeam + '~';
	            xmlTeamNames = xmlTeamNames + e.getAttribute('VisTmName').replace('\'', '`') + '~';		
	        }

            var sportGenderID = Clean(e.getAttribute('sg'));
            if(xmlSportGenderIDs.match(sportGenderID) != sportGenderID)
            {
                xmlSportGenderIDs = xmlSportGenderIDs + sportGenderID + '~';
            }

		    var sport = Clean(e.getAttribute('SportDesc'));	
		    if(xmlSports.match(sport) != sport)
		    {
		        xmlSports = xmlSports + sport + '~';
		        xmlSportNames = xmlSportNames + e.getAttribute('SportDesc').replace('\'','`') + '~';		
		    }		
    		
		    var hmConference = Clean(e.getAttribute('HomCnfName'));        		
		    if(xmlConferences.match(hmConference) != hmConference)
		    {
		        xmlConferences = xmlConferences + hmConference + '~';
		        xmlConferenceNames = xmlConferenceNames + e.getAttribute('HomCnfName').replace('\'','`') + '~';		
		    }		
    		
		    var vsConference = Clean(e.getAttribute('VisCnfName'));       		
		    if(xmlConferences.match(vsConference) != vsConference)
		    {
		        xmlConferences = xmlConferences + vsConference + '~';
		        xmlConferenceNames = xmlConferenceNames + e.getAttribute('VisCnfName').replace('\'','`') + '~';		
		    }
            ////////////////////////////////////////////////////////////////////////////////////////////
		    

            //Begin creating the div that will represent the innerHTML of the webticker div
		    webSyncFeed = webSyncFeed + '<div style="width:100%"><table style="width:100%"><tr><td colspan="3" style="text-align:left">';
		    
		    //if the webcast url exists, place a link to it in the ticker, else add a link to the box score
            ////////////////////////////////////////////////////////////////////////////////////////////////
		    if(e.getAttribute('wcURL').replace(/ /g,'').length > 0 && parseInt(e.getAttribute('STATUS'),10) == 1)
		    {
		        webCastLink = '<span style="vertical-align:center"><span style="font-size:12px">(</span><span style="font-size:10px">(</span><span style="font-size:8px">(</span><span style="vertical-align:bottom">WC</span><span style="font-size:8px">)</span><span style="font-size:10px">)</span><span style="font-size:12px">)</span></span>';
		        webSyncFeed = webSyncFeed + '<table style="width:100%" cellpadding="0" cellspacing="0"><tr><td style="font-size:12px; text-align:left; width:65%"><b> ' + e.getAttribute('SportDesc') + '</b></td><td><a style="text-decoration:none" target="_blank" href="' + e.getAttribute('wcURL') + '">' + webCastLink + '</a></td></tr></table></td></tr>';		    
		    }
		    else
		    {
		        webSyncFeed = webSyncFeed + '<table style="width:100%" cellpadding="0" cellspacing="0"><tr><td style="font-size:12px; text-align:left; width:65%"><b> ' + e.getAttribute('SportDesc') + '</b></td><td><a target="_blank" href="' + e.getAttribute('boxURL') + '">' + 'Box</a></td></tr></table></td></tr>';
		    }
		    webSyncFeed = webSyncFeed + '<tr><td style="width:70%">' + e.getAttribute('HomeTmName') + '</td><td style="width:5%; text-align:right;">' + e.getAttribute('HSCORE') + '</td><td style="padding-right:5px; text-align:right">';
            ///////////////////////////////////////////////////////////////////////////////////////////////
            
            //if the game is in progress and it is not baseball, softball or volleyball, show the current time,
            //else if the game hasn't started yet, show the game date
            ////////////////////////////////////////////////////////////////////////////////////////////            
            var sg = e.getAttribute('sg');
            if(parseInt(e.getAttribute('STATUS'),10) == 1 && (sg!='MBA' && sg!='WBA' && sg!='MVB' && sg!='WVB'))
            {		            
                webSyncFeed = webSyncFeed + e.getAttribute('InTime');
            }
            else if (parseInt(e.getAttribute('STATUS'), 10) == 2 || parseInt(e.getAttribute('STATUS'), 10) == 0)
            {
                webSyncFeed = webSyncFeed + GetGameDate(e.getAttribute('COMPDATE'));
            }        
            ////////////////////////////////////////////////////////////////////////////////////////////
            
            webSyncFeed = webSyncFeed + '</td></tr>';
            webSyncFeed = webSyncFeed + '<tr><td style="width:70%">' + e.getAttribute('VisTmName') + '</td><td style="width:5%; text-align:right;">' + e.getAttribute('VSCORE') + '</td>';
		    
		    //if the game hasn't started yet show the game time (which will appear below the game date)
		    //else if the game is in progress show which period it's in,
		    //else if the game is over, show the final score
            ////////////////////////////////////////////////////////////////////////////////////////////		    
		    if(parseInt(e.getAttribute('STATUS'),10) == 2)
		    {
		        webSyncFeed = webSyncFeed + '<td style="padding-right:5px; text-align:right">' + GetGameTime(e.getAttribute('COMPDATE')) +  '</td>';
		    }
		    else if(parseInt(e.getAttribute('STATUS'),10) == 1)
		    {
		        webSyncFeed = webSyncFeed + '<td style="text-align:right; padding-right:5px">' + GetGamePeriod(e.getAttribute('InPeriod'))  + '</td>';
		    }
		    else if(parseInt(e.getAttribute('STATUS'),10) == 0)
		    {
		        webSyncFeed = webSyncFeed + '<td style="text-align:right; padding-right:5px">Final' + GetPeriodsPlayed(e.getAttribute('sg'), e.getAttribute('NUMPERIODS')) + '</td>';
		    }
		    webSyncFeed = webSyncFeed + '</tr></table></div><br/>';	
            ////////////////////////////////////////////////////////////////////////////////////////////
		    
        }

        //inject the dynamic HTML into the ticker div
	    $('webSyncTicker').innerHTML = webSyncFeed;
	    
        //here we set the top position of the ticker div to zero and declare the height of the
        //inner scrolling div to be equal to the height initially passed in on page load.
        //setInterval actually begins the scrolling effect.
        /////////////////////////////////////////////////////////////////////////////////////////////////
        webSyncTickerInnerDiv = $("webSyncTicker");
        webSyncTickerInnerDiv.style.top = 0;
        webTickerContainerHeight = $("webSyncTickerContainer").offsetHeight;
        scrollerRenderedHeight = webSyncTickerInnerDiv.offsetHeight;
        lefttime = setInterval("scrollWebTicker()",30);
        /////////////////////////////////////////////////////////////////////////////////////////////////    
    		
        //---Creating the mouseover sports filter div---		
        //In this section we will go through each unique sport, found in the XML document.
        //For each one we find we create a dynamic checkbox for it and insert the checkbox along with the actual
        //unique name text into the filter div.
        //////////////////////////////////////////////////////////////////////////////////////////////////////////
        var sportsArray = new Array();
        sportsArray = xmlSportGenderIDs.split('~').sort();
        
	    var sportNamesString = xmlSportNames.substr(0,xmlSportNames.length);        
        var sportNamesArray = new Array();
	    sportNamesArray = sportNamesString.split('~').sort();

	    var sportsHTML = '<input id="allSportsCheckBox" type="checkbox" style="cursor:pointer" onmouseover="$(\'allSportsSpan\').style.color=\'#B22222\';" onmouseout="$(\'allSportsSpan\').style.color=\'transparent\';" onclick="AddRemoveItem(\'allSportsCheckBox\',\'allSports\',false, \'sports\');" checked="checked"/>';
	    sportsHTML = sportsHTML + '<span id="allSportsSpan" style="cursor:pointer" onmouseover="this.style.color=\'#B22222\';" onmouseout="this.style.color=\'transparent\';" onclick="AddRemoveItem(\'allSportsCheckBox\',\'allSports\',true, \'sports\');">View All Sports</span><hr />';
	    var heightCounter=40;

	    for(var x=0; x<sportsArray.length; x++)
	    {
	        if(sportsArray[x] != '')
	        {
	            var sport = Clean(sportsArray[x]);        
	            sportsHTML = sportsHTML + '<input id="' + sport + 'CheckBox" type="checkbox" style="cursor:pointer" onclick="AddRemoveItem(\'' + sport + 'CheckBox\',\'' + sport + '\',false, \'sports\');" onmouseover="$(\'sportSpan' + x + '\').style.color = \'#B22222\';" onmouseout="$(\'sportSpan' + x + '\').style.color = \'black\';" checked="checked"/>';
	            sportsHTML = sportsHTML + '<span id="sportSpan' + x + '" style="cursor:pointer;" onmouseover="$(\'sportSpan' + x + '\').style.color = \'#B22222\';" onmouseout="$(\'sportSpan' + x + '\').style.color = \'black\';" onclick="AddRemoveItem(\'' + sport + 'CheckBox\',\'' + sport + '\',true, \'sports\');">' + sportNamesArray[x] + '</span><br />';
	            heightCounter = heightCounter + 20;
	        }
	    }	
	    $('sportFilterDiv').innerHTML = sportsHTML;
	    $('sportFilterDiv').style.height = heightCounter + 'px';
        //////////////////////////////////////////////////////////////////////////////////////////////////////////

    	//---Creating the mouseover conferences filter div---		
        //In this section we will go through each unique conference, found in the XML document.
        //For each one we find we create a dynamic checkbox for it and insert the checkbox along with the actual
        //unique name text into the filter div.
        //////////////////////////////////////////////////////////////////////////////////////////////////////////
        var confArray = new Array();
        var confNamesArray = new Array();
        var xmlConfsString = xmlConferences.substr(0,xmlConferences.length-1);
        var xmlConfsNamesString = xmlConferenceNames.substr(0,xmlConferenceNames.length-1);
        confArray = xmlConfsString.split('~').sort();
        confNamesArray = xmlConfsNamesString.split('~').sort();
        var confHTML = '<div id="confScrollingDiv" style="overflow:auto; width:' + (parseInt(tickerWidth,10)-15) + 'px">';
	    confHTML = confHTML + '<input id="allConferencesCheckBox" type="checkbox" style="cursor:pointer" onmouseover="$(\'allConferencesSpan\').style.color=\'#B22222\';" onmouseout="$(\'allConferencesSpan\').style.color=\'transparent\';" onclick="AddRemoveItem(\'allConferencesCheckBox\',\'allConferences\',false, \'conferences\');" checked="checked"/>';
	    confHTML = confHTML + '<span id="allConferencesSpan" style="cursor:pointer" onmouseover="this.style.color=\'#B22222\';" onmouseout="this.style.color=\'transparent\';" onclick="AddRemoveItem(\'allConferencesCheckBox\',\'allConferences\',true, \'conferences\');">View All Conferences</span><hr />';
	    heightCounter = 40;
	    for(var x=0; x<confArray.length; x++)
	    {
	        var conf = Clean(confArray[x]);   
            confHTML = confHTML + '<input id="' + confArray[x].replace(/ /g,'') + 'CheckBox" type="checkbox" style="cursor:pointer" onmouseover="$(\'conferenceSpan' + x + '\').style.color=\'#B22222\';" onmouseout="$(\'conferenceSpan' + x + '\').style.color=\'transparent\';" onclick="AddRemoveItem(\'' + confArray[x].replace(/ /g,'') + 'CheckBox\',\'' + confArray[x].replace(/ /g,'') + '\',false, \'conferences\');" checked="checked"/>';
            confHTML = confHTML + '<span id="conferenceSpan' + x + '" style="cursor:pointer" onmouseover="this.style.color=\'#B22222\';" onmouseout="this.style.color=\'transparent\';" onclick="AddRemoveItem(\'' + confArray[x].replace(/ /g,'') + 'CheckBox\',\'' + confArray[x].replace(/ /g,'') + '\',true, \'conferences\');">' + confNamesArray[x] + '</span><br />';
	        heightCounter = heightCounter + 20;
	    }
	    confHTML = confHTML + '</div>';
	    $('confFilterDiv').innerHTML = confHTML;    
    	
	    if(heightCounter < parseInt(tickerHeight,10))
	    {
	        $('confFilterDiv').style.height = heightCounter + 'px';
	        $('confScrollingDiv').style.height = heightCounter + 'px';
	    }
	    else
	    {
	        $('confFilterDiv').style.height = tickerHeight + 'px';
	        $('confScrollingDiv').style.height = tickerWidth + 'px';
	    }
        //////////////////////////////////////////////////////////////////////////////////////////////////////////
    	
    	//---Creating the mouseover teams filter div---		
        //In this section we will go through each unique team, found in the XML document.
        //For each one we find we create a dynamic checkbox for it and insert the checkbox along with the actual
        //unique name text into the filter div.
        //////////////////////////////////////////////////////////////////////////////////////////////////////////
	    var teamsArray = new Array();
	    var teamNamesArray = new Array();
	    var xmlTeamsString = xmlTeams.substr(0,xmlTeams.length-1);
	    var xmlTeamNamesString = xmlTeamNames.substr(0,xmlTeamNames.length-1);
	    teamsArray = xmlTeamsString.split('~').sort();
	    teamNamesArray = xmlTeamNamesString.split('~').sort();
    	
        // -- This section will display the teams filter menu inside of a scrolling div --
        /////////////////////////////////////////////////////////////////////////////
	    var teamsHTML = '<div id="teamsScrollingDiv" style="overflow:auto; width:' + (parseInt(tickerWidth,10)-15) + 'px">';
	    teamsHTML = teamsHTML + '<input id="allTeamsCheckBox" type="checkbox" style="cursor:pointer" onmouseover="$(\'allTeamsSpan\').style.color=\'#B22222\';" onmouseout="$(\'allTeamsSpan\').style.color=\'transparent\';" onclick="AddRemoveItem(\'allTeamsCheckBox\',\'allTeams\',false, \'teams\');" checked="checked"/>';
	    teamsHTML = teamsHTML + '<span id="allTeamsSpan" style="cursor:pointer" onmouseover="this.style.color=\'#B22222\';" onmouseout="this.style.color=\'transparent\';" onclick="AddRemoveItem(\'allTeamsCheckBox\',\'allTeams\',true, \'teams\');">View All Schools</span><hr />';
	    heightCounter = 40;

	    for(var x=0; x<teamsArray.length; x++)
	    {
	        var teamValue = Clean(teamsArray[x]);      
	        teamsHTML = teamsHTML + '<input id="' + teamValue + 'CheckBox" type="checkbox" style="cursor:pointer" onmouseover="$(\'teamSpan' + x + '\').style.color=\'#B22222\';" onmouseout="$(\'teamSpan' + x + '\').style.color=\'transparent\';" onclick="AddRemoveItem(\'' + teamValue + 'CheckBox\',\'' + teamValue + '\',false, \'teams\');" checked="checked"/>';
	        teamsHTML = teamsHTML + '<span id="teamSpan' + x + '" style="cursor:pointer" onmouseover="this.style.color=\'#B22222\';" onmouseout="this.style.color=\'transparent\';" onclick="AddRemoveItem(\'' + teamValue + 'CheckBox\',\'' + teamValue + '\',true, \'teams\');">' + teamNamesArray[x] + '</span><br />';
	        heightCounter = heightCounter + 20;
	    }
	    teamsHTML = teamsHTML + '</div>';
        /////////////////////////////////////////////////////////////////////////////

	    $('teamsFilterDiv').innerHTML = teamsHTML;
	    if(heightCounter < parseInt(tickerHeight,10))
	    {
	        $('teamsFilterDiv').style.height = heightCounter + 'px';
	        $('teamsScrollingDiv').style.height = heightCounter + 'px';
	    }
	    else
	    {
	        $('teamsFilterDiv').style.height = tickerHeight + 'px';
	        $('teamsScrollingDiv').style.height = tickerHeight + 'px';
	    }
        //////////////////////////////////////////////////////////////////////////////////////////////////////////
	    
	}
	else
	{
	    $('webSyncTicker').innerHTML = "<div style='padding-top:" + ((tickerHeight/2)-15) + "px; text-align:center; vertical-align:middle; color:#FFD700; font-size:12pt'>No games currently being reported</div>";
	}
}

//This function will evaluate the current sports, conferences and teams contained in the 
//global strings and then rerender the innerHTML of the WebTicker div based on the available 
//teams, conferences and sports
function FilterFeed(sports,conferences,teams)
{
	var items = scoresXML.getElementsByTagName("ROWS");

	var webSyncFeed = "" ;

    var xmlTeamsArray = new Array();
    xmlTeamsArray = teams.split('~');
    var totalFilteredTeams = xmlTeamsArray.length-1;

    for(var i = 0; i < items.length; i++) 
    {
        var e = items[i];
        var sport = Clean(e.getAttribute('SportDesc'));
        var sportGenderID = Clean(e.getAttribute('sg'));
        var hmConference = Clean(e.getAttribute('HomCnfName'));
        var vsConference = Clean(e.getAttribute('VisCnfName'));
        var hmTeam = Clean(e.getAttribute('HomeTmName'));
        var vsTeam = Clean(e.getAttribute('VisTmName'));
        if(sports.match(sportGenderID) == sportGenderID || sports=='all')
        {
            if(conferences.match(hmConference) || conferences.match(vsConference) || conferences=='all')
            {       
                //Here we must account for the first item in the home team
                //list which will not be preceeded by a '~' character. The first
                //visiting team name will always be preceeded by a '~'.
                //////////////////////////////////////////////////////////////////
                var hmMatch = i==0 || totalFilteredTeams==1 ? hmTeam + '~' : '~' + hmTeam + '~';
                var vsMatch = '~' + vsTeam + '~';
                //////////////////////////////////////////////////////////////////
                
                if(teams.match(hmMatch)==(hmMatch) || teams.match(vsMatch)==(vsMatch) || teams=='all')
                {	               
                    webSyncFeed = webSyncFeed + '<div style="width:100%"><table style="width:100%"><tr><td colspan="3" style="text-align:left">';
	                if(e.getAttribute('wcURL').replace(/ /g,'').length > 0 && parseInt(e.getAttribute('STATUS'),10) == 1)
	                {
	                    webCastLink = '<span style="vertical-align:center"><span style="font-size:12px">(</span><span style="font-size:10px">(</span><span style="font-size:8px">(</span><span style="vertical-align:bottom">WC</span><span style="font-size:8px">)</span><span style="font-size:10px">)</span><span style="font-size:12px">)</span></span>';
	                    webSyncFeed = webSyncFeed + '<table style="width:100%" cellpadding="0" cellspacing="0"><tr><td style="font-size:12px; text-align:left; width:65%"><b> ' + e.getAttribute('SportDesc').replace('\'','`') + '</b></td><td><a style="text-decoration:none" target="_blank" href="' + e.getAttribute('wcURL') + '">' + webCastLink + '</a></td></tr></table></td></tr>';		    
	                }
	                else
	                {
	                    webSyncFeed = webSyncFeed + '<table style="width:100%" cellpadding="0" cellspacing="0"><tr><td style="font-size:12px; text-align:left; width:65%"><b>' + e.getAttribute('SportDesc').replace('\'','`') + '</b></td><td><a target="_blank" href="' + e.getAttribute('boxURL') + '">' + 'Box</a></td></tr></table></td></tr>';
	                }
	                webSyncFeed = webSyncFeed + '<tr><td style="width:70%">' + e.getAttribute('HomeTmName').replace('\'', '`') + '</td><td style="width:5%; text-align:right;">' + e.getAttribute('HSCORE') + '</td><td style="padding-right:5px; text-align:right">';
		            
	                var sg = e.getAttribute('SG');
	                if(parseInt(e.getAttribute('STATUS'),10) == 1 && (sg!='MBA' && sg!='WBA' && sg!='MVB' && sg!='WVB'))
	                {		            
	                    webSyncFeed = webSyncFeed + e.getAttribute('InTime');
	                }
	                else if (parseInt(e.getAttribute('STATUS'), 10) == 2 || parseInt(e.getAttribute('STATUS'), 10) == 0)
	                {
	                    webSyncFeed = webSyncFeed + GetGameDate(e.getAttribute('COMPDATE'));
	                }
		            
	                webSyncFeed = webSyncFeed + '</td></tr>';
	                webSyncFeed = webSyncFeed + '<tr><td style="width:70%">'+ e.getAttribute('VisTmName').replace('\'','`') +'</td><td style="width:5%; text-align:right;">' + e.getAttribute('VSCORE') + '</td>';		            
	                if(parseInt(e.getAttribute('STATUS'),10) == 2)
	                {
	                    webSyncFeed = webSyncFeed + '<td style="text-align:right; padding-right:5px">' + GetGameTime(e.getAttribute('COMPDATE')) +  '</td>';
	                }		            
	                else if(parseInt(e.getAttribute('STATUS'),10) == 1)
	                {         		    
	                    webSyncFeed = webSyncFeed + '<td style="text-align:right; padding-right:5px; font-size:10px;">' + GetGamePeriod(e.getAttribute('InPeriod')) + '</td>';
	                }
	                else if(parseInt(e.getAttribute('STATUS'),10) == 0)
	                {
	                    webSyncFeed = webSyncFeed + '<td style="text-align:right; padding-right:5px; font-size:10px; vertical-align:bottom">Final' + GetPeriodsPlayed(e.getAttribute('sg'),e.getAttribute('NUMPERIODS')) + '</td>';
	                }
	                webSyncFeed = webSyncFeed + '</tr></table></div><br/>';
                }
                else
                {
                    $('allTeamsCheckBox').checked = false;
                }

                $(hmTeam+'CheckBox').checked = teams.match(hmMatch)==hmMatch || teams=='all' ? true : false;
                $(vsTeam+'CheckBox').checked = teams.match(vsMatch)==vsMatch || teams=='all' ? true : false;
            }
            else
            {
                $('allConferencesCheckBox').checked = false;
            }

            if ($(hmConference + 'CheckBox') != null) 
            {
                $(hmConference + 'CheckBox').checked = conferences.match(hmConference) == hmConference || conferences == 'all' ? true : false;
            }
            if ($(vsConference + 'CheckBox') != null)
            {
                $(vsConference + 'CheckBox').checked = conferences.match(vsConference) == vsConference || conferences == 'all' ? true : false;
            }
        } 
        else
        {
            $('allSportsCheckBox').checked = false;
        }
        $(sportGenderID+'CheckBox').checked = sports.match(sportGenderID)==sportGenderID || sports=='all' ? true : false; 
	}
	
	$('webSyncTicker').innerHTML = "";
	$('webSyncTicker').innerHTML = webSyncFeed;   

	webSyncTickerInnerDiv = $("webSyncTicker");
    webSyncTickerInnerDiv.style.top = 0;
    webTickerContainerHeight = $("webSyncTickerContainer").offsetHeight;
    scrollerRenderedHeight = webSyncTickerInnerDiv.offsetHeight;
}

function scrollWebTicker()
{
    // Here we check to see if the value of the current top position of our scrolling div still exceeds
    // the value of the final top position (scrollerRenderedHeight * (-1))
    var currentTopPositionOfScroller = parseInt(webSyncTickerInnerDiv.style.top,10);
    var scrollerIsNotFinished = currentTopPositionOfScroller > (scrollerRenderedHeight * (-1));
    
    // If the scroller's top position is less than or equal to the final top position we reset 
    // the top position, if not we subtract "scrollSpeed" pixels from the top position
    webSyncTickerInnerDiv.style.top = scrollerIsNotFinished ? currentTopPositionOfScroller - scrollSpeed + "px" : parseInt(webTickerContainerHeight,10) + "px";
}

function ShowHideDiv(divIDToShow, displayProperty, freeze)
{
    if($(divIDToShow).style.display == 'block' && (x_coordinate < $(divIDToShow).style.left || y_coordinate > $(divIDToShow).style.top))
    {
        $(divIDToShow).style.display = 'none';
    }
    else
    {
        $(divIDToShow).style.display = displayProperty;
    }
    
    if(freeze)
    {
        $(divIDToShow).style.left = '10px';
        $(divIDToShow).style.top = '12px';
    }
}

//This method is used to capture the current position of the mouse pointer
//The position will be used in showing/hiding the menu lists
function setMousePosition(e)
{
    if (!e) var e = window.event;
    
    if(e.clientX || e.clientY)
    {
        x_coordinate = e.clientX;
        y_coordinate = e.clientY;    
    }
    else if (e.pageX || e.pageY)
    {
        x_coordinate = e.pageX;
        y_coordinate = e.pageY;
    }
}


//This function will add or remove a sport, conference or team when the user selects/deselects
//it from the filter div. It will also add/remove all sports, conferences or teams if the 'View All' 
//checkbox is checked/unchecked
function AddRemoveItem(controlID,text,textWasClicked, item)
{
    //This checks to see if the user clicked on the 'span' text instead of the actual checkbox
    if(textWasClicked)
    {
        $(controlID).checked = !$(controlID).checked;
    }
    
    if(text == 'allSports' || text == 'allConferences' || text == 'allTeams')
    {    
        if(!$(controlID).checked)
        {
            switch (item)
            {
                case 'sports':
                    xmlSports = '';
                    xmlSportGenderIDs = '';
                    break;
                case 'conferences':
                    xmlConferences = '';
                    break;
                case 'teams':
                    xmlTeams = '';
                    break;
            }
        }
        else
        {
	        var items = scoresXML.getElementsByTagName("ROWS");

	        for(var i = 0; i < items.length; i++) 
	        {
	            var e = items[i];
        		
                switch (item)
                {
                    case 'sports':
        		        var sport = Clean(e.getAttribute('SportDesc'));
        		        var sportGenderID = Clean(e.getAttribute('sg'));
		                if(!xmlSports.match(sport))
		                {
		                    xmlSports = xmlSports + sport + '~';
		                }
        		        
		                if(!xmlSportGenderIDs.match(sportGenderID))
		                {
		                    xmlSportGenderIDs = xmlSportGenderIDs + sportGenderID + '~';
		                }
                        break;
                    case 'conferences':
        		        var hmConference = Clean(e.getAttribute('HomCnfName'));
                        var vsConference = Clean(e.getAttribute('VisCnfName'));
                        
		                if(!xmlConferences.match(hmConference))
		                {
		                    xmlConferences = xmlConferences + Clean(hmConference) + '~';
		                }
                		
		                if(!xmlConferences.match(vsConference))
		                {
		                    xmlConferences = xmlConferences + Clean(vsConference) + '~';
		                }
                        break;
                    case 'teams':
                        var hmTeam = Clean(e.getAttribute('HomeTmName'));
                        var vsTeam = Clean(e.getAttribute('VisTmName'));

		                if(!xmlTeams.match(hmTeam + '~'))
		                {
		                    xmlTeams = xmlTeams + hmTeam + '~';
		                }
                		
		                if(!xmlTeams.match(vsTeam + '~'))
		                {
		                    xmlTeams = xmlTeams + vsTeam + '~';
		                }
                        break;
                }        
            }
        }
    }
    else
    {
        text = Clean(text);        
        var sg = Clean(controlID.replace('CheckBox',''));
        
        var controlIsChecked = $(controlID).checked;
        switch (item)
        {
            case 'sports':
                xmlSports = controlIsChecked ? xmlSports + text + "~" : xmlSports.replace(text + '~','');
                xmlSportGenderIDs = controlIsChecked ? xmlSportGenderIDs + sg + "~" : xmlSportGenderIDs.replace(sg + '~','');
                break;
            case 'conferences':
                xmlConferences = controlIsChecked ? xmlConferences + text + "~" : xmlConferences.replace(text + '~','');
                break;
            case 'teams':
                xmlTeams = controlIsChecked ? xmlTeams + text + "~" : xmlTeams.replace(text + '~','');
                break;
        }
    }

    FilterFeed(xmlSportGenderIDs,xmlConferences,xmlTeams);
}

function IncreaseDecreaseSpeed(direction) 
{
    if(direction == 'up')
    {
        if(scrollSpeed < 5)
        {
            scrollSpeed++;
        }
    }
    else
    {
        if(scrollSpeed > 1)
        {
            scrollSpeed--;
        }
    }
}

//This function will parse through the datetime field which is
//returned in the scores XML file and return the current game time.
//The datetime field is in the following format: 2007-04-24T17:30:00
function GetGameTime(datetime)
{
    var datetimeArray = new Array();
    datetimeArray = datetime.split('T');
    
    var timeArray = new Array();
    timeArray = datetimeArray[1].split(':');
    var hour = parseInt(timeArray[0],10);
    var minute = timeArray[1];
    var suffix=' a';
    
    if(hour == 24)
    {
        hour = 12;
    }
    else if(hour > 12)
    {
        hour = hour - 12;
        suffix=' p';
    }
    else if(hour == 12)
    {
        suffix=' p';
    }
    
    var gameTime = hour + ':' + minute + suffix;
    
    return gameTime;
}

//This function will parse through the datetime field which is
//returned in the scores XML file and return the current game date.
//The datetime field is in the following format: 2007-04-24T17:30:00
function GetGameDate(datetime)
{
    var datetimeArray = new Array();
    datetimeArray = datetime.split('T');

    var dateArray = new Array();
    dateArray = datetimeArray[0].split('-');
    
    var month = parseInt(dateArray[1],10);
    var day = parseInt(dateArray[2],10);
    
    var gameDate = month + '/' + day;
    
    return gameDate;
}

//This particular funtion will accept and parse the current XML InPeriod value
//and return a formatted string representing the game's current period
function GetGamePeriod(inPeriod)
{
    var postfix = '';
    var period = Clean(inPeriod);
    if(period == '1' || period == '21' || period == '31')
    {
        postfix = 'st';
    }
    else if(period == '2' || period == '22' || period == '32')
    {
        postfix = 'nd';
    }
    else if(period == '3' || period == '23' || period == '33')
    {
        postfix = 'rd';
    }		
    else if(period != '0' && period != '' && period != ' ')
    {
        postfix = 'th';
    }
    
    return (period + postfix);
}

//This function will apply specific game time rules to each
//sportgender and return how many periods have been played
function GetPeriodsPlayed(sg,numPeriods)
{
    var periodsPlayed = '';
    switch (sg.toUpperCase())
    {
        case 'MFB':
        case 'WFB':
            if(numPeriods.length != 0 && parseInt(numPeriods,10) > 4)
            {
                var OTs = (parseInt(numPeriods,10) - 4);
                periodsPlayed = OTs == 1 ? '/OT' : ('/' + OTs + 'OT');
            }
            break;
        case 'MSO':
        case 'WSO':
        case 'MBB':
        case 'WBB':        
            if(numPeriods.length != 0 && parseInt(numPeriods,10) > 0)
            {
                periodsPlayed = parseInt(numPeriods,10) == 1 ? '/OT' : '/' + parseInt(numPeriods,10) + 'OT';
            }
            break;
        case 'MBA':
        case 'WBA':
            periodsPlayed = '/' + parseInt(numPeriods,10);
            break;
    }
    
    return periodsPlayed;
}

//This function is used to 'strip out' all of the characters that grossly
//affect the operation of regular expressions in JavaScript (particularly
//the match function) as well as any others that are inappropriate for use in control identifiers. 
function Clean(str)
{
    if(str != null)
    {
        str = str.replace(/[ \.\(\)\[\]\*\+\-\\\<\>\?\;\:\{\}\/\|\"\'`&!@#$%^=~_,]/g,'');
    }
    else
    {
        str = "";
    }
    return str;
}
