function roster_validator( MaximumPlayerPerTeam,MinimumPlayerPerTeam,isWaivers,BlockSenttoFarmAfterTradeDeadline,isPastTradeDeadline,ProTeamEliminatedCannotSendPlayerstoFarm,isEliminated,ForceCorrect10LinesupbeforeSaving,
ProMinC,ProMinLW,ProMinRW,ProMinD,ProMinForward,ProGoalerInGame,ProPlayerInGame,ProPlayerLimit,
FarmMinC,FarmMinLW,FarmMinRW,FarmMinD,FarmMinForward,FarmGoalerInGame,FarmPlayerInGame,FarmPlayerLimit,MaxFarmOv,MaxFarmOvGoaler,GamesLeft,FullFarmEnable,MaxFarmSalary){
//Must have at least 18 players on the Pro Roster and farm if FullFarm enabled.
var FullRoster = 18;
var MinimumGoaliesDressed = 2;
// Declare variables needed inside the loop. Set to Null
var explode, status, proPlayerLimit, farmPlayerLimit, playerProToFarmTradeDeadline, playerProToFarmEliminated;
// Declare variables with a default value of empty text or 0
var playerCount = 0, waiverCount = 0;
var errorText = '', waiverText = '', s = '';
// Declare array variables for counting during the loops
var pro = [], proDress = [], farm = [], farmDress = [];
for(s=0;s<=5;s++){
pro[s] = [];
proDress[s] = [];
farm[s] = [];
farmDress[s] = [];
}
// Declare variables for validation.
var validated = true;
var lineValidated = [false,false,false,false,false,false,false,false,false,false];
var waiverList = [];
var injsus = false;
var positionNumbers = position_number_array(); // array;
// Loop through how many games are left up to 10.
// Only 1 if no schedule.
for(g=1;g<=GamesLeft;g++){
// Get the players from the current gameleft. And set the error element to display errors.
// Reset error text for each gameleft.
var players = document.getElementsByClassName( 'rosterline'+g ), res = {}, i;
errorElement = document.getElementById('errors rostererror' + g);
errorText = '';
// Reset count of pro and farm positions
for(s=0;s<=5;s++){
pro[s][g] = 0;
proDress[s][g] = 0;
farm[s][g] = 0;
farmDress[s][g] = 0;
}
// Reset other variables.
playerProToFarmTradeDeadline = 0;
playerProToFarmEliminated = 0;
// Loop through each player
for (x = 0; x < players.length; x++) {
// Split the value at the pipe "|" and use each section for checking.
//Anthony Marchant|571|1|C|3|80|true|anthonymarchant|false|100|2|1999000|true|true
// 0 = Name
// 1 = Number
// 2 = Position Number
// 3 = Position String
// 4 = Status1
// 5 = Overall
// 6 = ForceWaiver
// 7 = NameID
// 8 = Injure/Suspension
// 9 = Condition
//10 = Contract
//11 = Salary1
//12 = CanPlayPro
//13 = CamPlayFarm
explode = players[x].value.split("|");
// If the explode array only has 2 sections then its a change in which status we are going through.
if(explode.length == 2){
if(explode[1] == "ProDress"){status = 3;}
else if (explode[1] == "ProScratch"){status = 2;}
else if (explode[1] == "FarmDress"){status = 1;}
else{status = 0;}
// Else its a player and increment variables where needed
}else{
if(g == 1){playerCount++;}
injsus = (explode[8] == 'true' || explode[9] <= 95) ? true : false;
// explode[2] is PositionNumber passed through from the SQLite record. ie 1=centre 16 = goalie
for(p=0;p<=5;p++){
if(inArray(explode[2],positionNumbers[p])){
if(status == 3){pro[p][g]++;proDress[p][g]++;}
else if(status == 2 && !injsus){pro[p][g]++;}
else if(status == 1){farm[p][g]++;farmDress[p][g]++;}
else if(status == 0){farm[p][g]++;}
}
}
var elem = document.getElementById('line1_'+explode[7]);
// If flagged properly and trying to send to farm, not allowed if sending player to the farm after trade deadline
if(BlockSenttoFarmAfterTradeDeadline == "true" && isPastTradeDeadline == "true" && explode[4] >= 2 && status <= 1){playerProToFarmTradeDeadline++;}
// If flagged properly and trying to send to farm, not allowed if sending player to the farm if eliminated from the playoffs
if(ProTeamEliminatedCannotSendPlayerstoFarm == "true" && isEliminated == "true" && explode[4] >= 2 && status <= 1){playerProToFarmEliminated++;}
// Check for Overall to see if their overall is allowed in the farm
if(status <= 1 && explode[2] != 16 && explode[5] > MaxFarmOv || status <= 1 && explode[2] == 16 && explode[5] > MaxFarmOvGoaler){
errorText += '
' + explode[0] + ' overall is too high for farm.
'
if(elem.className.match(/\bprotofarmov\b/)){var me;}else{elem.className = elem.className + " protofarmov";}
}
// Check for Salary to see if their Salary is allowed in the farm
if(status <= 1 && explode[11] > MaxFarmSalary && MaxFarmSalary > 0){
errorText += '' + explode[0] + ' salary is too high for farm.
'
if(elem.className.match(/\bprotofarmsalary\b/)){var me;}else{elem.className = elem.className + " protofarmsalary";}
}
// Check for if CanPlayPro
if(status >= 2 && explode[12] == "false") {
errorText += '' + explode[0] + ' can\'t play pro.
'
if(elem.className.match(/\bproplaypro\b/)){var me;}else{elem.className = elem.className + " canplaypro";}
}
// Check for if CanPlayFarm
if(status <= 1 && explode[13] == "false") {
errorText += '' + explode[0] + ' can\'t play farm.
'
if(elem.className.match(/\bproplayfarm\b/)){var me;}else{elem.className = elem.className + " canplayfarm";}
}
// If flagged properly and player is forced to waivers set up waiver info. Can only do this on Game 1
if(isWaivers == true && explode[6]=="true" && g == 1 && status <= 1 && explode[4] >= 2){
// Add the movetowaiver class to the li
if(elem.className.match(/\bmovetowaiver\b/)){var me;}else{elem.className = elem.className + " movetowaiver";}
// Remove the li from where it was dropped and tag it to the bottom of the scratch list
elem.parentNode.removeChild(elem);
var scratchlist = document.getElementsByClassName("sortFarmScratch1");
scratchlist[0].appendChild(elem);
}
if (g == 1 && status >= 2){
// If moving the player back up to the pros, remove the some class.
var elemLine = 'line1_' + explode[7];
var elem = document.getElementById(elemLine);
elem.className = elem.className.replace(" movetowaiver","");
elem.className = elem.className.replace(" protofarmsalary","");
elem.className = elem.className.replace(" protofarmov","");
elem.className = elem.className.replace(" canplayfarm","");
}
if (g == 1 && status <= 1){
// If moving the player back up to the farm, remove the some class.
var elemLine = 'line1_' + explode[7];
var elem = document.getElementById(elemLine);
elem.className = elem.className.replace(" canplaypro","");
}
}
}
// Check for waived players
if(g == 1){
for (x = 0; x < players.length; x++) {
// Split the value at the pipe "|" and use each section for checking.
explode = players[x].value.split("|");
// If the explode array only has 2 sections then its a change in which status we are going through.
if(explode.length == 2){
if(explode[1] == "ProDress"){status = 3;}
else if (explode[1] == "ProScratch"){status = 2;}
else if (explode[1] == "FarmDress"){status = 1;}
else{status = 0;}
// Else its a player and increment variables where needed
}else{
if(isWaivers == true && explode[6]=="true" && g == 1 && status <= 1 && explode[4] >= 2){
if(waiverList.indexOf(explode[0]) == -1){
waiverList.push(explode[0]);
}
}
}
}
}
// Add to the waiverText if there is at least a player in the waivers section.
if(waiverList.length > 0 && g == 1){
waiverText = 'Saving will send ' + waiverList.length + ' players to waivers.
';
}
// Add to error text if conditions met.
if(proDress[0][g] < ProMinC){errorText += 'Pro C: ' + proDress[0][g] + ' dressed, ' + ProMinC + ' required.
';}
if(proDress[1][g] < ProMinLW){errorText += 'Pro LW: ' + proDress[1][g] + ' dressed, ' + ProMinLW + ' required.
';}
if(proDress[2][g] < ProMinRW){errorText += 'Pro RW: ' + proDress[2][g] + ' dressed, ' + ProMinRW + ' required.
';}
if(proDress[3][g] < ProMinD){errorText += 'Pro D: ' + proDress[3][g] + ' dressed, ' + ProMinD + ' required.
';}
if(proDress[4][g] < MinimumGoaliesDressed || proDress[4][g] > ProGoalerInGame){errorText += 'Pro G: ' + proDress[4][g] + ' dressed, ' + ProGoalerInGame + ' required.
';}
if(proDress[5][g] < ProMinForward){errorText += 'Pro Fwd: ' + proDress[5][g] + ' dressed, ' + ProMinForward + ' required.
';}
if(proDress[5][g] < FullRoster){errorText += 'Not Enough Pro players dressed.
';}
if(proDress[5][g] > ProPlayerInGame){errorText += 'Too many Pro Dress players.
';}
if(proDress[5][g] > ProPlayerLimit){errorText += 'Too many Pro players.
';}
if(FullFarmEnable){
if(farmDress[0][g] < FarmMinC){errorText += 'Farm C: ' + farmDress[0][g] + ' dressed, ' + FarmMinC + ' required.
';}
if(farmDress[1][g] < FarmMinLW){errorText += 'Farm LW: ' + farmDress[1][g] + ' dressed, ' + FarmMinLW + ' required.
';}
if(farmDress[2][g] < FarmMinRW){errorText += 'Farm RW: ' + farmDress[2][g] + ' dressed, ' + FarmMinRW + ' required.
';}
if(farmDress[5][g] < FarmMinForward){errorText += 'Farm Fwd: ' + farmDress[5][g] + ' dressed, ' + FarmMinForward + ' required.
';}
if(farmDress[3][g] < FarmMinD){errorText += 'Farm D: ' + farmDress[3][g] + ' dressed, ' + FarmMinD + ' required.
';}
if(farmDress[4][g] < MinimumGoaliesDressed || farmDress[4][g] > FarmGoalerInGame){errorText += 'Farm G: ' + farmDress[4][g] + ' dressed, ' + FarmGoalerInGame + ' required.
';}
if(farmDress[5][g] < FullRoster){errorText += 'Not Enough Farm players dressed.
';}
if(farmDress[5][g] > FarmPlayerInGame){errorText += 'Too many Farm Dress players.
';}
if(farmDress[5][g] > FarmPlayerLimit){errorText += 'Too many Farm players.
';}
}
if(playerCount > MaximumPlayerPerTeam){errorText += 'Too many players on your roster.
';}
if(playerCount < MinimumPlayerPerTeam){errorText += 'Not enough players on your roster.
';}
if(playerProToFarmTradeDeadline > 0){errorText += 'Cannot send ' + playerProToFarmTradeDeadline + ' players to the farm. (After Trade Deadline).
';}
if(playerProToFarmEliminated > 0){errorText += 'Cannot send ' + playerProToFarmEliminated + ' players to the farm. (Eliminated From Playoffs).
';}
// If the error text is empty still then the roster is complete and display
if(errorText == ''){
errorElement.innerHTML = waiverText + 'Roster is complete.
';
lineValidated[g] = true;
document.getElementById("saveroster").disabled = false;
// Else there are errors, display them
}else{
var displayErrors = '';
displayErrors += "";
displayErrors += " ";
displayErrors += errorText;
displayErrors += "
";
errorElement.innerHTML = waiverText + displayErrors;
document.getElementById("saveroster").disabled = true;
}
}
// Check to see if the flag is on for forcing all lines completed before saving.
// If not just check the first line.
if(ForceCorrect10LinesupbeforeSaving && GamesLeft > 1){
for(var g=1;g<=GamesLeft;g++){
if(lineValidated[g]){
validated = true;
}else{
validated = false;
break;
}
}
}else{
validated = (lineValidated[1] == true) ? true : false;
}
document.getElementById("saveroster").disabled = (validated) ? false : true;
}