/*******************************************************
DataProcessor Object:

- formats specific data values for proper display
*******************************************************/
	 
DataProcessor = function(){}

DataProcessor.prototype.getGameLocation = function(n){ return n.game_location; }
 
DataProcessor.prototype.getAwayTeam = function(n){ 
	var output = n.away.full;
	if (output == "Diamondbacks") output = "D-backs";
	if (n.away.split == true) output += " (ss)"; 
	return output;
}

DataProcessor.prototype.getHomeTeam = function(n){ 
	var output = n.home.full;
	if (output == "Diamondbacks") output = "D-backs";
	if (n.home.split == true) output += " (ss)"; 
	return output;
}

DataProcessor.prototype.getAwayProbable = function(n){
	var output = "";
	if (n.away.probable != null) output += "<a href='/team/player.jsp?player_id=" + n.away.probable_id + "' title='" + n.away.probable + " stats page'>" + n.away.probable + " (" + n.away.probable_stat + ")</a>";
	else output = "TBD";
	return output;
}

DataProcessor.prototype.getHomeProbable = function(n){
	var output = "";
	if (n.home.probable != null) output += "<a href='/team/player.jsp?player_id=" + n.home.probable_id + "' title='" + n.home.probable + " stats page'>" + n.home.probable + " (" + n.home.probable_stat + ")</a>";
	else output = "TBD";
	return output;
}

DataProcessor.prototype.getWinningPitcher = function(n){
	var output = "";
	if (n.pitcher.win != null) output = "<a href='/team/player.jsp?player_id=" + n.pitcher.win_id + "' title='" + n.pitcher.win + " stats page'>" + n.pitcher.win + " (" + n.pitcher.win_stat + ")</a>";
	else output = "&nbsp;";
	return output;
}

DataProcessor.prototype.getLosingPitcher = function(n){
	var output = "";
	if (n.pitcher.loss != null) output = "<a href='/team/player.jsp?player_id=" + n.pitcher.loss_id + "' title='" + n.pitcher.loss + " stats page'>" + n.pitcher.loss + " (" + n.pitcher.loss_stat + ")</a>";
	else output = "&nbsp;";
	return output;
}

DataProcessor.prototype.getAudio = function(n){
	return "<a href='/mediacenter/index.jsp?ymd=" + setGameDate(n.game_time) + "' title='Listen to game'><img src='/images/icons/audio.gif' with='15' height='12' align='absmiddle'/></a>";
}

DataProcessor.prototype.getMLBTV = function(n){
	var output = "";
	
	// Regular Season games
	if (n.game_type == "R" || n.game_type == "D" || n.game_type == "L" || n.game_type == "W") {
	
		if (n.game_status == "S" || n.game_status == "P") output = "<a href='/mlb/subscriptions/mlbtv.jsp' title='Watch the game'><img src='/images/icons/mlbtv.gif' with='15' height='12' align='absmiddle'/></a>";
		else if (n.game_status == "C" || n.game_status == "PO") output = "&nbsp;";
		else output = "<a href='/mediacenter/index.jsp?ymd=" + setGameDate(n.game_time) + "' title='Watch the game'><img src='/images/icons/mlbtv.gif' with='15' height='12' align='absmiddle'/></a>";
	
	// Spring or Exhibition games
	} else if (n.game_type == "S" || n.game_type == "E") {
	
		if (n.mlbtv == true) {
			if (n.game_status == "S" || n.game_status == "P") output = "<a href='/mlb/subscriptions/mlbtv.jsp' title='Watch the game'><img src='/images/icons/mlbtv.gif' with='15' height='12' align='absmiddle'/></a>";
			else if (n.game_status == "C" || n.game_status == "PO") output = "&nbsp;";
			else output = "<a href='/mediacenter/index.jsp?ymd=" + setGameDate(n.game_time) + "' title='Watch the game'><img src='/images/icons/mlbtv.gif' with='15' height='12' align='absmiddle'/></a>";
		} else output = "&nbsp;";
	
	} else output = "&nbsp;";
	
	/*
	if (n.game_status == "F") { 
		if ((n.game_type == "S" || n.game_type == "E") && n.mlbtv == false) output = "&nbsp;";
		else output = "<a href='/mediacenter/index.jsp?ymd=" + setGameDate(n.game_time) + "' title='Watch the game'><img src='/images/icons/mlbtv.gif' with='15' height='12' align='absmiddle'/></a>";
	}
	else if (n.game_status == "I" && n.mlbtv == true) output = "<a href='/mlb/subscriptions/mlbtv.jsp' title='Watch the game'><img src='/images/icons/mlbtv.gif' with='15' height='12' align='absmiddle'/></a>";
	else output = "&nbsp;";
	*/
	
	return output;
}

DataProcessor.prototype.getTickets = function(n){
	var output = "";
	if (n.home.tickets == null) output = "";
	else output = "<a href='" + n.home.tickets + "' title='Buy tickets'>Buy&nbsp;<img src='/images/schedule/icon_ticket.gif' width='13' height='13' align='absmiddle'/></a>";
	return output;
}

DataProcessor.prototype.getGameTimeResult = function(n){
	var output = "";
	var gameTime = setGameTime(n.game_time,n.game_time_offset_eastern);
	var homeCode = (n.home.code==null) ? n.home.full : n.home.code.toUpperCase();
	var awayCode = (n.away.code==null) ? n.away.full : n.away.code.toUpperCase();
	var gamer = (n.game_type == "S" || n.game_type == "E") ? n.home.recap : n.wrapup;	
	
	if (gameTime == "3:33 a.m.") gameTime = "TBD";
	if (n.game_status == "F" || n.game_status == "GO") { // if game is final
		
		if (gamer != null) {
			if (parseInt(n.home.result) > parseInt(n.away.result)) output = "<a href=\"" + gamer + "\" title='Game wrapup'>" + homeCode + " " + n.home.result + ", " + awayCode + " " + n.away.result + "</a>";
			else output = "<a href=\"" + gamer + "\" title='Game wrapup'>" + awayCode + " " + n.away.result + ", " + homeCode + " " + n.home.result + "</a>";
		}
		else {
			if (parseInt(n.home.result) > parseInt(n.away.result)) output = homeCode + " " + n.home.result + ", " + awayCode + " " + n.away.result;
			else output = awayCode + " " + n.away.result + ", " + homeCode + " " + n.home.result;
		} 
	
	} 
	else if (n.game_status == "C") output = "Cancelled"; 
	else if (n.game_status == "PO") output = "Postponed"; 
	else if (n.game_status == "D") output = "Delayed"; 
	else if (n.game_status == "S") output = "Suspended"; 
	else if (n.game_status == "I") { // if game is in progress
		if (n.game_type == "S" || n.game_type == "E") output = "<a href='/mlb/scoreboard/index.jsp?ymd=" + setGameDate(n.game_time) + "' title='Scoreboard'>In progress&nbsp;<img src='/mlb/images/audio/gda_2003/icon_live.gif' width='10' height='10' alt='LIVE' border='0' align='absmiddle'/></a>"; 
		else output = "<a href=\"javascript:launchGameday({gid:\'" + n.game_id.replace(/\//g,'_').replace(/-/g,'_') + "\'});\" title='Gameday'>In progress&nbsp;<img src='/mlb/images/audio/gda_2003/icon_live.gif' width='10' height='10' alt='LIVE' border='0' align='absmiddle'/></a>"; 
	}
	else if (n.game_status == "P") { // if game is in pre-game mode
		if (n.game_dh != null) {
			output = "GM " + n.game_num + ": " + gameTime;
			if (n.game_num == "2") output = "GM 2: " + gameTime;
		}
		else { 
			if ((n.preview != null) && (n.preview != "")) output = "<a href='" + n.preview + "' title='Game preview'>" + gameTime + "</a>";
			else output = gameTime;  
		}
	}
	else { // if all else fails
		output = gameTime; 
	}
	return output;
}



DataProcessor.prototype.getGameId = function(n){ 
 var game = n.game_id;
 var game_d = game.replace(/\//g, "_" );
 var gameID = game_d.replace(/-/g, "_" );
 var gameday_url = "<a href=\"javascript:void(0)\" onclick=\"launchGameday('" + gameID + "')\"><img src=\"/images/gameday/launchpage/base.gif\"</a>";
 gameday_url.replace(/\//g, "_" );
 gameday_url.replace(/-/g, "_" );
 var output;
 if (n.game_status == "F" || n.game_status == "D"|| n.game_status == "GO" || n.game_status == "IP" || n.game_status == "W") { 
		output = gameday_url;
	}
	else if (n.game_status == "I") output = gameday_url;
	else if (n.game_status == "P") output = gameday_url;
	else output = "&nbsp;";

 return output;
}