matchmonitor = "";
// The following block of code is for the challengee
	// Start running the specified function at 3 second intervals
	function startmon(runfunc) {
		if (matchmonitor == "") {
			matchmonitor = window.setInterval(runfunc,3000);
		}
	}
	
	// Stop running the timed funtion
	function stopmon() {
		clearInterval(matchmonitor);
		matchmonitor = "";
	}
	
	// Close the specified DIV... in this case the popup window and screen greyout
	function closepop(divname) {
		document.body.removeChild(divname);
		grayOut(false);
	}
	
	//Checks to see if anyone has invite them to a match and forwards to the "proccheckmatch" function
	function checkmatch()	{
		DWREngine._execute(_ajaxConfig._cfscriptLocation, null, 'mymatches', proccheckmatch);
	}
	
	// Determines what to do with the results from "checkmatch" function
	function proccheckmatch(r) {
		if (r.active == 1) {
			stopmon();
			grayOut(true);
			showbox = createDiv(350,145,"white","black");
			var buildpage = "";
			buildpage = buildpage + "<table style=\"color: black;\" align=\"center\" valign=\"middle\">";
			buildpage = buildpage + "	<tbody style=\"color: black;\" >";
			buildpage = buildpage + "		<tr>";
			buildpage = buildpage + "			<td style=\"color: black;\"  colspan=\"2\">You have recieved a new challenge!</td>";
			buildpage = buildpage + "		</tr>";
			buildpage = buildpage + "		<tr>";
			buildpage = buildpage + "			<td style=\"color: black;\"  align=\"right\">Challenger:</td>";
			buildpage = buildpage + "			<td style=\"color: black;\" >"+r.member1username+"</td>";
			buildpage = buildpage + "		</tr>";
			buildpage = buildpage + "		<tr>";
			buildpage = buildpage + "			<td style=\"color: black;\"  align=\"right\">Course:</td>";
			buildpage = buildpage + "			<td style=\"color: black;\" >"+r.course+"</td>";
			buildpage = buildpage + "		</tr>";
			buildpage = buildpage + "		<tr>";
			buildpage = buildpage + "			<td style=\"color: black;\"  align=\"right\">Holes:</td>";
			buildpage = buildpage + "			<td style=\"color: black;\" >"+r.holes+"</td>";
			buildpage = buildpage + "		</tr>";
			buildpage = buildpage + "		<tr>";
			buildpage = buildpage + "			<td style=\"color: black;\"  align=\"right\">Skill Level:</td>";
			buildpage = buildpage + "			<td style=\"color: black;\" >"+r.skill+"</td>";
			buildpage = buildpage + "		</tr>";
			buildpage = buildpage + "		<tr>";
			buildpage = buildpage + "			<td style=\"color: black;\"  align=\"right\">Buy-In:</td>";
			buildpage = buildpage + "			<td style=\"color: black;\" >"+r.balls+"</td>";
			buildpage = buildpage + "		</tr>";
			buildpage = buildpage + "	</tbody>";
			buildpage = buildpage + "</table>";
			buildpage = buildpage + "<div style='width: 100%; position: absolute; bottom: 0px; text-align: center; background-color: yellow;'>";
			buildpage = buildpage + "<a href='javascript: void(0);' onClick='verifyballs("+r.key+",1);' style='color: red; font-weight: bold;'>Accept</a>";
			buildpage = buildpage + "&nbsp;&nbsp;&nbsp;&nbsp;";
			buildpage = buildpage + "<a href='javascript: void(0);' onClick='verifyballs("+r.key+",0);' style='color: red; font-weight: bold;'>Reject</a>";
			buildpage = buildpage + "</div>";
			showbox.innerHTML = buildpage;
		}
		if (r.active == 2) {
			stopmon();
			grayOut(true);
			showbox = createDiv(350,350,"white","black");
			var buildpage = "";
			buildpage = buildpage + "<p style=\"text-align: center; font-weight: bold;\">"+r.member2username + " has " + r.challengeresponse +" your challenge.</p>";
			buildpage = buildpage + "<p style=\"text-align: center;\"> You can review your challenge options below: </p>";
			buildpage = buildpage + "<p style=\"text-align: center;\"> When you leave this website (goldenfairway.com) and sign into your GoldenFairway gold game, the new game you try to create or join will be your MVP Network Challenge Tournament Match with the opponent you just challenged. </p>";
			buildpage = buildpage + "<p style=\"text-align: center;\"> If you do not complete this Challenge Tournament within 24 hours, you will automatically lose the balls you have wagered.</p>";
			buildpage = buildpage + "<p style=\"text-align: center;\"> Click <a href='javascript: void(0);' onClick='confirmchallenge(showbox,"+r.key+");'>here</a> to close this window.</p>";
			showbox.innerHTML = buildpage;
		}
	}
	
	function verifyballs(key,action) {
		DWREngine._execute(_ajaxConfig._cfscriptLocation, null, 'verifyballs', key, action, runconfirm);
	}
	
	function confirmchallenge(divname,key) {
		stopmon();
		closepop(divname);

		DWREngine._execute(_ajaxConfig._cfscriptLocation, null, 'confirm', key, donothing);
	}
	
	function runconfirm(r) {
		closepop(showbox);

		grayOut(true);
		showbox = createDiv(450,550,"white","black");
		var buildpage = r.alert;
		buildpage = buildpage + "<br />";
		buildpage = buildpage + "<br />";
		buildpage = buildpage + "<p style=\"text-align: center;\"> Click <a href='javascript: void(0);' onClick='closepop(showbox);'>here</a> to close this window.</p>";
		showbox.innerHTML = buildpage;
	}

	// Called if the person clicks accept on the match popup
	function getresult(divname,ballMatchKey,answer) {
		closepop(divname);
		
		DWREngine._execute(_ajaxConfig._cfscriptLocation, null, 'challengeResponse', ballMatchKey, answer, donothing);
	}

	// Exactly as the title says	
	function donothing() {
		// hello moto
	}
	
// Let the user know if it was accepted or denied
function alertbox(userchoice) {
	alert(userchoice.alert);
}
