// JavaScript Document
// var at = 0; /* = 12 */
function refreshed() {
	// alert("Page has been refreshed!");
	document.getElementById('nm').value = '';
	document.getElementById('at').value = '';
	document.getElementById('df').value = '';
	document.getElementById('ft').value = '';
	document.getElementById('gk').value = '';
	document.getElementById('mn').value = '';
	document.getElementById('ta').value = '';
	document.getElementById('te').value = '';
	document.getElementById('dt').value = '';
	document.getElementById('di').value = '';
	document.getElementById('mo').value = '';
}

function disableEnterKey(e)
{
	var key;      
//		if(window.event)
//		key = window.event.keyCode; //IE
//	else
		key = e.which; //firefox      
	return (key != 13);
}

function testing(event,number) {
    if( event.keyCode == 13 )
    {
		var wow = document.getElementById(number);
		wow.focus();
	}        
}
	
function hover(a) {
//	alert("hello");
//	alert(a);
//	var abc = document.getElementById(a).className;
//	alert(abc);
	document.getElementById(a).className = a;
	
	switch (a) {
		case 'ft_row': document.getElementById('ftTimes').innerHTML="&times;9";
					   document.getElementById('dtTimes').innerHTML="&times;2";
					   document.getElementById('diTimes').innerHTML="&times;2";
					   document.getElementById('moTimes').innerHTML="&times;2"; break;
					   
		case 'gk_row': document.getElementById('gkTimes').innerHTML="&times;2";
					   document.getElementById('dtTimes').innerHTML="&times;1";
					   document.getElementById('diTimes').innerHTML="&times;1";
					   document.getElementById('moTimes').innerHTML="&times;1"; break;
					   
		case 'ta_row': document.getElementById('taTimes').innerHTML="&times;2";
					   document.getElementById('dtTimes').innerHTML="&times;1";
					   document.getElementById('diTimes').innerHTML="&times;1";
					   document.getElementById('moTimes').innerHTML="&times;1"; break;
					   
		case 'bc_row': document.getElementById('teTimes').innerHTML="&times;6";
					   document.getElementById('mnTimes').innerHTML="&times;3";
					   document.getElementById('dtTimes').innerHTML="&times;2";
					   document.getElementById('diTimes').innerHTML="&times;2";
					   document.getElementById('moTimes').innerHTML="&times;2"; break;
					   
		case 'df_row': document.getElementById('dfTimes').innerHTML="&times;8";
					   document.getElementById('taTimes').innerHTML="&times;3";
					   document.getElementById('dtTimes').innerHTML="&times;3";
					   document.getElementById('diTimes').innerHTML="&times;3";
					   document.getElementById('moTimes').innerHTML="&times;3"; break;
					   
		case 'at_row': document.getElementById('atTimes').innerHTML="&times;6";
					   document.getElementById('taTimes').innerHTML="&times;3";
					   document.getElementById('dtTimes').innerHTML="&times;2";
					   document.getElementById('diTimes').innerHTML="&times;2";
					   document.getElementById('moTimes').innerHTML="&times;2"; break;
					   
		case 'sh_row': document.getElementById('teTimes').innerHTML="&times;6";
					   document.getElementById('atTimes').innerHTML="&times;3";
					   document.getElementById('dtTimes').innerHTML="&times;2";
					   document.getElementById('diTimes').innerHTML="&times;2";
					   document.getElementById('moTimes').innerHTML="&times;2"; break;
					   
		case 'sp_row': document.getElementById('atTimes').innerHTML="&times;3";
					   document.getElementById('mnTimes').innerHTML="&times;3";
					   document.getElementById('teTimes').innerHTML="&times;3";
					   document.getElementById('dtTimes').innerHTML="&times;2";
					   document.getElementById('diTimes').innerHTML="&times;2";
					   document.getElementById('moTimes').innerHTML="&times;2"; break;
	}
}

function hoverOff(a) {
	document.getElementById(a).className = "";
	document.getElementById('atTimes').innerHTML="";
	document.getElementById('dfTimes').innerHTML="";
	document.getElementById('ftTimes').innerHTML="";
	document.getElementById('gkTimes').innerHTML="";
	document.getElementById('mnTimes').innerHTML="";
	document.getElementById('taTimes').innerHTML="";
	document.getElementById('teTimes').innerHTML="";
	document.getElementById('dtTimes').innerHTML="";
	document.getElementById('diTimes').innerHTML="";
	document.getElementById('moTimes').innerHTML="";
}
	
function onlyNum(evt) { // Only allows numbers into the textboxes
	var charCode = (evt.which) ? evt.which : event.keyCode;
	if ((charCode > 31 && (charCode < 48 || charCode > 57))) {
    	return false;
	}
	return true;
}

var at = 0;
var df = 0;
var ft = 0;
var gk = 0;
var mn = 0;
var ta = 0;
var te = 0;
var dt = 0;
var di = 0;
var mo = 0;

var ftRating;
var gkRating;
var taRating;
var bcRating;
var dfRating;
var atRating;
var shRating;
var spRating;

var s_ft; // These are the star ratings for each training area
var s_gk;
var s_ta;
var s_bc;
var s_df;
var s_at;
var s_sh;
var s_sp;

function updateResult() {	
	calcFtRating();
	calcGkRating();
	calcTaRating();
	calcBcRating();
	calcDfRating();
	calcAtRating();
	calcShRating();
	calcSpRating();
	
	var ft_total = document.getElementById('ft_total').innerHTML;
	var gk_total = document.getElementById('gk_total').innerHTML;
	var ta_total = document.getElementById('ta_total').innerHTML;
	var bc_total = document.getElementById('bc_total').innerHTML;
	var df_total = document.getElementById('df_total').innerHTML;
	var at_total = document.getElementById('at_total').innerHTML;
	var sh_total = document.getElementById('sh_total').innerHTML;
	var sp_total = document.getElementById('sp_total').innerHTML;
	
	ft_total = ft_total / 300;
	gk_total = gk_total / 100;
	ta_total = ta_total / 100;
	bc_total = bc_total / 300;
	df_total = df_total / 400;
	at_total = at_total / 300;
	sh_total = sh_total / 300;
	sp_total = sp_total / 300;
	
	var totCheck = [ft_total,gk_total,ta_total,bc_total,df_total,at_total,sh_total,sp_total];
	
	totCheck = totCheck.sort(sortNumber);
	var bestRatio = totCheck.pop();
	var aAn;
	var dontDisplay;
	if (bestRatio == 0) { dontDisplay = 1; }
	else if (bestRatio == ft_total) { (best = "Fitness Coach") && ( aAn = "a" ) }
	else if (bestRatio == gk_total) { (best = "Goalkeeping Coach") && ( aAn = "a" ) }
	else if (bestRatio == ta_total) { (best = "Tactical Coach") && ( aAn = "a" ) }
	else if (bestRatio == bc_total) { (best = "Ball Control Coach") && ( aAn = "a" ) }
	else if (bestRatio == df_total) { (best = "Defensive Coach") && ( aAn = "a" ) }
	else if (bestRatio == at_total) { (best = "Attacking Coach") && ( aAn = "an" ) }
	else if (bestRatio == sh_total) { (best = "Shooting Coach") && ( aAn = "a" ) }
	else if (bestRatio == sp_total) { (best = "Set Piece Coach") && ( aAn = "a" ) }
	else { best = "ERROR" }
	
	var best_star_rating;
	if (best == "Fitness Coach") { best_star_rating = document.getElementById('ft_star_rating').innerHTML }
	if (best == "Goalkeeping Coach") { best_star_rating = document.getElementById('gk_star_rating').innerHTML }
	if (best == "Tactical Coach") { best_star_rating = document.getElementById('ta_star_rating').innerHTML }
	if (best == "Ball Control Coach") { best_star_rating = document.getElementById('bc_star_rating').innerHTML }
	if (best == "Defensive Coach") { best_star_rating = document.getElementById('df_star_rating').innerHTML }
	if (best == "Attacking Coach") { best_star_rating = document.getElementById('at_star_rating').innerHTML }
	if (best == "Shooting Coach") { best_star_rating = document.getElementById('sh_star_rating').innerHTML }
	if (best == "Set Piece Coach") { best_star_rating = document.getElementById('sp_star_rating').innerHTML }
	
	var reputation_rating;
	if (best_star_rating == "&lt;5") { reputation_rating = "an Average"; }
	else if (best_star_rating == "5") { reputation_rating = "a Good"; }
	else if (best_star_rating == "6") { reputation_rating = "a Quality"; }
	else if (best_star_rating == "7") { reputation_rating = "a World Class"; }
	
	var name = document.getElementById('nm').value;
	if (name != '') { document.getElementById('thisCoach').innerHTML = name; }
	
	document.getElementById('rep_rating').innerHTML = reputation_rating;
	document.getElementById('aAn').innerHTML = aAn;
	document.getElementById('coach').innerHTML = best;
	document.getElementById('coach2').innerHTML = best;
	
	if (dontDisplay != 1) { document.getElementById('lingo_group').style.visibility = 'visible'; }
	 else { document.getElementById('lingo_group').style.visibility = 'hidden'; }
}

function sortNumber(a,b) {
	return a - b;
}

function getElementId_at() {
	at = document.getElementById('at').value;
	at = +at; // converts the input into a number
	if (at > 20) {
		at = 20;
	}
	document.getElementById('at').value = at;
	updateResult();
}

function getElementId_df() {
	df = document.getElementById('df').value;
	df = +df; // converts the input into a number
	if (df > 20) {
		df = 20;
	}
	document.getElementById('df').value = df;
	updateResult();
}

function getElementId_ft() {
	ft = document.getElementById('ft').value;
	ft = +ft; // converts the input into a number
	if (ft > 20) {
		ft = 20;
	}
	document.getElementById('ft').value = ft;
	updateResult();
}

function getElementId_gk() {
	gk = document.getElementById('gk').value;
	gk = +gk; // converts the input into a number
	if (gk > 20) {
		gk = 20;
	}
	document.getElementById('gk').value = gk;
	updateResult();
}

function getElementId_mn() {
	mn = document.getElementById('mn').value;
	mn = +mn; // converts the input into a number
	if (mn > 20) {
		mn = 20;
	}
	document.getElementById('mn').value = mn;
	updateResult();
}

function getElementId_ta() {
	ta = document.getElementById('ta').value;
	ta = +ta; // converts the input into a number
	if (ta > 20) {
		ta = 20;
	}
	document.getElementById('ta').value = ta;
	updateResult();
}

function getElementId_te() {
	te = document.getElementById('te').value;
	te = +te; // converts the input into a number
	if (te > 20) {
		te = 20;
	}
	document.getElementById('te').value = te;
	updateResult();
}

function getElementId_dt() {
	dt = document.getElementById('dt').value;
	dt = +dt; // converts the input into a number
	if (dt > 20) {
		dt = 20;
	}
	document.getElementById('dt').value = dt;
	updateResult();
}

function getElementId_di() {
	di = document.getElementById('di').value;
	di = +di; // converts the input into a number
	if (di > 20) {
		di = 20;
	}
	document.getElementById('di').value = di;
	updateResult();
}

function getElementId_mo() {
	mo = document.getElementById('mo').value;
	mo = +mo; // converts the input into a number
	if (mo > 20) {
		mo = 20;
	}
	document.getElementById('mo').value = mo;
	updateResult();
}

function calcFtRating() {
	ftRating = ft * 9 + (dt + di + mo) * 2;
	ft_star_class = document.getElementById('ft_star_rating').className;	
	ft_total_class = document.getElementById('ft_total').className;

	if (ftRating < 210) { (s_ft = "<5") && (ft_star_class = "star bold grey") && (ft_total_class = "grey"); }
	else if (ftRating < 240) { (s_ft = 5) && (ft_star_class = "star bold") && (ft_total_class = ""); }
	else if (ftRating < 270) { (s_ft = 6) && (ft_star_class = "star bold warm") && (ft_total_class = "warm"); }
	else { (s_ft = 7) && (ft_star_class = "star bold hot") && (ft_total_class = "hot"); }

	document.getElementById('ft_star_rating').innerHTML = s_ft;
	document.getElementById('ft_star_rating').className = ft_star_class;
	document.getElementById('ft_total').innerHTML = ftRating;
	document.getElementById('ft_total').className = ft_total_class;
}

function calcGkRating() {
	gkRating = gk * 2 + dt + di + mo;
	gk_star_class = document.getElementById('gk_star_rating').className;	
	gk_total_class = document.getElementById('gk_total').className;

	if (gkRating < 70) { (s_gk = "<5") && (gk_star_class = "star bold grey") && (gk_total_class = "grey"); }
	else if (gkRating < 80) { (s_gk = 5) && (gk_star_class = "star bold") && (gk_total_class = ""); }
	else if (gkRating < 90) { (s_gk = 6) && (gk_star_class = "star bold warm") && (gk_total_class = "warm"); }
	else { (s_gk = 7) && (gk_star_class = "star bold hot") && (gk_total_class = "hot"); }

	document.getElementById('gk_star_rating').innerHTML = s_gk;
	document.getElementById('gk_star_rating').className = gk_star_class;
	document.getElementById('gk_total').innerHTML = gkRating;
	document.getElementById('gk_total').className = gk_total_class;
}

function calcTaRating() {
	taRating = ta * 2 + dt + di + mo;
	ta_star_class = document.getElementById('ta_star_rating').className;	
	ta_total_class = document.getElementById('ta_total').className;

	if (taRating < 70) { (s_ta = "<5") && (ta_star_class = "star bold grey") && (ta_total_class = "grey"); }
	else if (taRating < 80) { (s_ta = 5) && (ta_star_class = "star bold") && (ta_total_class = ""); }
	else if (taRating < 90) { (s_ta = 6) && (ta_star_class = "star bold warm") && (ta_total_class = "warm"); }
	else { (s_ta = 7) && (ta_star_class = "star bold hot") && (ta_total_class = "hot"); }
	
	document.getElementById('ta_star_rating').innerHTML = s_ta;
	document.getElementById('ta_star_rating').className = ta_star_class;
	document.getElementById('ta_total').innerHTML = taRating;
	document.getElementById('ta_total').className = ta_total_class;
}

function calcBcRating() {
	bcRating = te * 6 + mn * 3 + (dt + di + mo) * 2;
	bc_star_class = document.getElementById('bc_star_rating').className;	
	bc_total_class = document.getElementById('bc_total').className;

	if (bcRating < 210) { (s_bc = "<5") && (bc_star_class = "star bold grey") && (bc_total_class = "grey"); }
	else if (bcRating < 240) { (s_bc = 5) && (bc_star_class = "star bold") && (bc_total_class = ""); }
	else if (bcRating < 270) { (s_bc = 6) && (bc_star_class = "star bold warm") && (bc_total_class = "warm"); }
	else { (s_bc = 7) && (bc_star_class = "star bold hot") && (bc_total_class = "hot"); }

	document.getElementById('bc_star_rating').innerHTML = s_bc;
	document.getElementById('bc_star_rating').className = bc_star_class;
	document.getElementById('bc_total').innerHTML = bcRating;
	document.getElementById('bc_total').className = bc_total_class;
}

function calcDfRating() {
	dfRating = df * 8 + (ta + dt + di + mo) * 3;
	df_star_class = document.getElementById('df_star_rating').className;	
	df_total_class = document.getElementById('df_total').className;

	if (dfRating < 280) { (s_df = "<5") && (df_star_class = "star bold grey") && (df_total_class = "grey"); }
	else if (dfRating < 320) { (s_df = 5) && (df_star_class = "star bold") && (df_total_class = ""); }
	else if (dfRating < 360) { (s_df = 6) && (df_star_class = "star bold warm") && (df_total_class = "warm"); }
	else { (s_df = 7) && (df_star_class = "star bold hot") && (df_total_class = "hot"); }

	document.getElementById('df_star_rating').innerHTML = s_df;
	document.getElementById('df_star_rating').className = df_star_class;
	document.getElementById('df_total').innerHTML = dfRating;
	document.getElementById('df_total').className = df_total_class;
}

function calcAtRating() {
	atRating = at * 6 + ta * 3 + (dt + di + mo) * 2;
	at_star_class = document.getElementById('at_star_rating').className;	
	at_total_class = document.getElementById('at_total').className;

	if (atRating < 210) { (s_at = "<5") && (at_star_class = "star bold grey") && (at_total_class = "grey"); }
	else if (atRating < 240) { (s_at = 5) && (at_star_class = "star bold") && (at_total_class = ""); }
	else if (atRating < 270) { (s_at = 6) && (at_star_class = "star bold warm") && (at_total_class = "warm"); }
	else { (s_at = 7) && (at_star_class = "star bold hot") && (at_total_class = "hot"); }

	document.getElementById('at_star_rating').innerHTML = s_at;
	document.getElementById('at_star_rating').className = at_star_class;
	document.getElementById('at_total').innerHTML = atRating;
	document.getElementById('at_total').className = at_total_class;
}

function calcShRating() {
	shRating = te * 6 + at * 3 + (dt + di + mo) * 2;
	sh_star_class = document.getElementById('sh_star_rating').className;	
	sh_total_class = document.getElementById('sh_total').className;

	if (shRating < 210) { (s_sh = "<5") && (sh_star_class = "star bold grey") && (sh_total_class = "grey"); }
	else if (shRating < 240) { (s_sh = 5) && (sh_star_class = "star bold") && (sh_total_class = ""); }
	else if (shRating < 270) { (s_sh = 6) && (sh_star_class = "star bold warm") && (sh_total_class = "warm"); }
	else { (s_sh = 7) && (sh_star_class = "star bold hot") && (sh_total_class = "hot"); }

	document.getElementById('sh_star_rating').innerHTML = s_sh;
	document.getElementById('sh_star_rating').className = sh_star_class;
	document.getElementById('sh_total').innerHTML = shRating;
	document.getElementById('sh_total').className = sh_total_class;
}

function calcSpRating() {
	spRating = (at + mn + te) * 3 + (dt + di + mo) * 2;
	sp_star_class = document.getElementById('sp_star_rating').className;	
	sp_total_class = document.getElementById('sp_total').className;
	
	if (spRating < 210) { (s_sp = "<5") && (sp_star_class = "star bold grey") && (sp_total_class = "grey"); }
	else if (spRating < 240) { (s_sp = 5) && (sp_star_class = "star bold") && (sp_total_class = ""); }
	else if (spRating < 270) { (s_sp = 6) && (sp_star_class = "star bold warm") && (sp_total_class = "warm"); }
	else { (s_sp = 7) && (sp_star_class = "star bold hot") && (sp_total_class = "hot"); }
	
	document.getElementById('sp_star_rating').innerHTML = s_sp;
	document.getElementById('sp_star_rating').className = sp_star_class;
	document.getElementById('sp_total').innerHTML = spRating;
	document.getElementById('sp_total').className = sp_total_class;
}