function createXmlHttpRequestObject() {
    var xmlHttp;
    try {
        xmlHttp = new XMLHttpRequest();
    } catch (e) {
        var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
                                      "MSXML2.XMLHTTP.5.0",
                                      "MSXML2.XMLHTTP.4.0",
                                      "MSXML2.XMLHTTP.3.0",
                                      "MSXML2.XMLHTTP",
                                      "Microsoft.XMLHTTP");
        for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++) {
            try {
                xmlHttp = new ActiveXObject(XmlHttpVersions[i])
            } catch (e) {}
        }
    }
    if (!xmlHttp) alert("Chyba při vytváření objektu XMLHttpRequest.");
    else return xmlHttp;
}

if (!xmlHttp) var xmlHttp = createXmlHttpRequestObject();

function zmena(vila, date) {
    if (xmlHttp) {
        try {
            xmlHttp.open("GET","/wp-admin/kalendare/data/kalendarZmena.php?vila="+vila+"&date="+date,true);
            xmlHttp.onreadystatechange = kalendarZmena;
            xmlHttp.send(null);
        } catch (e) {
            alert("Chyba při odesílání požadavku.");
        }
    }
}

function kalendarZmena() {
    if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
        try {
            var response = xmlHttp.responseText;
            if (response.match('([0-9]+)\|([0-9]+)-([0-9]+)-([0-9]+)')) {
                td = document.getElementById(response.toString());
                if (td.getAttribute('class') == 'empty') cl = 'full';
                if (td.getAttribute('class') == 'full') cl = 'maybe';
                if (td.getAttribute('class') == 'maybe') cl = 'empty';
                td.setAttribute('class', cl);
            } else {
                alert("Nastala chyba na straně serveru. Zkuste to znovu.");
            }
        } catch (e) {
            alert("Chyba při čtení odpovědi serveru.");
        }
    }
}

