function GetXmlHttpObject() {
    if (window.XMLHttpRequest) {
        return new XMLHttpRequest();
    }
    if (window.ActiveXObject) {
        return new ActiveXObject("Microsoft.XMLHTTP");
    } else {
        alert ("Vaš brskalnik ne podpira XMLHTTP!");
    }
    return null;
}

function getSelected(elements) {
    res = 'default';
    if ('/'+elements+'/'=='/NaN/') {} else {
        for (var i = 0; i < elements.length; i++) {
            if (elements[i].checked) { res = elements[i].value; break; }
            else { res = elements[0].value; }
        }
    }
    return res;
}

function nastavi_session (key, value) {
    var xmlhttp;
    var baseURL = location.href.substring(0, location.href.indexOf("/", location.href.indexOf("//", 0)+2));
    url=baseURL+"/ajax.php?nastavi_session=1&key=" + key + "&value=" + value;
    xmlhttp=GetXmlHttpObject();
    xmlhttp.onreadystatechange = function() {
        if(xmlhttp.readyState==4) {
            return xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
}

function menjaj_majico(id_majice, id_motiva) {
    var xmlhttp;
    var baseURL = location.href.substring(0, location.href.indexOf("/", location.href.indexOf("//", 0)+2));
    var url= baseURL + "/ajax.php?menjava_majice=1&id_majice=" + id_majice + "&id_motiva=" + id_motiva;
    xmlhttp=GetXmlHttpObject();
    xmlhttp.onreadystatechange = function() {
        if(xmlhttp.readyState==4) {
            document.getElementById('body').innerHTML = xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
}

function pripravi_preview(model_id, barva, motiv_id) {
    var xmlhttp;
    var baseURL = location.href.substring(0, location.href.indexOf("/", location.href.indexOf("//", 0)+2));
    var url= baseURL + "/ajax.php?vrni_sliko=" + model_id + "&barva=" + barva + "&motiv_id=" + motiv_id;
    xmlhttp=GetXmlHttpObject();
    xmlhttp.onreadystatechange = function() {
        if(xmlhttp.readyState==4) {
            document.getElementById('majica_preview').src = '/upload/pic_preview360/' + xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
}

function kosarica_dodaj (id_motiva, kolicina, barva, velikost, id_majice) {
    var xmlhtt;
    xmlhttp=GetXmlHttpObject();
    var baseURL = location.href.substring(0, location.href.indexOf("/", location.href.indexOf("//", 0)+2));
    var url= baseURL + "/ajax.php?kosarica_dodaj=1";
    url=url+"&id_motiva=" + id_motiva + "&kolicina=" + kolicina + "&barva=" + barva + "&velikost=" + velikost + "&id_majice=" + id_majice;
    xmlhttp.onreadystatechange = function() {
        if(xmlhttp.readyState==4) {
            document.getElementById('kosaricaSide').innerHTML = xmlhttp.responseText;
            document.getElementById("kosarica_napis").removeAttribute("class");
            document.getElementById("kosarica_napis").setAttribute("class", "kosarica_napis polna");
        }
    }
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
}

