// JavaScript Document
// JavaScript Document
var xmlHttp

function reloadCalendarItems(selectedMonth,selectedYear)
	{ 
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
			  {
				  alert ("Your browser does not support AJAX!");
				  return;
			  } 
		
		var url="includes/calendar-preferenceFunctions.php";
		
		//get the checkboxes
		checkboxes=document.forms.formPreferences.chk_categories;
		txt=""
		j=0;
		url=url+"?sid="+Math.random();
		for (i=0;i<checkboxes.length;++ i)
			{
				if (checkboxes[i].checked)
					{
						url=url+"&";
						url=url + "a" + i +"="+ checkboxes[i].value;				
					}
			}
			
		//get the selected audience
		var selectedAudience=document.forms.formPreferences.eventAudience.selectedIndex;
		//pass in info for selected audience
		url=url + "&audience=" + selectedAudience;
		
		//get the selected month
		if(selectedMonth==0)selectedMonth=document.getElementById("eventMonth").options[document.getElementById("eventMonth").selectedIndex].value;
		if(selectedYear==0)selectedYear=document.getElementById("eventYear").options[document.getElementById("eventYear").selectedIndex].value;
		//document.forms.formPreferences.eventMonth.selectedIndex.text;
		//document.getElementById("selectedMonth").options[mylist.selectedIndex].text;
		//pass in info for selected audience
		url=url + "&date=" + selectedMonth + "&year=" + selectedYear;
		
		//alert(selectedMonth);
		
		
		//url=url+"?q="+str;
		//url=url+"&sid="+Math.random();
		xmlHttp.onreadystatechange=stateChanged;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
	
	
	function reloadCalendarItemsUsingSession(categories, selectedAudience, selectedMonth, selectedYear)
	{ 		
		//document.write(categories);

		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
			  {
				  alert ("Your browser does not support AJAX!");
				  return;
			  } 
		
		var url="includes/calendar-preferenceFunctions.php";
		
		url=url+"?sid="+Math.random();
		
		for (i=0;i<categories.length;++ i)
			{
				url=url+"&";
				url=url + "a" + i +"="+ categories[i];								
			}
		
		url=url + "&audience=" + selectedAudience;		
		url=url + "&date=" + selectedMonth + "&year=" + selectedYear;
		
		
		/*
		//get the checkboxes
		checkboxes=document.forms.formPreferences.chk_categories;
		txt=""
		j=0;
		url=url+"?sid="+Math.random();
		for (i=0;i<checkboxes.length;++ i)
			{
				if (checkboxes[i].checked)
					{
						url=url+"&";
						url=url + "a" + i +"="+ checkboxes[i].value;				
					}
			}
			
		//get the selected audience
		var selectedAudience=document.forms.formPreferences.eventAudience.selectedIndex;
		//pass in info for selected audience
		url=url + "&audience=" + selectedAudience;
		
		//get the selected month
		var selectedMonth=document.getElementById("eventMonth").options[document.getElementById("eventMonth").selectedIndex].value;
		var selectedYear=document.getElementById("eventYear").options[document.getElementById("eventYear").selectedIndex].value;
		//document.forms.formPreferences.eventMonth.selectedIndex.text;
		//document.getElementById("selectedMonth").options[mylist.selectedIndex].text;
		//pass in info for selected audience
		url=url + "&date=" + selectedMonth + "&year=" + selectedYear;
		
		//alert(selectedMonth);
		
		
		//url=url+"?q="+str;
		//url=url+"&sid="+Math.random();
		
		*/
		xmlHttp.onreadystatechange=stateChanged;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}

function stateChanged() 
	{ 
		if (xmlHttp.readyState==4)
			{ 
				document.getElementById("calendar_items").innerHTML=xmlHttp.responseText;
			}
	}


function saveCalendarPreferences(userID)
	{ 
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		  {
		  alert ("Your browser does not support AJAX!");
		  return;
		  } 
		
		var url="includes/calendar-preferenceFunctions-Save.php";
		
		//get the checkboxes
		checkboxes=document.forms.formPreferences.chk_categories;
		txt=""
		j=0;
		url=url+"?sid="+Math.random();
		if (userID)
			{
			url=url+"&userID="+userID;
			}
		
		for (i=0;i<checkboxes.length;++ i)
		{
				if (checkboxes[i].checked)
					{
						url=url+"&";
						url=url + "a" + i +"="+ checkboxes[i].value;				
					}
		}
		//url=url+"?q="+str;
		//url=url+"&sid="+Math.random();
		//get the selected audience
		var selectedAudience=document.forms.formPreferences.eventAudience.selectedIndex;
		//pass in info for selected audience
		url=url + "&audience=" + selectedAudience;
		
		xmlHttp.onreadystatechange=stateChangedSave;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
	
	
function stateChangedSave() 
	{ 
		if (xmlHttp.readyState==4)
			{ 
				document.getElementById("save_confirmation").innerHTML=xmlHttp.responseText;
			}
	}


function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}



	/* Functions to help navigate dates in the calender */
	function nextmonth(thisyear)
	{
		monthcontrol = document.dates.eventMonth;
		yearcontrol = document.dates.eventYear;
		if (monthcontrol.selectedIndex == 11)
		{
			if (yearcontrol.selectedIndex < (thisyear-2008+4))
			{
				yearcontrol.selectedIndex = yearcontrol.selectedIndex + 1;
				monthcontrol.selectedIndex = 0;
			}
		}
		else
			monthcontrol.selectedIndex = monthcontrol.selectedIndex + 1;
			
		reloadCalendarItems();
	}
	function prevmonth()
	{
		monthcontrol = document.dates.eventMonth;
		yearcontrol = document.dates.eventYear;
		
		if (monthcontrol.selectedIndex == 0)
		{
			if (yearcontrol.selectedIndex > 0)
			{
				yearcontrol.selectedIndex = yearcontrol.selectedIndex - 1;
				monthcontrol.selectedIndex = 11;
			}
		}
		else
			monthcontrol.selectedIndex = monthcontrol .selectedIndex- 1;
			
		reloadCalendarItems();
	}
	/* ============= */