function showcalender(type)
{
	window.open("/calendar.html?fld=" + type, "calendar", "width=165, height=200, status=yes");
	return false;
}

function setDate(type, update, ignoredep)
{
	var day = document.getElementById(type + 'day');
	var month = document.getElementById(type + 'month');
	var year = document.getElementById(type + 'year');
	
	selectedday = day.selectedIndex;
	
	if(update)
	{
		for(i = day.options.length-1; i >= 0; i--)
			day.options[i] = null;
			
		numdays = getDaysInMonth(month.options[month.selectedIndex].value, year.options[year.selectedIndex].value);
		
		for(i = 0; i < numdays; i++)
			day.options[i] = new Option(i+1,i+1);
			
		day.selectedIndex = selectedday > (numdays - 1) ? numdays - 1 : selectedday;
	}
	
	if(!ignoredep && type == 'arr')
	{	
		var depday = document.getElementById('depday');
		var depmonth = document.getElementById('depmonth');
		var depyear = document.getElementById('depyear');
		
		if(day.selectedIndex == day.options.length - 1)	
		{				
			if(depmonth.selectedIndex == 11)
			{
				//volgend jaar	
				depday.selectedIndex = 0;
				depmonth.selectedIndex = 0;				
				depyear.selectedIndex = 1;				
			}
			else
			{
				//volgende maand				
				depday.selectedIndex = 0;
				depmonth.selectedIndex = month.selectedIndex + 1;				
				depyear.selectedIndex = year.selectedIndex;
			}
		}
		else
		{
			depday.selectedIndex = selectedday + 1;
			depmonth.selectedIndex = month.selectedIndex;
			depyear.selectedIndex = year.selectedIndex;
		}	
	}	
}

function isLeapYear(year)
{
	var leapYear=false;
	var year = parseInt(year);
	
	//als jaar deelbaar is door 4 dan schrikkeljaar, geen checks voor 100 jaar enzo, tegen die tijd zijn we toch dood :)
	if(year % 4 == 0)
		return true;
		
	return false;
}

function getDaysInMonth(month, year)
{
	var month = parseInt(month);
	
	switch(month)
	{
		case 2:  //feb
			return isLeapYear(year)	? 29 : 28;
			break;
		
		case 4:  //april
		case 6:  //juni
		case 9:  //sep
		case 11: //nov
			return 30;
			break;
			
		default: //overige
			return 31;		
	}
}

function changeCountry(country)
{
	var city = document.getElementById('city');

	for(i=city.options.length - 1; i > 0; i--)
		city.options[i] = null;
		
	for (i=0; i < options[country.selectedIndex].length; i++)	
		city.options[i] = options[country.selectedIndex][i];
			
	city.options[0].selected = true;
}

function setCountry(countrycode)
{
	var city = document.getElementById('city');
	var country = document.getElementById('country');

	for(i=city.options.length - 1; i > 0; i--)
		city.options[i] = null;
		
	for (i=0; i < options[country.selectedIndex].length; i++)	
		city.options[i] = options[country.selectedIndex][i];
			
	city.options[0].selected = true;
}
