var rbmonths = ["January","February","March","April","May","June","July","August","September","October","November","December"];
var rbdays = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
var curmonth = new Date();
curmonth = rbmonths[curmonth.getMonth()];

var tmp = Array();
var americanRaces = Array();
var internationalRaces = Array();
var currentTime = new Date();
var xmlDoc = null;
if (window.XMLHttpRequest) { // Mozilla, Safari, Chrome
	xmlDoc = new XMLHttpRequest();
	if (xmlDoc.overrideMimeType) {
		xmlDoc.overrideMimeType('text/xml');
	}
}
else { // IE6, IE7, IE8
	xmlDoc = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlDoc.onreadystatechange = function() {
	if(xmlDoc.readyState==4) {
		
// Get Races //
		var tmp = xmlDoc.responseXML.getElementsByTagName("international");
		for (var i=0;i<tmp.length;i++) {
			internationalRaces[i] = [Date.parse(tmp[i].getAttribute("date")),tmp[i].getAttribute("date").split(",", 1),tmp[i].getAttribute("name"),tmp[i].getAttribute("location"),tmp[i].getAttribute("purse"),tmp[i].getAttribute("link"),new Date(Date.parse(tmp[i].getAttribute("date")))];
		}
		
// Filter Past Races //
		for (var i=0;i<internationalRaces.length;i++) {
			if (internationalRaces[i][0] < currentTime.getTime()) {
				internationalRaces.splice(i,1);
				i=-1;
			}
		}
		
// Sort Races //
		internationalRaces.sort();	
		
// Get Races //
		var tmp = xmlDoc.responseXML.getElementsByTagName("american");
		for (var i=0;i<tmp.length;i++) {
			americanRaces[i] = [Date.parse(tmp[i].getAttribute("date")),tmp[i].getAttribute("date").split(",", 1),tmp[i].getAttribute("name"),tmp[i].getAttribute("location"),tmp[i].getAttribute("purse"),tmp[i].getAttribute("link"),new Date(Date.parse(tmp[i].getAttribute("date")))];
		}
		
// Filter Past Races //
		for (var i=0;i<americanRaces.length;i++) {
			if (americanRaces[i][0] < currentTime.getTime()) {
				americanRaces.splice(i,1);
				i=-1;
			}
		}
		
// Sort Races //
		americanRaces.sort();
	
// Output after Load //
		checkLoadStatus(internationalRaces,americanRaces);
	}
}

function checkLoadStatus(internationalRaces,americanRaces) {
	if (document.getElementById("load-status") != null) {
		output(internationalRaces,americanRaces);
	}
	else { setTimeout("checkLoadStatus(internationalRaces,americanRaces)",1); }
}

function output(internationalRaces,americanRaces) {
	monthlyMatchups(internationalRaces);
   showInternationalRaces(internationalRaces);
	showAmericanRaces(americanRaces);
}

function monthlyMatchups(ir)
{
   curmonthlabel = document.getElementById("curmonth1"); if(curmonthlabel) curmonthlabel.innerHTML = curmonth;
   curmonthlabel = document.getElementById("curmonth2"); if(curmonthlabel) curmonthlabel.innerHTML = curmonth;
   irtabler = '';

   for(x=0;x<4 && x<ir.length;x++)
      irtabler += '<tr style="height: 25px;"><td style="font-weight: bold; color: #11274c; border-bottom: 1px solid #dadce0;">' + rbdays[ir[x][6].getDay()].substring(0,3) + '. ' + ir[x][6].getDate() + ', ' + rbmonths[ir[x][6].getMonth()] + '</td><td style="color: #6B788E; border-bottom: 1px solid #dadce0;">' + ir[x][2] + '&nbsp;-&nbsp;' + ir[x][3] + '</td><td style="color: #6B788E; border-bottom: 1px solid #dadce0; width: 50px;"><a href="/sportsbook/horseracing-odds.aspx">Bet Now!</a></td></tr>';

   var ircontainer = document.getElementById("monthly-international-races");

   if(ircontainer) ircontainer.innerHTML = '<table style="width: 100%;">' + irtabler + '</table>';
}

// Show International Races //
function showInternationalRaces(internationalRaces) {
if (internationalRaces[0]) {


	if(document.cookie.indexOf('AsiSystem') > 0) { document.getElementById("international-races").innerHTML="<a href='"+internationalRaces[0][5]+"'><h3>International Race</h3><h4>"+internationalRaces[0][3]+"</h4><p>"+internationalRaces[0][2]+"</p><h5>"+internationalRaces[0][4]+"</h5><h6>"+internationalRaces[0][1]+"</h6></a>"; }
	else { document.getElementById("international-races").innerHTML="<a href='/join'><h3>International Race</h3><h4>"+internationalRaces[0][3]+"</h4><p>"+internationalRaces[0][2]+"</p><h5>"+internationalRaces[0][4]+"</h5><h6>"+internationalRaces[0][1]+"</h6></a>"; }

}

}

// Show American Races //
function showAmericanRaces(americanRaces) {

if (americanRaces[0]) {


	if(document.cookie.indexOf('AsiSystem') > 0) { document.getElementById("american-races").innerHTML="<a href='"+americanRaces[0][5]+"'><h3>American Race</h3><h4>"+americanRaces[0][3]+"</h4><p>"+americanRaces[0][2]+"</p><h5>"+americanRaces[0][4]+"</h5><h6>"+americanRaces[0][1]+"</h6></a>"; }
	else { document.getElementById("american-races").innerHTML="<a href='/join'><h3>American Race</h3><h4>"+americanRaces[0][3]+"</h4><p>"+americanRaces[0][2]+"</p><h5>"+americanRaces[0][4]+"</h5><h6>"+americanRaces[0][1]+"</h6></a>"; }

}


}

// Hide Yellow Note //
function hideYellowNote() {
	if (document.getElementById("yellow-note") != null) {
		if (location.pathname != '/racebook') {
			document.getElementById('yellow-note').style.display = 'none';
		}		
	}
	else { setTimeout("hideYellowNote()",1); }
}

xmlDoc.open("GET", "/images/newsite1024/xml/racebook.xml", true);
xmlDoc.send(null);
hideYellowNote();

function showHorseRacing() {
	document.getElementById('race-type-slider').setAttribute('class', 'horse-racing-on');
	document.getElementById('horse-racing').setAttribute('class', 'selected');
	document.getElementById('fixed-odds-racing').setAttribute('class', '');
	document.getElementById('greyhound-racing').setAttribute('class', '');
	document.getElementById('harness-racing').setAttribute('class', '');
	document.getElementById('race-type-slider').setAttribute('className', 'horse-racing-on');
	document.getElementById('horse-racing').setAttribute('className', 'selected');
	document.getElementById('fixed-odds-racing').setAttribute('className', '');
	document.getElementById('greyhound-racing').setAttribute('className', '');
	document.getElementById('harness-racing').setAttribute('className', '');
}

function showFixedOddsRacing() {
	document.getElementById('race-type-slider').setAttribute('class', 'fixed-odds-racing-on');
	document.getElementById('horse-racing').setAttribute('class', '');
	document.getElementById('fixed-odds-racing').setAttribute('class', 'selected');
	document.getElementById('greyhound-racing').setAttribute('class', '');
	document.getElementById('harness-racing').setAttribute('class', '');
	document.getElementById('race-type-slider').setAttribute('className', 'fixed-odds-racing-on');
	document.getElementById('horse-racing').setAttribute('className', '');
	document.getElementById('fixed-odds-racing').setAttribute('className', 'selected');
	document.getElementById('greyhound-racing').setAttribute('className', '');
	document.getElementById('harness-racing').setAttribute('className', '');
}

function showGreyhoundRacing() {
	document.getElementById('race-type-slider').setAttribute('class', 'greyhound-racing-on');
	document.getElementById('horse-racing').setAttribute('class', '');
	document.getElementById('fixed-odds-racing').setAttribute('class', '');
	document.getElementById('greyhound-racing').setAttribute('class', 'selected');
	document.getElementById('harness-racing').setAttribute('class', '');
	document.getElementById('race-type-slider').setAttribute('className', 'greyhound-racing-on');
	document.getElementById('horse-racing').setAttribute('className', '');
	document.getElementById('fixed-odds-racing').setAttribute('className', '');
	document.getElementById('greyhound-racing').setAttribute('className', 'selected');
	document.getElementById('harness-racing').setAttribute('className', '');
}

function showHarnessRacing() {
	document.getElementById('race-type-slider').setAttribute('class', 'harness-racing-on');
	document.getElementById('horse-racing').setAttribute('class', '');
	document.getElementById('fixed-odds-racing').setAttribute('class', '');
	document.getElementById('greyhound-racing').setAttribute('class', '');
	document.getElementById('harness-racing').setAttribute('class', 'selected');
	document.getElementById('race-type-slider').setAttribute('className', 'harness-racing-on');
	document.getElementById('horse-racing').setAttribute('className', '');
	document.getElementById('fixed-odds-racing').setAttribute('className', '');
	document.getElementById('greyhound-racing').setAttribute('className', '');
	document.getElementById('harness-racing').setAttribute('className', 'selected');
}

function showWeeklyMatchups() {
	document.getElementById('weekly-matchups-header').setAttribute('class', 'selected');
	//document.getElementById('breeders-cup-header').setAttribute('class', '');
	document.getElementById('kentucky-derby-header').setAttribute('class', '');
	document.getElementById('weekly-matchups-content').setAttribute('class', 'visible');
	//document.getElementById('breeders-cup-content').setAttribute('class', 'invisible');
	document.getElementById('kentucky-derby-content').setAttribute('class', 'invisible');
	document.getElementById('weekly-matchups-header').setAttribute('className', 'selected');
	//document.getElementById('breeders-cup-header').setAttribute('className', '');
	document.getElementById('kentucky-derby-header').setAttribute('className', '');
	document.getElementById('weekly-matchups-content').setAttribute('className', 'visible');
	//document.getElementById('breeders-cup-content').setAttribute('className', 'invisible');
	document.getElementById('kentucky-derby-content').setAttribute('className', 'invisible');
}

function showBreedersCup() {
	document.getElementById('weekly-matchups-header').setAttribute('class', '');
	//document.getElementById('breeders-cup-header').setAttribute('class', 'selected');
	document.getElementById('kentucky-derby-header').setAttribute('class', '');
	document.getElementById('weekly-matchups-content').setAttribute('class', 'invisible');
	//document.getElementById('breeders-cup-content').setAttribute('class', 'visible');
	document.getElementById('kentucky-derby-content').setAttribute('class', 'invisible');
	document.getElementById('weekly-matchups-header').setAttribute('className', '');
	//document.getElementById('breeders-cup-header').setAttribute('className', 'selected');
	document.getElementById('kentucky-derby-header').setAttribute('className', '');
	document.getElementById('weekly-matchups-content').setAttribute('className', 'invisible');
	//document.getElementById('breeders-cup-content').setAttribute('className', 'visible');
	document.getElementById('kentucky-derby-content').setAttribute('className', 'invisible');
}

function showKentuckyDerby() {
	document.getElementById('weekly-matchups-header').setAttribute('class', '');
	//document.getElementById('breeders-cup-header').setAttribute('class', '');
	document.getElementById('kentucky-derby-header').setAttribute('class', 'selected');
	document.getElementById('weekly-matchups-content').setAttribute('class', 'invisible');
	//document.getElementById('breeders-cup-content').setAttribute('class', 'invisible');
	document.getElementById('kentucky-derby-content').setAttribute('class', 'visible');
	document.getElementById('weekly-matchups-header').setAttribute('className', '');
	//document.getElementById('breeders-cup-header').setAttribute('className', '');
	document.getElementById('kentucky-derby-header').setAttribute('className', 'selected');
	document.getElementById('weekly-matchups-content').setAttribute('className', 'invisible');
	//document.getElementById('breeders-cup-content').setAttribute('className', 'invisible');
	document.getElementById('kentucky-derby-content').setAttribute('className', 'visible');
}

