function getDocument()
{
	xHRObject.open('GET', '/xml/dates.php?l=' + language + '&parent=' + document.getElementById('plans').value + '&id=' + Number(new Date), true);
	xHRObject.send(null);
}

function selectPlans()
{
	clearContent(document.getElementById('kurss'));
	if(document.getElementById('plans').value!=0)
	{
		if (window.XMLHttpRequest)
		{
			xHRObject = new XMLHttpRequest();
		}
		else if (window.ActiveXObject)
		{
			xHRObject = new ActiveXObject('Microsoft.XMLHTTP');
		}

		xHRObject.onreadystatechange = outputDates;
		getDocument();
	}
}

function outputDates()
{
	var songList = document.getElementById('kurss');
	if (xHRObject.readyState == 4 && xHRObject.status == 200)
	{
		if(xHRObject.responseXML)
		{
			var xmlDocument = xHRObject.responseXML;
			var rootNode = xmlDocument.documentElement;
			if(rootNode.firstChild)
			{
				var element = rootNode.firstChild;
				if(element.firstChild)
				{
					addOption(songList,element);
				}

				while(element = element.nextSibling)
				{
					if(element.firstChild)
					{
						addOption(songList,element);
					}
				}
			}
		}
		xHRObject.abort();
	}
}

function clearContent(obj)
{
	while(obj.firstChild) obj.removeChild(obj.firstChild);
}

function addOption(select,element)
{
	var option = document.createElement('option');
	option.setAttribute('value',element.firstChild.firstChild.nodeValue);
	option.appendChild(document.createTextNode(element.lastChild.firstChild.nodeValue));
	if(element.firstChild.firstChild.nodeValue && element.lastChild.firstChild.nodeValue)
	{
		select.appendChild(option);
	}
}
