function team() {
/* soccerteamstats.js */
/* Script created by Hans-Edward Hoene to manage team and player statistics for soccer from one convenient, easy-to-use, advanced function called "team" in soccerteamstats.js */
/*PROTOTYPE FOR TESTING AND DEVELOPMENT*/
var players = [];
var add = 1;
function player(name,number) {
this.name = name;
this.number = number;
this.time = 0; /*milliseconds*/
this.timehandler = {}, /* stores temporary variables in order to monitor player time */
this.passescompleted = 0;
this.passesattempted = 0;
this.assists = 0;
this.shots = 0;
this.shotsongoal = 0;
this.goals = 0;
this.cautions = 0;
this.sendoff = false;
this.fouls = 0;
this.timesfouled = 0;
this.interceptions = 0;
this.dribbles = 0;
this.saves = 0;
var titlerow = document.createElement("TD");
stattable.titlerow.appendChild(titlerow);
titlerow.innerHTML = ""+name+" (#"+number+")";
(function() { var col = document.createElement("TD");stattable.timein.appendChild(col);col.innerHTML = "0:00"; })();
(function() { var col = document.createElement("TD");stattable.goals.appendChild(col);col.innerHTML = "0"; })();
(function() { var col = document.createElement("TD");stattable.shotsongoal.appendChild(col);col.innerHTML = "0"; })();
(function() { var col = document.createElement("TD");stattable.shots.appendChild(col);col.innerHTML = "0"; })();
(function() { var col = document.createElement("TD");stattable.shotaccuracy.appendChild(col);col.innerHTML = "0"; })();
(function() { var col = document.createElement("TD");stattable.assists.appendChild(col);col.innerHTML = "0"; })();
(function() { var col = document.createElement("TD");stattable.passescompleted.appendChild(col);col.innerHTML = "0"; })();
(function() { var col = document.createElement("TD");stattable.passesattempted.appendChild(col);col.innerHTML = "0"; })();
(function() { var col = document.createElement("TD");stattable.passaccuracy.appendChild(col);col.innerHTML = "0"; })();
(function() { var col = document.createElement("TD");stattable.interceptions.appendChild(col);col.innerHTML = "0"; })();
(function() { var col = document.createElement("TD");stattable.fouls.appendChild(col);col.innerHTML = "0"; })();
(function() { var col = document.createElement("TD");stattable.timesfouled.appendChild(col);col.innerHTML = "0"; })();
(function() { var col = document.createElement("TD");stattable.dribbles.appendChild(col);col.innerHTML = "0"; })();
(function() { var col = document.createElement("TD");stattable.saves.appendChild(col);col.innerHTML = "0"; })();
}
function playercopy(index) {
if (players[index]) {
this.index = index;
this.name = players[index].name;
this.number = players[index].number;
this.time = 0; /*milliseconds*/
this.timehandler = {}, /* stores temporary variables in order to monitor player time */
this.passescompleted = 0;
this.passesattempted = 0;
this.assists = 0;
this.shots = 0;
this.shotsongoal = 0;
this.goals = 0;
this.cautions = 0;
this.sendoff = false;
this.fouls = 0;
this.timesfouled = 0;
this.interceptions = 0;
this.dribbles = 0;
this.saves = 0;
this.setToPlayer(index);
}
}
playercopy.prototype.setToPlayer = function(index) {
var index = parseInt(index);
var copyProp = Object.keys(this);
for ( i=0 ; i< copyProp.length ; i++ ) {
delete this[copyProp[i]];
}
var newProp = Object.keys(players[index]);
for ( i=0 ; i= 2) {
this.cautions = 2;
return undefined;
} else {
this.cautions = parseInt(this.cautions) + add;
if (parseInt(this.cautions) >= 2) {
this.cautions = 2;
this.addsendoff();
}
}
return this.cautions;
};
player.prototype.addsendoff = function() {
if (this.sendoff == true) {
var mistake = confirm(this.name+" (#"+this.number+") has already been sent off. If this was a mistake and you would like to revoke the sendoff, click cancel.");
if (mistake == false) this.sendoff = false;
} else {
this.sendoff = true;
this.outgame();
}
return this.sendoff;
};
var sendoffcheck = function(p) {
if (p.sendoff == true || parseInt(p.cautions) >=2) {
var mistake = confirm("ERROR: "+p.name+" (#"+p.number+") has been sent off. Therefore, this player cannot be modified.\n\nIf this was a mistake, hit cancel and the sendoff will be revoked.");
if (mistake == false) {
p.sendoff = false;
if (parseInt(p.cautions) == 2) do { p.cautions = prompt("According to your input, this player has two cautions. Please enter actual number of cautions."); }while(parseInt(p.cautions) >= 2 && parseInt(p.cautions) % 1 == 0);
return true;
} else {
return undefined;
}
} else {
return true;
}
};
var stattable = {
table: document.createElement("TABLE"),
tbody: document.createElement("TBODY"),
titlerow: document.createElement("TR"),
timein: document.createElement("TR"),
goals: document.createElement("TR"),
shotsongoal: document.createElement("TR"),
shots: document.createElement("TR"),
shotaccuracy: document.createElement("TR"),
assists: document.createElement("TR"),
passescompleted: document.createElement("TR"),
passesattempted: document.createElement("TR"),
passaccuracy: document.createElement("TR"),
interceptions: document.createElement("TR"),
fouls: document.createElement("TR"),
timesfouled: document.createElement("TR"),
dribbles: document.createElement("TR"),
saves: document.createElement("TR"),
};
stattable.table.setAttribute("border","1");
stattable.table.setAttribute("style","padding: 2px;");
stattable.titlerow.setAttribute("style","background-color:black;color:white;");
(function() { var col = document.createElement("TD");col.setAttribute("style","background-color:black;color:white;");stattable.titlerow.appendChild(col);col.innerHTML = "";})();
(function() { var col = document.createElement("TD");col.setAttribute("style","background-color:black;color:white;");stattable.timein.appendChild(col);col.innerHTML = "Time (Minutes:Seconds)";})();
(function() { var col = document.createElement("TD");col.setAttribute("style","background-color:black;color:white;");stattable.goals.appendChild(col);col.innerHTML = "Goals";})();
(function() { var col = document.createElement("TD");col.setAttribute("style","background-color:black;color:white;");stattable.shotsongoal.appendChild(col);col.innerHTML = "Shots on Goal";})();
(function() { var col = document.createElement("TD");col.setAttribute("style","background-color:black;color:white;");stattable.shots.appendChild(col);col.innerHTML = "Shots";})();
(function() { var col = document.createElement("TD");col.setAttribute("style","background-color:black;color:white;");stattable.shotaccuracy.appendChild(col);col.innerHTML = "Shot Accuracy";})();
(function() { var col = document.createElement("TD");col.setAttribute("style","background-color:black;color:white;");stattable.assists.appendChild(col);col.innerHTML = "Assists";})();
(function() { var col = document.createElement("TD");col.setAttribute("style","background-color:black;color:white;");stattable.passescompleted.appendChild(col);col.innerHTML = "Passes Completed";})();
(function() { var col = document.createElement("TD");col.setAttribute("style","background-color:black;color:white;");stattable.passesattempted.appendChild(col);col.innerHTML = "Passes Attempted";})();
(function() { var col = document.createElement("TD");col.setAttribute("style","background-color:black;color:white;");stattable.passaccuracy.appendChild(col);col.innerHTML = "Pass Accuracy";})();
(function() { var col = document.createElement("TD");col.setAttribute("style","background-color:black;color:white;");stattable.interceptions.appendChild(col);col.innerHTML = "Interceptions";})();
(function() { var col = document.createElement("TD");col.setAttribute("style","background-color:black;color:white;");stattable.fouls.appendChild(col);col.innerHTML = "Fouls";})();
(function() { var col = document.createElement("TD");col.setAttribute("style","background-color:black;color:white;");stattable.timesfouled.appendChild(col);col.innerHTML = "Times Fouled";})();
(function() { var col = document.createElement("TD");col.setAttribute("style","background-color:black;color:white;");stattable.dribbles.appendChild(col);col.innerHTML = "Dribbles";})();
(function() { var col = document.createElement("TD");col.setAttribute("style","background-color:black;color:white;");stattable.saves.appendChild(col);col.innerHTML = "Saves";})();
stattable.tbody.appendChild(stattable.titlerow);
stattable.tbody.appendChild(stattable.timein);
stattable.tbody.appendChild(stattable.goals);
stattable.tbody.appendChild(stattable.shotsongoal);
stattable.tbody.appendChild(stattable.shots);
stattable.tbody.appendChild(stattable.shotaccuracy);
stattable.tbody.appendChild(stattable.assists);
stattable.tbody.appendChild(stattable.passescompleted);
stattable.tbody.appendChild(stattable.passesattempted);
stattable.tbody.appendChild(stattable.passaccuracy);
stattable.tbody.appendChild(stattable.interceptions);
stattable.tbody.appendChild(stattable.fouls);
stattable.tbody.appendChild(stattable.timesfouled);
stattable.tbody.appendChild(stattable.dribbles);
stattable.tbody.appendChild(stattable.saves);
stattable.table.appendChild(stattable.tbody);
(function() {
var titlerow = document.createElement("TD");
stattable.titlerow.appendChild(titlerow);
titlerow.innerHTML = "Team Total";
(function() { var col = document.createElement("TD");stattable.timein.appendChild(col);col.innerHTML = "N/A"; })();
(function() { var col = document.createElement("TD");stattable.goals.appendChild(col);col.innerHTML = "0"; })();
(function() { var col = document.createElement("TD");stattable.shotsongoal.appendChild(col);col.innerHTML = "0"; })();
(function() { var col = document.createElement("TD");stattable.shots.appendChild(col);col.innerHTML = "0"; })();
(function() { var col = document.createElement("TD");stattable.shotaccuracy.appendChild(col);col.innerHTML = "0"; })();
(function() { var col = document.createElement("TD");stattable.assists.appendChild(col);col.innerHTML = "0"; })();
(function() { var col = document.createElement("TD");stattable.passescompleted.appendChild(col);col.innerHTML = "0"; })();
(function() { var col = document.createElement("TD");stattable.passesattempted.appendChild(col);col.innerHTML = "0"; })();
(function() { var col = document.createElement("TD");stattable.passaccuracy.appendChild(col);col.innerHTML = "0"; })();
(function() { var col = document.createElement("TD");stattable.interceptions.appendChild(col);col.innerHTML = "0"; })();
(function() { var col = document.createElement("TD");stattable.fouls.appendChild(col);col.innerHTML = "0"; })();
(function() { var col = document.createElement("TD");stattable.timesfouled.appendChild(col);col.innerHTML = "0"; })();
(function() { var col = document.createElement("TD");stattable.dribbles.appendChild(col);col.innerHTML = "0"; })();
(function() { var col = document.createElement("TD");stattable.saves.appendChild(col);col.innerHTML = "0"; })();
})();
Array.prototype.sum = function () {
var sum = 0;
for ( i=0 ; i