function laatikkoOver(el,luokka){
	document.getElementById(el).className=luokka;
}

function laatikkoOut(el,luokka){
	document.getElementById(el).className=luokka;
}

function goTo(url){
	window.location = url;
}

function selectNro(id){

	var kuvaidt = new Array();
	kuvaidt[0] = 1;
	kuvaidt[1] = 2;
	kuvaidt[2] = 3;
	kuvaidt[3] = 4;
	kuvaidt[4] = 5;

	for(var i=0; i<5; i++){
		if(kuvaidt[i]==id){
			document.getElementById('nro_id'+kuvaidt[i]).className = "nro2";
			document.getElementById("img_nro").value = parseFloat(i+1);
		}
		else{
			document.getElementById('nro_id'+kuvaidt[i]).className = "nro";
		}
	}
}

function setText(el,el2,count){
	document.getElementById(el).innerHTML = document.getElementById(el2+''+count).value;
}

function showMenu(el){
	document.getElementById(el).style.display="block";
}

function hideMenu(el){
	document.getElementById(el).style.display="none";
}

function showMenuColor(el){
	document.getElementById(el).style.backgroundColor="#41a253";
}

function hideMenuColor(el){
	document.getElementById(el).style.backgroundColor="#007646";
}

function haeUusiKoko(url,el){
	var ajaxRequest;  // The variable that makes Ajax possible!
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				return false;
			}
		}
	}
	//palautetaan uusi leveys ja korkeus stringinä
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			//asetetaan urli
			document.getElementById(el).src = url;
			var koko = ajaxRequest.responseText.split('#');
			document.getElementById(el).width = koko[0];
			document.getElementById(el).height = koko[1];
		}
	}

	var queryString = "?urli=" + url + "&r="+Math.round(Math.random() * 10000);
	ajaxRequest.open("GET", "http://www.kotimokki.fi/kuvakoko.php" + queryString, true);
	ajaxRequest.send(null); 
}

function setImage(el,url){

	//haetaan uuden kuvan koko ajaxilla, ettei tule vääristyneitä kuvia
	haeUusiKoko(url,el);
}

function openBigImage(el){
	var image = document.getElementById(el).src;
	window.open(image,"kuva","width=900,height=700");
}

function openBigImages(id){
	window.open("http://www.kotimokki.fi/isot_kuvat.php?id="+id,"isot_kuvat","width=900,height=700");
}

function naytaLomake(){
	document.getElementById("lomakediv").style.display="block";
     	//document.getElementById("nimi").focus();
	window.location.hash="LOMAKE"; 
}

function piilotaLomake(){
	document.getElementById("lomakediv").style.display="none";
}

function checkFieldsValue(radioObj){
	
	//haetaan asetettu arvo	
	var radioLength = radioObj.length;
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}

	return "";
}

function tarkistaLomake(){

	if(checkFieldsValue(document.lomake.elements['yhteydenotto'])==""){
		alert("Valitse yhteydenoton aihe");
		return false;
	}
	else if(document.lomake.nimi.value==""){
		alert("Nimi on pakollinen");
		return false;
	}
	else if(document.lomake.sahkoposti.value=="" && document.lomake.puhelin.value==""){
		alert("Syötä vähintään toinen: sähköpostiosoite tai puhelinnumero");
		return false;
	}
	else if(document.lomake.viesti.value==""){
		alert("Viesti on pakollinen");
		return false;
	}

	return true;
}

function checkForm(){

	if(document.lomake.nimi.value==""){
		alert("Nimi on pakollinen");
		return false;
	}
	else if(document.lomake.sahkoposti.value=="" && document.lomake.puhelin.value==""){
		alert("Syötä vähintään toinen: sähköpostiosoite tai puhelinnumero");
		return false;
	}
	else if(document.lomake.viesti.value==""){
		alert("Viesti on pakollinen");
		return false;
	}

	return true;
}

function piilotaIkkuna(el){
	
	document.getElementById(el).style.display="none";
}

//radio buttonien arvojen tarkistus
function checkRadioValue(radioObj){
	
	//haetaan asetettu arvo	
	var radioLength = radioObj.length;
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}

	return "";
}

function checkForm2(){

	//tarkistetaan vastaukset
	if(checkRadioValue(document.lomake.vastaus1)==""){
		alert("Anna arvosana sivuston yleisilmeelle");
		return false;
	}
	else if(checkRadioValue(document.lomake.vastaus2)==""){
		alert("Anna arvosana sivuston toimivuudelle");
		return false;
	}
	else if(checkRadioValue(document.lomake.vastaus3)==""){
		alert("Anna arvosana kiinnostavuudelle");
		return false;
	}
	else if(checkRadioValue(document.lomake.vastaus4)==""){
		alert("Anna arvosana kohdehaun toimivuudelle");
		return false;
	}
	else if(document.lomake.nimi.value==""){ //tarkistetaan yhteystiedot
		alert("Nimi on pakollinen");
		return false;
	}
	else if(document.lomake.osoite.value==""){
		alert("Osoite on pakollinen");
		return false;
	}
	else if(document.lomake.postinumero.value==""){
		alert("Postinumero on pakollinen");
		return false;
	}
	else if(document.lomake.postitoimipaikka.value==""){
		alert("Postitoimipaikka on pakollinen");
		return false;
	}
	else if(document.lomake.sahkopostiosoite.value=="" && document.lomake.puhelinnumero.value==""){
		alert("Syötä vähintään toinen: sähköpostiosoite tai puhelinnumero");
		return false;
	}

	return true;
}

function tarkistaYhteys(){	
	var ajaxRequest;  // The variable that makes Ajax possible!
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Selaimessasi tapahtui virhe!");
				return false;
			}
		}
	}

	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){

			if (ajaxRequest.status==200){	
				window.location='http://www.kotimokki.fi/ikkuna5.php';
    			}
  			else{
				return false;    				
    			}
		}
	}
	var queryString = "?r="+Math.round(Math.random() * 10000);
	ajaxRequest.open("GET", "http://www.kotimokki.fi/conn.php" + queryString, true);
	ajaxRequest.send(null); 
}

function tarkistaYhteys2(){	
	var ajaxRequest;  // The variable that makes Ajax possible!
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Selaimessasi tapahtui virhe!");
				return false;
			}
		}
	}

	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){

			if (ajaxRequest.status==200){	
				window.location='http://www.kotimokki.fi/ikkuna5_demo.php';
    			}
  			else{
				return false;    				
    			}
		}
	}
	var queryString = "?r="+Math.round(Math.random() * 10000);
	ajaxRequest.open("GET", "http://www.kotimokki.fi/conn.php" + queryString, true);
	ajaxRequest.send(null); 
}
