﻿window.onload = initForms;

var xmlhttpSundayGrid;
var xmlhttpHomilyDate;

function initForms()
    {
    var now = new Date();
    var day = now.getDay();
    var month = now.getMonth() + 1;
    var year = now.getFullYear();
    
    document.getElementById("YearValue").value = year;
    document.getElementById("MonthValue").value = month;

    dateChange(year, month);
    //homilyDates(year, month, day); 
   
    //document.getElementById("UploadBulletin").style.display = 'none';
    //document.getElementById("UploadReading").style.display = 'none';
    //document.getElementById("UploadHomily").style.display = 'none';
    //document.getElementById("UploadMessage").style.display = 'none';
    }

function dateChange(year, month)
{
    xmlhttpSundayGrid=GetXmlHttpObject();
    if (xmlhttpSundayGrid==null)
      {
      alert ("Your browser does not support XMLHTTP!");
      return;
      }
    var url="bulletinGrid.php";
    url=url+"?year="+year;
    url=url+"&month="+month;
    url=url+"&sid="+Math.random();
    xmlhttpSundayGrid.onreadystatechange=sundayGridStateChanged;
    xmlhttpSundayGrid.open("GET",url,true);
    xmlhttpSundayGrid.send(null);
}

function sundayGridStateChanged()
{
if (xmlhttpSundayGrid.readyState==4)
  {
  document.getElementById("sundayGrid").innerHTML=xmlhttpSundayGrid.responseText;
  }
}

function homilyDates(year, month, day)
{
    xmlhttpHomilyDate=GetXmlHttpObject();
    if (xmlhttpHomilyDate==null)
      {
      alert ("Your browser does not support XMLHTTP!");
      return;
      }
    var url="homilyDates.php";
    url=url+"?year="+year;
    url=url+"&month="+month;
    url=url+"&day="+day;
    url=url+"&sid="+Math.random();
    xmlhttpHomilyDate.onreadystatechange=homilyDateStateChanged;
    xmlhttpHomilyDate.open("GET",url,true);
    xmlhttpHomilyDate.send(null);
}

function homilyDateStateChanged()
{
if (xmlhttpHomilyDate.readyState==4)
  {
  document.getElementById("homilyDateFields").innerHTML=xmlhttpHomilyDate.responseText;
  }
}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}

function revealUpload(choice)
{
    document.getElementById("UploadBulletin").style.display = 'none';
    document.getElementById("UploadReading").style.display = 'none';
    document.getElementById("UploadHomily").style.display = 'none';
    document.getElementById("UploadMessage").style.display = 'none';

    document.getElementById(choice).style.display = 'block';
}