document.cookie = 'JavaScriptSupported=true;path=/';

var TR_currMenu;

jQuery.fn.extend({
  blink: function() {
    this.animate({opacity: 0.25},250)
        .animate({opacity: 1},250)
        .animate({opacity: 0.25},250)
        .animate({opacity: 1},250)
        .animate({opacity: 0.25},250)
        .animate({opacity: 1},250)
        .animate({opacity: 0.25},250)
        .animate({opacity: 1},250)
        .animate({opacity: 0.25},250)
        .animate({opacity: 1},250);
  }
});

String.prototype.isInteger = function() {
  return this.match(/^(-?)[1-9]+[0-9]*$/);
}

String.prototype.trim = function() {
  return this.valueOf().replace(/^\s*/,"").replace(/\s*$/,"");
}

function _TR_currMenu(id) {
  TR_currMenu = id;
}

function TR_closeMenu() {
  _TR_currMenu(null);
  setTimeout('_TR_closeMenu();',750);
}

function _TR_closeMenu() {
  if (!TR_currMenu) {
    $('.tr-menus').css('display','none');
    $('select').css('visibility','visible');
  }
}

function TR_openMenu(trigger) {
  if (jQuery.browser.msie && parseInt(jQuery.browser.version) < 7) {
    $("select").css('visibility','hidden');
  }
  var menu = $('#' + trigger.attr('id') + '-menu');
  _TR_currMenu(menu.attr('id'));
  if (menu.css('display') != 'block') {
    $('.tr-menus').css('display','none'); // Close all open menus
    menu.css('left',trigger.offset().left+'px').css('top','160px').fadeIn('def').css('display','block');
  }
}

function TR_noCaps(fo) {
  fo.value = ucwords(fo.value.toLowerCase());
}

function ucwords(str) {
  return (str + '').replace(/^(.)|\s(.)/g, function ($1) {
    return $1.toUpperCase();
  });
}

function trim(strText) { 
  while (strText.substring(0,1) == ' ') 
      strText = strText.substring(1, strText.length);
 
  while (strText.substring(strText.length-1,strText.length) == ' ')
      strText = strText.substring(0, strText.length-1);

  return strText;
}

function isEmail(email) {
  var emailReg = "^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.(([0-9]{1,3})|([a-zA-Z]{2,3})|(aero|coop|info|museum|name))$";
  var regex = new RegExp(emailReg);
  return regex.test(email);
}

function isInteger(val) {
  var regex = new RegExp('^(-)?([1-9])+(0-9)*$');
  return regex.test(val);
}

$(document).ready(function() {
  /**
   * Set up menus
   */
  $("#shopby-vehicles").bind('mouseover',function() { TR_openMenu($(this)) }).bind('mouseout',TR_closeMenu);
  $("#shopby-vehicles-menu").bind('mouseover', function() { _TR_currMenu("shopby-vehicles-menu") }).bind('mouseout',TR_closeMenu);
  $("#shopby-categories").bind('mouseover',function() { TR_openMenu($(this)) });
  $("#shopby-categories-menu").bind('mouseover', function() { _TR_currMenu("shopby-categories-menu") }).bind('mouseout',TR_closeMenu);
  $("#shopby-manufacturers").bind('mouseover',function() { TR_openMenu($(this)) });
  $("#shopby-manufacturers-menu").bind('mouseover', function() { _TR_currMenu("shopby-manufacturers-menu") }).bind('mouseout',TR_closeMenu);
});

