// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

/* fade flashes automatically */
Event.observe(window, 'load', function() { 
  $A(document.getElementsByClassName('alert')).each(function(o) {
    o.opacity = 100.0
    Effect.Fade(o, {duration: 8.0})
  });
});

var searchResultsTextPrepend = "Search results for: ";

function changeTextColor(color) {
  $('search').style.color = color;
}

function clearSearch(query, search_text_from_ruby_land) {
  if ($('search').value == search_text_from_ruby_land){
    $('search').value = "";
  }
  
  if (query && $('search').value == searchResultsTextPrepend + query) {
    $('search').value = query;
  }

  changeTextColor("black");
}

function resetSearch(query, search_text_from_ruby_land) {
  if ($('search').value == "") {
    $('search').value = search_text_from_ruby_land;
  } 
  if ($('search').value == query) {
    $('search').value = searchResultsTextPrepend + query;
  }
  
  changeTextColor("#999");
}

function clearListItem(list_item_value) {
  if ($('item_name').value == list_item_value) {
    $('item_name').value = "";
  } 
  $('item_name').style.color = "black";
}

function resetListItem(list_item_value) {
  if ($('item_name').value == "") {
    $('item_name').value = list_item_value;
  } 
  $('item_name').style.color = "#999";
}

function imposeMaxLength(Object, MaxLen)
{
  return (Object.value.length <= MaxLen);
}

function validateTermsAcceptance() {
  if($('terms').getValue() == null) {
    alert("You must accept our very simple 'Terms and Conditions' to create an account. So, check 'em out and then check that box.");
    return false;
  }
}

function emptyField(field_id)
{
  if ($(field_id).value == '' ) {
    alert('Oops. You can\'t submit an empty field.');
    return false;
  }
}
