function updateBrandDropdown(size){
    new Ajax.Updater('brands', '/ajax_requests/get_brands_for_brasize.php', {
	parameters: { brasize: size }
    });        
}

function updateStyleDropdown(brand_id){
    new Ajax.Updater('id1', '/ajax_requests/get_styles_for_brands.php', {
	parameters: { brand: brand_id }
    });        
}

function updateStyleDropdownForUnderwear(brand_id,style_id,size_id){
    new Ajax.Updater('id1', '/ajax_requests/get_substyles_for_brands.php?brand='+brand_id+'&id='+style_id+'&alias_id='+size_id);
}

function updateSizeDropdownForBrand(brand_id,size_id){
    new Ajax.Updater('id2', '/ajax_requests/get_sizes_for_brands.php?brand='+brand_id+'&alias_id='+size_id);
}

function updateSizeDropdownForBrandAndStyle(brand_id,style_id,size_id){
    new Ajax.Updater('id2', '/ajax_requests/get_sizes_for_brands.php?brand='+brand_id+'&id='+style_id+'&alias_id='+size_id);
}

function updateBrandDropdownForStyleAndSize(brand_id,style_id,size_id){
    new Ajax.Updater('brand', '/ajax_requests/get_brands_for_styles.php?brand='+brand_id+'&id='+style_id+'&alias_id='+size_id);
}

var sections_heights = new Array();

function collapse(title){
    var button = $$('#selection_box_'+title+' h2 a')[0];
    button.onclick = function(){return false};
    var section = $('selection_box_'+title);
    if(!sections_heights[title]){
	sections_heights[title] = section.getHeight();
    }
    new Effect.Scale(section, 100 * 25 / sections_heights[title], {
	scaleX: false, 
	scaleContent: false,
	afterFinish:function(){
	    button.className='button expand';
	    button.onclick = function(){expand(title); return false};
	}
    });
    var cookie = Cookie.getCookie('catalog_sections');
    if(!cookie || cookie.indexOf(title) == -1){
	cookie = (cookie ? cookie : '') + '|' + title;	
    }
    Cookie.setCookie('catalog_sections', cookie, null, '/');
}

function expand(title){
    var button = $$('#selection_box_'+title+' h2 a')[0];
    button.onclick = function(){return false};
    var section = $('selection_box_'+title);
    new Effect.Scale(section, 100 * sections_heights[title] / 25, {
	scaleX: false, 
	scaleContent: false,
	afterFinish:function(){
	    button.className='button collapse';
	    button.onclick = function(){collapse(title); return false;};
	}
    });
    var cookie = Cookie.getCookie('catalog_sections');
    if(cookie.indexOf(title) != -1){
	cookie = cookie.replace('|' + title, '');
    }
    Cookie.setCookie('catalog_sections', cookie,null, '/');
}

function hideSelectionBox(title){
    var cookie = Cookie.getCookie('catalog_sections');
    if(cookie && cookie.indexOf(title) != -1){
	section = $('selection_box_'+title);
	sections_heights[title] = section.getHeight();
	section.style.height = '25px';
	button = $$('#selection_box_'+title+' h2 a')[0];
	button.className='button expand';
	button.onclick = function(){expand(title); return false;};
    }
}

function seeAllSection(title){
    $('see_all_'+title).style.display = 'block';
    $('see_limited_link_'+title).style.display = 'block';
    $('see_all_link_'+title).style.display = 'none';
    sections_heights[title] = null;
    $('selection_box_'+title).style.height = '';
}

function seeLimitedSection(title){
    $('see_all_'+title).style.display = 'none';
    $('see_limited_link_'+title).style.display = 'none';
    $('see_all_link_'+title).style.display = 'block';
    sections_heights[title] = null;
    $('selection_box_'+title).style.height = '';
}
