var ajax = new sack();
var globalSize = '';

// get sizes
function updateSizeSelect(size, clearance_section)
{
	document.getElementById('sizeLoader').style.display = 'inline';
	var category_id = document.getElementById('div_category_id'); // DIV ID!
	ajax.requestFile = '/product_filter_sizes.php?cid='+category_id.value+'&size='+size+'&clearance='+clearance_section;
	ajax.onCompletion = populateSizeSelect;	// Specify function that will be executed after file has been found
	ajax.runAJAX();		// Execute AJAX function
  globalSize = size;
}

function populateSizeSelect() {
	document.getElementById('sizeLoader').style.display = 'none';
	var obj = document.getElementById('size_id');
	eval(ajax.response);	// Executing the response from Ajax as Javascript code
	preselectSize(globalSize);
}

function preselectSize(size) {
  var obj = document.getElementById('size_id');
  var len = obj.length;
  var option;
  for (var i=0; i < len; i++) {
    option = obj.options[i];
    if (option.value == size) {
      option.selected = true;
      break;
    }
  }
}