﻿
var y;
var m;
//var focus;
//var load;
//var OtherObj;
//Gets called when country combo box selection changes
function OnMonthChange(year,mon) 
{
    y = year;
    m = mon;
	//,loader
	//load = document.getElementById(loader);
	//load.style.display="";
	
	
		// URL to get states for a given country
		var requestUrl = "ajaxPages/calender.aspx?year=" + year + "&month=" + mon;
		
		CreateXmlHttp();
		
		
		// If browser supports XMLHTTPRequest object
		if(XmlHttp)
		{
			//Setting the event handler for the response
			XmlHttp.onreadystatechange = calendarHandleResponse;
			
			//Initializes the request object with GET (METHOD of posting), 
			//Request URL and sets the request as asynchronous.
			
			XmlHttp.open("GET", requestUrl,  true);
			
			//Sends the request to server
			XmlHttp.send(null);		
		}
	
}


//Called when response comes back from server
function calendarHandleResponse()
{
	   var moz = (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined');
        var ie = ( typeof window.ActiveXObject != 'undefined');
	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4)
	{
		
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200)
		{			
			 if (document.implementation.createDocument)
			{	
			    		
				SetCalendar(XmlHttp.responseXML.documentElement);
				
			} 
			else if (ie)
			{ 
				var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
				xmlDoc.async = false;
				xmlDoc.loadXML(XmlHttp.responseText);
				SetCalendar(xmlDoc);
				
			}
		   else
		   {
			   alert('browser does not support this script.');
		   }
			
		}
		else
		{
		//	alert("There was a problem retrieving data from the server." );
		}
	}
}

//Clears the contents of state combo box and adds the states of currently selected country
function SetCalendar(CalendarNode)
{
        
		if (CalendarNode!=null)
		{
			var CalendarNodes = CalendarNode.getElementsByTagName('eventList');
			
			eventDays= new Array(CalendarNodes.length);
			for (var count = 0; count < CalendarNodes.length; count++)
			{
   				textvalue = GetInnerText(CalendarNodes[count].getElementsByTagName('day')[0]);
                eventDays[count] = textvalue;
                
			}
			
		}
		
		 showCalenderBody(createCalender(y,m-1,false,true));
}

