function DailySched(offset, foo) {
	var xmlHttp=new XMLHttpRequest();
	url="dailysched.php?offset="+offset;
	xmlHttp.onreadystatechange=function() {
		if (xmlHttp.readyState==4)
		{ 
			if (xmlHttp.responseText.split("")[0] == undefined) // not connected to internet, avoids replacing current schedule with blank
				alert('Connection failed. Please verify that you are connected to the internet.');
				
			else {
				document.getElementById('ishs').removeChild(document.getElementById('dailyschedz'));
				document.getElementById('offsetdate').innerHTML = "Schedule";
				var newdailysched = document.createElement('fieldset');
				newdailysched.setAttribute('id', 'dailyschedz');
	
				if (xmlHttp.responseText != 'none')
				newdailysched.innerHTML = xmlHttp.responseText;
				
				else
				newdailysched.innerHTML = "<div class='row'><label>Have a Great Weekend</label></div>"
	
				document.getElementById('ishs').insertBefore(newdailysched, document.getElementById('navbuttons'));
	
			
				
				if(offset !=0){
					var currentTime = new Date(new Date().getTime() + offset*24*60*60*1000);
					var day = currentTime.getDate();
					var month  = currentTime.getMonth()+1;
					document.getElementById('offsetdate').innerHTML = "Schedule "+month+"/"+day+" <u>(not today)</u>";
					variable =2;
					//window.clearInterval(window.fetchdata); // define global variable so that the update every 10 seconds does not occur to daily schedule part
					document.getElementById('todaybutton').setAttribute('style', '-webkit-border-image: url(iui/todaybutton.png) 0 5 0 5; -moz-border-image: url(iui/todaybutton.png) 0 5 0 5 stretch stretch;');
					document.getElementById('todaybutton').setAttribute('onclick', 'DailySched(0, this)');
				}
				
				
				else {
					variable = 1;//fetchdata = window.setInterval ("fetchData()", 10000);
					document.getElementById('todaybutton').setAttribute('style', '-webkit-border-image: url(iui/todaybuttonfaded.png) 0 5 0 5; -moz-border-image: url(iui/todaybuttonfaded.png) 0 5 0 5 stretch stretch;');
					document.getElementById('todaybutton').setAttribute('onclick', '');		
				}
				
	
				offset = offset +1;
				
					
				/*if(foo.id == 'prevday')
				offset = offset - 1;
				
				else // (foo.id == 'nextday'*/
				
				var mamamia = offset -2;
				document.getElementById('nextday').setAttribute('onclick', 'DailySched('+offset+', this)');
				document.getElementById('prevday').setAttribute('onclick', 'DailySched('+mamamia+', this)');
			}
		}

	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function lunchmonth(newMonth) {
	var xmlHttp=new XMLHttpRequest();
	var url="lunchbox.php?m="+newMonth;
	xmlHttp.onreadystatechange=function() {
		if (xmlHttp.readyState==4) {
				if (xmlHttp.responseText.split("")[0] == undefined) // not connected to internet, avoids replacing current lunches with blank
					alert('Connection failed. Please verify that you are connected to the internet.');
				
				else {
					var lunch = xmlHttp.responseText.split("|")
					$('mondaylunch').innerHTML = lunch[0]
					$('tuesdaylunch').innerHTML = lunch[1]
					$('wednesdaylunch').innerHTML = lunch[2]
					$('thursdaylunch').innerHTML = lunch[3]
					$('fridaylunch').innerHTML = lunch[4]
					
					if (newMonth != 'September') {
						$('lunchboxcurmonth').innerHTML = newMonth;
						$('lunchcentermonth').setAttribute('style', '-webkit-border-image: url(iui/todaybutton.png) 0 5 0 5; -moz-border-image: url(iui/todaybutton.png) 0 5 0 5 stretch stretch;')
						$('lunchcentermonth').setAttribute('onclick','lunchmonth("September")')
					
					}
					
					else {
						$('lunchboxcurmonth').innerHTML = 'September'
						$('lunchcentermonth').removeAttribute('onclick')
						$('lunchcentermonth').setAttribute('style', '-webkit-border-image: url(iui/todaybuttonfaded.png) 0 5 0 5; -moz-border-image: url(iui/todaybuttonfaded.png) 0 5 0 5 stretch stretch;');
					
					}
					var m_names = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
					
					switch (newMonth) {
						case "January":
						var newMonth2 = 0;
						break;
						case "February":
						var newMonth2 = 1;
						break;
						case "March":
						var newMonth2 = 2;
						break;
						case "April":
						var newMonth2 = 3;
						break;
						case "May":
						var newMonth2 = 4;
						break;
						case "June":
						var newMonth2 = 5;
						break;
						case "July":
						var newMonth2 = 6;
						break;
						case "August":
						var newMonth2 = 7;
						break;
						case "September":
						var newMonth2 = 8;
						break;
						case "October":
						var newMonth2 = 9;
						break;
						case "November":
						var newMonth2 = 10;
						break;
						case "December":
						var newMonth2 = 11;
						break;
					}
					
					if (newMonth2 == 0)
						var prevMonth = "December";
					
					else
						var prevMonth = m_names[newMonth2 - 1]
						
						
					if (newMonth2 == 11)
						var nextMonth = "January"
					
					else
						var nextMonth = m_names[newMonth2 + 1]

					$('nextmonth').setAttribute('onclick','lunchmonth("'+nextMonth+'")')
					$('prevmonth').setAttribute('onclick','lunchmonth("'+prevMonth+'")')
					
			
				}		
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);

}
offset = 1;
variable = 1;
loadedTime = new Date();
loadedTime = loadedTime.getMonth()+"/"+loadedTime.getDate()+"/"+loadedTime.getFullYear();