// Choose the first month with data for article archive from 2010  (EYE 2010-07-21)
function chooseFirstMonth() {
	if ( document.getElementById('searchmonth_form') ) {
		if ( document.getElementById('FIELD_WFQBE_YEARMONTH_0').selectedIndex == 0 && document.getElementById('FIELD_WFQBE_YEARMONTH_0').options.length>1 ) {
			document.getElementById('FIELD_WFQBE_YEARMONTH_0').selectedIndex = 1;
			document.getElementById('searchmonth_form').submit();
		}
	}
}

function filterLoad() {
	// Cookie: Reset if set, otherwise perform initial search
	if (getCookie('smwflt') == 1) {
		document.cookie = 'smwflt=0';
	} else {
		if (document.getElementById('FIELD_WFQBE_MONTH_1').selectedIndex == 0) {
			//document.cookie = 'smwflt=1';
			//document.getElementById('FIELD_WFQBE_MONTH_1').selectedIndex = 1;
			var d = new Date();
			var month = d.getMonth()+1;
			if (month == 13) month = 1;
			document.getElementById('FIELD_WFQBE_MONTH_1').value = (prefixZero(month, 2));
			document.getElementById('searchmonth_form').submit();
		}
	}
	// Month & Rubrik: onChange => submit incl Cookie
	Event.observe('FIELD_WFQBE_MONTH_1',  'change', selectChange);
	Event.observe('FIELD_WFQBE_RUBRIK_2', 'change', selectChange);
	// Month & Rubrik: 'all' Text
	document.getElementById('FIELD_WFQBE_MONTH_1') .options[0].text = '(all months)';
	document.getElementById('FIELD_WFQBE_RUBRIK_2').options[0].text = '(all article types)';
}

function prefixZero(value, length) {
	var str = '' + value;
    while (str.length < length) {
        str = '0' + str;
    }
    return str;
}

function selectChange() {
	document.cookie = 'smwflt=1';
	document.getElementById('searchmonth_form').submit();
}

function getCookie ( cookie_name ) {
  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );
  if (results) return (unescape(results[2]));
  else return null;
}



