// JavaScript Document

function isPresent(){
	if(document.getElementById("kalends") != null){ // Initializes Kalendar feature
		var currentTime = new Date()
		var month = currentTime.getMonth() + 1
		var day = currentTime.getDate()
		var year = currentTime.getFullYear()
		updateBody(year + "-" + month + "-" + day)
	}
	if(document.getElementById("myNewz") != null) { // Initializes Newz feature
		updateNewz(1);
	}
}

function updateBody(myDate) { //Ajax function for updating Kalendar
  new Ajax.Request('http://foundation.missoulacatholicschools.org/myKal.php?myDate=' + myDate,
  {
    method: 'get',
    onSuccess: function(transport){
      $('kalends').innerHTML = transport.responseText || "The Event Calendar is currently unavailable.";
    },
    onFailure: function() {alert('Problem updating Calendar...') }
  });
}

function updateNewz(display) { //Ajax function for updating Kalendar
  new Ajax.Request('http://foundation.missoulacatholicschools.org/myNewz.php?display=' + display,
  {
    method: 'get',
    onSuccess: function(transport){
      $('myNewz').innerHTML = transport.responseText || "The Newz Reader is currently unavailable.";
    },
    onFailure: function() {alert('Problem updating Newz...') }
  });
}

function hideEvents() { //Hide Kalendar Event List
	document.getElementById('kalEvents').innerHTML= '';
}

function show_showEvent(text) { //Show Kalendar Event List
	document.getElementById('kalEvents').innerHTML=text;
}
$(document).ready(function(){
		isPresent();
	});

