/**
 * Hattrick Head-Quarters 2.0
 * Players
 *
 * @author Davide Lucchesi <davide@hattrickhq.org>
 * @version 2.0
 * @license http://opensource.org/licenses/gpl-license.php (GPL)
 *
 */

function players() {
	$("#content").hide("fast");
	content(sls['Current']['TeamName']+" players");
	contentAddTemplate($("#Players").html(), sls['Current']);

	var arr = new Array();
	for (var role in sls['Lineup']) {
		arr[role] = new Array();
		for (var beha in sls['Lineup'][role]) {
			for (var player in sls['Lineup'][role][beha]) {
				arr[role][beha] = new Array();
				arr[role][beha]['RatingStars'] = sls['Lineup'][role][beha][player]['RatingStars'];
				break;
			}
		}
	}

	$("#skill thead tr").append("<th height=40 width=20></th>");
	$("#skill thead tr").append("<th>Player</th>");
	$("#skill thead tr").append("<th align='center'>Stamina</th>");
	$("#skill thead tr").append("<th align='center'>Keeper</th>");
	$("#skill thead tr").append("<th align='center'>Defender</th>");
	$("#skill thead tr").append("<th align='center'>Playmaker</th>");
	$("#skill thead tr").append("<th align='center'>Scorer</th>");
	$("#skill thead tr").append("<th align='center'>Winger</th>");
	$("#skill thead tr").append("<th align='center'>Passing</th>");
	$("#skill thead tr").append("<th align='center'>SetPieces</th>");
	for (var idx in sls['Teams'][sls['Current']['TeamID']]['PlayerList']) {
		var trow = $('<tr id="skill-'+idx+'"></tr>');
		var training = false;
		var skills = new Array();
		if (sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['Events']['Training']) {
			if (sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['Events']['Training']['EventDate'])
				training = sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['Events']['Training'];
			else if (sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['Events']['Training'][0]) {
				training = sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['Events']['Training'][0];
			}
		}
		if (training) {
			var traininglast = new Date(stringToDate(sls['Leagues'][sls['Teams'][sls['Current']['TeamID']]['League']['LeagueID']]['TrainingDate']).getTime() - 1000*60*60*24*7);
			if (stringToDate(training['EventDate']).getTime() >= traininglast.getTime())
				skills[training['SkillID']] = 'color:#519e2d;font-weight:bold';
			else skills[training['SkillID']] = 'color:#336600;font-style:italic';
		}
		if (sls['Teams'][sls['Current']['TeamID']]['User']['HasSupporter']) {
			var num = sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['PlayerNumber'];
			if (num == 100)
				num = ' ';
			trow.append("<td align='right' style='font-size: 0.9em'>"+num+"</td>");
		}
		else
			trow.append("<td align='right' style='font-size: 0.9em'>"+idx+"</td>");
		var name = sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['Events']['Names']['Last']+" "+sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['Events']['Names']['ShortFirst'].substring(0, 1)+".";
		trow.append("<td style='font-size: 0.9em'>"+name+playerIcons(idx)+"</td>");
		trow.append("<td align='center' style='font-size: 0.9em"+(skills["2"]?";"+skills["2"]:"")+"'>"+sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['StaminaSkillTranslate']+"</td>");
		trow.append("<td align='center' style='font-size: 0.9em"+(skills["1"]?";"+skills["1"]:"")+"'>"+sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['KeeperSkillTranslate']+"</td>");
		trow.append("<td align='center' style='font-size: 0.9em"+(skills["4"]?";"+skills["4"]:"")+"'>"+sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['DefenderSkillTranslate']+"</td>");
		trow.append("<td align='center' style='font-size: 0.9em"+(skills["8"]?";"+skills["8"]:"")+"'>"+sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['PlaymakerSkillTranslate']+"</td>");
		trow.append("<td align='center' style='font-size: 0.9em"+(skills["5"]?";"+skills["5"]:"")+"'>"+sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['ScorerSkillTranslate']+"</td>");
		trow.append("<td align='center' style='font-size: 0.9em"+(skills["6"]?";"+skills["6"]:"")+"'>"+sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['WingerSkillTranslate']+"</td>");
		trow.append("<td align='center' style='font-size: 0.9em"+(skills["7"]?";"+skills["7"]:"")+"'>"+sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['PassingSkillTranslate']+"</td>");
		trow.append("<td align='center' style='font-size: 0.9em"+(skills["3"]?";"+skills["3"]:"")+"'>"+sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['SetPiecesSkillTranslate']+"</td>");
		$("#skill tbody").append(trow);
	}

	$("#stars thead tr").append("<th id='stars-num' height=40 width=20></th>");
	$("#stars thead tr").append("<th>Player</th>");
	$("#stars thead tr").append("<th align='center'>Form</th>");
	if (arr['1']['0']['RatingStars'] > 0) $("#stars thead tr").append("<th width=30><img src='images/f_gk.png' border=0 /></th>");
	if (arr['3']['0']['RatingStars'] > 0) $("#stars thead tr").append("<th width=30><img src='images/f_cdn.png' border=0 /></th>");
	if (arr['3']['1']['RatingStars'] > 0) $("#stars thead tr").append("<th width=30><img src='images/f_cdo.png' border=0 /></th>");
	if (arr['3']['4']['RatingStars'] > 0) $("#stars thead tr").append("<th width=30><img src='images/f_cde.png' border=0 /></th>");
	if (arr['2']['0']['RatingStars'] > 0) $("#stars thead tr").append("<th width=30><img src='images/f_wbn.png' border=0 /></th>");
	if (arr['2']['2']['RatingStars'] > 0) $("#stars thead tr").append("<th width=30><img src='images/f_wbd.png' border=0 /></th>");
	if (arr['2']['3']['RatingStars'] > 0) $("#stars thead tr").append("<th width=30><img src='images/f_wbc.png' border=0 /></th>");
	if (arr['2']['1']['RatingStars'] > 0) $("#stars thead tr").append("<th width=30><img src='images/f_wbo.png' border=0 /></th>");
	if (arr['7']['0']['RatingStars'] > 0) $("#stars thead tr").append("<th width=30><img src='images/f_mfn.png' border=0 /></th>");
	if (arr['7']['2']['RatingStars'] > 0) $("#stars thead tr").append("<th width=30><img src='images/f_mfd.png' border=0 /></th>");
	if (arr['7']['4']['RatingStars'] > 0) $("#stars thead tr").append("<th width=30><img src='images/f_mfe.png' border=0 /></th>");
	if (arr['7']['1']['RatingStars'] > 0) $("#stars thead tr").append("<th width=30><img src='images/f_mfo.png' border=0 /></th>");
	if (arr['6']['0']['RatingStars'] > 0) $("#stars thead tr").append("<th width=30><img src='images/f_wmn.png' border=0 /></th>");
	if (arr['6']['2']['RatingStars'] > 0) $("#stars thead tr").append("<th width=30><img src='images/f_wmd.png' border=0 /></th>");
	if (arr['6']['3']['RatingStars'] > 0) $("#stars thead tr").append("<th width=30><img src='images/f_wmc.png' border=0 /></th>");
	if (arr['6']['1']['RatingStars'] > 0) $("#stars thead tr").append("<th width=30><img src='images/f_wmo.png' border=0 /></th>");
	if (arr['10']['0']['RatingStars'] > 0) $("#stars thead tr").append("<th width=30><img src='images/f_an.png' border=0 /></th>");
	if (arr['10']['2']['RatingStars'] > 0) $("#stars thead tr").append("<th width=30><img src='images/f_ad.png' border=0 /></th>");
	if (arr['10']['4']['RatingStars'] > 0) $("#stars thead tr").append("<th width=30><img src='images/f_ae.png' border=0 /></th>");
	for (var idx in sls['Teams'][sls['Current']['TeamID']]['PlayerList']) {
		var max = 0;
		var trow = $('<tr id="stars-'+idx+'"></tr>');
		var num = sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['PlayerNumber'];
		if (sls['Teams'][sls['Current']['TeamID']]['User']['HasSupporter']) {
			var num = sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['PlayerNumber'];
			if (num == 100)
				num = ' ';
			trow.append("<td align='right' style='font-size: 0.9em'>"+num+"</td>");
		}
		else
			trow.append("<td align='right' style='font-size: 0.9em'>"+idx+"</td>");
		var name = sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['Events']['Names']['Last']+" "+sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['Events']['Names']['ShortFirst'].substring(0, 1)+".";
		trow.append("<td style='font-size: 0.9em'>"+name+playerIcons(idx)+"</td>");
		trow.append("<td align='center' style='font-size: 0.9em'>"+sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['PlayerFormTranslate']+"</td>");

		var cell;
		if (cell = playerStarsCell(arr, idx, '1', '0'))
			trow.append(cell);
		if (cell = playerStarsCell(arr, idx, '3', '0'))
			trow.append(cell);
		if (cell = playerStarsCell(arr, idx, '3', '1'))
			trow.append(cell);
		if (cell = playerStarsCell(arr, idx, '3', '4'))
			trow.append(cell);
		if (cell = playerStarsCell(arr, idx, '2', '0'))
			trow.append(cell);
		if (cell = playerStarsCell(arr, idx, '2', '2'))
			trow.append(cell);
		if (cell = playerStarsCell(arr, idx, '2', '3'))
			trow.append(cell);
		if (cell = playerStarsCell(arr, idx, '2', '1'))
			trow.append(cell);
		if (cell = playerStarsCell(arr, idx, '7', '0'))
			trow.append(cell);
		if (cell = playerStarsCell(arr, idx, '7', '2'))
			trow.append(cell);
		if (cell = playerStarsCell(arr, idx, '7', '4'))
			trow.append(cell);
		if (cell = playerStarsCell(arr, idx, '7', '1'))
			trow.append(cell);
		if (cell = playerStarsCell(arr, idx, '6', '0'))
			trow.append(cell);
		if (cell = playerStarsCell(arr, idx, '6', '2'))
			trow.append(cell);
		if (cell = playerStarsCell(arr, idx, '6', '3'))
			trow.append(cell);
		if (cell = playerStarsCell(arr, idx, '6', '1'))
			trow.append(cell);
		if (cell = playerStarsCell(arr, idx, '10', '0'))
			trow.append(cell);
		if (cell = playerStarsCell(arr, idx, '10', '2'))
			trow.append(cell);
		if (cell = playerStarsCell(arr, idx, '10', '4'))
			trow.append(cell);
		$("#stars tbody").append(trow);
	}

	$("#other thead tr").append("<th height=40 width=20></th>");
	$("#other thead tr").append("<th>Player</th>");
	$("#other thead tr").append("<th align='center'>Years</th>");
	$("#other thead tr").append("<th align='center'>Days</th>");
	$("#other thead tr").append("<th align='center'>TSI</th>");
	$("#other thead tr").append("<th align='center'><img src='images/salary.png' border=0 alt='Salary' title='Salary' /></th>");
	$("#other thead tr").append("<th align='center'>Experience</th>");
	$("#other thead tr").append("<th align='center'>Leadership</th>");
	$("#other thead tr").append("<th align='center'><img src='images/g_league.png' border=0 alt='League goals' title='League goals' /></th>");
	$("#other thead tr").append("<th align='center'><img src='images/g_cup.png' border=0 alt='Cup goals' title='Cup goals' /></th>");
	$("#other thead tr").append("<th align='center'><img src='images/g_friendly.png' border=0 alt='Friendlies goals' title='Friendlies goals' /></th>");
	$("#other thead tr").append("<th align='center'><img src='images/g_career.png' border=0 alt='Career goals' title='Career goals' /></th>");
	$("#other thead tr").append("<th align='center'><img src='images/g_hattricks.png' border=0 alt='Career hattricks' title='Career hattricks' /></th>");
	for (var idx in sls['Teams'][sls['Current']['TeamID']]['PlayerList']) {
		var trow = $('<tr id="other-'+idx+'"></tr>');
		if (sls['Teams'][sls['Current']['TeamID']]['User']['HasSupporter']) {
			var num = sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['PlayerNumber'];
			if (num == 100)
				num = ' ';
			trow.append("<td align='right' style='font-size: 0.9em'>"+num+"</td>");
		}
		else
			trow.append("<td align='right' style='font-size: 0.9em'>"+idx+"</td>");
		var name = sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['Events']['Names']['Last']+" "+sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['Events']['Names']['ShortFirst'].substring(0, 1)+".";
		var years = ((parseInt(sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['Age'])+parseFloat(parseInt(sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['AgeDays'])/112))+"").replace(/(\...).*/, "$1");
		trow.append("<td style='font-size: 0.9em'>"+name+playerIcons(idx)+"</td>");
		trow.append("<td align='center' style='font-size: 0.9em'>"+years+"</td>");
		trow.append("<td align='center' style='font-size: 0.9em'>"+sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['AgeDays']+"</td>");
		trow.append("<td align='center' style='font-size: 0.9em'>"+sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['TSI']+"</td>");
		trow.append("<td align='center' style='font-size: 0.9em'>"+sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['Salary']+"</td>");
		trow.append("<td align='center' style='font-size: 0.9em'>"+sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['ExperienceTranslate']+"</td>");
		trow.append("<td align='center' style='font-size: 0.9em'>"+sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['LeadershipTranslate']+"</td>");
		trow.append("<td align='center' style='font-size: 0.9em'>"+sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['LeagueGoals']+"</td>");
		trow.append("<td align='center' style='font-size: 0.9em'>"+sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['CupGoals']+"</td>");
		trow.append("<td align='center' style='font-size: 0.9em'>"+sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['FriendliesGoals']+"</td>");
		trow.append("<td align='center' style='font-size: 0.9em'>"+sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['CareerGoals']+"</td>");
		trow.append("<td align='center' style='font-size: 0.9em'>"+sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['CareerHattricks']+"</td>");
		$("#other tbody").append(trow);
	}

	$.tablesorter.addParser({
		id: 'skill',
		is: function(s) {return false;},
		format: function(s) {
			var idx = 0;
			for (idx in sls['Translations']['Skills']) {
				if (sls['Translations']['Skills'][idx] == s) {
					break;
				}
			}
			return idx;
		},
		type: 'numeric'
	});
	$.tablesorter.addParser({
		id: 'shirt',
		is: function(s) {return false;},
		format: function(s) {
			if (s == ' ')
				s = 100;
			return s;
		},
		type: 'numeric'
	});

	$("#skill").tablesorter({
		headers: {
			0: {sorter: 'shirt' },
			2: {sorter: 'skill' },
			3: {sorter: 'skill' },
			4: {sorter: 'skill' },
			5: {sorter: 'skill' },
			6: {sorter: 'skill' },
			7: {sorter: 'skill' },
			8: {sorter: 'skill' },
			9: {sorter: 'skill' }
		},
		widgets: ['zebra']
	});
	$("#skill > tbody > tr").click(function() {
		playerDetails($(this).attr("id").replace(/^.*-/, ""));
	});

	$("#stars").tablesorter({
		headers: {
			0: {sorter: 'shirt' },
			2: {sorter: 'skill' }
		},
		widgets: ['zebra']
	});
	$("#stars > tbody > tr").click(function() {
		playerDetails($(this).attr("id").replace(/^.*-/, ""));
	});

	$("#other").tablesorter({
		headers: {
			0: {sorter: 'shirt' },
			6: {sorter: 'skill' },
			7: {sorter: 'skill' },
			8: {sorter: 'digit' },
			9: {sorter: 'digit' },
			10: {sorter: 'digit' },
			11: {sorter: 'digit' },
			12: {sorter: 'digit' }
		},
		widgets: ['zebra']
	});
	$("#other > tbody > tr").click(function() {
		playerDetails($(this).attr("id").replace(/^.*-/, ""));
	});

	$("#tabs > ul").tabs();
	$("#content").show("fast");
	$("#detail").hide('fast');
}

function playerDetails(idx) {
	$("#detail").empty();
	$("#detail").hide('fast');
	player = sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx];
	if ((sls['Teams'][sls['Current']['TeamID']]['User']['HasSupporter']) && (sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['PlayerNumber'] != 100)) {
		player['Number'] = sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['PlayerNumber'];
	}
	else player['Number'] = '';
	player['Picture'] = playerPicture(idx);
	player['PlayerIcons'] = playerIcons(idx);
	$("#detail").html($(contentTemplate($("#PlayerDetail").html(), player)));
	$("#detail h3").click(function() {
		$("#detail").hide('slow');
	});
	$("#detail").show('slow');
}

function playerIcons(idx) {
	var icons = "";

	if (sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['InjuryLevel'] == 0) {
		icons = icons+'<img src="images/inj0.png" border="0" alt="bruised" title="bruised" />';
	}
	else if (sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['InjuryLevel'] == 1) {
		icons = icons+'<img src="images/inj1.png" border="0" alt="1 week" title="1 week" />';
	}
	else if (sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['InjuryLevel'] > 1) {
		icons = icons+'<img src="images/inj2.png" border="0" alt="'+sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['InjuryLevel']+' weeks" title="'+sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['InjuryLevel']+' weeks" />';
	}
	else if (sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['InjuryLevel'] > 1) {
		icons = icons+'<img src="images/inj2.png" border="0" alt="'+sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['InjuryLevel']+'" weeks" title="'+sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['InjuryLevel']+'" weeks" />';
	}
	if (sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['TransferListed'] == 1) {
		icons = icons+'<img src="images/tl.png" border="0" alt="on sale" title="on sale" />';
	}
	if (sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['Cards'] == 1) {
		icons = icons+'<img src="images/yel1.png" border="0" alt="1" title="1" />';
	}
	else if (sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['Cards'] == 2) {
		icons = icons+'<img src="images/yel2.png" border="0" alt="2" title="2" />';
	}
	else if (sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['Cards'] == 3) {
		icons = icons+'<img src="images/red.png" border="0" alt="out" title="out" />';
	}
	return icons;
}

function playerParseStars(stars) {
	var dec;

	if (stars < 0)
		stars = 0;
	if (stars > 20)
		stars = 20;
	if ((stars - parseInt(stars)) >= 0.5)
		dec = "5";
	else if (parseInt(stars) > 0)
		dec = 0;
	else return "0";
	return parseInt(stars)+"."+dec;
}

function playerPicture(idx) {
	var def = "";

	if (sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['Leadership'] >= 7) {
		if (sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['Agreeability'] <= 1) {
			def = "devil";
		}
		else if (sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['Agreeability'] >= 3) {
			def = "clown";
		}
		else def = "normal";
	}
	else if (sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['Leadership'] == 6) {
		if (sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['Agreeability'] <= 1) {
			def = "semidevil";
		}
		else if (sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['Agreeability'] >= 3) {
			def = "semiclown";
		}
		else def = "normal";
	}
	else def = "normal";
	return '<img src="images/pic_'+def+'.png" border="0" alt="'+def+'" title="'+def+'" />';
}

function playerStarsCell(arr, idx, role, beha) {
	var cell;

	if (arr[role][beha]['RatingStars'] > 0) {
		var stars = parseFloat(sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['Ratings'][role][beha]['RatingStars']);
		if ((stars == parseInt(stars)) && (stars > 0))
			stars += ".0";
		var max = 0;
		for (var i in sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['Ratings']) {
			for (var j in sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['Ratings'][i]) {
				if (parseFloat(sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['Ratings'][i][j]['RatingStars']) > max) {
					max = parseFloat(sls['Teams'][sls['Current']['TeamID']]['PlayerList'][idx]['Ratings'][i][j]['RatingStars']);
				}
			}
		}
		if ((max > 0) && (parseFloat(stars) == max))
			stars = '<strong>'+stars+'</strong>';
		cell = $('<td align="right" style="font-size: 0.9em">'+stars+'</td>');
		cell.click(function() {
			var stars = parseFloat($("input", $(this)).val());
			if (stars >= 0) {
				$("input", $(this)).focus();
			}
			else {
				stars = parseFloat($(this).html().replace(/[^0-9\.]/g, ""));
				if (! stars)
					stars = "0";
				var ival = $('<input id="stars-'+idx+'-'+role+'-'+beha+'" type="text" style="width: 30px" value="'+stars+'" />');
 				$(this).empty();
				$(this).append(ival);
				ival.keydown(function(event) {
					switch (event.keyCode) {
						case 9:
						case 13:
						case 27:
							$(this).parent().css('color', '#50A029');
							var star = playerParseStars(parseFloat($(this).val()));
							$(this).parent().html(star);
							var info = $(this).attr('id').replace("stars-", "");
							var idx = info.replace(/-.*/, "");
							var role = info.replace(/[0-9]*-/, "").replace(/-[0-9]*/, "");
							var beha = info.replace(idx+"-"+role+"-", "");
							console("<img src='images/ajax.gif' align='left' border=0 hspace=5 /> Submitting changes...");
							$.getJSON(
								"hthq.php", {
									"ht_action": "PlayerStars",
									"PlayerID": idx,
									"RoleID": role,
									"Behaviour": beha,
									"RatingStars": star
								},
								function(json) {
									sls['Lineup'] = json;
									console("");
								}
							);
							$("#stars").tablesorter({
								headers: {
									0: {sorter: 'shirt' }
								},
								widgets: ['zebra']
							});
						break;
					}
				});
				ival.focus();
			}
		});
	}
	else cell = false;
	return cell;
}

