//////////////////////////////////////////////////////////////////////////////////
//																				//
//	checkCountry(objCountry,objArea,objDistrict)								//
//	Test to see if there is a conflict with other regions that are choosen		//
//	at the same tine and remove them.											//
//																				//
//////////////////////////////////////////////////////////////////////////////////

function checkCountry(objCountry,objArea,objDistrict)
	{
	var s_area     = '';
	var i_area     = 0;
	var s_district = '';
	var i_district = 0;

//
//	Find the selected countries.
//	Retrieve selected countrycode.
//

	var i2 = objCountry.options.length;
	for (i3 = 0; i3 < i2; i3++)
		if (objCountry.options[i3].selected)
			{
			var s_countrycode = objCountry.options[i3].value.substr(0,2);

//
//	Find selected areas.
//	Check if the selected country contains the selected area.
//	If so, unselect it and add to message.
//

			if (objArea)
				{
				var i4 = objArea.options.length;
				for (i5 = 0; i5 < i4; i5++)
					if (objArea.options[i5].selected)
						if (objArea.options[i5].value.substr(0,2) == s_countrycode)
							{
							objArea.options[i5].selected = false;
							if (s_area == '')
								s_area = objArea.options[i5].text
							else
								s_area += ', '+objArea.options[i5].text;
							i_area += 1;
							}
				}

//
//	Find selected districts.
//	Check if the selected district is within the selected country.
//	At the moment all districts are considered to be in sweden.
//	If so, unselect it and add to message.
//

			if (objDistrict)
				{
				var i4 = objDistrict.options.length;
				for (i5 = 0; i5 < i4; i5++)
					if (objDistrict.options[i5].selected)
//						if (objDistrict.options[i5].value.substr(0,2) == s_countrycode)
						if ('se' == s_countrycode)
							{
							objDistrict.options[i5].selected = false;
							if (s_district == '')
								s_district = objDistrict.options[i5].text
							else
								s_district += ', '+objDistrict.options[i5].text;
							i_district += 1;
							}
				}
			}

//
//	Display messages.
//

	if (i_area == 1)
		alert(s_area+' wurde gelöscht, weil Sie im ganzen Land suchen.');
	if (i_area > 1)
		alert(s_area+' wurde gelöscht, weil Sie im ganzen Land suchen.');
	if (i_district == 1)
		alert('Die Kommune '+s_district+' wurde gelöscht, weil Sie im ganzen Land suchen.');
	if (i_district > 1)
		alert('Die Kommunen '+s_district+' wurde gelöscht, weil Sie im ganzen Land suchen.');
	return true;
	}

//////////////////////////////////////////////////////////////////////////////////
//																				//
//	checkArea(objCountry,objArea,objDistrict)									//
//	Test to see if there is a conflict with other regions that are choosen		//
//	at the same tine and remove them.											//
//																				//
//////////////////////////////////////////////////////////////////////////////////

function checkArea(objCountry,objArea,objDistrict)
	{
	var s_country  = '';
	var i_country  = 0;
	var s_district = '';
	var i_district = 0;

//
//	Find the selected areas.
//	Retrieve selected countrycode and areacode.
//

	var i2 = objArea.options.length;
	for (i3 = 0; i3 < i2; i3++)
		if (objArea.options[i3].selected)
			{
			var s_countrycode = objArea.options[i3].value.substr(0,2);
			var s_areacode    = objArea.options[i3].value.substr(2,2);

//
//	Find selected countries.
//	Check if the selected country contains the selected area.
//	If so, unselect it and add to message.
//

			if (objCountry)
				{
				var i4 = objCountry.options.length;
				for (i5 = 0; i5 < i4; i5++)
					if (objCountry.options[i5].selected)
						if (objCountry.options[i5].value.substr(0,2) == s_countrycode)
							{
							objCountry.options[i5].selected = false;
							if (s_country == '')
								s_country = objCountry.options[i5].text
							else
								s_country += ', '+objCountry.options[i5].text;
							i_country += 1;
							}
				}

//
//	Find selected districts.
//	Check if the selected district is within the selected area.
//	If so, unselect it and add to message.
//

			if (objDistrict)
				{
				var i4 = objDistrict.options.length;
				for (i5 = 0; i5 < i4; i5++)
					if (objDistrict.options[i5].selected)
						if (objDistrict.options[i5].value.substr(0,2) == s_areacode)
							{
							objDistrict.options[i5].selected = false;
							if (s_district == '')
								s_district = objDistrict.options[i5].text
							else
								s_district += ', '+objDistrict.options[i5].text;
							i_district += 1;
							}
				}

			}

//
//	Display messages.
//

	if (i_country == 1)
		alert(s_country+' wurde gelöscht, weil Sie einzelne Bezirke im Land gewählt haben.');
	if (i_country > 1)
		alert(s_country+' wurde gelöscht, weil Sie einzelne Bezirke in den Ländern gewählt haben.');
	if (i_district == 1)
		alert('Die Kommune '+s_district+' wurde gelöscht, weil Sie im ganzen Bezirk suchen.');
	if (i_district > 1)
		alert('Die Kommunen '+s_district+' wurde gelöscht, weil Sie den Bezirk gewählt haben, in dem die Gemeinden liegen.');
	return true;
	}

//////////////////////////////////////////////////////////////////////////////////
//																				//
//	checkDistrict(objCountry,objArea,objDistrict)								//
//	Test to see if there is a conflict with other regions that are choosen		//
//	at the same tine and remove them.											//
//																				//
//////////////////////////////////////////////////////////////////////////////////

function checkDistrict(objCountry,objArea,objDistrict)
	{
	var s_country = '';
	var i_country = 0;
	var s_area    = '';
	var i_area    = 0;

//
//	Find the selected districts.
//	Retrieve selected countrycode and areacode.
//	At the moment, countrycode is always 'se'.
//

	var i2 = objDistrict.options.length;
	for (i3 = 0; i3 < i2; i3++)
		if (objDistrict.options[i3].selected)
			{
			var s_countrycode = 'se';
			var s_areacode    = objDistrict.options[i3].value.substr(0,2);

//
//	Find selected countries.
//	Check if the selected country contains the selected district.
//	If so, unselect it and add to message.
//

			if (objCountry)
				{
				var i4 = objCountry.options.length;
				for (i5 = 0; i5 < i4; i5++)
					if (objCountry.options[i5].selected)
						if (objCountry.options[i5].value.substr(0,2) == s_countrycode)
							{
							objCountry.options[i5].selected = false;
							if (s_country == '')
								s_country = objCountry.options[i5].text
							else
								s_country += ', '+objCountry.options[i5].text;
							i_country += 1;
							}
				}

//
//	Find selected areas.
//	Check if the selected area contains the selected district.
//	If so, unselect it and add to message.
//

			if (objArea)
				{
				var i4 = objArea.options.length;
				for (i5 = 0; i5 < i4; i5++)
					if (objArea.options[i5].selected)
						if (objArea.options[i5].value.substr(2,2) == s_areacode)
							{
							objArea.options[i5].selected = false;
							if (s_area == '')
								s_area = objArea.options[i5].text
							else
								s_area += ', '+objArea.options[i5].text;
							i_area += 1;
							}
				}
			}

//
//	Display messages.
//

	if (i_country == 1)
		alert(s_country+' wurde gelöscht, weil Sie einzelne Gemeinden im Land gewählt haben.');
	if (i_country > 1)
		alert(s_country+' wurde gelöscht, weil Sie einzelne Gemeinden in den Ländern gewählt haben.');
	if (i_area == 1)
		alert(s_area+' wurde gelöscht, weil Sie einzelne Gemeinden im Bezirk gewählt haben.');
	if (i_area > 1)
		alert(s_area+' wurde gelöscht, weil Sie einzelne Gemeinden in den Bezirken gewählt haben.');
	return true;
	}

//////////////////////////////////////////////////////////////////////////////////
//																				//
//	checkMaxDate(dateCheck,maxDays)												//
//	Check to verify that the date is correct and within maxDays from now.		//
//																				//
//////////////////////////////////////////////////////////////////////////////////

function checkMaxDate(dateCheck,maxDays)
	{

//
//	Check date.
//	(199|200)[0-9]				Year between 1990 and 2009.
//	\-							Use - as separator.
//	(0[1-9]|1[0-2])				Month between 01 and 12.
//	\-							Use - as separator.
//	(0[1-9]|[12][0-9]|3[01])	Day between 01 and 1.
//

	var filter = /^(199|200)[0-9]\-(0[1-9]|1[0-2])\-(0[1-9]|[12][0-9]|3[01])$/;
	if (!filter.test(dateCheck))
		{
		alert('Bitte schreiben Sie das Datum auf schw. Weise: Jahr-Monat-Tag, (JJJJ-MM-TT).');
		return false;
		}

//
//	Check valid date by converting it to a date and back
//

	var dateCheckYear  = dateCheck.substr(0,4);
	var dateCheckMonth = dateCheck.substr(5,2)-1;
	var dateCheckDay   = dateCheck.substr(8,2);

	var dateTest = new Date(dateCheck.substr(0,4),dateCheck.substr(5,2)-1,dateCheck.substr(8,2));

	if (dateTest.getFullYear() != dateCheckYear  ||
		dateTest.getMonth()    != dateCheckMonth ||
		dateTest.getDate()     != dateCheckDay)
		{
		alert('Ungültiges Datum.');
		return false;
		}

//
//	Calculate todays date and date to check as UTC (milliseconds since 1970-01-01).
//

	var dateNow      = new Date();
	var dateNowUTC   = Date.UTC(dateNow.getFullYear(),dateNow.getMonth(),dateNow.getDate(),0,0,0,0);
	var dateCheckUTC = Date.UTC(dateCheckYear,dateCheckMonth,dateCheckDay,0,0,0,0);

//
//	Calculate days between today and date to check.
//

	var diffDays = (dateCheckUTC-dateNowUTC)/1000/60/60/24;
	if (diffDays < 0)
		{
		alert('Datum liegt vor dem heutigen Datum.');
		return false;
		}
	else
		{
		if (diffDays > maxDays)
			{
			alert('Datum bitte innerhalb der nächsten '+maxDays+' Tage wählen.');
			return false;
			}
		}
	return true;
	}

//////////////////////////////////////////////////////////////////////////////////
//																				//
//	displayDate()																//
//	Writes day, date and year.													//
//																				//
//////////////////////////////////////////////////////////////////////////////////

function displayDate()
	{
	var mydate=new Date()
	var year=mydate.getYear()
	if (year < 2000)
		year = year+1900
	var day=mydate.getDay()
	var month=mydate.getMonth()
	var daym=mydate.getDate()	
	
	var dayarray=new Array("Sonntag","Montag","Dienstag","Mittwoch","Donnerstag","Freitag","Samstag")
	var montharray=new Array("Januar","Februar","März","April","Mai","Juni","Juli",
	"Augusti","September","Oktober","November","Dezember")
	
	document.write(dayarray[day]+", "+daym+". "+montharray[month]+" "+year)
	}