﻿var currentselection = "";

function updatesubcatlist() {
    var data = "";

    try {
        data = "&id=" + $j('#sfddlMainCategorie').val();
        
        
        var url = '/shop.aspx?action=getsubcategories' + data;

        new Ajax.Request(url, {
            method: 'get',
            onSuccess: function(transport) {
                
                if (transport.responseText.length == 0) {
                    $('sfdivsubcategory').hide();
                }
                else {
                    $('sfdivsubcategory').show();
                    $('sfdivsubcategory').update(transport.responseText);
                }
                searchforit();
            }
        });
    }
    catch (e) {
        if (debug) alert(e.message);
    }
}
function uncheckselectie(divid) {
    $j('#' + divid + ' input:checked').each(function() {
        this.checked = false;
    });    
}
function searchforit() {
    var data = "";
       
    try {
        
        currentselection = "";
        
        if ($j('#sfddlMainCategorie').val()) {
            if ($j('#sfddlMainCategorie').val().length > 0) {
                data += "&mc=" + $j('#sfddlMainCategorie').val();
                currentselection += "<a href=\"javascript:void(0);\" class=\"purpleLink\" onclick=\"$j('#sfdivmaincategory > select').val('');$j('#sfdivsubcategory > select').val('');searchforit();\">" + $j("#sfddlMainCategorie option:selected").text() + "</a>,&nbsp;";
            }
        }

        if ($j('#sfddlSubCategorie').val()) {
            if ($j('#sfddlSubCategorie').val().length > 0) {
                data += "&sc=" + $j('#sfddlSubCategorie').val();
                currentselection += "<a href=\"javascript:void(0);\" class=\"purpleLink\" onclick=\"$j('#sfdivsubcategory > select').val('');searchforit();\">" + $j("#sfddlSubCategorie option:selected").text() + "</a>,&nbsp;";                    
            }
        }

        if ($j('#sfdivprices > select').val()) {
            if ($j('#sfdivprices > select').val().length > 0) {
                data += "&pr=" + $j('#sfdivprices > select option:selected').val();
                currentselection += "<a href=\"javascript:void(0);\" class=\"purpleLink\" onclick=\"$j('#sfdivprices > select').val('');searchforit();\">" + $j('#sfdivprices > select option:selected').text() + "</a>,&nbsp;";                    
            }
        }

        if ($j('#sfdivcolor > select option:selected').val()) {
            if ($j('#sfdivcolor > select').val().length > 0) {
                data += "&kl=" + $j('#sfdivcolor > select option:selected').val();
                currentselection += "<a href=\"javascript:void(0);\" class=\"purpleLink\" onclick=\"$j('#sfdivcolor > select').val('');searchforit();\">" + $j('#sfdivcolor > select option:selected').text() + "</a>,&nbsp;";                    
            }
        }

        var size = [];
        $j('#sfdivsize input:checked').each(function() {
            size.push(this.value);
        });
        if (size.length > 0) {
            data += "&sz=" + size;
            currentselection += "<a href=\"javascript:void(0);\" class=\"purpleLink\" onclick=\"uncheckselectie('sfdivsize');searchforit();\">maat selectie</a>,&nbsp;";                    
        }

        var brasize = [];
        $j('#sfdivcupsize input:checked').each(function() {
            brasize.push(this.value);
        });
        if (brasize.length > 0) {
            data += "&bsz=" + brasize;
            currentselection += "<a href=\"javascript:void(0);\" class=\"purpleLink\" onclick=\"uncheckselectie('sfdivcupsize');searchforit();\">cupmaat selectie</a>,&nbsp;"; 
        }

        var braomvangsize = [];
        $j('#sfdivBraSize input:checked').each(function() {
            braomvangsize.push(this.value);
        });
        if (braomvangsize.length > 0) {
            data += "&bosz=" + braomvangsize;
            currentselection += "<a href=\"javascript:void(0);\" class=\"purpleLink\" onclick=\"uncheckselectie('sfdivBraSize');searchforit();\">BH-Omvang selectie</a>,&nbsp;"; 
        }
        var shoesize = [];
        $j('#divshoesize input:checked').each(function() {
            shoesize.push(this.value);
        });
        if (shoesize.length > 0) {
            data += "&shsz=" + shoesize;
            currentselection += "<a href=\"javascript:void(0);\" class=\"purpleLink\" onclick=\"uncheckselectie('divshoesize');searchforit();\">Schoenmaat selectie</a>,&nbsp;";
        }
        if (data.length > 0)
            sfUpdateContent(data);
    }
    catch (e) {
        if (debug) alert(e.message);
    }    
}

function ShowProgress() {
    if (typeof jQuery('#content-rt-filter') != "undefined" && typeof jQuery('#product_filters') != "undefined" && jQuery('#content-rt-filter').size() > 0 && jQuery('#product_filters').size() > 0) {
        jQuery('#content-rt-filter_loader').show();
        $('content-rt-filter').update("");
    }
}

function HideProgress() {
    if (typeof jQuery('#content-rt-filter') != "undefined" && typeof jQuery('#product_filters') != "undefined" && jQuery('#content-rt-filter').size() > 0 && jQuery('#product_filters').size() > 0) {
        jQuery('#content-rt-filter_loader').hide();
    }
}

function sfUpdateContent(data) {
    try {
        ShowProgress();    
        var url = '/shop.aspx?action=searchforit&' + data;
        var output;
        var iskledingcategorie = false;

        new Ajax.Request(url, {
            method: 'get',
            onLoading: function() {
            },
            onLoaded: function() {
            },
            onSuccess: function(transport) {
                HideProgress();
                if (transport.responseText) {
                    if (transport.responseText.length > 0) {
                        iskledingcategorie = (transport.responseText.substring(transport.responseText.length - 1) == "1");
                        output = transport.responseText.substring(0, transport.responseText.length - 1);
                    }
                }
                if (typeof jQuery('#content-rt-filter') != "undefined" && typeof jQuery('#product_filters') != "undefined" && jQuery('#content-rt-filter').size() > 0 && jQuery('#product_filters').size() > 0) {
                    $('content-rt-filter').update(output);
                } else {
                    $('content-rt').update(output);
                }
                if (currentselection.length > 7) {
                    currentselection = currentselection.substring(0, currentselection.length - 7);
                }
                $('divcurrentselectie').update("Verwijder een van de volgende zoek criteria:&nbsp;" + currentselection);
                $('resultaat_zoekfilter').update("Zoekfilter:&nbsp;" + currentselection);
            }
        });
    }
    catch (e) {
        if (debug) alert(e.message);
    }
}


$j(document).ready(function() {
if (typeof $j('#sfddlMainCategorie') != "undefined" && typeof $j('#sfddlMainCategorie').val() != "undefined") {
        if ($j('#sfddlMainCategorie').val().length == 0)
            $j('#sfdivsubcategory').hide();
    }
});
