
//Gets called when combo box selection changes
function DaysListOnChange() 
{
	var yearList = document.getElementById("cmbYear");
	var monthList = document.getElementById("cmbMonth");

	//Getting the selected qualification from qualification combo box.
	var selectedYear = yearList.options[yearList.selectedIndex].value;
	var selectedMonth = monthList.selectedIndex;	
	
	// URL to get specialization for a given qualification
	var requestUrl = AjaxServerPageName + "?SelectedYear=" + encodeURIComponent(selectedYear) + "&SelectedMonth=" + encodeURIComponent(selectedMonth);
	CreateXmlHttp();
	
	// If browser supports XMLHTTPRequest object
	if(XmlHttp)
	{
		//Setting the event handler for the response
		XmlHttp.onreadystatechange = HandleDayResponse;
		
		//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 HandleDayResponse()
{
	// 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)
		{			
			ClearAndSetDayListItems(XmlHttp.responseXML.documentElement);			
		}
		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 ClearAndSetDayListItems(dayNode)
{	
	var listPosition = dayNode.firstChild.nodeName;
    var dayList = document.getElementById("cmbDay");
	//Clears the state combo box contents.
	for (var count = dayList.options.length-1; count >-1; count--)
	{
		dayList.options[count] = null;
	}
	
	var dayNodes = dayNode.getElementsByTagName('DayName');	
	var textValue; 
	
	var optionItem;	
	//Add new states list to the state combo box.
	for (var count = 0; count < dayNodes.length; count++)
	{
   		textValue = GetInnerText(dayNodes[count]);   		
		optionItem = new Option( textValue, textValue,  false, false);		
		dayList.options[dayList.length] = optionItem;
	}
}