
var myProgrammRequest;
var combo_day;
var combo_month;

window.addEvent('domready', function() {
		
	var d_day=1;
	var d_month=3;
	
	combo_day = $('c-mid-pprev-cbox-d');
	combo_month = $('c-mid-pprev-cbox-m');
	h_date = $('data-curDayOfWeek');
	
	var div_result = $('c-mid-pprev-result');
	
	var img_ajaxloader = $('c-mid-pprev-ajaxloader');
	img_ajaxloader.set('styles', {visibility: 'hidden'});
	
	combo_day.addEvent("change", function(){
		img_ajaxloader.set('styles', {visibility: 'visible'});
		requestNewProgramm();
	});
	
	combo_month.addEvent("change", function(){
		img_ajaxloader.set('styles', {visibility: 'visible'});
		requestNewProgramm();
	});
	
	myProgrammRequest = new Request.HTML({url:'ajax/getOverview.php',
		onComplete: function(responseTree, responseElements, responseHTML, responseJavaScript) {

			var response = responseHTML;
			var values = response.split('\n');
			
			div_result.set('html', values[2]);
			h_date.set('html', values[1]);
			combo_day.set('html', values[0]);
			
			img_ajaxloader.set('styles', {visibility: 'hidden'});
		},
		onFailure: function() {
			div_result.set('html', 'Die Programm Vorschau ist für dieses Datum aus technischen Gründen zur Zeit nicht abrufbar. Vielen Dank für Ihr Verständnis!');
			img_ajaxloader.set('styles', {visibility: 'hidden'});
		}
	});		
	
});

function requestNewProgramm() {
	
	var day = combo_day.options[combo_day.selectedIndex].value;
	var month = combo_month.options[combo_month.selectedIndex].value;
	
	myProgrammRequest.send({
	    method: 'get',
	    url: 'ajax/getOverview.php?d=' + day + '&m=' + month,
	});
}
