// JavaScript Document
function tabs(id, affiliateid, daterange1, daterange2, sportid1, sportid2, sportid3, sportid4, datasource){
	var schedulesbox = $('content');
	schedulesbox.innerHTML = 'Loading...';
	DWREngine._execute(_ajaxConfig._cfscriptLocation, null, 'tabs', id, affiliateid, daterange1, daterange2, sportid1, sportid2, sportid3, sportid4, datasource, tabsSuccess);
}

function tabsSuccess(r){
	var schedulesbox = $('content');
	schedulesbox.innerHTML = '';
	if (r.getRowCount() > 0){
		
		
			var month=new Array(12);
			month[0]="January";
			month[1]="February";
			month[2]="March";
			month[3]="April";
			month[4]="May";
			month[5]="June";
			month[6]="July";
			month[7]="August";
			month[8]="September";
			month[9]="October";
			month[10]="November";
			month[11]="December";
		
		for (var i = 0; i < r.getRowCount(); i++){
			var table 		= document.createElement('table');
			table.cellSpacing = "2px";
			var tablebody 	= document.createElement('tbody');
			if (i % 2 != 0){
				table.style.backgroundColor = "#BBBDBF";
			}else{
				table.style.backgroundColor = "#FFFFFF";
			}
			var row1 = document.createElement('tr');
			
				var date = document.createElement('td');
					date.setAttribute('width','185');
					date.style.textAlign = "left";
					date.style.padding = "0px 0px 0px 10px";
					date.style.fontWeight = "bold";
				var dateText = document.createTextNode(r.division[i] + ' ' + r.level[i] + ' ' + r.sport[i]);
				date.appendChild(dateText);
				row1.appendChild(date);
				
				var score = document.createElement('td');
					score.setAttribute('width','185');
					score.style.textAlign = "right";
					score.style.padding = "0 10px 0 0";
				var scoreText = document.createTextNode(month[r.eventdate[i].getMonth()] + ' ' + r.eventdate[i].getDate());
				score.appendChild(scoreText);
				row1.appendChild(score);
			
			if (i % 2 == 0){
				row1.style.backgroundColor = "#BBBDBF";
			}else{
				row1.style.backgroundColor = "#FFFFFF";
			}
			tablebody.appendChild(row1);
			
			var row2 = document.createElement('tr');
			
				var schedTeams = document.createElement('td');
					schedTeams.setAttribute('width','370');
					schedTeams.setAttribute('height','30');
					schedTeams.setAttribute('valign','middle');
					schedTeams.style.textAlign = "left";
					schedTeams.style.padding = "0 10px 0 10px";
					schedTeams.colSpan = "2";
				if (r.place[i].toLowerCase() == 'home'){
					var schedTeamsText = document.createTextNode(r.name[i] + ' @ ' + r.highschool[i]);
				}
				else{
					var schedTeamsText = document.createTextNode(r.highschool[i] + ' @ ' + r.name[i]);
				}
				schedTeams.appendChild(schedTeamsText);
				row2.appendChild(schedTeams);
			
			if (i % 2 == 0){
				row2.style.backgroundColor = "#BBBDBF";
			}else{
				row2.style.backgroundColor = "#FFFFFF";
			}
			tablebody.appendChild(row2);
			table.appendChild(tablebody);
			schedulesbox.appendChild(table);	
		}
	}
	else
	{
		var defaultSchedulesText = document.getElementById('defaultSchedulesText');
		if(defaultSchedulesText != null){
			schedulesbox.innerHTML = document.getElementById('defaultSchedulesText').innerHTML;
		}
		else {
			schedulesbox.innerHTML = "No Schedules Available";
		}
	}
}

function tabs2(id, affiliateid, daterange1, daterange2, sportid1, sportid2, sportid3, sportid4, datasource){
	var scoresbox = $('content2');
	scoresbox.innerHTML = 'Loading...';
	DWREngine._execute(_ajaxConfig._cfscriptLocation, null, 'tabs2', id, affiliateid, daterange1, daterange2, sportid1, sportid2, sportid3, sportid4, datasource, tabsSuccess2);
}

function tabsSuccess2(r){
	var scoresbox = $('content2');
	scoresbox.innerHTML = '';
	if (r.getRowCount() > 0){
		
		
			var month=new Array(12);
			month[0]="Jan";
			month[1]="Feb";
			month[2]="Mar";
			month[3]="Apr";
			month[4]="May";
			month[5]="Jun";
			month[6]="Jul";
			month[7]="Aug";
			month[8]="Sept";
			month[9]="Oct";
			month[10]="Nov";
			month[11]="Dec";
		
		for (var i = 0; i < r.getRowCount(); i++){
			var table 		= document.createElement('table');
			table.cellSpacing = "2px";
			var tablebody 	= document.createElement('tbody');
			if (i % 2 != 0){
				table.style.backgroundColor = "#BBBDBF";
			}else{
				table.style.backgroundColor = "#FFFFFF";
			}
			var row1 = document.createElement('tr');
			var gls = document.createElement('td');
			
			gls.setAttribute('width', '140');
			gls.style.textAlign = 'left';
			gls.style.padding = '0px 0px 0px 10px';
			
			var glsText = document.createTextNode(r.division_abr[i] + ' ' + r.level_abr[i] + ' ' + r.sport[i]);
			
			gls.appendChild(glsText);
			row1.appendChild(gls);
			
			var date = document.createElement('td');
			
			date.setAttribute('width', '68');
			date.style.textAlign = 'right';
			date.style.padding = '0px 10px 0px 0 px';
			
			var dateText = document.createTextNode(month[r.eventdate[i].getMonth()] + ' ' + r.eventdate[i].getDate());
			
			date.appendChild(dateText);
			row1.appendChild(date)
			
			if(i % 2 == 0)
			{
				row1.style.backgroundColor = '#BBBDBF';
			}else{
				row1.style.backgroundColor = '#FFFFFF';
			}
			
			tablebody.appendChild(row1);
			
			var row2outside = document.createElement('tr');
			var row2td = document.createElement('td');
			row2td.colSpan = "2";
			var table2 = document.createElement('table');
			var table2body = document.createElement('tbody');
			table2.cellSpacing = "0";
			var row2 = document.createElement('tr');
			var opponent = document.createElement('td');
			var oppScore = document.createElement('td');
			var row3 = document.createElement('tr');
			var hometeam = document.createElement('td');
			var homeScore = document.createElement('td');
			
			if(r.place[i].toLowerCase() == 'home')
			{
				if(r.low_win[i] != 1){
					if(r.ourscore[i] < r.theirscore[i])
					{
						opponent.style.fontWeight = 'bold';
						oppScore.style.fontWeight = 'bold';
					}
					else
					{
						hometeam.style.fontWeight = 'bold';
						homeScore.style.fontWeight = 'bold';
					}
				}else{
					if(r.ourscore[i] > r.theirscore[i])
					{
						opponent.style.fontWeight = 'bold';
						oppScore.style.fontWeight = 'bold';
					}
					else
					{
						hometeam.style.fontWeight = 'bold';
						homeScore.style.fontWeight = 'bold';
					}
				}
				
				opponent.setAttribute('width', '198');
				opponent.setAttribute('height', '20');
				opponent.setAttribute('valign', 'middle');
				opponent.style.textAlign = 'left';
				opponent.style.padding = '0px 0px 0px 10px';
				
				oppName = document.createTextNode(r.name[i]);
				
				opponent.appendChild(oppName);
				row2.appendChild(opponent);
				
				oppScore.setAttribute('width', '10');
				oppScore.setAttribute('height', '20');
				oppScore.setAttribute('valign', 'middle');
				oppScore.style.textAlign = 'right';
				oppScore.style.padding = '0px 2px 0px 10px';
				oppScoreText = document.createTextNode(r.theirscore[i]);
				
				oppScore.appendChild(oppScoreText);
				row2.appendChild(oppScore);
				
				hometeam.setAttribute('width', '198');
				hometeam.setAttribute('height', '20');
				hometeam.setAttribute('valign', 'middle');
				hometeam.style.textAlign = 'left';
				hometeam.style.padding = '0px 0px 0px 10px';
				homeName = document.createTextNode('@ ' + r.highschool[i]);
				
				hometeam.appendChild(homeName);
				row3.appendChild(hometeam);
				
				homeScore.setAttribute('width', '10');
				homeScore.setAttribute('height', '20');
				homeScore.setAttribute('valign', 'middle');
				homeScore.style.textAlign = 'right';
				homeScore.style.padding = '0px 2px 0px 10px';
				homeScoreText = document.createTextNode(r.ourscore[i]);
				
				homeScore.appendChild(homeScoreText);
				row3.appendChild(homeScore);
			}
			else
			{
				if(r.low_win[i] != 1){
					if(r.ourscore[i] < r.theirscore[i])
					{
						opponent.style.fontWeight = 'bold';
						oppScore.style.fontWeight = 'bold';
					}
					else
					{
						hometeam.style.fontWeight = 'bold';
						homeScore.style.fontWeight = 'bold';
					}
				}else{
					if(r.ourscore[i] > r.theirscore[i])
					{
						opponent.style.fontWeight = 'bold';
						oppScore.style.fontWeight = 'bold';
					}
					else
					{
						hometeam.style.fontWeight = 'bold';
						homeScore.style.fontWeight = 'bold';
					}					
				}
				
				
				hometeam.setAttribute('width', '198');
				hometeam.setAttribute('height', '20');
				hometeam.setAttribute('valign', 'middle');
				hometeam.style.textAlign = 'left';
				hometeam.style.padding = '0px 0px 0px 10px';
				homeName = document.createTextNode(r.highschool[i]);
				
				hometeam.appendChild(homeName);
				row2.appendChild(hometeam);
				
				homeScore.setAttribute('width', '10');
				homeScore.setAttribute('height', '20');
				homeScore.setAttribute('valign', 'middle');
				homeScore.style.textAlign = 'right';
				homeScore.style.padding = '0px 2px 0px 10px';
				homeScoreText = document.createTextNode(r.ourscore[i]);
				
				homeScore.appendChild(homeScoreText);
				row2.appendChild(homeScore);
				
				opponent.setAttribute('width', '198');
				opponent.setAttribute('height', '20');
				opponent.setAttribute('valign', 'middle');
				opponent.style.textAlign = 'left';
				opponent.style.padding = '0px 0px 0px 10px';
				oppName = document.createTextNode('@ ' + r.name[i]);
				
				opponent.appendChild(oppName);
				row3.appendChild(opponent);
				
				oppScore.setAttribute('width', '10');
				oppScore.setAttribute('height', '20');
				oppScore.setAttribute('valign', 'middle');
				oppScore.style.textAlign = 'right';
				oppScore.style.padding = '0px 2px 0px 10px';
				oppScoreText = document.createTextNode(r.theirscore[i]);
				
				oppScore.appendChild(oppScoreText);
				row3.appendChild(oppScore);
			}
			
			if(i % 2 == 0)
			{
				row2.style.backgroundColor = '#BBBDBF';
				row3.style.backgroundColor = '#BBBDBF';
			}
			else
			{
				row2.style.backgroundColor = '#FFFFFF';
				row3.style.backgroundColor = '#FFFFFF';
			}
			table2body.appendChild(row2);
			table2body.appendChild(row3);
			table2.appendChild(table2body);
			row2td.appendChild(table2);
			row2outside.appendChild(row2td);
			tablebody.appendChild(row2outside);
			//tablebody.appendChild(row3);
			/*var row1 = document.createElement('tr');
			
				var date = document.createElement('td');
					date.setAttribute('width','104');
					date.style.textAlign = "left";
					date.style.padding = "0px 0px 0px 10px";
				var dateText = document.createTextNode(month[r.eventdate[i].getMonth()] + ' ' + r.eventdate[i].getDate());
				date.appendChild(dateText);
				row1.appendChild(date);
				
				var score = document.createElement('td');
					score.setAttribute('width','104');
					score.style.textAlign = "right";
					score.style.padding = "0px 10px 0px 0px";
				var scoreText = document.createTextNode(r.ourscore[i] + '-' + r.theirscore[i]);
				score.appendChild(scoreText);
				row1.appendChild(score);
				
			if (i % 2 == 0){
				row1.style.backgroundColor = "#BBBDBF";
			}	
			tablebody.appendChild(row1);
			*/
			/*var row2 = document.createElement('tr');
			
				var eventTag = document.createElement('td');
				eventTag.setAttribute('width','208');
				eventTag.setAttribute('height','40');
				eventTag.setAttribute('valign','middle');
				eventTag.style.textAlign = "left";
				eventTag.style.padding = "0 10px 0 10px";
				eventTag.colSpan = "2";
				if (r.place[i].toLowerCase() == 'home'){
					var eventTagText = document.createTextNode(r.name[i] + ' @ ' + r.highschool[i]);
				}
				else{
					var eventTagText = document.createTextNode(r.highschool[i] + ' @ ' + r.name[i]);
				}
				eventTag.appendChild(eventTagText);
				row2.appendChild(eventTag);
			
			if (i % 2 == 0){
				row2.style.backgroundColor = "#BBBDBF";
			}
			tablebody.appendChild(row2);*/
			
			table.appendChild(tablebody);
			scoresbox.appendChild(table);
		}
		
		
	}
	else
	{
		var defaultScoresText = document.getElementById('defaultScoresText');
		if(defaultScoresText != null){
			scoresbox.innerHTML = document.getElementById('defaultScoresText').innerHTML;
		}
		else {
			scoresbox.innerHTML = "No Scores Available";
		}
	}
}