//
//   copyright  ManagerZone AB 2002-2008
//

var plinks;
var hasLambda = 0;
var tr_links;
var tr_bids_str;
var clubMember = 0;
var p_isRetiredPlayersPage;
var p_isShortListPage;

var playerType = 1;

str = "##mz##";
str = str.replace(/##([^#]*)##/gi, function(str, p1, p2) { return p1; } );
if (str.substring(0, 8) == "function") {
	hasLambda = 0;
}
else {
	hasLambda = 1;
}


function SinglePlayerMonitorHtml(i, national)
{
	plinks = "";
	tr_links = "";
	p = theMonitorPlayers[i];
	tr_link = "<img src=\"img/sell.gif\" border=\"0\" style=\"-moz-opacity:0.60; filter:alpha(opacity=60);\">";
	if (p.type == "Buy" && p.my_team_id != p.bidder_team_id) {
		var amount = 0;
		if (p.tr_lastbid == 0)
		amount = p.tr_startbid;
		else
		amount = p.tr_lastbid*1.05;

		amount = exchange(50,
		p.currency_id,
		amount,
		exchange_rates);

		tr_link = "<a target=_parent href=\"javascript: "+ p.buy_icon +"\"><img src=\"img/sell.gif\" width=23 height=21 border=\"0\"></a>";
	}

	eval("template = p_playerMonitor"+ p.type +"Template");

	return doTheReplace(template, p);
}



function getAltTitle(str)
{
	return " alt='" + str + "' title='" + str + "' ";
}

//var

//this removes the ##....##
function doTheReplace(template, p)
{
	if (hasLambda == 1) {
		template = template.replace(/##([^#]*)##/gi, function(str, p1, p2) { return eval(p1); } );
	}
	else {
		var re = /##([^#]*)##/gi;
		var reArr = re.exec(template);
		var varn;
		var theVal;
		while (reArr) {
			varn = reArr[0];
			theVal = eval(reArr[1]);
			template = template.replace(varn, theVal);
			re = /##([^#]*)##/gi;
			reArr = re.exec(template);
		}
	}
	return template;
}

function monitorShowHide(buysell)
{
	visible = (document.getElementById("monitordiv00").style.display == "block" || document.getElementById("monitordiv10").title == "") ? 0 : 1;
	if (buysell != visible) {
		visible = (document.getElementById("monitordiv"+buysell+"0").title != "") ? buysell : visible;
		//visible = buysell;
	}
	for (var i=0; i<2; i++) {
		for (var j=0; j<5; j++) {
			mdiv = "monitordiv"+i+""+j;
			if (i == visible && document.getElementById(mdiv).title != "")
			document.getElementById(mdiv).style.display = "block";
			else if (document.getElementById(mdiv).title != "No")
			document.getElementById(mdiv).style.display = "none";
		}
	}
}

function renderPlayerHtmlUpdate(national)
{
	// Render monitored players
	if (document.getElementById("monitorDiv")) { //IF label: 1
		visible = (document.getElementById("monitordiv00").style.display == "block") ? 0 : 1;
		var cntMonitor = new Array(0,0);
		for (var i=0; i<theMonitorPlayers.length; i++) {
			pls_monitor = "";
			type = (theMonitorPlayers[i].type == "Buy") ? 0 : 1;
			mdiv = "monitordiv"+type+""+cntMonitor[type];
			if (cntMonitor[type] < 5 && document.getElementById(mdiv)) {
				title_old = document.getElementById(mdiv).title;
				pls_monitor = SinglePlayerMonitorHtml(i, national);
				if (i == visible)
				document.getElementById(mdiv).style.display = "block";
				document.getElementById(mdiv).title = theMonitorPlayers[i].title;
				document.getElementById(mdiv).innerHTML = pls_monitor;
				if (title_old != "" && title_old != theMonitorPlayers[i].title) {
					// Only update when changed content
					str = (type == 0) ? "Buy" : "Sell";
				}
				cntMonitor[type]++;
			}
		}
		var mostof = (cntMonitor[0] > 0 && cntMonitor[0] >= cntMonitor[1]) ? 0 : 1;
		document.getElementById("nrBuy").innerHTML = p_strmonitorBuy +" ("+ cntMonitor[0] +")";
		document.getElementById("nrSell").innerHTML = p_strmonitorSell +" ("+ cntMonitor[1] +")";
		// Reset unused elements
		for (var i=0; i<2; i++) {
			for (var j=cntMonitor[i]; j<5; j++) {
				mdiv = "monitordiv"+i+""+j;
				if (j == -1) {
					document.getElementById(mdiv).innerHTML = "<center><strong>"+strNoPlayers+"</strong></center>";
					document.getElementById(mdiv).style.display = "block";
					document.getElementById(mdiv).title = "No";
				}
				else {
					document.getElementById(mdiv).innerHTML = "";
					document.getElementById(mdiv).style.display = "none";
					document.getElementById(mdiv).title = "";
				}
			}
		}
		document.getElementById("monitorDiv").style.height = 40 + (cntMonitor[mostof] * 43);
		visible = (document.getElementById("monitordiv"+visible+"0").title != "") ? visible : Math.abs(visible-1);
		monitorShowHide(visible);
	} //IF label: 1

	// Render transfer players
	if (playerType == 2 && $('#players_container').length ) {

		if ($("#players_container #errormsg").length && error_content == "") {
			$("#players_container #errormsg").empty();
			$("#players_container #errormsg").hide();
		}

		for (var i=0; i<20; i++) {
			pdiv = "playerdiv"+i;
			pls = "";
			title = "";
			if (i<thePlayers.length) {
				pls += ""+ thePlayers[i].toHTML(national);
				title = thePlayers[i].title;
			}
			else if (i==0) {
				pls += "<div class=\"player_loading_div\">" + strNoPlayersFound + "</div>";;
				title = " ";
			}

			if ( title != "" && $('#players_container #' + pdiv).attr("title") != title ) {
				$('#players_container #' + pdiv).html(pls);
				$('#players_container #' + pdiv).attr("title", title);
			}
			if (pls == "") {
				$('#players_container #' + pdiv).hide();
			}
			else {
				$('#players_container #' + pdiv).show();
			}
		}
	}

}

function renderPlayerAjaxHtml(national)
{
	if ( playerType > 0 ) {
		if ( $('#players_container').length ) {
			if ( playerType == 2 && $('#players_container div').length < 20 ) {
				renderPlayerHtml(national);
			}
			else {
				renderPlayerHtmlUpdate(national);
			}
		}
		else {
			renderPlayerHtmlUpdate(national);
		}
	}
}

function clearTransferSearch()
{
	if ( playerType > 1 && $("#players_container").length ) {
		ply = "<div class=\"player_loading_div\">" + strWaitForPlayers + "...</div>";
		$("#players_container").html(ply);
	}
}

function renderMonitorPlayerHtml()
{
	if (document.getElementById('monitorDiv') && theMonitorPlayers != undefined) {
		pls2 = "";
		for (j=0; j<2; j++) {
			mdivmain = "monitorMain"+j;
			pls2 += "<div id=\""+ mdivmain +"\" name=\""+ mdivmain +"\">";
			pls2 += "<table width='100%' cellspacing=0 cellpadding=0 border=0>";
			str = (j == 0) ? "Buy" : "Sell";
			pls2 += "<tr class=\"seriesHeader\"><td align='center' class=\"subheader\" onClick=\"monitorShowHide("+j+");\" style=\"cursor: pointer;\">";
			pls2 += "<strong><div id=\"nr"+str+"\" name=\"nr"+str+"\">"+ eval("p_strmonitor"+str) +"</div></strong></td></tr>";
			pls2 += "<tr><td height=1 bgcolor=black></td></tr><tr><td valign=\"top\">";
			pls = "";
			for (var i=0; i<5; i++) {
				mdiv = "monitordiv"+j+""+i;
				ply = "";
				if (i==0) {
					ply = "<table width='100%'><tr><td align='center'><i>"+strWaitForPlayers+"...</i></td></tr></table>";
					pls += "<div id=\""+ mdiv +"\" name=\""+ mdiv +"\" title=\"\" style=\"display:block;\">"+ ply +"</div>";
				}
				else
				pls += "<div id=\""+ mdiv +"\" name=\""+ mdiv +"\" title=\"\" style=\"display:none;\">"+ ply +"</div>";
			}
			pls2 += pls+"</td></tr></table></div>";
		}
		layer_write("monitorDiv", pls2);
		// Set default to show bayig players
		monitorShowHide(0);
	}
}

function replacePlayerPlaceholder( iframeref, index )
{
	lastRenderedPlayer = index;

	renderedPlayerIndexes[thePlayers[index].player_id] = 1;
	var newdiv = iframeref.document.createElement("div");
	newdiv.innerHTML = thePlayers[index].toHTML(lastnational);

	iframeref.document.getElementById('content').replaceChild(newdiv, iframeref.document.getElementById("thePlayers_"+index));
	newdiv.id = "thePlayers_"+index;
}

var renderedPlayerIndexes = new Array();
var lastRenderedPlayer = 0;
var lastnational = null;
function renderPlayerHtml(national) {
	lastnational = national;
	
	if ($("#players_container").length) {
		if (playerType == 1 && thePlayers != undefined) {
			var pls = "";
			for (var i=0; i<thePlayers.length; i++) {
				pls += "<div id=thePlayers_"+i+" class=\"playerContainer\">"+thePlayers[i].toHTML(national)+"</div>";
				renderedPlayerIndexes[thePlayers[i].player_id] = 1;
				lastRenderedPlayer = i;
			}
			$("#players_container").html(pls);
		}
		else if (playerType > 1) {
			if ($("#players_container div").length < 20) {
				pls = "";
				if ( typeof(error_content) != "undefined" && error_content != "") {
					pls += "<div id=\"errormsg\" name=\"errormsg\" class=\"errorMsgDiv\">"+ error_content +"</div>";
				}
				for (var i=0; i<20; i++) {
					pdiv = "playerdiv" + i;
					ply = "";
					if (i==0)
						ply = "<div class=\"player_loading_div\">" + strWaitForPlayers + "...</div>";
					pls += "<div id=\""+ pdiv +"\" name=\""+ pdiv +"\">"+ ply +"</div>";
				}
				$("#players_container").html(pls);
				
				if (playerType == 2)
					setTimeout("renderPlayerHtmlUpdate("+national+");",1500);
				else
					setTimeout("renderPlayerHtml("+national+");",5000);
			}
			else {
				renderPlayerHtmlUpdate(national);
			}
		}
	}
	
	var end = new Date();
}

var scr_step;
var scr_obj;
var scr_cur_y = 0;
var scr_end_y;
var scr_time_per_step = 10;
var scr_steps;
var bookmarkId = "thePlayers_0";

function scrollToPlayer(ply_idx) {
	$.scrollTo($("#thePlayers_" + ply_idx), 500);
}

function Player(player_id,
                team_id,
                national_team_id,
                national_shirt_no,
                national_shirtpricolor,
                national_shirtseccolor,
                national_shirtpattern,
                nationalU21_team_id,
                nationalU21_shirt_no,
                nationalU21_shirtpricolor,
                nationalU21_shirtseccolor,
                nationalU21_shirtpattern,
                team_name,
                player_name,
                t_salary,
                retiring,
                retiring_date,
                tc_cur_season,
                status,
                origin_country_id,
                origin_country_shortname,
                origin_country_name,
                origin_country_translated_name,
                skills,
                flags,
                tr_bids,
                attributes,
                stats,
                shirtnr,
                show_on_tactics,
                value,
                salary,
                age,
                birthseason,
                ontransfer,
                sell,
                transferarray,
                shirtpricolor,
                shirtseccolor,
                shirtpattern,
                junior, 
                shortlist,
                currency_suffix,
                currency_id,
                mz_currency_id,
                injury,
                training_camp,
                warning,
                training_id)
{

	if ( typeof(player_id) == "undefined" )	//fix to remove the overload errors while parsing the subclasses and nothing is passed to the constructor
	return;

	this.player_id = player_id;
	this.team_id = team_id;
	this.team_name = team_name;
	this.player_name = player_name;

	this.strsalary = p_strsalary;
	this.digitalGoodsArray = null;

  this.t_salary = t_salary;
  this.retiring = retiring;
  this.retiring_date = retiring_date;
  this.tc_cur_season = tc_cur_season;
  this.status = status;
  this.origin_country_id = origin_country_id;
  this.origin_country_shortname = typeof(origin_country_shortname) != "undefined" ? origin_country_shortname.toLowerCase() : "";
  this.origin_country_name = origin_country_name;
  this.origin_country_translated_name = origin_country_translated_name;
  this.skills = skills;
  this.flags = flags;
  this.tr_bids = tr_bids;
  this.attributes = attributes;
  this.stats = stats;
  this.shirtnr = shirtnr;
  this.show_on_tactics = show_on_tactics;  //Deprecated?
  this.value = value;
  this.salary = salary;
  this.age = age;
  this.birthseason = birthseason;
  this.junior = junior;
  this.juniorstr = this.junior ? p_strjunior : "";
  this.ontransfer = ontransfer;
  this.sell = sell;
  this.currency_suffix = currency_suffix;
  this.currency_id = currency_id;
  this.mz_currency_id = mz_currency_id;
	this.training_boost = new Array();

	if (status == "employed") {
		this.appearanceButton = typeof(p_appearanceButton) != "undefined" ? p_appearanceButton : "";
		if (typeof(p_changeNameButton) != "undefined" && this.junior) {
			this.changeNameButton = p_changeNameButton;
		}
		else {
			this.changeNameButton = "";
		}
	}
	else {
		this.appearanceButton = "";
		this.changeNameButton = "";
	}

	this.shortlist = shortlist;
	if (this.ontransfer) {
		this.value  = exchange(this.mz_currency_id,
		this.currency_id,
		this.value,
		exchange_rates);
		this.salary = exchange(this.mz_currency_id,
		this.currency_id,
		this.salary,
		exchange_rates);
	}

	this.value_display = presentMoney(this.value);
	this.salary_display = presentMoney(this.salary);

	this.exchanged_value = exchange(this.currency_id,
	user_currency_id,
	this.value,
	exchange_rates);
	this.exchanged_value_display = presentMoney(this.exchanged_value);

	this.exchanged_salary = exchange(this.currency_id,
	user_currency_id,
	this.salary,
	exchange_rates);
	this.exchanged_salary_display = presentMoney(this.exchanged_salary);

	this.tr_value =  exchange(this.mz_currency_id,
	this.currency_id,
	value,
	exchange_rates);
	this.tr_value_display = presentMoney(this.tr_value);

	this.tr_salary =  exchange(this.mz_currency_id,
	this.currency_id,
	salary,
	exchange_rates);
	this.tr_salary_display = presentMoney(this.tr_salary);



	this.tr_exchanged_value = exchange(this.currency_id,
	user_currency_id,
	this.tr_value,
	exchange_rates);
	this.tr_exchanged_value_display = presentMoney(this.tr_exchanged_value);

	this.tr_exchanged_salary = exchange(this.currency_id,
	user_currency_id,
	this.tr_salary,
	exchange_rates);
	this.tr_exchanged_salary_display = presentMoney(this.tr_exchanged_salary);

	this.national_team_id = national_team_id;
	this.national_shirt_no = national_shirt_no;
	this.national_shirtpricolor = national_shirtpricolor;
	this.national_shirtseccolor = national_shirtseccolor;
	this.national_shirtpattern = national_shirtpattern;

	this.nationalU21_team_id = nationalU21_team_id;
	this.nationalU21_shirt_no = nationalU21_shirt_no;
	this.nationalU21_shirtpricolor = nationalU21_shirtpricolor;
	this.nationalU21_shirtseccolor = nationalU21_shirtseccolor;
	this.nationalU21_shirtpattern = nationalU21_shirtpattern;

	this.overbid = '';
	if (transferarray && transferarray.length != 0) {
		this.tr_startbid = transferarray[0];

		this.tr_exchanged_startbid_display = presentMoney(exchange(this.mz_currency_id,
		user_currency_id,
		this.tr_startbid,
		exchange_rates));

		this.tr_lastbid = transferarray[1];
		this.tr_exchanged_lastbid = exchange(this.mz_currency_id,
		user_currency_id,
		this.tr_lastbid,
		exchange_rates);
		this.tr_exchanged_lastbid_display = presentMoney(this.tr_exchanged_lastbid);

		this.tr_enddate = transferarray[2];
		this.bidderlink = transferarray[3];
		if (transferarray[4].length != 0)
		this.tr_bidder = '('+transferarray[4]+')';
		else
		this.tr_bidder = '';
		this.tr_biddername = transferarray[5];

		if (this.tr_exchanged_lastbid >= (this.tr_exchanged_value*5))
		this.overbid = '<img src="img/exclamation_mark.gif" width=4 height=11>';
		this.tr_startbid_display = presentMoney(exchange(this.mz_currency_id,
		this.currency_id,
		this.tr_startbid,
		exchange_rates));
		this.tr_lastbid_display = presentMoney(exchange(this.mz_currency_id,
		this.currency_id,
		this.tr_lastbid,
		exchange_rates));
	}
	if (this.attributes[2] == 'r') {
		this.strside = p_str_right;
	}
	else if (this.attributes[2] == 'l') {
		this.strside = p_str_left;
	}
	else {
		this.strside = p_str_both;
	}

	if ( p_steamid == this.team_id && status == 'employed') {
		if (this.attributes[7] == '+') {
			this.formpicture = "<img src='img/formplus.gif' title='"+str_form_rest+"' alt='"+str_form_rest+"'>";
			this.formtext = str_form_rest;
		}
		else if (this.attributes[7] == '-') {
			this.formpicture = "<img src='img/formminus.gif' title='"+str_form_play+"' alt='"+str_form_play+"'>";
			this.formtext = str_form_play;
		}
		else {
			this.formpicture = "<img src='img/formgood.gif' title='"+str_form_satisfied+"' alt='"+str_form_satisfied+"'>";
			this.formtext = str_form_satisfied;
		}
	}
	else{
		this.formpicture = "";
		this.formtext = "";
	}

	this.shirtpricolor = shirtpricolor;
	this.shirtseccolor = shirtseccolor;
	this.shirtpattern = shirtpattern;
	if (status == 'employed') {
		if (injury && injury.length != 0) {

			this.injury_severity = injury[0];
			this.injury_name = injury[1];
			this.injury_days = injury[2];
			this.injury_translated_name = injury[3];
			this.injury_translated_severity = injury[4];
			this.injuryLink = injury[5];
			this.injuryIcon = '<img src="img/injuries/injury_icon.gif" border=0>';
			if (this.ontransfer) {
				this.injuryTable = '<td align=right><span title="'+str_injury +': '+this.injury_translated_name+' - '+this.injury_translated_severity+'">'+this.injuryIcon+'</span></td>';

			}
			else {
				this.injuryTable = '<tr><td colspan="5">';
				this.injuryTable += '<table border="0" cellspacing="0" cellpadding="0" width="100%"><tr>';
				this.injuryTable += '<td width=1 valign=top class='+p_windowbg+' colspan="5"><img src="img/trans.gif" width="1" height="1" border=0></td>';
				this.injuryTable += '</tr><tr>';
				this.injuryTable += '<td colspan=4 width=1 height=6 valign=top><img src="img/trans.gif" width="1" height="6" border=0></td>';
				this.injuryTable += '</tr><tr>';
				this.injuryTable += '<td width="6"></td>';
				this.injuryTable += '<td align="center" colspan="2"><a target=_parent href="'+this.injuryLink+'">'+this.injuryIcon+'</a></td></tr><tr><td colspan="3">'+this.injury_translated_severity+' '+str_injury+': '+this.injury_translated_name+'</td>';
				this.injuryTable += '</tr><tr>';
				this.injuryTable += '<td colspan=4 width=1 height=6 valign=top><img src="img/trans.gif" width="1" height="6" border=0></td>';
				this.injuryTable += '</tr>';
				this.injuryTable += '</table></td></tr>';
			}
		}
		else {
			this.injuryTable = '';
			this.injuryIcon = '<img src="img/injuries/injury_icon_bw.gif" border=0 style="-moz-opacity:0.40; filter:alpha(opacity=40); opacity:0.4;" />';
		}
	}
	else {
		this.injuryIcon = "";
		this.injuryTable = "";
	}

	if (status == 'employed') { //only show icons for employed players.
		if (this.tc_cur_season == 'y') {
			this.tcThisSeasonInfo = '<td align=right><span title="'+p_strtccurseason+'"><img src="img/icon_trainingcamp.gif" width="15" height="16"></span></td>';
			this.tcThisSeasonInfo = doTheReplace(this.tcThisSeasonInfo, this );
			this.tcThisIcon = '<img src="img/icon_trainingcamp.gif">';
		}
		else {
			this.tcThisSeasonInfo = '';
			this.tcThisIcon = '<img src="img/icon_trainingcamp_bw.gif" style="-moz-opacity:0.40; filter:alpha(opacity=40); opacity:0.4;" />';
		}

		if (training_camp) {
			this.tc_name = training_camp[1];
			this.tc_img_name = this.tc_name.toLowerCase();
			this.tc_level = training_camp[0];
			this.tc_type = training_camp[2];
			var imgLink = "img/trainingcamp/tc_"+this.tc_type+"_"+this.tc_level+".gif";
			this.tcIcon = '<img src="'+imgLink+'" border=0>';

			this.tcTable = '<tr>';
			this.tcTable += '<td align=left>'+this.tcIcon+' '+this.tc_name+'</td>';
			this.tcTable += '</tr>';
		}
		else
		this.tcTable = '';
	}
	else {
		this.tcThisIcon = ''; //no image for fired and retired player.
		this.tcThisSeasonInfo = '';
		this.tcTable = '';
	}

	this.training_id = training_id;

	var i = 1;

	for (skill in this.skills) {

		if (skill.indexOf('attr') == -1 && skill.indexOf('skill') == -1) // filter out indexOf, etc
		continue;
		if (this.flags[skill] > 0)
		this.flags[skill] = '<img src="img/flag.gif" width="9" height="10" border=0>';
		else
		this.flags[skill] = '';
		this.training_boost[skill] = 'w';
		i++;

		var skillcounter = i;
		if (sport == 'hockey') {
			skillcounter = i - 5; //ignore the attrs in hockey
			if (skillcounter == 1) // order of skills is messed up in hockey
			skillcounter = 11;
		}
		if (this.training_id == skillcounter)
		this.training_boost[skill] = 'b';
	}

	this.title = this.player_name +" ("+ this.player_id +") "+ this.tr_exchanged_lastbid_display +" @ "+ this.tr_enddate;

	this.warning = warning;




	var flashSport = 'football';
	if (sport == 'hockey') {
		flashSport = 'hockey';
	}
	this.shirtflash = getFlashString('jersey_viewer', 'swf/' + p_garmentFlashFilename, p_garmentFlashSizeWidth, p_garmentFlashSizeHeight, 'transparent',
	'pos_x=-8&pos_y=-5&browser=other&game_mode=' + flashSport + '&shirt_only=' + p_garmentFlashShirtOnly + '&shirt_number=' + this.shirtnr + '&scale=0.5&'+
	'shirt1=' + this.shirtpricolor + '&shirt2=' + this.shirtseccolor + '&pattern_type=' + (this.shirtpattern - 1),
	'd27cdb6e-ae6d-11cf-96b8-444553540000',
	'http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0', "swf/", '#F2F1EC');

}
Player.prototype.fetchNationalLinks = function(national)
{
	var p = this;
	var plink = new Array();
	if (national == 1) { //Remove senior player
		plink[plink.length] = '<a target=_parent href="?p=national_teams_admin&sub=players&pid=' + p.player_id + '&extra=remove">'+strRemove+'</a>';
	}
	else if (national == 2 && p.status == "employed") {//Adding Senior player
		plink[plink.length] = '<a target=_parent href="?p=national_teams_admin&sub=players&pid=' + p.player_id + '&extra=add">'+strAdd+'</a>';
	}
	else if (national == 3 && p.status == "employed") { //Remove U-21 player or copy it to senior team
		plink[plink.length] = '<a target=_parent href="?p=national_teams_admin&type=u21&sub=players&pid=' + p.player_id + '&extra=remove">'+strRemoveU21+'</a>';
		plink[plink.length] = '<a target=_parent href="?p=national_teams_admin&sub=players&pid=' + p.player_id + '&extra=add">'+strToSeniors+'</a>';
	}
	else if (national == 4 && p.status == "employed") {//Adding U-21 player
		plink[plink.length] = '<a target=_parent href="?p=national_teams_admin&type=u21&sub=players&pid=' + p.player_id + '&extra=add">'+strAddU21+'</a>';
	}
	else if (national == 5 && p.status == "employed") { //Adding both senior and U-21 player
		plink[plink.length] = '<a target=_parent href="?p=national_teams_admin&sub=players&pid=' + p.player_id + '&extra=add">'+strAdd+'</a>';
		plink[plink.length] = '<a target=_parent href="?p=national_teams_admin&type=u21&sub=players&pid=' + p.player_id + '&extra=add">'+strAddU21+'</a>';
	}
	else if (p.team_id == p_steamid && p.status == "employed") {
		if (p.junior == 0) {
			if (p.ontransfer) {
				plink[plink.length] = '';
				plink[plink.length] = '';
			}
			else {
				plink[plink.length] = '<a target=_parent href="?p=players&pid=' + p.player_id + '&extra=sell"><img src=\"img/sell.gif\" border=\"0\" ' +getAltTitle(p_strsell)+ ' ><br>' + p_strsell + '</a>';
				plink[plink.length] = '<a target=_parent href="?p=players&pid=' + p.player_id + '&extra=fire"><img src=\"img/discard.gif\" border=\"0\" ' +getAltTitle(p_strfire)+ ' ><br>' + p_strfire + '</a>';
				if (clubMember)
				plink[plink.length] = '<a target=_parent href="?p=players&sub=notes&pid=' + p.player_id + '"><img src=\"img/notes.gif\" border=\"0\" ' +getAltTitle(p_strnotes)+ ' ><br>' + p_strnotes + '</a>';
			}
		}
		else {
			plink[plink.length] = p_strjunior;
			plink[plink.length] = "";
			if (clubMember) {
				plink[plink.length] = '<a target=_parent href="?p=players&sub=notes&pid=' + p.player_id + '"><img src=\"img/notes.gif\" border=\"0\" ' +getAltTitle(p_strnotes)+ ' ><br>' + p_strnotes + '</a>';
			}

		}
	}
	else {
		plink[plink.length] = '';
		plink[plink.length] = '';
		plink[plink.length] = '';

	}
	return plink;
}
Player.prototype.toHTML = function(national)
{
	plinks = "";
	tr_links = "";
	tr_bids_str = "";
	var p = this;

	var tr_link = new Array();
	var plink = new Array();

	var nationalLinks = this.fetchNationalLinks(national);
	for ( var i = 0; i < nationalLinks.length; ++i ) {
		plink.push( nationalLinks[i] );
	}

	if (p.ontransfer && p.team_id != p_steamid) {
		var amount = 0;
		if (p.tr_lastbid == 0) {
			amount = p.tr_startbid;
			amount = exchange(p.mz_currency_id,
			p.currency_id,
			amount,
			exchange_rates);
		}
		else {
			amount = Math.ceil(p.tr_lastbid*1.05);
			amount = exchangeCeil(p.mz_currency_id,
			p.currency_id,
			amount,
			exchange_rates);
		}
		/* We have to replace quotes within the name to avoid Javascript crashes */
		var temp_str = p.player_name;
		var temp_str2 = temp_str.replace(/\'/g,'`'); //Replacing ' with ^ /g means global => change all instances of single quote
		var JSplayer_name = temp_str2;
		var buylink = "<a target=_parent title=\""+p_strbuyplayer+"\" href=\"javascript:buy(" + amount + ", " + p.value + ", " + p.player_id + ", " + p.currency_id  + ", " + user_currency_id  +  " , '" + p.currency_suffix + "', '" + user_currency_suffix  + "', " + p.value + ", " + p.salary + ", " + p.t_salary + ", " + p.warning + ", '" + JSplayer_name + "');\"><img src=\"img/sell.gif\" border=\"0\">";

		plink[plink.length] = buylink +"<br>"+ p_strbuyplayer +"</a>";
		tr_link[tr_link.length] = buylink +"</a>";

		plink[plink.length] = '<a target=_parent href="?p=players&sub=monitor&pid=' + p.player_id + '&extra=transfer"><img src=\"img/monitor.gif\" border=\"0\"  ' +getAltTitle(p_strmonitor)+ ' ><br>' + p_strmonitor + '</a>';
		tr_link[tr_link.length] = '<a target=_parent title=\"' +getAltTitle(p_strmonitor)+ '\" href="?p=players&sub=monitor&pid=' + p.player_id + '"><img src=\"img/monitor.gif\" border=\"0\" ' +getAltTitle(p_strmonitor)+ '></a>';

	}

	if (p.ontransfer) {
		if (p.tr_bids.length != 0) {
			for (var i=0; i<p.tr_bids.length; i++) {
				bid_value = exchange(p.mz_currency_id,
				p.tr_bids[i][3],
				p.tr_bids[i][0],
				exchange_rates);

				exch_bid_value = exchange(p.mz_currency_id,
				user_currency_id,
				p.tr_bids[i][0],
				exchange_rates);


				tr_bids_str += "<span title=\""+ presentMoney(bid_value) +" "+ p.tr_bids[i][4] +"\">"+presentMoney(exch_bid_value)+" "+ user_currency_suffix +"</span>, "+p.tr_bids[i][2]+"<br>";

			}
		}
		else
		tr_bids_str = strNoBidsYet;
	}

	if (p_isNationalCoach && !p_isNationalCoachPage &&
	p.origin_country_id == p_user_origin_country_id && p.status == "employed") {
		plink[plink.length] = '<a target=_parent href="?p=national_teams_admin&sub=search&pid=' + p.player_id + '">'+strView+'</a>';
	}
	if (p.status == "employed") {
		if (p.shortlist == 1)
		plink[plink.length] = '<a target=_parent href="?p=shortlist&sub=remove&pid=' + p.player_id + '"><img src=\"img/monitor_remove.gif\" border=\"0\"  ' +getAltTitle(p_strremove)+ ' >' + p_strremove + '</a>';
		else
		plink[plink.length] = '<a target=_parent href="?p=players&sub=monitor&pid=' + p.player_id + '&extra=transfer"><img src=\"img/monitor.gif\" border=\"0\"  ' +getAltTitle(p_strmonitor)+ ' ><br>' + p_strmonitor + '</a>';
		tr_link[tr_link.length] = '<a target=_parent title=\"' +getAltTitle(p_strmonitor)+ '\" href="?p=players&sub=monitor&pid=' + p.player_id + '"><img src=\"img/monitor.gif\" border=\"0\" ' +getAltTitle(p_strmonitor)+ '></a>';
	}
	else if (!p_isRetiredPlayersPage && p_isShortListPage) {
		plink[plink.length] = '<a target=_parent href="?p=shortlist&sub=remove&pid=' + p.player_id + '"><img src=\"img/monitor_remove.gif\" border=\"0\"  ' +getAltTitle(p_strremove)+ ' >' + p_strremove + '</a>';
		//We don't want to display the icon to remove a player if we are on Retired Player Page, but we want to if we are at Monitoring Page
	}
	// Shirts. If nationalteampage and player is nationalTeamPlayer the shirt
	// should be cached on national_team_id. Otherwise on team_id.
	if ((p_isNationalCoachPage || p_isNationalTeamPage) &&
	p.national_team_id != 0) {
		p.shirtcache_team_id = p.national_team_id;
	}
	else {
		p.shirtcache_team_id = p.team_id;
	}

	if (p.junior == 2) { //trainer
		plink = new Array();
		if (p.team_id == p_steamid)
		plink[plink.length] = '<a target=_parent href="?p=trainers&cid=' + p.player_id + '&extra=fire"><img src=\"img/discard.gif\" border=\"0\" ' +getAltTitle(p_strfire)+ ' >' + p_strfire + '</a>';
	}
	var template = p_playerTemplate;


	if (isSpecialPlayer(p.team_id)) {
		plink = new Array();
	}

	for (var i=0; i<plink.length; i++) {
		plinks += p_breaksBeforeLinks + plink[i];
	}

	for (var i=0; i<tr_link.length; i++) {
		tr_links += "&nbsp;" + tr_link[i];
	}

	return doTheReplace(template, this );
}
Player.prototype.generatePlayerSkillsHtml = function()
{
	var skills = "";
	if (p_isNationalCoachPage ||
	this.team_id == p_steamid ||
	this.ontransfer == 1 ||
	isSpecialPlayer(this.team_id)) {
		skills = doTheReplace(p_playerSkillsTemplate, this );
	}
	return skills;
}
Player.prototype.generateRetireInfo = function()
{
	if ( this.retiring ) {
		if ( this.ontransfer )
		return '<td colspan=2 style="padding-left: 5px; padding-right: 5px;"><table width="100%"><tr>' +
		'<td style="background-color: red; height: 25px; color: #FFFFFF;" align=center><b>'+str_retiring +' ('+ this.retiring_date + ')</b></td></tr></table></td>';
		else
		return "<tr><td style=\"background-color: red; height: 25px; color: #FFFFFF;\" align=center>&nbsp;<b>" + str_retiring +" ("+ this.retiring_date + ")</b></td></tr>";
	}
	return "";
}
Player.prototype.generateTeamInfoHtml = function()
{
	var p = this;
	teamInfo = "";
	// Show if player is in national team and if on national team or
	// national coach page
	if ( p && (p.national_team_id != 0 || p.national_teamU21_id != 0)&&
	(p_isNationalTeamPage || p_isNationalCoachPage)) {
		teamInfo = doTheReplace(p_teamInfoTemplate, this );
	}
	return teamInfo;
}

Player.prototype.generateTransferHtml = function() {
	var p = this;
	transfer = "";
	if ( p && p.ontransfer == 1) {
		transfer = doTheReplace(p_transferTemplate, this );
	}
	return transfer;
}

Player.prototype.generateNationalInfoHtml = function()
{
	var p = this;
	var html = "";
	if (p.national_team_id > 0 && !p_isNationalTeamPage) {
		html = doTheReplace(p_nationalTeamInfoTemplate, p);
	}
	else if (p.nationalU21_team_id > 0 && !p_isNationalTeamPage) {
		html = doTheReplace(p_nationalU21TeamInfoTemplate, p );
	}
	return html;
}
Player.prototype.renderSinglePlayer = function()
{
	layer_write("playercontent", this.toHTML() );
}
Player.prototype.setDigitalGoods = function(items)
{
	this.digitalGoodsArray = items;
}
Player.prototype.setDGColors = function(skin, hair, facial)
{
	//nothing
}
Player.prototype.addAppearanceButton = function()
{
	return "";
}
Player.prototype.addChangeNameButton = function()
{
	return "";
}


function soccerPlayer(player_id,team_id,national_team_id,national_shirt_no,national_shirtpricolor,national_shirtseccolor,national_shirtpattern, nationalU21_team_id,nationalU21_shirt_no,nationalU21_shirtpricolor,nationalU21_shirtseccolor,nationalU21_shirtpattern,team_name,player_name,t_salary,retiring,retiring_date,tc_cur_season,status,origin_country_id,origin_country_shortname,origin_country_name,origin_country_translated_name,skills,flags,tr_bids,attributes,stats,shirtnr,show_on_tactics,value,salary,age,birthseason,ontransfer,sell,transferarray,shirtpricolor,shirtseccolor,shirtpattern,junior, shortlist,currency_suffix,currency_id,mz_currency_id,injury,training_camp,warning,training_id)
{
  Player.call(this,player_id,team_id,national_team_id,national_shirt_no,national_shirtpricolor,national_shirtseccolor,national_shirtpattern, nationalU21_team_id,nationalU21_shirt_no,nationalU21_shirtpricolor,nationalU21_shirtseccolor,nationalU21_shirtpattern,team_name,player_name,t_salary,retiring,retiring_date,tc_cur_season,status,origin_country_id,origin_country_shortname,origin_country_name,origin_country_translated_name,skills,flags,tr_bids,attributes,stats,shirtnr,show_on_tactics,value,salary,age,birthseason,ontransfer,sell,transferarray,shirtpricolor,shirtseccolor,shirtpattern,junior, shortlist,currency_suffix,currency_id,mz_currency_id,injury,training_camp,warning,training_id);
	
  if (this.status == 'employed') {
    if (this.tc_cur_season == 'y') {
      this.tcThisSeasonInfo = '<td align=right></td>';
      this.tcThisIcon = '<img src="img/icon_trainingcamp_dg.gif" >';
    }
    else {
      this.tcThisSeasonInfo = '';
      this.tcThisIcon = '<img src="img/icon_trainingcamp_bw.gif" style="-moz-opacity:0.40; filter:alpha(opacity=40); opacity:0.4;">';
    }
  }
  else
    this.tcThisIcon = '';
	var date = new Date();

	if ( this.junior ) {
		this.strsalary = p_strjunior;
		this.salary_display = "";
		this.exchanged_salary_display = "";
	}
	else{
		this.strsalary += ":";
		this.exchanged_salary_display += " " + user_currency_suffix;
	}

	var flashSport = 'football';
	if (sport == 'hockey') {
		flashSport = 'hockey';
	}

	this.shirtflash = getFlashString('jersey_viewer', 'swf/' + p_garmentFlashFilename, p_garmentFlashSizeWidth, p_garmentFlashSizeHeight, 'transparent',
	'pos_x=-8&pos_y=-5&browser=other&game_mode='+flashSport+'&shirt_only=' + p_garmentFlashShirtOnly + '&uqid='+uqid+'&identifier=' + date.getTime() + '_' + this.player_id + '&scale=0.5&shirt_number=' + this.shirtnr + '&' +
	'shirt1=' + this.shirtpricolor + '&shirt2=' + this.shirtseccolor + '&pattern_type=' + (this.shirtpattern - 1) + '&pants1=' + p_shorts1 + '&pants2=' + p_shorts2 + '&socks1=' + p_socks1 + '&socks2=' + p_socks2,
	'd27cdb6e-ae6d-11cf-96b8-444553540000',
	'http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0', "swf/", '#F2F1EC');
}

soccerPlayer.prototype = new Player();
soccerPlayer.prototype.toString = function() { return "soccerPlayer"; };
soccerPlayer.prototype.setDGColors = function(skin, hair, facial)
{
	this.skin_color = skin;
	this.hair_color = hair;
	this.hair_facial_color = hair;	//same color for hair and facial right now.
}
soccerPlayer.prototype.addAppearanceButton = function()
{
	if ( p_steamid == this.team_id )
	return doTheReplace( this.appearanceButton, this );
	else
	return "";
}
soccerPlayer.prototype.addChangeNameButton = function()
{
	if ( p_steamid == this.team_id )
	return doTheReplace( this.changeNameButton, this );
	else
	return "";
}
soccerPlayer.prototype.setDigitalGoods = function(items)
{
	this.digitalGoodsArray = items;	//save if we want to use somewhere else.
	var goodsFlashVars = "&";
	for ( var i = 0; i < items.length; ++i ) {
		//items[i][0] = slotname
		//items[i][1] = swf path
		goodsFlashVars += items[i][0] + "=" + (( !items[i][1] ) ? "-1" : items[i][1]) + "&";
	}
	goodsFlashVars += "skin_color=" + this.skin_color + "&hair_color=" + this.hair_color + "&hair_facial_color=" + this.hair_facial_color;
	var date = new Date();
	this.shirtflash = getFlashString('jersey_viewer', 'swf/' + p_garmentFlashFilename, p_garmentFlashSizeWidth, p_garmentFlashSizeHeight, 'transparent',
	'pos_x=-8&pos_y=-5&browser=other&game_mode=soccer&shirt_only=' + p_garmentFlashShirtOnly + '&uqid='+uqid+'&identifier=' + date.getTime() + '_' + this.player_id + '&scale=0.5&shirt_number=' + this.shirtnr + '&' +
	'shirt1=' + this.shirtpricolor + '&shirt2=' + this.shirtseccolor + '&pattern_type=' + (this.shirtpattern - 1) + '&pants1=' + p_shorts1 + '&pants2=' + p_shorts2 + '&socks1=' + p_socks1 + '&socks2=' + p_socks2 + goodsFlashVars,
	'd27cdb6e-ae6d-11cf-96b8-444553540000',
	'http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0', "swf/", '#F2F1EC');
}
soccerPlayer.prototype.fetchNationalLinks = function(national)
{
	var p = this;
	var plink = new Array();
	if (national == 1) { //Remove senior player
		plink[plink.length] = '<br><a target=_parent href="?p=national_teams_admin&sub=players&pid=' + p.player_id + '&extra=remove">'+strRemove+'</a>';
	}
	else if (national == 2 && p.status != "retired") {//Adding Senior player
		plink[plink.length] = '<br><a target=_parent href="?p=national_teams_admin&sub=players&pid=' + p.player_id + '&extra=add">'+strAdd+'</a>';
	}
	else if (national == 3 && p.status != "retired") { //Remove U-21 player or copy it to senior team
		plink[plink.length] = '<br><a target=_parent href="?p=national_teams_admin&type=u21&sub=players&pid=' + p.player_id + '&extra=remove">'+strRemoveU21+'</a>';
		plink[plink.length] = '<a target=_parent href="?p=national_teams_admin&sub=players&pid=' + p.player_id + '&extra=add">'+strToSeniors+'</a>';
	}
	else if (national == 4 && p.status != "retired") {//Adding U-21 player
		plink[plink.length] = '<br><a target=_parent href="?p=national_teams_admin&type=u21&sub=players&pid=' + p.player_id + '&extra=add">'+strAddU21+'</a>';
	}
	else if (national == 5 && p.status != "retired") { //Adding both senior and U-21 player
		plink[plink.length] = '<br><a target=_parent href="?p=national_teams_admin&sub=players&pid=' + p.player_id + '&extra=add">'+strAdd+'</a>';
		plink[plink.length] = '<a target=_parent href="?p=national_teams_admin&type=u21&sub=players&pid=' + p.player_id + '&extra=add">'+strAddU21+'</a>';
	}
	else if (p.team_id == p_steamid && p.status == "employed") {
		if (p.junior == 0) {
			if (p.ontransfer) {
				plink[plink.length] = '';
				plink[plink.length] = '';
			}
			else {
				plink[plink.length] = '<a target=_parent href="?p=players&pid=' + p.player_id + '&extra=sell"><img src=\"img/sell.gif\" border=\"0\" ' +getAltTitle(p_strsell)+ ' ></a>';

				if (clubMember)
				plink[plink.length] = '<a target=_parent href="?p=players&sub=notes&pid=' + p.player_id + '"><img src=\"img/notes.gif\" border=\"0\" ' +getAltTitle(p_strnotes)+ ' ></a>';

				plink[plink.length] = '<a target=_parent href="?p=players&pid=' + p.player_id + '&extra=fire"><img src=\"img/discard.gif\" border=\"0\" ' +getAltTitle(p_strfire)+ ' ></a>';

			}
		}
		else {
			//plink[plink.length] = p_strjunior;
			plink[plink.length] = "";
			if (clubMember) {
				plink[plink.length] = '<a target=_parent href="?p=players&sub=notes&pid=' + p.player_id + '"><img src=\"img/notes.gif\" border=\"0\" ' +getAltTitle(p_strnotes)+ ' ></a>';
			}

		}
	}
	return plink;
}
soccerPlayer.prototype.toHTML = function(national)
{
	plinks = "";
	tr_links = "";
	tr_bids_str = "";
	var p = this;

	var tr_link = new Array();
	var plink = new Array();

	var nationalLinks = this.fetchNationalLinks(national);
	for ( var i = 0; i < nationalLinks.length; ++i ) {
		plink.push( nationalLinks[i] );
	}

	if (p.ontransfer && p.team_id != p_steamid) {
		var amount = 0;
		if (p.tr_lastbid == 0) {
			amount = p.tr_startbid;
			amount = exchange(p.mz_currency_id,
			p.currency_id,
			amount,
			exchange_rates);
		}
		else {
			amount = Math.ceil(p.tr_lastbid*1.05);
			amount = exchangeCeil(p.mz_currency_id,
			p.currency_id,
			amount,
			exchange_rates);
		}
		/* We have to replace quotes within the name to avoid Javascript crashes */
		var temp_str = p.player_name;
		var temp_str2 = temp_str.replace(/\'/g,'`'); //Replacing ' with ^ /g means global => change all instances of single quote
		var JSplayer_name = temp_str2;
		var buylink = "<a target=_parent title=\""+p_strbuyplayer+"\" href=\"javascript:buy(" + amount + ", " + p.value + ", " + p.player_id + ", " + p.currency_id  + ", " + user_currency_id  +  " , '" + p.currency_suffix + "', '" + user_currency_suffix  + "', " + p.value + ", " + p.salary + ", " + p.t_salary + ", " + p.warning + ", '" + JSplayer_name + "');\"><img src=\"img/sell.gif\" border=\"0\">";

		plink[plink.length] = buylink + "</a>";
		tr_link[tr_link.length] = buylink +"</a>";
	}

	if (p.ontransfer) {
		if (p.tr_bids.length != 0) {
			for (var i=0; i<p.tr_bids.length; i++) {
				bid_value = exchange(p.mz_currency_id,
				p.tr_bids[i][3],
				p.tr_bids[i][0],
				exchange_rates);

				exch_bid_value = exchange(p.mz_currency_id,
				user_currency_id,
				p.tr_bids[i][0],
				exchange_rates);


				tr_bids_str += "<span title=\""+ presentMoney(bid_value) +" "+ p.tr_bids[i][4] +"\">"+presentMoney(exch_bid_value)+" "+ user_currency_suffix +"</span>, "+p.tr_bids[i][2]+"<br>";

			}
		}
		else
		tr_bids_str = "No bids yet";
	}


	if (p.status != "retired") {
		if (p.shortlist == 1) {
			plink[plink.length] = '<a target=_parent href="?p=shortlist&sub=remove&pid=' + p.player_id + '"><img src=\"img/monitor_remove.gif\" border=\"0\"  ' +getAltTitle(p_strremove)+ ' ></a>';
		}
		else {
			/* switch place at discard icon and monitor icon */
			var index = plink.length-1;
			var discard = plink[index];

			if (p.status == "employed") {
				if ( index == -1 )
				plink[0] = '<a target=_parent href="?p=players&sub=monitor&pid=' + p.player_id + '&extra=transfer"><img src=\"img/monitor.gif\" border=\"0\"  ' +getAltTitle(p_strmonitor)+ ' /></a>';
				else
				plink[index] = '<a target=_parent href="?p=players&sub=monitor&pid=' + p.player_id + '&extra=transfer"><img src=\"img/monitor.gif\" border=\"0\"  ' +getAltTitle(p_strmonitor)+ ' /></a>';
			}

			if ( typeof(discard) != "undefined" && discard && index != -1 ) {
				plink[index+1] = discard;
			}
		}
		tr_link[tr_link.length] = '<a target=_parent title=\"' +getAltTitle(p_strmonitor)+ '\" href="?p=players&sub=monitor&pid=' + p.player_id + '"><img src=\"img/monitor.gif\" border=\"0\" ' +getAltTitle(p_strmonitor)+ '></a>';
	}
	else if (!p_isRetiredPlayersPage) {
		plink[plink.length] = '<a target=_parent href="?p=shortlist&sub=remove&pid=' + p.player_id + '"><img src=\"img/monitor_remove.gif\" border=\"0\"  ' +getAltTitle(p_strremove)+ ' ></a>';
		//We don't want to display the icon to remove a player if we are on Retired Player Page, but we want to if we are at Monitoring Page
	}
	// Shirts. If nationalteampage and player is nationalTeamPlayer the shirt
	// should be cached on national_team_id. Otherwise on team_id.
	if ((p_isNationalCoachPage || p_isNationalTeamPage) &&
	p.national_team_id != 0) {
		p.shirtcache_team_id = p.national_team_id;
	}
	else {
		p.shirtcache_team_id = p.team_id;
	}

	if (p.junior == 2) { //trainer
		plink = new Array();
		if (p.team_id == p_steamid)
		plink[plink.length] = '<a target=_parent href="?p=trainers&cid=' + p.player_id + '&extra=fire"><img src=\"img/discard.gif\" border=\"0\" ' +getAltTitle(p_strfire)+ ' ></a>';
	}

	if (p_isNationalCoach && !p_isNationalCoachPage &&
	p.origin_country_id == p_user_origin_country_id && p.status == "employed") {
		plink[plink.length] = '<a target=_parent href="?p=national_teams_admin&sub=search&pid=' + p.player_id + '">'+strView+'</a>';
	}

	var template = p_playerTemplate;


	if (isSpecialPlayer(p.team_id)) {
		plink = new Array();
	}

	for (var i=0; i<plink.length; i++) {
		plinks += p_breaksBeforeLinks + plink[i];
	}

	for (var i=0; i<tr_link.length; i++) {
		tr_links += "&nbsp;" + tr_link[i];
	}

	return doTheReplace(template, this );
}

function hockeyPlayer(player_id,team_id,national_team_id,national_shirt_no,national_shirtpricolor,national_shirtseccolor,national_shirtpattern, nationalU21_team_id,nationalU21_shirt_no,nationalU21_shirtpricolor,nationalU21_shirtseccolor,nationalU21_shirtpattern,team_name,player_name,t_salary,retiring,retiring_date,tc_cur_season,status,origin_country_id,origin_country_shortname,origin_country_name,origin_country_translated_name,skills,flags,tr_bids,attributes,stats,shirtnr,show_on_tactics,value,salary,age,birthseason,ontransfer,sell,transferarray,shirtpricolor,shirtseccolor,shirtpattern,junior, shortlist,currency_suffix,currency_id,mz_currency_id,injury,training_camp,warning,training_id)
{
  Player.call(this,player_id,team_id,national_team_id,national_shirt_no,national_shirtpricolor,national_shirtseccolor,national_shirtpattern, nationalU21_team_id,nationalU21_shirt_no,nationalU21_shirtpricolor,nationalU21_shirtseccolor,nationalU21_shirtpattern,team_name,player_name,t_salary,retiring,retiring_date,tc_cur_season,status,origin_country_id,origin_country_shortname,origin_country_name,origin_country_translated_name,skills,flags,tr_bids,attributes,stats,shirtnr,show_on_tactics,value,salary,age,birthseason,ontransfer,sell,transferarray,shirtpricolor,shirtseccolor,shirtpattern,junior, shortlist,currency_suffix,currency_id,mz_currency_id,injury,training_camp,warning,training_id);
}
hockeyPlayer.prototype.toString = function() { return "hockeyPlayer"; };
hockeyPlayer.prototype = new Player();
hockeyPlayer.prototype.addChangeNameButton = function()
{
	if ( p_steamid == this.team_id )
	return doTheReplace( this.changeNameButton, this );
	else
	return "";
}


function MonitorPlayer(team_id,
player_id,
player_name,
value,
salary,
t_salary,
origin_country_shortname,
currency_id,
currency_suffix,
last_bid,
bidder_team_id,
deadline,
my_team_id,
buy_icon)
{
	this.team_id = team_id;
	this.player_id = player_id;
	this.player_name = player_name;

	var spaceIndex = this.player_name.indexOf(" ");
	if (spaceIndex >= 0  )
	this.monitor_name = this.player_name.substr(0,1) +"."+ this.player_name.substr( spaceIndex );
	else
	this.monitor_name = this.player_name;

	this.value = value;
	this.salary = salary;
	this.t_salary = t_salary;
	this.value_display = presentMoney(value);
	this.salary_display = presentMoney(salary);

	this.origin_country_shortname = origin_country_shortname.toLowerCase();
	this.currency_id = currency_id;
	this.currency_suffix = currency_suffix;

	this.tr_lastbid = last_bid;
	this.tr_lastbid_display = presentMoney(this.tr_lastbid);
	this.tr_exchanged_lastbid_display = presentMoney(exchange(50,
	user_currency_id,
	this.tr_lastbid,
	exchange_rates));

	this.bidder_team_id = bidder_team_id;

	this.tr_enddate = deadline;
	this.my_team_id = my_team_id;

	this.type = "Buy";
	if (this.my_team_id == this.team_id)
	this.type = "Sell";

	this.is_leader = false;
	if (this.my_team_id == this.bidder_team_id)
	this.is_leader = true;

	this.buy_icon = buy_icon;
	this.buy_link = "";
	if (this.type == "Buy")
	if (this.is_leader)
	this.buy_link = "<a href='#'>"+ this.buy_icon +"</a>";
	else if (!this.is_leader)
	this.buy_link = "<a href='`?p=transfer&sub=bid&pid="+ this.player_id +"'>"+ this.buy_icon +"</a>";

	this.title = this.type +": "+ this.player_name +" ("+ this.player_id +") "+ this.tr_exchanged_lastbid_display +" "+ this.currency_suffix +" @ "+ this.tr_enddate;

}

function presentMoney(_money)
{
	if ( typeof(_money) == "undefined" )
	return "";
	var money = _money.toString();
	var result = "";
	var index = 0;
	while (money.length > 0) {
		index = money.length - 3;
		if (index < 0)
		index = 0;
		result = money.substr(index) + " " + result;
		money = money.substr(0, index);
	}
	if (result.length >= 1)
	result = result.substr(0, result.length-1);
	return result;
}

function isSpecialPlayer(tid)
{
	var x = false;
	if (tid == 79051 ||
	tid == 79052 ||
	tid == 79053 ||
	tid == 79054 ||
	tid == 111211 ||
	tid == 131549 ||
	tid == 51 ||
	tid == 52 ||
	tid == 53)
	x = true;
	return x;
}


function lookForPlayerNameChange(pid) {
	var ret = true;
	var el = $("#ajaxContainer_" + pid);
	if ($("#first_name_" + pid).val().trim() == "" || $("#sur_name_" + pid).val().trim() == "") {
		ret = false;
	}
	else {
		var past = el.parents("div.playerContainer").find("a.subheader span").text();
		var current = $("#first_name_" + pid).val() + " " + $("#sur_name_" + pid).val();
		if (past == current) {
			ret = false;
		}
	}
	if (ret) {
		$("#playerChangeNameSave_" + pid + " table").click();
	}
}

function renamePlayerContent(el, url, playerId, teamId) {
	if ($('#ajaxContainer_' + playerId).length == 0) {
		$(el).parents("div.playerContainer").find("h2").after('<div class="player_rename_container" id=ajaxContainer_' + playerId + '></div>');
	}
	$('#ajaxContainer_' + playerId).load(url, function() {
		$("#first_name_" + playerId + ":not(.ui-autocomplete-input)").live("focus", function (event) {
			$(this).autocomplete({source: url + '&sub=getNames&type=firstname', minLength:1, delay: 0, autoFocus: true});
		});

		$("#sur_name_" + playerId + ":not(.ui-autocomplete-input)").live("focus", function (event) {
			$(this).autocomplete({source: url + '&sub=getNames&type=surname', minLength:1, delay: 0, autoFocus: true});
		});

		$("#first_name_"+playerId+",#sur_name_"+playerId).live('focus', function() {
			$(this).autocomplete( "search" , $(this).val());
		});

		$("#first_name_" + playerId).live("blur", function(event) {
			validateAutocomplete(this, event);
		});

		$("#sur_name_" + playerId).live("blur", function(event) {
			validateAutocomplete(this, event);
		});

		validateAutocomplete = function(el, event) {
			var el = "#" + $(el).attr("id");
			var autocomplete = $(el).data("autocomplete");
			var matcher = new RegExp("^" + $.ui.autocomplete.escapeRegex($(el).val()) + "$", "i");
			var myInput = $(el);
			autocomplete.widget().children(".ui-menu-item").each(function() {
				//Check if each autocomplete item is a case-insensitive match on the input
				var item = $(this).data("item.autocomplete");
				if (matcher.test(item.label || item.value || item)) {
					//There was a match, lets stop checking
					autocomplete.selectedItem = item;
					return;
				}
			});
			//if there was a match trigger the select event on that match
			//I would recommend matching the label to the input in the select event
			if (autocomplete.selectedItem) {
				autocomplete._trigger("select", event, {
				item: autocomplete.selectedItem
			});
			//there was no match, clear the input
			} else {
				$(el).val('');
			}
		}

		var cancelButtonObj = $("#playerChangeNameCancel_"+playerId+"_table");
		var leftCol = $(".col_1_of_2").length ? $(".col_1_of_2") : $(".col_1_of_3");
		var rightOffset = (cancelButtonObj.position().left - leftCol.width()) + cancelButtonObj.width();
		var padding = 30;
		$(".player_name_cm_exclusive").css("width", (rightOffset - padding) + "px");
		$(this).fadeIn('slow');
		var playerIndex = $(this).parents("div.playerContainer").attr("id").match(/\d+/);
		scrollToPlayer(playerIndex);
	});
}

$(function() {

	$(".player_name_change_rules").live('click', function() {
		var ajaxEl = $(this).attr("class") + "_content";
		if ($("#"+ajaxEl).length) {
			if (!$(this).parent().parent().find("#"+ajaxEl).length) {
				$("#"+ajaxEl).hide();
				$("#"+ajaxEl).appendTo($(this).parent().parent());
				$("#"+ajaxEl).fadeIn("normal");
			}
			else {
				if ($("#"+ajaxEl+":visible").length) {
					$("#"+ajaxEl).fadeOut("normal");
				}
				else {
					$("#"+ajaxEl).fadeIn("normal");
				}
			}
		}
		else {
			$(this).parent().after("<div id=\"" + ajaxEl + "\"></div>");
			$("#"+ajaxEl).load($(this).attr("href").toString(), function() {
				$(this).fadeIn('slow');
			});
		}
		return false;
	});

	if (typeof($.livequery) == "function") {
		$(".renamePlayerForm").livequery(function() {
			var pid = $(this).find('input.hidden_pid').val();
			var form = $(this);
			var options = {
				multi: true,
				beforeSubmit: function(){$("#renamePlayerFormTarget_" + pid).empty();},
				success: function (responseText, statusText) {
					res = responseText.split("|");
					if (res.length == 3) {
						$("#renamePlayerFormTarget_" + pid).html("<p style=\"color:#C81111; font-weight: bold;\">"+res[2]+"</p>");
					}
					else {
						$("#renamePlayerFormTarget_" + pid).text(res[0]);
					}
					if (responseText !== "-1" && res.length == 2) {
						form.parents("div.playerContainer").find("a span").text(res[1]);
						if ($("#playerRightColumnOverview").length) {
							var playerIndex = form.parents("div.playerContainer").attr("id").match(/\d+/);
							$("#playerRightColumnOverview option[value='" + playerIndex + "']").text(res[1]);
						}
						form.parent().parent().find("p").remove();
						form.parent().parent().delay(1000).fadeOut("slow");
						form.remove();
					}
				},
				error: function () {
					$("#renamePlayerFormTarget_" + pid).html("An error occurred. Please try again.");
				}
			};
			form.ajaxForm(options);
			return false;
		});

	}
});
