//AJAX object
var xmlHttp

function moveCalendarByMonth(direction,month,year){
	//make sure ajax is supported
	xmlHttp=GetXmlHttpObject();
	if(xmlHttp==null){
  		alert ("Your browser does not support AJAX!");
  		return;
  	}
	
	var url = "moveCalendarByMonth.asp?operation=" + direction + "&month=" + month + "&year=" + year		
	
	xmlHttp.onreadystatechange=stateChangedCalendar;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function moveCalendarByDay(direction,date){
	//make sure ajax is supported
	xmlHttp=GetXmlHttpObject();
	if(xmlHttp==null){
  		alert ("Your browser does not support AJAX!");
  		return;
  	}
	
	var url = "moveCalendarByDay.asp?operation=" + direction + "&date="	+ date
	xmlHttp.onreadystatechange=stateChangedCalendar;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	
}

function moveCalendarByWeek(direction,date){
	//make sure ajax is supported
	xmlHttp=GetXmlHttpObject();
	if(xmlHttp==null){
  		alert ("Your browser does not support AJAX!");
  		return;
  	}
	
	var url = "moveCalendarByWeek.asp?operation=" + direction + "&date="	+ date
	xmlHttp.onreadystatechange=stateChangedCalendar;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);


}


function stateChangedCalendar(){
	if(xmlHttp.readyState==4){
		
		document.getElementById("calendar").innerHTML = xmlHttp.responseText;
		
	}
	
}

function changeView(element,month,year){
	//alert(view);
	var current = document.getElementById('selected')

	//If the calendar is already showing that view then dont do anything
	if(current.className == element.className){
		return;
	}else{
		
		//make sure ajax is supported
		xmlHttp=GetXmlHttpObject();
		if(xmlHttp==null){
  			alert ("Your browser does not support AJAX!");
  			return;
  		}
		
		if(document.getElementById('today')){
				var currentDate = new Date()
				var date =  month + "/" + currentDate.getDate() + "/" + year
				
			}else{
				var date = month + "/1/" + year
			}

		//Send server request to appropriate file based on what view the user clicked
		if(element.className=="day"){			
			var url = "changeCalendarViewByDay.asp?date=" + date
			xmlHttp.onreadystatechange=stateChangedCalendar;
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
		}else if(element.className=="week"){
			var url = "changeCalendarViewByWeek.asp?date=" + date
			xmlHttp.onreadystatechange=stateChangedCalendar;
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
		}else if(element.className=="month"){
			var url = "changeCalendarViewByMonth.asp?date=" + date
			xmlHttp.onreadystatechange=stateChangedCalendar;
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
		}else{
			return;
		}
	}
}


function closecalendar()
{
	titlerow = document.getElementById("closewrap")
	titlerow.style.display = ( titlerow.style.display == "none" ) ? "block" : "none";
}

function openkey()
{
	var thekey = document.getElementById("thekey");
	
	if(thekey.style.display == "none" || thekey.style.display == ""){
		thekey.style.display = "block";
	}else{
		thekey.style.display = "none";
	}
}


function viewSpecificDay(theDay){
	
	//make sure ajax is supported
	xmlHttp=GetXmlHttpObject();
	if(xmlHttp==null){
  		alert ("Your browser does not support AJAX!");
  		return;
  	}
	
	var url = "changeCalendarViewByDay.asp?date=" + theDay
	xmlHttp.onreadystatechange=stateChangedCalendar;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	
	
}
