/*
'Purpose	Javascript code for events.asp
'Copyright 2002(C) - IJ & ØM
'
'Changelog
'Date		Sign		Description
'22.06.02	ØM			Initial version
'
'
'
'
*/
function setToDate(form,datetime){
	if(datetime==0){
		form.endDay.value=form.startDay.value;
		form.endMonth.value=form.startMonth.value;
		form.endYear.value=form.startYear.value;
	}
	else{
		form.endHour.value=form.startHour.value;
		form.endMinute.value=form.startMinute.value;
	}
}

function checkStrLength(str,len,preStr){
	str = str.toString();
	if(str.length < len){
		str = preStr+str;
	}
		return str;

}


function goEventSearch(form){
	var fromDate = new Date(form.startYear.value,form.startMonth.value-1,form.startDay.value);
	var toDate	= new Date(form.endYear.value,form.endMonth.value-1,form.endDay.value);
	var	NormBGColor = '#333333';
	var ErrBGColor = '#553333';


	//set new dates on the form, just to make sure that the selected dates actually exists. I.e no 31.06.2002 dates. ;)
	form.startDay.value = checkStrLength(fromDate.getDate(),2,'0');
	form.startMonth.value = checkStrLength(fromDate.getMonth()+1,2,'0');
	form.endDay.value = checkStrLength(toDate.getDate(),2,'0');
	form.endMonth.value = checkStrLength(toDate.getMonth()+1,2,'0');

	if(toDate<fromDate){
		alert('Til dato kan ikke være mindre enn fra dato');
		form.endDay.style.backgroundColor=ErrBGColor;
		form.endMonth.style.backgroundColor=ErrBGColor;
		form.endYear.style.backgroundColor=ErrBGColor;
		form.endDay.focus();
	}
	else{
		form.actionType.value='search';
		form.submit();
		form.endDay.style.backgroundColor=NormBGColor;
		form.endMonth.style.backgroundColor=NormBGColor;
		form.endYear.style.backgroundColor=NormBGColor;
	}
}
