function hideAndDisable(elementId) {
  $(elementId).hide();
  $(elementId).disable();
}

function showAndEnable(elementId) {
  $(elementId).show();
  $(elementId).enable();
}

function setState(element, value) {
  if (value == 'United States') { 
    $('state_area').show(); 
    showAndEnable('state');
    hideAndDisable('province');
  } else if (value == 'Canada') { 
    $('state_area').show();
    hideAndDisable('state');     
    showAndEnable('province');
  } else { 
    $('state_area').hide(); 
    $('state').disable(); 
    $('province').disable(); 
  }  
}

function saveRecipe(form) {
	  $('directions_ids').value = Sortable.serialize('directions_list');
	  $('ingredients_ids').value = Sortable.serialize('ingredients_list');
    form.submit();
}

function catchExternalLinks() {
  $$('a').each(function(el, i){
    if(el.getAttribute('href') && el.getAttribute('href').toString().startsWith('http') && (el.getAttribute('href').toString().indexOf(window.location.host) == -1)) {
      el.observe('click', function(e){
        e.stop();
        window.open(e.target.href);
      });
    }
  });
}
