var xhrYear = createXHR();

function getYear(model){
    if(xhrYear){
        try{
            xhrYear.open("GET","./getYearType.php?type="+model,true);
            xhrYear.onreadystatechange = callBackYear;
            xhrYear.send(null);
            resetElement(document.getElementById('sel3'));
        }catch(e){
            alert("Nelze se připojik k serveru:\n" + e.toString());
        }
    }else{
        alert("Funkce \"precitSoubor()\": chybí objekt XMLHttpRequest");
    }
}
function callBackYear(){
    if(xhrYear.readyState == 4){
        if(xhrYear.status == 200){
            try{
                var XMLRes = xhrYear.responseXML;
                //zachycení chyb IE a Opery
                if(!XMLRes || !XMLRes.documentElement){
                    throw("Chybná struktura XML:\n" + xhrYear.responseText);
                }
                //zachycení chyb ohnivé lišky :-)
                var rootNodeName = XMLRes.documentElement.nodeName;
                if(rootNodeName == "parsererror"){
                    throw("Chybná struktura XML:\n" + xhrYear.responseText);
                }
                //čtu dokument, jelikož je vše ok :-)

                xmlRoot = XMLRes.documentElement;
                id = xmlRoot.getElementsByTagName("id");
                nameE = xmlRoot.getElementsByTagName("name");

                //sem budem ukládat výstup

                //vytvoříme obsah
                var options = document.getElementById("sel3").options;

                for(var i = 0; i < id.length; i++){
                        newOpt = document.createElement('option');
                        newOpt.text = nameE.item(i).firstChild.data;
                        newOpt.value = id.item(i).firstChild.data;
                        options.add(newOpt);
                }

            }catch(e){
                alert("Chyba při čtení odpovědi:" + e.toString());
            }
        }else{
            alert("Požadavek HTTP není v pořádku.")
        }
    }
}
