var league = 0;
var current_date = '<xsl:value-of select="@date"/>';
var game_counter = 0;
var game_color = "";
var game_date = "";
var game_time = "";
var team_counter = 0;
var score = '';
var in_header = false;
var number_of_books;
var sports_books;
var book_links;
var display_line;
var cell_color;

book_links = new Array (3);
//book_links [0] = 'http://www.vegashotsheet.com';
//book_links [1] = 'http://www.vegashotsheet.com';
//book_links [2] = 'http://www.vegashotsheet.com';
//book_links [3] = 'http://www.vegashotsheet.com';
//book_links [4] = 'http://www.vegashotsheet.com';
book_links [0] = '';
book_links [1] = '';
book_links [2] = '';

sports_books = new Array (3);
sports_books [0] = 'Mirage';
sports_books [1] = '5Dimes';
sports_books [2] = 'Bet Eagle';

function document_write (data)
    {
    document.write (data);
    }
function print_header (header) {
    if (in_header)
        display_header += '<br>';
    else
        {
        display_header = '';
        in_header = true;
        }
    display_header += header;
    }
function in_game (gd, gt)
    {
    game_date = gd;
    game_time = gt;
    if (in_header)
        {
        in_header = false;
        game_counter = 0;
        document_write ('<tr><td class="dataheader" width="540" colspan="' + (7+number_of_books) + '">' + display_header + '</td></tr>');
        document_write ('<tr>');
        document_write ('<td class="datasubheaderleft2" width="35">Time</td>');
        document_write ('<td class="datasubheader" width="40">Gm #</td>');
        document_write ('<td class="datasubheader" width="120">Team</td>');
        document_write ('<td class="datasubheader" width="75">Score</td>');
        document_write ('<td class="datasubheader" width="60">Opener</td>');
        for (i = 0; i < number_of_books; i++)
            {
            document_write ('<td class="datasubheader" width="60">');
            if (book_links [i].length == 0)
            	document.write (sports_books [i] + '</td>');
            else
                document.write ('<a href="' + book_links [i] + '" target="_blank">' + sports_books [i] + '</a></td>');
            }
        document_write ('</tr>');
        }
    if (((game_counter++) % 2) == 0)
        game_color = "white";
    else
        game_color = "grey";
    display_number = '';
    display_team = '';
    display_score = '';
    display_status = '';
    for (i = 0; i < number_of_books+1; i++)
        display_line [i] = '';
    }
function end_game ()
    {
    document_write ('<tr class="scores-' + game_color + 'bg">');
    document_write ('<td class="scores-' + game_color + 'bg-left">' + game_date.substring (4, 6) + '/' + game_date.substring (6) + '<br>');
    document_write (string_time (game_time) + '</td>');
    document_write ('<td class="scores-' + game_color + 'bg">' + display_number + '</td>');
    
    if (baseball)
        {
        document_write ('<td class="scores-' + game_color + 'bg-team"><table>');
        document_write ('<tr><td class="scores-' + game_color + 'bg-team-bb">' + display_team + '</td><td>&nbsp;</td><td class="scores-' + game_color + 'bg-team-bb">' + display_pitcher + '</td></tr>');
        document_write ('</table></td>');
        }
    else
        document_write ('<td class="scores-' + game_color + 'bg-team">' + display_team + '</td>');
        
    document_write ('<td class="scores-' + game_color + 'bg-team"><table padding-left="5">');    
    document_write ('<tr><td class="scores-' + game_color + 'bg-team-bb" >' + display_score + '</td><td >&nbsp;</td><td class="scores-' + game_color + 'bg-team-bb" >' + display_status + '</td></tr>');
    document_write ('</table></td>');
    for (i = 0; i < number_of_books+1; i++)
        document_write ('<td class="scores-' + game_color + 'bg-right" >' + display_line [i] + '</td>');
    document_write ('</tr>');
    }
function in_team (number, team, pitcher, hand, score, status)
    {
    if (display_number.length != 0)
        display_number += '<br>';
    display_number += number;

    if (league == 5)
        {
        baseball = true;

        b = pitcher.indexOf (' ');
        if (b > 0)
            {
            b2 = pitcher.substring (b+1).indexOf (' ');
            if (b2 >= 0)
                b += b2 + 1;
            pitcher = pitcher.substring (0, b) + ' ' + pitcher.substring (b+1, b+2) + pitcher.substring (b+2).toLowerCase ();
            }
        else
            pitcher = pitcher.substring (0, 1) + pitcher.substring (1).toLowerCase ();

        if (display_team.length == 0)
            {
            if (pitcher.length > 0)
                display_pitcher = pitcher;
            else if (team.length > 3 && team.charAt (3) == ' ')
                display_pitcher = team.substring (4);
            else if (team.length > 3 && team.charAt (3) != ' ')
                display_pitcher = team;
            else
                display_pitcher = '';
            if (hand == 'L')
                display_pitcher += '<b>-' + hand + '</b>';
            display_pitcher += '<br>';
            display_team = '&nbsp;' + team.substring (0, 3) + '<br>';
            }
        else
            {
            if (pitcher.length > 0)
                display_pitcher += pitcher;
            else if (team.length > 3 && team.charAt (3) == ' ')
                display_pitcher += team.substring (4);
            else if (team.length > 3 && team.charAt (3) != ' ')
                display_pitcher += team;
            if (hand == 'L')
                display_pitcher += '<b>-' + hand + '</b>';
            display_team += '&nbsp;' + team.substring (0, 3);
            }
        }
    else
        {
        baseball = false;
        if (display_team.length == 0)
            display_team = '&nbsp;' + team + '<br>';
        else
            display_team += '&nbsp;' + team;
        display_pitcher = '';
        }
    if (score == '255')
        score = '';

    if (score.length > 0 && isDigit (score.substring (0, 1)))
        bold_score = '<b>' + score + '</b>';
    else
        bold_score = score;

    if (display_score.length == 0)
        display_score = bold_score + '<br>';
    else
        display_score += bold_score;

    if (display_status.length == 0)
        display_status = status + '<br>';
    else
        display_status += status;

    book = 0;
    }
function in_line (value, color)
    {
    if (display_line [book].length == 0)
        br = '<br>'
    else
        br = '';

    if (value.length == 0 || value == ' ')
        cell = '&nbsp;';
    else
        cell = value;

    cell += '&nbsp;';
    if (color == '1' || color =='2')
        display_line [book] += cell + br;
    else
        display_line [book] += cell + br;

    book++;
    }
function string_time (ctime)
    {
    minutes = ctime.substring (3);
    hour = ctime.substring (0, 2);
    if (hour.substring (0,1) == '0')
        game_hour = parseInt (hour.substring (1));
    else
        game_hour = parseInt (hour);

    ampm = 'a';
    if (game_hour >= 12)
        {
        if (game_hour >= 13)
            game_hour -= 12;
        ampm = 'p';
        }
    value = game_hour + minutes + ampm;
    if (game_hour >= 10)
        return (value.substring (0, 2) + ':' + value.substring (2));
    else if (game_hour == 0)
        return ('12:' + value.substring (1));
    else
        return (value.substring (0, 1) + ':' + value.substring (1));
    }
function put_name (league)
    {
        document_write ('<a name="League' + league + '">');
    }
function isDigit (num)
    {
	if (num.length > 1)
	    return false;
	var string="1234567890";
	if (string.indexOf (num) != -1)
	    return true;
	return false;
	}
