
function prepTournaments() {
	clearViewer()
	loadTournaments()
}

function loadTournaments() {
	$.ajax({
	  url: "apps/tournamentViewer/loadTournaments.php",
	  cache: false,
	  type: "POST",
	  data: "month="+curMonth+"&year="+curYear,
	  dataType: "json",
	  success: function(data,textStatus) {
		tv="<table id='tournamentViewer_table' border=0 cellpadding=0 cellspacing=0><tr><td colspan=2 class='monthRow'>Upcoming Tournaments</td></tr>"

		for(i in data) {
			// PREP DISPLAY VARIABLES
			// start and end date
			startDate=monthNames[parseInt(data[i]['startDate'].substr(4,2),10)];
			endDate=monthNames[parseInt(data[i]['endDate'].substr(4,2),10)];
			startDay=parseInt(data[i]['startDate'].substr(6,2),10);
			endDay=parseInt(data[i]['endDate'].substr(6,2),10);
			switch(startDay) {
				case 1:   stPost='st';	break;
				case 2:   stPost='nd';	break;
				case 3:   stPost='rd';	break;
				default:  stPost='th';	break;
			}
			switch(endDay) {
				case 1:   endPost='st';	break;
				case 2:   endPost='nd';	break;
				case 3:   endPost='rd';	break;
				default:  endPost='th';	break;
			}
			startDate=startDate+" "+startDay+stPost;
			endDate=endDate+" "+endDay+endPost;

			// fee
			if(data[i]['fee'])
				fee="$"+data[i]['fee']
			else
				fee="No Fee"
			// location
			tournamentLocation=""
			if(data[i]['field'])
				tournamentLocation+=data[i]['field']+" - ";
			tournamentLocation+=data[i]['city']+", "+data[i]['state']

			tv+="<tr><td colspan=2 class='titleRow'>"+data[i]['name']+"</td></tr>";
			tv+="<tr><td class='dataRow' width=100%>"+startDate+" - "+endDate+"</td><td align=right class='dataRow' nowrap>"+fee+"</td></tr>";
			tv+="<tr><td colspan=2 class='dataRow'>"+tournamentLocation+"</td></tr>";
			// print leagues
			mens=parseInt(data[i]['mens']);
			womens=parseInt(data[i]['womens']);
			coed=parseInt(data[i]['coed']);
			if(mens || womens || coed) {
				tv+="<tr><td colspan=2 class='dataRow'>";
				if(mens)
					tv+="Men's";
				if(mens && womens && coed)
					tv+=", ";
				else if(mens && womens)
					tv+=" &amp; ";
				if(womens)
					tv+="Women's";
				if(mens && coed || womens && coed)
					tv+=" &amp; ";
				if(coed)
					tv+="COED";
				tv+=" Tournament";
				if(mens && womens || mens && coed || womens && coed)
					tv+="s";
				tv+="</td></tr>";
			}
			// print contact info
			if(data[i]['contact'] || data[i]['phone1'] || data[i]['phone2'] || data[i]['email']) {
				tv+="<tr><td colspan=2  class='dataRow'>Contact:";
				if(data[i]['contact'])
					tv+=" "+data[i]['contact'];
				if(data[i]['phone1'])
					tv+=" "+data[i]['phone1'];
				if(data[i]['phone1'] && data[i]['phone2'])
					tv+=" or";
				if(data[i]['phone2'])
					tv+=" "+data[i]['phone2'];
				if(data[i]['phone1'] || data[i]['phone2'])
					tv+="<BR>";
				if(data[i]['email'])
					tv+=" <a href='mailto:"+data[i]['email']+"'>"+data[i]['email']+"</a>";
				tv+="</td></tr>";
			}
			// print notes
			if(data[i]['notes']) {
				tv+="<tr><td colspan=2 class='dataRow'>"+data[i]['notes']+"</td></tr>";	
			}
			
		}
		tv+="</table>";
		$("#tournamentContainer").html(tv);
	  }
	});
} // loadTournaments