function start()
{	
	if(document.images)
	{
		btn_1a 		= newImage("images/AnjalanVPK_01.gif");
		btn_2a 		= newImage("images/AnjalanVPK_25.gif");
		btn_3a 		= newImage("images/Hallinto_01.gif");
		btn_4a 		= newImage("images/Rahoitus_01.gif");
		btn_5a 		= newImage("images/Organisaatio_01.gif");
		btn_6a 		= newImage("images/Harrastusos_01.gif");
		btn_7a 		= newImage("images/Halytysosasto_01.gif");
		btn_8a 		= newImage("images/Nuoriso_01.gif");
		btn_9a 		= newImage("images/Toiminta_01.gif");
		btn_10a 	= newImage("images/Puitteet_01.gif");
		btn_11a 	= newImage("images/Historia_01.gif");
		btn_12a 	= newImage("images/Galleria_01.gif");
		btn_13a 	= newImage("images/Arkisto_01.gif");
		btn_14a 	= newImage("images/Toimitilat_01.gif");
		btn_15a 	= newImage("images/Kalusto_01.gif");
		btn_16a 	= newImage("images/Varusteet_01.gif");
		btn_17a 	= newImage("images/Yhteystiedot_01.gif");
		btn_18a 	= newImage("images/Tiedostot_01.gif");
		btn_19a 	= newImage("images/Viikkonakyma_01.gif");
		btn_20a 	= newImage("images/Yleisnakyma_01.gif");
		btn_21a 	= newImage("images/Kausiohjelmat_01.gif");
		btn_22a 	= newImage("images/Uusi-tapahtuma_01.gif");
		btn_23a 	= newImage("images/Sivustonhallinta_01.gif");
		btn_24a 	= newImage("images/Kayttajienhallinta_01.gif");
		btn_25a 	= newImage("images/Tiedostonhallinta_01.gif");
		btn_26a 	= newImage("images/Palokuntapuvut_01.gif");
		btn_27a 	= newImage("images/Kalenteri_01.gif");
		btn_28a 	= newImage("images/Palokuntarekisteri_01.gif");
		btn_29a 	= newImage("images/Ajankohtaista_01.gif");
		btn_30a 	= newImage("images/Valikonhallinta_01.gif");

		btn_1b 		= newImage("images/AnjalanVPK_01-over.gif");
		btn_2b 		= newImage("images/AnjalanVPK_25-over.gif");
		btn_3b 		= newImage("images/Hallinto_01-over.gif");
		btn_4b 		= newImage("images/Rahoitus_01-over.gif");
		btn_5b 		= newImage("images/Organisaatio_01-over.gif");
		btn_6b 		= newImage("images/Harrastusos_01-over.gif");
		btn_7b 		= newImage("images/Halytysosasto_01-over.gif");
		btn_8b 		= newImage("images/Nuoriso_01-over.gif");
		btn_9b 		= newImage("images/Toiminta_01-over.gif");
		btn_10b 	= newImage("images/Puitteet_01-over.gif");
		btn_11b 	= newImage("images/Historia_01-over.gif");
		btn_12b 	= newImage("images/Galleria_01-over.gif");
		btn_13b 	= newImage("images/Arkisto_01-over.gif");
		btn_14b 	= newImage("images/Toimitilat_01-over.gif");
		btn_15b 	= newImage("images/Kalusto_01-over.gif");
		btn_16b 	= newImage("images/Varusteet_01-over.gif");
		btn_17b 	= newImage("images/Yhteystiedot_01-over.gif");
		btn_18b 	= newImage("images/Tiedostot_01-over.gif");
		btn_19b 	= newImage("images/Viikkonakyma_01-over.gif");
		btn_20b 	= newImage("images/Yleisnakyma_01-over.gif");
		btn_21b 	= newImage("images/Kausiohjelmat_01-over.gif");
		btn_22b 	= newImage("images/Uusi-tapahtuma_01-over.gif");
		btn_23b 	= newImage("images/Sivustonhallinta_01-over.gif");
		btn_24b 	= newImage("images/Kayttajienhallinta_01-over.gif");
		btn_25b 	= newImage("images/Tiedostonhallinta_01-over.gif");
		btn_26b 	= newImage("images/Palokuntapuvut_01-over.gif");
		btn_27b 	= newImage("images/Kalenteri_01-over.gif");
		btn_28b 	= newImage("images/Palokuntarekisteri_01-over.gif");
		btn_29b 	= newImage("images/Ajankohtaista_01-over.gif");
		btn_30b 	= newImage("images/Valikonhallinta_01-over.gif");
	}
}

function newImage(arg)
{
	if(document.images)
	{
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function over(imgName)
{
	if(document.images)
	{
		imgOn=eval(imgName + "b.src");
		document[imgName].src = imgOn;
	}
}

function out(imgName)
{
	if(document.images)
	{
		imgOff=eval(imgName + "a.src");
		document[imgName].src = imgOff;
	}
}

function confirmSubmit(sentence)
{
	var confirmWindow = confirm(sentence);
	
	if(confirmWindow)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function isChecked(field, sentence)
{
	for(i = 0; i < field.length; i++)
	{
		if(field[i].checked == true && field[i].value != "0")
		{
			return confirmSubmit(sentence);
		}
	}
	
	return false;
}

function checkText(isText, sentence)
{
	if(isText.value == false || isText.value == "")
	{
		alert(sentence);
		return false;
	}
	else
	{
		return true;
	}
}

function checkText2(upload, dropdownBox, fileTitle)
{
	return sendFile(upload, dropdownBox, fileTitle);
}

function checkText3(user, pass)
{
	if(checkText(user, 'Anna käyttäjätunnus') == false)
		return false;
	else if(checkText(pass, 'Anna salasana') == false)
		return false;
	else
		return true;
}

function checkText4(pass)
{
	return checkText(pass, 'Anna salasana');
}

function sendFile(upload, dropdownBox, fileTitle)
{	
	if(upload.value != "")
	{
		//if(fileTitle.value == "")
		//{
		//	alert('Kirjoita otsikko');
		//	return false;
		//}
		
		if(document.fileForm.hiddenPic.value == 1)
		{
			if(dropdownBox.pictures.value == '0')
			{
				alert('Valitse alaotsikko kuvalle');
				return false;
			}
			else
			{
				return true;
			}
		}

		if(document.fileForm.hiddenDoc.value == 1)
		{
			if(dropdownBox.documents.value == '0')
			{
				alert('Valitse alaotsikko tiedostolle');
				return false;
			}
			else if(dropdownBox.shown.value == '0')
			{
				alert('Valitse käyttäjäryhmä');
				return false;
			}
			else
			{
				return true;
			}
		}
	}
	else
	{
		alert('Valitse tiedosto');
		return false;
	}
}

function changeFileData(dropdownBox, fileTitle)
{
	if(fileTitle.value == "")
	{
		alert('Kirjoita otsikko');
		return false;
	}
	
	if(document.fileForm.hiddenPic.value == 1)
	{
		if(dropdownBox.pictures.value == '0')
		{
			alert('Valitse alaotsikko kuvalle');
			return false;
		}
		else
		{
			return true;
		}
	}

	if(document.fileForm.hiddenDoc.value == 1)
	{
		if(dropdownBox.documents.value == '0')
		{
			alert('Valitse alaotsikko tiedostolle');
			return false;
		}
		else if(dropdownBox.shown.value == '0')
		{
			alert('Valitse käyttäjäryhmä');
			return false;
		}
		else
		{
			return true;
		}
	}
}

function checkFilename()
{
	var newVal = document.fileForm.upload;
	
	if(newVal.value != "")
	{
		var check = 0;
		
		for(var i = (newVal.value.length - 1); i >= 0; i--)
		{			
			if(newVal.value.charAt(i) == ".")
			{
				check = 1;
				break;
			}
		}
		
		if(check == 1)
		{
			var lauseke = "";
			
			for(var j = (i + 1); j < newVal.value.length; j++)
			{
				lauseke +=  newVal.value.charAt(j);
			}
			
			lauseke = lauseke.toLowerCase();
			
			if(lauseke == "jpg" || lauseke == "gif" || lauseke == "png")
			{
				document.fileForm.hiddenPic.value = 1;
				document.fileForm.hiddenDoc.value = "";
				show1();
			}
			else
			{
				document.fileForm.hiddenPic.value = "";
				document.fileForm.hiddenDoc.value = 1;
				show2();
			}		
		}
		else
		{
			alert('Lisää tiedosto');
			return false;
		}
	}
}

function changeTableColor(idName, color)
{
	document.getElementById(idName).style.background = color;
}

function hide(obj)
{
	obj.style.display = "none";
}

function show(obj)
{
	obj.style.display = "";
}

function hideBoth(adminLink, newFile, alterFile)
{
	if(adminLink == "3" && newFile == "Uusi tiedosto")
	{
		hide(document.getElementById('1'));
		hide(document.getElementById('2'));
		hide(document.getElementById('30'));
		hide(document.getElementById('3'));
	}
	else if(adminLink == "3" && (alterFile == ".jpg" || alterFile == ".gif" || alterFile == ".png"))
	{
		document.fileForm.hiddenPic.value = 1;
		document.fileForm.hiddenDoc.value = "";
		document.fileForm.shown.value = "";
		show1();
	}
	else if(adminLink == "3" && alterFile != "")
	{
		document.fileForm.hiddenPic.value = "";
		document.fileForm.hiddenDoc.value = 1;
		document.fileForm.shown.value = 1;
		show2();
	}
}

function show1()
{
	show(document.getElementById('1'));
	hide(document.getElementById('2'));
	hide(document.getElementById('30'));
	hide(document.getElementById('3'));
}

function show2()
{
	hide(document.getElementById('1'));
	show(document.getElementById('2'));
	show(document.getElementById('30'));
	show(document.getElementById('3'));
}

function showPictures(id, imgWidth, imgHeight)
{
	imgWidth += 40;
	imgHeight += 32;
	
	myWindow = window.open("showPics.php", "showPictures", "resizable=yes, toolbar=0, location=0, directories=0, status=0, menubar=yes, scrollbars=yes, copyhistory=0, width=800, height=600");
	myWindow.location = "showPics.php?ID=" + id;
}

function printARs(ARYear, ARPeriod, ARDepartment, AROrder)
{
	if(ARDepartment != 0)
	{
		imgWidth = 720;
		imgHeight = 600;
		
		myWindow = window.open("printARs.php", "printAnnualReports", "resizable=no, toolbar=0, location=0, directories=0, status=0, menubar=yes, scrollbars=yes, copyhistory=0, width=" + imgWidth + ", height=" + imgHeight + "");
		myWindow.location = "printARs.php?annualReportChoosingYear=" + ARYear + "&annualReportChoosingPeriod=" + ARPeriod + "&annualReportChoosingDepartment=" + ARDepartment + "&order=" + AROrder;
	}
	else
	{
		alert('Valitse osasto.');
	}
}

function printCMNViews(search0, search1, search2, search3, search4, order)
{
	imgWidth = 720;
	imgHeight = 600;
	
	myWindow = window.open("printCMNViews.php", "printCommonViews", "resizable=no, toolbar=0, location=0, directories=0, status=0, menubar=yes, scrollbars=yes, copyhistory=0, width=" + imgWidth + ", height=" + imgHeight + "");
	myWindow.location = "printCMNViews.php?order=" + order + "&calStartTime=" + search0 + "&calEndTime=" + search1 + "&calCommonViewSelectEvent=" + search2 + "&calCommonViewSelectDepartment=" + search3 + "&calCommonViewSelectShow=" + search4;
}

function printCalendar(givenWeeks, weekDifference)
{
	imgWidth = 720;
	imgHeight = 600;
	
	myWindow = window.open("printCalendar.php", "printCalendar", "resizable=no, toolbar=0, location=0, directories=0, status=0, menubar=yes, scrollbars=yes, copyhistory=0, width=" + imgWidth + ", height=" + imgHeight + "");
	myWindow.location = "printCalendar.php?givenWeeks=" + givenWeeks + "&weekDifference=" + weekDifference;
}

function textfieldCheck(fields)
{
	// alert(fields[9].value); // Tulostaa aloitusvuoden
	
	if(checkTimes(fields.calendarStartTime) == true && checkTimes(fields.calendarEndTime) == true)
	{
		if(fields.calendarStartTime.value == "" || fields.calendarEndTime.value == "" || fields.calendarLeaders.value == "" || fields.calendarTitle.value == "" || fields.calendarMessage.value == "" || fields.calendarEventPlace.value == "")
		{
			alert('Täytä kaikki kentät.');
			return false;
		}
	}
	else
	{
		alert('Kellonaika voi sisältää ainoastaan "0-9" tai ":" merkit.');
		return false;
	}
}

function changeDates(field1, field2)
{
	field2.value = field1.value;
	checkStartDay();

	return field2;
}

function checkTimes(field)
{
	for(var i = 0; i < field.value.length; i++)
	{
		if(field.value.charAt(i) != ":" && !(field.value.charAt(i) >= 0 || field.value.charAt(i) <= 9))
		{
			return false;
		}
	}

	return true;	
}

function checkStartDay()
{
	var alkuPP = document.addEventForm.calendarStartDay.value;
	var alkuKK = document.addEventForm.calendarStartMonth.value;
	var alkuVV = document.addEventForm.calendarStartYear.value;
	
	var loppuPP = document.addEventForm.calendarEndDay.value;
	var loppuKK = document.addEventForm.calendarEndMonth.value;
	var loppuVV = document.addEventForm.calendarEndYear.value;
		
	var a = checkDay(alkuPP, (alkuKK - 1), alkuVV);
	var p = checkDay(loppuPP, (loppuKK - 1), loppuVV);

	document.getElementById('startDay').value = a;
	document.getElementById('endDay').value = p;
}

function checkEndDay()
{
	var loppuPP = document.addEventForm.calendarEndDay.value;
	var loppuKK = document.addEventForm.calendarEndMonth.value;
	var loppuVV = document.addEventForm.calendarEndYear.value;
		
	var p = checkDay(loppuPP, (loppuKK - 1), loppuVV);
	
	document.getElementById('endDay').value = p;
}

function checkDay(pp, kk, vv)
{
	var paivays = new Date(vv, kk, pp)
	var viikonPaiva = paivays.getDay();
	var VP;
	
	switch(viikonPaiva)
	{
		case 0: VP = " Su"; break;
		case 1: VP = " Ma"; break;
		case 2: VP = " Ti"; break;
		case 3: VP = " Ke"; break;
		case 4: VP = " To"; break;
		case 5: VP = " Pe"; break;
		case 6: VP = " La"; break;
	}		

	return VP;
}

function changeImgs()
{
	selectedImg = document.imgForm.images.options[document.imgForm.images.selectedIndex].value;

	if(selectedImg == "")
		return;
	else
		self.location = "showPics.php?ID=" + selectedImg;
}
