// JavaScript Document
var xmlHttp = createXmlHttpRequestObject(); 

// retrieves the XMLHttpRequest object
function createXmlHttpRequestObject() 
{	
  // will store the reference to the XMLHttpRequest object
  var xmlHttp;
  // if running Internet Explorer
  if(window.ActiveXObject)
  {
    try
    {
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  // if running Mozilla or other browsers
  else
  {
    try 
    {
      xmlHttp = new XMLHttpRequest();
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  // return the created object or display an error message
  if (!xmlHttp)
 
    alert("Error creating the XMLHttpRequest object.");
  else 
    return xmlHttp;
}


function showCalendar(folderpath, month, year, way, whatUID)
{
	 if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
	 {
		 month=parseInt(month);
		 year=parseInt(year);
		 
		 minMonth=1;
		 maxMonth=12;
		 
		if(way=='nexty')
		{
			year++;
		}
		if(way=='prevy')
		{
			year--;
		}
		 
		if(way=='nextm')
		{
			month++;
		}
		if(way=='prevm')
		{
			month--;
		}
		if(month==maxMonth+1)
		{
			month=minMonth;
			year++;
		}
		if(month==0)
		{
			month=maxMonth;
			year--;
		}
 //alert("mont=" + month + ", year=" + year);
		 
				xmlHttp.open("GET", folderpath + "calendar_xml.php?y=" + year + "&m=" + month + "&newsid=" + whatUID, true);
				
				
				 // define the method to handle server responses
				xmlHttp.onreadystatechange = function()
				{
					handleServerResponse(folderpath, month, year, way);
				}
				// make the server request
				xmlHttp.send(null);
    }
}


function handleServerResponse(folderpath, month, year, way) 
{
  // move forward only if the transaction has completed
  if (xmlHttp.readyState == 4) 
  {
	 // status of 200 indicates the transaction completed successfully
    if (xmlHttp.status == 200) 
    {
		arrayMonthString=new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
    	defaultMonthString=arrayMonthString[(month-1)];
		divBig=document.getElementById('showCalendar1');
		
		
		
		
		
	   // extract the XML retrieved from the server
      var xmlResponse = xmlHttp.responseXML;
	  
	  if(!xmlResponse || !xmlResponse.documentElement)
	  {
		throw("Invalid XML structure:\n" + xmlHttp.responseText);  
	  }
	  
	  var rootNodeName=xmlResponse.documentElement.nodeName;
	  
	  if(rootNodeName == "parserror")
	  {
		  throw("Invalid XML structure");
	  }
	  
	  xmlRoot=xmlResponse.documentElement;
	  
	 
      // obtain the document element (the root element) of the XML structure
     
	 	  
	  // get the text message, which is in the first child of
      // the the document element
	 	  
	    titleArray = xmlRoot.getElementsByTagName("obj1");
		helloMessage=titleArray.item(0).firstChild.data;
		
		if(helloMessage!="false")
		{
			divBig.innerHTML=helloMessage;
		}
		if(helloMessage=="false")
		{
			return false;
		}
    } 
    // a HTTP status different than 200 signals an error
    else 
    {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
}

function makeReservation(what, d, month, maxDays)
{
	return null;
}