﻿//INGREDIENTS
jQuery("#brand-family").ready(function() {
    pageToPost = 'handlers/brandsfamily.ashx';
    //alert('family loaded new');
    jQuery('#brand-family option').remove();
    familyUrl = 'handlers/brandsfamily.ashx';
    //    jQuery('#brand-style').load(styleUrl).attr("disabled", false);

    jQuery("#brand-family").load(familyUrl, function() {
        jQuery('#brand-family').attr("disabled", false);
        styleUrl = 'handlers/brandsfamily.ashx?key=' + jQuery('#brand-family').val();
        //alert('families loaded - ' + styleUrl);
        
        jQuery("#brand-style").load(styleUrl, function() {
            jQuery('#brand-style').attr("disabled", false);
        });

    });

    /*
    jQuery.getJSON(pageToPost,
    function(data) {
    jQuery('#brand-family option').remove();
    jQuery.each(data.items, function(i, item) {
    output = '<option value="' + item.code.c + '">' + item.name.n + '</option>';
    jQuery('#brand-family').append(output).attr("disabled", false);
    });
    pageToPost = 'handlers/brandsfamily.ashx?key=' + jQuery('#brand-family').val();
    jQuery.getJSON(pageToPost,
    function(data) {
    jQuery('#brand-style option').remove();
    jQuery.each(data.items, function(i, item) {
    output = '<option id="' + item.code.c + '">' + item.name.n + '</option>';
    jQuery('#brand-style').append(output).attr("disabled", false);
    //alert(output);
    });
    });
    });
    */
});

jQuery("select#brand-family").change(function() {
    // check input ($(this).val()) for validity here
    //alert('brand family - ' + jQuery(this).val());
        styleUrl = 'handlers/brandsfamily.ashx?key=' + jQuery('#brand-family').val();
        //alert('families changed - ' + styleUrl);
        jQuery("#brand-style").load(styleUrl, function() {
            jQuery('#brand-style').attr("disabled", false);
        });

});
/*
jQuery("select#brand-style").change(function() {
// check input ($(this).val()) for validity here
//alert('brand style - ' + jQuery(this).val());
});
*/
jQuery(".ingredient-select .submit-btn").click(function() {
    //alert('brand style - ' + jQuery('#brand-style').val());
    //pageToLoad = 'handlers/brandcontent.ashx?key=' + jQuery('#brand-style').val();
    brandContentUrl = 'handlers/brandcontent.ashx?key=' + jQuery('#brand-style').val();
    //    alert('brandContentUrl - ' + brandContentUrl);
    jQuery('#ingredients-list .table-box').toggleClass('loading').removeClass('onload');
    jQuery('#ingredients-list .list-holder ul#nav').remove();
    jQuery('#ingredients-list .list-holder').load(brandContentUrl, function() {
        jQuery('#ingredients-list .table-box').toggleClass('loading').removeClass('onload');
//        alert('content loaded');
    });
});

