function nappi(tila, kohde) {
	kohde = document.getElementById(kohde);
	var old = kohde.src.split("/");
	old = old[4];
	var kuva = old.split(".");
	if(tila == 1) {
		kohde.src = 'images/' + kuva[0] + '_on.' + kuva[1];
	} else if (tila == 0) {
		kohde.src = 'images/' + kuva[0].substr(0, (kuva[0].length - 3)) + '.gif';
	}
}

function submitform()
{
  document.lomake.submit();
}

function vaihto(kohde)
{
	if(kohde == 1) {
		document.getElementById('ruutu1').style.display = 'block';
		document.getElementById('ruutu2').style.display = 'none';
		document.getElementById('ruutu3').style.display = 'none';
		document.getElementById('r3v').className = 'ala_li';
		document.getElementById('r2v').className = 'ala_li';
		document.getElementById('r1v').className = 'ala_li_on';
	} else if (kohde == 2) {
		document.getElementById('ruutu2').style.display = 'block';
		document.getElementById('ruutu1').style.display = 'none';
		document.getElementById('ruutu3').style.display = 'none';
		document.getElementById('r3v').className = 'ala_li';
		document.getElementById('r2v').className = 'ala_li_on';
	} else if (kohde == 3) {
		document.getElementById('ruutu3').style.display = 'block';
		document.getElementById('ruutu2').style.display = 'none';
		document.getElementById('ruutu1').style.display = 'none';
		document.getElementById('r3v').className = 'ala_li_on';
		document.getElementById('r2v').className = 'ala_li';
	} else if (kohde == 4) {
		document.getElementById('ruutu2').style.display = 'none';

		document.getElementById('ruutu1').style.display = 'none';

		document.getElementById('r2v').className = 'ala_li';
	}
}

function hakuVal(tila) {
	var bN=navigator.appName;
	var teksti = 'Etsi: kirjoita ja paina enter';
	if(tila == 'fokus') {
		if(document.getElementById('hakuBx').value == teksti) {
			document.getElementById('hakuBx').value = '';
		}
		if (bN=="Microsoft Internet Explorer")
			document.getElementById('hakuBx').className = 'ie-searchform-focus';
	} else if (tila == 'blur') {
		if(document.getElementById('hakuBx').value == '') {
			document.getElementById('hakuBx').value = teksti;
		}
		if (bN=="Microsoft Internet Explorer")
			document.getElementById('hakuBx').className = '';
	} else if (tila == 'hover' && bN=="Microsoft Internet Explorer") {
		if(document.getElementById('hakuBx').className != 'ie-searchform-focus')
			document.getElementById('hakuBx').className = 'ie-searchform-hover';
	} else if (tila == 'exit' && bN=="Microsoft Internet Explorer") {
		if(document.getElementById('hakuBx').className != 'ie-searchform-focus')
			document.getElementById('hakuBx').className = '';
	}
}

function tunnusVal(tila) {
	var tunnus = document.getElementById('tunnus');
	if(tila == 1) {
		if(tunnus.value=='tunnus')
			tunnus.value='';
	} else if (tila == 0) {
		if(tunnus.value=='')
			tunnus.value='tunnus';
	}
}

function passuVal(tila) {
	var passu = document.getElementById('salasana');
	if(tila == 1) {
		if(passu.value=='salasana')
			passu.value='';
	} else if (tila == 0) {
		if(passu.value=='')
			passu.value='salasana';
	}
}


/*
        Quizien kysymysten dynaaminen lisääminen
        ----------------------------------------
*/

function addQuizQuestion()
{
	var ni = document.getElementById('quizQuestions');
	var numi = document.getElementById('noOfQuiz');
	var num = (document.getElementById("noOfQuiz").value -1)+ 2;
	numi.value = num;
	var divIdName = "question"+num;
	var newdiv = document.createElement('div');
	newdiv.setAttribute("id",divIdName);
	newdiv.setAttribute("class", "quiz");
	newdiv.innerHTML = "Kysymys: <input type=\"text\" name=\"q[]\" value=\"\" /><input type=\"hidden\" name=\"c[]\" value=\""+num+"\" /> Oikea vastaus on kyll&auml;? <input type=\"checkbox\" name=\"a[]\" value=\""+num+"\" /> <a href=\"javascript:;\" onclick=\"removeQuizQuestion(\'"+divIdName+"\')\">Poista kysymys</a>";
	ni.appendChild(newdiv);
}

function removeQuizQuestion(divNum)
{
	var d = document.getElementById('quizQuestions');
	var olddiv = document.getElementById(divNum);
	d.removeChild(olddiv);
}

function addQuizResult()
{
	var ni = document.getElementById('quizResults');
	var numi = document.getElementById('noOfResults');
	var num = (document.getElementById("noOfResults").value -1)+ 2;
	numi.value = num;
	var divIdName = "result"+num;
	var newdiv = document.createElement('div');
	newdiv.setAttribute("id",divIdName);
	newdiv.setAttribute("class", "qResult");
	newdiv.innerHTML = "Otsikko: <input type=\"text\" name=\"rOtsikko[]\" value=\"\" /> Pistem&auml;&auml;r&auml;st&auml;: <input type=\"text\" size=\"3\" name=\"rRaja1[]\" value=\"\" /> Pistem&auml;&auml;r&auml;&auml;n: <input type=\"text\" size=\"3\" name=\"rRaja2[]\" value=\"\" /><br />Kuvaus:<br /><textarea name=\"rKuvaus[]\" rows=\"3\" cols=\"60\"></textarea></p> <a href=\"javascript:;\" onclick=\"removeQuizResult(\'"+divIdName+"\')\">Poista kuvaus</a>";
	ni.appendChild(newdiv);
}

function removeQuizResult(divNum)
{
	var d = document.getElementById('quizResults');
	var olddiv = document.getElementById(divNum);
	d.removeChild(olddiv);
}


/*
        Julkaisu ei voi päättyä ennen kuin se alkaakaan
        --------------------------------------------------
*/

function makeTwoChars(inp) {
        return String(inp).length < 2 ? "0" + inp : inp;
}

function initialiseDatePickers() {
        // Attempt to grab the datePicker objects
        var sd = datePickerController.datePickers["julkaisu_alkaa"];
        var ed = datePickerController.datePickers["julkaisu_paattyy"];
        
        // For Internet Explorer: If they are not created then call this function 500 milliseconds later
        if(!sd || !ed) {
                setTimeout("initialiseDatePickers()", 200);
                return;
        }
        
        // Reset the low ranges to be today for both the datePickers
        var today = new Date();
        today = String(today.getFullYear()) + makeTwoChars(today.getMonth()+1) + makeTwoChars(today.getDate());

        sd.setRangeLow( today );
        ed.setRangeLow( today );
        
        // Clear any old values from the inputs (that might be cached by the browser after a page reload)
        document.getElementById("julkaisu_alkaa").value = "";
        document.getElementById("julkaisu_paattyy").value = "";

        // Add the onchange event handler to the start date input
        document.getElementById("julkaisu_alkaa").onchange = setReservationDates;
}
function setReservationDates(e) {
        // Check the associated datePicker object is available (be safe)
        if(!("julkaisu_alkaa" in datePickerController.datePickers)) {
                return;
        }
        
        // Check the value of the input is a date of the correct format
        var dt = datePickerController.dateFormat(this.value, datePickerController.datePickers["julkaisu_alkaa"].format.charAt(0) == "m");
        
        // If the input's value cannot be parsed as a valid date then return
        if(dt == 0) return;

        // Grab the value set within the endDate input and parse it using the dateFormat method
        // N.B: The second parameter to the dateFormat function, if TRUE, tells the function to favour the m-d-y date format
        var edv = datePickerController.dateFormat(document.getElementById("julkaisu_paattyy").value, datePickerController.datePickers["julkaisu_paattyy"].format.charAt(0) == "m");

        // Grab the end date datePicker Objects
        var ed = datePickerController.datePickers["julkaisu_paattyy"];

        ed.setRangeLow( dt );
        
        // If theres a value already present within the end date input and it's smaller than the start date
        // then clear the end date value
        if(edv < dt) {
                document.getElementById("julkaisu_paattyy").value = "";
        }
}

datePickerController.addEvent(window, 'load', initialiseDatePickers);



/*
	Julkaisu voi olla joko toistaiseksi voimassa, tai sitten aikavälillä - ei molemmilla
	------------------------------------------------------------------------------------
*/

function julkaisussaValinta()
{
	var julkCheck = document.getElementById("julkaisussa_check");
	var julkAlk   = document.getElementById("julkaisu_alkaa");
	var julkAlkKlo = document.getElementById("julkaisu_alkaa_kello");
	var julkPaat  = document.getElementById("julkaisu_paattyy");
	var julkPaatKlo = document.getElementById("julkaisu_paattyy_kello");
	if(julkCheck.checked == true)
	{
		julkAlk.disabled = true;
		julkAlkKlo.disabled = true;
		julkPaat.disabled = true;
		julkPaatKlo.disabled = true;
	}
		else if(julkCheck.checked == false)
	{
		julkAlk.disabled = false;
		julkAlkKlo.disabled = false;
		julkPaat.disabled = false;
		julkPaatKlo.disabled = false;
	}
}

/*
	Kommenttien esikatselu
	----------------------
*/

function esikNimi() {
	var txt = document.getElementById('uv-name').value;
	if(txt.length > 0 && document.getElementById('showPreview').checked)
		document.getElementById('esikNimi').innerHTML = txt + ' (Esikatselu)';
	else
		document.getElementById('esikNimi').innerHTML = 'Tuntematon (Esikatselu)';
}

function esikViesti() {
	var txt = document.getElementById('uv-message').value;
	if(txt.length > 0 && document.getElementById('showPreview').checked)
		document.getElementById('esikViesti').innerHTML = txt;
	else
		document.getElementById('esikViesti').innerHTML = 'Viestisi';
}

function ieFix(kohde, tila) {
	var bN=navigator.appName;
	if(tila == 'fokus' && bN=="Microsoft Internet Explorer") {
		document.getElementById(kohde).className = 'ie-searchform-focus';
	} else if (tila == 'blur' && bN=="Microsoft Internet Explorer") {
			document.getElementById(kohde).className = '';
	} else if (tila == 'hover' && bN=="Microsoft Internet Explorer") {
		if(document.getElementById(kohde).className != 'ie-searchform-focus')
			document.getElementById(kohde).className = 'ie-searchform-hover';
	} else if (tila == 'exit' && bN=="Microsoft Internet Explorer") {
		if(document.getElementById(kohde).className != 'ie-searchform-focus')
			document.getElementById(kohde).className = '';
	}
}

function hloValinnatPos(obj, sender) { //Etsitään eventin aiheuttanut objekti
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	if(sender == 'x')
		return curleft;
	if(sender == 'y')
		return curtop;
	else
		return 0;
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

addLoadEvent(function() {
/* more code to run on page load */
    var node_list = document.getElementsByTagName('input');
    for (var i = 0; i < node_list.length; i++) {
	   	var node = node_list[i];
    	node.className = "inputstyles";
		
		/*
		node.onmouseover = function() {
			node.className = "iputstyles_hover";
		}
		node.onmouseout = function() {
			node.className = "inputstyles";
		}
		node.onfocus = function() {
			node.className = "inputstyles_focus";
		}
		node.onblur = function() {
			node.className = "inputstyles";
		}
		*/
    }
	var area_list = document.getElementsByTagName('textarea');
	for (var i = 0; i < area_list.length; i++) {
	   	var arr = area_list[i];
    	arr.className = "inputstyles";
	}
});


function hloValinnat(obj)
{
	document.getElementById('kayttajaValikko').style.top = hloValinnatPos(obj, 'y') + 14 + 'px';
	document.getElementById('kayttajaValikko').style.left = hloValinnatPos(obj, 'x') + 'px';
	document.getElementById('kayttajaValikko').style.display = 'block';
}

/************************************************************************************************************
	(C) www.dhtmlgoodies.com, October 2005
	
	This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.	
	
	Terms of use:
	You are free to use this script as long as the copyright message is kept intact.
	
	Thank you!
	
	www.dhtmlgoodies.com
	Alf Magne Kalleland
	
	************************************************************************************************************/	
	// You can modify these three values
	var slideshow2_noFading = false;	// Just normal show/hide without fading ?
	var slideshow2_timeBetweenSlides = 2000;	// Amount of time between each image(1000 = 1 second)
	var slideshow2_fadingSpeed = 50;	// Speed of fading
	
	
	/* Don't change any of these values */
	var slideshow2_galleryHeigh;	// Height of galery	
	var slideshow2_galleryContainer;	// Reference to the gallery div
	var slideshow2_galleryWidth;	// Width of gallery	
	var slideshow2_slideIndex = -1;	// Index of current image shown
	var slideshow2_slideIndexNext = false;	// Index of next image shown
	var slideshow2_imageDivs = new Array();	// Array of image divs(Created dynamically)
	var slideshow2_currentOpacity = 100;	// Initial opacity
	var slideshow2_imagesInGallery = false;	// Number of images in gallery
	
	function getGalleryImageSize(imageIndex)
	{
		if(imageIndex==slideshow2_imagesInGallery){			
			showGallery();
		}else{
			var imgObj = document.getElementById('galleryImage' + imageIndex);
			var imgWidth = imgObj.width;
			var imgHeight = imgObj.height;
			if(imgWidth>50){						
				var tmpDiv = document.createElement('DIV');
				tmpDiv.id = 'galleryDiv' + imageIndex;
				tmpDiv.style.visibility = 'hidden';
				tmpDiv.className='imageInGallery';
				slideshow2_galleryContainer.appendChild(tmpDiv);
				tmpDiv.appendChild(imgObj);
				imgObj.style.left = Math.round((slideshow2_galleryWidth - imgWidth)/2)  + "px";
				imgObj.style.top = Math.round((slideshow2_galleryHeight - imgHeight)/2)  + "px";
				tmpDiv.style.visibility = 'hidden';
				slideshow2_imageDivs.push(tmpDiv);
				imageIndex++;
				getGalleryImageSize(imageIndex);
			}else{
				setTimeout('getGalleryImageSize(' + imageIndex + ')',10);
			}
		}		
	}
	
	function showGallery()
	{
		if(slideshow2_slideIndex==-1)slideshow2_slideIndex=0; else slideshow2_slideIndex++;	// Index of next image to show
		if(slideshow2_slideIndex==slideshow2_imageDivs.length)slideshow2_slideIndex=0;
		slideshow2_slideIndexNext = slideshow2_slideIndex+1;	// Index of the next next image
		if(slideshow2_slideIndexNext==slideshow2_imageDivs.length)slideshow2_slideIndexNext = 0;
		
		slideshow2_currentOpacity=100;	// Reset current opacity

		// Displaying image divs
		slideshow2_imageDivs[slideshow2_slideIndex].style.visibility = 'visible';
		if(navigator.userAgent.indexOf('Opera')<0){
			slideshow2_imageDivs[slideshow2_slideIndexNext].style.visibility = 'visible';
		}
		
		
		if(document.all){	// IE rules
			slideshow2_imageDivs[slideshow2_slideIndex].style.filter = 'alpha(opacity=100)';
			slideshow2_imageDivs[slideshow2_slideIndexNext].style.filter = 'alpha(opacity=1)';
		}else{
			slideshow2_imageDivs[slideshow2_slideIndex].style.opacity = 0.99;	// Can't use 1 and 0 because of screen flickering in FF
			slideshow2_imageDivs[slideshow2_slideIndexNext].style.opacity = 0.01;
		}		
		

		setTimeout('revealImage()',slideshow2_timeBetweenSlides);		
	}
	
	function revealImage()
	{
		if(slideshow2_noFading){
			slideshow2_imageDivs[slideshow2_slideIndex].style.visibility = 'hidden';
			showGallery();
			return;
		}
		slideshow2_currentOpacity--;
		if(document.all){
			slideshow2_imageDivs[slideshow2_slideIndex].style.filter = 'alpha(opacity='+slideshow2_currentOpacity+')';
			slideshow2_imageDivs[slideshow2_slideIndexNext].style.filter = 'alpha(opacity='+(100-slideshow2_currentOpacity)+')';
		}else{
			slideshow2_imageDivs[slideshow2_slideIndex].style.opacity = Math.max(0.01,slideshow2_currentOpacity/100);	// Can't use 1 and 0 because of screen flickering in FF
			slideshow2_imageDivs[slideshow2_slideIndexNext].style.opacity = Math.min(0.99,(1 - (slideshow2_currentOpacity/100)));
		}
		if(slideshow2_currentOpacity>0){
			setTimeout('revealImage()',slideshow2_fadingSpeed);
		}else{
			slideshow2_imageDivs[slideshow2_slideIndex].style.visibility = 'hidden';			
			showGallery();
		}
	}
	
	function initImageGallery()
	{
		slideshow2_galleryContainer = document.getElementById('imageSlideshowHolder');
		slideshow2_galleryWidth = slideshow2_galleryContainer.clientWidth;
		slideshow2_galleryHeight = slideshow2_galleryContainer.clientHeight;
		galleryImgArray = slideshow2_galleryContainer.getElementsByTagName('IMG');
		for(var no=0;no<galleryImgArray.length;no++){
			galleryImgArray[no].id = 'galleryImage' + no;
		}
		slideshow2_imagesInGallery = galleryImgArray.length;
		getGalleryImageSize(0);		
		
	}