function changeImg(id, imgSrc) {
	document.images[id].src = imgSrc;
}

function changeBanner(id, imgSrc) {
	top.document.images[id].src = imgSrc;
}

function getWeekNbr() {
    var currentDate = new Date();
    var firstDateOfYear = new Date(currentDate.getFullYear(), 00, 01);

    /* 86400000 = number of milliseconds in a day */
    var daysPassed = Math.ceil((currentDate.getTime() - firstDateOfYear.getTime()) / 86400000);

    return Math.floor(((daysPassed + firstDateOfYear.getDay()) / 7) + 1);
}

function highlightCurrentWeek() {
    
}

function calcSAC() {
    var cylinder = document.Calculator.cyl.value;
	var startPressure = document.Calculator.startPres.value;
	var endPressure = document.Calculator.endPres.value;
	var avgDepth = document.Calculator.avgDepth.value;
	var diveTime = document.Calculator.diveTime.value;
		
	// calculate air volume in the beginning
	var airVolumeStart = startPressure * cylinder;
	document.getElementById("airStart").innerHTML = airVolumeStart;
		
	// calculate air volume in the end
	var airVolumeEnd = endPressure * cylinder;
	document.getElementById("airEnd").innerHTML = airVolumeEnd;
		
	// calculate the used air volume 
	var usedAirVolume = airVolumeStart - airVolumeEnd;
	document.getElementById("airUsed").innerHTML = usedAirVolume;
		
	// calculate pressure at average depth
  	var avgPressure = (avgDepth / 10) + 1;
		
	if (diveTime > 0) {
  		// calculate the SAC
    	var SAC = (usedAirVolume / diveTime) / avgPressure;
  
  		// show the result with one decimal
  		document.getElementById("sac").innerHTML = (Math.round(SAC * 10) / 10);
	}
}
	
function createMenuAndSelect(selectedItem, path) {
	if (typeof path == "undefined") {
		path = "";
	}

	
	if (selectedItem == "Etusivu") {
		document.write('<span class="active">Etusivu</span>|');
	}
	else {
		document.write('<a href="' + path + 'index.php">Etusivu</a>|');
	}
	
	if (selectedItem == "Jäseneksi") {
		document.write('<span class="active">Jäseneksi</span>|');
	}
	else {
		document.write('<a href="' + path + 'jaseneksi.php">Jäseneksi</a>|');
	}

	if (selectedItem == "Laitesukellus") {
		document.write('<span class="active">Laitesukellus</span>|');
	}
	else {
		document.write('<a href="' + path + 'koulutus.php">Laitesukellus</a>|');
	}
	
	if (selectedItem == "Tekniikkasuk.") {
		document.write('<span class="active">Tekniikkasuk.</span>|');
	}
	else {
		document.write('<a href="' + path + 'tekniikkasukellus.php">Tekniikkasuk.</a>|');
	}
	
	if (selectedItem == "Vapaasuk.") {
		document.write('<span class="active">Vapaasuk.</span>|');
	}
	else {
		document.write('<a href="' + path + 'vapaasukellus.php">Vapaasuk.</a>|');
	}

	if (selectedItem == "Kalusto") {
		document.write('<span class="active">Kalusto</span>|');
	}
	else {
		document.write('<a href="' + path + 'kalusto.php">Kalusto</a>|');
	}
	
	if (selectedItem == "Nuoriso") {
		document.write('<span class="active">Nuoriso</span>|');
	}
	else {
		document.write('<a href="' + path + 'nuoriso.php">Nuoriso</a>|');
	}

	if (selectedItem == "Tapahtumat") {
		document.write('<span class="active">Tapahtumat</span>|');
	}
	else {
		document.write('<a href="' + path + 'tapahtumat.php">Tapahtumat</a>|');
	}

	if (selectedItem == "Ilmoitustaulu") {
		document.write('<span class="active">Ilmoitustaulu</span>|');
	}
	else {
		document.write('<a href="' + path + 'ilmoitustaulu.php">Ilmoitustaulu</a>|');
	}

	if (selectedItem == "Galleria") {
		document.write('<span class="active">Galleria</span>|');
	}
	else {
		document.write('<a href="' + path + 'galleria.php">Galleria</a>|');
	}

	if (selectedItem == "Yhteystiedot") {
		document.write('<span class="active">Yhteystiedot</span>|');
	}
	else {
		document.write('<a href="' + path + 'yhteystiedot.php">Yhteystiedot</a>|');
	}	

	if (selectedItem == "Linkit") {
		document.write('<span class="active">Linkit</span>|');
	}
	else {
		document.write('<a href="' + path + 'linkit.php">Linkit</a>|');
	}

	document.write('<a href="http://kus.munfoorumi.com">Foorumi</a>');          
}

function confirmation(osoite) {
	var answer = confirm("Poistetaanko ilmoitus?");
	if (answer) {
		window.location = "remove.php?id=" + osoite;
	}
}

