/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function go( url )
{
	var thisURL = document.URL;
	var it = 0;
	var currentFrame = null;
	var numberOfFrames = window.frames.length;

	if ( numberOfFrames > 0 )
	{
		for ( it = 0; it < numberOfFrames; ++it )
		{
			currentFrame = window.frames[it];

			if ( currentFrame.location.href == thisURL  )
			{
				currentFrame.location.href = url;
			}

		}
	} else
{
		window.location.href = url;
	}

}

function switchRadioTo( name, value )
{
	var radioButtons = false;
	var radioButton = false;

	radioButtons = document.getElementsByName( name );

	if ( radioButtons )
	{
		for ( var it = 0; it < radioButtons.length; it++ )
		{
			radioButton = radioButtons[it];

			radioButton.checked = ( radioButton.value == value ? true : false );
		}
	}
}

function switchClass( element, newClass )
{
	element.className = newClass;
}

function getDaysByMonth( month, year )
{
	var daysInMonth = new Array();

	daysInMonth[0] = 31;
	daysInMonth[1] = 28;
	daysInMonth[2] = 31;
	daysInMonth[3] = 30;
	daysInMonth[4] = 31;
	daysInMonth[5] = 30;
	daysInMonth[6] = 31;
	daysInMonth[7] = 31;
	daysInMonth[8] = 30;
	daysInMonth[9] = 31;
	daysInMonth[10] = 30;
	daysInMonth[11] = 31;

	if ( month == 1 && year % 4 == 0 )
	{
		daysInMonth[1] = 29;
	}

	return daysInMonth[month];
}

function getSelectedValue( comboBox )
{
	return comboBox.options[comboBox.selectedIndex].value;
}

function populateDayComboBox()
{
	var dayComboBox = document.getElementById( 'dayComboBox' );
	var monthComboBox = document.getElementById( 'monthComboBox' );
	var yearTextField = document.getElementById( 'yearTextField' );
	var month = getSelectedValue( monthComboBox );
	var year = yearTextField.value;
	var numberOfDays = getDaysByMonth( month, year );
	var newDayOption = false;
	var dayOptionList = dayComboBox.options;
	var dayNumber = 0;

	if ( /^\d+$/.test( year ) )
	{
		dayOptionList.length = 0;

		for ( var it = 0; it < numberOfDays; ++it )
		{
			dayNumber = it + 1;

			newDayOption = new Option( dayNumber, dayNumber );

			dayOptionList[dayOptionList.length] = newDayOption;
		}
	} else
	{
		alert( "Jaar veld moet nummeriek zijn" );
	}
}

function setToToday()
{
	var date = new Date();
	var dayComboBox = document.getElementById( 'dayComboBox' );
	var monthComboBox = document.getElementById( 'monthComboBox' );
	var yearTextField = document.getElementById( 'yearTextField' );

	yearTextField.value = date.getFullYear();
	monthComboBox.options.selectedIndex = date.getMonth();

	populateDayComboBox();

	dayComboBox.options.selectedIndex = date.getDate() - 1;
}
