function playerComment (empComment) {
	empCm = empComment; var tempCm = ""; var comment = ""; var x; var i = 0;
	for (x=0; x < empCm.length; x++) { if (i == 1) { tempCm = tempCm + empCm.charAt(x); }
		else { 	if (empCm.charAt(x) == '-') { i = 1; } } }
	i = 0;						
	for (x=0; x < tempCm.length; x++) {
		if (i == 1) { comment = comment + (tempCm.charAt(x)).toLowerCase(); }
		else { 	if (tempCm.charAt(x) != ' ' && tempCm.charAt(x) != '-' && i == 0) { comment = comment + (tempCm.charAt(x)).toUpperCase(); i = 1; } }
	}
	document.write(comment);
}//playerComment
			
function playerName(fName, lName) {
	var last = ""; var initial = ""; var x; var i = 0; var z = 0;
	for (x = 0; x < fName.length; x++) { if (i != 1) { if (fName.charAt(x) != ' ') { initial = initial + fName.charAt(x); i = 1; } } }
	last = lName; initial = initial.toUpperCase();
	//special Case for Nene
	if (last == 'Nene') { document.write("Nen&#234;"); }
	else { document.write(initial + '. ' + last); }
}//playerName

function gameStats (hTeam, vTeam, homeTeam, visiTeam, hTeamW, hTeamL, vTeamW, vTeamL, HomeScore, VisiScore) {
	//special case names for links
	if (hTeam == "Silver Stars") hTeam = "starzz"; if (vTeam == "Silver Stars") vTeam = "starzz";
	//lowercase
	var toLowerH = homeTeam.toLowerCase(); var toLowerV = visiTeam.toLowerCase(); var toLowerH2 = hTeam.toLowerCase(); var toLowerV2 = vTeam.toLowerCase(); var isAllStar = 0;
	if (toLowerH == "rookies" || toLowerV == "rookies" || toLowerV2 == "west" || toLowerH2 =="west") { 	isAllStar = 1; }
	
	//variables for scores
	var allStr = ""; var winLogo = ""; var winLink = ""; var winTeam = ""; var losLogo = ""; var losLink = ""; var losTeam = ""; var winScore = 0; var losScore = 0; var winTeamW, winTeamL, losTeamW, losTeamL;
	HomeScore =parseInt(HomeScore); VisiScore = parseInt(VisiScore);

	if (HomeScore > VisiScore) {
		winLogo = toLowerH2; winLink = toLowerH2; winTeam = homeTeam.toUpperCase(); winScore = HomeScore; winTeamW = hTeamW;
		winTeamL = hTeamL; losLogo = toLowerV2; losLink = toLowerV2; losTeam = visiTeam.toUpperCase(); losScore = VisiScore; losTeamW = vTeamW; losTeamL = vTeamL;
	} else { losLogo = toLowerH2; losLink = toLowerH2; losTeam = homeTeam.toUpperCase(); losScore = HomeScore; losTeamW = hTeamW;
		losTeamL = hTeamL; winLogo = toLowerV2; winLink = toLowerV2; winTeam = visiTeam.toUpperCase(); winScore = VisiScore; winTeamW = vTeamW; winTeamL = vTeamL; }
	
	
	if (isAllStar < 1) {
							
	//home team name and score
	allStr = '<table border="0" cellpadding="0" cellspacing="0"><tr><td valign="middle" align="center" class="teamTitles" >';
	allStr += '<a class="teamTitles" target="_parent" href="http://www.nba.com/' + winLink + '/" class="teamLinkTop">';
	// uncomment when win - loss issue is fixed
	//allStr += winTeam + '</a>&nbsp;' + winScore + '&nbsp;<br>(' + winTeamW + ' - ' + winTeamL + ')</td><td valign="middle" align="left" class="teamTitles" >';
	allStr += winTeam + '</a>&nbsp;' + winScore + '&nbsp;</td><td valign="middle" align="left" class="teamTitles" >';
	allStr += '<a target="_parent" href="http://www.nba.com/' + winLink + '/"><img src="http://www.nba.com/media/' + winLogo + '_sm.gif" border=0></a>';
	allStr += '</td><td valign="middle" align="center" class="teamTitles" >';
	//visiting team name and score
	allStr += '&nbsp;&nbsp;&nbsp;<a class="teamTitles" target="_parent" href="http://www.nba.com/' + losLink + '/" class="teamLinkTop">';
	// uncomment when win - loss issue is fixed
	//allStr += losTeam + '</a>&nbsp;' + losScore + '&nbsp;<br>(' + losTeamW + ' - ' + losTeamL + ')</td><td valign="middle" align="left" class="teamTitles" >';
	allStr += losTeam + '</a>&nbsp;' + losScore + '&nbsp;</td><td valign="middle" align="left" class="teamTitles" >';
	//the visiting team logo
	allStr += '<a target="_parent" href="http://www.nba.com/' + losLink + '/"><img src="http://www.nba.com/media/' + losLogo + '_sm.gif" border=0></a></td></tr></table>';
	} else {
	allStr = '<table border="0" cellpadding="0" cellspacing="0"><tr><td valign="middle" align="center" class="teamTitles" >';
	allStr += winTeam;
	// uncomment when win - loss issue is fixed
	//allStr += winTeam + '</a>&nbsp;' + winScore + '&nbsp;<br>(' + winTeamW + ' - ' + winTeamL + ')</td><td valign="middle" align="left" class="teamTitles" >';
	allStr += '&nbsp;' + winScore + '&nbsp;</td><td valign="middle" align="left" class="teamTitles" >';
	allStr += '&nbsp;';
	allStr += '</td><td valign="middle" align="center" class="teamTitles" >';
	//visiting team name and score
	allStr += '&nbsp;&nbsp;&nbsp;' + losTeam;
	// uncomment when win - loss issue is fixed
	//allStr += losTeam + '</a>&nbsp;' + losScore + '&nbsp;<br>(' + losTeamW + ' - ' + losTeamL + ')</td><td valign="middle" align="left" class="teamTitles" >';
	allStr += '&nbsp;' + losScore + '&nbsp;</td><td valign="middle" align="left" class="teamTitles" >';
	//the visiting team logo
	allStr += '&nbsp;';
	allStr += '</td></tr></table>';
	}
	document.write(allStr);
}//gamestats

function gameDate (gDate) {
	var gameDate = new Array(2) ; var gD = ""; var x, i, d;
						
	//initialize gamedate array
	for (x = 0; x <= 2; x++) { gameDate[x] = ""; }
	i = 0;
	for (x = 0; x < gDate.length; x++) { if (gDate.charAt(x) != ' ') { 
			if (gDate.charAt(x) != '/') gameDate[i] = gameDate[i] + gDate.charAt(x);
			else i++;
		}
	}
	gD = gameDate[0]; d = parseInt(gD);
	switch (d) {
		case 1: gameDate[0] = "January";break;
		case 2: gameDate[0] = "February";break;
		case 3: gameDate[0] = "March";break;
		case 4: gameDate[0] = "April";break;
		case 5: gameDate[0] = "May";break;
		case 6: gameDate[0] = "June";break;
		case 7: gameDate[0] = "July";break;
		case 8: gameDate[0] = "August";break;
		case 9: gameDate[0] = "September";break;
		case 10: gameDate[0] = "October";break;
		case 11: gameDate[0] = "November";break;
		case 12: gameDate[0] = "December";break;
	}
	document.write (gameDate[0] + " " + gameDate[1] + ", " + gameDate[2]);
}//gameDate

function PBPDescription (pbp) {
	/* This javascript will separate the play-by-play description into two variables. One for the time (which needed to be
	in bold) and one for the rest of the description. */
	var pbpStr1 = ""; var pbpStr2 = ""; var x, a, b; a = 0; b = 0; 										
	for (x = 0; x < pbp.length; x++) { if (pbp.charAt(x) == '(' && a != 1) { pbpStr1 = pbpStr1 + pbp.charAt(x); b = 1; }
		else { if (pbp.charAt(x) != ')' && b == 1 && a == 0) { pbpStr1 = pbpStr1 + pbp.charAt(x); }
			else { if (pbp.charAt(x) == ')' && b == 1 && a == 0) { pbpStr1 = pbpStr1 + pbp.charAt(x); a = 1; b = 2; }
				else { pbpStr2 = pbpStr2 + pbp.charAt(x); } } }
	}
	document.write ('<td valign="middle" class="dFontBL" width="10" height="15">&nbsp;</td>');
	document.write ('<td valign="top" class="dFontBL" width="40" height="15">' + pbpStr1 + '</td>');
	document.write ('<td valign="top" class="dFontL" width="249" height="15">' + pbpStr2 + ' </td>');
}//PBPDescription

function PBPDescriptionF (pbp) {
	/* This javascript will separate the play-by-play description into two variables. One for the time (which needed to be
	in bold) and one for the rest of the description. THIS IS FOR THE FULL PLAY-BY-PLAY */
	var pbpStr1 = ""; var pbpStr2 = ""; var x, a, b; a = 0;  b = 0;
										
	for (x = 0; x < pbp.length; x++) { if (pbp.charAt(x) == '(' && a != 1) { pbpStr1 = pbpStr1 + pbp.charAt(x); b = 1; }
		else { if (pbp.charAt(x) != ')' && b == 1 && a == 0) { pbpStr1 = pbpStr1 + pbp.charAt(x); }
			else { if (pbp.charAt(x) == ')' && b == 1 && a == 0) { pbpStr1 = pbpStr1 + pbp.charAt(x); a = 1; b = 2; }
				else { pbpStr2 = pbpStr2 + pbp.charAt(x); } } }
	}
	document.write ('<td valign="middle" class="dFontBL" width="10" height="15">&nbsp;</td>');
	document.write ('<td valign="top" class="dFontBL" width="40" height="15">' + pbpStr1 + '</td>');
	document.write ('<td valign="top" class="dFontL" width="550" height="15">' + pbpStr2 + ' </td>');
}//PBPDescriptionF

function teamCapsFirstLetter (teamName, teamLink) {
	/* uppercase for the Team name */
	var teamCaps = teamName.toUpperCase(); var contentStr = "";
	contentStr += '<table border="0" cellpadding="0" cellspacing="0">';
	contentStr += '<tr><td valign="middle" align="left" class="teamTitlesTwo">';
	contentStr += '<img src="http://www.nba.com/images/yellow_pointers.jpg">';
	contentStr += '</td><td valign="middle" align="left">';
	contentStr += '<a class="teamTitlesTwo" target="_parent" href="http://www.nba.com/' + teamLink + '/">' + teamCaps + '</a>';
	contentStr += '</td></tr></table>';
	document.write (contentStr);
}//teamCapsFirstLetter

function remZero (perc1, perc2, perc3) {
	/* this js script removes the initial zero digit from the percentages data pulled from the db */
	var perc = new Array(2); var strP = new Array(2); var x, i, c;
	perc[0] = perc1; perc[1] = perc2; perc[2] = perc3;
	//initialize
	for (x=0; x <= 2; x++) { strP[x] = ""; }
	for (x=0; x <= 2; x++) {
		c = 0;
		for (i = 0; i < perc[x].length; i++) {
			if (perc[x].charAt(i) != ' ') {
				if (perc[x].charAt(i) != '0') strP[x] = strP[x] + perc[x].charAt(i);
					else if (c == 1) strP[x] = strP[x] + perc[x].charAt(i);
						else c = 1;
			}
		}
	}
	document.write ('<td class="dFont" valign="middle" align="center" width="39">' + strP[0] + '</td>');
	document.write ('<td class="dFont" valign="middle" align="center" width="1"><img src="http://cache.nba.com/media/nbav2/blank.gif"></td>');
	document.write ('<td class="dFont" valign="middle" align="left" width="39">&nbsp;' + strP[1] + '</td>');
	document.write ('<td class="dFont" valign="middle" align="center" width="1"><img src="http://cache.nba.com/media/nbav2/blank.gif"></td>');
	document.write ('<td class="dFont" valign="middle" align="center" width="39">' + strP[2] + '</td>');
}//remZero

function gameLocation (gameLoc) {
	/* this will create a line break for a 2-line gamelocation text. Indicator for the line break is after the comma */
	var venue = ""; var x, i; i = 0;
	for (x = 0; x < gameLoc.length; x++) { 	if (gameLoc.charAt(x) != ',') { venue = venue + gameLoc.charAt(x); }
		else { if (i != 1) { i = 1; venue = venue + ",<br>"; }
			else { venue = venue + gameLoc.charAt(x); } }
	}
	document.write (venue);
}//gameLocation

function gameAttendance (attendance, att) {
	/* this script will put a comma for the game attendance figure */
	var attx = ""; var x, i;	
	if (attendance >= 1000 && attendance <= 9999) i = 1;
		else if (attendance >= 10000 && attendance <=99999) i = 2;
			else i = 0;
		for (x = 0; x < att.length; x++) {
			if (att.charAt(x) != ' ') {
				if (i == 1 && x == 1) attx = attx + "," + att.charAt(x);
				else if (i == 2 && x == 2) attx = attx + "," + att.charAt(x);
			else attx = attx + att.charAt(x);
		}
	}
	document.write ("Attendance:&nbsp;" + attx);
}//gameAttendance

function teamCheck (teamName, fot) {
	var x, i, tName; fot = fot.toLowerCase(); teamName = teamName.toLowerCase();
	if (fot == 'true') { if (teamName == "timberwolves") teamName = "t'wolves"; if (teamName == "trail blazers") teamName = "blazers"; if (teamName == "mavericks") teamName = "mavs"; }
	i = 0; tName = "";
	for (x=0; x < teamName.length; x++) { if (i == 1) { tName = tName + teamName.charAt(x); }
		else { 	tName = tName + (teamName.charAt(x)).toUpperCase(); i = 1; }
	}
	document.write (tName);
}//treamCheck

function sbLink (sbStatus, sbPath) {
	var gameStatus = sbStatus;
	//var gamePath = sbPath;
	var temp = ""; var x, y, temp2;
	for (x = 0; x < gameStatus.length; x++) { if (gameStatus.charAt(x) != ' ') { 	temp = temp + gameStatus.charAt(x); } }
	temp = temp.toLowerCase(); y = 0;
	if (temp == "final") { document.write ('<td colspan="2" valign="top" align="left" class="dFontS" height="8">&nbsp;<a target="_top" href="http://www.nba.com' + sbPath + 'boxscore.html" class="dFontS">' + sbStatus + '</a></td>'); }
	else {
		gameStatus = temp; temp = "";
		for (x = 0; x < gameStatus.length; x++) {
			temp = (gameStatus.charAt(x)).toLowerCase();
			if (temp == 'p' || temp == 'a') {
				temp2 = (gameStatus.charAt(x+1)).toLowerCase();
				if (temp2 == 'm') { y = 1; document.write ('<td colspan="2" valign="top" align="left" class="dFontS" height="8">&nbsp;<a target="_top" href="http://www.nba.com' + sbPath + 'preview.html" class="dFontS">' + sbStatus + '</a></td>'); }
			}
			else {
				if  (temp == 'q') {
					temp2 = (gameStatus.charAt(x+1)).toLowerCase(); temp2 = temp2 + (gameStatus.charAt(x+2)).toLowerCase(); temp = temp + temp2;
					if (temp == "qtr") { document.write ('<td colspan="2" valign="top" align="left" class="dFontS" height="8">&nbsp;<a target="_top" href="http://www.nba.com' + sbPath + 'livestats.html" class="dFontS">' + sbStatus + '</a></td>'); y = 1; }
				}
				else {
					if (temp == 'o') {
						temp2 = (gameStatus.charAt(x+1)).toLowerCase(); temp = temp + temp2;
						if (temp == 'ot') { document.write ('<td colspan="2" valign="top" align="left" class="dFontS" height="8">&nbsp;<a target="_top" href="http://www.nba.com' + sbPath + 'livestats.html" class="dFontS">' + sbStatus + '</a></td>'); y = 1; }
					}
					else {
						if (temp == 'h') {// half time
							temp2 = (gameStatus.charAt(x+1)).toLowerCase(); temp2 = temp2 + (gameStatus.charAt(x+2)).toLowerCase(); temp = temp + temp2;
							if (temp == 'hal') { document.write ('<td colspan="2" valign="top" align="left" class="dFontS" height="8">&nbsp;<a target="_top" href="http://www.nba.com' + sbPath + 'livestats.html" class="dFontS">' + sbStatus + '</a></td>'); y = 1; }
						}
						/*else {
							if (temp == 'e') { //end of a quarter
								temp2 = (gameStatus.charAt(x+1)).toLowerCase();
								temp2 = temp2 + (gameStatus.charAt(x+2)).toLowerCase();
								temp = temp + temp2;
								if (temp == 'end') {
									document.write ('<td colspan="2" valign="top" align="left" class="dFontS" height="8">&nbsp;<a target="_top" href="http://www.nba.com' + sbPath + 'livestats.html" class="dFontS">' + sbStatus + '</a></td>');
									y = 1;
								}
							}
						}*/
					}
				}
				
			}
		}
		if (y == 0) { document.write ('<td colspan="2" valign="top" align="left" class="dFontS" height="8">&nbsp;<a target="_top" href="http://www.nba.com' + sbPath + 'livestats.html" class="dFontS">' + sbStatus + '</a></td>'); }
	}
}//sbLink

function gameStatusSB (sText, sTime) {
	sText = sText.toUpperCase(); document.write(sText + ' ' + sTime);
}//gameStatusSB

function sbGameDate (gDate) {
	var x, i, gD; i = 0; gD = "";
	for (x = 0; x < gDate.length; x++) { if (gDate.charAt(x) == '/') { 	i++; }
		if (i < 2) { gD = gD + gDate.charAt(x); }
	}
	document.write (gD);
}//sbGameDate

function gameStatusText (gsText) {
	var v, x, sT; sT= ""; v = 0;
	for (x =0; x < gsText.length; x++) { 
		if ((gsText.charAt(x) == 'p' || gsText.charAt(x) == 'a') && gsText.charAt(x+1) == 'm') { v++; sT = sT + gsText.charAt(x) + gsText.charAt(x+1); }
		if (v ==0) { sT = sT + gsText.charAt(x); }
	}
	document.write(sT);
}

function liveStatsTeamStatistics (hTeam, hFGPL, hTTPL, hFTPL, hTTO, hFBP, hBLD, hUPTS, hPTIP, vTeam, vFGPL, vTTPL, vFTPL, vTTO, vFBP, vBLD, vUPTS, vPTIP) {
// this function is for the team statistics inside livestats pages
	var x = 0; var str = new Array ("", "FG%", "3PT%", "FT%", "Turnovers", "Fast Break", "Biggest Lead", "Unanswered Pts", "Points in the Paint");
	var hTStats = new Array (hTeam, hFGPL, hTTPL, hFTPL, hTTO, hFBP, hBLD, hUPTS, hPTIP); var vTStats = new Array (vTeam, vFGPL, vTTPL, vFTPL, vTTO, vFBP, vBLD, vUPTS, vPTIP);
	for (x = 0; x <= 8; x++) {
		if (x == 0) { document.write('<tr bgcolor="#8BACDF" valign=middle>'); document.write('<td width=150 class=dFontL height=20>&nbsp;</td>'); }
		else { document.write('<tr valign=middle>'); document.write('<td width=150 class=dFontBR height=20>' + str[x] + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>'); }
		document.write('<td bgcolor="#ffffff" width=1 height=20><img height=1 src="http://www.nba.com/media/nbav2/blank.gif"></td>');
		document.write('<td width=71 class=dFontB height=20>' + hTStats[x] + '</td>');
		document.write('<td bgcolor="#ffffff" width=1 height=20><img height=1 src="http://www.nba.com/media/nbav2/blank.gif"></td>');
		document.write('<td width=71 class=dFontB height=20>' + vTStats[x] + '</td>');
		document.write('</tr>');
	}
	
}//end liveStatsTeamStatistics

function openCourtSideLS(codeGame) {
// this is for the courtside live flash app pop-up
	/* window.open( 'http://www.nba.com/courtsidelive/csl_popup.html?game='+codeGame,'CourtsideLive','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,screenX=12,screenY=12,top=12,left=12,copyhistory=no,width=410,height=500' ); */
}

function open_window_ex(url, title, height, width, options) {
    var path = url;
    if( url.search(/^http:/) == -1 ) {
        path = "/popups/" + url;
    } else {
        var nbaDomain = new RegExp("/^http:\/\/www.nba.com\/([.*]*)/");
        var result = url.match(nbaDomain);
        if( result != null ) {
            path = "/popups/" + result[1];
        } else {
            path = url;
        }
    }
    var opts = '';
	if(options == null || options == "null")
		opts = 'toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=yes, resizable=yes';
    else
		opts = options;
		
	opts += ',width=' + width;
    opts += ',height=' + height;
    mywin=window.open(path,title,opts);
}

function nbaVideo(src,video){
src = src + "%26video%3D" + video
tokenPath = "/broadband/Connection.jsp?dest=" + src
		window.open(tokenPath,"BroadbandWin", "width=752,height=583,top=100,left=200,alwaysRaised=yes,toolbar=0,directories=0,menubar=0,status=0,resizable=no,location=0,scrollbars=0,copyhistory=0");
}