function searchFobia(str)
{
        var url="/functio_fobiat.php";
        url=url+"?q="+str;

        sendGETRequest(url, "fobiaLista");
}

function hide(element)
{
        document.getElementById(element).style.display = "none";
}

function show(element)
{
        document.getElementById(element).style.display = "block";
}

function insertArvostelu(id, arvo, ip)
{
        var url="/functio_arvostele.php";
        url=url+"?id="+id+"&arvo="+arvo+"&ip="+ip;

        sendGETRequest(url, "arvostele");
}

function raportoi(id, ip)
{
        var raportti = document.getElementById('raportti').value;
        if (raportti == "")
        {
                alert("Kirjoita raportti, kiitos.");
                return;
        }

        var url="/functio_raportoi.php";
        url=url+"?id="+id+"&raportti="+encodeURI(raportti)+"&ip="+ip;

        sendGETRequest(url, "raporttilomake");
}

function lisaaTarina(tulos, ip)
{
        var tarina = document.getElementById('uusitarina').value;
        if (tarina == ""){
                document.getElementById('status').innerHTML = "Tarina on tyhj&auml;.";
                return false;
        }

        var arvo = document.getElementById('varmistus').value;
        if (arvo != tulos){
                document.getElementById('status').innerHTML = "Varmistuskent&auml;n arvo on v&auml;&auml;rin.";
                return false;
        }

        var url="/functio_uusitarina.php";
        url=url+"?tarina="+encodeURI(tarina)+"&ip="+ip;

        sendGETRequest(url, "kerro_lomake");
}

function changeQuestion(change) {
	var currentId = parseInt(document.getElementById('q_id').innerHTML);
	var newId = currentId + change;
	if (newId > 0 && newId <= 15) {
		document.getElementById('q_'+currentId).style.display = "none";
		document.getElementById('q_'+newId).style.display = "block";
		document.getElementById('q_id').innerHTML = newId;
	}

	return false;
}






function sendGETRequest(url, statusElement)
{
	var xmlhttp=false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	 try {
	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
	  try {
	   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
	   xmlhttp = false;
  	 }
 	}
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	if (!xmlhttp && window.createRequest) {
		try {
			xmlhttp = window.createRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}

        if (!xmlhttp)
        {
                alert ("Browser does not support HTTP Request");
                return;
        }

        xmlhttp.open("GET",url,true);
	xmlhttp.onreadystatechange=function() {
  		if (xmlhttp.readyState==4) {
			document.getElementById(statusElement).innerHTML=xmlhttp.responseText; 
  		}
 	}
        xmlhttp.send(null);

}
