/**
 * Validate the entered restaurant city.  If valid then update and submit the form
 */
function restaurantFormOnSubmit()
{
    var geo = $('restaurantGeo').value;
    if (geo == '')
    {
        // TODO: Maybe we do have a match in the list and they typed it or did a copy/paste?
        alert(JS_choose_valid_city);
        return false;
    }

  // We need to 'pack' the price range into bits so we can pass to the URL
  var priceRange = 0;
  var checkboxes = $("RESTAURANT_FORM").priceRange;
  for (i = 0; i < checkboxes.length; i++)
  {
      if (checkboxes[i].checked)
      {
          priceRange |= 1 << i;
      }
  }
  if(priceRange > 0)
  {
      $("restaurantPricePack").value = priceRange;
  }
  
    return true;
}

rules['input.restaurantTypeAhead'] = function(elmt) {
  if (action = elmt.className.match(/\bact(\w+)\b/)) {
    new Autocompleter.Ajax.Json2(elmt, "/TypeAheadJson?action="+action[1], {
      ajaxOptions: {method:'get'},
      postVar: 'query',
      inheritWidth: false,
      onSelect: function(elmt, resObj) {
        $('restaurantGeo').value = resObj.value;
      }
    });
  }
}

rules['#RESTAURANT_FORM'] = function(elmt) {
  elmt.addEvent('submit', function(e) {
    if (!restaurantFormOnSubmit()) { (new Event(e)).stop(); }
  });
}