//globale Instanz von XMLHttpRequest
var xmlHttp = false;

//XMLHttpRequest-Instanz erstellen
//... für Internet Explorer
try {
    xmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
    try {
        xmlHttp  = new ActiveXObject("Microsoft.XMLHTTP");
    } catch(e) {
        xmlHttp  = false;
    }
}
//... für Mozilla, Opera, Safari usw.
if (!xmlHttp  && typeof XMLHttpRequest != 'undefined') {
    xmlHttp = new XMLHttpRequest();
}
 
//aktuelle Daten laden
loadUmfrageData();


//Wenn Umfrage vorhanden, Umfragebox anzeigen
window.setTimeout("checkumfrageexist()", 200);

function checkumfrageexist()
{
	if(document.getElementById("umfragebox").innerHTML == ""){
		document.getElementById('b_titel_right_umfrage').style.display = 'none';
		document.getElementById('b_right_umfrage').style.display = 'none';
	}
	else{
		//foo
	}
}
	
function loadUmfrageData()
{
 if (xmlHttp) {
     xmlHttp.open('GET', 'modules/umfrage/controller.php?getdata=true', true);
     xmlHttp.onreadystatechange = function () {
         if (xmlHttp.readyState == 4) {
             document.getElementById("umfragebox").innerHTML = xmlHttp.responseText;
         }
     };
     xmlHttp.send(null);
 }
}


function saveUmfrageData()
{
	var radioantwort = checkradio(document.frmumfrage.umfrageantwort);
	var checkradioantwort = "t"+radioantwort;
	if(checkradioantwort != "tundefined"){
		if (xmlHttp) {
			xmlHttp.open('GET', 'modules/umfrage/controller.php?savedata=true&antwort='+radioantwort);
			xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			xmlHttp.send('antwort='+radioantwort);
		}
		document.getElementById("umfragebox").innerHTML = "Danke f&uuml;r deine Stimme! =) Hinweis: Pro Umfrage darfst du nur eine Stimme abgeben.<hr style='height: 3px;' />"+document.getElementById("umfragebox").innerHTML;
	}
	else{
		//alert("Fehler");
		document.getElementById("umfragebox").innerHTML = "Bitte w&auml;hle eine Antwort aus!<hr style='height: 3px;' />"+document.getElementById("umfragebox").innerHTML;
	}
}

function getResultatData()
{
 if (xmlHttp) {
     xmlHttp.open('GET', 'modules/umfrage/controller.php?getresultat=true', true);
     xmlHttp.onreadystatechange = function () {
         if (xmlHttp.readyState == 4) {
             document.getElementById("umfragebox").innerHTML = xmlHttp.responseText;
         }
     };
     xmlHttp.send(null);
 }
}

function checkradio(feld){
	for (i=0; i < feld.length; i++){
		if(feld[i].checked == true){
			return feld[i].value;
		}
	}
} 
