
// function will loop through all input tags and create
// url string from checked checkboxes

function faceted_click(el) {
    if (el.className == "auswahl") {
        el.className = "link";
    } else {
        el.className = "auswahl";

        var list_obj = document.getElementsByTagName('li');

        // loop through all collected objects
        for (i=0; i < list_obj.length; i++) {
            var type = $(list_obj[i]).readAttribute("data-type");
            // if input object is checkbox and checkbox is checked then ...

            if ((type == "parentcategory") && ((list_obj[i].readAttribute('data-url') == el.readAttribute("data-parent")) )) {
                // ... increase counter and concatenate textContent to the url string
                list_obj[i].className = "link_alle";
            }

        }

        
    }
}

function faceted_url(){
    var dealercounter = 0;  // counter for checked checkboxes
    var catcounter = 0;  // counter for checked checkboxes
    var i       = 0;  // loop variable
    var url     = ''; // final url string
    var caturl  = '';
    var dealerurl = '';

    // get a collection of objects with the specified 'input' TAGNAME
    var list_obj = document.getElementsByTagName('li');

    // loop through all collected objects
    for (i=0; i < list_obj.length; i++) {
        var type = $(list_obj[i]).readAttribute("data-type");
        // if input object is checkbox and checkbox is checked then ...

        if (((type == "category") || (type == "parentcategory")) && ((list_obj[i].className == "auswahl") || list_obj[i].className == "auswahl_alle") ) {
            // ... increase counter and concatenate textContent to the url string
            catcounter++;
            caturl = caturl + ',' + list_obj[i].readAttribute('data-url');
        }

        if (type == "dealer" && list_obj[i].className == "auswahl") {
            // ... increase counter and concatenate textContent to the url string
            dealercounter++;
            dealerurl = dealerurl + ',' + list_obj[i].readAttribute('data-url');
            $('alldealer').className = "link_alle";
        }
    }

    if (dealercounter > 0) {
        dealerurl = dealerurl.substr(1); // remove first ',' from the generated url string
        url += "/" + dealerurl;
    }

    if (catcounter > 0){
        caturl = caturl.substr(1); // remove first ',' from the generated url string
        url += "/" + caturl;
    }

    if (url == '') {
        url = "/aktionen";
    }

    this.location.href = url;
}


function faceted_parent(el) {
    if (el.className == "auswahl_alle") {
        el.className = "link_alle";
    } else {
        el.className = "auswahl_alle";
    }

    var list_obj = document.getElementsByTagName('li');
    // loop through all collected objects

    for (i=0; i < list_obj.length; i++) {
        var parent = $(list_obj[i]).readAttribute("data-parent");
        // if input object is checkbox and checkbox is checked then ...

        if (parent == el.readAttribute('data-url')) {
            // uncheck all subcats if parent is checked
            $(list_obj[i]).className = "link";
        }

    }

}

function faceted_alldealer(el) {
    if (el.className == "auswahl_alle") {
        el.className = "link_alle";
    } else {
        el.className = "auswahl_alle";

        var list_obj = document.getElementsByTagName('li');
        // loop through all collected objects

        for (i=0; i < list_obj.length; i++) {
            var type = $(list_obj[i]).readAttribute("data-type");
            // if input object is checkbox and checkbox is checked then ...

            if (type == 'dealer') {
                // uncheck all subcats if parent is checked
                $(list_obj[i]).className = "link";
            }

        }


    }

}
