function redirectAgenda(url, searchtype) 
{
	var bar_search		= document.getElementById('bar_search');
	var fld_id			= document.getElementById('id');
	var gidssearch		= document.getElementById('gidssearch');
		
	bar_search.value 	= searchtype;
	
	try {
		var test2 		= parent.frames.iframeinclude;
		
		if (test2 == undefined) {
			  throw "ThrowError";
		}
		document.forms['frm'].target = "iframeinclude";
		document.forms['frm'].submit();
		
	} catch (err) {
		//window.parent.location.href = 'http://www.vlissingen.nl/web/show/id=377142';
		//window.parent.document.showURL("/web/show/id=377142", '_top');
		
		fld_id.value = 4;	
		gidssearch.value = 4;	
		
		document.forms['frm'].submit();
	}	
}

function changeMonth(action, url) 
{
	var current_week 	= document.getElementById('week');
	var current_month 	= document.getElementById('month');
	var current_year 	= document.getElementById('year');

	if (action == 'next') {
		var next_month 	= parseInt(current_month.value) + 1;
		if (next_month > 12) {
			next_month 	= 1;
			current_year.value = parseInt(current_year.value) + 1;
		}
		current_month.value = next_month
	}

	if (action == 'prev') {
		var next_month 	= parseInt(current_month.value) - 1;
		if (next_month < 1) {
			next_month 	= 12;
			current_year.value = parseInt(current_year.value) - 1;
		}
		current_month.value = next_month
	}

	current_week.value 	= '';

	//selectMonth(next_month, url);
	
	refreshAgenda(url);
}
function selectDay(new_day, url, special) 
{
	clearAll();
	
	var month_field		= document.getElementById('month');
	var day_field 		= document.getElementById('active_day');
	var new_td 			= document.getElementById(new_day);
		
	var old_month 		= month_field.value;
	
	if (special != undefined) {
		if (special == 'extra_begin') {
			month_field.value = parseInt(month_field.value) - 1;
			
			if (month_field.value == 0) {
				month_field.value = 12;
			}
		} else if (special == 'extra_end') {
			month_field.value = parseInt(month_field.value) + 1;

			if (month_field.value > 12) {
				month_field.value = 1;
			}
		}
	}
	
	
	new_td.className 	= new_td.className+' current';
	
	day_field.value 	= new_day;
	
	redirectAgenda(url, 2)
	
	month_field.value 	= old_month
}
function selectWeek(week, url) 
{
	clearAll();

	var week_field 		= document.getElementById('week');
	var new_week 		= document.getElementById('week'+week);
	
	new_week.className 	= new_week.className + ' current_week';
	
	week_field.value 	= week;
		
	redirectAgenda(url, 3)
}
function selectMonth(month, url) 
{
	clearAll();

	document.getElementById('month').value = month;
	document.getElementById('week').value = '';	
	
	redirectAgenda(url, 4)
}
function clearAll()
{
	//Clear currently selected day
	var day_field 		= document.getElementById("active_day");
	var old_td 			= document.getElementById(day_field.value);

	if (old_td != null) {
		old_td.className 	= old_td.className.replace(' current', '');
	}

	//Clear currently selected week
	var week_field = document.getElementById('week');
	var old_week = document.getElementById('week' + week_field.value);

	if (old_week != null) {
		old_week.className 	= old_week.className.replace(' current_week', '');
	}
}
function refreshAgenda(url) 
{
	var id				= '?id='			+ document.getElementById('agenda_id').value;
	var day				= '&ag_day='		+ document.getElementById('active_day').value;
	var month			= '&ag_month='		+ document.getElementById('month').value;
	var year			= '&ag_year='		+ document.getElementById('year').value;
	var week			= '&ag_week='		+ document.getElementById('week').value;
	var gidssearch 		= '&gidssearch=2' //	+ document.getElementById('gidssearch').value;
	

	
	window.location = url + id + day + month + year + week + gidssearch;
}

