$(function(){
  $("select##stateID").change(function(){
    $.getJSON( baseUrl + "/tasting/getRegionsByStateID", {stateID: $(this).val(), ajax: 'true' }, function(j){
      var options = '';
      for (var i = 0; i < j.length; i++) {
        options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
      }
      $("select##regionID").html(options);
    });
  });
});

$(function(){
  $("select##winetype").change(function(){
    $.getJSON( baseUrl + "/tasting/getVarietalsByWineType", {WineType: $(this).val(), ajax: 'true' }, function(j){
      var options = '<option value="">All</option>';
      for (var i = 0; i < j.length; i++) {
        options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
      }
      $("select##varietal").html(options);
    });
  });
});

$(document).ready(function () {
	$('input[name="addBooking"]').live('click', function() {
		
		var parentForm = $(this).parents("form:eq(0)");
		fieldExists = 0;
		if($('[name=methodPath]')){
			fieldExists = 1;
			tempEl = $('[name=methodPath]');
			$('[name=methodPath]').remove();
		}
		$('#laySmallClipBoard').load(baseUrl + "/clipboard/add", parentForm.serialize());
		if(fieldExists){
			$('form#laySmallClipBoard').append(tempEl).attr('name', 'methodPath').attr('name', tempEl.val());
		}
		return false;
	});
});

$(function() {
	$("#resultsPerPage").live('change',function() {
		var parentForm = $(this).parents("form:eq(0)");
		parentForm.submit();
		
	});
});