var baseurl = 'http://coop-recipe.jp/';

String.prototype.strip = function() {return this.replace(/^\s+/, '').replace(/\s+$/, '');};
String.prototype.empty = function() {return (this.strip().length == 0);};
String.prototype.escapeHTML = function() { return this.replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/&/g, '&amp;');};
String.prototype.br = function() { return this.replace(/\n/g, '<br />'); };
String.prototype.unbr = function() { return this.replace(/<br\s?\/?>/gi, '\n'); };
String.prototype.stripHTML = function() { return this.replace(/<\/?[^>]+>/gi, '');};
String.prototype.truncate = function(len) {
  if (this.length < len) return this;
  return this.substring(0, len-1) + '...';
};

function set_querystring(f) {
  if ($('input:text', f).hasClass('textinputhover_select_none'))
    $('input:text', f).attr('value', '');
}

$(document).ready(function() {
  $('input.search_input').textinputhover({defaultMessage:'レシピ名や材料から検索',clear:true});
  $('form.new_search a').click(function(e) {
    e.preventDefault();
    var f = $(this).parents('form').get(0);
    set_querystring(f);
    f.submit();
  });
  $('a.advanced_search_submit').click(function(e) {
    e.preventDefault();
    var f = $(this).parents('form').get(0);
    set_querystring(f);
    f.submit();
  });
  $('form.new_search').submit(function(e) {
    set_querystring(this);
  });
  $('form.advanced_search').submit(function(e) {
    set_querystring(this);
  });
});