HEAD-TO-HEAD REPORT by Habman

Description:
This script lays out all of the head to head matchups in table form.

Examples:
Click the Head-to-Head Report button on the following linked page:

    Sample Report
Implementation:
<style>

#habmanHTH {text-align:center}

#habmanHTH caption{display:table-caption!important;white-space:nowrap}

#habmanHTH_populating { font-style:italic; }

#habmanHTH_tableLegend {width:auto}

.habmanHTH_franchise {white-space:nowrap}

.habmanHTH_total {text-align:center}

.habmanHTH_week {text-align:center}

.habmanHTH_img {height:24px;width:auto;max-width:50px}

.habmanHTH_na {font-size:x-small!important;background-color:lightgray!important;color:darkgray!important}

.habmanHTH_isFuture{font-size:x-small;color:darkgray;white-space:nowrap}

.habmanHTH_ptsScored {display:block;font-size:smaller}

.habmanHTH_record {display:block;white-space:nowrap}

.habmanHTH_record_total, .habmanHTH_pf_total, .habmanHTH_pa_total {display:block;font-weight:bold;text-align:center;white-space:nowrap}

.habmanHTH_hilite {background-color:khaki!important}

.habmanHTH_win {color:green; font-weight:bold}

.habmanHTH_loss {color:red; font-weight:bold}

.habmanHTH_tie {color:black; font-weight:bold}



.habmanHTH_tooltip {position: relative; display: inline-block; cursor:zoom-in}

.habmanHTH_tooltip .habmanHTH_tooltiptext { width: 120px; margin-left: -60px; visibility: hidden; background-color: #555; color: #fff; text-align: center; border-radius: 6px; padding: 5px 0; position: absolute; z-index: 1; bottom: 125%; left: 50%; opacity: 0; transition: opacity 0.3s;}

.habmanHTH_tooltip .habmanHTH_tooltiptext.habmanHTH_tooltipleft { margin-left: -90px;}

.habmanHTH_tooltip .habmanHTH_tooltiptext::after { margin-left: -5px; content: ""; position: absolute; top: 100%; left: 50%; border-width: 5px; border-style: solid; border-color: #555 transparent transparent transparent;}

.habmanHTH_tooltip .habmanHTH_tooltiptext.habmanHTH_tooltipleft::after { margin-left: 25px;}

.habmanHTH_tooltip:hover .habmanHTH_tooltiptext { visibility: visible; opacity: 1;}

</style>
<div id="habmanHTH"></div>

<script>

//CUSTOM SETTINGS

var habmanHTH_weeks = 13; //weeks to include

var habmanHTH_precision = 1; //decimal places

var habmanHTH_includeFuture = true; 

var habmanHTH_buttonText = "Head-to-Head Report";



///////////////////////////////////////////////

//NO NEED TO EDIT BELOW THIS LINE

///////////////////////////////////////////////

if(habmanHTH_weeks==undefined) var habmanHTH_weeks = 13;

if(habmanHTH_precision==undefined) var habmanHTH_precision = 1;

if(habmanHTH_includeFuture==undefined) var habmanHTH_includeFuture = true;

if(habmanHTH_buttonText==undefined) var habmanHTH_buttonText = "Head-to-Head Report";



var habmanHTH_fid = new Array();

var habmanHTH_results = new Array();

var habmanHTH_resultsHTH = new Array();

function habmanHTH_hilite(remove,rowFid,colFid){

	if(remove)

		$(".hthHilite").removeClass("habmanHTH_hilite");

	else {

		$(".hthHilite_row_"+rowFid).addClass("habmanHTH_hilite");

		$(".hthHilite_col_"+colFid).addClass("habmanHTH_hilite");

	}

}

function habmanHTH_createHTML(){

	var html='';

	html+='<div class="mobile-wrap">';

	html+='<table align="center" cellspacing="1" class="homepagemodule report" id="habmanHTH_tableHTH"><caption><span>'+habmanHTH_buttonText+'</span></caption>';

	html+='<tr><th rowspan="2">Franchise</th><th colspan="3">Season</th><th colspan="'+habmanHTH_fid.length+'">Opponent</th></tr>';

	html+='<tr><th>Record</th><th>PF</th><th>PA</th>';

	var fidStr = new Array();

	for(var i=0;i<habmanHTH_fid.length;i++) {

		fidStr[i]='';

		if(franchiseDatabase["fid_"+habmanHTH_fid[i]].icon!=undefined&&franchiseDatabase["fid_"+habmanHTH_fid[i]].icon!='')

			var fIcon = '<img src="'+franchiseDatabase["fid_"+habmanHTH_fid[i]].icon+'" title="'+franchiseDatabase["fid_"+habmanHTH_fid[i]].name+'" class="habmanHTH_img" />';

		else if(franchiseDatabase["fid_"+habmanHTH_fid[i]].logo!=undefined&&franchiseDatabase["fid_"+habmanHTH_fid[i]].logo!='')

			var fIcon = '<img src="'+franchiseDatabase["fid_"+habmanHTH_fid[i]].logo+'" title="'+franchiseDatabase["fid_"+habmanHTH_fid[i]].name+'" class="habmanHTH_img" />';

		else if(franchiseDatabase["fid_"+habmanHTH_fid[i]].abbrev!=undefined&&franchiseDatabase["fid_"+habmanHTH_fid[i]].abbrev!='')

			var fIcon = '<span title="'+franchiseDatabase["fid_"+habmanHTH_fid[i]].name+'">'+franchiseDatabase["fid_"+habmanHTH_fid[i]].abbrev+'</span>';

		else {

			var fIcon = '<span title="'+franchiseDatabase["fid_"+habmanHTH_fid[i]].name+'">'+habmanHTH_fid[i]+'</span>';

			fidStr[i] = ' ('+habmanHTH_fid[i]+')';

		}		

		html+='<th class="hthHilite hthHilite_col_'+habmanHTH_fid[i]+'">'+fIcon+'</th>';

	}

	html+='</tr>';

	for(var i=0;i<habmanHTH_fid.length;i++){

		if(i%2)

			html+='<tr class="eventablerow hthHilite hthHilite_row_'+habmanHTH_fid[i]+'">';

		else

			html+='<tr class="oddtablerow hthHilite hthHilite_row_'+habmanHTH_fid[i]+'">';



		if(franchiseDatabase["fid_"+habmanHTH_fid[i]].icon!=undefined&&franchiseDatabase["fid_"+habmanHTH_fid[i]].icon!='')

			var fIcon = '<img src="'+franchiseDatabase["fid_"+habmanHTH_fid[i]].icon+'" title="'+franchiseDatabase["fid_"+habmanHTH_fid[i]].name+'" class="habmanHTH_img" /> ';

		else if(franchiseDatabase["fid_"+habmanHTH_fid[i]].logo!=undefined&&franchiseDatabase["fid_"+habmanHTH_fid[i]].logo!='')

			var fIcon = '<img src="'+franchiseDatabase["fid_"+habmanHTH_fid[i]].logo+'" title="'+franchiseDatabase["fid_"+habmanHTH_fid[i]].name+'" class="habmanHTH_img" /> ';

		else 

			var fIcon = '';

		var fName = '<a class="franchise_'+habmanHTH_fid[i]+'" href="'+baseURLDynamic+'/'+year+'/options?L='+league_id+'&F='+habmanHTH_fid[i]+'&O=01">'+franchiseDatabase["fid_"+habmanHTH_fid[i]].name+'</a>'+fidStr[i];

		

		html+='<td class="franchise_'+habmanHTH_fid[i]+' habmanHTH_franchise">'+fIcon+fName+'</td>';

		html+='<td class="habmanHTH_total"><span class="habmanHTH_record_total">'+habmanHTH[habmanHTH_fid[i]]["totals"].w+'-'+habmanHTH[habmanHTH_fid[i]]["totals"].l+'-'+habmanHTH[habmanHTH_fid[i]]["totals"].t+'</span></td>';

		html+='<td class="habmanHTH_total"><span class="habmanHTH_pf_total">'+habmanHTH[habmanHTH_fid[i]]["totals"].pf.toFixed(habmanHTH_precision)+'</span></td>';

		html+='<td class="habmanHTH_total"><span class="habmanHTH_pa_total">'+habmanHTH[habmanHTH_fid[i]]["totals"].pa.toFixed(habmanHTH_precision)+'</span></td>';

		for(var j=0;j<habmanHTH_fid.length;j++){

			if(i==j)

				html+='<td class="habmanHTH_week habmanHTH_na hthHilite hthHilite_col_'+habmanHTH_fid[j]+'" onmouseover="habmanHTH_hilite(false,\''+habmanHTH_fid[i]+'\',\''+habmanHTH_fid[j]+'\')" onmouseout="habmanHTH_hilite(true)">x</td>';

			else {

				if(habmanHTH[habmanHTH_fid[i]][habmanHTH_fid[j]]==undefined)

					html+='<td class="habmanHTH_week hthHilite hthHilite_col_'+habmanHTH_fid[j]+'" onmouseover="habmanHTH_hilite(false,\''+habmanHTH_fid[i]+'\',\''+habmanHTH_fid[j]+'\')" onmouseout="habmanHTH_hilite(true)">-</td>';

				else {

					html+='<td class="habmanHTH_week hthHilite hthHilite_col_'+habmanHTH_fid[j]+'" onmouseover="habmanHTH_hilite(false,\''+habmanHTH_fid[i]+'\',\''+habmanHTH_fid[j]+'\')" onmouseout="habmanHTH_hilite(true)">';

					for (var k=0;k<habmanHTH[habmanHTH_fid[i]][habmanHTH_fid[j]].length;k++) {

						var game = habmanHTH[habmanHTH_fid[i]][habmanHTH_fid[j]][k];

						if(j==(habmanHTH_fid.length-1)) var tooltipLeft = " habmanHTH_tooltipleft"; else var tooltipLeft="";

						if(k>0) var br=', '; else var br='';

						if(game.isFuture) {

							var titleStr='Wk '+game.week+' Spread: '+game.spread;

								html+=br+'<div class="habmanHTH_tooltip"><span class="habmanHTH_isFuture">wk '+game.week+'</span><span class="habmanHTH_tooltiptext'+tooltipLeft+'">'+titleStr+'</span></div>';

						} else {

							if(parseInt(game.isHome)==1)

								var titleStr='Wk '+game.week+': '+game.result+' '+game.score+' vs '+game.oppScore;

							else

								var titleStr='Wk '+game.week+': '+game.result+' '+game.score+' at '+game.oppScore;

							if(game.result=="W")

								html+=br+'<div class="habmanHTH_tooltip habmanHTH_win">W<span class="habmanHTH_tooltiptext'+tooltipLeft+'">'+titleStr+'</span></div>';

							else if(game.result=="L")

								html+=br+'<div class="habmanHTH_tooltip habmanHTH_loss">L<span class="habmanHTH_tooltiptext'+tooltipLeft+'">'+titleStr+'</span></div>';

							else

								html+=br+'<div class="habmanHTH_tooltip habmanHTH_tie">T<span class="habmanHTH_tooltiptext'+tooltipLeft+'">'+titleStr+'</span></div>';

						}

					}

					html+='</td>';

				}

			}

		}

		html+='</tr>';

	}

	html+='</table>';

	html+='</div>';

	

	$("#habmanHTH").html(html);

}

function habmanHTH_sortResults(){

	for (var fid in habmanHTH) {

		if(habmanHTH.hasOwnProperty(fid)) {

			habmanHTH_fid.push(fid);

		}

	}

	for(var i=0;i<habmanHTH_fid.length;i++){

		for(var j=0;j<(habmanHTH_fid.length - i -1);j++) {

			var currPts = habmanHTH[habmanHTH_fid[j]]["totals"].w*2+habmanHTH[habmanHTH_fid[j]]["totals"].t;

			var nextPts = habmanHTH[habmanHTH_fid[j+1]]["totals"].w*2+habmanHTH[habmanHTH_fid[j+1]]["totals"].t;

			var currPf = habmanHTH[habmanHTH_fid[j]]["totals"].pf;

			var nextPf = habmanHTH[habmanHTH_fid[j+1]]["totals"].pf;

			if(currPts<nextPts || (currPts==nextPts&&currPf<nextPf) ) {

				var temp = habmanHTH_fid[j];

				habmanHTH_fid[j] = habmanHTH_fid[j+1];

				habmanHTH_fid[j+1] = temp;

			}

		}

	}

}

function habmanHTH_populate(){

	//get weekly scores

	var habmanHTH_weeklyResults = new Array();

	var habmanHTH_scores = new Array();

	if(completedWeek>habmanHTH_weeks) var toWeek = habmanHTH_weeks; else var toWeek = completedWeek;

	if(habmanHTH_includeFuture) toWeek = habmanHTH_weeks;

	for (var i=1; i<=toWeek; i++) {

		var url = baseURLDynamic + "/" + year + "/export?TYPE=weeklyResults&L=" + league_id + "&W=" + i + "&JSON=1";

		jQuery.ajax({ 

			url: url, 

			success: function(data) { 

				habmanHTH_weeklyResults[i] = data; 

				try { //MULTI-GAME

					for (var j=0;j<habmanHTH_weeklyResults[i].weeklyResults.matchup.length;j++) {

						var road = habmanHTH_weeklyResults[i].weeklyResults.matchup[j].franchise[0];

						var home = habmanHTH_weeklyResults[i].weeklyResults.matchup[j].franchise[1];

						if(habmanHTH[road.id]==undefined) { habmanHTH[road.id] = new Array(); habmanHTH[road.id]['totals'] = ({ "w":0 , "l":0 , "t":0 , "pf":0 , "pa":0 }); }

						if(habmanHTH[home.id]==undefined) { habmanHTH[home.id] = new Array(); habmanHTH[home.id]['totals'] = ({ "w":0 , "l":0 , "t":0 , "pf":0 , "pa":0 }); }

						if(habmanHTH[road.id][home.id]==undefined) habmanHTH[road.id][home.id] = new Array();

						if(habmanHTH[home.id][road.id]==undefined) habmanHTH[home.id][road.id] = new Array();

						if(i>completedWeek) {

							habmanHTH[road.id][home.id][habmanHTH[road.id][home.id].length] = ({ "week":i , "spread":road.spread , "isHome":road.isHome , "isFuture":true });

							habmanHTH[home.id][road.id][habmanHTH[home.id][road.id].length] = ({ "week":i , "spread":home.spread , "isHome":home.isHome , "isFuture":true });

						} else {

							habmanHTH[road.id][home.id][habmanHTH[road.id][home.id].length] = ({ "week":i , "score":road.score , "oppScore":home.score , "isHome":road.isHome , "result":road.result , "isFuture":false });

							habmanHTH[home.id][road.id][habmanHTH[home.id][road.id].length] = ({ "week":i , "score":home.score , "oppScore":road.score , "isHome":home.isHome , "result":home.result , "isFuture":false });

							

							if(road.result=="W") habmanHTH[road.id]['totals'].w++;

							if(road.result=="L") habmanHTH[road.id]['totals'].l++;

							if(road.result=="T") habmanHTH[road.id]['totals'].t++;

							if(home.result=="W") habmanHTH[home.id]['totals'].w++;

							if(home.result=="L") habmanHTH[home.id]['totals'].l++;

							if(home.result=="T") habmanHTH[home.id]['totals'].t++;

							habmanHTH[road.id]['totals'].pf += parseInt(parseFloat(road.score)*Math.pow(10,habmanHTH_precision))/Math.pow(10,habmanHTH_precision);

							habmanHTH[road.id]['totals'].pa += parseInt(parseFloat(home.score)*Math.pow(10,habmanHTH_precision))/Math.pow(10,habmanHTH_precision);

							habmanHTH[home.id]['totals'].pf += parseInt(parseFloat(home.score)*Math.pow(10,habmanHTH_precision))/Math.pow(10,habmanHTH_precision);

							habmanHTH[home.id]['totals'].pa += parseInt(parseFloat(road.score)*Math.pow(10,habmanHTH_precision))/Math.pow(10,habmanHTH_precision);

						}

					}	

				} catch(er) {}

				try { //SINGLE GAME

					var road = habmanHTH_weeklyResults[i].weeklyResults.matchup.franchise[0];

					var home = habmanHTH_weeklyResults[i].weeklyResults.matchup.franchise[1];

					if(habmanHTH[road.id]==undefined) { habmanHTH[road.id] = new Array(); habmanHTH[road.id]['totals'] = ({ "w":0 , "l":0 , "t":0 , "pf":0 , "pa":0 }); }

					if(habmanHTH[home.id]==undefined) { habmanHTH[home.id] = new Array(); habmanHTH[home.id]['totals'] = ({ "w":0 , "l":0 , "t":0 , "pf":0 , "pa":0 }); }

					if(habmanHTH[road.id][home.id]==undefined) habmanHTH[road.id][home.id] = new Array();

					if(habmanHTH[home.id][road.id]==undefined) habmanHTH[home.id][road.id] = new Array();

					if(i>completedWeek) {

						habmanHTH[road.id][home.id][habmanHTH[road.id][home.id].length] = ({ "week":i , "spread":road.spread , "isHome":road.isHome , "isFuture":true });

						habmanHTH[home.id][road.id][habmanHTH[home.id][road.id].length] = ({ "week":i , "spread":home.spread , "isHome":home.isHome , "isFuture":true });

					} else {

						habmanHTH[road.id][home.id][habmanHTH[road.id][home.id].length] = ({ "week":i , "score":road.score , "oppScore":home.score , "isHome":road.isHome , "result":road.result , "isFuture":false });

						habmanHTH[home.id][road.id][habmanHTH[home.id][road.id].length] = ({ "week":i , "score":home.score , "oppScore":road.score , "isHome":home.isHome , "result":home.result , "isFuture":false });

							

						if(road.result=="W") habmanHTH[road.id]['totals'].w++;

						if(road.result=="L") habmanHTH[road.id]['totals'].l++;

						if(road.result=="T") habmanHTH[road.id]['totals'].t++;

						if(home.result=="W") habmanHTH[home.id]['totals'].w++;

						if(home.result=="L") habmanHTH[home.id]['totals'].l++;

						if(home.result=="T") habmanHTH[home.id]['totals'].t++;

						habmanHTH[road.id]['totals'].pf += parseInt(parseFloat(road.score)*Math.pow(10,habmanHTH_precision))/Math.pow(10,habmanHTH_precision);

						habmanHTH[road.id]['totals'].pa += parseInt(parseFloat(home.score)*Math.pow(10,habmanHTH_precision))/Math.pow(10,habmanHTH_precision);

						habmanHTH[home.id]['totals'].pf += parseInt(parseFloat(home.score)*Math.pow(10,habmanHTH_precision))/Math.pow(10,habmanHTH_precision);

						habmanHTH[home.id]['totals'].pa += parseInt(parseFloat(road.score)*Math.pow(10,habmanHTH_precision))/Math.pow(10,habmanHTH_precision);

					}

				} catch(er) {}

			}, 

			async: false 

		});

	}

	habmanHTH_sortResults();

	habmanHTH_createHTML();

}

function habmanHTH_initiate(){

	$("#habmanHTH").html('<span id="habmanHTH_populating">Populating . . . </i>');

	setTimeout("habmanHTH_populate()",250);

}

jQuery(document).ready(function(){

	$("#habmanHTH").html('<input id="triggerButton_habmanHTH" class="appButton" type="button" onclick="habmanHTH_initiate()" value="' + habmanHTH_buttonText + '" />');

});

</script>
Consider Donating:
These apps are all 100% free to use however if you want to show your appreciation for the time and effort it took to create then these apps then please consider donating.

Thank you.