var xmlhttp;

function posljiPosto(zanimanje, ime, email, telefon, sporocilo) {
        xmlhttp=GetXmlHttpObject();

	if (xmlhttp==null) {
  		alert ("Vaš brskalnik ne podpira HTTP zahtevkov");
  		return;
  	}
        
        var url = "posiljanje.php";
	url+="?zanimanje="+zanimanje;
	url+="&ime="+ime;
	url+="&email="+email;
        url+="&telefon="+telefon;
        url+="&sporocilo="+sporocilo;
        
	xmlhttp.onreadystatechange=stateChanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);

}

function stateChanged() {
    	if (xmlhttp.readyState>0 && xmlhttp.readyState<4) {
		document.getElementById("obvestilo").innerHTML="Pošiljanje ...";
                document.kontakt.poslji.disabled = true;
	}
	if (xmlhttp.readyState==4) {
            if(xmlhttp.responseText == "Poslano!") {
                document.getElementById("obvestilo").innerHTML="Poslano!";
                document.kontakt.ime.value = "";
                document.kontakt.mail.value = "";
                document.kontakt.telefon.value = "";
                document.kontakt.sporocilo.value = "";
            } else {
                document.getElementById("obvestilo").innerHTML="<span style='color:red'>Napaka pri pošiljanju.</span><br />Prosimo, izpolnite vsa polja.";             
            }
            document.kontakt.poslji.disabled = false;
	}
}

function GetXmlHttpObject() {
	if (window.XMLHttpRequest) {
  		// IE7+, Firefox, Chrome, Opera, Safari
  		return new XMLHttpRequest();
	}
	if (window.ActiveXObject) {
  		// IE6, IE5
  		return new ActiveXObject("Microsoft.XMLHTTP");
  	}
	return null;
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}