var matches_L 		     = document.getElementById('matchesContent');
var matches_b_prev_dis_m = document.getElementById('matches_prev_disabled_m');
var matches_b_prev_en_m  = document.getElementById('matches_prev_enabled_m');
var matches_b_next_dis_m = document.getElementById('matches_next_disabled_m');
var matches_b_next_en_m  = document.getElementById('matches_next_enabled_m');
function ajaxReq() {
	var request = null;
	try {
		request = new XMLHttpRequest();
	}
	catch (trymicrosoft) {
		try {
			request = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (othermicrosoft) {
			try {
				request = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (failed) {
				request = null;
			}
		}
	}
	return request;
}

var matchesHTML = new Array();
function displayLMatches(pageNum,roundId,siteURL) {
		matches_b_prev_en_m.style.display = 'none';
		matches_b_next_en_m.style.display = 'none';
		matches_b_prev_dis_m.style.display = 'inline';
		matches_b_next_dis_m.style.display = 'inline';
		matches_L.innerHTML = '<div style="width: 100%; text-align: center; padding-bottom: 71px; padding-top: 70px; background-color: #EDEDED;"><img src="../../images/loading.gif" /></div>';
		var r = ajaxReq();
		if (r == null) matches_L.innerHTML = "We're sorry, but this feature isn't supported by your browser.";
		else {
			var url = siteURL+'/page_include/ajax_switch_include.php?strCategoryId='+roundId+'&strInclude=NM&strpage=' + pageNum;
			r.onreadystatechange = function() {
				if (r.readyState == 4) {
					if (r.status == 200 && r.responseText != '') {
						matchesHTML[pageNum] = r.responseText;
						var hasPrev = r.responseText.substring(0, 1);
						var hasNext = r.responseText.substring(1, 2);
						matches_L.innerHTML = r.responseText.substring(2);
						
						
						if (hasPrev == 'Y') {
							matches_b_prev_dis_m.style.display = 'none';
							matches_b_prev_en_m.style.display = 'inline';
						}
						else {
							matches_b_prev_en_m.style.display = 'none';
							matches_b_prev_dis_m.style.display = 'inline';
						}
						if (hasNext == 'Y') {
							matches_b_next_dis_m.style.display = 'none';
							matches_b_next_en_m.style.display = 'inline';
						}
						else {
							matches_b_next_en_m.style.display = 'none';
							matches_b_next_dis_m.style.display = 'inline';
						}
					}
					else
						matches_L.innerHTML = "We're sorry, but the matches can't be displayed at the moment.";
				}
			}
			r.open('GET', url, true);
			r.send(null);
		}
}

function displayFMatches(pageNum,roundId,matchflag,siteURL) {
		var matches_b_prev_dis_f = document.getElementById('matches_prev_disabled_f');
		var matches_b_prev_en_f  = document.getElementById('matches_prev_enabled_f');
		var matches_b_next_dis_f = document.getElementById('matches_next_disabled_f');
		var matches_b_next_en_f  = document.getElementById('matches_next_enabled_f');

		matches_b_prev_en_f.style.display = 'none';
		matches_b_next_en_f.style.display = 'none';
		matches_b_prev_dis_f.style.display = 'inline';
		matches_b_next_dis_f.style.display = 'inline';
		var matches_F 		     = document.getElementById('matchesContentF');		
		matches_F.innerHTML = '<div style="width: 100%; text-align: center; padding-bottom: 71px; padding-top: 70px; background-color: #EDEDED;"><img src="../../images/loading.gif" /></div>';
		var r = ajaxReq();
		if (r == null) matches_F.innerHTML = "We're sorry, but this feature isn't supported by your browser.";
		else {matchflag
			var url = siteURL+'/page_include/ajax_switch_include.php?strCategoryId='+roundId+'&strInclude=NM&strpage=' + pageNum + '&strOther='+matchflag;
			r.onreadystatechange = function() {
				if (r.readyState == 4) {
					if (r.status == 200 && r.responseText != '') {
						matchesHTML[pageNum] = r.responseText;
						var hasPrev = r.responseText.substring(0, 1);
						var hasNext = r.responseText.substring(1, 2);
						matches_F.innerHTML = r.responseText.substring(2);
						
						
						if (hasPrev == 'Y') {
							matches_b_prev_dis_f.style.display = 'none';
							matches_b_prev_en_f.style.display = 'inline';
						}
						else {
							matches_b_prev_en_f.style.display = 'none';
							matches_b_prev_dis_f.style.display = 'inline';
						}
						if (hasNext == 'Y') {
							matches_b_next_dis_f.style.display = 'none';
							matches_b_next_en_f.style.display = 'inline';
						}
						else {
							matches_b_next_en_f.style.display = 'none';
							matches_b_next_dis_f.style.display = 'inline';
						}
					}
					else
						matches_F.innerHTML = "We're sorry, but the matches can't be displayed at the moment.";
				}
			}
			r.open('GET', url, true);
			r.send(null);
		}
}


var currentPage = 1;
function showmatches(goBack,roundId,siteURL) {
	var goBack;
	var roundId;
	if(goBack==true) {
		currentPage++;
	}else {
		currentPage--;
	}
	if(goBack=='F') {
		currentPage = 1;		
	}
	displayLMatches(currentPage,roundId,siteURL);
}
var currentPagenew = 1;
function showmatchesNew(goBack,roundId,matchflag,siteURL) {
	var goBack;
	var roundId;
	if(goBack==true) {
		currentPagenew++;
	}else {
		currentPagenew--;
	}
	if(goBack=='F') {
		currentPagenew = 1;		
	}
	displayFMatches(currentPagenew,roundId,matchflag,siteURL);
}
