var xmlHttp

var response
var page
var id	
var month
var year
var type
var day

function drawCalendar(month,year){
		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null)
		 {
 		alert ("Browser does not support HTTP Request")
		 return
		 }
	destroyBox()
	document.getElementById('loading').style.display= 'block'
	var url="calendar-functions.php?action=drawCalendar&month="+month+"&year="+year
	xmlHttp.onreadystatechange=stateChanged
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
	function stateChanged() 
	{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	 { 
	 	response=xmlHttp.responseText;
		document.getElementById('loading').style.display= 'none'
		document.getElementById('calendar').innerHTML=response	
 	} 
	}
	}
	
function drawAddBox(month,day,year){
		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null)
		 {
 		alert ("Browser does not support HTTP Request")
		 return
		 }
	var url="calendar-functions.php?action=drawAddBox&month="+month+"&year="+year+"&day="+day
	xmlHttp.onreadystatechange=stateChanged2
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
	function stateChanged2() 
	{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	 { 
	 	response=xmlHttp.responseText;
		document.getElementById('addBox').innerHTML=response
		document.getElementById('addBox').style.display= 'block'	
 	} 
	}
	}
	
function addCalendarEvent(){
		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null)
		 {
 		alert ("Browser does not support HTTP Request")
		 return
		 }
	var date=escape(document.addEvent.date.value)
	var name=escape(document.addEvent.name.value)
	var location=escape(document.addEvent.location.value)
	var description=document.addEvent.description.value
	var time1=escape(document.addEvent.time1.value)
	var time2=escape(document.addEvent.time2.value)
	var type=escape(document.addEvent.type.value)
	var month=escape(document.addEvent.month.value)
	var year=escape(document.addEvent.year.value)
	description=nl2br(description);
	description=escape(description);
	destroyBox()
	var url="calendar-functions.php?action=addEvent&date="+date+"&name="+name+"&location="+location+"&description="+description+"&time1="+time1+"&time2="+time2+"&type="+type
	xmlHttp.onreadystatechange=stateChanged3
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
	function stateChanged3() 
	{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	 { 
	 	response=xmlHttp.responseText;
		drawCalendar(month,year)
 	} 
	}
	}	
	
	function viewEvent(id){
		xmlHttp2=GetXmlHttpObject2()
		if (xmlHttp2==null)
		 {
 		alert ("Browser does not support HTTP Request")
		 return
		 }
	var url="calendar-functions.php?action=viewEvent&id="+id
	xmlHttp2.onreadystatechange=stateChanged4
	xmlHttp2.open("GET",url,true)
	xmlHttp2.send(null)
	function stateChanged4() 
	{ 
	if (xmlHttp2.readyState==4 || xmlHttp2.readyState=="complete")
	 { 
	 	response=xmlHttp2.responseText;
		document.getElementById('addBox').innerHTML=response
		document.getElementById('addBox').style.display= 'block'	
 	} 
	}
	}
	
		function deleteEvent(id,month,year){
		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null)
		 {
 		alert ("Browser does not support HTTP Request")
		 return
		 }
	destroyBox();
	var url="calendar-functions.php?action=deleteEvent&id="+id
	xmlHttp.onreadystatechange=stateChanged4
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
	function stateChanged4() 
	{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	 { 
	 	response=xmlHttp.responseText;
		drawCalendar(month,year);
 	} 
	}
	}

function destroyBox(){
	var boxid='addBox';
		document.getElementById(boxid).style.display='none'
		document.getElementById(boxid).innerHTML=''
	}	


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;
}

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

function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++;
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.FILTER = "Alpha(opacity=" + opacity + ")";
	
	if(opacity<=0){
				document.getElementById(id).style.display='none'	
	}
	} 

function nl2br (str) {
    breakTag = '<br />';
    return (str + '').replace(/([^>]?)\n/g, '$1'+ breakTag +'\n');
}