var sUpcomingFeed = '';
var xmlhttpupcomingfeed;
var sUpcomingMonth;
var sUpcomingYear;

function get_upcomingfeed(sMonth, sYear){
	sUpcomingFeed = '';
		
	sUpcomingMonth = sMonth;
	sUpcomingYear = sYear;
		
	var d = new Date();
	//load_upcomingfeed('../common/ferdie_upcoming_events_feed.asp?m=' + sMonth + '&y=' + sYear + '&time=' + d.getFullYear() + d.getMonth() + d.getDate());
	load_upcomingfeed('../common/ferdie_upcoming_events_feed.asp?m=' + sMonth + '&y=' + sYear + '&time=' + d);
}

function load_upcomingfeed(url) {
	xmlhttpupcomingfeed=null;

	if (window.XMLHttpRequest) {
		// code for Mozilla, etc.
		xmlhttpupcomingfeed=new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		// code for IE
		xmlhttpupcomingfeed=new ActiveXObject("Microsoft.XMLHTTP");
	}

	if (xmlhttpupcomingfeed!=null) {
		xmlhttpupcomingfeed.onreadystatechange=upcomingfeed_state_Change;
		xmlhttpupcomingfeed.open("GET",url,true);
		xmlhttpupcomingfeed.send(null);
	} else {
		alert("Your browser does not support XMLHTTP.");
	}
}			

function upcomingfeed_state_Change() {

	// if xmlhttpupcomingfeed shows "loaded"
	if (xmlhttpupcomingfeed.readyState==4) {
		// if "OK"
		if (xmlhttpupcomingfeed.status==200) {
			// ...some code here...		 
			sUpcomingFeed = xmlhttpupcomingfeed.responseText;
			update_upcoming_div();
			
		} else {
			
			alert(xmlhttpupcomingfeed.status)
			
		}
	}
}

function update_upcoming_div(){
	sUpcomingText = ""
	
	var arrFeed = sUpcomingFeed.split("\r\n");
	
	if(arrFeed.length > 1) {
	
		for(i = 0; i <= arrFeed.length-2; i++){
			var arrSingleEvent = arrFeed[i].split("|");

			if (i>0) {
				sUpcomingText += "<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td width='15'><img src='img/clr.gif' width='15' height='1'></td><td><img src='img/blue.png' width='100%' height='1'></td><td width='15'><img src='img/clr.gif' width='15' height='1'></td></tr></table>";
			}

			sDate  = arrSingleEvent[0]
			sTitle = arrSingleEvent[1]
			sText  = arrSingleEvent[2]
			sDay   = sDate.substring( 0, sDate.indexOf('/') )

			sUpcomingText += "<table width='100%' border='0' cellspacing='0' cellpadding='15'><tr><td>";
			sUpcomingText += sDate;
			sUpcomingText += "<br><strong><span class='txt14p'>";
			sUpcomingText += sTitle;
			sUpcomingText += "</span></strong><br>";
			sUpcomingText += sText;
			sUpcomingText += "<br><a href='calendar.asp?type=FerdieGeneral&month=" + sUpcomingMonth + "|" + sUpcomingYear + "&show=" + sDay + "'>Read more</a></td></tr></table>";

		}
	} else {
		sUpcomingText += "<table width='100%' border='0' cellspacing='0' cellpadding='15'><tr><td>";
		switch(sUpcomingMonth+''){
			case '1':
				sUpcomingText += "There are no events in January"
				break;
			case '2':
				sUpcomingText += "There are no events in February"
				break;
			case '3':
				sUpcomingText += "There are no events in March"
				break;
			case '4':
				sUpcomingText += "There are no events in April"
				break;
			case '5':
				sUpcomingText += "There are no events in May"
				break;
			case '6':
				sUpcomingText += "There are no events in June"
				break;
			case '7':
				sUpcomingText += "There are no events in July"
				break;
			case '8':
				sUpcomingText += "There are no events in August"
				break;
			case '9':
				sUpcomingText += "There are no events in September"
				break;
			case '10':
				sUpcomingText += "There are no events in October"
				break;
			case '11':
				sUpcomingText += "There are no events in November"
				break;
			case '12':
				sUpcomingText += "There are no events in December"
				break;
		}
		sUpcomingText += "</td></tr></table>";
	}
	
	document.getElementById('upcoming_events_div').innerHTML = sUpcomingText
	
	for(i = 1; i <= 12; i++){
		if (document.getElementById('upcoming_month_' + i)){
			if (parseInt(sUpcomingMonth)==i){
				document.getElementById('upcoming_month_' + i).style.background = 'url(img/home/cal-monthon.png)';
				document.getElementById('upcoming_month_' + i).style.fontWeight = 'bold';
				document.getElementById('upcoming_month_' + i).style.className = 'txt11p';
			} else {
				document.getElementById('upcoming_month_' + i).style.background = 'url(img/home/cal-monthoff.png)';
				document.getElementById('upcoming_month_' + i).style.fontWeight = 'normal';
				document.getElementById('upcoming_month_' + i).style.className = 'txt10p';
			}	
		}
	}
}
