/*
Description: JavaScript for AJAX calendar
Author: Brian Toms and Jeremy "Gub" Johnson
Date: 16 May 2006
Filename: calendar_ajax.js
*/
timedCountd();
var request_folder = '/src/';
function createRequestObject() { //generic function to create AJAX request
	var req; 
	if(window.XMLHttpRequest) {
		req = new XMLHttpRequest(); 
	} else if(window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP"); 
	} else {
		alert('Problem creating the XMLHttpRequest object');
	} 

	return req;
} 

var http = createRequestObject();

function calClick(day, month, year, cal) { //when clicking on a day in calendar
	var allTDs=document.getElementById('calBody').getElementsByTagName("*"); //unbold all dates
	for (i=0; i<allTDs.length; i++) {
		if (allTDs[i].className=='activeDay') {
			allTDs[i].className='regularDay';
		}
		else if (allTDs[i].className=='activeToday') {
			allTDs[i].className='today';
		}
	}
	var theDay = document.getElementById("cal_" + year + "-" + month + "-" + day); //set clicked date to active (bold)
	if(theDay.className == 'regularDay') {
		theDay.className = 'activeDay';
	}
	else if(theDay.className == 'today') {
		theDay.className = 'activeToday';
	}
	//AJAX Stuff
	http.open('get', request_folder + 'calendar.php?action=getevents&date=' + day + '&month=' + month + "&year=" + year + "&cal=" + cal);
	http.onreadystatechange = handleCalEventResponse;
	http.send(null);
}

function handleCalEventResponse() {  //handles response for calClick()
  if(http.readyState == 4 && http.status == 200) { 
    var response = http.responseText;

    if(response) {
      document.getElementById('calTextbox').innerHTML = response;
   }
  } 
}

function calMonth(month, year, cal) { //for next/previous arrows
	http.open('get', request_folder + 'calendar.php?action=showcalendar&month=' + month + "&year=" + year + '&cal=' + cal);
	http.onreadystatechange = handleShowCalResponse;
	http.send(null);
}

function handleShowCalResponse() { //handles response for calMonth() and initCal()
	if(http.readyState == 4 && http.status == 200) { 
		var response = http.responseText;

		if(response) {
			document.getElementById('calWrapper').innerHTML = response;
			document.getElementById('calTextbox').innerHTML = "<center><em>Click any date to display activities</em></center>";
		}
	} 
}

function initCal(cal) { //initial onLoad function
	http.open('get', request_folder + 'calendar.php?action=showcalendar&cal=' + cal);
	http.onreadystatechange = handleShowCalResponse;
	http.send(null);
}
function getarticle(id, args) {
	http.open('get', request_folder + 'news.php?id='+id+'&'+args);
	http.onreadystatechange = handleArticle(id);
	http.send(null);
}
var response = "";
function handleArticle(id) {
	if(http.readyState == 4 && http.status == 200) { 
		response = http.responseText;
		alert(1);
		if(response.length>0) {
			Effect.Fade(id);
			
			window.setTimeout(('document.getElementById(\'id\').innerHTML = response;'),1000);
			window.setTimeout('Effect.Appear(\'id\')',1000);
			
		}
	} 
}

function searchfocus(input){
	if(input.defaulted != false){
		input.value = "";
		input.style.color = "#000";
		input.style.fontStyle = "normal";
		input.defaulted = false;
	}
}

function refreshimages(url){
	new Ajax.PeriodicalUpdater('side_images_preload', url, {
	  method: 'get', frequency: 10, decay: 0,onSuccess : function(){
		  $('side_images').innerHTML = $('side_images_preload').innerHTML;
		  //initLightbox();
		  //look at switching to shadowbox
	  }
	});
}
function test11() {
	http.open('get', '/inc/photos.php');
	http.onreadystatechange = arsa;
	http.send(null);
}
function arsa() {
	if(http.readyState == 4 && http.status == 200) { 
		response = http.responseText;
		if(response.length>0) {
document.getElementById("side_images").innerHTML = response;
			
		}
	} 
}
function searchblur(input){
	if(input.value.length==0){
		input.value = "Search GBHS";
		input.style.color = "#000";
		//input.style.fontWeight = "bold";
		input.style.fontStyle = "italic";
		input.defaulted = true;
	}
}


var cdas=0
var t
function timedCountd()
{
test11();
cdas=cdas+1;
t=setTimeout("timedCountd()",10000);
}