function PlayerListRow(playerID, playerName, enterCode, editButton, deleteButton) {
	this.playerID = playerID;
	this.playerName = playerName;
	this.enterCode = enterCode;
	this.editButton = editButton;
	this.deleteButton = deleteButton;
}


function PlayerList(tagDiv, playerListManager) {
	var self = this;
	this.playerListManager = playerListManager;
	// console.log(tagDiv);
	// console.log(playerListManager);

	this.playerCount = 0;
	this.activePageNo = 1;

	// var id_list = tagDiv.find(".player_id");
	var id_list = tagDiv.find(".player-list");
	// console.log(id_list);

	this.listRows = new Array();
	for(var i = 0; i < id_list.length; i++) {
		// console.log(playerEditButtonList[i]);
		// console.log(playerDeleteButtonList[i]);

		this.listRows[i] = new PlayerListRow(
			id_list[i].getElementsByClassName("player_id"),
			id_list[i].getElementsByClassName("player_name"),
			id_list[i].getElementsByClassName("player_entercode"),
			id_list[i].getElementsByClassName("player_edit"),
			id_list[i].getElementsByClassName("player_delete")
		);

		$(this.listRows[i].playerID).empty();

		$(this.listRows[i].editButton).click(function() {
			playerListManager.editPlayer(this);
		})

		$(this.listRows[i].deleteButton).click(function() {
			playerListManager.deletePlayer(this);
		})

		this.disableItem(this.listRows[i]);
	}
}

PlayerList.prototype.disableItem = function(item) {
	$(item.playerName).prop("disabled", true);
	$(item.enterCode).prop("disabled", true);
	$(item.editButton).prop("disabled", true);
	$(item.deleteButton).prop("disabled", true);
}

PlayerList.prototype.enableItem = function(item) {
	$(item.playerName).prop("disabled", false);
	$(item.enterCode).prop("disabled", false);
	$(item.editButton).prop("disabled", false);
	$(item.deleteButton).prop("disabled", false);
}

PlayerList.prototype.updatePlayerList = function(jsonData) {
	if(jsonData === null) {
		for(var i = 0; i < 10; i++) {
			$(this.listRows[i].playerName).val("");
			$(this.listRows[i].enterCode).val("");

			this.disableItem(this.listRows[i]);
		}

		return;
	}

	for(var i = 0; i < 10; i++) {
		$(this.listRows[i].playerID).empty();

		if(i < jsonData.length) {
			$(this.listRows[i].playerID).append(jsonData[i]["playerID"]);
			$(this.listRows[i].playerName).val(jsonData[i]["playerName"]);
			$(this.listRows[i].enterCode).val(jsonData[i]["enterCode"]);

			this.enableItem(this.listRows[i]);
		} else {
			$(this.listRows[i].playerName).val("");
			$(this.listRows[i].enterCode).val("");

			this.disableItem(this.listRows[i]);
		}
	}
}